@netnodeag/kraftwerk 0.74.0 → 0.75.1

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.
@@ -1,4 +1,4 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/editor-ByOSpxTX.js","assets/dist-CYzOYk_e.js","assets/dist-Df4EJMUZ.js","assets/dist-CaGkA8bH.js","assets/dist-BJQuUDA0.js","assets/dist-BdZ5cNRp.js","assets/editor-CZMrhTTL.css"])))=>i.map(i=>d[i]);
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/editor-DEb8z5-Q.js","assets/dist-CYzOYk_e.js","assets/dist-QqFmuPda.js","assets/dist-BI4umsk6.js","assets/dist-YNCNGGgK.js","assets/dist-BdZ5cNRp.js","assets/editor-CZMrhTTL.css"])))=>i.map(i=>d[i]);
2
2
  var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),s=(e,n)=>{let r={};for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n||t(r,Symbol.toStringTag,{value:`Module`}),r},c=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},l=(n,r,o)=>(o=n==null?{}:e(i(n)),c(r||!n||!n.__esModule||!a.call(n,`default`)?t(o,`default`,{value:n,enumerable:!0}):o,n));(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var u=o((e=>{var t=Symbol.for(`react.transitional.element`),n=Symbol.for(`react.portal`),r=Symbol.for(`react.fragment`),i=Symbol.for(`react.strict_mode`),a=Symbol.for(`react.profiler`),o=Symbol.for(`react.consumer`),s=Symbol.for(`react.context`),c=Symbol.for(`react.forward_ref`),l=Symbol.for(`react.suspense`),u=Symbol.for(`react.memo`),d=Symbol.for(`react.lazy`),f=Symbol.for(`react.activity`),p=Symbol.for(`react.view_transition`),m=Symbol.iterator;function h(e){return typeof e!=`object`||!e?null:(e=m&&e[m]||e[`@@iterator`],typeof e==`function`?e:null)}var g={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},_=Object.assign,v={};function y(e,t,n){this.props=e,this.context=t,this.refs=v,this.updater=n||g}y.prototype.isReactComponent={},y.prototype.setState=function(e,t){if(typeof e!=`object`&&typeof e!=`function`&&e!=null)throw Error(`takes an object of state variables to update or a function which returns an object of state variables.`);this.updater.enqueueSetState(this,e,t,`setState`)},y.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,`forceUpdate`)};function b(){}b.prototype=y.prototype;function x(e,t,n){this.props=e,this.context=t,this.refs=v,this.updater=n||g}var S=x.prototype=new b;S.constructor=x,_(S,y.prototype),S.isPureReactComponent=!0;var C=Array.isArray;function w(){}var T={H:null,A:null,T:null,S:null},E=Object.prototype.hasOwnProperty;function D(e,n,r){var i=r.ref;return{$$typeof:t,type:e,key:n,ref:i===void 0?null:i,props:r}}function O(e,t){return D(e.type,t,e.props)}function k(e){return typeof e==`object`&&!!e&&e.$$typeof===t}function A(e){var t={"=":`=0`,":":`=2`};return`$`+e.replace(/[=:]/g,function(e){return t[e]})}var j=/\/+/g;function ee(e,t){return typeof e==`object`&&e&&e.key!=null?A(``+e.key):t.toString(36)}function M(e){switch(e.status){case`fulfilled`:return e.value;case`rejected`:throw e.reason;default:switch(typeof e.status==`string`?e.then(w,w):(e.status=`pending`,e.then(function(t){e.status===`pending`&&(e.status=`fulfilled`,e.value=t)},function(t){e.status===`pending`&&(e.status=`rejected`,e.reason=t)})),e.status){case`fulfilled`:return e.value;case`rejected`:throw e.reason}}throw e}function N(e,r,i,a,o){var s=typeof e;(s===`undefined`||s===`boolean`)&&(e=null);var c=!1;if(e===null)c=!0;else switch(s){case`bigint`:case`string`:case`number`:c=!0;break;case`object`:switch(e.$$typeof){case t:case n:c=!0;break;case d:return c=e._init,N(c(e._payload),r,i,a,o)}}if(c)return o=o(e),c=a===``?`.`+ee(e,0):a,C(o)?(i=``,c!=null&&(i=c.replace(j,`$&/`)+`/`),N(o,r,i,``,function(e){return e})):o!=null&&(k(o)&&(o=O(o,i+(o.key==null||e&&e.key===o.key?``:(``+o.key).replace(j,`$&/`)+`/`)+c)),r.push(o)),1;c=0;var l=a===``?`.`:a+`:`;if(C(e))for(var u=0;u<e.length;u++)a=e[u],s=l+ee(a,u),c+=N(a,r,i,s,o);else if(u=h(e),typeof u==`function`)for(e=u.call(e),u=0;!(a=e.next()).done;)a=a.value,s=l+ee(a,u++),c+=N(a,r,i,s,o);else if(s===`object`){if(typeof e.then==`function`)return N(M(e),r,i,a,o);throw r=String(e),Error(`Objects are not valid as a React child (found: `+(r===`[object Object]`?`object with keys {`+Object.keys(e).join(`, `)+`}`:r)+`). If you meant to render a collection of children, use an array instead.`)}return c}function P(e,t,n){if(e==null)return e;var r=[],i=0;return N(e,r,``,``,function(e){return t.call(n,e,i++)}),r}function te(e){if(e._status===-1){var t=e._result,n=t();n.then(function(t){(e._status===0||e._status===-1)&&(e._status=1,e._result=t,n.status===void 0&&(n.status=`fulfilled`,n.value=t))},function(t){(e._status===0||e._status===-1)&&(e._status=2,e._result=t,n.status===void 0&&(n.status=`rejected`,n.reason=t))}),e._status===-1&&(e._status=0,e._result=n)}if(e._status===1)return e._result.default;throw e._result}var ne=typeof reportError==`function`?reportError:function(e){if(typeof window==`object`&&typeof window.ErrorEvent==`function`){var t=new window.ErrorEvent(`error`,{bubbles:!0,cancelable:!0,message:typeof e==`object`&&e&&typeof e.message==`string`?String(e.message):String(e),error:e});if(!window.dispatchEvent(t))return}else if(typeof process==`object`&&typeof process.emit==`function`){process.emit(`uncaughtException`,e);return}console.error(e)};function F(e){var t=T.T,n={};n.types=t===null?null:t.types,T.T=n;try{var r=e(),i=T.S;i!==null&&i(n,r),typeof r==`object`&&r&&typeof r.then==`function`&&r.then(w,ne)}catch(e){ne(e)}finally{t!==null&&n.types!==null&&(t.types=n.types),T.T=t}}function I(e){var t=T.T;if(t!==null){var n=t.types;n===null?t.types=[e]:n.indexOf(e)===-1&&n.push(e)}else F(I.bind(null,e))}var L={map:P,forEach:function(e,t,n){P(e,function(){t.apply(this,arguments)},n)},count:function(e){var t=0;return P(e,function(){t++}),t},toArray:function(e){return P(e,function(e){return e})||[]},only:function(e){if(!k(e))throw Error(`React.Children.only expected to receive a single React element child.`);return e}};e.Activity=f,e.Children=L,e.Component=y,e.Fragment=r,e.Profiler=a,e.PureComponent=x,e.StrictMode=i,e.Suspense=l,e.ViewTransition=p,e.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=T,e.__COMPILER_RUNTIME={__proto__:null,c:function(e){return T.H.useMemoCache(e)}},e.addTransitionType=I,e.cache=function(e){return function(){return e.apply(null,arguments)}},e.cacheSignal=function(){return null},e.cloneElement=function(e,t,n){if(e==null)throw Error(`The argument must be a React element, but you passed `+e+`.`);var r=_({},e.props),i=e.key;if(t!=null)for(a in t.key!==void 0&&(i=``+t.key),t)!E.call(t,a)||a===`key`||a===`__self`||a===`__source`||a===`ref`&&t.ref===void 0||(r[a]=t[a]);var a=arguments.length-2;if(a===1)r.children=n;else if(1<a){for(var o=Array(a),s=0;s<a;s++)o[s]=arguments[s+2];r.children=o}return D(e.type,i,r)},e.createContext=function(e){return e={$$typeof:s,_currentValue:e,_currentValue2:e,_threadCount:0,Provider:null,Consumer:null},e.Provider=e,e.Consumer={$$typeof:o,_context:e},e},e.createElement=function(e,t,n){var r,i={},a=null;if(t!=null)for(r in t.key!==void 0&&(a=``+t.key),t)E.call(t,r)&&r!==`key`&&r!==`__self`&&r!==`__source`&&(i[r]=t[r]);var o=arguments.length-2;if(o===1)i.children=n;else if(1<o){for(var s=Array(o),c=0;c<o;c++)s[c]=arguments[c+2];i.children=s}if(e&&e.defaultProps)for(r in o=e.defaultProps,o)i[r]===void 0&&(i[r]=o[r]);return D(e,a,i)},e.createRef=function(){return{current:null}},e.forwardRef=function(e){return{$$typeof:c,render:e}},e.isValidElement=k,e.lazy=function(e){return{$$typeof:d,_payload:{_status:-1,_result:e},_init:te}},e.memo=function(e,t){return{$$typeof:u,type:e,compare:t===void 0?null:t}},e.startTransition=F,e.unstable_useCacheRefresh=function(){return T.H.useCacheRefresh()},e.use=function(e){return T.H.use(e)},e.useActionState=function(e,t,n){return T.H.useActionState(e,t,n)},e.useCallback=function(e,t){return T.H.useCallback(e,t)},e.useContext=function(e){return T.H.useContext(e)},e.useDebugValue=function(){},e.useDeferredValue=function(e,t){return T.H.useDeferredValue(e,t)},e.useEffect=function(e,t){return T.H.useEffect(e,t)},e.useEffectEvent=function(e){return T.H.useEffectEvent(e)},e.useId=function(){return T.H.useId()},e.useImperativeHandle=function(e,t,n){return T.H.useImperativeHandle(e,t,n)},e.useInsertionEffect=function(e,t){return T.H.useInsertionEffect(e,t)},e.useLayoutEffect=function(e,t){return T.H.useLayoutEffect(e,t)},e.useMemo=function(e,t){return T.H.useMemo(e,t)},e.useOptimistic=function(e,t){return T.H.useOptimistic(e,t)},e.useReducer=function(e,t,n){return T.H.useReducer(e,t,n)},e.useRef=function(e){return T.H.useRef(e)},e.useState=function(e){return T.H.useState(e)},e.useSyncExternalStore=function(e,t,n){return T.H.useSyncExternalStore(e,t,n)},e.useTransition=function(){return T.H.useTransition()},e.version=`19.3.0`})),d=o(((e,t)=>{t.exports=u()})),f=o((e=>{function t(e,t){var n=e.length;e.push(t);a:for(;0<n;){var r=n-1>>>1,a=e[r];if(0<i(a,t))e[r]=t,e[n]=a,n=r;else break a}}function n(e){return e.length===0?null:e[0]}function r(e){if(e.length===0)return null;var t=e[0],n=e.pop();if(n!==t){e[0]=n;a:for(var r=0,a=e.length,o=a>>>1;r<o;){var s=2*(r+1)-1,c=e[s],l=s+1,u=e[l];if(0>i(c,n))l<a&&0>i(u,c)?(e[r]=u,e[l]=n,r=l):(e[r]=c,e[s]=n,r=s);else if(l<a&&0>i(u,n))e[r]=u,e[l]=n,r=l;else break a}}return t}function i(e,t){var n=e.sortIndex-t.sortIndex;return n===0?e.id-t.id:n}if(e.unstable_now=void 0,typeof performance==`object`&&typeof performance.now==`function`){var a=performance;e.unstable_now=function(){return a.now()}}else{var o=Date,s=o.now();e.unstable_now=function(){return o.now()-s}}var c=[],l=[],u=1,d=null,f=3,p=!1,m=!1,h=!1,g=!1,_=typeof setTimeout==`function`?setTimeout:null,v=typeof clearTimeout==`function`?clearTimeout:null,y=typeof setImmediate<`u`?setImmediate:null;function b(e){for(var i=n(l);i!==null;){if(i.callback===null)r(l);else if(i.startTime<=e)r(l),i.sortIndex=i.expirationTime,t(c,i);else break;i=n(l)}}function x(e){if(h=!1,b(e),!m){if(n(c)!==null)m=!0,S||(S=!0,O());else{var t=n(l);t!==null&&j(x,t.startTime-e)}}}var S=!1,C=-1,w=5,T=-1;function E(){return g?!0:!(e.unstable_now()-T<w)}function D(){if(g=!1,S){var t=e.unstable_now();T=t;var i=!0;try{a:{m=!1,h&&(h=!1,v(C),C=-1),p=!0;var a=f;try{b:{for(b(t),d=n(c);d!==null&&!(d.expirationTime>t&&E());){var o=d.callback;if(typeof o==`function`){d.callback=null,f=d.priorityLevel;var s=o(d.expirationTime<=t);if(t=e.unstable_now(),typeof s==`function`){d.callback=s,b(t),i=!0;break b}d===n(c)&&r(c),b(t)}else r(c);d=n(c)}if(d!==null)i=!0;else{var u=n(l);u!==null&&j(x,u.startTime-t),i=!1}}break a}finally{d=null,f=a,p=!1}i=void 0}}finally{i?O():S=!1}}}var O;if(typeof y==`function`)O=function(){y(D)};else if(typeof MessageChannel<`u`){var k=new MessageChannel,A=k.port2;k.port1.onmessage=D,O=function(){A.postMessage(null)}}else O=function(){_(D,0)};function j(t,n){C=_(function(){t(e.unstable_now())},n)}e.unstable_IdlePriority=5,e.unstable_ImmediatePriority=1,e.unstable_LowPriority=4,e.unstable_NormalPriority=3,e.unstable_Profiling=null,e.unstable_UserBlockingPriority=2,e.unstable_cancelCallback=function(e){e.callback=null},e.unstable_forceFrameRate=function(e){0>e||125<e?console.error(`forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported`):w=0<e?Math.floor(1e3/e):5},e.unstable_getCurrentPriorityLevel=function(){return f},e.unstable_next=function(e){switch(f){case 1:case 2:case 3:var t=3;break;default:t=f}var n=f;f=t;try{return e()}finally{f=n}},e.unstable_requestPaint=function(){g=!0},e.unstable_runWithPriority=function(e,t){switch(e){case 1:case 2:case 3:case 4:case 5:break;default:e=3}var n=f;f=e;try{return t()}finally{f=n}},e.unstable_scheduleCallback=function(r,i,a){var o=e.unstable_now();switch(typeof a==`object`&&a?(a=a.delay,a=typeof a==`number`&&0<a?o+a:o):a=o,r){case 1:var s=-1;break;case 2:s=250;break;case 5:s=1073741823;break;case 4:s=1e4;break;default:s=5e3}return s=a+s,r={id:u++,callback:i,priorityLevel:r,startTime:a,expirationTime:s,sortIndex:-1},a>o?(r.sortIndex=a,t(l,r),n(c)===null&&r===n(l)&&(h?(v(C),C=-1):h=!0,j(x,a-o))):(r.sortIndex=s,t(c,r),m||p||(m=!0,S||(S=!0,O()))),r},e.unstable_shouldYield=E,e.unstable_wrapCallback=function(e){var t=f;return function(){var n=f;f=t;try{return e.apply(this,arguments)}finally{f=n}}}})),p=o(((e,t)=>{t.exports=f()})),m=o((e=>{var t=d();function n(e){var t=`https://react.dev/errors/`+e;if(1<arguments.length){t+=`?args[]=`+encodeURIComponent(arguments[1]);for(var n=2;n<arguments.length;n++)t+=`&args[]=`+encodeURIComponent(arguments[n])}return`Minified React error #`+e+`; visit `+t+` for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`}function r(){}var i={d:{f:r,r:function(){throw Error(n(522))},D:r,C:r,L:r,m:r,X:r,S:r,M:r},p:0,findDOMNode:null},a=Symbol.for(`react.portal`),o=Symbol.for(`react.recoverable`),s=Symbol.for(`react.optimistic_key`);function c(e,t,n){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:a,key:r==null?null:r===s?s:``+r,children:e,containerInfo:t,implementation:n}}var l=t.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;function u(e,t){if(e===`font`)return``;if(typeof t==`string`)return t===`use-credentials`?t:``}e.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=i,e.browser=function(e){return{$$typeof:o,_reason:e}},e.createPortal=function(e,t){var r=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!t||t.nodeType!==1&&t.nodeType!==9&&t.nodeType!==11)throw Error(n(299));return c(e,t,null,r)},e.flushSync=function(e){var t=l.T,n=i.p;try{if(l.T=null,i.p=2,e)return e()}finally{l.T=t,i.p=n,i.d.f()}},e.preconnect=function(e,t){typeof e==`string`&&(t?(t=t.crossOrigin,t=typeof t==`string`?t===`use-credentials`?t:``:void 0):t=null,i.d.C(e,t))},e.prefetchDNS=function(e){typeof e==`string`&&i.d.D(e)},e.preinit=function(e,t){if(typeof e==`string`&&t&&typeof t.as==`string`){var n=t.as,r=u(n,t.crossOrigin),a=typeof t.integrity==`string`?t.integrity:void 0,o=typeof t.fetchPriority==`string`?t.fetchPriority:void 0;n===`style`?i.d.S(e,typeof t.precedence==`string`?t.precedence:void 0,{crossOrigin:r,integrity:a,fetchPriority:o}):n===`script`&&i.d.X(e,{crossOrigin:r,integrity:a,fetchPriority:o,nonce:typeof t.nonce==`string`?t.nonce:void 0})}},e.preinitModule=function(e,t){if(typeof e==`string`){if(typeof t==`object`&&t){if(t.as==null||t.as===`script`){var n=u(t.as,t.crossOrigin);i.d.M(e,{crossOrigin:n,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0,fetchPriority:typeof t.fetchPriority==`string`?t.fetchPriority:void 0})}}else t??i.d.M(e)}},e.preload=function(e,t){if(typeof e==`string`&&typeof t==`object`&&t&&typeof t.as==`string`){var n=t.as,r=u(n,t.crossOrigin);i.d.L(e,n,{crossOrigin:r,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0,type:typeof t.type==`string`?t.type:void 0,fetchPriority:typeof t.fetchPriority==`string`?t.fetchPriority:void 0,referrerPolicy:typeof t.referrerPolicy==`string`?t.referrerPolicy:void 0,imageSrcSet:typeof t.imageSrcSet==`string`?t.imageSrcSet:void 0,imageSizes:typeof t.imageSizes==`string`?t.imageSizes:void 0,media:typeof t.media==`string`?t.media:void 0})}},e.preloadModule=function(e,t){if(typeof e==`string`){if(t){var n=u(t.as,t.crossOrigin);i.d.m(e,{as:typeof t.as==`string`&&t.as!==`script`?t.as:void 0,crossOrigin:n,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0,fetchPriority:typeof t.fetchPriority==`string`?t.fetchPriority:void 0})}else i.d.m(e)}},e.requestFormReset=function(e){i.d.r(e)},e.unstable_batchedUpdates=function(e,t){return e(t)},e.useFormState=function(e,t,n){return l.H.useFormState(e,t,n)},e.useFormStatus=function(){return l.H.useHostTransitionStatus()},e.version=`19.3.0`})),h=o(((e,t)=>{function n(){if(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<`u`&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE==`function`)try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(n)}catch(e){console.error(e)}}n(),t.exports=m()})),g=o((e=>{var t=p(),n=d(),r=h();function i(e){var t=`https://react.dev/errors/`+e;if(1<arguments.length){t+=`?args[]=`+encodeURIComponent(arguments[1]);for(var n=2;n<arguments.length;n++)t+=`&args[]=`+encodeURIComponent(arguments[n])}return`Minified React error #`+e+`; visit `+t+` for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`}function a(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function o(e){for(var t=e,n=t;n&&!n.alternate;)t=n,t.flags&4098&&(e=t.return),n=t.return;for(;t.return;)t=t.return;return t.tag===3?e:null}function s(e){if(e.tag===13){var t=e.memoizedState;if(t===null&&(e=e.alternate,e!==null&&(t=e.memoizedState)),t!==null)return t.dehydrated}return null}function c(e){if(e.tag===31){var t=e.memoizedState;if(t===null&&(e=e.alternate,e!==null&&(t=e.memoizedState)),t!==null)return t.dehydrated}return null}function l(e){if(o(e)!==e)throw Error(i(188))}function u(e){var t=e.alternate;if(!t){if(t=o(e),t===null)throw Error(i(188));return t===e?e:null}for(var n=e,r=t;;){var a=n.return;if(a===null)break;var s=a.alternate;if(s===null){if(r=a.return,r!==null){n=r;continue}break}if(a.child===s.child){for(s=a.child;s;){if(s===n)return l(a),e;if(s===r)return l(a),t;s=s.sibling}throw Error(i(188))}if(n.return!==r.return)n=a,r=s;else{for(var c=!1,u=a.child;u;){if(u===n){c=!0,n=a,r=s;break}if(u===r){c=!0,r=a,n=s;break}u=u.sibling}if(!c){for(u=s.child;u;){if(u===n){c=!0,n=s,r=a;break}if(u===r){c=!0,r=s,n=a;break}u=u.sibling}if(!c)throw Error(i(189))}}if(n.alternate!==r)throw Error(i(190))}if(n.tag!==3)throw Error(i(188));return n.stateNode.current===n?e:t}function f(e){var t=e.tag;if(t===5||t===26||t===27||t===6)return e;for(e=e.child;e!==null;){if(t=f(e),t!==null)return t;e=e.sibling}return null}function m(e,t,n,r,i,a){for(;e!==null;){if((e.tag===5||e.tag===27||e.tag===6)&&n(e,r,i,a)||(e.tag!==22||e.memoizedState===null)&&(t||e.tag!==5&&e.tag!==27)&&m(e.child,t,n,r,i,a))return!0;e=e.sibling}return!1}function g(e){for(e=e.return;e!==null;){if(e.tag===3||e.tag===5||e.tag===27)return e;e=e.return}return null}function _(e){var t=!1;for(e=e.return;e!==null&&(e.tag===4&&(t=!0),e.tag!==3&&e.tag!==5&&e.tag!==27);)e=e.return;return t}function v(e){var t=[null,null],n=g(e);return n===null||y(t,e,n.child,{foundSelf:!1}),t}function y(e,t,n,r){for(;n!==null;){if(n===t)r.foundSelf=!0;else if(n.tag===5||n.tag===27||n.tag===6){if(r.foundSelf)return e[1]=n,!0;e[0]=n}else if((n.tag!==22||n.memoizedState===null)&&y(e,t,n.child,r))return!0;n=n.sibling}return!1}function b(e){switch(e.tag){case 5:case 27:case 6:return e.stateNode;case 3:return e.stateNode.containerInfo;default:throw Error(i(559))}}var x=null,S=null;function C(e,t,n){return e===n||e===t&&(x=e,!0)}function w(e,t,n){return e===n?(S=e,!1):e===t&&(S!==null&&(x=e),!0)}function T(e){if(e===null)return null;do e=e===null?null:e.return;while(e&&e.tag!==5&&e.tag!==27&&e.tag!==3);return e||null}function E(e,t,n){for(var r=0,i=e;i;i=n(i))r++;i=0;for(var a=t;a;a=n(a))i++;for(;0<r-i;)e=n(e),r--;for(;0<i-r;)t=n(t),i--;for(;r--;){if(e===t||t!==null&&e===t.alternate)return e;e=n(e),t=n(t)}return null}var D=Object.assign,O=Symbol.for(`react.element`),k=Symbol.for(`react.transitional.element`),A=Symbol.for(`react.portal`),j=Symbol.for(`react.fragment`),ee=Symbol.for(`react.strict_mode`),M=Symbol.for(`react.profiler`),N=Symbol.for(`react.consumer`),P=Symbol.for(`react.context`),te=Symbol.for(`react.forward_ref`),ne=Symbol.for(`react.suspense`),F=Symbol.for(`react.suspense_list`),I=Symbol.for(`react.memo`),L=Symbol.for(`react.lazy`),re=Symbol.for(`react.activity`),ie=Symbol.for(`react.legacy_hidden`),ae=Symbol.for(`react.memo_cache_sentinel`),oe=Symbol.for(`react.view_transition`),se=Symbol.for(`react.recoverable`),ce=Symbol.iterator;function le(e){return typeof e!=`object`||!e?null:(e=ce&&e[ce]||e[`@@iterator`],typeof e==`function`?e:null)}var ue=Symbol.for(`react.client.reference`);function de(e){if(e==null)return null;if(typeof e==`function`)return e.$$typeof===ue?null:e.displayName||e.name||null;if(typeof e==`string`)return e;switch(e){case j:return`Fragment`;case M:return`Profiler`;case ee:return`StrictMode`;case ne:return`Suspense`;case F:return`SuspenseList`;case re:return`Activity`;case oe:return`ViewTransition`}if(typeof e==`object`)switch(e.$$typeof){case A:return`Portal`;case P:return e.displayName||`Context`;case N:return(e._context.displayName||`Context`)+`.Consumer`;case te:var t=e.render;return e=e.displayName,e||=(e=t.displayName||t.name||``,e===``?`ForwardRef`:`ForwardRef(`+e+`)`),e;case I:return t=e.displayName||null,t===null?de(e.type)||`Memo`:t;case L:t=e._payload,e=e._init;try{return de(e(t))}catch{}}return null}var R=Array.isArray,z=n.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,B=r.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,fe={pending:!1,data:null,method:null,action:null},pe=[],me=-1;function he(e){return{current:e}}function ge(e){0>me||(e.current=pe[me],pe[me]=null,me--)}function _e(e,t){me++,pe[me]=e.current,e.current=t}var ve=he(null),ye=he(null),be=he(null),xe=he(null);function Se(e,t){switch(_e(be,t),_e(ye,e),_e(ve,null),t.nodeType){case 9:case 11:e=(e=t.documentElement)&&(e=e.namespaceURI)?up(e):0;break;default:if(e=t.tagName,t=t.namespaceURI)t=up(t),e=dp(t,e);else switch(e){case`svg`:e=1;break;case`math`:e=2;break;default:e=0}}ge(ve),_e(ve,e)}function Ce(){ge(ve),ge(ye),ge(be)}function we(e){var t=e.memoizedState;t!==null&&(sh._currentValue=t.memoizedState,_e(xe,e)),t=ve.current;var n=dp(t,e.type);t!==n&&(_e(ye,e),_e(ve,n))}function Te(e){ye.current===e&&(ge(ve),ge(ye)),xe.current===e&&(ge(xe),sh._currentValue=fe)}var Ee,De;function Oe(e){if(Ee===void 0)try{throw Error()}catch(e){var t=e.stack.trim().match(/\n( *(at )?)/);Ee=t&&t[1]||``,De=-1<e.stack.indexOf(`
3
3
  at`)?` (<anonymous>)`:-1<e.stack.indexOf(`@`)?`@unknown:0:0`:``}return`
4
4
  `+Ee+e+De}var ke=!1;function Ae(e,t){if(!e||ke)return``;ke=!0;var n=Error.prepareStackTrace;Error.prepareStackTrace=void 0;try{var r={DetermineComponentFrameRoot:function(){try{if(t){var n=function(){throw Error()};if(Object.defineProperty(n.prototype,"props",{set:function(){throw Error()}}),typeof Reflect==`object`&&Reflect.construct){try{Reflect.construct(n,[])}catch(e){var r=e}Reflect.construct(e,[],n)}else{try{n.call()}catch(e){r=e}n=!1;try{var i=Object.getOwnPropertyDescriptor(e.prototype,`props`);Object.defineProperty(e.prototype,"props",{configurable:!0,set:function(){throw Error()}}),n=!0,new e}finally{n&&(i===void 0?delete e.prototype.props:Object.defineProperty(e.prototype,"props",i))}}}else{try{throw Error()}catch(e){r=e}(n=e())&&typeof n.catch==`function`&&n.catch(function(){})}}catch(e){if(e&&r&&typeof e.stack==`string`)return[e.stack,r.stack]}return[null,null]}};r.DetermineComponentFrameRoot.displayName=`DetermineComponentFrameRoot`;var i=Object.getOwnPropertyDescriptor(r.DetermineComponentFrameRoot,`name`);i&&i.configurable&&Object.defineProperty(r.DetermineComponentFrameRoot,"name",{value:`DetermineComponentFrameRoot`});var a=r.DetermineComponentFrameRoot(),o=a[0],s=a[1];if(o&&s){var c=o.split(`
@@ -78,16 +78,16 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
78
78
  `+u),xe&&(u=ht(u)),T&&Ae?j(u):u},t.setConfig=function(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};et(e),we=!0,Te=R,Ee=B},t.clearConfig=function(){G=null,we=!1,Te=null,Ee=null,T=D,E=``},t.isValidAttribute=function(e,t,n){G||et({});let r=$e(e),i=$e(t);return Tt(r,i,n)},t.addHook=function(e,t){typeof t==`function`&&vi(L,e)&&ai(L[e],t)},t.removeHook=function(e,t){if(vi(L,e)){if(t!==void 0){let n=ri(L[e],t);return n===-1?void 0:oi(L[e],n,1)[0]}return ii(L[e])}},t.removeHooks=function(e){vi(L,e)&&(L[e]=[])},t.removeAllHooks=function(){L=sa()},t}var da=ua(),fa=l(h(),1),pa=`kw-vibeable`,ma=`kw-vibe-slot`;function ha(e){window.dispatchEvent(new CustomEvent(pa,{detail:e}))}async function ga(e,t){let n=await A.request(`chats.setVibeable`,{id:e,body:{slug:t}});if(!n.ok)throw Error(M(n));return n.data}function _a({chatId:e,slug:t,agentBusy:n,onClosed:r}){let[i,a]=(0,v.useState)(null),[o,s]=(0,v.useState)(0),[c,l]=(0,v.useState)(``),[u,d]=(0,v.useState)(``),[f,p]=(0,v.useState)(``),[m,h]=(0,v.useState)(!1),g=(0,v.useRef)(null),_=(0,v.useCallback)(async()=>{try{let e=await A.request(`vibeables.get`,{slug:t});if(!e.ok)throw Error(M(e));a(e.data),d(``)}catch(e){d(e.message)}},[t]);(0,v.useEffect)(()=>{_();let e,n=ee.subscribe(`vibeable.${t}`,{},t=>{let n=t;if(n.type===`change`)s(e=>e+1),l(n.files.slice(0,3).join(`, `)+(n.files.length>3?` +${n.files.length-3}`:``)),clearTimeout(e),e=setTimeout(()=>l(``),2500);else if(n.type===`dev`&&n.dev){let e=n.dev;a(t=>t&&{...t,dev:e,mode:e.running?`dev`:`static`})}else n.type===`error`&&d(n.message)});return()=>{n(),clearTimeout(e)}},[t,_]);let y=!!i?.dev?.running;(0,v.useEffect)(()=>{if(!y||!m)return;let e=setInterval(()=>void _(),2e3);return()=>clearInterval(e)},[y,m,_]);let b=i?`${j(i.url)}?v=${o}`:``,x=()=>s(e=>e+1),S=async e=>{p(e),d(``);try{let n=await A.request(e===`start`?`vibeables.devStart`:`vibeables.devStop`,{slug:t});if(!n.ok)throw Error(M(n));a(n.data),e===`start`&&h(!0)}catch(e){d(e.message)}finally{p(``)}},C=async()=>{if(e&&r){p(`close`),d(``);try{r(await ga(e,null))}catch(e){d(e.message),p(``)}}},w=i?.dev,T=w?.running?w.ready?{tone:`ok`,text:`dev :${w.port}`}:{tone:`working`,text:`starting…`}:w&&w.exitCode!==void 0?{tone:`bad`,text:`dev exited${w.exitCode==null?``:` (${w.exitCode})`}`}:{tone:`ok`,text:`static`};return(0,F.jsxs)(`aside`,{className:ya,"data-vibe":t,children:[(0,F.jsxs)(`div`,{className:ba,children:[(0,F.jsx)(I,{name:`web`,className:`text-fg-2`}),(0,F.jsx)(`span`,{className:`truncate text-base font-medium`,title:i?.path,children:t}),(0,F.jsx)(Sa,{tone:T.tone,title:w?.command?`dev: ${w.command}`:i?.dir,children:T.text}),c&&(0,F.jsxs)(`span`,{className:`inline-flex animate-vibe-flash items-center gap-1 text-2xs whitespace-nowrap text-accent`,title:c,children:[(0,F.jsx)(I,{name:`bolt`,className:`ms-sm`}),` reloaded`]}),(0,F.jsx)(`span`,{className:`flex-1`}),i?.config.dev&&(w?.running?(0,F.jsx)(H,{icon:f===`stop`?`progress_activity`:`stop`,label:`stop dev server`,title:`Stop the dev server (${i.config.dev})`,onClick:()=>void S(`stop`),disabled:!!f}):(0,F.jsx)(H,{icon:f===`start`?`progress_activity`:`play_arrow`,label:`start dev server`,title:`Start the dev server: ${i.config.dev}`,className:`text-accent`,onClick:()=>void S(`start`),disabled:!!f})),w&&(0,F.jsx)(H,{icon:`terminal`,label:`dev server output`,title:`Dev server output`,className:m?`bg-accent-soft text-on-accent-soft`:void 0,"aria-pressed":m,onClick:()=>h(e=>!e)}),(0,F.jsx)(H,{icon:`refresh`,label:`reload preview`,title:`Reload the preview`,onClick:x}),(0,F.jsx)(H,{icon:`open_in_new`,label:`open in new tab`,title:`Open in a new tab`,onClick:()=>window.open(i?j(i.url):``,`_blank`,`noopener`),disabled:!i}),e&&r&&(0,F.jsx)(H,{icon:f===`close`?`progress_activity`:`close`,label:`close preview`,title:n?`The agent is working — close the preview when the turn is done`:`Close the preview (the agent returns to the project root)`,onClick:()=>void C(),disabled:!!f||n})]}),(u||i?.configError)&&(0,F.jsxs)(`div`,{className:xa,children:[(0,F.jsx)(`span`,{className:`flex-1`,children:u||i?.configError}),u&&(0,F.jsx)(H,{icon:`close`,label:`dismiss`,size:`sm`,className:`rounded-full text-inherit hover:bg-transparent hover:text-inherit`,onClick:()=>d(``)})]}),i?.config.dev&&!w?.running&&!u&&(0,F.jsxs)(G,{className:`flex-none border-b border-line px-3.5 py-1.5`,children:[`This app has a dev command (`,(0,F.jsx)(`code`,{children:i.config.dev}),`). Showing the static folder until you start it.`]}),b&&(0,F.jsx)(`iframe`,{ref:g,className:`vibeable-frame block min-h-0 w-full flex-1 border-0 bg-white`,src:b,title:`vibeable ${t}`,sandbox:`allow-scripts allow-forms allow-popups allow-modals allow-downloads`,allow:`clipboard-write`}),!b&&!u&&(0,F.jsx)(K,{className:`m-auto`,children:`loading…`}),m&&w&&(0,F.jsx)(`pre`,{className:`m-0 max-h-[180px] flex-none overflow-auto border-t border-line bg-surface-2 px-3.5 py-2 font-mono text-[11.5px] leading-[1.5] break-words whitespace-pre-wrap text-fg-2`,"aria-label":`dev server log`,children:w.log.length?w.log.join(`
79
79
  `):`(no output yet)`})]})}var va=`vibeable-pane flex flex-col overflow-hidden rounded-2xl bg-surface-2`,ya=`${va} min-h-0 min-w-0 flex-1`,ba=`flex min-h-11 flex-none items-center gap-2 border-b border-line py-1.5 pr-2 pl-3.5`,xa=`flex flex-none items-center gap-2.5 bg-bad-soft py-1.5 pr-2 pl-3.5 text-[12.5px] text-on-bad-soft`;function Sa({tone:e,title:t,children:n}){return(0,F.jsxs)(`span`,{className:P(`vibeable-mode inline-flex items-center gap-1.5 rounded-full px-2.5 py-0.5 text-2xs font-medium tracking-[0.02em] whitespace-nowrap`,e===`bad`?`bg-bad-soft text-on-bad-soft`:`bg-surface text-fg-2`),title:t,children:[(0,F.jsx)(U,{tone:e}),n]})}function Ca({chatId:e,slug:t,onClosed:n}){let[r,i]=(0,v.useState)(``);return(0,F.jsxs)(`aside`,{className:P(va,`max-w-[420px] min-w-[320px] flex-none self-start`),"data-vibe":t,children:[(0,F.jsxs)(`div`,{className:ba,children:[(0,F.jsx)(I,{name:`web`,className:`text-fg-2`}),(0,F.jsx)(`span`,{className:`truncate text-base font-medium`,children:t}),(0,F.jsx)(Sa,{tone:`bad`,children:`vibeables are off`}),(0,F.jsx)(`span`,{className:`flex-1`}),(0,F.jsx)(H,{icon:`close`,label:`close preview`,title:`Detach the app from this chat`,onClick:()=>ga(e,null).then(n).catch(e=>i(e.message))})]}),(0,F.jsxs)(G,{className:`flex-none border-b border-line px-3.5 py-1.5`,children:[`This chat has `,(0,F.jsx)(`b`,{children:t}),` open, but vibeables were switched off in `,(0,F.jsx)(`a`,{href:`#/settings`,children:`settings`}),`. Turn them back on to see the preview, or detach the app.`]}),r&&(0,F.jsx)(`div`,{className:xa,children:(0,F.jsx)(`span`,{className:`flex-1`,children:r})})]})}var wa=`kw-vibeable-agent`;async function Ta(e,t){let n=await A.request(`chats.create`,{body:{agent:t,scope:{kind:`general`}}});if(!n.ok)throw Error(M(n));let r=n.data;if(!r.id)throw Error(`HTTP ${n.status}`);await ga(r.id,e),B(`/agents/chats/${r.id}`)}function Ea({slug:e}){let[t,n]=(0,v.useState)(null),[r,i]=(0,v.useState)(``),[a,o]=(0,v.useState)(``),[s,c]=(0,v.useState)(``),[l,u]=(0,v.useState)({}),[d,f]=(0,v.useState)({}),[p,m]=(0,v.useState)(!1),[h,g]=(0,v.useState)(()=>{try{let e=localStorage.getItem(wa);return e===`codex`||e===`pi`?e:`claude`}catch{return`claude`}}),_=be(),y=(0,v.useCallback)(async()=>{try{let e=await A.request(`vibeables.list`);if(!e.ok)throw Error(`HTTP ${e.status}`);n(e.data),i(``)}catch(e){i(e.message||`could not load the apps`)}},[]);(0,v.useEffect)(()=>{let e=!0,t,n=async()=>{await y(),e&&(t=setTimeout(n,15e3))};return n(),()=>{e=!1,clearTimeout(t)}},[y]);let b=[...t?.vibeables??[]].sort((e,t)=>(t.updatedAt??``).localeCompare(e.updatedAt??``)),x=s.trim().toLowerCase(),S=x?b.filter(e=>e.slug.toLowerCase().includes(x)):b,C=e===`new`,w=e&&!C?b.find(t=>t.slug===e):void 0;(0,v.useEffect)(()=>{y()},[e,y]);let T=b[0]?.slug;(0,v.useEffect)(()=>{!e&&T&&B(`/vibeables/${encodeURIComponent(T)}`,{replace:!0})},[e,T]);let E=(e,t)=>u(n=>({...n,[e]:t})),D=e=>u(t=>{let n={...t};return delete n[e],n}),O=(e,t)=>f(n=>({...n,[e]:t.message})),k=async e=>{e.preventDefault();let t=a.trim();if(t&&!l.__new){E(`__new`,`create`),f(e=>({...e,__new:``}));try{let e=await A.request(`vibeables.create`,{body:{name:t}});if(!e.ok)throw Error(M(e));let n=e.data;o(``),await y(),B(`/vibeables/${encodeURIComponent(n.slug??t)}`)}catch(e){O(`__new`,e)}finally{D(`__new`)}}},j=async e=>{E(e,`open`);try{await Ta(e,h)}catch(t){O(e,t),D(e)}},ee=async e=>{E(e,`remove`),m(!1);try{let t=await A.request(`vibeables.delete`,{slug:e});if(!t.ok)throw Error(t.error||`failed`);await y(),B(`/vibeables`,{replace:!0})}catch(t){O(e,t),y()}finally{D(e)}},N=e=>{g(e);try{localStorage.setItem(wa,e)}catch{}},P=e=>e.configError?{label:`config error`,tone:`bad`}:e.hasIndex?{label:e.dev?`dev`:`static`,tone:`ok`}:{label:`no index.html yet`,tone:`idle`},te;if(t&&!t.enabled)te=(0,F.jsx)(K,{children:t.error&&!/are off/.test(t.error)?(0,F.jsx)(q,{tone:`bad`,children:t.error}):(0,F.jsxs)(F.Fragment,{children:[`Apps are off. Turn them on in `,(0,F.jsx)(`a`,{href:`#/settings`,children:`settings`}),` or add a `,(0,F.jsx)(`code`,{children:`vibeables:`}),` block to kraftwerk.yml.`]})});else if(!t)te=(0,F.jsx)(K,{children:`loading…`});else if(C||b.length===0)te=(0,F.jsxs)(`form`,{className:`mx-auto flex w-full max-w-[560px] flex-col gap-2.5 px-4 py-10`,onSubmit:e=>void k(e),children:[(0,F.jsxs)(`div`,{className:`flex gap-2.5`,children:[(0,F.jsx)(X,{className:`flex-1 font-mono text-sm`,value:a,placeholder:`e.g. team-dashboard`,"aria-label":`new app name`,onChange:e=>o(e.target.value),autoFocus:!0}),(0,F.jsx)(V,{type:`submit`,variant:`primary`,icon:`add`,busy:!!l.__new,disabled:!a.trim(),children:l.__new?`creating…`:`new app`})]}),d.__new&&(0,F.jsx)(q,{tone:`bad`,children:d.__new}),(0,F.jsxs)(`p`,{className:`m-0 text-xs text-fg-2`,children:[`A small app built live with an agent. One folder each under `,(0,F.jsx)(`code`,{title:t.root,children:t.root}),`; part of the workspace, commit it from the git screen.`]})]});else if(e&&!w)te=(0,F.jsxs)(K,{children:[`no vibeable named `,e]});else if(w){let e=w,t=P(e),n=l[e.slug];te=(0,F.jsxs)(`div`,{className:`chat-main gap-3`,children:[(0,F.jsxs)(`div`,{className:`flex flex-none flex-wrap items-center gap-x-4 gap-y-2.5`,children:[(0,F.jsx)(U,{tone:t.tone}),(0,F.jsx)(nt,{children:e.slug}),(0,F.jsx)(W,{tone:t.tone===`bad`?`bad`:t.tone===`ok`?`ok`:`neutral`,children:t.label}),e.updatedAt&&(0,F.jsxs)(`span`,{className:`text-xs text-fg-2`,title:e.updatedAt,children:[`changed `,Ge(e.updatedAt)]}),_&&(0,F.jsx)(`span`,{className:`max-w-[40ch] truncate font-mono text-xs text-fg-2`,title:e.path,children:e.path}),(0,F.jsx)(`span`,{className:`flex-1`}),(0,F.jsxs)(_t,{className:`h-8 w-auto text-sm`,value:h,onChange:e=>N(e.target.value),"aria-label":`agent for new chats`,children:[(0,F.jsx)(`option`,{value:`claude`,children:`claude`}),(0,F.jsx)(`option`,{value:`codex`,children:`codex`}),(0,F.jsx)(`option`,{value:`pi`,children:`pi`})]}),(0,F.jsx)(V,{variant:`primary`,icon:`chat`,busy:n===`open`,disabled:!!n,onClick:()=>void j(e.slug),title:`Start a ${h} chat with this app in the preview pane`,children:`open in chat`}),p?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(V,{variant:`danger`,icon:`delete`,onClick:()=>void ee(e.slug),children:`confirm remove`}),(0,F.jsx)(V,{variant:`quiet`,onClick:()=>m(!1),children:`cancel`})]}):(0,F.jsx)(V,{variant:`danger`,icon:`delete`,disabled:!!n,onClick:()=>m(!0),title:`Move the folder to the trash`,children:`remove`})]}),(e.configError||d[e.slug])&&(0,F.jsx)(q,{tone:`bad`,children:e.configError||d[e.slug]}),(0,F.jsx)(_a,{slug:e.slug},e.slug)]})}else te=(0,F.jsx)(K,{children:`loading…`});return(0,F.jsxs)(`div`,{className:`runs-screen vibeables-screen`,children:[(0,F.jsxs)(`aside`,{className:`runs-side`,children:[(0,F.jsx)(wt,{title:`apps`,count:t?.enabled?b.length:void 0,action:t?.enabled&&(0,F.jsx)(V,{size:`sm`,variant:`quiet`,icon:`add`,href:`/vibeables/new`,children:`new`})}),(0,F.jsx)(Tt,{icon:`filter_list`,value:s,placeholder:`search apps`,"aria-label":`search apps`,onChange:e=>c(e.target.value)}),(0,F.jsxs)(Et,{children:[S.map(t=>{let n=P(t);return(0,F.jsx)(`div`,{className:`vibeable-row`,"data-vibeable":t.slug,children:(0,F.jsx)(Y,{href:`/vibeables/${encodeURIComponent(t.slug)}`,active:t.slug===e,size:`sm`,leading:(0,F.jsx)(U,{tone:n.tone}),title:t.slug,sub:`${n.label}${t.dev?` · ${t.dev}`:``}`,meta:t.updatedAt&&(0,F.jsx)(`span`,{title:t.updatedAt,children:Ge(t.updatedAt)})})},t.slug)}),t&&b.length===0&&(0,F.jsx)(Dt,{children:`nothing built yet`}),t&&b.length>0&&S.length===0&&(0,F.jsx)(Dt,{children:`no vibeable matches`}),r&&(0,F.jsx)(q,{tone:`bad`,children:r})]})]}),(0,F.jsx)(`div`,{className:`runs-main`,children:te})]})}function Da({slug:e}){let t=N(`channels.list`,{},{interval:4e3}),n=N(`agents.list`,{},{interval:15e3}),r=e?t?.channels.find(t=>t.slug===e):void 0;return e?t?r?(0,F.jsx)(ja,{channel:r,agents:n?.agents??[]},r.slug):(0,F.jsx)(K,{icon:`forum`,children:`channel not found`}):(0,F.jsx)(K,{children:`loading…`}):(0,F.jsx)(ja,{agents:n?.agents??[]})}function Oa({seg:e}){let t=e[0]&&e[0]!==`new`?decodeURIComponent(e[0]):void 0,n=e[0]===`new`?`new`:t&&e[1]===`edit`?`edit`:t?`channel`:`home`,r=N(`channels.list`,{},{interval:4e3}),i=N(`agents.list`,{},{interval:15e3}),a=r?.channels??[],o=t?a.find(e=>e.slug===t):void 0,s=a.reduce((e,t)=>!e||t.updatedAt>e.updatedAt?t:e,void 0);(0,v.useEffect)(()=>{n===`home`&&s&&B(`/channels/${encodeURIComponent(s.slug)}`,{replace:!0})},[n,s?.slug]);let c;return c=n===`new`?(0,F.jsx)(ja,{agents:i?.agents??[]}):n===`edit`&&o?(0,F.jsx)(ja,{channel:o,agents:i?.agents??[]},o.slug):n===`channel`&&o?(0,F.jsx)(`div`,{className:`chat-main`,children:(0,F.jsx)(jo,{id:o.chatId,channel:o,agents:i?.agents??[]},o.chatId)}):n===`channel`&&r?(0,F.jsx)(K,{icon:`forum`,children:`channel not found`}):n===`channel`||!r||s?(0,F.jsx)(K,{children:`loading…`}):(0,F.jsx)(ka,{}),(0,F.jsxs)(`div`,{className:`runs-screen channels-screen`,children:[(0,F.jsxs)(`aside`,{className:`runs-side`,children:[(0,F.jsx)(wt,{title:`channels`,action:(0,F.jsx)(V,{size:`sm`,variant:`quiet`,icon:`add`,href:`/channels/new`,children:`new`})}),(0,F.jsxs)(Et,{children:[a.map(e=>(0,F.jsx)(Y,{href:`/channels/${encodeURIComponent(e.slug)}`,active:e.slug===t,size:`sm`,leading:(0,F.jsx)(U,{tone:e.awaitingApproval?`bad`:e.busy?`working`:`idle`,title:e.awaitingApproval?`waiting for your approval`:e.busy?`an agent is working`:void 0}),title:`#${e.slug}`,sub:`${e.name}${e.project?` · 📁 ${e.project}`:``}${e.members.length?` · ${e.members.map(e=>`@${e}`).join(` `)}`:``}`,meta:We(e.updatedAt)},e.slug)),r&&a.length===0&&(0,F.jsx)(Dt,{children:`no channels yet — create one, or add a coworker to an agent session or a project chat`})]})]}),(0,F.jsx)(`div`,{className:`runs-main`,children:c})]})}function ka(){return(0,F.jsx)(K,{className:`m-auto`,action:(0,F.jsx)(V,{variant:`primary`,icon:`add`,href:`/channels/new`,children:`new channel`}),children:null})}function Aa({agents:e,checked:t,onToggle:n,none:r}){return(0,F.jsxs)(`div`,{className:`flex flex-col gap-0.5 rounded-control border border-line p-1`,children:[e.map(e=>(0,F.jsx)(bt,{checked:t.includes(e.slug),onChange:t=>n(e.slug,t),hint:`@${e.slug}${e.description?` · ${e.description}`:``}`,className:P(`rounded-control px-2.5 py-1.5 transition-colors hover:bg-surface-2`,t.includes(e.slug)&&`bg-surface-2`),children:(0,F.jsxs)(`b`,{className:`font-semibold`,children:[e.emoji,` `,e.name]})},e.slug)),e.length===0&&(0,F.jsx)(K,{className:`py-4`,children:r})]})}function ja({channel:e,agents:t}){let[n,r]=(0,v.useState)(e?.name??``),[i,a]=(0,v.useState)(e?.purpose??``),[o,s]=(0,v.useState)(e?.members??[]),[c,l]=(0,v.useState)(e?.responder??``),[u,d]=(0,v.useState)(!1),[f,p]=(0,v.useState)(``),m=t.filter(e=>!e.archived);function h(e,t){s(n=>t?[...n.filter(t=>t!==e),e]:n.filter(t=>t!==e)),!t&&c===e&&l(``)}async function g(){d(!0),p(``);try{let t={name:n,purpose:i,members:o,responder:c||null},r=e?await A.request(`channels.save`,{slug:e.slug,body:t}):await A.request(`channels.create`,{body:t});if(!r.ok)throw Error(M(r));B(`/channels/${encodeURIComponent(r.data.slug)}`)}catch(e){p(e.message)}d(!1)}async function _(){e&&window.confirm(`Move #${e.slug} and its transcript to the trash?`)&&(await A.request(`channels.delete`,{slug:e.slug}).catch(()=>{}),B(`/channels`))}return(0,F.jsx)(it,{width:`narrow`,children:(0,F.jsx)(J,{title:e?`edit #${e.slug}`:`new channel`,actions:e&&(0,F.jsx)(V,{size:`sm`,variant:`danger`,icon:`delete`,onClick:()=>void _(),children:`delete`}),children:(0,F.jsxs)(`div`,{className:`flex flex-col gap-4 p-[18px]`,children:[(0,F.jsx)(Z,{label:`name`,children:(0,F.jsx)(X,{value:n,placeholder:`e.g. Website relaunch`,onChange:e=>r(e.target.value),autoFocus:!0})}),(0,F.jsx)(Z,{label:`purpose — one line the agents read`,children:(0,F.jsx)(X,{value:i,placeholder:`what this channel is for`,onChange:e=>a(e.target.value)})}),(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(`span`,{className:`text-sm font-semibold text-fg`,children:`members — agents in this channel`}),(0,F.jsx)(Aa,{agents:m,checked:o,onToggle:h,none:`no agents yet — create one on the agents screen first`})]}),(0,F.jsx)(Z,{label:`responder — answers when a message mentions nobody`,children:(0,F.jsxs)(_t,{value:c,onChange:e=>l(e.target.value),children:[(0,F.jsx)(`option`,{value:``,children:`nobody (agents only answer when @mentioned)`}),o.map(e=>(0,F.jsxs)(`option`,{value:e,children:[`@`,e]},e))]})}),f&&(0,F.jsx)(q,{tone:`bad`,children:f}),(0,F.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,F.jsx)(V,{variant:`primary`,busy:u,disabled:!n.trim()||o.length===0,onClick:()=>void g(),children:u?`saving…`:e?`save`:`create channel`}),(0,F.jsx)(V,{variant:`quiet`,href:e?`/channels/${encodeURIComponent(e.slug)}`:`/channels`,children:`cancel`})]})]})})})}function Ma({chatId:e,agentSlug:t,project:n,title:r,onClose:i,onCreated:a}){let[o,s]=(0,v.useState)([]),[c,l]=(0,v.useState)(r||``),[u,d]=(0,v.useState)([]),[f,p]=(0,v.useState)(!1),[m,h]=(0,v.useState)(``);(0,v.useEffect)(()=>{A.call(`agents.list`).then(e=>s(e.agents.filter(e=>!e.archived&&e.slug!==t))).catch(()=>{})},[t]);async function g(){p(!0),h(``);try{let n=await A.request(`channels.fromChat`,{body:{chatId:e,name:c,members:t?[t,...u]:u,responder:t??u[0]}});if(!n.ok)throw Error(M(n));let r=n.data;if(!r.slug)throw Error(`HTTP ${n.status}`);i(),a?a(r.slug):B(`/channels/${encodeURIComponent(r.slug)}`)}catch(e){h(e.message)}p(!1)}return(0,F.jsx)(`div`,{className:`fixed inset-0 z-40 grid animate-fade place-items-center bg-[color-mix(in_srgb,var(--text)_32%,transparent)] p-6`,onMouseDown:e=>e.target===e.currentTarget&&i(),children:(0,F.jsxs)(`div`,{className:`max-h-[calc(100dvh-48px)] w-[min(560px,100%)] animate-rise overflow-y-auto rounded-card border border-line bg-surface shadow-modal`,role:`dialog`,"aria-label":`Add a coworker`,children:[(0,F.jsxs)(`div`,{className:`flex min-h-12 items-center gap-2 border-b border-line px-[18px] py-2`,children:[(0,F.jsx)(et,{className:`text-fg`,children:`add a coworker`}),(0,F.jsx)(`span`,{className:`flex-1`}),(0,F.jsx)(H,{icon:`close`,label:`close`,size:`sm`,onClick:i})]}),(0,F.jsxs)(`div`,{className:`flex flex-col gap-4 p-[18px]`,children:[(0,F.jsx)(`p`,{className:`m-0 text-sm text-fg-2`,children:t?(0,F.jsxs)(F.Fragment,{children:[`This session becomes a channel: @`,t,` stays and keeps its memory, the agents you pick join, and everyone reads the same transcript. @`,t,` answers when nobody is mentioned.`]}):(0,F.jsxs)(F.Fragment,{children:[`This chat becomes a channel session of the project `,(0,F.jsx)(`b`,{className:`text-fg`,children:n}),` and stays here: the agents you pick join with everything said so far and the project's brief, state, records and links. The first one you pick answers when nobody is mentioned.`]})}),(0,F.jsx)(Z,{label:`channel name`,children:(0,F.jsx)(X,{value:c,placeholder:`e.g. Website relaunch`,onChange:e=>l(e.target.value),autoFocus:!0})}),(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(`span`,{className:`text-sm font-semibold text-fg`,children:`invite`}),(0,F.jsx)(Aa,{agents:o,checked:u,onToggle:(e,t)=>d(n=>t?[...n,e]:n.filter(t=>t!==e)),none:`no other agents to invite yet`})]}),m&&(0,F.jsx)(q,{tone:`bad`,children:m}),(0,F.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,F.jsx)(V,{variant:`primary`,busy:f,disabled:!c.trim()||u.length===0,onClick:()=>void g(),children:f?`creating…`:`create channel`}),(0,F.jsx)(V,{variant:`quiet`,onClick:i,children:`cancel`})]})]})]})})}var Na=`kw-sessions-list`,Pa=(()=>{try{return localStorage.getItem(Na)===`open`}catch{return!1}})(),Fa=new Set;function Ia(e){Pa=e;try{localStorage.setItem(Na,e?`open`:`hidden`)}catch{}Fa.forEach(e=>e())}function La({busy:e,onClick:t,href:n}){return(0,F.jsx)(H,{icon:e?`progress_activity`:`add`,label:`new chat`,size:`sm`,className:`mb-1 ml-1 rounded-full`,disabled:e,onClick:t,href:n})}function Ra(){return(0,v.useSyncExternalStore)(e=>(Fa.add(e),()=>Fa.delete(e)),()=>Pa)}var za=e=>`kw-tabs:${e}`,Ba=e=>{try{let t=JSON.parse(localStorage.getItem(za(e))??`[]`);return Array.isArray(t)?t.filter(e=>typeof e==`string`):[]}catch{return[]}},Va=(e,t)=>{try{localStorage.setItem(za(e),JSON.stringify(t))}catch{}};function Ha({name:e,onDone:t}){let[n,r]=(0,v.useState)(e),i=n.replace(/\s+/g,` `).trim().slice(0,80);return(0,F.jsx)(`input`,{autoFocus:!0,value:n,"aria-label":`chat name`,maxLength:80,className:`-mb-px w-[220px] flex-none self-end rounded-t-[10px] border border-b-0 border-accent bg-surface px-3 py-[7px] font-[inherit] text-sm font-medium text-fg outline-none`,onFocus:e=>e.currentTarget.select(),onChange:e=>r(e.target.value),onKeyDown:n=>{n.key===`Enter`&&t(i&&i!==e?i:void 0),n.key===`Escape`&&t()},onBlur:()=>t(i&&i!==e?i:void 0)})}var Ua=`kw-strip-end`;function Wa({children:e}){let[t,n]=(0,v.useState)(null);return(0,v.useEffect)(()=>{let e=document.getElementById(Ua);e!==t&&n(e)}),t?(0,fa.createPortal)(e,t):null}function Ga({storeKey:e,label:t,fallbackTitle:n,chatId:r,filter:i,hrefOf:a,closeHref:o,subOf:s,actions:c}){let l=N(`chats.list`,{},{refresh:r}),u=(0,v.useMemo)(()=>i(l?.chats??[]),[l,i]),d=(0,v.useMemo)(()=>new Map(u.map(e=>[e.id,e])),[u]),f=Ra(),[p,m]=(0,v.useState)(()=>Ba(e)),[h,g]=(0,v.useState)(!1),_=t=>{m(t),Va(e,t)};(0,v.useEffect)(()=>{r&&!p.includes(r)&&_([...p,r])},[r]),(0,v.useEffect)(()=>{if(!l)return;let e=p.filter(e=>d.has(e));e.length!==p.length&&_(e)},[l]);let y=e=>{let t=p.indexOf(e),n=p.filter(t=>t!==e);if(_(n),e!==r)return;let i=d.get(n[Math.min(Math.max(t,0),n.length-1)]??``);B(i?a(i):o)},b=async e=>{window.confirm(`Delete ${t===`chats`?`chat`:`session`} "${e.title||e.id}"?`)&&(await A.request(`chats.delete`,{id:e.id}).catch(()=>{}),p.includes(e.id)&&y(e.id))},[x,S]=(0,v.useState)(null),C=async(e,t)=>{S(null),await A.request(`chats.rename`,{id:e,body:{title:t}}).catch(()=>null)},w=l?p.filter(e=>d.has(e)):[],T=e=>e.scope.kind===`channel`?e.title||`#${e.scope.slug}`:e.title||n;return(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(`nav`,{className:`order-first col-span-full flex min-w-0 items-end gap-1 border-b border-line bg-surface-2 pt-1.5 pr-2 pl-1.5`,"aria-label":`open chats`,children:[(0,F.jsxs)(`button`,{type:`button`,className:P(`mb-1 inline-flex flex-none cursor-pointer items-center gap-1 self-center rounded-control px-2 py-1 text-2xs transition-colors`,f?`bg-accent-soft text-on-accent-soft`:`text-fg-2 hover:bg-surface hover:text-fg`),onClick:()=>Ia(!f),title:f?`hide the ${t} list`:`show all ${t}`,"aria-label":`${t} list`,"aria-pressed":f,children:[(0,F.jsx)(I,{name:`view_list`,className:`ms-sm`}),l&&(0,F.jsx)(`span`,{className:`tabular-nums`,children:u.length})]}),(0,F.jsxs)(`div`,{className:`flex min-w-0 items-center gap-0.5 overflow-x-auto [scrollbar-width:none]`,role:`tablist`,children:[w.map(e=>{let t=d.get(e),n=e===r;return x===e?(0,F.jsx)(Ha,{name:T(t),onDone:t=>t?void C(e,t):S(null)},e):(0,F.jsxs)(he,{href:a(t),className:P(`session-tab group/tab -mb-px inline-flex max-w-[220px] min-w-0 flex-none animate-tab-in items-center gap-1.5 self-end`,`rounded-t-[10px] border border-b-0 py-[7px] pr-1.5 pl-3 text-sm font-medium no-underline transition-colors`,n?`border-line bg-surface text-fg`:`border-transparent text-fg-2 hover:bg-surface`),role:`tab`,"aria-selected":n,title:`${T(t)} · double-click to rename`,onDoubleClick:t=>{t.preventDefault(),S(e)},children:[(t.busy||t.awaitingApproval)&&(0,F.jsx)(U,{tone:t.awaitingApproval?`bad`:`working`,title:t.awaitingApproval?`waiting for your approval`:`working`}),t.scope.kind===`channel`&&(0,F.jsx)(I,{name:`forum`,className:`ms-sm text-fg-2`}),(0,F.jsx)(`span`,{className:`truncate`,children:T(t)}),n&&(0,F.jsx)(`button`,{type:`button`,className:`inline-flex flex-none cursor-pointer rounded-md p-0.5 text-fg-2 opacity-0 transition-opacity group-hover/tab:opacity-100 hover:bg-surface-2 hover:text-fg focus-visible:opacity-100 pointer-coarse:opacity-100`,"aria-label":`rename ${T(t)}`,title:`rename`,onClick:t=>{t.preventDefault(),t.stopPropagation(),S(e)},children:(0,F.jsx)(I,{name:`edit`,className:`ms-sm`})}),(0,F.jsx)(`button`,{type:`button`,className:P(`inline-flex flex-none cursor-pointer rounded-md p-0.5 text-fg-2 transition-opacity hover:bg-surface-2 hover:text-fg focus-visible:opacity-100`,n?`opacity-100`:`opacity-0 group-hover/tab:opacity-100`),"aria-label":`close ${T(t)}`,title:`close tab`,onClick:t=>{t.preventDefault(),t.stopPropagation(),y(e)},children:(0,F.jsx)(I,{name:`close`,className:`ms-sm`})})]},e)}),c]}),(0,F.jsx)(`span`,{className:`flex-1`}),(0,F.jsx)(`span`,{id:Ua,className:`mb-1 flex flex-none items-center gap-0.5 self-center`})]}),f&&(0,F.jsxs)(`aside`,{className:`runs-side sessions-side animate-slide-left`,children:[(0,F.jsx)(wt,{title:t,action:(0,F.jsx)(H,{icon:`close`,label:`hide the list`,size:`sm`,onClick:()=>Ia(!1)})}),(0,F.jsxs)(Et,{children:[u.map(e=>(0,F.jsx)(Y,{href:a(e),active:e.id===r,size:`sm`,leading:(0,F.jsx)(U,{tone:e.awaitingApproval?`bad`:e.busy?`working`:`idle`,title:e.awaitingApproval?`waiting for your approval`:void 0}),title:(0,F.jsxs)(F.Fragment,{children:[e.scope.kind===`channel`&&(0,F.jsx)(I,{name:`forum`,className:`ms-sm mr-1 align-[-3px]`}),T(e)]}),sub:(0,F.jsxs)(F.Fragment,{children:[s&&(0,F.jsxs)(F.Fragment,{children:[s(e),` · `]}),(0,F.jsx)(`span`,{className:`tabular-nums`,children:We(e.updatedAt)})]}),actions:(0,F.jsx)(H,{icon:`close`,size:`sm`,label:t===`chats`?`delete chat`:`delete session`,disabled:h,onClick:()=>{g(!0),b(e).finally(()=>g(!1))}})},e.id)),l&&u.length===0&&(0,F.jsxs)(Dt,{children:[`no `,t,` yet`]})]})]})]})}var Ka=`kw-me`;function qa(){try{return localStorage.getItem(Ka)||``}catch{return``}}function Ja(e){try{localStorage.setItem(Ka,e)}catch{}}function Ya(e,t){A.request(`chats.cancel`,{id:e,body:t?{agent:t}:{}}).catch(()=>{})}var Xa=(e,t=90)=>{let n=e.replace(/\s+/g,` `).trim();return n.length>t?`${n.slice(0,t)}…`:n};function Za(e,t){let n=RegExp(`(^|[^a-z0-9-])@${t.replace(/[.*+?^${}()|[\\]\\]/g,`\\$&`)}(?![a-z0-9-])`,`i`),r,i,a=!1,o=``;for(let s of e){if(s.from?.kind!==`agent`||s.from.slug!==t){(s.type===`user_message`||s.type===`text`)&&n.test(s.text)&&(r=Xa(s.text));continue}switch(s.type){case`turn_start`:a=!0,i=void 0,o=``;break;case`turn_end`:case`error`:a=!1;break;case`tool_call`:a&&(i=Xa(`${s.kind&&s.kind!==`other`?`${s.kind}: `:``}${s.title}`));break;case`text`:a&&(o+=s.text,(!i||i.startsWith(`says: `))&&(i=Xa(`says: ${o}`)))}}return{task:r,now:i}}function Qa(e,t){let n=e=>!t&&!e||t?.kind===`agent`&&e?.kind===`agent`&&e.slug===t.slug,r=null,i,a=[],o=[],s;for(let t of e)n(t.from)&&(t.type===`plan`?r=t.entries:t.type===`usage`?i={used:t.used,size:t.size,costUsd:t.costUsd}:t.type===`commands`?a=t.commands:t.type===`config`?o=t.options:t.type===`auth`&&(s=t));return{plan:r,usage:i,commands:a,config:o,auth:s}}var $a=(0,v.createContext)(()=>`The agent`),eo=()=>(0,v.useContext)($a);function to(e){let t=new Map;for(let n of e)(n.type===`permission_request`||n.type===`elicitation_request`)&&t.set(n.requestId,n.from??null),(n.type===`permission_resolved`||n.type===`elicitation_resolved`)&&t.delete(n.requestId);return t.size?[...t.values()][0]:void 0}function no(e,t,n){if(e.kind===`agent`){let r=t.find(t=>t.slug===e.slug);return r?`${r.emoji?`${r.emoji} `:``}${r.name}`:n??e.slug}return e.kind===`general`||e.kind===`kraftwerk`?`🎩 Ralv`:e.kind===`project`?`${ze.emoji} ${ze.name}`:`The assistant`}var ro=`kw-browse`;function io(e){window.dispatchEvent(new CustomEvent(ro,{detail:e}))}function ao(e){if(!/<a\s/i.test(e))return e;let t=document.createElement(`template`);t.innerHTML=e;for(let e of t.content.querySelectorAll(`a[href^="http://"], a[href^="https://"]`)){if(e.classList.contains(`md-browse`))continue;let t=document.createElement(`a`);t.className=`md-browse ml-0.5 inline-grid size-[18px] place-items-center rounded-[5px] align-[-3px] text-fg-2 no-underline opacity-55 transition hover:bg-surface-2 hover:text-accent hover:opacity-100 [&_.ms]:align-[0] [&_.ms]:text-[14px]`,t.href=e.getAttribute(`href`)??``,t.title=`Open beside the conversation`,t.setAttribute(`aria-label`,`Open beside the conversation`),t.innerHTML=`<span class="ms material-symbols-rounded ms-sm" aria-hidden="true">open_in_new</span>`,e.after(t)}return t.innerHTML}function oo(e){let t=e.target.closest?.(`a.md-browse`);t&&(e.metaKey||e.ctrlKey||e.shiftKey||e.button!==0||(e.preventDefault(),io(t.href)))}var so=`kw-browser-tabs`;function co(e){try{return new URL(e).host.replace(/^www\./,``)}catch{return e}}function lo(e){let t=e.trim();return t?/^[a-z]+:\/\//i.test(t)?t:`https://${t}`:``}function uo({storeKey:e,onTabs:t}){let n=`${so}:${e}`,[r,i]=(0,v.useState)(()=>{try{let e=JSON.parse(sessionStorage.getItem(n)??`[]`);return Array.isArray(e)?e.filter(e=>typeof e.url==`string`&&typeof e.id==`number`):[]}catch{return[]}}),[a,o]=(0,v.useState)(()=>r[0]?.id??null),[s,c]=(0,v.useState)(``),[l,u]=(0,v.useState)({}),d=(0,v.useRef)(Math.max(0,...r.map(e=>e.id))+1);(0,v.useEffect)(()=>{try{sessionStorage.setItem(n,JSON.stringify(r))}catch{}t?.(r.length)},[r,t,n]);let f=e=>{i(t=>{let n=t.find(t=>t.url===e);if(n)return o(n.id),t;let r={id:d.current++,url:e};return o(r.id),[...t,r]})};(0,v.useEffect)(()=>{let e=e=>f(e.detail);return window.addEventListener(ro,e),()=>window.removeEventListener(ro,e)},[]);let p=r.find(e=>e.id===a)??null;(0,v.useEffect)(()=>c(p?.url??``),[p?.url]);let m=e=>{i(t=>{let n=t.findIndex(t=>t.id===e),r=t.filter(t=>t.id!==e);return a===e&&o(r[Math.min(n,r.length-1)]?.id??null),r})},h=()=>{let e=lo(s);e&&(p?i(t=>t.map(t=>t.id===p.id?{...t,url:e}:t)):f(e))},g=`grid size-[30px] flex-none place-items-center rounded-full text-fg-2 no-underline transition-colors hover:bg-surface hover:text-fg`;return(0,F.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden rounded-card border border-line bg-surface`,children:[(0,F.jsxs)(`div`,{className:`flex flex-none items-center gap-0.5 overflow-x-auto px-1.5 pt-1.5 [scrollbar-width:none]`,role:`tablist`,"aria-label":`Browser tabs`,children:[r.map(e=>(0,F.jsxs)(`div`,{className:P(`flex max-w-[180px] items-center rounded-t-lg`,e.id===a?`bg-surface-2 text-fg`:`text-fg-2`),children:[(0,F.jsx)(`button`,{role:`tab`,"aria-selected":e.id===a,className:`min-w-0 cursor-pointer truncate border-0 bg-transparent py-1.5 pr-1 pl-2.5 text-[12.5px] font-semibold text-inherit`,title:e.url,onClick:()=>o(e.id),children:co(e.url)}),(0,F.jsx)(H,{icon:`close`,label:`Close ${co(e.url)}`,className:`size-6 text-inherit`,onClick:()=>m(e.id)})]},e.id)),(0,F.jsx)(H,{icon:`add`,label:`New tab`,className:`ml-1 size-6`,onClick:()=>{o(null),c(``)}})]}),(0,F.jsxs)(`form`,{className:`flex flex-none items-center gap-1 border-y border-line bg-surface-2 px-2 py-1.5`,onSubmit:e=>{e.preventDefault(),h()},children:[(0,F.jsx)(`button`,{type:`button`,className:P(g,`cursor-pointer border-0 bg-transparent disabled:pointer-events-none disabled:opacity-40`),title:`Reload`,"aria-label":`Reload`,disabled:!p,onClick:()=>p&&u(e=>({...e,[p.id]:(e[p.id]??0)+1})),children:(0,F.jsx)(I,{name:`refresh`})}),(0,F.jsx)(`input`,{className:`h-[30px] min-w-0 flex-1 rounded-full border border-line bg-surface px-3 font-sans text-[13px] text-fg focus:border-fg focus:outline-none`,value:s,placeholder:`https://…`,"aria-label":`Address`,spellCheck:!1,onChange:e=>c(e.target.value)}),(0,F.jsx)(`button`,{type:`submit`,className:P(g,`cursor-pointer border-0 bg-transparent`),title:`Go`,"aria-label":`Go`,children:(0,F.jsx)(I,{name:`arrow_forward`})}),(0,F.jsx)(`a`,{className:P(g,!p&&`pointer-events-none opacity-40`),href:p?.url,target:`_blank`,rel:`noopener noreferrer`,title:`Open in a window`,"aria-label":`Open in a window`,children:(0,F.jsx)(I,{name:`open_in_new`})})]}),(0,F.jsxs)(`div`,{className:`relative min-h-0 flex-1 bg-white`,children:[r.map(e=>(0,F.jsx)(`iframe`,{className:`block size-full border-0 bg-white [&[hidden]]:hidden`,src:e.url,title:co(e.url),hidden:e.id!==a,sandbox:`allow-scripts allow-forms allow-popups allow-same-origin allow-downloads`,referrerPolicy:`no-referrer-when-downgrade`},`${e.id}:${l[e.id]??0}`)),!p&&(0,F.jsxs)(`div`,{className:`absolute inset-0 grid place-content-center justify-items-center gap-2 bg-surface p-6 text-center text-fg-2`,children:[(0,F.jsx)(I,{name:`public`,className:`text-[32px]`}),(0,F.jsxs)(`p`,{className:`m-0 max-w-[36ch] text-[13.5px]`,children:[`Read a page beside the conversation: type an address, or click the `,(0,F.jsx)(I,{name:`open_in_new`,className:`ms-sm align-[-3px]`}),` next to a link in the chat.`]})]})]})]})}var fo=(e,t)=>!e&&!t||!!e&&!!t&&e.kind===t.kind&&(e.kind===`human`?e.name===t.name:e.slug===t.slug);function po(e){let t=[],n=new Map,r=new Map,i=new Map,a=new Map,o=new Map,s=new Map,c,l;for(let u of e){let e=`subagent`in u&&u.subagent?r.get(u.subagent):void 0,d=e?e.children:t,f=d[d.length-1];switch(u.type){case`user_message`:c=u.text,d.push({kind:`user`,text:u.text,steered:u.steered,attachments:u.attachments,key:`e${u.seq}`,from:u.from});break;case`text`:f?.kind===`agent`&&fo(f.from,u.from)?f.text+=u.text:d.push({kind:`agent`,text:u.text,key:`e${u.seq}`,from:u.from});break;case`thought`:f?.kind===`thought`&&fo(f.from,u.from)?f.text+=u.text:d.push({kind:`thought`,text:u.text,key:`e${u.seq}`,from:u.from});break;case`tool_call`:{let e={kind:`tool`,callId:u.callId,title:u.title,toolKind:u.kind,status:u.status,compaction:u.compaction,key:`e${u.seq}`,from:u.from};n.set(u.callId,e),d.push(e);break}case`tool_update`:{let e=n.get(u.callId);e&&(u.title&&(e.title=u.title),u.status&&(e.status=u.status),u.compaction&&(e.compaction={...e.compaction,...u.compaction}));break}case`subagent`:{let e={kind:`subagent`,sessionId:u.sessionId,name:u.name,task:u.task,children:[],key:`e${u.seq}`,from:u.from};r.set(u.sessionId,e),t.push(e);break}case`subagent_state`:{let e=r.get(u.sessionId);e&&(e.state=u.state);break}case`task`:{let e={kind:`task`,taskId:u.taskId,name:u.name,taskType:u.taskType,description:u.description,canStop:u.canStop,state:`running`,key:`e${u.seq}`,from:u.from};i.set(u.taskId,e),d.push(e);break}case`task_update`:{let e=i.get(u.taskId);e&&(u.description&&(e.description=u.description),u.summary&&(e.summary=u.summary),u.state&&(e.state=u.state));break}case`permission_request`:s.set(u.requestId,d.length),d.push({kind:`permission`,requestId:u.requestId,title:u.title,options:u.options,resolved:void 0,key:`e${u.seq}`,from:u.from});break;case`permission_resolved`:{let e=s.get(u.requestId);e!=null&&(d[e].resolved=u.optionId);break}case`error`:d.push({kind:`error`,text:u.message,key:`e${u.seq}`,from:u.from});break;case`failure`:{let{type:e,seq:n,ts:r,from:i,...o}=u,s=a.get(o.id);if(s&&o.revision>=s.failure.revision)s.failure=o,s.resolved=!1,s.retryText=c;else if(!s){let e={kind:`failure`,failure:o,resolved:!1,retryText:c,key:`e${u.seq}`,from:i};a.set(o.id,e),t.push(e)}break}case`turn_end`:for(let e of a.values())e.resolved=!0;break;case`plan`:u.entries===null?l&&(l.removed=!0):l&&!l.removed?l.entries=u.entries:(l={kind:`plan`,entries:u.entries,removed:!1,key:`e${u.seq}`,from:u.from},t.push(l));break;case`files_changed`:(u.paths.length>0||u.uncertainty)&&t.push({kind:`files`,paths:u.paths,complete:u.complete,...u.uncertainty?{note:u.uncertainty}:{},key:`e${u.seq}`,from:u.from});break;case`elicitation_request`:{let e={kind:`question`,requestId:u.requestId,message:u.message,fields:u.fields,key:`e${u.seq}`,from:u.from};o.set(u.requestId,e),t.push(e);break}case`elicitation_resolved`:{let e=o.get(u.requestId);e&&(e.resolved={action:u.action,...u.action===`accept`?{content:u.content}:{}});break}}}return t}function mo({b:e,chatId:t}){let[n,r]=(0,v.useState)({}),[i,a]=(0,v.useState)(!1),o=eo(),[s,c]=(0,v.useState)(null),l=e.resolved===void 0&&!s;async function u(r){a(!0);try{let i=await A.request(`chats.elicitation`,{id:t,body:{requestId:e.requestId,action:r,...r===`accept`?{content:n}:{}}});i.ok||c(i.error??`request failed (${i.status})`)}catch{}a(!1)}let d=(e,t)=>r(n=>({...n,[e]:t})),f=e.fields.some(e=>e.required&&(n[e.key]===void 0||n[e.key]===``));return(0,F.jsx)(ho,{className:P(`question-card`,l&&`pending`),requestId:e.requestId,who:`${o(e.from)} asks`,what:e.message,children:l?(0,F.jsxs)(`div`,{className:`mt-2.5 flex flex-col gap-2.5`,children:[e.fields.map(e=>(0,F.jsxs)(`label`,{className:P(`flex flex-col gap-1.5 text-sm`,e.custom&&`-mt-1`),children:[(e.title||e.description)&&!e.custom&&(0,F.jsxs)(`span`,{children:[e.title&&(0,F.jsx)(`b`,{children:e.title}),e.description&&(0,F.jsxs)(`span`,{className:`opacity-85`,children:[` `,e.description]})]}),e.kind===`select`&&(0,F.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:e.options?.map(t=>(0,F.jsx)(V,{size:`sm`,variant:n[e.key]===t.value?`primary`:`secondary`,title:t.description,onClick:()=>d(e.key,t.value),children:t.label},t.value))}),e.kind===`multiselect`&&(0,F.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:e.options?.map(t=>{let r=n[e.key]??[],i=r.includes(t.value);return(0,F.jsx)(V,{size:`sm`,variant:i?`primary`:`secondary`,title:t.description,onClick:()=>d(e.key,i?r.filter(e=>e!==t.value):[...r,t.value]),children:t.label},t.value)})}),e.kind===`text`&&(0,F.jsx)(X,{className:`max-w-[60ch]`,placeholder:e.custom?`or type your own answer`:e.title??e.key,value:n[e.key]??``,onChange:t=>d(e.key,t.target.value)}),e.kind===`number`&&(0,F.jsx)(X,{type:`number`,className:`max-w-[60ch]`,value:n[e.key]??``,onChange:t=>d(e.key,t.target.value===``?``:Number(t.target.value))}),e.kind===`boolean`&&(0,F.jsxs)(`span`,{children:[(0,F.jsx)(`input`,{type:`checkbox`,className:`accent-accent`,checked:n[e.key]===!0,onChange:t=>d(e.key,t.target.checked)}),` `,e.title??e.key]})]},e.key)),(0,F.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,F.jsx)(V,{variant:`primary`,disabled:i||f,onClick:()=>u(`accept`),children:`answer`}),(0,F.jsx)(V,{disabled:i,onClick:()=>u(`decline`),children:`skip`})]})]}):(0,F.jsx)(go,{children:s?`→ ${s}`:e.resolved?.action===`accept`?`→ ${Object.values(e.resolved.content??{}).filter(e=>e!==``&&e!==void 0&&!(Array.isArray(e)&&e.length===0)).map(e=>Array.isArray(e)?e.join(`, `):String(e)).join(` · `)||`answered`}`:e.resolved?.action===`decline`?`→ skipped`:`→ dismissed`})})}function ho({className:e,requestId:t,who:n,what:r,children:i}){return(0,F.jsxs)(`div`,{className:P(`perm-card max-w-[76ch] self-start rounded-2xl bg-ask-soft px-4 py-3 text-on-ask-soft`,e),"data-request":t,children:[(0,F.jsxs)(`div`,{className:`flex flex-col gap-[3px]`,children:[(0,F.jsx)(`span`,{className:`perm-who text-[12.5px] font-semibold text-fg-2`,children:n}),(0,F.jsx)(`span`,{className:`text-base font-semibold [overflow-wrap:anywhere] text-fg`,children:r})]}),i]})}function go({children:e}){return(0,F.jsx)(`div`,{className:`mt-1.5 font-mono text-xs text-fg-2`,children:e})}function _o({b:e,chatId:t}){let[n,r]=(0,v.useState)(!1),i=eo(),[a,o]=(0,v.useState)(null),s=e.resolved===void 0&&!a;async function c(n){r(!0);try{let r=await A.request(`chats.permission`,{id:t,body:{requestId:e.requestId,optionId:n}});r.ok||o(r.error??`request failed (${r.status})`)}catch{}r(!1)}return(0,F.jsx)(ho,{className:P(s&&`pending`),requestId:e.requestId,who:`${i(e.from)} asks for your OK`,what:e.title,children:s?(0,F.jsx)(`div`,{className:`mt-2.5 flex flex-wrap gap-2`,children:e.options.map(e=>(0,F.jsx)(V,{variant:e.kind?.startsWith(`allow`)?`primary`:`secondary`,disabled:n,title:e.name,onClick:()=>c(e.optionId),children:vo(e)},e.optionId))}):(0,F.jsx)(go,{children:e.resolved?`→ ${(()=>{let t=e.options.find(t=>t.optionId===e.resolved);return t?vo(t):e.resolved})()}`:a?`→ ${a}`:`→ dismissed`})})}function vo(e){return e.kind===`allow_once`?`Allow`:e.kind===`allow_always`?`Always allow`:e.kind===`reject_once`?`Don't allow`:e.kind===`reject_always`?`Never allow`:e.name}var yo=new Set([`tool`,`thought`,`subagent`,`task`,`files`]);function bo({id:e,events:t,busy:n,channel:r,agentMap:i,working:a,focus:o}){let s=be(),c=(0,v.useMemo)(()=>{let e=po(o?t.filter(e=>e.from?.kind===`human`||e.from?.kind===`agent`&&e.from.slug===o):t);return s||o?e:e.filter(e=>!yo.has(e.kind))},[t,s,o]),l=eo(),u=(0,v.useMemo)(()=>to(t),[t]),d=(0,v.useRef)(null),f=(0,v.useRef)(!0);return(0,v.useEffect)(()=>{let e=d.current;e&&f.current&&(e.scrollTop=e.scrollHeight)},[c,n]),(0,F.jsxs)(`div`,{className:`-mx-5 flex min-h-0 flex-1 flex-col gap-2.5 overflow-y-auto px-[22px] pt-3.5 pb-5 [&>:nth-last-child(-n+3)]:animate-rise`,ref:d,onClick:oo,onScroll:e=>{let t=e.currentTarget;f.current=t.scrollHeight-t.scrollTop-t.clientHeight<60},children:[c.length===0&&(0,F.jsx)(K,{className:`m-auto`,children:r?`say something — @mention an agent to wake it${r.responder?`, or just write: @${r.responder} answers`:``}`:`say something — the agent starts on your first message`}),c.map((t,n)=>{let a=c[n-1],o=r&&t.kind!==`error`&&(!a||!fo(a.from,t.from)||a.kind===`error`)?t.from:void 0;return(0,F.jsxs)(`div`,{className:`contents`,children:[o&&(0,F.jsx)(xo,{from:o,agentMap:i}),(0,F.jsx)(To,{b:t,chatId:e})]},t.key)}),n&&u!==void 0&&(0,F.jsxs)(`div`,{className:`chat-working waiting flex animate-breathe items-center gap-2 text-xs font-semibold text-bad`,children:[(0,F.jsx)(U,{tone:`bad`}),` `,l(u??void 0),` is waiting for you`]}),n&&u===void 0&&(0,F.jsxs)(`div`,{className:`chat-working flex animate-breathe items-center gap-2 text-xs text-fg-2`,children:[(0,F.jsx)(U,{tone:`working`}),` `,r&&a?.length?a.map(e=>`${i?.get(e)?.emoji??``} @${e}`).join(`, `)+(a.length===1?` is working…`:` are working…`):`${l()} is working…`]})]})}function xo({from:e,agentMap:t}){let n=`mt-2.5 -mb-0.5 inline-flex items-center gap-2 text-sm text-fg-2 no-underline`,r=`grid size-[22px] place-items-center rounded-full text-xs font-semibold`;if(e.kind===`human`)return(0,F.jsxs)(`div`,{className:P(`byline human self-end`,n),children:[(0,F.jsx)(`span`,{className:P(r,`bg-accent text-on-accent`),children:e.name.slice(0,1).toUpperCase()}),(0,F.jsx)(`span`,{className:`byline-name font-semibold text-fg`,children:e.name})]});let i=t?.get(e.slug);return(0,F.jsxs)(he,{href:`/agents/${encodeURIComponent(e.slug)}/info`,className:P(`byline agent self-start`,n),children:[(0,F.jsx)(`span`,{className:P(r,`bg-accent-soft text-on-accent-soft`),children:i?.emoji??`🤖`}),(0,F.jsx)(`span`,{className:`byline-name font-semibold text-fg`,children:i?.name??e.slug}),(0,F.jsxs)(`span`,{className:`font-mono text-2xs`,children:[`@`,e.slug]})]})}function So({text:e,small:t}){let n=(0,v.useMemo)(()=>ao(da.sanitize(Fr.parse(e,{async:!1}))),[e]);return(0,F.jsx)(`div`,{className:P(`md-body h-auto self-stretch overflow-visible p-0 break-words text-fg`,t?`font-sans text-[12.5px] leading-[1.6]`:`font-reading text-[17px] leading-[1.62]`,`[&_img]:my-1 [&_img]:block [&_img]:rounded-xl [&_pre]:max-w-full`),dangerouslySetInnerHTML:{__html:n}})}function Co({tone:e,kind:t,kindTone:n,children:r,extra:i}){return(0,F.jsxs)(`div`,{className:`flex max-w-[min(90ch,100%)] items-start gap-2 self-start px-0.5 font-mono text-2xs text-fg-2 max-[800px]:flex-wrap max-[800px]:gap-y-0.5`,children:[(0,F.jsx)(`span`,{className:`mt-[3px] grid`,children:(0,F.jsx)(U,{tone:e})}),(0,F.jsx)(`span`,{className:P(`min-w-16 shrink-0 text-[10px] tracking-[0.5px] uppercase`,n===`ask`&&`text-ask`),children:t}),(0,F.jsx)(`span`,{className:`min-w-0 leading-[1.5] [overflow-wrap:anywhere] whitespace-pre-wrap max-[800px]:basis-full max-[800px]:ps-4`,children:r}),i]})}var wo=(e,t=`working`)=>e===`completed`?`ok`:e===`failed`?`bad`:e===`running`||e===void 0?t:`idle`;function To({b:e,chatId:t,nested:n}){switch(e.kind){case`user`:return(0,F.jsxs)(`div`,{className:P(`msg user -mx-[22px] my-1.5 self-stretch bg-[color-mix(in_srgb,var(--accent)_14%,var(--surface-1))] px-[22px] py-4 text-md leading-[1.55] break-words whitespace-pre-wrap text-fg`,e.steered&&`border-l-[3px] border-ask`),children:[e.steered&&(0,F.jsx)(et,{className:`mb-0.5 block text-[10px] opacity-70`,children:`steered in`}),e.text,e.attachments&&e.attachments.length>0&&(0,F.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-2`,children:e.attachments.map(e=>{let n=A.url(`chats.attachment`,{id:t,name:e.name});return e.mimeType.startsWith(`image/`)?(0,F.jsx)(`a`,{href:n,target:`_blank`,rel:`noreferrer`,title:e.name,children:(0,F.jsx)(`img`,{src:n,alt:e.name,className:`block max-h-60 max-w-full rounded-lg`})},e.name):(0,F.jsxs)(`a`,{className:`inline-flex items-center gap-1 text-xs text-inherit underline`,href:n,target:`_blank`,rel:`noreferrer`,children:[(0,F.jsx)(I,{name:`attach_file`,className:`ms-sm`}),` `,e.name]},e.name)})})]});case`agent`:return(0,F.jsx)(So,{text:e.text,small:n});case`thought`:return(0,F.jsxs)(`details`,{className:`self-stretch`,children:[(0,F.jsx)(`summary`,{className:`cursor-pointer text-xs font-medium text-fg-2 select-none`,children:`thinking`}),(0,F.jsx)(`div`,{className:`mt-1 border-l-2 border-line px-3 py-2 text-xs break-words whitespace-pre-wrap text-fg-2`,children:e.text})]});case`tool`:return(0,F.jsx)(Co,{tone:e.status===`completed`?`ok`:e.status===`failed`?`bad`:`working`,kind:e.compaction?`compact`:e.toolKind,kindTone:e.compaction?`ask`:void 0,children:e.compaction?Oo(e.compaction,e.status):e.title});case`subagent`:return(0,F.jsxs)(`details`,{className:`max-w-[90ch] self-stretch`,open:!e.state,children:[(0,F.jsx)(`summary`,{className:`cursor-pointer list-none select-none [&::-webkit-details-marker]:hidden`,children:(0,F.jsxs)(Co,{tone:wo(e.state),kind:`subagent`,children:[(0,F.jsx)(`b`,{children:e.name}),` — `,e.task,e.state&&e.state!==`completed`&&(0,F.jsxs)(`span`,{className:`opacity-70`,children:[` · `,e.state]})]})}),(0,F.jsxs)(`div`,{className:`mt-1.5 mb-1 ml-[3px] flex flex-col gap-2.5 border-l-2 border-line py-1.5 pl-3.5`,children:[e.children.length===0&&(0,F.jsx)(`div`,{className:`font-mono text-2xs text-fg-2 opacity-70`,children:`working…`}),e.children.map(e=>(0,F.jsx)(To,{b:e,chatId:t,nested:!0},e.key))]})]});case`task`:return(0,F.jsxs)(Co,{tone:wo(e.state,`working`),kind:e.taskType,kindTone:`ask`,extra:e.canStop&&(e.state===`running`||e.state===`paused`)&&(0,F.jsx)(`button`,{type:`button`,className:`ml-2 cursor-pointer rounded-lg border border-line bg-transparent px-1.5 py-px font-[inherit] text-[10px] tracking-[0.5px] text-inherit uppercase hover:border-bad hover:text-bad`,title:`stop this background task (the turn goes on)`,onClick:()=>A.request(`chats.stopTask`,{id:t,body:{taskId:e.taskId}}).catch(()=>{}),children:`stop`}),children:[(0,F.jsx)(`b`,{children:e.name}),` — `,e.summary??e.description,e.state&&e.state!==`running`&&e.state!==`completed`&&(0,F.jsxs)(`span`,{className:`opacity-70`,children:[` · `,e.state]})]});case`plan`:return(0,F.jsxs)(`div`,{className:P(`max-w-[76ch] self-start rounded-xl bg-surface-2 px-3.5 py-2.5 text-[12.5px] text-fg-2`,e.removed&&`opacity-55`),children:[(0,F.jsxs)(`div`,{className:`mb-1 flex items-baseline gap-2`,children:[(0,F.jsx)(et,{children:`plan`}),(0,F.jsxs)(`span`,{className:`font-mono text-2xs`,children:[e.entries.filter(e=>e.status===`completed`).length,`/`,e.entries.length]})]}),(0,F.jsx)(`ul`,{className:`m-0 flex list-none flex-col gap-[3px] p-0`,children:e.entries.map((e,t)=>(0,F.jsxs)(`li`,{className:P(`flex items-start gap-1.5 leading-[1.45]`,e.status===`completed`&&`line-through opacity-60`,e.status===`in_progress`&&`font-semibold text-fg`),children:[(0,F.jsx)(I,{name:e.status===`completed`?`check_circle`:e.status===`in_progress`?`play_circle`:`radio_button_unchecked`,className:P(`ms-sm mt-0.5 shrink-0`,e.status===`in_progress`&&`text-accent`)}),(0,F.jsx)(`span`,{children:e.content})]},t))})]});case`files`:return(0,F.jsxs)(Co,{tone:`ok`,kind:`changed`,children:[e.paths.join(`
80
80
  `),(!e.complete||e.note)&&(0,F.jsxs)(`span`,{className:`opacity-70`,children:[` · `,e.note??`list may be incomplete`]})]});case`question`:return(0,F.jsx)(mo,{b:e,chatId:t});case`permission`:return(0,F.jsx)(_o,{b:e,chatId:t});case`error`:return(0,F.jsxs)(`div`,{className:`flex items-center gap-1 self-start text-[12.5px] text-bad`,children:[(0,F.jsx)(I,{name:`error`,className:`ms-sm`}),` `,e.text]});case`failure`:return(0,F.jsx)(Do,{b:e,chatId:t})}}var Eo={retry:`try again`,login:`sign in again`,new_session:`start a fresh session`};function Do({b:e,chatId:t}){let[n,r]=(0,v.useState)(!1),[i,a]=(0,v.useState)(null),o=e.failure,s=!e.resolved&&!i;async function c(n){if(n===`login`){a(`Sign in again in a terminal (claude login, or codex login), then send your message again.`);return}r(!0);try{if(n===`retry`){if(!e.retryText)return a(`nothing to retry — send a message`);await A.request(`chats.message`,{id:t,body:{text:e.retryText}})}else{let e=await A.request(`chats.resetSession`,{id:t});e.ok||a(e.error??`reset failed (${e.status})`)}}catch{}finally{r(!1)}}return(0,F.jsxs)(`div`,{className:P(`max-w-[76ch] self-start rounded-2xl px-4 py-3`,o.severity===`warning`?`bg-ask-soft text-on-ask-soft`:`bg-bad-soft text-on-bad-soft`,!s&&`opacity-70`),children:[(0,F.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[13.5px]`,children:[(0,F.jsx)(I,{name:o.severity===`warning`?`warning`:`error`,className:`ms-sm`}),(0,F.jsx)(et,{className:`mr-1 font-bold text-inherit`,children:o.category}),` `,o.title]}),o.details&&(0,F.jsx)(`div`,{className:`mt-1.5 text-xs break-words whitespace-pre-wrap`,children:o.details}),i&&(0,F.jsx)(`div`,{className:`mt-1.5 text-xs break-words whitespace-pre-wrap`,children:i}),s&&o.actions.length>0&&(0,F.jsx)(`div`,{className:`mt-2.5 flex flex-wrap gap-2`,children:o.actions.map(e=>(0,F.jsx)(V,{size:`sm`,disabled:n,className:`border-current text-inherit`,onClick:()=>c(e),children:Eo[e]},e))})]})}function Oo(e,t){let n=e=>e>=1e4?`${Math.round(e/1e3)}k`:String(e),r=[t===`completed`?`context compacted`:t===`failed`?`compaction failed`:`compacting context`];return e.preTokens!=null&&e.postTokens!=null?r.push(`${n(e.preTokens)} → ${n(e.postTokens)} tokens`):e.preTokens!=null&&r.push(`${n(e.preTokens)} tokens`),e.trigger&&r.push(e.trigger),e.error&&r.push(e.error),r.join(` · `)}function ko({id:e,busy:t,scope:n,channel:r,agentMap:i,commands:a=[],canSteer:o,account:s}){let[c,l]=(0,v.useState)(``),[u,d]=(0,v.useState)(null),f=eo()().replace(/^\S+\s(?=\S)/u,e=>/\p{Extended_Pictographic}/u.test(e)?``:e).replace(/^The /,`the `),[p,m]=(0,v.useState)([]),[h,g]=(0,v.useState)(0),[_,y]=(0,v.useState)(!1);async function b(t){for(let n of Array.from(t)){g(e=>e+1);try{let t=await A.request(`chats.attach`,{id:e,headers:{"content-type":n.type||`application/octet-stream`,"x-file-name":encodeURIComponent(n.name||`pasted.png`)},body:n});if(typeof t.data!=`object`||!t.data)throw Error(`not json`);t.ok?m(e=>[...e,{...t.data,...n.type.startsWith(`image/`)?{preview:URL.createObjectURL(n)}:{}}]):d(t.error??`upload failed (${t.status})`)}catch{d(`upload failed`)}finally{g(e=>e-1)}}}let[x,S]=(0,v.useState)([]),[C,w]=(0,v.useState)(0),[T,E]=(0,v.useState)(!1),[D,O]=(0,v.useState)(qa),[k,j]=(0,v.useState)(!1),ee=(0,v.useRef)(null),M=(0,v.useRef)(null),N=t&&!r&&!!o,te=t&&!r&&!o;(0,v.useEffect)(()=>{let e=!0;return(async()=>{try{let t=await A.request(`skills.list`),r=(t.ok?t.data.skills:void 0)??[];if(n?.kind===`agent`){let[e,t]=await Promise.all([A.call(`agents.get`,{slug:n.slug}).catch(()=>null),A.call(`agents.skills`,{slug:n.slug}).catch(()=>null)]);if(e&&Array.isArray(e.skills)){let t=new Set(e.skills.map(e=>e.toLowerCase()));r=r.filter(e=>t.has(e.name.toLowerCase()))}let i=t?.skills??[],a=new Set(i.map(e=>e.name.toLowerCase()));r=[...i,...r.filter(e=>!a.has(e.name.toLowerCase()))]}e&&S(r)}catch{}})(),()=>{e=!1}},[e]);let ne=/^\/([\w-]*)$/.exec(c)?.[1],L=ne!==void 0&&!T?x.filter(e=>e.name.toLowerCase().startsWith(ne.toLowerCase())):[],re=new Set(x.map(e=>e.name.toLowerCase())),ie=ne!==void 0&&!T?a.filter(e=>e.name.toLowerCase().startsWith(ne.toLowerCase())&&!re.has(e.name.toLowerCase())):[],ae=ee.current?.selectionStart??c.length,oe=r&&!T?/(^|\s)@([a-z0-9-]*)$/i.exec(c.slice(0,ae)):null,se=oe&&r?r.members.filter(e=>e.startsWith(oe[2].toLowerCase())||(i?.get(e)?.name??``).toLowerCase().startsWith(oe[2].toLowerCase())):[],ce=[...L.map(e=>({id:`/${e.name}`,label:`/${e.name}`,hint:e.description,src:e.source,pick:()=>{l(`/${e.name} `),w(0)}})),...ie.map(e=>({id:`/${e.name}`,label:`/${e.name}${e.hint?` ${e.hint}`:``}`,hint:e.description,src:`agent`,pick:()=>{l(`/${e.name} `),w(0)}})),...se.map(e=>({id:`@${e}`,label:`${i?.get(e)?.emoji??`🤖`} @${e}`,hint:i?.get(e)?.name,pick:()=>{let t=c.slice(0,ae).replace(/@[a-z0-9-]*$/i,`@${e} `);l(t+c.slice(ae)),w(0),requestAnimationFrame(()=>{let e=ee.current;e&&(e.selectionStart=e.selectionEnd=t.length)})}}))].slice(0,15),le=ce.length>0,ue=Math.min(C,ce.length-1);async function de(){let t=c.trim();if(!t&&p.length===0||te||h>0)return;let n=p.map(({preview:e,...t})=>t);l(``),m([]),d(null);let i={text:t,...n.length?{attachments:n}:{},...r?{from:D||`you`}:{}},a=await(N?A.request(`chats.steer`,{id:e,body:i}):A.request(`chats.message`,{id:e,body:i})).catch(()=>null);a&&!a.ok&&(d(a.error??`not sent (${a.status})`),l(t),m(p))}return(0,F.jsxs)(`div`,{className:`composer relative flex flex-none flex-wrap items-end border-t border-line pt-2.5 pb-1`,onDragOver:e=>{e.dataTransfer.types.includes(`Files`)&&(e.preventDefault(),y(!0))},onDragLeave:()=>y(!1),onDrop:e=>{e.dataTransfer.files.length&&(e.preventDefault(),y(!1),b(e.dataTransfer.files))},children:[p.length>0&&(0,F.jsxs)(`div`,{className:`flex basis-full flex-wrap gap-1.5 px-1 pb-1.5`,children:[p.map(e=>(0,F.jsxs)(`span`,{className:Ao,title:`${e.name} · ${Math.round(e.size/1024)} KB`,children:[e.preview?(0,F.jsx)(`img`,{src:e.preview,alt:e.name,className:`h-7 rounded`}):(0,F.jsx)(I,{name:`attach_file`,className:`ms-sm`}),e.name.replace(/^\d{8}-\d{6}-/,``),(0,F.jsx)(`button`,{type:`button`,className:`inline-flex cursor-pointer border-0 bg-transparent p-0 text-inherit hover:text-fg`,title:`remove`,"aria-label":`remove ${e.name}`,onClick:()=>m(t=>t.filter(t=>t.name!==e.name)),children:(0,F.jsx)(I,{name:`close`,className:`ms-sm`})})]},e.name)),h>0&&(0,F.jsx)(`span`,{className:Ao,children:`uploading…`})]}),r&&(0,F.jsxs)(`div`,{className:`composer-me flex basis-full items-center gap-1.5 px-1 pb-1 text-xs text-fg-2`,children:[`posting as`,` `,k?(0,F.jsx)(X,{autoFocus:!0,className:`h-7 w-48 text-xs`,value:D,placeholder:`your name`,"aria-label":`your name`,onChange:e=>O(e.target.value),onBlur:()=>{Ja(D.trim()),j(!1)},onKeyDown:e=>{(e.key===`Enter`||e.key===`Escape`)&&e.target.blur()}}):(0,F.jsxs)(`button`,{type:`button`,className:`me-name inline-flex cursor-pointer items-center gap-1 border-0 bg-transparent p-0 font-[inherit] font-semibold text-fg`,onClick:()=>j(!0),title:`change your name`,children:[D||`you`,` `,(0,F.jsx)(I,{name:`edit`,className:`ms-sm`})]})]}),le&&(0,F.jsx)(`div`,{className:`skill-menu absolute inset-x-0 bottom-full z-5 mb-1.5 flex max-h-[46vh] flex-col overflow-y-auto rounded-card border border-line bg-surface py-1 shadow-pop`,children:ce.map((e,t)=>(0,F.jsxs)(`button`,{type:`button`,className:P(`flex cursor-pointer items-center gap-1.5 border-0 px-3.5 py-2 text-left text-sm whitespace-nowrap text-fg`,t===ue?`bg-surface-2`:`bg-transparent hover:bg-surface-2`),onMouseDown:t=>{t.preventDefault(),e.pick()},children:[(0,F.jsx)(`b`,{className:`max-w-[42%] flex-none truncate font-mono text-[12.5px] font-medium`,children:e.label}),e.hint&&(0,F.jsxs)(`span`,{className:`min-w-0 flex-1 truncate text-xs text-fg-2`,children:[`— `,e.hint]}),e.src&&(0,F.jsx)(`span`,{className:`ml-auto flex-none text-[10.5px] tracking-[0.04em] text-fg-2 uppercase`,children:e.src})]},e.id))}),u&&(0,F.jsx)(`div`,{className:`basis-full`,children:(0,F.jsx)(q,{tone:`bad`,children:u})}),(0,F.jsxs)(`div`,{className:P(`flex min-w-0 flex-1 items-end gap-0.5 rounded-[24px] border bg-surface py-[5px] pr-[5px] pl-3.5 transition-[border-color,box-shadow]`,`focus-within:border-accent focus-within:shadow-[0_0_0_3px_color-mix(in_srgb,var(--accent)_16%,transparent)]`,_?`border-dashed border-accent`:`border-line`),children:[(0,F.jsx)(`textarea`,{ref:ee,value:c,className:`max-h-[40vh] min-w-0 flex-1 resize-none overflow-y-auto rounded-none border-0 bg-transparent px-1.5 py-2 font-sans text-md leading-[1.5] text-fg shadow-none outline-none [field-sizing:content] placeholder:text-fg-2`,placeholder:r?te?`the agents are working…`:`Message the channel…`:te?`${f} is working…`:N?`Add to what ${f} is doing…`:`Message ${f}…`,title:`${r?`Enter to send · Shift+Enter for a newline · @ mentions an agent · / for skills · drop or paste files`:`Enter to send · Shift+Enter for a newline · / for skills · drop or paste files`}${s?`\nruns as ${s}`:``}`,rows:Math.min(6,Math.max(1,c.split(`
81
- `).length)),onChange:e=>{l(e.target.value),w(0),E(!1)},onPaste:e=>{let t=Array.from(e.clipboardData.items).filter(e=>e.kind===`file`).map(e=>e.getAsFile()).filter(e=>!!e);t.length&&(e.preventDefault(),b(t))},onKeyDown:e=>{if(le){if(e.key===`ArrowDown`)return e.preventDefault(),w((ue+1)%ce.length);if(e.key===`ArrowUp`)return e.preventDefault(),w((ue-1+ce.length)%ce.length);if(e.key===`Tab`||e.key===`Enter`)return e.preventDefault(),ce[ue].pick();if(e.key===`Escape`)return e.preventDefault(),E(!0)}e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),de())}}),t&&(0,F.jsx)(V,{size:`sm`,variant:`danger`,icon:`stop`,className:`mr-1 self-center`,onClick:()=>A.request(`chats.cancel`,{id:e}).catch(()=>{}),children:`stop`}),!te&&(0,F.jsx)(H,{icon:`attach_file`,label:`attach files (or drop / paste them)`,className:`size-9 rounded-full [&_.ms]:text-[20px]`,onClick:()=>M.current?.click()}),(0,F.jsx)(`input`,{ref:M,type:`file`,multiple:!0,hidden:!0,onChange:e=>{e.target.files?.length&&b(e.target.files),e.target.value=``}}),!te&&(0,F.jsx)(`button`,{type:`button`,className:`inline-grid size-9 flex-none cursor-pointer place-items-center rounded-full border-0 bg-accent p-0 text-on-accent transition-[filter,opacity] hover:enabled:brightness-110 active:enabled:scale-95 disabled:cursor-default disabled:opacity-30`,disabled:!c.trim()&&p.length===0||h>0,onClick:de,"aria-label":N?`steer`:`send`,title:N?`steer: hand this into the running turn (Enter)`:`send (Enter)`,children:(0,F.jsx)(I,{name:N?`alt_route`:`send`,className:`text-[19px]`})})]})]})}var Ao=`inline-flex items-center gap-1.5 rounded-full border border-line bg-surface-2 px-2 py-0.5 text-2xs text-fg-2`;function $({id:e,live:t}){let n=be(),[r,i]=(0,v.useState)(null),a=t.config.filter(e=>e.category===`model`||e.category===`thought_level`);async function o(t,n){i(t.id);let r=await A.request(`chats.config`,{id:e,body:{configId:t.id,value:n}}).catch(()=>null);i(null),r&&!r.ok&&alert(r.error??`setting refused (${r.status})`)}return(0,F.jsxs)(F.Fragment,{children:[t.auth?.kind===`none`&&(0,F.jsx)(`span`,{title:[t.auth.detail,t.auth.email,t.auth.organization,t.auth.plan].filter(Boolean).join(` · `),children:(0,F.jsxs)(W,{tone:t.auth.kind===`none`?`bad`:`neutral`,children:[(0,F.jsx)(I,{name:t.auth.kind===`none`?`person_off`:`person`,className:`ms-sm mr-1`}),` `,t.auth.email??t.auth.label]})}),n&&t.usage&&t.usage.size>0&&(0,F.jsx)(`span`,{className:`font-mono`,title:`${t.usage.used.toLocaleString()} of ${t.usage.size.toLocaleString()} context tokens${t.usage.costUsd==null?``:` · $${t.usage.costUsd.toFixed(2)} so far`}`,children:(0,F.jsxs)(W,{children:[Math.round(100*t.usage.used/t.usage.size),`% ctx`,t.usage.costUsd!=null&&` · $${t.usage.costUsd.toFixed(2)}`]})}),n&&a.map(e=>e.type===`select`?(0,F.jsx)(_t,{className:`h-7 w-auto max-w-[22ch] px-2 pr-6 text-xs text-fg-2`,value:e.value,disabled:r===e.id,title:e.description??e.name,"aria-label":e.name,onChange:t=>o(e,t.target.value),children:e.choices.map(e=>(0,F.jsxs)(`option`,{value:e.value,title:e.description,children:[e.group?`${e.group} · `:``,e.name]},e.value))},e.id):(0,F.jsxs)(`label`,{className:`inline-flex cursor-pointer items-center gap-1 text-xs text-fg-2`,title:e.description??e.name,children:[(0,F.jsx)(`input`,{type:`checkbox`,className:`accent-accent`,checked:e.value,disabled:r===e.id,onChange:t=>o(e,t.target.checked)}),` `,e.name]},e.id))]})}function jo({id:e,agentName:t,agentDescription:n,channel:r,agents:i,onConverted:a}){let[o,s]=(0,v.useState)(null),c=N(`chats.list`,{})?.chats.find(t=>t.id===e)?.title;(0,v.useEffect)(()=>{c!==void 0&&s(e=>e&&e.title!==c?{...e,title:c}:e)},[c]);let[l,u]=(0,v.useState)([]),[d,f]=(0,v.useState)(!1),[p,m]=(0,v.useState)(!1),[h,g]=(0,v.useState)(!1),[_,y]=(0,v.useState)(null),[b,x]=(0,v.useState)(null),S=we(),C=be(),w=N(`agents.list`,r?null:{},{interval:3e4})?.agents??[],T=o?.vibeable&&S.vibeables?o.vibeable:null,[E,D]=(0,v.useState)(null);(0,v.useEffect)(()=>T?(ha({chatId:e,slug:T}),D(document.getElementById(ma)),()=>ha(null)):D(null),[e,T]);let O=(0,v.useMemo)(()=>Qa(l),[l]);(0,v.useEffect)(()=>{let t=!0,n;return A.call(`chats.get`,{id:e}).then(r=>{if(!t)return;s(r.meta),u(r.events);let i=r.events[r.events.length-1]?.seq??0;n=ee.subscribe(`chat.${e}`,{after:i},e=>{let t=e;u(e=>e.some(e=>e.seq===t.seq)?e:[...e,t])})}).catch(()=>t&&f(!0)),()=>{t=!1,n?.()}},[e]);let k=(0,v.useMemo)(()=>{if(!r)return[];let e=new Set;for(let t of l)t.from?.kind===`agent`&&(t.type===`turn_start`&&e.add(t.from.slug),(t.type===`turn_end`||t.type===`error`)&&e.delete(t.from.slug));return[...e]},[l,r]),j=(0,v.useMemo)(()=>{if(r)return k.length>0;for(let e=l.length-1;e>=0;e--){let t=l[e].type;if(t===`user_message`)return!0;if(t===`turn_end`||t===`error`)return!1}return!1},[l,r,k]),M=(0,v.useMemo)(()=>{if(o?.title)return o.title;let e=l.find(e=>e.type===`user_message`);return e&&e.type===`user_message`?e.text.replace(/\s+/g,` `).trim().slice(0,80):``},[o,l]);if((0,v.useEffect)(()=>o?r?(le(`#${r.slug} · ${r.name}`),()=>le(``)):(le([t??(o.scope.kind===`agent`?o.scope.slug:o.agent),n,M||`new chat`].filter(Boolean).join(` · `)),()=>le(``)):void 0,[o,M,t,n,r]),d)return(0,F.jsx)(K,{icon:`chat_error`,children:`chat not found`});if(!o)return(0,F.jsx)(K,{children:`loading…`});let te=new Map((i??[]).map(e=>[e.slug,e]));if(r)return(0,F.jsxs)(`div`,{className:`chat-thread flex min-h-0 w-full flex-1 animate-rise flex-col`,children:[(0,F.jsxs)(`div`,{className:`channel-head flex flex-none flex-wrap items-center gap-x-3 gap-y-2 pb-1.5`,children:[(0,F.jsx)(U,{tone:j?`working`:`ok`}),(0,F.jsxs)(nt,{children:[`#`,r.slug]}),(0,F.jsx)(`span`,{className:`text-md text-fg-2`,children:r.name}),(0,F.jsx)(`span`,{className:`flex-1`}),k.length>0&&(0,F.jsxs)(V,{size:`sm`,variant:`danger`,icon:`stop`,title:`interrupt every agent working in this channel`,onClick:()=>Ya(e),children:[`stop all (`,k.length,`)`]}),(0,F.jsx)(V,{size:`sm`,icon:`tune`,href:`/channels/${encodeURIComponent(r.slug)}/edit`,title:`members, purpose, responder`,children:`members`})]}),(0,F.jsxs)(`div`,{className:`channel-members flex flex-none flex-wrap items-center gap-x-2.5 gap-y-2 pb-3`,children:[r.purpose&&(0,F.jsx)(`span`,{className:`channel-purpose w-full text-sm text-fg-2`,children:r.purpose}),r.members.map(t=>{let n=te.get(t),i=k.includes(t),a=Za(l,t);return(0,F.jsxs)(`div`,{className:P(`member-chip inline-flex items-center gap-1 rounded-full py-[3px] pr-1.5 pl-[3px] text-sm transition-colors`,i?`bg-accent-soft`:`bg-surface-2`,b===t&&`outline-2 outline-accent`),title:n?.description,children:[(0,F.jsxs)(`button`,{type:`button`,className:`flex min-w-0 cursor-pointer items-center gap-2 border-0 bg-transparent p-0 text-left font-[inherit] text-inherit`,onClick:()=>x(b===t?null:t),title:b===t?`back to the channel`:`look at @${t}'s session`,children:[(0,F.jsxs)(`span`,{className:`relative grid size-7 flex-none place-items-center rounded-full bg-surface text-[15px]`,children:[(0,F.jsx)(`span`,{"aria-hidden":!0,children:n?.emoji??`🤖`}),(0,F.jsx)(`span`,{className:`absolute -right-0.5 -bottom-0.5 grid rounded-full bg-surface p-px`,children:(0,F.jsx)(U,{tone:i?`working`:`idle`})})]}),(0,F.jsxs)(`span`,{className:`flex min-w-0 flex-col gap-px`,children:[(0,F.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,F.jsx)(`span`,{className:`font-medium text-fg`,children:n?.name??t}),(0,F.jsxs)(`span`,{className:`member-handle font-mono text-2xs text-fg-2`,children:[`@`,t]}),r.responder===t&&(0,F.jsx)(W,{children:`responder`})]}),(a.task||a.now)&&(0,F.jsx)(`span`,{className:`max-w-[44ch] truncate text-2xs text-fg-2`,children:i?a.now?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(et,{className:`mr-1`,children:`now`}),` `,a.now]}):(0,F.jsxs)(F.Fragment,{children:[`working on: `,a.task]}):(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(et,{className:`mr-1`,children:`last`}),` `,a.task]})})]})]}),i&&(0,F.jsx)(H,{icon:`stop`,label:`interrupt @${t}`,variant:`danger`,size:`sm`,className:`size-6`,onClick:()=>Ya(e,t)}),(0,F.jsx)(H,{icon:`info`,label:`agent definition`,size:`sm`,className:`size-6`,href:`/agents/${encodeURIComponent(t)}/info`})]},t)})]}),b&&(0,F.jsxs)(`div`,{className:`flex flex-none items-center gap-2.5 border-b border-line py-1.5 text-sm`,children:[(0,F.jsx)(V,{size:`sm`,variant:`quiet`,icon:`arrow_back`,onClick:()=>x(null),children:`channel`}),(0,F.jsxs)(`span`,{className:`min-w-0 truncate text-fg-2`,children:[te.get(b)?.emoji??`🤖`,` @`,b,`'s session — everything this agent did, tools included`]}),(0,F.jsx)(`span`,{className:`flex-1`}),k.includes(b)&&(0,F.jsxs)(V,{size:`sm`,variant:`danger`,icon:`stop`,onClick:()=>Ya(e,b),children:[`stop @`,b]})]}),(0,F.jsxs)($a.Provider,{value:e=>{let t=e?.kind===`agent`?te.get(e.slug):void 0;return e?.kind===`agent`?`${t?.emoji??`🤖`} ${t?.name??e.slug}`:`The agent`},children:[(0,F.jsx)(bo,{id:e,events:l,busy:j,channel:r,agentMap:te,working:k,focus:b??void 0}),(0,F.jsx)(ko,{id:e,busy:j,scope:o.scope,channel:r,agentMap:te})]})]});let ne=o.scope.kind===`agent`&&!o.scope.routine||o.scope.kind===`project`,I=O.auth?.kind===`none`;return(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(`div`,{className:`chat-thread flex min-h-0 w-full flex-1 animate-rise flex-col`,children:[ne&&(0,F.jsx)(Wa,{children:(0,F.jsx)(H,{size:`sm`,icon:`group_add`,label:`add coworker`,title:o.scope.kind===`project`?`add coworker: turn this chat into a channel of the project and invite agents`:`add coworker: turn this chat into a channel and invite more agents`,onClick:()=>m(!0),disabled:j})}),(C||I)&&(0,F.jsxs)(`div`,{className:`flex flex-none flex-wrap items-center gap-x-2.5 gap-y-1.5 pb-1.5`,children:[C&&o.agent!==`pi`&&o.sessions?.main&&(0,F.jsx)(V,{size:`sm`,variant:`quiet`,icon:`call_split`,busy:h,className:o.agent===`codex`?`opacity-50`:void 0,disabled:j,"aria-disabled":o.agent===`codex`,title:o.agent===`codex`?`not supported: codex has no session fork`:`Branch this conversation: a new chat with the same history, the original stays as it is`,onClick:async()=>{if(o.agent===`codex`)return y(`fork is not supported by codex`);g(!0);let t=await A.request(`chats.fork`,{id:e});if(g(!1),!t.ok||!t.data?.id)return alert(t.error??`fork failed (${t.status})`);let n=t.data;B(n.scope?.kind===`agent`?`/agents/${encodeURIComponent(n.scope.slug)}/chat/${n.id}`:`/agents/chats/${n.id}`)},children:h?`forking…`:`fork`}),C&&_&&(0,F.jsx)(`span`,{className:`text-2xs text-fg-2`,children:_}),C&&(0,F.jsx)(`span`,{className:`max-[800px]:hidden`,children:(0,F.jsx)(W,{children:o.agent})}),(0,F.jsx)($,{id:e,live:O}),C&&o.scope.kind===`run`&&(0,F.jsx)(Mo,{href:`/runs/${o.scope.runId}`,children:o.scope.runId}),C&&o.scope.kind===`kraftwerk`&&(0,F.jsx)(W,{children:`kraftwerk-aware`}),C&&o.scope.kind===`knowledge`&&(0,F.jsxs)(Mo,{href:o.scope.bundle?`/knowledge/${encodeURIComponent(o.scope.bundle)}`:`/knowledge`,children:[`knowledge`,o.scope.bundle?`:${o.scope.bundle}`:``]}),C&&o.scope.kind===`agent`&&(0,F.jsx)(`span`,{className:`max-[800px]:hidden`,children:(0,F.jsxs)(Mo,{href:`/agents/${encodeURIComponent(o.scope.slug)}/info`,children:[`agent:`,o.scope.slug]})}),C&&(0,F.jsx)(`span`,{className:`rid max-w-[34ch] min-w-0 truncate font-mono text-xs text-fg-2 max-[800px]:hidden`,title:o.cwd,children:o.cwd})]}),o.vibeable&&!S.vibeables&&(0,F.jsx)(Ca,{chatId:e,slug:o.vibeable,onClosed:s}),(0,F.jsxs)($a.Provider,{value:()=>no(o.scope,w,t),children:[(0,F.jsx)(bo,{id:e,events:l,busy:j}),(0,F.jsx)(ko,{id:e,busy:j,scope:o.scope,commands:O.commands,canSteer:o.agent!==`pi`,account:O.auth&&O.auth.kind!==`none`?O.auth.email??O.auth.label:void 0})]})]}),T&&E&&(0,fa.createPortal)((0,F.jsx)(_a,{chatId:e,slug:T,agentBusy:j,onClosed:s},T),E),p&&o.scope.kind===`agent`&&(0,F.jsx)(Ma,{chatId:e,agentSlug:o.scope.slug,title:M,onClose:()=>m(!1)}),p&&o.scope.kind===`project`&&(0,F.jsx)(Ma,{chatId:e,project:o.scope.slug,title:M||t||``,onClose:()=>m(!1),onCreated:a})]})}function Mo({href:e,children:t}){return(0,F.jsx)(he,{href:e,className:`no-underline hover:opacity-80`,children:(0,F.jsx)(W,{children:t})})}var No=[{id:`claude`,label:`claude`,hint:`Claude Code via ACP`},{id:`codex`,label:`codex`,hint:`Codex (ChatGPT) via ACP`},{id:`pi`,label:`pi`,hint:`pi coding agent`}];async function Po(e,t,n){let r=await A.request(`chats.create`,{body:{agent:e,scope:t,...n?{resume:n}:{}}}),i=r.ok?r.data:null;i?.id&&B(i.scope?.kind===`agent`?`/agents/${encodeURIComponent(i.scope.slug)}/chat/${i.id}`:i.scope?.kind===`project`?`/projects/${encodeURIComponent(i.scope.slug)}/chat/${i.id}`:`/agents/chats/${i.id}`)}function Fo(){let[e,t]=(0,v.useState)(`claude`),[n,r]=(0,v.useState)(!0),[i,a]=(0,v.useState)(!1),[o,s]=(0,v.useState)(null);return(0,v.useEffect)(()=>s(null),[e]),(0,F.jsxs)(it,{width:`narrow`,children:[(0,F.jsx)(nt,{children:`new chat`}),(0,F.jsxs)(J,{title:`agent`,children:[(0,F.jsx)(`div`,{className:`grid grid-cols-3 gap-2.5 p-4 max-[940px]:grid-cols-1`,children:No.map(n=>{let r=e===n.id;return(0,F.jsxs)(`button`,{type:`button`,"aria-pressed":r,className:P(`flex cursor-pointer flex-col gap-0.5 rounded-card border px-3.5 py-3 text-left transition-colors`,r?`border-transparent bg-accent-soft text-on-accent-soft`:`border-line bg-transparent text-fg hover:bg-surface-2`),onClick:()=>t(n.id),children:[(0,F.jsx)(`b`,{className:`text-base font-medium`,children:n.label}),(0,F.jsx)(`span`,{className:P(`text-xs`,r?`text-on-accent-soft`:`text-fg-2`),children:n.hint})]},n.id)})}),(0,F.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 px-4 pb-3.5 text-sm text-fg-2`,children:[(0,F.jsx)(`input`,{type:`checkbox`,className:`size-[15px] accent-accent`,checked:n,onChange:e=>r(e.target.checked)}),(0,F.jsx)(`span`,{className:`text-fg`,children:`kraftwerk-aware`}),` — agent gets workflows + recent runs as context`]}),(0,F.jsx)(`div`,{className:`px-4 pb-4`,children:(0,F.jsx)(V,{variant:`primary`,busy:i,onClick:async()=>{a(!0),await Po(e,{kind:n?`kraftwerk`:`general`}),a(!1)},children:i?`starting…`:`start chat`})})]}),e!==`pi`&&(0,F.jsxs)(J,{title:`continue a session`,actions:o===null&&(0,F.jsxs)(V,{size:`sm`,variant:`quiet`,icon:`history`,onClick:async()=>{s(`loading`);let t=await A.call(`agents.sessions`,{query:{agent:e}}).catch(()=>({sessions:[]}));s((t.sessions??[]).slice(0,20))},children:[`list `,e,` sessions`]}),children:[o===null&&(0,F.jsxs)(K,{className:`py-6`,children:[`Pick up a `,e,` session started outside kraftwerk.`]}),o===`loading`&&(0,F.jsxs)(K,{className:`py-6`,children:[`asking `,e,`…`]}),Array.isArray(o)&&o.length===0&&(0,F.jsxs)(K,{className:`py-6`,children:[`no `,e,` sessions in this project`]}),Array.isArray(o)&&o.length>0&&(0,F.jsx)(`div`,{className:`flex flex-col p-1.5`,children:o.map(t=>(0,F.jsx)(Y,{size:`sm`,title:t.title||t.sessionId.slice(0,8),meta:t.updatedAt&&new Date(t.updatedAt).toLocaleString(),innerProps:{title:t.sessionId},onClick:async()=>{i||(a(!0),await Po(e,{kind:n?`kraftwerk`:`general`},t.sessionId),a(!1))}},t.sessionId))})]})]})}var Io=[`active`,`paused`,`done`,`archived`],Lo={active:`working`,paused:`idle`,done:`ok`,archived:`idle`},Ro={active:`accent`,paused:`neutral`,done:`ok`,archived:`neutral`},zo={"my-netnode":`my.netnode.ch`,"google-drive":`Google Drive`,github:`GitHub`,bitbucket:`Bitbucket`,notion:`Notion`,slack:`Slack`,url:`Link`},Bo=e=>zo[e]??e,Vo=[{id:`claude`,label:`claude`,hint:`Claude Code via ACP`},{id:`codex`,label:`codex`,hint:`Codex (ChatGPT) via ACP`},{id:`pi`,label:`pi`,hint:`pi coding agent`}],Ho=e=>[e.harness,e.model,e.effort?`effort ${e.effort}`:``].filter(Boolean).join(` · `),Uo=(e,t)=>(e??[]).filter(e=>e.scope.kind===`project`&&e.scope.slug===t||e.project===t),Wo=(e,t)=>`/projects/${encodeURIComponent(t)}/chat/${e.id}`;async function Go(e,t){let n=await A.request(`projects.save`,{slug:e,body:t});if(!n.ok)throw Error(M(n));return n.data}function Ko({seg:e}){let t=e[0]&&e[0]!==`new`?decodeURIComponent(e[0]):void 0,n=e[0]===`new`?`new`:e[1]===`info`?`info`:e[1]===`chat`?`chat`:t?`project`:`home`,r=n===`chat`?e[2]:void 0,[i,a]=(0,v.useState)(null),[o,s]=(0,v.useState)(``),c=be(),l=Ra(),u=(0,v.useCallback)(async()=>{try{let e=await A.request(`projects.list`);if(!e.ok)throw Error(`HTTP ${e.status}`);a(e.data),s(``)}catch(e){s(e.message||`could not load projects`)}},[]);(0,v.useEffect)(()=>{let e=!0,t,n=async()=>{await u(),e&&(t=setTimeout(n,15e3))};return n(),()=>{e=!1,clearTimeout(t)}},[u]),(0,v.useEffect)(()=>{u()},[t,n,u]);let d=i?.projects??[],f=t?d.find(e=>e.slug===t):void 0,p=[...d].sort((e,t)=>(t.updatedAt??``).localeCompare(e.updatedAt??``))[0]?.slug;(0,v.useEffect)(()=>{n===`home`&&p&&B(`/projects/${encodeURIComponent(p)}`,{replace:!0})},[n,p]);let m;return m=i&&!i.enabled?(0,F.jsx)(K,{icon:`folder_off`,children:i.error&&!/are off/.test(i.error)?(0,F.jsx)(`span`,{className:`text-bad`,children:i.error}):(0,F.jsxs)(F.Fragment,{children:[`Projects are off. Turn them on in `,(0,F.jsx)(`a`,{href:`#/settings`,children:`settings`}),` or add a `,(0,F.jsx)(`code`,{children:`projects:`}),` block to kraftwerk.yml.`]})}):i?n===`new`||n===`home`&&d.length===0?(0,F.jsx)(Jo,{root:i.root,onCreated:u}):n===`home`?(0,F.jsx)(K,{children:`loading…`}):t&&!f?(0,F.jsxs)(K,{icon:`folder_off`,children:[`no project named `,t]}):n===`chat`&&t&&r===`new`?(0,F.jsx)(Xo,{slug:t,title:f?.title??t},t):n===`chat`&&t&&r?(0,F.jsx)(`div`,{className:`chat-main`,children:(0,F.jsx)(Zo,{chatId:r,title:f?.title??t,goal:f?.goal},r)}):n===`info`&&t?(0,F.jsx)(es,{slug:t,onChanged:u},t):t?(0,F.jsx)(Yo,{slug:t,title:f?.title??t},t):(0,F.jsx)(K,{children:`loading…`}):(0,F.jsx)(K,{children:`loading…`}),(0,F.jsxs)(`div`,{className:`runs-screen agents-screen projects-screen ${t&&f?`has-tabs`:``} ${t&&f&&l?`has-sessions`:``}`,children:[(0,F.jsxs)(`aside`,{className:`runs-side`,children:[(0,F.jsx)(wt,{title:`projects`,count:i?.enabled?d.length:void 0,action:i?.enabled&&(c||d.length===0)&&(0,F.jsx)(V,{size:`sm`,variant:`quiet`,icon:`add`,href:`/projects/new`,children:`new`})}),(0,F.jsxs)(Et,{children:[d.map(e=>(0,F.jsx)(Y,{href:`/projects/${encodeURIComponent(e.slug)}`,active:e.slug===t,size:`sm`,innerProps:{"data-project":e.slug},leading:(0,F.jsx)(U,{tone:e.configError?`bad`:Lo[e.status],title:e.status}),title:e.title,sub:e.configError?e.configError:e.goal||e.status,subTone:e.configError?`bad`:`plain`,meta:e.updatedAt&&(0,F.jsx)(`span`,{title:e.updatedAt,children:Ge(e.updatedAt)})},e.slug)),i&&i.enabled&&d.length===0&&(0,F.jsx)(Dt,{children:`no projects yet`}),o&&(0,F.jsx)(q,{tone:`bad`,children:o})]})]}),t&&f&&(0,F.jsx)(Qo,{slug:t,chatId:r===`new`?void 0:r}),(0,F.jsx)(`div`,{className:`runs-main`,children:m})]})}function qo(){let e=N(`projects.list`,{},{interval:6e4});return e&&!e.enabled?(0,F.jsxs)(K,{icon:`folder_off`,children:[`Projects are off. Turn them on in `,(0,F.jsx)(`a`,{href:`#/settings`,children:`settings`}),`.`]}):(0,F.jsx)(Jo,{root:e?.root,onCreated:async()=>{}})}function Jo({root:e,onCreated:t}){let[n,r]=(0,v.useState)(``),[i,a]=(0,v.useState)(``),[o,s]=(0,v.useState)(!1),[c,l]=(0,v.useState)(``),u=async e=>{e.preventDefault();let r=n.trim();if(r&&!o){s(!0),l(``);try{let e=await A.request(`projects.create`,{body:{title:r,goal:i.trim()}});if(!e.ok)throw Error(M(e));let n=e.data;B(`/projects/${encodeURIComponent(n.slug)}/info`),t()}catch(e){l(e.message)}finally{s(!1)}}};return(0,F.jsxs)(`form`,{className:`new-chat mx-auto flex w-full max-w-[640px] animate-rise flex-col gap-4`,onSubmit:e=>void u(e),children:[(0,F.jsx)(nt,{size:`lg`,children:`new project`}),(0,F.jsx)(J,{children:(0,F.jsxs)(vt,{className:`max-w-[680px]`,children:[(0,F.jsx)(Z,{label:`title`,children:(0,F.jsx)(X,{value:n,placeholder:`e.g. Relaunch netnode.ch`,"aria-label":`project title`,autoFocus:!0,onChange:e=>r(e.target.value)})}),(0,F.jsx)(Z,{label:`goal (one line)`,children:(0,F.jsx)(X,{value:i,placeholder:`e.g. Ship the new site on NodeHive by November`,"aria-label":`project goal`,onChange:e=>a(e.target.value)})}),(0,F.jsx)(`div`,{children:(0,F.jsx)(V,{variant:`primary`,type:`submit`,icon:`add`,busy:o,disabled:!n.trim(),children:o?`creating…`:`create project`})}),c&&(0,F.jsx)(q,{tone:`bad`,children:c}),(0,F.jsxs)(G,{children:[`One folder each under `,(0,F.jsx)(`code`,{title:e,children:e}),` with project.yml, brief.md, state.md and log.md; part of the workspace, commit it from the git screen. Chats opened in the project carry all of it as context.`]})]})})]})}function Yo({slug:e,title:t}){let[n,r]=(0,v.useState)(!1);return(0,v.useEffect)(()=>{let t=!0;return r(!1),A.call(`chats.list`).then(n=>{if(!t)return;let i=n.chats.find(t=>t.scope.kind===`project`&&t.scope.slug===e);i?B(`/projects/${encodeURIComponent(e)}/chat/${i.id}`,{replace:!0}):r(!0)}).catch(()=>t&&r(!0)),()=>{t=!1}},[e]),n?(0,F.jsx)(Xo,{slug:e,title:t}):(0,F.jsx)(K,{children:`loading…`})}function Xo({slug:e,title:t}){let[n,r]=(0,v.useState)(null),[i,a]=(0,v.useState)(!1);(0,v.useEffect)(()=>{let t=!0;return A.call(`projects.get`,{slug:e}).then(e=>t&&r(e)).catch(()=>{}),()=>{t=!1}},[e]);let o=Vo.find(e=>e.id===n?.harness)??Vo[0];return(0,F.jsxs)(it,{width:`narrow`,children:[(0,F.jsxs)(nt,{size:`lg`,children:[ze.emoji,` `,ze.name,` · `,t]}),(0,F.jsxs)(J,{title:`runs on`,children:[(0,F.jsx)(`div`,{className:`p-4`,children:(0,F.jsxs)(`button`,{type:`button`,className:`flex w-full cursor-pointer flex-col gap-0.5 rounded-card border border-transparent bg-accent-soft px-3.5 py-3 text-left text-on-accent-soft transition-[filter] hover:enabled:brightness-[0.97] disabled:cursor-default disabled:opacity-60`,disabled:i||!n,onClick:async()=>{a(!0),await Po(o.id,{kind:`project`,slug:e}),a(!1)},children:[(0,F.jsx)(`b`,{className:`text-base font-medium`,children:i?`starting…`:`start chat`}),(0,F.jsx)(`span`,{className:`text-xs`,children:n?`${Ho(n)} — ${o.hint}`:`…`})]})}),(0,F.jsxs)(G,{className:`px-[18px] pb-3.5`,children:[`The chat starts with the project's brief, state, systems of record and links as context. Harness, model and effort are set on the `,(0,F.jsx)(he,{href:`/projects/${encodeURIComponent(e)}/info`,children:`project page`}),`, like an agent's.`]})]})]})}function Zo({chatId:e,title:t,goal:n}){let[r,i]=(0,v.useState)(null),[a,o]=(0,v.useState)(!1),[s,c]=(0,v.useState)(0);(0,v.useEffect)(()=>{let t=!0;return A.call(`chats.get`,{id:e}).then(e=>t&&i(e.meta.scope)).catch(()=>t&&o(!0)),()=>{t=!1}},[e,s]);let l=r?.kind===`channel`?r.slug:void 0,u=N(`channels.list`,l?{}:null,{interval:4e3}),d=N(`agents.list`,l?{}:null,{interval:8e3});if(a)return(0,F.jsx)(K,{icon:`chat_error`,children:`chat not found`});if(!r)return(0,F.jsx)(K,{children:`loading…`});if(l){let t=u?.channels.find(e=>e.slug===l);return u?t?(0,F.jsx)(jo,{id:e,channel:t,agents:d?.agents??[]},`${e}:channel`):(0,F.jsxs)(K,{icon:`forum`,children:[`channel #`,l,` is gone — its definition under channels/ was removed`]}):(0,F.jsx)(K,{children:`loading…`})}return(0,F.jsx)(jo,{id:e,agentName:t,agentDescription:n,onConverted:()=>c(e=>e+1)},`${e}:${s}`)}function Qo({slug:e,chatId:t}){let[n,r]=(0,v.useState)(!1),i=(0,v.useCallback)(t=>Uo(t,e),[e]),a=(0,v.useCallback)(t=>Wo(t,e),[e]);return(0,F.jsx)(Ga,{storeKey:`project:${e}`,label:`chats`,fallbackTitle:`new chat`,chatId:t,filter:i,hrefOf:a,closeHref:`/projects/${encodeURIComponent(e)}/chat/new`,subOf:e=>e.scope.kind===`channel`?`with coworkers · #${e.scope.slug}`:e.agent,actions:(0,F.jsx)(La,{busy:n,onClick:async()=>{r(!0),await Po(`claude`,{kind:`project`,slug:e}),r(!1)}})})}var $o=[{kind:`knowledge`,label:`knowledge`,icon:`menu_book`,href:e=>`/knowledge/${encodeURIComponent(e)}`},{kind:`vibeables`,label:`apps`,icon:`web`,href:e=>`/vibeables/${encodeURIComponent(e)}`},{kind:`repos`,label:`repositories`,icon:`source`},{kind:`workflows`,label:`workflows`,icon:`account_tree`,href:e=>`/workflows/${encodeURIComponent(e)}`},{kind:`agents`,label:`agents`,icon:`groups`,href:e=>`/agents/${encodeURIComponent(e)}`}];function es({slug:e,onChanged:t}){let[n,r]=(0,v.useState)(null),[i,a]=(0,v.useState)(!1),[o,s]=(0,v.useState)(``),[c,l]=(0,v.useState)(!1),[u,d]=(0,v.useState)(!1),[f,p]=(0,v.useState)(!1),[m,h]=(0,v.useState)(``),[g,_]=(0,v.useState)(``),[y,b]=(0,v.useState)(`active`),[x,S]=(0,v.useState)(`claude`),[C,w]=(0,v.useState)(``),[T,E]=(0,v.useState)(``),[D,O]=(0,v.useState)(``),[k,j]=(0,v.useState)(``),[ee,M]=(0,v.useState)(!1),[N,P]=(0,v.useState)(``),te=be(),ne=e=>{r(e),h(e.title),_(e.goal),b(e.status),S(e.harness),w(e.model??``),E(e.effort??``),O(e.brief),j(e.state),M(!1)};(0,v.useEffect)(()=>{let t=!0;return A.call(`projects.get`,{slug:e}).then(e=>t&&ne(e)).catch(()=>t&&a(!0)),()=>{t=!1}},[e]);let I=()=>{M(!0),d(!1),s(``)},L=async(n,i={})=>{l(!0),s(``);try{let a=await Go(e,n);i.keepEdits?r(a):ne(a),d(!i.keepEdits),await t()}catch(e){s(e.message)}finally{l(!1)}},re=async()=>{l(!0);try{let n=await A.request(`projects.delete`,{slug:e});if(!n.ok)throw Error(n.error||`failed`);await t(),B(`/`,{replace:!0})}catch(e){s(e.message),l(!1)}},ie=async()=>{let t=N.trim();if(t){l(!0),s(``);try{let n=await A.request(`projects.log`,{slug:e,body:{entry:t}});if(!n.ok)throw Error(n.error||`failed`);let i=n.data;P(``),r(e=>e&&{...e,log:i.log??e.log})}catch(e){s(e.message)}finally{l(!1)}}};return i?(0,F.jsx)(K,{icon:`folder_off`,children:`project not found`}):n?(0,F.jsxs)(`div`,{className:`chat-main project-page flex flex-col gap-3`,children:[(0,F.jsxs)(`div`,{className:`flex flex-none flex-wrap items-center gap-x-4 gap-y-2`,children:[(0,F.jsx)(at,{children:(0,F.jsx)(`span`,{"aria-hidden":!0,children:`📁`})}),(0,F.jsx)(nt,{size:`lg`,children:n.title}),(0,F.jsx)(W,{tone:Ro[n.status],children:n.status}),(0,F.jsx)(W,{title:`harness · model · effort every chat in this project runs on`,children:Ho(n)}),te&&(0,F.jsx)(`span`,{className:`min-w-0 truncate font-mono text-xs text-fg-2`,title:n.path,children:n.path})]}),n.configError&&(0,F.jsxs)(q,{tone:`bad`,children:[`project.yml: `,n.configError]}),(0,F.jsx)(J,{title:`project`,className:`flex-none`,actions:(0,F.jsxs)(F.Fragment,{children:[u&&!ee&&(0,F.jsx)(`span`,{className:`text-xs text-fg-2`,children:`saved`}),(0,F.jsx)(V,{variant:`primary`,size:`sm`,busy:c,disabled:!ee,onClick:()=>void L({title:m,goal:g,status:y,harness:x,model:C,effort:T,brief:D,state:k}),children:c?`saving…`:`save changes`})]}),children:(0,F.jsxs)(vt,{className:`max-w-[680px]`,children:[(0,F.jsxs)(yt,{children:[(0,F.jsx)(Z,{label:`title`,className:`flex-1`,children:(0,F.jsx)(X,{value:m,"aria-label":`title`,onChange:e=>{h(e.target.value),I()}})}),(0,F.jsx)(Z,{label:`status`,children:(0,F.jsx)(_t,{value:y,"aria-label":`status`,onChange:e=>{b(e.target.value),I()},children:Io.map(e=>(0,F.jsx)(`option`,{value:e,children:e},e))})})]}),(0,F.jsxs)(yt,{children:[(0,F.jsx)(Z,{label:`harness`,className:`w-[140px] max-[940px]:w-auto`,children:(0,F.jsx)(_t,{value:x,"aria-label":`harness`,onChange:e=>{S(e.target.value),I()},children:Vo.map(e=>(0,F.jsx)(`option`,{value:e.id,children:e.label},e.id))})}),(0,F.jsx)(Z,{label:`model`,className:`flex-1`,children:(0,F.jsx)(X,{value:C,"aria-label":`model`,placeholder:`harness default — e.g. sonnet, gpt-5.6-sol`,onChange:e=>{w(e.target.value),I()}})}),(0,F.jsx)(Z,{label:`effort`,className:`w-[140px] max-[940px]:w-auto`,children:(0,F.jsx)(_t,{value:T,"aria-label":`effort`,onChange:e=>{E(e.target.value),I()},children:qe.map(e=>(0,F.jsx)(`option`,{value:e,children:e||`default`},e))})})]}),(0,F.jsx)(Z,{label:`goal (one line)`,children:(0,F.jsx)(X,{value:g,"aria-label":`goal`,placeholder:`what the project is for`,onChange:e=>{_(e.target.value),I()}})}),(0,F.jsx)(Z,{label:`brief.md — what done looks like, constraints, stakeholders`,children:(0,F.jsx)(gt,{rows:10,className:`resize-y font-mono text-sm`,value:D,"aria-label":`brief`,onChange:e=>{O(e.target.value),I()}})}),(0,F.jsx)(Z,{label:`state.md — current state, rewritten at the end of a session`,children:(0,F.jsx)(gt,{rows:6,className:`resize-y font-mono text-sm`,value:k,"aria-label":`state`,onChange:e=>{j(e.target.value),I()}})}),o&&(0,F.jsx)(q,{tone:`bad`,children:o})]})}),(0,F.jsx)(as,{records:n.records,saving:c,onSave:e=>L({records:e},{keepEdits:!0})}),(0,F.jsx)(J,{title:`links`,className:`flex-none`,actions:(0,F.jsx)(`span`,{className:`text-xs text-fg-2`,children:`by name; a target that is missing in this workspace is marked`}),children:(0,F.jsx)(ct,{children:$o.map(i=>(0,F.jsx)(rs,{kind:i.kind,label:i.label,icon:i.icon,href:i.href,links:n.links[i.kind],saving:c,onChange:(n,a)=>void ts(e,i.kind,n,a,e=>{r(e),t()},s)},i.kind))})}),(0,F.jsxs)(J,{title:`log`,className:`flex-none`,children:[(0,F.jsx)(vt,{className:`max-w-[680px]`,children:(0,F.jsxs)(yt,{children:[(0,F.jsx)(Z,{label:`new entry — a decision, a milestone`,className:`flex-1`,children:(0,F.jsx)(X,{value:N,"aria-label":`log entry`,placeholder:`e.g. Decided on NodeHive as the CMS`,onChange:e=>P(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),ie())}})}),(0,F.jsx)(V,{icon:`add`,disabled:c||!N.trim(),onClick:()=>void ie(),children:`log`})]})}),(0,F.jsx)(`div`,{className:`md-body h-auto overflow-visible px-[18px] pt-1 pb-4 text-sm [&_h1]:hidden [&_h2]:mt-3 [&_h2]:mb-1 [&_h2]:text-xs [&_ul]:m-0 [&_ul]:pl-[18px]`,dangerouslySetInnerHTML:{__html:da.sanitize(Fr.parse(n.log||`_no entries yet_`,{async:!1}))}})]}),(0,F.jsx)(J,{title:`danger zone`,className:`flex-none [&>div]:border-b-0`,actions:f?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(V,{size:`sm`,variant:`danger`,icon:`delete`,disabled:c,onClick:()=>void re(),children:`confirm delete`}),(0,F.jsx)(V,{size:`sm`,variant:`quiet`,onClick:()=>p(!1),children:`cancel`})]}):(0,F.jsx)(V,{size:`sm`,variant:`danger`,icon:`delete`,disabled:c,onClick:()=>p(!0),title:`Move the project, its files and log to the trash; #/trash puts it back`,children:`delete project`}),children:null})]}):(0,F.jsx)(K,{children:`loading…`})}async function ts(e,t,n,r,i,a){try{let a=await A.request(`projects.link`,{slug:e,body:{kind:t,target:n,remove:r}});if(!a.ok)throw Error(M(a));i(a.data)}catch(e){a(e.message)}}async function ns(e){switch(e){case`knowledge`:return(await A.call(`knowledge.list`)).bundles.map(e=>({slug:e.name,hint:`${e.concepts} concepts`}));case`vibeables`:return(await A.call(`vibeables.list`)).vibeables.map(e=>({slug:e.slug,hint:e.dev?`dev`:`static`}));case`repos`:return(await A.call(`repos.list`)).repos.map(e=>({slug:e.slug,hint:e.branch}));case`workflows`:return(await A.call(`workflows.list`)).workflows.map(e=>({slug:e.slug,hint:e.description??e.name}));case`agents`:return(await A.call(`agents.list`)).agents.filter(e=>!e.archived).map(e=>({slug:e.slug,hint:`${e.emoji} ${e.name}`}))}}function rs({kind:e,label:t,icon:n,href:r,links:i,saving:a,onChange:o}){let[s,c]=(0,v.useState)(!1),[l,u]=(0,v.useState)(null),[d,f]=(0,v.useState)(``);(0,v.useEffect)(()=>{if(!s||l)return;let t=!0;return ns(e).then(e=>t&&u(e)).catch(()=>t&&u([])),()=>{t=!1}},[s,l,e]);let p=new Set(i.map(e=>e.slug)),m=(l??[]).filter(e=>!p.has(e.slug));return(0,F.jsxs)(st,{icon:n,title:t,"data-link-kind":e,action:!s&&(0,F.jsx)(V,{size:`sm`,icon:`add`,onClick:()=>c(!0),children:`link`}),children:[i.length===0&&!s&&(0,F.jsx)(`span`,{className:`text-xs text-fg-2`,children:`none linked`}),i.length>0&&(0,F.jsx)(`span`,{className:`flex flex-wrap gap-1.5`,children:i.map(e=>(0,F.jsxs)(W,{tone:e.found?`neutral`:`bad`,title:e.found?e.label:`configured but not found in this workspace`,children:[r&&e.found?(0,F.jsx)(he,{href:r(e.slug),className:`text-inherit no-underline hover:underline`,children:e.slug}):e.slug,!e.found&&` · not found`,(0,F.jsx)(`button`,{type:`button`,className:`-mr-1 ml-1 inline-grid size-4 cursor-pointer place-items-center rounded-full border-0 bg-transparent p-0 text-inherit opacity-70 hover:bg-surface hover:opacity-100 disabled:cursor-default [&_.ms]:text-[13px]`,"aria-label":`unlink ${e.slug}`,disabled:a,onClick:()=>o(e.slug,!0),children:(0,F.jsx)(I,{name:`close`})})]},e.slug))}),s&&(0,F.jsx)(`span`,{className:`mt-1.5 flex flex-wrap items-center gap-2`,children:l===null?(0,F.jsx)(`span`,{className:`text-xs text-fg-2`,children:`loading…`}):(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(_t,{className:`w-auto max-w-full min-w-48 flex-1`,"aria-label":`link ${t}`,value:d,onChange:e=>f(e.target.value),children:[(0,F.jsx)(`option`,{value:``,children:m.length?`pick ${t}…`:`nothing to link`}),m.map(e=>(0,F.jsxs)(`option`,{value:e.slug,children:[e.slug,e.hint?` — ${e.hint}`:``]},e.slug))]}),(0,F.jsx)(V,{disabled:a||!d,onClick:()=>{o(d,!1),f(``),c(!1)},children:`link`}),(0,F.jsx)(V,{variant:`quiet`,onClick:()=>c(!1),children:`cancel`})]})})]})}var is={kind:`url`};function as({records:e,saving:t,onSave:n}){let[r,i]=(0,v.useState)(null),[a,o]=(0,v.useState)(!1),s=e=>i(t=>({...t??is,...e})),c=e=>{let t={kind:e.kind.trim().toLowerCase()||`url`};for(let n of[`title`,`url`,`workspace`,`note`]){let r=(e[n]??``).trim();r&&(t[n]=r)}return t};return(0,F.jsx)(J,{title:`systems of record`,className:`flex-none`,actions:(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`span`,{className:`text-xs text-fg-2`,children:`where the truth is managed outside kraftwerk — context for the agent, not a credential`}),!r&&(0,F.jsx)(V,{size:`sm`,icon:`add`,onClick:()=>i({...is}),children:`add`})]}),children:(0,F.jsxs)(ct,{children:[e.map((r,i)=>(0,F.jsx)(st,{"data-record-kind":r.kind,icon:`database`,title:(0,F.jsxs)(F.Fragment,{children:[Bo(r.kind),r.title&&(0,F.jsx)(`span`,{className:`text-xs font-normal text-fg-2`,children:r.title}),r.workspace&&(0,F.jsxs)(W,{children:[`workspace `,r.workspace]})]}),action:(0,F.jsx)(H,{icon:`close`,size:`sm`,label:`remove record ${r.title??r.kind}`,disabled:t,onClick:()=>void n(e.filter((e,t)=>t!==i))}),children:(r.url||r.note)&&(0,F.jsxs)(`span`,{className:`text-xs leading-normal text-fg-2`,children:[r.url&&(0,F.jsx)(`a`,{href:r.url,target:`_blank`,rel:`noreferrer`,children:r.url}),r.url&&r.note&&` — `,r.note]})},i)),e.length===0&&!r&&(0,F.jsx)(G,{className:`px-[18px] py-3`,children:`none yet — e.g. a my.netnode.ch workspace, a Google Drive folder, a board`}),r&&(0,F.jsxs)(vt,{className:`max-w-[680px]`,children:[(0,F.jsxs)(yt,{children:[(0,F.jsx)(Z,{label:`kind`,children:a?(0,F.jsx)(X,{value:r.kind,"aria-label":`record kind`,placeholder:`e.g. jira`,onChange:e=>s({kind:e.target.value})}):(0,F.jsxs)(_t,{value:r.kind,"aria-label":`record kind`,onChange:e=>{e.target.value===`__other`?(o(!0),s({kind:``})):s({kind:e.target.value})},children:[Object.entries(zo).map(([e,t])=>(0,F.jsx)(`option`,{value:e,children:t},e)),(0,F.jsx)(`option`,{value:`__other`,children:`other…`})]})}),(0,F.jsx)(Z,{label:`title`,className:`flex-1`,children:(0,F.jsx)(X,{value:r.title??``,"aria-label":`record title`,placeholder:`e.g. Contracts folder`,onChange:e=>s({title:e.target.value})})}),(0,F.jsx)(Z,{label:`workspace / id`,children:(0,F.jsx)(X,{value:r.workspace??``,"aria-label":`record workspace`,placeholder:`e.g. 22`,onChange:e=>s({workspace:e.target.value})})})]}),(0,F.jsx)(Z,{label:`url`,children:(0,F.jsx)(X,{value:r.url??``,"aria-label":`record url`,placeholder:`https://…`,onChange:e=>s({url:e.target.value})})}),(0,F.jsxs)(yt,{children:[(0,F.jsx)(Z,{label:`note — what lives there and how it is usually reached`,className:`flex-1`,children:(0,F.jsx)(X,{value:r.note??``,"aria-label":`record note`,placeholder:`e.g. tickets and roadmap; the my CLI`,onChange:e=>s({note:e.target.value})})}),(0,F.jsx)(V,{disabled:t||!r.kind.trim(),onClick:async()=>{await n([...e,c(r)]),i(null),o(!1)},children:`add record`}),(0,F.jsx)(V,{variant:`quiet`,onClick:()=>{i(null),o(!1)},children:`cancel`})]})]})]})})}async function os(e,t){let n=window.open(``,`_blank`);if(!n)return;let r=t?`${e}/${t}`:e;n.document.write(`<title>${us(r)}</title><body style="font-family:system-ui;padding:40px;color:#555">preparing ${us(r)}…</body>`);let i,a=``;try{let[n,r]=await Promise.all([t?Promise.resolve([t]):A.call(`knowledge.get`,{bundle:e}).then(e=>e.concepts.map(e=>e.id)),A.call(`meta.get`).catch(()=>({}))]);if(a=r.workspaceName??``,i=await Promise.all(n.map(t=>A.call(`knowledge.concept`,{bundle:e,query:{id:t}}))),i.some(e=>typeof e?.id!=`string`))throw Error(`missing concept`)}catch{n.document.body.textContent=`could not load "${r}"`;return}let o=[],s=i.map(e=>{let t=[e.type,e.generated?.at?`updated ${e.generated.at.slice(0,10)}`:``,e.trustTier===`human-reviewed`?`human-reviewed`:``,(e.tags??[]).map(e=>`#${e}`).join(` `)].filter(Boolean).join(` · `),{md:n,notes:r}=cs(ss(e.body??``,null)),i=!e.title||e.title===e.id||e.title===e.id.split(`/`).pop(),{html:a,title:s}=ls(da.sanitize(Fr.parse(n,{async:!1})),{title:e.title||e.id,meta:t,titleIsFallback:i});return o.push(s),`<article>
81
+ `).length)),onChange:e=>{l(e.target.value),w(0),E(!1)},onPaste:e=>{let t=Array.from(e.clipboardData.items).filter(e=>e.kind===`file`).map(e=>e.getAsFile()).filter(e=>!!e);t.length&&(e.preventDefault(),b(t))},onKeyDown:e=>{if(le){if(e.key===`ArrowDown`)return e.preventDefault(),w((ue+1)%ce.length);if(e.key===`ArrowUp`)return e.preventDefault(),w((ue-1+ce.length)%ce.length);if(e.key===`Tab`||e.key===`Enter`)return e.preventDefault(),ce[ue].pick();if(e.key===`Escape`)return e.preventDefault(),E(!0)}e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),de())}}),t&&(0,F.jsx)(V,{size:`sm`,variant:`danger`,icon:`stop`,className:`mr-1 self-center`,onClick:()=>A.request(`chats.cancel`,{id:e}).catch(()=>{}),children:`stop`}),!te&&(0,F.jsx)(H,{icon:`attach_file`,label:`attach files (or drop / paste them)`,className:`size-9 rounded-full [&_.ms]:text-[20px]`,onClick:()=>M.current?.click()}),(0,F.jsx)(`input`,{ref:M,type:`file`,multiple:!0,hidden:!0,onChange:e=>{e.target.files?.length&&b(e.target.files),e.target.value=``}}),!te&&(0,F.jsx)(`button`,{type:`button`,className:`inline-grid size-9 flex-none cursor-pointer place-items-center rounded-full border-0 bg-accent p-0 text-on-accent transition-[filter,opacity] hover:enabled:brightness-110 active:enabled:scale-95 disabled:cursor-default disabled:opacity-30`,disabled:!c.trim()&&p.length===0||h>0,onClick:de,"aria-label":N?`steer`:`send`,title:N?`steer: hand this into the running turn (Enter)`:`send (Enter)`,children:(0,F.jsx)(I,{name:N?`alt_route`:`send`,className:`text-[19px]`})})]})]})}var Ao=`inline-flex items-center gap-1.5 rounded-full border border-line bg-surface-2 px-2 py-0.5 text-2xs text-fg-2`;function $({id:e,live:t}){let n=be(),[r,i]=(0,v.useState)(null),a=t.config.filter(e=>e.category===`model`||e.category===`thought_level`);async function o(t,n){i(t.id);let r=await A.request(`chats.config`,{id:e,body:{configId:t.id,value:n}}).catch(()=>null);i(null),r&&!r.ok&&alert(r.error??`setting refused (${r.status})`)}return(0,F.jsxs)(F.Fragment,{children:[t.auth?.kind===`none`&&(0,F.jsx)(`span`,{title:[t.auth.detail,t.auth.email,t.auth.organization,t.auth.plan].filter(Boolean).join(` · `),children:(0,F.jsxs)(W,{tone:t.auth.kind===`none`?`bad`:`neutral`,children:[(0,F.jsx)(I,{name:t.auth.kind===`none`?`person_off`:`person`,className:`ms-sm mr-1`}),` `,t.auth.email??t.auth.label]})}),n&&t.usage&&t.usage.size>0&&(0,F.jsx)(`span`,{className:`font-mono`,title:`${t.usage.used.toLocaleString()} of ${t.usage.size.toLocaleString()} context tokens${t.usage.costUsd==null?``:` · $${t.usage.costUsd.toFixed(2)} so far`}`,children:(0,F.jsxs)(W,{children:[Math.round(100*t.usage.used/t.usage.size),`% ctx`,t.usage.costUsd!=null&&` · $${t.usage.costUsd.toFixed(2)}`]})}),n&&a.map(e=>e.type===`select`?(0,F.jsx)(_t,{className:`h-7 w-auto max-w-[22ch] px-2 pr-6 text-xs text-fg-2`,value:e.value,disabled:r===e.id,title:e.description??e.name,"aria-label":e.name,onChange:t=>o(e,t.target.value),children:e.choices.map(e=>(0,F.jsxs)(`option`,{value:e.value,title:e.description,children:[e.group?`${e.group} · `:``,e.name]},e.value))},e.id):(0,F.jsxs)(`label`,{className:`inline-flex cursor-pointer items-center gap-1 text-xs text-fg-2`,title:e.description??e.name,children:[(0,F.jsx)(`input`,{type:`checkbox`,className:`accent-accent`,checked:e.value,disabled:r===e.id,onChange:t=>o(e,t.target.checked)}),` `,e.name]},e.id))]})}function jo({id:e,agentName:t,agentDescription:n,channel:r,agents:i,onConverted:a}){let[o,s]=(0,v.useState)(null),c=N(`chats.list`,{})?.chats.find(t=>t.id===e)?.title;(0,v.useEffect)(()=>{c!==void 0&&s(e=>e&&e.title!==c?{...e,title:c}:e)},[c]);let[l,u]=(0,v.useState)([]),[d,f]=(0,v.useState)(!1),[p,m]=(0,v.useState)(!1),[h,g]=(0,v.useState)(!1),[_,y]=(0,v.useState)(null),[b,x]=(0,v.useState)(null),S=we(),C=be(),w=N(`agents.list`,r?null:{},{interval:3e4})?.agents??[],T=o?.vibeable&&S.vibeables?o.vibeable:null,[E,D]=(0,v.useState)(null);(0,v.useEffect)(()=>T?(ha({chatId:e,slug:T}),D(document.getElementById(ma)),()=>ha(null)):D(null),[e,T]);let O=(0,v.useMemo)(()=>Qa(l),[l]);(0,v.useEffect)(()=>{let t=!0,n;return A.call(`chats.get`,{id:e}).then(r=>{if(!t)return;s(r.meta),u(r.events);let i=r.events[r.events.length-1]?.seq??0;n=ee.subscribe(`chat.${e}`,{after:i},e=>{let t=e;u(e=>e.some(e=>e.seq===t.seq)?e:[...e,t])})}).catch(()=>t&&f(!0)),()=>{t=!1,n?.()}},[e]);let k=(0,v.useMemo)(()=>{if(!r)return[];let e=new Set;for(let t of l)t.from?.kind===`agent`&&(t.type===`turn_start`&&e.add(t.from.slug),(t.type===`turn_end`||t.type===`error`)&&e.delete(t.from.slug));return[...e]},[l,r]),j=(0,v.useMemo)(()=>{if(r)return k.length>0;for(let e=l.length-1;e>=0;e--){let t=l[e].type;if(t===`user_message`)return!0;if(t===`turn_end`||t===`error`)return!1}return!1},[l,r,k]),M=(0,v.useMemo)(()=>{if(o?.title)return o.title;let e=l.find(e=>e.type===`user_message`);return e&&e.type===`user_message`?e.text.replace(/\s+/g,` `).trim().slice(0,80):``},[o,l]);if((0,v.useEffect)(()=>o?r?(le(`#${r.slug} · ${r.name}`),()=>le(``)):(le([t??(o.scope.kind===`agent`?o.scope.slug:o.agent),n,M||`new chat`].filter(Boolean).join(` · `)),()=>le(``)):void 0,[o,M,t,n,r]),d)return(0,F.jsx)(K,{icon:`chat_error`,children:`chat not found`});if(!o)return(0,F.jsx)(K,{children:`loading…`});let te=new Map((i??[]).map(e=>[e.slug,e]));if(r)return(0,F.jsxs)(`div`,{className:`chat-thread flex min-h-0 w-full flex-1 animate-rise flex-col`,children:[(0,F.jsxs)(`div`,{className:`channel-head flex flex-none flex-wrap items-center gap-x-3 gap-y-2 pb-1.5`,children:[(0,F.jsx)(U,{tone:j?`working`:`ok`}),(0,F.jsxs)(nt,{children:[`#`,r.slug]}),(0,F.jsx)(`span`,{className:`text-md text-fg-2`,children:r.name}),(0,F.jsx)(`span`,{className:`flex-1`}),k.length>0&&(0,F.jsxs)(V,{size:`sm`,variant:`danger`,icon:`stop`,title:`interrupt every agent working in this channel`,onClick:()=>Ya(e),children:[`stop all (`,k.length,`)`]}),(0,F.jsx)(V,{size:`sm`,icon:`tune`,href:`/channels/${encodeURIComponent(r.slug)}/edit`,title:`members, purpose, responder`,children:`members`})]}),(0,F.jsxs)(`div`,{className:`channel-members flex flex-none flex-wrap items-center gap-x-2.5 gap-y-2 pb-3`,children:[r.purpose&&(0,F.jsx)(`span`,{className:`channel-purpose w-full text-sm text-fg-2`,children:r.purpose}),r.members.map(t=>{let n=te.get(t),i=k.includes(t),a=Za(l,t);return(0,F.jsxs)(`div`,{className:P(`member-chip inline-flex items-center gap-1 rounded-full py-[3px] pr-1.5 pl-[3px] text-sm transition-colors`,i?`bg-accent-soft`:`bg-surface-2`,b===t&&`outline-2 outline-accent`),title:n?.description,children:[(0,F.jsxs)(`button`,{type:`button`,className:`flex min-w-0 cursor-pointer items-center gap-2 border-0 bg-transparent p-0 text-left font-[inherit] text-inherit`,onClick:()=>x(b===t?null:t),title:b===t?`back to the channel`:`look at @${t}'s session`,children:[(0,F.jsxs)(`span`,{className:`relative grid size-7 flex-none place-items-center rounded-full bg-surface text-[15px]`,children:[(0,F.jsx)(`span`,{"aria-hidden":!0,children:n?.emoji??`🤖`}),(0,F.jsx)(`span`,{className:`absolute -right-0.5 -bottom-0.5 grid rounded-full bg-surface p-px`,children:(0,F.jsx)(U,{tone:i?`working`:`idle`})})]}),(0,F.jsxs)(`span`,{className:`flex min-w-0 flex-col gap-px`,children:[(0,F.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,F.jsx)(`span`,{className:`font-medium text-fg`,children:n?.name??t}),(0,F.jsxs)(`span`,{className:`member-handle font-mono text-2xs text-fg-2`,children:[`@`,t]}),r.responder===t&&(0,F.jsx)(W,{children:`responder`})]}),(a.task||a.now)&&(0,F.jsx)(`span`,{className:`max-w-[44ch] truncate text-2xs text-fg-2`,children:i?a.now?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(et,{className:`mr-1`,children:`now`}),` `,a.now]}):(0,F.jsxs)(F.Fragment,{children:[`working on: `,a.task]}):(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(et,{className:`mr-1`,children:`last`}),` `,a.task]})})]})]}),i&&(0,F.jsx)(H,{icon:`stop`,label:`interrupt @${t}`,variant:`danger`,size:`sm`,className:`size-6`,onClick:()=>Ya(e,t)}),(0,F.jsx)(H,{icon:`info`,label:`agent definition`,size:`sm`,className:`size-6`,href:`/agents/${encodeURIComponent(t)}/info`})]},t)})]}),b&&(0,F.jsxs)(`div`,{className:`flex flex-none items-center gap-2.5 border-b border-line py-1.5 text-sm`,children:[(0,F.jsx)(V,{size:`sm`,variant:`quiet`,icon:`arrow_back`,onClick:()=>x(null),children:`channel`}),(0,F.jsxs)(`span`,{className:`min-w-0 truncate text-fg-2`,children:[te.get(b)?.emoji??`🤖`,` @`,b,`'s session — everything this agent did, tools included`]}),(0,F.jsx)(`span`,{className:`flex-1`}),k.includes(b)&&(0,F.jsxs)(V,{size:`sm`,variant:`danger`,icon:`stop`,onClick:()=>Ya(e,b),children:[`stop @`,b]})]}),(0,F.jsxs)($a.Provider,{value:e=>{let t=e?.kind===`agent`?te.get(e.slug):void 0;return e?.kind===`agent`?`${t?.emoji??`🤖`} ${t?.name??e.slug}`:`The agent`},children:[(0,F.jsx)(bo,{id:e,events:l,busy:j,channel:r,agentMap:te,working:k,focus:b??void 0}),(0,F.jsx)(ko,{id:e,busy:j,scope:o.scope,channel:r,agentMap:te})]})]});let ne=o.scope.kind===`agent`&&!o.scope.routine||o.scope.kind===`project`,I=O.auth?.kind===`none`;return(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(`div`,{className:`chat-thread flex min-h-0 w-full flex-1 animate-rise flex-col`,children:[o.scope.kind===`agent`&&!o.scope.routine&&(0,F.jsx)(Wa,{children:(0,F.jsx)(No,{id:e,project:o.project,onFiled:e=>s(t=>t&&{...t,project:e})})}),ne&&(0,F.jsx)(Wa,{children:(0,F.jsx)(H,{size:`sm`,icon:`group_add`,label:`add coworker`,title:o.scope.kind===`project`?`add coworker: turn this chat into a channel of the project and invite agents`:`add coworker: turn this chat into a channel and invite more agents`,onClick:()=>m(!0),disabled:j})}),(C||I)&&(0,F.jsxs)(`div`,{className:`flex flex-none flex-wrap items-center gap-x-2.5 gap-y-1.5 pb-1.5`,children:[C&&o.agent!==`pi`&&o.sessions?.main&&(0,F.jsx)(V,{size:`sm`,variant:`quiet`,icon:`call_split`,busy:h,className:o.agent===`codex`?`opacity-50`:void 0,disabled:j,"aria-disabled":o.agent===`codex`,title:o.agent===`codex`?`not supported: codex has no session fork`:`Branch this conversation: a new chat with the same history, the original stays as it is`,onClick:async()=>{if(o.agent===`codex`)return y(`fork is not supported by codex`);g(!0);let t=await A.request(`chats.fork`,{id:e});if(g(!1),!t.ok||!t.data?.id)return alert(t.error??`fork failed (${t.status})`);let n=t.data;B(n.scope?.kind===`agent`?`/agents/${encodeURIComponent(n.scope.slug)}/chat/${n.id}`:`/agents/chats/${n.id}`)},children:h?`forking…`:`fork`}),C&&_&&(0,F.jsx)(`span`,{className:`text-2xs text-fg-2`,children:_}),C&&(0,F.jsx)(`span`,{className:`max-[800px]:hidden`,children:(0,F.jsx)(W,{children:o.agent})}),(0,F.jsx)($,{id:e,live:O}),C&&o.scope.kind===`run`&&(0,F.jsx)(Mo,{href:`/runs/${o.scope.runId}`,children:o.scope.runId}),C&&o.scope.kind===`kraftwerk`&&(0,F.jsx)(W,{children:`kraftwerk-aware`}),C&&o.scope.kind===`knowledge`&&(0,F.jsxs)(Mo,{href:o.scope.bundle?`/knowledge/${encodeURIComponent(o.scope.bundle)}`:`/knowledge`,children:[`knowledge`,o.scope.bundle?`:${o.scope.bundle}`:``]}),C&&o.scope.kind===`agent`&&(0,F.jsx)(`span`,{className:`max-[800px]:hidden`,children:(0,F.jsxs)(Mo,{href:`/agents/${encodeURIComponent(o.scope.slug)}/info`,children:[`agent:`,o.scope.slug]})}),C&&(0,F.jsx)(`span`,{className:`rid max-w-[34ch] min-w-0 truncate font-mono text-xs text-fg-2 max-[800px]:hidden`,title:o.cwd,children:o.cwd})]}),o.vibeable&&!S.vibeables&&(0,F.jsx)(Ca,{chatId:e,slug:o.vibeable,onClosed:s}),(0,F.jsxs)($a.Provider,{value:()=>no(o.scope,w,t),children:[(0,F.jsx)(bo,{id:e,events:l,busy:j}),(0,F.jsx)(ko,{id:e,busy:j,scope:o.scope,commands:O.commands,canSteer:o.agent!==`pi`,account:O.auth&&O.auth.kind!==`none`?O.auth.email??O.auth.label:void 0})]})]}),T&&E&&(0,fa.createPortal)((0,F.jsx)(_a,{chatId:e,slug:T,agentBusy:j,onClosed:s},T),E),p&&o.scope.kind===`agent`&&(0,F.jsx)(Ma,{chatId:e,agentSlug:o.scope.slug,title:M,onClose:()=>m(!1)}),p&&o.scope.kind===`project`&&(0,F.jsx)(Ma,{chatId:e,project:o.scope.slug,title:M||t||``,onClose:()=>m(!1),onCreated:a})]})}function Mo({href:e,children:t}){return(0,F.jsx)(he,{href:e,className:`no-underline hover:opacity-80`,children:(0,F.jsx)(W,{children:t})})}function No({id:e,project:t,onFiled:n}){let r=N(`projects.list`,{},{interval:6e4}),[i,a]=(0,v.useState)(!1),o=r?.enabled===!1?[]:r?.projects??[];return!o.length&&!t?null:(0,F.jsxs)(`label`,{className:`inline-flex items-center gap-1 text-fg-2`,title:`file this chat under a project: the agent works in its context`,children:[(0,F.jsx)(I,{name:`folder`,className:`ms-sm`}),(0,F.jsxs)(_t,{"aria-label":`project`,className:`h-7 w-auto max-w-[180px] py-0 pl-2 text-sm`,value:t??``,disabled:i,onChange:async t=>{let r=t.target.value||null;a(!0);let i=await A.request(`chats.setProject`,{id:e,body:{project:r}}).catch(()=>null);a(!1),i?.ok&&n(r??void 0)},children:[(0,F.jsx)(`option`,{value:``,children:`no project`}),o.map(e=>(0,F.jsx)(`option`,{value:e.slug,children:e.title},e.slug))]})]})}var Po=[{id:`claude`,label:`claude`,hint:`Claude Code via ACP`},{id:`codex`,label:`codex`,hint:`Codex (ChatGPT) via ACP`},{id:`pi`,label:`pi`,hint:`pi coding agent`}];async function Fo(e,t,n,r){let i=await A.request(`chats.create`,{body:{agent:e,scope:t,...n?{resume:n}:{},...r?{project:r}:{}}}),a=i.ok?i.data:null;a?.id&&B(a.project?`/projects/${encodeURIComponent(a.project)}/chat/${a.id}`:a.scope?.kind===`agent`?`/agents/${encodeURIComponent(a.scope.slug)}/chat/${a.id}`:a.scope?.kind===`project`?`/projects/${encodeURIComponent(a.scope.slug)}/chat/${a.id}`:`/agents/chats/${a.id}`)}function Io(){let[e,t]=(0,v.useState)(`claude`),[n,r]=(0,v.useState)(!0),[i,a]=(0,v.useState)(!1),[o,s]=(0,v.useState)(null);return(0,v.useEffect)(()=>s(null),[e]),(0,F.jsxs)(it,{width:`narrow`,children:[(0,F.jsx)(nt,{children:`new chat`}),(0,F.jsxs)(J,{title:`agent`,children:[(0,F.jsx)(`div`,{className:`grid grid-cols-3 gap-2.5 p-4 max-[940px]:grid-cols-1`,children:Po.map(n=>{let r=e===n.id;return(0,F.jsxs)(`button`,{type:`button`,"aria-pressed":r,className:P(`flex cursor-pointer flex-col gap-0.5 rounded-card border px-3.5 py-3 text-left transition-colors`,r?`border-transparent bg-accent-soft text-on-accent-soft`:`border-line bg-transparent text-fg hover:bg-surface-2`),onClick:()=>t(n.id),children:[(0,F.jsx)(`b`,{className:`text-base font-medium`,children:n.label}),(0,F.jsx)(`span`,{className:P(`text-xs`,r?`text-on-accent-soft`:`text-fg-2`),children:n.hint})]},n.id)})}),(0,F.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 px-4 pb-3.5 text-sm text-fg-2`,children:[(0,F.jsx)(`input`,{type:`checkbox`,className:`size-[15px] accent-accent`,checked:n,onChange:e=>r(e.target.checked)}),(0,F.jsx)(`span`,{className:`text-fg`,children:`kraftwerk-aware`}),` — agent gets workflows + recent runs as context`]}),(0,F.jsx)(`div`,{className:`px-4 pb-4`,children:(0,F.jsx)(V,{variant:`primary`,busy:i,onClick:async()=>{a(!0),await Fo(e,{kind:n?`kraftwerk`:`general`}),a(!1)},children:i?`starting…`:`start chat`})})]}),e!==`pi`&&(0,F.jsxs)(J,{title:`continue a session`,actions:o===null&&(0,F.jsxs)(V,{size:`sm`,variant:`quiet`,icon:`history`,onClick:async()=>{s(`loading`);let t=await A.call(`agents.sessions`,{query:{agent:e}}).catch(()=>({sessions:[]}));s((t.sessions??[]).slice(0,20))},children:[`list `,e,` sessions`]}),children:[o===null&&(0,F.jsxs)(K,{className:`py-6`,children:[`Pick up a `,e,` session started outside kraftwerk.`]}),o===`loading`&&(0,F.jsxs)(K,{className:`py-6`,children:[`asking `,e,`…`]}),Array.isArray(o)&&o.length===0&&(0,F.jsxs)(K,{className:`py-6`,children:[`no `,e,` sessions in this project`]}),Array.isArray(o)&&o.length>0&&(0,F.jsx)(`div`,{className:`flex flex-col p-1.5`,children:o.map(t=>(0,F.jsx)(Y,{size:`sm`,title:t.title||t.sessionId.slice(0,8),meta:t.updatedAt&&new Date(t.updatedAt).toLocaleString(),innerProps:{title:t.sessionId},onClick:async()=>{i||(a(!0),await Fo(e,{kind:n?`kraftwerk`:`general`},t.sessionId),a(!1))}},t.sessionId))})]})]})}var Lo=[`active`,`paused`,`done`,`archived`],Ro={active:`working`,paused:`idle`,done:`ok`,archived:`idle`},zo={active:`accent`,paused:`neutral`,done:`ok`,archived:`neutral`},Bo={"my-netnode":`my.netnode.ch`,"google-drive":`Google Drive`,github:`GitHub`,bitbucket:`Bitbucket`,notion:`Notion`,slack:`Slack`,url:`Link`},Vo=e=>Bo[e]??e,Ho=[{id:`claude`,label:`claude`,hint:`Claude Code via ACP`},{id:`codex`,label:`codex`,hint:`Codex (ChatGPT) via ACP`},{id:`pi`,label:`pi`,hint:`pi coding agent`}],Uo=e=>[e.harness,e.model,e.effort?`effort ${e.effort}`:``].filter(Boolean).join(` · `),Wo=(e,t)=>(e??[]).filter(e=>e.scope.kind===`project`&&e.scope.slug===t||e.project===t),Go=(e,t)=>`/projects/${encodeURIComponent(t)}/chat/${e.id}`;async function Ko(e,t){let n=await A.request(`projects.save`,{slug:e,body:t});if(!n.ok)throw Error(M(n));return n.data}function qo({seg:e}){let t=e[0]&&e[0]!==`new`?decodeURIComponent(e[0]):void 0,n=e[0]===`new`?`new`:e[1]===`info`?`info`:e[1]===`chat`?`chat`:t?`project`:`home`,r=n===`chat`?e[2]:void 0,[i,a]=(0,v.useState)(null),[o,s]=(0,v.useState)(``),c=be(),l=Ra(),u=(0,v.useCallback)(async()=>{try{let e=await A.request(`projects.list`);if(!e.ok)throw Error(`HTTP ${e.status}`);a(e.data),s(``)}catch(e){s(e.message||`could not load projects`)}},[]);(0,v.useEffect)(()=>{let e=!0,t,n=async()=>{await u(),e&&(t=setTimeout(n,15e3))};return n(),()=>{e=!1,clearTimeout(t)}},[u]),(0,v.useEffect)(()=>{u()},[t,n,u]);let d=i?.projects??[],f=t?d.find(e=>e.slug===t):void 0,p=[...d].sort((e,t)=>(t.updatedAt??``).localeCompare(e.updatedAt??``))[0]?.slug;(0,v.useEffect)(()=>{n===`home`&&p&&B(`/projects/${encodeURIComponent(p)}`,{replace:!0})},[n,p]);let m;return m=i&&!i.enabled?(0,F.jsx)(K,{icon:`folder_off`,children:i.error&&!/are off/.test(i.error)?(0,F.jsx)(`span`,{className:`text-bad`,children:i.error}):(0,F.jsxs)(F.Fragment,{children:[`Projects are off. Turn them on in `,(0,F.jsx)(`a`,{href:`#/settings`,children:`settings`}),` or add a `,(0,F.jsx)(`code`,{children:`projects:`}),` block to kraftwerk.yml.`]})}):i?n===`new`||n===`home`&&d.length===0?(0,F.jsx)(Yo,{root:i.root,onCreated:u}):n===`home`?(0,F.jsx)(K,{children:`loading…`}):t&&!f?(0,F.jsxs)(K,{icon:`folder_off`,children:[`no project named `,t]}):n===`chat`&&t&&r===`new`?(0,F.jsx)(Zo,{slug:t,title:f?.title??t},t):n===`chat`&&t&&r?(0,F.jsx)(`div`,{className:`chat-main`,children:(0,F.jsx)(Qo,{chatId:r,title:f?.title??t,goal:f?.goal},r)}):n===`info`&&t?(0,F.jsx)(ts,{slug:t,onChanged:u},t):t?(0,F.jsx)(Xo,{slug:t,title:f?.title??t},t):(0,F.jsx)(K,{children:`loading…`}):(0,F.jsx)(K,{children:`loading…`}),(0,F.jsxs)(`div`,{className:`runs-screen agents-screen projects-screen ${t&&f?`has-tabs`:``} ${t&&f&&l?`has-sessions`:``}`,children:[(0,F.jsxs)(`aside`,{className:`runs-side`,children:[(0,F.jsx)(wt,{title:`projects`,count:i?.enabled?d.length:void 0,action:i?.enabled&&(c||d.length===0)&&(0,F.jsx)(V,{size:`sm`,variant:`quiet`,icon:`add`,href:`/projects/new`,children:`new`})}),(0,F.jsxs)(Et,{children:[d.map(e=>(0,F.jsx)(Y,{href:`/projects/${encodeURIComponent(e.slug)}`,active:e.slug===t,size:`sm`,innerProps:{"data-project":e.slug},leading:(0,F.jsx)(U,{tone:e.configError?`bad`:Ro[e.status],title:e.status}),title:e.title,sub:e.configError?e.configError:e.goal||e.status,subTone:e.configError?`bad`:`plain`,meta:e.updatedAt&&(0,F.jsx)(`span`,{title:e.updatedAt,children:Ge(e.updatedAt)})},e.slug)),i&&i.enabled&&d.length===0&&(0,F.jsx)(Dt,{children:`no projects yet`}),o&&(0,F.jsx)(q,{tone:`bad`,children:o})]})]}),t&&f&&(0,F.jsx)($o,{slug:t,chatId:r===`new`?void 0:r}),(0,F.jsx)(`div`,{className:`runs-main`,children:m})]})}function Jo(){let e=N(`projects.list`,{},{interval:6e4});return e&&!e.enabled?(0,F.jsxs)(K,{icon:`folder_off`,children:[`Projects are off. Turn them on in `,(0,F.jsx)(`a`,{href:`#/settings`,children:`settings`}),`.`]}):(0,F.jsx)(Yo,{root:e?.root,onCreated:async()=>{}})}function Yo({root:e,onCreated:t}){let[n,r]=(0,v.useState)(``),[i,a]=(0,v.useState)(``),[o,s]=(0,v.useState)(!1),[c,l]=(0,v.useState)(``),u=async e=>{e.preventDefault();let r=n.trim();if(r&&!o){s(!0),l(``);try{let e=await A.request(`projects.create`,{body:{title:r,goal:i.trim()}});if(!e.ok)throw Error(M(e));let n=e.data;B(`/projects/${encodeURIComponent(n.slug)}/info`),t()}catch(e){l(e.message)}finally{s(!1)}}};return(0,F.jsxs)(`form`,{className:`new-chat mx-auto flex w-full max-w-[640px] animate-rise flex-col gap-4`,onSubmit:e=>void u(e),children:[(0,F.jsx)(nt,{size:`lg`,children:`new project`}),(0,F.jsx)(J,{children:(0,F.jsxs)(vt,{className:`max-w-[680px]`,children:[(0,F.jsx)(Z,{label:`title`,children:(0,F.jsx)(X,{value:n,placeholder:`e.g. Relaunch netnode.ch`,"aria-label":`project title`,autoFocus:!0,onChange:e=>r(e.target.value)})}),(0,F.jsx)(Z,{label:`goal (one line)`,children:(0,F.jsx)(X,{value:i,placeholder:`e.g. Ship the new site on NodeHive by November`,"aria-label":`project goal`,onChange:e=>a(e.target.value)})}),(0,F.jsx)(`div`,{children:(0,F.jsx)(V,{variant:`primary`,type:`submit`,icon:`add`,busy:o,disabled:!n.trim(),children:o?`creating…`:`create project`})}),c&&(0,F.jsx)(q,{tone:`bad`,children:c}),(0,F.jsxs)(G,{children:[`One folder each under `,(0,F.jsx)(`code`,{title:e,children:e}),` with project.yml, brief.md, state.md and log.md; part of the workspace, commit it from the git screen. Chats opened in the project carry all of it as context.`]})]})})]})}function Xo({slug:e,title:t}){let[n,r]=(0,v.useState)(!1);return(0,v.useEffect)(()=>{let t=!0;return r(!1),A.call(`chats.list`).then(n=>{if(!t)return;let i=n.chats.find(t=>t.scope.kind===`project`&&t.scope.slug===e);i?B(`/projects/${encodeURIComponent(e)}/chat/${i.id}`,{replace:!0}):r(!0)}).catch(()=>t&&r(!0)),()=>{t=!1}},[e]),n?(0,F.jsx)(Zo,{slug:e,title:t}):(0,F.jsx)(K,{children:`loading…`})}function Zo({slug:e,title:t}){let[n,r]=(0,v.useState)(null),[i,a]=(0,v.useState)(!1);(0,v.useEffect)(()=>{let t=!0;return A.call(`projects.get`,{slug:e}).then(e=>t&&r(e)).catch(()=>{}),()=>{t=!1}},[e]);let o=Ho.find(e=>e.id===n?.harness)??Ho[0],s=N(`agents.list`,{}),c=(n?.links.agents??[]).flatMap(e=>s?.agents.filter(t=>t.slug===e.slug)??[]),[l,u]=(0,v.useState)(null);return(0,F.jsxs)(it,{width:`narrow`,children:[(0,F.jsxs)(nt,{size:`lg`,children:[ze.emoji,` `,ze.name,` · `,t]}),(0,F.jsxs)(J,{title:`runs on`,children:[(0,F.jsx)(`div`,{className:`p-4`,children:(0,F.jsxs)(`button`,{type:`button`,className:`flex w-full cursor-pointer flex-col gap-0.5 rounded-card border border-transparent bg-accent-soft px-3.5 py-3 text-left text-on-accent-soft transition-[filter] hover:enabled:brightness-[0.97] disabled:cursor-default disabled:opacity-60`,disabled:i||!n,onClick:async()=>{a(!0),await Fo(o.id,{kind:`project`,slug:e}),a(!1)},children:[(0,F.jsx)(`b`,{className:`text-base font-medium`,children:i?`starting…`:`start chat`}),(0,F.jsx)(`span`,{className:`text-xs`,children:n?`${Uo(n)} — ${o.hint}`:`…`})]})}),(0,F.jsxs)(G,{className:`px-[18px] pb-3.5`,children:[`The chat starts with the project's brief, state, systems of record and links as context. Harness, model and effort are set on the `,(0,F.jsx)(he,{href:`/projects/${encodeURIComponent(e)}/info`,children:`project page`}),`, like an agent's.`]})]}),c.length>0&&(0,F.jsxs)(J,{title:`or with an agent of the project`,children:[(0,F.jsx)(`div`,{className:`flex flex-col gap-2 p-4`,children:c.map(t=>(0,F.jsxs)(`button`,{type:`button`,className:`flex w-full cursor-pointer items-center gap-2.5 rounded-card border border-line bg-transparent px-3.5 py-2.5 text-left text-fg transition-colors hover:enabled:bg-surface-2 disabled:cursor-default disabled:opacity-60`,disabled:l!==null,onClick:async()=>{u(t.slug),await Fo(`claude`,{kind:`agent`,slug:t.slug},void 0,e),u(null)},children:[(0,F.jsx)(`span`,{className:`text-lg`,children:t.emoji||`🤖`}),(0,F.jsxs)(`span`,{className:`flex min-w-0 flex-col`,children:[(0,F.jsx)(`b`,{className:`text-base font-medium`,children:l===t.slug?`starting…`:t.name}),t.description&&(0,F.jsx)(`span`,{className:`truncate text-xs text-fg-2`,children:t.description})]})]},t.slug))}),(0,F.jsx)(G,{className:`px-[18px] pb-3.5`,children:`The agent works with its own instructions and the project's context; the chat is listed here and with the agent.`})]})]})}function Qo({chatId:e,title:t,goal:n}){let[r,i]=(0,v.useState)(null),[a,o]=(0,v.useState)(!1),[s,c]=(0,v.useState)(0);(0,v.useEffect)(()=>{let t=!0;return A.call(`chats.get`,{id:e}).then(e=>t&&i(e.meta.scope)).catch(()=>t&&o(!0)),()=>{t=!1}},[e,s]);let l=r?.kind===`channel`?r.slug:void 0,u=r?.kind===`agent`?r.slug:void 0,d=N(`channels.list`,l?{}:null,{interval:4e3}),f=N(`agents.list`,l||u?{}:null,{interval:8e3});if(a)return(0,F.jsx)(K,{icon:`chat_error`,children:`chat not found`});if(!r)return(0,F.jsx)(K,{children:`loading…`});if(l){let t=d?.channels.find(e=>e.slug===l);return d?t?(0,F.jsx)(jo,{id:e,channel:t,agents:f?.agents??[]},`${e}:channel`):(0,F.jsxs)(K,{icon:`forum`,children:[`channel #`,l,` is gone — its definition under channels/ was removed`]}):(0,F.jsx)(K,{children:`loading…`})}if(u){let t=f?.agents.find(e=>e.slug===u);return f?(0,F.jsx)(jo,{id:e,agentName:t?`${t.emoji||`🤖`} ${t.name}`:u,agentDescription:t?.description,onConverted:()=>c(e=>e+1)},`${e}:${s}`):(0,F.jsx)(K,{children:`loading…`})}return(0,F.jsx)(jo,{id:e,agentName:t,agentDescription:n,onConverted:()=>c(e=>e+1)},`${e}:${s}`)}function $o({slug:e,chatId:t}){let[n,r]=(0,v.useState)(!1),i=(0,v.useCallback)(t=>Wo(t,e),[e]),a=(0,v.useCallback)(t=>Go(t,e),[e]),o=N(`agents.list`,{},{interval:3e4}),s=e=>{let t=o?.agents.find(t=>t.slug===e);return t?`${t.emoji||`🤖`} ${t.name}`:e};return(0,F.jsx)(Ga,{storeKey:`project:${e}`,label:`chats`,fallbackTitle:`new chat`,chatId:t,filter:i,hrefOf:a,closeHref:`/projects/${encodeURIComponent(e)}/chat/new`,subOf:e=>e.scope.kind===`channel`?`with coworkers · #${e.scope.slug}`:e.scope.kind===`agent`?`with ${s(e.scope.slug)}`:e.agent,actions:(0,F.jsx)(La,{busy:n,onClick:async()=>{r(!0),await Fo(`claude`,{kind:`project`,slug:e}),r(!1)}})})}var es=[{kind:`knowledge`,label:`knowledge`,icon:`menu_book`,href:e=>`/knowledge/${encodeURIComponent(e)}`},{kind:`vibeables`,label:`apps`,icon:`web`,href:e=>`/vibeables/${encodeURIComponent(e)}`},{kind:`repos`,label:`repositories`,icon:`source`},{kind:`workflows`,label:`workflows`,icon:`account_tree`,href:e=>`/workflows/${encodeURIComponent(e)}`},{kind:`agents`,label:`agents`,icon:`groups`,href:e=>`/agents/${encodeURIComponent(e)}`}];function ts({slug:e,onChanged:t}){let[n,r]=(0,v.useState)(null),[i,a]=(0,v.useState)(!1),[o,s]=(0,v.useState)(``),[c,l]=(0,v.useState)(!1),[u,d]=(0,v.useState)(!1),[f,p]=(0,v.useState)(!1),[m,h]=(0,v.useState)(``),[g,_]=(0,v.useState)(``),[y,b]=(0,v.useState)(`active`),[x,S]=(0,v.useState)(`claude`),[C,w]=(0,v.useState)(``),[T,E]=(0,v.useState)(``),[D,O]=(0,v.useState)(``),[k,j]=(0,v.useState)(``),[ee,M]=(0,v.useState)(!1),[N,P]=(0,v.useState)(``),te=be(),ne=e=>{r(e),h(e.title),_(e.goal),b(e.status),S(e.harness),w(e.model??``),E(e.effort??``),O(e.brief),j(e.state),M(!1)};(0,v.useEffect)(()=>{let t=!0;return A.call(`projects.get`,{slug:e}).then(e=>t&&ne(e)).catch(()=>t&&a(!0)),()=>{t=!1}},[e]);let I=()=>{M(!0),d(!1),s(``)},L=async(n,i={})=>{l(!0),s(``);try{let a=await Ko(e,n);i.keepEdits?r(a):ne(a),d(!i.keepEdits),await t()}catch(e){s(e.message)}finally{l(!1)}},re=async()=>{l(!0);try{let n=await A.request(`projects.delete`,{slug:e});if(!n.ok)throw Error(n.error||`failed`);await t(),B(`/`,{replace:!0})}catch(e){s(e.message),l(!1)}},ie=async()=>{let t=N.trim();if(t){l(!0),s(``);try{let n=await A.request(`projects.log`,{slug:e,body:{entry:t}});if(!n.ok)throw Error(n.error||`failed`);let i=n.data;P(``),r(e=>e&&{...e,log:i.log??e.log})}catch(e){s(e.message)}finally{l(!1)}}};return i?(0,F.jsx)(K,{icon:`folder_off`,children:`project not found`}):n?(0,F.jsxs)(`div`,{className:`chat-main project-page flex flex-col gap-3`,children:[(0,F.jsxs)(`div`,{className:`flex flex-none flex-wrap items-center gap-x-4 gap-y-2`,children:[(0,F.jsx)(at,{children:(0,F.jsx)(`span`,{"aria-hidden":!0,children:`📁`})}),(0,F.jsx)(nt,{size:`lg`,children:n.title}),(0,F.jsx)(W,{tone:zo[n.status],children:n.status}),(0,F.jsx)(W,{title:`harness · model · effort every chat in this project runs on`,children:Uo(n)}),te&&(0,F.jsx)(`span`,{className:`min-w-0 truncate font-mono text-xs text-fg-2`,title:n.path,children:n.path})]}),n.configError&&(0,F.jsxs)(q,{tone:`bad`,children:[`project.yml: `,n.configError]}),(0,F.jsx)(J,{title:`project`,className:`flex-none`,actions:(0,F.jsxs)(F.Fragment,{children:[u&&!ee&&(0,F.jsx)(`span`,{className:`text-xs text-fg-2`,children:`saved`}),(0,F.jsx)(V,{variant:`primary`,size:`sm`,busy:c,disabled:!ee,onClick:()=>void L({title:m,goal:g,status:y,harness:x,model:C,effort:T,brief:D,state:k}),children:c?`saving…`:`save changes`})]}),children:(0,F.jsxs)(vt,{className:`max-w-[680px]`,children:[(0,F.jsxs)(yt,{children:[(0,F.jsx)(Z,{label:`title`,className:`flex-1`,children:(0,F.jsx)(X,{value:m,"aria-label":`title`,onChange:e=>{h(e.target.value),I()}})}),(0,F.jsx)(Z,{label:`status`,children:(0,F.jsx)(_t,{value:y,"aria-label":`status`,onChange:e=>{b(e.target.value),I()},children:Lo.map(e=>(0,F.jsx)(`option`,{value:e,children:e},e))})})]}),(0,F.jsxs)(yt,{children:[(0,F.jsx)(Z,{label:`harness`,className:`w-[140px] max-[940px]:w-auto`,children:(0,F.jsx)(_t,{value:x,"aria-label":`harness`,onChange:e=>{S(e.target.value),I()},children:Ho.map(e=>(0,F.jsx)(`option`,{value:e.id,children:e.label},e.id))})}),(0,F.jsx)(Z,{label:`model`,className:`flex-1`,children:(0,F.jsx)(X,{value:C,"aria-label":`model`,placeholder:`harness default — e.g. sonnet, gpt-5.6-sol`,onChange:e=>{w(e.target.value),I()}})}),(0,F.jsx)(Z,{label:`effort`,className:`w-[140px] max-[940px]:w-auto`,children:(0,F.jsx)(_t,{value:T,"aria-label":`effort`,onChange:e=>{E(e.target.value),I()},children:qe.map(e=>(0,F.jsx)(`option`,{value:e,children:e||`default`},e))})})]}),(0,F.jsx)(Z,{label:`goal (one line)`,children:(0,F.jsx)(X,{value:g,"aria-label":`goal`,placeholder:`what the project is for`,onChange:e=>{_(e.target.value),I()}})}),(0,F.jsx)(Z,{label:`brief.md — what done looks like, constraints, stakeholders`,children:(0,F.jsx)(gt,{rows:10,className:`resize-y font-mono text-sm`,value:D,"aria-label":`brief`,onChange:e=>{O(e.target.value),I()}})}),(0,F.jsx)(Z,{label:`state.md — current state, rewritten at the end of a session`,children:(0,F.jsx)(gt,{rows:6,className:`resize-y font-mono text-sm`,value:k,"aria-label":`state`,onChange:e=>{j(e.target.value),I()}})}),o&&(0,F.jsx)(q,{tone:`bad`,children:o})]})}),(0,F.jsx)(os,{records:n.records,saving:c,onSave:e=>L({records:e},{keepEdits:!0})}),(0,F.jsx)(J,{title:`links`,className:`flex-none`,actions:(0,F.jsx)(`span`,{className:`text-xs text-fg-2`,children:`by name; a target that is missing in this workspace is marked`}),children:(0,F.jsx)(ct,{children:es.map(i=>(0,F.jsx)(is,{kind:i.kind,label:i.label,icon:i.icon,href:i.href,links:n.links[i.kind],saving:c,onChange:(n,a)=>void ns(e,i.kind,n,a,e=>{r(e),t()},s)},i.kind))})}),(0,F.jsxs)(J,{title:`log`,className:`flex-none`,children:[(0,F.jsx)(vt,{className:`max-w-[680px]`,children:(0,F.jsxs)(yt,{children:[(0,F.jsx)(Z,{label:`new entry — a decision, a milestone`,className:`flex-1`,children:(0,F.jsx)(X,{value:N,"aria-label":`log entry`,placeholder:`e.g. Decided on NodeHive as the CMS`,onChange:e=>P(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),ie())}})}),(0,F.jsx)(V,{icon:`add`,disabled:c||!N.trim(),onClick:()=>void ie(),children:`log`})]})}),(0,F.jsx)(`div`,{className:`md-body h-auto overflow-visible px-[18px] pt-1 pb-4 text-sm [&_h1]:hidden [&_h2]:mt-3 [&_h2]:mb-1 [&_h2]:text-xs [&_ul]:m-0 [&_ul]:pl-[18px]`,dangerouslySetInnerHTML:{__html:da.sanitize(Fr.parse(n.log||`_no entries yet_`,{async:!1}))}})]}),(0,F.jsx)(J,{title:`danger zone`,className:`flex-none [&>div]:border-b-0`,actions:f?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(V,{size:`sm`,variant:`danger`,icon:`delete`,disabled:c,onClick:()=>void re(),children:`confirm delete`}),(0,F.jsx)(V,{size:`sm`,variant:`quiet`,onClick:()=>p(!1),children:`cancel`})]}):(0,F.jsx)(V,{size:`sm`,variant:`danger`,icon:`delete`,disabled:c,onClick:()=>p(!0),title:`Move the project, its files and log to the trash; #/trash puts it back`,children:`delete project`}),children:null})]}):(0,F.jsx)(K,{children:`loading…`})}async function ns(e,t,n,r,i,a){try{let a=await A.request(`projects.link`,{slug:e,body:{kind:t,target:n,remove:r}});if(!a.ok)throw Error(M(a));i(a.data)}catch(e){a(e.message)}}async function rs(e){switch(e){case`knowledge`:return(await A.call(`knowledge.list`)).bundles.map(e=>({slug:e.name,hint:`${e.concepts} concepts`}));case`vibeables`:return(await A.call(`vibeables.list`)).vibeables.map(e=>({slug:e.slug,hint:e.dev?`dev`:`static`}));case`repos`:return(await A.call(`repos.list`)).repos.map(e=>({slug:e.slug,hint:e.branch}));case`workflows`:return(await A.call(`workflows.list`)).workflows.map(e=>({slug:e.slug,hint:e.description??e.name}));case`agents`:return(await A.call(`agents.list`)).agents.filter(e=>!e.archived).map(e=>({slug:e.slug,hint:`${e.emoji} ${e.name}`}))}}function is({kind:e,label:t,icon:n,href:r,links:i,saving:a,onChange:o}){let[s,c]=(0,v.useState)(!1),[l,u]=(0,v.useState)(null),[d,f]=(0,v.useState)(``);(0,v.useEffect)(()=>{if(!s||l)return;let t=!0;return rs(e).then(e=>t&&u(e)).catch(()=>t&&u([])),()=>{t=!1}},[s,l,e]);let p=new Set(i.map(e=>e.slug)),m=(l??[]).filter(e=>!p.has(e.slug));return(0,F.jsxs)(st,{icon:n,title:t,"data-link-kind":e,action:!s&&(0,F.jsx)(V,{size:`sm`,icon:`add`,onClick:()=>c(!0),children:`link`}),children:[i.length===0&&!s&&(0,F.jsx)(`span`,{className:`text-xs text-fg-2`,children:`none linked`}),i.length>0&&(0,F.jsx)(`span`,{className:`flex flex-wrap gap-1.5`,children:i.map(e=>(0,F.jsxs)(W,{tone:e.found?`neutral`:`bad`,title:e.found?e.label:`configured but not found in this workspace`,children:[r&&e.found?(0,F.jsx)(he,{href:r(e.slug),className:`text-inherit no-underline hover:underline`,children:e.slug}):e.slug,!e.found&&` · not found`,(0,F.jsx)(`button`,{type:`button`,className:`-mr-1 ml-1 inline-grid size-4 cursor-pointer place-items-center rounded-full border-0 bg-transparent p-0 text-inherit opacity-70 hover:bg-surface hover:opacity-100 disabled:cursor-default [&_.ms]:text-[13px]`,"aria-label":`unlink ${e.slug}`,disabled:a,onClick:()=>o(e.slug,!0),children:(0,F.jsx)(I,{name:`close`})})]},e.slug))}),s&&(0,F.jsx)(`span`,{className:`mt-1.5 flex flex-wrap items-center gap-2`,children:l===null?(0,F.jsx)(`span`,{className:`text-xs text-fg-2`,children:`loading…`}):(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(_t,{className:`w-auto max-w-full min-w-48 flex-1`,"aria-label":`link ${t}`,value:d,onChange:e=>f(e.target.value),children:[(0,F.jsx)(`option`,{value:``,children:m.length?`pick ${t}…`:`nothing to link`}),m.map(e=>(0,F.jsxs)(`option`,{value:e.slug,children:[e.slug,e.hint?` — ${e.hint}`:``]},e.slug))]}),(0,F.jsx)(V,{disabled:a||!d,onClick:()=>{o(d,!1),f(``),c(!1)},children:`link`}),(0,F.jsx)(V,{variant:`quiet`,onClick:()=>c(!1),children:`cancel`})]})})]})}var as={kind:`url`};function os({records:e,saving:t,onSave:n}){let[r,i]=(0,v.useState)(null),[a,o]=(0,v.useState)(!1),s=e=>i(t=>({...t??as,...e})),c=e=>{let t={kind:e.kind.trim().toLowerCase()||`url`};for(let n of[`title`,`url`,`workspace`,`note`]){let r=(e[n]??``).trim();r&&(t[n]=r)}return t};return(0,F.jsx)(J,{title:`systems of record`,className:`flex-none`,actions:(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`span`,{className:`text-xs text-fg-2`,children:`where the truth is managed outside kraftwerk — context for the agent, not a credential`}),!r&&(0,F.jsx)(V,{size:`sm`,icon:`add`,onClick:()=>i({...as}),children:`add`})]}),children:(0,F.jsxs)(ct,{children:[e.map((r,i)=>(0,F.jsx)(st,{"data-record-kind":r.kind,icon:`database`,title:(0,F.jsxs)(F.Fragment,{children:[Vo(r.kind),r.title&&(0,F.jsx)(`span`,{className:`text-xs font-normal text-fg-2`,children:r.title}),r.workspace&&(0,F.jsxs)(W,{children:[`workspace `,r.workspace]})]}),action:(0,F.jsx)(H,{icon:`close`,size:`sm`,label:`remove record ${r.title??r.kind}`,disabled:t,onClick:()=>void n(e.filter((e,t)=>t!==i))}),children:(r.url||r.note)&&(0,F.jsxs)(`span`,{className:`text-xs leading-normal text-fg-2`,children:[r.url&&(0,F.jsx)(`a`,{href:r.url,target:`_blank`,rel:`noreferrer`,children:r.url}),r.url&&r.note&&` — `,r.note]})},i)),e.length===0&&!r&&(0,F.jsx)(G,{className:`px-[18px] py-3`,children:`none yet — e.g. a my.netnode.ch workspace, a Google Drive folder, a board`}),r&&(0,F.jsxs)(vt,{className:`max-w-[680px]`,children:[(0,F.jsxs)(yt,{children:[(0,F.jsx)(Z,{label:`kind`,children:a?(0,F.jsx)(X,{value:r.kind,"aria-label":`record kind`,placeholder:`e.g. jira`,onChange:e=>s({kind:e.target.value})}):(0,F.jsxs)(_t,{value:r.kind,"aria-label":`record kind`,onChange:e=>{e.target.value===`__other`?(o(!0),s({kind:``})):s({kind:e.target.value})},children:[Object.entries(Bo).map(([e,t])=>(0,F.jsx)(`option`,{value:e,children:t},e)),(0,F.jsx)(`option`,{value:`__other`,children:`other…`})]})}),(0,F.jsx)(Z,{label:`title`,className:`flex-1`,children:(0,F.jsx)(X,{value:r.title??``,"aria-label":`record title`,placeholder:`e.g. Contracts folder`,onChange:e=>s({title:e.target.value})})}),(0,F.jsx)(Z,{label:`workspace / id`,children:(0,F.jsx)(X,{value:r.workspace??``,"aria-label":`record workspace`,placeholder:`e.g. 22`,onChange:e=>s({workspace:e.target.value})})})]}),(0,F.jsx)(Z,{label:`url`,children:(0,F.jsx)(X,{value:r.url??``,"aria-label":`record url`,placeholder:`https://…`,onChange:e=>s({url:e.target.value})})}),(0,F.jsxs)(yt,{children:[(0,F.jsx)(Z,{label:`note — what lives there and how it is usually reached`,className:`flex-1`,children:(0,F.jsx)(X,{value:r.note??``,"aria-label":`record note`,placeholder:`e.g. tickets and roadmap; the my CLI`,onChange:e=>s({note:e.target.value})})}),(0,F.jsx)(V,{disabled:t||!r.kind.trim(),onClick:async()=>{await n([...e,c(r)]),i(null),o(!1)},children:`add record`}),(0,F.jsx)(V,{variant:`quiet`,onClick:()=>{i(null),o(!1)},children:`cancel`})]})]})]})})}async function ss(e,t){let n=window.open(``,`_blank`);if(!n)return;let r=t?`${e}/${t}`:e;n.document.write(`<title>${ds(r)}</title><body style="font-family:system-ui;padding:40px;color:#555">preparing ${ds(r)}…</body>`);let i,a=``;try{let[n,r]=await Promise.all([t?Promise.resolve([t]):A.call(`knowledge.get`,{bundle:e}).then(e=>e.concepts.map(e=>e.id)),A.call(`meta.get`).catch(()=>({}))]);if(a=r.workspaceName??``,i=await Promise.all(n.map(t=>A.call(`knowledge.concept`,{bundle:e,query:{id:t}}))),i.some(e=>typeof e?.id!=`string`))throw Error(`missing concept`)}catch{n.document.body.textContent=`could not load "${r}"`;return}let o=[],s=i.map(e=>{let t=[e.type,e.generated?.at?`updated ${e.generated.at.slice(0,10)}`:``,e.trustTier===`human-reviewed`?`human-reviewed`:``,(e.tags??[]).map(e=>`#${e}`).join(` `)].filter(Boolean).join(` · `),{md:n,notes:r}=ls(cs(e.body??``,null)),i=!e.title||e.title===e.id||e.title===e.id.split(`/`).pop(),{html:a,title:s}=us(da.sanitize(Fr.parse(n,{async:!1})),{title:e.title||e.id,meta:t,titleIsFallback:i});return o.push(s),`<article>
82
82
  ${a}
83
- ${r.length?`<ol class="notes">${r.map(e=>`<li id="fn-${us(e.id)}">${da.sanitize(Fr.parseInline(e.text,{async:!1}))}</li>`).join(``)}</ol>`:``}
83
+ ${r.length?`<ol class="notes">${r.map(e=>`<li id="fn-${ds(e.id)}">${da.sanitize(Fr.parseInline(e.text,{async:!1}))}</li>`).join(``)}</ol>`:``}
84
84
  </article>`}).join(`
85
- `),c=new Date().toISOString().slice(0,10),l=a?`${us(a)} · ${us(e)}`:us(e),u=t?o[0]||r:e,d=t?``:`<h1 class="cover">${us(e)}</h1>
86
- <div class="cover-sub">${a?`${us(a)} · `:``}knowledge bundle · ${i.length} concept${i.length===1?``:`s`} · exported ${c}</div>`,f=`<!doctype html>
85
+ `),c=new Date().toISOString().slice(0,10),l=a?`${ds(a)} · ${ds(e)}`:ds(e),u=t?o[0]||r:e,d=t?``:`<h1 class="cover">${ds(e)}</h1>
86
+ <div class="cover-sub">${a?`${ds(a)} · `:``}knowledge bundle · ${i.length} concept${i.length===1?``:`s`} · exported ${c}</div>`,f=`<!doctype html>
87
87
  <html>
88
88
  <head>
89
89
  <meta charset="utf-8">
90
- <title>${us(u)}</title>
90
+ <title>${ds(u)}</title>
91
91
  <style>
92
92
  :root { color-scheme: light; }
93
93
  /* Page margins live in the sheet itself (repeating thead/tfoot cells +
@@ -203,29 +203,29 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
203
203
  </table>
204
204
  <script>setTimeout(() => window.print(), 400);<\/script>
205
205
  </body>
206
- </html>`;n.location.href=URL.createObjectURL(new Blob([f],{type:`text/html`}))}function ss(e,t){return e.split(/(```[\s\S]*?```|`[^`]*`)/).map((e,n)=>n%2==1?e:e.replace(/\[\[([^\]|]+)(?:\|([^\]]+))?\]\]/g,(e,n,r)=>{let i=n.trim().replace(/\.md$/,``),a=(r??i).trim();return t===null?a:`[${a}](#/knowledge/${encodeURIComponent(t)}/${i})`})).join(``)}function cs(e){let t=[];return{md:e.replace(/^\[\^([^\]]+)\]:[ \t]*(.+)$/gm,(e,n,r)=>(t.push({id:n,text:r.trim()}),``)).replace(/\[\^([^\]]+)\]/g,(e,n)=>{let r=t.findIndex(e=>e.id===n);return r>=0?`<sup class="fnref">${r+1}</sup>`:``}),notes:t}}function ls(e,t){let n=new DOMParser().parseFromString(e,`text/html`),r=t.title,i=n.body.firstElementChild;t.titleIsFallback&&i?.tagName===`H1`&&(r=i.textContent?.trim()||r,i.remove());let a=n.createElement(`header`);a.innerHTML=`<h1>${us(r)}</h1><div class="meta">${us(t.meta)}</div>`,n.body.prepend(a);for(let e of n.querySelectorAll(`table`)){e.classList.add(`md`);for(let t of e.querySelectorAll(`th, td`))(t.textContent??``).trim().length<=14&&t.classList.add(`nw`)}for(let e of[5,4,3,2,1])for(let t of Array.from(n.body.querySelectorAll(`:scope > h${e}`))){let r=n.createElement(`h${e+1}`);r.innerHTML=t.innerHTML,t.replaceWith(r)}for(let e of Array.from(n.body.querySelectorAll(`:scope > header, :scope > h2, :scope > h3, :scope > h4`))){let t=e.nextElementSibling;if(!t||/^H[1-6]$/.test(t.tagName))continue;let r=n.createElement(`div`);r.className=`keep`,e.replaceWith(r),r.append(e,t)}return{html:n.body.innerHTML,title:r}}function us(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`)}var ds=`text-xs leading-[1.5] text-fg-2 [&_a]:text-inherit [&_code]:text-2xs`;function fs({children:e}){return(0,F.jsx)(`span`,{className:`mt-[3px] flex flex-wrap gap-1.5`,children:e})}function ps({children:e}){return(0,F.jsx)(`div`,{className:`flex flex-col gap-[7px] py-1`,children:e})}var ms=`resize-y font-mono text-[12.5px] leading-[1.65]`;function hs({bundles:e,onHide:t,onResize:n}){let[r,i]=(0,v.useState)({}),[a,o]=(0,v.useState)(null),[s,c]=(0,v.useState)({}),[l,u]=(0,v.useState)({}),[d,f]=(0,v.useState)(null),[p,m]=(0,v.useState)(``),[h,g]=(0,v.useState)(!1),[_,y]=(0,v.useState)(``);(0,v.useEffect)(()=>{i({});let t=!0,n,r=async()=>{await Promise.all(e.map(async e=>{try{let n=await A.request(`knowledge.get`,{bundle:e}),r=n.ok?n.data:null;t&&i(t=>JSON.stringify(t[e])===JSON.stringify(r)?t:{...t,[e]:r})}catch{t&&i(t=>e in t?t:{...t,[e]:null})}})),t&&(n=setTimeout(r,6e3))};return r(),()=>{t=!1,clearTimeout(n)}},[e.join(`,`)]),(0,v.useEffect)(()=>{if(!a||d===a)return;let e=a.indexOf(`::`),t=a.slice(0,e),n=a.slice(e+2),r=!0,i,o=async()=>{try{let e=await A.request(`knowledge.concept`,{bundle:t,query:{id:n}}),i=e.ok?e.data:null;r&&c(e=>JSON.stringify(e[a])===JSON.stringify(i)?e:{...e,[a]:i})}catch{r&&c(e=>a in e?e:{...e,[a]:null})}r&&(i=setTimeout(o,6e3))};return o(),()=>{r=!1,clearTimeout(i)}},[a,d]);function b(e,t){let n=`${e}::${t}`;o(a===n?null:n)}async function x(e,t){let n=`${e}::${t}`;g(!0),y(``);try{let r=await A.request(`knowledge.putConcept`,{bundle:e,body:{id:t,content:p}});if(!r.ok)y(M(r));else if(r.data.error)y(r.data.error);else{let e=r.data;c(t=>({...t,[n]:e})),f(null)}}catch(e){y(e.message)}g(!1)}return(0,F.jsxs)(`aside`,{className:`runs-side knowledge-side`,children:[(0,F.jsx)(`div`,{className:`absolute inset-y-0 -left-[3px] z-4 w-[7px] cursor-col-resize hover:bg-accent/25`,title:`Drag to resize`,onMouseDown:e=>{e.preventDefault();let t=e.clientX,r=e.currentTarget.parentElement.offsetWidth,i=e=>n(Math.min(900,Math.max(280,r+(t-e.clientX)))),a=()=>{window.removeEventListener(`mousemove`,i),window.removeEventListener(`mouseup`,a)};window.addEventListener(`mousemove`,i),window.addEventListener(`mouseup`,a)}}),(0,F.jsxs)(`div`,{className:`flex items-center gap-2.5 border-b border-line px-4 py-3.5`,children:[(0,F.jsxs)(`span`,{className:`flex min-w-0 flex-col gap-px`,children:[(0,F.jsx)(et,{children:`knowledge`}),(0,F.jsx)(`span`,{className:`truncate text-[10.5px] text-fg-2`,children:`read & kept current by this agent`})]}),(0,F.jsx)(`span`,{className:`flex-1`}),(0,F.jsxs)(V,{size:`sm`,variant:`quiet`,onClick:t,title:`Hide knowledge sidebar`,children:[`hide `,(0,F.jsx)(I,{name:`close`,className:`ms-sm`})]})]}),(0,F.jsx)(`div`,{className:`flex-1 divide-y divide-line overflow-y-auto p-1.5`,children:e.map(e=>{let t=r[e],n=l[e]===!0;return(0,F.jsxs)(`div`,{className:`px-2 pt-1.5 pb-2.5`,children:[(0,F.jsxs)(`div`,{className:`flex items-center gap-0.5 py-0.5`,children:[(0,F.jsxs)(`button`,{type:`button`,className:`flex min-w-0 flex-1 cursor-pointer items-center gap-[7px] rounded-xl border-0 bg-transparent px-2 py-1.5 text-left hover:bg-surface-2`,"aria-expanded":!n,onClick:()=>u({...l,[e]:!n}),children:[(0,F.jsx)(gs,{open:!n}),(0,F.jsx)(`span`,{className:`truncate text-xs font-semibold text-fg`,children:e}),t&&(0,F.jsx)(`span`,{className:`flex-none rounded-full bg-surface-2 px-[7px] text-[10.5px] leading-[17px] tabular-nums text-fg-2`,children:t.concepts.length})]}),(0,F.jsx)(H,{icon:`picture_as_pdf`,label:`Export this bundle as PDF`,size:`sm`,onClick:()=>void os(e)}),(0,F.jsx)(H,{icon:`arrow_outward`,label:`Open this bundle on the knowledge screen`,size:`sm`,href:`/knowledge/${encodeURIComponent(e)}`})]}),!n&&t===null&&(0,F.jsx)(G,{className:`px-[18px] py-1.5`,children:`bundle not found`}),!n&&t?.concepts.map(t=>{let n=`${e}::${t.id}`,r=a===n,i=`/knowledge/${encodeURIComponent(e)}/${t.id.split(`/`).map(encodeURIComponent).join(`/`)}`;return(0,F.jsxs)(`div`,{children:[(0,F.jsxs)(`button`,{type:`button`,className:P(`flex w-full cursor-pointer items-center gap-[7px] rounded-xl border-0 py-1.5 pr-2 pl-[18px] text-left text-xs`,r?`bg-accent-soft font-medium text-on-accent-soft`:`bg-transparent text-fg-2 hover:bg-surface-2 hover:text-fg`),"aria-expanded":r,title:t.description||void 0,onClick:()=>b(e,t.id),children:[(0,F.jsx)(gs,{open:r}),(0,F.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:t.title||t.id}),t.stale&&(0,F.jsx)(`span`,{className:`cursor-help`,title:`Past its stale-after date — ask the agent to re-verify it`,children:(0,F.jsx)(W,{tone:`bad`,children:`stale`})})]}),r&&(0,F.jsx)(`div`,{className:`mt-1 mb-2.5 ml-[18px] overflow-hidden rounded-xl border border-line bg-surface-2`,ref:e=>e?.scrollIntoView({block:`nearest`}),children:s[n]===void 0?(0,F.jsx)(G,{className:`px-[18px] py-3`,children:`loading…`}):s[n]===null?(0,F.jsx)(G,{className:`px-[18px] py-3`,children:`could not load concept`}):d===n?(0,F.jsxs)(`div`,{className:`flex flex-col gap-2 px-3 py-2.5`,children:[(0,F.jsx)(gt,{className:`resize-y font-mono text-[12.5px] leading-[1.65]`,"aria-label":`concept`,value:p,rows:Math.min(28,Math.max(10,p.split(`
207
- `).length+2)),onChange:e=>m(e.target.value),spellCheck:!1}),(0,F.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,F.jsx)(V,{size:`sm`,variant:`quiet`,disabled:h,onClick:()=>f(null),children:`cancel`}),(0,F.jsx)(V,{size:`sm`,variant:`primary`,icon:`check`,busy:h,onClick:()=>x(e,t.id),children:h?`saving…`:`save`})]}),_&&(0,F.jsx)(q,{tone:`bad`,children:_})]}):(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 border-b border-line px-3 py-[7px]`,children:[t.type&&(0,F.jsx)(W,{children:t.type}),_s(t)&&(0,F.jsxs)(`span`,{className:`text-[10.5px] tabular-nums text-fg-2`,children:[`updated `,We(_s(t))]}),(0,F.jsx)(`span`,{className:`flex-1`}),(0,F.jsx)(V,{size:`sm`,variant:`quiet`,icon:`edit`,onClick:()=>{m(s[n].raw),f(n),y(``)},children:`edit`}),(0,F.jsx)(V,{size:`sm`,variant:`quiet`,icon:`open_in_new`,href:`/knowledge/${encodeURIComponent(e)}/${t.id}`,title:`The page in the knowledge section`,children:`page`}),(0,F.jsx)(V,{size:`sm`,variant:`quiet`,href:i,children:`open ↗`})]}),(0,F.jsx)(`div`,{className:`md-body h-auto overflow-visible px-3.5 pt-3 pb-3.5 text-xs`,dangerouslySetInnerHTML:{__html:da.sanitize(Fr.parse(s[n].body??``,{async:!1}))}})]})})]},t.id)}),!n&&t&&t.concepts.length===0&&(0,F.jsx)(G,{className:`px-[18px] py-1.5`,children:`no concepts yet`})]},e)})})]})}function gs({open:e}){return(0,F.jsx)(`span`,{className:P(`inline-grid w-[15px] flex-none text-fg-2 transition-transform`,e&&`rotate-90`),"aria-hidden":!0,children:(0,F.jsx)(I,{name:`chevron_right`,className:`text-[15px]`})})}function _s(e){return[e.generated?.at,...e.verified.map(e=>e.at)].filter(e=>typeof e==`string`&&e.length>0).sort().pop()}function vs({slug:e,name:t}){let[n,r]=(0,v.useState)(!1);return(0,v.useEffect)(()=>{let t=!0;return r(!1),A.call(`chats.list`).then(n=>{if(!t)return;let i=n.chats.find(t=>t.scope.kind===`agent`&&t.scope.slug===e);i?B(`/agents/${encodeURIComponent(e)}/chat/${i.id}`,{replace:!0}):r(!0)}).catch(()=>t&&r(!0)),()=>{t=!1}},[e]),n?(0,F.jsx)(ys,{slug:e,name:t}):(0,F.jsx)(K,{children:`loading…`})}function ys({slug:e,name:t}){let[n,r]=(0,v.useState)(!1);return(0,F.jsxs)(it,{width:`narrow`,children:[(0,F.jsxs)(nt,{children:[`new session with `,t??e]}),(0,F.jsx)(J,{children:(0,F.jsx)(`div`,{className:`p-4`,children:(0,F.jsxs)(`button`,{type:`button`,className:`flex w-full cursor-pointer flex-col gap-0.5 rounded-card border border-transparent bg-accent-soft px-3.5 py-3 text-left text-on-accent-soft transition-colors hover:brightness-[0.98] disabled:cursor-default disabled:opacity-60`,disabled:n,onClick:async()=>{r(!0),await Po(`claude`,{kind:`agent`,slug:e}),r(!1)},children:[(0,F.jsx)(`b`,{className:`text-base font-medium`,children:n?`starting…`:`start chat`}),(0,F.jsx)(`span`,{className:`text-xs`,children:`on the agent's harness, with its role, knowledge and skills`})]})})})]})}function bs(){let[e,t]=(0,v.useState)(!1);return(0,v.useEffect)(()=>{let e=!0;return A.call(`chats.list`).then(n=>{if(!e)return;let r=n.chats.find(e=>e.scope.kind!==`agent`&&e.scope.kind!==`channel`&&e.scope.kind!==`project`);r?B(`/agents/chats/${r.id}`,{replace:!0}):t(!0)}).catch(()=>e&&t(!0)),()=>{e=!1}},[]),e?(0,F.jsx)(Fo,{}):(0,F.jsx)(K,{children:`loading…`})}function xs({slug:e,chatId:t}){let[n,r]=(0,v.useState)(!1),i=(0,v.useCallback)(t=>t.filter(t=>t.scope.kind===`agent`&&t.scope.slug===e),[e]),a=(0,v.useCallback)(t=>`/agents/${encodeURIComponent(e)}/chat/${t.id}`,[e]);return(0,F.jsx)(Ga,{storeKey:`agent:${e}`,label:`chats`,fallbackTitle:`new chat`,chatId:t,filter:i,hrefOf:a,closeHref:`/agents/${encodeURIComponent(e)}/chat/new`,actions:(0,F.jsx)(La,{busy:n,onClick:async()=>{r(!0),await Po(`claude`,{kind:`agent`,slug:e}),r(!1)}})})}var Ss=e=>e.filter(e=>e.scope.kind!==`agent`&&e.scope.kind!==`channel`&&e.scope.kind!==`project`),Cs=e=>`/agents/chats/${e.id}`;function ws({chatId:e}){return(0,F.jsx)(Ga,{storeKey:`general`,label:`chats`,fallbackTitle:`new chat`,chatId:e,filter:Ss,hrefOf:Cs,closeHref:`/agents/chats/new`,subOf:e=>(0,F.jsxs)(F.Fragment,{children:[e.agent,e.scope.kind===`run`?` · ${e.scope.runId}`:e.scope.kind===`kraftwerk`?` · kraftwerk`:e.scope.kind===`knowledge`?` · knowledge${e.scope.bundle?`:${e.scope.bundle}`:``}`:``]}),actions:(0,F.jsx)(La,{href:`/agents/chats/new`})})}function Ts({agents:e}){return(0,v.useEffect)(()=>{let t=!0,n=()=>B(`/agents/${encodeURIComponent(e[0].slug)}`,{replace:!0});return A.call(`chats.list`).then(r=>{if(!t)return;let i=new Set(e.map(e=>e.slug)),a=r.chats.find(e=>e.scope.kind===`agent`&&i.has(e.scope.slug));a&&a.scope.kind===`agent`?B(`/agents/${encodeURIComponent(a.scope.slug)}/chat/${a.id}`,{replace:!0}):n()}).catch(()=>t&&n()),()=>{t=!1}},[e.map(e=>e.slug).join(`,`)]),(0,F.jsx)(K,{children:`loading…`})}function Es(){let e=be();return(0,F.jsx)(`div`,{className:`empty-action flex justify-center py-16 text-center text-sm text-fg-2`,children:e?(0,F.jsx)(V,{variant:`primary`,icon:`add`,onClick:()=>B(`/agents/new`),children:`create your first agent`}):(0,F.jsx)(`span`,{children:`Creating agents needs expert mode — flip the switch in the top bar.`})})}var Ds=`---
206
+ </html>`;n.location.href=URL.createObjectURL(new Blob([f],{type:`text/html`}))}function cs(e,t){return e.split(/(```[\s\S]*?```|`[^`]*`)/).map((e,n)=>n%2==1?e:e.replace(/\[\[([^\]|]+)(?:\|([^\]]+))?\]\]/g,(e,n,r)=>{let i=n.trim().replace(/\.md$/,``),a=(r??i).trim();return t===null?a:`[${a}](#/knowledge/${encodeURIComponent(t)}/${i})`})).join(``)}function ls(e){let t=[];return{md:e.replace(/^\[\^([^\]]+)\]:[ \t]*(.+)$/gm,(e,n,r)=>(t.push({id:n,text:r.trim()}),``)).replace(/\[\^([^\]]+)\]/g,(e,n)=>{let r=t.findIndex(e=>e.id===n);return r>=0?`<sup class="fnref">${r+1}</sup>`:``}),notes:t}}function us(e,t){let n=new DOMParser().parseFromString(e,`text/html`),r=t.title,i=n.body.firstElementChild;t.titleIsFallback&&i?.tagName===`H1`&&(r=i.textContent?.trim()||r,i.remove());let a=n.createElement(`header`);a.innerHTML=`<h1>${ds(r)}</h1><div class="meta">${ds(t.meta)}</div>`,n.body.prepend(a);for(let e of n.querySelectorAll(`table`)){e.classList.add(`md`);for(let t of e.querySelectorAll(`th, td`))(t.textContent??``).trim().length<=14&&t.classList.add(`nw`)}for(let e of[5,4,3,2,1])for(let t of Array.from(n.body.querySelectorAll(`:scope > h${e}`))){let r=n.createElement(`h${e+1}`);r.innerHTML=t.innerHTML,t.replaceWith(r)}for(let e of Array.from(n.body.querySelectorAll(`:scope > header, :scope > h2, :scope > h3, :scope > h4`))){let t=e.nextElementSibling;if(!t||/^H[1-6]$/.test(t.tagName))continue;let r=n.createElement(`div`);r.className=`keep`,e.replaceWith(r),r.append(e,t)}return{html:n.body.innerHTML,title:r}}function ds(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`)}var fs=`text-xs leading-[1.5] text-fg-2 [&_a]:text-inherit [&_code]:text-2xs`;function ps({children:e}){return(0,F.jsx)(`span`,{className:`mt-[3px] flex flex-wrap gap-1.5`,children:e})}function ms({children:e}){return(0,F.jsx)(`div`,{className:`flex flex-col gap-[7px] py-1`,children:e})}var hs=`resize-y font-mono text-[12.5px] leading-[1.65]`;function gs({bundles:e,onHide:t,onResize:n}){let[r,i]=(0,v.useState)({}),[a,o]=(0,v.useState)(null),[s,c]=(0,v.useState)({}),[l,u]=(0,v.useState)({}),[d,f]=(0,v.useState)(null),[p,m]=(0,v.useState)(``),[h,g]=(0,v.useState)(!1),[_,y]=(0,v.useState)(``);(0,v.useEffect)(()=>{i({});let t=!0,n,r=async()=>{await Promise.all(e.map(async e=>{try{let n=await A.request(`knowledge.get`,{bundle:e}),r=n.ok?n.data:null;t&&i(t=>JSON.stringify(t[e])===JSON.stringify(r)?t:{...t,[e]:r})}catch{t&&i(t=>e in t?t:{...t,[e]:null})}})),t&&(n=setTimeout(r,6e3))};return r(),()=>{t=!1,clearTimeout(n)}},[e.join(`,`)]),(0,v.useEffect)(()=>{if(!a||d===a)return;let e=a.indexOf(`::`),t=a.slice(0,e),n=a.slice(e+2),r=!0,i,o=async()=>{try{let e=await A.request(`knowledge.concept`,{bundle:t,query:{id:n}}),i=e.ok?e.data:null;r&&c(e=>JSON.stringify(e[a])===JSON.stringify(i)?e:{...e,[a]:i})}catch{r&&c(e=>a in e?e:{...e,[a]:null})}r&&(i=setTimeout(o,6e3))};return o(),()=>{r=!1,clearTimeout(i)}},[a,d]);function b(e,t){let n=`${e}::${t}`;o(a===n?null:n)}async function x(e,t){let n=`${e}::${t}`;g(!0),y(``);try{let r=await A.request(`knowledge.putConcept`,{bundle:e,body:{id:t,content:p}});if(!r.ok)y(M(r));else if(r.data.error)y(r.data.error);else{let e=r.data;c(t=>({...t,[n]:e})),f(null)}}catch(e){y(e.message)}g(!1)}return(0,F.jsxs)(`aside`,{className:`runs-side knowledge-side`,children:[(0,F.jsx)(`div`,{className:`absolute inset-y-0 -left-[3px] z-4 w-[7px] cursor-col-resize hover:bg-accent/25`,title:`Drag to resize`,onMouseDown:e=>{e.preventDefault();let t=e.clientX,r=e.currentTarget.parentElement.offsetWidth,i=e=>n(Math.min(900,Math.max(280,r+(t-e.clientX)))),a=()=>{window.removeEventListener(`mousemove`,i),window.removeEventListener(`mouseup`,a)};window.addEventListener(`mousemove`,i),window.addEventListener(`mouseup`,a)}}),(0,F.jsxs)(`div`,{className:`flex items-center gap-2.5 border-b border-line px-4 py-3.5`,children:[(0,F.jsxs)(`span`,{className:`flex min-w-0 flex-col gap-px`,children:[(0,F.jsx)(et,{children:`knowledge`}),(0,F.jsx)(`span`,{className:`truncate text-[10.5px] text-fg-2`,children:`read & kept current by this agent`})]}),(0,F.jsx)(`span`,{className:`flex-1`}),(0,F.jsxs)(V,{size:`sm`,variant:`quiet`,onClick:t,title:`Hide knowledge sidebar`,children:[`hide `,(0,F.jsx)(I,{name:`close`,className:`ms-sm`})]})]}),(0,F.jsx)(`div`,{className:`flex-1 divide-y divide-line overflow-y-auto p-1.5`,children:e.map(e=>{let t=r[e],n=l[e]===!0;return(0,F.jsxs)(`div`,{className:`px-2 pt-1.5 pb-2.5`,children:[(0,F.jsxs)(`div`,{className:`flex items-center gap-0.5 py-0.5`,children:[(0,F.jsxs)(`button`,{type:`button`,className:`flex min-w-0 flex-1 cursor-pointer items-center gap-[7px] rounded-xl border-0 bg-transparent px-2 py-1.5 text-left hover:bg-surface-2`,"aria-expanded":!n,onClick:()=>u({...l,[e]:!n}),children:[(0,F.jsx)(_s,{open:!n}),(0,F.jsx)(`span`,{className:`truncate text-xs font-semibold text-fg`,children:e}),t&&(0,F.jsx)(`span`,{className:`flex-none rounded-full bg-surface-2 px-[7px] text-[10.5px] leading-[17px] tabular-nums text-fg-2`,children:t.concepts.length})]}),(0,F.jsx)(H,{icon:`picture_as_pdf`,label:`Export this bundle as PDF`,size:`sm`,onClick:()=>void ss(e)}),(0,F.jsx)(H,{icon:`arrow_outward`,label:`Open this bundle on the knowledge screen`,size:`sm`,href:`/knowledge/${encodeURIComponent(e)}`})]}),!n&&t===null&&(0,F.jsx)(G,{className:`px-[18px] py-1.5`,children:`bundle not found`}),!n&&t?.concepts.map(t=>{let n=`${e}::${t.id}`,r=a===n,i=`/knowledge/${encodeURIComponent(e)}/${t.id.split(`/`).map(encodeURIComponent).join(`/`)}`;return(0,F.jsxs)(`div`,{children:[(0,F.jsxs)(`button`,{type:`button`,className:P(`flex w-full cursor-pointer items-center gap-[7px] rounded-xl border-0 py-1.5 pr-2 pl-[18px] text-left text-xs`,r?`bg-accent-soft font-medium text-on-accent-soft`:`bg-transparent text-fg-2 hover:bg-surface-2 hover:text-fg`),"aria-expanded":r,title:t.description||void 0,onClick:()=>b(e,t.id),children:[(0,F.jsx)(_s,{open:r}),(0,F.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:t.title||t.id}),t.stale&&(0,F.jsx)(`span`,{className:`cursor-help`,title:`Past its stale-after date — ask the agent to re-verify it`,children:(0,F.jsx)(W,{tone:`bad`,children:`stale`})})]}),r&&(0,F.jsx)(`div`,{className:`mt-1 mb-2.5 ml-[18px] overflow-hidden rounded-xl border border-line bg-surface-2`,ref:e=>e?.scrollIntoView({block:`nearest`}),children:s[n]===void 0?(0,F.jsx)(G,{className:`px-[18px] py-3`,children:`loading…`}):s[n]===null?(0,F.jsx)(G,{className:`px-[18px] py-3`,children:`could not load concept`}):d===n?(0,F.jsxs)(`div`,{className:`flex flex-col gap-2 px-3 py-2.5`,children:[(0,F.jsx)(gt,{className:`resize-y font-mono text-[12.5px] leading-[1.65]`,"aria-label":`concept`,value:p,rows:Math.min(28,Math.max(10,p.split(`
207
+ `).length+2)),onChange:e=>m(e.target.value),spellCheck:!1}),(0,F.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,F.jsx)(V,{size:`sm`,variant:`quiet`,disabled:h,onClick:()=>f(null),children:`cancel`}),(0,F.jsx)(V,{size:`sm`,variant:`primary`,icon:`check`,busy:h,onClick:()=>x(e,t.id),children:h?`saving…`:`save`})]}),_&&(0,F.jsx)(q,{tone:`bad`,children:_})]}):(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 border-b border-line px-3 py-[7px]`,children:[t.type&&(0,F.jsx)(W,{children:t.type}),vs(t)&&(0,F.jsxs)(`span`,{className:`text-[10.5px] tabular-nums text-fg-2`,children:[`updated `,We(vs(t))]}),(0,F.jsx)(`span`,{className:`flex-1`}),(0,F.jsx)(V,{size:`sm`,variant:`quiet`,icon:`edit`,onClick:()=>{m(s[n].raw),f(n),y(``)},children:`edit`}),(0,F.jsx)(V,{size:`sm`,variant:`quiet`,icon:`open_in_new`,href:`/knowledge/${encodeURIComponent(e)}/${t.id}`,title:`The page in the knowledge section`,children:`page`}),(0,F.jsx)(V,{size:`sm`,variant:`quiet`,href:i,children:`open ↗`})]}),(0,F.jsx)(`div`,{className:`md-body h-auto overflow-visible px-3.5 pt-3 pb-3.5 text-xs`,dangerouslySetInnerHTML:{__html:da.sanitize(Fr.parse(s[n].body??``,{async:!1}))}})]})})]},t.id)}),!n&&t&&t.concepts.length===0&&(0,F.jsx)(G,{className:`px-[18px] py-1.5`,children:`no concepts yet`})]},e)})})]})}function _s({open:e}){return(0,F.jsx)(`span`,{className:P(`inline-grid w-[15px] flex-none text-fg-2 transition-transform`,e&&`rotate-90`),"aria-hidden":!0,children:(0,F.jsx)(I,{name:`chevron_right`,className:`text-[15px]`})})}function vs(e){return[e.generated?.at,...e.verified.map(e=>e.at)].filter(e=>typeof e==`string`&&e.length>0).sort().pop()}function ys({slug:e,name:t}){let[n,r]=(0,v.useState)(!1);return(0,v.useEffect)(()=>{let t=!0;return r(!1),A.call(`chats.list`).then(n=>{if(!t)return;let i=n.chats.find(t=>t.scope.kind===`agent`&&t.scope.slug===e);i?B(`/agents/${encodeURIComponent(e)}/chat/${i.id}`,{replace:!0}):r(!0)}).catch(()=>t&&r(!0)),()=>{t=!1}},[e]),n?(0,F.jsx)(bs,{slug:e,name:t}):(0,F.jsx)(K,{children:`loading…`})}function bs({slug:e,name:t}){let[n,r]=(0,v.useState)(!1);return(0,F.jsxs)(it,{width:`narrow`,children:[(0,F.jsxs)(nt,{children:[`new session with `,t??e]}),(0,F.jsx)(J,{children:(0,F.jsx)(`div`,{className:`p-4`,children:(0,F.jsxs)(`button`,{type:`button`,className:`flex w-full cursor-pointer flex-col gap-0.5 rounded-card border border-transparent bg-accent-soft px-3.5 py-3 text-left text-on-accent-soft transition-colors hover:brightness-[0.98] disabled:cursor-default disabled:opacity-60`,disabled:n,onClick:async()=>{r(!0),await Fo(`claude`,{kind:`agent`,slug:e}),r(!1)},children:[(0,F.jsx)(`b`,{className:`text-base font-medium`,children:n?`starting…`:`start chat`}),(0,F.jsx)(`span`,{className:`text-xs`,children:`on the agent's harness, with its role, knowledge and skills`})]})})})]})}function xs(){let[e,t]=(0,v.useState)(!1);return(0,v.useEffect)(()=>{let e=!0;return A.call(`chats.list`).then(n=>{if(!e)return;let r=n.chats.find(e=>e.scope.kind!==`agent`&&e.scope.kind!==`channel`&&e.scope.kind!==`project`);r?B(`/agents/chats/${r.id}`,{replace:!0}):t(!0)}).catch(()=>e&&t(!0)),()=>{e=!1}},[]),e?(0,F.jsx)(Io,{}):(0,F.jsx)(K,{children:`loading…`})}function Ss({slug:e,chatId:t}){let[n,r]=(0,v.useState)(!1),i=(0,v.useCallback)(t=>t.filter(t=>t.scope.kind===`agent`&&t.scope.slug===e),[e]),a=(0,v.useCallback)(t=>`/agents/${encodeURIComponent(e)}/chat/${t.id}`,[e]),o=N(`projects.list`,{},{interval:6e4}),s=e=>o?.projects.find(t=>t.slug===e)?.title??e;return(0,F.jsx)(Ga,{storeKey:`agent:${e}`,label:`chats`,fallbackTitle:`new chat`,chatId:t,filter:i,hrefOf:a,closeHref:`/agents/${encodeURIComponent(e)}/chat/new`,subOf:e=>e.project?`📁 ${s(e.project)}`:e.agent,actions:(0,F.jsx)(La,{busy:n,onClick:async()=>{r(!0),await Fo(`claude`,{kind:`agent`,slug:e}),r(!1)}})})}var Cs=e=>e.filter(e=>e.scope.kind!==`agent`&&e.scope.kind!==`channel`&&e.scope.kind!==`project`),ws=e=>`/agents/chats/${e.id}`;function Ts({chatId:e}){return(0,F.jsx)(Ga,{storeKey:`general`,label:`chats`,fallbackTitle:`new chat`,chatId:e,filter:Cs,hrefOf:ws,closeHref:`/agents/chats/new`,subOf:e=>(0,F.jsxs)(F.Fragment,{children:[e.agent,e.scope.kind===`run`?` · ${e.scope.runId}`:e.scope.kind===`kraftwerk`?` · kraftwerk`:e.scope.kind===`knowledge`?` · knowledge${e.scope.bundle?`:${e.scope.bundle}`:``}`:``]}),actions:(0,F.jsx)(La,{href:`/agents/chats/new`})})}function Es({agents:e}){return(0,v.useEffect)(()=>{let t=!0,n=()=>B(`/agents/${encodeURIComponent(e[0].slug)}`,{replace:!0});return A.call(`chats.list`).then(r=>{if(!t)return;let i=new Set(e.map(e=>e.slug)),a=r.chats.find(e=>e.scope.kind===`agent`&&i.has(e.scope.slug));a&&a.scope.kind===`agent`?B(`/agents/${encodeURIComponent(a.scope.slug)}/chat/${a.id}`,{replace:!0}):n()}).catch(()=>t&&n()),()=>{t=!1}},[e.map(e=>e.slug).join(`,`)]),(0,F.jsx)(K,{children:`loading…`})}function Ds(){let e=be();return(0,F.jsx)(`div`,{className:`empty-action flex justify-center py-16 text-center text-sm text-fg-2`,children:e?(0,F.jsx)(V,{variant:`primary`,icon:`add`,onClick:()=>B(`/agents/new`),children:`create your first agent`}):(0,F.jsx)(`span`,{children:`Creating agents needs expert mode — flip the switch in the top bar.`})})}var Os=`---
208
208
  description: What this skill is for (one line)
209
209
  ---
210
210
 
211
211
  Instructions this agent follows when the skill applies or is invoked with /<name>.
212
- `;function Os({slug:e}){let t=N(`agents.skills`,{slug:e})?.skills??[],[n,r]=(0,v.useState)(null),[i,a]=(0,v.useState)(!1),[o,s]=(0,v.useState)(``);async function c(t){s(``);let n=await A.request(`agents.skill`,{slug:e,name:t}).catch(()=>null);if(!n)return void s(`could not load skill`);if(!n.ok||!n.data||typeof n.data!=`object`)return void s(n.error??`could not load skill`);r({name:t,content:n.data.content??``,isNew:!1})}async function l(){if(!n)return;a(!0),s(``);let t=await A.request(`agents.saveSkill`,{slug:e,body:{name:n.name,content:n.content}});a(!1),!t.ok||!t.data||typeof t.data!=`object`?s(t.error??`save failed`):r(null)}async function u(t){window.confirm(`Move skill "/${t}" of this agent to the trash?`)&&(await A.request(`agents.deleteSkill`,{slug:e,name:t}).catch(()=>{}),n?.name===t&&r(null))}return(0,F.jsxs)(J,{title:`own skills — only this agent`,actions:!n&&(0,F.jsx)(V,{size:`sm`,icon:`add`,onClick:()=>{r({name:``,content:Ds,isNew:!0}),s(``)},children:`new skill`}),children:[t.length===0&&!n&&(0,F.jsxs)(G,{className:`px-[18px] py-3 text-xs`,children:[`none — skills in `,(0,F.jsxs)(`code`,{children:[`agents/`,e,`/skills/`]}),` are private to this agent; skills for every agent live in the workspace skills folder.`]}),t.length>0&&!n&&(0,F.jsx)(ct,{children:t.map(e=>(0,F.jsx)(st,{icon:`extension`,title:`/${e.name}`,action:(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(V,{size:`sm`,icon:`edit`,onClick:()=>void c(e.name),children:`edit`}),(0,F.jsx)(H,{icon:`delete`,label:`delete /${e.name}`,variant:`danger`,size:`sm`,onClick:()=>void u(e.name)})]}),children:(0,F.jsx)(`span`,{className:`text-xs leading-[1.5] text-fg-2 [&_a]:text-inherit [&_code]:text-2xs`,children:e.description||(0,F.jsx)(`code`,{children:`SKILL.md`})})},e.name))}),n&&(0,F.jsxs)(vt,{className:`max-w-[680px]`,children:[(0,F.jsx)(Z,{label:`name — invoked as /<name>`,children:(0,F.jsx)(X,{className:`font-mono`,value:n.name,placeholder:`e.g. report-html`,disabled:!n.isNew,onChange:e=>r({...n,name:e.target.value})})}),(0,F.jsx)(Z,{label:`SKILL.md — frontmatter (description) + the instructions`,children:(0,F.jsx)(gt,{className:`resize-y font-mono text-[12.5px] leading-[1.65]`,rows:Math.min(28,Math.max(12,n.content.split(`
213
- `).length+2)),value:n.content,spellCheck:!1,onChange:e=>r({...n,content:e.target.value})})}),(0,F.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,F.jsx)(V,{variant:`primary`,busy:i,disabled:!n.name.trim(),onClick:()=>void l(),children:i?`saving…`:`save`}),(0,F.jsx)(V,{variant:`quiet`,disabled:i,onClick:()=>r(null),children:`cancel`})]})]}),o&&(0,F.jsx)(`div`,{className:`px-[18px] pb-3`,children:(0,F.jsx)(q,{tone:`bad`,children:o})})]})}function ks({slug:e}){let t=N(`agents.routines`,{slug:e})?.routines??[],[n,r]=(0,v.useState)(null),[i,a]=(0,v.useState)(``),[o,s]=(0,v.useState)(``);async function c(t){a(``);let n=await A.request(`agents.saveRoutine`,{slug:e,body:t});return n.ok?!0:(a(M(n)),!1)}async function l(t){s(t),a(``);let n=await A.request(`agents.runRoutine`,{slug:e,id:t});s(``),n.ok?n.data.chatId&&B(`/agents/${encodeURIComponent(e)}/chat/${n.data.chatId}`):a(M(n))}async function u(t){window.confirm(`Delete the scheduled prompt "${t}"?`)&&await A.request(`agents.deleteRoutine`,{slug:e,id:t}).catch(()=>{})}return(0,F.jsxs)(J,{title:`schedule — prompts that run on their own`,actions:!n&&(0,F.jsx)(V,{size:`sm`,icon:`add`,onClick:()=>r({name:``,schedule:`0 9 * * 1-5`,prompt:``,enabled:!0}),children:`schedule a prompt`}),children:[t.length===0&&!n&&(0,F.jsx)(G,{className:`px-[18px] py-3 text-xs`,children:`none — a routine messages this agent on a schedule (cron, server local time) and each run opens a new session with the result.`}),t.length>0&&(0,F.jsx)(ct,{children:t.map(t=>(0,F.jsx)(st,{icon:`schedule`,title:(0,F.jsxs)(F.Fragment,{children:[t.name,t.lastError&&(0,F.jsx)(`span`,{title:t.lastError,children:(0,F.jsx)(W,{tone:`bad`,children:`error`})}),t.awaitingApproval&&t.lastChatId&&(0,F.jsx)(W,{href:`/agents/${encodeURIComponent(e)}/chat/${t.lastChatId}`,tone:`bad`,title:`the last run asked for a permission nobody has answered yet`,children:`needs approval`})]}),action:(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(V,{size:`sm`,icon:`play_arrow`,busy:o===t.id,onClick:()=>l(t.id),children:o===t.id?`starting…`:`run`}),(0,F.jsx)(V,{size:`sm`,variant:`quiet`,onClick:()=>r({id:t.id,name:t.name,schedule:t.schedule,prompt:t.prompt,enabled:t.enabled}),children:`edit`}),(0,F.jsx)(V,{size:`sm`,variant:`danger`,onClick:()=>void u(t.id),children:`delete`}),(0,F.jsx)(St,{checked:t.enabled,label:t.enabled?`enabled — click to pause`:`paused — click to enable`,onChange:()=>void c({id:t.id,name:t.name,schedule:t.schedule,prompt:t.prompt,enabled:!t.enabled})})]}),children:(0,F.jsxs)(`span`,{className:`text-xs leading-[1.5] text-fg-2 [&_a]:text-inherit [&_code]:text-2xs`,children:[(0,F.jsx)(`code`,{children:t.schedule}),t.enabled?t.nextRunAt?` · next ${We(t.nextRunAt)}`:``:` · paused`,` · `,t.lastChatId?(0,F.jsxs)(he,{href:`/agents/${encodeURIComponent(e)}/chat/${t.lastChatId}`,children:[`last run `,We(t.lastRunAt)]}):`never ran`]})},t.id))}),n&&(0,F.jsxs)(vt,{className:`max-w-[680px]`,children:[(0,F.jsxs)(yt,{children:[(0,F.jsx)(Z,{label:`name`,className:`flex-1`,children:(0,F.jsx)(X,{value:n.name,placeholder:`e.g. Morning report`,onChange:e=>r({...n,name:e.target.value})})}),(0,F.jsx)(Z,{label:`schedule (cron)`,className:`w-[200px] max-[900px]:w-auto`,children:(0,F.jsx)(X,{className:`font-mono`,value:n.schedule,placeholder:`0 9 * * 1-5`,onChange:e=>r({...n,schedule:e.target.value})})}),(0,F.jsxs)(`label`,{className:`flex h-9 cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,F.jsx)(`input`,{type:`checkbox`,className:`accent-accent`,checked:n.enabled,onChange:e=>r({...n,enabled:e.target.checked})}),`enabled`]})]}),(0,F.jsx)(Z,{label:`prompt — what to ask this agent on each run`,children:(0,F.jsx)(gt,{rows:5,value:n.prompt,placeholder:`Check ... and summarize what changed.`,onChange:e=>r({...n,prompt:e.target.value})})}),(0,F.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,F.jsx)(V,{variant:`primary`,disabled:!n.name.trim()||!n.prompt.trim(),onClick:async()=>{await c(n)&&r(null)},children:n.id?`save`:`add to the schedule`}),(0,F.jsx)(V,{variant:`quiet`,onClick:()=>(r(null),a(``)),children:`cancel`})]})]}),i&&(0,F.jsx)(`div`,{className:`px-[18px] pb-3`,children:(0,F.jsx)(q,{tone:`bad`,children:i})})]})}function As({slug:e}){let[t,n]=(0,v.useState)(null),[r,i]=(0,v.useState)(!1),[a,o]=(0,v.useState)(!1),[s,c]=(0,v.useState)(``),[l,u]=(0,v.useState)(``),[d,f]=(0,v.useState)([]),[p,m]=(0,v.useState)(!0),[h,g]=(0,v.useState)(!1),[_,y]=(0,v.useState)(``),b=we(),x=N(`workflows.list`,{}),S=N(`knowledge.list`,{}),C=N(`vibeables.list`,b.vibeables?{}:null),w=N(`skills.list`,{});(0,v.useEffect)(()=>{let t=!0;return A.call(`agents.get`,{slug:e}).then(e=>t&&n(e)).catch(()=>t&&i(!0)),()=>{t=!1}},[e]);async function T(r){if(t){g(!0),y(``);try{let i=await A.request(`agents.save`,{slug:e,body:{name:t.name,emoji:t.emoji,description:t.description,harness:t.harness,model:t.model,effort:t.effort,group:t.group,system:t.system,workflows:t.workflows,knowledge:t.knowledge,vibeables:t.vibeables,skills:t.skills,...r}});i.ok?(n(i.data),c(``)):y(M(i))}catch(e){y(e.message)}g(!1)}}function E(e,t){f(t?[...d,e]:d.filter(t=>t!==e))}async function D(t){g(!0),y(``);try{let r=await A.request(`agents.archive`,{slug:e,body:{archived:t}});r.ok?n(r.data):y(M(r))}catch(e){y(e.message)}g(!1)}if(r)return(0,F.jsx)(K,{icon:`person_off`,children:`agent not found`});if(!t)return(0,F.jsx)(K,{children:`loading…`});let O=e=>(0,F.jsxs)(`div`,{className:`mt-2 flex items-center gap-2.5`,children:[(0,F.jsx)(V,{variant:`primary`,busy:h,onClick:()=>void T(e),children:h?`saving…`:`save`}),(0,F.jsx)(V,{variant:`quiet`,disabled:h,onClick:()=>(c(``),y(``)),children:`cancel`})]}),k=e=>(0,F.jsx)(V,{size:`sm`,onClick:()=>{e(),y(``)},children:`edit`});return(0,F.jsxs)(`div`,{className:`agent-view flex animate-rise flex-col gap-4`,children:[(0,F.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2.5`,children:[(0,F.jsx)(at,{children:(0,F.jsx)(`span`,{"aria-hidden":!0,children:t.emoji})}),(0,F.jsx)(nt,{size:`lg`,children:t.name}),(0,F.jsx)(W,{children:t.harness}),t.model&&(0,F.jsx)(W,{children:t.model}),t.effort&&(0,F.jsxs)(W,{children:[`effort: `,t.effort]}),t.archived&&(0,F.jsxs)(W,{children:[(0,F.jsx)(I,{name:`inventory_2`,className:`ms-sm mr-1`}),` archived`]}),(0,F.jsx)(`span`,{className:`flex-1`}),(0,F.jsx)(V,{href:`/agents/${encodeURIComponent(e)}/edit`,children:`edit`}),t.archived?(0,F.jsx)(V,{variant:`primary`,icon:`unarchive`,busy:h,onClick:()=>void D(!1),children:h?`…`:`unarchive`}):(0,F.jsx)(V,{variant:`quiet`,icon:`archive`,disabled:h,title:`Hide this agent from the roster — restorable any time`,onClick:()=>void D(!0),children:`archive`})]}),(0,F.jsxs)(J,{children:[(0,F.jsxs)(ct,{children:[(0,F.jsxs)(`div`,{children:[(0,F.jsxs)(`button`,{type:`button`,className:`flex w-full cursor-pointer items-center gap-3.5 border-0 bg-transparent px-[18px] py-3 text-left font-[inherit] text-inherit hover:bg-surface-2`,"aria-expanded":a,onClick:()=>o(!a),children:[(0,F.jsx)(ot,{name:`badge`}),(0,F.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col gap-[3px]`,children:[(0,F.jsx)(`span`,{className:`text-[13.5px] font-medium text-fg`,children:`role`}),!a&&(0,F.jsx)(`span`,{className:P(`text-xs leading-[1.5] text-fg-2 [&_a]:text-inherit [&_code]:text-2xs`,`truncate`),children:(t.system||``).trim().split(`
212
+ `;function ks({slug:e}){let t=N(`agents.skills`,{slug:e})?.skills??[],[n,r]=(0,v.useState)(null),[i,a]=(0,v.useState)(!1),[o,s]=(0,v.useState)(``);async function c(t){s(``);let n=await A.request(`agents.skill`,{slug:e,name:t}).catch(()=>null);if(!n)return void s(`could not load skill`);if(!n.ok||!n.data||typeof n.data!=`object`)return void s(n.error??`could not load skill`);r({name:t,content:n.data.content??``,isNew:!1})}async function l(){if(!n)return;a(!0),s(``);let t=await A.request(`agents.saveSkill`,{slug:e,body:{name:n.name,content:n.content}});a(!1),!t.ok||!t.data||typeof t.data!=`object`?s(t.error??`save failed`):r(null)}async function u(t){window.confirm(`Move skill "/${t}" of this agent to the trash?`)&&(await A.request(`agents.deleteSkill`,{slug:e,name:t}).catch(()=>{}),n?.name===t&&r(null))}return(0,F.jsxs)(J,{title:`own skills — only this agent`,actions:!n&&(0,F.jsx)(V,{size:`sm`,icon:`add`,onClick:()=>{r({name:``,content:Os,isNew:!0}),s(``)},children:`new skill`}),children:[t.length===0&&!n&&(0,F.jsxs)(G,{className:`px-[18px] py-3 text-xs`,children:[`none — skills in `,(0,F.jsxs)(`code`,{children:[`agents/`,e,`/skills/`]}),` are private to this agent; skills for every agent live in the workspace skills folder.`]}),t.length>0&&!n&&(0,F.jsx)(ct,{children:t.map(e=>(0,F.jsx)(st,{icon:`extension`,title:`/${e.name}`,action:(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(V,{size:`sm`,icon:`edit`,onClick:()=>void c(e.name),children:`edit`}),(0,F.jsx)(H,{icon:`delete`,label:`delete /${e.name}`,variant:`danger`,size:`sm`,onClick:()=>void u(e.name)})]}),children:(0,F.jsx)(`span`,{className:`text-xs leading-[1.5] text-fg-2 [&_a]:text-inherit [&_code]:text-2xs`,children:e.description||(0,F.jsx)(`code`,{children:`SKILL.md`})})},e.name))}),n&&(0,F.jsxs)(vt,{className:`max-w-[680px]`,children:[(0,F.jsx)(Z,{label:`name — invoked as /<name>`,children:(0,F.jsx)(X,{className:`font-mono`,value:n.name,placeholder:`e.g. report-html`,disabled:!n.isNew,onChange:e=>r({...n,name:e.target.value})})}),(0,F.jsx)(Z,{label:`SKILL.md — frontmatter (description) + the instructions`,children:(0,F.jsx)(gt,{className:`resize-y font-mono text-[12.5px] leading-[1.65]`,rows:Math.min(28,Math.max(12,n.content.split(`
213
+ `).length+2)),value:n.content,spellCheck:!1,onChange:e=>r({...n,content:e.target.value})})}),(0,F.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,F.jsx)(V,{variant:`primary`,busy:i,disabled:!n.name.trim(),onClick:()=>void l(),children:i?`saving…`:`save`}),(0,F.jsx)(V,{variant:`quiet`,disabled:i,onClick:()=>r(null),children:`cancel`})]})]}),o&&(0,F.jsx)(`div`,{className:`px-[18px] pb-3`,children:(0,F.jsx)(q,{tone:`bad`,children:o})})]})}function As({slug:e}){let t=N(`agents.routines`,{slug:e})?.routines??[],[n,r]=(0,v.useState)(null),[i,a]=(0,v.useState)(``),[o,s]=(0,v.useState)(``);async function c(t){a(``);let n=await A.request(`agents.saveRoutine`,{slug:e,body:t});return n.ok?!0:(a(M(n)),!1)}async function l(t){s(t),a(``);let n=await A.request(`agents.runRoutine`,{slug:e,id:t});s(``),n.ok?n.data.chatId&&B(`/agents/${encodeURIComponent(e)}/chat/${n.data.chatId}`):a(M(n))}async function u(t){window.confirm(`Delete the scheduled prompt "${t}"?`)&&await A.request(`agents.deleteRoutine`,{slug:e,id:t}).catch(()=>{})}return(0,F.jsxs)(J,{title:`schedule — prompts that run on their own`,actions:!n&&(0,F.jsx)(V,{size:`sm`,icon:`add`,onClick:()=>r({name:``,schedule:`0 9 * * 1-5`,prompt:``,enabled:!0}),children:`schedule a prompt`}),children:[t.length===0&&!n&&(0,F.jsx)(G,{className:`px-[18px] py-3 text-xs`,children:`none — a routine messages this agent on a schedule (cron, server local time) and each run opens a new session with the result.`}),t.length>0&&(0,F.jsx)(ct,{children:t.map(t=>(0,F.jsx)(st,{icon:`schedule`,title:(0,F.jsxs)(F.Fragment,{children:[t.name,t.lastError&&(0,F.jsx)(`span`,{title:t.lastError,children:(0,F.jsx)(W,{tone:`bad`,children:`error`})}),t.awaitingApproval&&t.lastChatId&&(0,F.jsx)(W,{href:`/agents/${encodeURIComponent(e)}/chat/${t.lastChatId}`,tone:`bad`,title:`the last run asked for a permission nobody has answered yet`,children:`needs approval`})]}),action:(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(V,{size:`sm`,icon:`play_arrow`,busy:o===t.id,onClick:()=>l(t.id),children:o===t.id?`starting…`:`run`}),(0,F.jsx)(V,{size:`sm`,variant:`quiet`,onClick:()=>r({id:t.id,name:t.name,schedule:t.schedule,prompt:t.prompt,enabled:t.enabled}),children:`edit`}),(0,F.jsx)(V,{size:`sm`,variant:`danger`,onClick:()=>void u(t.id),children:`delete`}),(0,F.jsx)(St,{checked:t.enabled,label:t.enabled?`enabled — click to pause`:`paused — click to enable`,onChange:()=>void c({id:t.id,name:t.name,schedule:t.schedule,prompt:t.prompt,enabled:!t.enabled})})]}),children:(0,F.jsxs)(`span`,{className:`text-xs leading-[1.5] text-fg-2 [&_a]:text-inherit [&_code]:text-2xs`,children:[(0,F.jsx)(`code`,{children:t.schedule}),t.enabled?t.nextRunAt?` · next ${We(t.nextRunAt)}`:``:` · paused`,` · `,t.lastChatId?(0,F.jsxs)(he,{href:`/agents/${encodeURIComponent(e)}/chat/${t.lastChatId}`,children:[`last run `,We(t.lastRunAt)]}):`never ran`]})},t.id))}),n&&(0,F.jsxs)(vt,{className:`max-w-[680px]`,children:[(0,F.jsxs)(yt,{children:[(0,F.jsx)(Z,{label:`name`,className:`flex-1`,children:(0,F.jsx)(X,{value:n.name,placeholder:`e.g. Morning report`,onChange:e=>r({...n,name:e.target.value})})}),(0,F.jsx)(Z,{label:`schedule (cron)`,className:`w-[200px] max-[900px]:w-auto`,children:(0,F.jsx)(X,{className:`font-mono`,value:n.schedule,placeholder:`0 9 * * 1-5`,onChange:e=>r({...n,schedule:e.target.value})})}),(0,F.jsxs)(`label`,{className:`flex h-9 cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,F.jsx)(`input`,{type:`checkbox`,className:`accent-accent`,checked:n.enabled,onChange:e=>r({...n,enabled:e.target.checked})}),`enabled`]})]}),(0,F.jsx)(Z,{label:`prompt — what to ask this agent on each run`,children:(0,F.jsx)(gt,{rows:5,value:n.prompt,placeholder:`Check ... and summarize what changed.`,onChange:e=>r({...n,prompt:e.target.value})})}),(0,F.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,F.jsx)(V,{variant:`primary`,disabled:!n.name.trim()||!n.prompt.trim(),onClick:async()=>{await c(n)&&r(null)},children:n.id?`save`:`add to the schedule`}),(0,F.jsx)(V,{variant:`quiet`,onClick:()=>(r(null),a(``)),children:`cancel`})]})]}),i&&(0,F.jsx)(`div`,{className:`px-[18px] pb-3`,children:(0,F.jsx)(q,{tone:`bad`,children:i})})]})}function js({slug:e}){let[t,n]=(0,v.useState)(null),[r,i]=(0,v.useState)(!1),[a,o]=(0,v.useState)(!1),[s,c]=(0,v.useState)(``),[l,u]=(0,v.useState)(``),[d,f]=(0,v.useState)([]),[p,m]=(0,v.useState)(!0),[h,g]=(0,v.useState)(!1),[_,y]=(0,v.useState)(``),b=we(),x=N(`workflows.list`,{}),S=N(`knowledge.list`,{}),C=N(`vibeables.list`,b.vibeables?{}:null),w=N(`skills.list`,{});(0,v.useEffect)(()=>{let t=!0;return A.call(`agents.get`,{slug:e}).then(e=>t&&n(e)).catch(()=>t&&i(!0)),()=>{t=!1}},[e]);async function T(r){if(t){g(!0),y(``);try{let i=await A.request(`agents.save`,{slug:e,body:{name:t.name,emoji:t.emoji,description:t.description,harness:t.harness,model:t.model,effort:t.effort,group:t.group,system:t.system,workflows:t.workflows,knowledge:t.knowledge,vibeables:t.vibeables,skills:t.skills,...r}});i.ok?(n(i.data),c(``)):y(M(i))}catch(e){y(e.message)}g(!1)}}function E(e,t){f(t?[...d,e]:d.filter(t=>t!==e))}async function D(t){g(!0),y(``);try{let r=await A.request(`agents.archive`,{slug:e,body:{archived:t}});r.ok?n(r.data):y(M(r))}catch(e){y(e.message)}g(!1)}if(r)return(0,F.jsx)(K,{icon:`person_off`,children:`agent not found`});if(!t)return(0,F.jsx)(K,{children:`loading…`});let O=e=>(0,F.jsxs)(`div`,{className:`mt-2 flex items-center gap-2.5`,children:[(0,F.jsx)(V,{variant:`primary`,busy:h,onClick:()=>void T(e),children:h?`saving…`:`save`}),(0,F.jsx)(V,{variant:`quiet`,disabled:h,onClick:()=>(c(``),y(``)),children:`cancel`})]}),k=e=>(0,F.jsx)(V,{size:`sm`,onClick:()=>{e(),y(``)},children:`edit`});return(0,F.jsxs)(`div`,{className:`agent-view flex animate-rise flex-col gap-4`,children:[(0,F.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2.5`,children:[(0,F.jsx)(at,{children:(0,F.jsx)(`span`,{"aria-hidden":!0,children:t.emoji})}),(0,F.jsx)(nt,{size:`lg`,children:t.name}),(0,F.jsx)(W,{children:t.harness}),t.model&&(0,F.jsx)(W,{children:t.model}),t.effort&&(0,F.jsxs)(W,{children:[`effort: `,t.effort]}),t.archived&&(0,F.jsxs)(W,{children:[(0,F.jsx)(I,{name:`inventory_2`,className:`ms-sm mr-1`}),` archived`]}),(0,F.jsx)(`span`,{className:`flex-1`}),(0,F.jsx)(V,{href:`/agents/${encodeURIComponent(e)}/edit`,children:`edit`}),t.archived?(0,F.jsx)(V,{variant:`primary`,icon:`unarchive`,busy:h,onClick:()=>void D(!1),children:h?`…`:`unarchive`}):(0,F.jsx)(V,{variant:`quiet`,icon:`archive`,disabled:h,title:`Hide this agent from the roster — restorable any time`,onClick:()=>void D(!0),children:`archive`})]}),(0,F.jsxs)(J,{children:[(0,F.jsxs)(ct,{children:[(0,F.jsxs)(`div`,{children:[(0,F.jsxs)(`button`,{type:`button`,className:`flex w-full cursor-pointer items-center gap-3.5 border-0 bg-transparent px-[18px] py-3 text-left font-[inherit] text-inherit hover:bg-surface-2`,"aria-expanded":a,onClick:()=>o(!a),children:[(0,F.jsx)(ot,{name:`badge`}),(0,F.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col gap-[3px]`,children:[(0,F.jsx)(`span`,{className:`text-[13.5px] font-medium text-fg`,children:`role`}),!a&&(0,F.jsx)(`span`,{className:P(`text-xs leading-[1.5] text-fg-2 [&_a]:text-inherit [&_code]:text-2xs`,`truncate`),children:(t.system||``).trim().split(`
214
214
  `)[0]||`empty — expand to give this agent a role`})]}),(0,F.jsx)(I,{name:`expand_more`,className:P(`ms-sm flex-none text-fg-2 transition-transform`,a&&`rotate-180`)})]}),a&&s!==`role`&&(0,F.jsxs)(`div`,{className:`pr-[18px] pb-4 pl-16`,children:[(0,F.jsx)(`pre`,{className:`m-0 font-mono text-[12.5px] leading-[1.65] whitespace-pre-wrap`,children:t.system||`(empty — click edit to give this agent a role)`}),(0,F.jsxs)(`div`,{className:`mt-2.5 flex items-center gap-2.5`,children:[(0,F.jsx)(V,{size:`sm`,icon:`edit`,onClick:()=>{u(t.system),c(`role`),y(``)},children:`edit role`}),(0,F.jsx)(`span`,{className:`flex-1`}),(0,F.jsxs)(`span`,{className:`text-xs leading-[1.5] text-fg-2 [&_a]:text-inherit [&_code]:text-2xs`,children:[`agents/`,t.slug,`/system.md`]})]})]}),a&&s===`role`&&(0,F.jsxs)(`div`,{className:`pr-[18px] pb-4 pl-16`,children:[(0,F.jsx)(gt,{className:`resize-y font-mono text-[12.5px] leading-[1.65]`,"aria-label":`role`,rows:Math.min(24,Math.max(8,l.split(`
215
- `).length+2)),value:l,placeholder:`You are the ... for this project. Your job is ...`,onChange:e=>u(e.target.value),spellCheck:!1}),O({system:l})]})]}),(0,F.jsx)(st,{icon:`account_tree`,title:`workflows`,action:s!==`workflows`&&k(()=>(f(t.workflows),c(`workflows`))),children:s===`workflows`?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(ps,{children:[(x?.workflows??[]).map(e=>(0,F.jsx)(bt,{checked:d.includes(e.slug),onChange:t=>E(e.slug,t),hint:e.description,mono:!0,children:e.slug},e.slug)),(x?.workflows??[]).length===0&&(0,F.jsx)(G,{className:`py-1.5 px-0`,children:`no workflows in this project`})]}),O({workflows:d})]}):t.workflows.length===0?(0,F.jsx)(`span`,{className:ds,children:`none connected — the agent can run any workflow you connect`}):(0,F.jsx)(fs,{children:t.workflows.map(e=>(0,F.jsx)(W,{href:`/workflows/${encodeURIComponent(e)}`,children:e},e))})}),(0,F.jsx)(st,{icon:`menu_book`,title:`knowledge`,action:s!==`knowledge`&&k(()=>(f(t.knowledge),c(`knowledge`))),children:s===`knowledge`?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(ps,{children:[(S?.bundles??[]).map(e=>(0,F.jsx)(bt,{checked:d.includes(e.name),onChange:t=>E(e.name,t),hint:`${e.concepts} concepts`,mono:!0,children:e.name},e.name)),(S?.bundles??[]).length===0&&(0,F.jsx)(G,{className:`py-1.5 px-0`,children:`no knowledge bundles in this project`})]}),O({knowledge:d})]}):t.knowledge.length===0?(0,F.jsx)(`span`,{className:ds,children:`none connected — connected bundles are read and kept current by the agent`}):(0,F.jsx)(fs,{children:t.knowledge.map(e=>(0,F.jsx)(W,{href:`/knowledge/${encodeURIComponent(e)}`,children:e},e))})}),(b.vibeables||(t.vibeables??[]).length>0)&&(0,F.jsx)(st,{icon:`web`,title:`apps`,"data-link-kind":`vibeables`,action:s!==`vibeables`&&k(()=>(f(t.vibeables??[]),c(`vibeables`))),children:s===`vibeables`?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(ps,{children:[(C?.vibeables??[]).map(e=>(0,F.jsx)(bt,{checked:d.includes(e.slug),onChange:t=>E(e.slug,t),hint:e.dev?`dev`:`static`,mono:!0,children:e.slug},e.slug)),d.filter(e=>!(C?.vibeables??[]).some(t=>t.slug===e)).map(e=>(0,F.jsx)(bt,{checked:!0,onChange:t=>E(e,t),hint:`not found in this workspace`,mono:!0,children:e},e)),!b.vibeables&&(0,F.jsx)(G,{className:`py-1.5 px-0`,children:`vibeables are off in this workspace's settings`}),b.vibeables&&(C?.vibeables??[]).length===0&&(0,F.jsx)(G,{className:`py-1.5 px-0`,children:`no apps in this workspace yet — create one on the apps page`})]}),O({vibeables:d})]}):(t.vibeables??[]).length===0?(0,F.jsx)(`span`,{className:`text-xs leading-[1.5] text-fg-2 [&_a]:text-inherit [&_code]:text-2xs`,children:`none linked — linked apps are the agent's to build and maintain; it knows them from the first message`}):(0,F.jsx)(fs,{children:(t.vibeables??[]).map(e=>{let t=!b.vibeables||!C||C.vibeables.some(t=>t.slug===e);return(0,F.jsxs)(W,{href:`/vibeables/${encodeURIComponent(e)}`,tone:t?`neutral`:`bad`,title:t?void 0:`configured but not found in this workspace`,children:[e,!t&&` · not found`]},e)})})}),(0,F.jsx)(st,{icon:`extension`,title:`shared skills`,action:s!==`skills`&&k(()=>{m(t.skills===void 0),f(t.skills??[]),c(`skills`)}),children:s===`skills`?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(ps,{children:[(0,F.jsx)(bt,{checked:p,onChange:m,hint:`every discovered skill, including future ones`,mono:!0,children:`all skills`}),!p&&(w?.skills??[]).map(e=>(0,F.jsx)(bt,{checked:d.includes(e.name),onChange:t=>E(e.name,t),hint:e.description,mono:!0,children:`/${e.name}`},e.name)),!p&&(w?.skills??[]).length===0&&(0,F.jsx)(G,{className:`py-1.5 px-0`,children:`no skills found (.claude/skills, project or user)`})]}),O({skills:p?void 0:d})]}):t.skills===void 0?(0,F.jsx)(`span`,{className:ds,children:`all discovered skills (default) — invoke with /name in a session`}):t.skills.length===0?(0,F.jsx)(`span`,{className:ds,children:`none — this agent runs without skills`}):(0,F.jsx)(fs,{children:t.skills.map(e=>(0,F.jsxs)(W,{children:[`/`,e]},e))})})]}),_&&(0,F.jsx)(`div`,{className:`px-[18px] pb-3`,children:(0,F.jsx)(q,{tone:`bad`,children:_})})]}),(0,F.jsx)(Os,{slug:e}),(0,F.jsx)(ks,{slug:e})]})}var js=[`🤖`,`🧑‍💻`,`🎧`,`🛠️`,`📊`,`✍️`,`🔍`,`🧹`,`📦`,`🚀`];function Ms({slug:e}){let[t,n]=(0,v.useState)(e?null:f()),[r,i]=(0,v.useState)(``),[a,o]=(0,v.useState)(!1),s=N(`workflows.list`,{})?.workflows??[],c=N(`knowledge.list`,{})?.bundles??[],l=we(),u=N(`vibeables.list`,l.vibeables?{}:null)?.vibeables??[],d=N(`skills.list`,{})?.skills??[];(0,v.useEffect)(()=>{e&&A.call(`agents.get`,{slug:e}).then(e=>n({name:e.name,emoji:e.emoji,description:e.description??``,harness:e.harness,model:e.model??``,effort:e.effort??``,group:e.group??``,system:e.system,workflows:e.workflows,knowledge:e.knowledge??[],vibeables:e.vibeables??[],skillsAll:e.skills===void 0,skills:e.skills??[]})).catch(()=>i(`agent not found`))},[e]);function f(){return{name:``,emoji:`🤖`,description:``,harness:`claude`,model:``,effort:``,group:``,system:``,workflows:[],knowledge:[],vibeables:[],skillsAll:!0,skills:[]}}async function p(){if(!t)return;o(!0),i(``);let n={...t,skills:t.skillsAll?void 0:t.skills},r=e?await A.request(`agents.save`,{slug:e,body:n}):await A.request(`agents.create`,{body:n});o(!1),r.ok?B(`/agents/${encodeURIComponent(r.data.slug)}/info`):i(M(r))}async function m(){e&&window.confirm(`Move agent "${e}" to the trash?`)&&(await A.request(`agents.delete`,{slug:e}).catch(()=>{}),B(`/agents`))}if(!t)return(0,F.jsx)(K,{children:r||`loading…`});let h=e=>n({...t,...e}),g=(e,n,r)=>h({[e]:r?[...t[e],n]:t[e].filter(e=>e!==n)});return(0,F.jsxs)(it,{width:`narrow`,children:[(0,F.jsx)(nt,{children:e?`edit ${e}`:`new agent`}),(0,F.jsx)(J,{children:(0,F.jsxs)(vt,{className:`max-w-[680px]`,children:[(0,F.jsxs)(yt,{children:[(0,F.jsx)(Z,{label:`name`,className:`flex-1`,children:(0,F.jsx)(X,{value:t.name,placeholder:`e.g. Max`,onChange:e=>h({name:e.target.value})})}),(0,F.jsx)(Z,{label:`emoji`,className:`w-[90px] max-[900px]:w-auto`,children:(0,F.jsx)(X,{value:t.emoji,onChange:e=>h({emoji:e.target.value})})})]}),(0,F.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:js.map(e=>(0,F.jsx)(`button`,{type:`button`,"aria-pressed":t.emoji===e,className:P(`cursor-pointer rounded-xl border px-2.5 py-1.5 text-base transition-colors`,t.emoji===e?`border-transparent bg-accent-soft`:`border-line bg-transparent hover:bg-surface-2`),onClick:()=>h({emoji:e}),children:e},e))}),(0,F.jsxs)(yt,{children:[(0,F.jsx)(Z,{label:`description`,className:`flex-1`,children:(0,F.jsx)(X,{value:t.description,placeholder:`one line: what this agent is for`,onChange:e=>h({description:e.target.value})})}),(0,F.jsx)(Z,{label:`group`,className:`w-[180px] max-[900px]:w-auto`,children:(0,F.jsx)(X,{value:t.group,placeholder:`none`,onChange:e=>h({group:e.target.value})})})]}),(0,F.jsxs)(yt,{children:[(0,F.jsx)(Z,{label:`harness`,className:`w-[140px] max-[900px]:w-auto`,children:(0,F.jsxs)(_t,{value:t.harness,onChange:e=>h({harness:e.target.value}),children:[(0,F.jsx)(`option`,{value:`claude`,children:`claude`}),(0,F.jsx)(`option`,{value:`codex`,children:`codex`}),(0,F.jsx)(`option`,{value:`pi`,children:`pi`})]})}),(0,F.jsx)(Z,{label:`model`,className:`flex-1`,children:(0,F.jsx)(X,{className:`font-mono`,value:t.model,placeholder:`harness default — e.g. sonnet, gpt-5.6-sol`,onChange:e=>h({model:e.target.value})})}),(0,F.jsx)(Z,{label:`effort`,className:`w-[140px] max-[900px]:w-auto`,children:(0,F.jsx)(_t,{value:t.effort,onChange:e=>h({effort:e.target.value}),children:qe.map(e=>(0,F.jsx)(`option`,{value:e,children:e||`default`},e))})})]}),(0,F.jsx)(Z,{label:`system prompt — the agent's role`,children:(0,F.jsx)(gt,{className:ms,rows:10,value:t.system,placeholder:`You are the ... for this project. Your job is ...`,onChange:e=>h({system:e.target.value})})}),(0,F.jsxs)(Ns,{label:`connected workflows — autoloaded into the agent's context; it can run them`,children:[s.map(e=>(0,F.jsx)(bt,{checked:t.workflows.includes(e.slug),onChange:t=>g(`workflows`,e.slug,t),hint:e.description,mono:!0,children:e.slug},e.slug)),s.length===0&&(0,F.jsx)(G,{className:`py-1.5 px-0`,children:`no workflows in this project`})]}),(0,F.jsxs)(Ns,{label:`connected knowledge — OKF bundles the agent consults and maintains`,children:[c.map(e=>(0,F.jsx)(bt,{checked:t.knowledge.includes(e.name),onChange:t=>g(`knowledge`,e.name,t),hint:`${e.concepts} concepts`,mono:!0,children:e.name},e.name)),c.length===0&&(0,F.jsx)(G,{className:`py-1.5 px-0`,children:`no knowledge bundles in this project`})]}),(l.vibeables||t.vibeables.length>0)&&(0,F.jsxs)(Ns,{label:`apps — small apps the agent builds and maintains`,linkKind:`vibeables`,children:[u.map(e=>(0,F.jsx)(bt,{checked:t.vibeables.includes(e.slug),onChange:t=>g(`vibeables`,e.slug,t),hint:e.dev?`dev`:`static`,mono:!0,children:e.slug},e.slug)),t.vibeables.filter(e=>!u.some(t=>t.slug===e)).map(e=>(0,F.jsx)(bt,{checked:!0,onChange:()=>g(`vibeables`,e,!1),hint:`not found in this workspace`,mono:!0,children:e},e)),!l.vibeables&&(0,F.jsx)(G,{className:`py-1.5 px-0`,children:`vibeables are off in this workspace's settings`}),l.vibeables&&u.length===0&&(0,F.jsx)(G,{className:`py-1.5 px-0`,children:`no vibeables in this workspace yet`})]}),(0,F.jsxs)(Ns,{label:`connected skills — workspace skill packages (see the skills tab); invoked with /name in sessions`,children:[(0,F.jsx)(bt,{checked:t.skillsAll,onChange:e=>h({skillsAll:e}),hint:`every discovered skill, including future ones`,mono:!0,children:`all skills`}),!t.skillsAll&&d.map(e=>(0,F.jsx)(bt,{checked:t.skills.includes(e.name),onChange:t=>g(`skills`,e.name,t),hint:e.description,mono:!0,children:`/${e.name}`},e.name)),!t.skillsAll&&d.length===0&&(0,F.jsx)(G,{className:`py-1.5 px-0`,children:`no skills found (.claude/skills, project or user)`})]}),r&&(0,F.jsx)(q,{tone:`bad`,children:r}),(0,F.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,F.jsx)(V,{variant:`primary`,busy:a,disabled:!t.name.trim(),onClick:p,children:a?`saving…`:e?`save`:`create`}),(0,F.jsx)(`span`,{className:`flex-1`}),e&&(0,F.jsx)(V,{variant:`danger`,icon:`delete`,onClick:m,children:`delete agent`})]})]})})]})}function Ns({label:e,linkKind:t,children:n}){return(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,"data-link-kind":t,children:[(0,F.jsx)(`span`,{className:`text-sm font-semibold text-fg`,children:e}),(0,F.jsx)(ps,{children:n})]})}var Ps=`bg-accent/7 outline-[1.5px] -outline-offset-[1.5px] outline-accent outline-dashed`,Fs=`px-2.5 pt-1.5 pb-2 text-2xs text-fg-2`;function Is({seg:e}){let t=e[0]&&e[0]!==`new`&&e[0]!==`chats`?decodeURIComponent(e[0]):void 0,n=e[0]===`new`?`new`:e[0]===`chats`?`chats`:e[1]===`edit`?`edit`:e[1]===`info`?`info`:e[1]===`chat`?`chat`:t?`agent`:`home`,r=n===`chats`&&e[1]===`new`,i=n===`chat`?e[2]:n===`chats`&&!r?e[1]:void 0,a=N(`agents.list`,{}),o=be(),s=Ra(),[c,l]=(0,v.useState)(()=>{try{let e=JSON.parse(localStorage.getItem(`kw-agent-groups`)??`[]`);return Array.isArray(e)?e.map(String):[]}catch{return[]}}),[u,d]=(0,v.useState)(!1),[f,p]=(0,v.useState)(``),[m,h]=(0,v.useState)(null),[g,_]=(0,v.useState)(``),[y,b]=(0,v.useState)(null),[x,S]=(0,v.useState)(null),[C,w]=(0,v.useState)({}),T=(a?.agents??[]).map(e=>C[e.slug]===void 0?e:{...e,group:C[e.slug]||void 0});(0,v.useEffect)(()=>{w(e=>{let t={...e},n=!1;for(let e of a?.agents??[])t[e.slug]!==void 0&&(e.group??``)===t[e.slug]&&(delete t[e.slug],n=!0);return n?t:e})},[a]);let E=T.filter(e=>!e.archived),D=T.filter(e=>e.archived),[O,k]=(0,v.useState)(!1),j=[...new Set([...E.map(e=>e.group??``).filter(Boolean),...c])].sort((e,t)=>e.localeCompare(t)),ee=E.filter(e=>!e.group);function M(e){l(e);try{localStorage.setItem(`kw-agent-groups`,JSON.stringify(e))}catch{}}function te(){let e=f.trim();d(!1),p(``),e&&!j.includes(e)&&M([...c,e])}function ne(e,t){h(null);let n=t.trim();if(n&&n!==e){for(let t of T.filter(t=>t.group===e))L(t.slug,n);c.includes(e)&&M([...new Set(c.map(t=>t===e?n:t))])}}async function L(e,t){if((T.find(t=>t.slug===e)?.group??``)!==t){w(n=>({...n,[e]:t}));try{let n=await A.call(`agents.get`,{slug:e});await A.call(`agents.save`,{slug:e,body:{...n,group:t||void 0}})}catch{w(t=>{let n={...t};return delete n[e],n})}}}let re=e=>o?{onDragOver:t=>{y!=null&&(t.preventDefault(),t.dataTransfer.dropEffect=`move`,x!==e&&S(e))},onDrop:t=>{t.preventDefault();let n=t.dataTransfer.getData(`text/plain`)||y;n&&L(n,e),b(null),S(null)}}:{},ie=e=>(0,F.jsx)(`div`,{className:y===e.slug?`opacity-40`:void 0,onDragStart:t=>{if(!o)return t.preventDefault();t.dataTransfer.setData(`text/plain`,e.slug),t.dataTransfer.effectAllowed=`move`,b(e.slug)},onDragEnd:()=>{b(null),S(null)},children:(0,F.jsx)(Y,{href:`/agents/${encodeURIComponent(e.slug)}`,active:e.slug===t,leading:(0,F.jsx)(`span`,{"aria-hidden":!0,children:e.emoji}),title:e.name,sub:e.description||e.harness})},e.slug),ae=e=>(0,F.jsx)(Y,{href:`/agents/${encodeURIComponent(e.slug)}/info`,active:e.slug===t,dim:e.slug!==t,leading:(0,F.jsx)(`span`,{"aria-hidden":!0,children:e.emoji}),title:e.name,sub:e.description||e.harness},e.slug),oe;oe=n===`new`?(0,F.jsx)(Ms,{},`new`):n===`edit`&&t?(0,F.jsx)(Ms,{slug:t},t):n===`chat`&&t&&i===`new`?(0,F.jsx)(ys,{slug:t,name:T.find(e=>e.slug===t)?.name},t):n===`chat`&&t&&i?(0,F.jsx)(`div`,{className:`chat-main`,children:(0,F.jsx)(jo,{id:i,agentName:T.find(e=>e.slug===t)?.name??t,agentDescription:T.find(e=>e.slug===t)?.description},i)}):n===`chats`?i?(0,F.jsx)(`div`,{className:`chat-main`,children:(0,F.jsx)(jo,{id:i},i)}):r?(0,F.jsx)(Fo,{}):(0,F.jsx)(bs,{}):n===`info`&&t?(0,F.jsx)(As,{slug:t},t):t?(0,F.jsx)(vs,{slug:t,name:T.find(e=>e.slug===t)?.name},t):a?E.length?(0,F.jsx)(Ts,{agents:E}):(0,F.jsx)(Es,{}):(0,F.jsx)(K,{children:`loading…`});let se=(n===`agent`||n===`info`||n===`chat`)&&t?T.find(e=>e.slug===t)?.knowledge??[]:[],[ce,le]=(0,v.useState)(()=>localStorage.getItem(`kw-kside`)!==`hidden`),[ue,de]=(0,v.useState)(()=>Number(localStorage.getItem(`kw-kside-w`))||460),R=se.length>0&&ce;function z(e){le(e),localStorage.setItem(`kw-kside`,e?`open`:`hidden`)}function B(e){de(e),localStorage.setItem(`kw-kside-w`,String(e))}return(0,F.jsxs)(`div`,{className:`runs-screen agents-screen ${t||n===`chats`?`has-tabs`:``} ${(t||n===`chats`)&&s?`has-sessions`:``} ${R?`has-knowledge`:``}`,style:R?{"--kside-w":`${ue}px`}:void 0,children:[(0,F.jsxs)(`aside`,{className:`runs-side`,children:[(0,F.jsx)(wt,{title:`agents`,action:o&&(0,F.jsx)(V,{size:`sm`,variant:`quiet`,icon:`add`,href:`/agents/new`,children:`new`})}),(0,F.jsxs)(Et,{children:[(0,F.jsx)(`div`,{className:`mb-1.5 border-b border-line pb-1.5`,children:(0,F.jsx)(Y,{href:`/agents/chats`,active:n===`chats`,leading:(0,F.jsx)(`span`,{"aria-hidden":!0,children:`🎩`}),title:`Ralv`,sub:`chief of staff of the workspace`})}),(0,F.jsxs)(`div`,{className:P(`rounded-xl`,y&&x===``&&Ps),...re(``),children:[ee.map(ie),y!=null&&ee.length===0&&(0,F.jsx)(`div`,{className:Fs,children:`no group — drop here`})]}),j.map(e=>{let t=E.filter(t=>t.group===e);return(0,F.jsxs)(`div`,{className:P(`group/grp mt-3 rounded-xl`,y&&x===e&&Ps),...re(e),children:[(0,F.jsxs)(`div`,{className:`flex items-center gap-1.5 px-2.5 pt-1.5 pb-0.5`,children:[m===e?(0,F.jsx)(X,{className:`h-7 min-w-0 flex-1 text-2xs`,autoFocus:!0,"aria-label":`group name`,value:g,onChange:e=>_(e.target.value),onKeyDown:t=>{t.key===`Enter`&&ne(e,g),t.key===`Escape`&&h(null)},onBlur:()=>ne(e,g)}):(0,F.jsx)(et,{children:e}),(0,F.jsx)(`span`,{className:`text-[10px] tabular-nums text-fg-2`,children:t.length}),(0,F.jsx)(`span`,{className:`flex-1`}),o&&m!==e&&(0,F.jsx)(H,{icon:`edit`,label:`Rename group`,size:`sm`,className:`size-6 opacity-0 group-hover/grp:opacity-100 focus-visible:opacity-100`,onClick:()=>{h(e),_(e)}}),o&&t.length===0&&c.includes(e)&&(0,F.jsx)(H,{icon:`close`,label:`Remove empty group`,size:`sm`,className:`size-6 opacity-0 group-hover/grp:opacity-100 focus-visible:opacity-100`,onClick:()=>M(c.filter(t=>t!==e))})]}),t.map(ie),t.length===0&&(0,F.jsx)(`div`,{className:Fs,children:o?`drag agents here`:`no agents`})]},e)}),D.length>0&&(0,F.jsxs)(`div`,{className:`mt-2.5 border-t border-line pt-1`,children:[(0,F.jsxs)(`button`,{type:`button`,className:`group/arch flex w-full cursor-pointer items-center gap-1.5 border-0 bg-transparent px-2.5 pt-1.5 pb-0.5 text-left text-fg-2`,"aria-expanded":O,onClick:()=>k(e=>!e),children:[(0,F.jsx)(et,{className:`group-hover/arch:text-fg`,children:`archived`}),(0,F.jsx)(`span`,{className:`text-[10px] tabular-nums`,children:D.length}),(0,F.jsx)(`span`,{className:`flex-1`}),(0,F.jsx)(I,{name:O?`expand_less`:`expand_more`,className:`ms-sm`})]}),O&&D.map(ae)]}),a&&T.length===0&&(0,F.jsx)(G,{className:`py-1.5 px-2.5`,children:`no agents yet`}),o&&(u?(0,F.jsx)(`div`,{className:`px-2.5 pt-2.5 pb-1`,children:(0,F.jsx)(X,{className:`h-8 text-sm`,autoFocus:!0,"aria-label":`new group`,value:f,placeholder:`group name, e.g. Team Content`,onChange:e=>p(e.target.value),onKeyDown:e=>{e.key===`Enter`&&te(),e.key===`Escape`&&(d(!1),p(``))},onBlur:te})}):(0,F.jsxs)(`button`,{type:`button`,className:`mx-2.5 mt-3 mb-1 flex cursor-pointer items-center gap-1 rounded-lg border border-dashed border-line bg-transparent px-2.5 py-1 text-2xs text-fg-2 hover:text-accent`,onClick:()=>d(!0),children:[(0,F.jsx)(I,{name:`add`,className:`ms-sm`}),` group`]}))]})]}),t&&(0,F.jsx)(xs,{slug:t,chatId:i===`new`?void 0:i}),n===`chats`&&(0,F.jsx)(ws,{chatId:i}),(0,F.jsx)(`div`,{className:`runs-main`,children:oe}),R&&(0,F.jsx)(hs,{bundles:se,onHide:()=>z(!1),onResize:B}),se.length>0&&!ce&&(0,F.jsxs)(`button`,{type:`button`,className:`kside-reopen fixed top-[60px] right-3.5 z-5 inline-flex cursor-pointer items-center gap-1 rounded-full border border-line bg-surface-2 px-3 py-1 text-2xs text-fg-2 hover:text-fg`,onClick:()=>z(!0),title:`Show knowledge sidebar`,children:[(0,F.jsx)(I,{name:`menu_book`,className:`ms-sm`}),` knowledge`]})]})}function Ls(e){if(!z(e))return null;let t=e.split(`/`).filter(Boolean),n=decodeURIComponent(t[1]),r=t[0]===`agents`||t[0]===`team`;return n===`new`?t[0]===`projects`?(0,F.jsx)(qo,{},`new-project`):r?(0,F.jsx)(Ms,{},`new-agent`):(0,F.jsx)(Da,{},`new-channel`):t[0]===`projects`&&t[2]===`info`?(0,F.jsx)(es,{slug:n,onChanged:async()=>{}},n):r&&t[2]===`info`?(0,F.jsx)(As,{slug:n},n):r&&t[2]===`edit`?(0,F.jsx)(Ms,{slug:n},n):t[0]===`channels`&&t[2]===`edit`?(0,F.jsx)(Da,{slug:n},n):null}function Rs({back:e,children:t}){let n=()=>B(e);return(0,v.useEffect)(()=>{let e=e=>{e.key!==`Escape`||e.defaultPrevented||document.querySelector(`.palette-backdrop`)||(e.preventDefault(),n())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)}),(0,F.jsx)(`div`,{className:`fixed inset-0 z-40 flex animate-fade items-start justify-center bg-black/38 px-4 pt-[6vh] pb-4 max-[800px]:p-0`,onMouseDown:n,children:(0,F.jsxs)(`div`,{className:`edit-modal relative max-h-[88dvh] w-[min(960px,100%)] animate-modal overflow-y-auto rounded-card border border-line bg-surface shadow-modal max-[800px]:max-h-dvh max-[800px]:rounded-none`,role:`dialog`,"aria-label":`edit`,onMouseDown:e=>e.stopPropagation(),children:[(0,F.jsx)(H,{icon:`close`,label:`close (esc)`,className:`absolute top-3 right-3 z-1 rounded-full`,onClick:n}),(0,F.jsx)(`div`,{className:`runs-main min-w-0 pt-[18px] pr-12 pb-10 pl-6`,children:t})]})})}function zs({runId:e,decision:t}){let{request:n,answer:r}=t,[i,a]=(0,v.useState)(n.options.length===1?n.options[0].value:null),[o,s]=(0,v.useState)(``),[c,l]=(0,v.useState)(!1),[u,d]=(0,v.useState)(null),f=e=>n.options.find(t=>t.value===e)?.label??e;if(r)return(0,F.jsx)(`section`,{className:P(Bs,`decision-panel is-decided`),"aria-label":`decision`,children:(0,F.jsxs)(`div`,{className:`flex flex-col gap-3 px-5 py-4`,children:[(0,F.jsx)(`div`,{className:Vs,children:n.title??`Decision`}),(0,F.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 text-base`,children:[(0,F.jsx)(W,{tone:`ok`,children:f(r.decision)}),r.note&&(0,F.jsxs)(`span`,{className:`text-fg-2`,children:[`“`,r.note,`”`]}),r.decidedAt&&(0,F.jsx)(`span`,{className:`text-xs tabular-nums text-fg-2`,children:We(r.decidedAt)})]})]})});let p=!!i&&!c&&(n.note!==`required`||!!o.trim());async function m(){if(!p)return;l(!0),d(null);let t=await A.request(`runs.decide`,{id:e,body:{decision:i,note:o.trim()}}).catch(()=>null);t?.ok||(d(t?.error??`could not save the decision`),l(!1))}return(0,F.jsx)(`section`,{className:P(Bs,`decision-panel`),"aria-label":`decision needed`,children:(0,F.jsxs)(`div`,{className:`flex flex-col gap-3 px-5 py-4`,children:[(0,F.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,F.jsx)(U,{tone:`working`}),(0,F.jsx)(`div`,{className:Vs,children:n.title??`This run needs your decision`})]}),n.prompt&&(0,F.jsx)(`p`,{className:`m-0 max-w-[80ch] text-base text-fg-2`,children:n.prompt}),(0,F.jsx)(`div`,{className:`flex flex-wrap gap-2 self-start`,role:`radiogroup`,"aria-label":`options`,children:n.options.map(e=>(0,F.jsx)(V,{role:`radio`,"aria-checked":i===e.value,variant:i===e.value?`primary`:`secondary`,onClick:()=>a(e.value),children:e.label??e.value},e.value))}),n.note!==!1&&(0,F.jsx)(X,{value:o,placeholder:n.note===`required`?`Note (required)`:`Note`,"aria-label":`note`,className:`max-w-[60ch]`,onChange:e=>s(e.target.value),onKeyDown:e=>e.key===`Enter`&&m()}),u&&(0,F.jsx)(q,{tone:`bad`,children:u}),(0,F.jsx)(`div`,{className:`flex gap-2`,children:(0,F.jsx)(V,{variant:`primary`,onClick:m,disabled:!p,busy:c,children:c?`Saving…`:`Submit decision`})})]})})}var Bs=`mb-[18px] overflow-hidden rounded-card border border-line bg-surface`,Vs=`text-[16px] font-medium text-fg`;function Hs(e){return e===`ok`?`ok`:e===`running`?`working`:e===`failed`||e===`blocked`?`bad`:`idle`}function Us({status:e}){return(0,F.jsx)(`span`,{"data-ui":`status`,"data-status":e,className:`inline-flex`,children:(0,F.jsx)(W,{tone:e===`ok`?`ok`:e===`failed`||e===`blocked`?`bad`:e===`running`?`accent`:`neutral`,children:e})})}function Ws(){return(0,F.jsx)(`span`,{"data-ui":`decision`,className:`inline-flex`,children:(0,F.jsx)(W,{tone:`accent`,children:`decision needed`})})}function Gs({label:e,children:t,className:n}){return(0,F.jsxs)(`div`,{className:n,children:[(0,F.jsx)(et,{className:`mb-px block`,children:e}),(0,F.jsx)(`div`,{className:`font-mono text-md font-medium tabular-nums text-fg`,children:t})]})}var Ks=`mb-[22px] flex flex-wrap gap-[26px]`;function qs({id:e,workflow:t}){let n=N(`runs.list`,{},{fast:!0}),r=n?.runs??[],[i,a]=(0,v.useState)(t??``),o=(0,v.useMemo)(()=>{let e=i.trim().toLowerCase();return e?r.filter(t=>[t.workflow,t.request,t.id].some(t=>t?.toLowerCase().includes(e))):r},[r,i]);return(0,F.jsxs)(`div`,{className:`runs-screen`,children:[(0,F.jsxs)(`aside`,{className:`runs-side`,children:[(0,F.jsx)(wt,{title:`runs`,back:{href:`/workflows`,label:`back to workflows`},count:i?`${o.length} / ${r.length}`:r.length}),(0,F.jsx)(Tt,{icon:`filter_list`,value:i,placeholder:`filter by workflow or request`,"aria-label":`filter runs`,onChange:e=>a(e.target.value)}),(0,F.jsxs)(Et,{label:`runs list`,children:[o.map(t=>(0,F.jsx)(Js,{r:t,active:t.id===e},t.id)),n&&r.length===0&&(0,F.jsx)(Dt,{children:`no runs yet`}),r.length>0&&o.length===0&&(0,F.jsxs)(Dt,{children:[`no run matches “`,i,`”`]})]})]}),(0,F.jsx)(`div`,{className:`runs-main`,children:(0,F.jsx)(Ys,{id:e},e)})]})}function Js({r:e,active:t}){return(0,F.jsx)(Y,{href:`/runs/${e.id}`,active:t,size:`sm`,leading:(0,F.jsx)(U,{tone:Hs(e.status),title:e.status}),title:e.workflow??`unknown`,meta:We(e.startedAt),sub:(0,F.jsxs)(`span`,{className:`flex gap-2`,children:[(0,F.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,title:e.request,children:e.status===`running`&&e.currentPhase?`${e.currentPhase}`:e.request??``}),(0,F.jsx)(`span`,{className:`shrink-0 tabular-nums`,children:e.status===`running`?(0,F.jsx)(Ke,{since:e.startedAt}):Be(e.durationMs)})]})})}function Ys({id:e}){let t=N(`runs.get`,{id:e},{fast:!0}),n=t?.status===`running`,[r,i]=(0,v.useState)(null),[a,o]=(0,v.useState)(!1),[s,c]=(0,v.useState)(null),l=be();if(!t)return(0,F.jsx)(K,{children:`loading…`});let u=t.files.some(e=>e.name===`runner.json`),d=r??(n?`run`:`artifacts`),f=l?t.files.length:t.files.filter(e=>!nc(e.name)).length;async function p(){o(!0),c(null);let t=await A.request(`runs.stop`,{id:e}).catch(()=>null);t?.ok||(o(!1),c(t?.error??`stop failed`))}async function m(){if(!window.confirm(`Move run ${e} to the trash?`))return;c(null);let n=await A.request(`runs.delete`,{id:e}).catch(()=>null);if(n?.ok){B(t?.workflow?`/workflows/${encodeURIComponent(t.workflow)}`:`/workflows`);return}c(n?.error??`remove failed`)}return(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(`header`,{className:`mb-1.5 flex flex-wrap items-center gap-x-4 gap-y-2.5`,children:[(0,F.jsx)(U,{tone:Hs(t.status),title:t.status}),(0,F.jsx)(nt,{size:`lg`,children:t.workflow?(0,F.jsx)(he,{href:`/workflows/${encodeURIComponent(t.workflow)}`,title:`open workflow`,className:`text-inherit no-underline hover:text-accent`,children:t.workflow}):`unknown workflow`}),(0,F.jsx)(Us,{status:t.status}),u&&(0,F.jsxs)(W,{children:[(0,F.jsx)(I,{name:`science`,className:`ms-sm mr-1`}),` sandbox`]}),(0,F.jsx)(`span`,{className:`font-mono text-xs text-fg-2`,children:e.replace(/^run-/,``)}),n?(0,F.jsx)(V,{size:`sm`,variant:`danger`,icon:`stop`,busy:a,onClick:p,children:a?`stopping…`:`stop`}):(0,F.jsx)(V,{size:`sm`,variant:`danger`,icon:`delete`,onClick:m,title:`delete this run's folder`,children:`remove`}),s&&(0,F.jsx)(`span`,{className:`text-xs text-bad`,children:s}),(0,F.jsx)(`span`,{className:`flex-1`}),(0,F.jsx)(V,{size:`sm`,variant:`quiet`,title:`chat with an agent about this run`,onClick:()=>void Po(`claude`,{kind:`run`,runId:e}),children:`⌬ discuss`}),(0,F.jsx)(ft,{className:`border-b-0 px-0`,label:`run sections`,value:d,onChange:i,items:[{id:`run`,label:`run`},{id:`artifacts`,label:`artifacts`,count:f}]})]}),t.request&&(0,F.jsx)(`p`,{className:`mb-5 max-w-[90ch] text-base text-fg-2`,children:t.request}),d===`run`?(0,F.jsx)(Xs,{run:t,live:n}):(0,F.jsx)(ic,{id:e,files:t.files,live:n})]})}function Xs({run:e,live:t}){return(0,F.jsxs)(`div`,{className:`max-w-[1080px]`,children:[e.decision&&(0,F.jsx)(zs,{runId:e.id,decision:e.decision}),(0,F.jsxs)(`div`,{className:Ks,children:[(0,F.jsxs)(Gs,{label:`phases`,children:[e.phasesDone,e.phasesTotal==null?``:` / ${e.phasesTotal}`]}),(0,F.jsx)(Gs,{label:`duration`,children:t?(0,F.jsx)(Ke,{since:e.startedAt}):Be(e.durationMs)}),(0,F.jsx)(Gs,{label:`cost`,children:Ve(e.costUsd??Qs(e.phases))}),(0,F.jsxs)(Gs,{label:`tokens in / out`,children:[He(Zs(e.phases,`tokensIn`)),` / `,He(Zs(e.phases,`tokensOut`))]})]}),(0,F.jsx)(J,{title:`phase timeline`,actions:t&&(0,F.jsxs)(`span`,{className:`inline-flex items-center gap-[7px] text-2xs text-fg-2`,children:[(0,F.jsx)(U,{tone:`working`}),` live · polling`]}),children:(0,F.jsx)(`div`,{className:`py-1.5`,children:e.phases.map(e=>(0,F.jsx)(ec,{p:e},e.phase))})})]})}function Zs(e,t){return e.reduce((e,n)=>e+(n[t]??0),0)}function Qs(e){return e.reduce((e,t)=>e+(t.costUsd??0),0)}var $s=`relative border-line/55 [&+&]:border-t before:absolute before:top-0 before:bottom-0 before:w-px before:bg-line last:before:bottom-auto`;function ec({p:e}){let t=e.gates.filter(e=>!e.passed);return(0,F.jsxs)(`div`,{className:P($s,`py-2.5 pr-[18px] pl-[42px] before:left-[23px] first:before:top-4 last:before:h-4`),children:[(0,F.jsx)(`span`,{className:`absolute top-4 left-[19px] z-1 grid`,children:(0,F.jsx)(U,{tone:Hs(e.status),title:e.status})}),(0,F.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-2.5`,children:[(0,F.jsx)(`span`,{className:`text-base font-medium text-fg`,children:e.phase}),e.kind===`agent`?(0,F.jsxs)(W,{tone:`accent`,children:[e.agent,e.model?` · ${e.model}`:``,e.protocol?` · ${e.protocol}`:``]}):(0,F.jsx)(W,{children:`script`}),e.status===`skipped`&&(0,F.jsx)(Us,{status:`skipped`}),(0,F.jsxs)(`span`,{className:`ml-auto flex gap-3.5 font-mono text-[11.5px] tabular-nums text-fg-2`,children:[e.attempts>1&&(0,F.jsxs)(`span`,{children:[`att `,e.attempts]}),e.status===`running`?(0,F.jsx)(Ke,{since:e.startedAt}):e.durationMs!=null&&(0,F.jsx)(`span`,{children:Be(e.durationMs)}),e.kind===`agent`&&e.tokensIn!=null&&(0,F.jsxs)(`span`,{children:[He(e.tokensIn),` / `,He(e.tokensOut)]}),e.costUsd!=null&&e.costUsd>0&&(0,F.jsx)(`span`,{children:Ve(e.costUsd)})]})]}),e.status===`running`&&e.lastActivity&&(0,F.jsxs)(`div`,{className:`mt-[3px] font-mono text-[11.5px] text-accent`,children:[`▸ `,e.lastActivity]}),e.summary&&e.status!==`running`&&(0,F.jsx)(`div`,{className:`mt-[3px] max-w-[72ch] text-[12.5px] text-fg-2`,children:e.summary}),e.gates.length>0&&(0,F.jsx)(`div`,{className:`mt-[5px] flex flex-wrap gap-1.5`,children:e.gates.map(e=>(0,F.jsxs)(`span`,{className:P(`inline-flex items-center gap-[5px] rounded-lg px-2.5 py-0.5 font-mono text-2xs`,e.passed?`bg-ok-soft text-ok`:`bg-bad-soft text-on-bad-soft`),title:e.failure??``,children:[(0,F.jsx)(I,{name:e.passed?`check`:`close`,className:`ms-sm`}),` `,e.gate]},e.gate))}),t.map(e=>(0,F.jsx)(`div`,{className:`mt-1 text-xs text-bad`,children:e.failure},e.gate))]})}var tc=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`]);function nc(e){return e===`runner.json`||e.endsWith(`.jsonl`)||e.endsWith(`.log`)}function rc(e){let t=[`report.html`,`recommendation.md`].find(t=>e.some(e=>e.name===t));if(t)return t;let n=e=>{let t=e.split(`.`).pop()?.toLowerCase()??``;return[`html`,`md`,`markdown`,`pdf`].includes(t)||tc.has(t)?0:nc(e)?2:1},r=null;for(let t of e)(!r||n(t.name)<n(r.name))&&(r=t);return r?.name??null}function ic({id:e,files:t,live:n}){let[r,i]=(0,v.useState)(null),a=be(),o=(0,v.useMemo)(()=>a?t:t.filter(e=>!nc(e.name)),[t,a]);return(0,v.useEffect)(()=>{!a&&r&&nc(r)&&i(null)},[a,r]),(0,v.useEffect)(()=>{r||o.length===0||i(rc(o))},[o,r]),(0,F.jsxs)(`div`,{className:`grid h-[calc(100vh-172px)] min-h-[420px] grid-cols-[280px_minmax(0,1fr)] gap-3.5 max-[940px]:h-auto max-[940px]:grid-cols-1`,children:[(0,F.jsx)(J,{title:(0,F.jsxs)(F.Fragment,{children:[`files `,(0,F.jsxs)(`span`,{className:`tabular-nums`,children:[`(`,o.length,`)`]})]}),className:`flex min-h-0 flex-col`,children:(0,F.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-auto max-[940px]:max-h-60`,children:[o.map(e=>(0,F.jsxs)(`button`,{type:`button`,className:P(`flex w-full cursor-pointer items-center gap-2.5 border-0 border-b border-line/55 px-[18px] py-2 text-left font-mono text-[12.5px] transition-colors last:border-b-0`,r===e.name?`bg-accent-soft text-on-accent-soft`:`bg-transparent text-fg-2 hover:bg-surface-2 hover:text-fg`),onClick:()=>i(e.name),children:[(0,F.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.name}),(0,F.jsx)(`span`,{className:`text-2xs tabular-nums text-fg-2`,children:Ue(e.size)})]},e.name)),o.length===0&&(0,F.jsx)(G,{className:`px-[18px] py-3`,children:t.length>0?`no result files — raw run files live in expert mode`:`no files yet`})]})}),(0,F.jsx)(J,{title:r??`viewer`,className:`flex min-h-0 flex-col`,actions:r&&(0,F.jsx)(`a`,{className:ac,href:A.url(`runs.file`,{id:e,query:{name:r,raw:!0}}),target:`_blank`,children:`open raw ↗`}),children:r?(0,F.jsx)(uc,{id:e,name:r,live:n}):(0,F.jsx)(K,{className:`flex-1 justify-center`,children:`select a file`})})]})}var ac=`inline-flex h-7 items-center rounded-control px-2.5 text-sm font-medium text-fg-2 no-underline transition-colors hover:bg-surface-2 hover:text-fg`,oc=`flex min-h-0 flex-1 flex-col`,sc=`min-h-0 flex-1`,cc=`m-0 h-full overflow-auto px-[18px] py-3.5 text-xs leading-[1.55] break-words whitespace-pre-wrap text-fg-2`,lc=`block h-full min-h-[560px] w-full border-0 bg-white`;function uc({id:e,name:t,live:n}){let r=t.split(`.`).pop()?.toLowerCase()??``,i=A.url(`runs.file`,{id:e,query:{name:t,raw:!0}});return r===`html`?(0,F.jsx)(`div`,{className:oc,children:(0,F.jsx)(`div`,{className:sc,children:(0,F.jsx)(`iframe`,{className:lc,src:i,sandbox:`allow-scripts`,allow:`clipboard-write`,title:t})})}):r===`pdf`?(0,F.jsx)(`div`,{className:oc,children:(0,F.jsx)(`div`,{className:sc,children:(0,F.jsx)(`iframe`,{className:lc,src:i,title:t})})}):tc.has(r)?(0,F.jsx)(`div`,{className:oc,children:(0,F.jsx)(`div`,{className:sc,children:(0,F.jsx)(`img`,{className:`block max-h-full max-w-full object-contain px-[18px] py-3.5`,src:i,alt:t})})}):r===`md`||r===`markdown`?(0,F.jsx)(fc,{id:e,name:t,live:n}):(0,F.jsx)(pc,{id:e,name:t,live:n})}var dc=`flex items-center gap-3 border-b border-line/55 px-[18px] py-1.5 text-2xs text-fg-2`;function fc({id:e,name:t,live:n}){let[r,i]=(0,v.useState)(`rendered`),a=N(`runs.fileText`,{id:e,query:{name:t}},{fast:n}),o=(0,v.useMemo)(()=>a?da.sanitize(Fr.parse(a.content,{async:!1})):``,[a?.content]);return(0,F.jsxs)(`div`,{className:oc,children:[(0,F.jsxs)(`div`,{className:dc,children:[(0,F.jsx)(ft,{className:`border-b-0 px-0`,label:`markdown view`,value:r,onChange:i,items:[{id:`rendered`,label:`rendered`},{id:`source`,label:`source`}]}),a?.truncated&&(0,F.jsxs)(`span`,{children:[`large file — showing the last `,Ue(4e5)]})]}),(0,F.jsx)(`div`,{className:P(sc,`overflow-auto`),children:a?r===`rendered`?(0,F.jsx)(`div`,{className:`md-body`,dangerouslySetInnerHTML:{__html:o}}):(0,F.jsx)(`pre`,{className:cc,children:a.content||`(empty)`}):(0,F.jsx)(`pre`,{className:cc,children:`loading…`})})]})}function pc({id:e,name:t,live:n}){let r=N(`runs.fileText`,{id:e,query:{name:t}},{fast:n});return(0,F.jsxs)(`div`,{className:oc,children:[r?.truncated&&(0,F.jsxs)(`div`,{className:dc,children:[`large file — showing the last `,Ue(4e5)]}),(0,F.jsx)(`div`,{className:sc,children:(0,F.jsx)(`pre`,{className:cc,children:r?r.content||`(empty)`:`loading…`})})]})}function mc(){return N(`workflows.runner`,{slug:`any`},{interval:15e3})}var hc=e=>!!e?.available&&!!e?.image;function gc(e){return e?e.available?e.image?`isolated container per run`:"image missing — run `kraftwerk runner build`":`Docker is not running`:``}async function _c(e,t){return(await A.call(`workflows.run`,{slug:e,body:t})).runId}function vc(e,t,n,r){let[i,a]=(0,v.useState)(``),[o,s]=(0,v.useState)(!0),[c,l]=(0,v.useState)(!1),[u,d]=(0,v.useState)(!1),[f,p]=(0,v.useState)(null),m=mc();(0,v.useEffect)(()=>{!i&&n&&a(n)},[n]),(0,v.useEffect)(()=>{m&&!hc(m)&&s(!1)},[m]);let h=!u&&(!t||!!i.trim())&&(!o||hc(m));async function g(){if(h){d(!0),p(null);try{let t=await _c(e,{request:i.trim(),sandbox:o,ssh:c});r?(r(t),d(!1)):B(`/runs/${t}`)}catch(e){p(e.message),d(!1)}}}return{request:i,setRequest:a,sandbox:o,setSandbox:s,ssh:c,setSsh:l,busy:u,error:f,docker:m,canRun:h,launch:g}}function yc({slug:e,usesRequest:t,initialRequest:n,onLaunched:r}){let i=vc(e,t,n,r);return(0,F.jsxs)(`div`,{className:`flex flex-col gap-1 px-5 pt-4 pb-2`,children:[(0,F.jsxs)(`div`,{className:`flex items-center gap-4 max-[700px]:flex-wrap`,children:[t?(0,F.jsx)(X,{className:`h-11 min-w-0 flex-1 text-md`,value:i.request,placeholder:`Request`,"aria-label":`request`,onChange:e=>i.setRequest(e.target.value),onKeyDown:e=>e.key===`Enter`&&i.launch()}):(0,F.jsx)(`span`,{className:`flex-1 text-base text-fg-2`,children:`This workflow takes no request.`}),(0,F.jsx)(V,{variant:`primary`,icon:`play_arrow`,className:`h-11 px-5 max-[700px]:w-full`,busy:i.busy,onClick:i.launch,disabled:!i.canRun,children:i.busy?`Starting…`:`Run`})]}),(0,F.jsxs)(`div`,{className:`-mx-2 mt-1 flex flex-wrap gap-x-2`,children:[(0,F.jsx)(Ct,{label:`Docker sandbox`,hint:gc(i.docker),checked:i.sandbox,onChange:i.setSandbox}),i.sandbox&&(0,F.jsx)(Ct,{label:`Forward SSH agent`,hint:`keys and known hosts from this machine`,checked:i.ssh,onChange:i.setSsh})]}),i.error&&(0,F.jsx)(q,{tone:`bad`,children:i.error})]})}var bc=`\0done`,xc=5;function Sc(e,t){return e.status===`ok`?bc:e.currentPhase&&t.includes(e.currentPhase)?e.currentPhase:t[0]??bc}var Cc=[`var(--accent)`,`#4fb8a8`,`#a78bfa`,`#e5793b`];function wc(e){return e==null?`var(--text-2)`:Cc[e%Cc.length]}function Tc({colour:e,children:t,small:n}){return(0,F.jsx)(`span`,{style:{"--aid":e},className:P(`relative z-1 grid flex-none place-items-center rounded-full border font-mono font-bold tabular-nums`,`border-[color-mix(in_srgb,var(--aid)_55%,var(--line))] bg-[color-mix(in_srgb,var(--aid)_18%,var(--surface-1))] text-[var(--aid)]`,n?`size-[22px] text-2xs`:`mt-px size-[26px] text-[11.5px]`),children:t})}function Ec({wf:e,runs:t,agentIdx:n,runsHref:r}){let i=e.steps.map(e=>e.name),a=new Map([...i,bc].map(e=>[e,[]]));for(let e of t)a.get(Sc(e,i)).push(e);let o=a.get(bc)??[];return(0,F.jsxs)(`div`,{className:`board flex items-start gap-3 overflow-x-auto px-[18px] pt-3.5 pb-[18px]`,children:[e.steps.map((e,t)=>{let i=a.get(e.name)??[];return(0,F.jsx)(Dc,{step:e.name,index:(0,F.jsx)(Tc,{small:!0,colour:wc(e.agent?n.get(e.agent)??0:null),children:t+1}),count:i.length,children:(0,F.jsx)(Oc,{cards:i,moreHref:r})},e.name)}),(0,F.jsx)(Dc,{step:`done`,name:`done`,done:!0,index:(0,F.jsx)(Tc,{small:!0,colour:`var(--ok)`,children:`✓`}),count:o.length,children:(0,F.jsx)(Oc,{cards:o,moreHref:r})})]})}function Dc({step:e,name:t,done:n,index:r,count:i,children:a}){return(0,F.jsxs)(`div`,{className:P(`board-col flex min-w-60 flex-[0_0_240px] flex-col gap-1.5`,n&&`is-done`),"data-step":e,children:[(0,F.jsxs)(`div`,{className:`flex items-center gap-2 px-0.5 pt-0.5 pb-1`,children:[r,(0,F.jsx)(`span`,{className:`board-col-name min-w-0 truncate text-[13.5px] font-medium text-fg`,title:t??e,children:t??e}),(0,F.jsx)(`span`,{className:`board-col-count ml-auto font-mono text-[11.5px] tabular-nums text-fg-2`,children:i})]}),a]})}function Oc({cards:e,moreHref:t}){return(0,F.jsxs)(`div`,{className:`flex min-h-14 flex-col gap-2 rounded-xl bg-surface-2/60 p-2`,children:[e.slice(0,xc).map(e=>(0,F.jsx)(kc,{r:e},e.id)),e.length===0&&(0,F.jsx)(`div`,{className:`board-col-empty py-3.5 text-center text-xs text-fg-2`,children:`—`}),e.length>xc&&(0,F.jsxs)(he,{href:t,className:`board-more block p-1.5 text-center text-xs text-fg-2 no-underline hover:text-accent`,children:[`+ `,e.length-xc,` more ↗`]})]})}function kc({r:e}){let t=e.request??e.id.replace(/^run-/,``);return(0,F.jsxs)(he,{href:`/runs/${e.id}`,className:`board-card block rounded-xl border border-line bg-surface px-3 py-2.5 text-inherit no-underline transition-colors hover:bg-surface-2`,children:[(0,F.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,F.jsx)(U,{tone:Hs(e.status),title:e.status}),(0,F.jsx)(`span`,{className:`min-w-0 truncate text-[13.5px] font-medium text-fg`,title:t,children:t})]}),(0,F.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap gap-2.5 font-mono text-[11.5px] tabular-nums text-fg-2`,children:[(0,F.jsx)(`span`,{children:We(e.startedAt)}),(0,F.jsx)(`span`,{children:e.status===`running`?(0,F.jsx)(Ke,{since:e.startedAt}):Be(e.durationMs)}),e.costUsd!=null&&e.costUsd>0&&(0,F.jsx)(`span`,{children:Ve(e.costUsd)})]}),(e.awaitingDecision||e.status===`failed`||e.status===`aborted`)&&(0,F.jsxs)(`div`,{className:`mt-2 flex flex-wrap gap-1.5`,children:[e.awaitingDecision&&(0,F.jsx)(Ws,{}),(e.status===`failed`||e.status===`aborted`)&&(0,F.jsx)(Us,{status:e.status})]})]})}function Ac({slug:e,tab:t}){let n=N(`workflows.get`,{slug:e}),[r,i]=(0,v.useState)(0),[a,o]=(0,v.useState)(0),s=N(`runs.list`,{},{fast:a>0||Date.now()-r<2e4});if(!n)return(0,F.jsx)(K,{children:`loading…`});if(n.error)return(0,F.jsxs)(K,{children:[(0,F.jsx)(W,{tone:`bad`,children:`broken workflow`}),(0,F.jsx)(`pre`,{className:`mt-3 text-left`,children:n.error}),(0,F.jsx)(`div`,{className:`mt-4 flex justify-center`,children:(0,F.jsx)(Mc,{slug:n.slug})})]});let c=new Map(n.agents.map((e,t)=>[e.id,t%4])),l=(s?.runs??[]).filter(e=>e.workflow===n.name||e.workflow===n.slug),u=`/workflows/${encodeURIComponent(n.slug)}`,d=l.filter(e=>e.status===`running`).length;return d!==a&&o(d),(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(`header`,{className:`mb-1.5 flex flex-wrap items-center gap-x-4 gap-y-2.5 in-[.ctx-embed]:mb-3 in-[.ctx-embed]:gap-y-2`,children:[(0,F.jsx)(nt,{size:`lg`,className:`in-[.ctx-embed]:text-xl`,children:n.name??n.slug}),(0,F.jsx)(`span`,{className:`min-w-0 font-mono text-xs [overflow-wrap:anywhere] text-fg-2 in-[.ctx-embed]:hidden`,children:n.dir}),(0,F.jsx)(`span`,{className:`flex-1`}),(0,F.jsx)(ft,{bare:!0,label:`workflow sections`,value:t,items:[{id:`overview`,href:u,label:`overview`},{id:`details`,href:`${u}/details`,label:`details`},{id:`runs`,href:`${u}/runs`,label:(0,F.jsxs)(F.Fragment,{children:[`runs `,(0,F.jsxs)(`span`,{className:`tabular-nums`,children:[`(`,l.length,`)`]})]})}]})]}),n.description&&(0,F.jsx)(`p`,{className:`mb-5 max-w-[90ch] text-base text-fg-2`,children:n.description}),t===`overview`&&(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(J,{className:`run-panel mb-[18px]`,children:(0,F.jsx)(yc,{slug:n.slug,usesRequest:n.usesRequest,initialRequest:l[0]?.request,onLaunched:()=>i(Date.now())})}),(0,F.jsx)(J,{title:(0,F.jsxs)(F.Fragment,{children:[`board`,` `,(0,F.jsxs)(`span`,{className:`tabular-nums`,children:[`(`,l.length,` runs`,d>0?`, ${d} live`:``,`)`]})]}),actions:l[0]&&(0,F.jsx)(V,{size:`sm`,variant:`quiet`,href:`${u}/runs`,className:`in-[.ctx-embed]:hidden`,children:`all runs ↗`}),children:(0,F.jsx)(Ec,{wf:n,runs:l,agentIdx:c,runsHref:`${u}/runs`})})]}),t===`details`&&(0,F.jsx)(jc,{wf:n,agentIdx:c}),t===`runs`&&(0,F.jsx)(Nc,{runs:l})]})}function jc({wf:e,agentIdx:t}){return(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(`div`,{className:Ks,children:[(0,F.jsx)(Gs,{label:`agents`,children:e.agents.length}),(0,F.jsxs)(Gs,{label:`steps`,children:[e.steps.length,` `,(0,F.jsxs)(`span`,{className:`font-normal text-fg-2`,children:[`(`,e.steps.filter(e=>e.kind===`agent`).length,` agent · `,e.steps.filter(e=>e.kind===`script`).length,` script)`]})]}),e.workspace&&(0,F.jsx)(Gs,{label:`workspace`,className:`max-w-[420px]`,children:(0,F.jsx)(`span`,{className:`text-[11.5px] font-normal whitespace-pre-wrap text-fg-2`,children:e.workspace})})]}),(0,F.jsx)(J,{title:`agents`,className:`mb-[18px]`,children:(0,F.jsxs)(`div`,{className:`grid grid-cols-[repeat(auto-fit,minmax(280px,1fr))]`,children:[e.agents.map(e=>(0,F.jsx)(Fc,{a:e,idx:t.get(e.id)??0},e.id)),e.agents.length===0&&(0,F.jsx)(G,{className:`px-[18px] py-3`,children:`no agents — script-only workflow`})]})}),(0,F.jsxs)(`div`,{className:`grid items-start gap-[18px] grid-cols-[minmax(430px,5fr)_minmax(360px,4fr)] max-[1100px]:grid-cols-1 in-[.ctx-embed]:grid-cols-1`,children:[(0,F.jsx)(J,{title:`pipeline`,children:(0,F.jsx)(`div`,{className:`pipeline py-2`,children:e.steps.map((e,n)=>(0,F.jsx)(Ic,{s:e,i:n,idx:e.agent?t.get(e.agent)??0:null},e.name))})}),(0,F.jsx)(J,{title:(0,F.jsxs)(F.Fragment,{children:[`folder `,(0,F.jsxs)(`span`,{className:`tabular-nums`,children:[`(`,e.files.length,` files)`]})]}),children:(0,F.jsx)(`div`,{className:`max-h-[300px] overflow-auto`,children:e.files.map(e=>(0,F.jsx)(`div`,{className:`truncate border-b border-line/55 px-[18px] py-2 font-mono text-[12.5px] text-fg-2 last:border-b-0`,children:e},e))})})]}),(0,F.jsx)(`div`,{className:`mt-[18px] in-[.ctx-embed]:hidden`,children:(0,F.jsx)(Mc,{slug:e.slug})})]})}function Mc({slug:e}){let[t,n]=(0,v.useState)(!1),[r,i]=(0,v.useState)(!1),[a,o]=(0,v.useState)(``),s=async()=>{i(!0),o(``);try{let t=await A.request(`workflows.delete`,{slug:e});if(!t.ok)throw Error(t.error||`failed`);B(`/workflows`,{replace:!0})}catch(e){o(e.message),n(!1)}finally{i(!1)}};return(0,F.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,F.jsx)(`div`,{className:`flex flex-wrap items-center gap-2`,children:t?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(V,{variant:`danger`,icon:`delete`,busy:r,onClick:()=>void s(),children:`confirm delete`}),(0,F.jsx)(V,{variant:`quiet`,onClick:()=>n(!1),children:`cancel`}),(0,F.jsx)(G,{children:`its runs stay; the trash can put it back`})]}):(0,F.jsx)(V,{variant:`danger`,icon:`delete`,onClick:()=>n(!0),title:`Move the workflow's folder to the trash`,children:`delete workflow`})}),a&&(0,F.jsx)(q,{tone:`bad`,children:a})]})}function Nc({runs:e}){return e.length===0?(0,F.jsx)(K,{children:`no runs of this workflow yet`}):(0,F.jsx)(`div`,{className:`flex flex-col gap-2`,children:e.map(e=>{let t=e.phasesTotal??0,n=t>0?Math.round(e.phasesDone/t*100):e.status===`ok`?100:0;return(0,F.jsxs)(he,{href:`/runs/${e.id}`,className:`run-card grid grid-cols-[12px_200px_1fr_auto] items-center gap-x-4 gap-y-2 rounded-card border border-line bg-surface px-5 py-3.5 text-inherit no-underline transition-colors hover:bg-surface-2 max-[900px]:grid-cols-[12px_1fr]`,children:[(0,F.jsx)(U,{tone:Hs(e.status),title:e.status}),(0,F.jsx)(`span`,{className:`font-mono text-[12.5px] text-fg-2`,children:e.id.replace(/^run-/,``)}),(0,F.jsx)(`span`,{className:`min-w-0 truncate text-fg`,title:e.request,children:e.status===`running`&&e.currentPhase?e.currentPhase:e.request??``}),(0,F.jsxs)(`span`,{className:`flex items-center gap-3.5 font-mono text-xs tabular-nums text-fg-2 max-[900px]:col-span-2`,children:[e.awaitingDecision&&(0,F.jsx)(Ws,{}),(0,F.jsx)(Us,{status:e.status}),(0,F.jsx)(`span`,{className:`h-1 w-[90px] overflow-hidden rounded-full bg-surface-2`,title:`${e.phasesDone}${t?` / ${t}`:``} steps`,children:(0,F.jsx)(`i`,{className:P(`block h-full rounded-full`,e.status===`ok`?`bg-ok`:e.status===`failed`?`bg-bad`:`bg-accent`),style:{width:`${n}%`}})}),(0,F.jsx)(`span`,{children:e.status===`running`?(0,F.jsx)(Ke,{since:e.startedAt}):Be(e.durationMs)}),(0,F.jsx)(`span`,{children:Ve(e.costUsd)}),(0,F.jsx)(`span`,{children:We(e.startedAt)})]})]},e.id)})})}var Pc=`border-line/55`;function Fc({a:e,idx:t}){return(0,F.jsxs)(`div`,{className:P(`agent-card border-r border-b px-[18px] py-3.5`,Pc),children:[(0,F.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,F.jsx)(`span`,{className:`size-2.5 rounded-full`,style:{background:wc(t)}}),(0,F.jsx)(`b`,{className:`text-base font-medium text-fg`,children:e.name??e.id}),(0,F.jsxs)(`code`,{className:`text-2xs text-fg-2`,children:[`[`,e.id,`]`]}),(0,F.jsx)(`span`,{className:`flex-1`}),(0,F.jsxs)(W,{children:[e.model??`default`,e.effort?` · ${e.effort}`:``,e.protocol===`acp`?` · acp`:``]})]}),e.tools.length>0&&(0,F.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-[5px]`,children:e.tools.map(e=>(0,F.jsx)(`span`,{className:`rounded-md bg-surface-2 px-2 py-px font-mono text-2xs text-fg-2`,children:e},e))}),e.persona&&(0,F.jsx)(`p`,{className:`mt-2 mb-0 text-xs leading-[1.55] whitespace-pre-wrap text-fg-2`,children:e.persona})]})}function Ic({s:e,i:t,idx:n}){let r=e.kind===`script`?e.script:e.prompt;return(0,F.jsxs)(`div`,{className:P(`step-node flex gap-3.5 px-[18px] py-3 first:before:top-[18px] last:before:h-[18px] before:left-[31px]`,$s),children:[(0,F.jsx)(Tc,{colour:wc(n),children:t+1}),(0,F.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,F.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-2.5`,children:[(0,F.jsx)(`span`,{className:`text-base font-medium text-fg`,children:e.name}),e.kind===`agent`?(0,F.jsxs)(`span`,{className:`inline-flex h-5 items-center rounded-full border px-2 text-2xs font-semibold`,style:{color:wc(n??0),borderColor:`color-mix(in srgb, ${wc(n??0)} 50%, var(--line))`},children:[`agent · `,e.agent]}):(0,F.jsxs)(W,{children:[`script`,e.sourceRef?` · ${e.sourceRef}`:``]})]}),r&&(0,F.jsxs)(`details`,{className:`mt-1.5`,children:[(0,F.jsx)(`summary`,{className:`cursor-pointer text-xs font-medium text-fg-2 select-none hover:text-accent`,children:e.kind===`agent`?`prompt`:`script`}),(0,F.jsx)(`pre`,{className:`mt-1.5 max-h-[360px] overflow-auto rounded-xl bg-surface-2 px-3 py-2.5 text-[11.5px] leading-[1.55] break-words whitespace-pre-wrap text-fg-2`,children:r})]}),e.gates.length>0&&(0,F.jsx)(`div`,{className:`mt-[5px] flex flex-wrap gap-1.5`,children:e.gates.map(e=>(0,F.jsxs)(`span`,{className:`inline-flex items-center gap-[5px] rounded-lg bg-surface-2 px-2.5 py-0.5 font-mono text-2xs text-fg-2`,children:[`⛨ `,e]},e))})]})]})}function Lc(e,t){let n=e.filter(e=>e.workflow===(t.name??t.slug));return{count:n.length,last:n[0]}}function Rc(e,t){return`/runs/${e.id}?workflow=${encodeURIComponent(t.name??t.slug)}`}function zc({slug:e,tab:t}){let n=N(`workflows.list`,{}),r=N(`runs.list`,{}),[i,a]=(0,v.useState)(``),o=(0,v.useMemo)(()=>n?.workflows??[],[n]),s=r?.runs??[],c=(0,v.useMemo)(()=>{let e=i.trim().toLowerCase();return e?o.filter(t=>[t.name,t.slug,t.description].some(t=>t?.toLowerCase().includes(e))):o},[o,i]),l=(0,v.useMemo)(()=>{if(o.length!==0)return(o.map(e=>({w:e,last:Lc(s,e).last})).filter(e=>!!e.last).sort((e,t)=>(t.last.updatedAt??``).localeCompare(e.last.updatedAt??``))[0]?.w??o[0]).slug},[o,s]),u=!!r;return(0,v.useEffect)(()=>{!e&&l&&u&&B(`/workflows/${encodeURIComponent(l)}`,{replace:!0})},[e,l,u]),(0,F.jsxs)(`div`,{className:`runs-screen workflows-screen`,children:[(0,F.jsxs)(`aside`,{className:`runs-side`,children:[(0,F.jsx)(wt,{title:`workflows`,count:n?o.length:void 0,action:(0,F.jsxs)(V,{size:`sm`,variant:`quiet`,icon:`history`,href:`/runs`,title:`every run of every workflow, newest first`,children:[`runs `,(0,F.jsx)(`span`,{className:`tabular-nums`,children:s.length})]})}),o.length>0&&(0,F.jsx)(Tt,{icon:`search`,value:i,placeholder:`search workflows`,"aria-label":`search workflows`,onChange:e=>a(e.target.value)}),(0,F.jsxs)(Et,{children:[c.map(t=>{let n=Lc(s,t);return(0,F.jsx)(Y,{className:`wf-row`,href:`/workflows/${encodeURIComponent(t.slug)}`,active:t.slug===e,leading:(0,F.jsx)(U,{tone:Hs(n.last?.status),title:n.last?.status??`no runs yet`}),title:t.name??t.slug,titleExtra:t.error&&(0,F.jsx)(W,{tone:`bad`,children:`broken`}),meta:n.last&&Ge(n.last.updatedAt),sub:(0,F.jsx)(`span`,{title:t.error??t.description??``,children:t.error??t.description??`${t.agents} agents · ${t.steps} steps`}),subTone:t.error?`bad`:`plain`,actionsAlways:!0,actions:n.last?(0,F.jsxs)(`button`,{type:`button`,className:`wf-runs inline-flex cursor-pointer items-center gap-1 rounded-control border-0 bg-transparent px-1.5 py-0.5 text-2xs tabular-nums text-fg-2 transition-colors hover:bg-surface-2 hover:text-fg`,title:`show the runs of this workflow`,onClick:()=>B(Rc(n.last,t)),children:[n.count,` `,n.count===1?`run`:`runs`,` · `,(0,F.jsx)(Us,{status:n.last.status})]}):(0,F.jsx)(`span`,{className:`wf-runs px-1.5 text-2xs text-fg-2 opacity-80`,children:`no runs yet`})},t.slug)}),n&&o.length>0&&c.length===0&&(0,F.jsxs)(Dt,{className:`wf-nomatch`,children:[`no workflow matches “`,i,`”`]}),n&&o.length===0&&(0,F.jsx)(Dt,{children:`no workflows yet`})]})]}),(0,F.jsx)(`div`,{className:`runs-main`,children:e?(0,F.jsx)(Ac,{slug:e,tab:t},e):n&&o.length===0?(0,F.jsxs)(K,{icon:`account_tree`,children:[`No workflows found — expected `,(0,F.jsx)(`code`,{children:`src/workflows/`}),` or `,(0,F.jsx)(`code`,{children:`workflows/`}),` next to the output folder.`]}):(0,F.jsx)(K,{children:`loading…`})})]})}var Bc=e=>e===`ok`?`ok`:e===`running`?`running`:e===`aborted`?`aborted`:`failed`,Vc=e=>e===`ok`?`done`:e===`running`?`working`:e===`aborted`?`stopped`:`failed`;function Hc(e){return e.scope.kind===`channel`?`/channels/${e.scope.slug}`:e.scope.kind===`project`?`/projects/${e.scope.slug}/chat/${e.id}`:e.scope.kind===`agent`?`/agents/${e.scope.slug}/chat/${e.id}`:`/agents/chats/${e.id}`}function Uc(e,t,n){switch(e.scope.kind){case`agent`:{let n=e.scope.slug,r=t.find(e=>e.slug===n);return r?`${r.emoji||`🤖`} ${r.name}`:n}case`project`:return`📁 ${n(e.scope.slug)}`;case`channel`:return e.project?`📁 ${n(e.project)} · #${e.scope.slug}`:`#${e.scope.slug}`;case`run`:return`⚙️ run ${e.scope.runId}`;case`knowledge`:return e.scope.bundle?`📚 ${e.scope.bundle}`:`📚 knowledge`;default:return`🎩 Ralv`}}function Wc(e){return e.length>64?`${e.slice(0,46)}…${e.slice(-14)}`:e}function Gc(){let e=N(`runs.list`,{}),t=N(`chats.list`,{}),n=N(`knowledge.list`,{}),r=N(`agents.list`,{}),i=N(`workflows.list`,{}),a=N(`skills.list`,{}),[o,s]=(0,v.useState)(`all`),c=be(),l=N(`projects.list`,{},{interval:3e4}),u=e=>l?.projects.find(t=>t.slug===e)?.title??e,d=e?.runs??[],f=t?.chats??[],p=n?.bundles??[],m=(a?.skills??[]).filter(e=>e.source===`workspace`),h=[[i?.workflows.length,`workflows`,`/workflows`],[e?d.length:void 0,`runs`,`/runs`],[n?p.length:void 0,`bundles`,`/knowledge`],[a?m.length:void 0,`skills`,`/skills`],[t?f.length:void 0,`chats`,`/agents/chats`]],g=d.filter(e=>e.status===`failed`&&Date.now()-Date.parse(e.updatedAt)<864e5);return(0,F.jsxs)(`div`,{className:`w-full px-7 pt-6 pb-10 max-[800px]:px-3 max-[800px]:pt-3`,children:[(0,F.jsx)($c,{runs:d,chats:f,bundles:p,agents:r?.agents??[],workflows:i?.workflows??[],projectTitle:u,loaded:!!e&&!!t}),c&&(0,F.jsx)(`div`,{className:`mx-0.5 mt-3.5 mb-3 flex flex-wrap justify-end gap-x-[18px] gap-y-1 text-xs text-fg-2 max-[800px]:justify-start max-[800px]:gap-x-3.5`,children:h.map(([e,t,n])=>(0,F.jsxs)(he,{href:n,className:`group/mini text-inherit no-underline hover:text-accent hover:underline`,children:[(0,F.jsx)(`b`,{className:`font-semibold tabular-nums text-fg group-hover/mini:text-accent`,children:e??`…`}),` `,t]},t))}),c&&g.length>0&&o!==`failed`&&(0,F.jsxs)(`button`,{type:`button`,className:`mb-3.5 flex w-full cursor-pointer items-center gap-2 rounded-xl border border-bad/40 bg-bad-soft px-3.5 py-[9px] text-left text-[12.5px] text-on-bad-soft hover:brightness-104`,onClick:()=>s(`failed`),children:[`⚠ `,g.length,` run`,g.length===1?``:`s`,` failed in the last 24 h — review`]}),c&&(0,F.jsx)(Jc,{projectTitle:u,runs:d,chats:f,bundles:p,agents:r?.agents??[],workflows:i?.workflows??[],filter:o,setFilter:s})]})}function Kc(e){if(e.lamp===`running`)return`now`;let t=new Date(e.at),n=new Date;if(t.toDateString()===n.toDateString())return`today`;let r=new Date(n);return r.setDate(r.getDate()-1),t.toDateString()===r.toDateString()?`yesterday`:`earlier`}var qc=[[`all`,`all`],[`run`,`runs`],[`session`,`chats`],[`knowledge`,`knowledge`]];function Jc({projectTitle:e,runs:t,chats:n,bundles:r,agents:i,workflows:a,filter:o,setFilter:s}){let c=be(),l=(0,v.useMemo)(()=>{let s=[],l=e=>e?a.find(t=>t.slug===e)?.name??e:void 0;for(let e of t)s.push({at:e.updatedAt,kind:`run`,emoji:`⚙️`,title:l(e.workflow)??e.id,sub:e.request??``,href:`/runs/${e.id}`,lamp:Bc(e.status),status:Vc(e.status)});for(let t of n){let n=t.scope.kind===`agent`?i.find(e=>t.scope.kind===`agent`&&e.slug===t.scope.slug):void 0;s.push({at:t.updatedAt,kind:`session`,emoji:n?n.emoji||`🤖`:`💬`,title:n?n.name:t.title||`new chat`,sub:n?`${t.title||`new chat`}${c?` · ${t.agent}`:``}`:c?`${t.agent} · ${Uc(t,i,e)}`:Uc(t,i,e),href:Hc(t),lamp:t.awaitingApproval?`blocked`:t.busy?`running`:`ok`,status:t.awaitingApproval?`needs approval`:t.busy?`working`:void 0})}for(let e of r)e.updatedAt&&s.push({at:e.updatedAt,kind:`knowledge`,emoji:`📚`,title:e.name,sub:`${e.concepts} concepts`,href:`/knowledge/${encodeURIComponent(e.name)}`,lamp:`ok`});return(o===`all`?s:o===`failed`?s.filter(e=>e.kind===`run`&&e.lamp===`failed`):s.filter(e=>e.kind===o)).sort((e,t)=>{let n=Number(t.lamp===`running`)-Number(e.lamp===`running`);return n===0?t.at.localeCompare(e.at):n}).slice(0,15)},[t,n,r,i,c,o]),u=``,d=(e,t)=>P(`inline-flex cursor-pointer items-center gap-0.5 rounded-lg border px-2.5 py-0.5 text-2xs transition-colors`,e?P(`border-transparent`,t?`bg-bad-soft text-on-bad-soft`:`bg-accent-soft text-on-accent-soft`):`border-line bg-transparent text-fg-2 hover:text-fg`);return(0,F.jsx)(J,{className:`animate-rise`,title:`all activity`,actions:(0,F.jsxs)(`span`,{className:`flex flex-wrap gap-1.5`,children:[qc.map(([e,t])=>(0,F.jsx)(`button`,{type:`button`,className:d(o===e),"aria-pressed":o===e,onClick:()=>s(e),children:t},e)),o===`failed`&&(0,F.jsxs)(`button`,{type:`button`,className:d(!0,!0),onClick:()=>s(`all`),children:[`failed `,(0,F.jsx)(I,{name:`close`,className:`ms-sm`})]})]}),children:l.length===0?(0,F.jsx)(`div`,{className:`px-[18px] py-4 text-sm text-fg-2`,children:o===`all`?`nothing yet — run a workflow or start a chat`:`nothing here for this filter`}):(0,F.jsx)(`div`,{className:`flex flex-col p-1.5`,children:l.map(e=>{let t=Kc(e),n=t===u?null:t;return u=t,(0,F.jsxs)(`div`,{children:[n&&(0,F.jsx)(et,{className:`block px-2.5 pt-3 pb-1`,children:n}),(0,F.jsx)(Y,{href:e.href,leading:(0,F.jsxs)(`span`,{className:`relative text-[18px] leading-none`,children:[(0,F.jsx)(`span`,{"aria-hidden":!0,children:e.emoji}),e.lamp===`running`&&(0,F.jsx)(`span`,{className:`absolute -right-1 -bottom-1 grid rounded-full bg-surface p-px`,children:(0,F.jsx)(U,{tone:`working`})})]}),title:Wc(e.title),titleExtra:(0,F.jsx)(`span`,{className:`max-[800px]:hidden`,children:(0,F.jsx)(W,{tone:Yc[e.kind],children:e.kind===`session`?`chat`:e.kind})}),sub:e.sub&&Wc(e.sub),meta:(0,F.jsxs)(`span`,{className:`flex items-center gap-2`,children:[e.status&&(0,F.jsx)(W,{tone:Xc[e.lamp]??`neutral`,children:e.status}),(0,F.jsx)(`span`,{title:new Date(e.at).toLocaleString(),children:Ge(e.at)}),(0,F.jsx)(I,{name:`chevron_right`,className:`ms-sm max-[800px]:hidden`})]})})]},`${e.kind}:${e.href}:${e.at}`)})})})}var Yc={run:`accent`,session:`ask`,knowledge:`ok`},Xc={ok:`ok`,failed:`bad`,blocked:`bad`,running:`accent`,aborted:`neutral`};function Zc(e){if(!e)return``;let t=Math.max(0,Math.round((Date.now()-Date.parse(e))/6e4));return t<1?`just started`:t<60?`${t} min`:`${Math.floor(t/60)} h ${t%60} min`}var Qc=e=>new Date(e).toDateString()===new Date().toDateString();function $c({runs:e,chats:t,bundles:n,agents:r,workflows:i,projectTitle:a,loaded:o}){let s=Ft()??[],c=L(),l=N(`agents.status`,{},{interval:5e3}),u=e=>e?i.find(t=>t.slug===e)?.name??e:`workflow`,d=new Map;for(let e of Object.values(l??{}))for(let t of e.working)t.since&&d.set(t.chatId,t.since);let f=[...t.filter(e=>e.busy&&!e.awaitingApproval).map(e=>({key:`c:${e.id}`,owner:Uc(e,r,a),title:Wc(e.title||`new chat`),meta:`working${d.get(e.id)?` · ${Zc(d.get(e.id))}`:``}`,href:Hc(e),tone:`working`})),...e.filter(e=>e.status===`running`).map(e=>({key:`r:${e.id}`,owner:`⚙️ ${u(e.workflow)}`,title:Wc(e.request??``),meta:`running`,href:`/runs/${e.id}`,tone:`working`}))],p=[...t.filter(e=>!e.busy&&!e.awaitingApproval&&Qc(e.updatedAt)&&e.title).map(e=>({key:`c:${e.id}`,at:e.updatedAt,owner:Uc(e,r,a),title:Wc(e.title),meta:Ge(e.updatedAt),href:Hc(e)})),...e.filter(e=>e.status!==`running`&&Qc(e.updatedAt)).map(e=>({key:`r:${e.id}`,at:e.updatedAt,owner:`⚙️ ${u(e.workflow)}`,title:Wc(e.request??``),meta:`${e.status===`ok`?`done`:e.status===`aborted`?`stopped`:`failed`} · ${Ge(e.updatedAt)}`,href:`/runs/${e.id}`})),...n.filter(e=>e.updatedAt&&Qc(e.updatedAt)).map(e=>({key:`k:${e.name}`,at:e.updatedAt,owner:`📚 ${e.name}`,title:`knowledge updated`,meta:Ge(e.updatedAt),href:`/knowledge/${encodeURIComponent(e.name)}`}))].sort((e,t)=>t.at.localeCompare(e.at)).slice(0,12),m=Bt(s,c),h=o&&s.length===0&&f.length===0;return(0,F.jsxs)(`div`,{className:`today flex flex-col gap-3.5`,children:[(0,F.jsxs)(J,{className:`today-section`,title:`needs you`,count:s.length,actions:m&&(0,F.jsxs)(V,{variant:`primary`,size:`sm`,onClick:()=>Vt(m),className:`bg-bad text-on-bad hover:bg-bad`,children:[`start `,(0,F.jsx)(I,{name:`arrow_forward`,className:`ms-sm`})]}),children:[s.length===0?(0,F.jsx)(`p`,{className:`m-0 px-[18px] py-4 text-sm text-fg-2`,children:h?`Nothing waiting, nothing running.`:`Nothing is waiting for you.`}):(0,F.jsx)(`div`,{className:`p-1.5`,children:s.map(e=>(0,F.jsx)(Y,{className:`today-row waiting`,onClick:()=>Vt(e),over:Lt(e.owner),title:e.title,meta:(0,F.jsxs)(`span`,{className:`font-semibold text-bad`,children:[e.kind===`approval`?`needs approval`:e.kind===`question`?`asks you`:`failed`,` · `,Ge(e.since)]})},e.id))}),h&&(0,F.jsx)(`div`,{className:`px-[18px] pb-4`,children:(0,F.jsx)(V,{variant:`primary`,icon:`chat`,href:`/agents/chats`,children:`chat with Ralv`})})]}),f.length>0&&(0,F.jsx)(J,{className:`today-section`,title:`in progress`,children:(0,F.jsx)(`div`,{className:`p-1.5`,children:f.map(e=>(0,F.jsx)(el,{r:e},e.key))})}),(0,F.jsx)(J,{className:`today-section`,title:`done today`,children:p.length===0?(0,F.jsx)(`p`,{className:`m-0 px-[18px] py-4 text-sm text-fg-2`,children:`Nothing finished yet today.`}):(0,F.jsx)(`div`,{className:`p-1.5`,children:p.map(e=>(0,F.jsx)(el,{r:e},e.key))})})]})}function el({r:e}){return(0,F.jsx)(Y,{className:`today-row`,href:e.href,over:e.owner,title:e.title,meta:(0,F.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[e.tone===`working`&&(0,F.jsx)(U,{tone:`working`}),e.meta]})})}var tl=`modulepreload`,nl=function(e){return`/`+e},rl={},il=function(e){return e.pathname.endsWith(`.css`)},al=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e,i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?new URL(import.meta.resolve(e)):new URL(e,import.meta.url)}r=o(t.map(t=>{t=nl(t,n);let r=s(t);if(r.href in rl)return;rl[r.href]=!0;let i=il(r);if(e===void 0){e={all:new Set,styles:new Set};let t=document.getElementsByTagName(`link`);for(let n=t.length-1;n>=0;n--){let r=t[n];e.all.add(r.href),r.rel===`stylesheet`&&e.styles.add(r.href)}}if((i?e.styles:e.all).has(r.href))return;let o=document.createElement(`link`);if(o.rel=i?`stylesheet`:tl,i||(o.as=`script`),o.crossOrigin=``,o.href=r.href,a&&o.setAttribute(`nonce`,a),document.head.appendChild(o),i)return new Promise((e,t)=>{o.addEventListener(`load`,e),o.addEventListener(`error`,()=>t(Error(`Unable to preload CSS for ${r}`)))})}).filter(e=>e!==void 0))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},ol=(0,v.lazy)(()=>al(()=>import(`./editor-ByOSpxTX.js`).then(e=>({default:e.DocEditor})),__vite__mapDeps([0,1,2,3,4,5,6]))),sl=()=>al(()=>import(`./editor-ByOSpxTX.js`),__vite__mapDeps([0,1,2,3,4,5,6]));function cl({bundle:e,conceptId:t}){let n=N(`knowledge.list`,{}),[r,i]=(0,v.useState)([]);(0,v.useEffect)(()=>{n&&i(e=>e.filter(e=>n.bundles.some(t=>t.name===e)))},[n]);let a=(n?.bundles??[]).filter(e=>!r.includes(e.name)),o=e===`new`,s=a.reduce((e,t)=>!e||(t.updatedAt??``)>(e.updatedAt??``)?t:e,void 0);return(0,v.useEffect)(()=>{!e&&s&&B(`/knowledge/${encodeURIComponent(s.name)}`,{replace:!0})},[e,s?.name]),(0,F.jsxs)(`div`,{className:`runs-screen`,children:[(0,F.jsxs)(`aside`,{className:`runs-side`,children:[(0,F.jsx)(wt,{title:`bundles`,action:(0,F.jsx)(V,{size:`sm`,variant:`quiet`,icon:`add`,href:`/knowledge/new`,children:`new`})}),(0,F.jsxs)(Et,{children:[a.map(t=>(0,F.jsx)(Y,{href:`/knowledge/${encodeURIComponent(t.name)}`,active:t.name===e,size:`sm`,leading:(0,F.jsx)(U,{tone:`ok`}),title:t.name,meta:t.concepts,sub:`${t.okfVersion?`okf ${t.okfVersion}`:`okf`}${t.updatedAt?` · ${t.updatedAt.slice(0,10)}`:``}`},t.name)),n&&a.length===0&&(0,F.jsx)(Dt,{children:`no bundles yet`})]})]}),(0,F.jsx)(`div`,{className:`runs-main`,children:e&&!o?(0,F.jsx)(hl,{name:e,conceptId:t,onRemoved:()=>{i(t=>[...t,e]),B(`/knowledge`,{replace:!0})}},e):o||n&&!s?(0,F.jsx)(ll,{}):(0,F.jsx)(K,{children:`loading…`})})]})}function ll(){let[e,t]=(0,v.useState)(``),[n,r]=(0,v.useState)(``),[i,a]=(0,v.useState)(!1);async function o(){let t=e.trim();if(!t)return;a(!0),r(``);let n=await A.request(`knowledge.create`,{body:{name:t}});a(!1),n.ok?B(`/knowledge/${encodeURIComponent(t)}`):r(M(n))}return(0,F.jsxs)(`div`,{className:`empty-action flex flex-col items-center gap-3 px-4 py-16`,children:[(0,F.jsxs)(`div`,{className:`flex w-full max-w-[520px] gap-2.5`,children:[(0,F.jsx)(X,{className:`flex-1 font-mono text-sm`,value:e,placeholder:`bundle name, e.g. customer-support`,"aria-label":`bundle name`,onChange:e=>t(e.target.value),onKeyDown:e=>e.key===`Enter`&&void o(),autoFocus:!0}),(0,F.jsx)(V,{variant:`primary`,icon:`add`,busy:i,disabled:!e.trim(),onClick:o,children:i?`creating…`:`new bundle`})]}),n&&(0,F.jsx)(q,{tone:`bad`,children:n})]})}function ul({tier:e}){return(0,F.jsx)(W,{tone:e===`human-reviewed`?`ok`:e===`machine-confirmed`?`accent`:`neutral`,children:e})}var dl=e=>e===`deprecated`||e===`stale`?`bad`:e===`draft`?`accent`:`neutral`,fl=()=>(0,v.useContext)(me)!==null,pl=`m-0 max-h-[560px] overflow-auto px-[18px] py-3.5 font-mono text-xs leading-[1.55] break-words whitespace-pre-wrap text-fg-2`,ml=`@activity`;function hl({name:e,conceptId:t,onRemoved:n}){let r=N(`knowledge.get`,{bundle:e}),i=fl(),[a,o]=(0,v.useState)(!1),[s,c]=(0,v.useState)(``);async function l(){let t=await A.request(`knowledge.delete`,{bundle:e}).catch(()=>null);if(!t?.ok){c(t?.error??`delete failed`),o(!1);return}n?n():B(`/knowledge`,{replace:!0})}if(!r)return(0,F.jsx)(K,{children:`loading…`});if(`error`in r)return(0,F.jsx)(K,{icon:`menu_book`,children:`bundle not found`});let u=t===ml?`activity`:`pages`,d=r.concepts,f=u===`pages`?t&&d.some(e=>e.id===t)?t:d[0]?.id:void 0,p=`/knowledge/${encodeURIComponent(e)}`;return(0,F.jsxs)(`div`,{className:P(`agent-view @container flex flex-col`,i?`gap-2.5`:`gap-4`),children:[(0,F.jsxs)(`div`,{className:P(`flex flex-wrap items-center gap-x-4 gap-y-2`,i?`mb-0.5`:`mx-0.5 mt-1 mb-2`),children:[(0,F.jsx)(nt,{size:i?`md`:`lg`,children:e}),(0,F.jsxs)(`span`,{className:P(`text-fg-2`,i?`text-[12.5px]`:`text-base`),children:[d.length,` pages`]}),(0,F.jsx)(ft,{bare:!0,className:`self-end`,label:`bundle views`,value:u,items:[{id:`pages`,href:p,label:`pages`},{id:`activity`,href:`${p}/${ml}`,label:`activity`}]}),(0,F.jsx)(`span`,{className:`flex-1`}),!i&&(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(V,{size:`sm`,variant:`quiet`,icon:`picture_as_pdf`,onClick:()=>void os(e),children:`export PDF`}),a?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(V,{size:`sm`,variant:`danger`,icon:`delete`,onClick:()=>void l(),children:`move to trash`}),(0,F.jsx)(V,{size:`sm`,variant:`quiet`,onClick:()=>o(!1),children:`cancel`})]}):(0,F.jsx)(V,{size:`sm`,variant:`quiet`,icon:`delete`,onClick:()=>o(!0),title:`Move the bundle to the trash`,children:`delete`}),(0,F.jsx)(V,{variant:`primary`,onClick:()=>void Po(`claude`,{kind:`knowledge`,bundle:e}),children:`curate in chat`})]})]}),s&&(0,F.jsx)(q,{tone:`bad`,children:s}),u===`activity`?r.log?(0,F.jsx)(vl,{name:e,log:r.log}):(0,F.jsx)(J,{children:(0,F.jsx)(`p`,{className:`m-0 px-[18px] py-3 text-sm text-fg-2`,children:`no activity yet`})}):d.length===0?(0,F.jsx)(J,{children:(0,F.jsxs)(`p`,{className:`m-0 px-[18px] py-3 text-sm text-fg-2`,children:[`No pages yet — start a chat to author some, or write one with`,` `,(0,F.jsxs)(`code`,{children:[`kraftwerk knowledge put `,e,`/<path>`]}),`.`]})}):(0,F.jsxs)(`div`,{className:P(`grid items-start`,i?`grid-cols-[170px_minmax(0,1fr)] gap-3.5 @max-[560px]:grid-cols-1`:`grid-cols-[260px_minmax(0,1fr)] gap-6 max-[1100px]:grid-cols-1`),children:[(0,F.jsx)(`aside`,{className:P(`flex flex-col gap-0.5 overflow-y-auto border-r border-line`,i?`sticky top-0 max-h-[calc(100vh-var(--topbar-h)-160px)] pr-2 pb-1.5 @max-[560px]:static @max-[560px]:max-h-[200px] @max-[560px]:border-r-0 @max-[560px]:pr-0`:`sticky top-[calc(var(--topbar-h)+18px)] max-h-[calc(100vh-var(--topbar-h)-36px)] py-1.5 pr-3 max-[1100px]:static max-[1100px]:max-h-none max-[1100px]:border-r-0 max-[1100px]:pr-0`),children:(0,F.jsx)(bl,{concepts:d,base:p,selected:f})}),(0,F.jsx)(`div`,{className:`min-w-0`,children:f&&(0,F.jsx)(Sl,{bundle:e,conceptId:f},f)})]})]})}function gl(e){let t=[];for(let n of e.split(`
216
- `)){let e=n.match(/^##\s+(\d{4}-\d{2}-\d{2})/);if(e){t.push({date:e[1],entries:[]});continue}let r=n.match(/^[*-]\s+\*\*([^*]+)\*\*:\s*(.*)$/);r&&t.length>0&&t[t.length-1].entries.push({kind:r[1].toLowerCase(),text:r[2]})}return t.filter(e=>e.entries.length>0)}function _l(e,t){let n=[],r=/\[([^\]]+)\]\(\/?([^)]+?)\.md\)/g,i=0,a;for(;a=r.exec(t);)a.index>i&&n.push(t.slice(i,a.index)),n.push((0,F.jsx)(he,{href:`/knowledge/${encodeURIComponent(e)}/${a[2].replace(/^\//,``)}`,children:a[1]},a.index)),i=a.index+a[0].length;return i<t.length&&n.push(t.slice(i)),n}function vl({name:e,log:t}){let n=gl(t),[r,i]=(0,v.useState)(!1);return(0,F.jsx)(J,{title:`activity`,actions:(0,F.jsx)(V,{size:`sm`,variant:`quiet`,onClick:()=>i(!r),children:r?`timeline`:`raw log`}),children:r||n.length===0?(0,F.jsx)(`pre`,{className:pl,children:t}):(0,F.jsx)(`div`,{className:`pt-0.5 pb-2.5`,children:n.map((t,n)=>(0,F.jsxs)(v.Fragment,{children:[(0,F.jsx)(`div`,{className:P(`px-[18px] pt-3.5 pb-1 font-mono text-2xs tracking-[0.05em] text-fg-2 tabular-nums`,n>0&&`mt-1 border-t border-line`),children:t.date}),t.entries.map((t,n)=>(0,F.jsxs)(`div`,{className:`flex items-baseline gap-2.5 px-[18px] py-1`,children:[(0,F.jsx)(W,{tone:t.kind===`verification`?`ok`:t.kind===`creation`||t.kind===`initialization`?`accent`:`neutral`,children:t.kind}),(0,F.jsx)(`span`,{className:`min-w-0 text-[12.5px] leading-[1.55] break-words text-fg-2 [&_a]:text-accent`,children:_l(e,t.text)})]},n))]},t.date))})})}function yl(e){let t={name:``,path:``,folders:[],pages:[],total:0};for(let n of e){let e=n.id.split(`/`),r=t;r.total++;for(let t of e.slice(0,-1)){let e=r.folders.find(e=>e.name===t);e||(e={name:t,path:r.path?`${r.path}/${t}`:t,folders:[],pages:[],total:0},r.folders.push(e)),r=e,r.total++}r.pages.push(n)}let n=e=>{e.folders.sort((e,t)=>e.name.localeCompare(t.name)),e.pages.sort((e,t)=>e.title.localeCompare(t.title)),e.folders.forEach(n)};return n(t),t}function bl({concepts:e,base:t,selected:n}){let r=(0,v.useMemo)(()=>yl(e),[e]),[i,a]=(0,v.useState)(()=>new Set);(0,v.useEffect)(()=>{n&&n.includes(`/`)&&a(e=>{let t=new Set(e),r=n.split(`/`).slice(0,-1);for(let e=1;e<=r.length;e++)t.delete(r.slice(0,e).join(`/`));return t.size===e.size?e:t})},[n]);let o=e=>a(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),s=fl();return(0,F.jsx)(xl,{folder:r,base:t,selected:n,closed:i,toggle:o,embedded:s})}function xl({folder:e,base:t,selected:n,closed:r,toggle:i,embedded:a}){return(0,F.jsxs)(F.Fragment,{children:[e.pages.map(e=>{let r=e.id===n;return(0,F.jsxs)(he,{href:`${t}/${e.id}`,"aria-current":r?`page`:void 0,className:P(`wiki-page flex items-center gap-2 rounded-control px-2.5 py-1.5 leading-[1.35] no-underline transition-colors`,a?`text-[12.5px]`:`text-sm`,r?`active bg-accent-soft font-medium text-on-accent-soft`:`text-fg hover:bg-surface-2`),title:`${e.id}.md`,children:[(0,F.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.title}),(e.stale||e.error)&&(0,F.jsx)(`span`,{className:`size-1.5 flex-none rounded-full bg-bad`,title:e.error??`stale`})]},e.id)}),e.folders.map(e=>{let o=!r.has(e.path),s=!!n&&n.startsWith(`${e.path}/`)&&!o;return(0,F.jsxs)(v.Fragment,{children:[(0,F.jsxs)(`button`,{type:`button`,className:P(`wiki-folder mt-2.5 mb-0.5 flex w-full cursor-pointer items-center gap-1 rounded-control border-0 bg-transparent py-1 pr-2 pl-0.5 text-left`,`font-[inherit] text-2xs leading-[1.3] font-semibold tracking-[0.06em] uppercase transition-colors`,o&&`open`,s?`holds text-accent`:`text-fg-2 hover:text-fg`),onClick:()=>i(e.path),"aria-expanded":o,title:`${e.path}/`,children:[(0,F.jsx)(I,{name:`chevron_right`,className:P(`ms-sm flex-none text-[16px] transition-transform`,o&&`rotate-90`,!s&&`text-fg-2`)}),(0,F.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.name}),(0,F.jsx)(`span`,{className:`text-[10.5px] font-medium tracking-normal text-fg-2 tabular-nums opacity-70`,children:e.total})]}),o&&(0,F.jsx)(`div`,{className:`wiki-branch ml-[9px] flex flex-col gap-0.5 border-l border-line pl-1`,children:(0,F.jsx)(xl,{folder:e,base:t,selected:n,closed:r,toggle:i,embedded:a})})]},e.path)})]})}function Sl({bundle:e,conceptId:t}){let[n,r]=(0,v.useState)(null),[i,a]=(0,v.useState)(!1),[o,s]=(0,v.useState)(!1),c=fl(),[l,u]=(0,v.useState)(`document`),[d,f]=(0,v.useState)(``),[p,m]=(0,v.useState)(!1),[h,g]=(0,v.useState)(``),[_,y]=(0,v.useState)(null),[b,x]=(0,v.useState)(`saved`),[S,C]=(0,v.useState)(``),w=(0,v.useRef)(``),T=(0,v.useRef)(null),E=(0,v.useRef)(!1),D=(0,v.useRef)(null),O=(0,v.useRef)(null),k=(0,v.useRef)(null),j=()=>{A.call(`knowledge.concept`,{bundle:e,query:{id:t}}).then(r,()=>a(!0))};(0,v.useEffect)(()=>{if(l===`markdown`)return;let n=!0,i,o=async()=>{try{let i=await A.request(`knowledge.concept`,{bundle:e,query:{id:t}});if(i.ok){let e=i.data;n&&(a(!1),r(t=>JSON.stringify(t)===JSON.stringify(e)?t:e))}else i.status===404&&n&&a(!0)}catch{}n&&(i=setTimeout(o,6e3))};return o(),()=>{n=!1,clearTimeout(i)}},[e,t,l]),(0,v.useEffect)(()=>{if(!n||n.raw===T.current||D.current!==null||k.current)return;let e=!0;return sl().then(({splitFrontmatter:t,unwrapParagraphs:r})=>{if(!e)return;let{head:i,body:a}=t(n.raw);w.current=i,T.current=n.raw,E.current=!1,y(e=>({key:(e?.key??0)+1,body:r(a)}))}),()=>{e=!1}},[n]);async function ee(){k.current&&await k.current;let n=D.current;if(n===null)return;D.current=null,x(`saving`);let i=(async()=>{try{let i=w.current,a=i?`${i}${i.endsWith(`
215
+ `).length+2)),value:l,placeholder:`You are the ... for this project. Your job is ...`,onChange:e=>u(e.target.value),spellCheck:!1}),O({system:l})]})]}),(0,F.jsx)(st,{icon:`account_tree`,title:`workflows`,action:s!==`workflows`&&k(()=>(f(t.workflows),c(`workflows`))),children:s===`workflows`?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(ms,{children:[(x?.workflows??[]).map(e=>(0,F.jsx)(bt,{checked:d.includes(e.slug),onChange:t=>E(e.slug,t),hint:e.description,mono:!0,children:e.slug},e.slug)),(x?.workflows??[]).length===0&&(0,F.jsx)(G,{className:`py-1.5 px-0`,children:`no workflows in this project`})]}),O({workflows:d})]}):t.workflows.length===0?(0,F.jsx)(`span`,{className:fs,children:`none connected — the agent can run any workflow you connect`}):(0,F.jsx)(ps,{children:t.workflows.map(e=>(0,F.jsx)(W,{href:`/workflows/${encodeURIComponent(e)}`,children:e},e))})}),(0,F.jsx)(st,{icon:`menu_book`,title:`knowledge`,action:s!==`knowledge`&&k(()=>(f(t.knowledge),c(`knowledge`))),children:s===`knowledge`?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(ms,{children:[(S?.bundles??[]).map(e=>(0,F.jsx)(bt,{checked:d.includes(e.name),onChange:t=>E(e.name,t),hint:`${e.concepts} concepts`,mono:!0,children:e.name},e.name)),(S?.bundles??[]).length===0&&(0,F.jsx)(G,{className:`py-1.5 px-0`,children:`no knowledge bundles in this project`})]}),O({knowledge:d})]}):t.knowledge.length===0?(0,F.jsx)(`span`,{className:fs,children:`none connected — connected bundles are read and kept current by the agent`}):(0,F.jsx)(ps,{children:t.knowledge.map(e=>(0,F.jsx)(W,{href:`/knowledge/${encodeURIComponent(e)}`,children:e},e))})}),(b.vibeables||(t.vibeables??[]).length>0)&&(0,F.jsx)(st,{icon:`web`,title:`apps`,"data-link-kind":`vibeables`,action:s!==`vibeables`&&k(()=>(f(t.vibeables??[]),c(`vibeables`))),children:s===`vibeables`?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(ms,{children:[(C?.vibeables??[]).map(e=>(0,F.jsx)(bt,{checked:d.includes(e.slug),onChange:t=>E(e.slug,t),hint:e.dev?`dev`:`static`,mono:!0,children:e.slug},e.slug)),d.filter(e=>!(C?.vibeables??[]).some(t=>t.slug===e)).map(e=>(0,F.jsx)(bt,{checked:!0,onChange:t=>E(e,t),hint:`not found in this workspace`,mono:!0,children:e},e)),!b.vibeables&&(0,F.jsx)(G,{className:`py-1.5 px-0`,children:`vibeables are off in this workspace's settings`}),b.vibeables&&(C?.vibeables??[]).length===0&&(0,F.jsx)(G,{className:`py-1.5 px-0`,children:`no apps in this workspace yet — create one on the apps page`})]}),O({vibeables:d})]}):(t.vibeables??[]).length===0?(0,F.jsx)(`span`,{className:`text-xs leading-[1.5] text-fg-2 [&_a]:text-inherit [&_code]:text-2xs`,children:`none linked — linked apps are the agent's to build and maintain; it knows them from the first message`}):(0,F.jsx)(ps,{children:(t.vibeables??[]).map(e=>{let t=!b.vibeables||!C||C.vibeables.some(t=>t.slug===e);return(0,F.jsxs)(W,{href:`/vibeables/${encodeURIComponent(e)}`,tone:t?`neutral`:`bad`,title:t?void 0:`configured but not found in this workspace`,children:[e,!t&&` · not found`]},e)})})}),(0,F.jsx)(st,{icon:`extension`,title:`shared skills`,action:s!==`skills`&&k(()=>{m(t.skills===void 0),f(t.skills??[]),c(`skills`)}),children:s===`skills`?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(ms,{children:[(0,F.jsx)(bt,{checked:p,onChange:m,hint:`every discovered skill, including future ones`,mono:!0,children:`all skills`}),!p&&(w?.skills??[]).map(e=>(0,F.jsx)(bt,{checked:d.includes(e.name),onChange:t=>E(e.name,t),hint:e.description,mono:!0,children:`/${e.name}`},e.name)),!p&&(w?.skills??[]).length===0&&(0,F.jsx)(G,{className:`py-1.5 px-0`,children:`no skills found (.claude/skills, project or user)`})]}),O({skills:p?void 0:d})]}):t.skills===void 0?(0,F.jsx)(`span`,{className:fs,children:`all discovered skills (default) — invoke with /name in a session`}):t.skills.length===0?(0,F.jsx)(`span`,{className:fs,children:`none — this agent runs without skills`}):(0,F.jsx)(ps,{children:t.skills.map(e=>(0,F.jsxs)(W,{children:[`/`,e]},e))})})]}),_&&(0,F.jsx)(`div`,{className:`px-[18px] pb-3`,children:(0,F.jsx)(q,{tone:`bad`,children:_})})]}),(0,F.jsx)(ks,{slug:e}),(0,F.jsx)(As,{slug:e})]})}var Ms=[`🤖`,`🧑‍💻`,`🎧`,`🛠️`,`📊`,`✍️`,`🔍`,`🧹`,`📦`,`🚀`];function Ns({slug:e}){let[t,n]=(0,v.useState)(e?null:f()),[r,i]=(0,v.useState)(``),[a,o]=(0,v.useState)(!1),s=N(`workflows.list`,{})?.workflows??[],c=N(`knowledge.list`,{})?.bundles??[],l=we(),u=N(`vibeables.list`,l.vibeables?{}:null)?.vibeables??[],d=N(`skills.list`,{})?.skills??[];(0,v.useEffect)(()=>{e&&A.call(`agents.get`,{slug:e}).then(e=>n({name:e.name,emoji:e.emoji,description:e.description??``,harness:e.harness,model:e.model??``,effort:e.effort??``,group:e.group??``,system:e.system,workflows:e.workflows,knowledge:e.knowledge??[],vibeables:e.vibeables??[],skillsAll:e.skills===void 0,skills:e.skills??[]})).catch(()=>i(`agent not found`))},[e]);function f(){return{name:``,emoji:`🤖`,description:``,harness:`claude`,model:``,effort:``,group:``,system:``,workflows:[],knowledge:[],vibeables:[],skillsAll:!0,skills:[]}}async function p(){if(!t)return;o(!0),i(``);let n={...t,skills:t.skillsAll?void 0:t.skills},r=e?await A.request(`agents.save`,{slug:e,body:n}):await A.request(`agents.create`,{body:n});o(!1),r.ok?B(`/agents/${encodeURIComponent(r.data.slug)}/info`):i(M(r))}async function m(){e&&window.confirm(`Move agent "${e}" to the trash?`)&&(await A.request(`agents.delete`,{slug:e}).catch(()=>{}),B(`/agents`))}if(!t)return(0,F.jsx)(K,{children:r||`loading…`});let h=e=>n({...t,...e}),g=(e,n,r)=>h({[e]:r?[...t[e],n]:t[e].filter(e=>e!==n)});return(0,F.jsxs)(it,{width:`narrow`,children:[(0,F.jsx)(nt,{children:e?`edit ${e}`:`new agent`}),(0,F.jsx)(J,{children:(0,F.jsxs)(vt,{className:`max-w-[680px]`,children:[(0,F.jsxs)(yt,{children:[(0,F.jsx)(Z,{label:`name`,className:`flex-1`,children:(0,F.jsx)(X,{value:t.name,placeholder:`e.g. Max`,onChange:e=>h({name:e.target.value})})}),(0,F.jsx)(Z,{label:`emoji`,className:`w-[90px] max-[900px]:w-auto`,children:(0,F.jsx)(X,{value:t.emoji,onChange:e=>h({emoji:e.target.value})})})]}),(0,F.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:Ms.map(e=>(0,F.jsx)(`button`,{type:`button`,"aria-pressed":t.emoji===e,className:P(`cursor-pointer rounded-xl border px-2.5 py-1.5 text-base transition-colors`,t.emoji===e?`border-transparent bg-accent-soft`:`border-line bg-transparent hover:bg-surface-2`),onClick:()=>h({emoji:e}),children:e},e))}),(0,F.jsxs)(yt,{children:[(0,F.jsx)(Z,{label:`description`,className:`flex-1`,children:(0,F.jsx)(X,{value:t.description,placeholder:`one line: what this agent is for`,onChange:e=>h({description:e.target.value})})}),(0,F.jsx)(Z,{label:`group`,className:`w-[180px] max-[900px]:w-auto`,children:(0,F.jsx)(X,{value:t.group,placeholder:`none`,onChange:e=>h({group:e.target.value})})})]}),(0,F.jsxs)(yt,{children:[(0,F.jsx)(Z,{label:`harness`,className:`w-[140px] max-[900px]:w-auto`,children:(0,F.jsxs)(_t,{value:t.harness,onChange:e=>h({harness:e.target.value}),children:[(0,F.jsx)(`option`,{value:`claude`,children:`claude`}),(0,F.jsx)(`option`,{value:`codex`,children:`codex`}),(0,F.jsx)(`option`,{value:`pi`,children:`pi`})]})}),(0,F.jsx)(Z,{label:`model`,className:`flex-1`,children:(0,F.jsx)(X,{className:`font-mono`,value:t.model,placeholder:`harness default — e.g. sonnet, gpt-5.6-sol`,onChange:e=>h({model:e.target.value})})}),(0,F.jsx)(Z,{label:`effort`,className:`w-[140px] max-[900px]:w-auto`,children:(0,F.jsx)(_t,{value:t.effort,onChange:e=>h({effort:e.target.value}),children:qe.map(e=>(0,F.jsx)(`option`,{value:e,children:e||`default`},e))})})]}),(0,F.jsx)(Z,{label:`system prompt — the agent's role`,children:(0,F.jsx)(gt,{className:hs,rows:10,value:t.system,placeholder:`You are the ... for this project. Your job is ...`,onChange:e=>h({system:e.target.value})})}),(0,F.jsxs)(Ps,{label:`connected workflows — autoloaded into the agent's context; it can run them`,children:[s.map(e=>(0,F.jsx)(bt,{checked:t.workflows.includes(e.slug),onChange:t=>g(`workflows`,e.slug,t),hint:e.description,mono:!0,children:e.slug},e.slug)),s.length===0&&(0,F.jsx)(G,{className:`py-1.5 px-0`,children:`no workflows in this project`})]}),(0,F.jsxs)(Ps,{label:`connected knowledge — OKF bundles the agent consults and maintains`,children:[c.map(e=>(0,F.jsx)(bt,{checked:t.knowledge.includes(e.name),onChange:t=>g(`knowledge`,e.name,t),hint:`${e.concepts} concepts`,mono:!0,children:e.name},e.name)),c.length===0&&(0,F.jsx)(G,{className:`py-1.5 px-0`,children:`no knowledge bundles in this project`})]}),(l.vibeables||t.vibeables.length>0)&&(0,F.jsxs)(Ps,{label:`apps — small apps the agent builds and maintains`,linkKind:`vibeables`,children:[u.map(e=>(0,F.jsx)(bt,{checked:t.vibeables.includes(e.slug),onChange:t=>g(`vibeables`,e.slug,t),hint:e.dev?`dev`:`static`,mono:!0,children:e.slug},e.slug)),t.vibeables.filter(e=>!u.some(t=>t.slug===e)).map(e=>(0,F.jsx)(bt,{checked:!0,onChange:()=>g(`vibeables`,e,!1),hint:`not found in this workspace`,mono:!0,children:e},e)),!l.vibeables&&(0,F.jsx)(G,{className:`py-1.5 px-0`,children:`vibeables are off in this workspace's settings`}),l.vibeables&&u.length===0&&(0,F.jsx)(G,{className:`py-1.5 px-0`,children:`no vibeables in this workspace yet`})]}),(0,F.jsxs)(Ps,{label:`connected skills — workspace skill packages (see the skills tab); invoked with /name in sessions`,children:[(0,F.jsx)(bt,{checked:t.skillsAll,onChange:e=>h({skillsAll:e}),hint:`every discovered skill, including future ones`,mono:!0,children:`all skills`}),!t.skillsAll&&d.map(e=>(0,F.jsx)(bt,{checked:t.skills.includes(e.name),onChange:t=>g(`skills`,e.name,t),hint:e.description,mono:!0,children:`/${e.name}`},e.name)),!t.skillsAll&&d.length===0&&(0,F.jsx)(G,{className:`py-1.5 px-0`,children:`no skills found (.claude/skills, project or user)`})]}),r&&(0,F.jsx)(q,{tone:`bad`,children:r}),(0,F.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,F.jsx)(V,{variant:`primary`,busy:a,disabled:!t.name.trim(),onClick:p,children:a?`saving…`:e?`save`:`create`}),(0,F.jsx)(`span`,{className:`flex-1`}),e&&(0,F.jsx)(V,{variant:`danger`,icon:`delete`,onClick:m,children:`delete agent`})]})]})})]})}function Ps({label:e,linkKind:t,children:n}){return(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,"data-link-kind":t,children:[(0,F.jsx)(`span`,{className:`text-sm font-semibold text-fg`,children:e}),(0,F.jsx)(ms,{children:n})]})}var Fs=`bg-accent/7 outline-[1.5px] -outline-offset-[1.5px] outline-accent outline-dashed`,Is=`px-2.5 pt-1.5 pb-2 text-2xs text-fg-2`;function Ls({seg:e}){let t=e[0]&&e[0]!==`new`&&e[0]!==`chats`?decodeURIComponent(e[0]):void 0,n=e[0]===`new`?`new`:e[0]===`chats`?`chats`:e[1]===`edit`?`edit`:e[1]===`info`?`info`:e[1]===`chat`?`chat`:t?`agent`:`home`,r=n===`chats`&&e[1]===`new`,i=n===`chat`?e[2]:n===`chats`&&!r?e[1]:void 0,a=N(`agents.list`,{}),o=be(),s=Ra(),[c,l]=(0,v.useState)(()=>{try{let e=JSON.parse(localStorage.getItem(`kw-agent-groups`)??`[]`);return Array.isArray(e)?e.map(String):[]}catch{return[]}}),[u,d]=(0,v.useState)(!1),[f,p]=(0,v.useState)(``),[m,h]=(0,v.useState)(null),[g,_]=(0,v.useState)(``),[y,b]=(0,v.useState)(null),[x,S]=(0,v.useState)(null),[C,w]=(0,v.useState)({}),T=(a?.agents??[]).map(e=>C[e.slug]===void 0?e:{...e,group:C[e.slug]||void 0});(0,v.useEffect)(()=>{w(e=>{let t={...e},n=!1;for(let e of a?.agents??[])t[e.slug]!==void 0&&(e.group??``)===t[e.slug]&&(delete t[e.slug],n=!0);return n?t:e})},[a]);let E=T.filter(e=>!e.archived),D=T.filter(e=>e.archived),[O,k]=(0,v.useState)(!1),j=[...new Set([...E.map(e=>e.group??``).filter(Boolean),...c])].sort((e,t)=>e.localeCompare(t)),ee=E.filter(e=>!e.group);function M(e){l(e);try{localStorage.setItem(`kw-agent-groups`,JSON.stringify(e))}catch{}}function te(){let e=f.trim();d(!1),p(``),e&&!j.includes(e)&&M([...c,e])}function ne(e,t){h(null);let n=t.trim();if(n&&n!==e){for(let t of T.filter(t=>t.group===e))L(t.slug,n);c.includes(e)&&M([...new Set(c.map(t=>t===e?n:t))])}}async function L(e,t){if((T.find(t=>t.slug===e)?.group??``)!==t){w(n=>({...n,[e]:t}));try{let n=await A.call(`agents.get`,{slug:e});await A.call(`agents.save`,{slug:e,body:{...n,group:t||void 0}})}catch{w(t=>{let n={...t};return delete n[e],n})}}}let re=e=>o?{onDragOver:t=>{y!=null&&(t.preventDefault(),t.dataTransfer.dropEffect=`move`,x!==e&&S(e))},onDrop:t=>{t.preventDefault();let n=t.dataTransfer.getData(`text/plain`)||y;n&&L(n,e),b(null),S(null)}}:{},ie=e=>(0,F.jsx)(`div`,{className:y===e.slug?`opacity-40`:void 0,onDragStart:t=>{if(!o)return t.preventDefault();t.dataTransfer.setData(`text/plain`,e.slug),t.dataTransfer.effectAllowed=`move`,b(e.slug)},onDragEnd:()=>{b(null),S(null)},children:(0,F.jsx)(Y,{href:`/agents/${encodeURIComponent(e.slug)}`,active:e.slug===t,leading:(0,F.jsx)(`span`,{"aria-hidden":!0,children:e.emoji}),title:e.name,sub:e.description||e.harness})},e.slug),ae=e=>(0,F.jsx)(Y,{href:`/agents/${encodeURIComponent(e.slug)}/info`,active:e.slug===t,dim:e.slug!==t,leading:(0,F.jsx)(`span`,{"aria-hidden":!0,children:e.emoji}),title:e.name,sub:e.description||e.harness},e.slug),oe;oe=n===`new`?(0,F.jsx)(Ns,{},`new`):n===`edit`&&t?(0,F.jsx)(Ns,{slug:t},t):n===`chat`&&t&&i===`new`?(0,F.jsx)(bs,{slug:t,name:T.find(e=>e.slug===t)?.name},t):n===`chat`&&t&&i?(0,F.jsx)(`div`,{className:`chat-main`,children:(0,F.jsx)(jo,{id:i,agentName:T.find(e=>e.slug===t)?.name??t,agentDescription:T.find(e=>e.slug===t)?.description},i)}):n===`chats`?i?(0,F.jsx)(`div`,{className:`chat-main`,children:(0,F.jsx)(jo,{id:i},i)}):r?(0,F.jsx)(Io,{}):(0,F.jsx)(xs,{}):n===`info`&&t?(0,F.jsx)(js,{slug:t},t):t?(0,F.jsx)(ys,{slug:t,name:T.find(e=>e.slug===t)?.name},t):a?E.length?(0,F.jsx)(Es,{agents:E}):(0,F.jsx)(Ds,{}):(0,F.jsx)(K,{children:`loading…`});let se=(n===`agent`||n===`info`||n===`chat`)&&t?T.find(e=>e.slug===t)?.knowledge??[]:[],[ce,le]=(0,v.useState)(()=>localStorage.getItem(`kw-kside`)!==`hidden`),[ue,de]=(0,v.useState)(()=>Number(localStorage.getItem(`kw-kside-w`))||460),R=se.length>0&&ce;function z(e){le(e),localStorage.setItem(`kw-kside`,e?`open`:`hidden`)}function B(e){de(e),localStorage.setItem(`kw-kside-w`,String(e))}return(0,F.jsxs)(`div`,{className:`runs-screen agents-screen ${t||n===`chats`?`has-tabs`:``} ${(t||n===`chats`)&&s?`has-sessions`:``} ${R?`has-knowledge`:``}`,style:R?{"--kside-w":`${ue}px`}:void 0,children:[(0,F.jsxs)(`aside`,{className:`runs-side`,children:[(0,F.jsx)(wt,{title:`agents`,action:o&&(0,F.jsx)(V,{size:`sm`,variant:`quiet`,icon:`add`,href:`/agents/new`,children:`new`})}),(0,F.jsxs)(Et,{children:[(0,F.jsx)(`div`,{className:`mb-1.5 border-b border-line pb-1.5`,children:(0,F.jsx)(Y,{href:`/agents/chats`,active:n===`chats`,leading:(0,F.jsx)(`span`,{"aria-hidden":!0,children:`🎩`}),title:`Ralv`,sub:`chief of staff of the workspace`})}),(0,F.jsxs)(`div`,{className:P(`rounded-xl`,y&&x===``&&Fs),...re(``),children:[ee.map(ie),y!=null&&ee.length===0&&(0,F.jsx)(`div`,{className:Is,children:`no group — drop here`})]}),j.map(e=>{let t=E.filter(t=>t.group===e);return(0,F.jsxs)(`div`,{className:P(`group/grp mt-3 rounded-xl`,y&&x===e&&Fs),...re(e),children:[(0,F.jsxs)(`div`,{className:`flex items-center gap-1.5 px-2.5 pt-1.5 pb-0.5`,children:[m===e?(0,F.jsx)(X,{className:`h-7 min-w-0 flex-1 text-2xs`,autoFocus:!0,"aria-label":`group name`,value:g,onChange:e=>_(e.target.value),onKeyDown:t=>{t.key===`Enter`&&ne(e,g),t.key===`Escape`&&h(null)},onBlur:()=>ne(e,g)}):(0,F.jsx)(et,{children:e}),(0,F.jsx)(`span`,{className:`text-[10px] tabular-nums text-fg-2`,children:t.length}),(0,F.jsx)(`span`,{className:`flex-1`}),o&&m!==e&&(0,F.jsx)(H,{icon:`edit`,label:`Rename group`,size:`sm`,className:`size-6 opacity-0 group-hover/grp:opacity-100 focus-visible:opacity-100`,onClick:()=>{h(e),_(e)}}),o&&t.length===0&&c.includes(e)&&(0,F.jsx)(H,{icon:`close`,label:`Remove empty group`,size:`sm`,className:`size-6 opacity-0 group-hover/grp:opacity-100 focus-visible:opacity-100`,onClick:()=>M(c.filter(t=>t!==e))})]}),t.map(ie),t.length===0&&(0,F.jsx)(`div`,{className:Is,children:o?`drag agents here`:`no agents`})]},e)}),D.length>0&&(0,F.jsxs)(`div`,{className:`mt-2.5 border-t border-line pt-1`,children:[(0,F.jsxs)(`button`,{type:`button`,className:`group/arch flex w-full cursor-pointer items-center gap-1.5 border-0 bg-transparent px-2.5 pt-1.5 pb-0.5 text-left text-fg-2`,"aria-expanded":O,onClick:()=>k(e=>!e),children:[(0,F.jsx)(et,{className:`group-hover/arch:text-fg`,children:`archived`}),(0,F.jsx)(`span`,{className:`text-[10px] tabular-nums`,children:D.length}),(0,F.jsx)(`span`,{className:`flex-1`}),(0,F.jsx)(I,{name:O?`expand_less`:`expand_more`,className:`ms-sm`})]}),O&&D.map(ae)]}),a&&T.length===0&&(0,F.jsx)(G,{className:`py-1.5 px-2.5`,children:`no agents yet`}),o&&(u?(0,F.jsx)(`div`,{className:`px-2.5 pt-2.5 pb-1`,children:(0,F.jsx)(X,{className:`h-8 text-sm`,autoFocus:!0,"aria-label":`new group`,value:f,placeholder:`group name, e.g. Team Content`,onChange:e=>p(e.target.value),onKeyDown:e=>{e.key===`Enter`&&te(),e.key===`Escape`&&(d(!1),p(``))},onBlur:te})}):(0,F.jsxs)(`button`,{type:`button`,className:`mx-2.5 mt-3 mb-1 flex cursor-pointer items-center gap-1 rounded-lg border border-dashed border-line bg-transparent px-2.5 py-1 text-2xs text-fg-2 hover:text-accent`,onClick:()=>d(!0),children:[(0,F.jsx)(I,{name:`add`,className:`ms-sm`}),` group`]}))]})]}),t&&(0,F.jsx)(Ss,{slug:t,chatId:i===`new`?void 0:i}),n===`chats`&&(0,F.jsx)(Ts,{chatId:i}),(0,F.jsx)(`div`,{className:`runs-main`,children:oe}),R&&(0,F.jsx)(gs,{bundles:se,onHide:()=>z(!1),onResize:B}),se.length>0&&!ce&&(0,F.jsxs)(`button`,{type:`button`,className:`kside-reopen fixed top-[60px] right-3.5 z-5 inline-flex cursor-pointer items-center gap-1 rounded-full border border-line bg-surface-2 px-3 py-1 text-2xs text-fg-2 hover:text-fg`,onClick:()=>z(!0),title:`Show knowledge sidebar`,children:[(0,F.jsx)(I,{name:`menu_book`,className:`ms-sm`}),` knowledge`]})]})}function Rs(e){if(!z(e))return null;let t=e.split(`/`).filter(Boolean),n=decodeURIComponent(t[1]),r=t[0]===`agents`||t[0]===`team`;return n===`new`?t[0]===`projects`?(0,F.jsx)(Jo,{},`new-project`):r?(0,F.jsx)(Ns,{},`new-agent`):(0,F.jsx)(Da,{},`new-channel`):t[0]===`projects`&&t[2]===`info`?(0,F.jsx)(ts,{slug:n,onChanged:async()=>{}},n):r&&t[2]===`info`?(0,F.jsx)(js,{slug:n},n):r&&t[2]===`edit`?(0,F.jsx)(Ns,{slug:n},n):t[0]===`channels`&&t[2]===`edit`?(0,F.jsx)(Da,{slug:n},n):null}function zs({back:e,children:t}){let n=()=>B(e);return(0,v.useEffect)(()=>{let e=e=>{e.key!==`Escape`||e.defaultPrevented||document.querySelector(`.palette-backdrop`)||(e.preventDefault(),n())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)}),(0,F.jsx)(`div`,{className:`fixed inset-0 z-40 flex animate-fade items-start justify-center bg-black/38 px-4 pt-[6vh] pb-4 max-[800px]:p-0`,onMouseDown:n,children:(0,F.jsxs)(`div`,{className:`edit-modal relative max-h-[88dvh] w-[min(960px,100%)] animate-modal overflow-y-auto rounded-card border border-line bg-surface shadow-modal max-[800px]:max-h-dvh max-[800px]:rounded-none`,role:`dialog`,"aria-label":`edit`,onMouseDown:e=>e.stopPropagation(),children:[(0,F.jsx)(H,{icon:`close`,label:`close (esc)`,className:`absolute top-3 right-3 z-1 rounded-full`,onClick:n}),(0,F.jsx)(`div`,{className:`runs-main min-w-0 pt-[18px] pr-12 pb-10 pl-6`,children:t})]})})}function Bs({runId:e,decision:t}){let{request:n,answer:r}=t,[i,a]=(0,v.useState)(n.options.length===1?n.options[0].value:null),[o,s]=(0,v.useState)(``),[c,l]=(0,v.useState)(!1),[u,d]=(0,v.useState)(null),f=e=>n.options.find(t=>t.value===e)?.label??e;if(r)return(0,F.jsx)(`section`,{className:P(Vs,`decision-panel is-decided`),"aria-label":`decision`,children:(0,F.jsxs)(`div`,{className:`flex flex-col gap-3 px-5 py-4`,children:[(0,F.jsx)(`div`,{className:Hs,children:n.title??`Decision`}),(0,F.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 text-base`,children:[(0,F.jsx)(W,{tone:`ok`,children:f(r.decision)}),r.note&&(0,F.jsxs)(`span`,{className:`text-fg-2`,children:[`“`,r.note,`”`]}),r.decidedAt&&(0,F.jsx)(`span`,{className:`text-xs tabular-nums text-fg-2`,children:We(r.decidedAt)})]})]})});let p=!!i&&!c&&(n.note!==`required`||!!o.trim());async function m(){if(!p)return;l(!0),d(null);let t=await A.request(`runs.decide`,{id:e,body:{decision:i,note:o.trim()}}).catch(()=>null);t?.ok||(d(t?.error??`could not save the decision`),l(!1))}return(0,F.jsx)(`section`,{className:P(Vs,`decision-panel`),"aria-label":`decision needed`,children:(0,F.jsxs)(`div`,{className:`flex flex-col gap-3 px-5 py-4`,children:[(0,F.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,F.jsx)(U,{tone:`working`}),(0,F.jsx)(`div`,{className:Hs,children:n.title??`This run needs your decision`})]}),n.prompt&&(0,F.jsx)(`p`,{className:`m-0 max-w-[80ch] text-base text-fg-2`,children:n.prompt}),(0,F.jsx)(`div`,{className:`flex flex-wrap gap-2 self-start`,role:`radiogroup`,"aria-label":`options`,children:n.options.map(e=>(0,F.jsx)(V,{role:`radio`,"aria-checked":i===e.value,variant:i===e.value?`primary`:`secondary`,onClick:()=>a(e.value),children:e.label??e.value},e.value))}),n.note!==!1&&(0,F.jsx)(X,{value:o,placeholder:n.note===`required`?`Note (required)`:`Note`,"aria-label":`note`,className:`max-w-[60ch]`,onChange:e=>s(e.target.value),onKeyDown:e=>e.key===`Enter`&&m()}),u&&(0,F.jsx)(q,{tone:`bad`,children:u}),(0,F.jsx)(`div`,{className:`flex gap-2`,children:(0,F.jsx)(V,{variant:`primary`,onClick:m,disabled:!p,busy:c,children:c?`Saving…`:`Submit decision`})})]})})}var Vs=`mb-[18px] overflow-hidden rounded-card border border-line bg-surface`,Hs=`text-[16px] font-medium text-fg`;function Us(e){return e===`ok`?`ok`:e===`running`?`working`:e===`failed`||e===`blocked`?`bad`:`idle`}function Ws({status:e}){return(0,F.jsx)(`span`,{"data-ui":`status`,"data-status":e,className:`inline-flex`,children:(0,F.jsx)(W,{tone:e===`ok`?`ok`:e===`failed`||e===`blocked`?`bad`:e===`running`?`accent`:`neutral`,children:e})})}function Gs(){return(0,F.jsx)(`span`,{"data-ui":`decision`,className:`inline-flex`,children:(0,F.jsx)(W,{tone:`accent`,children:`decision needed`})})}function Ks({label:e,children:t,className:n}){return(0,F.jsxs)(`div`,{className:n,children:[(0,F.jsx)(et,{className:`mb-px block`,children:e}),(0,F.jsx)(`div`,{className:`font-mono text-md font-medium tabular-nums text-fg`,children:t})]})}var qs=`mb-[22px] flex flex-wrap gap-[26px]`;function Js({id:e,workflow:t}){let n=N(`runs.list`,{},{fast:!0}),r=n?.runs??[],[i,a]=(0,v.useState)(t??``),o=(0,v.useMemo)(()=>{let e=i.trim().toLowerCase();return e?r.filter(t=>[t.workflow,t.request,t.id].some(t=>t?.toLowerCase().includes(e))):r},[r,i]);return(0,F.jsxs)(`div`,{className:`runs-screen`,children:[(0,F.jsxs)(`aside`,{className:`runs-side`,children:[(0,F.jsx)(wt,{title:`runs`,back:{href:`/workflows`,label:`back to workflows`},count:i?`${o.length} / ${r.length}`:r.length}),(0,F.jsx)(Tt,{icon:`filter_list`,value:i,placeholder:`filter by workflow or request`,"aria-label":`filter runs`,onChange:e=>a(e.target.value)}),(0,F.jsxs)(Et,{label:`runs list`,children:[o.map(t=>(0,F.jsx)(Ys,{r:t,active:t.id===e},t.id)),n&&r.length===0&&(0,F.jsx)(Dt,{children:`no runs yet`}),r.length>0&&o.length===0&&(0,F.jsxs)(Dt,{children:[`no run matches “`,i,`”`]})]})]}),(0,F.jsx)(`div`,{className:`runs-main`,children:(0,F.jsx)(Xs,{id:e},e)})]})}function Ys({r:e,active:t}){return(0,F.jsx)(Y,{href:`/runs/${e.id}`,active:t,size:`sm`,leading:(0,F.jsx)(U,{tone:Us(e.status),title:e.status}),title:e.workflow??`unknown`,meta:We(e.startedAt),sub:(0,F.jsxs)(`span`,{className:`flex gap-2`,children:[(0,F.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,title:e.request,children:e.status===`running`&&e.currentPhase?`${e.currentPhase}`:e.request??``}),(0,F.jsx)(`span`,{className:`shrink-0 tabular-nums`,children:e.status===`running`?(0,F.jsx)(Ke,{since:e.startedAt}):Be(e.durationMs)})]})})}function Xs({id:e}){let t=N(`runs.get`,{id:e},{fast:!0}),n=t?.status===`running`,[r,i]=(0,v.useState)(null),[a,o]=(0,v.useState)(!1),[s,c]=(0,v.useState)(null),l=be();if(!t)return(0,F.jsx)(K,{children:`loading…`});let u=t.files.some(e=>e.name===`runner.json`),d=r??(n?`run`:`artifacts`),f=l?t.files.length:t.files.filter(e=>!rc(e.name)).length;async function p(){o(!0),c(null);let t=await A.request(`runs.stop`,{id:e}).catch(()=>null);t?.ok||(o(!1),c(t?.error??`stop failed`))}async function m(){if(!window.confirm(`Move run ${e} to the trash?`))return;c(null);let n=await A.request(`runs.delete`,{id:e}).catch(()=>null);if(n?.ok){B(t?.workflow?`/workflows/${encodeURIComponent(t.workflow)}`:`/workflows`);return}c(n?.error??`remove failed`)}return(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(`header`,{className:`mb-1.5 flex flex-wrap items-center gap-x-4 gap-y-2.5`,children:[(0,F.jsx)(U,{tone:Us(t.status),title:t.status}),(0,F.jsx)(nt,{size:`lg`,children:t.workflow?(0,F.jsx)(he,{href:`/workflows/${encodeURIComponent(t.workflow)}`,title:`open workflow`,className:`text-inherit no-underline hover:text-accent`,children:t.workflow}):`unknown workflow`}),(0,F.jsx)(Ws,{status:t.status}),u&&(0,F.jsxs)(W,{children:[(0,F.jsx)(I,{name:`science`,className:`ms-sm mr-1`}),` sandbox`]}),(0,F.jsx)(`span`,{className:`font-mono text-xs text-fg-2`,children:e.replace(/^run-/,``)}),n?(0,F.jsx)(V,{size:`sm`,variant:`danger`,icon:`stop`,busy:a,onClick:p,children:a?`stopping…`:`stop`}):(0,F.jsx)(V,{size:`sm`,variant:`danger`,icon:`delete`,onClick:m,title:`delete this run's folder`,children:`remove`}),s&&(0,F.jsx)(`span`,{className:`text-xs text-bad`,children:s}),(0,F.jsx)(`span`,{className:`flex-1`}),(0,F.jsx)(V,{size:`sm`,variant:`quiet`,title:`chat with an agent about this run`,onClick:()=>void Fo(`claude`,{kind:`run`,runId:e}),children:`⌬ discuss`}),(0,F.jsx)(ft,{className:`border-b-0 px-0`,label:`run sections`,value:d,onChange:i,items:[{id:`run`,label:`run`},{id:`artifacts`,label:`artifacts`,count:f}]})]}),t.request&&(0,F.jsx)(`p`,{className:`mb-5 max-w-[90ch] text-base text-fg-2`,children:t.request}),d===`run`?(0,F.jsx)(Zs,{run:t,live:n}):(0,F.jsx)(ac,{id:e,files:t.files,live:n})]})}function Zs({run:e,live:t}){return(0,F.jsxs)(`div`,{className:`max-w-[1080px]`,children:[e.decision&&(0,F.jsx)(Bs,{runId:e.id,decision:e.decision}),(0,F.jsxs)(`div`,{className:qs,children:[(0,F.jsxs)(Ks,{label:`phases`,children:[e.phasesDone,e.phasesTotal==null?``:` / ${e.phasesTotal}`]}),(0,F.jsx)(Ks,{label:`duration`,children:t?(0,F.jsx)(Ke,{since:e.startedAt}):Be(e.durationMs)}),(0,F.jsx)(Ks,{label:`cost`,children:Ve(e.costUsd??$s(e.phases))}),(0,F.jsxs)(Ks,{label:`tokens in / out`,children:[He(Qs(e.phases,`tokensIn`)),` / `,He(Qs(e.phases,`tokensOut`))]})]}),(0,F.jsx)(J,{title:`phase timeline`,actions:t&&(0,F.jsxs)(`span`,{className:`inline-flex items-center gap-[7px] text-2xs text-fg-2`,children:[(0,F.jsx)(U,{tone:`working`}),` live · polling`]}),children:(0,F.jsx)(`div`,{className:`py-1.5`,children:e.phases.map(e=>(0,F.jsx)(tc,{p:e},e.phase))})})]})}function Qs(e,t){return e.reduce((e,n)=>e+(n[t]??0),0)}function $s(e){return e.reduce((e,t)=>e+(t.costUsd??0),0)}var ec=`relative border-line/55 [&+&]:border-t before:absolute before:top-0 before:bottom-0 before:w-px before:bg-line last:before:bottom-auto`;function tc({p:e}){let t=e.gates.filter(e=>!e.passed);return(0,F.jsxs)(`div`,{className:P(ec,`py-2.5 pr-[18px] pl-[42px] before:left-[23px] first:before:top-4 last:before:h-4`),children:[(0,F.jsx)(`span`,{className:`absolute top-4 left-[19px] z-1 grid`,children:(0,F.jsx)(U,{tone:Us(e.status),title:e.status})}),(0,F.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-2.5`,children:[(0,F.jsx)(`span`,{className:`text-base font-medium text-fg`,children:e.phase}),e.kind===`agent`?(0,F.jsxs)(W,{tone:`accent`,children:[e.agent,e.model?` · ${e.model}`:``,e.protocol?` · ${e.protocol}`:``]}):(0,F.jsx)(W,{children:`script`}),e.status===`skipped`&&(0,F.jsx)(Ws,{status:`skipped`}),(0,F.jsxs)(`span`,{className:`ml-auto flex gap-3.5 font-mono text-[11.5px] tabular-nums text-fg-2`,children:[e.attempts>1&&(0,F.jsxs)(`span`,{children:[`att `,e.attempts]}),e.status===`running`?(0,F.jsx)(Ke,{since:e.startedAt}):e.durationMs!=null&&(0,F.jsx)(`span`,{children:Be(e.durationMs)}),e.kind===`agent`&&e.tokensIn!=null&&(0,F.jsxs)(`span`,{children:[He(e.tokensIn),` / `,He(e.tokensOut)]}),e.costUsd!=null&&e.costUsd>0&&(0,F.jsx)(`span`,{children:Ve(e.costUsd)})]})]}),e.status===`running`&&e.lastActivity&&(0,F.jsxs)(`div`,{className:`mt-[3px] font-mono text-[11.5px] text-accent`,children:[`▸ `,e.lastActivity]}),e.summary&&e.status!==`running`&&(0,F.jsx)(`div`,{className:`mt-[3px] max-w-[72ch] text-[12.5px] text-fg-2`,children:e.summary}),e.gates.length>0&&(0,F.jsx)(`div`,{className:`mt-[5px] flex flex-wrap gap-1.5`,children:e.gates.map(e=>(0,F.jsxs)(`span`,{className:P(`inline-flex items-center gap-[5px] rounded-lg px-2.5 py-0.5 font-mono text-2xs`,e.passed?`bg-ok-soft text-ok`:`bg-bad-soft text-on-bad-soft`),title:e.failure??``,children:[(0,F.jsx)(I,{name:e.passed?`check`:`close`,className:`ms-sm`}),` `,e.gate]},e.gate))}),t.map(e=>(0,F.jsx)(`div`,{className:`mt-1 text-xs text-bad`,children:e.failure},e.gate))]})}var nc=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`]);function rc(e){return e===`runner.json`||e.endsWith(`.jsonl`)||e.endsWith(`.log`)}function ic(e){let t=[`report.html`,`recommendation.md`].find(t=>e.some(e=>e.name===t));if(t)return t;let n=e=>{let t=e.split(`.`).pop()?.toLowerCase()??``;return[`html`,`md`,`markdown`,`pdf`].includes(t)||nc.has(t)?0:rc(e)?2:1},r=null;for(let t of e)(!r||n(t.name)<n(r.name))&&(r=t);return r?.name??null}function ac({id:e,files:t,live:n}){let[r,i]=(0,v.useState)(null),a=be(),o=(0,v.useMemo)(()=>a?t:t.filter(e=>!rc(e.name)),[t,a]);return(0,v.useEffect)(()=>{!a&&r&&rc(r)&&i(null)},[a,r]),(0,v.useEffect)(()=>{r||o.length===0||i(ic(o))},[o,r]),(0,F.jsxs)(`div`,{className:`grid h-[calc(100vh-172px)] min-h-[420px] grid-cols-[280px_minmax(0,1fr)] gap-3.5 max-[940px]:h-auto max-[940px]:grid-cols-1`,children:[(0,F.jsx)(J,{title:(0,F.jsxs)(F.Fragment,{children:[`files `,(0,F.jsxs)(`span`,{className:`tabular-nums`,children:[`(`,o.length,`)`]})]}),className:`flex min-h-0 flex-col`,children:(0,F.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-auto max-[940px]:max-h-60`,children:[o.map(e=>(0,F.jsxs)(`button`,{type:`button`,className:P(`flex w-full cursor-pointer items-center gap-2.5 border-0 border-b border-line/55 px-[18px] py-2 text-left font-mono text-[12.5px] transition-colors last:border-b-0`,r===e.name?`bg-accent-soft text-on-accent-soft`:`bg-transparent text-fg-2 hover:bg-surface-2 hover:text-fg`),onClick:()=>i(e.name),children:[(0,F.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.name}),(0,F.jsx)(`span`,{className:`text-2xs tabular-nums text-fg-2`,children:Ue(e.size)})]},e.name)),o.length===0&&(0,F.jsx)(G,{className:`px-[18px] py-3`,children:t.length>0?`no result files — raw run files live in expert mode`:`no files yet`})]})}),(0,F.jsx)(J,{title:r??`viewer`,className:`flex min-h-0 flex-col`,actions:r&&(0,F.jsx)(`a`,{className:oc,href:A.url(`runs.file`,{id:e,query:{name:r,raw:!0}}),target:`_blank`,children:`open raw ↗`}),children:r?(0,F.jsx)(dc,{id:e,name:r,live:n}):(0,F.jsx)(K,{className:`flex-1 justify-center`,children:`select a file`})})]})}var oc=`inline-flex h-7 items-center rounded-control px-2.5 text-sm font-medium text-fg-2 no-underline transition-colors hover:bg-surface-2 hover:text-fg`,sc=`flex min-h-0 flex-1 flex-col`,cc=`min-h-0 flex-1`,lc=`m-0 h-full overflow-auto px-[18px] py-3.5 text-xs leading-[1.55] break-words whitespace-pre-wrap text-fg-2`,uc=`block h-full min-h-[560px] w-full border-0 bg-white`;function dc({id:e,name:t,live:n}){let r=t.split(`.`).pop()?.toLowerCase()??``,i=A.url(`runs.file`,{id:e,query:{name:t,raw:!0}});return r===`html`?(0,F.jsx)(`div`,{className:sc,children:(0,F.jsx)(`div`,{className:cc,children:(0,F.jsx)(`iframe`,{className:uc,src:i,sandbox:`allow-scripts`,allow:`clipboard-write`,title:t})})}):r===`pdf`?(0,F.jsx)(`div`,{className:sc,children:(0,F.jsx)(`div`,{className:cc,children:(0,F.jsx)(`iframe`,{className:uc,src:i,title:t})})}):nc.has(r)?(0,F.jsx)(`div`,{className:sc,children:(0,F.jsx)(`div`,{className:cc,children:(0,F.jsx)(`img`,{className:`block max-h-full max-w-full object-contain px-[18px] py-3.5`,src:i,alt:t})})}):r===`md`||r===`markdown`?(0,F.jsx)(pc,{id:e,name:t,live:n}):(0,F.jsx)(mc,{id:e,name:t,live:n})}var fc=`flex items-center gap-3 border-b border-line/55 px-[18px] py-1.5 text-2xs text-fg-2`;function pc({id:e,name:t,live:n}){let[r,i]=(0,v.useState)(`rendered`),a=N(`runs.fileText`,{id:e,query:{name:t}},{fast:n}),o=(0,v.useMemo)(()=>a?da.sanitize(Fr.parse(a.content,{async:!1})):``,[a?.content]);return(0,F.jsxs)(`div`,{className:sc,children:[(0,F.jsxs)(`div`,{className:fc,children:[(0,F.jsx)(ft,{className:`border-b-0 px-0`,label:`markdown view`,value:r,onChange:i,items:[{id:`rendered`,label:`rendered`},{id:`source`,label:`source`}]}),a?.truncated&&(0,F.jsxs)(`span`,{children:[`large file — showing the last `,Ue(4e5)]})]}),(0,F.jsx)(`div`,{className:P(cc,`overflow-auto`),children:a?r===`rendered`?(0,F.jsx)(`div`,{className:`md-body`,dangerouslySetInnerHTML:{__html:o}}):(0,F.jsx)(`pre`,{className:lc,children:a.content||`(empty)`}):(0,F.jsx)(`pre`,{className:lc,children:`loading…`})})]})}function mc({id:e,name:t,live:n}){let r=N(`runs.fileText`,{id:e,query:{name:t}},{fast:n});return(0,F.jsxs)(`div`,{className:sc,children:[r?.truncated&&(0,F.jsxs)(`div`,{className:fc,children:[`large file — showing the last `,Ue(4e5)]}),(0,F.jsx)(`div`,{className:cc,children:(0,F.jsx)(`pre`,{className:lc,children:r?r.content||`(empty)`:`loading…`})})]})}function hc(){return N(`workflows.runner`,{slug:`any`},{interval:15e3})}var gc=e=>!!e?.available&&!!e?.image;function _c(e){return e?e.available?e.image?`isolated container per run`:"image missing — run `kraftwerk runner build`":`Docker is not running`:``}async function vc(e,t){return(await A.call(`workflows.run`,{slug:e,body:t})).runId}function yc(e,t,n,r){let[i,a]=(0,v.useState)(``),[o,s]=(0,v.useState)(!0),[c,l]=(0,v.useState)(!1),[u,d]=(0,v.useState)(!1),[f,p]=(0,v.useState)(null),m=hc();(0,v.useEffect)(()=>{!i&&n&&a(n)},[n]),(0,v.useEffect)(()=>{m&&!gc(m)&&s(!1)},[m]);let h=!u&&(!t||!!i.trim())&&(!o||gc(m));async function g(){if(h){d(!0),p(null);try{let t=await vc(e,{request:i.trim(),sandbox:o,ssh:c});r?(r(t),d(!1)):B(`/runs/${t}`)}catch(e){p(e.message),d(!1)}}}return{request:i,setRequest:a,sandbox:o,setSandbox:s,ssh:c,setSsh:l,busy:u,error:f,docker:m,canRun:h,launch:g}}function bc({slug:e,usesRequest:t,initialRequest:n,onLaunched:r}){let i=yc(e,t,n,r);return(0,F.jsxs)(`div`,{className:`flex flex-col gap-1 px-5 pt-4 pb-2`,children:[(0,F.jsxs)(`div`,{className:`flex items-center gap-4 max-[700px]:flex-wrap`,children:[t?(0,F.jsx)(X,{className:`h-11 min-w-0 flex-1 text-md`,value:i.request,placeholder:`Request`,"aria-label":`request`,onChange:e=>i.setRequest(e.target.value),onKeyDown:e=>e.key===`Enter`&&i.launch()}):(0,F.jsx)(`span`,{className:`flex-1 text-base text-fg-2`,children:`This workflow takes no request.`}),(0,F.jsx)(V,{variant:`primary`,icon:`play_arrow`,className:`h-11 px-5 max-[700px]:w-full`,busy:i.busy,onClick:i.launch,disabled:!i.canRun,children:i.busy?`Starting…`:`Run`})]}),(0,F.jsxs)(`div`,{className:`-mx-2 mt-1 flex flex-wrap gap-x-2`,children:[(0,F.jsx)(Ct,{label:`Docker sandbox`,hint:_c(i.docker),checked:i.sandbox,onChange:i.setSandbox}),i.sandbox&&(0,F.jsx)(Ct,{label:`Forward SSH agent`,hint:`keys and known hosts from this machine`,checked:i.ssh,onChange:i.setSsh})]}),i.error&&(0,F.jsx)(q,{tone:`bad`,children:i.error})]})}var xc=`\0done`,Sc=5;function Cc(e,t){return e.status===`ok`?xc:e.currentPhase&&t.includes(e.currentPhase)?e.currentPhase:t[0]??xc}var wc=[`var(--accent)`,`#4fb8a8`,`#a78bfa`,`#e5793b`];function Tc(e){return e==null?`var(--text-2)`:wc[e%wc.length]}function Ec({colour:e,children:t,small:n}){return(0,F.jsx)(`span`,{style:{"--aid":e},className:P(`relative z-1 grid flex-none place-items-center rounded-full border font-mono font-bold tabular-nums`,`border-[color-mix(in_srgb,var(--aid)_55%,var(--line))] bg-[color-mix(in_srgb,var(--aid)_18%,var(--surface-1))] text-[var(--aid)]`,n?`size-[22px] text-2xs`:`mt-px size-[26px] text-[11.5px]`),children:t})}function Dc({wf:e,runs:t,agentIdx:n,runsHref:r}){let i=e.steps.map(e=>e.name),a=new Map([...i,xc].map(e=>[e,[]]));for(let e of t)a.get(Cc(e,i)).push(e);let o=a.get(xc)??[];return(0,F.jsxs)(`div`,{className:`board flex items-start gap-3 overflow-x-auto px-[18px] pt-3.5 pb-[18px]`,children:[e.steps.map((e,t)=>{let i=a.get(e.name)??[];return(0,F.jsx)(Oc,{step:e.name,index:(0,F.jsx)(Ec,{small:!0,colour:Tc(e.agent?n.get(e.agent)??0:null),children:t+1}),count:i.length,children:(0,F.jsx)(kc,{cards:i,moreHref:r})},e.name)}),(0,F.jsx)(Oc,{step:`done`,name:`done`,done:!0,index:(0,F.jsx)(Ec,{small:!0,colour:`var(--ok)`,children:`✓`}),count:o.length,children:(0,F.jsx)(kc,{cards:o,moreHref:r})})]})}function Oc({step:e,name:t,done:n,index:r,count:i,children:a}){return(0,F.jsxs)(`div`,{className:P(`board-col flex min-w-60 flex-[0_0_240px] flex-col gap-1.5`,n&&`is-done`),"data-step":e,children:[(0,F.jsxs)(`div`,{className:`flex items-center gap-2 px-0.5 pt-0.5 pb-1`,children:[r,(0,F.jsx)(`span`,{className:`board-col-name min-w-0 truncate text-[13.5px] font-medium text-fg`,title:t??e,children:t??e}),(0,F.jsx)(`span`,{className:`board-col-count ml-auto font-mono text-[11.5px] tabular-nums text-fg-2`,children:i})]}),a]})}function kc({cards:e,moreHref:t}){return(0,F.jsxs)(`div`,{className:`flex min-h-14 flex-col gap-2 rounded-xl bg-surface-2/60 p-2`,children:[e.slice(0,Sc).map(e=>(0,F.jsx)(Ac,{r:e},e.id)),e.length===0&&(0,F.jsx)(`div`,{className:`board-col-empty py-3.5 text-center text-xs text-fg-2`,children:`—`}),e.length>Sc&&(0,F.jsxs)(he,{href:t,className:`board-more block p-1.5 text-center text-xs text-fg-2 no-underline hover:text-accent`,children:[`+ `,e.length-Sc,` more ↗`]})]})}function Ac({r:e}){let t=e.request??e.id.replace(/^run-/,``);return(0,F.jsxs)(he,{href:`/runs/${e.id}`,className:`board-card block rounded-xl border border-line bg-surface px-3 py-2.5 text-inherit no-underline transition-colors hover:bg-surface-2`,children:[(0,F.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,F.jsx)(U,{tone:Us(e.status),title:e.status}),(0,F.jsx)(`span`,{className:`min-w-0 truncate text-[13.5px] font-medium text-fg`,title:t,children:t})]}),(0,F.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap gap-2.5 font-mono text-[11.5px] tabular-nums text-fg-2`,children:[(0,F.jsx)(`span`,{children:We(e.startedAt)}),(0,F.jsx)(`span`,{children:e.status===`running`?(0,F.jsx)(Ke,{since:e.startedAt}):Be(e.durationMs)}),e.costUsd!=null&&e.costUsd>0&&(0,F.jsx)(`span`,{children:Ve(e.costUsd)})]}),(e.awaitingDecision||e.status===`failed`||e.status===`aborted`)&&(0,F.jsxs)(`div`,{className:`mt-2 flex flex-wrap gap-1.5`,children:[e.awaitingDecision&&(0,F.jsx)(Gs,{}),(e.status===`failed`||e.status===`aborted`)&&(0,F.jsx)(Ws,{status:e.status})]})]})}function jc({slug:e,tab:t}){let n=N(`workflows.get`,{slug:e}),[r,i]=(0,v.useState)(0),[a,o]=(0,v.useState)(0),s=N(`runs.list`,{},{fast:a>0||Date.now()-r<2e4});if(!n)return(0,F.jsx)(K,{children:`loading…`});if(n.error)return(0,F.jsxs)(K,{children:[(0,F.jsx)(W,{tone:`bad`,children:`broken workflow`}),(0,F.jsx)(`pre`,{className:`mt-3 text-left`,children:n.error}),(0,F.jsx)(`div`,{className:`mt-4 flex justify-center`,children:(0,F.jsx)(Nc,{slug:n.slug})})]});let c=new Map(n.agents.map((e,t)=>[e.id,t%4])),l=(s?.runs??[]).filter(e=>e.workflow===n.name||e.workflow===n.slug),u=`/workflows/${encodeURIComponent(n.slug)}`,d=l.filter(e=>e.status===`running`).length;return d!==a&&o(d),(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(`header`,{className:`mb-1.5 flex flex-wrap items-center gap-x-4 gap-y-2.5 in-[.ctx-embed]:mb-3 in-[.ctx-embed]:gap-y-2`,children:[(0,F.jsx)(nt,{size:`lg`,className:`in-[.ctx-embed]:text-xl`,children:n.name??n.slug}),(0,F.jsx)(`span`,{className:`min-w-0 font-mono text-xs [overflow-wrap:anywhere] text-fg-2 in-[.ctx-embed]:hidden`,children:n.dir}),(0,F.jsx)(`span`,{className:`flex-1`}),(0,F.jsx)(ft,{bare:!0,label:`workflow sections`,value:t,items:[{id:`overview`,href:u,label:`overview`},{id:`details`,href:`${u}/details`,label:`details`},{id:`runs`,href:`${u}/runs`,label:(0,F.jsxs)(F.Fragment,{children:[`runs `,(0,F.jsxs)(`span`,{className:`tabular-nums`,children:[`(`,l.length,`)`]})]})}]})]}),n.description&&(0,F.jsx)(`p`,{className:`mb-5 max-w-[90ch] text-base text-fg-2`,children:n.description}),t===`overview`&&(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(J,{className:`run-panel mb-[18px]`,children:(0,F.jsx)(bc,{slug:n.slug,usesRequest:n.usesRequest,initialRequest:l[0]?.request,onLaunched:()=>i(Date.now())})}),(0,F.jsx)(J,{title:(0,F.jsxs)(F.Fragment,{children:[`board`,` `,(0,F.jsxs)(`span`,{className:`tabular-nums`,children:[`(`,l.length,` runs`,d>0?`, ${d} live`:``,`)`]})]}),actions:l[0]&&(0,F.jsx)(V,{size:`sm`,variant:`quiet`,href:`${u}/runs`,className:`in-[.ctx-embed]:hidden`,children:`all runs ↗`}),children:(0,F.jsx)(Dc,{wf:n,runs:l,agentIdx:c,runsHref:`${u}/runs`})})]}),t===`details`&&(0,F.jsx)(Mc,{wf:n,agentIdx:c}),t===`runs`&&(0,F.jsx)(Pc,{runs:l})]})}function Mc({wf:e,agentIdx:t}){return(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(`div`,{className:qs,children:[(0,F.jsx)(Ks,{label:`agents`,children:e.agents.length}),(0,F.jsxs)(Ks,{label:`steps`,children:[e.steps.length,` `,(0,F.jsxs)(`span`,{className:`font-normal text-fg-2`,children:[`(`,e.steps.filter(e=>e.kind===`agent`).length,` agent · `,e.steps.filter(e=>e.kind===`script`).length,` script)`]})]}),e.workspace&&(0,F.jsx)(Ks,{label:`workspace`,className:`max-w-[420px]`,children:(0,F.jsx)(`span`,{className:`text-[11.5px] font-normal whitespace-pre-wrap text-fg-2`,children:e.workspace})})]}),(0,F.jsx)(J,{title:`agents`,className:`mb-[18px]`,children:(0,F.jsxs)(`div`,{className:`grid grid-cols-[repeat(auto-fit,minmax(280px,1fr))]`,children:[e.agents.map(e=>(0,F.jsx)(Ic,{a:e,idx:t.get(e.id)??0},e.id)),e.agents.length===0&&(0,F.jsx)(G,{className:`px-[18px] py-3`,children:`no agents — script-only workflow`})]})}),(0,F.jsxs)(`div`,{className:`grid items-start gap-[18px] grid-cols-[minmax(430px,5fr)_minmax(360px,4fr)] max-[1100px]:grid-cols-1 in-[.ctx-embed]:grid-cols-1`,children:[(0,F.jsx)(J,{title:`pipeline`,children:(0,F.jsx)(`div`,{className:`pipeline py-2`,children:e.steps.map((e,n)=>(0,F.jsx)(Lc,{s:e,i:n,idx:e.agent?t.get(e.agent)??0:null},e.name))})}),(0,F.jsx)(J,{title:(0,F.jsxs)(F.Fragment,{children:[`folder `,(0,F.jsxs)(`span`,{className:`tabular-nums`,children:[`(`,e.files.length,` files)`]})]}),children:(0,F.jsx)(`div`,{className:`max-h-[300px] overflow-auto`,children:e.files.map(e=>(0,F.jsx)(`div`,{className:`truncate border-b border-line/55 px-[18px] py-2 font-mono text-[12.5px] text-fg-2 last:border-b-0`,children:e},e))})})]}),(0,F.jsx)(`div`,{className:`mt-[18px] in-[.ctx-embed]:hidden`,children:(0,F.jsx)(Nc,{slug:e.slug})})]})}function Nc({slug:e}){let[t,n]=(0,v.useState)(!1),[r,i]=(0,v.useState)(!1),[a,o]=(0,v.useState)(``),s=async()=>{i(!0),o(``);try{let t=await A.request(`workflows.delete`,{slug:e});if(!t.ok)throw Error(t.error||`failed`);B(`/workflows`,{replace:!0})}catch(e){o(e.message),n(!1)}finally{i(!1)}};return(0,F.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,F.jsx)(`div`,{className:`flex flex-wrap items-center gap-2`,children:t?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(V,{variant:`danger`,icon:`delete`,busy:r,onClick:()=>void s(),children:`confirm delete`}),(0,F.jsx)(V,{variant:`quiet`,onClick:()=>n(!1),children:`cancel`}),(0,F.jsx)(G,{children:`its runs stay; the trash can put it back`})]}):(0,F.jsx)(V,{variant:`danger`,icon:`delete`,onClick:()=>n(!0),title:`Move the workflow's folder to the trash`,children:`delete workflow`})}),a&&(0,F.jsx)(q,{tone:`bad`,children:a})]})}function Pc({runs:e}){return e.length===0?(0,F.jsx)(K,{children:`no runs of this workflow yet`}):(0,F.jsx)(`div`,{className:`flex flex-col gap-2`,children:e.map(e=>{let t=e.phasesTotal??0,n=t>0?Math.round(e.phasesDone/t*100):e.status===`ok`?100:0;return(0,F.jsxs)(he,{href:`/runs/${e.id}`,className:`run-card grid grid-cols-[12px_200px_1fr_auto] items-center gap-x-4 gap-y-2 rounded-card border border-line bg-surface px-5 py-3.5 text-inherit no-underline transition-colors hover:bg-surface-2 max-[900px]:grid-cols-[12px_1fr]`,children:[(0,F.jsx)(U,{tone:Us(e.status),title:e.status}),(0,F.jsx)(`span`,{className:`font-mono text-[12.5px] text-fg-2`,children:e.id.replace(/^run-/,``)}),(0,F.jsx)(`span`,{className:`min-w-0 truncate text-fg`,title:e.request,children:e.status===`running`&&e.currentPhase?e.currentPhase:e.request??``}),(0,F.jsxs)(`span`,{className:`flex items-center gap-3.5 font-mono text-xs tabular-nums text-fg-2 max-[900px]:col-span-2`,children:[e.awaitingDecision&&(0,F.jsx)(Gs,{}),(0,F.jsx)(Ws,{status:e.status}),(0,F.jsx)(`span`,{className:`h-1 w-[90px] overflow-hidden rounded-full bg-surface-2`,title:`${e.phasesDone}${t?` / ${t}`:``} steps`,children:(0,F.jsx)(`i`,{className:P(`block h-full rounded-full`,e.status===`ok`?`bg-ok`:e.status===`failed`?`bg-bad`:`bg-accent`),style:{width:`${n}%`}})}),(0,F.jsx)(`span`,{children:e.status===`running`?(0,F.jsx)(Ke,{since:e.startedAt}):Be(e.durationMs)}),(0,F.jsx)(`span`,{children:Ve(e.costUsd)}),(0,F.jsx)(`span`,{children:We(e.startedAt)})]})]},e.id)})})}var Fc=`border-line/55`;function Ic({a:e,idx:t}){return(0,F.jsxs)(`div`,{className:P(`agent-card border-r border-b px-[18px] py-3.5`,Fc),children:[(0,F.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,F.jsx)(`span`,{className:`size-2.5 rounded-full`,style:{background:Tc(t)}}),(0,F.jsx)(`b`,{className:`text-base font-medium text-fg`,children:e.name??e.id}),(0,F.jsxs)(`code`,{className:`text-2xs text-fg-2`,children:[`[`,e.id,`]`]}),(0,F.jsx)(`span`,{className:`flex-1`}),(0,F.jsxs)(W,{children:[e.model??`default`,e.effort?` · ${e.effort}`:``,e.protocol===`acp`?` · acp`:``]})]}),e.tools.length>0&&(0,F.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-[5px]`,children:e.tools.map(e=>(0,F.jsx)(`span`,{className:`rounded-md bg-surface-2 px-2 py-px font-mono text-2xs text-fg-2`,children:e},e))}),e.persona&&(0,F.jsx)(`p`,{className:`mt-2 mb-0 text-xs leading-[1.55] whitespace-pre-wrap text-fg-2`,children:e.persona})]})}function Lc({s:e,i:t,idx:n}){let r=e.kind===`script`?e.script:e.prompt;return(0,F.jsxs)(`div`,{className:P(`step-node flex gap-3.5 px-[18px] py-3 first:before:top-[18px] last:before:h-[18px] before:left-[31px]`,ec),children:[(0,F.jsx)(Ec,{colour:Tc(n),children:t+1}),(0,F.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,F.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-2.5`,children:[(0,F.jsx)(`span`,{className:`text-base font-medium text-fg`,children:e.name}),e.kind===`agent`?(0,F.jsxs)(`span`,{className:`inline-flex h-5 items-center rounded-full border px-2 text-2xs font-semibold`,style:{color:Tc(n??0),borderColor:`color-mix(in srgb, ${Tc(n??0)} 50%, var(--line))`},children:[`agent · `,e.agent]}):(0,F.jsxs)(W,{children:[`script`,e.sourceRef?` · ${e.sourceRef}`:``]})]}),r&&(0,F.jsxs)(`details`,{className:`mt-1.5`,children:[(0,F.jsx)(`summary`,{className:`cursor-pointer text-xs font-medium text-fg-2 select-none hover:text-accent`,children:e.kind===`agent`?`prompt`:`script`}),(0,F.jsx)(`pre`,{className:`mt-1.5 max-h-[360px] overflow-auto rounded-xl bg-surface-2 px-3 py-2.5 text-[11.5px] leading-[1.55] break-words whitespace-pre-wrap text-fg-2`,children:r})]}),e.gates.length>0&&(0,F.jsx)(`div`,{className:`mt-[5px] flex flex-wrap gap-1.5`,children:e.gates.map(e=>(0,F.jsxs)(`span`,{className:`inline-flex items-center gap-[5px] rounded-lg bg-surface-2 px-2.5 py-0.5 font-mono text-2xs text-fg-2`,children:[`⛨ `,e]},e))})]})]})}function Rc(e,t){let n=e.filter(e=>e.workflow===(t.name??t.slug));return{count:n.length,last:n[0]}}function zc(e,t){return`/runs/${e.id}?workflow=${encodeURIComponent(t.name??t.slug)}`}function Bc({slug:e,tab:t}){let n=N(`workflows.list`,{}),r=N(`runs.list`,{}),[i,a]=(0,v.useState)(``),o=(0,v.useMemo)(()=>n?.workflows??[],[n]),s=r?.runs??[],c=(0,v.useMemo)(()=>{let e=i.trim().toLowerCase();return e?o.filter(t=>[t.name,t.slug,t.description].some(t=>t?.toLowerCase().includes(e))):o},[o,i]),l=(0,v.useMemo)(()=>{if(o.length!==0)return(o.map(e=>({w:e,last:Rc(s,e).last})).filter(e=>!!e.last).sort((e,t)=>(t.last.updatedAt??``).localeCompare(e.last.updatedAt??``))[0]?.w??o[0]).slug},[o,s]),u=!!r;return(0,v.useEffect)(()=>{!e&&l&&u&&B(`/workflows/${encodeURIComponent(l)}`,{replace:!0})},[e,l,u]),(0,F.jsxs)(`div`,{className:`runs-screen workflows-screen`,children:[(0,F.jsxs)(`aside`,{className:`runs-side`,children:[(0,F.jsx)(wt,{title:`workflows`,count:n?o.length:void 0,action:(0,F.jsxs)(V,{size:`sm`,variant:`quiet`,icon:`history`,href:`/runs`,title:`every run of every workflow, newest first`,children:[`runs `,(0,F.jsx)(`span`,{className:`tabular-nums`,children:s.length})]})}),o.length>0&&(0,F.jsx)(Tt,{icon:`search`,value:i,placeholder:`search workflows`,"aria-label":`search workflows`,onChange:e=>a(e.target.value)}),(0,F.jsxs)(Et,{children:[c.map(t=>{let n=Rc(s,t);return(0,F.jsx)(Y,{className:`wf-row`,href:`/workflows/${encodeURIComponent(t.slug)}`,active:t.slug===e,leading:(0,F.jsx)(U,{tone:Us(n.last?.status),title:n.last?.status??`no runs yet`}),title:t.name??t.slug,titleExtra:t.error&&(0,F.jsx)(W,{tone:`bad`,children:`broken`}),meta:n.last&&Ge(n.last.updatedAt),sub:(0,F.jsx)(`span`,{title:t.error??t.description??``,children:t.error??t.description??`${t.agents} agents · ${t.steps} steps`}),subTone:t.error?`bad`:`plain`,actionsAlways:!0,actions:n.last?(0,F.jsxs)(`button`,{type:`button`,className:`wf-runs inline-flex cursor-pointer items-center gap-1 rounded-control border-0 bg-transparent px-1.5 py-0.5 text-2xs tabular-nums text-fg-2 transition-colors hover:bg-surface-2 hover:text-fg`,title:`show the runs of this workflow`,onClick:()=>B(zc(n.last,t)),children:[n.count,` `,n.count===1?`run`:`runs`,` · `,(0,F.jsx)(Ws,{status:n.last.status})]}):(0,F.jsx)(`span`,{className:`wf-runs px-1.5 text-2xs text-fg-2 opacity-80`,children:`no runs yet`})},t.slug)}),n&&o.length>0&&c.length===0&&(0,F.jsxs)(Dt,{className:`wf-nomatch`,children:[`no workflow matches “`,i,`”`]}),n&&o.length===0&&(0,F.jsx)(Dt,{children:`no workflows yet`})]})]}),(0,F.jsx)(`div`,{className:`runs-main`,children:e?(0,F.jsx)(jc,{slug:e,tab:t},e):n&&o.length===0?(0,F.jsxs)(K,{icon:`account_tree`,children:[`No workflows found — expected `,(0,F.jsx)(`code`,{children:`src/workflows/`}),` or `,(0,F.jsx)(`code`,{children:`workflows/`}),` next to the output folder.`]}):(0,F.jsx)(K,{children:`loading…`})})]})}var Vc=e=>e===`ok`?`ok`:e===`running`?`running`:e===`aborted`?`aborted`:`failed`,Hc=e=>e===`ok`?`done`:e===`running`?`working`:e===`aborted`?`stopped`:`failed`;function Uc(e){return e.scope.kind===`channel`?`/channels/${e.scope.slug}`:e.scope.kind===`project`?`/projects/${e.scope.slug}/chat/${e.id}`:e.scope.kind===`agent`?`/agents/${e.scope.slug}/chat/${e.id}`:`/agents/chats/${e.id}`}function Wc(e,t,n){switch(e.scope.kind){case`agent`:{let r=e.scope.slug,i=t.find(e=>e.slug===r),a=i?`${i.emoji||`🤖`} ${i.name}`:r;return e.project?`📁 ${n(e.project)} · ${a}`:a}case`project`:return`📁 ${n(e.scope.slug)}`;case`channel`:return e.project?`📁 ${n(e.project)} · #${e.scope.slug}`:`#${e.scope.slug}`;case`run`:return`⚙️ run ${e.scope.runId}`;case`knowledge`:return e.scope.bundle?`📚 ${e.scope.bundle}`:`📚 knowledge`;default:return`🎩 Ralv`}}function Gc(e){return e.length>64?`${e.slice(0,46)}…${e.slice(-14)}`:e}function Kc(){let e=N(`runs.list`,{}),t=N(`chats.list`,{}),n=N(`knowledge.list`,{}),r=N(`agents.list`,{}),i=N(`workflows.list`,{}),a=N(`skills.list`,{}),[o,s]=(0,v.useState)(`all`),c=be(),l=N(`projects.list`,{},{interval:3e4}),u=e=>l?.projects.find(t=>t.slug===e)?.title??e,d=e?.runs??[],f=t?.chats??[],p=n?.bundles??[],m=(a?.skills??[]).filter(e=>e.source===`workspace`),h=[[i?.workflows.length,`workflows`,`/workflows`],[e?d.length:void 0,`runs`,`/runs`],[n?p.length:void 0,`bundles`,`/knowledge`],[a?m.length:void 0,`skills`,`/skills`],[t?f.length:void 0,`chats`,`/agents/chats`]],g=d.filter(e=>e.status===`failed`&&Date.now()-Date.parse(e.updatedAt)<864e5);return(0,F.jsxs)(`div`,{className:`w-full px-7 pt-6 pb-10 max-[800px]:px-3 max-[800px]:pt-3`,children:[(0,F.jsx)(el,{runs:d,chats:f,bundles:p,agents:r?.agents??[],workflows:i?.workflows??[],projectTitle:u,loaded:!!e&&!!t}),c&&(0,F.jsx)(`div`,{className:`mx-0.5 mt-3.5 mb-3 flex flex-wrap justify-end gap-x-[18px] gap-y-1 text-xs text-fg-2 max-[800px]:justify-start max-[800px]:gap-x-3.5`,children:h.map(([e,t,n])=>(0,F.jsxs)(he,{href:n,className:`group/mini text-inherit no-underline hover:text-accent hover:underline`,children:[(0,F.jsx)(`b`,{className:`font-semibold tabular-nums text-fg group-hover/mini:text-accent`,children:e??`…`}),` `,t]},t))}),c&&g.length>0&&o!==`failed`&&(0,F.jsxs)(`button`,{type:`button`,className:`mb-3.5 flex w-full cursor-pointer items-center gap-2 rounded-xl border border-bad/40 bg-bad-soft px-3.5 py-[9px] text-left text-[12.5px] text-on-bad-soft hover:brightness-104`,onClick:()=>s(`failed`),children:[`⚠ `,g.length,` run`,g.length===1?``:`s`,` failed in the last 24 h — review`]}),c&&(0,F.jsx)(Yc,{projectTitle:u,runs:d,chats:f,bundles:p,agents:r?.agents??[],workflows:i?.workflows??[],filter:o,setFilter:s})]})}function qc(e){if(e.lamp===`running`)return`now`;let t=new Date(e.at),n=new Date;if(t.toDateString()===n.toDateString())return`today`;let r=new Date(n);return r.setDate(r.getDate()-1),t.toDateString()===r.toDateString()?`yesterday`:`earlier`}var Jc=[[`all`,`all`],[`run`,`runs`],[`session`,`chats`],[`knowledge`,`knowledge`]];function Yc({projectTitle:e,runs:t,chats:n,bundles:r,agents:i,workflows:a,filter:o,setFilter:s}){let c=be(),l=(0,v.useMemo)(()=>{let s=[],l=e=>e?a.find(t=>t.slug===e)?.name??e:void 0;for(let e of t)s.push({at:e.updatedAt,kind:`run`,emoji:`⚙️`,title:l(e.workflow)??e.id,sub:e.request??``,href:`/runs/${e.id}`,lamp:Vc(e.status),status:Hc(e.status)});for(let t of n){let n=t.scope.kind===`agent`?i.find(e=>t.scope.kind===`agent`&&e.slug===t.scope.slug):void 0;s.push({at:t.updatedAt,kind:`session`,emoji:n?n.emoji||`🤖`:`💬`,title:n?n.name:t.title||`new chat`,sub:n?`${t.title||`new chat`}${c?` · ${t.agent}`:``}`:c?`${t.agent} · ${Wc(t,i,e)}`:Wc(t,i,e),href:Uc(t),lamp:t.awaitingApproval?`blocked`:t.busy?`running`:`ok`,status:t.awaitingApproval?`needs approval`:t.busy?`working`:void 0})}for(let e of r)e.updatedAt&&s.push({at:e.updatedAt,kind:`knowledge`,emoji:`📚`,title:e.name,sub:`${e.concepts} concepts`,href:`/knowledge/${encodeURIComponent(e.name)}`,lamp:`ok`});return(o===`all`?s:o===`failed`?s.filter(e=>e.kind===`run`&&e.lamp===`failed`):s.filter(e=>e.kind===o)).sort((e,t)=>{let n=Number(t.lamp===`running`)-Number(e.lamp===`running`);return n===0?t.at.localeCompare(e.at):n}).slice(0,15)},[t,n,r,i,c,o]),u=``,d=(e,t)=>P(`inline-flex cursor-pointer items-center gap-0.5 rounded-lg border px-2.5 py-0.5 text-2xs transition-colors`,e?P(`border-transparent`,t?`bg-bad-soft text-on-bad-soft`:`bg-accent-soft text-on-accent-soft`):`border-line bg-transparent text-fg-2 hover:text-fg`);return(0,F.jsx)(J,{className:`animate-rise`,title:`all activity`,actions:(0,F.jsxs)(`span`,{className:`flex flex-wrap gap-1.5`,children:[Jc.map(([e,t])=>(0,F.jsx)(`button`,{type:`button`,className:d(o===e),"aria-pressed":o===e,onClick:()=>s(e),children:t},e)),o===`failed`&&(0,F.jsxs)(`button`,{type:`button`,className:d(!0,!0),onClick:()=>s(`all`),children:[`failed `,(0,F.jsx)(I,{name:`close`,className:`ms-sm`})]})]}),children:l.length===0?(0,F.jsx)(`div`,{className:`px-[18px] py-4 text-sm text-fg-2`,children:o===`all`?`nothing yet — run a workflow or start a chat`:`nothing here for this filter`}):(0,F.jsx)(`div`,{className:`flex flex-col p-1.5`,children:l.map(e=>{let t=qc(e),n=t===u?null:t;return u=t,(0,F.jsxs)(`div`,{children:[n&&(0,F.jsx)(et,{className:`block px-2.5 pt-3 pb-1`,children:n}),(0,F.jsx)(Y,{href:e.href,leading:(0,F.jsxs)(`span`,{className:`relative text-[18px] leading-none`,children:[(0,F.jsx)(`span`,{"aria-hidden":!0,children:e.emoji}),e.lamp===`running`&&(0,F.jsx)(`span`,{className:`absolute -right-1 -bottom-1 grid rounded-full bg-surface p-px`,children:(0,F.jsx)(U,{tone:`working`})})]}),title:Gc(e.title),titleExtra:(0,F.jsx)(`span`,{className:`max-[800px]:hidden`,children:(0,F.jsx)(W,{tone:Xc[e.kind],children:e.kind===`session`?`chat`:e.kind})}),sub:e.sub&&Gc(e.sub),meta:(0,F.jsxs)(`span`,{className:`flex items-center gap-2`,children:[e.status&&(0,F.jsx)(W,{tone:Zc[e.lamp]??`neutral`,children:e.status}),(0,F.jsx)(`span`,{title:new Date(e.at).toLocaleString(),children:Ge(e.at)}),(0,F.jsx)(I,{name:`chevron_right`,className:`ms-sm max-[800px]:hidden`})]})})]},`${e.kind}:${e.href}:${e.at}`)})})})}var Xc={run:`accent`,session:`ask`,knowledge:`ok`},Zc={ok:`ok`,failed:`bad`,blocked:`bad`,running:`accent`,aborted:`neutral`};function Qc(e){if(!e)return``;let t=Math.max(0,Math.round((Date.now()-Date.parse(e))/6e4));return t<1?`just started`:t<60?`${t} min`:`${Math.floor(t/60)} h ${t%60} min`}var $c=e=>new Date(e).toDateString()===new Date().toDateString();function el({runs:e,chats:t,bundles:n,agents:r,workflows:i,projectTitle:a,loaded:o}){let s=Ft()??[],c=L(),l=N(`agents.status`,{},{interval:5e3}),u=e=>e?i.find(t=>t.slug===e)?.name??e:`workflow`,d=new Map;for(let e of Object.values(l??{}))for(let t of e.working)t.since&&d.set(t.chatId,t.since);let f=[...t.filter(e=>e.busy&&!e.awaitingApproval).map(e=>({key:`c:${e.id}`,owner:Wc(e,r,a),title:Gc(e.title||`new chat`),meta:`working${d.get(e.id)?` · ${Qc(d.get(e.id))}`:``}`,href:Uc(e),tone:`working`})),...e.filter(e=>e.status===`running`).map(e=>({key:`r:${e.id}`,owner:`⚙️ ${u(e.workflow)}`,title:Gc(e.request??``),meta:`running`,href:`/runs/${e.id}`,tone:`working`}))],p=[...t.filter(e=>!e.busy&&!e.awaitingApproval&&$c(e.updatedAt)&&e.title).map(e=>({key:`c:${e.id}`,at:e.updatedAt,owner:Wc(e,r,a),title:Gc(e.title),meta:Ge(e.updatedAt),href:Uc(e)})),...e.filter(e=>e.status!==`running`&&$c(e.updatedAt)).map(e=>({key:`r:${e.id}`,at:e.updatedAt,owner:`⚙️ ${u(e.workflow)}`,title:Gc(e.request??``),meta:`${e.status===`ok`?`done`:e.status===`aborted`?`stopped`:`failed`} · ${Ge(e.updatedAt)}`,href:`/runs/${e.id}`})),...n.filter(e=>e.updatedAt&&$c(e.updatedAt)).map(e=>({key:`k:${e.name}`,at:e.updatedAt,owner:`📚 ${e.name}`,title:`knowledge updated`,meta:Ge(e.updatedAt),href:`/knowledge/${encodeURIComponent(e.name)}`}))].sort((e,t)=>t.at.localeCompare(e.at)).slice(0,12),m=Bt(s,c),h=o&&s.length===0&&f.length===0;return(0,F.jsxs)(`div`,{className:`today flex flex-col gap-3.5`,children:[(0,F.jsxs)(J,{className:`today-section`,title:`needs you`,count:s.length,actions:m&&(0,F.jsxs)(V,{variant:`primary`,size:`sm`,onClick:()=>Vt(m),className:`bg-bad text-on-bad hover:bg-bad`,children:[`start `,(0,F.jsx)(I,{name:`arrow_forward`,className:`ms-sm`})]}),children:[s.length===0?(0,F.jsx)(`p`,{className:`m-0 px-[18px] py-4 text-sm text-fg-2`,children:h?`Nothing waiting, nothing running.`:`Nothing is waiting for you.`}):(0,F.jsx)(`div`,{className:`p-1.5`,children:s.map(e=>(0,F.jsx)(Y,{className:`today-row waiting`,onClick:()=>Vt(e),over:Lt(e.owner),title:e.title,meta:(0,F.jsxs)(`span`,{className:`font-semibold text-bad`,children:[e.kind===`approval`?`needs approval`:e.kind===`question`?`asks you`:`failed`,` · `,Ge(e.since)]})},e.id))}),h&&(0,F.jsx)(`div`,{className:`px-[18px] pb-4`,children:(0,F.jsx)(V,{variant:`primary`,icon:`chat`,href:`/agents/chats`,children:`chat with Ralv`})})]}),f.length>0&&(0,F.jsx)(J,{className:`today-section`,title:`in progress`,children:(0,F.jsx)(`div`,{className:`p-1.5`,children:f.map(e=>(0,F.jsx)(tl,{r:e},e.key))})}),(0,F.jsx)(J,{className:`today-section`,title:`done today`,children:p.length===0?(0,F.jsx)(`p`,{className:`m-0 px-[18px] py-4 text-sm text-fg-2`,children:`Nothing finished yet today.`}):(0,F.jsx)(`div`,{className:`p-1.5`,children:p.map(e=>(0,F.jsx)(tl,{r:e},e.key))})})]})}function tl({r:e}){return(0,F.jsx)(Y,{className:`today-row`,href:e.href,over:e.owner,title:e.title,meta:(0,F.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[e.tone===`working`&&(0,F.jsx)(U,{tone:`working`}),e.meta]})})}var nl=`modulepreload`,rl=function(e){return`/`+e},il={},al=function(e){return e.pathname.endsWith(`.css`)},ol=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e,i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?new URL(import.meta.resolve(e)):new URL(e,import.meta.url)}r=o(t.map(t=>{t=rl(t,n);let r=s(t);if(r.href in il)return;il[r.href]=!0;let i=al(r);if(e===void 0){e={all:new Set,styles:new Set};let t=document.getElementsByTagName(`link`);for(let n=t.length-1;n>=0;n--){let r=t[n];e.all.add(r.href),r.rel===`stylesheet`&&e.styles.add(r.href)}}if((i?e.styles:e.all).has(r.href))return;let o=document.createElement(`link`);if(o.rel=i?`stylesheet`:nl,i||(o.as=`script`),o.crossOrigin=``,o.href=r.href,a&&o.setAttribute(`nonce`,a),document.head.appendChild(o),i)return new Promise((e,t)=>{o.addEventListener(`load`,e),o.addEventListener(`error`,()=>t(Error(`Unable to preload CSS for ${r}`)))})}).filter(e=>e!==void 0))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},sl=(0,v.lazy)(()=>ol(()=>import(`./editor-DEb8z5-Q.js`).then(e=>({default:e.DocEditor})),__vite__mapDeps([0,1,2,3,4,5,6]))),cl=()=>ol(()=>import(`./editor-DEb8z5-Q.js`),__vite__mapDeps([0,1,2,3,4,5,6]));function ll({bundle:e,conceptId:t}){let n=N(`knowledge.list`,{}),[r,i]=(0,v.useState)([]);(0,v.useEffect)(()=>{n&&i(e=>e.filter(e=>n.bundles.some(t=>t.name===e)))},[n]);let a=(n?.bundles??[]).filter(e=>!r.includes(e.name)),o=e===`new`,s=a.reduce((e,t)=>!e||(t.updatedAt??``)>(e.updatedAt??``)?t:e,void 0);return(0,v.useEffect)(()=>{!e&&s&&B(`/knowledge/${encodeURIComponent(s.name)}`,{replace:!0})},[e,s?.name]),(0,F.jsxs)(`div`,{className:`runs-screen`,children:[(0,F.jsxs)(`aside`,{className:`runs-side`,children:[(0,F.jsx)(wt,{title:`bundles`,action:(0,F.jsx)(V,{size:`sm`,variant:`quiet`,icon:`add`,href:`/knowledge/new`,children:`new`})}),(0,F.jsxs)(Et,{children:[a.map(t=>(0,F.jsx)(Y,{href:`/knowledge/${encodeURIComponent(t.name)}`,active:t.name===e,size:`sm`,leading:(0,F.jsx)(U,{tone:`ok`}),title:t.name,meta:t.concepts,sub:`${t.okfVersion?`okf ${t.okfVersion}`:`okf`}${t.updatedAt?` · ${t.updatedAt.slice(0,10)}`:``}`},t.name)),n&&a.length===0&&(0,F.jsx)(Dt,{children:`no bundles yet`})]})]}),(0,F.jsx)(`div`,{className:`runs-main`,children:e&&!o?(0,F.jsx)(gl,{name:e,conceptId:t,onRemoved:()=>{i(t=>[...t,e]),B(`/knowledge`,{replace:!0})}},e):o||n&&!s?(0,F.jsx)(ul,{}):(0,F.jsx)(K,{children:`loading…`})})]})}function ul(){let[e,t]=(0,v.useState)(``),[n,r]=(0,v.useState)(``),[i,a]=(0,v.useState)(!1);async function o(){let t=e.trim();if(!t)return;a(!0),r(``);let n=await A.request(`knowledge.create`,{body:{name:t}});a(!1),n.ok?B(`/knowledge/${encodeURIComponent(t)}`):r(M(n))}return(0,F.jsxs)(`div`,{className:`empty-action flex flex-col items-center gap-3 px-4 py-16`,children:[(0,F.jsxs)(`div`,{className:`flex w-full max-w-[520px] gap-2.5`,children:[(0,F.jsx)(X,{className:`flex-1 font-mono text-sm`,value:e,placeholder:`bundle name, e.g. customer-support`,"aria-label":`bundle name`,onChange:e=>t(e.target.value),onKeyDown:e=>e.key===`Enter`&&void o(),autoFocus:!0}),(0,F.jsx)(V,{variant:`primary`,icon:`add`,busy:i,disabled:!e.trim(),onClick:o,children:i?`creating…`:`new bundle`})]}),n&&(0,F.jsx)(q,{tone:`bad`,children:n})]})}function dl({tier:e}){return(0,F.jsx)(W,{tone:e===`human-reviewed`?`ok`:e===`machine-confirmed`?`accent`:`neutral`,children:e})}var fl=e=>e===`deprecated`||e===`stale`?`bad`:e===`draft`?`accent`:`neutral`,pl=()=>(0,v.useContext)(me)!==null,ml=`m-0 max-h-[560px] overflow-auto px-[18px] py-3.5 font-mono text-xs leading-[1.55] break-words whitespace-pre-wrap text-fg-2`,hl=`@activity`;function gl({name:e,conceptId:t,onRemoved:n}){let r=N(`knowledge.get`,{bundle:e}),i=pl(),[a,o]=(0,v.useState)(!1),[s,c]=(0,v.useState)(``);async function l(){let t=await A.request(`knowledge.delete`,{bundle:e}).catch(()=>null);if(!t?.ok){c(t?.error??`delete failed`),o(!1);return}n?n():B(`/knowledge`,{replace:!0})}if(!r)return(0,F.jsx)(K,{children:`loading…`});if(`error`in r)return(0,F.jsx)(K,{icon:`menu_book`,children:`bundle not found`});let u=t===hl?`activity`:`pages`,d=r.concepts,f=u===`pages`?t&&d.some(e=>e.id===t)?t:d[0]?.id:void 0,p=`/knowledge/${encodeURIComponent(e)}`;return(0,F.jsxs)(`div`,{className:P(`agent-view @container flex flex-col`,i?`gap-2.5`:`gap-4`),children:[(0,F.jsxs)(`div`,{className:P(`flex flex-wrap items-center gap-x-4 gap-y-2`,i?`mb-0.5`:`mx-0.5 mt-1 mb-2`),children:[(0,F.jsx)(nt,{size:i?`md`:`lg`,children:e}),(0,F.jsxs)(`span`,{className:P(`text-fg-2`,i?`text-[12.5px]`:`text-base`),children:[d.length,` pages`]}),(0,F.jsx)(ft,{bare:!0,className:`self-end`,label:`bundle views`,value:u,items:[{id:`pages`,href:p,label:`pages`},{id:`activity`,href:`${p}/${hl}`,label:`activity`}]}),(0,F.jsx)(`span`,{className:`flex-1`}),!i&&(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(V,{size:`sm`,variant:`quiet`,icon:`picture_as_pdf`,onClick:()=>void ss(e),children:`export PDF`}),a?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(V,{size:`sm`,variant:`danger`,icon:`delete`,onClick:()=>void l(),children:`move to trash`}),(0,F.jsx)(V,{size:`sm`,variant:`quiet`,onClick:()=>o(!1),children:`cancel`})]}):(0,F.jsx)(V,{size:`sm`,variant:`quiet`,icon:`delete`,onClick:()=>o(!0),title:`Move the bundle to the trash`,children:`delete`}),(0,F.jsx)(V,{variant:`primary`,onClick:()=>void Fo(`claude`,{kind:`knowledge`,bundle:e}),children:`curate in chat`})]})]}),s&&(0,F.jsx)(q,{tone:`bad`,children:s}),u===`activity`?r.log?(0,F.jsx)(yl,{name:e,log:r.log}):(0,F.jsx)(J,{children:(0,F.jsx)(`p`,{className:`m-0 px-[18px] py-3 text-sm text-fg-2`,children:`no activity yet`})}):d.length===0?(0,F.jsx)(J,{children:(0,F.jsxs)(`p`,{className:`m-0 px-[18px] py-3 text-sm text-fg-2`,children:[`No pages yet — start a chat to author some, or write one with`,` `,(0,F.jsxs)(`code`,{children:[`kraftwerk knowledge put `,e,`/<path>`]}),`.`]})}):(0,F.jsxs)(`div`,{className:P(`grid items-start`,i?`grid-cols-[170px_minmax(0,1fr)] gap-3.5 @max-[560px]:grid-cols-1`:`grid-cols-[260px_minmax(0,1fr)] gap-6 max-[1100px]:grid-cols-1`),children:[(0,F.jsx)(`aside`,{className:P(`flex flex-col gap-0.5 overflow-y-auto border-r border-line`,i?`sticky top-0 max-h-[calc(100vh-var(--topbar-h)-160px)] pr-2 pb-1.5 @max-[560px]:static @max-[560px]:max-h-[200px] @max-[560px]:border-r-0 @max-[560px]:pr-0`:`sticky top-[calc(var(--topbar-h)+18px)] max-h-[calc(100vh-var(--topbar-h)-36px)] py-1.5 pr-3 max-[1100px]:static max-[1100px]:max-h-none max-[1100px]:border-r-0 max-[1100px]:pr-0`),children:(0,F.jsx)(xl,{concepts:d,base:p,selected:f})}),(0,F.jsx)(`div`,{className:`min-w-0`,children:f&&(0,F.jsx)(Cl,{bundle:e,conceptId:f},f)})]})]})}function _l(e){let t=[];for(let n of e.split(`
216
+ `)){let e=n.match(/^##\s+(\d{4}-\d{2}-\d{2})/);if(e){t.push({date:e[1],entries:[]});continue}let r=n.match(/^[*-]\s+\*\*([^*]+)\*\*:\s*(.*)$/);r&&t.length>0&&t[t.length-1].entries.push({kind:r[1].toLowerCase(),text:r[2]})}return t.filter(e=>e.entries.length>0)}function vl(e,t){let n=[],r=/\[([^\]]+)\]\(\/?([^)]+?)\.md\)/g,i=0,a;for(;a=r.exec(t);)a.index>i&&n.push(t.slice(i,a.index)),n.push((0,F.jsx)(he,{href:`/knowledge/${encodeURIComponent(e)}/${a[2].replace(/^\//,``)}`,children:a[1]},a.index)),i=a.index+a[0].length;return i<t.length&&n.push(t.slice(i)),n}function yl({name:e,log:t}){let n=_l(t),[r,i]=(0,v.useState)(!1);return(0,F.jsx)(J,{title:`activity`,actions:(0,F.jsx)(V,{size:`sm`,variant:`quiet`,onClick:()=>i(!r),children:r?`timeline`:`raw log`}),children:r||n.length===0?(0,F.jsx)(`pre`,{className:ml,children:t}):(0,F.jsx)(`div`,{className:`pt-0.5 pb-2.5`,children:n.map((t,n)=>(0,F.jsxs)(v.Fragment,{children:[(0,F.jsx)(`div`,{className:P(`px-[18px] pt-3.5 pb-1 font-mono text-2xs tracking-[0.05em] text-fg-2 tabular-nums`,n>0&&`mt-1 border-t border-line`),children:t.date}),t.entries.map((t,n)=>(0,F.jsxs)(`div`,{className:`flex items-baseline gap-2.5 px-[18px] py-1`,children:[(0,F.jsx)(W,{tone:t.kind===`verification`?`ok`:t.kind===`creation`||t.kind===`initialization`?`accent`:`neutral`,children:t.kind}),(0,F.jsx)(`span`,{className:`min-w-0 text-[12.5px] leading-[1.55] break-words text-fg-2 [&_a]:text-accent`,children:vl(e,t.text)})]},n))]},t.date))})})}function bl(e){let t={name:``,path:``,folders:[],pages:[],total:0};for(let n of e){let e=n.id.split(`/`),r=t;r.total++;for(let t of e.slice(0,-1)){let e=r.folders.find(e=>e.name===t);e||(e={name:t,path:r.path?`${r.path}/${t}`:t,folders:[],pages:[],total:0},r.folders.push(e)),r=e,r.total++}r.pages.push(n)}let n=e=>{e.folders.sort((e,t)=>e.name.localeCompare(t.name)),e.pages.sort((e,t)=>e.title.localeCompare(t.title)),e.folders.forEach(n)};return n(t),t}function xl({concepts:e,base:t,selected:n}){let r=(0,v.useMemo)(()=>bl(e),[e]),[i,a]=(0,v.useState)(()=>new Set);(0,v.useEffect)(()=>{n&&n.includes(`/`)&&a(e=>{let t=new Set(e),r=n.split(`/`).slice(0,-1);for(let e=1;e<=r.length;e++)t.delete(r.slice(0,e).join(`/`));return t.size===e.size?e:t})},[n]);let o=e=>a(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),s=pl();return(0,F.jsx)(Sl,{folder:r,base:t,selected:n,closed:i,toggle:o,embedded:s})}function Sl({folder:e,base:t,selected:n,closed:r,toggle:i,embedded:a}){return(0,F.jsxs)(F.Fragment,{children:[e.pages.map(e=>{let r=e.id===n;return(0,F.jsxs)(he,{href:`${t}/${e.id}`,"aria-current":r?`page`:void 0,className:P(`wiki-page flex items-center gap-2 rounded-control px-2.5 py-1.5 leading-[1.35] no-underline transition-colors`,a?`text-[12.5px]`:`text-sm`,r?`active bg-accent-soft font-medium text-on-accent-soft`:`text-fg hover:bg-surface-2`),title:`${e.id}.md`,children:[(0,F.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.title}),(e.stale||e.error)&&(0,F.jsx)(`span`,{className:`size-1.5 flex-none rounded-full bg-bad`,title:e.error??`stale`})]},e.id)}),e.folders.map(e=>{let o=!r.has(e.path),s=!!n&&n.startsWith(`${e.path}/`)&&!o;return(0,F.jsxs)(v.Fragment,{children:[(0,F.jsxs)(`button`,{type:`button`,className:P(`wiki-folder mt-2.5 mb-0.5 flex w-full cursor-pointer items-center gap-1 rounded-control border-0 bg-transparent py-1 pr-2 pl-0.5 text-left`,`font-[inherit] text-2xs leading-[1.3] font-semibold tracking-[0.06em] uppercase transition-colors`,o&&`open`,s?`holds text-accent`:`text-fg-2 hover:text-fg`),onClick:()=>i(e.path),"aria-expanded":o,title:`${e.path}/`,children:[(0,F.jsx)(I,{name:`chevron_right`,className:P(`ms-sm flex-none text-[16px] transition-transform`,o&&`rotate-90`,!s&&`text-fg-2`)}),(0,F.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.name}),(0,F.jsx)(`span`,{className:`text-[10.5px] font-medium tracking-normal text-fg-2 tabular-nums opacity-70`,children:e.total})]}),o&&(0,F.jsx)(`div`,{className:`wiki-branch ml-[9px] flex flex-col gap-0.5 border-l border-line pl-1`,children:(0,F.jsx)(Sl,{folder:e,base:t,selected:n,closed:r,toggle:i,embedded:a})})]},e.path)})]})}function Cl({bundle:e,conceptId:t}){let[n,r]=(0,v.useState)(null),[i,a]=(0,v.useState)(!1),[o,s]=(0,v.useState)(!1),c=pl(),[l,u]=(0,v.useState)(`document`),[d,f]=(0,v.useState)(``),[p,m]=(0,v.useState)(!1),[h,g]=(0,v.useState)(``),[_,y]=(0,v.useState)(null),[b,x]=(0,v.useState)(`saved`),[S,C]=(0,v.useState)(``),w=(0,v.useRef)(``),T=(0,v.useRef)(null),E=(0,v.useRef)(!1),D=(0,v.useRef)(null),O=(0,v.useRef)(null),k=(0,v.useRef)(null),j=()=>{A.call(`knowledge.concept`,{bundle:e,query:{id:t}}).then(r,()=>a(!0))};(0,v.useEffect)(()=>{if(l===`markdown`)return;let n=!0,i,o=async()=>{try{let i=await A.request(`knowledge.concept`,{bundle:e,query:{id:t}});if(i.ok){let e=i.data;n&&(a(!1),r(t=>JSON.stringify(t)===JSON.stringify(e)?t:e))}else i.status===404&&n&&a(!0)}catch{}n&&(i=setTimeout(o,6e3))};return o(),()=>{n=!1,clearTimeout(i)}},[e,t,l]),(0,v.useEffect)(()=>{if(!n||n.raw===T.current||D.current!==null||k.current)return;let e=!0;return cl().then(({splitFrontmatter:t,unwrapParagraphs:r})=>{if(!e)return;let{head:i,body:a}=t(n.raw);w.current=i,T.current=n.raw,E.current=!1,y(e=>({key:(e?.key??0)+1,body:r(a)}))}),()=>{e=!1}},[n]);async function ee(){k.current&&await k.current;let n=D.current;if(n===null)return;D.current=null,x(`saving`);let i=(async()=>{try{let i=w.current,a=i?`${i}${i.endsWith(`
217
217
  `)?``:`
218
218
  `}${n.replace(/^\n+/,`
219
- `)}`:n,o=await A.request(`knowledge.putConcept`,{bundle:e,body:{id:t,content:a},keepalive:!0});if(!o.ok)throw Error(M(o));let s=o.data;if(s.error)throw Error(s.error);w.current=(await sl()).splitFrontmatter(s.raw).head,T.current=s.raw,r(s),C(``),x(D.current===null?`saved`:`unsaved`)}catch(e){C(e.message),x(`error`),D.current===null&&(D.current=n)}})();k.current=i,await i,k.current=null}function N(e){E.current&&(D.current=e,x(`unsaved`),O.current&&clearTimeout(O.current),O.current=setTimeout(()=>void ee(),1e3))}(0,v.useEffect)(()=>{let e=()=>{D.current!==null&&ee()};return window.addEventListener(`beforeunload`,e),window.addEventListener(`pagehide`,e),()=>{window.removeEventListener(`beforeunload`,e),window.removeEventListener(`pagehide`,e),O.current&&clearTimeout(O.current),D.current!==null&&ee()}},[]);async function te(){s(!0),await A.request(`knowledge.verify`,{bundle:e,body:{id:t}}).catch(()=>{}),s(!1),j()}function ne(){n&&(f(n.raw),g(``),u(`markdown`))}async function I(){m(!0),g(``);let n=await A.request(`knowledge.putConcept`,{bundle:e,body:{id:t,content:d}}).catch(()=>null);m(!1),!n?.ok||!n.data||typeof n.data!=`object`?g(n?.error??`save failed`):n.data.error?g(n.data.error):(T.current=null,r(n.data),u(`document`))}if(i)return(0,F.jsx)(K,{icon:`description`,children:`concept not found`});if(!n)return(0,F.jsx)(K,{children:`loading…`});let L=b===`saving`?`saving…`:b===`unsaved`?`unsaved changes`:b===`error`?`not saved — ${S}`:`all changes saved`;return(0,F.jsxs)(`div`,{className:P(`agent-view flex flex-col`,c?`gap-2.5`:`gap-4`),children:[(0,F.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[(0,F.jsx)(nt,{size:c?`md`:`lg`,children:n.title}),n.type&&(0,F.jsx)(W,{children:n.type}),(0,F.jsx)(ul,{tier:n.trustTier}),n.status!==`stable`&&(0,F.jsx)(W,{tone:dl(n.status),children:n.status}),n.stale&&(0,F.jsxs)(W,{tone:`bad`,children:[`stale since `,n.staleAfter?.slice(0,10)]}),(0,F.jsx)(`span`,{className:`flex-1`}),!c&&(0,F.jsx)(V,{size:`sm`,variant:`quiet`,icon:`picture_as_pdf`,onClick:()=>void os(e,n.id),children:`export PDF`}),(0,F.jsx)(V,{variant:`primary`,size:c?`sm`:`md`,icon:`check`,busy:o,onClick:te,children:o?`verifying…`:`verify (human)`})]}),n.error&&(0,F.jsx)(q,{tone:`bad`,children:n.error}),(0,F.jsxs)(`div`,{className:P(`grid items-start`,c?`grid-cols-1 gap-3`:`grid-cols-[minmax(0,1fr)_320px] gap-4 max-[1020px]:grid-cols-1`),children:[(0,F.jsxs)(J,{className:`min-w-0`,title:`content`,actions:(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(`span`,{className:`min-w-0 truncate font-mono text-[10.5px] text-fg-2`,children:[e,`/`,n.id,`.md`]}),l===`markdown`?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(V,{size:`sm`,variant:`quiet`,onClick:()=>{u(`document`),g(``)},children:`cancel`}),(0,F.jsx)(V,{size:`sm`,icon:`check`,busy:p,onClick:()=>void I(),children:p?`saving…`:`save`})]}):(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`span`,{className:P(`text-xs whitespace-nowrap`,b===`error`?`text-bad`:b===`unsaved`||b===`saving`?`text-ask`:`text-fg-2`),children:L}),(0,F.jsx)(V,{size:`sm`,variant:`quiet`,icon:`code`,title:`The whole file as text, frontmatter included`,onClick:ne,children:`edit markdown`})]})]}),children:[l===`markdown`?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`textarea`,{className:`concept-edit block w-full resize-y border-0 border-b border-line bg-surface px-[18px] py-3.5 font-mono text-[12.5px] leading-[1.65] text-fg outline-none`,value:d,rows:Math.min(40,Math.max(18,d.split(`
220
- `).length+2)),onChange:e=>f(e.target.value),spellCheck:!1}),(0,F.jsxs)(G,{className:`border-b border-line px-[18px] py-1.5`,children:[`full file (frontmatter + markdown body) — saving stamps provenance as `,(0,F.jsx)(`code`,{children:`human:user`}),` and logs an update.`]})]}):(0,F.jsxs)(`div`,{className:P(`concept-doc`,c?`[&_.editor-content]:min-h-[220px]`:`[&_.editor-content]:min-h-[280px]`),onPointerDownCapture:()=>E.current=!0,onKeyDownCapture:()=>E.current=!0,onPasteCapture:()=>E.current=!0,onDropCapture:()=>E.current=!0,children:[_?(0,F.jsx)(v.Suspense,{fallback:(0,F.jsx)(G,{className:`border-b border-line px-[18px] py-1.5`,children:`loading the editor…`}),children:(0,F.jsx)(ol,{markdown:_.body,autoFocus:!1,onChange:N,onError:ne},_.key)}):(0,F.jsx)(G,{className:`border-b border-line px-[18px] py-1.5`,children:`loading…`}),(0,F.jsxs)(G,{className:`border-b border-line px-[18px] py-1.5`,children:[`the page as a document, saved as you type; every save stamps provenance as `,(0,F.jsx)(`code`,{children:`human:user`}),` and logs an update.`]})]}),h&&(0,F.jsx)(`div`,{className:`px-3 py-1`,children:(0,F.jsx)(q,{tone:`bad`,children:h})})]}),(0,F.jsxs)(`aside`,{className:P(`flex min-w-0 flex-col`,c?`gap-2.5`:`gap-4`),children:[(0,F.jsx)(J,{title:`about`,children:(0,F.jsxs)(ut,{compact:c,children:[(0,F.jsx)(dt,{label:`trust`,children:(0,F.jsx)(ul,{tier:n.trustTier})}),(0,F.jsx)(dt,{label:`generated`,dim:!n.generated,children:n.generated?`${n.generated.by??`?`} · ${(n.generated.at??`?`).slice(0,10)}`:`not stamped`}),(0,F.jsx)(dt,{label:`verified`,dim:n.verified.length===0,children:n.verified.length===0?`never`:n.verified.map((e,t)=>(0,F.jsxs)(`span`,{className:`block`,children:[e.by??`?`,` · `,(e.at??`?`).slice(0,10)]},t))}),n.staleAfter&&(0,F.jsxs)(dt,{label:`stale after`,dim:!n.stale,children:[n.staleAfter.slice(0,10),n.stale&&(0,F.jsx)(W,{tone:`bad`,children:`stale`})]}),n.tags.length>0&&(0,F.jsx)(dt,{label:`tags`,children:n.tags.map(e=>(0,F.jsx)(W,{children:e},e))})]})}),n.sources.length>0&&(0,F.jsx)(J,{title:`sources`,children:(0,F.jsx)(ut,{compact:c,children:n.sources.map((e,t)=>(0,F.jsxs)(`div`,{className:P(`flex flex-col gap-[3px] break-words`,c?`px-3.5 py-1.5 text-xs`:`px-[18px] py-2.5 text-[12.5px]`),children:[(0,F.jsxs)(`span`,{className:`text-fg [&_a]:text-accent`,children:[e.resource?.startsWith(`http`)?(0,F.jsx)(`a`,{href:e.resource,target:`_blank`,rel:`noreferrer`,children:e.title??e.resource}):e.title??e.resource??`?`,e.id&&(0,F.jsxs)(`span`,{className:`ml-2 font-mono text-2xs text-fg-2`,children:[`[^`,e.id,`]`]})]}),(0,F.jsx)(`span`,{className:`text-fg-2`,children:[e.author,e.usage_count==null?null:`${e.usage_count} uses`,e.last_modified?`mod ${e.last_modified.slice(0,10)}`:null].filter(Boolean).join(` · `)})]},t))})})]})]})]})}var Cl={workspace:`workspace`,project:`.claude`,user:`global`,agent:`agent`};function wl(e){return(0,F.jsx)(W,{tone:e===`workspace`?`ok`:e===`agent`?`accent`:`neutral`,children:Cl[e]})}function Tl({name:e}){let t=N(`skills.list`,{}),n=t?.skills??[],r=n.filter(e=>e.source===`workspace`),i=n.filter(e=>e.source!==`workspace`),a=r[0]??i[0];(0,v.useEffect)(()=>{!e&&a&&B(`/skills/${encodeURIComponent(a.name)}`,{replace:!0})},[e,a?.name]);let o=t=>(0,F.jsx)(Y,{href:`/skills/${encodeURIComponent(t.name)}`,active:t.name===e,size:`sm`,leading:(0,F.jsx)(U,{tone:t.source===`workspace`?`ok`:`idle`}),title:`/${t.name}`,titleExtra:t.source!==`workspace`&&wl(t.source),sub:t.description||`no description`},`${t.source}:${t.name}`);return(0,F.jsxs)(`div`,{className:`runs-screen`,children:[(0,F.jsxs)(`aside`,{className:`runs-side`,children:[(0,F.jsx)(wt,{title:`workspace skills`}),(0,F.jsxs)(Et,{children:[r.map(o),t&&r.length===0&&(0,F.jsx)(Dt,{children:`no workspace skills yet`}),i.length>0&&(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(wt,{title:`local (this machine / repo)`,divided:!0}),i.map(o)]})]})]}),(0,F.jsx)(`div`,{className:`runs-main`,children:e?(0,F.jsx)(Dl,{name:e},e):t&&!a?(0,F.jsx)(El,{root:t.root}):(0,F.jsx)(K,{children:`loading…`})})]})}function El({root:e}){return(0,F.jsx)(`div`,{className:`empty-action py-6`,children:(0,F.jsxs)(K,{icon:`extension`,children:[`Create `,(0,F.jsxs)(`code`,{children:[e,`/<name>/SKILL.md`]}),` and it appears here and in every session's `,(0,F.jsx)(`code`,{children:`/`}),` menu.`]})})}function Dl({name:e}){let[t,n]=(0,v.useState)(null),[r,i]=(0,v.useState)(!1),[a,o]=(0,v.useState)(`rendered`),s=(0,v.useMemo)(()=>t?t.content.replace(/^---\r?\n[\s\S]*?\r?\n---(\r?\n|$)/,``):``,[t?.content]),c=(0,v.useMemo)(()=>t?da.sanitize(Fr.parse(s,{async:!1})):``,[s]);return(0,v.useEffect)(()=>{A.call(`skills.get`,{name:e}).then(n,()=>i(!0))},[e]),r?(0,F.jsx)(K,{icon:`extension`,children:`skill not found`}):t?(0,F.jsxs)(`div`,{className:`agent-view flex flex-col gap-4`,children:[(0,F.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[(0,F.jsxs)(nt,{size:`lg`,children:[`/`,t.name]}),wl(t.source)]}),t.description&&(0,F.jsx)(`p`,{className:`-mt-2 mb-0 mx-0.5 text-sm leading-[1.6] text-fg-2`,children:t.description}),(0,F.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_320px] items-start gap-4 max-[1020px]:grid-cols-1`,children:[(0,F.jsx)(J,{className:`min-w-0`,title:`SKILL.md`,actions:(0,F.jsx)(ft,{bare:!0,label:`SKILL.md view`,value:a,onChange:o,items:[{id:`rendered`,label:`rendered`},{id:`source`,label:`source`}]}),children:a===`rendered`?(0,F.jsx)(`div`,{className:`md-body h-auto overflow-visible [&_a]:text-accent [&_a]:underline [&_a]:underline-offset-2`,dangerouslySetInnerHTML:{__html:c}}):(0,F.jsx)(`pre`,{className:`m-0 max-h-[560px] overflow-auto px-[18px] py-3.5 font-mono text-xs leading-[1.55] break-words whitespace-pre-wrap text-fg-2`,children:t.content.trim()||`(empty)`})}),(0,F.jsx)(`aside`,{className:`flex min-w-0 flex-col gap-4`,children:(0,F.jsx)(J,{title:`about`,children:(0,F.jsxs)(ut,{children:[(0,F.jsx)(dt,{label:`source`,children:t.source===`workspace`?`workspace — git-tracked, shared with the team`:t.source===`project`?`repo .claude/skills — tracked, but outside the workspace root`:`global ~/.claude/skills — only on this machine`}),(0,F.jsx)(dt,{label:`path`,mono:!0,children:(0,F.jsx)(`span`,{title:t.path,children:t.path})}),(0,F.jsx)(dt,{label:`invoke`,children:(0,F.jsxs)(`span`,{children:[(0,F.jsxs)(`code`,{children:[`/`,t.name]}),` in any session`]})}),t.files.length>0&&(0,F.jsx)(dt,{label:`bundled files`,mono:!0,children:t.files.map(e=>(0,F.jsx)(`span`,{className:`block w-full`,children:e},e))})]})})})]})]}):(0,F.jsx)(K,{children:`loading…`})}var Ol=function(e,t){let n=e,r=Al[t],i=null,a=0,o=null,s=[],c={},l=function(e,t){a=n*4+17,i=function(e){let t=Array(e);for(let n=0;n<e;n+=1){t[n]=Array(e);for(let r=0;r<e;r+=1)t[n][r]=null}return t}(a),u(0,0),u(a-7,0),u(0,a-7),p(),f(),h(e,t),n>=7&&m(e),o??=v(n,r,s),g(o,t)},u=function(e,t){for(let n=-1;n<=7;n+=1)if(!(e+n<=-1||a<=e+n))for(let r=-1;r<=7;r+=1)t+r<=-1||a<=t+r||(0<=n&&n<=6&&(r==0||r==6)||0<=r&&r<=6&&(n==0||n==6)||2<=n&&n<=4&&2<=r&&r<=4?i[e+n][t+r]=!0:i[e+n][t+r]=!1)},d=function(){let e=0,t=0;for(let n=0;n<8;n+=1){l(!0,n);let r=Ml.getLostPoint(c);(n==0||e>r)&&(e=r,t=n)}return t},f=function(){for(let e=8;e<a-8;e+=1)i[e][6]??(i[e][6]=e%2==0);for(let e=8;e<a-8;e+=1)i[6][e]??(i[6][e]=e%2==0)},p=function(){let e=Ml.getPatternPosition(n);for(let t=0;t<e.length;t+=1)for(let n=0;n<e.length;n+=1){let r=e[t],a=e[n];if(i[r][a]==null)for(let e=-2;e<=2;e+=1)for(let t=-2;t<=2;t+=1)e==-2||e==2||t==-2||t==2||e==0&&t==0?i[r+e][a+t]=!0:i[r+e][a+t]=!1}},m=function(e){let t=Ml.getBCHTypeNumber(n);for(let n=0;n<18;n+=1){let r=!e&&(t>>n&1)==1;i[Math.floor(n/3)][n%3+a-8-3]=r}for(let n=0;n<18;n+=1){let r=!e&&(t>>n&1)==1;i[n%3+a-8-3][Math.floor(n/3)]=r}},h=function(e,t){let n=r<<3|t,o=Ml.getBCHTypeInfo(n);for(let t=0;t<15;t+=1){let n=!e&&(o>>t&1)==1;t<6?i[t][8]=n:t<8?i[t+1][8]=n:i[a-15+t][8]=n}for(let t=0;t<15;t+=1){let n=!e&&(o>>t&1)==1;t<8?i[8][a-t-1]=n:t<9?i[8][15-t-1+1]=n:i[8][15-t-1]=n}i[a-8][8]=!e},g=function(e,t){let n=-1,r=a-1,o=7,s=0,c=Ml.getMaskFunction(t);for(let t=a-1;t>0;t-=2)for(t==6&&--t;;){for(let n=0;n<2;n+=1)if(i[r][t-n]==null){let a=!1;s<e.length&&(a=(e[s]>>>o&1)==1),c(r,t-n)&&(a=!a),i[r][t-n]=a,--o,o==-1&&(s+=1,o=7)}if(r+=n,r<0||a<=r){r-=n,n=-n;break}}},_=function(e,t){let n=0,r=0,i=0,a=Array(t.length),o=Array(t.length);for(let s=0;s<t.length;s+=1){let c=t[s].dataCount,l=t[s].totalCount-c;r=Math.max(r,c),i=Math.max(i,l),a[s]=Array(c);for(let t=0;t<a[s].length;t+=1)a[s][t]=255&e.getBuffer()[t+n];n+=c;let u=Ml.getErrorCorrectPolynomial(l),d=Pl(a[s],u.getLength()-1).mod(u);o[s]=Array(u.getLength()-1);for(let e=0;e<o[s].length;e+=1){let t=e+d.getLength()-o[s].length;o[s][e]=t>=0?d.getAt(t):0}}let s=0;for(let e=0;e<t.length;e+=1)s+=t[e].totalCount;let c=Array(s),l=0;for(let e=0;e<r;e+=1)for(let n=0;n<t.length;n+=1)e<a[n].length&&(c[l]=a[n][e],l+=1);for(let e=0;e<i;e+=1)for(let n=0;n<t.length;n+=1)e<o[n].length&&(c[l]=o[n][e],l+=1);return c},v=function(e,t,n){let r=Fl.getRSBlocks(e,t),i=Il();for(let t=0;t<n.length;t+=1){let r=n[t];i.put(r.getMode(),4),i.put(r.getLength(),Ml.getLengthInBits(r.getMode(),e)),r.write(i)}let a=0;for(let e=0;e<r.length;e+=1)a+=r[e].dataCount;if(i.getLengthInBits()>a*8)throw`code length overflow. (`+i.getLengthInBits()+`>`+a*8+`)`;for(i.getLengthInBits()+4<=a*8&&i.put(0,4);i.getLengthInBits()%8!=0;)i.putBit(!1);for(;!(i.getLengthInBits()>=a*8||(i.put(236,8),i.getLengthInBits()>=a*8));)i.put(17,8);return _(i,r)};c.addData=function(e,t){t||=`Byte`;let n=null;switch(t){case`Numeric`:n=Ll(e);break;case`Alphanumeric`:n=Rl(e);break;case`Byte`:n=zl(e);break;case`Kanji`:n=Bl(e);break;default:throw`mode:`+t}s.push(n),o=null},c.isDark=function(e,t){if(e<0||a<=e||t<0||a<=t)throw e+`,`+t;return i[e][t]},c.getModuleCount=function(){return a},c.make=function(){if(n<1){let e=1;for(;e<40;e++){let t=Fl.getRSBlocks(e,r),n=Il();for(let t=0;t<s.length;t++){let r=s[t];n.put(r.getMode(),4),n.put(r.getLength(),Ml.getLengthInBits(r.getMode(),e)),r.write(n)}let i=0;for(let e=0;e<t.length;e++)i+=t[e].dataCount;if(n.getLengthInBits()<=i*8)break}n=e}l(!1,d())},c.createTableTag=function(e,t){e||=2,t=t===void 0?e*4:t;let n=``;n+=`<table style="`,n+=` border-width: 0px; border-style: none;`,n+=` border-collapse: collapse;`,n+=` padding: 0px; margin: `+t+`px;`,n+=`">`,n+=`<tbody>`;for(let t=0;t<c.getModuleCount();t+=1){n+=`<tr>`;for(let r=0;r<c.getModuleCount();r+=1)n+=`<td style="`,n+=` border-width: 0px; border-style: none;`,n+=` border-collapse: collapse;`,n+=` padding: 0px; margin: 0px;`,n+=` width: `+e+`px;`,n+=` height: `+e+`px;`,n+=` background-color: `,n+=c.isDark(t,r)?`#000000`:`#ffffff`,n+=`;`,n+=`"/>`;n+=`</tr>`}return n+=`</tbody>`,n+=`</table>`,n},c.createSvgTag=function(e,t,n,r){let i={};typeof arguments[0]==`object`&&(i=arguments[0],e=i.cellSize,t=i.margin,n=i.alt,r=i.title),e||=2,t=t===void 0?e*4:t,n=typeof n==`string`?{text:n}:n||{},n.text=n.text||null,n.id=n.text?n.id||`qrcode-description`:null,r=typeof r==`string`?{text:r}:r||{},r.text=r.text||null,r.id=r.text?r.id||`qrcode-title`:null;let a=c.getModuleCount()*e+t*2,o,s,l,u,d=``,f;for(f=`l`+e+`,0 0,`+e+` -`+e+`,0 0,-`+e+`z `,d+=`<svg version="1.1" xmlns="http://www.w3.org/2000/svg"`,d+=i.scalable?``:` width="`+a+`px" height="`+a+`px"`,d+=` viewBox="0 0 `+a+` `+a+`" `,d+=` preserveAspectRatio="xMinYMin meet"`,d+=r.text||n.text?` role="img" aria-labelledby="`+y([r.id,n.id].join(` `).trim())+`"`:``,d+=`>`,d+=r.text?`<title id="`+y(r.id)+`">`+y(r.text)+`</title>`:``,d+=n.text?`<description id="`+y(n.id)+`">`+y(n.text)+`</description>`:``,d+=`<rect width="100%" height="100%" fill="white" cx="0" cy="0"/>`,d+=`<path d="`,l=0;l<c.getModuleCount();l+=1)for(u=l*e+t,o=0;o<c.getModuleCount();o+=1)c.isDark(l,o)&&(s=o*e+t,d+=`M`+s+`,`+u+f);return d+=`" stroke="transparent" fill="black"/>`,d+=`</svg>`,d},c.createDataURL=function(e,t){e||=2,t=t===void 0?e*4:t;let n=c.getModuleCount()*e+t*2,r=t,i=n-t;return Gl(n,n,function(t,n){if(r<=t&&t<i&&r<=n&&n<i){let i=Math.floor((t-r)/e),a=Math.floor((n-r)/e);return+!c.isDark(a,i)}return 1})},c.createImgTag=function(e,t,n){e||=2,t=t===void 0?e*4:t;let r=c.getModuleCount()*e+t*2,i=``;return i+=`<img`,i+=` src="`,i+=c.createDataURL(e,t),i+=`"`,i+=` width="`,i+=r,i+=`"`,i+=` height="`,i+=r,i+=`"`,n&&(i+=` alt="`,i+=y(n),i+=`"`),i+=`/>`,i};let y=function(e){let t=``;for(let n=0;n<e.length;n+=1){let r=e.charAt(n);switch(r){case`<`:t+=`&lt;`;break;case`>`:t+=`&gt;`;break;case`&`:t+=`&amp;`;break;case`"`:t+=`&quot;`;break;default:t+=r}}return t},b=function(e){e=e===void 0?2:e;let t=c.getModuleCount()*1+e*2,n=e,r=t-e,i,a,o,s,l,u={"██":`█`,"█ ":`▀`," █":`▄`," ":` `},d={"██":`▀`,"█ ":`▀`," █":` `," ":` `},f=``;for(i=0;i<t;i+=2){for(o=Math.floor((i-n)/1),s=Math.floor((i+1-n)/1),a=0;a<t;a+=1)l=`█`,n<=a&&a<r&&n<=i&&i<r&&c.isDark(o,Math.floor((a-n)/1))&&(l=` `),n<=a&&a<r&&n<=i+1&&i+1<r&&c.isDark(s,Math.floor((a-n)/1))?l+=` `:l+=`█`,f+=e<1&&i+1>=r?d[l]:u[l];f+=`
219
+ `)}`:n,o=await A.request(`knowledge.putConcept`,{bundle:e,body:{id:t,content:a},keepalive:!0});if(!o.ok)throw Error(M(o));let s=o.data;if(s.error)throw Error(s.error);w.current=(await cl()).splitFrontmatter(s.raw).head,T.current=s.raw,r(s),C(``),x(D.current===null?`saved`:`unsaved`)}catch(e){C(e.message),x(`error`),D.current===null&&(D.current=n)}})();k.current=i,await i,k.current=null}function N(e){E.current&&(D.current=e,x(`unsaved`),O.current&&clearTimeout(O.current),O.current=setTimeout(()=>void ee(),1e3))}(0,v.useEffect)(()=>{let e=()=>{D.current!==null&&ee()};return window.addEventListener(`beforeunload`,e),window.addEventListener(`pagehide`,e),()=>{window.removeEventListener(`beforeunload`,e),window.removeEventListener(`pagehide`,e),O.current&&clearTimeout(O.current),D.current!==null&&ee()}},[]);async function te(){s(!0),await A.request(`knowledge.verify`,{bundle:e,body:{id:t}}).catch(()=>{}),s(!1),j()}function ne(){n&&(f(n.raw),g(``),u(`markdown`))}async function I(){m(!0),g(``);let n=await A.request(`knowledge.putConcept`,{bundle:e,body:{id:t,content:d}}).catch(()=>null);m(!1),!n?.ok||!n.data||typeof n.data!=`object`?g(n?.error??`save failed`):n.data.error?g(n.data.error):(T.current=null,r(n.data),u(`document`))}if(i)return(0,F.jsx)(K,{icon:`description`,children:`concept not found`});if(!n)return(0,F.jsx)(K,{children:`loading…`});let L=b===`saving`?`saving…`:b===`unsaved`?`unsaved changes`:b===`error`?`not saved — ${S}`:`all changes saved`;return(0,F.jsxs)(`div`,{className:P(`agent-view flex flex-col`,c?`gap-2.5`:`gap-4`),children:[(0,F.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[(0,F.jsx)(nt,{size:c?`md`:`lg`,children:n.title}),n.type&&(0,F.jsx)(W,{children:n.type}),(0,F.jsx)(dl,{tier:n.trustTier}),n.status!==`stable`&&(0,F.jsx)(W,{tone:fl(n.status),children:n.status}),n.stale&&(0,F.jsxs)(W,{tone:`bad`,children:[`stale since `,n.staleAfter?.slice(0,10)]}),(0,F.jsx)(`span`,{className:`flex-1`}),!c&&(0,F.jsx)(V,{size:`sm`,variant:`quiet`,icon:`picture_as_pdf`,onClick:()=>void ss(e,n.id),children:`export PDF`}),(0,F.jsx)(V,{variant:`primary`,size:c?`sm`:`md`,icon:`check`,busy:o,onClick:te,children:o?`verifying…`:`verify (human)`})]}),n.error&&(0,F.jsx)(q,{tone:`bad`,children:n.error}),(0,F.jsxs)(`div`,{className:P(`grid items-start`,c?`grid-cols-1 gap-3`:`grid-cols-[minmax(0,1fr)_320px] gap-4 max-[1020px]:grid-cols-1`),children:[(0,F.jsxs)(J,{className:`min-w-0`,title:`content`,actions:(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(`span`,{className:`min-w-0 truncate font-mono text-[10.5px] text-fg-2`,children:[e,`/`,n.id,`.md`]}),l===`markdown`?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(V,{size:`sm`,variant:`quiet`,onClick:()=>{u(`document`),g(``)},children:`cancel`}),(0,F.jsx)(V,{size:`sm`,icon:`check`,busy:p,onClick:()=>void I(),children:p?`saving…`:`save`})]}):(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`span`,{className:P(`text-xs whitespace-nowrap`,b===`error`?`text-bad`:b===`unsaved`||b===`saving`?`text-ask`:`text-fg-2`),children:L}),(0,F.jsx)(V,{size:`sm`,variant:`quiet`,icon:`code`,title:`The whole file as text, frontmatter included`,onClick:ne,children:`edit markdown`})]})]}),children:[l===`markdown`?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`textarea`,{className:`concept-edit block w-full resize-y border-0 border-b border-line bg-surface px-[18px] py-3.5 font-mono text-[12.5px] leading-[1.65] text-fg outline-none`,value:d,rows:Math.min(40,Math.max(18,d.split(`
220
+ `).length+2)),onChange:e=>f(e.target.value),spellCheck:!1}),(0,F.jsxs)(G,{className:`border-b border-line px-[18px] py-1.5`,children:[`full file (frontmatter + markdown body) — saving stamps provenance as `,(0,F.jsx)(`code`,{children:`human:user`}),` and logs an update.`]})]}):(0,F.jsxs)(`div`,{className:P(`concept-doc`,c?`[&_.editor-content]:min-h-[220px]`:`[&_.editor-content]:min-h-[280px]`),onPointerDownCapture:()=>E.current=!0,onKeyDownCapture:()=>E.current=!0,onPasteCapture:()=>E.current=!0,onDropCapture:()=>E.current=!0,children:[_?(0,F.jsx)(v.Suspense,{fallback:(0,F.jsx)(G,{className:`border-b border-line px-[18px] py-1.5`,children:`loading the editor…`}),children:(0,F.jsx)(sl,{markdown:_.body,autoFocus:!1,onChange:N,onError:ne},_.key)}):(0,F.jsx)(G,{className:`border-b border-line px-[18px] py-1.5`,children:`loading…`}),(0,F.jsxs)(G,{className:`border-b border-line px-[18px] py-1.5`,children:[`the page as a document, saved as you type; every save stamps provenance as `,(0,F.jsx)(`code`,{children:`human:user`}),` and logs an update.`]})]}),h&&(0,F.jsx)(`div`,{className:`px-3 py-1`,children:(0,F.jsx)(q,{tone:`bad`,children:h})})]}),(0,F.jsxs)(`aside`,{className:P(`flex min-w-0 flex-col`,c?`gap-2.5`:`gap-4`),children:[(0,F.jsx)(J,{title:`about`,children:(0,F.jsxs)(ut,{compact:c,children:[(0,F.jsx)(dt,{label:`trust`,children:(0,F.jsx)(dl,{tier:n.trustTier})}),(0,F.jsx)(dt,{label:`generated`,dim:!n.generated,children:n.generated?`${n.generated.by??`?`} · ${(n.generated.at??`?`).slice(0,10)}`:`not stamped`}),(0,F.jsx)(dt,{label:`verified`,dim:n.verified.length===0,children:n.verified.length===0?`never`:n.verified.map((e,t)=>(0,F.jsxs)(`span`,{className:`block`,children:[e.by??`?`,` · `,(e.at??`?`).slice(0,10)]},t))}),n.staleAfter&&(0,F.jsxs)(dt,{label:`stale after`,dim:!n.stale,children:[n.staleAfter.slice(0,10),n.stale&&(0,F.jsx)(W,{tone:`bad`,children:`stale`})]}),n.tags.length>0&&(0,F.jsx)(dt,{label:`tags`,children:n.tags.map(e=>(0,F.jsx)(W,{children:e},e))})]})}),n.sources.length>0&&(0,F.jsx)(J,{title:`sources`,children:(0,F.jsx)(ut,{compact:c,children:n.sources.map((e,t)=>(0,F.jsxs)(`div`,{className:P(`flex flex-col gap-[3px] break-words`,c?`px-3.5 py-1.5 text-xs`:`px-[18px] py-2.5 text-[12.5px]`),children:[(0,F.jsxs)(`span`,{className:`text-fg [&_a]:text-accent`,children:[e.resource?.startsWith(`http`)?(0,F.jsx)(`a`,{href:e.resource,target:`_blank`,rel:`noreferrer`,children:e.title??e.resource}):e.title??e.resource??`?`,e.id&&(0,F.jsxs)(`span`,{className:`ml-2 font-mono text-2xs text-fg-2`,children:[`[^`,e.id,`]`]})]}),(0,F.jsx)(`span`,{className:`text-fg-2`,children:[e.author,e.usage_count==null?null:`${e.usage_count} uses`,e.last_modified?`mod ${e.last_modified.slice(0,10)}`:null].filter(Boolean).join(` · `)})]},t))})})]})]})]})}var wl={workspace:`workspace`,project:`.claude`,user:`global`,agent:`agent`};function Tl(e){return(0,F.jsx)(W,{tone:e===`workspace`?`ok`:e===`agent`?`accent`:`neutral`,children:wl[e]})}function El({name:e}){let t=N(`skills.list`,{}),n=t?.skills??[],r=n.filter(e=>e.source===`workspace`),i=n.filter(e=>e.source!==`workspace`),a=r[0]??i[0];(0,v.useEffect)(()=>{!e&&a&&B(`/skills/${encodeURIComponent(a.name)}`,{replace:!0})},[e,a?.name]);let o=t=>(0,F.jsx)(Y,{href:`/skills/${encodeURIComponent(t.name)}`,active:t.name===e,size:`sm`,leading:(0,F.jsx)(U,{tone:t.source===`workspace`?`ok`:`idle`}),title:`/${t.name}`,titleExtra:t.source!==`workspace`&&Tl(t.source),sub:t.description||`no description`},`${t.source}:${t.name}`);return(0,F.jsxs)(`div`,{className:`runs-screen`,children:[(0,F.jsxs)(`aside`,{className:`runs-side`,children:[(0,F.jsx)(wt,{title:`workspace skills`}),(0,F.jsxs)(Et,{children:[r.map(o),t&&r.length===0&&(0,F.jsx)(Dt,{children:`no workspace skills yet`}),i.length>0&&(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(wt,{title:`local (this machine / repo)`,divided:!0}),i.map(o)]})]})]}),(0,F.jsx)(`div`,{className:`runs-main`,children:e?(0,F.jsx)(Ol,{name:e},e):t&&!a?(0,F.jsx)(Dl,{root:t.root}):(0,F.jsx)(K,{children:`loading…`})})]})}function Dl({root:e}){return(0,F.jsx)(`div`,{className:`empty-action py-6`,children:(0,F.jsxs)(K,{icon:`extension`,children:[`Create `,(0,F.jsxs)(`code`,{children:[e,`/<name>/SKILL.md`]}),` and it appears here and in every session's `,(0,F.jsx)(`code`,{children:`/`}),` menu.`]})})}function Ol({name:e}){let[t,n]=(0,v.useState)(null),[r,i]=(0,v.useState)(!1),[a,o]=(0,v.useState)(`rendered`),s=(0,v.useMemo)(()=>t?t.content.replace(/^---\r?\n[\s\S]*?\r?\n---(\r?\n|$)/,``):``,[t?.content]),c=(0,v.useMemo)(()=>t?da.sanitize(Fr.parse(s,{async:!1})):``,[s]);return(0,v.useEffect)(()=>{A.call(`skills.get`,{name:e}).then(n,()=>i(!0))},[e]),r?(0,F.jsx)(K,{icon:`extension`,children:`skill not found`}):t?(0,F.jsxs)(`div`,{className:`agent-view flex flex-col gap-4`,children:[(0,F.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[(0,F.jsxs)(nt,{size:`lg`,children:[`/`,t.name]}),Tl(t.source)]}),t.description&&(0,F.jsx)(`p`,{className:`-mt-2 mb-0 mx-0.5 text-sm leading-[1.6] text-fg-2`,children:t.description}),(0,F.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_320px] items-start gap-4 max-[1020px]:grid-cols-1`,children:[(0,F.jsx)(J,{className:`min-w-0`,title:`SKILL.md`,actions:(0,F.jsx)(ft,{bare:!0,label:`SKILL.md view`,value:a,onChange:o,items:[{id:`rendered`,label:`rendered`},{id:`source`,label:`source`}]}),children:a===`rendered`?(0,F.jsx)(`div`,{className:`md-body h-auto overflow-visible [&_a]:text-accent [&_a]:underline [&_a]:underline-offset-2`,dangerouslySetInnerHTML:{__html:c}}):(0,F.jsx)(`pre`,{className:`m-0 max-h-[560px] overflow-auto px-[18px] py-3.5 font-mono text-xs leading-[1.55] break-words whitespace-pre-wrap text-fg-2`,children:t.content.trim()||`(empty)`})}),(0,F.jsx)(`aside`,{className:`flex min-w-0 flex-col gap-4`,children:(0,F.jsx)(J,{title:`about`,children:(0,F.jsxs)(ut,{children:[(0,F.jsx)(dt,{label:`source`,children:t.source===`workspace`?`workspace — git-tracked, shared with the team`:t.source===`project`?`repo .claude/skills — tracked, but outside the workspace root`:`global ~/.claude/skills — only on this machine`}),(0,F.jsx)(dt,{label:`path`,mono:!0,children:(0,F.jsx)(`span`,{title:t.path,children:t.path})}),(0,F.jsx)(dt,{label:`invoke`,children:(0,F.jsxs)(`span`,{children:[(0,F.jsxs)(`code`,{children:[`/`,t.name]}),` in any session`]})}),t.files.length>0&&(0,F.jsx)(dt,{label:`bundled files`,mono:!0,children:t.files.map(e=>(0,F.jsx)(`span`,{className:`block w-full`,children:e},e))})]})})})]})]}):(0,F.jsx)(K,{children:`loading…`})}var kl=function(e,t){let n=e,r=jl[t],i=null,a=0,o=null,s=[],c={},l=function(e,t){a=n*4+17,i=function(e){let t=Array(e);for(let n=0;n<e;n+=1){t[n]=Array(e);for(let r=0;r<e;r+=1)t[n][r]=null}return t}(a),u(0,0),u(a-7,0),u(0,a-7),p(),f(),h(e,t),n>=7&&m(e),o??=v(n,r,s),g(o,t)},u=function(e,t){for(let n=-1;n<=7;n+=1)if(!(e+n<=-1||a<=e+n))for(let r=-1;r<=7;r+=1)t+r<=-1||a<=t+r||(0<=n&&n<=6&&(r==0||r==6)||0<=r&&r<=6&&(n==0||n==6)||2<=n&&n<=4&&2<=r&&r<=4?i[e+n][t+r]=!0:i[e+n][t+r]=!1)},d=function(){let e=0,t=0;for(let n=0;n<8;n+=1){l(!0,n);let r=Nl.getLostPoint(c);(n==0||e>r)&&(e=r,t=n)}return t},f=function(){for(let e=8;e<a-8;e+=1)i[e][6]??(i[e][6]=e%2==0);for(let e=8;e<a-8;e+=1)i[6][e]??(i[6][e]=e%2==0)},p=function(){let e=Nl.getPatternPosition(n);for(let t=0;t<e.length;t+=1)for(let n=0;n<e.length;n+=1){let r=e[t],a=e[n];if(i[r][a]==null)for(let e=-2;e<=2;e+=1)for(let t=-2;t<=2;t+=1)e==-2||e==2||t==-2||t==2||e==0&&t==0?i[r+e][a+t]=!0:i[r+e][a+t]=!1}},m=function(e){let t=Nl.getBCHTypeNumber(n);for(let n=0;n<18;n+=1){let r=!e&&(t>>n&1)==1;i[Math.floor(n/3)][n%3+a-8-3]=r}for(let n=0;n<18;n+=1){let r=!e&&(t>>n&1)==1;i[n%3+a-8-3][Math.floor(n/3)]=r}},h=function(e,t){let n=r<<3|t,o=Nl.getBCHTypeInfo(n);for(let t=0;t<15;t+=1){let n=!e&&(o>>t&1)==1;t<6?i[t][8]=n:t<8?i[t+1][8]=n:i[a-15+t][8]=n}for(let t=0;t<15;t+=1){let n=!e&&(o>>t&1)==1;t<8?i[8][a-t-1]=n:t<9?i[8][15-t-1+1]=n:i[8][15-t-1]=n}i[a-8][8]=!e},g=function(e,t){let n=-1,r=a-1,o=7,s=0,c=Nl.getMaskFunction(t);for(let t=a-1;t>0;t-=2)for(t==6&&--t;;){for(let n=0;n<2;n+=1)if(i[r][t-n]==null){let a=!1;s<e.length&&(a=(e[s]>>>o&1)==1),c(r,t-n)&&(a=!a),i[r][t-n]=a,--o,o==-1&&(s+=1,o=7)}if(r+=n,r<0||a<=r){r-=n,n=-n;break}}},_=function(e,t){let n=0,r=0,i=0,a=Array(t.length),o=Array(t.length);for(let s=0;s<t.length;s+=1){let c=t[s].dataCount,l=t[s].totalCount-c;r=Math.max(r,c),i=Math.max(i,l),a[s]=Array(c);for(let t=0;t<a[s].length;t+=1)a[s][t]=255&e.getBuffer()[t+n];n+=c;let u=Nl.getErrorCorrectPolynomial(l),d=Fl(a[s],u.getLength()-1).mod(u);o[s]=Array(u.getLength()-1);for(let e=0;e<o[s].length;e+=1){let t=e+d.getLength()-o[s].length;o[s][e]=t>=0?d.getAt(t):0}}let s=0;for(let e=0;e<t.length;e+=1)s+=t[e].totalCount;let c=Array(s),l=0;for(let e=0;e<r;e+=1)for(let n=0;n<t.length;n+=1)e<a[n].length&&(c[l]=a[n][e],l+=1);for(let e=0;e<i;e+=1)for(let n=0;n<t.length;n+=1)e<o[n].length&&(c[l]=o[n][e],l+=1);return c},v=function(e,t,n){let r=Il.getRSBlocks(e,t),i=Ll();for(let t=0;t<n.length;t+=1){let r=n[t];i.put(r.getMode(),4),i.put(r.getLength(),Nl.getLengthInBits(r.getMode(),e)),r.write(i)}let a=0;for(let e=0;e<r.length;e+=1)a+=r[e].dataCount;if(i.getLengthInBits()>a*8)throw`code length overflow. (`+i.getLengthInBits()+`>`+a*8+`)`;for(i.getLengthInBits()+4<=a*8&&i.put(0,4);i.getLengthInBits()%8!=0;)i.putBit(!1);for(;!(i.getLengthInBits()>=a*8||(i.put(236,8),i.getLengthInBits()>=a*8));)i.put(17,8);return _(i,r)};c.addData=function(e,t){t||=`Byte`;let n=null;switch(t){case`Numeric`:n=Rl(e);break;case`Alphanumeric`:n=zl(e);break;case`Byte`:n=Bl(e);break;case`Kanji`:n=Vl(e);break;default:throw`mode:`+t}s.push(n),o=null},c.isDark=function(e,t){if(e<0||a<=e||t<0||a<=t)throw e+`,`+t;return i[e][t]},c.getModuleCount=function(){return a},c.make=function(){if(n<1){let e=1;for(;e<40;e++){let t=Il.getRSBlocks(e,r),n=Ll();for(let t=0;t<s.length;t++){let r=s[t];n.put(r.getMode(),4),n.put(r.getLength(),Nl.getLengthInBits(r.getMode(),e)),r.write(n)}let i=0;for(let e=0;e<t.length;e++)i+=t[e].dataCount;if(n.getLengthInBits()<=i*8)break}n=e}l(!1,d())},c.createTableTag=function(e,t){e||=2,t=t===void 0?e*4:t;let n=``;n+=`<table style="`,n+=` border-width: 0px; border-style: none;`,n+=` border-collapse: collapse;`,n+=` padding: 0px; margin: `+t+`px;`,n+=`">`,n+=`<tbody>`;for(let t=0;t<c.getModuleCount();t+=1){n+=`<tr>`;for(let r=0;r<c.getModuleCount();r+=1)n+=`<td style="`,n+=` border-width: 0px; border-style: none;`,n+=` border-collapse: collapse;`,n+=` padding: 0px; margin: 0px;`,n+=` width: `+e+`px;`,n+=` height: `+e+`px;`,n+=` background-color: `,n+=c.isDark(t,r)?`#000000`:`#ffffff`,n+=`;`,n+=`"/>`;n+=`</tr>`}return n+=`</tbody>`,n+=`</table>`,n},c.createSvgTag=function(e,t,n,r){let i={};typeof arguments[0]==`object`&&(i=arguments[0],e=i.cellSize,t=i.margin,n=i.alt,r=i.title),e||=2,t=t===void 0?e*4:t,n=typeof n==`string`?{text:n}:n||{},n.text=n.text||null,n.id=n.text?n.id||`qrcode-description`:null,r=typeof r==`string`?{text:r}:r||{},r.text=r.text||null,r.id=r.text?r.id||`qrcode-title`:null;let a=c.getModuleCount()*e+t*2,o,s,l,u,d=``,f;for(f=`l`+e+`,0 0,`+e+` -`+e+`,0 0,-`+e+`z `,d+=`<svg version="1.1" xmlns="http://www.w3.org/2000/svg"`,d+=i.scalable?``:` width="`+a+`px" height="`+a+`px"`,d+=` viewBox="0 0 `+a+` `+a+`" `,d+=` preserveAspectRatio="xMinYMin meet"`,d+=r.text||n.text?` role="img" aria-labelledby="`+y([r.id,n.id].join(` `).trim())+`"`:``,d+=`>`,d+=r.text?`<title id="`+y(r.id)+`">`+y(r.text)+`</title>`:``,d+=n.text?`<description id="`+y(n.id)+`">`+y(n.text)+`</description>`:``,d+=`<rect width="100%" height="100%" fill="white" cx="0" cy="0"/>`,d+=`<path d="`,l=0;l<c.getModuleCount();l+=1)for(u=l*e+t,o=0;o<c.getModuleCount();o+=1)c.isDark(l,o)&&(s=o*e+t,d+=`M`+s+`,`+u+f);return d+=`" stroke="transparent" fill="black"/>`,d+=`</svg>`,d},c.createDataURL=function(e,t){e||=2,t=t===void 0?e*4:t;let n=c.getModuleCount()*e+t*2,r=t,i=n-t;return Kl(n,n,function(t,n){if(r<=t&&t<i&&r<=n&&n<i){let i=Math.floor((t-r)/e),a=Math.floor((n-r)/e);return+!c.isDark(a,i)}return 1})},c.createImgTag=function(e,t,n){e||=2,t=t===void 0?e*4:t;let r=c.getModuleCount()*e+t*2,i=``;return i+=`<img`,i+=` src="`,i+=c.createDataURL(e,t),i+=`"`,i+=` width="`,i+=r,i+=`"`,i+=` height="`,i+=r,i+=`"`,n&&(i+=` alt="`,i+=y(n),i+=`"`),i+=`/>`,i};let y=function(e){let t=``;for(let n=0;n<e.length;n+=1){let r=e.charAt(n);switch(r){case`<`:t+=`&lt;`;break;case`>`:t+=`&gt;`;break;case`&`:t+=`&amp;`;break;case`"`:t+=`&quot;`;break;default:t+=r}}return t},b=function(e){e=e===void 0?2:e;let t=c.getModuleCount()*1+e*2,n=e,r=t-e,i,a,o,s,l,u={"██":`█`,"█ ":`▀`," █":`▄`," ":` `},d={"██":`▀`,"█ ":`▀`," █":` `," ":` `},f=``;for(i=0;i<t;i+=2){for(o=Math.floor((i-n)/1),s=Math.floor((i+1-n)/1),a=0;a<t;a+=1)l=`█`,n<=a&&a<r&&n<=i&&i<r&&c.isDark(o,Math.floor((a-n)/1))&&(l=` `),n<=a&&a<r&&n<=i+1&&i+1<r&&c.isDark(s,Math.floor((a-n)/1))?l+=` `:l+=`█`,f+=e<1&&i+1>=r?d[l]:u[l];f+=`
221
221
  `}return t%2&&e>0?f.substring(0,f.length-t-1)+Array(t+1).join(`▀`):f.substring(0,f.length-1)};return c.createASCII=function(e,t){if(e||=1,e<2)return b(t);--e,t=t===void 0?e*2:t;let n=c.getModuleCount()*e+t*2,r=t,i=n-t,a,o,s,l,u=Array(e+1).join(`██`),d=Array(e+1).join(` `),f=``,p=``;for(a=0;a<n;a+=1){for(s=Math.floor((a-r)/e),p=``,o=0;o<n;o+=1)l=1,r<=o&&o<i&&r<=a&&a<i&&c.isDark(s,Math.floor((o-r)/e))&&(l=0),p+=l?u:d;for(s=0;s<e;s+=1)f+=p+`
222
- `}return f.substring(0,f.length-1)},c.renderTo2dContext=function(e,t){t||=2;let n=c.getModuleCount();for(let r=0;r<n;r++)for(let i=0;i<n;i++)e.fillStyle=c.isDark(r,i)?`black`:`white`,e.fillRect(i*t,r*t,t,t)},c};Ol.stringToBytes=function(e){let t=[];for(let n=0;n<e.length;n+=1){let r=e.charCodeAt(n);t.push(r&255)}return t},Ol.createStringToBytes=function(e,t){let n=function(){let n=Ul(e),r=function(){let e=n.read();if(e==-1)throw`eof`;return e},i=0,a={};for(;;){let e=n.read();if(e==-1)break;let t=r(),o=r(),s=r(),c=String.fromCharCode(e<<8|t);a[c]=o<<8|s,i+=1}if(i!=t)throw i+` != `+t;return a}();return function(e){let t=[];for(let r=0;r<e.length;r+=1){let i=e.charCodeAt(r);if(i<128)t.push(i);else{let i=n[e.charAt(r)];typeof i==`number`?(i&255)==i?t.push(i):(t.push(i>>>8),t.push(i&255)):t.push(63)}}return t}};var kl={MODE_NUMBER:1,MODE_ALPHA_NUM:2,MODE_8BIT_BYTE:4,MODE_KANJI:8},Al={L:1,M:0,Q:3,H:2},jl={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7},Ml=function(){let e=[[],[6,18],[6,22],[6,26],[6,30],[6,34],[6,22,38],[6,24,42],[6,26,46],[6,28,50],[6,30,54],[6,32,58],[6,34,62],[6,26,46,66],[6,26,48,70],[6,26,50,74],[6,30,54,78],[6,30,56,82],[6,30,58,86],[6,34,62,90],[6,28,50,72,94],[6,26,50,74,98],[6,30,54,78,102],[6,28,54,80,106],[6,32,58,84,110],[6,30,58,86,114],[6,34,62,90,118],[6,26,50,74,98,122],[6,30,54,78,102,126],[6,26,52,78,104,130],[6,30,56,82,108,134],[6,34,60,86,112,138],[6,30,58,86,114,142],[6,34,62,90,118,146],[6,30,54,78,102,126,150],[6,24,50,76,102,128,154],[6,28,54,80,106,132,158],[6,32,58,84,110,136,162],[6,26,54,82,110,138,166],[6,30,58,86,114,142,170]],t=1335,n=7973,r={},i=function(e){let t=0;for(;e!=0;)t+=1,e>>>=1;return t};return r.getBCHTypeInfo=function(e){let n=e<<10;for(;i(n)-i(t)>=0;)n^=t<<i(n)-i(t);return(e<<10|n)^21522},r.getBCHTypeNumber=function(e){let t=e<<12;for(;i(t)-i(n)>=0;)t^=n<<i(t)-i(n);return e<<12|t},r.getPatternPosition=function(t){return e[t-1]},r.getMaskFunction=function(e){switch(e){case jl.PATTERN000:return function(e,t){return(e+t)%2==0};case jl.PATTERN001:return function(e,t){return e%2==0};case jl.PATTERN010:return function(e,t){return t%3==0};case jl.PATTERN011:return function(e,t){return(e+t)%3==0};case jl.PATTERN100:return function(e,t){return(Math.floor(e/2)+Math.floor(t/3))%2==0};case jl.PATTERN101:return function(e,t){return e*t%2+e*t%3==0};case jl.PATTERN110:return function(e,t){return(e*t%2+e*t%3)%2==0};case jl.PATTERN111:return function(e,t){return(e*t%3+(e+t)%2)%2==0};default:throw`bad maskPattern:`+e}},r.getErrorCorrectPolynomial=function(e){let t=Pl([1],0);for(let n=0;n<e;n+=1)t=t.multiply(Pl([1,Nl.gexp(n)],0));return t},r.getLengthInBits=function(e,t){if(1<=t&&t<10)switch(e){case kl.MODE_NUMBER:return 10;case kl.MODE_ALPHA_NUM:return 9;case kl.MODE_8BIT_BYTE:return 8;case kl.MODE_KANJI:return 8;default:throw`mode:`+e}else if(t<27)switch(e){case kl.MODE_NUMBER:return 12;case kl.MODE_ALPHA_NUM:return 11;case kl.MODE_8BIT_BYTE:return 16;case kl.MODE_KANJI:return 10;default:throw`mode:`+e}else if(t<41)switch(e){case kl.MODE_NUMBER:return 14;case kl.MODE_ALPHA_NUM:return 13;case kl.MODE_8BIT_BYTE:return 16;case kl.MODE_KANJI:return 12;default:throw`mode:`+e}else throw`type:`+t},r.getLostPoint=function(e){let t=e.getModuleCount(),n=0;for(let r=0;r<t;r+=1)for(let i=0;i<t;i+=1){let a=0,o=e.isDark(r,i);for(let n=-1;n<=1;n+=1)if(!(r+n<0||t<=r+n))for(let s=-1;s<=1;s+=1)i+s<0||t<=i+s||(n!=0||s!=0)&&o==e.isDark(r+n,i+s)&&(a+=1);a>5&&(n+=3+a-5)}for(let r=0;r<t-1;r+=1)for(let i=0;i<t-1;i+=1){let t=0;e.isDark(r,i)&&(t+=1),e.isDark(r+1,i)&&(t+=1),e.isDark(r,i+1)&&(t+=1),e.isDark(r+1,i+1)&&(t+=1),(t==0||t==4)&&(n+=3)}for(let r=0;r<t;r+=1)for(let i=0;i<t-6;i+=1)e.isDark(r,i)&&!e.isDark(r,i+1)&&e.isDark(r,i+2)&&e.isDark(r,i+3)&&e.isDark(r,i+4)&&!e.isDark(r,i+5)&&e.isDark(r,i+6)&&(n+=40);for(let r=0;r<t;r+=1)for(let i=0;i<t-6;i+=1)e.isDark(i,r)&&!e.isDark(i+1,r)&&e.isDark(i+2,r)&&e.isDark(i+3,r)&&e.isDark(i+4,r)&&!e.isDark(i+5,r)&&e.isDark(i+6,r)&&(n+=40);let r=0;for(let n=0;n<t;n+=1)for(let i=0;i<t;i+=1)e.isDark(i,n)&&(r+=1);let i=Math.abs(100*r/t/t-50)/5;return n+=i*10,n},r}(),Nl=function(){let e=Array(256),t=Array(256);for(let t=0;t<8;t+=1)e[t]=1<<t;for(let t=8;t<256;t+=1)e[t]=e[t-4]^e[t-5]^e[t-6]^e[t-8];for(let n=0;n<255;n+=1)t[e[n]]=n;let n={};return n.glog=function(e){if(e<1)throw`glog(`+e+`)`;return t[e]},n.gexp=function(t){for(;t<0;)t+=255;for(;t>=256;)t-=255;return e[t]},n}(),Pl=function(e,t){if(e.length===void 0)throw e.length+`/`+t;let n=function(){let n=0;for(;n<e.length&&e[n]==0;)n+=1;let r=Array(e.length-n+t);for(let t=0;t<e.length-n;t+=1)r[t]=e[t+n];return r}(),r={};return r.getAt=function(e){return n[e]},r.getLength=function(){return n.length},r.multiply=function(e){let t=Array(r.getLength()+e.getLength()-1);for(let n=0;n<r.getLength();n+=1)for(let i=0;i<e.getLength();i+=1)t[n+i]^=Nl.gexp(Nl.glog(r.getAt(n))+Nl.glog(e.getAt(i)));return Pl(t,0)},r.mod=function(e){if(r.getLength()-e.getLength()<0)return r;let t=Nl.glog(r.getAt(0))-Nl.glog(e.getAt(0)),n=Array(r.getLength());for(let e=0;e<r.getLength();e+=1)n[e]=r.getAt(e);for(let r=0;r<e.getLength();r+=1)n[r]^=Nl.gexp(Nl.glog(e.getAt(r))+t);return Pl(n,0).mod(e)},r},Fl=function(){let e=[[1,26,19],[1,26,16],[1,26,13],[1,26,9],[1,44,34],[1,44,28],[1,44,22],[1,44,16],[1,70,55],[1,70,44],[2,35,17],[2,35,13],[1,100,80],[2,50,32],[2,50,24],[4,25,9],[1,134,108],[2,67,43],[2,33,15,2,34,16],[2,33,11,2,34,12],[2,86,68],[4,43,27],[4,43,19],[4,43,15],[2,98,78],[4,49,31],[2,32,14,4,33,15],[4,39,13,1,40,14],[2,121,97],[2,60,38,2,61,39],[4,40,18,2,41,19],[4,40,14,2,41,15],[2,146,116],[3,58,36,2,59,37],[4,36,16,4,37,17],[4,36,12,4,37,13],[2,86,68,2,87,69],[4,69,43,1,70,44],[6,43,19,2,44,20],[6,43,15,2,44,16],[4,101,81],[1,80,50,4,81,51],[4,50,22,4,51,23],[3,36,12,8,37,13],[2,116,92,2,117,93],[6,58,36,2,59,37],[4,46,20,6,47,21],[7,42,14,4,43,15],[4,133,107],[8,59,37,1,60,38],[8,44,20,4,45,21],[12,33,11,4,34,12],[3,145,115,1,146,116],[4,64,40,5,65,41],[11,36,16,5,37,17],[11,36,12,5,37,13],[5,109,87,1,110,88],[5,65,41,5,66,42],[5,54,24,7,55,25],[11,36,12,7,37,13],[5,122,98,1,123,99],[7,73,45,3,74,46],[15,43,19,2,44,20],[3,45,15,13,46,16],[1,135,107,5,136,108],[10,74,46,1,75,47],[1,50,22,15,51,23],[2,42,14,17,43,15],[5,150,120,1,151,121],[9,69,43,4,70,44],[17,50,22,1,51,23],[2,42,14,19,43,15],[3,141,113,4,142,114],[3,70,44,11,71,45],[17,47,21,4,48,22],[9,39,13,16,40,14],[3,135,107,5,136,108],[3,67,41,13,68,42],[15,54,24,5,55,25],[15,43,15,10,44,16],[4,144,116,4,145,117],[17,68,42],[17,50,22,6,51,23],[19,46,16,6,47,17],[2,139,111,7,140,112],[17,74,46],[7,54,24,16,55,25],[34,37,13],[4,151,121,5,152,122],[4,75,47,14,76,48],[11,54,24,14,55,25],[16,45,15,14,46,16],[6,147,117,4,148,118],[6,73,45,14,74,46],[11,54,24,16,55,25],[30,46,16,2,47,17],[8,132,106,4,133,107],[8,75,47,13,76,48],[7,54,24,22,55,25],[22,45,15,13,46,16],[10,142,114,2,143,115],[19,74,46,4,75,47],[28,50,22,6,51,23],[33,46,16,4,47,17],[8,152,122,4,153,123],[22,73,45,3,74,46],[8,53,23,26,54,24],[12,45,15,28,46,16],[3,147,117,10,148,118],[3,73,45,23,74,46],[4,54,24,31,55,25],[11,45,15,31,46,16],[7,146,116,7,147,117],[21,73,45,7,74,46],[1,53,23,37,54,24],[19,45,15,26,46,16],[5,145,115,10,146,116],[19,75,47,10,76,48],[15,54,24,25,55,25],[23,45,15,25,46,16],[13,145,115,3,146,116],[2,74,46,29,75,47],[42,54,24,1,55,25],[23,45,15,28,46,16],[17,145,115],[10,74,46,23,75,47],[10,54,24,35,55,25],[19,45,15,35,46,16],[17,145,115,1,146,116],[14,74,46,21,75,47],[29,54,24,19,55,25],[11,45,15,46,46,16],[13,145,115,6,146,116],[14,74,46,23,75,47],[44,54,24,7,55,25],[59,46,16,1,47,17],[12,151,121,7,152,122],[12,75,47,26,76,48],[39,54,24,14,55,25],[22,45,15,41,46,16],[6,151,121,14,152,122],[6,75,47,34,76,48],[46,54,24,10,55,25],[2,45,15,64,46,16],[17,152,122,4,153,123],[29,74,46,14,75,47],[49,54,24,10,55,25],[24,45,15,46,46,16],[4,152,122,18,153,123],[13,74,46,32,75,47],[48,54,24,14,55,25],[42,45,15,32,46,16],[20,147,117,4,148,118],[40,75,47,7,76,48],[43,54,24,22,55,25],[10,45,15,67,46,16],[19,148,118,6,149,119],[18,75,47,31,76,48],[34,54,24,34,55,25],[20,45,15,61,46,16]],t=function(e,t){let n={};return n.totalCount=e,n.dataCount=t,n},n={},r=function(t,n){switch(n){case Al.L:return e[(t-1)*4+0];case Al.M:return e[(t-1)*4+1];case Al.Q:return e[(t-1)*4+2];case Al.H:return e[(t-1)*4+3];default:return}};return n.getRSBlocks=function(e,n){let i=r(e,n);if(i===void 0)throw`bad rs block @ typeNumber:`+e+`/errorCorrectionLevel:`+n;let a=i.length/3,o=[];for(let e=0;e<a;e+=1){let n=i[e*3+0],r=i[e*3+1],a=i[e*3+2];for(let e=0;e<n;e+=1)o.push(t(r,a))}return o},n}(),Il=function(){let e=[],t=0,n={};return n.getBuffer=function(){return e},n.getAt=function(t){let n=Math.floor(t/8);return(e[n]>>>7-t%8&1)==1},n.put=function(e,t){for(let r=0;r<t;r+=1)n.putBit((e>>>t-r-1&1)==1)},n.getLengthInBits=function(){return t},n.putBit=function(n){let r=Math.floor(t/8);e.length<=r&&e.push(0),n&&(e[r]|=128>>>t%8),t+=1},n},Ll=function(e){let t=kl.MODE_NUMBER,n=e,r={};r.getMode=function(){return t},r.getLength=function(e){return n.length},r.write=function(e){let t=n,r=0;for(;r+2<t.length;)e.put(i(t.substring(r,r+3)),10),r+=3;r<t.length&&(t.length-r==1?e.put(i(t.substring(r,r+1)),4):t.length-r==2&&e.put(i(t.substring(r,r+2)),7))};let i=function(e){let t=0;for(let n=0;n<e.length;n+=1)t=t*10+a(e.charAt(n));return t},a=function(e){if(`0`<=e&&e<=`9`)return e.charCodeAt(0)-48;throw`illegal char :`+e};return r},Rl=function(e){let t=kl.MODE_ALPHA_NUM,n=e,r={};r.getMode=function(){return t},r.getLength=function(e){return n.length},r.write=function(e){let t=n,r=0;for(;r+1<t.length;)e.put(i(t.charAt(r))*45+i(t.charAt(r+1)),11),r+=2;r<t.length&&e.put(i(t.charAt(r)),6)};let i=function(e){if(`0`<=e&&e<=`9`)return e.charCodeAt(0)-48;if(`A`<=e&&e<=`Z`)return e.charCodeAt(0)-65+10;switch(e){case` `:return 36;case`$`:return 37;case`%`:return 38;case`*`:return 39;case`+`:return 40;case`-`:return 41;case`.`:return 42;case`/`:return 43;case`:`:return 44;default:throw`illegal char :`+e}};return r},zl=function(e){let t=kl.MODE_8BIT_BYTE,n=Ol.stringToBytes(e),r={};return r.getMode=function(){return t},r.getLength=function(e){return n.length},r.write=function(e){for(let t=0;t<n.length;t+=1)e.put(n[t],8)},r},Bl=function(e){let t=kl.MODE_KANJI,n=Ol.stringToBytes;(function(e,t){let r=n(e);if(r.length!=2||(r[0]<<8|r[1])!=t)throw`sjis not supported.`})(`友`,38726);let r=n(e),i={};return i.getMode=function(){return t},i.getLength=function(e){return~~(r.length/2)},i.write=function(e){let t=r,n=0;for(;n+1<t.length;){let r=(255&t[n])<<8|255&t[n+1];if(33088<=r&&r<=40956)r-=33088;else if(57408<=r&&r<=60351)r-=49472;else throw`illegal char at `+(n+1)+`/`+r;r=(r>>>8&255)*192+(r&255),e.put(r,13),n+=2}if(n<t.length)throw`illegal char at `+(n+1)},i},Vl=function(){let e=[],t={};return t.writeByte=function(t){e.push(t&255)},t.writeShort=function(e){t.writeByte(e),t.writeByte(e>>>8)},t.writeBytes=function(e,n,r){n||=0,r||=e.length;for(let i=0;i<r;i+=1)t.writeByte(e[i+n])},t.writeString=function(e){for(let n=0;n<e.length;n+=1)t.writeByte(e.charCodeAt(n))},t.toByteArray=function(){return e},t.toString=function(){let t=``;t+=`[`;for(let n=0;n<e.length;n+=1)n>0&&(t+=`,`),t+=e[n];return t+=`]`,t},t},Hl=function(){let e=0,t=0,n=0,r=``,i={},a=function(e){r+=String.fromCharCode(o(e&63))},o=function(e){if(e<0)throw`n:`+e;if(e<26)return 65+e;if(e<52)return 97+(e-26);if(e<62)return 48+(e-52);if(e==62)return 43;if(e==63)return 47;throw`n:`+e};return i.writeByte=function(r){for(e=e<<8|r&255,t+=8,n+=1;t>=6;)a(e>>>t-6),t-=6},i.flush=function(){if(t>0&&(a(e<<6-t),e=0,t=0),n%3!=0){let e=3-n%3;for(let t=0;t<e;t+=1)r+=`=`}},i.toString=function(){return r},i},Ul=function(e){let t=e,n=0,r=0,i=0,a={};a.read=function(){for(;i<8;){if(n>=t.length){if(i==0)return-1;throw`unexpected end of file./`+i}let e=t.charAt(n);if(n+=1,e==`=`)return i=0,-1;e.match(/^\s$/)||(r=r<<6|o(e.charCodeAt(0)),i+=6)}let e=r>>>i-8&255;return i-=8,e};let o=function(e){if(65<=e&&e<=90)return e-65;if(97<=e&&e<=122)return e-97+26;if(48<=e&&e<=57)return e-48+52;if(e==43)return 62;if(e==47)return 63;throw`c:`+e};return a},Wl=function(e,t){let n=e,r=t,i=Array(e*t),a={};a.setPixel=function(e,t,r){i[t*n+e]=r},a.write=function(e){e.writeString(`GIF87a`),e.writeShort(n),e.writeShort(r),e.writeByte(128),e.writeByte(0),e.writeByte(0),e.writeByte(0),e.writeByte(0),e.writeByte(0),e.writeByte(255),e.writeByte(255),e.writeByte(255),e.writeString(`,`),e.writeShort(0),e.writeShort(0),e.writeShort(n),e.writeShort(r),e.writeByte(0);let t=s(2);e.writeByte(2);let i=0;for(;t.length-i>255;)e.writeByte(255),e.writeBytes(t,i,255),i+=255;e.writeByte(t.length-i),e.writeBytes(t,i,t.length-i),e.writeByte(0),e.writeString(`;`)};let o=function(e){let t=e,n=0,r=0,i={};return i.write=function(e,i){if(e>>>i)throw`length over`;for(;n+i>=8;)t.writeByte(255&(e<<n|r)),i-=8-n,e>>>=8-n,r=0,n=0;r=e<<n|r,n+=i},i.flush=function(){n>0&&t.writeByte(r)},i},s=function(e){let t=1<<e,n=(1<<e)+1,r=e+1,a=c();for(let e=0;e<t;e+=1)a.add(String.fromCharCode(e));a.add(String.fromCharCode(t)),a.add(String.fromCharCode(n));let s=Vl(),l=o(s);l.write(t,r);let u=0,d=String.fromCharCode(i[u]);for(u+=1;u<i.length;){let e=String.fromCharCode(i[u]);u+=1,a.contains(d+e)?d+=e:(l.write(a.indexOf(d),r),a.size()<4095&&(a.size()==1<<r&&(r+=1),a.add(d+e)),d=e)}return l.write(a.indexOf(d),r),l.write(n,r),l.flush(),s.toByteArray()},c=function(){let e={},t=0,n={};return n.add=function(r){if(n.contains(r))throw`dup key:`+r;e[r]=t,t+=1},n.size=function(){return t},n.indexOf=function(t){return e[t]},n.contains=function(t){return e[t]!==void 0},n};return a},Gl=function(e,t,n){let r=Wl(e,t);for(let i=0;i<t;i+=1)for(let t=0;t<e;t+=1)r.setPixel(t,i,n(t,i));let i=Vl();r.write(i);let a=Hl(),o=i.toByteArray();for(let e=0;e<o.length;e+=1)a.writeByte(o[e]);return a.flush(),`data:image/gif;base64,`+a};Ol.stringToBytes;function Kl(){let e=navigator.userAgent,t=/iPhone/.test(e)?`iPhone`:/iPad/.test(e)?`iPad`:/Android/.test(e)?`Android`:/Mac/.test(e)?`Mac`:/Windows/.test(e)?`Windows`:/Linux/.test(e)?`Linux`:`device`,n=/Edg\//.test(e)?`Edge`:/Firefox\//.test(e)?`Firefox`:/Chrome\//.test(e)?`Chrome`:/Safari\//.test(e)?`Safari`:``;return n?`${t} · ${n}`:t}function ql(){let[e,t]=(0,v.useState)(``),[n,r]=(0,v.useState)(Kl),[i,a]=(0,v.useState)(!1),[o,s]=(0,v.useState)(``),c=async()=>{a(!0),s(``);let t=await A.request(`devices.pair`,{body:{code:e,name:n}}).catch(()=>null);if(t?.ok)return location.reload();a(!1),s(t?M(t):`could not reach kraftwerk`)};return(0,F.jsxs)(`main`,{className:`mx-auto flex min-h-screen w-full max-w-[420px] flex-col justify-center gap-5 px-4`,children:[(0,F.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,F.jsx)(I,{name:`phonelink_lock`,className:`text-[32px] text-fg-2`}),(0,F.jsx)(nt,{size:`lg`,children:`Pair this device`}),(0,F.jsxs)(`p`,{className:`m-0 text-sm leading-relaxed text-fg-2`,children:[`This kraftwerk runs on another machine. On that machine, run `,(0,F.jsx)(`code`,{children:`kraftwerk devices pair`}),` or open settings → devices, and enter the code here. You pair once; it stays paired until it is removed there.`]})]}),(0,F.jsxs)(`form`,{className:`flex flex-col gap-3.5`,onSubmit:e=>{e.preventDefault(),c()},children:[(0,F.jsx)(Z,{label:`pairing code`,children:(0,F.jsx)(X,{value:e,onChange:e=>t(e.target.value.toUpperCase()),placeholder:`ABCD-EF23`,autoFocus:!0,autoComplete:`one-time-code`,autoCapitalize:`characters`,"aria-label":`pairing code`,className:`font-mono tracking-widest`})}),(0,F.jsx)(Z,{label:`name of this device`,hint:`how it shows in the list of paired devices`,children:(0,F.jsx)(X,{value:n,onChange:e=>r(e.target.value),"aria-label":`device name`})}),o&&(0,F.jsx)(q,{tone:`bad`,children:o}),(0,F.jsx)(V,{variant:`primary`,type:`submit`,busy:i,disabled:!e.trim(),children:`pair`})]})]})}function Jl({children:e}){return O()?(0,F.jsx)(ql,{}):(0,F.jsx)(F.Fragment,{children:e})}function Yl({text:e,size:t=176}){let n=(0,v.useMemo)(()=>{let t=Ol(0,`M`);t.addData(e),t.make();let n=t.getModuleCount(),r=``;for(let e=0;e<n;e++)for(let i=0;i<n;i++)t.isDark(e,i)&&(r+=`M${i+4} ${e+4}h1v1h-1z`);return{d:r,n:n+8}},[e]);return(0,F.jsx)(`svg`,{viewBox:`0 0 ${n.n} ${n.n}`,width:t,height:t,role:`img`,"aria-label":`pairing QR code`,className:`rounded-lg bg-white text-black`,shapeRendering:`crispEdges`,children:(0,F.jsx)(`path`,{d:n.d,fill:`currentColor`})})}function Xl({onError:e}){let t=N(`devices.relay`,{},{interval:1e4}),[n,r]=(0,v.useState)(!1);if(!t)return null;let i=async()=>{r(!0);let n=await A.request(`devices.setRelay`,{body:{enabled:!t.enabled}}).catch(()=>null);r(!1),n&&!n.ok&&e(M(n))},a=t.enabled?t.daemon?t.state===`connected`?`connected${t.clients?` · ${t.clients} device${t.clients===1?``:`s`} now`:``}`:t.state===`error`?`not connected: ${t.error??`unknown error`}`:`connecting…`:"on — the daemon connects it (this kraftwerk is not the daemon: `kraftwerk daemon`)":`off — devices reach this machine on your network only`;return(0,F.jsx)(ct,{children:(0,F.jsx)(st,{icon:t.enabled?`public`:`public_off`,title:`reach this machine from anywhere`,"data-relay":t.enabled?t.state:`off`,action:(0,F.jsx)(V,{size:`sm`,busy:n,variant:t.enabled?void 0:`primary`,onClick:()=>void i(),children:t.enabled?`turn off`:`turn on`}),children:(0,F.jsxs)(`span`,{className:`text-xs text-fg-2`,children:[a,t.enabled&&t.fingerprint&&(0,F.jsxs)(F.Fragment,{children:[` · machine key `,(0,F.jsx)(`code`,{children:t.fingerprint})]}),` — through the kraftwerk relay, end to end encrypted: it cannot read along`]})})})}function Zl(){let e=N(`devices.self`,{},{interval:6e4}),t=e?.trust===`local`,n=N(`devices.list`,t?{}:null,{interval:15e3}),[r,i]=(0,v.useState)(null),[a,o]=(0,v.useState)(``);if(!e)return null;if(!t)return(0,F.jsx)(J,{title:`devices`,children:(0,F.jsx)(ct,{children:(0,F.jsx)(st,{icon:`phonelink_lock`,title:`this browser is paired as “${e.device?.name}”`,children:(0,F.jsx)(`span`,{className:`text-xs text-fg-2`,children:`devices are managed on the machine kraftwerk runs on`})})})});let s=async()=>{o(``);let e=await A.request(`devices.code`).catch(()=>null);e?.ok?i(e.data):o(e?M(e):`could not make a code`)},c=async(e,t)=>{if(!window.confirm(`Unpair “${t}”? It loses access at once.`))return;let n=await A.request(`devices.revoke`,{id:e}).catch(()=>null);n&&!n.ok&&o(M(n))};return(0,F.jsxs)(J,{title:`devices`,actions:(0,F.jsx)(V,{size:`sm`,icon:`add_link`,onClick:()=>void s(),children:`pair a device`}),children:[r&&(0,F.jsxs)(vt,{className:`border-b border-line`,children:[(0,F.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-3`,children:[(0,F.jsx)(`span`,{className:`font-mono text-[22px] font-semibold tracking-widest text-fg`,"aria-label":`pairing code`,children:r.code}),(0,F.jsxs)(`span`,{className:`text-xs text-fg-2`,children:[`once, until `,new Date(r.expiresAt).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})]})]}),r.remote&&(0,F.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4`,children:[(0,F.jsx)(Yl,{text:r.remote}),(0,F.jsxs)(`span`,{className:`max-w-[28ch] text-sm text-fg-2`,children:[`From anywhere: scan this with the phone's camera, or open `,(0,F.jsx)(`a`,{href:r.remote,target:`_blank`,rel:`noreferrer`,children:`the pairing link`}),` on it. It carries the code — treat it like a password.`]})]}),r.urls.length?(0,F.jsxs)(`span`,{className:`text-sm text-fg-2`,children:[`On the device, open `,r.urls.map((e,t)=>(0,F.jsxs)(`span`,{children:[t>0&&` or `,(0,F.jsx)(`code`,{children:e})]},e)),` and enter the code.`]}):r.remote?null:(0,F.jsxs)(`span`,{className:`text-sm text-fg-2`,children:[`This kraftwerk only listens on this machine. Restart it with `,(0,F.jsx)(`code`,{children:`kraftwerk ui --lan`}),` to reach it from your network (or use a tunnel), then enter the code on the device — or turn on “reach this machine from anywhere”.`]})]}),(0,F.jsx)(Xl,{onError:o}),a&&(0,F.jsx)(`div`,{className:`px-[18px] pt-3`,children:(0,F.jsx)(q,{tone:`bad`,children:a})}),n&&n.devices.length===0&&!r&&(0,F.jsx)(K,{icon:`devices`,children:`no paired devices — a phone or another computer can use this kraftwerk once paired`}),n&&n.devices.length>0&&(0,F.jsx)(ct,{children:n.devices.map(e=>(0,F.jsx)(st,{icon:`devices`,title:e.name,"data-device":e.id,action:(0,F.jsx)(V,{size:`sm`,variant:`danger`,icon:`link_off`,onClick:()=>void c(e.id,e.name),"aria-label":`unpair ${e.name}`,children:`unpair`}),children:(0,F.jsxs)(`span`,{className:`text-xs text-fg-2`,children:[`paired `,Ge(e.createdAt),` · `,e.lastSeenAt?`last seen ${Ge(e.lastSeenAt)}`:`not used yet`]})},e.id))})]})}var Ql={enabled:!1,remote:`origin`,branch:``,interval:`300`,autosync:`pull`};function $l(e){let t=e.config.git;return t?{enabled:t.enabled!==!1,remote:t.remote??Ql.remote,branch:t.branch??``,interval:String(t.interval??Ql.interval),autosync:t.autosync??Ql.autosync}:Ql}var eu={enabled:!1,root:``};function tu(e){let t=e.config.repos;return t?{enabled:t.enabled!==!1,root:t.root??``}:eu}function nu(e){let t=e.config.vibeables;return t?{enabled:t.enabled!==!1,root:t.root??``}:eu}function ru(e){let t=e.config.projects;return t?{enabled:t.enabled!==!1,root:t.root??``}:eu}function iu(){let[e,t]=(0,v.useState)(null),[n,r]=(0,v.useState)(!1);if((0,v.useEffect)(()=>{let e=!0,n=()=>A.call(`meta.get`).then(n=>e&&n.cloud&&t(n.cloud)).catch(()=>{});n();let r=setInterval(n,1e4);return()=>{e=!1,clearInterval(r)}},[]),!e)return null;let i=e.state===`connected`?e.account?`claimed`:`unclaimed`:e.state,a=e.state===`connected`&&e.account?`ok`:e.state===`error`?`bad`:`neutral`;return(0,F.jsx)(J,{title:(0,F.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[`cloud `,(0,F.jsx)(W,{tone:a,children:i})]}),actions:e.url&&(0,F.jsxs)(`a`,{className:Ze(`secondary`,`sm`),href:e.url,target:`_blank`,rel:`noreferrer`,children:[(0,F.jsx)(I,{name:`cloud`,className:`ms-sm`}),` open the cloud`]}),children:(0,F.jsxs)(vt,{children:[e.state===`off`&&(0,F.jsxs)(G,{children:[`Off — `,(0,F.jsx)(`code`,{children:`cloud.enabled: false`}),` in kraftwerk.yml or `,(0,F.jsx)(`code`,{children:`KRAFTWERK_CLOUD_URL=off`}),` in the environment. Every other`,(0,F.jsx)(`code`,{children:` kraftwerk ui`}),` registers with the kraftwerk cloud on start, so its owner can see it running from anywhere.`]}),e.state===`connecting`&&(0,F.jsxs)(G,{children:[`Registering with `,e.url,` …`]}),e.state===`error`&&(0,F.jsxs)(G,{children:[`Could not reach `,e.url,`: `,e.error,`. Retrying every `,e.interval??60,`s — the UI works as before meanwhile.`]}),e.state===`connected`&&e.account&&(0,F.jsxs)(G,{children:[`This workspace is registered at `,(0,F.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noreferrer`,children:e.url}),` under `,(0,F.jsx)(`strong`,{children:e.account}),`. Last heartbeat `,e.lastSeen?new Date(e.lastSeen).toLocaleTimeString():`pending`,`.`]}),e.state===`connected`&&!e.account&&(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(G,{children:[`Registered at `,(0,F.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noreferrer`,children:e.url}),`, not yet under an account. Sign in there and enter this code — or open the link — and the workspace shows up under `,(0,F.jsx)(`em`,{children:`My instances`}),`:`]}),(0,F.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2.5`,children:[(0,F.jsx)(`code`,{className:`rounded-control border border-line bg-surface-2 px-3 py-1.5 font-mono text-lg tracking-[0.12em] text-fg`,children:e.claimCode??`…`}),e.claimCode&&(0,F.jsx)(V,{size:`sm`,icon:`content_copy`,onClick:()=>{navigator.clipboard.writeText(e.claimCode),r(!0),setTimeout(()=>r(!1),1500)},children:n?`copied`:`copy`}),e.claimUrl&&(0,F.jsxs)(`a`,{className:Ze(`primary`,`sm`),href:e.claimUrl,target:`_blank`,rel:`noreferrer`,children:[(0,F.jsx)(I,{name:`link`,className:`ms-sm`}),` claim in the cloud`]})]}),(0,F.jsxs)(G,{children:[`A claim made there reaches this instance with the next heartbeat (every `,e.interval??60,`s). To keep this workspace out of the cloud, set `,(0,F.jsx)(`code`,{children:`cloud.enabled: false`}),` in kraftwerk.yml.`]})]})]})})}function au(){let[e,t]=(0,v.useState)(null),[n,r]=(0,v.useState)(``),[i,a]=(0,v.useState)(``),[o,s]=(0,v.useState)(``),[c,l]=(0,v.useState)([]),[u,d]=(0,v.useState)(Ql),[f,p]=(0,v.useState)(eu),[m,h]=(0,v.useState)(eu),[g,_]=(0,v.useState)(eu),[y,b]=(0,v.useState)(!1),[x,S]=(0,v.useState)(!1),[C,w]=(0,v.useState)(!1),[T,E]=(0,v.useState)(``);(0,v.useEffect)(()=>{A.call(`settings.get`).then(e=>{t(e),r(e.config.name??``),a(e.config.icon??``),s(e.config.color??``),l(e.config.switcher??[]),d($l(e)),p(tu(e)),h(nu(e)),_(ru(e))}).catch(()=>E(`could not load settings`))},[]);let D=()=>{b(!0),w(!1),E(``)};async function O(){S(!0),E(``);try{let e=await A.request(`settings.save`,{body:{name:n,icon:i,color:o,switcher:c,git:{...u,interval:u.interval===``?void 0:Number(u.interval)},repos:f,vibeables:m,projects:g}});if(!e.ok)throw Error(e.error||`save failed`);let r=e.data;t(r),l(r.config.switcher??[]),d($l(r)),p(tu(r)),h(nu(r)),_(ru(r)),b(!1),w(!0)}catch(e){E(e.message)}finally{S(!1)}}let k=(e,t)=>{l(n=>n.map((n,r)=>r===e?{...n,...t}:n)),D()},j=e=>{d(t=>({...t,...e})),D()},ee=e=>{p(t=>({...t,...e})),D()},M=e=>{h(t=>({...t,...e})),D()},N=e=>{_(t=>({...t,...e})),D()};if(!e)return(0,F.jsx)(K,{children:T||`loading…`});let P=[[`port`,String(e.resolved.port),`kraftwerk ui listens here (CLI --port wins)`],[`workflows`,e.resolved.workflowsRoot??`— none found`,`workflow definitions`],[`output`,e.resolved.outputDir,`run artifacts`],[`knowledge`,e.config.knowledge??`knowledge`,`OKF knowledge bundles`],[`agents`,e.config.agents??`agents`,`agent definitions`],[`skills`,e.config.skills??`skills`,`workspace skills`]];return(0,F.jsxs)(`div`,{className:`mx-auto flex w-full max-w-[860px] flex-col gap-4`,children:[(0,F.jsx)(rt,{icon:(0,F.jsx)(I,{name:`settings`,className:`text-[28px] text-fg-2`}),title:`Settings`,actions:(0,F.jsxs)(F.Fragment,{children:[T&&(0,F.jsx)(q,{tone:`bad`,children:T}),C&&!y&&(0,F.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[12.5px] text-ok`,children:[(0,F.jsx)(I,{name:`check`,className:`ms-sm`}),` saved`]}),(0,F.jsx)(V,{variant:`primary`,busy:x,disabled:!y,onClick:()=>void O(),children:x?`saving…`:`save changes`})]})}),(0,F.jsx)(J,{title:`workspace`,children:(0,F.jsxs)(vt,{children:[(0,F.jsxs)(yt,{children:[(0,F.jsx)(Z,{label:`icon`,className:`w-[90px]`,children:(0,F.jsx)(X,{value:i,placeholder:`🤖`,onChange:e=>{a(e.target.value),D()}})}),(0,F.jsx)(Z,{label:`name`,className:`min-w-40 flex-1`,children:(0,F.jsx)(X,{value:n,placeholder:`my workspace`,onChange:e=>{r(e.target.value),D()}})}),(0,F.jsxs)(`label`,{className:`flex w-[130px] flex-col gap-1.5`,title:`Accent in the workspace switcher; empty = derived from the folder`,children:[(0,F.jsx)(`span`,{className:`text-sm font-semibold text-fg`,children:`color`}),(0,F.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,F.jsx)(`input`,{type:`color`,"aria-label":`pick a color`,className:`h-9 w-10 flex-none cursor-pointer rounded-control border border-line bg-surface p-0.5`,value:/^#[0-9a-f]{6}$/i.test(o)?o:`#888888`,onChange:e=>{s(e.target.value),D()}}),(0,F.jsx)(X,{className:`min-w-0 px-2`,value:o,placeholder:`auto`,onChange:e=>{s(e.target.value),D()}})]})]})]}),(0,F.jsx)(G,{children:`Shown in the header, browser tab and to other workspaces discovering this one.`})]})}),(0,F.jsx)(J,{title:`workspace switcher`,actions:(0,F.jsx)(V,{size:`sm`,icon:`add`,onClick:()=>{l(e=>[...e,{name:``,url:`http://localhost:`}]),D()},children:`add entry`}),children:(0,F.jsxs)(vt,{children:[c.length===0&&(0,F.jsx)(G,{children:`No manual entries.`}),c.map((e,t)=>(0,F.jsxs)(yt,{children:[(0,F.jsx)(Z,{label:`icon`,className:`w-[70px]`,children:(0,F.jsx)(X,{value:e.icon??``,placeholder:`•`,onChange:e=>k(t,{icon:e.target.value})})}),(0,F.jsx)(Z,{label:`name`,className:`min-w-32 flex-1`,children:(0,F.jsx)(X,{value:e.name,placeholder:`other workspace`,onChange:e=>k(t,{name:e.target.value})})}),(0,F.jsx)(Z,{label:`url`,className:`min-w-40 flex-[1.4]`,children:(0,F.jsx)(X,{value:e.url,placeholder:`http://localhost:1982`,onChange:e=>k(t,{url:e.target.value})})}),(0,F.jsx)(H,{icon:`close`,label:`remove entry`,className:`mb-0.5`,onClick:()=>{l(e=>e.filter((e,n)=>n!==t)),D()}})]},t)),(0,F.jsx)(G,{children:`Running workspaces on this machine are discovered automatically — manual entries are for remote instances or extra links.`})]})}),(0,F.jsx)(J,{title:`git sync`,actions:(0,F.jsx)(V,{size:`sm`,icon:`account_tree`,href:`/git`,children:`open git`}),children:(0,F.jsxs)(vt,{children:[(0,F.jsx)(bt,{checked:u.enabled,onChange:e=>j({enabled:e}),children:`sync workflows, knowledge, agents and skills with a git remote`}),u.enabled&&(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(yt,{children:[(0,F.jsx)(Z,{label:`remote`,className:`min-w-32 flex-1`,children:(0,F.jsx)(X,{value:u.remote,placeholder:`origin`,onChange:e=>j({remote:e.target.value})})}),(0,F.jsx)(Z,{label:`branch`,className:`min-w-32 flex-1`,children:(0,F.jsx)(X,{value:u.branch,placeholder:`checked-out branch`,onChange:e=>j({branch:e.target.value})})}),(0,F.jsx)(Z,{label:`interval (s)`,className:`w-[120px]`,children:(0,F.jsx)(X,{type:`number`,min:0,step:1,value:u.interval,placeholder:`300`,onChange:e=>j({interval:e.target.value})})}),(0,F.jsx)(Z,{label:`autosync`,className:`w-[150px]`,children:(0,F.jsxs)(_t,{value:u.autosync,onChange:e=>j({autosync:e.target.value}),children:[(0,F.jsx)(`option`,{value:`pull`,children:`fetch and pull`}),(0,F.jsx)(`option`,{value:`off`,children:`fetch only`})]})})]}),(0,F.jsx)(G,{children:`The interval fetches in the background (0 turns the timer off); with autosync on it also fast-forwards when behind and nothing is modified locally. Commit and push stay manual on the git screen.`})]})]})}),(0,F.jsx)(J,{title:`repositories`,actions:(0,F.jsx)(V,{size:`sm`,icon:`source`,href:`/repos`,children:`open repositories`}),children:(0,F.jsxs)(vt,{children:[(0,F.jsx)(bt,{checked:f.enabled,onChange:e=>ee({enabled:e}),children:`keep git repositories the agents work on under one folder`}),f.enabled&&(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(Z,{label:`repos root`,children:(0,F.jsx)(X,{value:f.root,placeholder:`repos`,onChange:e=>ee({root:e.target.value})})}),(0,F.jsxs)(G,{children:[`Relative to the project root. Saving creates the folder and adds it to .gitignore; every agent gets the list of clones as context and can add more with `,(0,F.jsx)(`code`,{children:`kraftwerk repos add`}),`.`]})]})]})}),(0,F.jsx)(J,{title:`apps (vibeables)`,actions:(0,F.jsx)(V,{size:`sm`,icon:`web`,href:`/vibeables`,children:`open apps`}),children:(0,F.jsxs)(vt,{children:[(0,F.jsx)(bt,{checked:m.enabled,onChange:e=>M({enabled:e}),children:`build small apps live in a chat, with a preview pane next to the thread`}),m.enabled&&(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(Z,{label:`vibeables root`,children:(0,F.jsx)(X,{value:m.root,placeholder:`kraftwerk-data/vibeables`,onChange:e=>M({root:e.target.value})})}),(0,F.jsxs)(G,{children:[`Relative to the project root, one folder per app. Part of the workspace: versioned with it on the git screen, not git-ignored. Every chat gets a `,(0,F.jsx)(`b`,{children:`vibeable`}),` button; the agent then works inside the app folder.`]})]})]})}),(0,F.jsx)(J,{title:`projects`,actions:(0,F.jsx)(V,{size:`sm`,icon:`folder_special`,href:`/projects`,children:`open projects`}),children:(0,F.jsxs)(vt,{children:[(0,F.jsx)(bt,{checked:g.enabled,onChange:e=>N({enabled:e}),children:`gather a goal, its brief, systems of record and links in one folder, and chat inside it`}),g.enabled&&(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(Z,{label:`projects root`,children:(0,F.jsx)(X,{value:g.root,placeholder:`kraftwerk-data/projects`,onChange:e=>N({root:e.target.value})})}),(0,F.jsx)(G,{children:`Relative to the project root, one folder per project (project.yml, brief.md, state.md, log.md). Part of the workspace: versioned with it on the git screen. A chat opened in a project starts with all of it as context.`})]})]})}),(0,F.jsx)(iu,{}),(0,F.jsx)(Zl,{}),(0,F.jsxs)(J,{title:`paths & port`,actions:(0,F.jsx)(`code`,{className:`max-w-[60%] truncate text-2xs text-fg-2`,title:e.configPath,children:e.exists?e.configPath:`${e.configPath} (not created yet)`}),children:[(0,F.jsx)(`div`,{className:`flex flex-col pt-1.5 pb-2.5`,children:P.map(([e,t,n])=>(0,F.jsxs)(`div`,{className:`grid grid-cols-[110px_1fr] items-baseline gap-x-3.5 gap-y-px border-line/55 px-[18px] py-2 [&+&]:border-t`,children:[(0,F.jsx)(et,{children:e}),(0,F.jsx)(`code`,{className:`text-xs break-all`,children:t}),(0,F.jsx)(`span`,{className:`col-start-2 text-2xs text-fg-2`,children:n})]},e))}),(0,F.jsxs)(G,{className:`px-[18px] pb-3.5`,children:[`Read-only here — edit `,(0,F.jsx)(`code`,{children:`kraftwerk.yml`}),` directly to change these.`]})]})]})}var ou={agents:{label:`agents`,icon:`smart_toy`},"agent-skills":{label:`agent skills`,icon:`extension`},projects:{label:`projects`,icon:`folder`},workflows:{label:`workflows`,icon:`account_tree`},knowledge:{label:`knowledge bundles`,icon:`menu_book`},vibeables:{label:`apps`,icon:`web`},channels:{label:`channels`,icon:`forum`},repos:{label:`repositories`,icon:`source`},chats:{label:`chats`,icon:`chat`},runs:{label:`runs`,icon:`play_circle`}};function su(){let[e,t]=(0,v.useState)(null),[n,r]=(0,v.useState)(``),[i,a]=(0,v.useState)(null),[o,s]=(0,v.useState)(null),c=(0,v.useCallback)(async()=>{let e=await A.request(`trash.list`).catch(()=>null);e?.ok?t(e.data):r(e?.status===404?`this server has no trash yet — restart it after updating`:`could not load the trash`)},[]);(0,v.useEffect)(()=>{c()},[c]);let l=async(e,t)=>{a(t),r(``),s(null);try{let n=e===`empty`?(await A.request(`trash.empty`)).error:M(await A.request(`trash.${e}`,{body:{id:t}}));if(n)throw Error(n)}catch(e){r(e.message)}finally{a(null),c()}},u=e?.entries??[],d=[...new Set(u.map(e=>e.kind))].sort((e,t)=>Object.keys(ou).indexOf(e)-Object.keys(ou).indexOf(t));return(0,F.jsxs)(it,{className:`px-6 py-6`,children:[(0,F.jsx)(rt,{icon:(0,F.jsx)(I,{name:`delete`,className:`text-[28px] text-fg-2`}),title:`Trash`,sub:e?`${u.length} item${u.length===1?``:`s`}`:void 0,actions:u.length>0&&(o===`*`?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(V,{variant:`danger`,icon:`delete_forever`,onClick:()=>void l(`empty`,`*`),children:[`delete all `,u.length,` for good`]}),(0,F.jsx)(V,{variant:`quiet`,onClick:()=>s(null),children:`cancel`})]}):(0,F.jsx)(V,{variant:`danger`,icon:`delete_forever`,disabled:!!i,onClick:()=>s(`*`),children:`empty trash`}))}),n&&(0,F.jsx)(q,{tone:`bad`,children:n}),!e&&!n&&(0,F.jsx)(J,{children:(0,F.jsx)(K,{children:`loading…`})}),e&&u.length===0&&(0,F.jsx)(J,{children:(0,F.jsx)(K,{icon:`delete`,children:`The trash is empty. What you delete lands here first.`})}),d.map(e=>(0,F.jsx)(J,{title:ou[e]?.label??e,actions:(0,F.jsxs)(`code`,{className:`text-xs text-fg-2`,children:[`trash/`,e,`/`]}),children:(0,F.jsx)(`div`,{className:`p-1.5`,children:u.filter(t=>t.kind===e).map(t=>(0,F.jsx)(Y,{className:`trash-row`,leading:(0,F.jsx)(I,{name:ou[e]?.icon??`draft`,className:`ms-sm`}),title:t.name,sub:(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`span`,{className:`font-mono`,children:t.from}),` · `,(0,F.jsxs)(`span`,{title:t.trashedAt,children:[`deleted `,Ge(t.trashedAt)]})]}),meta:(0,F.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,F.jsx)(V,{size:`sm`,variant:`secondary`,icon:`restore_from_trash`,busy:i===t.id,disabled:!!i,onClick:()=>void l(`restore`,t.id),title:`Put it back at ${t.from}`,children:`restore`}),o===t.id?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(V,{size:`sm`,variant:`danger`,icon:`delete_forever`,onClick:()=>void l(`purge`,t.id),children:`delete for good`}),(0,F.jsx)(V,{size:`sm`,variant:`quiet`,onClick:()=>s(null),children:`cancel`})]}):(0,F.jsx)(V,{size:`sm`,variant:`danger`,icon:`delete_forever`,disabled:!!i,onClick:()=>s(t.id),children:`delete`})]})},t.id))})},e)),e&&(0,F.jsxs)(`p`,{className:`m-0 text-sm text-fg-2`,children:[`The trash lives in `,(0,F.jsx)(`code`,{children:e.root}),`, kept out of the workspace git. From the terminal:`,` `,(0,F.jsx)(`code`,{children:`kraftwerk trash`}),`, `,(0,F.jsx)(`code`,{children:`kraftwerk trash restore <id>`}),`, `,(0,F.jsx)(`code`,{children:`kraftwerk trash empty`}),`.`]})]})}var cu=(e,t,n=!1)=>A.url(`files.raw`,{query:{scope:e,path:t,download:n}}),lu=(e,t=``,n)=>`/files/${encodeURIComponent(e)}${t?`/${t.split(`/`).map(encodeURIComponent).join(`/`)}`:``}${n?`?file=${encodeURIComponent(n)}`:``}`,uu=`inline-grid size-7 shrink-0 place-items-center rounded-control text-fg-2 no-underline hover:bg-surface-2 hover:text-fg`,du=`whitespace-nowrap border-b border-line px-2.5 py-1.5 text-left`;function fu({here:e,onClick:t,children:n}){return(0,F.jsx)(`button`,{type:`button`,onClick:t,className:P(`cursor-pointer rounded-md border-0 bg-transparent px-1 py-0.5 font-[inherit] hover:bg-surface-2 hover:text-fg`,e?`font-semibold text-fg`:`text-fg-2`),children:n})}function pu(e){if(e.type===`dir`)return`folder`;let t=e.mime??``;return t.startsWith(`image/`)?`image`:t===`application/pdf`?`picture_as_pdf`:t.startsWith(`video/`)?`movie`:t.startsWith(`audio/`)?`music_note`:/csv|tab-separated|spreadsheet/.test(t)?`table`:/zip/.test(t)?`folder_zip`:/presentation/.test(t)?`slideshow`:t.startsWith(`text/`)||/json|yaml|xml|wordprocessing/.test(t)?`description`:`draft`}function mu({scope:e,dir:t,file:n}){let[r,i]=(0,v.useState)(null),[a,o]=(0,v.useState)(0);(0,v.useEffect)(()=>{A.call(`files.scopes`).then(e=>i(e.scopes),()=>i([]))},[a]);let s=(r??[]).filter(e=>e.scope!==`workspace`);return(0,F.jsxs)(`div`,{className:`runs-screen files-screen`,children:[(0,F.jsxs)(`aside`,{className:`runs-side`,children:[(0,F.jsx)(wt,{title:`files`}),(0,F.jsxs)(Et,{children:[(r??[]).filter(e=>e.scope===`workspace`).map(t=>(0,F.jsx)(hu,{s:t,active:e===t.scope,icon:`home_storage`},t.scope)),s.length>0&&(0,F.jsx)(wt,{title:`projects`,divided:!0}),s.map(t=>(0,F.jsx)(hu,{s:t,active:e===t.scope,icon:`folder_special`},t.scope))]})]}),(0,F.jsx)(`div`,{className:`runs-main min-w-0`,children:(0,F.jsx)(gu,{scope:e,dir:t,file:n,onOpen:(t,n)=>B(lu(e,t,n)),onChanged:()=>o(e=>e+1)},e)})]})}function hu({s:e,active:t,icon:n}){return(0,F.jsx)(Y,{href:lu(e.scope),active:t,size:`sm`,leading:(0,F.jsx)(I,{name:n,className:`ms-sm`}),title:e.label,sub:(0,F.jsxs)(`span`,{className:`font-mono`,children:[e.root,`/`]}),meta:e.count})}function gu({scope:e,dir:t,file:n,onOpen:r,onChanged:i,compact:a=!1}){let[o,s]=(0,v.useState)(null),[c,l]=(0,v.useState)(``),[u,d]=(0,v.useState)(``),[f,p]=(0,v.useState)(!1),[m,h]=(0,v.useState)(null),[g,_]=(0,v.useState)(null),[y,b]=(0,v.useState)(null),x=(0,v.useRef)(null),S=(0,v.useCallback)(async()=>{let n=await A.request(`files.list`,{query:{scope:e,path:t}}).catch(()=>null);if(!n?.ok||!n.data||typeof n.data!=`object`){l(n?.error??`could not load the folder`),s(null);return}l(``),s(n.data)},[e,t]);(0,v.useEffect)(()=>{S();let e=setInterval(()=>void S(),1e4);return()=>clearInterval(e)},[S]);let C=async()=>{await S(),i?.()};async function w(n){let r=[...n];if(r.length){l(``);for(let[n,i]of r.entries()){d(r.length>1?`uploading ${n+1} of ${r.length}…`:`uploading ${i.name}…`);let a=await A.request(`files.upload`,{query:{scope:e,path:t},headers:{"x-file-name":encodeURIComponent(i.name),"content-type":i.type||`application/octet-stream`},body:i}).catch(()=>null);a?.ok||l(a?.error??`could not upload ${i.name}`)}d(``),await C()}}async function T(n){let r=n.trim();if(h(null),!r)return;let i=M(await A.request(`files.mkdir`,{body:{scope:e,path:t?`${t}/${r}`:r}}));i&&l(i),await C()}async function E(i,a){_(null);let o=a.trim();if(!o||o===i.split(`/`).pop())return;let s=i.includes(`/`)?`${i.slice(0,i.lastIndexOf(`/`))}/${o}`:o,c=M(await A.request(`files.move`,{body:{scope:e,from:i,to:s}}));c?l(c):n===i&&r(t,s),await C()}async function D(i){b(null);let a=await A.request(`files.delete`,{query:{scope:e,path:i}}).catch(()=>null);a?.ok||l(a?.error??`could not delete`),n===i&&r(t),await C()}let O=t?t.split(`/`):[],k=n?o?.entries.find(e=>e.path===n):void 0,j=!(a&&n);return(0,F.jsxs)(`div`,{className:P(`files-browser h-full min-h-0`,a?`flex flex-col gap-2 px-1.5 py-1`:P(`grid gap-4`,n?`grid-cols-1 min-[900px]:grid-cols-[minmax(280px,1fr)_minmax(0,1.3fr)]`:`grid-cols-1`)),children:[j&&(0,F.jsxs)(`div`,{className:P(`flex min-h-0 flex-col rounded-card outline-2 -outline-offset-2 outline-dashed transition-colors`,f?`bg-accent/5 outline-accent`:`outline-transparent`),onDragOver:e=>{[...e.dataTransfer.types].includes(`Files`)&&(e.preventDefault(),p(!0))},onDragLeave:e=>{e.currentTarget.contains(e.relatedTarget)||p(!1)},onDrop:e=>{e.preventDefault(),p(!1),w(e.dataTransfer.files)},children:[(0,F.jsxs)(`div`,{className:P(`flex items-center gap-1`,a?`px-1 pb-1.5 pt-0.5`:`px-0.5 pb-2.5 pt-1`),children:[(0,F.jsxs)(`nav`,{className:P(`flex min-w-0 flex-wrap items-center`,a?`text-sm`:`text-md`),"aria-label":`Folder`,children:[(0,F.jsx)(fu,{here:!O.length,onClick:()=>r(``),children:o?.label??(e===`workspace`?`Workspace`:e.replace(/^project:/,``))}),O.map((e,t)=>(0,F.jsxs)(`span`,{className:`inline-flex items-center text-fg-2`,children:[(0,F.jsx)(I,{name:`chevron_right`,className:`ms-sm`}),(0,F.jsx)(fu,{here:t===O.length-1,onClick:()=>r(O.slice(0,t+1).join(`/`)),children:e})]},t))]}),(0,F.jsx)(`span`,{className:`flex-1`}),a?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(H,{icon:`create_new_folder`,label:`New folder`,size:`sm`,onClick:()=>h(``)}),(0,F.jsx)(H,{icon:`upload`,label:`Upload files`,size:`sm`,onClick:()=>x.current?.click()})]}):(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(V,{variant:`quiet`,size:`sm`,icon:`create_new_folder`,onClick:()=>h(``),title:`New folder`,children:`folder`}),(0,F.jsx)(V,{variant:`quiet`,size:`sm`,icon:`upload`,onClick:()=>x.current?.click(),title:`Upload files`,children:`upload`})]}),(0,F.jsx)(`input`,{ref:x,type:`file`,multiple:!0,hidden:!0,"aria-label":`Upload files`,onChange:e=>e.target.files&&void w(e.target.files)})]}),u&&(0,F.jsx)(q,{children:u}),c&&(0,F.jsx)(q,{tone:`bad`,children:c}),(0,F.jsxs)(`div`,{className:`files-list flex min-h-0 flex-1 flex-col gap-px overflow-y-auto`,role:`list`,children:[m!==null&&(0,F.jsxs)(`div`,{className:`flex items-center gap-2.5 px-2.5 py-1`,children:[(0,F.jsx)(I,{name:`create_new_folder`,className:`text-[20px] text-fg-2`}),(0,F.jsx)(X,{className:`h-8`,autoFocus:!0,value:m,placeholder:`folder name`,"aria-label":`Folder name`,onChange:e=>h(e.target.value),onKeyDown:e=>{e.key===`Enter`&&T(m),e.key===`Escape`&&h(null)},onBlur:()=>void T(m)})]}),o?.entries.map(i=>g?.path===i.path?(0,F.jsxs)(`div`,{role:`listitem`,className:`flex items-center gap-2.5 px-2.5 py-1`,children:[(0,F.jsx)(I,{name:pu(i),className:`text-[20px] text-fg-2`}),(0,F.jsx)(X,{className:`h-8`,autoFocus:!0,value:g.name,"aria-label":`New name`,onChange:e=>_({path:i.path,name:e.target.value}),onKeyDown:e=>{e.key===`Enter`&&E(i.path,g.name),e.key===`Escape`&&_(null)},onBlur:()=>void E(i.path,g.name)})]},i.path):(0,F.jsx)(`div`,{role:`listitem`,children:(0,F.jsx)(Y,{className:`files-row`,active:i.path===n,onClick:()=>i.type===`dir`?r(i.path):r(t,i.path),label:i.name,leading:(0,F.jsx)(I,{name:pu(i),className:`text-[20px] text-fg-2`}),title:(0,F.jsx)(`span`,{className:`font-normal`,children:i.name}),titleExtra:i.local?(0,F.jsx)(`span`,{className:`text-xs font-normal text-fg-2`,title:`Over 25 MB: kept out of git, stays on this machine`,children:`local only`}):void 0,meta:(0,F.jsxs)(F.Fragment,{children:[i.type===`dir`?`${i.count??0} file${i.count===1?``:`s`}`:Ue(i.size??0),!a&&` · ${Ge(i.modifiedAt)}`]}),actions:(0,F.jsxs)(F.Fragment,{children:[i.type===`file`&&(0,F.jsx)(`a`,{className:`inline-grid size-7 place-items-center rounded-control text-fg-2 no-underline hover:bg-surface-2 hover:text-fg`,href:cu(e,i.path,!0),title:`Download`,"aria-label":`Download ${i.name}`,children:(0,F.jsx)(I,{name:`download`,className:`ms-sm`})}),(0,F.jsx)(H,{icon:`edit`,size:`sm`,label:`Rename ${i.name}`,onClick:()=>_({path:i.path,name:i.name})}),y===i.path?(0,F.jsx)(V,{variant:`danger`,size:`sm`,autoFocus:!0,onClick:()=>void D(i.path),onBlur:()=>b(null),children:`move to trash`}):(0,F.jsx)(H,{icon:`delete`,size:`sm`,label:`Delete ${i.name}`,onClick:()=>b(i.path)})]})})},i.path)),o&&o.entries.length===0&&m===null&&(0,F.jsxs)(K,{icon:`upload_file`,action:(0,F.jsxs)(`span`,{className:`font-mono text-2xs opacity-80`,children:[o.root,`/`,t?`${t}/`:``]}),children:[`Drop files here, or`,` `,(0,F.jsx)(`button`,{type:`button`,className:`cursor-pointer border-0 bg-transparent p-0 font-[inherit] text-accent underline`,onClick:()=>x.current?.click(),children:`choose some`}),`.`]}),!o&&!c&&(0,F.jsx)(K,{children:`loading…`})]})]}),n&&(0,F.jsx)(_u,{scope:e,path:n,entry:k,onClose:()=>r(t),compact:a})]})}function _u({scope:e,path:t,entry:n,onClose:r,compact:i}){let a=n?.mime??``,o=t.split(`/`).pop()??t,s=cu(e,t),c=/^text\/|json|yaml|xml/.test(a)&&!/html/.test(a),[l,u]=(0,v.useState)(null);(0,v.useEffect)(()=>{if(u(null),!c||(n?.size??0)>2e6)return;let e=!0;return fetch(s,{cache:`no-store`}).then(e=>e.text()).then(t=>e&&u(t)).catch(()=>{}),()=>{e=!1}},[s,c,n?.size]);let d;return d=n?a.startsWith(`image/`)?(0,F.jsx)(`img`,{className:`m-auto max-h-full max-w-full flex-none object-contain p-4`,src:s,alt:o}):a===`application/pdf`?(0,F.jsx)(`iframe`,{className:P(`w-full border-0 bg-white`,i?`min-h-[60vh]`:`min-h-[70vh]`),src:s,title:o}):a.startsWith(`video/`)?(0,F.jsx)(`video`,{className:`m-auto max-h-full w-full p-4`,src:s,controls:!0}):a.startsWith(`audio/`)?(0,F.jsx)(`audio`,{className:`m-auto w-full p-4`,src:s,controls:!0}):c&&l!==null?/markdown/.test(a)?(0,F.jsx)(`div`,{className:`md-body files-md px-5 py-4`,dangerouslySetInnerHTML:{__html:da.sanitize(Fr.parse(l,{async:!1}))}}):/csv|tab-separated/.test(a)?(0,F.jsx)(vu,{text:l,tab:/tab-separated/.test(a)}):(0,F.jsx)(`pre`,{className:`files-text m-0 whitespace-pre-wrap p-4 font-mono text-[12.5px] leading-relaxed [overflow-wrap:anywhere]`,children:l}):c&&(n.size??0)<=2e6?(0,F.jsx)(K,{children:`loading…`}):(0,F.jsx)(K,{icon:pu(n),action:(0,F.jsx)(V,{variant:`primary`,size:`sm`,icon:`download`,href:void 0,onClick:()=>window.location.href=cu(e,t,!0),children:`download`}),children:`No preview for this kind of file.`}):(0,F.jsx)(K,{children:`loading…`}),(0,F.jsxs)(`section`,{className:P(`files-preview flex min-h-0 flex-col overflow-hidden rounded-card border border-line bg-surface`,i&&`min-h-[60vh]`),"aria-label":`Preview of ${o}`,children:[(0,F.jsxs)(`div`,{className:`flex items-center gap-1.5 border-b border-line px-3 py-2`,children:[i&&(0,F.jsx)(H,{icon:`arrow_back`,label:`Back to the folder`,size:`sm`,onClick:r}),(0,F.jsx)(`span`,{className:`min-w-0 truncate text-base font-semibold`,title:t,children:o}),n?.size!==void 0&&(0,F.jsx)(`span`,{className:`shrink-0 text-xs tabular-nums text-fg-2`,children:Ue(n.size)}),(0,F.jsx)(`span`,{className:`flex-1`}),(0,F.jsx)(`a`,{className:uu,href:s,target:`_blank`,rel:`noopener`,title:`Open in a new tab`,"aria-label":`Open in a new tab`,children:(0,F.jsx)(I,{name:`open_in_new`,className:`ms-sm`})}),(0,F.jsx)(`a`,{className:uu,href:cu(e,t,!0),title:`Download`,"aria-label":`Download`,children:(0,F.jsx)(I,{name:`download`,className:`ms-sm`})}),!i&&(0,F.jsx)(H,{icon:`close`,label:`Close the preview`,size:`sm`,onClick:r})]}),(0,F.jsx)(`div`,{className:`flex min-h-0 flex-1 overflow-auto [&>*]:flex-1`,children:d})]})}function vu({text:e,tab:t}){let n=t?` `:e.split(`
222
+ `}return f.substring(0,f.length-1)},c.renderTo2dContext=function(e,t){t||=2;let n=c.getModuleCount();for(let r=0;r<n;r++)for(let i=0;i<n;i++)e.fillStyle=c.isDark(r,i)?`black`:`white`,e.fillRect(i*t,r*t,t,t)},c};kl.stringToBytes=function(e){let t=[];for(let n=0;n<e.length;n+=1){let r=e.charCodeAt(n);t.push(r&255)}return t},kl.createStringToBytes=function(e,t){let n=function(){let n=Wl(e),r=function(){let e=n.read();if(e==-1)throw`eof`;return e},i=0,a={};for(;;){let e=n.read();if(e==-1)break;let t=r(),o=r(),s=r(),c=String.fromCharCode(e<<8|t);a[c]=o<<8|s,i+=1}if(i!=t)throw i+` != `+t;return a}();return function(e){let t=[];for(let r=0;r<e.length;r+=1){let i=e.charCodeAt(r);if(i<128)t.push(i);else{let i=n[e.charAt(r)];typeof i==`number`?(i&255)==i?t.push(i):(t.push(i>>>8),t.push(i&255)):t.push(63)}}return t}};var Al={MODE_NUMBER:1,MODE_ALPHA_NUM:2,MODE_8BIT_BYTE:4,MODE_KANJI:8},jl={L:1,M:0,Q:3,H:2},Ml={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7},Nl=function(){let e=[[],[6,18],[6,22],[6,26],[6,30],[6,34],[6,22,38],[6,24,42],[6,26,46],[6,28,50],[6,30,54],[6,32,58],[6,34,62],[6,26,46,66],[6,26,48,70],[6,26,50,74],[6,30,54,78],[6,30,56,82],[6,30,58,86],[6,34,62,90],[6,28,50,72,94],[6,26,50,74,98],[6,30,54,78,102],[6,28,54,80,106],[6,32,58,84,110],[6,30,58,86,114],[6,34,62,90,118],[6,26,50,74,98,122],[6,30,54,78,102,126],[6,26,52,78,104,130],[6,30,56,82,108,134],[6,34,60,86,112,138],[6,30,58,86,114,142],[6,34,62,90,118,146],[6,30,54,78,102,126,150],[6,24,50,76,102,128,154],[6,28,54,80,106,132,158],[6,32,58,84,110,136,162],[6,26,54,82,110,138,166],[6,30,58,86,114,142,170]],t=1335,n=7973,r={},i=function(e){let t=0;for(;e!=0;)t+=1,e>>>=1;return t};return r.getBCHTypeInfo=function(e){let n=e<<10;for(;i(n)-i(t)>=0;)n^=t<<i(n)-i(t);return(e<<10|n)^21522},r.getBCHTypeNumber=function(e){let t=e<<12;for(;i(t)-i(n)>=0;)t^=n<<i(t)-i(n);return e<<12|t},r.getPatternPosition=function(t){return e[t-1]},r.getMaskFunction=function(e){switch(e){case Ml.PATTERN000:return function(e,t){return(e+t)%2==0};case Ml.PATTERN001:return function(e,t){return e%2==0};case Ml.PATTERN010:return function(e,t){return t%3==0};case Ml.PATTERN011:return function(e,t){return(e+t)%3==0};case Ml.PATTERN100:return function(e,t){return(Math.floor(e/2)+Math.floor(t/3))%2==0};case Ml.PATTERN101:return function(e,t){return e*t%2+e*t%3==0};case Ml.PATTERN110:return function(e,t){return(e*t%2+e*t%3)%2==0};case Ml.PATTERN111:return function(e,t){return(e*t%3+(e+t)%2)%2==0};default:throw`bad maskPattern:`+e}},r.getErrorCorrectPolynomial=function(e){let t=Fl([1],0);for(let n=0;n<e;n+=1)t=t.multiply(Fl([1,Pl.gexp(n)],0));return t},r.getLengthInBits=function(e,t){if(1<=t&&t<10)switch(e){case Al.MODE_NUMBER:return 10;case Al.MODE_ALPHA_NUM:return 9;case Al.MODE_8BIT_BYTE:return 8;case Al.MODE_KANJI:return 8;default:throw`mode:`+e}else if(t<27)switch(e){case Al.MODE_NUMBER:return 12;case Al.MODE_ALPHA_NUM:return 11;case Al.MODE_8BIT_BYTE:return 16;case Al.MODE_KANJI:return 10;default:throw`mode:`+e}else if(t<41)switch(e){case Al.MODE_NUMBER:return 14;case Al.MODE_ALPHA_NUM:return 13;case Al.MODE_8BIT_BYTE:return 16;case Al.MODE_KANJI:return 12;default:throw`mode:`+e}else throw`type:`+t},r.getLostPoint=function(e){let t=e.getModuleCount(),n=0;for(let r=0;r<t;r+=1)for(let i=0;i<t;i+=1){let a=0,o=e.isDark(r,i);for(let n=-1;n<=1;n+=1)if(!(r+n<0||t<=r+n))for(let s=-1;s<=1;s+=1)i+s<0||t<=i+s||(n!=0||s!=0)&&o==e.isDark(r+n,i+s)&&(a+=1);a>5&&(n+=3+a-5)}for(let r=0;r<t-1;r+=1)for(let i=0;i<t-1;i+=1){let t=0;e.isDark(r,i)&&(t+=1),e.isDark(r+1,i)&&(t+=1),e.isDark(r,i+1)&&(t+=1),e.isDark(r+1,i+1)&&(t+=1),(t==0||t==4)&&(n+=3)}for(let r=0;r<t;r+=1)for(let i=0;i<t-6;i+=1)e.isDark(r,i)&&!e.isDark(r,i+1)&&e.isDark(r,i+2)&&e.isDark(r,i+3)&&e.isDark(r,i+4)&&!e.isDark(r,i+5)&&e.isDark(r,i+6)&&(n+=40);for(let r=0;r<t;r+=1)for(let i=0;i<t-6;i+=1)e.isDark(i,r)&&!e.isDark(i+1,r)&&e.isDark(i+2,r)&&e.isDark(i+3,r)&&e.isDark(i+4,r)&&!e.isDark(i+5,r)&&e.isDark(i+6,r)&&(n+=40);let r=0;for(let n=0;n<t;n+=1)for(let i=0;i<t;i+=1)e.isDark(i,n)&&(r+=1);let i=Math.abs(100*r/t/t-50)/5;return n+=i*10,n},r}(),Pl=function(){let e=Array(256),t=Array(256);for(let t=0;t<8;t+=1)e[t]=1<<t;for(let t=8;t<256;t+=1)e[t]=e[t-4]^e[t-5]^e[t-6]^e[t-8];for(let n=0;n<255;n+=1)t[e[n]]=n;let n={};return n.glog=function(e){if(e<1)throw`glog(`+e+`)`;return t[e]},n.gexp=function(t){for(;t<0;)t+=255;for(;t>=256;)t-=255;return e[t]},n}(),Fl=function(e,t){if(e.length===void 0)throw e.length+`/`+t;let n=function(){let n=0;for(;n<e.length&&e[n]==0;)n+=1;let r=Array(e.length-n+t);for(let t=0;t<e.length-n;t+=1)r[t]=e[t+n];return r}(),r={};return r.getAt=function(e){return n[e]},r.getLength=function(){return n.length},r.multiply=function(e){let t=Array(r.getLength()+e.getLength()-1);for(let n=0;n<r.getLength();n+=1)for(let i=0;i<e.getLength();i+=1)t[n+i]^=Pl.gexp(Pl.glog(r.getAt(n))+Pl.glog(e.getAt(i)));return Fl(t,0)},r.mod=function(e){if(r.getLength()-e.getLength()<0)return r;let t=Pl.glog(r.getAt(0))-Pl.glog(e.getAt(0)),n=Array(r.getLength());for(let e=0;e<r.getLength();e+=1)n[e]=r.getAt(e);for(let r=0;r<e.getLength();r+=1)n[r]^=Pl.gexp(Pl.glog(e.getAt(r))+t);return Fl(n,0).mod(e)},r},Il=function(){let e=[[1,26,19],[1,26,16],[1,26,13],[1,26,9],[1,44,34],[1,44,28],[1,44,22],[1,44,16],[1,70,55],[1,70,44],[2,35,17],[2,35,13],[1,100,80],[2,50,32],[2,50,24],[4,25,9],[1,134,108],[2,67,43],[2,33,15,2,34,16],[2,33,11,2,34,12],[2,86,68],[4,43,27],[4,43,19],[4,43,15],[2,98,78],[4,49,31],[2,32,14,4,33,15],[4,39,13,1,40,14],[2,121,97],[2,60,38,2,61,39],[4,40,18,2,41,19],[4,40,14,2,41,15],[2,146,116],[3,58,36,2,59,37],[4,36,16,4,37,17],[4,36,12,4,37,13],[2,86,68,2,87,69],[4,69,43,1,70,44],[6,43,19,2,44,20],[6,43,15,2,44,16],[4,101,81],[1,80,50,4,81,51],[4,50,22,4,51,23],[3,36,12,8,37,13],[2,116,92,2,117,93],[6,58,36,2,59,37],[4,46,20,6,47,21],[7,42,14,4,43,15],[4,133,107],[8,59,37,1,60,38],[8,44,20,4,45,21],[12,33,11,4,34,12],[3,145,115,1,146,116],[4,64,40,5,65,41],[11,36,16,5,37,17],[11,36,12,5,37,13],[5,109,87,1,110,88],[5,65,41,5,66,42],[5,54,24,7,55,25],[11,36,12,7,37,13],[5,122,98,1,123,99],[7,73,45,3,74,46],[15,43,19,2,44,20],[3,45,15,13,46,16],[1,135,107,5,136,108],[10,74,46,1,75,47],[1,50,22,15,51,23],[2,42,14,17,43,15],[5,150,120,1,151,121],[9,69,43,4,70,44],[17,50,22,1,51,23],[2,42,14,19,43,15],[3,141,113,4,142,114],[3,70,44,11,71,45],[17,47,21,4,48,22],[9,39,13,16,40,14],[3,135,107,5,136,108],[3,67,41,13,68,42],[15,54,24,5,55,25],[15,43,15,10,44,16],[4,144,116,4,145,117],[17,68,42],[17,50,22,6,51,23],[19,46,16,6,47,17],[2,139,111,7,140,112],[17,74,46],[7,54,24,16,55,25],[34,37,13],[4,151,121,5,152,122],[4,75,47,14,76,48],[11,54,24,14,55,25],[16,45,15,14,46,16],[6,147,117,4,148,118],[6,73,45,14,74,46],[11,54,24,16,55,25],[30,46,16,2,47,17],[8,132,106,4,133,107],[8,75,47,13,76,48],[7,54,24,22,55,25],[22,45,15,13,46,16],[10,142,114,2,143,115],[19,74,46,4,75,47],[28,50,22,6,51,23],[33,46,16,4,47,17],[8,152,122,4,153,123],[22,73,45,3,74,46],[8,53,23,26,54,24],[12,45,15,28,46,16],[3,147,117,10,148,118],[3,73,45,23,74,46],[4,54,24,31,55,25],[11,45,15,31,46,16],[7,146,116,7,147,117],[21,73,45,7,74,46],[1,53,23,37,54,24],[19,45,15,26,46,16],[5,145,115,10,146,116],[19,75,47,10,76,48],[15,54,24,25,55,25],[23,45,15,25,46,16],[13,145,115,3,146,116],[2,74,46,29,75,47],[42,54,24,1,55,25],[23,45,15,28,46,16],[17,145,115],[10,74,46,23,75,47],[10,54,24,35,55,25],[19,45,15,35,46,16],[17,145,115,1,146,116],[14,74,46,21,75,47],[29,54,24,19,55,25],[11,45,15,46,46,16],[13,145,115,6,146,116],[14,74,46,23,75,47],[44,54,24,7,55,25],[59,46,16,1,47,17],[12,151,121,7,152,122],[12,75,47,26,76,48],[39,54,24,14,55,25],[22,45,15,41,46,16],[6,151,121,14,152,122],[6,75,47,34,76,48],[46,54,24,10,55,25],[2,45,15,64,46,16],[17,152,122,4,153,123],[29,74,46,14,75,47],[49,54,24,10,55,25],[24,45,15,46,46,16],[4,152,122,18,153,123],[13,74,46,32,75,47],[48,54,24,14,55,25],[42,45,15,32,46,16],[20,147,117,4,148,118],[40,75,47,7,76,48],[43,54,24,22,55,25],[10,45,15,67,46,16],[19,148,118,6,149,119],[18,75,47,31,76,48],[34,54,24,34,55,25],[20,45,15,61,46,16]],t=function(e,t){let n={};return n.totalCount=e,n.dataCount=t,n},n={},r=function(t,n){switch(n){case jl.L:return e[(t-1)*4+0];case jl.M:return e[(t-1)*4+1];case jl.Q:return e[(t-1)*4+2];case jl.H:return e[(t-1)*4+3];default:return}};return n.getRSBlocks=function(e,n){let i=r(e,n);if(i===void 0)throw`bad rs block @ typeNumber:`+e+`/errorCorrectionLevel:`+n;let a=i.length/3,o=[];for(let e=0;e<a;e+=1){let n=i[e*3+0],r=i[e*3+1],a=i[e*3+2];for(let e=0;e<n;e+=1)o.push(t(r,a))}return o},n}(),Ll=function(){let e=[],t=0,n={};return n.getBuffer=function(){return e},n.getAt=function(t){let n=Math.floor(t/8);return(e[n]>>>7-t%8&1)==1},n.put=function(e,t){for(let r=0;r<t;r+=1)n.putBit((e>>>t-r-1&1)==1)},n.getLengthInBits=function(){return t},n.putBit=function(n){let r=Math.floor(t/8);e.length<=r&&e.push(0),n&&(e[r]|=128>>>t%8),t+=1},n},Rl=function(e){let t=Al.MODE_NUMBER,n=e,r={};r.getMode=function(){return t},r.getLength=function(e){return n.length},r.write=function(e){let t=n,r=0;for(;r+2<t.length;)e.put(i(t.substring(r,r+3)),10),r+=3;r<t.length&&(t.length-r==1?e.put(i(t.substring(r,r+1)),4):t.length-r==2&&e.put(i(t.substring(r,r+2)),7))};let i=function(e){let t=0;for(let n=0;n<e.length;n+=1)t=t*10+a(e.charAt(n));return t},a=function(e){if(`0`<=e&&e<=`9`)return e.charCodeAt(0)-48;throw`illegal char :`+e};return r},zl=function(e){let t=Al.MODE_ALPHA_NUM,n=e,r={};r.getMode=function(){return t},r.getLength=function(e){return n.length},r.write=function(e){let t=n,r=0;for(;r+1<t.length;)e.put(i(t.charAt(r))*45+i(t.charAt(r+1)),11),r+=2;r<t.length&&e.put(i(t.charAt(r)),6)};let i=function(e){if(`0`<=e&&e<=`9`)return e.charCodeAt(0)-48;if(`A`<=e&&e<=`Z`)return e.charCodeAt(0)-65+10;switch(e){case` `:return 36;case`$`:return 37;case`%`:return 38;case`*`:return 39;case`+`:return 40;case`-`:return 41;case`.`:return 42;case`/`:return 43;case`:`:return 44;default:throw`illegal char :`+e}};return r},Bl=function(e){let t=Al.MODE_8BIT_BYTE,n=kl.stringToBytes(e),r={};return r.getMode=function(){return t},r.getLength=function(e){return n.length},r.write=function(e){for(let t=0;t<n.length;t+=1)e.put(n[t],8)},r},Vl=function(e){let t=Al.MODE_KANJI,n=kl.stringToBytes;(function(e,t){let r=n(e);if(r.length!=2||(r[0]<<8|r[1])!=t)throw`sjis not supported.`})(`友`,38726);let r=n(e),i={};return i.getMode=function(){return t},i.getLength=function(e){return~~(r.length/2)},i.write=function(e){let t=r,n=0;for(;n+1<t.length;){let r=(255&t[n])<<8|255&t[n+1];if(33088<=r&&r<=40956)r-=33088;else if(57408<=r&&r<=60351)r-=49472;else throw`illegal char at `+(n+1)+`/`+r;r=(r>>>8&255)*192+(r&255),e.put(r,13),n+=2}if(n<t.length)throw`illegal char at `+(n+1)},i},Hl=function(){let e=[],t={};return t.writeByte=function(t){e.push(t&255)},t.writeShort=function(e){t.writeByte(e),t.writeByte(e>>>8)},t.writeBytes=function(e,n,r){n||=0,r||=e.length;for(let i=0;i<r;i+=1)t.writeByte(e[i+n])},t.writeString=function(e){for(let n=0;n<e.length;n+=1)t.writeByte(e.charCodeAt(n))},t.toByteArray=function(){return e},t.toString=function(){let t=``;t+=`[`;for(let n=0;n<e.length;n+=1)n>0&&(t+=`,`),t+=e[n];return t+=`]`,t},t},Ul=function(){let e=0,t=0,n=0,r=``,i={},a=function(e){r+=String.fromCharCode(o(e&63))},o=function(e){if(e<0)throw`n:`+e;if(e<26)return 65+e;if(e<52)return 97+(e-26);if(e<62)return 48+(e-52);if(e==62)return 43;if(e==63)return 47;throw`n:`+e};return i.writeByte=function(r){for(e=e<<8|r&255,t+=8,n+=1;t>=6;)a(e>>>t-6),t-=6},i.flush=function(){if(t>0&&(a(e<<6-t),e=0,t=0),n%3!=0){let e=3-n%3;for(let t=0;t<e;t+=1)r+=`=`}},i.toString=function(){return r},i},Wl=function(e){let t=e,n=0,r=0,i=0,a={};a.read=function(){for(;i<8;){if(n>=t.length){if(i==0)return-1;throw`unexpected end of file./`+i}let e=t.charAt(n);if(n+=1,e==`=`)return i=0,-1;e.match(/^\s$/)||(r=r<<6|o(e.charCodeAt(0)),i+=6)}let e=r>>>i-8&255;return i-=8,e};let o=function(e){if(65<=e&&e<=90)return e-65;if(97<=e&&e<=122)return e-97+26;if(48<=e&&e<=57)return e-48+52;if(e==43)return 62;if(e==47)return 63;throw`c:`+e};return a},Gl=function(e,t){let n=e,r=t,i=Array(e*t),a={};a.setPixel=function(e,t,r){i[t*n+e]=r},a.write=function(e){e.writeString(`GIF87a`),e.writeShort(n),e.writeShort(r),e.writeByte(128),e.writeByte(0),e.writeByte(0),e.writeByte(0),e.writeByte(0),e.writeByte(0),e.writeByte(255),e.writeByte(255),e.writeByte(255),e.writeString(`,`),e.writeShort(0),e.writeShort(0),e.writeShort(n),e.writeShort(r),e.writeByte(0);let t=s(2);e.writeByte(2);let i=0;for(;t.length-i>255;)e.writeByte(255),e.writeBytes(t,i,255),i+=255;e.writeByte(t.length-i),e.writeBytes(t,i,t.length-i),e.writeByte(0),e.writeString(`;`)};let o=function(e){let t=e,n=0,r=0,i={};return i.write=function(e,i){if(e>>>i)throw`length over`;for(;n+i>=8;)t.writeByte(255&(e<<n|r)),i-=8-n,e>>>=8-n,r=0,n=0;r=e<<n|r,n+=i},i.flush=function(){n>0&&t.writeByte(r)},i},s=function(e){let t=1<<e,n=(1<<e)+1,r=e+1,a=c();for(let e=0;e<t;e+=1)a.add(String.fromCharCode(e));a.add(String.fromCharCode(t)),a.add(String.fromCharCode(n));let s=Hl(),l=o(s);l.write(t,r);let u=0,d=String.fromCharCode(i[u]);for(u+=1;u<i.length;){let e=String.fromCharCode(i[u]);u+=1,a.contains(d+e)?d+=e:(l.write(a.indexOf(d),r),a.size()<4095&&(a.size()==1<<r&&(r+=1),a.add(d+e)),d=e)}return l.write(a.indexOf(d),r),l.write(n,r),l.flush(),s.toByteArray()},c=function(){let e={},t=0,n={};return n.add=function(r){if(n.contains(r))throw`dup key:`+r;e[r]=t,t+=1},n.size=function(){return t},n.indexOf=function(t){return e[t]},n.contains=function(t){return e[t]!==void 0},n};return a},Kl=function(e,t,n){let r=Gl(e,t);for(let i=0;i<t;i+=1)for(let t=0;t<e;t+=1)r.setPixel(t,i,n(t,i));let i=Hl();r.write(i);let a=Ul(),o=i.toByteArray();for(let e=0;e<o.length;e+=1)a.writeByte(o[e]);return a.flush(),`data:image/gif;base64,`+a};kl.stringToBytes;function ql(){let e=navigator.userAgent,t=/iPhone/.test(e)?`iPhone`:/iPad/.test(e)?`iPad`:/Android/.test(e)?`Android`:/Mac/.test(e)?`Mac`:/Windows/.test(e)?`Windows`:/Linux/.test(e)?`Linux`:`device`,n=/Edg\//.test(e)?`Edge`:/Firefox\//.test(e)?`Firefox`:/Chrome\//.test(e)?`Chrome`:/Safari\//.test(e)?`Safari`:``;return n?`${t} · ${n}`:t}function Jl(){let[e,t]=(0,v.useState)(``),[n,r]=(0,v.useState)(ql),[i,a]=(0,v.useState)(!1),[o,s]=(0,v.useState)(``),c=async()=>{a(!0),s(``);let t=await A.request(`devices.pair`,{body:{code:e,name:n}}).catch(()=>null);if(t?.ok)return location.reload();a(!1),s(t?M(t):`could not reach kraftwerk`)};return(0,F.jsxs)(`main`,{className:`mx-auto flex min-h-screen w-full max-w-[420px] flex-col justify-center gap-5 px-4`,children:[(0,F.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,F.jsx)(I,{name:`phonelink_lock`,className:`text-[32px] text-fg-2`}),(0,F.jsx)(nt,{size:`lg`,children:`Pair this device`}),(0,F.jsxs)(`p`,{className:`m-0 text-sm leading-relaxed text-fg-2`,children:[`This kraftwerk runs on another machine. On that machine, run `,(0,F.jsx)(`code`,{children:`kraftwerk devices pair`}),` or open settings → devices, and enter the code here. You pair once; it stays paired until it is removed there.`]})]}),(0,F.jsxs)(`form`,{className:`flex flex-col gap-3.5`,onSubmit:e=>{e.preventDefault(),c()},children:[(0,F.jsx)(Z,{label:`pairing code`,children:(0,F.jsx)(X,{value:e,onChange:e=>t(e.target.value.toUpperCase()),placeholder:`ABCD-EF23`,autoFocus:!0,autoComplete:`one-time-code`,autoCapitalize:`characters`,"aria-label":`pairing code`,className:`font-mono tracking-widest`})}),(0,F.jsx)(Z,{label:`name of this device`,hint:`how it shows in the list of paired devices`,children:(0,F.jsx)(X,{value:n,onChange:e=>r(e.target.value),"aria-label":`device name`})}),o&&(0,F.jsx)(q,{tone:`bad`,children:o}),(0,F.jsx)(V,{variant:`primary`,type:`submit`,busy:i,disabled:!e.trim(),children:`pair`})]})]})}function Yl({children:e}){return O()?(0,F.jsx)(Jl,{}):(0,F.jsx)(F.Fragment,{children:e})}function Xl({text:e,size:t=176}){let n=(0,v.useMemo)(()=>{let t=kl(0,`M`);t.addData(e),t.make();let n=t.getModuleCount(),r=``;for(let e=0;e<n;e++)for(let i=0;i<n;i++)t.isDark(e,i)&&(r+=`M${i+4} ${e+4}h1v1h-1z`);return{d:r,n:n+8}},[e]);return(0,F.jsx)(`svg`,{viewBox:`0 0 ${n.n} ${n.n}`,width:t,height:t,role:`img`,"aria-label":`pairing QR code`,className:`rounded-lg bg-white text-black`,shapeRendering:`crispEdges`,children:(0,F.jsx)(`path`,{d:n.d,fill:`currentColor`})})}function Zl({onError:e}){let t=N(`devices.relay`,{},{interval:1e4}),[n,r]=(0,v.useState)(!1);if(!t)return null;let i=async()=>{r(!0);let n=await A.request(`devices.setRelay`,{body:{enabled:!t.enabled}}).catch(()=>null);r(!1),n&&!n.ok&&e(M(n))},a=t.enabled?t.daemon?t.state===`connected`?`connected${t.clients?` · ${t.clients} device${t.clients===1?``:`s`} now`:``}`:t.state===`error`?`not connected: ${t.error??`unknown error`}`:`connecting…`:"on — the daemon connects it (this kraftwerk is not the daemon: `kraftwerk daemon`)":`off — devices reach this machine on your network only`;return(0,F.jsx)(ct,{children:(0,F.jsx)(st,{icon:t.enabled?`public`:`public_off`,title:`reach this machine from anywhere`,"data-relay":t.enabled?t.state:`off`,action:(0,F.jsx)(V,{size:`sm`,busy:n,variant:t.enabled?void 0:`primary`,onClick:()=>void i(),children:t.enabled?`turn off`:`turn on`}),children:(0,F.jsxs)(`span`,{className:`text-xs text-fg-2`,children:[a,t.enabled&&t.fingerprint&&(0,F.jsxs)(F.Fragment,{children:[` · machine key `,(0,F.jsx)(`code`,{children:t.fingerprint})]}),` — through the kraftwerk relay, end to end encrypted: it cannot read along`]})})})}function Ql(){let e=N(`devices.self`,{},{interval:6e4}),t=e?.trust===`local`,n=N(`devices.list`,t?{}:null,{interval:15e3}),[r,i]=(0,v.useState)(null),[a,o]=(0,v.useState)(``);if(!e)return null;if(!t)return(0,F.jsx)(J,{title:`devices`,children:(0,F.jsx)(ct,{children:(0,F.jsx)(st,{icon:`phonelink_lock`,title:`this browser is paired as “${e.device?.name}”`,children:(0,F.jsx)(`span`,{className:`text-xs text-fg-2`,children:`devices are managed on the machine kraftwerk runs on`})})})});let s=async()=>{o(``);let e=await A.request(`devices.code`).catch(()=>null);e?.ok?i(e.data):o(e?M(e):`could not make a code`)},c=async(e,t)=>{if(!window.confirm(`Unpair “${t}”? It loses access at once.`))return;let n=await A.request(`devices.revoke`,{id:e}).catch(()=>null);n&&!n.ok&&o(M(n))};return(0,F.jsxs)(J,{title:`devices`,actions:(0,F.jsx)(V,{size:`sm`,icon:`add_link`,onClick:()=>void s(),children:`pair a device`}),children:[r&&(0,F.jsxs)(vt,{className:`border-b border-line`,children:[(0,F.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-3`,children:[(0,F.jsx)(`span`,{className:`font-mono text-[22px] font-semibold tracking-widest text-fg`,"aria-label":`pairing code`,children:r.code}),(0,F.jsxs)(`span`,{className:`text-xs text-fg-2`,children:[`once, until `,new Date(r.expiresAt).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})]})]}),r.remote&&(0,F.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4`,children:[(0,F.jsx)(Xl,{text:r.remote}),(0,F.jsxs)(`span`,{className:`max-w-[28ch] text-sm text-fg-2`,children:[`From anywhere: scan this with the phone's camera, or open `,(0,F.jsx)(`a`,{href:r.remote,target:`_blank`,rel:`noreferrer`,children:`the pairing link`}),` on it. It carries the code — treat it like a password.`]})]}),r.urls.length?(0,F.jsxs)(`span`,{className:`text-sm text-fg-2`,children:[`On the device, open `,r.urls.map((e,t)=>(0,F.jsxs)(`span`,{children:[t>0&&` or `,(0,F.jsx)(`code`,{children:e})]},e)),` and enter the code.`]}):r.remote?null:(0,F.jsxs)(`span`,{className:`text-sm text-fg-2`,children:[`This kraftwerk only listens on this machine. Restart it with `,(0,F.jsx)(`code`,{children:`kraftwerk ui --lan`}),` to reach it from your network (or use a tunnel), then enter the code on the device — or turn on “reach this machine from anywhere”.`]})]}),(0,F.jsx)(Zl,{onError:o}),a&&(0,F.jsx)(`div`,{className:`px-[18px] pt-3`,children:(0,F.jsx)(q,{tone:`bad`,children:a})}),n&&n.devices.length===0&&!r&&(0,F.jsx)(K,{icon:`devices`,children:`no paired devices — a phone or another computer can use this kraftwerk once paired`}),n&&n.devices.length>0&&(0,F.jsx)(ct,{children:n.devices.map(e=>(0,F.jsx)(st,{icon:`devices`,title:e.name,"data-device":e.id,action:(0,F.jsx)(V,{size:`sm`,variant:`danger`,icon:`link_off`,onClick:()=>void c(e.id,e.name),"aria-label":`unpair ${e.name}`,children:`unpair`}),children:(0,F.jsxs)(`span`,{className:`text-xs text-fg-2`,children:[`paired `,Ge(e.createdAt),` · `,e.lastSeenAt?`last seen ${Ge(e.lastSeenAt)}`:`not used yet`]})},e.id))})]})}var $l={enabled:!1,remote:`origin`,branch:``,interval:`300`,autosync:`pull`};function eu(e){let t=e.config.git;return t?{enabled:t.enabled!==!1,remote:t.remote??$l.remote,branch:t.branch??``,interval:String(t.interval??$l.interval),autosync:t.autosync??$l.autosync}:$l}var tu={enabled:!1,root:``};function nu(e){let t=e.config.repos;return t?{enabled:t.enabled!==!1,root:t.root??``}:tu}function ru(e){let t=e.config.vibeables;return t?{enabled:t.enabled!==!1,root:t.root??``}:tu}function iu(e){let t=e.config.projects;return t?{enabled:t.enabled!==!1,root:t.root??``}:tu}function au(){let[e,t]=(0,v.useState)(null),[n,r]=(0,v.useState)(!1);if((0,v.useEffect)(()=>{let e=!0,n=()=>A.call(`meta.get`).then(n=>e&&n.cloud&&t(n.cloud)).catch(()=>{});n();let r=setInterval(n,1e4);return()=>{e=!1,clearInterval(r)}},[]),!e)return null;let i=e.state===`connected`?e.account?`claimed`:`unclaimed`:e.state,a=e.state===`connected`&&e.account?`ok`:e.state===`error`?`bad`:`neutral`;return(0,F.jsx)(J,{title:(0,F.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[`cloud `,(0,F.jsx)(W,{tone:a,children:i})]}),actions:e.url&&(0,F.jsxs)(`a`,{className:Ze(`secondary`,`sm`),href:e.url,target:`_blank`,rel:`noreferrer`,children:[(0,F.jsx)(I,{name:`cloud`,className:`ms-sm`}),` open the cloud`]}),children:(0,F.jsxs)(vt,{children:[e.state===`off`&&(0,F.jsxs)(G,{children:[`Off — `,(0,F.jsx)(`code`,{children:`cloud.enabled: false`}),` in kraftwerk.yml or `,(0,F.jsx)(`code`,{children:`KRAFTWERK_CLOUD_URL=off`}),` in the environment. Every other`,(0,F.jsx)(`code`,{children:` kraftwerk ui`}),` registers with the kraftwerk cloud on start, so its owner can see it running from anywhere.`]}),e.state===`connecting`&&(0,F.jsxs)(G,{children:[`Registering with `,e.url,` …`]}),e.state===`error`&&(0,F.jsxs)(G,{children:[`Could not reach `,e.url,`: `,e.error,`. Retrying every `,e.interval??60,`s — the UI works as before meanwhile.`]}),e.state===`connected`&&e.account&&(0,F.jsxs)(G,{children:[`This workspace is registered at `,(0,F.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noreferrer`,children:e.url}),` under `,(0,F.jsx)(`strong`,{children:e.account}),`. Last heartbeat `,e.lastSeen?new Date(e.lastSeen).toLocaleTimeString():`pending`,`.`]}),e.state===`connected`&&!e.account&&(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(G,{children:[`Registered at `,(0,F.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noreferrer`,children:e.url}),`, not yet under an account. Sign in there and enter this code — or open the link — and the workspace shows up under `,(0,F.jsx)(`em`,{children:`My instances`}),`:`]}),(0,F.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2.5`,children:[(0,F.jsx)(`code`,{className:`rounded-control border border-line bg-surface-2 px-3 py-1.5 font-mono text-lg tracking-[0.12em] text-fg`,children:e.claimCode??`…`}),e.claimCode&&(0,F.jsx)(V,{size:`sm`,icon:`content_copy`,onClick:()=>{navigator.clipboard.writeText(e.claimCode),r(!0),setTimeout(()=>r(!1),1500)},children:n?`copied`:`copy`}),e.claimUrl&&(0,F.jsxs)(`a`,{className:Ze(`primary`,`sm`),href:e.claimUrl,target:`_blank`,rel:`noreferrer`,children:[(0,F.jsx)(I,{name:`link`,className:`ms-sm`}),` claim in the cloud`]})]}),(0,F.jsxs)(G,{children:[`A claim made there reaches this instance with the next heartbeat (every `,e.interval??60,`s). To keep this workspace out of the cloud, set `,(0,F.jsx)(`code`,{children:`cloud.enabled: false`}),` in kraftwerk.yml.`]})]})]})})}function ou(){let[e,t]=(0,v.useState)(null),[n,r]=(0,v.useState)(``),[i,a]=(0,v.useState)(``),[o,s]=(0,v.useState)(``),[c,l]=(0,v.useState)([]),[u,d]=(0,v.useState)($l),[f,p]=(0,v.useState)(tu),[m,h]=(0,v.useState)(tu),[g,_]=(0,v.useState)(tu),[y,b]=(0,v.useState)(!1),[x,S]=(0,v.useState)(!1),[C,w]=(0,v.useState)(!1),[T,E]=(0,v.useState)(``);(0,v.useEffect)(()=>{A.call(`settings.get`).then(e=>{t(e),r(e.config.name??``),a(e.config.icon??``),s(e.config.color??``),l(e.config.switcher??[]),d(eu(e)),p(nu(e)),h(ru(e)),_(iu(e))}).catch(()=>E(`could not load settings`))},[]);let D=()=>{b(!0),w(!1),E(``)};async function O(){S(!0),E(``);try{let e=await A.request(`settings.save`,{body:{name:n,icon:i,color:o,switcher:c,git:{...u,interval:u.interval===``?void 0:Number(u.interval)},repos:f,vibeables:m,projects:g}});if(!e.ok)throw Error(e.error||`save failed`);let r=e.data;t(r),l(r.config.switcher??[]),d(eu(r)),p(nu(r)),h(ru(r)),_(iu(r)),b(!1),w(!0)}catch(e){E(e.message)}finally{S(!1)}}let k=(e,t)=>{l(n=>n.map((n,r)=>r===e?{...n,...t}:n)),D()},j=e=>{d(t=>({...t,...e})),D()},ee=e=>{p(t=>({...t,...e})),D()},M=e=>{h(t=>({...t,...e})),D()},N=e=>{_(t=>({...t,...e})),D()};if(!e)return(0,F.jsx)(K,{children:T||`loading…`});let P=[[`port`,String(e.resolved.port),`kraftwerk ui listens here (CLI --port wins)`],[`workflows`,e.resolved.workflowsRoot??`— none found`,`workflow definitions`],[`output`,e.resolved.outputDir,`run artifacts`],[`knowledge`,e.config.knowledge??`knowledge`,`OKF knowledge bundles`],[`agents`,e.config.agents??`agents`,`agent definitions`],[`skills`,e.config.skills??`skills`,`workspace skills`]];return(0,F.jsxs)(`div`,{className:`mx-auto flex w-full max-w-[860px] flex-col gap-4`,children:[(0,F.jsx)(rt,{icon:(0,F.jsx)(I,{name:`settings`,className:`text-[28px] text-fg-2`}),title:`Settings`,actions:(0,F.jsxs)(F.Fragment,{children:[T&&(0,F.jsx)(q,{tone:`bad`,children:T}),C&&!y&&(0,F.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[12.5px] text-ok`,children:[(0,F.jsx)(I,{name:`check`,className:`ms-sm`}),` saved`]}),(0,F.jsx)(V,{variant:`primary`,busy:x,disabled:!y,onClick:()=>void O(),children:x?`saving…`:`save changes`})]})}),(0,F.jsx)(J,{title:`workspace`,children:(0,F.jsxs)(vt,{children:[(0,F.jsxs)(yt,{children:[(0,F.jsx)(Z,{label:`icon`,className:`w-[90px]`,children:(0,F.jsx)(X,{value:i,placeholder:`🤖`,onChange:e=>{a(e.target.value),D()}})}),(0,F.jsx)(Z,{label:`name`,className:`min-w-40 flex-1`,children:(0,F.jsx)(X,{value:n,placeholder:`my workspace`,onChange:e=>{r(e.target.value),D()}})}),(0,F.jsxs)(`label`,{className:`flex w-[130px] flex-col gap-1.5`,title:`Accent in the workspace switcher; empty = derived from the folder`,children:[(0,F.jsx)(`span`,{className:`text-sm font-semibold text-fg`,children:`color`}),(0,F.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,F.jsx)(`input`,{type:`color`,"aria-label":`pick a color`,className:`h-9 w-10 flex-none cursor-pointer rounded-control border border-line bg-surface p-0.5`,value:/^#[0-9a-f]{6}$/i.test(o)?o:`#888888`,onChange:e=>{s(e.target.value),D()}}),(0,F.jsx)(X,{className:`min-w-0 px-2`,value:o,placeholder:`auto`,onChange:e=>{s(e.target.value),D()}})]})]})]}),(0,F.jsx)(G,{children:`Shown in the header, browser tab and to other workspaces discovering this one.`})]})}),(0,F.jsx)(J,{title:`workspace switcher`,actions:(0,F.jsx)(V,{size:`sm`,icon:`add`,onClick:()=>{l(e=>[...e,{name:``,url:`http://localhost:`}]),D()},children:`add entry`}),children:(0,F.jsxs)(vt,{children:[c.length===0&&(0,F.jsx)(G,{children:`No manual entries.`}),c.map((e,t)=>(0,F.jsxs)(yt,{children:[(0,F.jsx)(Z,{label:`icon`,className:`w-[70px]`,children:(0,F.jsx)(X,{value:e.icon??``,placeholder:`•`,onChange:e=>k(t,{icon:e.target.value})})}),(0,F.jsx)(Z,{label:`name`,className:`min-w-32 flex-1`,children:(0,F.jsx)(X,{value:e.name,placeholder:`other workspace`,onChange:e=>k(t,{name:e.target.value})})}),(0,F.jsx)(Z,{label:`url`,className:`min-w-40 flex-[1.4]`,children:(0,F.jsx)(X,{value:e.url,placeholder:`http://localhost:1982`,onChange:e=>k(t,{url:e.target.value})})}),(0,F.jsx)(H,{icon:`close`,label:`remove entry`,className:`mb-0.5`,onClick:()=>{l(e=>e.filter((e,n)=>n!==t)),D()}})]},t)),(0,F.jsx)(G,{children:`Running workspaces on this machine are discovered automatically — manual entries are for remote instances or extra links.`})]})}),(0,F.jsx)(J,{title:`git sync`,actions:(0,F.jsx)(V,{size:`sm`,icon:`account_tree`,href:`/git`,children:`open git`}),children:(0,F.jsxs)(vt,{children:[(0,F.jsx)(bt,{checked:u.enabled,onChange:e=>j({enabled:e}),children:`sync workflows, knowledge, agents and skills with a git remote`}),u.enabled&&(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(yt,{children:[(0,F.jsx)(Z,{label:`remote`,className:`min-w-32 flex-1`,children:(0,F.jsx)(X,{value:u.remote,placeholder:`origin`,onChange:e=>j({remote:e.target.value})})}),(0,F.jsx)(Z,{label:`branch`,className:`min-w-32 flex-1`,children:(0,F.jsx)(X,{value:u.branch,placeholder:`checked-out branch`,onChange:e=>j({branch:e.target.value})})}),(0,F.jsx)(Z,{label:`interval (s)`,className:`w-[120px]`,children:(0,F.jsx)(X,{type:`number`,min:0,step:1,value:u.interval,placeholder:`300`,onChange:e=>j({interval:e.target.value})})}),(0,F.jsx)(Z,{label:`autosync`,className:`w-[150px]`,children:(0,F.jsxs)(_t,{value:u.autosync,onChange:e=>j({autosync:e.target.value}),children:[(0,F.jsx)(`option`,{value:`pull`,children:`fetch and pull`}),(0,F.jsx)(`option`,{value:`off`,children:`fetch only`})]})})]}),(0,F.jsx)(G,{children:`The interval fetches in the background (0 turns the timer off); with autosync on it also fast-forwards when behind and nothing is modified locally. Commit and push stay manual on the git screen.`})]})]})}),(0,F.jsx)(J,{title:`repositories`,actions:(0,F.jsx)(V,{size:`sm`,icon:`source`,href:`/repos`,children:`open repositories`}),children:(0,F.jsxs)(vt,{children:[(0,F.jsx)(bt,{checked:f.enabled,onChange:e=>ee({enabled:e}),children:`keep git repositories the agents work on under one folder`}),f.enabled&&(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(Z,{label:`repos root`,children:(0,F.jsx)(X,{value:f.root,placeholder:`repos`,onChange:e=>ee({root:e.target.value})})}),(0,F.jsxs)(G,{children:[`Relative to the project root. Saving creates the folder and adds it to .gitignore; every agent gets the list of clones as context and can add more with `,(0,F.jsx)(`code`,{children:`kraftwerk repos add`}),`.`]})]})]})}),(0,F.jsx)(J,{title:`apps (vibeables)`,actions:(0,F.jsx)(V,{size:`sm`,icon:`web`,href:`/vibeables`,children:`open apps`}),children:(0,F.jsxs)(vt,{children:[(0,F.jsx)(bt,{checked:m.enabled,onChange:e=>M({enabled:e}),children:`build small apps live in a chat, with a preview pane next to the thread`}),m.enabled&&(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(Z,{label:`vibeables root`,children:(0,F.jsx)(X,{value:m.root,placeholder:`kraftwerk-data/vibeables`,onChange:e=>M({root:e.target.value})})}),(0,F.jsxs)(G,{children:[`Relative to the project root, one folder per app. Part of the workspace: versioned with it on the git screen, not git-ignored. Every chat gets a `,(0,F.jsx)(`b`,{children:`vibeable`}),` button; the agent then works inside the app folder.`]})]})]})}),(0,F.jsx)(J,{title:`projects`,actions:(0,F.jsx)(V,{size:`sm`,icon:`folder_special`,href:`/projects`,children:`open projects`}),children:(0,F.jsxs)(vt,{children:[(0,F.jsx)(bt,{checked:g.enabled,onChange:e=>N({enabled:e}),children:`gather a goal, its brief, systems of record and links in one folder, and chat inside it`}),g.enabled&&(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(Z,{label:`projects root`,children:(0,F.jsx)(X,{value:g.root,placeholder:`kraftwerk-data/projects`,onChange:e=>N({root:e.target.value})})}),(0,F.jsx)(G,{children:`Relative to the project root, one folder per project (project.yml, brief.md, state.md, log.md). Part of the workspace: versioned with it on the git screen. A chat opened in a project starts with all of it as context.`})]})]})}),(0,F.jsx)(au,{}),(0,F.jsx)(Ql,{}),(0,F.jsxs)(J,{title:`paths & port`,actions:(0,F.jsx)(`code`,{className:`max-w-[60%] truncate text-2xs text-fg-2`,title:e.configPath,children:e.exists?e.configPath:`${e.configPath} (not created yet)`}),children:[(0,F.jsx)(`div`,{className:`flex flex-col pt-1.5 pb-2.5`,children:P.map(([e,t,n])=>(0,F.jsxs)(`div`,{className:`grid grid-cols-[110px_1fr] items-baseline gap-x-3.5 gap-y-px border-line/55 px-[18px] py-2 [&+&]:border-t`,children:[(0,F.jsx)(et,{children:e}),(0,F.jsx)(`code`,{className:`text-xs break-all`,children:t}),(0,F.jsx)(`span`,{className:`col-start-2 text-2xs text-fg-2`,children:n})]},e))}),(0,F.jsxs)(G,{className:`px-[18px] pb-3.5`,children:[`Read-only here — edit `,(0,F.jsx)(`code`,{children:`kraftwerk.yml`}),` directly to change these.`]})]})]})}var su={agents:{label:`agents`,icon:`smart_toy`},"agent-skills":{label:`agent skills`,icon:`extension`},projects:{label:`projects`,icon:`folder`},workflows:{label:`workflows`,icon:`account_tree`},knowledge:{label:`knowledge bundles`,icon:`menu_book`},vibeables:{label:`apps`,icon:`web`},channels:{label:`channels`,icon:`forum`},repos:{label:`repositories`,icon:`source`},chats:{label:`chats`,icon:`chat`},runs:{label:`runs`,icon:`play_circle`}};function cu(){let[e,t]=(0,v.useState)(null),[n,r]=(0,v.useState)(``),[i,a]=(0,v.useState)(null),[o,s]=(0,v.useState)(null),c=(0,v.useCallback)(async()=>{let e=await A.request(`trash.list`).catch(()=>null);e?.ok?t(e.data):r(e?.status===404?`this server has no trash yet — restart it after updating`:`could not load the trash`)},[]);(0,v.useEffect)(()=>{c()},[c]);let l=async(e,t)=>{a(t),r(``),s(null);try{let n=e===`empty`?(await A.request(`trash.empty`)).error:M(await A.request(`trash.${e}`,{body:{id:t}}));if(n)throw Error(n)}catch(e){r(e.message)}finally{a(null),c()}},u=e?.entries??[],d=[...new Set(u.map(e=>e.kind))].sort((e,t)=>Object.keys(su).indexOf(e)-Object.keys(su).indexOf(t));return(0,F.jsxs)(it,{className:`px-6 py-6`,children:[(0,F.jsx)(rt,{icon:(0,F.jsx)(I,{name:`delete`,className:`text-[28px] text-fg-2`}),title:`Trash`,sub:e?`${u.length} item${u.length===1?``:`s`}`:void 0,actions:u.length>0&&(o===`*`?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(V,{variant:`danger`,icon:`delete_forever`,onClick:()=>void l(`empty`,`*`),children:[`delete all `,u.length,` for good`]}),(0,F.jsx)(V,{variant:`quiet`,onClick:()=>s(null),children:`cancel`})]}):(0,F.jsx)(V,{variant:`danger`,icon:`delete_forever`,disabled:!!i,onClick:()=>s(`*`),children:`empty trash`}))}),n&&(0,F.jsx)(q,{tone:`bad`,children:n}),!e&&!n&&(0,F.jsx)(J,{children:(0,F.jsx)(K,{children:`loading…`})}),e&&u.length===0&&(0,F.jsx)(J,{children:(0,F.jsx)(K,{icon:`delete`,children:`The trash is empty. What you delete lands here first.`})}),d.map(e=>(0,F.jsx)(J,{title:su[e]?.label??e,actions:(0,F.jsxs)(`code`,{className:`text-xs text-fg-2`,children:[`trash/`,e,`/`]}),children:(0,F.jsx)(`div`,{className:`p-1.5`,children:u.filter(t=>t.kind===e).map(t=>(0,F.jsx)(Y,{className:`trash-row`,leading:(0,F.jsx)(I,{name:su[e]?.icon??`draft`,className:`ms-sm`}),title:t.name,sub:(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`span`,{className:`font-mono`,children:t.from}),` · `,(0,F.jsxs)(`span`,{title:t.trashedAt,children:[`deleted `,Ge(t.trashedAt)]})]}),meta:(0,F.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,F.jsx)(V,{size:`sm`,variant:`secondary`,icon:`restore_from_trash`,busy:i===t.id,disabled:!!i,onClick:()=>void l(`restore`,t.id),title:`Put it back at ${t.from}`,children:`restore`}),o===t.id?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(V,{size:`sm`,variant:`danger`,icon:`delete_forever`,onClick:()=>void l(`purge`,t.id),children:`delete for good`}),(0,F.jsx)(V,{size:`sm`,variant:`quiet`,onClick:()=>s(null),children:`cancel`})]}):(0,F.jsx)(V,{size:`sm`,variant:`danger`,icon:`delete_forever`,disabled:!!i,onClick:()=>s(t.id),children:`delete`})]})},t.id))})},e)),e&&(0,F.jsxs)(`p`,{className:`m-0 text-sm text-fg-2`,children:[`The trash lives in `,(0,F.jsx)(`code`,{children:e.root}),`, kept out of the workspace git. From the terminal:`,` `,(0,F.jsx)(`code`,{children:`kraftwerk trash`}),`, `,(0,F.jsx)(`code`,{children:`kraftwerk trash restore <id>`}),`, `,(0,F.jsx)(`code`,{children:`kraftwerk trash empty`}),`.`]})]})}var lu=(e,t,n=!1)=>A.url(`files.raw`,{query:{scope:e,path:t,download:n}}),uu=(e,t=``,n)=>`/files/${encodeURIComponent(e)}${t?`/${t.split(`/`).map(encodeURIComponent).join(`/`)}`:``}${n?`?file=${encodeURIComponent(n)}`:``}`,du=`inline-grid size-7 shrink-0 place-items-center rounded-control text-fg-2 no-underline hover:bg-surface-2 hover:text-fg`,fu=`whitespace-nowrap border-b border-line px-2.5 py-1.5 text-left`;function pu({here:e,onClick:t,children:n}){return(0,F.jsx)(`button`,{type:`button`,onClick:t,className:P(`cursor-pointer rounded-md border-0 bg-transparent px-1 py-0.5 font-[inherit] hover:bg-surface-2 hover:text-fg`,e?`font-semibold text-fg`:`text-fg-2`),children:n})}function mu(e){if(e.type===`dir`)return`folder`;let t=e.mime??``;return t.startsWith(`image/`)?`image`:t===`application/pdf`?`picture_as_pdf`:t.startsWith(`video/`)?`movie`:t.startsWith(`audio/`)?`music_note`:/csv|tab-separated|spreadsheet/.test(t)?`table`:/zip/.test(t)?`folder_zip`:/presentation/.test(t)?`slideshow`:t.startsWith(`text/`)||/json|yaml|xml|wordprocessing/.test(t)?`description`:`draft`}function hu({scope:e,dir:t,file:n}){let[r,i]=(0,v.useState)(null),[a,o]=(0,v.useState)(0);(0,v.useEffect)(()=>{A.call(`files.scopes`).then(e=>i(e.scopes),()=>i([]))},[a]);let s=(r??[]).filter(e=>e.scope!==`workspace`);return(0,F.jsxs)(`div`,{className:`runs-screen files-screen`,children:[(0,F.jsxs)(`aside`,{className:`runs-side`,children:[(0,F.jsx)(wt,{title:`files`}),(0,F.jsxs)(Et,{children:[(r??[]).filter(e=>e.scope===`workspace`).map(t=>(0,F.jsx)(gu,{s:t,active:e===t.scope,icon:`home_storage`},t.scope)),s.length>0&&(0,F.jsx)(wt,{title:`projects`,divided:!0}),s.map(t=>(0,F.jsx)(gu,{s:t,active:e===t.scope,icon:`folder_special`},t.scope))]})]}),(0,F.jsx)(`div`,{className:`runs-main min-w-0`,children:(0,F.jsx)(_u,{scope:e,dir:t,file:n,onOpen:(t,n)=>B(uu(e,t,n)),onChanged:()=>o(e=>e+1)},e)})]})}function gu({s:e,active:t,icon:n}){return(0,F.jsx)(Y,{href:uu(e.scope),active:t,size:`sm`,leading:(0,F.jsx)(I,{name:n,className:`ms-sm`}),title:e.label,sub:(0,F.jsxs)(`span`,{className:`font-mono`,children:[e.root,`/`]}),meta:e.count})}function _u({scope:e,dir:t,file:n,onOpen:r,onChanged:i,compact:a=!1}){let[o,s]=(0,v.useState)(null),[c,l]=(0,v.useState)(``),[u,d]=(0,v.useState)(``),[f,p]=(0,v.useState)(!1),[m,h]=(0,v.useState)(null),[g,_]=(0,v.useState)(null),[y,b]=(0,v.useState)(null),x=(0,v.useRef)(null),S=(0,v.useCallback)(async()=>{let n=await A.request(`files.list`,{query:{scope:e,path:t}}).catch(()=>null);if(!n?.ok||!n.data||typeof n.data!=`object`){l(n?.error??`could not load the folder`),s(null);return}l(``),s(n.data)},[e,t]);(0,v.useEffect)(()=>{S();let e=setInterval(()=>void S(),1e4);return()=>clearInterval(e)},[S]);let C=async()=>{await S(),i?.()};async function w(n){let r=[...n];if(r.length){l(``);for(let[n,i]of r.entries()){d(r.length>1?`uploading ${n+1} of ${r.length}…`:`uploading ${i.name}…`);let a=await A.request(`files.upload`,{query:{scope:e,path:t},headers:{"x-file-name":encodeURIComponent(i.name),"content-type":i.type||`application/octet-stream`},body:i}).catch(()=>null);a?.ok||l(a?.error??`could not upload ${i.name}`)}d(``),await C()}}async function T(n){let r=n.trim();if(h(null),!r)return;let i=M(await A.request(`files.mkdir`,{body:{scope:e,path:t?`${t}/${r}`:r}}));i&&l(i),await C()}async function E(i,a){_(null);let o=a.trim();if(!o||o===i.split(`/`).pop())return;let s=i.includes(`/`)?`${i.slice(0,i.lastIndexOf(`/`))}/${o}`:o,c=M(await A.request(`files.move`,{body:{scope:e,from:i,to:s}}));c?l(c):n===i&&r(t,s),await C()}async function D(i){b(null);let a=await A.request(`files.delete`,{query:{scope:e,path:i}}).catch(()=>null);a?.ok||l(a?.error??`could not delete`),n===i&&r(t),await C()}let O=t?t.split(`/`):[],k=n?o?.entries.find(e=>e.path===n):void 0,j=!(a&&n);return(0,F.jsxs)(`div`,{className:P(`files-browser h-full min-h-0`,a?`flex flex-col gap-2 px-1.5 py-1`:P(`grid gap-4`,n?`grid-cols-1 min-[900px]:grid-cols-[minmax(280px,1fr)_minmax(0,1.3fr)]`:`grid-cols-1`)),children:[j&&(0,F.jsxs)(`div`,{className:P(`flex min-h-0 flex-col rounded-card outline-2 -outline-offset-2 outline-dashed transition-colors`,f?`bg-accent/5 outline-accent`:`outline-transparent`),onDragOver:e=>{[...e.dataTransfer.types].includes(`Files`)&&(e.preventDefault(),p(!0))},onDragLeave:e=>{e.currentTarget.contains(e.relatedTarget)||p(!1)},onDrop:e=>{e.preventDefault(),p(!1),w(e.dataTransfer.files)},children:[(0,F.jsxs)(`div`,{className:P(`flex items-center gap-1`,a?`px-1 pb-1.5 pt-0.5`:`px-0.5 pb-2.5 pt-1`),children:[(0,F.jsxs)(`nav`,{className:P(`flex min-w-0 flex-wrap items-center`,a?`text-sm`:`text-md`),"aria-label":`Folder`,children:[(0,F.jsx)(pu,{here:!O.length,onClick:()=>r(``),children:o?.label??(e===`workspace`?`Workspace`:e.replace(/^project:/,``))}),O.map((e,t)=>(0,F.jsxs)(`span`,{className:`inline-flex items-center text-fg-2`,children:[(0,F.jsx)(I,{name:`chevron_right`,className:`ms-sm`}),(0,F.jsx)(pu,{here:t===O.length-1,onClick:()=>r(O.slice(0,t+1).join(`/`)),children:e})]},t))]}),(0,F.jsx)(`span`,{className:`flex-1`}),a?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(H,{icon:`create_new_folder`,label:`New folder`,size:`sm`,onClick:()=>h(``)}),(0,F.jsx)(H,{icon:`upload`,label:`Upload files`,size:`sm`,onClick:()=>x.current?.click()})]}):(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(V,{variant:`quiet`,size:`sm`,icon:`create_new_folder`,onClick:()=>h(``),title:`New folder`,children:`folder`}),(0,F.jsx)(V,{variant:`quiet`,size:`sm`,icon:`upload`,onClick:()=>x.current?.click(),title:`Upload files`,children:`upload`})]}),(0,F.jsx)(`input`,{ref:x,type:`file`,multiple:!0,hidden:!0,"aria-label":`Upload files`,onChange:e=>e.target.files&&void w(e.target.files)})]}),u&&(0,F.jsx)(q,{children:u}),c&&(0,F.jsx)(q,{tone:`bad`,children:c}),(0,F.jsxs)(`div`,{className:`files-list flex min-h-0 flex-1 flex-col gap-px overflow-y-auto`,role:`list`,children:[m!==null&&(0,F.jsxs)(`div`,{className:`flex items-center gap-2.5 px-2.5 py-1`,children:[(0,F.jsx)(I,{name:`create_new_folder`,className:`text-[20px] text-fg-2`}),(0,F.jsx)(X,{className:`h-8`,autoFocus:!0,value:m,placeholder:`folder name`,"aria-label":`Folder name`,onChange:e=>h(e.target.value),onKeyDown:e=>{e.key===`Enter`&&T(m),e.key===`Escape`&&h(null)},onBlur:()=>void T(m)})]}),o?.entries.map(i=>g?.path===i.path?(0,F.jsxs)(`div`,{role:`listitem`,className:`flex items-center gap-2.5 px-2.5 py-1`,children:[(0,F.jsx)(I,{name:mu(i),className:`text-[20px] text-fg-2`}),(0,F.jsx)(X,{className:`h-8`,autoFocus:!0,value:g.name,"aria-label":`New name`,onChange:e=>_({path:i.path,name:e.target.value}),onKeyDown:e=>{e.key===`Enter`&&E(i.path,g.name),e.key===`Escape`&&_(null)},onBlur:()=>void E(i.path,g.name)})]},i.path):(0,F.jsx)(`div`,{role:`listitem`,children:(0,F.jsx)(Y,{className:`files-row`,active:i.path===n,onClick:()=>i.type===`dir`?r(i.path):r(t,i.path),label:i.name,leading:(0,F.jsx)(I,{name:mu(i),className:`text-[20px] text-fg-2`}),title:(0,F.jsx)(`span`,{className:`font-normal`,children:i.name}),titleExtra:i.local?(0,F.jsx)(`span`,{className:`text-xs font-normal text-fg-2`,title:`Over 25 MB: kept out of git, stays on this machine`,children:`local only`}):void 0,meta:(0,F.jsxs)(F.Fragment,{children:[i.type===`dir`?`${i.count??0} file${i.count===1?``:`s`}`:Ue(i.size??0),!a&&` · ${Ge(i.modifiedAt)}`]}),actions:(0,F.jsxs)(F.Fragment,{children:[i.type===`file`&&(0,F.jsx)(`a`,{className:`inline-grid size-7 place-items-center rounded-control text-fg-2 no-underline hover:bg-surface-2 hover:text-fg`,href:lu(e,i.path,!0),title:`Download`,"aria-label":`Download ${i.name}`,children:(0,F.jsx)(I,{name:`download`,className:`ms-sm`})}),(0,F.jsx)(H,{icon:`edit`,size:`sm`,label:`Rename ${i.name}`,onClick:()=>_({path:i.path,name:i.name})}),y===i.path?(0,F.jsx)(V,{variant:`danger`,size:`sm`,autoFocus:!0,onClick:()=>void D(i.path),onBlur:()=>b(null),children:`move to trash`}):(0,F.jsx)(H,{icon:`delete`,size:`sm`,label:`Delete ${i.name}`,onClick:()=>b(i.path)})]})})},i.path)),o&&o.entries.length===0&&m===null&&(0,F.jsxs)(K,{icon:`upload_file`,action:(0,F.jsxs)(`span`,{className:`font-mono text-2xs opacity-80`,children:[o.root,`/`,t?`${t}/`:``]}),children:[`Drop files here, or`,` `,(0,F.jsx)(`button`,{type:`button`,className:`cursor-pointer border-0 bg-transparent p-0 font-[inherit] text-accent underline`,onClick:()=>x.current?.click(),children:`choose some`}),`.`]}),!o&&!c&&(0,F.jsx)(K,{children:`loading…`})]})]}),n&&(0,F.jsx)(vu,{scope:e,path:n,entry:k,onClose:()=>r(t),compact:a})]})}function vu({scope:e,path:t,entry:n,onClose:r,compact:i}){let a=n?.mime??``,o=t.split(`/`).pop()??t,s=lu(e,t),c=/^text\/|json|yaml|xml/.test(a)&&!/html/.test(a),[l,u]=(0,v.useState)(null);(0,v.useEffect)(()=>{if(u(null),!c||(n?.size??0)>2e6)return;let e=!0;return fetch(s,{cache:`no-store`}).then(e=>e.text()).then(t=>e&&u(t)).catch(()=>{}),()=>{e=!1}},[s,c,n?.size]);let d;return d=n?a.startsWith(`image/`)?(0,F.jsx)(`img`,{className:`m-auto max-h-full max-w-full flex-none object-contain p-4`,src:s,alt:o}):a===`application/pdf`?(0,F.jsx)(`iframe`,{className:P(`w-full border-0 bg-white`,i?`min-h-[60vh]`:`min-h-[70vh]`),src:s,title:o}):a.startsWith(`video/`)?(0,F.jsx)(`video`,{className:`m-auto max-h-full w-full p-4`,src:s,controls:!0}):a.startsWith(`audio/`)?(0,F.jsx)(`audio`,{className:`m-auto w-full p-4`,src:s,controls:!0}):c&&l!==null?/markdown/.test(a)?(0,F.jsx)(`div`,{className:`md-body files-md px-5 py-4`,dangerouslySetInnerHTML:{__html:da.sanitize(Fr.parse(l,{async:!1}))}}):/csv|tab-separated/.test(a)?(0,F.jsx)(yu,{text:l,tab:/tab-separated/.test(a)}):(0,F.jsx)(`pre`,{className:`files-text m-0 whitespace-pre-wrap p-4 font-mono text-[12.5px] leading-relaxed [overflow-wrap:anywhere]`,children:l}):c&&(n.size??0)<=2e6?(0,F.jsx)(K,{children:`loading…`}):(0,F.jsx)(K,{icon:mu(n),action:(0,F.jsx)(V,{variant:`primary`,size:`sm`,icon:`download`,href:void 0,onClick:()=>window.location.href=lu(e,t,!0),children:`download`}),children:`No preview for this kind of file.`}):(0,F.jsx)(K,{children:`loading…`}),(0,F.jsxs)(`section`,{className:P(`files-preview flex min-h-0 flex-col overflow-hidden rounded-card border border-line bg-surface`,i&&`min-h-[60vh]`),"aria-label":`Preview of ${o}`,children:[(0,F.jsxs)(`div`,{className:`flex items-center gap-1.5 border-b border-line px-3 py-2`,children:[i&&(0,F.jsx)(H,{icon:`arrow_back`,label:`Back to the folder`,size:`sm`,onClick:r}),(0,F.jsx)(`span`,{className:`min-w-0 truncate text-base font-semibold`,title:t,children:o}),n?.size!==void 0&&(0,F.jsx)(`span`,{className:`shrink-0 text-xs tabular-nums text-fg-2`,children:Ue(n.size)}),(0,F.jsx)(`span`,{className:`flex-1`}),(0,F.jsx)(`a`,{className:du,href:s,target:`_blank`,rel:`noopener`,title:`Open in a new tab`,"aria-label":`Open in a new tab`,children:(0,F.jsx)(I,{name:`open_in_new`,className:`ms-sm`})}),(0,F.jsx)(`a`,{className:du,href:lu(e,t,!0),title:`Download`,"aria-label":`Download`,children:(0,F.jsx)(I,{name:`download`,className:`ms-sm`})}),!i&&(0,F.jsx)(H,{icon:`close`,label:`Close the preview`,size:`sm`,onClick:r})]}),(0,F.jsx)(`div`,{className:`flex min-h-0 flex-1 overflow-auto [&>*]:flex-1`,children:d})]})}function yu({text:e,tab:t}){let n=t?` `:e.split(`
223
223
  `)[0].includes(`;`)&&!e.split(`
224
- `)[0].includes(`,`)?`;`:`,`,r=[];for(let t of e.split(/\r?\n/).slice(0,501)){if(!t)continue;let e=[],i=``,a=!1;for(let r=0;r<t.length;r++){let o=t[r];a&&o===`"`&&t[r+1]===`"`?(i+=`"`,r++):o===`"`?a=!a:o===n&&!a?(e.push(i),i=``):i+=o}e.push(i),r.push(e)}let[i,...a]=r;return(0,F.jsx)(`div`,{className:`overflow-auto`,children:(0,F.jsxs)(`table`,{className:`border-collapse text-[12.5px]`,children:[i&&(0,F.jsx)(`thead`,{children:(0,F.jsx)(`tr`,{children:i.map((e,t)=>(0,F.jsx)(`th`,{className:P(du,`sticky top-0 bg-surface font-semibold`),children:e},t))})}),(0,F.jsx)(`tbody`,{children:a.map((e,t)=>(0,F.jsx)(`tr`,{children:e.map((e,t)=>(0,F.jsx)(`td`,{className:du,children:e},t))},t))})]})})}function yu(){let[e,t]=(0,v.useState)(`overview`),[n,r]=(0,v.useState)(!0);return(0,F.jsxs)(`div`,{className:`mx-auto flex max-w-[1100px] flex-col gap-4 p-6`,children:[(0,F.jsx)(rt,{title:`Components`,sub:`src/ui — what every screen is built from`,actions:(0,F.jsx)(V,{variant:`primary`,icon:`add`,children:`primary`})}),(0,F.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,F.jsxs)(J,{title:`Buttons`,children:[(0,F.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 p-4`,children:[(0,F.jsx)(V,{variant:`primary`,icon:`play_arrow`,children:`Run`}),(0,F.jsx)(V,{variant:`secondary`,icon:`upload`,children:`Upload`}),(0,F.jsx)(V,{variant:`quiet`,icon:`create_new_folder`,children:`Folder`}),(0,F.jsx)(V,{variant:`danger`,icon:`delete`,children:`Move to trash`}),(0,F.jsx)(V,{variant:`primary`,busy:!0,children:`Saving`}),(0,F.jsx)(V,{variant:`secondary`,disabled:!0,children:`Disabled`})]}),(0,F.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 px-4 pb-4`,children:[(0,F.jsx)(V,{size:`sm`,variant:`primary`,children:`small`}),(0,F.jsx)(V,{size:`sm`,variant:`secondary`,children:`small`}),(0,F.jsx)(V,{size:`sm`,variant:`quiet`,children:`small`}),(0,F.jsx)(H,{icon:`edit`,label:`Rename`}),(0,F.jsx)(H,{icon:`download`,label:`Download`}),(0,F.jsx)(H,{icon:`delete`,label:`Delete`,variant:`danger`}),(0,F.jsx)(H,{icon:`close`,label:`Close`,size:`sm`})]})]}),(0,F.jsxs)(J,{title:`Status`,children:[(0,F.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 p-4`,children:[(0,F.jsx)(Qe,{n:3}),` `,(0,F.jsx)(Qe,{n:12,tone:`neutral`}),(0,F.jsx)(U,{tone:`ok`}),` `,(0,F.jsx)(U,{tone:`bad`}),` `,(0,F.jsx)(U,{tone:`ask`}),` `,(0,F.jsx)(U,{tone:`live`}),` `,(0,F.jsx)(U,{tone:`working`}),` `,(0,F.jsx)(U,{tone:`idle`}),(0,F.jsx)(W,{children:`static`}),` `,(0,F.jsx)(W,{tone:`ok`,children:`done`}),` `,(0,F.jsx)(W,{tone:`bad`,children:`failed`}),` `,(0,F.jsx)(W,{tone:`ask`,children:`needs approval`}),` `,(0,F.jsx)(W,{tone:`accent`,children:`running`})]}),(0,F.jsx)(q,{tone:`bad`,children:`Could not upload brief.pdf`}),(0,F.jsx)(q,{children:`uploading 2 of 3…`})]}),(0,F.jsx)(J,{title:`Rows`,count:1,actions:(0,F.jsx)(V,{size:`sm`,variant:`quiet`,icon:`arrow_forward`,children:`all`}),children:(0,F.jsxs)(`div`,{className:`p-1.5`,children:[(0,F.jsx)(Y,{leading:`🐻`,title:`Max`,sub:`waiting for you · Set up the build`,subTone:`bad`,titleExtra:(0,F.jsx)(Qe,{n:1}),href:`/ui`}),(0,F.jsx)(Y,{leading:`🦊`,title:`Lisa`,sub:`last active 2h ago`,href:`/ui`,active:!0}),(0,F.jsx)(Y,{leading:(0,F.jsx)(`span`,{className:`ms material-symbols-rounded ms-sm`,children:`folder`}),title:`briefing`,meta:`3 files`,onClick:()=>{},actions:(0,F.jsx)(H,{icon:`edit`,label:`Rename`,size:`sm`})}),(0,F.jsx)(Y,{leading:(0,F.jsx)(U,{tone:`working`}),title:`website-check`,sub:`https://netnode.ch`,meta:`running`,size:`sm`}),(0,F.jsx)(Y,{leading:`📁`,title:`Gone project`,sub:`not in this workspace`,dim:!0})]})}),(0,F.jsxs)(J,{title:`Tabs and sections`,children:[(0,F.jsx)(ft,{items:[{id:`overview`,label:`overview`},{id:`files`,label:`files`,count:4},{id:`knowledge`,label:`knowledge`,count:0}],value:e,onChange:t}),(0,F.jsxs)(`div`,{className:`p-2`,children:[(0,F.jsx)(tt,{size:`lg`,title:`needs you`,count:2,action:(0,F.jsx)(V,{size:`sm`,variant:`quiet`,children:`all`}),children:(0,F.jsx)(Y,{leading:`✋`,title:`Run npm install`,sub:`🐻 Max · needs approval · 4m ago`,onClick:()=>{}})}),(0,F.jsx)(tt,{title:`team`,children:(0,F.jsx)(Y,{leading:`🦊`,title:`Lisa`,sub:`Research`})})]})]}),(0,F.jsx)(J,{title:`Fields`,children:(0,F.jsxs)(`div`,{className:`flex flex-col gap-3 p-4`,children:[(0,F.jsx)(Z,{label:`Name`,hint:`Shown in the rail.`,children:(0,F.jsx)(X,{placeholder:`e.g. Max`})}),(0,F.jsx)(Z,{label:`Harness`,children:(0,F.jsxs)(_t,{defaultValue:`claude`,children:[(0,F.jsx)(`option`,{children:`claude`}),(0,F.jsx)(`option`,{children:`codex`}),(0,F.jsx)(`option`,{children:`pi`})]})}),(0,F.jsx)(Z,{label:`Role`,children:(0,F.jsx)(gt,{rows:3,placeholder:`What this agent does`})})]})}),(0,F.jsxs)(J,{title:`Empty and menus`,children:[(0,F.jsx)(K,{icon:`upload_file`,action:(0,F.jsx)(V,{variant:`secondary`,size:`sm`,icon:`upload`,children:`choose files`}),children:`Drop files here.`}),(0,F.jsx)(`div`,{className:`p-4`,children:(0,F.jsx)(Ot,{trigger:({toggle:e})=>(0,F.jsx)(V,{onClick:e,icon:`expand_more`,children:`menu`}),children:e=>(0,F.jsxs)(`div`,{className:`flex flex-col`,children:[(0,F.jsx)(Y,{leading:`⚙️`,title:`Settings`,onClick:e,size:`sm`}),(0,F.jsx)(Y,{leading:`🗑`,title:`Trash`,onClick:e,size:`sm`})]})})})]}),(0,F.jsx)(J,{title:`Sidebar parts`,children:(0,F.jsxs)(`div`,{className:`w-[300px] border-r border-line`,children:[(0,F.jsx)(wt,{title:`workflows`,count:3,action:(0,F.jsx)(V,{size:`sm`,variant:`quiet`,icon:`add`,children:`new`})}),(0,F.jsx)(Tt,{placeholder:`search workflows`,"aria-label":`search workflows`}),(0,F.jsxs)(Et,{children:[(0,F.jsx)(Y,{leading:(0,F.jsx)(U,{tone:`ok`}),title:`triage`,sub:`checks, drafts, publishes`,size:`sm`,active:!0}),(0,F.jsx)(Dt,{children:`no workflow matches “x”`})]})]})}),(0,F.jsx)(J,{title:`Choices`,children:(0,F.jsxs)(vt,{children:[(0,F.jsx)(bt,{checked:n,onChange:r,hint:`every discovered skill`,children:`all skills`}),(0,F.jsx)(bt,{checked:!n,onChange:e=>r(!e),hint:`0 concepts`,mono:!0,children:`brand-guide`}),(0,F.jsxs)(yt,{children:[(0,F.jsx)(St,{checked:n,onChange:r,label:`routine enabled`}),(0,F.jsxs)(G,{children:[`Hint: a small explaining line. Keys look like `,(0,F.jsx)($e,{children:`⌘K`}),`.`]})]}),(0,F.jsx)(Ct,{label:`Docker sandbox`,hint:`Docker is not running`,checked:n,onChange:r})]})}),(0,F.jsxs)(J,{title:`Page parts`,children:[(0,F.jsxs)(`div`,{className:`flex flex-col gap-3 p-4`,children:[(0,F.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,F.jsx)(at,{children:`🐻`}),(0,F.jsx)(nt,{size:`lg`,children:`Max`}),(0,F.jsx)(W,{href:`#/ui`,children:`linked tag`})]}),(0,F.jsx)(ft,{bare:!0,label:`link tabs`,value:`pages`,items:[{id:`pages`,label:`pages`,href:`/ui`},{id:`activity`,label:`activity`,href:`/ui`}]})]}),(0,F.jsxs)(ct,{children:[(0,F.jsx)(st,{icon:`account_tree`,title:`workflows`,action:(0,F.jsx)(V,{size:`sm`,children:`edit`}),children:(0,F.jsx)(`span`,{className:`text-xs text-fg-2`,children:`none connected`})}),(0,F.jsx)(st,{icon:`menu_book`,title:`knowledge`})]}),(0,F.jsxs)(ut,{children:[(0,F.jsx)(dt,{label:`source`,children:`workspace`}),(0,F.jsx)(dt,{label:`path`,mono:!0,children:`skills/release-notes/SKILL.md`})]})]})]})]})}var bu={running:{label:`running`},stopped:{label:`stopped`},died:{label:`died`,note:`was killed or crashed`},missing:{label:`missing`,note:`folder is gone`},orphaned:{label:`orphaned`,note:`no kraftwerk.yml any more`}},xu={running:`text-ok`,stopped:`text-fg-2`,died:`text-ask`,missing:`text-bad`,orphaned:`text-bad`},Su={running:``,stopped:`opacity-65 grayscale-50`,died:`opacity-80`,missing:`opacity-45 grayscale-80`,orphaned:`opacity-45 grayscale-80`};function Cu(){let[e,t]=(0,v.useState)(null),[n,r]=(0,v.useState)(``),[i,a]=(0,v.useState)({}),[o,s]=(0,v.useState)({}),[c,l]=(0,v.useState)(null),u=(0,v.useCallback)(async()=>{try{let e=await A.request(`workspaces.list`);if(e.ok){t(e.data),r(``);return}r(e.status===404?`This workspace runs a kraftwerk without the workspaces API. Update it and restart its UI.`:`Could not load the workspace registry (HTTP ${e.status}).`)}catch(e){r(e.message||`Could not reach this workspace's server.`)}},[]);(0,v.useEffect)(()=>{let e=!0,t,n=async()=>{await u(),e&&(t=setTimeout(n,6e3))};return n(),()=>{e=!1,clearTimeout(t)}},[u]);let d=e=>e.root??e.url,f=async(e,t)=>{let n=d(e);a(e=>({...e,[n]:t})),s(e=>({...e,[n]:``})),l(null);try{let n=t===`stop`?{root:e.root,url:e.url}:{root:e.root},r=await A.request(`workspaces.${t}`,{body:n});if(!r.ok)throw Error(M(r));if(!r.data.ok)throw Error(`failed`)}catch(e){s(t=>({...t,[n]:e.message}))}finally{a(e=>{let t={...e};return delete t[n],t}),u()}},p=e?.filter(e=>e.live).length??0,m=new Map;for(let t of e??[])t.icon&&m.set(t.icon,(m.get(t.icon)??0)+1);let h=e=>!!e&&(m.get(e)??0)>1;return(0,F.jsxs)(it,{children:[(0,F.jsx)(rt,{icon:(0,F.jsx)(I,{name:`hub`,className:`text-[28px] text-fg-2`}),title:`Workspaces`,actions:(0,F.jsxs)(F.Fragment,{children:[e&&(0,F.jsxs)(`span`,{className:`text-xs text-fg-2`,children:[e.length,` known · `,p,` running`]}),e&&n&&(0,F.jsx)(q,{tone:`bad`,children:n})]})}),(0,F.jsxs)(J,{title:`workspaces on this machine`,actions:(0,F.jsxs)(`span`,{className:`text-xs text-fg-2`,children:[`registry: `,(0,F.jsx)(`code`,{className:`text-2xs`,children:`~/.kraftwerk/workspaces`})]}),children:[!e&&!n&&(0,F.jsx)(K,{className:`py-6`,children:`loading…`}),!e&&n&&(0,F.jsx)(`div`,{className:`px-[18px] py-4`,children:(0,F.jsx)(q,{tone:`bad`,children:n})}),e&&e.length===0&&(0,F.jsx)(K,{className:`py-6`,children:`No workspaces known yet.`}),e?.map(e=>{let t=d(e),n=i[t],r=!e.live&&!!e.root&&(e.exists===!1||e.hasConfig===!1),a=P(`text-md font-semibold text-fg`,e.named===!1&&`italic text-fg-2`);return(0,F.jsxs)(`div`,{className:P(`grid grid-cols-[40px_minmax(0,1fr)_auto] items-start gap-3.5 px-[18px] py-3.5 [&+&]:border-t [&+&]:border-line/55`,e.state===`died`&&`bg-ask-soft/30`),children:[(0,F.jsx)(Re,{className:P(`size-10`,Su[e.state]),icon:e.icon,name:e.name,color:e.color,seed:e.root??e.url,ambiguous:h(e.icon)}),(0,F.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-[3px]`,children:[(0,F.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2.5`,children:[e.live&&!e.current?(0,F.jsx)(`a`,{href:fe(e),className:P(a,`no-underline hover:underline`),children:e.name}):(0,F.jsx)(`span`,{className:a,children:e.name}),e.current&&(0,F.jsx)(`span`,{className:`text-[10.5px] font-semibold tracking-[0.4px] text-fg-2 uppercase`,children:`current`}),(0,F.jsxs)(`span`,{className:P(`inline-flex items-center gap-1.5 text-2xs font-semibold tracking-[0.4px] uppercase`,xu[e.state]),children:[e.live&&(0,F.jsx)(`span`,{className:`inline-block size-2 rounded-full bg-ok`}),bu[e.state].label]}),bu[e.state].note&&(0,F.jsx)(`span`,{className:`text-xs text-fg-2`,children:bu[e.state].note})]}),(0,F.jsx)(`div`,{className:`font-mono text-xs [overflow-wrap:anywhere] text-fg-2`,title:e.root,children:e.rootLabel??(0,F.jsx)(`span`,{className:`font-sans opacity-70`,children:`no root recorded (started by an older version)`})}),(0,F.jsxs)(`div`,{className:`flex flex-wrap gap-x-3.5 gap-y-1 text-xs text-fg-2`,children:[e.state!==`missing`&&e.state!==`orphaned`&&(0,F.jsx)(`span`,{children:e.url.replace(/^https?:\/\//,``)}),e.counts&&(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(`span`,{children:[e.counts.agents,` agents`]}),(0,F.jsxs)(`span`,{children:[e.counts.workflows,` workflows`]}),(0,F.jsxs)(`span`,{children:[e.counts.runs,` runs`]}),(0,F.jsxs)(`span`,{children:[e.counts.chats,` chats`]})]}),e.lastStarted&&(0,F.jsxs)(`span`,{title:e.lastStarted,children:[`started `,Ge(e.lastStarted)]}),!e.live&&e.lastStopped&&(0,F.jsxs)(`span`,{title:e.lastStopped,children:[`stopped `,Ge(e.lastStopped)]}),e.startCount!=null&&(0,F.jsxs)(`span`,{children:[e.startCount,`× launched`]}),e.firstSeen&&(0,F.jsxs)(`span`,{title:e.firstSeen,children:[`first seen `,Ge(e.firstSeen)]})]}),o[t]&&(0,F.jsx)(q,{tone:`bad`,children:o[t]})]}),(0,F.jsxs)(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[e.live&&!e.current&&(0,F.jsxs)(`a`,{className:Ze(`secondary`,`sm`),href:fe(e),title:`Open this workspace`,children:[(0,F.jsx)(I,{name:`open_in_new`,className:`ms-sm`}),` open`]}),!e.live&&e.root&&e.exists!==!1&&!e.dirGone&&(0,F.jsx)(V,{size:`sm`,variant:`primary`,icon:`play_arrow`,busy:n===`start`,disabled:!!n,onClick:()=>void f(e,`start`),children:n===`start`?`starting…`:`start`}),e.live&&!e.current&&(0,F.jsx)(V,{size:`sm`,variant:`danger`,icon:`stop`,busy:n===`stop`,disabled:!!n,onClick:()=>void f(e,`stop`),children:n===`stop`?`stopping…`:`stop`}),r&&c!==t&&(0,F.jsx)(V,{size:`sm`,icon:`delete`,disabled:!!n,title:`Drop this project from the registry (files untouched)`,onClick:()=>l(t),children:`remove`}),r&&c===t&&(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(V,{size:`sm`,variant:`danger`,icon:`delete`,onClick:()=>void f(e,`forget`),children:`confirm remove`}),(0,F.jsx)(V,{size:`sm`,variant:`quiet`,onClick:()=>l(null),children:`cancel`})]})]})]},t)})]}),(0,F.jsxs)(`p`,{className:`m-0 text-xs text-fg-2 [&_code]:text-2xs`,children:[`Start launches `,(0,F.jsx)(`code`,{children:`kraftwerk ui`}),` detached in the project root (log in `,(0,F.jsx)(`code`,{children:`~/.kraftwerk/logs`}),`). Stop sends SIGTERM to the running server. Remove is offered only for records whose root no longer holds a `,(0,F.jsx)(`code`,{children:`kraftwerk.yml`}),` — the same from the terminal:`,` `,(0,F.jsx)(`code`,{children:`kraftwerk workspaces`}),`.`]})]})}function wu(e){if(e<60)return`${e}s`;let t=Math.round(e/60);if(t<60)return`${t} min`;let n=Math.floor(t/60),r=t%60;return r?`${n} h ${r} min`:`${n} h`}var Tu=[[/^(\+\+\+|---|diff |index )/,`text-fg-2 opacity-80`],[/^@@/,`text-accent`],[/^\+/,`text-ok`],[/^-/,`text-bad`]],Eu=e=>Tu.find(([t])=>t.test(e))?.[1]??``;function Du({file:e}){return(0,F.jsx)(ku,{source:{route:`git.diff`,input:{query:{path:e}}}})}var Ou=e=>(e.route===`git.diff`||e.route,A.request(e.route,e.input));function ku({source:e,refresh:t}){let[n,r]=(0,v.useState)(null),[i,a]=(0,v.useState)(!1),[o,s]=(0,v.useState)(``),c=JSON.stringify(e);return(0,v.useEffect)(()=>{let t=!0;return r(null),s(``),Ou(e).then(e=>{if(t){if(!e.data||typeof e.data!=`object`)throw Error(`not json`);if(!e.ok){r(``),a(!1),s(e.error??``);return}r(e.data.diff??``),a(!!e.data.truncated),s(e.data.error??``)}}).catch(()=>t&&s(`could not load the diff`)),()=>{t=!1}},[c,t]),o?(0,F.jsx)(`div`,{className:P(Au,`text-bad`),children:o}):n===null?(0,F.jsx)(`div`,{className:Au,children:`loading…`}):n.trim()?(0,F.jsxs)(`pre`,{className:Au,children:[n.split(`
225
- `).map((e,t)=>(0,F.jsxs)(`span`,{className:Eu(e),children:[e||` `,`
224
+ `)[0].includes(`,`)?`;`:`,`,r=[];for(let t of e.split(/\r?\n/).slice(0,501)){if(!t)continue;let e=[],i=``,a=!1;for(let r=0;r<t.length;r++){let o=t[r];a&&o===`"`&&t[r+1]===`"`?(i+=`"`,r++):o===`"`?a=!a:o===n&&!a?(e.push(i),i=``):i+=o}e.push(i),r.push(e)}let[i,...a]=r;return(0,F.jsx)(`div`,{className:`overflow-auto`,children:(0,F.jsxs)(`table`,{className:`border-collapse text-[12.5px]`,children:[i&&(0,F.jsx)(`thead`,{children:(0,F.jsx)(`tr`,{children:i.map((e,t)=>(0,F.jsx)(`th`,{className:P(fu,`sticky top-0 bg-surface font-semibold`),children:e},t))})}),(0,F.jsx)(`tbody`,{children:a.map((e,t)=>(0,F.jsx)(`tr`,{children:e.map((e,t)=>(0,F.jsx)(`td`,{className:fu,children:e},t))},t))})]})})}function bu(){let[e,t]=(0,v.useState)(`overview`),[n,r]=(0,v.useState)(!0);return(0,F.jsxs)(`div`,{className:`mx-auto flex max-w-[1100px] flex-col gap-4 p-6`,children:[(0,F.jsx)(rt,{title:`Components`,sub:`src/ui — what every screen is built from`,actions:(0,F.jsx)(V,{variant:`primary`,icon:`add`,children:`primary`})}),(0,F.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,F.jsxs)(J,{title:`Buttons`,children:[(0,F.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 p-4`,children:[(0,F.jsx)(V,{variant:`primary`,icon:`play_arrow`,children:`Run`}),(0,F.jsx)(V,{variant:`secondary`,icon:`upload`,children:`Upload`}),(0,F.jsx)(V,{variant:`quiet`,icon:`create_new_folder`,children:`Folder`}),(0,F.jsx)(V,{variant:`danger`,icon:`delete`,children:`Move to trash`}),(0,F.jsx)(V,{variant:`primary`,busy:!0,children:`Saving`}),(0,F.jsx)(V,{variant:`secondary`,disabled:!0,children:`Disabled`})]}),(0,F.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 px-4 pb-4`,children:[(0,F.jsx)(V,{size:`sm`,variant:`primary`,children:`small`}),(0,F.jsx)(V,{size:`sm`,variant:`secondary`,children:`small`}),(0,F.jsx)(V,{size:`sm`,variant:`quiet`,children:`small`}),(0,F.jsx)(H,{icon:`edit`,label:`Rename`}),(0,F.jsx)(H,{icon:`download`,label:`Download`}),(0,F.jsx)(H,{icon:`delete`,label:`Delete`,variant:`danger`}),(0,F.jsx)(H,{icon:`close`,label:`Close`,size:`sm`})]})]}),(0,F.jsxs)(J,{title:`Status`,children:[(0,F.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 p-4`,children:[(0,F.jsx)(Qe,{n:3}),` `,(0,F.jsx)(Qe,{n:12,tone:`neutral`}),(0,F.jsx)(U,{tone:`ok`}),` `,(0,F.jsx)(U,{tone:`bad`}),` `,(0,F.jsx)(U,{tone:`ask`}),` `,(0,F.jsx)(U,{tone:`live`}),` `,(0,F.jsx)(U,{tone:`working`}),` `,(0,F.jsx)(U,{tone:`idle`}),(0,F.jsx)(W,{children:`static`}),` `,(0,F.jsx)(W,{tone:`ok`,children:`done`}),` `,(0,F.jsx)(W,{tone:`bad`,children:`failed`}),` `,(0,F.jsx)(W,{tone:`ask`,children:`needs approval`}),` `,(0,F.jsx)(W,{tone:`accent`,children:`running`})]}),(0,F.jsx)(q,{tone:`bad`,children:`Could not upload brief.pdf`}),(0,F.jsx)(q,{children:`uploading 2 of 3…`})]}),(0,F.jsx)(J,{title:`Rows`,count:1,actions:(0,F.jsx)(V,{size:`sm`,variant:`quiet`,icon:`arrow_forward`,children:`all`}),children:(0,F.jsxs)(`div`,{className:`p-1.5`,children:[(0,F.jsx)(Y,{leading:`🐻`,title:`Max`,sub:`waiting for you · Set up the build`,subTone:`bad`,titleExtra:(0,F.jsx)(Qe,{n:1}),href:`/ui`}),(0,F.jsx)(Y,{leading:`🦊`,title:`Lisa`,sub:`last active 2h ago`,href:`/ui`,active:!0}),(0,F.jsx)(Y,{leading:(0,F.jsx)(`span`,{className:`ms material-symbols-rounded ms-sm`,children:`folder`}),title:`briefing`,meta:`3 files`,onClick:()=>{},actions:(0,F.jsx)(H,{icon:`edit`,label:`Rename`,size:`sm`})}),(0,F.jsx)(Y,{leading:(0,F.jsx)(U,{tone:`working`}),title:`website-check`,sub:`https://netnode.ch`,meta:`running`,size:`sm`}),(0,F.jsx)(Y,{leading:`📁`,title:`Gone project`,sub:`not in this workspace`,dim:!0})]})}),(0,F.jsxs)(J,{title:`Tabs and sections`,children:[(0,F.jsx)(ft,{items:[{id:`overview`,label:`overview`},{id:`files`,label:`files`,count:4},{id:`knowledge`,label:`knowledge`,count:0}],value:e,onChange:t}),(0,F.jsxs)(`div`,{className:`p-2`,children:[(0,F.jsx)(tt,{size:`lg`,title:`needs you`,count:2,action:(0,F.jsx)(V,{size:`sm`,variant:`quiet`,children:`all`}),children:(0,F.jsx)(Y,{leading:`✋`,title:`Run npm install`,sub:`🐻 Max · needs approval · 4m ago`,onClick:()=>{}})}),(0,F.jsx)(tt,{title:`team`,children:(0,F.jsx)(Y,{leading:`🦊`,title:`Lisa`,sub:`Research`})})]})]}),(0,F.jsx)(J,{title:`Fields`,children:(0,F.jsxs)(`div`,{className:`flex flex-col gap-3 p-4`,children:[(0,F.jsx)(Z,{label:`Name`,hint:`Shown in the rail.`,children:(0,F.jsx)(X,{placeholder:`e.g. Max`})}),(0,F.jsx)(Z,{label:`Harness`,children:(0,F.jsxs)(_t,{defaultValue:`claude`,children:[(0,F.jsx)(`option`,{children:`claude`}),(0,F.jsx)(`option`,{children:`codex`}),(0,F.jsx)(`option`,{children:`pi`})]})}),(0,F.jsx)(Z,{label:`Role`,children:(0,F.jsx)(gt,{rows:3,placeholder:`What this agent does`})})]})}),(0,F.jsxs)(J,{title:`Empty and menus`,children:[(0,F.jsx)(K,{icon:`upload_file`,action:(0,F.jsx)(V,{variant:`secondary`,size:`sm`,icon:`upload`,children:`choose files`}),children:`Drop files here.`}),(0,F.jsx)(`div`,{className:`p-4`,children:(0,F.jsx)(Ot,{trigger:({toggle:e})=>(0,F.jsx)(V,{onClick:e,icon:`expand_more`,children:`menu`}),children:e=>(0,F.jsxs)(`div`,{className:`flex flex-col`,children:[(0,F.jsx)(Y,{leading:`⚙️`,title:`Settings`,onClick:e,size:`sm`}),(0,F.jsx)(Y,{leading:`🗑`,title:`Trash`,onClick:e,size:`sm`})]})})})]}),(0,F.jsx)(J,{title:`Sidebar parts`,children:(0,F.jsxs)(`div`,{className:`w-[300px] border-r border-line`,children:[(0,F.jsx)(wt,{title:`workflows`,count:3,action:(0,F.jsx)(V,{size:`sm`,variant:`quiet`,icon:`add`,children:`new`})}),(0,F.jsx)(Tt,{placeholder:`search workflows`,"aria-label":`search workflows`}),(0,F.jsxs)(Et,{children:[(0,F.jsx)(Y,{leading:(0,F.jsx)(U,{tone:`ok`}),title:`triage`,sub:`checks, drafts, publishes`,size:`sm`,active:!0}),(0,F.jsx)(Dt,{children:`no workflow matches “x”`})]})]})}),(0,F.jsx)(J,{title:`Choices`,children:(0,F.jsxs)(vt,{children:[(0,F.jsx)(bt,{checked:n,onChange:r,hint:`every discovered skill`,children:`all skills`}),(0,F.jsx)(bt,{checked:!n,onChange:e=>r(!e),hint:`0 concepts`,mono:!0,children:`brand-guide`}),(0,F.jsxs)(yt,{children:[(0,F.jsx)(St,{checked:n,onChange:r,label:`routine enabled`}),(0,F.jsxs)(G,{children:[`Hint: a small explaining line. Keys look like `,(0,F.jsx)($e,{children:`⌘K`}),`.`]})]}),(0,F.jsx)(Ct,{label:`Docker sandbox`,hint:`Docker is not running`,checked:n,onChange:r})]})}),(0,F.jsxs)(J,{title:`Page parts`,children:[(0,F.jsxs)(`div`,{className:`flex flex-col gap-3 p-4`,children:[(0,F.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,F.jsx)(at,{children:`🐻`}),(0,F.jsx)(nt,{size:`lg`,children:`Max`}),(0,F.jsx)(W,{href:`#/ui`,children:`linked tag`})]}),(0,F.jsx)(ft,{bare:!0,label:`link tabs`,value:`pages`,items:[{id:`pages`,label:`pages`,href:`/ui`},{id:`activity`,label:`activity`,href:`/ui`}]})]}),(0,F.jsxs)(ct,{children:[(0,F.jsx)(st,{icon:`account_tree`,title:`workflows`,action:(0,F.jsx)(V,{size:`sm`,children:`edit`}),children:(0,F.jsx)(`span`,{className:`text-xs text-fg-2`,children:`none connected`})}),(0,F.jsx)(st,{icon:`menu_book`,title:`knowledge`})]}),(0,F.jsxs)(ut,{children:[(0,F.jsx)(dt,{label:`source`,children:`workspace`}),(0,F.jsx)(dt,{label:`path`,mono:!0,children:`skills/release-notes/SKILL.md`})]})]})]})]})}var xu={running:{label:`running`},stopped:{label:`stopped`},died:{label:`died`,note:`was killed or crashed`},missing:{label:`missing`,note:`folder is gone`},orphaned:{label:`orphaned`,note:`no kraftwerk.yml any more`}},Su={running:`text-ok`,stopped:`text-fg-2`,died:`text-ask`,missing:`text-bad`,orphaned:`text-bad`},Cu={running:``,stopped:`opacity-65 grayscale-50`,died:`opacity-80`,missing:`opacity-45 grayscale-80`,orphaned:`opacity-45 grayscale-80`};function wu(){let[e,t]=(0,v.useState)(null),[n,r]=(0,v.useState)(``),[i,a]=(0,v.useState)({}),[o,s]=(0,v.useState)({}),[c,l]=(0,v.useState)(null),u=(0,v.useCallback)(async()=>{try{let e=await A.request(`workspaces.list`);if(e.ok){t(e.data),r(``);return}r(e.status===404?`This workspace runs a kraftwerk without the workspaces API. Update it and restart its UI.`:`Could not load the workspace registry (HTTP ${e.status}).`)}catch(e){r(e.message||`Could not reach this workspace's server.`)}},[]);(0,v.useEffect)(()=>{let e=!0,t,n=async()=>{await u(),e&&(t=setTimeout(n,6e3))};return n(),()=>{e=!1,clearTimeout(t)}},[u]);let d=e=>e.root??e.url,f=async(e,t)=>{let n=d(e);a(e=>({...e,[n]:t})),s(e=>({...e,[n]:``})),l(null);try{let n=t===`stop`?{root:e.root,url:e.url}:{root:e.root},r=await A.request(`workspaces.${t}`,{body:n});if(!r.ok)throw Error(M(r));if(!r.data.ok)throw Error(`failed`)}catch(e){s(t=>({...t,[n]:e.message}))}finally{a(e=>{let t={...e};return delete t[n],t}),u()}},p=e?.filter(e=>e.live).length??0,m=new Map;for(let t of e??[])t.icon&&m.set(t.icon,(m.get(t.icon)??0)+1);let h=e=>!!e&&(m.get(e)??0)>1;return(0,F.jsxs)(it,{children:[(0,F.jsx)(rt,{icon:(0,F.jsx)(I,{name:`hub`,className:`text-[28px] text-fg-2`}),title:`Workspaces`,actions:(0,F.jsxs)(F.Fragment,{children:[e&&(0,F.jsxs)(`span`,{className:`text-xs text-fg-2`,children:[e.length,` known · `,p,` running`]}),e&&n&&(0,F.jsx)(q,{tone:`bad`,children:n})]})}),(0,F.jsxs)(J,{title:`workspaces on this machine`,actions:(0,F.jsxs)(`span`,{className:`text-xs text-fg-2`,children:[`registry: `,(0,F.jsx)(`code`,{className:`text-2xs`,children:`~/.kraftwerk/workspaces`})]}),children:[!e&&!n&&(0,F.jsx)(K,{className:`py-6`,children:`loading…`}),!e&&n&&(0,F.jsx)(`div`,{className:`px-[18px] py-4`,children:(0,F.jsx)(q,{tone:`bad`,children:n})}),e&&e.length===0&&(0,F.jsx)(K,{className:`py-6`,children:`No workspaces known yet.`}),e?.map(e=>{let t=d(e),n=i[t],r=!e.live&&!!e.root&&(e.exists===!1||e.hasConfig===!1),a=P(`text-md font-semibold text-fg`,e.named===!1&&`italic text-fg-2`);return(0,F.jsxs)(`div`,{className:P(`grid grid-cols-[40px_minmax(0,1fr)_auto] items-start gap-3.5 px-[18px] py-3.5 [&+&]:border-t [&+&]:border-line/55`,e.state===`died`&&`bg-ask-soft/30`),children:[(0,F.jsx)(Re,{className:P(`size-10`,Cu[e.state]),icon:e.icon,name:e.name,color:e.color,seed:e.root??e.url,ambiguous:h(e.icon)}),(0,F.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-[3px]`,children:[(0,F.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2.5`,children:[e.live&&!e.current?(0,F.jsx)(`a`,{href:fe(e),className:P(a,`no-underline hover:underline`),children:e.name}):(0,F.jsx)(`span`,{className:a,children:e.name}),e.current&&(0,F.jsx)(`span`,{className:`text-[10.5px] font-semibold tracking-[0.4px] text-fg-2 uppercase`,children:`current`}),(0,F.jsxs)(`span`,{className:P(`inline-flex items-center gap-1.5 text-2xs font-semibold tracking-[0.4px] uppercase`,Su[e.state]),children:[e.live&&(0,F.jsx)(`span`,{className:`inline-block size-2 rounded-full bg-ok`}),xu[e.state].label]}),xu[e.state].note&&(0,F.jsx)(`span`,{className:`text-xs text-fg-2`,children:xu[e.state].note})]}),(0,F.jsx)(`div`,{className:`font-mono text-xs [overflow-wrap:anywhere] text-fg-2`,title:e.root,children:e.rootLabel??(0,F.jsx)(`span`,{className:`font-sans opacity-70`,children:`no root recorded (started by an older version)`})}),(0,F.jsxs)(`div`,{className:`flex flex-wrap gap-x-3.5 gap-y-1 text-xs text-fg-2`,children:[e.state!==`missing`&&e.state!==`orphaned`&&(0,F.jsx)(`span`,{children:e.url.replace(/^https?:\/\//,``)}),e.counts&&(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(`span`,{children:[e.counts.agents,` agents`]}),(0,F.jsxs)(`span`,{children:[e.counts.workflows,` workflows`]}),(0,F.jsxs)(`span`,{children:[e.counts.runs,` runs`]}),(0,F.jsxs)(`span`,{children:[e.counts.chats,` chats`]})]}),e.lastStarted&&(0,F.jsxs)(`span`,{title:e.lastStarted,children:[`started `,Ge(e.lastStarted)]}),!e.live&&e.lastStopped&&(0,F.jsxs)(`span`,{title:e.lastStopped,children:[`stopped `,Ge(e.lastStopped)]}),e.startCount!=null&&(0,F.jsxs)(`span`,{children:[e.startCount,`× launched`]}),e.firstSeen&&(0,F.jsxs)(`span`,{title:e.firstSeen,children:[`first seen `,Ge(e.firstSeen)]})]}),o[t]&&(0,F.jsx)(q,{tone:`bad`,children:o[t]})]}),(0,F.jsxs)(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[e.live&&!e.current&&(0,F.jsxs)(`a`,{className:Ze(`secondary`,`sm`),href:fe(e),title:`Open this workspace`,children:[(0,F.jsx)(I,{name:`open_in_new`,className:`ms-sm`}),` open`]}),!e.live&&e.root&&e.exists!==!1&&!e.dirGone&&(0,F.jsx)(V,{size:`sm`,variant:`primary`,icon:`play_arrow`,busy:n===`start`,disabled:!!n,onClick:()=>void f(e,`start`),children:n===`start`?`starting…`:`start`}),e.live&&!e.current&&(0,F.jsx)(V,{size:`sm`,variant:`danger`,icon:`stop`,busy:n===`stop`,disabled:!!n,onClick:()=>void f(e,`stop`),children:n===`stop`?`stopping…`:`stop`}),r&&c!==t&&(0,F.jsx)(V,{size:`sm`,icon:`delete`,disabled:!!n,title:`Drop this project from the registry (files untouched)`,onClick:()=>l(t),children:`remove`}),r&&c===t&&(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(V,{size:`sm`,variant:`danger`,icon:`delete`,onClick:()=>void f(e,`forget`),children:`confirm remove`}),(0,F.jsx)(V,{size:`sm`,variant:`quiet`,onClick:()=>l(null),children:`cancel`})]})]})]},t)})]}),(0,F.jsxs)(`p`,{className:`m-0 text-xs text-fg-2 [&_code]:text-2xs`,children:[`Start launches `,(0,F.jsx)(`code`,{children:`kraftwerk ui`}),` detached in the project root (log in `,(0,F.jsx)(`code`,{children:`~/.kraftwerk/logs`}),`). Stop sends SIGTERM to the running server. Remove is offered only for records whose root no longer holds a `,(0,F.jsx)(`code`,{children:`kraftwerk.yml`}),` — the same from the terminal:`,` `,(0,F.jsx)(`code`,{children:`kraftwerk workspaces`}),`.`]})]})}function Tu(e){if(e<60)return`${e}s`;let t=Math.round(e/60);if(t<60)return`${t} min`;let n=Math.floor(t/60),r=t%60;return r?`${n} h ${r} min`:`${n} h`}var Eu=[[/^(\+\+\+|---|diff |index )/,`text-fg-2 opacity-80`],[/^@@/,`text-accent`],[/^\+/,`text-ok`],[/^-/,`text-bad`]],Du=e=>Eu.find(([t])=>t.test(e))?.[1]??``;function Ou({file:e}){return(0,F.jsx)(Au,{source:{route:`git.diff`,input:{query:{path:e}}}})}var ku=e=>(e.route===`git.diff`||e.route,A.request(e.route,e.input));function Au({source:e,refresh:t}){let[n,r]=(0,v.useState)(null),[i,a]=(0,v.useState)(!1),[o,s]=(0,v.useState)(``),c=JSON.stringify(e);return(0,v.useEffect)(()=>{let t=!0;return r(null),s(``),ku(e).then(e=>{if(t){if(!e.data||typeof e.data!=`object`)throw Error(`not json`);if(!e.ok){r(``),a(!1),s(e.error??``);return}r(e.data.diff??``),a(!!e.data.truncated),s(e.data.error??``)}}).catch(()=>t&&s(`could not load the diff`)),()=>{t=!1}},[c,t]),o?(0,F.jsx)(`div`,{className:P(ju,`text-bad`),children:o}):n===null?(0,F.jsx)(`div`,{className:ju,children:`loading…`}):n.trim()?(0,F.jsxs)(`pre`,{className:ju,children:[n.split(`
225
+ `).map((e,t)=>(0,F.jsxs)(`span`,{className:Du(e),children:[e||` `,`
226
226
  `]},t)),i&&(0,F.jsxs)(`span`,{className:`text-fg-2 opacity-80`,children:[`… diff truncated, see the rest in a terminal`,`
227
- `]})]}):(0,F.jsx)(`div`,{className:Au,children:`no textual diff (binary or empty)`})}var Au=`git-diff mt-1.5 mb-0.5 max-h-[420px] basis-full overflow-auto rounded-xl bg-surface-2 px-3 py-2.5 font-mono text-[11.5px] leading-[1.5] whitespace-pre`,ju={modified:`text-accent`,added:`text-ok`,untracked:`text-ok`,deleted:`text-bad`,conflicted:`text-bad`};function Mu({status:e,muted:t}){return(0,F.jsx)(`span`,{className:P(`flex-none rounded-full border border-line px-2 py-0.5 text-[10.5px] font-semibold tracking-[0.4px] uppercase`,t?`text-fg-2`:ju[e]??`text-fg-2`),children:e})}var Nu=`text-xs text-fg-2`,Pu=`m-0 p-[18px] text-sm text-fg-2`;function Fu(){let[e,t]=(0,v.useState)(null),[n,r]=(0,v.useState)(new Set),[i,a]=(0,v.useState)(new Set),[o,s]=(0,v.useState)(``),[c,l]=(0,v.useState)(``),[u,d]=(0,v.useState)(``),[f,p]=(0,v.useState)(``),m=(0,v.useRef)(!0),h=(0,v.useCallback)(async()=>{try{let e=await A.request(`git.status`,{query:{fresh:m.current}});m.current=!1,e.ok&&t(e.data)}catch{}},[]);(0,v.useEffect)(()=>{let e=!0,t,n=async()=>{await h(),e&&(t=setTimeout(n,6e3))};return n(),()=>{e=!1,clearTimeout(t)}},[h]),(0,v.useEffect)(()=>{if(!e?.files)return;let t=new Set(e.files.filter(e=>e.syncable).map(e=>e.path));r(e=>{let n=new Set([...e].filter(e=>t.has(e)));return n.size===e.size?e:n})},[e]);let g=async(e,t)=>{l(e),d(``),p(``);try{let n=await A.request(`git.${e}`,{body:t??{}});n.ok&&n.data.ok?p(e===`push`?`pushed`:e===`pull`?`pulled`:`fetched`):d(M(n)||`${e} failed`)}catch(t){d(t.message||`${e} failed`)}finally{l(``)}h()},_=async()=>{l(`commit`),d(``),p(``);try{let e=await A.request(`git.commit`,{body:{paths:[...n],message:o}});e.ok&&e.data.ok?(p(`committed ${n.size} file${n.size===1?``:`s`}`),r(new Set),s(``)):d(M(e)||`commit failed`)}catch(e){d(e.message||`commit failed`)}finally{l(``)}h()};if(!e)return(0,F.jsx)(K,{children:`loading…`});if(!e.enabled)return(0,F.jsxs)(it,{children:[(0,F.jsx)(rt,{icon:`cloud_sync`,title:`Git sync`}),(0,F.jsx)(J,{children:(0,F.jsxs)(`p`,{className:Pu,children:[`Git sync is off. Turn it on in `,(0,F.jsx)(`a`,{href:`#/settings`,children:`settings`}),`, or add a `,(0,F.jsx)(`code`,{children:`git:`}),` block to kraftwerk.yml.`]})})]});let y=(e.files??[]).filter(e=>e.syncable),b=(e.files??[]).filter(e=>!e.syncable),x=(e,t)=>r(n=>{let r=new Set(n);return t?r.add(e):r.delete(e),r});return(0,F.jsxs)(it,{children:[(0,F.jsx)(rt,{icon:`cloud_sync`,title:`Git sync`,actions:(0,F.jsxs)(F.Fragment,{children:[f&&(0,F.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-sm text-ok`,children:[(0,F.jsx)(I,{name:`check`,className:`ms-sm`}),` `,f]}),u&&(0,F.jsx)(q,{tone:`bad`,children:u})]})}),(0,F.jsx)(J,{title:`branch`,actions:(0,F.jsxs)(F.Fragment,{children:[e.lastFetch&&(0,F.jsxs)(`span`,{className:`text-xs text-fg-2`,title:e.lastFetch,children:[`fetched `,Ge(e.lastFetch)]}),e.lastError&&(0,F.jsxs)(`span`,{className:`inline-flex max-w-[46ch] items-center gap-1 truncate text-xs text-bad`,title:e.lastError,children:[(0,F.jsx)(I,{name:`cloud_off`,className:`ms-sm`}),` `,e.lastError.split(`
228
- `)[0]]})]}),children:e.error?(0,F.jsxs)(`div`,{className:`flex items-center gap-2 p-[18px] text-sm text-bad`,children:[(0,F.jsx)(I,{name:`error`,className:`ms-sm`}),` `,e.error]}):(0,F.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4 px-[18px] py-3.5`,children:[(0,F.jsxs)(`div`,{className:`flex items-center gap-2 text-base`,children:[(0,F.jsx)(I,{name:`account_tree`,className:`ms-sm`}),(0,F.jsx)(`strong`,{className:`font-mono`,children:e.branch}),(0,F.jsx)(`span`,{className:Nu,children:e.upstream?`tracking ${e.upstream}`:`no upstream yet, push sets one`})]}),(0,F.jsxs)(`div`,{className:`flex items-center gap-2.5 text-[12.5px] font-semibold`,children:[e.diverged&&(0,F.jsx)(`span`,{className:`text-bad`,children:`diverged, resolve in a terminal`}),!!e.behind&&(0,F.jsxs)(`span`,{className:`text-accent`,children:[e.behind,` behind`]}),!!e.ahead&&(0,F.jsxs)(`span`,{className:`text-ok`,children:[e.ahead,` ahead`]}),!e.ahead&&!e.behind&&(0,F.jsx)(`span`,{className:P(`text-xs text-fg-2`,`font-normal`),children:`up to date`})]}),(0,F.jsxs)(`div`,{className:`ml-auto flex flex-wrap items-center gap-2`,children:[(0,F.jsx)(V,{size:`sm`,icon:`refresh`,busy:c===`fetch`,disabled:!!c,onClick:()=>void g(`fetch`),children:`fetch`}),(0,F.jsx)(V,{size:`sm`,icon:`download`,busy:c===`pull`,disabled:!!c||!e.behind||e.diverged,title:e.diverged?`Diverged. Resolve in a terminal.`:`Fast-forward to the remote`,onClick:()=>void g(`pull`),children:`pull`}),(0,F.jsx)(V,{size:`sm`,variant:`primary`,icon:`upload`,busy:c===`push`,disabled:!!c||!e.ahead&&!!e.upstream,title:e.upstream?`Push to the upstream`:`Push and set the upstream`,onClick:()=>void g(`push`),children:`push`})]})]})}),(0,F.jsxs)(J,{title:`changes`,actions:(0,F.jsx)(`span`,{className:Nu,children:y.length===0?`workspace clean`:`${n.size} of ${y.length} selected`}),children:[y.length===0&&b.length===0&&(0,F.jsx)(`p`,{className:`m-0 p-[18px] text-sm text-fg-2`,children:`Nothing changed under the workspace paths.`}),y.map(e=>(0,F.jsxs)(`div`,{className:P(`git-row px-[18px]`,Iu),children:[(0,F.jsx)(`input`,{type:`checkbox`,className:`accent-accent`,"aria-label":`select ${e.path}`,checked:n.has(e.path),onChange:t=>x(e.path,t.target.checked)}),(0,F.jsxs)(`button`,{type:`button`,className:`group/file flex min-w-0 flex-1 cursor-pointer items-center gap-2 border-0 bg-transparent px-0 py-0.5 text-left font-[inherit] text-fg`,onClick:()=>a(t=>{let n=new Set(t);return n.has(e.path)?n.delete(e.path):n.add(e.path),n}),children:[(0,F.jsx)(I,{name:i.has(e.path)?`expand_more`:`chevron_right`,className:`ms-sm`}),(0,F.jsx)(Mu,{status:e.status}),(0,F.jsx)(`span`,{className:P(Lu,`group-hover/file:underline`),children:e.path})]}),i.has(e.path)&&(0,F.jsx)(Du,{file:e.path})]},e.path)),y.length>0&&(0,F.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2.5 border-t border-line bg-surface-2 px-[18px] py-3`,children:[(0,F.jsx)(X,{className:`min-w-[220px] flex-1 text-sm`,placeholder:`Commit message`,"aria-label":`commit message`,value:o,onChange:e=>s(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!c&&o.trim()&&n.size>0&&_()}}),(0,F.jsx)(V,{size:`sm`,disabled:n.size===y.length,onClick:()=>r(new Set(y.map(e=>e.path))),children:`select all`}),(0,F.jsxs)(V,{size:`sm`,variant:`primary`,icon:`check`,busy:c===`commit`,disabled:!!c||n.size===0||!o.trim(),onClick:()=>void _(),children:[`commit `,n.size||``]})]}),b.length>0&&(0,F.jsxs)(`details`,{className:`border-t border-line px-[18px] py-2.5`,children:[(0,F.jsxs)(`summary`,{className:`cursor-pointer text-[12.5px] text-fg-2`,children:[b.length,e.blockedHidden?`+`:``,` change`,b.length===1&&!e.blockedHidden?``:`s`,` outside the workspace paths`]}),b.map(e=>(0,F.jsxs)(`div`,{className:P(`git-row blocked opacity-60`,Iu),children:[(0,F.jsx)(Mu,{status:e.status,muted:!0}),(0,F.jsx)(`span`,{className:Lu,children:e.path}),(0,F.jsx)(`span`,{className:`text-xs text-fg-2`,children:e.reason})]},e.path)),!!e.blockedHidden&&(0,F.jsx)(`div`,{className:P(`git-row blocked opacity-60`,Iu),children:(0,F.jsxs)(`span`,{className:`text-xs text-fg-2`,children:[`and `,e.blockedHidden,` more, not listed`]})})]})]}),(0,F.jsxs)(`p`,{className:P(Nu,`m-0`),children:[`Synced paths: `,(e.scope??[]).map((e,t)=>(0,F.jsxs)(`span`,{children:[t>0&&`, `,(0,F.jsx)(`code`,{children:e})]},e)),`. Run artifacts and files like `,(0,F.jsx)(`code`,{children:`.env`}),` are never staged.`,` `,e.interval?`Fetches every ${wu(e.interval)}${e.autosync===`pull`?` and fast-forwards when the working tree is clean`:``}. `:`Background fetching is off. `,`Commit and push are always manual.`]})]})}var Iu=`flex flex-wrap items-center gap-2.5 py-2 [&+&]:border-t [&+&]:border-line`,Lu=`truncate font-mono text-[12.5px]`,Ru=e=>e.replace(/^https?:\/\//,``).replace(/^git@([^:]+):/,`$1/`).replace(/\.git$/,``),zu=e=>e.error?{label:`unreadable`,state:`unreadable`}:e.dirty?{label:`${e.dirty} changed`,state:`changed`}:e.ahead?{label:`${e.ahead} to push`,state:`clean`}:e.behind?{label:`${e.behind} behind`,state:`behind`}:{label:`clean`,state:`clean`};function Bu({label:e,state:t}){return(0,F.jsx)(`span`,{className:P(`inline-flex items-center text-2xs font-semibold tracking-[0.4px] uppercase`,t===`clean`?`text-ok`:t===`changed`?`text-ask`:t===`unreadable`?`text-bad`:`text-fg-2`),children:e})}var Vu=`rounded-full border border-line px-[7px] py-px font-mono text-xs text-fg-2`,Hu=`border-line px-[18px] py-2 [&+&]:border-t`,Uu=`group/item flex w-full cursor-pointer items-center gap-2 border-0 bg-transparent px-0 py-0.5 text-left font-[inherit] text-fg`,Wu=`min-w-0 truncate font-mono text-[12.5px] group-hover/item:underline`;function Gu({title:e,children:t}){return(0,F.jsxs)(`header`,{className:`flex flex-wrap items-center gap-3`,children:[(0,F.jsx)(V,{size:`sm`,variant:`quiet`,icon:`arrow_back`,href:`/repos`,title:`all repositories`,children:`repositories`}),(0,F.jsx)(I,{name:`folder_data`,className:`text-[26px] text-fg-2`}),(0,F.jsx)(nt,{children:e}),t]})}var Ku=e=>!!(e.error||e.dirty||e.ahead===void 0||e.ahead);function qu({slug:e}){return e?(0,F.jsx)(Ju,{slug:e}):(0,F.jsx)(Yu,{})}function Ju({slug:e}){let[t,n]=(0,v.useState)(null),[r,i]=(0,v.useState)(``),[a,o]=(0,v.useState)(null),[s,c]=(0,v.useState)(null),[l,u]=(0,v.useState)(``),[d,f]=(0,v.useState)(``),[p,m]=(0,v.useState)(0),h=be(),g=(0,v.useCallback)(async()=>{try{let t=await A.request(`repos.get`,{slug:e});if(!t.ok)throw Error(M(t));n(t.data),i(``)}catch(e){i(e.message||`could not load the repository`)}},[e]);(0,v.useEffect)(()=>{let e=!0,t,n=async()=>{await g(),e&&(t=setTimeout(n,5e3))};return n(),()=>{e=!1,clearTimeout(t)}},[g,p]);let _=async()=>{u(`update`),f(``);try{let t=await A.request(`repos.update`,{slug:e});if(!t.ok||!t.data.ok)throw Error(t.error||`failed`);t.data.error&&f(t.data.error)}catch(e){f(e.message)}finally{u(``),m(e=>e+1)}};if(r&&!t)return(0,F.jsxs)(it,{className:`repo-page`,children:[(0,F.jsx)(Gu,{title:e}),(0,F.jsx)(q,{tone:`bad`,children:r})]});if(!t)return(0,F.jsx)(K,{children:`loading…`});let y=zu(t),b=t.commits.filter(e=>e.local).length;return(0,F.jsxs)(it,{className:`repo-page`,children:[(0,F.jsxs)(Gu,{title:t.slug,children:[t.branch&&(0,F.jsx)(`span`,{className:Vu,children:t.branch}),t.upstream&&(0,F.jsxs)(`span`,{className:`text-xs text-fg-2`,title:`upstream`,children:[`→ `,t.upstream]}),(0,F.jsx)(Bu,{...y}),(0,F.jsx)(`span`,{className:`flex-1`}),(0,F.jsx)(V,{size:`sm`,icon:`sync`,busy:l===`update`,disabled:!!l,onClick:()=>void _(),title:`git fetch, then fast-forward when clean`,children:l===`update`?`updating…`:`update`})]}),(0,F.jsxs)(`div`,{className:P(Nu,`flex flex-wrap gap-x-3.5 gap-y-1`),children:[t.url&&(0,F.jsx)(`span`,{title:t.url,children:Ru(t.url)}),h&&(0,F.jsx)(`span`,{title:t.path,children:t.path}),t.head&&(0,F.jsxs)(`span`,{children:[`at `,(0,F.jsx)(`code`,{children:t.head}),t.committedAt?` · ${Ge(t.committedAt)}`:``]}),!!t.ahead&&(0,F.jsxs)(`span`,{children:[t.ahead,` to push`]}),!!t.behind&&(0,F.jsxs)(`span`,{children:[t.behind,` behind`]}),t.updatedAt&&(0,F.jsxs)(`span`,{children:[`changed `,Ge(t.updatedAt)]})]}),(t.error||d||r)&&(0,F.jsx)(q,{tone:`bad`,children:t.error||d||r}),(0,F.jsxs)(J,{title:`changes · working tree against HEAD`,actions:(0,F.jsxs)(`span`,{className:Nu,children:[t.files.length,` file`,t.files.length===1?``:`s`,t.insertions||t.deletions?(0,F.jsxs)(F.Fragment,{children:[` · `,(0,F.jsxs)(`span`,{className:`text-ok`,children:[`+`,t.insertions]}),` `,(0,F.jsxs)(`span`,{className:`text-bad`,children:[`−`,t.deletions]})]}):null]}),children:[t.files.length===0&&(0,F.jsx)(`p`,{className:`m-0 p-[18px] text-sm text-fg-2`,children:`Clean — nothing changed since the last commit.`}),t.files.map(n=>(0,F.jsxs)(`div`,{className:P(`repo-file`,Hu),"data-file":n.path,children:[(0,F.jsxs)(`button`,{type:`button`,className:Uu,onClick:()=>o(a===n.path?null:n.path),children:[(0,F.jsx)(I,{name:a===n.path?`expand_more`:`chevron_right`,className:`ms-sm`}),(0,F.jsx)(Mu,{status:n.status}),(0,F.jsx)(`span`,{className:Wu,children:n.path})]}),a===n.path&&(0,F.jsx)(ku,{source:{route:`repos.diff`,input:{slug:e,query:{path:n.path}}},refresh:t.updatedAt})]},n.path))]}),(0,F.jsxs)(J,{title:`commits · newest first`,actions:(0,F.jsx)(`span`,{className:Nu,children:b?`${b} not pushed`:t.commits.length?`all pushed`:``}),children:[t.commits.length===0&&(0,F.jsx)(`p`,{className:`m-0 p-[18px] text-sm text-fg-2`,children:`No commits yet.`}),t.commits.map(t=>(0,F.jsxs)(`div`,{className:P(`repo-commit`,Hu),"data-commit":t.short,children:[(0,F.jsxs)(`button`,{type:`button`,className:Uu,onClick:()=>c(s===t.hash?null:t.hash),title:t.hash,children:[(0,F.jsx)(I,{name:s===t.hash?`expand_more`:`chevron_right`,className:`ms-sm`}),(0,F.jsx)(`code`,{className:`text-xs`,children:t.short}),(0,F.jsx)(`span`,{className:`min-w-0 truncate text-sm group-hover/item:underline`,children:t.subject}),t.local&&(0,F.jsx)(W,{tone:`accent`,children:`not pushed`}),(0,F.jsxs)(`span`,{className:P(Nu,`ml-auto flex-none`),children:[t.author,` · `,Ge(t.committedAt)]})]}),s===t.hash&&(0,F.jsx)(ku,{source:{route:`repos.commit`,input:{slug:e,hash:t.hash}}})]},t.hash))]})]})}function Yu(){let[e,t]=(0,v.useState)(null),[n,r]=(0,v.useState)(``),[i,a]=(0,v.useState)({}),[o,s]=(0,v.useState)({}),[c,l]=(0,v.useState)(null),[u,d]=(0,v.useState)(``),[f,p]=(0,v.useState)(``),[m,h]=(0,v.useState)(``),[g,_]=(0,v.useState)(!1),[y,b]=(0,v.useState)(``),x=be(),S=(0,v.useCallback)(async()=>{try{let e=await A.request(`repos.list`);if(!e.ok)throw Error(`HTTP ${e.status}`);t(e.data),r(``)}catch(e){r(e.message||`could not load repositories`)}},[]);(0,v.useEffect)(()=>{let e=!0,t,n=async()=>{await S(),e&&(t=setTimeout(n,15e3))};return n(),()=>{e=!1,clearTimeout(t)}},[S]);let C=async(e,t,n=!1)=>{a(n=>({...n,[e]:t})),s(t=>({...t,[e]:``})),l(null);try{let r=t===`update`?await A.request(`repos.update`,{slug:e}):await A.request(`repos.remove`,{slug:e,query:{force:n}});if(!r.ok||!r.data.ok)throw Error(r.error||`failed`);let i=r.data.error;i&&s(t=>({...t,[e]:i}))}catch(t){s(n=>({...n,[e]:t.message}))}finally{a(t=>{let n={...t};return delete n[e],n}),S()}},w=async e=>{if(e.preventDefault(),u.trim()&&!g){_(!0),b(``);try{let e=await A.request(`repos.add`,{body:{url:u.trim(),name:f.trim()||void 0,branch:m.trim()||void 0}});if(!e.ok)throw Error(e.error||`clone failed`);d(``),p(``),h(``),await S()}catch(e){b(e.message)}finally{_(!1)}}},T=[...e?.repos??[]].sort((e,t)=>(t.updatedAt??``).localeCompare(e.updatedAt??``));return(0,F.jsxs)(it,{children:[(0,F.jsx)(rt,{icon:`source`,title:`Repositories`,actions:(0,F.jsxs)(F.Fragment,{children:[e?.enabled&&(0,F.jsxs)(`span`,{className:`text-xs text-fg-2`,children:[T.length,` cloned`]}),n&&(0,F.jsx)(q,{tone:`bad`,children:n})]})}),e&&!e.enabled&&(0,F.jsx)(J,{children:(0,F.jsx)(`div`,{className:`m-0 p-[18px] text-sm text-fg-2`,children:e.error&&!/are off/.test(e.error)?(0,F.jsx)(q,{tone:`bad`,children:e.error}):(0,F.jsxs)(F.Fragment,{children:[`Repositories are off. Turn them on in `,(0,F.jsx)(`a`,{href:`#/settings`,children:`settings`}),` or add a `,(0,F.jsx)(`code`,{children:`repos:`}),` block to kraftwerk.yml.`]})})}),e?.enabled&&(0,F.jsx)(J,{title:`add a repository`,actions:(0,F.jsxs)(`span`,{className:`text-xs text-fg-2`,children:[`clones into `,(0,F.jsx)(`code`,{title:e.root,children:e.root})]}),children:(0,F.jsxs)(`form`,{className:`flex flex-col gap-2.5 p-[18px]`,onSubmit:e=>void w(e),children:[(0,F.jsxs)(`div`,{className:`flex flex-wrap items-end gap-2.5`,children:[(0,F.jsx)(Z,{label:`url`,className:`min-w-[240px] flex-[2]`,children:(0,F.jsx)(X,{value:u,placeholder:`https://github.com/org/repo.git, git@host:org/repo.git or github:org/repo`,onChange:e=>d(e.target.value),autoFocus:!0})}),(0,F.jsx)(Z,{label:`name`,className:`min-w-[140px] flex-1`,children:(0,F.jsx)(X,{value:f,placeholder:`from the url`,onChange:e=>p(e.target.value)})}),(0,F.jsx)(Z,{label:`branch`,className:`w-[140px]`,children:(0,F.jsx)(X,{value:m,placeholder:`default`,onChange:e=>h(e.target.value)})}),(0,F.jsx)(V,{type:`submit`,variant:`primary`,icon:`download`,busy:g,disabled:!u.trim(),children:g?`cloning…`:`clone`})]}),y&&(0,F.jsx)(q,{tone:`bad`,children:y}),(0,F.jsxs)(`p`,{className:P(`text-xs text-fg-2`,`m-0`),children:[`Uses your own git credentials and never prompts: a private remote must already work from a terminal. Agents see every clone here and can add more with `,(0,F.jsx)(`code`,{children:`kraftwerk repos add`}),`.`]})]})}),e?.enabled&&(0,F.jsxs)(J,{title:`cloned repositories · newest change first`,children:[T.length===0&&(0,F.jsx)(`p`,{className:`m-0 p-[18px] text-sm text-fg-2`,children:`Nothing cloned yet.`}),T.map(e=>{let t=i[e.slug],n=zu(e);return(0,F.jsxs)(`div`,{className:P(`repo-row grid grid-cols-[40px_minmax(0,1fr)_auto] items-start gap-3.5 border-line px-[18px] py-3.5 [&+&]:border-t`,n.state===`changed`&&`bg-ask-soft/40`),"data-repo":e.slug,children:[(0,F.jsx)(`span`,{className:P(`grid size-10 place-items-center rounded-full bg-surface-2 text-fg-2`,n.state===`unreadable`&&`opacity-45 grayscale`),children:(0,F.jsx)(I,{name:`folder_data`,className:`text-[22px]`})}),(0,F.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-[3px]`,children:[(0,F.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2.5`,children:[(0,F.jsx)(he,{href:`/repos/${encodeURIComponent(e.slug)}`,className:`text-md font-semibold text-fg no-underline hover:underline`,title:`changes and commits`,children:e.slug}),e.branch&&(0,F.jsx)(`span`,{className:Vu,children:e.branch}),(0,F.jsx)(Bu,{...n}),e.updatedAt&&(0,F.jsxs)(`span`,{className:`text-xs text-fg-2`,title:e.updatedAt,children:[`changed `,Ge(e.updatedAt)]})]}),e.url&&(0,F.jsx)(`div`,{className:`font-mono text-xs [overflow-wrap:anywhere] text-fg-2`,title:e.url,children:Ru(e.url)}),x&&(0,F.jsx)(`div`,{className:`text-xs [overflow-wrap:anywhere] text-fg-2 opacity-70`,title:e.path,children:e.path}),(0,F.jsxs)(`div`,{className:P(`text-xs text-fg-2`,`flex flex-wrap gap-x-3.5 gap-y-1 [&_code]:text-[11.5px]`),children:[e.head&&(0,F.jsxs)(`span`,{title:e.committedAt,children:[(0,F.jsx)(`code`,{children:e.head}),` `,e.subject,e.committedAt?` · ${Ge(e.committedAt)}`:``]}),!!e.behind&&!!e.dirty&&(0,F.jsxs)(`span`,{children:[`behind by `,e.behind]}),e.error&&(0,F.jsx)(`span`,{className:`text-bad`,children:e.error})]}),o[e.slug]&&(0,F.jsx)(q,{tone:`bad`,children:o[e.slug]})]}),(0,F.jsxs)(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[(0,F.jsx)(V,{size:`sm`,icon:`difference`,href:`/repos/${encodeURIComponent(e.slug)}`,title:`changed files with diffs, recent commits`,children:`changes`}),(0,F.jsx)(V,{size:`sm`,icon:`sync`,busy:t===`update`,disabled:!!t,onClick:()=>void C(e.slug,`update`),title:`git fetch, then fast-forward when clean`,children:t===`update`?`updating…`:`update`}),c!==e.slug&&(0,F.jsx)(V,{size:`sm`,icon:`delete`,disabled:!!t,onClick:()=>l(e.slug),title:`Move the clone to the trash`,children:`remove`}),c===e.slug&&(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(V,{size:`sm`,variant:`danger`,icon:`delete`,onClick:()=>void C(e.slug,`remove`,Ku(e)),children:e.dirty||e.ahead?`delete with local changes`:Ku(e)?`delete anyway`:`confirm remove`}),(0,F.jsx)(V,{size:`sm`,variant:`quiet`,onClick:()=>l(null),children:`cancel`})]})]})]},e.slug)})]})]})}var Xu=40,Zu=/Mac|iPhone|iPad/.test(navigator.platform),Qu=null,$u=e=>(e?.workspaces??[]).flatMap(e=>[...e.agents.map(t=>({kind:`agent`,agent:t,ws:e,key:`${e.url}|agent|${t.slug}`})),...(e.projects??[]).map(t=>({kind:`project`,project:t,ws:e,key:`${e.url}|project|${t.slug}`})),...(e.channels??[]).map(t=>({kind:`channel`,channel:t,ws:e,key:`${e.url}|channel|${t.slug}`}))]),ed=e=>e.kind===`agent`?e.agent.name:e.kind===`project`?e.project.title:e.channel.name,td=e=>e.kind===`agent`?e.agent.description:e.kind===`project`?e.project.goal||(e.project.status===`active`?void 0:e.project.status):e.channel.purpose,nd=e=>e.kind===`agent`?`/agents/${encodeURIComponent(e.agent.slug)}`:e.kind===`project`?`/projects/${encodeURIComponent(e.project.slug)}`:`/channels/${encodeURIComponent(e.channel.slug)}`,rd={active:`📁`,paused:`⏸️`,done:`✅`,archived:`🗄️`},id=e=>e.kind===`agent`?e.agent.emoji:e.kind===`project`?rd[e.project.status]:(0,F.jsx)(I,{name:`forum`,className:`text-[18px] text-fg-2`}),ad=`flex-none rounded-full border border-line px-1.5 py-px text-[10px] font-semibold tracking-[0.4px] uppercase`;function od(e,t){let n=t.toLowerCase().split(/\s+/).filter(Boolean);if(n.length===0)return e;let r=[],i=new Map;for(let t of e){i.has(t.ws)||i.set(t.ws,i.size);let e=ed(t).toLowerCase(),a=[e,...t.kind===`agent`?[t.agent.slug,t.agent.description??``,t.agent.group??``,`agent`]:t.kind===`project`?[t.project.slug,t.project.goal??``,t.project.status,`project`]:[t.channel.slug,t.channel.purpose??``,`channel`],t.ws.name].join(` `).toLowerCase();if(!n.every(e=>a.includes(e)))continue;let o=e.startsWith(n[0])?0:e.includes(n[0])?1:2;r.push({hit:t,score:o,ws:i.get(t.ws)})}return r.sort((e,t)=>e.ws-t.ws||e.score-t.score).map(e=>e.hit)}function sd(e){let t=[];for(let n of e){let e=t.find(e=>e.ws===n.ws);e?e.hits.push(n):t.push({ws:n.ws,hits:[n]})}return t}async function cd(e){let t=nd(e);if(e.ws.current)return B(t);let n=e.ws.live||!e.ws.root?fe(e.ws):await pe(e.ws.root);window.location.assign(`${n.replace(/\/+$/,``)}/#${t}`)}function ld(){let[e,t]=(0,v.useState)(!1);return(0,v.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&!e.altKey&&!e.shiftKey&&e.key.toLowerCase()===`k`&&(e.preventDefault(),t(e=>!e))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[]),(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(`button`,{type:`button`,className:`inline-flex flex-none cursor-pointer items-center gap-1.5 rounded-xl border-0 bg-transparent py-1 pr-2 pl-1.5 text-fg-2 transition-colors hover:bg-surface-2 hover:text-fg active:scale-96`,onClick:()=>t(!0),title:`jump to an agent, project or channel`,"aria-label":`search`,children:[(0,F.jsx)(I,{name:`search`}),(0,F.jsx)($e,{className:`max-[1100px]:hidden`,children:Zu?`⌘K`:`Ctrl K`})]}),e&&(0,F.jsx)(ud,{onClose:()=>t(!1)})]})}function ud({onClose:e}){let[t,n]=(0,v.useState)(Qu),[r,i]=(0,v.useState)(Qu===null),[a,o]=(0,v.useState)(!1),[s,c]=(0,v.useState)(``),[l,u]=(0,v.useState)(0),[d,f]=(0,v.useState)(null),[p,m]=(0,v.useState)(``),h=(0,v.useRef)(null);(0,v.useEffect)(()=>{let e=!0;return A.call(`search.agents`).then(t=>{Qu=t,e&&n(t)}).catch(()=>e&&o(!0)).finally(()=>e&&i(!1)),()=>{e=!1}},[]);let g=(0,v.useMemo)(()=>$u(t),[t]),_=(0,v.useMemo)(()=>od(g,s).slice(0,Xu),[g,s]),y=(0,v.useMemo)(()=>sd(_),[_]),b=Math.min(l,Math.max(_.length-1,0));(0,v.useEffect)(()=>{h.current?.querySelector(`[aria-selected="true"]`)?.scrollIntoView({block:`nearest`})},[b,_]);let x=t=>{if(!d){if(t.ws.current||t.ws.live){e(),cd(t);return}f(t.key),m(``),cd(t).catch(e=>{f(null),m(`${t.ws.name}: ${e.message}`)})}},S=t=>{if(t.key===`ArrowDown`)t.preventDefault(),u(_.length?(b+1)%_.length:0);else if(t.key===`ArrowUp`)t.preventDefault(),u(_.length?(b-1+_.length)%_.length:0);else if(t.key===`Enter`){t.preventDefault();let e=_[b];e&&x(e)}else t.key===`Escape`&&(t.preventDefault(),e())},C=`px-4 py-7 text-center text-sm text-fg-2 [&_a]:underline`,w;if(_.length>0){let e=-1;w=(0,F.jsx)(`ul`,{className:`m-0 list-none overflow-y-auto overscroll-contain p-1.5`,role:`listbox`,"aria-label":`agents, projects and channels`,ref:h,children:y.map(t=>(0,F.jsxs)(v.Fragment,{children:[(0,F.jsxs)(`li`,{className:`palette-group flex items-center gap-1.5 px-2.5 pt-3 pb-1 text-2xs font-semibold tracking-[0.4px] text-fg-2 uppercase first:pt-1.5`,role:`presentation`,title:t.ws.current?`this workspace`:t.ws.url,children:[t.ws.icon&&(0,F.jsx)(`span`,{"aria-hidden":!0,children:t.ws.icon}),(0,F.jsx)(`span`,{className:`truncate`,children:t.ws.name}),t.ws.current?(0,F.jsx)(`span`,{className:`font-normal tracking-normal normal-case`,children:`this workspace`}):t.ws.live?(0,F.jsx)(I,{name:`open_in_new`,className:`ms-sm`}):(0,F.jsx)(`span`,{className:ad,children:`stopped`})]}),t.hits.map(t=>{let n=++e;return(0,F.jsxs)(`li`,{role:`option`,"aria-selected":n===b,className:P(`flex cursor-pointer items-center gap-2.5 rounded-xl px-2.5 py-2`,n===b&&`bg-surface-2`),onMouseMove:()=>n!==b&&u(n),onClick:()=>x(t),children:[(0,F.jsx)(`span`,{className:`w-6 flex-none text-center text-[18px] leading-none`,"aria-hidden":!0,children:id(t)}),(0,F.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,F.jsx)(`span`,{className:`truncate text-[13.5px] font-medium text-fg`,children:ed(t)}),td(t)&&(0,F.jsx)(`span`,{className:`truncate text-xs text-fg-2`,children:td(t)})]}),d===t.key?(0,F.jsx)(I,{name:`progress_activity`,className:`ms-sm`}):t.kind!==`agent`&&(0,F.jsx)(`span`,{className:P(ad,`text-fg-2`),children:t.kind})]},t.key)})]},t.ws.url||t.ws.name))})}else w=a?(0,F.jsx)(`div`,{className:C,children:`could not load the agents, projects and channels`}):r?(0,F.jsx)(`div`,{className:C,children:`looking for agents, projects and channels…`}):g.length===0?(0,F.jsxs)(`div`,{className:C,children:[`no agents yet — `,(0,F.jsx)(`a`,{href:`#/agents/new`,onClick:e,children:`create one`})]}):(0,F.jsxs)(`div`,{className:C,children:[`no agent, project or channel matches “`,s,`”`]});return(0,F.jsx)(`div`,{className:`palette-backdrop fixed inset-0 z-50 flex animate-fade items-start justify-center bg-black/35 px-4 pt-[12vh] pb-4`,onMouseDown:e,children:(0,F.jsxs)(`div`,{className:`flex max-h-[min(70dvh,560px)] w-[min(620px,100%)] animate-modal flex-col overflow-hidden rounded-2xl border border-line bg-surface shadow-modal`,role:`dialog`,"aria-label":`jump to an agent, project or channel`,onMouseDown:e=>e.stopPropagation(),onKeyDown:S,children:[(0,F.jsxs)(`div`,{className:`flex items-center gap-2.5 border-b border-line px-4 py-3 text-fg-2`,children:[(0,F.jsx)(I,{name:`search`}),(0,F.jsx)(`input`,{autoFocus:!0,className:`min-w-0 flex-1 border-0 bg-transparent p-0 font-sans text-[16px] text-fg outline-none`,value:s,onChange:e=>{c(e.target.value),u(0)},placeholder:`jump to an agent, project or channel…`,"aria-label":`search`,autoComplete:`off`,spellCheck:!1}),r&&t&&(0,F.jsx)(I,{name:`progress_activity`,className:`ms-sm`}),(0,F.jsx)($e,{children:`esc`})]}),w,(0,F.jsxs)(`div`,{className:`flex items-center gap-3.5 border-t border-line px-3.5 py-2 text-2xs text-fg-2 [&>span]:inline-flex [&>span]:items-center [&>span]:gap-1`,children:[(0,F.jsxs)(`span`,{children:[(0,F.jsx)($e,{children:`↑`}),(0,F.jsx)($e,{children:`↓`}),` move`]}),(0,F.jsxs)(`span`,{children:[(0,F.jsx)($e,{children:`↵`}),` open`]}),d&&(0,F.jsxs)(`span`,{className:`ml-auto`,children:[(0,F.jsx)(I,{name:`progress_activity`,className:`ms-sm`}),` starting the workspace…`]}),p&&(0,F.jsxs)(`span`,{className:`ml-auto max-w-[60%] truncate text-bad`,title:p,children:[(0,F.jsx)(I,{name:`warning`,className:`ms-sm`}),` `,p]})]})]})})}var dd=1296e5;function fd(e){if(e<6e4)return`just now`;let t=Math.floor(e/6e4);if(t<60)return`${t}m`;let n=Math.floor(t/60);return n<24?`${n}h`:`${Math.floor(n/24)}d`}function pd(e,t){let n=new Date(e),r=n.toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`}),i=Math.round((new Date(n).setHours(0,0,0,0)-new Date(t).setHours(0,0,0,0))/864e5);return i<=0?r:i===1?`tomorrow ${r}`:`${n.toLocaleDateString([],{weekday:`short`})} ${r}`}function md(e,t=``,n=new Date){if(!e)return t?{text:t,tone:`plain`}:null;let r=e=>`${e[0].title||`a session`}${e.length>1?` +${e.length-1}`:``}`;if(e.waiting.length)return{text:`waiting for you · ${r(e.waiting)}`,tone:`waiting`};if(e.working.length){let t=e.working[0].since,i=t?fd(Math.max(0,n.getTime()-Date.parse(t))):``;return{text:`working · ${r(e.working)}${i&&i!==`just now`?` · ${i}`:``}`,tone:`working`}}if(e.nextRoutine&&Date.parse(e.nextRoutine.at)-n.getTime()<dd)return{text:`next: ${e.nextRoutine.name} · ${pd(e.nextRoutine.at,n)}`,tone:`plain`};if(e.lastActiveAt){let t=fd(Math.max(0,n.getTime()-Date.parse(e.lastActiveAt)));return{text:t===`just now`?`last active just now`:`last active ${t} ago`,tone:`plain`}}return{text:t||`no sessions yet`,tone:`plain`}}var hd=e=>`section`in e;function gd(e){return[...e.top.map(e=>({slug:e})),...e.sections.flatMap(e=>[{section:e.name},...e.projects.map(e=>({slug:e}))])]}function _d(e){let t={top:[],sections:[]};for(let n of e)hd(n)?t.sections.push({name:n.section,projects:[]}):(t.sections.at(-1)?.projects??t.top).push(n.slug);return t}var vd=(e,t)=>hd(e)?`section`in t&&e.section===t.section:`slug`in t&&e.slug===t.slug;function yd(e,t,n){let r=e.findIndex(e=>vd(e,t));if(r<0)return e;let i=r+1;if(`section`in t)for(;i<e.length&&!hd(e[i]);)i++;if(n>=r&&n<=i)return e;let a=e.slice(r,i),o=[...e.slice(0,r),...e.slice(i)],s=n>r?n-a.length:n;return[...o.slice(0,s),...a,...o.slice(s)]}function bd({layout:e,visible:t,render:n,onSave:r,collapsed:i,onCollapse:a,editing:o,onEdited:s}){let[c,l]=(0,v.useState)(null),u=c??gd(e);(0,v.useEffect)(()=>l(null),[JSON.stringify(e)]);let[d,f]=(0,v.useState)(null),[p,m]=(0,v.useState)(null),[h,g]=(0,v.useState)(o);(0,v.useEffect)(()=>g(o),[o]);let _=async e=>{l(e),await r(_d(e))||l(null)},y=()=>{f(null),m(null)},b=(e,t)=>{let n=e.currentTarget.getBoundingClientRect(),r=e.clientY>n.top+n.height/2,i=u[t];if(d&&`slug`in d&&hd(i))return t+1;if(d&&`section`in d){let e=t;for(;e>=0&&!hd(u[e]);)e--;if(e<0)return u.findIndex(hd)<0?u.length:u.findIndex(hd);if(!r&&e===t)return e;let n=e+1;for(;n<u.length&&!hd(u[n]);)n++;return n}return r?t+1:t},x=e=>({onDragOver:t=>{if(!d)return;t.preventDefault(),t.stopPropagation(),t.dataTransfer.dropEffect=`move`;let n=e===void 0?u.length:b(t,e);n!==p&&m(n)},onDrop:t=>{if(!d)return;t.preventDefault(),t.stopPropagation();let n=yd(u,d,e===void 0?u.length:b(t,e));y(),n!==u&&_(n)}}),S=e=>({draggable:!0,onDragStart:t=>{t.stopPropagation(),t.dataTransfer.effectAllowed=`move`,t.dataTransfer.setData(`text/plain`,`slug`in e?e.slug:e.section),f(e)},onDragEnd:y}),C=e=>t=>{if(!t.altKey||t.key!==`ArrowUp`&&t.key!==`ArrowDown`)return;t.preventDefault();let n=u.findIndex(t=>!hd(t)&&t.slug===e),r=t.key===`ArrowUp`?n-1:n+2;r<0||r>u.length||_(yd(u,{slug:e},r))},w=e=>d&&p===e?(0,F.jsx)(`div`,{className:`relative h-0`,"aria-hidden":!0,children:(0,F.jsx)(`div`,{className:`absolute inset-x-2 -top-px h-0.5 rounded-full bg-accent`})}):null,T=[],E;return u.forEach((e,r)=>{if(T.push((0,F.jsx)(v.Fragment,{children:w(r)},`line:${r}`)),hd(e)){E=e.section;let t=e.section,n=i(t),o=0;for(let e=r+1;e<u.length&&!hd(u[e]);e++)o++;T.push((0,F.jsx)(`div`,{...x(r),...h===t?{}:S({section:t}),className:P(`group/sec mt-2 flex items-center gap-0.5 rounded-control pl-1 pr-1`,d&&`section`in d&&d.section===t&&`opacity-40`),"data-section":t,children:h===t?(0,F.jsx)(xd,{name:t,taken:u.filter(hd).map(e=>e.section).filter(e=>e!==t),onDone:e=>{g(void 0),s(),e&&e!==t&&_(u.map(n=>hd(n)&&n.section===t?{section:e}:n))}}):(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(`button`,{type:`button`,className:`flex min-w-0 flex-1 cursor-pointer items-center gap-1 border-0 bg-transparent px-1 py-1 text-left font-[inherit] text-xs font-semibold text-fg-2 hover:text-fg`,"aria-expanded":!n,title:n?`show the projects in ${t}`:`fold ${t}`,onClick:()=>a(t),children:[(0,F.jsx)(I,{name:`chevron_right`,className:P(`ms-sm flex-none text-[15px] transition-transform`,!n&&`rotate-90`)}),(0,F.jsx)(`span`,{className:`min-w-0 truncate`,children:t}),(0,F.jsx)(`span`,{className:`font-normal tabular-nums opacity-70`,children:o})]}),(0,F.jsxs)(`span`,{className:`flex items-center opacity-0 transition-opacity group-hover/sec:opacity-100 group-focus-within/sec:opacity-100 pointer-coarse:opacity-100`,children:[(0,F.jsx)(H,{size:`sm`,icon:`edit`,label:`rename section ${t}`,onClick:()=>g(t)}),(0,F.jsx)(H,{size:`sm`,icon:`close`,label:`remove section ${t}`,title:`remove the section; its projects move up`,onClick:()=>void _(u.filter(e=>!(hd(e)&&e.section===t)))})]})]})},`section:${t}`));return}E&&i(E)&&!t(e.slug)||T.push((0,F.jsx)(`div`,{...x(r),...S({slug:e.slug}),onKeyDown:C(e.slug),className:P(`flex flex-col gap-0.5`,d&&`slug`in d&&d.slug===e.slug&&`opacity-40`),"data-sort":e.slug,children:n(e.slug)},e.slug))}),T.push((0,F.jsx)(v.Fragment,{children:w(u.length)},`line:end`)),d&&T.push((0,F.jsx)(`div`,{className:`h-4`,...x()},`drop:end`)),(0,F.jsx)(F.Fragment,{children:T})}function xd({name:e,taken:t,onDone:n}){let[r,i]=(0,v.useState)(e),a=(0,v.useRef)(null);(0,v.useEffect)(()=>{a.current?.focus(),a.current?.select()},[]);let o=r.trim().slice(0,60),s=!!o&&!t.includes(o);return(0,F.jsx)(`input`,{ref:a,value:r,"aria-label":`section name`,maxLength:60,className:P(`min-w-0 flex-1 rounded-control border bg-surface px-2 py-1 font-[inherit] text-xs font-semibold text-fg outline-none`,s?`border-line focus:border-accent`:`border-bad`),onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Enter`&&n(s?o:void 0),e.key===`Escape`&&n()},onBlur:()=>n(s?o:void 0)})}function Sd(e){let t=new Set(e.sections.map(e=>e.name)),n=`New section`;for(let e=2;t.has(n);e++)n=`New section ${e}`;return n}function Cd({chatPath:e}){let t=we(),n=be(),r=N(`agents.list`,{},{interval:15e3}),i=N(`channels.list`,{},{interval:6e3}),a=N(`projects.list`,t.projects?{}:null,{interval:15e3}),o=N(`agents.status`,{},{interval:5e3}),s=N(`vibeables.list`,t.vibeables?{}:null,{interval:15e3}),c=new Set((s?.vibeables??[]).map(e=>e.slug)),l=e.split(`/`).filter(Boolean),u=(e,t)=>l[0]===e&&(t===void 0||(l[1]?decodeURIComponent(l[1]):void 0)===t),d=l[0]===`agents`&&l[1]===`chats`,[f,p]=Od(),[m,h]=(0,v.useState)(),g=l[0]===`projects`&&l[1]&&l[1]!==`new`?decodeURIComponent(l[1]):void 0;(0,v.useEffect)(()=>{g&&h(g)},[g]);let _=Ft()??[],y=new Map((r?.agents??[]).filter(e=>!e.archived).map(e=>[e.slug,e])),b=a?.projects??[],x=e=>(e.agents??[]).map(e=>y.get(e)).filter(e=>!!e),S=e=>u(`projects`,e.slug)||e.slug===m&&x(e).some(e=>u(`agents`,e.slug)),C=new Map(b.map(e=>[e.slug,e])),w=a?.layout?[...a.layout.top,...a.layout.sections.flatMap(e=>e.projects)].map(e=>C.get(e)).filter(e=>!!e):b,T=async e=>!!(await A.request(`projects.saveLayout`,{body:e}).catch(()=>null))?.ok,[E,D]=(0,v.useState)(),O=async()=>{if(!a?.layout)return;let e=Sd(a.layout);await T({...a.layout,sections:[...a.layout.sections,{name:e,projects:[]}]})&&D(e)},k=e=>{let n=x(e),r=t.vibeables?(e.vibeables??[]).filter(e=>c.has(e)):[],i=f.open[e.slug]??e.slug===(g??m),a=n.map(e=>o?.[e.slug]).filter(e=>!!e),s=!i&&a.some(e=>e.working.length&&!e.waiting.length);return(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(Y,{size:`sm`,href:`/projects/${encodeURIComponent(e.slug)}`,active:u(`projects`,e.slug)&&!i,innerProps:{"data-project":e.slug,title:e.goal?`${e.title}: ${e.goal}`:e.title},leading:(0,F.jsx)(`span`,{"aria-hidden":!0,children:e.status===`done`?`✅`:e.status===`paused`?`⏸️`:e.status===`archived`?`🗄️`:`📁`}),title:e.title,titleExtra:(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(Qe,{n:It.project(_,e.slug,e.agents).length,title:`waiting for you`}),s&&(0,F.jsx)(U,{tone:`working`,title:`an agent is working`})]}),titleLines:2,actionsAlways:i,actions:(0,F.jsx)(H,{size:`sm`,icon:i?`expand_more`:`chevron_right`,label:`${i?`collapse`:`expand`} ${e.title}`,"aria-expanded":i,title:i?`hide its assistant, agents and apps`:[`the assistant`,n.length&&`${n.length} agent${n.length===1?``:`s`}`,r.length&&`${r.length} app${r.length===1?``:`s`}`].filter(Boolean).join(`, `),onClick:()=>p(t=>({...t,open:{...t.open,[e.slug]:!i}}))})}),i&&(0,F.jsx)(Y,{className:wd,size:`sm`,href:`/projects/${encodeURIComponent(e.slug)}`,active:u(`projects`,e.slug),innerProps:{title:`${e.title}'s assistant: knows its brief, state and links`,"data-nested":`assistant`},leading:(0,F.jsx)(`span`,{"aria-hidden":!0,children:ze.emoji}),title:(0,F.jsx)(`span`,{className:`font-medium`,children:ze.name}),titleExtra:(0,F.jsx)(Qe,{n:_.filter(t=>t.owner.project?.slug===e.slug&&!t.owner.agent).length,title:`waiting for you`})}),i&&n.map(t=>(0,F.jsx)(Y,{className:wd,size:`sm`,href:`/agents/${encodeURIComponent(t.slug)}`,active:u(`agents`,t.slug),onClick:()=>h(e.slug),innerProps:{title:t.description||t.name,"data-nested":`agent`},leading:(0,F.jsx)(`span`,{"aria-hidden":!0,children:t.emoji||`🤖`}),title:(0,F.jsx)(`span`,{className:`font-medium`,children:t.name}),titleExtra:(0,F.jsx)(Ed,{n:It.agent(_,t.slug).length,st:o?.[t.slug]})},t.slug)),i&&r.map(t=>(0,F.jsx)(Y,{className:wd,size:`sm`,href:`/projects/${encodeURIComponent(e.slug)}?app=${encodeURIComponent(t)}`,onClick:()=>h(e.slug),innerProps:{title:`open ${t} beside the project's chat`,"data-nested":`app`},leading:(0,F.jsx)(I,{name:`web`,className:`ms-sm`}),title:(0,F.jsx)(`span`,{className:`font-medium`,children:t})},`app:${t}`))]})};return(0,F.jsx)(`nav`,{className:`rail`,"aria-label":`Conversations`,children:(0,F.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-0.5 overflow-y-auto px-2 pt-2 pb-4`,children:[(0,F.jsx)(Y,{href:`/`,active:e===`/`,leading:(0,F.jsx)(I,{name:`home`}),title:`Home`,innerProps:{title:`Today: what needs you, what happened`}}),(0,F.jsx)(Y,{href:`/agents/chats`,active:d,leading:(0,F.jsx)(`span`,{"aria-hidden":!0,children:`🎩`}),title:`Ralv`,titleExtra:(0,F.jsx)(Qe,{n:It.general(_).length,title:`waiting for you`}),innerProps:{title:`Chief of staff: knows the workspace, advises, launches things`}}),t.projects&&(0,F.jsxs)(Td,{label:`projects`,href:`/projects`,add:a?.enabled?{href:`/projects/new`,label:`new project`}:void 0,badge:f.all?(0,F.jsx)(Qe,{n:new Set(b.filter(e=>!S(e)).flatMap(e=>It.project(_,e.slug,e.agents).map(e=>e.id))).size,title:`waiting in the projects folded away`}):void 0,fold:b.length>0?(0,F.jsxs)(F.Fragment,{children:[!f.all&&a?.layout&&(0,F.jsx)(H,{size:`sm`,icon:`create_new_folder`,label:`new section`,title:`new section: drag projects into it`,onClick:()=>void O()}),(0,F.jsx)(H,{size:`sm`,icon:f.all?`chevron_right`:`expand_more`,label:f.all?`show all projects`:`collapse projects`,"aria-expanded":!f.all,onClick:()=>p(e=>({...e,all:!e.all}))})]}):void 0,children:[f.all||!a?.layout?w.filter(e=>!f.all||S(e)).map(e=>(0,F.jsx)(v.Fragment,{children:k(e)},e.slug)):(0,F.jsx)(bd,{layout:a.layout,visible:e=>!!C.get(e)&&S(C.get(e)),render:e=>C.get(e)?k(C.get(e)):null,onSave:T,collapsed:e=>!!f.sections[e],onCollapse:e=>p(t=>({...t,sections:{...t.sections,[e]:!t.sections[e]}})),editing:E,onEdited:()=>D(void 0)}),f.all&&b.length>0&&(0,F.jsxs)(V,{variant:`quiet`,size:`sm`,icon:`expand_more`,className:`justify-start`,onClick:()=>p(e=>({...e,all:!1})),children:[b.filter(e=>!S(e)).length,` more`]})]}),(0,F.jsx)(Td,{label:`agents`,href:`/agents`,add:n?{href:`/agents/new`,label:`new agent`}:void 0,children:(r?.agents??[]).filter(e=>!e.archived).map(e=>{let t=md(o?.[e.slug],e.description);return(0,F.jsx)(Y,{href:`/agents/${encodeURIComponent(e.slug)}`,active:u(`agents`,e.slug)||u(`team`,e.slug),innerProps:{title:e.description||void 0},leading:(0,F.jsx)(`span`,{"aria-hidden":!0,children:e.emoji||`🤖`}),title:e.name,titleExtra:(0,F.jsx)(Ed,{n:It.agent(_,e.slug).length,st:o?.[e.slug]}),sub:t?(0,F.jsx)(`span`,{className:`rail-status${t.tone===`plain`?``:` ${t.tone}`}`,children:t.text}):void 0,subTone:t?.tone===`waiting`?`bad`:t?.tone===`working`?`accent`:`plain`},e.slug)})}),(0,F.jsx)(Td,{label:`channels`,href:`/channels`,add:{href:`/channels/new`,label:`new channel`},children:(i?.channels??[]).map(e=>(0,F.jsx)(Y,{href:`/channels/${encodeURIComponent(e.slug)}`,active:u(`channels`,e.slug),leading:(0,F.jsx)(`span`,{"aria-hidden":!0,className:`font-semibold`,children:`#`}),title:e.name,titleExtra:(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(Qe,{n:It.channel(_,e.slug).length,title:`waiting for you`}),e.busy&&!e.awaitingApproval&&(0,F.jsx)(U,{tone:`working`,title:`an agent is working`})]}),sub:e.purpose||(e.members.length?`with ${e.members.map(e=>`@${e}`).join(` `)}`:`no agents yet`)},e.slug))})]})})}var wd=`ml-5 rounded-l-none border-l border-line`;function Td({label:e,href:t,add:n,badge:r,fold:i,children:a}){return(0,F.jsxs)(`div`,{className:`mt-3 flex flex-col gap-0.5`,role:`group`,"aria-label":e[0].toUpperCase()+e.slice(1),children:[(0,F.jsxs)(`div`,{className:`group/head flex items-center gap-1 pl-2.5 pr-1`,children:[(0,F.jsx)(he,{href:t,className:`flex-1 px-0 py-1 text-2xs font-semibold uppercase tracking-[0.08em] text-fg-2 no-underline hover:text-fg`,children:e}),r,(0,F.jsxs)(`span`,{className:`flex items-center gap-1 opacity-0 transition-opacity group-hover/head:opacity-100 group-focus-within/head:opacity-100 pointer-coarse:opacity-100`,children:[n&&(0,F.jsx)(H,{size:`sm`,icon:`add`,label:n.label,href:n.href}),i]})]}),a]})}function Ed({n:e,st:t}){return(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(Qe,{n:e,title:`waiting for you`}),!e&&t?.working.length&&!t.waiting.length?(0,F.jsx)(U,{tone:`working`,title:`working`}):null]})}var Dd=`kw-rail-fold`;function Od(){let[e,t]=(0,v.useState)(()=>{try{let e=JSON.parse(localStorage.getItem(Dd)??`null`),t=e=>e&&typeof e==`object`?e:{};return{all:!!e?.all,open:t(e?.open),sections:t(e?.sections)}}catch{return{all:!1,open:{},sections:{}}}});return[e,e=>t(t=>{let n=e(t);try{localStorage.setItem(Dd,JSON.stringify(n))}catch{}return n})]}function kd({path:e}){let t=be(),n=we(),r=e.split(`/`).filter(Boolean)[0]??``;if(!t)return null;let i=[{id:`workflows`,href:`/workflows`,label:`workflows`,icon:`account_tree`},{id:`knowledge`,href:`/knowledge`,label:`knowledge`,icon:`menu_book`},{id:`files`,href:`/files`,label:`files`,icon:`folder_open`},...n.vibeables?[{id:`vibeables`,href:`/vibeables`,label:`apps`,icon:`web`}]:[],{id:`skills`,href:`/skills`,label:`skills`,icon:`extension`},...n.repos?[{id:`repos`,href:`/repos`,label:`repositories`,icon:`source`}]:[],...n.git?[{id:`git`,href:`/git`,label:`git`,icon:`cloud_sync`,badge:(0,F.jsx)(Ad,{})}]:[],{id:`workspaces`,href:`/workspaces`,label:`workspaces`,icon:`grid_view`},{id:`trash`,href:`/trash`,label:`trash`,icon:`delete`}],a=e=>r===e||e===`workflows`&&r===`runs`;return(0,F.jsx)(`nav`,{className:`global-nav flex min-w-0 flex-[0_1_auto] justify-start gap-0.5 overflow-x-auto [scrollbar-width:none] max-[1199px]:[mask-image:linear-gradient(to_right,#000_calc(100%-24px),transparent)] max-[800px]:hidden`,"aria-label":`Workspace`,children:i.map(e=>{let t=a(e.id);return(0,F.jsxs)(`a`,{href:`#${e.href}`,className:P(`inline-flex flex-none items-center gap-1.5 rounded-full px-3 py-1.5 text-[13.5px] font-semibold no-underline transition-colors`,`[&_.ms]:text-[18px] max-[1520px]:gap-[5px] max-[1520px]:[&_.ms]:text-[17px]`,t?`bg-surface text-accent shadow-[inset_0_0_0_1px_var(--line)]`:`text-fg-2 hover:bg-surface-2 hover:text-fg`),"aria-current":t?`page`:void 0,children:[(0,F.jsx)(I,{name:e.icon,fill:t}),` `,e.label,e.badge]},e.id)})})}function Ad(){let e=N(`git.status`,{},{interval:15e3}),t=e?.files?.filter(e=>e.syncable).length??0,n=`ml-[5px] rounded-full bg-surface-2 px-1.5 py-px text-[10.5px] font-semibold tabular-nums`;return(0,F.jsxs)(F.Fragment,{children:[!!e?.behind&&(0,F.jsxs)(`span`,{className:P(n,`text-accent`),children:[e.behind,`↓`]}),!!e?.ahead&&(0,F.jsxs)(`span`,{className:P(n,`text-ok`),children:[e.ahead,`↑`]}),!e?.ahead&&!e?.behind&&!!t&&(0,F.jsx)(`span`,{className:n,children:t})]})}var jd=e=>e.replace(/^# .*\n+/,``).replace(/\(human:user\)/g,`(you)`),Md=`flex flex-col gap-1.5 px-1.5 pb-6 pt-3`,Nd=`m-0 px-2.5 pb-0.5 text-md leading-[1.45] text-fg`,Pd=`m-0 px-2.5 py-0.5 text-sm text-fg-2`,Fd=`md-body px-2.5 text-sm leading-normal`,Id=e=>da.sanitize(Fr.parse(jd(e),{async:!1}));function Ld(e,t){let n=[],r=``;for(let i of e.split(`
229
- `)){let e=/^## (.+)$/.exec(i.trim());if(e?r=e[1]:/^[-*] /.test(i)&&n.push({day:r,text:i.replace(/^[-*] /,``)}),n.length>=t)break}return n}function Rd({items:e}){return e.length===0?null:(0,F.jsx)(tt,{size:`lg`,title:`needs you`,count:e.length,children:e.map(e=>(0,F.jsx)(Y,{onClick:()=>Vt(e),leading:(0,F.jsx)(I,{name:e.kind===`approval`?`front_hand`:e.kind===`question`?`help`:`error`,className:`ms-sm text-bad`}),title:e.title,sub:`${e.owner.agent?`${e.owner.agent.emoji??``} ${e.owner.agent.name} · `:``}${e.kind===`approval`?`needs approval`:e.kind===`question`?`asks you`:`failed`} · ${Ge(e.since)}`},e.id))})}function zd({slugs:e,agents:t,status:n,title:r=`team`}){let i=e.map(e=>t.find(t=>t.slug===e)).filter(e=>!!e);return i.length===0?null:(0,F.jsx)(tt,{size:`lg`,title:r,children:i.map(e=>{let t=md(n?.[e.slug],e.description);return(0,F.jsx)(Y,{href:`/agents/${encodeURIComponent(e.slug)}`,leading:(0,F.jsx)(`span`,{"aria-hidden":!0,children:e.emoji||`🤖`}),title:e.name,sub:t?.text,subTone:t?.tone===`waiting`?`bad`:t?.tone===`working`?`accent`:`plain`},e.slug)})})}function Bd({scope:e}){let t=N(`files.recent`,{query:{scope:e}},{interval:2e4});return!t||t.count===0?null:(0,F.jsx)(tt,{size:`lg`,title:`files`,count:t.count,action:(0,F.jsxs)(V,{variant:`quiet`,size:`sm`,href:lu(e),children:[`all `,(0,F.jsx)(I,{name:`arrow_forward`,className:`ms-sm`})]}),children:t.recent.map(t=>{let n=t.path.includes(`/`)?t.path.slice(0,t.path.lastIndexOf(`/`)):``;return(0,F.jsx)(Y,{href:lu(e,n,t.path),leading:(0,F.jsx)(I,{name:`draft`,className:`ms-sm`}),title:t.path.split(`/`).pop(),sub:`${n?`${n}/ · `:``}${Ge(t.at)}`},t.path)})})}function Vd({of:e}){let t=Ft()??[],n=N(`agents.list`,{},{interval:15e3})?.agents??[],r=N(`agents.status`,{},{interval:5e3})??void 0;if(e.kind===`project`){let i=e.project,a=i.links.agents.map(e=>e.slug),o=Ld(i.log,5);return(0,F.jsxs)(`div`,{className:Md,children:[(0,F.jsx)(tt,{size:`lg`,title:`goal`,children:(0,F.jsxs)(`p`,{className:Nd,children:[i.goal||(0,F.jsx)(`span`,{className:`text-fg-2`,children:`No goal written yet.`}),i.status!==`active`&&(0,F.jsxs)(`span`,{className:`text-fg-2`,children:[` · `,i.status]})]})}),o.length>0&&(0,F.jsx)(tt,{size:`lg`,title:`lately`,children:o.map((e,t)=>(0,F.jsxs)(`div`,{className:`grid grid-cols-[74px_minmax(0,1fr)] gap-2 px-2.5 py-1 text-sm`,children:[(0,F.jsx)(`span`,{className:`pt-px text-xs tabular-nums text-fg-2`,children:e.day}),(0,F.jsx)(`span`,{dangerouslySetInnerHTML:{__html:da.sanitize(Fr.parseInline(jd(e.text),{async:!1}))}})]},t))}),(0,F.jsx)(Rd,{items:It.project(t,i.slug,a)}),(0,F.jsx)(zd,{slugs:a,agents:n,status:r}),(0,F.jsx)(tt,{size:`lg`,title:`where it stands`,children:i.state.trim()?(0,F.jsx)(`div`,{className:Fd,dangerouslySetInnerHTML:{__html:Id(i.state)}}):(0,F.jsx)(`p`,{className:Pd,children:`Nothing recorded yet: the project's chat writes this down at the end of a session that changed something.`})}),(0,F.jsx)(Bd,{scope:`project:${i.slug}`}),i.records.length>0&&(0,F.jsx)(tt,{size:`lg`,title:`systems of record`,children:i.records.map((e,t)=>(0,F.jsx)(Y,{onClick:()=>e.url&&window.open(e.url,`_blank`,`noopener`),leading:(0,F.jsx)(I,{name:`open_in_new`,className:`ms-sm`}),title:e.title||e.kind,sub:e.note},t))})]})}if(e.kind===`agent`)return(0,F.jsx)(Hd,{agent:e.agent,journal:e.journal,waiting:t,status:r});if(e.kind===`channel`){let i=e.channel;return(0,F.jsxs)(`div`,{className:Md,children:[(0,F.jsx)(`p`,{className:Nd,children:i.purpose||(0,F.jsxs)(`span`,{className:`text-fg-2`,children:[`A group chat with `,i.members.length,` agent`,i.members.length===1?``:`s`,`.`]})}),(0,F.jsx)(Rd,{items:It.channel(t,i.slug)}),(0,F.jsx)(zd,{slugs:i.members,agents:n,status:r,title:`in this channel`})]})}return(0,F.jsx)(Ud,{waiting:t,agents:n,status:r})}function Hd({agent:e,journal:t,waiting:n,status:r}){let i=N(`projects.list`,{},{interval:3e4})?.projects??[],a=N(`agents.routines`,{slug:e.slug},{interval:3e4})?.routines??[],[o,s]=(0,v.useState)(t);(0,v.useEffect)(()=>s(t),[t]);let c=md(r?.[e.slug],e.description),l=i.filter(t=>t.agents.includes(e.slug));return(0,F.jsxs)(`div`,{className:Md,children:[(0,F.jsx)(`p`,{className:Nd,children:e.description||(0,F.jsx)(`span`,{className:`text-fg-2`,children:`No description yet.`})}),c&&c.text!==e.description&&(0,F.jsx)(`p`,{className:`m-0 px-2.5 text-sm ${c.tone===`waiting`?`text-bad`:c.tone===`working`?`text-accent`:`text-fg-2`}`,children:c.text}),(0,F.jsx)(Rd,{items:It.agent(n,e.slug)}),l.length>0&&(0,F.jsx)(tt,{size:`lg`,title:`works on`,children:l.map(e=>(0,F.jsx)(Y,{href:`/projects/${encodeURIComponent(e.slug)}`,leading:(0,F.jsx)(`span`,{"aria-hidden":!0,children:`📁`}),title:e.title,sub:e.goal||void 0},e.slug))}),a.length>0&&(0,F.jsx)(tt,{size:`lg`,title:`schedule`,children:a.map(e=>(0,F.jsx)(Y,{leading:(0,F.jsx)(I,{name:`schedule`,className:`ms-sm`}),title:e.name,sub:`${e.enabled?e.nextRunAt?`next ${new Date(e.nextRunAt).toLocaleString([],{weekday:`short`,hour:`2-digit`,minute:`2-digit`})}`:e.schedule:`paused`}${e.lastRunAt?` · last ${Ge(e.lastRunAt)}`:``}`},e.id))}),(0,F.jsxs)(tt,{size:`lg`,title:`journal`,children:[(0,F.jsx)(Wd,{slug:e.slug,onAdded:s}),(0,F.jsx)(`div`,{className:Fd,dangerouslySetInnerHTML:{__html:Id(jd(o)||`_Nothing yet: the agent notes what it learns, decides and promises here, and reads it back at the start of every session._`)}})]})]})}function Ud({waiting:e,agents:t,status:n}){let r=N(`projects.list`,{},{interval:3e4}),i=(r?.projects??[]).filter(e=>e.status===`active`);return(0,F.jsxs)(`div`,{className:Md,children:[(0,F.jsx)(Rd,{items:e}),r?.enabled&&(0,F.jsxs)(tt,{size:`lg`,title:`projects`,count:i.length,children:[i.length===0&&(0,F.jsx)(`p`,{className:Pd,children:`No active projects.`}),i.map(t=>{let n=It.project(e,t.slug,t.agents).length;return(0,F.jsx)(Y,{href:`/projects/${encodeURIComponent(t.slug)}`,leading:(0,F.jsx)(`span`,{"aria-hidden":!0,children:`📁`}),title:t.title,sub:n?`${n} waiting for you`:t.goal||`no goal yet`,subTone:n?`bad`:`plain`},t.slug)})]}),(0,F.jsx)(zd,{slugs:t.filter(e=>!e.archived).map(e=>e.slug),agents:t,status:n,title:`agents`}),(0,F.jsx)(Bd,{scope:`workspace`})]})}function Wd({slug:e,onAdded:t}){let[n,r]=(0,v.useState)(``),[i,a]=(0,v.useState)(!1),[o,s]=(0,v.useState)(``),c=async()=>{if(!n.trim())return;a(!0),s(``);let i=await A.request(`agents.addJournal`,{slug:e,body:{entry:n,kind:`note`}}).then(e=>e.ok?{error:void 0,journal:e.data?.journal}:{error:M(e),journal:void 0}).catch(e=>({error:e.message,journal:void 0}));if(a(!1),i.error||i.journal===void 0)return s(i.error??`could not save`);r(``),t(i.journal)};return(0,F.jsxs)(`div`,{className:`px-2.5 pb-1.5 pt-0.5`,children:[(0,F.jsx)(X,{className:`h-8 text-sm`,value:n,placeholder:`add a note for the agent to remember`,onChange:e=>r(e.target.value),onKeyDown:e=>e.key===`Enter`&&void c(),disabled:i}),o&&(0,F.jsx)(q,{tone:`bad`,children:o})]})}function Gd(e){let t=e.split(`/`).filter(Boolean),n=t[1]?decodeURIComponent(t[1]):``;return t[0]===`projects`&&n&&n!==`new`?{kind:`project`,slug:n}:t[0]===`channels`&&n&&n!==`new`?{kind:`channel`,slug:n}:(t[0]===`agents`||t[0]===`team`)&&n&&n!==`new`&&n!==`chats`?{kind:`agent`,slug:n}:{kind:`general`}}function Kd(e){let t=new Date(e),n=t.toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`}),r=e=>new Date(e.getFullYear(),e.getMonth(),e.getDate()).getTime(),i=Math.round((r(t)-r(new Date))/864e5);return i===0?`today ${n}`:i===1?`tomorrow ${n}`:i>1&&i<7?`${t.toLocaleDateString([],{weekday:`short`})} ${n}`:`${t.toLocaleDateString([],{day:`numeric`,month:`short`})} ${n}`}var qd=(e,t)=>e.map(e=>({slug:e,found:t.has(e)}));function Jd({chatPath:e,workspace:t}){let n=Gd(e),r=`${n.kind}:${`slug`in n?n.slug:``}`,i=we(),a=be(),[o,s]=n.kind===`project`?[`/projects/${encodeURIComponent(n.slug)}/info`,`edit the project: brief, state, records, links`]:n.kind===`agent`?[`/agents/${encodeURIComponent(n.slug)}/info`,`edit the agent: profile and settings`]:n.kind===`channel`?[`/channels/${encodeURIComponent(n.slug)}/edit`,`edit the channel`]:a?[`/settings`,`workspace settings`]:[void 0,``],c=N(`workflows.list`,{},{interval:15e3}),l=N(`runs.list`,{},{interval:6e3}),u=N(`routines.list`,{},{interval:3e4}),[d,f]=(0,v.useState)(null),p=N(`knowledge.list`,{},{interval:15e3}),m=N(`vibeables.list`,i.vibeables?{}:null,{interval:15e3}),[h,g]=(0,v.useState)(null),[_,y]=(0,v.useState)(0),[b,x]=(0,v.useState)(()=>{try{return localStorage.getItem(`kw-ctx-tab`)||`overview`}catch{return`overview`}}),[S,C]=(0,v.useState)(0);(0,v.useEffect)(()=>{let e=()=>w(`browser`);return window.addEventListener(ro,e),()=>window.removeEventListener(ro,e)},[]);let w=e=>{x(e);try{localStorage.setItem(`kw-ctx-tab`,e)}catch{}},[T,E]=(0,v.useState)({});(0,v.useEffect)(()=>E(oe.current?{vibeables:`/vibeables/${encodeURIComponent(oe.current.slug)}`}:{}),[r]);let[D,O]=(0,v.useState)(!1);(0,v.useEffect)(()=>O(!1),[r]);let k=L(),j=n.kind===`project`?new URLSearchParams(k.split(`?`)[1]??``).get(`app`):null;(0,v.useEffect)(()=>{j&&(w(`vibeables`),E(e=>({...e,vibeables:`/vibeables/${encodeURIComponent(j)}`})),O(!0))},[j,r]);let ee=e=>E(t=>({...t,[ue]:e})),[M,P]=(0,v.useState)({dir:``});(0,v.useEffect)(()=>P({dir:``}),[r]);let te=async(e,t,n)=>{(await A.request(`projects.link`,{slug:e,body:{kind:`vibeables`,target:t,remove:n}}).catch(()=>null))?.ok&&y(e=>e+1)},ne=()=>{O(!1),E(e=>({...e,[ue]:null}))},re=e=>t=>t.startsWith(e)?(E(e=>({...e,[ue]:t})),!0):!1,[ie,ae]=(0,v.useState)(null),oe=(0,v.useRef)(null);(0,v.useEffect)(()=>{let e=e=>{let t=e.detail;oe.current=t,ae(t),t?(w(`vibeables`),E(e=>({...e,vibeables:`/vibeables/${encodeURIComponent(t.slug)}`}))):E(e=>e.vibeables?.startsWith(`/vibeables/`)?{...e,vibeables:null}:e)};return window.addEventListener(pa,e),()=>window.removeEventListener(pa,e)},[]);let se=i.repos&&!!h?.repos,ce=n.kind===`project`?`project:${n.slug}`:h?.channel?.project?`project:${h.channel.project}`:`workspace`,le=[{id:`overview`,label:`overview`},{id:`files`,label:`files`,allHref:`/files/${encodeURIComponent(ce)}`},{id:`knowledge`,label:`knowledge`,count:h?.knowledge.length,allHref:`/knowledge`},...i.vibeables?[{id:`vibeables`,label:`apps`,count:h?.all?m?.vibeables.length:h?.vibeables?.length??0,allHref:`/vibeables`}]:[],{id:`workflows`,label:`workflows`,count:h?.workflows.length,allHref:`/workflows`},...a&&se?[{id:`repos`,label:`repositories`,count:h?.repos?.length,allHref:`/repos`}]:[],...S>0||b===`browser`?[{id:`browser`,label:`browser`,count:S}]:[]],ue=le.some(e=>e.id===b)?b:`overview`,de=le.find(e=>e.id===ue),R=T[ue]??null,B=!!ie&&ue===`vibeables`&&R===`/vibeables/${encodeURIComponent(ie.slug)}`,fe=ue===`vibeables`&&!!R,pe=D&&fe,ge=e=>t=>{t.metaKey||t.ctrlKey||t.shiftKey||t.button!==0||(t.preventDefault(),ee(e))};(0,v.useEffect)(()=>{let e=setInterval(()=>y(e=>e+1),15e3);return()=>clearInterval(e)},[]);let _e=z(k),ve=(0,v.useRef)(_e);(0,v.useEffect)(()=>{ve.current&&!_e&&y(e=>e+1),ve.current=_e},[_e]),(0,v.useEffect)(()=>{let e=!0,r=new Set((c?.workflows??[]).map(e=>e.slug)),i=new Set((p?.bundles??[]).map(e=>e.name)),a=new Set((m?.vibeables??[]).map(e=>e.slug));return(async()=>{let o=null;if(n.kind===`agent`){let e=await A.call(`agents.get`,{slug:n.slug}).catch(()=>null);e&&(o={title:`${e.emoji?`${e.emoji} `:``}${e.name}`,agent:e,workflows:qd(e.workflows,r),knowledge:qd(e.knowledge,i),editHref:`/agents/${encodeURIComponent(n.slug)}/edit`},(e.vibeables??[]).length>0&&(o.vibeables=qd(e.vibeables,a)),o.journal=(await A.call(`agents.journal`,{slug:n.slug}).catch(()=>null))?.journal??``)}else if(n.kind===`project`){let e=await A.call(`projects.get`,{slug:n.slug}).catch(()=>null);e&&(o={title:`📁 ${e.title}`,project:e,workflows:e.links.workflows,knowledge:e.links.knowledge,vibeables:e.links.vibeables,repos:e.links.repos,agents:e.links.agents,records:e.records,state:e.state,log:e.log,editHref:`/projects/${encodeURIComponent(n.slug)}/info`})}else if(n.kind===`channel`){let e=(await A.call(`channels.list`).catch(()=>null))?.channels.find(e=>e.slug===n.slug);if(e){let t=(await Promise.all(e.members.map(e=>A.call(`agents.get`,{slug:e}).catch(()=>null)))).filter(e=>!!e),s=e=>[...new Set(t.flatMap(e))],c=s(e=>e.vibeables??[]);o={title:`#${e.slug}`,channel:e,workflows:qd(s(e=>e.workflows),r),knowledge:qd(s(e=>e.knowledge),i),...c.length>0?{vibeables:qd(c,a)}:{},agents:e.members.map(e=>({slug:e,found:t.some(t=>t.slug===e),label:t.find(t=>t.slug===e)?.name})),editHref:`/channels/${encodeURIComponent(n.slug)}/edit`}}}else o={title:`${t.icon?`${t.icon} `:``}${t.name||`workspace`}`,workflows:qd([...r],r),knowledge:qd([...i],i),all:!0};e&&g(o)})(),()=>{e=!1}},[r,_,c,p,m,t.name,t.icon]);let ye=e=>c?.workflows.find(t=>t.slug===e),xe=e=>e?l?.runs.find(t=>t.workflow===(e.name??e.slug)||t.workflow===e.slug):void 0,Se=e=>p?.bundles.find(t=>t.name===e),Ce=e=>m?.vibeables.find(t=>t.slug===e),Te=e=>(0,F.jsxs)(`p`,{className:`m-0 px-2.5 py-3 text-sm text-fg-2`,children:[h?.all?`No ${e} in this workspace yet.`:`No ${e} linked.`,h?.editHref&&a&&!h.all&&(0,F.jsxs)(F.Fragment,{children:[` `,(0,F.jsx)(he,{href:h.editHref,className:`text-accent`,children:`Edit the links`}),`.`]})]});return(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(`div`,{className:`space-title flex min-w-0 items-center gap-2 px-1`,children:[(0,F.jsx)(`span`,{className:`min-w-0 truncate text-[22px] leading-[1.15] font-[750] tracking-[-0.015em] text-fg animate-fade max-[800px]:text-lg`,title:h?.title,children:h?h.title:`…`},h?.title??``),o&&(0,F.jsx)(he,{href:o,className:`ctx-edit inline-grid size-7 flex-none place-items-center rounded-full text-fg-2 no-underline transition-colors hover:bg-surface-2 hover:text-accent active:scale-96 [&_.ms]:text-[18px]`,title:s,"aria-label":s,children:(0,F.jsx)(I,{name:`edit`,className:`ms-sm`})})]}),(0,F.jsxs)(`aside`,{className:`ctx`,"aria-label":`Context`,"data-full":pe||void 0,children:[(0,F.jsx)(ft,{className:`flex-none gap-y-0.5 pt-2`,label:`Categories`,items:le,value:ue,onChange:w}),R&&(0,F.jsxs)(`div`,{className:`flex items-center gap-2 px-3 pb-1 pt-2`,children:[(0,F.jsx)(V,{variant:`quiet`,size:`sm`,icon:`arrow_back`,onClick:ne,"aria-label":`Back to the list`,children:de?.label}),(0,F.jsx)(`span`,{className:`flex-1`}),fe&&(0,F.jsx)(V,{variant:`quiet`,size:`sm`,icon:pe?`close_fullscreen`:`open_in_full`,onClick:()=>O(!pe),title:pe?`back beside the chat`:`full size, in place of the chat`,children:pe?`beside the chat`:`full size`}),(0,F.jsx)(V,{variant:`quiet`,size:`sm`,icon:`open_in_new`,href:R,title:`Open as a page`,children:`page`})]}),R&&ue===`knowledge`&&(0,F.jsx)(`div`,{className:`ctx-body ctx-embed`,children:(0,F.jsx)(me.Provider,{value:re(`/knowledge/`),children:(()=>{let e=R.split(`/`).filter(Boolean),t=decodeURIComponent(e[1]??``),n=e.length>2?e.slice(2).map(decodeURIComponent).join(`/`):void 0;return(0,F.jsx)(hl,{name:t,conceptId:n},t)})()})}),R&&ue===`workflows`&&(0,F.jsx)(`div`,{className:`ctx-body ctx-embed`,children:(0,F.jsx)(me.Provider,{value:re(`/workflows/`),children:(()=>{let e=R.split(`/`).filter(Boolean),t=e[2]===`details`||e[2]===`runs`?e[2]:`overview`;return(0,F.jsx)(Ac,{slug:decodeURIComponent(e[1]??``),tab:t},e[1])})()})}),R&&ue===`vibeables`&&!B&&(0,F.jsx)(`div`,{className:`ctx-body ctx-embed ctx-embed-vibe`,children:(0,F.jsx)(_a,{slug:decodeURIComponent(R.split(`/`).filter(Boolean)[1]??``)},R)}),(0,F.jsx)(`div`,{id:ma,className:`ctx-body ctx-embed ctx-embed-vibe`,hidden:!B}),(0,F.jsx)(`div`,{className:`ctx-body ctx-embed ctx-browser`,hidden:ue!==`browser`,children:(0,F.jsx)(uo,{storeKey:r,onTabs:C},r)}),(0,F.jsxs)(`div`,{className:`ctx-body`,role:`tabpanel`,hidden:ue===`browser`||!!R&&[`knowledge`,`workflows`,`vibeables`].includes(ue),children:[de?.allHref&&(0,F.jsx)(`div`,{className:`flex justify-end px-1 pb-1`,children:(0,F.jsxs)(V,{variant:`quiet`,size:`sm`,href:de.allHref,children:[`all `,de.label,` `,(0,F.jsx)(I,{name:`arrow_forward`,className:`ms-sm`})]})}),ue===`workflows`&&(0,F.jsxs)(F.Fragment,{children:[h&&h.workflows.length===0&&Te(`workflows`),h?.workflows.map(({slug:e,found:t})=>{let n=ye(e),r=xe(n),i=t&&!!n&&!n.error,a=(u?.routines??[]).filter(t=>t.workflows.includes(e));return(0,F.jsxs)(`div`,{className:`flex flex-col`,children:[(0,F.jsx)(Y,{href:`/workflows/${encodeURIComponent(e)}`,onClick:t?ge(`/workflows/${encodeURIComponent(e)}`):void 0,dim:!t,leading:(0,F.jsx)(U,{tone:!t||n?.error?`bad`:Xd(r?.status)}),title:n?.name??e,sub:t?n?.error?`broken`:r?`${r.status} · ${Ge(r.updatedAt)}`:n?.description??`no runs yet`:`not in this workspace`,actionsAlways:!0,actions:i?(0,F.jsx)(H,{size:`sm`,icon:d===e?`close`:`play_arrow`,label:d===e?`close the launcher of ${n.name??e}`:`run ${n.name??e}`,"aria-expanded":d===e,onClick:()=>f(d===e?null:e)}):void 0}),a.map(e=>(0,F.jsxs)(he,{href:`/agents/${encodeURIComponent(e.agent.slug)}/info`,className:`routine-line flex min-w-0 items-center gap-1.5 pt-0.5 pb-2 pl-[46px] pr-3 text-xs text-fg-2 no-underline hover:text-fg`,title:`${e.agent.name}'s routine "${e.name}" (${e.schedule}) runs this workflow: ${e.prompt}`,children:[(0,F.jsx)(I,{name:`schedule`,className:`ms-sm flex-none text-[14px]`}),(0,F.jsxs)(`span`,{className:`min-w-0 truncate`,children:[e.agent.emoji,` `,e.agent.name,` · `,e.name,` · `,e.enabled?e.nextRunAt?`next ${Kd(e.nextRunAt)}`:e.schedule:`paused`]})]},`${e.agent.slug}/${e.id}`)),d===e&&n&&(0,F.jsx)(`div`,{className:`mx-1 mb-2 rounded-card border border-line bg-surface [&>div]:px-3 [&>div]:pt-3`,children:(0,F.jsx)(yc,{slug:e,usesRequest:n.usesRequest,onLaunched:()=>{f(null),ee(`/workflows/${encodeURIComponent(e)}`)}})})]},e)})]}),ue===`knowledge`&&(0,F.jsxs)(F.Fragment,{children:[h&&h.knowledge.length===0&&Te(`knowledge`),h?.knowledge.map(({slug:e,found:t})=>{let n=Se(e);return(0,F.jsx)(Y,{href:`/knowledge/${encodeURIComponent(e)}`,onClick:t?ge(`/knowledge/${encodeURIComponent(e)}`):void 0,dim:!t,leading:(0,F.jsx)(I,{name:`menu_book`,className:`ms-sm`}),title:e,sub:t?n?`${n.concepts} ${n.concepts===1?`page`:`pages`}${n.updatedAt?` · ${Ge(n.updatedAt)}`:``}`:void 0:`not in this workspace`},e)})]}),ue===`vibeables`&&h&&(0,F.jsxs)(F.Fragment,{children:[(h.all?(m?.vibeables??[]).map(e=>({slug:e.slug,found:!0})):h.vibeables??[]).map(({slug:e,found:t})=>{let r=Ce(e);return(0,F.jsx)(Y,{href:`/vibeables/${encodeURIComponent(e)}`,onClick:t?ge(`/vibeables/${encodeURIComponent(e)}`):void 0,dim:!t,leading:(0,F.jsx)(I,{name:`web`,className:`ms-sm`}),title:e,sub:t?r?.updatedAt?`changed ${Ge(r.updatedAt)}`:void 0:`not in this workspace`,actions:n.kind===`project`?(0,F.jsx)(H,{icon:`keep_off`,size:`sm`,label:`unpin ${e}`,onClick:()=>void te(n.slug,e,!0)}):void 0},e)}),n.kind===`project`&&m&&(0,F.jsx)(Yd,{options:m.vibeables.map(e=>e.slug).filter(e=>!h.vibeables?.some(t=>t.slug===e)),onPin:e=>void te(n.slug,e,!1)}),h.all&&m&&m.vibeables.length===0&&Te(`vibeables`),!h.all&&h.vibeables?.length===0&&Te(`vibeables`)]}),ue===`repos`&&h?.repos&&(0,F.jsxs)(F.Fragment,{children:[h.repos.length===0&&Te(`repositories`),h.repos.map(({slug:e,found:t})=>(0,F.jsx)(Y,{href:`/repos/${encodeURIComponent(e)}`,dim:!t,leading:(0,F.jsx)(I,{name:`source`,className:`ms-sm`}),title:e,sub:t?void 0:`not in this workspace`},e))]}),ue===`overview`&&h&&(0,F.jsx)(Vd,{of:h.project?{kind:`project`,project:h.project}:h.agent?{kind:`agent`,agent:h.agent,journal:h.journal??``}:h.channel?{kind:`channel`,channel:h.channel}:{kind:`workspace`}},r),ue===`files`&&(0,F.jsx)(gu,{compact:!0,scope:ce,dir:M.dir,file:M.file,onOpen:(e,t)=>P({dir:e,file:t})},ce)]},ue)]})]})}function Yd({options:e,onPin:t}){return e.length===0?null:(0,F.jsxs)(`div`,{className:`flex items-center gap-2 px-2.5 py-2 text-fg-2`,children:[(0,F.jsx)(I,{name:`keep`,className:`ms-sm`}),(0,F.jsxs)(_t,{className:`h-8 text-sm`,value:``,onChange:e=>e.target.value&&t(e.target.value),"aria-label":`pin an app to this project`,children:[(0,F.jsx)(`option`,{value:``,children:`pin an app to this project…`}),e.map(e=>(0,F.jsx)(`option`,{value:e,children:e},e))]})]})}function Xd(e){return e===`ok`?`ok`:e===`failed`?`bad`:e===`running`?`working`:`idle`}var Zd=`kw-chat-path`,Qd=`kw-ctx-w`,$d=()=>{try{let e=Number(localStorage.getItem(Qd));return e>0?e:null}catch{return null}};function ef({onResize:e}){let[t,n]=(0,v.useState)(!1);return(0,F.jsx)(`div`,{className:`split-handle${t?` dragging`:``}`,role:`separator`,"aria-orientation":`vertical`,"aria-label":`resize chat and context`,title:`drag to resize · double-click for half and half`,onPointerDown:t=>{if(t.button!==0)return;let r=t.currentTarget.closest(`.shell`);if(!r)return;t.preventDefault();let i=r.getBoundingClientRect().right-parseFloat(getComputedStyle(r).paddingRight),a=t=>e(Math.round(i-t.clientX)),o=()=>{window.removeEventListener(`pointermove`,a),window.removeEventListener(`pointerup`,o),window.removeEventListener(`pointercancel`,o),document.body.classList.remove(`kw-resizing`),n(!1)};window.addEventListener(`pointermove`,a),window.addEventListener(`pointerup`,o),window.addEventListener(`pointercancel`,o),document.body.classList.add(`kw-resizing`),n(!0)},onDoubleClick:()=>e(null)})}var tf=(e,t)=>{try{return sessionStorage.getItem(e)||t}catch{return t}},nf=(e,t)=>{try{sessionStorage.setItem(e,t)}catch{}};function rf(){let e=L();Wt();let[t]=e.split(`?`),n=t.split(`/`).filter(Boolean),[r,i]=(0,v.useState)(``),[a,o]=(0,v.useState)(``),[s,c]=(0,v.useState)(``),[l,u]=(0,v.useState)(!0),[d,f]=(0,v.useState)(``),[p,m]=(0,v.useState)(``),[h,g]=(0,v.useState)([]),_=ue.has(n[0]??``),y=n.length===0,[b,x]=(0,v.useState)(()=>tf(Zd,`/agents/chats`)),S=_?Ls(t):null,C=_&&!S?t:b,[w,T]=(0,v.useState)(`chat`),[E,D]=(0,v.useState)($d),O=e=>{D(e);try{e===null?localStorage.removeItem(Qd):localStorage.setItem(Qd,String(e))}catch{}};(0,v.useEffect)(()=>{T(e=>e===`side`?`chat`:e)},[e]),(0,v.useEffect)(()=>{_&&!Ls(t)&&(x(t),nf(Zd,t))},[e]),(0,v.useEffect)(()=>{let e=e=>{let t=e.detail;de(t)===`chat`?(x(t),nf(Zd,t)):window.location.replace(`#${t}`)};return window.addEventListener(R,e),()=>window.removeEventListener(R,e)},[]);let k=N(`meta.get`,{},{interval:3e4});(0,v.useEffect)(()=>{let e=k;e&&(i(e.workspaceName??``),o(e.workspaceIcon??``),c(e.workspaceColor??``),u(e.workspaceNamed!==!1),f(e.workspaceRootLabel??``),m(e.workspaceRoot??``),Ce({git:!!e.git,repos:!!e.repos,vibeables:!!e.vibeables,projects:!!e.projects}),g(Array.isArray(e.switcher)?e.switcher:[]))},[k]),(0,v.useEffect)(()=>{if(ce(r?`${r} — kraftwerk`:`kraftwerk inspector`),!a)return;let e=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><text y="0.9em" font-size="85">${a}</text></svg>`,t=document.querySelector(`link[rel="icon"]`);t||(t=document.createElement(`link`),t.rel=`icon`,document.head.appendChild(t)),t.href=`data:image/svg+xml,${encodeURIComponent(e)}`},[r,a]);let A=C.split(`/`).filter(Boolean),j=new URLSearchParams(e.split(`?`)[1]??``).get(`workflow`)??void 0,ee;ee=A[0]===`chats`?(0,F.jsx)(Is,{seg:A}):A[0]===`projects`?(0,F.jsx)(Ko,{seg:A.slice(1)}):A[0]===`channels`?(0,F.jsx)(Oa,{seg:A.slice(1)}):(0,F.jsx)(Is,{seg:A.slice(1)});let M=null;return n[0]===`runs`&&n[1]?M=(0,F.jsx)(qs,{id:n[1],workflow:j}):n[0]===`runs`?M=(0,F.jsx)(mf,{}):n[0]===`workflows`?M=(0,F.jsx)(zc,{slug:n[1]?decodeURIComponent(n[1]):void 0,tab:n[2]===`details`||n[2]===`runs`?n[2]:`overview`}):n[0]===`vibeables`?M=(0,F.jsx)(Ea,{slug:n[1]?decodeURIComponent(n[1]):void 0}):n[0]===`knowledge`?M=(0,F.jsx)(cl,{bundle:n[1]?decodeURIComponent(n[1]):void 0,conceptId:n.length>2?n.slice(2).map(decodeURIComponent).join(`/`):void 0}):n[0]===`skills`?M=(0,F.jsx)(Tl,{name:n[1]?decodeURIComponent(n[1]):void 0}):n[0]===`settings`?M=(0,F.jsx)(au,{}):n[0]===`trash`?M=(0,F.jsx)(su,{}):n[0]===`ui`?M=(0,F.jsx)(yu,{}):n[0]===`files`?M=(0,F.jsx)(mu,{scope:n[1]?decodeURIComponent(n[1]):`workspace`,dir:n.slice(2).map(decodeURIComponent).join(`/`),file:new URLSearchParams(e.split(`?`)[1]??``).get(`file`)??void 0}):n[0]===`workspaces`?M=(0,F.jsx)(Cu,{}):n[0]===`git`?M=(0,F.jsx)(Fu,{}):n[0]===`repos`&&(M=(0,F.jsx)(qu,{slug:n[1]?decodeURIComponent(n[1]):void 0})),(0,v.useEffect)(()=>{let e=document.documentElement,t=p||r,n=t?Ie(Ee(s,t)):null;if(!n){delete e.dataset.wsAccent;return}for(let[t,r]of Object.entries(n))e.style.setProperty(t,r);e.dataset.wsAccent=``},[s,p,r]),(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(`header`,{className:`topbar sticky top-0 z-10 flex h-[var(--topbar-h)] items-center gap-3.5 bg-bg px-5 shadow-[inset_0_-1px_0_var(--line)] max-[1520px]:gap-2.5 max-[800px]:gap-1.5 max-[800px]:px-3`,style:{"--ws-c":Ee(s,p||r)},children:[(0,F.jsxs)(`span`,{className:`flex min-w-0 flex-none items-center gap-2.5 max-[800px]:flex-[0_1_auto] max-[800px]:gap-1`,children:[(0,F.jsx)(`a`,{href:`#/`,className:`grid size-8 place-items-center rounded-full text-[15px] leading-none transition-shadow hover:shadow-[0_0_0_4px_color-mix(in_srgb,var(--ws-c,var(--text))_16%,transparent)]`,title:`Dashboard`,children:r?(0,F.jsx)(Re,{size:`sm`,icon:a,name:r,color:s,seed:p||r}):(0,F.jsx)(I,{name:`home`})}),r&&(0,F.jsx)(pf,{name:r,icon:a,color:s,named:l,root:d,seed:p||r,entries:h})]}),(0,F.jsx)(kd,{path:t}),(0,F.jsx)(`span`,{className:`flex-[1_1_8px]`}),(0,F.jsx)(ld,{}),(0,F.jsx)(H,{icon:`settings`,label:`settings`,href:`/settings`,"aria-current":n[0]===`settings`?`page`:void 0}),(0,F.jsx)(_f,{}),(0,F.jsx)(Ut,{}),(0,F.jsx)(bf,{}),(0,F.jsx)(gf,{})]}),M&&(0,F.jsx)(`main`,{className:`shell shell-global`,children:M}),(0,F.jsxs)(`main`,{className:`shell three${y?` home`:``}`,"data-focus":w,hidden:!!M,style:E?{"--ctx-w":`${E}px`}:void 0,children:[(0,F.jsx)(Cd,{chatPath:y?`/`:C}),(0,F.jsxs)(`section`,{className:`col-chat`,"aria-label":y?`Dashboard`:`Conversation`,children:[y?(0,F.jsx)(Gc,{}):ee,(0,F.jsx)(ef,{onResize:O})]}),(0,F.jsx)(Jd,{chatPath:y?`/`:C,workspace:{name:r,icon:a}}),S&&(0,F.jsx)(Rs,{back:C,children:S})]}),!M&&(0,F.jsxs)(`nav`,{className:`places`,"aria-label":`Sections`,children:[(0,F.jsxs)(`button`,{className:w===`side`?`active`:``,onClick:()=>T(`side`),children:[(0,F.jsx)(I,{name:`menu`}),` list`]}),(0,F.jsxs)(`button`,{className:w===`chat`?`active`:``,onClick:()=>T(`chat`),children:[(0,F.jsx)(I,{name:`forum`}),` chat`]}),(0,F.jsxs)(`button`,{className:w===`context`?`active`:``,onClick:()=>T(`context`),children:[(0,F.jsx)(I,{name:`account_tree`}),` context`]})]})]})}function af(e){try{let t=new URL(e);return t.hostname===`localhost`||t.hostname===`127.0.0.1`?`:${t.port||(t.protocol===`https:`?443:80)}`:t.host}catch{return e.replace(/^https?:\/\//,``)}}var of=`truncate text-sm text-fg-2 group-aria-[current=true]/ws:text-on-accent-soft group-aria-[current=true]/ws:opacity-80`,sf=`group/ws relative flex min-h-[60px] items-center gap-3.5 px-4 py-2.5 text-fg no-underline transition-colors`;function cf({label:e}){return e?(0,F.jsx)(`span`,{className:P(of,`[direction:rtl] text-left`),title:e,children:(0,F.jsx)(`span`,{dir:`ltr`,className:`[unicode-bidi:isolate]`,children:e})}):null}function lf({name:e,named:t}){let n=t===!1;return(0,F.jsx)(`span`,{className:P(`truncate text-md tracking-[0.2px]`,n&&`italic text-fg-2`,`group-data-[missing]/ws:line-through group-data-[stopped]/ws:text-fg-2`),title:n?`${e} — folder name; set name: in kraftwerk.yml`:e,children:e})}function uf({entry:e,ambiguous:t}){let[n,r]=(0,v.useState)(`idle`),[i,a]=(0,v.useState)(``),o=e.exists===!1,s=async()=>{r(`starting`),a(``);try{window.location.assign(await pe(e.root))}catch(e){r(`error`),a(e.message)}};return(0,F.jsxs)(`span`,{className:P(sf,`cursor-default`),role:`menuitem`,"data-stopped":``,"data-missing":o?``:void 0,style:{"--ws-c":Ee(e.color,e.root??e.url)},children:[(0,F.jsx)(Re,{className:`opacity-60 grayscale-50`,icon:e.icon,name:e.name,color:e.color,seed:e.root??e.url,ambiguous:t}),(0,F.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,F.jsx)(lf,{name:e.name,named:e.named}),n===`error`?(0,F.jsx)(`span`,{className:P(of,`text-bad`),title:i,children:i}):o?(0,F.jsx)(`span`,{className:of,children:`folder missing`}):(0,F.jsx)(cf,{label:e.rootLabel})]}),(0,F.jsxs)(`span`,{className:`ml-auto inline-flex flex-none items-center gap-3`,children:[(0,F.jsx)(df,{entry:e}),(0,F.jsx)(V,{variant:`quiet`,size:`sm`,icon:`play_arrow`,busy:n===`starting`,className:`text-accent hover:text-accent`,disabled:o,title:o?`The project folder no longer exists`:`Start the UI for this project`,onClick:e=>{e.stopPropagation(),s()},children:n===`starting`?`starting`:`start`})]})]})}function df({entry:e}){return(0,F.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 whitespace-nowrap text-2xs font-medium tracking-[0.5px] text-fg-2`,children:[e.live&&(0,F.jsx)(U,{tone:`ok`,title:`running`}),!e.here&&(0,F.jsx)(`span`,{className:`max-[800px]:hidden`,children:af(e.url)})]})}function ff({entry:e,ambiguous:t}){let n=e.root??e.url;return(0,F.jsxs)(`a`,{className:P(sf,`hover:bg-surface-2 active:bg-surface-2`),role:`menuitem`,href:fe(e),style:{"--ws-c":Ee(e.color,n)},children:[(0,F.jsx)(Re,{icon:e.icon,name:e.name,color:e.color,seed:n,ambiguous:t}),(0,F.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,F.jsx)(lf,{name:e.name,named:e.named}),(0,F.jsx)(cf,{label:e.rootLabel??(e.root?void 0:e.url.replace(/^https?:\/\//,``))})]}),(0,F.jsx)(`span`,{className:`ml-auto inline-flex flex-none items-center gap-3`,children:(0,F.jsx)(df,{entry:e})})]})}function pf({name:e,icon:t,color:n,named:r,root:i,seed:a,entries:o}){let[s,c]=(0,v.useState)(!1),l=be();(0,v.useEffect)(()=>{if(!s)return;let e=e=>{e.target.closest(`[data-switcher]`)||c(!1)};return window.addEventListener(`mousedown`,e),()=>window.removeEventListener(`mousedown`,e)},[s]);let u=new Map;for(let e of[t,...o.map(e=>e.icon)])e&&u.set(e,(u.get(e)??0)+1);let d=e=>!!e&&(u.get(e)??0)>1,f=[{key:`running`,label:`running`,items:o.filter(e=>e.live===!0)},{key:`stopped`,label:`stopped`,items:o.filter(e=>e.live===!1)},{key:`linked`,label:`linked`,items:o.filter(e=>e.live===void 0)}].filter(e=>e.items.length>0),p=a||e;return(0,F.jsxs)(`span`,{className:`relative inline-flex min-w-0`,"data-switcher":``,children:[(0,F.jsxs)(`button`,{type:`button`,className:`env-switch inline-flex max-w-[220px] min-w-0 cursor-pointer items-center gap-[5px] rounded-xl border-0 bg-transparent px-2 py-1 font-[inherit] text-[15px] font-bold tracking-[0.02em] whitespace-nowrap text-fg transition-colors hover:bg-surface-2 max-[1520px]:max-w-[250px]`,title:i?`${i} — workspace menu`:`Workspace menu`,"aria-haspopup":`menu`,"aria-expanded":s,onClick:()=>c(e=>!e),children:[(0,F.jsx)(`span`,{className:`min-w-0 truncate`,children:e}),(0,F.jsx)(I,{name:`expand_more`,className:`flex-none opacity-55`})]}),s&&(0,F.jsxs)(`div`,{className:`absolute top-[calc(100%+8px)] left-0 z-20 max-h-[calc(100dvh-120px)] max-w-[min(480px,92vw)] min-w-[360px] max-[800px]:fixed max-[800px]:inset-x-2 max-[800px]:top-[calc(var(--topbar-h)-4px)] max-[800px]:max-w-none max-[800px]:min-w-0 overflow-y-auto overscroll-contain rounded-card border border-line bg-surface py-2 shadow-pop`,role:`menu`,children:[o.length>0&&(0,F.jsx)(et,{className:`block px-4 pt-1 pb-2`,children:`workspaces`}),(0,F.jsxs)(`span`,{className:P(sf,`cursor-default bg-accent-soft text-on-accent-soft`),"aria-current":`true`,style:{"--ws-c":Ee(n,p)},children:[(0,F.jsx)(Re,{icon:t,name:e,color:n,seed:p,ambiguous:d(t)}),(0,F.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,F.jsx)(lf,{name:e,named:r}),i?(0,F.jsx)(cf,{label:i}):(0,F.jsx)(`span`,{className:of,children:`this workspace`})]}),(0,F.jsx)(`span`,{className:`ml-auto inline-flex flex-none items-center gap-3`,children:(0,F.jsx)(I,{name:`check`,className:`text-[24px] text-on-accent-soft`})})]}),f.map(e=>(0,F.jsxs)(`div`,{className:`mt-2 border-t border-line pt-1`,role:`group`,"aria-label":e.label,children:[(0,F.jsx)(et,{className:`block px-4 pt-2 pb-1`,children:e.label}),e.items.map(e=>e.live===!1&&e.root?(0,F.jsx)(uf,{entry:e,ambiguous:d(e.icon)},e.root):(0,F.jsx)(ff,{entry:e,ambiguous:d(e.icon)},e.root??e.url))]},e.key)),l&&o.length>0&&(0,F.jsxs)(`a`,{className:`mt-2 flex min-h-12 items-center gap-4 border-t border-line px-4 text-md text-fg no-underline transition-colors hover:bg-surface-2`,href:`#/workspaces`,role:`menuitem`,onClick:()=>c(!1),children:[(0,F.jsx)(I,{name:`hub`,className:`text-[22px] text-fg-2`}),` manage workspaces`]}),(0,F.jsx)(Cf,{onClose:()=>c(!1)})]})]})}function mf(){let[e,t]=(0,v.useState)(null);return(0,v.useEffect)(()=>{let e=!0;return A.call(`runs.list`).then(n=>{e&&(n.runs.length>0?B(`/runs/${n.runs[0].id}`,{replace:!0}):t({outputDir:n.outputDir}))}).catch(()=>{}),()=>{e=!1}},[]),e?(0,F.jsxs)(K,{icon:`play_circle`,children:[`No runs found in `,(0,F.jsx)(`code`,{children:e.outputDir}),`. Start one from the`,` `,(0,F.jsx)(`a`,{href:`#/workflows`,className:`text-accent`,children:`workflows`}),` list or with `,(0,F.jsx)(`code`,{children:`kraftwerk run <workflow> [request]`}),`.`]}):(0,F.jsx)(K,{children:`loading…`})}async function hf(e){await A.request(`server.restart`).catch(()=>{});for(let t=0;t<60;t++){await new Promise(e=>setTimeout(e,500));try{if((await A.call(`meta.get`)).version===e)break}catch{}}location.reload()}function gf(){let e=N(`meta.get`,{},{interval:3e4}),[t,n]=(0,v.useState)(!1),r=e?.restartable&&e.diskVersion&&e.diskVersion!==e.version?e.diskVersion:null;async function i(){r&&(n(!0),await hf(r))}return!r&&!t?null:(0,F.jsx)(`button`,{type:`button`,className:`mr-2.5 inline-flex flex-none cursor-pointer items-center gap-1 rounded-full border border-accent bg-accent/10 px-3 py-1 font-[inherit] text-xs text-accent hover:bg-accent/18 disabled:cursor-default disabled:opacity-70`,disabled:t,title:`v${r} is installed on disk, the server still runs v${e?.version}. Click to relaunch with the new version.`,onClick:()=>void i(),children:t?`relaunching…`:(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(I,{name:`restart_alt`,className:`ms-sm`}),` v`,r,` ready — relaunch`]})})}function _f(){let e=be();return(0,F.jsxs)(`button`,{type:`button`,className:P(`expert-toggle inline-flex cursor-pointer items-center gap-[7px] rounded-full border-0 bg-transparent px-2 py-1 font-mono text-2xs tracking-[0.5px] transition-colors hover:text-fg`,e?`text-fg`:`text-fg-2`),title:e?`Expert mode on — full detail`:`Expert mode off — simplified view`,"aria-pressed":e,onClick:()=>ye(!e),children:[(0,F.jsx)(`span`,{className:P(`relative h-[15px] w-[26px] rounded-full transition-colors`,e?`bg-accent`:`bg-fg/14`),children:(0,F.jsx)(`span`,{className:P(`absolute top-0.5 size-[11px] rounded-full transition-[left,background-color]`,e?`left-[13px] bg-on-accent`:`left-0.5 bg-surface`)})}),(0,F.jsx)(`span`,{className:`max-[640px]:hidden`,children:`expert`})]})}var vf={approval:`gavel`,routine_done:`schedule`,routine_failed:`schedule`,run_done:`account_tree`,run_failed:`account_tree`},yf=`kw.notif.toast.dismissed`;function bf(){let[e,t]=(0,v.useState)(!1),n=N(`notifications.list`,{},{interval:5e3}),[r,i]=(0,v.useState)(()=>typeof Notification>`u`?`unsupported`:Notification.permission),[a,o]=(0,v.useState)(()=>{try{return localStorage.getItem(yf)===`1`}catch{return!1}}),s=(0,v.useRef)(null),[c,l]=(0,v.useState)(null),[u,d]=(0,v.useState)(null);(0,v.useEffect)(()=>l(null),[n]);let f=(c??n)?.items??[],p=Ft()??[],m=new Set(p.map(e=>e.notificationId).filter(Boolean)),h=f.filter(e=>e.kind!==`approval`&&!m.has(e.id)),g=h.filter(e=>!e.readAt).length,_=p.length;(0,v.useEffect)(()=>se(p.length),[p.length]),(0,v.useEffect)(()=>{if(n){if(!s.current){s.current=new Set(f.map(e=>e.id));return}for(let e of f)if(!s.current.has(e.id)&&(s.current.add(e.id),!(e.readAt||r!==`granted`)&&(document.hidden||location.hash!==`#${e.href}`)))try{let t=new Notification(e.title,{body:e.body,tag:e.id});t.onclick=()=>{window.focus(),S(e),t.close()}}catch{}}},[n]),(0,v.useEffect)(()=>{if(!e)return;let n=e=>{e.target.closest(`[data-bell]`)||t(!1)};return window.addEventListener(`mousedown`,n),()=>window.removeEventListener(`mousedown`,n)},[e]);async function y(e){try{let t=await e;if(!t.ok)return;let n=t.data;l(`items`in n?n:{items:[],unread:0})}catch{}}let b=e=>y(A.request(`notifications.read`,{body:{ids:e}})),x=()=>y(A.request(`notifications.clear`));function S(e){t(!1),e.readAt||b([e.id]),B(e.href)}async function C(e){d(e.id);try{let n=await A.request(`notifications.diagnose`,{id:e.id});n.ok?(t(!1),B(n.data.href)):n.error&&alert(n.error)}catch{}d(null)}async function w(){typeof Notification<`u`&&i(await Notification.requestPermission())}function T(){o(!0);try{localStorage.setItem(yf,`1`)}catch{}}let E=r==="default"&&!a;return(0,F.jsxs)(`span`,{className:`relative inline-flex`,"data-bell":``,children:[(0,F.jsxs)(`button`,{type:`button`,className:P(`relative grid size-8 cursor-pointer place-items-center rounded-full border-0 bg-transparent transition-colors hover:bg-surface-2 hover:text-fg`,_?`text-fg`:`text-fg-2`),title:_?`${_} thing${_===1?``:`s`} waiting for you`:g?`${g} update${g===1?``:`s`}`:`Notifications`,"aria-label":`Notifications`,onClick:()=>t(e=>!e),children:[(0,F.jsx)(I,{name:_?`notifications_active`:`notifications`}),g>0&&(0,F.jsx)(`span`,{className:`absolute top-1.5 right-1.5 size-[7px] rounded-full bg-accent`})]}),e&&(0,F.jsxs)(`div`,{className:`notif-pop absolute right-0 top-[calc(100%+8px)] z-50 flex max-h-[min(80dvh,640px)] w-[min(460px,92vw)] flex-col overflow-hidden rounded-card border border-line bg-surface shadow-pop`,role:`menu`,children:[(0,F.jsxs)(`div`,{className:`flex items-center gap-1 border-b border-line px-4 py-2`,children:[(0,F.jsx)(et,{className:`text-fg`,children:`notifications`}),(0,F.jsx)(`span`,{className:`flex-1`}),g>0&&(0,F.jsx)(V,{variant:`quiet`,size:`sm`,onClick:()=>void b(h.filter(e=>!e.readAt).map(e=>e.id)),children:`mark updates read`}),f.length>0&&(0,F.jsx)(V,{variant:`quiet`,size:`sm`,onClick:()=>void x(),children:`clear`})]}),(0,F.jsxs)(`div`,{className:`min-h-0 overflow-y-auto overscroll-contain pb-1.5`,children:[E&&(0,F.jsxs)(`div`,{className:`m-2 flex flex-col gap-2 rounded-control bg-surface-2 p-3 text-sm`,children:[(0,F.jsx)(`span`,{children:`Get a system notification when something needs you, even with this tab in the background.`}),(0,F.jsxs)(`span`,{className:`flex gap-2`,children:[(0,F.jsx)(V,{variant:`primary`,size:`sm`,onClick:()=>void w(),children:`enable`}),(0,F.jsx)(V,{variant:`quiet`,size:`sm`,onClick:T,children:`not now`})]})]}),r===`denied`&&(0,F.jsx)(`p`,{className:`m-0 px-4 pt-2 text-xs text-fg-2`,children:`Browser notifications are blocked for this site — allow them in the address bar to get system alerts.`}),(0,F.jsx)(tt,{title:`needs you`,count:p.length||void 0,className:`px-1.5 pt-1.5`,children:p.length===0?(0,F.jsx)(`p`,{className:`m-0 px-2.5 py-2 text-sm text-fg-2`,children:`nothing is waiting for you`}):Sf(p).map(([e,n])=>(0,F.jsxs)(`div`,{children:[(0,F.jsx)(`div`,{className:`notif-owner px-2.5 pb-0.5 pt-2 text-xs font-semibold text-fg`,children:e}),n.map(e=>{let n=e.notificationId?f.find(t=>t.id===e.notificationId):void 0;return(0,F.jsx)(Y,{className:`notif-row need`,onClick:()=>{t(!1),Vt(e)},leading:(0,F.jsx)(I,{name:e.kind===`approval`?`front_hand`:e.kind===`question`?`help`:`error`,className:`ms-sm text-bad`}),title:e.title,sub:`${e.kind===`approval`?`needs approval`:e.kind===`question`?`asks you`:`failed`}${e.chatTitle?` · in ${e.chatTitle}`:``}`,meta:Ge(e.since),actionsAlways:!0,actions:n?.diagnose?(0,F.jsx)(xf,{busy:u===n.id,onClick:()=>void C(n)}):void 0},e.id)})]},e))}),(0,F.jsx)(tt,{title:`updates`,className:`px-1.5 pt-1.5`,children:h.length===0?(0,F.jsx)(`p`,{className:`m-0 px-2.5 py-2 text-sm text-fg-2`,children:`no updates`}):h.slice(0,50).map(e=>(0,F.jsx)(Y,{className:P(`notif-row`,!e.readAt&&`bg-accent/5`),onClick:()=>S(e),leading:(0,F.jsx)(I,{name:vf[e.kind],className:P(`ms-sm`,e.kind.endsWith(`failed`)?`text-bad`:e.kind.endsWith(`done`)?`text-ok`:``)}),title:e.title,sub:e.body,meta:Ge(e.at),actionsAlways:!0,actions:e.diagnose?(0,F.jsx)(xf,{busy:u===e.id,onClick:()=>void C(e)}):void 0},e.id))})]})]})]})}function xf({busy:e,onClick:t}){return(0,F.jsx)(V,{variant:`secondary`,size:`sm`,icon:`troubleshoot`,busy:e,title:`Open a chat that finds the cause and proposes the fix`,onClick:e=>{e.stopPropagation(),t()},children:e?`starting…`:`diagnose`})}function Sf(e){let t=new Map;for(let n of e){let e=Lt(n.owner);t.set(e,[...t.get(e)??[],n])}return[...t.entries()]}function Cf({onClose:e}){let t=be(),[n,r]=(0,v.useState)(null),[i,a]=(0,v.useState)(null),[o,s]=(0,v.useState)(``);return(0,v.useEffect)(()=>{A.call(`meta.get`).then(e=>s(e.version)).catch(()=>{}),t&&(A.call(`runs.list`).then(r).catch(()=>{}),A.call(`workflows.list`).then(a).catch(()=>{}))},[t]),(0,F.jsxs)(`div`,{className:`ws-menu mt-1.5 flex flex-col gap-0.5 border-t border-line px-1.5 pb-1 pt-2`,children:[(0,F.jsx)(wf,{label:`Theme`,children:(0,F.jsx)(kf,{})}),(0,F.jsx)(`div`,{className:`flex gap-1 px-1`,children:(0,F.jsx)(V,{variant:`quiet`,size:`sm`,icon:`delete`,href:`/trash`,onClick:e,children:`trash`})}),t&&(0,F.jsxs)(`div`,{className:`flex flex-col gap-1 px-2.5 py-1.5 text-xs`,children:[(0,F.jsxs)(`div`,{children:[(0,F.jsx)(et,{children:`Workflows`}),` `,i?`${i.workflows.length} discovered`:`…`,` `,(0,F.jsx)(`code`,{className:`block break-all text-2xs text-fg-2`,title:i?.root,children:i?.root??``})]}),(0,F.jsxs)(`div`,{children:[(0,F.jsx)(et,{children:`Runs`}),` `,n?`${n.runs.length} total`:`…`,` `,(0,F.jsx)(`code`,{className:`block break-all text-2xs text-fg-2`,title:n?.outputDir,children:n?.outputDir??``})]})]}),(0,F.jsx)(wf,{label:(0,F.jsx)(`span`,{className:`font-mono`,children:o?`kraftwerk ${o}`:`…`}),children:(0,F.jsx)(Ef,{})})]})}function wf({label:e,children:t}){return(0,F.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-2.5 py-1.5`,children:[(0,F.jsx)(`span`,{className:`text-sm text-fg-2`,children:e}),t]})}function Tf(e,t){let n=e.split(`.`).map(Number),r=t.split(`.`).map(Number);for(let e=0;e<3;e++)if((n[e]??0)!==(r[e]??0))return(n[e]??0)<(r[e]??0);return!1}function Ef(){let[e,t]=(0,v.useState)(`idle`),[n,r]=(0,v.useState)(null),[i,a]=(0,v.useState)(null),[o,s]=(0,v.useState)(``),[c,l]=(0,v.useState)(!1);async function u(){t(`busy`);try{let e=await A.call(`update.check`);if(!e.latest)throw Error();r(e),t(`done`)}catch{t(`err`)}}let d=i?.state===`running`;(0,v.useEffect)(()=>{if(!d)return;let e=!0,t=setInterval(async()=>{try{let t=await A.call(`update.status`);if(!e)return;a(t)}catch{}},1e3);return()=>{e=!1,clearInterval(t)}},[d]);async function f(){if(!n)return;s(``);let e=await A.request(`update.start`,{body:{version:n.latest}});e.ok?a(e.data):s(e.error??`update refused`)}if(i&&i.state!==`idle`&&n){let e=i.log[i.log.length-1]??``;return i.state===`running`?(0,F.jsxs)(`span`,{className:P(Df,`basis-full flex-wrap`),children:[(0,F.jsx)(I,{name:`progress_activity`,className:`ms-sm`}),` installing v`,n.latest,`…`,e&&(0,F.jsx)(`code`,{className:`max-w-full truncate text-2xs text-fg-2`,title:i.log.join(`
230
- `),children:e})]}):i.state===`done`?(0,F.jsxs)(`span`,{className:P(Df,Of),children:[`v`,n.latest,` installed —`,` `,i.restartable?(0,F.jsx)(V,{size:`sm`,icon:`restart_alt`,busy:c,onClick:()=>{l(!0),hf(n.latest)},children:c?`relaunching…`:`relaunch`}):(0,F.jsxs)(F.Fragment,{children:[`restart `,(0,F.jsx)(`code`,{children:`kraftwerk ui`}),` to use it`]})]}):(0,F.jsxs)(`span`,{className:P(Df,`basis-full flex-wrap text-bad`),title:i.log.join(`
231
- `),children:[(0,F.jsx)(I,{name:`error`,className:`ms-sm`}),` install failed`,e?` — ${e}`:``,` · `,(0,F.jsxs)(`code`,{children:[`npm i -g `,n.name,`@latest`]})]})}return e===`done`&&n?Tf(n.current,n.latest)?(0,F.jsxs)(`span`,{className:P(Df,Of),children:[`v`,n.latest,` available —`,` `,o?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`span`,{className:`font-normal text-fg-2`,title:o,children:o}),` · `,(0,F.jsxs)(`code`,{className:`text-2xs`,children:[`npm i -g `,n.name,`@latest`]})]}):(0,F.jsx)(V,{size:`sm`,icon:`download`,onClick:()=>void f(),children:`update now`})]}):(0,F.jsxs)(`span`,{className:Df,children:[(0,F.jsx)(I,{name:`check`,className:`ms-sm text-ok`}),` up to date`]}):(0,F.jsx)(V,{size:`sm`,icon:e===`busy`||e===`err`?void 0:`sync`,disabled:e===`busy`,onClick:()=>void u(),children:e===`busy`?`checking…`:e===`err`?`npm unreachable — retry`:`check for updates`})}var Df=`inline-flex items-center gap-[5px] text-xs text-fg-2`,Of=`basis-full flex-wrap font-medium text-accent`;function kf(){return(0,F.jsx)(V,{size:`sm`,icon:`contrast`,onClick:()=>{let e=document.documentElement,t=e.dataset.theme===`light`?`dark`:`light`;e.dataset.theme=t;try{localStorage.setItem(`kw-theme`,t)}catch{}},children:`day / night`})}(0,y.createRoot)(document.getElementById(`root`)).render((0,F.jsx)(v.StrictMode,{children:(0,F.jsx)(Jl,{children:(0,F.jsx)(rf,{})})}));export{o as a,d as i,ne as n,s as o,h as r,l as s,al as t};
227
+ `]})]}):(0,F.jsx)(`div`,{className:ju,children:`no textual diff (binary or empty)`})}var ju=`git-diff mt-1.5 mb-0.5 max-h-[420px] basis-full overflow-auto rounded-xl bg-surface-2 px-3 py-2.5 font-mono text-[11.5px] leading-[1.5] whitespace-pre`,Mu={modified:`text-accent`,added:`text-ok`,untracked:`text-ok`,deleted:`text-bad`,conflicted:`text-bad`};function Nu({status:e,muted:t}){return(0,F.jsx)(`span`,{className:P(`flex-none rounded-full border border-line px-2 py-0.5 text-[10.5px] font-semibold tracking-[0.4px] uppercase`,t?`text-fg-2`:Mu[e]??`text-fg-2`),children:e})}var Pu=`text-xs text-fg-2`,Fu=`m-0 p-[18px] text-sm text-fg-2`;function Iu(){let[e,t]=(0,v.useState)(null),[n,r]=(0,v.useState)(new Set),[i,a]=(0,v.useState)(new Set),[o,s]=(0,v.useState)(``),[c,l]=(0,v.useState)(``),[u,d]=(0,v.useState)(``),[f,p]=(0,v.useState)(``),m=(0,v.useRef)(!0),h=(0,v.useCallback)(async()=>{try{let e=await A.request(`git.status`,{query:{fresh:m.current}});m.current=!1,e.ok&&t(e.data)}catch{}},[]);(0,v.useEffect)(()=>{let e=!0,t,n=async()=>{await h(),e&&(t=setTimeout(n,6e3))};return n(),()=>{e=!1,clearTimeout(t)}},[h]),(0,v.useEffect)(()=>{if(!e?.files)return;let t=new Set(e.files.filter(e=>e.syncable).map(e=>e.path));r(e=>{let n=new Set([...e].filter(e=>t.has(e)));return n.size===e.size?e:n})},[e]);let g=async(e,t)=>{l(e),d(``),p(``);try{let n=await A.request(`git.${e}`,{body:t??{}});n.ok&&n.data.ok?p(e===`push`?`pushed`:e===`pull`?`pulled`:`fetched`):d(M(n)||`${e} failed`)}catch(t){d(t.message||`${e} failed`)}finally{l(``)}h()},_=async()=>{l(`commit`),d(``),p(``);try{let e=await A.request(`git.commit`,{body:{paths:[...n],message:o}});e.ok&&e.data.ok?(p(`committed ${n.size} file${n.size===1?``:`s`}`),r(new Set),s(``)):d(M(e)||`commit failed`)}catch(e){d(e.message||`commit failed`)}finally{l(``)}h()};if(!e)return(0,F.jsx)(K,{children:`loading…`});if(!e.enabled)return(0,F.jsxs)(it,{children:[(0,F.jsx)(rt,{icon:`cloud_sync`,title:`Git sync`}),(0,F.jsx)(J,{children:(0,F.jsxs)(`p`,{className:Fu,children:[`Git sync is off. Turn it on in `,(0,F.jsx)(`a`,{href:`#/settings`,children:`settings`}),`, or add a `,(0,F.jsx)(`code`,{children:`git:`}),` block to kraftwerk.yml.`]})})]});let y=(e.files??[]).filter(e=>e.syncable),b=(e.files??[]).filter(e=>!e.syncable),x=(e,t)=>r(n=>{let r=new Set(n);return t?r.add(e):r.delete(e),r});return(0,F.jsxs)(it,{children:[(0,F.jsx)(rt,{icon:`cloud_sync`,title:`Git sync`,actions:(0,F.jsxs)(F.Fragment,{children:[f&&(0,F.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-sm text-ok`,children:[(0,F.jsx)(I,{name:`check`,className:`ms-sm`}),` `,f]}),u&&(0,F.jsx)(q,{tone:`bad`,children:u})]})}),(0,F.jsx)(J,{title:`branch`,actions:(0,F.jsxs)(F.Fragment,{children:[e.lastFetch&&(0,F.jsxs)(`span`,{className:`text-xs text-fg-2`,title:e.lastFetch,children:[`fetched `,Ge(e.lastFetch)]}),e.lastError&&(0,F.jsxs)(`span`,{className:`inline-flex max-w-[46ch] items-center gap-1 truncate text-xs text-bad`,title:e.lastError,children:[(0,F.jsx)(I,{name:`cloud_off`,className:`ms-sm`}),` `,e.lastError.split(`
228
+ `)[0]]})]}),children:e.error?(0,F.jsxs)(`div`,{className:`flex items-center gap-2 p-[18px] text-sm text-bad`,children:[(0,F.jsx)(I,{name:`error`,className:`ms-sm`}),` `,e.error]}):(0,F.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4 px-[18px] py-3.5`,children:[(0,F.jsxs)(`div`,{className:`flex items-center gap-2 text-base`,children:[(0,F.jsx)(I,{name:`account_tree`,className:`ms-sm`}),(0,F.jsx)(`strong`,{className:`font-mono`,children:e.branch}),(0,F.jsx)(`span`,{className:Pu,children:e.upstream?`tracking ${e.upstream}`:`no upstream yet, push sets one`})]}),(0,F.jsxs)(`div`,{className:`flex items-center gap-2.5 text-[12.5px] font-semibold`,children:[e.diverged&&(0,F.jsx)(`span`,{className:`text-bad`,children:`diverged, resolve in a terminal`}),!!e.behind&&(0,F.jsxs)(`span`,{className:`text-accent`,children:[e.behind,` behind`]}),!!e.ahead&&(0,F.jsxs)(`span`,{className:`text-ok`,children:[e.ahead,` ahead`]}),!e.ahead&&!e.behind&&(0,F.jsx)(`span`,{className:P(`text-xs text-fg-2`,`font-normal`),children:`up to date`})]}),(0,F.jsxs)(`div`,{className:`ml-auto flex flex-wrap items-center gap-2`,children:[(0,F.jsx)(V,{size:`sm`,icon:`refresh`,busy:c===`fetch`,disabled:!!c,onClick:()=>void g(`fetch`),children:`fetch`}),(0,F.jsx)(V,{size:`sm`,icon:`download`,busy:c===`pull`,disabled:!!c||!e.behind||e.diverged,title:e.diverged?`Diverged. Resolve in a terminal.`:`Fast-forward to the remote`,onClick:()=>void g(`pull`),children:`pull`}),(0,F.jsx)(V,{size:`sm`,variant:`primary`,icon:`upload`,busy:c===`push`,disabled:!!c||!e.ahead&&!!e.upstream,title:e.upstream?`Push to the upstream`:`Push and set the upstream`,onClick:()=>void g(`push`),children:`push`})]})]})}),(0,F.jsxs)(J,{title:`changes`,actions:(0,F.jsx)(`span`,{className:Pu,children:y.length===0?`workspace clean`:`${n.size} of ${y.length} selected`}),children:[y.length===0&&b.length===0&&(0,F.jsx)(`p`,{className:`m-0 p-[18px] text-sm text-fg-2`,children:`Nothing changed under the workspace paths.`}),y.map(e=>(0,F.jsxs)(`div`,{className:P(`git-row px-[18px]`,Lu),children:[(0,F.jsx)(`input`,{type:`checkbox`,className:`accent-accent`,"aria-label":`select ${e.path}`,checked:n.has(e.path),onChange:t=>x(e.path,t.target.checked)}),(0,F.jsxs)(`button`,{type:`button`,className:`group/file flex min-w-0 flex-1 cursor-pointer items-center gap-2 border-0 bg-transparent px-0 py-0.5 text-left font-[inherit] text-fg`,onClick:()=>a(t=>{let n=new Set(t);return n.has(e.path)?n.delete(e.path):n.add(e.path),n}),children:[(0,F.jsx)(I,{name:i.has(e.path)?`expand_more`:`chevron_right`,className:`ms-sm`}),(0,F.jsx)(Nu,{status:e.status}),(0,F.jsx)(`span`,{className:P(Ru,`group-hover/file:underline`),children:e.path})]}),i.has(e.path)&&(0,F.jsx)(Ou,{file:e.path})]},e.path)),y.length>0&&(0,F.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2.5 border-t border-line bg-surface-2 px-[18px] py-3`,children:[(0,F.jsx)(X,{className:`min-w-[220px] flex-1 text-sm`,placeholder:`Commit message`,"aria-label":`commit message`,value:o,onChange:e=>s(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!c&&o.trim()&&n.size>0&&_()}}),(0,F.jsx)(V,{size:`sm`,disabled:n.size===y.length,onClick:()=>r(new Set(y.map(e=>e.path))),children:`select all`}),(0,F.jsxs)(V,{size:`sm`,variant:`primary`,icon:`check`,busy:c===`commit`,disabled:!!c||n.size===0||!o.trim(),onClick:()=>void _(),children:[`commit `,n.size||``]})]}),b.length>0&&(0,F.jsxs)(`details`,{className:`border-t border-line px-[18px] py-2.5`,children:[(0,F.jsxs)(`summary`,{className:`cursor-pointer text-[12.5px] text-fg-2`,children:[b.length,e.blockedHidden?`+`:``,` change`,b.length===1&&!e.blockedHidden?``:`s`,` outside the workspace paths`]}),b.map(e=>(0,F.jsxs)(`div`,{className:P(`git-row blocked opacity-60`,Lu),children:[(0,F.jsx)(Nu,{status:e.status,muted:!0}),(0,F.jsx)(`span`,{className:Ru,children:e.path}),(0,F.jsx)(`span`,{className:`text-xs text-fg-2`,children:e.reason})]},e.path)),!!e.blockedHidden&&(0,F.jsx)(`div`,{className:P(`git-row blocked opacity-60`,Lu),children:(0,F.jsxs)(`span`,{className:`text-xs text-fg-2`,children:[`and `,e.blockedHidden,` more, not listed`]})})]})]}),(0,F.jsxs)(`p`,{className:P(Pu,`m-0`),children:[`Synced paths: `,(e.scope??[]).map((e,t)=>(0,F.jsxs)(`span`,{children:[t>0&&`, `,(0,F.jsx)(`code`,{children:e})]},e)),`. Run artifacts and files like `,(0,F.jsx)(`code`,{children:`.env`}),` are never staged.`,` `,e.interval?`Fetches every ${Tu(e.interval)}${e.autosync===`pull`?` and fast-forwards when the working tree is clean`:``}. `:`Background fetching is off. `,`Commit and push are always manual.`]})]})}var Lu=`flex flex-wrap items-center gap-2.5 py-2 [&+&]:border-t [&+&]:border-line`,Ru=`truncate font-mono text-[12.5px]`,zu=e=>e.replace(/^https?:\/\//,``).replace(/^git@([^:]+):/,`$1/`).replace(/\.git$/,``),Bu=e=>e.error?{label:`unreadable`,state:`unreadable`}:e.dirty?{label:`${e.dirty} changed`,state:`changed`}:e.ahead?{label:`${e.ahead} to push`,state:`clean`}:e.behind?{label:`${e.behind} behind`,state:`behind`}:{label:`clean`,state:`clean`};function Vu({label:e,state:t}){return(0,F.jsx)(`span`,{className:P(`inline-flex items-center text-2xs font-semibold tracking-[0.4px] uppercase`,t===`clean`?`text-ok`:t===`changed`?`text-ask`:t===`unreadable`?`text-bad`:`text-fg-2`),children:e})}var Hu=`rounded-full border border-line px-[7px] py-px font-mono text-xs text-fg-2`,Uu=`border-line px-[18px] py-2 [&+&]:border-t`,Wu=`group/item flex w-full cursor-pointer items-center gap-2 border-0 bg-transparent px-0 py-0.5 text-left font-[inherit] text-fg`,Gu=`min-w-0 truncate font-mono text-[12.5px] group-hover/item:underline`;function Ku({title:e,children:t}){return(0,F.jsxs)(`header`,{className:`flex flex-wrap items-center gap-3`,children:[(0,F.jsx)(V,{size:`sm`,variant:`quiet`,icon:`arrow_back`,href:`/repos`,title:`all repositories`,children:`repositories`}),(0,F.jsx)(I,{name:`folder_data`,className:`text-[26px] text-fg-2`}),(0,F.jsx)(nt,{children:e}),t]})}var qu=e=>!!(e.error||e.dirty||e.ahead===void 0||e.ahead);function Ju({slug:e}){return e?(0,F.jsx)(Yu,{slug:e}):(0,F.jsx)(Xu,{})}function Yu({slug:e}){let[t,n]=(0,v.useState)(null),[r,i]=(0,v.useState)(``),[a,o]=(0,v.useState)(null),[s,c]=(0,v.useState)(null),[l,u]=(0,v.useState)(``),[d,f]=(0,v.useState)(``),[p,m]=(0,v.useState)(0),h=be(),g=(0,v.useCallback)(async()=>{try{let t=await A.request(`repos.get`,{slug:e});if(!t.ok)throw Error(M(t));n(t.data),i(``)}catch(e){i(e.message||`could not load the repository`)}},[e]);(0,v.useEffect)(()=>{let e=!0,t,n=async()=>{await g(),e&&(t=setTimeout(n,5e3))};return n(),()=>{e=!1,clearTimeout(t)}},[g,p]);let _=async()=>{u(`update`),f(``);try{let t=await A.request(`repos.update`,{slug:e});if(!t.ok||!t.data.ok)throw Error(t.error||`failed`);t.data.error&&f(t.data.error)}catch(e){f(e.message)}finally{u(``),m(e=>e+1)}};if(r&&!t)return(0,F.jsxs)(it,{className:`repo-page`,children:[(0,F.jsx)(Ku,{title:e}),(0,F.jsx)(q,{tone:`bad`,children:r})]});if(!t)return(0,F.jsx)(K,{children:`loading…`});let y=Bu(t),b=t.commits.filter(e=>e.local).length;return(0,F.jsxs)(it,{className:`repo-page`,children:[(0,F.jsxs)(Ku,{title:t.slug,children:[t.branch&&(0,F.jsx)(`span`,{className:Hu,children:t.branch}),t.upstream&&(0,F.jsxs)(`span`,{className:`text-xs text-fg-2`,title:`upstream`,children:[`→ `,t.upstream]}),(0,F.jsx)(Vu,{...y}),(0,F.jsx)(`span`,{className:`flex-1`}),(0,F.jsx)(V,{size:`sm`,icon:`sync`,busy:l===`update`,disabled:!!l,onClick:()=>void _(),title:`git fetch, then fast-forward when clean`,children:l===`update`?`updating…`:`update`})]}),(0,F.jsxs)(`div`,{className:P(Pu,`flex flex-wrap gap-x-3.5 gap-y-1`),children:[t.url&&(0,F.jsx)(`span`,{title:t.url,children:zu(t.url)}),h&&(0,F.jsx)(`span`,{title:t.path,children:t.path}),t.head&&(0,F.jsxs)(`span`,{children:[`at `,(0,F.jsx)(`code`,{children:t.head}),t.committedAt?` · ${Ge(t.committedAt)}`:``]}),!!t.ahead&&(0,F.jsxs)(`span`,{children:[t.ahead,` to push`]}),!!t.behind&&(0,F.jsxs)(`span`,{children:[t.behind,` behind`]}),t.updatedAt&&(0,F.jsxs)(`span`,{children:[`changed `,Ge(t.updatedAt)]})]}),(t.error||d||r)&&(0,F.jsx)(q,{tone:`bad`,children:t.error||d||r}),(0,F.jsxs)(J,{title:`changes · working tree against HEAD`,actions:(0,F.jsxs)(`span`,{className:Pu,children:[t.files.length,` file`,t.files.length===1?``:`s`,t.insertions||t.deletions?(0,F.jsxs)(F.Fragment,{children:[` · `,(0,F.jsxs)(`span`,{className:`text-ok`,children:[`+`,t.insertions]}),` `,(0,F.jsxs)(`span`,{className:`text-bad`,children:[`−`,t.deletions]})]}):null]}),children:[t.files.length===0&&(0,F.jsx)(`p`,{className:`m-0 p-[18px] text-sm text-fg-2`,children:`Clean — nothing changed since the last commit.`}),t.files.map(n=>(0,F.jsxs)(`div`,{className:P(`repo-file`,Uu),"data-file":n.path,children:[(0,F.jsxs)(`button`,{type:`button`,className:Wu,onClick:()=>o(a===n.path?null:n.path),children:[(0,F.jsx)(I,{name:a===n.path?`expand_more`:`chevron_right`,className:`ms-sm`}),(0,F.jsx)(Nu,{status:n.status}),(0,F.jsx)(`span`,{className:Gu,children:n.path})]}),a===n.path&&(0,F.jsx)(Au,{source:{route:`repos.diff`,input:{slug:e,query:{path:n.path}}},refresh:t.updatedAt})]},n.path))]}),(0,F.jsxs)(J,{title:`commits · newest first`,actions:(0,F.jsx)(`span`,{className:Pu,children:b?`${b} not pushed`:t.commits.length?`all pushed`:``}),children:[t.commits.length===0&&(0,F.jsx)(`p`,{className:`m-0 p-[18px] text-sm text-fg-2`,children:`No commits yet.`}),t.commits.map(t=>(0,F.jsxs)(`div`,{className:P(`repo-commit`,Uu),"data-commit":t.short,children:[(0,F.jsxs)(`button`,{type:`button`,className:Wu,onClick:()=>c(s===t.hash?null:t.hash),title:t.hash,children:[(0,F.jsx)(I,{name:s===t.hash?`expand_more`:`chevron_right`,className:`ms-sm`}),(0,F.jsx)(`code`,{className:`text-xs`,children:t.short}),(0,F.jsx)(`span`,{className:`min-w-0 truncate text-sm group-hover/item:underline`,children:t.subject}),t.local&&(0,F.jsx)(W,{tone:`accent`,children:`not pushed`}),(0,F.jsxs)(`span`,{className:P(Pu,`ml-auto flex-none`),children:[t.author,` · `,Ge(t.committedAt)]})]}),s===t.hash&&(0,F.jsx)(Au,{source:{route:`repos.commit`,input:{slug:e,hash:t.hash}}})]},t.hash))]})]})}function Xu(){let[e,t]=(0,v.useState)(null),[n,r]=(0,v.useState)(``),[i,a]=(0,v.useState)({}),[o,s]=(0,v.useState)({}),[c,l]=(0,v.useState)(null),[u,d]=(0,v.useState)(``),[f,p]=(0,v.useState)(``),[m,h]=(0,v.useState)(``),[g,_]=(0,v.useState)(!1),[y,b]=(0,v.useState)(``),x=be(),S=(0,v.useCallback)(async()=>{try{let e=await A.request(`repos.list`);if(!e.ok)throw Error(`HTTP ${e.status}`);t(e.data),r(``)}catch(e){r(e.message||`could not load repositories`)}},[]);(0,v.useEffect)(()=>{let e=!0,t,n=async()=>{await S(),e&&(t=setTimeout(n,15e3))};return n(),()=>{e=!1,clearTimeout(t)}},[S]);let C=async(e,t,n=!1)=>{a(n=>({...n,[e]:t})),s(t=>({...t,[e]:``})),l(null);try{let r=t===`update`?await A.request(`repos.update`,{slug:e}):await A.request(`repos.remove`,{slug:e,query:{force:n}});if(!r.ok||!r.data.ok)throw Error(r.error||`failed`);let i=r.data.error;i&&s(t=>({...t,[e]:i}))}catch(t){s(n=>({...n,[e]:t.message}))}finally{a(t=>{let n={...t};return delete n[e],n}),S()}},w=async e=>{if(e.preventDefault(),u.trim()&&!g){_(!0),b(``);try{let e=await A.request(`repos.add`,{body:{url:u.trim(),name:f.trim()||void 0,branch:m.trim()||void 0}});if(!e.ok)throw Error(e.error||`clone failed`);d(``),p(``),h(``),await S()}catch(e){b(e.message)}finally{_(!1)}}},T=[...e?.repos??[]].sort((e,t)=>(t.updatedAt??``).localeCompare(e.updatedAt??``));return(0,F.jsxs)(it,{children:[(0,F.jsx)(rt,{icon:`source`,title:`Repositories`,actions:(0,F.jsxs)(F.Fragment,{children:[e?.enabled&&(0,F.jsxs)(`span`,{className:`text-xs text-fg-2`,children:[T.length,` cloned`]}),n&&(0,F.jsx)(q,{tone:`bad`,children:n})]})}),e&&!e.enabled&&(0,F.jsx)(J,{children:(0,F.jsx)(`div`,{className:`m-0 p-[18px] text-sm text-fg-2`,children:e.error&&!/are off/.test(e.error)?(0,F.jsx)(q,{tone:`bad`,children:e.error}):(0,F.jsxs)(F.Fragment,{children:[`Repositories are off. Turn them on in `,(0,F.jsx)(`a`,{href:`#/settings`,children:`settings`}),` or add a `,(0,F.jsx)(`code`,{children:`repos:`}),` block to kraftwerk.yml.`]})})}),e?.enabled&&(0,F.jsx)(J,{title:`add a repository`,actions:(0,F.jsxs)(`span`,{className:`text-xs text-fg-2`,children:[`clones into `,(0,F.jsx)(`code`,{title:e.root,children:e.root})]}),children:(0,F.jsxs)(`form`,{className:`flex flex-col gap-2.5 p-[18px]`,onSubmit:e=>void w(e),children:[(0,F.jsxs)(`div`,{className:`flex flex-wrap items-end gap-2.5`,children:[(0,F.jsx)(Z,{label:`url`,className:`min-w-[240px] flex-[2]`,children:(0,F.jsx)(X,{value:u,placeholder:`https://github.com/org/repo.git, git@host:org/repo.git or github:org/repo`,onChange:e=>d(e.target.value),autoFocus:!0})}),(0,F.jsx)(Z,{label:`name`,className:`min-w-[140px] flex-1`,children:(0,F.jsx)(X,{value:f,placeholder:`from the url`,onChange:e=>p(e.target.value)})}),(0,F.jsx)(Z,{label:`branch`,className:`w-[140px]`,children:(0,F.jsx)(X,{value:m,placeholder:`default`,onChange:e=>h(e.target.value)})}),(0,F.jsx)(V,{type:`submit`,variant:`primary`,icon:`download`,busy:g,disabled:!u.trim(),children:g?`cloning…`:`clone`})]}),y&&(0,F.jsx)(q,{tone:`bad`,children:y}),(0,F.jsxs)(`p`,{className:P(`text-xs text-fg-2`,`m-0`),children:[`Uses your own git credentials and never prompts: a private remote must already work from a terminal. Agents see every clone here and can add more with `,(0,F.jsx)(`code`,{children:`kraftwerk repos add`}),`.`]})]})}),e?.enabled&&(0,F.jsxs)(J,{title:`cloned repositories · newest change first`,children:[T.length===0&&(0,F.jsx)(`p`,{className:`m-0 p-[18px] text-sm text-fg-2`,children:`Nothing cloned yet.`}),T.map(e=>{let t=i[e.slug],n=Bu(e);return(0,F.jsxs)(`div`,{className:P(`repo-row grid grid-cols-[40px_minmax(0,1fr)_auto] items-start gap-3.5 border-line px-[18px] py-3.5 [&+&]:border-t`,n.state===`changed`&&`bg-ask-soft/40`),"data-repo":e.slug,children:[(0,F.jsx)(`span`,{className:P(`grid size-10 place-items-center rounded-full bg-surface-2 text-fg-2`,n.state===`unreadable`&&`opacity-45 grayscale`),children:(0,F.jsx)(I,{name:`folder_data`,className:`text-[22px]`})}),(0,F.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-[3px]`,children:[(0,F.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2.5`,children:[(0,F.jsx)(he,{href:`/repos/${encodeURIComponent(e.slug)}`,className:`text-md font-semibold text-fg no-underline hover:underline`,title:`changes and commits`,children:e.slug}),e.branch&&(0,F.jsx)(`span`,{className:Hu,children:e.branch}),(0,F.jsx)(Vu,{...n}),e.updatedAt&&(0,F.jsxs)(`span`,{className:`text-xs text-fg-2`,title:e.updatedAt,children:[`changed `,Ge(e.updatedAt)]})]}),e.url&&(0,F.jsx)(`div`,{className:`font-mono text-xs [overflow-wrap:anywhere] text-fg-2`,title:e.url,children:zu(e.url)}),x&&(0,F.jsx)(`div`,{className:`text-xs [overflow-wrap:anywhere] text-fg-2 opacity-70`,title:e.path,children:e.path}),(0,F.jsxs)(`div`,{className:P(`text-xs text-fg-2`,`flex flex-wrap gap-x-3.5 gap-y-1 [&_code]:text-[11.5px]`),children:[e.head&&(0,F.jsxs)(`span`,{title:e.committedAt,children:[(0,F.jsx)(`code`,{children:e.head}),` `,e.subject,e.committedAt?` · ${Ge(e.committedAt)}`:``]}),!!e.behind&&!!e.dirty&&(0,F.jsxs)(`span`,{children:[`behind by `,e.behind]}),e.error&&(0,F.jsx)(`span`,{className:`text-bad`,children:e.error})]}),o[e.slug]&&(0,F.jsx)(q,{tone:`bad`,children:o[e.slug]})]}),(0,F.jsxs)(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[(0,F.jsx)(V,{size:`sm`,icon:`difference`,href:`/repos/${encodeURIComponent(e.slug)}`,title:`changed files with diffs, recent commits`,children:`changes`}),(0,F.jsx)(V,{size:`sm`,icon:`sync`,busy:t===`update`,disabled:!!t,onClick:()=>void C(e.slug,`update`),title:`git fetch, then fast-forward when clean`,children:t===`update`?`updating…`:`update`}),c!==e.slug&&(0,F.jsx)(V,{size:`sm`,icon:`delete`,disabled:!!t,onClick:()=>l(e.slug),title:`Move the clone to the trash`,children:`remove`}),c===e.slug&&(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(V,{size:`sm`,variant:`danger`,icon:`delete`,onClick:()=>void C(e.slug,`remove`,qu(e)),children:e.dirty||e.ahead?`delete with local changes`:qu(e)?`delete anyway`:`confirm remove`}),(0,F.jsx)(V,{size:`sm`,variant:`quiet`,onClick:()=>l(null),children:`cancel`})]})]})]},e.slug)})]})]})}var Zu=40,Qu=/Mac|iPhone|iPad/.test(navigator.platform),$u=null,ed=e=>(e?.workspaces??[]).flatMap(e=>[...e.agents.map(t=>({kind:`agent`,agent:t,ws:e,key:`${e.url}|agent|${t.slug}`})),...(e.projects??[]).map(t=>({kind:`project`,project:t,ws:e,key:`${e.url}|project|${t.slug}`})),...(e.channels??[]).map(t=>({kind:`channel`,channel:t,ws:e,key:`${e.url}|channel|${t.slug}`}))]),td=e=>e.kind===`agent`?e.agent.name:e.kind===`project`?e.project.title:e.channel.name,nd=e=>e.kind===`agent`?e.agent.description:e.kind===`project`?e.project.goal||(e.project.status===`active`?void 0:e.project.status):e.channel.purpose,rd=e=>e.kind===`agent`?`/agents/${encodeURIComponent(e.agent.slug)}`:e.kind===`project`?`/projects/${encodeURIComponent(e.project.slug)}`:`/channels/${encodeURIComponent(e.channel.slug)}`,id={active:`📁`,paused:`⏸️`,done:`✅`,archived:`🗄️`},ad=e=>e.kind===`agent`?e.agent.emoji:e.kind===`project`?id[e.project.status]:(0,F.jsx)(I,{name:`forum`,className:`text-[18px] text-fg-2`}),od=`flex-none rounded-full border border-line px-1.5 py-px text-[10px] font-semibold tracking-[0.4px] uppercase`;function sd(e,t){let n=t.toLowerCase().split(/\s+/).filter(Boolean);if(n.length===0)return e;let r=[],i=new Map;for(let t of e){i.has(t.ws)||i.set(t.ws,i.size);let e=td(t).toLowerCase(),a=[e,...t.kind===`agent`?[t.agent.slug,t.agent.description??``,t.agent.group??``,`agent`]:t.kind===`project`?[t.project.slug,t.project.goal??``,t.project.status,`project`]:[t.channel.slug,t.channel.purpose??``,`channel`],t.ws.name].join(` `).toLowerCase();if(!n.every(e=>a.includes(e)))continue;let o=e.startsWith(n[0])?0:e.includes(n[0])?1:2;r.push({hit:t,score:o,ws:i.get(t.ws)})}return r.sort((e,t)=>e.ws-t.ws||e.score-t.score).map(e=>e.hit)}function cd(e){let t=[];for(let n of e){let e=t.find(e=>e.ws===n.ws);e?e.hits.push(n):t.push({ws:n.ws,hits:[n]})}return t}async function ld(e){let t=rd(e);if(e.ws.current)return B(t);let n=e.ws.live||!e.ws.root?fe(e.ws):await pe(e.ws.root);window.location.assign(`${n.replace(/\/+$/,``)}/#${t}`)}function ud(){let[e,t]=(0,v.useState)(!1);return(0,v.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&!e.altKey&&!e.shiftKey&&e.key.toLowerCase()===`k`&&(e.preventDefault(),t(e=>!e))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[]),(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(`button`,{type:`button`,className:`inline-flex flex-none cursor-pointer items-center gap-1.5 rounded-xl border-0 bg-transparent py-1 pr-2 pl-1.5 text-fg-2 transition-colors hover:bg-surface-2 hover:text-fg active:scale-96`,onClick:()=>t(!0),title:`jump to an agent, project or channel`,"aria-label":`search`,children:[(0,F.jsx)(I,{name:`search`}),(0,F.jsx)($e,{className:`max-[1100px]:hidden`,children:Qu?`⌘K`:`Ctrl K`})]}),e&&(0,F.jsx)(dd,{onClose:()=>t(!1)})]})}function dd({onClose:e}){let[t,n]=(0,v.useState)($u),[r,i]=(0,v.useState)($u===null),[a,o]=(0,v.useState)(!1),[s,c]=(0,v.useState)(``),[l,u]=(0,v.useState)(0),[d,f]=(0,v.useState)(null),[p,m]=(0,v.useState)(``),h=(0,v.useRef)(null);(0,v.useEffect)(()=>{let e=!0;return A.call(`search.agents`).then(t=>{$u=t,e&&n(t)}).catch(()=>e&&o(!0)).finally(()=>e&&i(!1)),()=>{e=!1}},[]);let g=(0,v.useMemo)(()=>ed(t),[t]),_=(0,v.useMemo)(()=>sd(g,s).slice(0,Zu),[g,s]),y=(0,v.useMemo)(()=>cd(_),[_]),b=Math.min(l,Math.max(_.length-1,0));(0,v.useEffect)(()=>{h.current?.querySelector(`[aria-selected="true"]`)?.scrollIntoView({block:`nearest`})},[b,_]);let x=t=>{if(!d){if(t.ws.current||t.ws.live){e(),ld(t);return}f(t.key),m(``),ld(t).catch(e=>{f(null),m(`${t.ws.name}: ${e.message}`)})}},S=t=>{if(t.key===`ArrowDown`)t.preventDefault(),u(_.length?(b+1)%_.length:0);else if(t.key===`ArrowUp`)t.preventDefault(),u(_.length?(b-1+_.length)%_.length:0);else if(t.key===`Enter`){t.preventDefault();let e=_[b];e&&x(e)}else t.key===`Escape`&&(t.preventDefault(),e())},C=`px-4 py-7 text-center text-sm text-fg-2 [&_a]:underline`,w;if(_.length>0){let e=-1;w=(0,F.jsx)(`ul`,{className:`m-0 list-none overflow-y-auto overscroll-contain p-1.5`,role:`listbox`,"aria-label":`agents, projects and channels`,ref:h,children:y.map(t=>(0,F.jsxs)(v.Fragment,{children:[(0,F.jsxs)(`li`,{className:`palette-group flex items-center gap-1.5 px-2.5 pt-3 pb-1 text-2xs font-semibold tracking-[0.4px] text-fg-2 uppercase first:pt-1.5`,role:`presentation`,title:t.ws.current?`this workspace`:t.ws.url,children:[t.ws.icon&&(0,F.jsx)(`span`,{"aria-hidden":!0,children:t.ws.icon}),(0,F.jsx)(`span`,{className:`truncate`,children:t.ws.name}),t.ws.current?(0,F.jsx)(`span`,{className:`font-normal tracking-normal normal-case`,children:`this workspace`}):t.ws.live?(0,F.jsx)(I,{name:`open_in_new`,className:`ms-sm`}):(0,F.jsx)(`span`,{className:od,children:`stopped`})]}),t.hits.map(t=>{let n=++e;return(0,F.jsxs)(`li`,{role:`option`,"aria-selected":n===b,className:P(`flex cursor-pointer items-center gap-2.5 rounded-xl px-2.5 py-2`,n===b&&`bg-surface-2`),onMouseMove:()=>n!==b&&u(n),onClick:()=>x(t),children:[(0,F.jsx)(`span`,{className:`w-6 flex-none text-center text-[18px] leading-none`,"aria-hidden":!0,children:ad(t)}),(0,F.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,F.jsx)(`span`,{className:`truncate text-[13.5px] font-medium text-fg`,children:td(t)}),nd(t)&&(0,F.jsx)(`span`,{className:`truncate text-xs text-fg-2`,children:nd(t)})]}),d===t.key?(0,F.jsx)(I,{name:`progress_activity`,className:`ms-sm`}):t.kind!==`agent`&&(0,F.jsx)(`span`,{className:P(od,`text-fg-2`),children:t.kind})]},t.key)})]},t.ws.url||t.ws.name))})}else w=a?(0,F.jsx)(`div`,{className:C,children:`could not load the agents, projects and channels`}):r?(0,F.jsx)(`div`,{className:C,children:`looking for agents, projects and channels…`}):g.length===0?(0,F.jsxs)(`div`,{className:C,children:[`no agents yet — `,(0,F.jsx)(`a`,{href:`#/agents/new`,onClick:e,children:`create one`})]}):(0,F.jsxs)(`div`,{className:C,children:[`no agent, project or channel matches “`,s,`”`]});return(0,F.jsx)(`div`,{className:`palette-backdrop fixed inset-0 z-50 flex animate-fade items-start justify-center bg-black/35 px-4 pt-[12vh] pb-4`,onMouseDown:e,children:(0,F.jsxs)(`div`,{className:`flex max-h-[min(70dvh,560px)] w-[min(620px,100%)] animate-modal flex-col overflow-hidden rounded-2xl border border-line bg-surface shadow-modal`,role:`dialog`,"aria-label":`jump to an agent, project or channel`,onMouseDown:e=>e.stopPropagation(),onKeyDown:S,children:[(0,F.jsxs)(`div`,{className:`flex items-center gap-2.5 border-b border-line px-4 py-3 text-fg-2`,children:[(0,F.jsx)(I,{name:`search`}),(0,F.jsx)(`input`,{autoFocus:!0,className:`min-w-0 flex-1 border-0 bg-transparent p-0 font-sans text-[16px] text-fg outline-none`,value:s,onChange:e=>{c(e.target.value),u(0)},placeholder:`jump to an agent, project or channel…`,"aria-label":`search`,autoComplete:`off`,spellCheck:!1}),r&&t&&(0,F.jsx)(I,{name:`progress_activity`,className:`ms-sm`}),(0,F.jsx)($e,{children:`esc`})]}),w,(0,F.jsxs)(`div`,{className:`flex items-center gap-3.5 border-t border-line px-3.5 py-2 text-2xs text-fg-2 [&>span]:inline-flex [&>span]:items-center [&>span]:gap-1`,children:[(0,F.jsxs)(`span`,{children:[(0,F.jsx)($e,{children:`↑`}),(0,F.jsx)($e,{children:`↓`}),` move`]}),(0,F.jsxs)(`span`,{children:[(0,F.jsx)($e,{children:`↵`}),` open`]}),d&&(0,F.jsxs)(`span`,{className:`ml-auto`,children:[(0,F.jsx)(I,{name:`progress_activity`,className:`ms-sm`}),` starting the workspace…`]}),p&&(0,F.jsxs)(`span`,{className:`ml-auto max-w-[60%] truncate text-bad`,title:p,children:[(0,F.jsx)(I,{name:`warning`,className:`ms-sm`}),` `,p]})]})]})})}var fd=1296e5;function pd(e){if(e<6e4)return`just now`;let t=Math.floor(e/6e4);if(t<60)return`${t}m`;let n=Math.floor(t/60);return n<24?`${n}h`:`${Math.floor(n/24)}d`}function md(e,t){let n=new Date(e),r=n.toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`}),i=Math.round((new Date(n).setHours(0,0,0,0)-new Date(t).setHours(0,0,0,0))/864e5);return i<=0?r:i===1?`tomorrow ${r}`:`${n.toLocaleDateString([],{weekday:`short`})} ${r}`}function hd(e,t=``,n=new Date){if(!e)return t?{text:t,tone:`plain`}:null;let r=e=>`${e[0].title||`a session`}${e.length>1?` +${e.length-1}`:``}`;if(e.waiting.length)return{text:`waiting for you · ${r(e.waiting)}`,tone:`waiting`};if(e.working.length){let t=e.working[0].since,i=t?pd(Math.max(0,n.getTime()-Date.parse(t))):``;return{text:`working · ${r(e.working)}${i&&i!==`just now`?` · ${i}`:``}`,tone:`working`}}if(e.nextRoutine&&Date.parse(e.nextRoutine.at)-n.getTime()<fd)return{text:`next: ${e.nextRoutine.name} · ${md(e.nextRoutine.at,n)}`,tone:`plain`};if(e.lastActiveAt){let t=pd(Math.max(0,n.getTime()-Date.parse(e.lastActiveAt)));return{text:t===`just now`?`last active just now`:`last active ${t} ago`,tone:`plain`}}return{text:t||`no sessions yet`,tone:`plain`}}var gd=e=>`section`in e;function _d(e){return[...e.top.map(e=>({slug:e})),...e.sections.flatMap(e=>[{section:e.name},...e.projects.map(e=>({slug:e}))])]}function vd(e){let t={top:[],sections:[]};for(let n of e)gd(n)?t.sections.push({name:n.section,projects:[]}):(t.sections.at(-1)?.projects??t.top).push(n.slug);return t}var yd=(e,t)=>gd(e)?`section`in t&&e.section===t.section:`slug`in t&&e.slug===t.slug;function bd(e,t,n){let r=e.findIndex(e=>yd(e,t));if(r<0)return e;let i=r+1;if(`section`in t)for(;i<e.length&&!gd(e[i]);)i++;if(n>=r&&n<=i)return e;let a=e.slice(r,i),o=[...e.slice(0,r),...e.slice(i)],s=n>r?n-a.length:n;return[...o.slice(0,s),...a,...o.slice(s)]}function xd({layout:e,visible:t,render:n,onSave:r,collapsed:i,onCollapse:a,editing:o,onEdited:s}){let[c,l]=(0,v.useState)(null),u=c??_d(e);(0,v.useEffect)(()=>l(null),[JSON.stringify(e)]);let[d,f]=(0,v.useState)(null),[p,m]=(0,v.useState)(null),[h,g]=(0,v.useState)(o);(0,v.useEffect)(()=>g(o),[o]);let _=async e=>{l(e),await r(vd(e))||l(null)},y=()=>{f(null),m(null)},b=(e,t)=>{let n=e.currentTarget.getBoundingClientRect(),r=e.clientY>n.top+n.height/2,i=u[t];if(d&&`slug`in d&&gd(i))return t+1;if(d&&`section`in d){let e=t;for(;e>=0&&!gd(u[e]);)e--;if(e<0)return u.findIndex(gd)<0?u.length:u.findIndex(gd);if(!r&&e===t)return e;let n=e+1;for(;n<u.length&&!gd(u[n]);)n++;return n}return r?t+1:t},x=e=>({onDragOver:t=>{if(!d)return;t.preventDefault(),t.stopPropagation(),t.dataTransfer.dropEffect=`move`;let n=e===void 0?u.length:b(t,e);n!==p&&m(n)},onDrop:t=>{if(!d)return;t.preventDefault(),t.stopPropagation();let n=bd(u,d,e===void 0?u.length:b(t,e));y(),n!==u&&_(n)}}),S=e=>({draggable:!0,onDragStart:t=>{t.stopPropagation(),t.dataTransfer.effectAllowed=`move`,t.dataTransfer.setData(`text/plain`,`slug`in e?e.slug:e.section),f(e)},onDragEnd:y}),C=e=>t=>{if(!t.altKey||t.key!==`ArrowUp`&&t.key!==`ArrowDown`)return;t.preventDefault();let n=u.findIndex(t=>!gd(t)&&t.slug===e),r=t.key===`ArrowUp`?n-1:n+2;r<0||r>u.length||_(bd(u,{slug:e},r))},w=e=>d&&p===e?(0,F.jsx)(`div`,{className:`relative h-0`,"aria-hidden":!0,children:(0,F.jsx)(`div`,{className:`absolute inset-x-2 -top-px h-0.5 rounded-full bg-accent`})}):null,T=[],E;return u.forEach((e,r)=>{if(T.push((0,F.jsx)(v.Fragment,{children:w(r)},`line:${r}`)),gd(e)){E=e.section;let t=e.section,n=i(t),o=0;for(let e=r+1;e<u.length&&!gd(u[e]);e++)o++;T.push((0,F.jsx)(`div`,{...x(r),...h===t?{}:S({section:t}),className:P(`group/sec mt-2 flex items-center gap-0.5 rounded-control pl-1 pr-1`,d&&`section`in d&&d.section===t&&`opacity-40`),"data-section":t,children:h===t?(0,F.jsx)(Sd,{name:t,taken:u.filter(gd).map(e=>e.section).filter(e=>e!==t),onDone:e=>{g(void 0),s(),e&&e!==t&&_(u.map(n=>gd(n)&&n.section===t?{section:e}:n))}}):(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(`button`,{type:`button`,className:`flex min-w-0 flex-1 cursor-pointer items-center gap-1 border-0 bg-transparent px-1 py-1 text-left font-[inherit] text-xs font-semibold text-fg-2 hover:text-fg`,"aria-expanded":!n,title:n?`show the projects in ${t}`:`fold ${t}`,onClick:()=>a(t),children:[(0,F.jsx)(I,{name:`chevron_right`,className:P(`ms-sm flex-none text-[15px] transition-transform`,!n&&`rotate-90`)}),(0,F.jsx)(`span`,{className:`min-w-0 truncate`,children:t}),(0,F.jsx)(`span`,{className:`font-normal tabular-nums opacity-70`,children:o})]}),(0,F.jsxs)(`span`,{className:`flex items-center opacity-0 transition-opacity group-hover/sec:opacity-100 group-focus-within/sec:opacity-100 pointer-coarse:opacity-100`,children:[(0,F.jsx)(H,{size:`sm`,icon:`edit`,label:`rename section ${t}`,onClick:()=>g(t)}),(0,F.jsx)(H,{size:`sm`,icon:`close`,label:`remove section ${t}`,title:`remove the section; its projects move up`,onClick:()=>void _(u.filter(e=>!(gd(e)&&e.section===t)))})]})]})},`section:${t}`));return}E&&i(E)&&!t(e.slug)||T.push((0,F.jsx)(`div`,{...x(r),...S({slug:e.slug}),onKeyDown:C(e.slug),className:P(`flex flex-col gap-0.5`,d&&`slug`in d&&d.slug===e.slug&&`opacity-40`),"data-sort":e.slug,children:n(e.slug)},e.slug))}),T.push((0,F.jsx)(v.Fragment,{children:w(u.length)},`line:end`)),d&&T.push((0,F.jsx)(`div`,{className:`h-4`,...x()},`drop:end`)),(0,F.jsx)(F.Fragment,{children:T})}function Sd({name:e,taken:t,onDone:n}){let[r,i]=(0,v.useState)(e),a=(0,v.useRef)(null);(0,v.useEffect)(()=>{a.current?.focus(),a.current?.select()},[]);let o=r.trim().slice(0,60),s=!!o&&!t.includes(o);return(0,F.jsx)(`input`,{ref:a,value:r,"aria-label":`section name`,maxLength:60,className:P(`min-w-0 flex-1 rounded-control border bg-surface px-2 py-1 font-[inherit] text-xs font-semibold text-fg outline-none`,s?`border-line focus:border-accent`:`border-bad`),onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Enter`&&n(s?o:void 0),e.key===`Escape`&&n()},onBlur:()=>n(s?o:void 0)})}function Cd(e){let t=new Set(e.sections.map(e=>e.name)),n=`New section`;for(let e=2;t.has(n);e++)n=`New section ${e}`;return n}function wd({chatPath:e}){let t=we(),n=be(),r=N(`agents.list`,{},{interval:15e3}),i=N(`channels.list`,{},{interval:6e3}),a=N(`projects.list`,t.projects?{}:null,{interval:15e3}),o=N(`agents.status`,{},{interval:5e3}),s=N(`vibeables.list`,t.vibeables?{}:null,{interval:15e3}),c=new Set((s?.vibeables??[]).map(e=>e.slug)),l=e.split(`/`).filter(Boolean),u=(e,t)=>l[0]===e&&(t===void 0||(l[1]?decodeURIComponent(l[1]):void 0)===t),d=l[0]===`agents`&&l[1]===`chats`,[f,p]=kd(),[m,h]=(0,v.useState)(),g=l[0]===`projects`&&l[1]&&l[1]!==`new`?decodeURIComponent(l[1]):void 0;(0,v.useEffect)(()=>{g&&h(g)},[g]);let _=Ft()??[],y=new Map((r?.agents??[]).filter(e=>!e.archived).map(e=>[e.slug,e])),b=a?.projects??[],x=e=>(e.agents??[]).map(e=>y.get(e)).filter(e=>!!e),S=e=>u(`projects`,e.slug)||e.slug===m&&x(e).some(e=>u(`agents`,e.slug)),C=new Map(b.map(e=>[e.slug,e])),w=a?.layout?[...a.layout.top,...a.layout.sections.flatMap(e=>e.projects)].map(e=>C.get(e)).filter(e=>!!e):b,T=async e=>!!(await A.request(`projects.saveLayout`,{body:e}).catch(()=>null))?.ok,[E,D]=(0,v.useState)(),O=async()=>{if(!a?.layout)return;let e=Cd(a.layout);await T({...a.layout,sections:[...a.layout.sections,{name:e,projects:[]}]})&&D(e)},k=e=>{let n=x(e),r=t.vibeables?(e.vibeables??[]).filter(e=>c.has(e)):[],i=f.open[e.slug]??e.slug===(g??m),a=n.map(e=>o?.[e.slug]).filter(e=>!!e),s=!i&&a.some(e=>e.working.length&&!e.waiting.length);return(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(Y,{size:`sm`,href:`/projects/${encodeURIComponent(e.slug)}`,active:u(`projects`,e.slug)&&!i,innerProps:{"data-project":e.slug,title:e.goal?`${e.title}: ${e.goal}`:e.title},leading:(0,F.jsx)(`span`,{"aria-hidden":!0,children:e.status===`done`?`✅`:e.status===`paused`?`⏸️`:e.status===`archived`?`🗄️`:`📁`}),title:e.title,titleExtra:(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(Qe,{n:It.project(_,e.slug,e.agents).length,title:`waiting for you`}),s&&(0,F.jsx)(U,{tone:`working`,title:`an agent is working`})]}),titleLines:2,actionsAlways:i,actions:(0,F.jsx)(H,{size:`sm`,icon:i?`expand_more`:`chevron_right`,label:`${i?`collapse`:`expand`} ${e.title}`,"aria-expanded":i,title:i?`hide its assistant, agents and apps`:[`the assistant`,n.length&&`${n.length} agent${n.length===1?``:`s`}`,r.length&&`${r.length} app${r.length===1?``:`s`}`].filter(Boolean).join(`, `),onClick:()=>p(t=>({...t,open:{...t.open,[e.slug]:!i}}))})}),i&&(0,F.jsx)(Y,{className:Td,size:`sm`,href:`/projects/${encodeURIComponent(e.slug)}`,active:u(`projects`,e.slug),innerProps:{title:`${e.title}'s assistant: knows its brief, state and links`,"data-nested":`assistant`},leading:(0,F.jsx)(`span`,{"aria-hidden":!0,children:ze.emoji}),title:(0,F.jsx)(`span`,{className:`font-medium`,children:ze.name}),titleExtra:(0,F.jsx)(Qe,{n:_.filter(t=>t.owner.project?.slug===e.slug&&!t.owner.agent).length,title:`waiting for you`})}),i&&n.map(t=>(0,F.jsx)(Y,{className:Td,size:`sm`,href:`/agents/${encodeURIComponent(t.slug)}`,active:u(`agents`,t.slug),onClick:()=>h(e.slug),innerProps:{title:t.description||t.name,"data-nested":`agent`},leading:(0,F.jsx)(`span`,{"aria-hidden":!0,children:t.emoji||`🤖`}),title:(0,F.jsx)(`span`,{className:`font-medium`,children:t.name}),titleExtra:(0,F.jsx)(Dd,{n:It.agent(_,t.slug).length,st:o?.[t.slug]})},t.slug)),i&&r.map(t=>(0,F.jsx)(Y,{className:Td,size:`sm`,href:`/projects/${encodeURIComponent(e.slug)}?app=${encodeURIComponent(t)}`,onClick:()=>h(e.slug),innerProps:{title:`open ${t} beside the project's chat`,"data-nested":`app`},leading:(0,F.jsx)(I,{name:`web`,className:`ms-sm`}),title:(0,F.jsx)(`span`,{className:`font-medium`,children:t})},`app:${t}`))]})};return(0,F.jsx)(`nav`,{className:`rail`,"aria-label":`Conversations`,children:(0,F.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-0.5 overflow-y-auto px-2 pt-2 pb-4`,children:[(0,F.jsx)(Y,{href:`/`,active:e===`/`,leading:(0,F.jsx)(I,{name:`home`}),title:`Home`,innerProps:{title:`Today: what needs you, what happened`}}),(0,F.jsx)(Y,{href:`/agents/chats`,active:d,leading:(0,F.jsx)(`span`,{"aria-hidden":!0,children:`🎩`}),title:`Ralv`,titleExtra:(0,F.jsx)(Qe,{n:It.general(_).length,title:`waiting for you`}),innerProps:{title:`Chief of staff: knows the workspace, advises, launches things`}}),t.projects&&(0,F.jsxs)(Ed,{label:`projects`,href:`/projects`,add:a?.enabled?{href:`/projects/new`,label:`new project`}:void 0,badge:f.all?(0,F.jsx)(Qe,{n:new Set(b.filter(e=>!S(e)).flatMap(e=>It.project(_,e.slug,e.agents).map(e=>e.id))).size,title:`waiting in the projects folded away`}):void 0,fold:b.length>0?(0,F.jsxs)(F.Fragment,{children:[!f.all&&a?.layout&&(0,F.jsx)(H,{size:`sm`,icon:`create_new_folder`,label:`new section`,title:`new section: drag projects into it`,onClick:()=>void O()}),(0,F.jsx)(H,{size:`sm`,icon:f.all?`chevron_right`:`expand_more`,label:f.all?`show all projects`:`collapse projects`,"aria-expanded":!f.all,onClick:()=>p(e=>({...e,all:!e.all}))})]}):void 0,children:[f.all||!a?.layout?w.filter(e=>!f.all||S(e)).map(e=>(0,F.jsx)(v.Fragment,{children:k(e)},e.slug)):(0,F.jsx)(xd,{layout:a.layout,visible:e=>!!C.get(e)&&S(C.get(e)),render:e=>C.get(e)?k(C.get(e)):null,onSave:T,collapsed:e=>!!f.sections[e],onCollapse:e=>p(t=>({...t,sections:{...t.sections,[e]:!t.sections[e]}})),editing:E,onEdited:()=>D(void 0)}),f.all&&b.length>0&&(0,F.jsxs)(V,{variant:`quiet`,size:`sm`,icon:`expand_more`,className:`justify-start`,onClick:()=>p(e=>({...e,all:!1})),children:[b.filter(e=>!S(e)).length,` more`]})]}),(0,F.jsx)(Ed,{label:`agents`,href:`/agents`,add:n?{href:`/agents/new`,label:`new agent`}:void 0,children:(r?.agents??[]).filter(e=>!e.archived).map(e=>{let t=hd(o?.[e.slug],e.description);return(0,F.jsx)(Y,{href:`/agents/${encodeURIComponent(e.slug)}`,active:u(`agents`,e.slug)||u(`team`,e.slug),innerProps:{title:e.description||void 0},leading:(0,F.jsx)(`span`,{"aria-hidden":!0,children:e.emoji||`🤖`}),title:e.name,titleExtra:(0,F.jsx)(Dd,{n:It.agent(_,e.slug).length,st:o?.[e.slug]}),sub:t?(0,F.jsx)(`span`,{className:`rail-status${t.tone===`plain`?``:` ${t.tone}`}`,children:t.text}):void 0,subTone:t?.tone===`waiting`?`bad`:t?.tone===`working`?`accent`:`plain`},e.slug)})}),(0,F.jsx)(Ed,{label:`channels`,href:`/channels`,add:{href:`/channels/new`,label:`new channel`},children:(i?.channels??[]).map(e=>(0,F.jsx)(Y,{href:`/channels/${encodeURIComponent(e.slug)}`,active:u(`channels`,e.slug),leading:(0,F.jsx)(`span`,{"aria-hidden":!0,className:`font-semibold`,children:`#`}),title:e.name,titleExtra:(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(Qe,{n:It.channel(_,e.slug).length,title:`waiting for you`}),e.busy&&!e.awaitingApproval&&(0,F.jsx)(U,{tone:`working`,title:`an agent is working`})]}),sub:e.purpose||(e.members.length?`with ${e.members.map(e=>`@${e}`).join(` `)}`:`no agents yet`)},e.slug))})]})})}var Td=`ml-5 rounded-l-none border-l border-line`;function Ed({label:e,href:t,add:n,badge:r,fold:i,children:a}){return(0,F.jsxs)(`div`,{className:`mt-3 flex flex-col gap-0.5`,role:`group`,"aria-label":e[0].toUpperCase()+e.slice(1),children:[(0,F.jsxs)(`div`,{className:`group/head flex items-center gap-1 pl-2.5 pr-1`,children:[(0,F.jsx)(he,{href:t,className:`flex-1 px-0 py-1 text-2xs font-semibold uppercase tracking-[0.08em] text-fg-2 no-underline hover:text-fg`,children:e}),r,(0,F.jsxs)(`span`,{className:`flex items-center gap-1 opacity-0 transition-opacity group-hover/head:opacity-100 group-focus-within/head:opacity-100 pointer-coarse:opacity-100`,children:[n&&(0,F.jsx)(H,{size:`sm`,icon:`add`,label:n.label,href:n.href}),i]})]}),a]})}function Dd({n:e,st:t}){return(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(Qe,{n:e,title:`waiting for you`}),!e&&t?.working.length&&!t.waiting.length?(0,F.jsx)(U,{tone:`working`,title:`working`}):null]})}var Od=`kw-rail-fold`;function kd(){let[e,t]=(0,v.useState)(()=>{try{let e=JSON.parse(localStorage.getItem(Od)??`null`),t=e=>e&&typeof e==`object`?e:{};return{all:!!e?.all,open:t(e?.open),sections:t(e?.sections)}}catch{return{all:!1,open:{},sections:{}}}});return[e,e=>t(t=>{let n=e(t);try{localStorage.setItem(Od,JSON.stringify(n))}catch{}return n})]}function Ad({path:e}){let t=be(),n=we(),r=e.split(`/`).filter(Boolean)[0]??``;if(!t)return null;let i=[{id:`workflows`,href:`/workflows`,label:`workflows`,icon:`account_tree`},{id:`knowledge`,href:`/knowledge`,label:`knowledge`,icon:`menu_book`},{id:`files`,href:`/files`,label:`files`,icon:`folder_open`},...n.vibeables?[{id:`vibeables`,href:`/vibeables`,label:`apps`,icon:`web`}]:[],{id:`skills`,href:`/skills`,label:`skills`,icon:`extension`},...n.repos?[{id:`repos`,href:`/repos`,label:`repositories`,icon:`source`}]:[],...n.git?[{id:`git`,href:`/git`,label:`git`,icon:`cloud_sync`,badge:(0,F.jsx)(jd,{})}]:[],{id:`workspaces`,href:`/workspaces`,label:`workspaces`,icon:`grid_view`},{id:`trash`,href:`/trash`,label:`trash`,icon:`delete`}],a=e=>r===e||e===`workflows`&&r===`runs`;return(0,F.jsx)(`nav`,{className:`global-nav flex min-w-0 flex-[0_1_auto] justify-start gap-0.5 overflow-x-auto [scrollbar-width:none] max-[1199px]:[mask-image:linear-gradient(to_right,#000_calc(100%-24px),transparent)] max-[800px]:hidden`,"aria-label":`Workspace`,children:i.map(e=>{let t=a(e.id);return(0,F.jsxs)(`a`,{href:`#${e.href}`,className:P(`inline-flex flex-none items-center gap-1.5 rounded-full px-3 py-1.5 text-[13.5px] font-semibold no-underline transition-colors`,`[&_.ms]:text-[18px] max-[1520px]:gap-[5px] max-[1520px]:[&_.ms]:text-[17px]`,t?`bg-surface text-accent shadow-[inset_0_0_0_1px_var(--line)]`:`text-fg-2 hover:bg-surface-2 hover:text-fg`),"aria-current":t?`page`:void 0,children:[(0,F.jsx)(I,{name:e.icon,fill:t}),` `,e.label,e.badge]},e.id)})})}function jd(){let e=N(`git.status`,{},{interval:15e3}),t=e?.files?.filter(e=>e.syncable).length??0,n=`ml-[5px] rounded-full bg-surface-2 px-1.5 py-px text-[10.5px] font-semibold tabular-nums`;return(0,F.jsxs)(F.Fragment,{children:[!!e?.behind&&(0,F.jsxs)(`span`,{className:P(n,`text-accent`),children:[e.behind,`↓`]}),!!e?.ahead&&(0,F.jsxs)(`span`,{className:P(n,`text-ok`),children:[e.ahead,`↑`]}),!e?.ahead&&!e?.behind&&!!t&&(0,F.jsx)(`span`,{className:n,children:t})]})}var Md=e=>e.replace(/^# .*\n+/,``).replace(/\(human:user\)/g,`(you)`),Nd=`flex flex-col gap-1.5 px-1.5 pb-6 pt-3`,Pd=`m-0 px-2.5 pb-0.5 text-md leading-[1.45] text-fg`,Fd=`m-0 px-2.5 py-0.5 text-sm text-fg-2`,Id=`md-body px-2.5 text-sm leading-normal`,Ld=e=>da.sanitize(Fr.parse(Md(e),{async:!1}));function Rd(e,t){let n=[],r=``;for(let i of e.split(`
229
+ `)){let e=/^## (.+)$/.exec(i.trim());if(e?r=e[1]:/^[-*] /.test(i)&&n.push({day:r,text:i.replace(/^[-*] /,``)}),n.length>=t)break}return n}function zd({items:e}){return e.length===0?null:(0,F.jsx)(tt,{size:`lg`,title:`needs you`,count:e.length,children:e.map(e=>(0,F.jsx)(Y,{onClick:()=>Vt(e),leading:(0,F.jsx)(I,{name:e.kind===`approval`?`front_hand`:e.kind===`question`?`help`:`error`,className:`ms-sm text-bad`}),title:e.title,sub:`${e.owner.agent?`${e.owner.agent.emoji??``} ${e.owner.agent.name} · `:``}${e.kind===`approval`?`needs approval`:e.kind===`question`?`asks you`:`failed`} · ${Ge(e.since)}`},e.id))})}function Bd({slugs:e,agents:t,status:n,title:r=`team`}){let i=e.map(e=>t.find(t=>t.slug===e)).filter(e=>!!e);return i.length===0?null:(0,F.jsx)(tt,{size:`lg`,title:r,children:i.map(e=>{let t=hd(n?.[e.slug],e.description);return(0,F.jsx)(Y,{href:`/agents/${encodeURIComponent(e.slug)}`,leading:(0,F.jsx)(`span`,{"aria-hidden":!0,children:e.emoji||`🤖`}),title:e.name,sub:t?.text,subTone:t?.tone===`waiting`?`bad`:t?.tone===`working`?`accent`:`plain`},e.slug)})})}function Vd({scope:e}){let t=N(`files.recent`,{query:{scope:e}},{interval:2e4});return!t||t.count===0?null:(0,F.jsx)(tt,{size:`lg`,title:`files`,count:t.count,action:(0,F.jsxs)(V,{variant:`quiet`,size:`sm`,href:uu(e),children:[`all `,(0,F.jsx)(I,{name:`arrow_forward`,className:`ms-sm`})]}),children:t.recent.map(t=>{let n=t.path.includes(`/`)?t.path.slice(0,t.path.lastIndexOf(`/`)):``;return(0,F.jsx)(Y,{href:uu(e,n,t.path),leading:(0,F.jsx)(I,{name:`draft`,className:`ms-sm`}),title:t.path.split(`/`).pop(),sub:`${n?`${n}/ · `:``}${Ge(t.at)}`},t.path)})})}function Hd({of:e}){let t=Ft()??[],n=N(`agents.list`,{},{interval:15e3})?.agents??[],r=N(`agents.status`,{},{interval:5e3})??void 0;if(e.kind===`project`){let i=e.project,a=i.links.agents.map(e=>e.slug),o=Rd(i.log,5);return(0,F.jsxs)(`div`,{className:Nd,children:[(0,F.jsx)(tt,{size:`lg`,title:`goal`,children:(0,F.jsxs)(`p`,{className:Pd,children:[i.goal||(0,F.jsx)(`span`,{className:`text-fg-2`,children:`No goal written yet.`}),i.status!==`active`&&(0,F.jsxs)(`span`,{className:`text-fg-2`,children:[` · `,i.status]})]})}),o.length>0&&(0,F.jsx)(tt,{size:`lg`,title:`lately`,children:o.map((e,t)=>(0,F.jsxs)(`div`,{className:`grid grid-cols-[74px_minmax(0,1fr)] gap-2 px-2.5 py-1 text-sm`,children:[(0,F.jsx)(`span`,{className:`pt-px text-xs tabular-nums text-fg-2`,children:e.day}),(0,F.jsx)(`span`,{dangerouslySetInnerHTML:{__html:da.sanitize(Fr.parseInline(Md(e.text),{async:!1}))}})]},t))}),(0,F.jsx)(zd,{items:It.project(t,i.slug,a)}),(0,F.jsx)(Bd,{slugs:a,agents:n,status:r}),(0,F.jsx)(tt,{size:`lg`,title:`where it stands`,children:i.state.trim()?(0,F.jsx)(`div`,{className:Id,dangerouslySetInnerHTML:{__html:Ld(i.state)}}):(0,F.jsx)(`p`,{className:Fd,children:`Nothing recorded yet: the project's chat writes this down at the end of a session that changed something.`})}),(0,F.jsx)(Vd,{scope:`project:${i.slug}`}),i.records.length>0&&(0,F.jsx)(tt,{size:`lg`,title:`systems of record`,children:i.records.map((e,t)=>(0,F.jsx)(Y,{onClick:()=>e.url&&window.open(e.url,`_blank`,`noopener`),leading:(0,F.jsx)(I,{name:`open_in_new`,className:`ms-sm`}),title:e.title||e.kind,sub:e.note},t))})]})}if(e.kind===`agent`)return(0,F.jsx)(Ud,{agent:e.agent,journal:e.journal,waiting:t,status:r});if(e.kind===`channel`){let i=e.channel;return(0,F.jsxs)(`div`,{className:Nd,children:[(0,F.jsx)(`p`,{className:Pd,children:i.purpose||(0,F.jsxs)(`span`,{className:`text-fg-2`,children:[`A group chat with `,i.members.length,` agent`,i.members.length===1?``:`s`,`.`]})}),(0,F.jsx)(zd,{items:It.channel(t,i.slug)}),(0,F.jsx)(Bd,{slugs:i.members,agents:n,status:r,title:`in this channel`})]})}return(0,F.jsx)(Wd,{waiting:t,agents:n,status:r})}function Ud({agent:e,journal:t,waiting:n,status:r}){let i=N(`projects.list`,{},{interval:3e4})?.projects??[],a=N(`agents.routines`,{slug:e.slug},{interval:3e4})?.routines??[],[o,s]=(0,v.useState)(t);(0,v.useEffect)(()=>s(t),[t]);let c=hd(r?.[e.slug],e.description),l=i.filter(t=>t.agents.includes(e.slug));return(0,F.jsxs)(`div`,{className:Nd,children:[(0,F.jsx)(`p`,{className:Pd,children:e.description||(0,F.jsx)(`span`,{className:`text-fg-2`,children:`No description yet.`})}),c&&c.text!==e.description&&(0,F.jsx)(`p`,{className:`m-0 px-2.5 text-sm ${c.tone===`waiting`?`text-bad`:c.tone===`working`?`text-accent`:`text-fg-2`}`,children:c.text}),(0,F.jsx)(zd,{items:It.agent(n,e.slug)}),l.length>0&&(0,F.jsx)(tt,{size:`lg`,title:`works on`,children:l.map(e=>(0,F.jsx)(Y,{href:`/projects/${encodeURIComponent(e.slug)}`,leading:(0,F.jsx)(`span`,{"aria-hidden":!0,children:`📁`}),title:e.title,sub:e.goal||void 0},e.slug))}),a.length>0&&(0,F.jsx)(tt,{size:`lg`,title:`schedule`,children:a.map(e=>(0,F.jsx)(Y,{leading:(0,F.jsx)(I,{name:`schedule`,className:`ms-sm`}),title:e.name,sub:`${e.enabled?e.nextRunAt?`next ${new Date(e.nextRunAt).toLocaleString([],{weekday:`short`,hour:`2-digit`,minute:`2-digit`})}`:e.schedule:`paused`}${e.lastRunAt?` · last ${Ge(e.lastRunAt)}`:``}`},e.id))}),(0,F.jsxs)(tt,{size:`lg`,title:`journal`,children:[(0,F.jsx)(Gd,{slug:e.slug,onAdded:s}),(0,F.jsx)(`div`,{className:Id,dangerouslySetInnerHTML:{__html:Ld(Md(o)||`_Nothing yet: the agent notes what it learns, decides and promises here, and reads it back at the start of every session._`)}})]})]})}function Wd({waiting:e,agents:t,status:n}){let r=N(`projects.list`,{},{interval:3e4}),i=(r?.projects??[]).filter(e=>e.status===`active`);return(0,F.jsxs)(`div`,{className:Nd,children:[(0,F.jsx)(zd,{items:e}),r?.enabled&&(0,F.jsxs)(tt,{size:`lg`,title:`projects`,count:i.length,children:[i.length===0&&(0,F.jsx)(`p`,{className:Fd,children:`No active projects.`}),i.map(t=>{let n=It.project(e,t.slug,t.agents).length;return(0,F.jsx)(Y,{href:`/projects/${encodeURIComponent(t.slug)}`,leading:(0,F.jsx)(`span`,{"aria-hidden":!0,children:`📁`}),title:t.title,sub:n?`${n} waiting for you`:t.goal||`no goal yet`,subTone:n?`bad`:`plain`},t.slug)})]}),(0,F.jsx)(Bd,{slugs:t.filter(e=>!e.archived).map(e=>e.slug),agents:t,status:n,title:`agents`}),(0,F.jsx)(Vd,{scope:`workspace`})]})}function Gd({slug:e,onAdded:t}){let[n,r]=(0,v.useState)(``),[i,a]=(0,v.useState)(!1),[o,s]=(0,v.useState)(``),c=async()=>{if(!n.trim())return;a(!0),s(``);let i=await A.request(`agents.addJournal`,{slug:e,body:{entry:n,kind:`note`}}).then(e=>e.ok?{error:void 0,journal:e.data?.journal}:{error:M(e),journal:void 0}).catch(e=>({error:e.message,journal:void 0}));if(a(!1),i.error||i.journal===void 0)return s(i.error??`could not save`);r(``),t(i.journal)};return(0,F.jsxs)(`div`,{className:`px-2.5 pb-1.5 pt-0.5`,children:[(0,F.jsx)(X,{className:`h-8 text-sm`,value:n,placeholder:`add a note for the agent to remember`,onChange:e=>r(e.target.value),onKeyDown:e=>e.key===`Enter`&&void c(),disabled:i}),o&&(0,F.jsx)(q,{tone:`bad`,children:o})]})}function Kd(e){let t=e.split(`/`).filter(Boolean),n=t[1]?decodeURIComponent(t[1]):``;return t[0]===`projects`&&n&&n!==`new`?{kind:`project`,slug:n}:t[0]===`channels`&&n&&n!==`new`?{kind:`channel`,slug:n}:(t[0]===`agents`||t[0]===`team`)&&n&&n!==`new`&&n!==`chats`?{kind:`agent`,slug:n}:{kind:`general`}}function qd(e){let t=new Date(e),n=t.toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`}),r=e=>new Date(e.getFullYear(),e.getMonth(),e.getDate()).getTime(),i=Math.round((r(t)-r(new Date))/864e5);return i===0?`today ${n}`:i===1?`tomorrow ${n}`:i>1&&i<7?`${t.toLocaleDateString([],{weekday:`short`})} ${n}`:`${t.toLocaleDateString([],{day:`numeric`,month:`short`})} ${n}`}var Jd=(e,t)=>e.map(e=>({slug:e,found:t.has(e)}));function Yd({chatPath:e,workspace:t}){let n=Kd(e),r=`${n.kind}:${`slug`in n?n.slug:``}`,i=we(),a=be(),[o,s]=n.kind===`project`?[`/projects/${encodeURIComponent(n.slug)}/info`,`edit the project: brief, state, records, links`]:n.kind===`agent`?[`/agents/${encodeURIComponent(n.slug)}/info`,`edit the agent: profile and settings`]:n.kind===`channel`?[`/channels/${encodeURIComponent(n.slug)}/edit`,`edit the channel`]:a?[`/settings`,`workspace settings`]:[void 0,``],c=N(`workflows.list`,{},{interval:15e3}),l=N(`runs.list`,{},{interval:6e3}),u=N(`routines.list`,{},{interval:3e4}),[d,f]=(0,v.useState)(null),p=N(`knowledge.list`,{},{interval:15e3}),m=N(`vibeables.list`,i.vibeables?{}:null,{interval:15e3}),[h,g]=(0,v.useState)(null),[_,y]=(0,v.useState)(0),[b,x]=(0,v.useState)(()=>{try{return localStorage.getItem(`kw-ctx-tab`)||`overview`}catch{return`overview`}}),[S,C]=(0,v.useState)(0);(0,v.useEffect)(()=>{let e=()=>w(`browser`);return window.addEventListener(ro,e),()=>window.removeEventListener(ro,e)},[]);let w=e=>{x(e);try{localStorage.setItem(`kw-ctx-tab`,e)}catch{}},[T,E]=(0,v.useState)({});(0,v.useEffect)(()=>E(oe.current?{vibeables:`/vibeables/${encodeURIComponent(oe.current.slug)}`}:{}),[r]);let[D,O]=(0,v.useState)(!1);(0,v.useEffect)(()=>O(!1),[r]);let k=L(),j=n.kind===`project`?new URLSearchParams(k.split(`?`)[1]??``).get(`app`):null;(0,v.useEffect)(()=>{j&&(w(`vibeables`),E(e=>({...e,vibeables:`/vibeables/${encodeURIComponent(j)}`})),O(!0))},[j,r]);let ee=e=>E(t=>({...t,[ue]:e})),[M,P]=(0,v.useState)({dir:``});(0,v.useEffect)(()=>P({dir:``}),[r]);let te=async(e,t,n)=>{(await A.request(`projects.link`,{slug:e,body:{kind:`vibeables`,target:t,remove:n}}).catch(()=>null))?.ok&&y(e=>e+1)},ne=()=>{O(!1),E(e=>({...e,[ue]:null}))},re=e=>t=>t.startsWith(e)?(E(e=>({...e,[ue]:t})),!0):!1,[ie,ae]=(0,v.useState)(null),oe=(0,v.useRef)(null);(0,v.useEffect)(()=>{let e=e=>{let t=e.detail;oe.current=t,ae(t),t?(w(`vibeables`),E(e=>({...e,vibeables:`/vibeables/${encodeURIComponent(t.slug)}`}))):E(e=>e.vibeables?.startsWith(`/vibeables/`)?{...e,vibeables:null}:e)};return window.addEventListener(pa,e),()=>window.removeEventListener(pa,e)},[]);let se=i.repos&&!!h?.repos,ce=n.kind===`project`?`project:${n.slug}`:h?.channel?.project?`project:${h.channel.project}`:`workspace`,le=[{id:`overview`,label:`overview`},{id:`files`,label:`files`,allHref:`/files/${encodeURIComponent(ce)}`},{id:`knowledge`,label:`knowledge`,count:h?.knowledge.length,allHref:`/knowledge`},...i.vibeables?[{id:`vibeables`,label:`apps`,count:h?.all?m?.vibeables.length:h?.vibeables?.length??0,allHref:`/vibeables`}]:[],{id:`workflows`,label:`workflows`,count:h?.workflows.length,allHref:`/workflows`},...a&&se?[{id:`repos`,label:`repositories`,count:h?.repos?.length,allHref:`/repos`}]:[],...S>0||b===`browser`?[{id:`browser`,label:`browser`,count:S}]:[]],ue=le.some(e=>e.id===b)?b:`overview`,de=le.find(e=>e.id===ue),R=T[ue]??null,B=!!ie&&ue===`vibeables`&&R===`/vibeables/${encodeURIComponent(ie.slug)}`,fe=ue===`vibeables`&&!!R,pe=D&&fe,ge=e=>t=>{t.metaKey||t.ctrlKey||t.shiftKey||t.button!==0||(t.preventDefault(),ee(e))};(0,v.useEffect)(()=>{let e=setInterval(()=>y(e=>e+1),15e3);return()=>clearInterval(e)},[]);let _e=z(k),ve=(0,v.useRef)(_e);(0,v.useEffect)(()=>{ve.current&&!_e&&y(e=>e+1),ve.current=_e},[_e]),(0,v.useEffect)(()=>{let e=!0,r=new Set((c?.workflows??[]).map(e=>e.slug)),i=new Set((p?.bundles??[]).map(e=>e.name)),a=new Set((m?.vibeables??[]).map(e=>e.slug));return(async()=>{let o=null;if(n.kind===`agent`){let e=await A.call(`agents.get`,{slug:n.slug}).catch(()=>null);e&&(o={title:`${e.emoji?`${e.emoji} `:``}${e.name}`,agent:e,workflows:Jd(e.workflows,r),knowledge:Jd(e.knowledge,i),editHref:`/agents/${encodeURIComponent(n.slug)}/edit`},(e.vibeables??[]).length>0&&(o.vibeables=Jd(e.vibeables,a)),o.journal=(await A.call(`agents.journal`,{slug:n.slug}).catch(()=>null))?.journal??``)}else if(n.kind===`project`){let e=await A.call(`projects.get`,{slug:n.slug}).catch(()=>null);e&&(o={title:`📁 ${e.title}`,project:e,workflows:e.links.workflows,knowledge:e.links.knowledge,vibeables:e.links.vibeables,repos:e.links.repos,agents:e.links.agents,records:e.records,state:e.state,log:e.log,editHref:`/projects/${encodeURIComponent(n.slug)}/info`})}else if(n.kind===`channel`){let e=(await A.call(`channels.list`).catch(()=>null))?.channels.find(e=>e.slug===n.slug);if(e){let t=(await Promise.all(e.members.map(e=>A.call(`agents.get`,{slug:e}).catch(()=>null)))).filter(e=>!!e),s=e=>[...new Set(t.flatMap(e))],c=s(e=>e.vibeables??[]);o={title:`#${e.slug}`,channel:e,workflows:Jd(s(e=>e.workflows),r),knowledge:Jd(s(e=>e.knowledge),i),...c.length>0?{vibeables:Jd(c,a)}:{},agents:e.members.map(e=>({slug:e,found:t.some(t=>t.slug===e),label:t.find(t=>t.slug===e)?.name})),editHref:`/channels/${encodeURIComponent(n.slug)}/edit`}}}else o={title:`${t.icon?`${t.icon} `:``}${t.name||`workspace`}`,workflows:Jd([...r],r),knowledge:Jd([...i],i),all:!0};e&&g(o)})(),()=>{e=!1}},[r,_,c,p,m,t.name,t.icon]);let ye=e=>c?.workflows.find(t=>t.slug===e),xe=e=>e?l?.runs.find(t=>t.workflow===(e.name??e.slug)||t.workflow===e.slug):void 0,Se=e=>p?.bundles.find(t=>t.name===e),Ce=e=>m?.vibeables.find(t=>t.slug===e),Te=e=>(0,F.jsxs)(`p`,{className:`m-0 px-2.5 py-3 text-sm text-fg-2`,children:[h?.all?`No ${e} in this workspace yet.`:`No ${e} linked.`,h?.editHref&&a&&!h.all&&(0,F.jsxs)(F.Fragment,{children:[` `,(0,F.jsx)(he,{href:h.editHref,className:`text-accent`,children:`Edit the links`}),`.`]})]});return(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(`div`,{className:`space-title flex min-w-0 items-center gap-2 px-1`,children:[(0,F.jsx)(`span`,{className:`min-w-0 truncate text-[22px] leading-[1.15] font-[750] tracking-[-0.015em] text-fg animate-fade max-[800px]:text-lg`,title:h?.title,children:h?h.title:`…`},h?.title??``),o&&(0,F.jsx)(he,{href:o,className:`ctx-edit inline-grid size-7 flex-none place-items-center rounded-full text-fg-2 no-underline transition-colors hover:bg-surface-2 hover:text-accent active:scale-96 [&_.ms]:text-[18px]`,title:s,"aria-label":s,children:(0,F.jsx)(I,{name:`edit`,className:`ms-sm`})})]}),(0,F.jsxs)(`aside`,{className:`ctx`,"aria-label":`Context`,"data-full":pe||void 0,children:[(0,F.jsx)(ft,{className:`flex-none gap-y-0.5 pt-2`,label:`Categories`,items:le,value:ue,onChange:w}),R&&(0,F.jsxs)(`div`,{className:`flex items-center gap-2 px-3 pb-1 pt-2`,children:[(0,F.jsx)(V,{variant:`quiet`,size:`sm`,icon:`arrow_back`,onClick:ne,"aria-label":`Back to the list`,children:de?.label}),(0,F.jsx)(`span`,{className:`flex-1`}),fe&&(0,F.jsx)(V,{variant:`quiet`,size:`sm`,icon:pe?`close_fullscreen`:`open_in_full`,onClick:()=>O(!pe),title:pe?`back beside the chat`:`full size, in place of the chat`,children:pe?`beside the chat`:`full size`}),(0,F.jsx)(V,{variant:`quiet`,size:`sm`,icon:`open_in_new`,href:R,title:`Open as a page`,children:`page`})]}),R&&ue===`knowledge`&&(0,F.jsx)(`div`,{className:`ctx-body ctx-embed`,children:(0,F.jsx)(me.Provider,{value:re(`/knowledge/`),children:(()=>{let e=R.split(`/`).filter(Boolean),t=decodeURIComponent(e[1]??``),n=e.length>2?e.slice(2).map(decodeURIComponent).join(`/`):void 0;return(0,F.jsx)(gl,{name:t,conceptId:n},t)})()})}),R&&ue===`workflows`&&(0,F.jsx)(`div`,{className:`ctx-body ctx-embed`,children:(0,F.jsx)(me.Provider,{value:re(`/workflows/`),children:(()=>{let e=R.split(`/`).filter(Boolean),t=e[2]===`details`||e[2]===`runs`?e[2]:`overview`;return(0,F.jsx)(jc,{slug:decodeURIComponent(e[1]??``),tab:t},e[1])})()})}),R&&ue===`vibeables`&&!B&&(0,F.jsx)(`div`,{className:`ctx-body ctx-embed ctx-embed-vibe`,children:(0,F.jsx)(_a,{slug:decodeURIComponent(R.split(`/`).filter(Boolean)[1]??``)},R)}),(0,F.jsx)(`div`,{id:ma,className:`ctx-body ctx-embed ctx-embed-vibe`,hidden:!B}),(0,F.jsx)(`div`,{className:`ctx-body ctx-embed ctx-browser`,hidden:ue!==`browser`,children:(0,F.jsx)(uo,{storeKey:r,onTabs:C},r)}),(0,F.jsxs)(`div`,{className:`ctx-body`,role:`tabpanel`,hidden:ue===`browser`||!!R&&[`knowledge`,`workflows`,`vibeables`].includes(ue),children:[de?.allHref&&(0,F.jsx)(`div`,{className:`flex justify-end px-1 pb-1`,children:(0,F.jsxs)(V,{variant:`quiet`,size:`sm`,href:de.allHref,children:[`all `,de.label,` `,(0,F.jsx)(I,{name:`arrow_forward`,className:`ms-sm`})]})}),ue===`workflows`&&(0,F.jsxs)(F.Fragment,{children:[h&&h.workflows.length===0&&Te(`workflows`),h?.workflows.map(({slug:e,found:t})=>{let n=ye(e),r=xe(n),i=t&&!!n&&!n.error,a=(u?.routines??[]).filter(t=>t.workflows.includes(e));return(0,F.jsxs)(`div`,{className:`flex flex-col`,children:[(0,F.jsx)(Y,{href:`/workflows/${encodeURIComponent(e)}`,onClick:t?ge(`/workflows/${encodeURIComponent(e)}`):void 0,dim:!t,leading:(0,F.jsx)(U,{tone:!t||n?.error?`bad`:Zd(r?.status)}),title:n?.name??e,sub:t?n?.error?`broken`:r?`${r.status} · ${Ge(r.updatedAt)}`:n?.description??`no runs yet`:`not in this workspace`,actionsAlways:!0,actions:i?(0,F.jsx)(H,{size:`sm`,icon:d===e?`close`:`play_arrow`,label:d===e?`close the launcher of ${n.name??e}`:`run ${n.name??e}`,"aria-expanded":d===e,onClick:()=>f(d===e?null:e)}):void 0}),a.map(e=>(0,F.jsxs)(he,{href:`/agents/${encodeURIComponent(e.agent.slug)}/info`,className:`routine-line flex min-w-0 items-center gap-1.5 pt-0.5 pb-2 pl-[46px] pr-3 text-xs text-fg-2 no-underline hover:text-fg`,title:`${e.agent.name}'s routine "${e.name}" (${e.schedule}) runs this workflow: ${e.prompt}`,children:[(0,F.jsx)(I,{name:`schedule`,className:`ms-sm flex-none text-[14px]`}),(0,F.jsxs)(`span`,{className:`min-w-0 truncate`,children:[e.agent.emoji,` `,e.agent.name,` · `,e.name,` · `,e.enabled?e.nextRunAt?`next ${qd(e.nextRunAt)}`:e.schedule:`paused`]})]},`${e.agent.slug}/${e.id}`)),d===e&&n&&(0,F.jsx)(`div`,{className:`mx-1 mb-2 rounded-card border border-line bg-surface [&>div]:px-3 [&>div]:pt-3`,children:(0,F.jsx)(bc,{slug:e,usesRequest:n.usesRequest,onLaunched:()=>{f(null),ee(`/workflows/${encodeURIComponent(e)}`)}})})]},e)})]}),ue===`knowledge`&&(0,F.jsxs)(F.Fragment,{children:[h&&h.knowledge.length===0&&Te(`knowledge`),h?.knowledge.map(({slug:e,found:t})=>{let n=Se(e);return(0,F.jsx)(Y,{href:`/knowledge/${encodeURIComponent(e)}`,onClick:t?ge(`/knowledge/${encodeURIComponent(e)}`):void 0,dim:!t,leading:(0,F.jsx)(I,{name:`menu_book`,className:`ms-sm`}),title:e,sub:t?n?`${n.concepts} ${n.concepts===1?`page`:`pages`}${n.updatedAt?` · ${Ge(n.updatedAt)}`:``}`:void 0:`not in this workspace`},e)})]}),ue===`vibeables`&&h&&(0,F.jsxs)(F.Fragment,{children:[(h.all?(m?.vibeables??[]).map(e=>({slug:e.slug,found:!0})):h.vibeables??[]).map(({slug:e,found:t})=>{let r=Ce(e);return(0,F.jsx)(Y,{href:`/vibeables/${encodeURIComponent(e)}`,onClick:t?ge(`/vibeables/${encodeURIComponent(e)}`):void 0,dim:!t,leading:(0,F.jsx)(I,{name:`web`,className:`ms-sm`}),title:e,sub:t?r?.updatedAt?`changed ${Ge(r.updatedAt)}`:void 0:`not in this workspace`,actions:n.kind===`project`?(0,F.jsx)(H,{icon:`keep_off`,size:`sm`,label:`unpin ${e}`,onClick:()=>void te(n.slug,e,!0)}):void 0},e)}),n.kind===`project`&&m&&(0,F.jsx)(Xd,{options:m.vibeables.map(e=>e.slug).filter(e=>!h.vibeables?.some(t=>t.slug===e)),onPin:e=>void te(n.slug,e,!1)}),h.all&&m&&m.vibeables.length===0&&Te(`vibeables`),!h.all&&h.vibeables?.length===0&&Te(`vibeables`)]}),ue===`repos`&&h?.repos&&(0,F.jsxs)(F.Fragment,{children:[h.repos.length===0&&Te(`repositories`),h.repos.map(({slug:e,found:t})=>(0,F.jsx)(Y,{href:`/repos/${encodeURIComponent(e)}`,dim:!t,leading:(0,F.jsx)(I,{name:`source`,className:`ms-sm`}),title:e,sub:t?void 0:`not in this workspace`},e))]}),ue===`overview`&&h&&(0,F.jsx)(Hd,{of:h.project?{kind:`project`,project:h.project}:h.agent?{kind:`agent`,agent:h.agent,journal:h.journal??``}:h.channel?{kind:`channel`,channel:h.channel}:{kind:`workspace`}},r),ue===`files`&&(0,F.jsx)(_u,{compact:!0,scope:ce,dir:M.dir,file:M.file,onOpen:(e,t)=>P({dir:e,file:t})},ce)]},ue)]})]})}function Xd({options:e,onPin:t}){return e.length===0?null:(0,F.jsxs)(`div`,{className:`flex items-center gap-2 px-2.5 py-2 text-fg-2`,children:[(0,F.jsx)(I,{name:`keep`,className:`ms-sm`}),(0,F.jsxs)(_t,{className:`h-8 text-sm`,value:``,onChange:e=>e.target.value&&t(e.target.value),"aria-label":`pin an app to this project`,children:[(0,F.jsx)(`option`,{value:``,children:`pin an app to this project…`}),e.map(e=>(0,F.jsx)(`option`,{value:e,children:e},e))]})]})}function Zd(e){return e===`ok`?`ok`:e===`failed`?`bad`:e===`running`?`working`:`idle`}var Qd=`kw-chat-path`,$d=`kw-ctx-w`,ef=()=>{try{let e=Number(localStorage.getItem($d));return e>0?e:null}catch{return null}};function tf({onResize:e}){let[t,n]=(0,v.useState)(!1);return(0,F.jsx)(`div`,{className:`split-handle${t?` dragging`:``}`,role:`separator`,"aria-orientation":`vertical`,"aria-label":`resize chat and context`,title:`drag to resize · double-click for half and half`,onPointerDown:t=>{if(t.button!==0)return;let r=t.currentTarget.closest(`.shell`);if(!r)return;t.preventDefault();let i=r.getBoundingClientRect().right-parseFloat(getComputedStyle(r).paddingRight),a=t=>e(Math.round(i-t.clientX)),o=()=>{window.removeEventListener(`pointermove`,a),window.removeEventListener(`pointerup`,o),window.removeEventListener(`pointercancel`,o),document.body.classList.remove(`kw-resizing`),n(!1)};window.addEventListener(`pointermove`,a),window.addEventListener(`pointerup`,o),window.addEventListener(`pointercancel`,o),document.body.classList.add(`kw-resizing`),n(!0)},onDoubleClick:()=>e(null)})}var nf=(e,t)=>{try{return sessionStorage.getItem(e)||t}catch{return t}},rf=(e,t)=>{try{sessionStorage.setItem(e,t)}catch{}};function af(){let e=L();Wt();let[t]=e.split(`?`),n=t.split(`/`).filter(Boolean),[r,i]=(0,v.useState)(``),[a,o]=(0,v.useState)(``),[s,c]=(0,v.useState)(``),[l,u]=(0,v.useState)(!0),[d,f]=(0,v.useState)(``),[p,m]=(0,v.useState)(``),[h,g]=(0,v.useState)([]),_=ue.has(n[0]??``),y=n.length===0,[b,x]=(0,v.useState)(()=>nf(Qd,`/agents/chats`)),S=_?Rs(t):null,C=_&&!S?t:b,[w,T]=(0,v.useState)(`chat`),[E,D]=(0,v.useState)(ef),O=e=>{D(e);try{e===null?localStorage.removeItem($d):localStorage.setItem($d,String(e))}catch{}};(0,v.useEffect)(()=>{T(e=>e===`side`?`chat`:e)},[e]),(0,v.useEffect)(()=>{_&&!Rs(t)&&(x(t),rf(Qd,t))},[e]),(0,v.useEffect)(()=>{let e=e=>{let t=e.detail;de(t)===`chat`?(x(t),rf(Qd,t)):window.location.replace(`#${t}`)};return window.addEventListener(R,e),()=>window.removeEventListener(R,e)},[]);let k=N(`meta.get`,{},{interval:3e4});(0,v.useEffect)(()=>{let e=k;e&&(i(e.workspaceName??``),o(e.workspaceIcon??``),c(e.workspaceColor??``),u(e.workspaceNamed!==!1),f(e.workspaceRootLabel??``),m(e.workspaceRoot??``),Ce({git:!!e.git,repos:!!e.repos,vibeables:!!e.vibeables,projects:!!e.projects}),g(Array.isArray(e.switcher)?e.switcher:[]))},[k]),(0,v.useEffect)(()=>{if(ce(r?`${r} — kraftwerk`:`kraftwerk inspector`),!a)return;let e=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><text y="0.9em" font-size="85">${a}</text></svg>`,t=document.querySelector(`link[rel="icon"]`);t||(t=document.createElement(`link`),t.rel=`icon`,document.head.appendChild(t)),t.href=`data:image/svg+xml,${encodeURIComponent(e)}`},[r,a]);let A=C.split(`/`).filter(Boolean),j=new URLSearchParams(e.split(`?`)[1]??``).get(`workflow`)??void 0,ee;ee=A[0]===`chats`?(0,F.jsx)(Ls,{seg:A}):A[0]===`projects`?(0,F.jsx)(qo,{seg:A.slice(1)}):A[0]===`channels`?(0,F.jsx)(Oa,{seg:A.slice(1)}):(0,F.jsx)(Ls,{seg:A.slice(1)});let M=null;return n[0]===`runs`&&n[1]?M=(0,F.jsx)(Js,{id:n[1],workflow:j}):n[0]===`runs`?M=(0,F.jsx)(hf,{}):n[0]===`workflows`?M=(0,F.jsx)(Bc,{slug:n[1]?decodeURIComponent(n[1]):void 0,tab:n[2]===`details`||n[2]===`runs`?n[2]:`overview`}):n[0]===`vibeables`?M=(0,F.jsx)(Ea,{slug:n[1]?decodeURIComponent(n[1]):void 0}):n[0]===`knowledge`?M=(0,F.jsx)(ll,{bundle:n[1]?decodeURIComponent(n[1]):void 0,conceptId:n.length>2?n.slice(2).map(decodeURIComponent).join(`/`):void 0}):n[0]===`skills`?M=(0,F.jsx)(El,{name:n[1]?decodeURIComponent(n[1]):void 0}):n[0]===`settings`?M=(0,F.jsx)(ou,{}):n[0]===`trash`?M=(0,F.jsx)(cu,{}):n[0]===`ui`?M=(0,F.jsx)(bu,{}):n[0]===`files`?M=(0,F.jsx)(hu,{scope:n[1]?decodeURIComponent(n[1]):`workspace`,dir:n.slice(2).map(decodeURIComponent).join(`/`),file:new URLSearchParams(e.split(`?`)[1]??``).get(`file`)??void 0}):n[0]===`workspaces`?M=(0,F.jsx)(wu,{}):n[0]===`git`?M=(0,F.jsx)(Iu,{}):n[0]===`repos`&&(M=(0,F.jsx)(Ju,{slug:n[1]?decodeURIComponent(n[1]):void 0})),(0,v.useEffect)(()=>{let e=document.documentElement,t=p||r,n=t?Ie(Ee(s,t)):null;if(!n){delete e.dataset.wsAccent;return}for(let[t,r]of Object.entries(n))e.style.setProperty(t,r);e.dataset.wsAccent=``},[s,p,r]),(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(`header`,{className:`topbar sticky top-0 z-10 flex h-[var(--topbar-h)] items-center gap-3.5 bg-bg px-5 shadow-[inset_0_-1px_0_var(--line)] max-[1520px]:gap-2.5 max-[800px]:gap-1.5 max-[800px]:px-3`,style:{"--ws-c":Ee(s,p||r)},children:[(0,F.jsxs)(`span`,{className:`flex min-w-0 flex-none items-center gap-2.5 max-[800px]:flex-[0_1_auto] max-[800px]:gap-1`,children:[(0,F.jsx)(`a`,{href:`#/`,className:`grid size-8 place-items-center rounded-full text-[15px] leading-none transition-shadow hover:shadow-[0_0_0_4px_color-mix(in_srgb,var(--ws-c,var(--text))_16%,transparent)]`,title:`Dashboard`,children:r?(0,F.jsx)(Re,{size:`sm`,icon:a,name:r,color:s,seed:p||r}):(0,F.jsx)(I,{name:`home`})}),r&&(0,F.jsx)(mf,{name:r,icon:a,color:s,named:l,root:d,seed:p||r,entries:h})]}),(0,F.jsx)(Ad,{path:t}),(0,F.jsx)(`span`,{className:`flex-[1_1_8px]`}),(0,F.jsx)(ud,{}),(0,F.jsx)(H,{icon:`settings`,label:`settings`,href:`/settings`,"aria-current":n[0]===`settings`?`page`:void 0}),(0,F.jsx)(vf,{}),(0,F.jsx)(Ut,{}),(0,F.jsx)(xf,{}),(0,F.jsx)(_f,{})]}),M&&(0,F.jsx)(`main`,{className:`shell shell-global`,children:M}),(0,F.jsxs)(`main`,{className:`shell three${y?` home`:``}`,"data-focus":w,hidden:!!M,style:E?{"--ctx-w":`${E}px`}:void 0,children:[(0,F.jsx)(wd,{chatPath:y?`/`:C}),(0,F.jsxs)(`section`,{className:`col-chat`,"aria-label":y?`Dashboard`:`Conversation`,children:[y?(0,F.jsx)(Kc,{}):ee,(0,F.jsx)(tf,{onResize:O})]}),(0,F.jsx)(Yd,{chatPath:y?`/`:C,workspace:{name:r,icon:a}}),S&&(0,F.jsx)(zs,{back:C,children:S})]}),!M&&(0,F.jsxs)(`nav`,{className:`places`,"aria-label":`Sections`,children:[(0,F.jsxs)(`button`,{className:w===`side`?`active`:``,onClick:()=>T(`side`),children:[(0,F.jsx)(I,{name:`menu`}),` list`]}),(0,F.jsxs)(`button`,{className:w===`chat`?`active`:``,onClick:()=>T(`chat`),children:[(0,F.jsx)(I,{name:`forum`}),` chat`]}),(0,F.jsxs)(`button`,{className:w===`context`?`active`:``,onClick:()=>T(`context`),children:[(0,F.jsx)(I,{name:`account_tree`}),` context`]})]})]})}function of(e){try{let t=new URL(e);return t.hostname===`localhost`||t.hostname===`127.0.0.1`?`:${t.port||(t.protocol===`https:`?443:80)}`:t.host}catch{return e.replace(/^https?:\/\//,``)}}var sf=`truncate text-sm text-fg-2 group-aria-[current=true]/ws:text-on-accent-soft group-aria-[current=true]/ws:opacity-80`,cf=`group/ws relative flex min-h-[60px] items-center gap-3.5 px-4 py-2.5 text-fg no-underline transition-colors`;function lf({label:e}){return e?(0,F.jsx)(`span`,{className:P(sf,`[direction:rtl] text-left`),title:e,children:(0,F.jsx)(`span`,{dir:`ltr`,className:`[unicode-bidi:isolate]`,children:e})}):null}function uf({name:e,named:t}){let n=t===!1;return(0,F.jsx)(`span`,{className:P(`truncate text-md tracking-[0.2px]`,n&&`italic text-fg-2`,`group-data-[missing]/ws:line-through group-data-[stopped]/ws:text-fg-2`),title:n?`${e} — folder name; set name: in kraftwerk.yml`:e,children:e})}function df({entry:e,ambiguous:t}){let[n,r]=(0,v.useState)(`idle`),[i,a]=(0,v.useState)(``),o=e.exists===!1,s=async()=>{r(`starting`),a(``);try{window.location.assign(await pe(e.root))}catch(e){r(`error`),a(e.message)}};return(0,F.jsxs)(`span`,{className:P(cf,`cursor-default`),role:`menuitem`,"data-stopped":``,"data-missing":o?``:void 0,style:{"--ws-c":Ee(e.color,e.root??e.url)},children:[(0,F.jsx)(Re,{className:`opacity-60 grayscale-50`,icon:e.icon,name:e.name,color:e.color,seed:e.root??e.url,ambiguous:t}),(0,F.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,F.jsx)(uf,{name:e.name,named:e.named}),n===`error`?(0,F.jsx)(`span`,{className:P(sf,`text-bad`),title:i,children:i}):o?(0,F.jsx)(`span`,{className:sf,children:`folder missing`}):(0,F.jsx)(lf,{label:e.rootLabel})]}),(0,F.jsxs)(`span`,{className:`ml-auto inline-flex flex-none items-center gap-3`,children:[(0,F.jsx)(ff,{entry:e}),(0,F.jsx)(V,{variant:`quiet`,size:`sm`,icon:`play_arrow`,busy:n===`starting`,className:`text-accent hover:text-accent`,disabled:o,title:o?`The project folder no longer exists`:`Start the UI for this project`,onClick:e=>{e.stopPropagation(),s()},children:n===`starting`?`starting`:`start`})]})]})}function ff({entry:e}){return(0,F.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 whitespace-nowrap text-2xs font-medium tracking-[0.5px] text-fg-2`,children:[e.live&&(0,F.jsx)(U,{tone:`ok`,title:`running`}),!e.here&&(0,F.jsx)(`span`,{className:`max-[800px]:hidden`,children:of(e.url)})]})}function pf({entry:e,ambiguous:t}){let n=e.root??e.url;return(0,F.jsxs)(`a`,{className:P(cf,`hover:bg-surface-2 active:bg-surface-2`),role:`menuitem`,href:fe(e),style:{"--ws-c":Ee(e.color,n)},children:[(0,F.jsx)(Re,{icon:e.icon,name:e.name,color:e.color,seed:n,ambiguous:t}),(0,F.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,F.jsx)(uf,{name:e.name,named:e.named}),(0,F.jsx)(lf,{label:e.rootLabel??(e.root?void 0:e.url.replace(/^https?:\/\//,``))})]}),(0,F.jsx)(`span`,{className:`ml-auto inline-flex flex-none items-center gap-3`,children:(0,F.jsx)(ff,{entry:e})})]})}function mf({name:e,icon:t,color:n,named:r,root:i,seed:a,entries:o}){let[s,c]=(0,v.useState)(!1),l=be();(0,v.useEffect)(()=>{if(!s)return;let e=e=>{e.target.closest(`[data-switcher]`)||c(!1)};return window.addEventListener(`mousedown`,e),()=>window.removeEventListener(`mousedown`,e)},[s]);let u=new Map;for(let e of[t,...o.map(e=>e.icon)])e&&u.set(e,(u.get(e)??0)+1);let d=e=>!!e&&(u.get(e)??0)>1,f=[{key:`running`,label:`running`,items:o.filter(e=>e.live===!0)},{key:`stopped`,label:`stopped`,items:o.filter(e=>e.live===!1)},{key:`linked`,label:`linked`,items:o.filter(e=>e.live===void 0)}].filter(e=>e.items.length>0),p=a||e;return(0,F.jsxs)(`span`,{className:`relative inline-flex min-w-0`,"data-switcher":``,children:[(0,F.jsxs)(`button`,{type:`button`,className:`env-switch inline-flex max-w-[220px] min-w-0 cursor-pointer items-center gap-[5px] rounded-xl border-0 bg-transparent px-2 py-1 font-[inherit] text-[15px] font-bold tracking-[0.02em] whitespace-nowrap text-fg transition-colors hover:bg-surface-2 max-[1520px]:max-w-[250px]`,title:i?`${i} — workspace menu`:`Workspace menu`,"aria-haspopup":`menu`,"aria-expanded":s,onClick:()=>c(e=>!e),children:[(0,F.jsx)(`span`,{className:`min-w-0 truncate`,children:e}),(0,F.jsx)(I,{name:`expand_more`,className:`flex-none opacity-55`})]}),s&&(0,F.jsxs)(`div`,{className:`absolute top-[calc(100%+8px)] left-0 z-20 max-h-[calc(100dvh-120px)] max-w-[min(480px,92vw)] min-w-[360px] max-[800px]:fixed max-[800px]:inset-x-2 max-[800px]:top-[calc(var(--topbar-h)-4px)] max-[800px]:max-w-none max-[800px]:min-w-0 overflow-y-auto overscroll-contain rounded-card border border-line bg-surface py-2 shadow-pop`,role:`menu`,children:[o.length>0&&(0,F.jsx)(et,{className:`block px-4 pt-1 pb-2`,children:`workspaces`}),(0,F.jsxs)(`span`,{className:P(cf,`cursor-default bg-accent-soft text-on-accent-soft`),"aria-current":`true`,style:{"--ws-c":Ee(n,p)},children:[(0,F.jsx)(Re,{icon:t,name:e,color:n,seed:p,ambiguous:d(t)}),(0,F.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,F.jsx)(uf,{name:e,named:r}),i?(0,F.jsx)(lf,{label:i}):(0,F.jsx)(`span`,{className:sf,children:`this workspace`})]}),(0,F.jsx)(`span`,{className:`ml-auto inline-flex flex-none items-center gap-3`,children:(0,F.jsx)(I,{name:`check`,className:`text-[24px] text-on-accent-soft`})})]}),f.map(e=>(0,F.jsxs)(`div`,{className:`mt-2 border-t border-line pt-1`,role:`group`,"aria-label":e.label,children:[(0,F.jsx)(et,{className:`block px-4 pt-2 pb-1`,children:e.label}),e.items.map(e=>e.live===!1&&e.root?(0,F.jsx)(df,{entry:e,ambiguous:d(e.icon)},e.root):(0,F.jsx)(pf,{entry:e,ambiguous:d(e.icon)},e.root??e.url))]},e.key)),l&&o.length>0&&(0,F.jsxs)(`a`,{className:`mt-2 flex min-h-12 items-center gap-4 border-t border-line px-4 text-md text-fg no-underline transition-colors hover:bg-surface-2`,href:`#/workspaces`,role:`menuitem`,onClick:()=>c(!1),children:[(0,F.jsx)(I,{name:`hub`,className:`text-[22px] text-fg-2`}),` manage workspaces`]}),(0,F.jsx)(wf,{onClose:()=>c(!1)})]})]})}function hf(){let[e,t]=(0,v.useState)(null);return(0,v.useEffect)(()=>{let e=!0;return A.call(`runs.list`).then(n=>{e&&(n.runs.length>0?B(`/runs/${n.runs[0].id}`,{replace:!0}):t({outputDir:n.outputDir}))}).catch(()=>{}),()=>{e=!1}},[]),e?(0,F.jsxs)(K,{icon:`play_circle`,children:[`No runs found in `,(0,F.jsx)(`code`,{children:e.outputDir}),`. Start one from the`,` `,(0,F.jsx)(`a`,{href:`#/workflows`,className:`text-accent`,children:`workflows`}),` list or with `,(0,F.jsx)(`code`,{children:`kraftwerk run <workflow> [request]`}),`.`]}):(0,F.jsx)(K,{children:`loading…`})}async function gf(e){await A.request(`server.restart`).catch(()=>{});for(let t=0;t<60;t++){await new Promise(e=>setTimeout(e,500));try{if((await A.call(`meta.get`)).version===e)break}catch{}}location.reload()}function _f(){let e=N(`meta.get`,{},{interval:3e4}),[t,n]=(0,v.useState)(!1),r=e?.restartable&&e.diskVersion&&e.diskVersion!==e.version?e.diskVersion:null;async function i(){r&&(n(!0),await gf(r))}return!r&&!t?null:(0,F.jsx)(`button`,{type:`button`,className:`mr-2.5 inline-flex flex-none cursor-pointer items-center gap-1 rounded-full border border-accent bg-accent/10 px-3 py-1 font-[inherit] text-xs text-accent hover:bg-accent/18 disabled:cursor-default disabled:opacity-70`,disabled:t,title:`v${r} is installed on disk, the server still runs v${e?.version}. Click to relaunch with the new version.`,onClick:()=>void i(),children:t?`relaunching…`:(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(I,{name:`restart_alt`,className:`ms-sm`}),` v`,r,` ready — relaunch`]})})}function vf(){let e=be();return(0,F.jsxs)(`button`,{type:`button`,className:P(`expert-toggle inline-flex cursor-pointer items-center gap-[7px] rounded-full border-0 bg-transparent px-2 py-1 font-mono text-2xs tracking-[0.5px] transition-colors hover:text-fg`,e?`text-fg`:`text-fg-2`),title:e?`Expert mode on — full detail`:`Expert mode off — simplified view`,"aria-pressed":e,onClick:()=>ye(!e),children:[(0,F.jsx)(`span`,{className:P(`relative h-[15px] w-[26px] rounded-full transition-colors`,e?`bg-accent`:`bg-fg/14`),children:(0,F.jsx)(`span`,{className:P(`absolute top-0.5 size-[11px] rounded-full transition-[left,background-color]`,e?`left-[13px] bg-on-accent`:`left-0.5 bg-surface`)})}),(0,F.jsx)(`span`,{className:`max-[640px]:hidden`,children:`expert`})]})}var yf={approval:`gavel`,routine_done:`schedule`,routine_failed:`schedule`,run_done:`account_tree`,run_failed:`account_tree`},bf=`kw.notif.toast.dismissed`;function xf(){let[e,t]=(0,v.useState)(!1),n=N(`notifications.list`,{},{interval:5e3}),[r,i]=(0,v.useState)(()=>typeof Notification>`u`?`unsupported`:Notification.permission),[a,o]=(0,v.useState)(()=>{try{return localStorage.getItem(bf)===`1`}catch{return!1}}),s=(0,v.useRef)(null),[c,l]=(0,v.useState)(null),[u,d]=(0,v.useState)(null);(0,v.useEffect)(()=>l(null),[n]);let f=(c??n)?.items??[],p=Ft()??[],m=new Set(p.map(e=>e.notificationId).filter(Boolean)),h=f.filter(e=>e.kind!==`approval`&&!m.has(e.id)),g=h.filter(e=>!e.readAt).length,_=p.length;(0,v.useEffect)(()=>se(p.length),[p.length]),(0,v.useEffect)(()=>{if(n){if(!s.current){s.current=new Set(f.map(e=>e.id));return}for(let e of f)if(!s.current.has(e.id)&&(s.current.add(e.id),!(e.readAt||r!==`granted`)&&(document.hidden||location.hash!==`#${e.href}`)))try{let t=new Notification(e.title,{body:e.body,tag:e.id});t.onclick=()=>{window.focus(),S(e),t.close()}}catch{}}},[n]),(0,v.useEffect)(()=>{if(!e)return;let n=e=>{e.target.closest(`[data-bell]`)||t(!1)};return window.addEventListener(`mousedown`,n),()=>window.removeEventListener(`mousedown`,n)},[e]);async function y(e){try{let t=await e;if(!t.ok)return;let n=t.data;l(`items`in n?n:{items:[],unread:0})}catch{}}let b=e=>y(A.request(`notifications.read`,{body:{ids:e}})),x=()=>y(A.request(`notifications.clear`));function S(e){t(!1),e.readAt||b([e.id]),B(e.href)}async function C(e){d(e.id);try{let n=await A.request(`notifications.diagnose`,{id:e.id});n.ok?(t(!1),B(n.data.href)):n.error&&alert(n.error)}catch{}d(null)}async function w(){typeof Notification<`u`&&i(await Notification.requestPermission())}function T(){o(!0);try{localStorage.setItem(bf,`1`)}catch{}}let E=r==="default"&&!a;return(0,F.jsxs)(`span`,{className:`relative inline-flex`,"data-bell":``,children:[(0,F.jsxs)(`button`,{type:`button`,className:P(`relative grid size-8 cursor-pointer place-items-center rounded-full border-0 bg-transparent transition-colors hover:bg-surface-2 hover:text-fg`,_?`text-fg`:`text-fg-2`),title:_?`${_} thing${_===1?``:`s`} waiting for you`:g?`${g} update${g===1?``:`s`}`:`Notifications`,"aria-label":`Notifications`,onClick:()=>t(e=>!e),children:[(0,F.jsx)(I,{name:_?`notifications_active`:`notifications`}),g>0&&(0,F.jsx)(`span`,{className:`absolute top-1.5 right-1.5 size-[7px] rounded-full bg-accent`})]}),e&&(0,F.jsxs)(`div`,{className:`notif-pop absolute right-0 top-[calc(100%+8px)] z-50 flex max-h-[min(80dvh,640px)] w-[min(460px,92vw)] flex-col overflow-hidden rounded-card border border-line bg-surface shadow-pop`,role:`menu`,children:[(0,F.jsxs)(`div`,{className:`flex items-center gap-1 border-b border-line px-4 py-2`,children:[(0,F.jsx)(et,{className:`text-fg`,children:`notifications`}),(0,F.jsx)(`span`,{className:`flex-1`}),g>0&&(0,F.jsx)(V,{variant:`quiet`,size:`sm`,onClick:()=>void b(h.filter(e=>!e.readAt).map(e=>e.id)),children:`mark updates read`}),f.length>0&&(0,F.jsx)(V,{variant:`quiet`,size:`sm`,onClick:()=>void x(),children:`clear`})]}),(0,F.jsxs)(`div`,{className:`min-h-0 overflow-y-auto overscroll-contain pb-1.5`,children:[E&&(0,F.jsxs)(`div`,{className:`m-2 flex flex-col gap-2 rounded-control bg-surface-2 p-3 text-sm`,children:[(0,F.jsx)(`span`,{children:`Get a system notification when something needs you, even with this tab in the background.`}),(0,F.jsxs)(`span`,{className:`flex gap-2`,children:[(0,F.jsx)(V,{variant:`primary`,size:`sm`,onClick:()=>void w(),children:`enable`}),(0,F.jsx)(V,{variant:`quiet`,size:`sm`,onClick:T,children:`not now`})]})]}),r===`denied`&&(0,F.jsx)(`p`,{className:`m-0 px-4 pt-2 text-xs text-fg-2`,children:`Browser notifications are blocked for this site — allow them in the address bar to get system alerts.`}),(0,F.jsx)(tt,{title:`needs you`,count:p.length||void 0,className:`px-1.5 pt-1.5`,children:p.length===0?(0,F.jsx)(`p`,{className:`m-0 px-2.5 py-2 text-sm text-fg-2`,children:`nothing is waiting for you`}):Cf(p).map(([e,n])=>(0,F.jsxs)(`div`,{children:[(0,F.jsx)(`div`,{className:`notif-owner px-2.5 pb-0.5 pt-2 text-xs font-semibold text-fg`,children:e}),n.map(e=>{let n=e.notificationId?f.find(t=>t.id===e.notificationId):void 0;return(0,F.jsx)(Y,{className:`notif-row need`,onClick:()=>{t(!1),Vt(e)},leading:(0,F.jsx)(I,{name:e.kind===`approval`?`front_hand`:e.kind===`question`?`help`:`error`,className:`ms-sm text-bad`}),title:e.title,sub:`${e.kind===`approval`?`needs approval`:e.kind===`question`?`asks you`:`failed`}${e.chatTitle?` · in ${e.chatTitle}`:``}`,meta:Ge(e.since),actionsAlways:!0,actions:n?.diagnose?(0,F.jsx)(Sf,{busy:u===n.id,onClick:()=>void C(n)}):void 0},e.id)})]},e))}),(0,F.jsx)(tt,{title:`updates`,className:`px-1.5 pt-1.5`,children:h.length===0?(0,F.jsx)(`p`,{className:`m-0 px-2.5 py-2 text-sm text-fg-2`,children:`no updates`}):h.slice(0,50).map(e=>(0,F.jsx)(Y,{className:P(`notif-row`,!e.readAt&&`bg-accent/5`),onClick:()=>S(e),leading:(0,F.jsx)(I,{name:yf[e.kind],className:P(`ms-sm`,e.kind.endsWith(`failed`)?`text-bad`:e.kind.endsWith(`done`)?`text-ok`:``)}),title:e.title,sub:e.body,meta:Ge(e.at),actionsAlways:!0,actions:e.diagnose?(0,F.jsx)(Sf,{busy:u===e.id,onClick:()=>void C(e)}):void 0},e.id))})]})]})]})}function Sf({busy:e,onClick:t}){return(0,F.jsx)(V,{variant:`secondary`,size:`sm`,icon:`troubleshoot`,busy:e,title:`Open a chat that finds the cause and proposes the fix`,onClick:e=>{e.stopPropagation(),t()},children:e?`starting…`:`diagnose`})}function Cf(e){let t=new Map;for(let n of e){let e=Lt(n.owner);t.set(e,[...t.get(e)??[],n])}return[...t.entries()]}function wf({onClose:e}){let t=be(),[n,r]=(0,v.useState)(null),[i,a]=(0,v.useState)(null),[o,s]=(0,v.useState)(``);return(0,v.useEffect)(()=>{A.call(`meta.get`).then(e=>s(e.version)).catch(()=>{}),t&&(A.call(`runs.list`).then(r).catch(()=>{}),A.call(`workflows.list`).then(a).catch(()=>{}))},[t]),(0,F.jsxs)(`div`,{className:`ws-menu mt-1.5 flex flex-col gap-0.5 border-t border-line px-1.5 pb-1 pt-2`,children:[(0,F.jsx)(Tf,{label:`Theme`,children:(0,F.jsx)(Af,{})}),(0,F.jsx)(`div`,{className:`flex gap-1 px-1`,children:(0,F.jsx)(V,{variant:`quiet`,size:`sm`,icon:`delete`,href:`/trash`,onClick:e,children:`trash`})}),t&&(0,F.jsxs)(`div`,{className:`flex flex-col gap-1 px-2.5 py-1.5 text-xs`,children:[(0,F.jsxs)(`div`,{children:[(0,F.jsx)(et,{children:`Workflows`}),` `,i?`${i.workflows.length} discovered`:`…`,` `,(0,F.jsx)(`code`,{className:`block break-all text-2xs text-fg-2`,title:i?.root,children:i?.root??``})]}),(0,F.jsxs)(`div`,{children:[(0,F.jsx)(et,{children:`Runs`}),` `,n?`${n.runs.length} total`:`…`,` `,(0,F.jsx)(`code`,{className:`block break-all text-2xs text-fg-2`,title:n?.outputDir,children:n?.outputDir??``})]})]}),(0,F.jsx)(Tf,{label:(0,F.jsx)(`span`,{className:`font-mono`,children:o?`kraftwerk ${o}`:`…`}),children:(0,F.jsx)(Df,{})})]})}function Tf({label:e,children:t}){return(0,F.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-2.5 py-1.5`,children:[(0,F.jsx)(`span`,{className:`text-sm text-fg-2`,children:e}),t]})}function Ef(e,t){let n=e.split(`.`).map(Number),r=t.split(`.`).map(Number);for(let e=0;e<3;e++)if((n[e]??0)!==(r[e]??0))return(n[e]??0)<(r[e]??0);return!1}function Df(){let[e,t]=(0,v.useState)(`idle`),[n,r]=(0,v.useState)(null),[i,a]=(0,v.useState)(null),[o,s]=(0,v.useState)(``),[c,l]=(0,v.useState)(!1);async function u(){t(`busy`);try{let e=await A.call(`update.check`);if(!e.latest)throw Error();r(e),t(`done`)}catch{t(`err`)}}let d=i?.state===`running`;(0,v.useEffect)(()=>{if(!d)return;let e=!0,t=setInterval(async()=>{try{let t=await A.call(`update.status`);if(!e)return;a(t)}catch{}},1e3);return()=>{e=!1,clearInterval(t)}},[d]);async function f(){if(!n)return;s(``);let e=await A.request(`update.start`,{body:{version:n.latest}});e.ok?a(e.data):s(e.error??`update refused`)}if(i&&i.state!==`idle`&&n){let e=i.log[i.log.length-1]??``;return i.state===`running`?(0,F.jsxs)(`span`,{className:P(Of,`basis-full flex-wrap`),children:[(0,F.jsx)(I,{name:`progress_activity`,className:`ms-sm`}),` installing v`,n.latest,`…`,e&&(0,F.jsx)(`code`,{className:`max-w-full truncate text-2xs text-fg-2`,title:i.log.join(`
230
+ `),children:e})]}):i.state===`done`?(0,F.jsxs)(`span`,{className:P(Of,kf),children:[`v`,n.latest,` installed —`,` `,i.restartable?(0,F.jsx)(V,{size:`sm`,icon:`restart_alt`,busy:c,onClick:()=>{l(!0),gf(n.latest)},children:c?`relaunching…`:`relaunch`}):(0,F.jsxs)(F.Fragment,{children:[`restart `,(0,F.jsx)(`code`,{children:`kraftwerk ui`}),` to use it`]})]}):(0,F.jsxs)(`span`,{className:P(Of,`basis-full flex-wrap text-bad`),title:i.log.join(`
231
+ `),children:[(0,F.jsx)(I,{name:`error`,className:`ms-sm`}),` install failed`,e?` — ${e}`:``,` · `,(0,F.jsxs)(`code`,{children:[`npm i -g `,n.name,`@latest`]})]})}return e===`done`&&n?Ef(n.current,n.latest)?(0,F.jsxs)(`span`,{className:P(Of,kf),children:[`v`,n.latest,` available —`,` `,o?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`span`,{className:`font-normal text-fg-2`,title:o,children:o}),` · `,(0,F.jsxs)(`code`,{className:`text-2xs`,children:[`npm i -g `,n.name,`@latest`]})]}):(0,F.jsx)(V,{size:`sm`,icon:`download`,onClick:()=>void f(),children:`update now`})]}):(0,F.jsxs)(`span`,{className:Of,children:[(0,F.jsx)(I,{name:`check`,className:`ms-sm text-ok`}),` up to date`]}):(0,F.jsx)(V,{size:`sm`,icon:e===`busy`||e===`err`?void 0:`sync`,disabled:e===`busy`,onClick:()=>void u(),children:e===`busy`?`checking…`:e===`err`?`npm unreachable — retry`:`check for updates`})}var Of=`inline-flex items-center gap-[5px] text-xs text-fg-2`,kf=`basis-full flex-wrap font-medium text-accent`;function Af(){return(0,F.jsx)(V,{size:`sm`,icon:`contrast`,onClick:()=>{let e=document.documentElement,t=e.dataset.theme===`light`?`dark`:`light`;e.dataset.theme=t;try{localStorage.setItem(`kw-theme`,t)}catch{}},children:`day / night`})}(0,y.createRoot)(document.getElementById(`root`)).render((0,F.jsx)(v.StrictMode,{children:(0,F.jsx)(Yl,{children:(0,F.jsx)(af,{})})}));export{o as a,d as i,ne as n,s as o,h as r,l as s,ol as t};