@netnodeag/kraftwerk 0.40.0 → 0.41.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. package/README.md +43 -0
  2. package/dist/inspector/channels.d.ts +48 -0
  3. package/dist/inspector/channels.js +130 -0
  4. package/dist/inspector/chat/sessions.d.ts +17 -1
  5. package/dist/inspector/chat/sessions.js +280 -44
  6. package/dist/inspector/chat/types.d.ts +18 -0
  7. package/dist/inspector/notifications.js +2 -0
  8. package/dist/inspector/server.js +74 -2
  9. package/inspector/dist/assets/{dist-HuQTcyVK.js → dist-BO4gDbWB.js} +1 -1
  10. package/inspector/dist/assets/{dist-Bv3fOisq.js → dist-BiIrAs8U.js} +1 -1
  11. package/inspector/dist/assets/{dist-uQIhtGKj.js → dist-Bj7XitTo.js} +1 -1
  12. package/inspector/dist/assets/{dist-D9-MFS0x.js → dist-BvHfHbzl.js} +1 -1
  13. package/inspector/dist/assets/{dist-Dyv2EX0S.js → dist-CASrSR5E.js} +1 -1
  14. package/inspector/dist/assets/{dist-XL4xXfDo.js → dist-CoT4dTT9.js} +1 -1
  15. package/inspector/dist/assets/{dist-Cex4_N6v.js → dist-CqbReWDG.js} +1 -1
  16. package/inspector/dist/assets/{dist-DdbyO9w9.js → dist-DKds1beX.js} +1 -1
  17. package/inspector/dist/assets/dist-Dg2YcNTD.js +1 -0
  18. package/inspector/dist/assets/{dist-AXonJXol.js → dist-g0pveAaF.js} +1 -1
  19. package/inspector/dist/assets/{dist-BJLTdJRF.js → dist-h7tJ3T-Z.js} +1 -1
  20. package/inspector/dist/assets/{editor--4qv8VP5.js → editor-BiyVJ7Wz.js} +3 -3
  21. package/inspector/dist/assets/{index-E1E7-_NW.css → index-CHI0eOQa.css} +1 -1
  22. package/inspector/dist/assets/{index-BSqc9eg2.js → index-lwVGUk9H.js} +17 -17
  23. package/inspector/dist/index.html +2 -2
  24. package/package.json +1 -1
  25. package/inspector/dist/assets/dist-UTSke4yL.js +0 -1
@@ -1,4 +1,4 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/editor--4qv8VP5.js","assets/dist-H3rerbMg.js","assets/dist-XL4xXfDo.js","assets/dist-HuQTcyVK.js","assets/dist-Dyv2EX0S.js","assets/dist-CPlSMtdY.js","assets/editor-B1Jq9YIq.css"])))=>i.map(i=>d[i]);
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/editor-BiyVJ7Wz.js","assets/dist-H3rerbMg.js","assets/dist-CoT4dTT9.js","assets/dist-BO4gDbWB.js","assets/dist-CASrSR5E.js","assets/dist-CPlSMtdY.js","assets/editor-B1Jq9YIq.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.iterator;function m(e){return typeof e!=`object`||!e?null:(e=p&&e[p]||e[`@@iterator`],typeof e==`function`?e:null)}var h={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},g=Object.assign,_={};function v(e,t,n){this.props=e,this.context=t,this.refs=_,this.updater=n||h}v.prototype.isReactComponent={},v.prototype.setState=function(e,t){if(typeof e!=`object`&&typeof e!=`function`&&e!=null)throw Error(`takes an object of state variables to update or a function which returns an object of state variables.`);this.updater.enqueueSetState(this,e,t,`setState`)},v.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,`forceUpdate`)};function y(){}y.prototype=v.prototype;function b(e,t,n){this.props=e,this.context=t,this.refs=_,this.updater=n||h}var x=b.prototype=new y;x.constructor=b,g(x,v.prototype),x.isPureReactComponent=!0;var S=Array.isArray;function C(){}var w={H:null,A:null,T:null,S:null},T=Object.prototype.hasOwnProperty;function E(e,n,r){var i=r.ref;return{$$typeof:t,type:e,key:n,ref:i===void 0?null:i,props:r}}function D(e,t){return E(e.type,t,e.props)}function O(e){return typeof e==`object`&&!!e&&e.$$typeof===t}function ee(e){var t={"=":`=0`,":":`=2`};return`$`+e.replace(/[=:]/g,function(e){return t[e]})}var te=/\/+/g;function ne(e,t){return typeof e==`object`&&e&&e.key!=null?ee(``+e.key):t.toString(36)}function k(e){switch(e.status){case`fulfilled`:return e.value;case`rejected`:throw e.reason;default:switch(typeof e.status==`string`?e.then(C,C):(e.status=`pending`,e.then(function(t){e.status===`pending`&&(e.status=`fulfilled`,e.value=t)},function(t){e.status===`pending`&&(e.status=`rejected`,e.reason=t)})),e.status){case`fulfilled`:return e.value;case`rejected`:throw e.reason}}throw e}function re(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,re(c(e._payload),r,i,a,o)}}if(c)return o=o(e),c=a===``?`.`+ne(e,0):a,S(o)?(i=``,c!=null&&(i=c.replace(te,`$&/`)+`/`),re(o,r,i,``,function(e){return e})):o!=null&&(O(o)&&(o=D(o,i+(o.key==null||e&&e.key===o.key?``:(``+o.key).replace(te,`$&/`)+`/`)+c)),r.push(o)),1;c=0;var l=a===``?`.`:a+`:`;if(S(e))for(var u=0;u<e.length;u++)a=e[u],s=l+ne(a,u),c+=re(a,r,i,s,o);else if(u=m(e),typeof u==`function`)for(e=u.call(e),u=0;!(a=e.next()).done;)a=a.value,s=l+ne(a,u++),c+=re(a,r,i,s,o);else if(s===`object`){if(typeof e.then==`function`)return re(k(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 A(e,t,n){if(e==null)return e;var r=[],i=0;return re(e,r,``,``,function(e){return t.call(n,e,i++)}),r}function ie(e){if(e._status===-1){var t=e._result;t=t(),t.then(function(t){(e._status===0||e._status===-1)&&(e._status=1,e._result=t)},function(t){(e._status===0||e._status===-1)&&(e._status=2,e._result=t)}),e._status===-1&&(e._status=0,e._result=t)}if(e._status===1)return e._result.default;throw e._result}var j=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)},M={map:A,forEach:function(e,t,n){A(e,function(){t.apply(this,arguments)},n)},count:function(e){var t=0;return A(e,function(){t++}),t},toArray:function(e){return A(e,function(e){return e})||[]},only:function(e){if(!O(e))throw Error(`React.Children.only expected to receive a single React element child.`);return e}};e.Activity=f,e.Children=M,e.Component=v,e.Fragment=r,e.Profiler=a,e.PureComponent=b,e.StrictMode=i,e.Suspense=l,e.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=w,e.__COMPILER_RUNTIME={__proto__:null,c:function(e){return w.H.useMemoCache(e)}},e.cache=function(e){return function(){return e.apply(null,arguments)}},e.cacheSignal=function(){return null},e.cloneElement=function(e,t,n){if(e==null)throw Error(`The argument must be a React element, but you passed `+e+`.`);var r=g({},e.props),i=e.key;if(t!=null)for(a in t.key!==void 0&&(i=``+t.key),t)!T.call(t,a)||a===`key`||a===`__self`||a===`__source`||a===`ref`&&t.ref===void 0||(r[a]=t[a]);var a=arguments.length-2;if(a===1)r.children=n;else if(1<a){for(var o=Array(a),s=0;s<a;s++)o[s]=arguments[s+2];r.children=o}return E(e.type,i,r)},e.createContext=function(e){return e={$$typeof:s,_currentValue:e,_currentValue2:e,_threadCount:0,Provider:null,Consumer:null},e.Provider=e,e.Consumer={$$typeof:o,_context:e},e},e.createElement=function(e,t,n){var r,i={},a=null;if(t!=null)for(r in t.key!==void 0&&(a=``+t.key),t)T.call(t,r)&&r!==`key`&&r!==`__self`&&r!==`__source`&&(i[r]=t[r]);var o=arguments.length-2;if(o===1)i.children=n;else if(1<o){for(var s=Array(o),c=0;c<o;c++)s[c]=arguments[c+2];i.children=s}if(e&&e.defaultProps)for(r in o=e.defaultProps,o)i[r]===void 0&&(i[r]=o[r]);return E(e,a,i)},e.createRef=function(){return{current:null}},e.forwardRef=function(e){return{$$typeof:c,render:e}},e.isValidElement=O,e.lazy=function(e){return{$$typeof:d,_payload:{_status:-1,_result:e},_init:ie}},e.memo=function(e,t){return{$$typeof:u,type:e,compare:t===void 0?null:t}},e.startTransition=function(e){var t=w.T,n={};w.T=n;try{var r=e(),i=w.S;i!==null&&i(n,r),typeof r==`object`&&r&&typeof r.then==`function`&&r.then(C,j)}catch(e){j(e)}finally{t!==null&&n.types!==null&&(t.types=n.types),w.T=t}},e.unstable_useCacheRefresh=function(){return w.H.useCacheRefresh()},e.use=function(e){return w.H.use(e)},e.useActionState=function(e,t,n){return w.H.useActionState(e,t,n)},e.useCallback=function(e,t){return w.H.useCallback(e,t)},e.useContext=function(e){return w.H.useContext(e)},e.useDebugValue=function(){},e.useDeferredValue=function(e,t){return w.H.useDeferredValue(e,t)},e.useEffect=function(e,t){return w.H.useEffect(e,t)},e.useEffectEvent=function(e){return w.H.useEffectEvent(e)},e.useId=function(){return w.H.useId()},e.useImperativeHandle=function(e,t,n){return w.H.useImperativeHandle(e,t,n)},e.useInsertionEffect=function(e,t){return w.H.useInsertionEffect(e,t)},e.useLayoutEffect=function(e,t){return w.H.useLayoutEffect(e,t)},e.useMemo=function(e,t){return w.H.useMemo(e,t)},e.useOptimistic=function(e,t){return w.H.useOptimistic(e,t)},e.useReducer=function(e,t,n){return w.H.useReducer(e,t,n)},e.useRef=function(e){return w.H.useRef(e)},e.useState=function(e){return w.H.useState(e)},e.useSyncExternalStore=function(e,t,n){return w.H.useSyncExternalStore(e,t,n)},e.useTransition=function(){return w.H.useTransition()},e.version=`19.2.8`})),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&&ne(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&&ne(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 ee=new MessageChannel,te=ee.port2;ee.port1.onmessage=D,O=function(){te.postMessage(null)}}else O=function(){_(D,0)};function ne(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,ne(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`);function o(e,t,n){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:a,key:r==null?null:``+r,children:e,containerInfo:t,implementation:n}}var s=t.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;function c(e,t){if(e===`font`)return``;if(typeof t==`string`)return t===`use-credentials`?t:``}e.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=i,e.createPortal=function(e,t){var r=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!t||t.nodeType!==1&&t.nodeType!==9&&t.nodeType!==11)throw Error(n(299));return o(e,t,null,r)},e.flushSync=function(e){var t=s.T,n=i.p;try{if(s.T=null,i.p=2,e)return e()}finally{s.T=t,i.p=n,i.d.f()}},e.preconnect=function(e,t){typeof e==`string`&&(t?(t=t.crossOrigin,t=typeof t==`string`?t===`use-credentials`?t:``:void 0):t=null,i.d.C(e,t))},e.prefetchDNS=function(e){typeof e==`string`&&i.d.D(e)},e.preinit=function(e,t){if(typeof e==`string`&&t&&typeof t.as==`string`){var n=t.as,r=c(n,t.crossOrigin),a=typeof t.integrity==`string`?t.integrity:void 0,o=typeof t.fetchPriority==`string`?t.fetchPriority:void 0;n===`style`?i.d.S(e,typeof t.precedence==`string`?t.precedence:void 0,{crossOrigin:r,integrity:a,fetchPriority:o}):n===`script`&&i.d.X(e,{crossOrigin:r,integrity:a,fetchPriority:o,nonce:typeof t.nonce==`string`?t.nonce:void 0})}},e.preinitModule=function(e,t){if(typeof e==`string`){if(typeof t==`object`&&t){if(t.as==null||t.as===`script`){var n=c(t.as,t.crossOrigin);i.d.M(e,{crossOrigin:n,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0})}}else t??i.d.M(e)}},e.preload=function(e,t){if(typeof e==`string`&&typeof t==`object`&&t&&typeof t.as==`string`){var n=t.as,r=c(n,t.crossOrigin);i.d.L(e,n,{crossOrigin:r,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0,type:typeof t.type==`string`?t.type:void 0,fetchPriority:typeof t.fetchPriority==`string`?t.fetchPriority:void 0,referrerPolicy:typeof t.referrerPolicy==`string`?t.referrerPolicy:void 0,imageSrcSet:typeof t.imageSrcSet==`string`?t.imageSrcSet:void 0,imageSizes:typeof t.imageSizes==`string`?t.imageSizes:void 0,media:typeof t.media==`string`?t.media:void 0})}},e.preloadModule=function(e,t){if(typeof e==`string`){if(t){var n=c(t.as,t.crossOrigin);i.d.m(e,{as:typeof t.as==`string`&&t.as!==`script`?t.as:void 0,crossOrigin:n,integrity:typeof t.integrity==`string`?t.integrity:void 0})}else i.d.m(e)}},e.requestFormReset=function(e){i.d.r(e)},e.unstable_batchedUpdates=function(e,t){return e(t)},e.useFormState=function(e,t,n){return s.H.useFormState(e,t,n)},e.useFormStatus=function(){return s.H.useHostTransitionStatus()},e.version=`19.2.8`})),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){var t=e,n=e;if(e.alternate)for(;t.return;)t=t.return;else{e=t;do t=e,t.flags&4098&&(n=t.return),e=t.return;while(e)}return t.tag===3?n:null}function s(e){if(e.tag===13){var t=e.memoizedState;if(t===null&&(e=e.alternate,e!==null&&(t=e.memoizedState)),t!==null)return t.dehydrated}return null}function c(e){if(e.tag===31){var t=e.memoizedState;if(t===null&&(e=e.alternate,e!==null&&(t=e.memoizedState)),t!==null)return t.dehydrated}return null}function l(e){if(o(e)!==e)throw Error(i(188))}function u(e){var t=e.alternate;if(!t){if(t=o(e),t===null)throw Error(i(188));return t===e?e:null}for(var n=e,r=t;;){var a=n.return;if(a===null)break;var s=a.alternate;if(s===null){if(r=a.return,r!==null){n=r;continue}break}if(a.child===s.child){for(s=a.child;s;){if(s===n)return l(a),e;if(s===r)return l(a),t;s=s.sibling}throw Error(i(188))}if(n.return!==r.return)n=a,r=s;else{for(var c=!1,u=a.child;u;){if(u===n){c=!0,n=a,r=s;break}if(u===r){c=!0,r=a,n=s;break}u=u.sibling}if(!c){for(u=s.child;u;){if(u===n){c=!0,n=s,r=a;break}if(u===r){c=!0,r=s,n=a;break}u=u.sibling}if(!c)throw Error(i(189))}}if(n.alternate!==r)throw Error(i(190))}if(n.tag!==3)throw Error(i(188));return n.stateNode.current===n?e:t}function f(e){var t=e.tag;if(t===5||t===26||t===27||t===6)return e;for(e=e.child;e!==null;){if(t=f(e),t!==null)return t;e=e.sibling}return null}var m=Object.assign,g=Symbol.for(`react.element`),_=Symbol.for(`react.transitional.element`),v=Symbol.for(`react.portal`),y=Symbol.for(`react.fragment`),b=Symbol.for(`react.strict_mode`),x=Symbol.for(`react.profiler`),S=Symbol.for(`react.consumer`),C=Symbol.for(`react.context`),w=Symbol.for(`react.forward_ref`),T=Symbol.for(`react.suspense`),E=Symbol.for(`react.suspense_list`),D=Symbol.for(`react.memo`),O=Symbol.for(`react.lazy`),ee=Symbol.for(`react.activity`),te=Symbol.for(`react.memo_cache_sentinel`),ne=Symbol.iterator;function k(e){return typeof e!=`object`||!e?null:(e=ne&&e[ne]||e[`@@iterator`],typeof e==`function`?e:null)}var re=Symbol.for(`react.client.reference`);function A(e){if(e==null)return null;if(typeof e==`function`)return e.$$typeof===re?null:e.displayName||e.name||null;if(typeof e==`string`)return e;switch(e){case y:return`Fragment`;case x:return`Profiler`;case b:return`StrictMode`;case T:return`Suspense`;case E:return`SuspenseList`;case ee:return`Activity`}if(typeof e==`object`)switch(e.$$typeof){case v:return`Portal`;case C:return e.displayName||`Context`;case S:return(e._context.displayName||`Context`)+`.Consumer`;case w:var t=e.render;return e=e.displayName,e||=(e=t.displayName||t.name||``,e===``?`ForwardRef`:`ForwardRef(`+e+`)`),e;case D:return t=e.displayName||null,t===null?A(e.type)||`Memo`:t;case O:t=e._payload,e=e._init;try{return A(e(t))}catch{}}return null}var ie=Array.isArray,j=n.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,M=r.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,ae={pending:!1,data:null,method:null,action:null},N=[],oe=-1;function se(e){return{current:e}}function ce(e){0>oe||(e.current=N[oe],N[oe]=null,oe--)}function P(e,t){oe++,N[oe]=e.current,e.current=t}var le=se(null),ue=se(null),de=se(null),fe=se(null);function pe(e,t){switch(P(de,t),P(ue,e),P(le,null),t.nodeType){case 9:case 11:e=(e=t.documentElement)&&(e=e.namespaceURI)?Vd(e):0;break;default:if(e=t.tagName,t=t.namespaceURI)t=Vd(t),e=Hd(t,e);else switch(e){case`svg`:e=1;break;case`math`:e=2;break;default:e=0}}ce(le),P(le,e)}function F(){ce(le),ce(ue),ce(de)}function me(e){e.memoizedState!==null&&P(fe,e);var t=le.current,n=Hd(t,e.type);t!==n&&(P(ue,e),P(le,n))}function I(e){ue.current===e&&(ce(le),ce(ue)),fe.current===e&&(ce(fe),Qf._currentValue=ae)}var he,ge;function _e(e){if(he===void 0)try{throw Error()}catch(e){var t=e.stack.trim().match(/\n( *(at )?)/);he=t&&t[1]||``,ge=-1<e.stack.indexOf(`
3
3
  at`)?` (<anonymous>)`:-1<e.stack.indexOf(`@`)?`@unknown:0:0`:``}return`
4
4
  `+he+e+ge}var ve=!1;function ye(e,t){if(!e||ve)return``;ve=!0;var n=Error.prepareStackTrace;Error.prepareStackTrace=void 0;try{var r={DetermineComponentFrameRoot:function(){try{if(t){var n=function(){throw Error()};if(Object.defineProperty(n.prototype,"props",{set:function(){throw Error()}}),typeof Reflect==`object`&&Reflect.construct){try{Reflect.construct(n,[])}catch(e){var r=e}Reflect.construct(e,[],n)}else{try{n.call()}catch(e){r=e}e.call(n.prototype)}}else{try{throw Error()}catch(e){r=e}(n=e())&&typeof n.catch==`function`&&n.catch(function(){})}}catch(e){if(e&&r&&typeof e.stack==`string`)return[e.stack,r.stack]}return[null,null]}};r.DetermineComponentFrameRoot.displayName=`DetermineComponentFrameRoot`;var i=Object.getOwnPropertyDescriptor(r.DetermineComponentFrameRoot,`name`);i&&i.configurable&&Object.defineProperty(r.DetermineComponentFrameRoot,"name",{value:`DetermineComponentFrameRoot`});var a=r.DetermineComponentFrameRoot(),o=a[0],s=a[1];if(o&&s){var c=o.split(`
@@ -74,17 +74,17 @@ ${e}</tr>
74
74
  Please report this to https://github.com/markedjs/marked.`,e){let e=`<p>An error occurred:</p><pre>`+Vt(n.message+``,!0)+`</pre>`;return t?Promise.resolve(e):e}if(t)return Promise.reject(n);throw n}}};function z(e,t){return nn.parse(e,t)}z.options=z.setOptions=function(e){return nn.setOptions(e),z.defaults=nn.defaults,we(z.defaults),z},z.getDefaults=Se,z.defaults=Ce;function rn(...e){return nn.use(...e),z.defaults=nn.defaults,we(z.defaults),z}z.use=rn,z.walkTokens=function(e,t){return nn.walkTokens(e,t)},z.parseInline=nn.parseInline,z.Parser=en,z.parser=en.parse,z.Renderer=Qt,z.TextRenderer=$t,z.Lexer=Zt,z.lexer=Zt.lex,z.Tokenizer=Xt,z.Hooks=tn,z.parse=z,z.options,z.setOptions,z.walkTokens,z.parseInline,en.parse,Zt.lex;function an(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function on(e){if(Array.isArray(e))return e}function sn(e,t){var n=e==null?null:typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n!=null){var r,i,a,o,s=[],c=!0,l=!1;try{if(a=(n=n.call(e)).next,t!==0)for(;!(c=(r=a.call(n)).done)&&(s.push(r.value),s.length!==t);c=!0);}catch(e){l=!0,i=e}finally{try{if(!c&&n.return!=null&&(o=n.return(),Object(o)!==o))return}finally{if(l)throw i}}return s}}function cn(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
75
75
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function ln(e,t){return on(e)||sn(e,t)||un(e,t)||cn()}function un(e,t){if(e){if(typeof e==`string`)return an(e,t);var n={}.toString.call(e).slice(8,-1);return n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`?Array.from(e):n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?an(e,t):void 0}}var dn=Object.entries,fn=Object.setPrototypeOf,pn=Object.isFrozen,mn=Object.getPrototypeOf,hn=Object.getOwnPropertyDescriptor,gn=Object.freeze,_n=Object.seal,vn=Object.create,yn=typeof Reflect<`u`&&Reflect,bn=yn.apply,xn=yn.construct;gn||=function(e){return e},_n||=function(e){return e},bn||=function(e,t){var n=[...arguments].slice(2);return e.apply(t,n)},xn||=function(e){return new e(...[...arguments].slice(1))};var Sn=Hn(Array.prototype.forEach),Cn=Hn(Array.prototype.lastIndexOf),wn=Hn(Array.prototype.pop),Tn=Hn(Array.prototype.push),En=Hn(Array.prototype.splice),Dn=Array.isArray,On=Hn(String.prototype.toLowerCase),kn=Hn(String.prototype.toString),An=Hn(String.prototype.match),jn=Hn(String.prototype.replace),Mn=Hn(String.prototype.indexOf),Nn=Hn(String.prototype.trim),Pn=Hn(Number.prototype.toString),Fn=Hn(Boolean.prototype.toString),In=typeof BigInt>`u`?null:Hn(BigInt.prototype.toString),Ln=typeof Symbol>`u`?null:Hn(Symbol.prototype.toString),Rn=Hn(Object.prototype.hasOwnProperty),zn=Hn(Object.prototype.toString),Bn=Hn(RegExp.prototype.test),Vn=Un(TypeError);function Hn(e){return function(t){t instanceof RegExp&&(t.lastIndex=0);var n=[...arguments].slice(1);return bn(e,t,n)}}function Un(e){return function(){return xn(e,[...arguments])}}function B(e,t){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:On;if(fn&&fn(e,null),!Dn(t))return e;let r=t.length;for(;r--;){let i=t[r];if(typeof i==`string`){let e=n(i);e!==i&&(pn(t)||(t[r]=e),i=e)}e[i]=!0}return e}function Wn(e){for(let t=0;t<e.length;t++)Rn(e,t)||(e[t]=null);return e}function Gn(e){let t=vn(null);for(let r of dn(e)){var n=ln(r,2);let i=n[0],a=n[1];Rn(e,i)&&(t[i]=Dn(a)?Wn(a):a&&typeof a==`object`&&a.constructor===Object?Gn(a):a)}return t}function Kn(e){switch(typeof e){case`string`:return e;case`number`:return Pn(e);case`boolean`:return Fn(e);case`bigint`:return In?In(e):`0`;case`symbol`:return Ln?Ln(e):`Symbol()`;case`undefined`:return zn(e);case`function`:case`object`:{if(e===null)return zn(e);let t=e,n=qn(t,`toString`);if(typeof n==`function`){let e=n(t);return typeof e==`string`?e:zn(e)}return zn(e)}default:return zn(e)}}function qn(e,t){for(;e!==null;){let n=hn(e,t);if(n){if(n.get)return Hn(n.get);if(typeof n.value==`function`)return Hn(n.value)}e=mn(e)}function n(){return null}return n}function Jn(e){try{return Bn(e,``),!0}catch{return!1}}var Yn=gn(`a.abbr.acronym.address.area.article.aside.audio.b.bdi.bdo.big.blink.blockquote.body.br.button.canvas.caption.center.cite.code.col.colgroup.content.data.datalist.dd.decorator.del.details.dfn.dialog.dir.div.dl.dt.element.em.fieldset.figcaption.figure.font.footer.form.h1.h2.h3.h4.h5.h6.head.header.hgroup.hr.html.i.img.input.ins.kbd.label.legend.li.main.map.mark.marquee.menu.menuitem.meter.nav.nobr.ol.optgroup.option.output.p.picture.pre.progress.q.rp.rt.ruby.s.samp.search.section.select.shadow.slot.small.source.spacer.span.strike.strong.style.sub.summary.sup.table.tbody.td.template.textarea.tfoot.th.thead.time.tr.track.tt.u.ul.var.video.wbr`.split(`.`)),Xn=gn(`svg.a.altglyph.altglyphdef.altglyphitem.animatecolor.animatemotion.animatetransform.circle.clippath.defs.desc.ellipse.enterkeyhint.exportparts.filter.font.g.glyph.glyphref.hkern.image.inputmode.line.lineargradient.marker.mask.metadata.mpath.part.path.pattern.polygon.polyline.radialgradient.rect.stop.style.switch.symbol.text.textpath.title.tref.tspan.view.vkern`.split(`.`)),Zn=gn([`feBlend`,`feColorMatrix`,`feComponentTransfer`,`feComposite`,`feConvolveMatrix`,`feDiffuseLighting`,`feDisplacementMap`,`feDistantLight`,`feDropShadow`,`feFlood`,`feFuncA`,`feFuncB`,`feFuncG`,`feFuncR`,`feGaussianBlur`,`feImage`,`feMerge`,`feMergeNode`,`feMorphology`,`feOffset`,`fePointLight`,`feSpecularLighting`,`feSpotLight`,`feTile`,`feTurbulence`]),Qn=gn([`animate`,`color-profile`,`cursor`,`discard`,`font-face`,`font-face-format`,`font-face-name`,`font-face-src`,`font-face-uri`,`foreignobject`,`hatch`,`hatchpath`,`mesh`,`meshgradient`,`meshpatch`,`meshrow`,`missing-glyph`,`script`,`set`,`solidcolor`,`unknown`,`use`]),$n=gn(`math.menclose.merror.mfenced.mfrac.mglyph.mi.mlabeledtr.mmultiscripts.mn.mo.mover.mpadded.mphantom.mroot.mrow.ms.mspace.msqrt.mstyle.msub.msup.msubsup.mtable.mtd.mtext.mtr.munder.munderover.mprescripts`.split(`.`)),er=gn([`maction`,`maligngroup`,`malignmark`,`mlongdiv`,`mscarries`,`mscarry`,`msgroup`,`mstack`,`msline`,`msrow`,`semantics`,`annotation`,`annotation-xml`,`mprescripts`,`none`]),tr=gn([`#text`]),nr=gn(`accept.action.align.alt.autocapitalize.autocomplete.autopictureinpicture.autoplay.background.bgcolor.border.capture.cellpadding.cellspacing.checked.cite.class.clear.color.cols.colspan.command.commandfor.controls.controlslist.coords.crossorigin.datetime.decoding.default.dir.disabled.disablepictureinpicture.disableremoteplayback.download.draggable.enctype.enterkeyhint.exportparts.face.for.headers.height.hidden.high.href.hreflang.id.inert.inputmode.integrity.ismap.kind.label.lang.list.loading.loop.low.max.maxlength.media.method.min.minlength.multiple.muted.name.nonce.noshade.novalidate.nowrap.open.optimum.part.pattern.placeholder.playsinline.popover.popovertarget.popovertargetaction.poster.preload.pubdate.radiogroup.readonly.rel.required.rev.reversed.role.rows.rowspan.spellcheck.scope.selected.shape.size.sizes.slot.span.srclang.start.src.srcset.step.style.summary.tabindex.title.translate.type.usemap.valign.value.width.wrap.xmlns`.split(`.`)),rr=gn(`accent-height.accumulate.additive.alignment-baseline.amplitude.ascent.attributename.attributetype.azimuth.basefrequency.baseline-shift.begin.bias.by.class.clip.clippathunits.clip-path.clip-rule.color.color-interpolation.color-interpolation-filters.color-profile.color-rendering.cx.cy.d.dx.dy.diffuseconstant.direction.display.divisor.dominant-baseline.dur.edgemode.elevation.end.exponent.fill.fill-opacity.fill-rule.filter.filterunits.flood-color.flood-opacity.font-family.font-size.font-size-adjust.font-stretch.font-style.font-variant.font-weight.fx.fy.g1.g2.glyph-name.glyphref.gradientunits.gradienttransform.height.href.id.image-rendering.in.in2.intercept.k.k1.k2.k3.k4.kerning.keypoints.keysplines.keytimes.lang.lengthadjust.letter-spacing.kernelmatrix.kernelunitlength.lighting-color.local.marker-end.marker-mid.marker-start.markerheight.markerunits.markerwidth.maskcontentunits.maskunits.max.mask.mask-type.media.method.mode.min.name.numoctaves.offset.operator.opacity.order.orient.orientation.origin.overflow.paint-order.path.pathlength.patterncontentunits.patterntransform.patternunits.pointer-events.points.preservealpha.preserveaspectratio.primitiveunits.r.rx.ry.radius.refx.refy.repeatcount.repeatdur.restart.result.rotate.scale.seed.shape-rendering.slope.specularconstant.specularexponent.spreadmethod.startoffset.stddeviation.stitchtiles.stop-color.stop-opacity.stroke-dasharray.stroke-dashoffset.stroke-linecap.stroke-linejoin.stroke-miterlimit.stroke-opacity.stroke.stroke-width.style.surfacescale.systemlanguage.tabindex.tablevalues.targetx.targety.transform.transform-origin.text-anchor.text-decoration.text-orientation.text-rendering.textlength.type.u1.u2.unicode.values.vector-effect.viewbox.visibility.version.vert-adv-y.vert-origin-x.vert-origin-y.width.word-spacing.wrap.writing-mode.xchannelselector.ychannelselector.x.x1.x2.xmlns.y.y1.y2.z.zoomandpan`.split(`.`)),ir=gn(`accent.accentunder.align.bevelled.close.columnalign.columnlines.columnspacing.columnspan.denomalign.depth.dir.display.displaystyle.encoding.fence.frame.height.href.id.largeop.length.linethickness.lquote.lspace.mathbackground.mathcolor.mathsize.mathvariant.maxsize.minsize.movablelimits.notation.numalign.open.rowalign.rowlines.rowspacing.rowspan.rspace.rquote.scriptlevel.scriptminsize.scriptsizemultiplier.selection.separator.separators.stretchy.subscriptshift.supscriptshift.symmetric.voffset.width.xmlns`.split(`.`)),ar=gn([`xlink:href`,`xml:id`,`xlink:title`,`xml:space`,`xmlns:xlink`]),or=_n(/{{[\w\W]*|^[\w\W]*}}/g),sr=_n(/<%[\w\W]*|^[\w\W]*%>/g),cr=_n(/\${[\w\W]*/g),lr=_n(/^data-[\-\w.\u00B7-\uFFFF]+$/),ur=_n(/^aria-[\-\w]+$/),dr=_n(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),fr=_n(/^(?:\w+script|data):/i),pr=_n(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),mr=_n(/^html$/i),hr=_n(/^[a-z][.\w]*(-[.\w]+)+$/i),gr=_n(/<[/\w!]/g),_r=_n(/<[/\w]/g),vr=_n(/<\/no(script|embed|frames)/i),yr=_n(/\/>/i),V={element:1,attribute:2,text:3,cdataSection:4,entityReference:5,entityNode:6,processingInstruction:7,comment:8,document:9,documentType:10,documentFragment:11,notation:12},br=[`style`,`script`,`xmp`,`iframe`,`noembed`,`noframes`,`plaintext`,`noscript`],xr=gn(B({},br)),Sr=function(){let e={};return Sn(br,t=>{e[t]=_n(RegExp(`</`+t+`(?=[\\t\\n\\f\\r />])`,`i`))}),gn(e)}(),Cr=function(){return typeof window>`u`?null:window},wr=function(e,t){if(typeof e!=`object`||typeof e.createPolicy!=`function`)return null;let n=null,r=`data-tt-policy-suffix`;t&&t.hasAttribute(r)&&(n=t.getAttribute(r));let i=`dompurify`+(n?`#`+n:``);try{return e.createPolicy(i,{createHTML(e){return e},createScriptURL(e){return e}})}catch{return console.warn(`TrustedTypes policy `+i+` could not be created.`),null}},Tr=function(){return{afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}},Er=function(e,t,n,r){return Rn(e,t)&&Dn(e[t])?B(r.base?Gn(r.base):{},e[t],r.transform):n},Dr=function(e,t,n){let r=Rn(e,t)?e[t]:void 0;return r&&typeof r==`object`?Gn(r):n()};function Or(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:Cr(),t=e=>Or(e);if(t.version=`3.4.14`,t.removed=[],!e||!e.document||e.document.nodeType!==V.document||!e.Element)return t.isSupported=!1,t;let n=e.document,r=n,i=r.currentScript;e.DocumentFragment;let a=e.HTMLTemplateElement,o=e.Node,s=e.Element,c=e.NodeFilter;e.NamedNodeMap===void 0&&(e.NamedNodeMap||e.MozNamedAttrMap),e.HTMLFormElement;let l=e.DOMParser,u=e.trustedTypes,d=s.prototype,f=qn(d,`cloneNode`),p=qn(d,`remove`),m=qn(d,`nextSibling`),h=qn(d,`childNodes`),g=qn(d,`parentNode`),_=qn(d,`shadowRoot`),v=qn(d,`attributes`),y=o&&o.prototype?qn(o.prototype,`nodeType`):null,b=o&&o.prototype?qn(o.prototype,`nodeName`):null,x=o&&o.prototype?qn(o.prototype,`ownerDocument`):null,S=function(e){return y?y(e):e.nodeType},C=function(e){return b?b(e):e.nodeName};if(typeof a==`function`){let e=n.createElement(`template`);e.content&&e.content.ownerDocument&&(n=e.content.ownerDocument)}let w,T=``,E,D=!1,O=0,ee=function(){if(O>0)throw Vn(`A configured TRUSTED_TYPES_POLICY callback (createHTML or createScriptURL) must not call DOMPurify.sanitize, as that causes infinite recursion. Do not pass a policy whose callbacks wrap DOMPurify as TRUSTED_TYPES_POLICY; see the "DOMPurify and Trusted Types" section of the README.`)},te=function(e){ee(),O++;try{return w.createHTML(e)}finally{O--}},ne=function(e){ee(),O++;try{return w.createScriptURL(e)}finally{O--}},k=function(){return D||=(E=wr(u,i),!0),E},re=n,A=re.implementation,ie=re.createNodeIterator,j=re.createDocumentFragment,M=re.getElementsByTagName,ae=r.importNode,N=Tr();t.isSupported=typeof dn==`function`&&typeof g==`function`&&A&&A.createHTMLDocument!==void 0;let oe=or,se=sr,ce=cr,P=lr,le=ur,ue=fr,de=pr,fe=hr,pe=dr,F=null,me=B({},[...Yn,...Xn,...Zn,...$n,...tr]),I=null,he=B({},[...nr,...rr,...ir,...ar]),ge=Object.seal(vn(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),_e=null,ve=null,ye=Object.seal(vn(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}})),be=!0,xe=!0,Se=!1,Ce=!0,we=!1,Te=!0,Ee=!1,L=!1,De=null,Oe=null,ke=!1,Ae=!1,je=!1,Me=!1,Ne=!0,Pe=!1,Fe=`user-content-`,Ie=!0,Le=!1,Re={},ze=null,Be=B({},`annotation-xml.audio.colgroup.desc.foreignobject.head.iframe.math.mi.mn.mo.ms.mtext.noembed.noframes.noscript.plaintext.script.selectedcontent.style.svg.template.thead.title.video.xmp`.split(`.`)),Ve=null,He=B({},[`audio`,`video`,`img`,`source`,`image`,`track`]),Ue=null,We=B({},[`alt`,`class`,`for`,`id`,`label`,`name`,`pattern`,`placeholder`,`role`,`summary`,`title`,`value`,`style`,`xmlns`]),Ge=`http://www.w3.org/1998/Math/MathML`,Ke=`http://www.w3.org/2000/svg`,qe=`http://www.w3.org/1999/xhtml`,Je=qe,Ye=!1,Xe=null,Ze=B({},[Ge,Ke,qe],kn),Qe=gn([`mi`,`mo`,`mn`,`ms`,`mtext`]),$e=B({},Qe),et=gn([`annotation-xml`]),tt=B({},et),nt=B({},[`title`,`style`,`font`,`a`,`script`]),rt=null,it=[`application/xhtml+xml`,`text/html`],R=null,at=null,ot=n.createElement(`form`),st=function(e){return e instanceof RegExp||e instanceof Function},ct=function(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(at&&at===e)return;(!e||typeof e!=`object`)&&(e={}),e=Gn(e),rt=it.indexOf(e.PARSER_MEDIA_TYPE)===-1?`text/html`:e.PARSER_MEDIA_TYPE,R=rt===`application/xhtml+xml`?kn:On,F=Er(e,`ALLOWED_TAGS`,me,{transform:R}),I=Er(e,`ALLOWED_ATTR`,he,{transform:R}),Xe=Er(e,`ALLOWED_NAMESPACES`,Ze,{transform:kn}),Ue=Er(e,`ADD_URI_SAFE_ATTR`,We,{transform:R,base:We}),Ve=Er(e,`ADD_DATA_URI_TAGS`,He,{transform:R,base:He}),ze=Er(e,`FORBID_CONTENTS`,Be,{transform:R}),_e=Er(e,`FORBID_TAGS`,Gn({}),{transform:R}),ve=Er(e,`FORBID_ATTR`,Gn({}),{transform:R}),Re=Rn(e,`USE_PROFILES`)?e.USE_PROFILES&&typeof e.USE_PROFILES==`object`?Gn(e.USE_PROFILES):e.USE_PROFILES:!1,be=e.ALLOW_ARIA_ATTR!==!1,xe=e.ALLOW_DATA_ATTR!==!1,Se=e.ALLOW_UNKNOWN_PROTOCOLS||!1,Ce=e.ALLOW_SELF_CLOSE_IN_ATTR!==!1,we=e.SAFE_FOR_TEMPLATES||!1,Te=e.SAFE_FOR_XML!==!1,Ee=e.WHOLE_DOCUMENT||!1,Ae=e.RETURN_DOM||!1,je=e.RETURN_DOM_FRAGMENT||!1,Me=e.RETURN_TRUSTED_TYPE||!1,ke=e.FORCE_BODY||!1,Ne=e.SANITIZE_DOM!==!1,Pe=e.SANITIZE_NAMED_PROPS||!1,Ie=e.KEEP_CONTENT!==!1,Le=e.IN_PLACE||!1,pe=Jn(e.ALLOWED_URI_REGEXP)?e.ALLOWED_URI_REGEXP:dr,Je=typeof e.NAMESPACE==`string`?e.NAMESPACE:qe,$e=Dr(e,`MATHML_TEXT_INTEGRATION_POINTS`,()=>B({},Qe)),tt=Dr(e,`HTML_INTEGRATION_POINTS`,()=>B({},et));let t=Dr(e,`CUSTOM_ELEMENT_HANDLING`,()=>vn(null));if(ge=vn(null),Rn(t,`tagNameCheck`)&&st(t.tagNameCheck)&&(ge.tagNameCheck=t.tagNameCheck),Rn(t,`attributeNameCheck`)&&st(t.attributeNameCheck)&&(ge.attributeNameCheck=t.attributeNameCheck),Rn(t,`allowCustomizedBuiltInElements`)&&typeof t.allowCustomizedBuiltInElements==`boolean`&&(ge.allowCustomizedBuiltInElements=t.allowCustomizedBuiltInElements),_n(ge),we&&(xe=!1),je&&(Ae=!0),Re&&(F=B({},tr),I=vn(null),Re.html===!0&&(B(F,Yn),B(I,nr)),Re.svg===!0&&(B(F,Xn),B(I,rr),B(I,ar)),Re.svgFilters===!0&&(B(F,Zn),B(I,rr),B(I,ar)),Re.mathMl===!0&&(B(F,$n),B(I,ir),B(I,ar))),ye.tagCheck=null,ye.attributeCheck=null,Rn(e,`ADD_TAGS`)&&(typeof e.ADD_TAGS==`function`?ye.tagCheck=e.ADD_TAGS:Dn(e.ADD_TAGS)&&(F===me&&(F=Gn(F)),B(F,e.ADD_TAGS,R))),Rn(e,`ADD_ATTR`)&&(typeof e.ADD_ATTR==`function`?ye.attributeCheck=e.ADD_ATTR:Dn(e.ADD_ATTR)&&(I===he&&(I=Gn(I)),B(I,e.ADD_ATTR,R))),Rn(e,`ADD_FORBID_CONTENTS`)&&Dn(e.ADD_FORBID_CONTENTS)&&(ze===Be&&(ze=Gn(ze)),B(ze,e.ADD_FORBID_CONTENTS,R)),Ie&&(F[`#text`]=!0),Ee&&B(F,[`html`,`head`,`body`]),F.table&&(B(F,[`tbody`]),delete _e.tbody),e.TRUSTED_TYPES_POLICY){if(typeof e.TRUSTED_TYPES_POLICY.createHTML!=`function`)throw Vn(`TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.`);if(typeof e.TRUSTED_TYPES_POLICY.createScriptURL!=`function`)throw Vn(`TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.`);let t=w;w=e.TRUSTED_TYPES_POLICY;try{T=te(``)}catch(e){throw w=t,e}}else e.TRUSTED_TYPES_POLICY===null?(w=void 0,T=``):(w===void 0&&(w=k()),w&&typeof T==`string`&&(T=te(``)));gn&&gn(e),at=e},lt=B({},[...Xn,...Zn,...Qn]),ut=B({},[...$n,...er]),dt=function(e,t,n){return t.namespaceURI===qe?e===`svg`:t.namespaceURI===Ge?e===`svg`&&(n===`annotation-xml`||$e[n]):!!lt[e]},ft=function(e,t,n){return t.namespaceURI===qe?e===`math`:t.namespaceURI===Ke?e===`math`&&tt[n]:!!ut[e]},pt=function(e,t,n){return t.namespaceURI===Ke&&!tt[n]||t.namespaceURI===Ge&&!$e[n]?!1:!ut[e]&&(nt[e]||!lt[e])},mt=function(e){let t=g(e);(!t||!t.tagName)&&(t={namespaceURI:Je,tagName:`template`});let n=On(e.tagName),r=On(t.tagName);return Xe[e.namespaceURI]?e.namespaceURI===Ke?dt(n,t,r):e.namespaceURI===Ge?ft(n,t,r):e.namespaceURI===qe?pt(n,t,r):!!(rt===`application/xhtml+xml`&&Xe[e.namespaceURI]):!1},ht=function(e){Tn(t.removed,{element:e});try{g(e).removeChild(e)}catch{if(p(e),!g(e))throw Vn(`a node selected for removal could not be detached from its tree and cannot be safely returned; refusing to sanitize in place`)}},gt=function(e,t,n){try{e.removeAttributeNode(t)}catch{try{e.removeAttribute(n)}catch{}}},_t=function(e){bt(e);let t=h(e);if(t){let e=[];Sn(t,t=>{Tn(e,t)}),Sn(e,e=>{try{p(e)}catch{}})}let n=v(e);if(n)for(let t=n.length-1;t>=0;--t){let r=n[t],i=r&&r.name;typeof i==`string`&&gt(e,r,i)}},vt=function(e,n,r){if(!r)try{r=n.getAttributeNode(e)}catch{r=null}Tn(t.removed,{attribute:r||null,from:n});try{r?n.removeAttributeNode(r):n.removeAttribute(e)}catch{try{n.removeAttribute(e)}catch{}}if(e===`is`){if(Ae||je)try{ht(n)}catch{}else try{n.setAttribute(e,``)}catch{}}},yt=function(e){let t=v(e);if(t)for(let n=t.length-1;n>=0;--n){let r=t[n],i=r&&r.name;typeof i!=`string`||I[R(i)]||gt(e,r,i)}},bt=function(e){let t=[e];for(;t.length>0;){let e=t.pop();S(e)===V.element&&yt(e);let n=h(e);if(n)for(let e=n.length-1;e>=0;--e)t.push(n[e])}},xt=function(e,t){return Te?e===`patchsrc`||e===`for`&&t!==`label`&&t!==`output`:!1},St=function(e){if(!Te)return;let t=[e];for(;t.length>0;){let e=t.pop(),n=S(e);if(n===V.processingInstruction||n===V.comment&&Bn(_r,e.data)){try{p(e)}catch{}continue}if(n===V.element){let t=e,n=R(C(e));try{t.hasAttribute&&t.hasAttribute(`patchsrc`)&&t.removeAttribute(`patchsrc`),t.hasAttribute&&t.hasAttribute(`for`)&&xt(`for`,n)&&t.removeAttribute(`for`)}catch{}}let r=h(e);if(r)for(let e=r.length-1;e>=0;--e)t.push(r[e])}},Ct=function(e){let t=null,r=null;if(ke)e=`<remove></remove>`+e;else{let t=An(e,/^[\r\n\t ]+/);r=t&&t[0]}rt===`application/xhtml+xml`&&Je===qe&&(e=`<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>`+e+`</body></html>`);let i=w?te(e):e;if(Je===qe)try{t=new l().parseFromString(i,rt)}catch{}if(!t||!t.documentElement){t=A.createDocument(Je,`template`,null);try{t.documentElement.innerHTML=Ye?T:i}catch{}}let a=t.body||t.documentElement;return e&&r&&a.insertBefore(n.createTextNode(r),a.childNodes[0]||null),Je===qe?M.call(t,Ee?`html`:`body`)[0]:Ee?t.documentElement:a},wt=function(e){let t=x?x(e):e.ownerDocument;return ie.call(t||e,e,c.SHOW_ELEMENT|c.SHOW_COMMENT|c.SHOW_TEXT|c.SHOW_PROCESSING_INSTRUCTION|c.SHOW_CDATA_SECTION,null)},Tt=function(e){return e=jn(e,oe,` `),e=jn(e,se,` `),e=jn(e,ce,` `),e},Et=function(e){e.normalize();let t=x?x(e):e.ownerDocument,n=ie.call(t||e,e,c.SHOW_TEXT|c.SHOW_COMMENT|c.SHOW_CDATA_SECTION|c.SHOW_PROCESSING_INSTRUCTION,null),r=n.nextNode();for(;r;)r.data=Tt(r.data),r=n.nextNode();let i=e.querySelectorAll?.call(e,`template`);i&&Sn(i,e=>{Ot(e.content)&&Et(e.content)})},Dt=function(e){let t=b?b(e):null;return typeof t!=`string`||R(t)!==`form`?!1:typeof e.nodeName!=`string`||typeof e.textContent!=`string`||typeof e.removeChild!=`function`||e.attributes!==v(e)||typeof e.removeAttribute!=`function`||typeof e.setAttribute!=`function`||typeof e.namespaceURI!=`string`||typeof e.insertBefore!=`function`||typeof e.hasChildNodes!=`function`||e.nodeType!==y(e)||e.childNodes!==h(e)},Ot=function(e){if(!y||typeof e!=`object`||!e)return!1;try{return y(e)===V.documentFragment}catch{return!1}},kt=function(e){if(!y||typeof e!=`object`||!e)return!1;try{return typeof y(e)==`number`}catch{return!1}};function At(e,n,r){e.length!==0&&Sn(e,e=>{e.call(t,n,r,at)})}let jt=function(e,t){return!!(Te&&e.hasChildNodes()&&!kt(e.firstElementChild)&&Bn(gr,e.textContent)&&Bn(gr,e.innerHTML)||Te&&e.namespaceURI===qe&&xr[t]&&(kt(e.firstElementChild)||typeof e.textContent==`string`&&Bn(Sr[t],e.textContent))||e.nodeType===V.processingInstruction||Te&&e.nodeType===V.comment&&Bn(_r,e.data))},Mt=function(e,t){return e instanceof RegExp?Bn(e,t):e instanceof Function&&!!e(t,...[...arguments].slice(2))},Nt=function(e,t,n){if(!_e[t]&&zt(t)&&Mt(ge.tagNameCheck,t))return!1;if(Ie&&!ze[t]){let t=g(e),r=h(e);if(r&&t){let i=r.length;for(let a=i-1;a>=0;--a){let i=e===n?f(r[a],!0):r[a];t.insertBefore(i,m(e))}}}return ht(e),!0},Pt=function(e,t,n,r){return e.length===0?t:t===n||t===r?Gn(t):t},Ft=function(e,t){return e===t||g(e)!==null?!1:(Le&&bt(e),!0)},It=function(e,n){if(At(N.beforeSanitizeElements,e,null),Ft(e,n))return!0;if(Dt(e))return ht(e),!0;let r=R(C(e));if(F=Pt(N.uponSanitizeElement,F,me,De),At(N.uponSanitizeElement,e,{tagName:r,allowedTags:F}),Ft(e,n))return!0;if(jt(e,r))return ht(e),!0;if(_e[r]||!(ye.tagCheck instanceof Function&&ye.tagCheck(r))&&!F[r]){let t=Nt(e,r,n);return t===!1&&At(N.afterSanitizeElements,e,null),t}if(S(e)===V.element&&!mt(e)||(r===`noscript`||r===`noembed`||r===`noframes`)&&Bn(vr,e.innerHTML))return ht(e),!0;if(we&&e.nodeType===V.text){let n=Tt(e.textContent);e.textContent!==n&&(Tn(t.removed,{element:e.cloneNode()}),e.textContent=n)}return At(N.afterSanitizeElements,e,null),!1},Lt=function(e,t,r){if(ve[t]||xt(t,e)||Ne&&(t===`id`||t===`name`)&&(r in n||r in ot))return!1;let i=I[t]||ye.attributeCheck instanceof Function&&ye.attributeCheck(t,e);return xe&&Bn(P,t)||be&&Bn(le,t)?!0:i?Ue[t]||Bn(pe,jn(r,de,``))||(t===`src`||t===`xlink:href`||t===`href`)&&e!==`script`&&Mn(r,`data:`)===0&&Ve[e]||Se&&!Bn(ue,jn(r,de,``))?!0:!r:zt(e)&&Mt(ge.tagNameCheck,e)&&Mt(ge.attributeNameCheck,t,e)||t===`is`&&ge.allowCustomizedBuiltInElements&&Mt(ge.tagNameCheck,r)},Rt=B({},[`annotation-xml`,`color-profile`,`font-face`,`font-face-format`,`font-face-name`,`font-face-src`,`font-face-uri`,`missing-glyph`]),zt=function(e){return!Rt[On(e)]&&Bn(fe,e)},Bt=function(e,t,n,r){if(w&&typeof u==`object`&&typeof u.getAttributeType==`function`&&!n)switch(u.getAttributeType(e,t)){case`TrustedHTML`:return te(r);case`TrustedScriptURL`:return ne(r)}return r},Vt=function(e,n,r,i){try{r?e.setAttributeNS(r,n,i):e.setAttribute(n,i),Dt(e)?ht(e):wn(t.removed)}catch{vt(n,e)}},Ht=function(e){At(N.beforeSanitizeAttributes,e,null);let t=e.attributes;if(!t||Dt(e))return;I=Pt(N.uponSanitizeAttribute,I,he,Oe);let n={attrName:``,attrValue:``,keepAttr:!0,allowedAttributes:I,forceKeepAttr:void 0},r=t.length,i=R(e.nodeName);for(;r--;){let a=t[r],o=a.name,s=a.namespaceURI,c=a.value,l=R(o),u=c,d=o===`value`?u:Nn(u);if(n.attrName=l,n.attrValue=d,n.keepAttr=!0,n.forceKeepAttr=void 0,At(N.uponSanitizeAttribute,e,n),d=n.attrValue,Pe&&(l===`id`||l===`name`)&&Mn(d,Fe)!==0&&(vt(o,e,a),d=Fe+d),Te&&Bn(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i,d)){vt(o,e,a);continue}if(l===`attributename`&&An(d,`href`)){vt(o,e,a);continue}if(!n.forceKeepAttr){if(!n.keepAttr){vt(o,e,a);continue}if(!Ce&&Bn(yr,d)){vt(o,e,a);continue}if(we&&(d=Tt(d)),!Lt(i,l,d)){vt(o,e,a);continue}d=Bt(i,l,s,d),d!==u&&Vt(e,o,s,d)}}At(N.afterSanitizeAttributes,e,null)},Ut=function(e){let t=null,n=wt(e);for(At(N.beforeSanitizeShadowDOM,e,null);t=n.nextNode();)if(At(N.uponSanitizeShadowNode,t,null),It(t,e),Ht(t),Ot(t.content)&&Ut(t.content),S(t)===V.element){let e=_(t);Ot(e)&&(Wt(e),Ut(e))}At(N.afterSanitizeShadowDOM,e,null)},Wt=function(e){let t=[{node:e,shadow:null}];for(;t.length>0;){let e=t.pop();if(e.shadow){Ut(e.shadow);continue}let n=e.node,r=S(n)===V.element,i=h(n);if(i)for(let e=i.length-1;e>=0;--e)t.push({node:i[e],shadow:null});if(r){let e=b?b(n):null;if(typeof e==`string`&&R(e)===`template`){let e=n.content;Ot(e)&&t.push({node:e,shadow:null})}}if(r){let e=_(n);Ot(e)&&t.push({node:null,shadow:e},{node:e,shadow:null})}}};return t.sanitize=function(e){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},i=null,a=null,o=null,s=null;if(Ye=!e,Ye&&(e=`<!-->`),typeof e!=`string`&&!kt(e)&&(e=Kn(e),typeof e!=`string`))throw Vn(`dirty is not a string, aborting`);if(!t.isSupported)return e;L?(F=De,I=Oe):ct(n),(N.uponSanitizeElement.length>0||N.uponSanitizeAttribute.length>0)&&(F=Gn(F)),N.uponSanitizeAttribute.length>0&&(I=Gn(I)),t.removed=[];let c=Le&&typeof e!=`string`&&kt(e);if(c){St(e);let t=C(e);if(typeof t==`string`){let n=R(t);if(!F[n]||_e[n])throw _t(e),Vn(`root node is forbidden and cannot be sanitized in-place`)}if(Dt(e))throw _t(e),Vn(`root node is clobbered and cannot be sanitized in-place`);try{Wt(e)}catch(t){throw _t(e),t}}else if(kt(e))i=Ct(`<!---->`),a=i.ownerDocument.importNode(e,!0),a.nodeType===V.element&&a.nodeName===`BODY`||a.nodeName===`HTML`?i=a:i.appendChild(a),Wt(a);else{if(!Ae&&!we&&!Ee&&e.indexOf(`<`)===-1)return w&&Me?te(e):e;if(i=Ct(e),!i)return Ae?null:Me?T:``}i&&ke&&ht(i.firstChild);let l=c?e:i;try{let e=wt(l);for(;o=e.nextNode();)It(o,l),Ht(o),Ot(o.content)&&Ut(o.content)}catch(n){throw c&&(_t(e),Sn(t.removed,e=>{e.element&&bt(e.element)})),n}if(c)return Sn(t.removed,e=>{e.element&&bt(e.element)}),we&&Et(e),e;if(Ae){if(we&&Et(i),je)for(s=j.call(i.ownerDocument);i.firstChild;)s.appendChild(i.firstChild);else s=i;return(I.shadowroot||I.shadowrootmode)&&(s=ae.call(r,s,!0)),s}let u=Ee?i.outerHTML:i.innerHTML;return Ee&&F[`!doctype`]&&i.ownerDocument&&i.ownerDocument.doctype&&i.ownerDocument.doctype.name&&Bn(mr,i.ownerDocument.doctype.name)&&(u=`<!DOCTYPE `+i.ownerDocument.doctype.name+`>
76
76
  `+u),we&&(u=Tt(u)),w&&Me?te(u):u},t.setConfig=function(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};ct(e),L=!0,De=F,Oe=I},t.clearConfig=function(){at=null,L=!1,De=null,Oe=null,w=E,T=``},t.isValidAttribute=function(e,t,n){at||ct({});let r=R(e),i=R(t);return Lt(r,i,n)},t.addHook=function(e,t){typeof t==`function`&&Rn(N,e)&&Tn(N[e],t)},t.removeHook=function(e,t){if(Rn(N,e)){if(t!==void 0){let n=Cn(N[e],t);return n===-1?void 0:En(N[e],n,1)[0]}return wn(N[e])}},t.removeHooks=function(e){Rn(N,e)&&(N[e]=[])},t.removeAllHooks=function(){N=Tr()},t}var kr=Or();async function Ar(e,t){let n=await fetch(`/api/chats/${e}/vibeable`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({slug:t})}),r=await n.json();if(!n.ok)throw Error(r.error||`HTTP ${n.status}`);return r}function jr({chatId:e,onClose:t,onOpened:n}){let[r,i]=(0,v.useState)(null),[a,o]=(0,v.useState)(``),[s,c]=(0,v.useState)(``),[l,u]=(0,v.useState)(``);(0,v.useEffect)(()=>{let e=!0;return fetch(`/api/vibeables`,{cache:`no-store`}).then(e=>e.json()).then(t=>e&&i(t)).catch(t=>e&&u(t.message)),()=>{e=!1}},[]),(0,v.useEffect)(()=>{let e=e=>e.key===`Escape`&&t();return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let d=async t=>{c(t),u(``);try{n(await Ar(e,t))}catch(e){u(e.message),c(``)}},f=async t=>{t.preventDefault();let r=a.trim();if(r){c(`new`),u(``);try{let t=await fetch(`/api/vibeables`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:r})}),i=await t.json();if(!t.ok)throw Error(i.error||`HTTP ${t.status}`);n(await Ar(e,i.slug))}catch(e){u(e.message),c(``)}}},p=r?.vibeables??[];return(0,S.jsx)(`div`,{className:`vibeable-overlay`,onMouseDown:e=>e.target===e.currentTarget&&t(),children:(0,S.jsxs)(`div`,{className:`vibeable-picker`,role:`dialog`,"aria-label":`Open a vibeable`,children:[(0,S.jsxs)(`div`,{className:`vibeable-picker-head`,children:[(0,S.jsx)(C,{name:`web`}),(0,S.jsx)(`h2`,{children:`Open a vibeable`}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsx)(`button`,{className:`icon-btn`,onClick:t,title:`Close`,"aria-label":`Close`,children:(0,S.jsx)(C,{name:`close`})})]}),(0,S.jsx)(`p`,{className:`vibeable-picker-hint`,children:`A small app built live in this chat: the agent works inside its folder, and every saved file shows up in the preview pane.`}),r&&!r.enabled&&(0,S.jsxs)(`div`,{className:`vibeable-picker-off`,children:[`Vibeables are off. Turn them on in `,(0,S.jsx)(`a`,{href:`#/settings`,children:`settings`}),` first.`]}),r?.enabled&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`form`,{className:`vibeable-new`,onSubmit:e=>void f(e),children:[(0,S.jsx)(`input`,{value:a,placeholder:`new vibeable, e.g. team-dashboard`,"aria-label":`new vibeable name`,onChange:e=>o(e.target.value),autoFocus:!0,disabled:!!s}),(0,S.jsxs)(`button`,{className:`ws-btn primary`,type:`submit`,disabled:!!s||!a.trim(),children:[(0,S.jsx)(C,{name:s===`new`?`progress_activity`:`add`,className:`ms-sm`}),s===`new`?`creating…`:`create`]})]}),(0,S.jsxs)(`div`,{className:`vibeable-picker-list`,children:[p.length===0&&(0,S.jsx)(`div`,{className:`vibeable-picker-empty`,children:`No vibeables yet — create one above.`}),p.map(e=>(0,S.jsxs)(`button`,{className:`vibeable-repo`,disabled:!!s,onClick:()=>void d(e.slug),children:[(0,S.jsx)(`span`,{className:`vibeable-repo-icon`,children:(0,S.jsx)(C,{name:s===e.slug?`progress_activity`:e.dev?`terminal`:`web`})}),(0,S.jsxs)(`span`,{className:`vibeable-repo-main`,children:[(0,S.jsx)(`span`,{className:`vibeable-repo-name`,children:e.slug}),(0,S.jsxs)(`span`,{className:`vibeable-repo-sub`,children:[e.configError?e.configError:e.dev?`dev: ${e.dev}`:e.hasIndex?`static`:`no index.html yet`,e.updatedAt?` · ${ve(e.updatedAt)}`:``]})]}),(0,S.jsx)(C,{name:`chevron_right`,className:`vibeable-repo-go`})]},e.slug))]})]}),l&&(0,S.jsx)(`div`,{className:`settings-err vibeable-picker-err`,children:l})]})})}function Mr({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 fetch(`/api/vibeables/${encodeURIComponent(t)}`,{cache:`no-store`}),n=await e.json();if(!e.ok)throw Error(n.error||`HTTP ${e.status}`);a(n),d(``)}catch(e){d(e.message)}},[t]);(0,v.useEffect)(()=>{_();let e=new EventSource(`/api/vibeables/${encodeURIComponent(t)}/events`),n;return e.onmessage=e=>{let t=JSON.parse(e.data);if(t.type===`change`)s(e=>e+1),l(t.files.slice(0,3).join(`, `)+(t.files.length>3?` +${t.files.length-3}`:``)),clearTimeout(n),n=setTimeout(()=>l(``),2500);else if(t.type===`dev`&&t.dev){let e=t.dev;a(t=>t&&{...t,dev:e,mode:e.running?`dev`:`static`})}else t.type===`error`&&d(t.message)},()=>{e.close(),clearTimeout(n)}},[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?`${i.url}?v=${o}`:``,x=()=>s(e=>e+1),w=async e=>{p(e),d(``);try{let n=await fetch(`/api/vibeables/${encodeURIComponent(t)}/dev/${e}`,{method:`POST`}),r=await n.json();if(!n.ok)throw Error(r.error||`HTTP ${n.status}`);a(r),e===`start`&&h(!0)}catch(e){d(e.message)}finally{p(``)}},T=async()=>{p(`close`),d(``);try{r(await Ar(e,null))}catch(e){d(e.message),p(``)}},E=i?.dev,D=E?.running?E.ready?{cls:`ok`,text:`dev :${E.port}`}:{cls:`running`,text:`starting…`}:E&&E.exitCode!==void 0?{cls:`failed`,text:`dev exited${E.exitCode==null?``:` (${E.exitCode})`}`}:{cls:`ok`,text:`static`};return(0,S.jsxs)(`aside`,{className:`vibeable-pane`,"data-vibe":t,children:[(0,S.jsxs)(`div`,{className:`vibeable-bar`,children:[(0,S.jsx)(C,{name:`web`,className:`vibeable-bar-icon`}),(0,S.jsx)(`span`,{className:`vibeable-name`,title:i?.path,children:t}),(0,S.jsxs)(`span`,{className:`vibeable-mode ${D.cls}`,title:E?.command?`dev: ${E.command}`:i?.dir,children:[(0,S.jsx)(`span`,{className:`lamp ${D.cls}`}),D.text]}),c&&(0,S.jsxs)(`span`,{className:`vibeable-flash`,title:c,children:[(0,S.jsx)(C,{name:`bolt`,className:`ms-sm`}),` reloaded`]}),(0,S.jsx)(`span`,{className:`spacer`}),i?.config.dev&&(E?.running?(0,S.jsx)(`button`,{className:`icon-btn`,onClick:()=>void w(`stop`),disabled:!!f,title:`Stop the dev server (${i.config.dev})`,"aria-label":`stop dev server`,children:(0,S.jsx)(C,{name:f===`stop`?`progress_activity`:`stop`})}):(0,S.jsx)(`button`,{className:`icon-btn vibeable-play`,onClick:()=>void w(`start`),disabled:!!f,title:`Start the dev server: ${i.config.dev}`,"aria-label":`start dev server`,children:(0,S.jsx)(C,{name:f===`start`?`progress_activity`:`play_arrow`})})),E&&(0,S.jsx)(`button`,{className:`icon-btn${m?` active`:``}`,onClick:()=>h(e=>!e),title:`Dev server output`,"aria-label":`dev server output`,children:(0,S.jsx)(C,{name:`terminal`})}),(0,S.jsx)(`button`,{className:`icon-btn`,onClick:x,title:`Reload the preview`,"aria-label":`reload preview`,children:(0,S.jsx)(C,{name:`refresh`})}),(0,S.jsx)(`button`,{className:`icon-btn`,onClick:()=>window.open(i?.url??``,`_blank`,`noopener`),disabled:!i,title:`Open in a new tab`,"aria-label":`open in new tab`,children:(0,S.jsx)(C,{name:`open_in_new`})}),(0,S.jsx)(`button`,{className:`icon-btn`,onClick:()=>void T(),disabled:!!f||n,title:n?`The agent is working — close the preview when the turn is done`:`Close the preview (the agent returns to the project root)`,"aria-label":`close preview`,children:(0,S.jsx)(C,{name:f===`close`?`progress_activity`:`close`})})]}),(u||i?.configError)&&(0,S.jsxs)(`div`,{className:`vibeable-err`,children:[(0,S.jsx)(`span`,{children:u||i?.configError}),u&&(0,S.jsx)(`button`,{className:`vibeable-err-x`,onClick:()=>d(``),"aria-label":`dismiss`,children:(0,S.jsx)(C,{name:`close`,className:`ms-sm`})})]}),i?.config.dev&&!E?.running&&!u&&(0,S.jsxs)(`div`,{className:`vibeable-note`,children:[`This app has a dev command (`,(0,S.jsx)(`code`,{children:i.config.dev}),`). Showing the static folder until you start it.`]}),b&&(0,S.jsx)(`iframe`,{ref:g,className:`vibeable-frame`,src:b,title:`vibeable ${t}`,sandbox:`allow-scripts allow-forms allow-popups allow-modals allow-downloads`,allow:`clipboard-write`}),!b&&!u&&(0,S.jsx)(`div`,{className:`empty`,children:`loading…`}),m&&E&&(0,S.jsx)(`pre`,{className:`vibeable-log`,"aria-label":`dev server log`,children:E.log.length?E.log.join(`
77
- `):`(no output yet)`})]})}function Nr({chatId:e,slug:t,onClosed:n}){let[r,i]=(0,v.useState)(``);return(0,S.jsxs)(`aside`,{className:`vibeable-pane vibeable-pane-off`,"data-vibe":t,children:[(0,S.jsxs)(`div`,{className:`vibeable-bar`,children:[(0,S.jsx)(C,{name:`web`,className:`vibeable-bar-icon`}),(0,S.jsx)(`span`,{className:`vibeable-name`,children:t}),(0,S.jsxs)(`span`,{className:`vibeable-mode failed`,children:[(0,S.jsx)(`span`,{className:`lamp failed`}),`vibeables are off`]}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsx)(`button`,{className:`icon-btn`,onClick:()=>Ar(e,null).then(n).catch(e=>i(e.message)),title:`Detach the app from this chat`,"aria-label":`close preview`,children:(0,S.jsx)(C,{name:`close`})})]}),(0,S.jsxs)(`div`,{className:`vibeable-note`,children:[`This chat has `,(0,S.jsx)(`b`,{children:t}),` open, but vibeables were switched off in `,(0,S.jsx)(`a`,{href:`#/settings`,children:`settings`}),`. Turn them back on to see the preview, or detach the app.`]}),r&&(0,S.jsx)(`div`,{className:`vibeable-err`,children:(0,S.jsx)(`span`,{children:r})})]})}var Pr=`kw-vibeable-agent`;async function Fr(e,t){let n=await fetch(`/api/chats`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({agent:t,scope:{kind:`general`}})}),r=await n.json();if(!n.ok||!r.id)throw Error(r.error||`HTTP ${n.status}`);await Ar(r.id,e),k(`/agents/chats/${r.id}`)}function Ir(){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)(null),[f,p]=(0,v.useState)(()=>{try{let e=localStorage.getItem(Pr);return e===`codex`||e===`pi`?e:`claude`}catch{return`claude`}}),m=N(),h=(0,v.useCallback)(async()=>{try{let e=await fetch(`/api/vibeables`,{cache:`no-store`});if(!e.ok)throw Error(`HTTP ${e.status}`);t(await e.json()),r(``)}catch(e){r(e.message||`could not load vibeables`)}},[]);(0,v.useEffect)(()=>{let e=!0,t,n=async()=>{await h(),e&&(t=setTimeout(n,15e3))};return n(),()=>{e=!1,clearTimeout(t)}},[h]);let g=(e,t)=>s(n=>({...n,[e]:t})),_=e=>s(t=>{let n={...t};return delete n[e],n}),y=(e,t)=>l(n=>({...n,[e]:t.message})),b=async e=>{e.preventDefault();let t=i.trim();if(t&&!o.__new){g(`__new`,`create`),l(e=>({...e,__new:``}));try{let e=await fetch(`/api/vibeables`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:t})}),n=await e.json();if(!e.ok)throw Error(n.error||`HTTP ${e.status}`);a(``),await h()}catch(e){y(`__new`,e)}finally{_(`__new`)}}},x=async e=>{g(e,`open`);try{await Fr(e,f)}catch(t){y(e,t),_(e)}},w=async e=>{g(e,`remove`),d(null);try{let t=await fetch(`/api/vibeables/${encodeURIComponent(e)}`,{method:`DELETE`}),n=await t.json();if(!t.ok||!n.ok)throw Error(n.error||`failed`)}catch(t){y(e,t)}finally{_(e),h()}},T=e=>{p(e);try{localStorage.setItem(Pr,e)}catch{}},E=[...e?.vibeables??[]].sort((e,t)=>(t.updatedAt??``).localeCompare(e.updatedAt??``));return(0,S.jsxs)(`div`,{className:`settings-screen ws-screen vibeables-screen`,children:[(0,S.jsxs)(`div`,{className:`settings-head`,children:[(0,S.jsxs)(`h1`,{children:[(0,S.jsx)(C,{name:`web`,className:`ms-lg`}),` Vibeables`]}),(0,S.jsx)(`span`,{className:`spacer`}),e?.enabled&&(0,S.jsxs)(`span`,{className:`settings-note`,children:[E.length,` app`,E.length===1?``:`s`]}),n&&(0,S.jsx)(`span`,{className:`settings-err`,children:n})]}),e&&!e.enabled&&(0,S.jsx)(`section`,{className:`panel`,children:(0,S.jsx)(`div`,{className:`ws-empty`,children:e.error&&!/are off/.test(e.error)?(0,S.jsx)(`span`,{className:`settings-err`,children:e.error}):(0,S.jsxs)(S.Fragment,{children:[`Vibeables are off. Turn them on in `,(0,S.jsx)(`a`,{href:`#/settings`,children:`settings`}),` or add a `,(0,S.jsx)(`code`,{children:`vibeables:`}),` block to kraftwerk.yml.`]})})}),e?.enabled&&(0,S.jsxs)(`section`,{className:`panel`,children:[(0,S.jsxs)(`div`,{className:`panel-head`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`new vibeable`}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsxs)(`span`,{className:`settings-note`,children:[`one folder each under `,(0,S.jsx)(`code`,{title:e.root,children:e.root})]})]}),(0,S.jsxs)(`form`,{className:`agent-form`,onSubmit:e=>void b(e),children:[(0,S.jsxs)(`div`,{className:`agent-form-row`,children:[(0,S.jsxs)(`label`,{className:`agent-field`,style:{flex:1},children:[`name`,(0,S.jsx)(`input`,{value:i,placeholder:`e.g. team-dashboard`,onChange:e=>a(e.target.value),autoFocus:!0})]}),(0,S.jsxs)(`button`,{className:`ws-btn primary`,type:`submit`,disabled:!!o.__new||!i.trim(),children:[(0,S.jsx)(C,{name:o.__new?`progress_activity`:`add`,className:`ms-sm`}),o.__new?`creating…`:`create`]})]}),c.__new&&(0,S.jsx)(`div`,{className:`settings-err`,children:c.__new}),(0,S.jsx)(`div`,{className:`settings-note`,children:`A small app built live with an agent: a chat on the left, the app rendered on the right, every saved file shows up at once. Part of the workspace — commit it from the git screen.`})]})]}),e?.enabled&&(0,S.jsxs)(`section`,{className:`panel`,children:[(0,S.jsxs)(`div`,{className:`panel-head`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`vibeables · newest change first`}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsxs)(`label`,{className:`vibeables-agent`,children:[`open in chat with`,(0,S.jsxs)(`select`,{value:f,onChange:e=>T(e.target.value),"aria-label":`agent for new chats`,children:[(0,S.jsx)(`option`,{value:`claude`,children:`claude`}),(0,S.jsx)(`option`,{value:`codex`,children:`codex`}),(0,S.jsx)(`option`,{value:`pi`,children:`pi`})]})]})]}),E.length===0&&(0,S.jsx)(`div`,{className:`ws-empty`,children:`Nothing built yet — create one above, or press the vibeable button in any chat.`}),E.map(e=>{let t=o[e.slug],n=e.configError?{label:`config error`,cls:`missing`}:e.hasIndex?{label:e.dev?`dev`:`static`,cls:`running`}:{label:`no index.html yet`,cls:`stopped`};return(0,S.jsxs)(`div`,{className:`ws-row vibeable-row state-${n.cls}`,"data-vibeable":e.slug,children:[(0,S.jsx)(`span`,{className:`vibeable-repo-icon ws-icon`,children:(0,S.jsx)(C,{name:e.dev?`terminal`:`web`})}),(0,S.jsxs)(`div`,{className:`ws-main`,children:[(0,S.jsxs)(`div`,{className:`ws-title`,children:[(0,S.jsx)(`span`,{className:`ws-name`,children:e.slug}),(0,S.jsx)(`span`,{className:`ws-state ws-state-${n.cls}`,children:n.label}),e.updatedAt&&(0,S.jsxs)(`span`,{className:`vibeable-when`,title:e.updatedAt,children:[`changed `,ve(e.updatedAt)]})]}),e.dev&&(0,S.jsx)(`div`,{className:`ws-root`,title:`dev command from vibeable.yml`,children:(0,S.jsx)(`code`,{children:e.dev})}),m&&(0,S.jsx)(`div`,{className:`ws-root ws-dim`,title:e.path,children:e.path}),e.configError&&(0,S.jsx)(`div`,{className:`settings-err`,children:e.configError}),c[e.slug]&&(0,S.jsx)(`div`,{className:`settings-err`,children:c[e.slug]})]}),(0,S.jsxs)(`div`,{className:`ws-actions`,children:[(0,S.jsxs)(`button`,{className:`ws-btn primary`,disabled:!!t,onClick:()=>void x(e.slug),title:`Start a ${f} chat with this app in the preview pane`,children:[(0,S.jsx)(C,{name:t===`open`?`progress_activity`:`chat`,className:`ms-sm`}),` open in chat`]}),(0,S.jsxs)(`a`,{className:`ws-btn`,href:`/vibeables/${encodeURIComponent(e.slug)}/`,target:`_blank`,rel:`noopener`,title:`Open the static preview in a new tab`,children:[(0,S.jsx)(C,{name:`open_in_new`,className:`ms-sm`}),` preview`]}),u!==e.slug&&(0,S.jsxs)(`button`,{className:`ws-btn`,disabled:!!t,onClick:()=>d(e.slug),title:`Delete the folder; its history stays in the workspace git`,children:[(0,S.jsx)(C,{name:`delete`,className:`ms-sm`}),` remove`]}),u===e.slug&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`button`,{className:`ws-btn danger`,onClick:()=>void w(e.slug),children:[(0,S.jsx)(C,{name:`delete`,className:`ms-sm`}),` confirm remove`]}),(0,S.jsx)(`button`,{className:`ws-btn`,onClick:()=>d(null),children:`cancel`})]})]})]},e.slug)})]})]})}var Lr=[{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 Rr(e,t){let n=await(await fetch(`/api/chats`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({agent:e,scope:t})})).json();n.id&&k(n.scope?.kind===`agent`?`/agents/${encodeURIComponent(n.scope.slug)}/chat/${n.id}`:`/agents/chats/${n.id}`)}function zr(){let[e,t]=(0,v.useState)(`claude`),[n,r]=(0,v.useState)(!0),[i,a]=(0,v.useState)(!1);return(0,S.jsxs)(`div`,{className:`new-chat`,children:[(0,S.jsx)(`div`,{className:`page-head`,children:(0,S.jsx)(`h1`,{children:`new chat`})}),(0,S.jsxs)(`section`,{className:`panel new-chat-panel`,children:[(0,S.jsx)(`div`,{className:`panel-head`,children:(0,S.jsx)(`span`,{className:`microlabel`,children:`agent`})}),(0,S.jsx)(`div`,{className:`agent-pick`,children:Lr.map(n=>(0,S.jsxs)(`button`,{className:`agent-pick-btn ${e===n.id?`active`:``}`,onClick:()=>t(n.id),children:[(0,S.jsx)(`b`,{children:n.label}),(0,S.jsx)(`span`,{children:n.hint})]},n.id))}),(0,S.jsx)(`div`,{className:`run-opts`,style:{padding:`0 16px 14px`},children:(0,S.jsxs)(`label`,{children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:n,onChange:e=>r(e.target.checked)}),`kraftwerk-aware`,(0,S.jsx)(`span`,{className:`opt-hint`,children:`— agent gets workflows + recent runs as context`})]})}),(0,S.jsx)(`div`,{style:{padding:`0 16px 16px`},children:(0,S.jsx)(`button`,{className:`run-btn`,disabled:i,onClick:async()=>{a(!0),await Rr(e,{kind:n?`kraftwerk`:`general`}),a(!1)},children:i?`starting…`:`start chat`})})]})]})}function Br({id:e,agentName:t,agentDescription:n}){let[r,i]=(0,v.useState)(null),[a,o]=(0,v.useState)([]),[s,c]=(0,v.useState)(!1),[l,u]=(0,v.useState)(!1),d=P();(0,v.useEffect)(()=>{let t=!0,n=null;return fetch(`/api/chats/${e}`).then(e=>e.ok?e.json():Promise.reject()).then(r=>{if(!t)return;i(r.meta),o(r.events);let a=r.events[r.events.length-1]?.seq??0;n=new EventSource(`/api/chats/${e}/events?after=${a}`),n.onmessage=e=>{let t=JSON.parse(e.data);o(e=>e.some(e=>e.seq===t.seq)?e:[...e,t])}}).catch(()=>t&&c(!0)),()=>{t=!1,n?.close()}},[e]);let f=(0,v.useMemo)(()=>{for(let e=a.length-1;e>=0;e--){let t=a[e].type;if(t===`user_message`)return!0;if(t===`turn_end`||t===`error`)return!1}return!1},[a]),p=(0,v.useMemo)(()=>{if(r?.title)return r.title;let e=a.find(e=>e.type===`user_message`);return e&&e.type===`user_message`?e.text.replace(/\s+/g,` `).trim().slice(0,80):``},[r,a]);return(0,v.useEffect)(()=>r?(ne([t??(r.scope.kind===`agent`?r.scope.slug:r.agent),n,p||`new chat`].filter(Boolean).join(` · `)),()=>ne(``)):void 0,[r,p,t,n]),s?(0,S.jsx)(`div`,{className:`empty`,children:`chat not found`}):r?(0,S.jsxs)(`div`,{className:`chat-split${r.vibeable?` open`:``}`,children:[(0,S.jsxs)(`div`,{className:`chat-thread`,children:[(0,S.jsxs)(`div`,{className:`detail-head`,children:[(0,S.jsx)(`span`,{className:`lamp ${f?`running`:`ok`}`}),(0,S.jsx)(`h1`,{children:p||`new chat`}),!r.vibeable&&d.vibeables&&(0,S.jsxs)(`button`,{className:`ws-btn vibeable-open`,onClick:()=>u(!0),title:`Build a small app live: a preview pane next to this chat`,disabled:f,children:[(0,S.jsx)(C,{name:`web`,className:`ms-sm`}),` vibeable`]}),(0,S.jsx)(`span`,{className:`chip agent`,children:r.agent}),r.scope.kind===`run`&&(0,S.jsx)(A,{href:`/runs/${r.scope.runId}`,className:`chip`,children:r.scope.runId}),r.scope.kind===`kraftwerk`&&(0,S.jsx)(`span`,{className:`chip`,children:`kraftwerk-aware`}),r.scope.kind===`knowledge`&&(0,S.jsxs)(A,{href:r.scope.bundle?`/knowledge/${encodeURIComponent(r.scope.bundle)}`:`/knowledge`,className:`chip`,children:[`knowledge`,r.scope.bundle?`:${r.scope.bundle}`:``]}),r.scope.kind===`agent`&&(0,S.jsxs)(A,{href:`/agents/${encodeURIComponent(r.scope.slug)}/info`,className:`chip`,children:[`agent:`,r.scope.slug]}),(0,S.jsx)(`span`,{className:`rid`,title:r.cwd,children:r.cwd})]}),(0,S.jsx)(Hr,{id:e,events:a,busy:f}),(0,S.jsx)(Kr,{id:e,busy:f,scope:r.scope})]}),r.vibeable&&d.vibeables&&(0,S.jsx)(Mr,{chatId:e,slug:r.vibeable,agentBusy:f,onClosed:i},r.vibeable),r.vibeable&&!d.vibeables&&(0,S.jsx)(Nr,{chatId:e,slug:r.vibeable,onClosed:i}),l&&(0,S.jsx)(jr,{chatId:e,onClose:()=>u(!1),onOpened:e=>{i(e),u(!1)}})]}):(0,S.jsx)(`div`,{className:`empty`,children:`loading…`})}function Vr(e){let t=[],n=new Map,r=new Map;for(let i of e){let e=t[t.length-1];switch(i.type){case`user_message`:t.push({kind:`user`,text:i.text,key:`e${i.seq}`});break;case`text`:e?.kind===`agent`?e.text+=i.text:t.push({kind:`agent`,text:i.text,key:`e${i.seq}`});break;case`thought`:e?.kind===`thought`?e.text+=i.text:t.push({kind:`thought`,text:i.text,key:`e${i.seq}`});break;case`tool_call`:n.set(i.callId,t.length),t.push({kind:`tool`,callId:i.callId,title:i.title,toolKind:i.kind,status:i.status,key:`e${i.seq}`});break;case`tool_update`:{let e=n.get(i.callId);if(e!=null){let n=t[e];i.title&&(n.title=i.title),i.status&&(n.status=i.status)}break}case`permission_request`:r.set(i.requestId,t.length),t.push({kind:`permission`,requestId:i.requestId,title:i.title,options:i.options,resolved:void 0,key:`e${i.seq}`});break;case`permission_resolved`:{let e=r.get(i.requestId);e!=null&&(t[e].resolved=i.optionId);break}case`error`:t.push({kind:`error`,text:i.message,key:`e${i.seq}`})}}return t}function Hr({id:e,events:t,busy:n}){let r=N(),i=(0,v.useMemo)(()=>{let e=Vr(t);return r?e:e.filter(e=>e.kind!==`tool`&&e.kind!==`thought`)},[t,r]),a=(0,v.useRef)(null),o=(0,v.useRef)(!0);return(0,v.useEffect)(()=>{let e=a.current;e&&o.current&&(e.scrollTop=e.scrollHeight)},[i,n]),(0,S.jsxs)(`div`,{className:`chat-scroll`,ref:a,onScroll:e=>{let t=e.currentTarget;o.current=t.scrollHeight-t.scrollTop-t.clientHeight<60},children:[i.length===0&&(0,S.jsx)(`div`,{className:`empty`,children:`say something — the agent starts on your first message`}),i.map(t=>(0,S.jsx)(Wr,{b:t,chatId:e},t.key)),n&&(0,S.jsxs)(`div`,{className:`chat-working`,children:[(0,S.jsx)(`span`,{className:`lamp running`}),` working…`]})]})}function Ur({text:e}){let t=(0,v.useMemo)(()=>kr.sanitize(z.parse(e,{async:!1})),[e]);return(0,S.jsx)(`div`,{className:`msg agent md-body chat-md`,dangerouslySetInnerHTML:{__html:t}})}function Wr({b:e,chatId:t}){switch(e.kind){case`user`:return(0,S.jsx)(`div`,{className:`msg user`,children:e.text});case`agent`:return(0,S.jsx)(Ur,{text:e.text});case`thought`:return(0,S.jsxs)(`details`,{className:`msg thought`,children:[(0,S.jsx)(`summary`,{children:`thinking`}),(0,S.jsx)(`div`,{children:e.text})]});case`tool`:return(0,S.jsxs)(`div`,{className:`tool-card ${e.status??``}`,children:[(0,S.jsx)(`span`,{className:`lamp ${e.status===`completed`?`ok`:e.status===`failed`?`failed`:`running`}`}),e.toolKind&&(0,S.jsx)(`span`,{className:`chip tool-kind`,children:e.toolKind}),(0,S.jsx)(`span`,{className:`tool-title`,children:e.title})]});case`permission`:return(0,S.jsx)(Gr,{b:e,chatId:t});case`error`:return(0,S.jsxs)(`div`,{className:`msg error`,children:[(0,S.jsx)(C,{name:`error`,className:`ms-sm`}),` `,e.text]})}}function Gr({b:e,chatId:t}){let[n,r]=(0,v.useState)(!1),i=e.resolved===void 0;async function a(n){r(!0),await fetch(`/api/chats/${t}/permission`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({requestId:e.requestId,optionId:n})}).catch(()=>{}),r(!1)}return(0,S.jsxs)(`div`,{className:`perm-card ${i?`pending`:``}`,children:[(0,S.jsxs)(`div`,{className:`perm-title`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`permission`}),` `,e.title]}),i?(0,S.jsx)(`div`,{className:`perm-actions`,children:e.options.map(e=>(0,S.jsx)(`button`,{className:`perm-btn ${e.kind?.startsWith(`allow`)?`allow`:`deny`}`,disabled:n,onClick:()=>a(e.optionId),children:e.name},e.optionId))}):(0,S.jsx)(`div`,{className:`perm-resolved`,children:e.resolved?`→ ${e.options.find(t=>t.optionId===e.resolved)?.name??e.resolved}`:`→ dismissed`})]})}function Kr({id:e,busy:t,scope:n}){let[r,i]=(0,v.useState)(``),[a,o]=(0,v.useState)([]),[s,c]=(0,v.useState)(0),[l,u]=(0,v.useState)(!1);(0,v.useEffect)(()=>{let e=!0;return(async()=>{try{let t=(await fetch(`/api/skills`).then(e=>e.json())).skills??[];if(n?.kind===`agent`){let[e,r]=await Promise.all([fetch(`/api/agents/${encodeURIComponent(n.slug)}`).then(e=>e.ok?e.json():null).catch(()=>null),fetch(`/api/agents/${encodeURIComponent(n.slug)}/skills`).then(e=>e.ok?e.json():null).catch(()=>null)]);if(e&&Array.isArray(e.skills)){let n=new Set(e.skills.map(e=>e.toLowerCase()));t=t.filter(e=>n.has(e.name.toLowerCase()))}let i=r?.skills??[],a=new Set(i.map(e=>e.name.toLowerCase()));t=[...i,...t.filter(e=>!a.has(e.name.toLowerCase()))]}e&&o(t)}catch{}})(),()=>{e=!1}},[e]);let d=/^\/([\w-]*)$/.exec(r)?.[1],f=d!==void 0&&!l?a.filter(e=>e.name.toLowerCase().startsWith(d.toLowerCase())):[],p=f.length>0,m=Math.min(s,f.length-1);function h(e){i(`/${e.name} `),c(0)}async function g(){let n=r.trim();n&&!t&&(i(``),await fetch(`/api/chats/${e}/message`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:n})}).catch(()=>{}))}return(0,S.jsxs)(`div`,{className:`composer`,children:[p&&(0,S.jsx)(`div`,{className:`skill-menu`,children:f.map((e,t)=>(0,S.jsxs)(`button`,{className:t===m?`active`:``,onMouseDown:t=>{t.preventDefault(),h(e)},children:[(0,S.jsxs)(`b`,{children:[`/`,e.name]}),e.description&&(0,S.jsxs)(`span`,{children:[` — `,e.description]}),(0,S.jsx)(`span`,{className:`skill-src`,children:e.source})]},e.name))}),(0,S.jsx)(`textarea`,{value:r,placeholder:t?`agent is working…`:`message · Enter to send, Shift+Enter for newline, / for skills`,rows:Math.min(6,Math.max(1,r.split(`
78
- `).length)),onChange:e=>{i(e.target.value),c(0),u(!1)},onKeyDown:e=>{if(p){if(e.key===`ArrowDown`)return e.preventDefault(),c((m+1)%f.length);if(e.key===`ArrowUp`)return e.preventDefault(),c((m-1+f.length)%f.length);if(e.key===`Tab`||e.key===`Enter`)return e.preventDefault(),h(f[m]);if(e.key===`Escape`)return e.preventDefault(),u(!0)}e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),g())}}),t?(0,S.jsxs)(`button`,{className:`stop-btn`,onClick:()=>fetch(`/api/chats/${e}/cancel`,{method:`POST`}).catch(()=>{}),children:[(0,S.jsx)(C,{name:`stop`,className:`ms-sm`}),` stop`]}):(0,S.jsxs)(`button`,{className:`run-btn`,disabled:!r.trim(),onClick:g,children:[(0,S.jsx)(C,{name:`send`,className:`ms-sm`}),` send`]})]})}function qr({id:e}){let t=F(`/api/runs`,!0),n=t?.runs??[];return(0,S.jsxs)(`div`,{className:`runs-screen`,children:[(0,S.jsxs)(`aside`,{className:`runs-side`,children:[(0,S.jsxs)(`div`,{className:`side-head`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`runs`}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsx)(`span`,{className:`microlabel num`,children:n.length})]}),(0,S.jsxs)(`div`,{className:`side-list`,children:[n.map(t=>(0,S.jsx)(Jr,{r:t,active:t.id===e},t.id)),t&&n.length===0&&(0,S.jsx)(`div`,{className:`viewer-note`,children:`no runs yet`})]})]}),(0,S.jsx)(`div`,{className:`runs-main`,children:(0,S.jsx)(Yr,{id:e},e)})]})}function Jr({r:e,active:t}){return(0,S.jsxs)(A,{href:`/runs/${e.id}`,className:`side-row ${t?`active`:``}`,children:[(0,S.jsx)(be,{status:e.status}),(0,S.jsxs)(`div`,{className:`side-row-body`,children:[(0,S.jsxs)(`div`,{className:`side-row-top`,children:[(0,S.jsx)(`span`,{className:`side-wf`,children:e.workflow??`unknown`}),(0,S.jsx)(`span`,{className:`side-when num`,children:_e(e.startedAt)})]}),(0,S.jsxs)(`div`,{className:`side-row-sub`,children:[(0,S.jsx)(`span`,{className:`side-req`,title:e.request,children:e.status===`running`&&e.currentPhase?`${e.currentPhase}`:e.request??``}),(0,S.jsx)(`span`,{className:`side-meta num`,children:e.status===`running`?(0,S.jsx)(ye,{since:e.startedAt}):me(e.durationMs)})]})]})]})}function Yr({id:e}){let t=F(`/api/runs/${e}`,!0),n=t?.status===`running`,[r,i]=(0,v.useState)(null),[a,o]=(0,v.useState)(!1),s=N();if(!t)return(0,S.jsx)(`div`,{className:`empty`,children:`loading…`});let c=t.files.some(e=>e.name===`runner.json`),l=r??(n?`run`:`artifacts`),u=s?t.files.length:t.files.filter(e=>!ti(e.name)).length;async function d(){o(!0),await fetch(`/api/runs/${e}/stop`,{method:`POST`}).catch(()=>{})}return(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`div`,{className:`detail-head`,children:[(0,S.jsx)(be,{status:t.status}),(0,S.jsx)(`h1`,{children:t.workflow?(0,S.jsx)(A,{href:`/workflows/${encodeURIComponent(t.workflow)}`,title:`open workflow`,children:t.workflow}):`unknown workflow`}),(0,S.jsx)(xe,{status:t.status}),c&&(0,S.jsxs)(`span`,{className:`chip sandbox-chip`,children:[(0,S.jsx)(C,{name:`science`,className:`ms-sm`}),` sandbox`]}),(0,S.jsx)(`span`,{className:`rid`,children:e.replace(/^run-/,``)}),n&&c&&(0,S.jsx)(`button`,{className:`stop-btn`,onClick:d,disabled:a,children:a?`stopping…`:(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(C,{name:`stop`,className:`ms-sm`}),` stop`]})}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsx)(`button`,{className:`open-raw`,title:`chat with an agent about this run`,onClick:()=>void Rr(`claude`,{kind:`run`,runId:e}),children:`⌬ discuss`}),(0,S.jsxs)(`nav`,{className:`tabs`,children:[(0,S.jsx)(`button`,{className:l===`run`?`active`:``,onClick:()=>i(`run`),children:`run`}),(0,S.jsxs)(`button`,{className:l===`artifacts`?`active`:``,onClick:()=>i(`artifacts`),children:[`artifacts `,(0,S.jsxs)(`span`,{className:`num`,children:[`(`,u,`)`]})]})]})]}),t.request&&(0,S.jsx)(`p`,{className:`detail-req`,children:t.request}),l===`run`?(0,S.jsx)(Xr,{run:t,live:n}):(0,S.jsx)(ri,{id:e,files:t.files,live:n})]})}function Xr({run:e,live:t}){return(0,S.jsxs)(`div`,{className:`run-tab`,children:[(0,S.jsxs)(`div`,{className:`statgrid`,children:[(0,S.jsxs)(`div`,{className:`stat`,children:[(0,S.jsx)(`div`,{className:`microlabel`,children:`phases`}),(0,S.jsxs)(`div`,{className:`v num`,children:[e.phasesDone,e.phasesTotal==null?``:` / ${e.phasesTotal}`]})]}),(0,S.jsxs)(`div`,{className:`stat`,children:[(0,S.jsx)(`div`,{className:`microlabel`,children:`duration`}),(0,S.jsx)(`div`,{className:`v num`,children:t?(0,S.jsx)(ye,{since:e.startedAt}):me(e.durationMs)})]}),(0,S.jsxs)(`div`,{className:`stat`,children:[(0,S.jsx)(`div`,{className:`microlabel`,children:`cost`}),(0,S.jsx)(`div`,{className:`v num`,children:I(e.costUsd??Qr(e.phases))})]}),(0,S.jsxs)(`div`,{className:`stat`,children:[(0,S.jsx)(`div`,{className:`microlabel`,children:`tokens in / out`}),(0,S.jsxs)(`div`,{className:`v num`,children:[he(Zr(e.phases,`tokensIn`)),` / `,he(Zr(e.phases,`tokensOut`))]})]})]}),(0,S.jsxs)(`section`,{className:`panel`,children:[(0,S.jsxs)(`div`,{className:`panel-head`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`phase timeline`}),(0,S.jsx)(`span`,{className:`spacer`}),t&&(0,S.jsxs)(`span`,{className:`live-note`,children:[(0,S.jsx)(`span`,{className:`lamp running`}),` live · polling`]})]}),(0,S.jsx)(`div`,{className:`phases`,children:e.phases.map(e=>(0,S.jsx)($r,{p:e},e.phase))})]})]})}function Zr(e,t){return e.reduce((e,n)=>e+(n[t]??0),0)}function Qr(e){return e.reduce((e,t)=>e+(t.costUsd??0),0)}function $r({p:e}){let t=e.gates.filter(e=>!e.passed);return(0,S.jsxs)(`div`,{className:`phase-row`,children:[(0,S.jsx)(be,{status:e.status}),(0,S.jsxs)(`div`,{className:`phase-top`,children:[(0,S.jsx)(`span`,{className:`phase-name`,children:e.phase}),e.kind===`agent`?(0,S.jsxs)(`span`,{className:`chip agent`,children:[e.agent,e.model?` · ${e.model}`:``]}):(0,S.jsx)(`span`,{className:`chip`,children:`script`}),(0,S.jsxs)(`span`,{className:`right num`,children:[e.attempts>1&&(0,S.jsxs)(`span`,{children:[`att `,e.attempts]}),e.status===`running`?(0,S.jsx)(ye,{since:e.startedAt}):e.durationMs!=null&&(0,S.jsx)(`span`,{children:me(e.durationMs)}),e.kind===`agent`&&e.tokensIn!=null&&(0,S.jsxs)(`span`,{children:[he(e.tokensIn),` / `,he(e.tokensOut)]}),e.costUsd!=null&&e.costUsd>0&&(0,S.jsx)(`span`,{children:I(e.costUsd)})]})]}),e.status===`running`&&e.lastActivity&&(0,S.jsx)(`div`,{className:`phase-activity`,children:e.lastActivity}),e.summary&&e.status!==`running`&&(0,S.jsx)(`div`,{className:`phase-sub`,children:e.summary}),e.gates.length>0&&(0,S.jsx)(`div`,{className:`gate-line`,children:e.gates.map(e=>(0,S.jsxs)(`span`,{className:`gate ${e.passed?``:`failed`}`,title:e.failure??``,children:[(0,S.jsx)(C,{name:e.passed?`check`:`close`,className:`ms-sm`}),` `,e.gate]},e.gate))}),t.map(e=>(0,S.jsx)(`div`,{className:`gate-fail-msg`,children:e.failure},e.gate))]})}var ei=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`]);function ti(e){return e===`runner.json`||e.endsWith(`.jsonl`)||e.endsWith(`.log`)}function ni(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)||ei.has(t)?0:ti(e)?2:1},r=null;for(let t of e)(!r||n(t.name)<n(r.name))&&(r=t);return r?.name??null}function ri({id:e,files:t,live:n}){let[r,i]=(0,v.useState)(null),a=N(),o=(0,v.useMemo)(()=>a?t:t.filter(e=>!ti(e.name)),[t,a]);return(0,v.useEffect)(()=>{!a&&r&&ti(r)&&i(null)},[a,r]),(0,v.useEffect)(()=>{r||o.length===0||i(ni(o))},[o,r]),(0,S.jsxs)(`div`,{className:`art-layout`,children:[(0,S.jsxs)(`section`,{className:`panel art-files`,children:[(0,S.jsx)(`div`,{className:`panel-head`,children:(0,S.jsxs)(`span`,{className:`microlabel`,children:[`files `,(0,S.jsxs)(`span`,{className:`num`,children:[`(`,o.length,`)`]})]})}),(0,S.jsxs)(`div`,{className:`file-list`,children:[o.map(e=>(0,S.jsxs)(`button`,{className:`file-row ${r===e.name?`active`:``}`,onClick:()=>i(e.name),children:[(0,S.jsx)(`span`,{className:`fname`,children:e.name}),(0,S.jsx)(`span`,{className:`fsize num`,children:ge(e.size)})]},e.name)),o.length===0&&(0,S.jsx)(`div`,{className:`viewer-note`,children:t.length>0?`no result files — raw run files live in expert mode`:`no files yet`})]})]}),(0,S.jsxs)(`section`,{className:`panel art-viewer`,children:[(0,S.jsxs)(`div`,{className:`panel-head`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:r??`viewer`}),(0,S.jsx)(`span`,{className:`spacer`}),r&&(0,S.jsx)(`a`,{className:`open-raw`,href:`/api/runs/${e}/file?name=${encodeURIComponent(r)}&raw=1`,target:`_blank`,children:`open raw ↗`})]}),r?(0,S.jsx)(ii,{id:e,name:r,live:n}):(0,S.jsx)(`div`,{className:`empty`,children:`select a file`})]})]})}function ii({id:e,name:t,live:n}){let r=t.split(`.`).pop()?.toLowerCase()??``,i=`/api/runs/${e}/file?name=${encodeURIComponent(t)}&raw=1`;return r===`html`?(0,S.jsx)(`div`,{className:`viewer`,children:(0,S.jsx)(`div`,{className:`viewer-body`,children:(0,S.jsx)(`iframe`,{src:i,sandbox:`allow-scripts`,allow:`clipboard-write`,title:t})})}):r===`pdf`?(0,S.jsx)(`div`,{className:`viewer`,children:(0,S.jsx)(`div`,{className:`viewer-body`,children:(0,S.jsx)(`iframe`,{src:i,title:t})})}):ei.has(r)?(0,S.jsx)(`div`,{className:`viewer`,children:(0,S.jsx)(`div`,{className:`viewer-body`,children:(0,S.jsx)(`img`,{src:i,alt:t})})}):r===`md`||r===`markdown`?(0,S.jsx)(ai,{id:e,name:t,live:n}):(0,S.jsx)(oi,{id:e,name:t,live:n})}function ai({id:e,name:t,live:n}){let[r,i]=(0,v.useState)(`rendered`),a=F(`/api/runs/${e}/file?name=${encodeURIComponent(t)}`,n),o=(0,v.useMemo)(()=>a?kr.sanitize(z.parse(a.content,{async:!1})):``,[a?.content]);return(0,S.jsxs)(`div`,{className:`viewer`,children:[(0,S.jsxs)(`div`,{className:`viewer-note md-toolbar`,children:[(0,S.jsxs)(`div`,{className:`tabs`,children:[(0,S.jsx)(`button`,{className:r===`rendered`?`active`:``,onClick:()=>i(`rendered`),children:`rendered`}),(0,S.jsx)(`button`,{className:r===`source`?`active`:``,onClick:()=>i(`source`),children:`source`})]}),a?.truncated&&(0,S.jsxs)(`span`,{children:[`large file — showing the last `,ge(4e5)]})]}),(0,S.jsx)(`div`,{className:`viewer-body`,children:a?r===`rendered`?(0,S.jsx)(`div`,{className:`md-body`,dangerouslySetInnerHTML:{__html:o}}):(0,S.jsx)(`pre`,{children:a.content||`(empty)`}):(0,S.jsx)(`pre`,{children:`loading…`})})]})}function oi({id:e,name:t,live:n}){let r=F(`/api/runs/${e}/file?name=${encodeURIComponent(t)}`,n);return(0,S.jsxs)(`div`,{className:`viewer`,children:[r?.truncated&&(0,S.jsxs)(`div`,{className:`viewer-note`,children:[`large file — showing the last `,ge(4e5)]}),(0,S.jsx)(`div`,{className:`viewer-body`,children:(0,S.jsx)(`pre`,{children:r?r.content||`(empty)`:`loading…`})})]})}function si(){let e=F(`/api/workflows`,!1),t=e?.workflows??[];return(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`div`,{className:`page-head`,children:[(0,S.jsx)(`h1`,{children:`Workflows`}),(0,S.jsxs)(`span`,{className:`count num`,children:[t.length,` discovered`]}),e?.root&&(0,S.jsx)(`span`,{className:`count mono`,children:e.root})]}),e&&t.length===0&&(0,S.jsxs)(`div`,{className:`empty`,children:[`No workflows found — expected `,(0,S.jsx)(`code`,{children:`src/workflows/`}),` or `,(0,S.jsx)(`code`,{children:`workflows/`}),` `,`next to the output folder.`]}),(0,S.jsx)(`div`,{className:`wf-grid`,children:t.map(e=>(0,S.jsxs)(A,{href:`/workflows/${e.slug}`,className:`wf-card`,children:[(0,S.jsxs)(`div`,{className:`wf-card-head`,children:[(0,S.jsx)(`span`,{className:`wf-name`,children:e.name??e.slug}),e.error&&(0,S.jsx)(`span`,{className:`status-word failed`,children:`broken`})]}),(0,S.jsx)(`p`,{className:`wf-desc`,children:e.error??e.description??``}),(0,S.jsxs)(`div`,{className:`wf-meta num`,children:[(0,S.jsxs)(`span`,{children:[e.agents,` agents`]}),(0,S.jsx)(`span`,{children:`·`}),(0,S.jsxs)(`span`,{children:[e.steps,` steps`]})]})]},e.slug))})]})}function ci({slug:e}){let t=F(`/api/workflows/${encodeURIComponent(e)}`,!1),n=F(`/api/runs`,!1);if(!t)return(0,S.jsx)(`div`,{className:`empty`,children:`loading…`});if(t.error)return(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(ui,{slug:t.slug}),(0,S.jsxs)(`div`,{className:`empty`,children:[(0,S.jsx)(`span`,{className:`status-word failed`,children:`broken workflow`}),(0,S.jsx)(`pre`,{style:{marginTop:12,textAlign:`left`},children:t.error})]})]});let r=new Map(t.agents.map((e,t)=>[e.id,t%4])),i=(n?.runs??[]).filter(e=>e.workflow===t.name).slice(0,8);return(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(ui,{slug:t.slug}),(0,S.jsxs)(`div`,{className:`detail-head`,children:[(0,S.jsx)(`h1`,{children:t.name??t.slug}),(0,S.jsx)(`span`,{className:`rid mono`,children:t.dir})]}),t.description&&(0,S.jsx)(`p`,{className:`detail-req`,children:t.description}),(0,S.jsxs)(`div`,{className:`statgrid`,children:[(0,S.jsxs)(`div`,{className:`stat`,children:[(0,S.jsx)(`div`,{className:`microlabel`,children:`agents`}),(0,S.jsx)(`div`,{className:`v num`,children:t.agents.length})]}),(0,S.jsxs)(`div`,{className:`stat`,children:[(0,S.jsx)(`div`,{className:`microlabel`,children:`steps`}),(0,S.jsxs)(`div`,{className:`v num`,children:[t.steps.length,` `,(0,S.jsxs)(`span`,{style:{color:`var(--muted)`,fontWeight:400},children:[`(`,t.steps.filter(e=>e.kind===`agent`).length,` agent ·`,` `,t.steps.filter(e=>e.kind===`script`).length,` script)`]})]})]}),t.workspace&&(0,S.jsxs)(`div`,{className:`stat`,style:{maxWidth:420},children:[(0,S.jsx)(`div`,{className:`microlabel`,children:`workspace`}),(0,S.jsx)(`div`,{className:`wf-workspace mono`,children:t.workspace})]})]}),(0,S.jsx)(li,{slug:t.slug,lastRequest:i[0]?.request}),(0,S.jsxs)(`section`,{className:`panel`,style:{marginBottom:18},children:[(0,S.jsx)(`div`,{className:`panel-head`,children:(0,S.jsx)(`span`,{className:`microlabel`,children:`agents`})}),(0,S.jsxs)(`div`,{className:`agent-grid`,children:[t.agents.map(e=>(0,S.jsx)(di,{a:e,idx:r.get(e.id)??0},e.id)),t.agents.length===0&&(0,S.jsx)(`div`,{className:`viewer-note`,children:`no agents — script-only workflow`})]})]}),(0,S.jsxs)(`div`,{className:`columns`,children:[(0,S.jsxs)(`section`,{className:`panel`,children:[(0,S.jsx)(`div`,{className:`panel-head`,children:(0,S.jsx)(`span`,{className:`microlabel`,children:`pipeline`})}),(0,S.jsx)(`div`,{className:`pipeline`,children:t.steps.map((e,t)=>(0,S.jsx)(fi,{s:e,i:t,idx:e.agent?r.get(e.agent)??0:null},e.name))})]}),(0,S.jsxs)(`div`,{style:{display:`grid`,gap:18},children:[(0,S.jsxs)(`section`,{className:`panel`,children:[(0,S.jsx)(`div`,{className:`panel-head`,children:(0,S.jsxs)(`span`,{className:`microlabel`,children:[`folder `,(0,S.jsxs)(`span`,{className:`num`,children:[`(`,t.files.length,` files)`]})]})}),(0,S.jsx)(`div`,{className:`file-list`,children:t.files.map(e=>(0,S.jsx)(`div`,{className:`file-row`,style:{cursor:`default`},children:(0,S.jsx)(`span`,{className:`fname`,children:e})},e))})]}),(0,S.jsxs)(`section`,{className:`panel`,children:[(0,S.jsx)(`div`,{className:`panel-head`,children:(0,S.jsxs)(`span`,{className:`microlabel`,children:[`recent runs `,(0,S.jsxs)(`span`,{className:`num`,children:[`(`,i.length,`)`]})]})}),(0,S.jsxs)(`div`,{className:`file-list`,children:[i.map(e=>(0,S.jsxs)(A,{href:`/runs/${e.id}`,className:`file-row`,children:[(0,S.jsx)(be,{status:e.status}),(0,S.jsx)(`span`,{className:`fname`,children:e.id.replace(/^run-/,``)}),(0,S.jsxs)(`span`,{className:`fsize num`,children:[me(e.durationMs),` · `,I(e.costUsd),` · `,_e(e.startedAt)]})]},e.id)),i.length===0&&(0,S.jsx)(`div`,{className:`viewer-note`,children:`no runs of this workflow yet`})]})]})]})]})]})}function li({slug:e,lastRequest:t}){let[n,r]=(0,v.useState)(``),[i,a]=(0,v.useState)(!0),[o,s]=(0,v.useState)(!1),[c,l]=(0,v.useState)(!1),[u,d]=(0,v.useState)(null),f=F(`/api/workflows/${encodeURIComponent(e)}/run`,!1);(0,v.useEffect)(()=>{!n&&t&&r(t)},[t]);let p=f?.available&&f?.image,m=f?f.available?f.image?`isolated container per run`:"image missing — run `kraftwerk runner build`":`Docker not running — sandbox unavailable`:``;async function h(){if(n.trim()&&!c){l(!0),d(null);try{let t=await fetch(`/api/workflows/${encodeURIComponent(e)}/run`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({request:n.trim(),sandbox:i,ssh:o})}),r=await t.json();if(!t.ok)throw Error(r.error??`HTTP ${t.status}`);k(`/runs/${r.runId}`)}catch(e){d(e.message),l(!1)}}}return(0,S.jsxs)(`section`,{className:`panel run-panel`,style:{marginBottom:18},children:[(0,S.jsx)(`div`,{className:`panel-head`,children:(0,S.jsx)(`span`,{className:`microlabel`,children:`trigger run`})}),(0,S.jsxs)(`div`,{className:`run-form`,children:[(0,S.jsx)(`input`,{type:`text`,value:n,placeholder:`request — topic, URL, host …`,onChange:e=>r(e.target.value),onKeyDown:e=>e.key===`Enter`&&h()}),(0,S.jsx)(`button`,{className:`run-btn`,onClick:h,disabled:c||!n.trim()||i&&!p,children:c?`starting…`:(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(C,{name:`play_arrow`,className:`ms-sm`}),` `,i?`run in sandbox`:`run locally`]})})]}),(0,S.jsxs)(`div`,{className:`run-opts`,children:[(0,S.jsxs)(`label`,{children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:i,onChange:e=>a(e.target.checked)}),`docker sandbox `,m&&(0,S.jsxs)(`span`,{className:`opt-hint`,children:[`— `,m]})]}),(0,S.jsxs)(`label`,{children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:o,onChange:e=>s(e.target.checked),disabled:!i}),`forward SSH agent`]})]}),u&&(0,S.jsx)(`div`,{className:`gate-fail-msg`,children:u})]})}function ui({slug:e}){return(0,S.jsxs)(`nav`,{className:`crumbs`,children:[(0,S.jsx)(A,{href:`/workflows`,children:`workflows`}),(0,S.jsx)(`span`,{className:`sep`,children:`/`}),(0,S.jsx)(`span`,{className:`mono`,children:e})]})}function di({a:e,idx:t}){return(0,S.jsxs)(`div`,{className:`agent-card aid-${t}`,children:[(0,S.jsxs)(`div`,{className:`agent-head`,children:[(0,S.jsx)(`span`,{className:`agent-dot`}),(0,S.jsx)(`b`,{children:e.name??e.id}),(0,S.jsxs)(`code`,{className:`agent-id`,children:[`[`,e.id,`]`]}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsxs)(`span`,{className:`chip`,children:[e.model??`default`,e.effort?` · ${e.effort}`:``]})]}),e.tools.length>0&&(0,S.jsx)(`div`,{className:`agent-tools`,children:e.tools.map(e=>(0,S.jsx)(`span`,{className:`tool-chip`,children:e},e))}),e.persona&&(0,S.jsx)(`p`,{className:`agent-persona`,children:e.persona})]})}function fi({s:e,i:t,idx:n}){let r=e.kind===`script`?e.script:e.prompt;return(0,S.jsxs)(`div`,{className:`step-node`,children:[(0,S.jsx)(`div`,{className:`step-index num ${n==null?`is-script`:`aid-${n}`}`,children:t+1}),(0,S.jsxs)(`div`,{className:`step-body`,children:[(0,S.jsxs)(`div`,{className:`phase-top`,children:[(0,S.jsx)(`span`,{className:`phase-name`,children:e.name}),e.kind===`agent`?(0,S.jsxs)(`span`,{className:`chip agent-chip aid-${n??0}`,children:[`agent · `,e.agent]}):(0,S.jsxs)(`span`,{className:`chip`,children:[`script`,e.sourceRef?` · ${e.sourceRef}`:``]})]}),r&&(0,S.jsxs)(`details`,{className:`step-source`,children:[(0,S.jsx)(`summary`,{children:e.kind===`agent`?`prompt`:`script`}),(0,S.jsx)(`pre`,{children:r})]}),e.gates.length>0&&(0,S.jsx)(`div`,{className:`gate-line`,children:e.gates.map(e=>(0,S.jsxs)(`span`,{className:`gate neutral`,children:[`⛨ `,e]},e))})]})]})}var pi=e=>e===`ok`?`ok`:e===`running`?`running`:e===`aborted`?`aborted`:`failed`,mi=e=>e===`ok`?`done`:e===`running`?`working`:e===`aborted`?`stopped`:`failed`;function hi(e){return e.scope.kind===`agent`?`/agents/${e.scope.slug}/chat/${e.id}`:`/agents/chats/${e.id}`}function gi(e){switch(e.scope.kind){case`agent`:return e.scope.slug;case`run`:return e.scope.runId;case`knowledge`:return e.scope.bundle?`knowledge:${e.scope.bundle}`:`knowledge`;case`kraftwerk`:return`kraftwerk-aware`;default:return`general`}}function _i(e){return e.length>64?`${e.slice(0,46)}…${e.slice(-14)}`:e}function vi(){let e=F(`/api/runs`,!1),t=F(`/api/chats`,!1),n=F(`/api/knowledge`,!1),r=F(`/api/agents`,!1),i=F(`/api/workflows`,!1),a=F(`/api/skills`,!1),o=F(`/api/meta`,!1),[s,c]=(0,v.useState)(`all`),l=e?.runs??[],u=t?.chats??[],d=n?.bundles??[],f=(a?.skills??[]).filter(e=>e.source===`workspace`),p=[[i?.workflows.length,`workflows`,`/workflows`],[e?l.length:void 0,`runs`,`/runs`],[n?d.length:void 0,`bundles`,`/knowledge`],[a?f.length:void 0,`skills`,`/skills`],[t?u.length:void 0,`chats`,`/agents/chats`]],m=l.filter(e=>e.status===`failed`&&Date.now()-Date.parse(e.updatedAt)<864e5);return(0,S.jsxs)(`div`,{className:`dash`,children:[(0,S.jsxs)(`div`,{className:`page-head`,children:[(0,S.jsxs)(`h1`,{children:[o?.projectIcon?`${o.projectIcon} `:``,o?.projectName||`workspace`]}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsx)(`span`,{className:`dash-mini`,children:p.map(([e,t,n])=>(0,S.jsxs)(A,{href:n,children:[(0,S.jsx)(`b`,{className:`num`,children:e??`…`}),` `,t]},t))}),(0,S.jsx)(yi,{workflows:i?.workflows??[]})]}),(0,S.jsx)(bi,{agents:r?.agents.filter(e=>!e.archived),chats:u}),m.length>0&&s!==`failed`&&(0,S.jsxs)(`button`,{className:`dash-alert`,onClick:()=>c(`failed`),children:[`⚠ `,m.length,` run`,m.length===1?``:`s`,` failed in the last 24 h — review`]}),(0,S.jsx)(Ci,{runs:l,chats:u,bundles:d,agents:r?.agents??[],workflows:i?.workflows??[],filter:s,setFilter:c})]})}function yi({workflows:e}){let[t,n]=(0,v.useState)(!1);return(0,v.useEffect)(()=>{if(!t)return;let e=e=>{e.target.closest(`.wf-pick-wrap`)||n(!1)};return window.addEventListener(`mousedown`,e),()=>window.removeEventListener(`mousedown`,e)},[t]),(0,S.jsxs)(`div`,{className:`dash-actions`,children:[(0,S.jsxs)(`button`,{className:`run-btn dash-newchat`,onClick:()=>k(`/agents/chats`),children:[(0,S.jsx)(C,{name:`forum`}),` new chat`]}),(0,S.jsxs)(`span`,{className:`wf-pick-wrap`,children:[(0,S.jsxs)(`button`,{className:`run-btn tonal`,"aria-haspopup":`menu`,"aria-expanded":t,onClick:()=>n(e=>!e),children:[(0,S.jsx)(C,{name:`play_arrow`}),` run workflow`]}),t&&(0,S.jsxs)(`div`,{className:`wf-pick-pop`,role:`menu`,children:[e.length===0&&(0,S.jsx)(`span`,{className:`wf-pick-empty`,children:`no workflows yet`}),e.map(e=>(0,S.jsxs)(A,{href:`/workflows/${encodeURIComponent(e.slug)}`,className:`wf-pick-item`,role:`menuitem`,children:[(0,S.jsx)(`span`,{className:`wf-pick-name`,children:e.name??e.slug}),e.description&&(0,S.jsx)(`span`,{className:`wf-pick-desc`,children:e.description})]},e.slug))]})]})]})}function bi({agents:e,chats:t}){let n=N();return e&&e.length===0?(0,S.jsx)(`section`,{className:`panel dash-agents-empty`,children:(0,S.jsx)(`div`,{className:`viewer-note`,children:n?(0,S.jsxs)(S.Fragment,{children:[`No agents yet — `,(0,S.jsx)(A,{href:`/agents/new`,children:`create your first agent`}),` and it will show up here, ready to chat.`]}):(0,S.jsx)(S.Fragment,{children:`No agents yet — ask an expert-mode user to create one.`})})}):(0,S.jsx)(`div`,{className:`dash-agents`,children:(e??[]).map(e=>{let n=t.filter(t=>t.scope.kind===`agent`&&t.scope.slug===e.slug),r=n.find(e=>e.awaitingApproval),i=n.find(e=>e.busy),a=()=>k(`/agents/${encodeURIComponent(e.slug)}`);return(0,S.jsxs)(`div`,{className:`dash-agent`,role:`link`,tabIndex:0,onClick:a,onKeyDown:e=>{e.key===`Enter`&&a()},children:[(0,S.jsxs)(`div`,{className:`dash-agent-id`,children:[(0,S.jsxs)(`span`,{className:`agent-avatar lg`,children:[(0,S.jsx)(`span`,{"aria-hidden":!0,children:e.emoji}),(0,S.jsx)(`span`,{className:`lamp ${i?`running`:`idle`}`})]}),(0,S.jsx)(`span`,{className:`dash-agent-name`,children:e.name}),e.description&&(0,S.jsx)(`span`,{className:`dash-agent-desc`,children:e.description})]}),(0,S.jsxs)(`div`,{className:`dash-agent-foot`,children:[(0,S.jsx)(`span`,{className:`dash-agent-state`,children:r?(0,S.jsx)(A,{href:`/agents/${encodeURIComponent(e.slug)}/chat/${r.id}`,className:`chip attention`,onClick:e=>e.stopPropagation(),children:`needs approval`}):i&&(0,S.jsx)(A,{href:`/agents/${encodeURIComponent(e.slug)}/chat/${i.id}`,onClick:e=>e.stopPropagation(),children:`working…`})}),(0,S.jsxs)(`button`,{className:`run-btn dash-chat-btn`,onClick:t=>{t.stopPropagation(),Rr(`claude`,{kind:`agent`,slug:e.slug})},children:[(0,S.jsx)(C,{name:`chat_bubble`,className:`ms-sm`}),` chat`]})]})]},e.slug)})})}function xi(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 Si=[[`all`,`all`],[`run`,`runs`],[`session`,`chats`],[`knowledge`,`knowledge`]];function Ci({runs:e,chats:t,bundles:n,agents:r,workflows:i,filter:a,setFilter:o}){let s=N(),c=(0,v.useMemo)(()=>{let o=[],c=e=>e?i.find(t=>t.slug===e)?.name??e:void 0;for(let t of e)o.push({at:t.updatedAt,kind:`run`,emoji:`⚙️`,title:c(t.workflow)??t.id,sub:t.request??``,href:`/runs/${t.id}`,lamp:pi(t.status),status:mi(t.status)});for(let e of t){let t=e.scope.kind===`agent`?r.find(t=>e.scope.kind===`agent`&&t.slug===e.scope.slug):void 0;o.push({at:e.updatedAt,kind:`session`,emoji:t?t.emoji||`🤖`:`💬`,title:t?t.name:e.title||`new chat`,sub:t?`${e.title||`new chat`}${s?` · ${e.agent}`:``}`:s?`${e.agent} · ${gi(e)}`:gi(e),href:hi(e),lamp:e.awaitingApproval?`blocked`:e.busy?`running`:`ok`,status:e.awaitingApproval?`needs approval`:e.busy?`working`:void 0})}for(let e of n)e.updatedAt&&o.push({at:e.updatedAt,kind:`knowledge`,emoji:`📚`,title:e.name,sub:`${e.concepts} concepts`,href:`/knowledge/${encodeURIComponent(e.name)}`,lamp:`ok`});return(a===`all`?o:a===`failed`?o.filter(e=>e.kind===`run`&&e.lamp===`failed`):o.filter(e=>e.kind===a)).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)},[e,t,n,r,s,a]),l=``;return(0,S.jsxs)(`section`,{className:`panel dash-feed`,children:[(0,S.jsxs)(`div`,{className:`panel-head`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`activity`}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsxs)(`span`,{className:`dash-feed-filter`,children:[Si.map(([e,t])=>(0,S.jsx)(`button`,{className:`feed-chip ${a===e?`on`:``}`,onClick:()=>o(e),children:t},e)),a===`failed`&&(0,S.jsxs)(`button`,{className:`feed-chip on failed`,onClick:()=>o(`all`),children:[`failed `,(0,S.jsx)(C,{name:`close`,className:`ms-sm`})]})]})]}),c.length===0?(0,S.jsx)(`div`,{className:`viewer-note`,children:a===`all`?`nothing yet — run a workflow or start a session`:`nothing here for this filter`}):(0,S.jsx)(`div`,{className:`m3-list`,children:c.map(e=>{let t=xi(e),n=t===l?null:t;return l=t,(0,S.jsxs)(`div`,{className:`feed-group`,children:[n&&(0,S.jsx)(`div`,{className:`feed-day microlabel`,children:n}),(0,S.jsxs)(A,{href:e.href,className:`m3-row m3-link`,children:[(0,S.jsxs)(`span`,{className:`agent-avatar`,children:[(0,S.jsx)(`span`,{"aria-hidden":!0,children:e.emoji}),e.lamp===`running`&&(0,S.jsx)(`span`,{className:`lamp running`})]}),(0,S.jsx)(`span`,{className:`chip dash-kind ${e.kind}`,children:e.kind===`session`?`chat`:e.kind}),(0,S.jsxs)(`span`,{className:`m3-body`,children:[(0,S.jsx)(`span`,{className:`m3-head`,children:_i(e.title)}),e.sub&&(0,S.jsx)(`span`,{className:`m3-sub`,children:_i(e.sub)})]}),e.status&&(0,S.jsx)(`span`,{className:`chip status ${e.lamp}`,children:e.status}),(0,S.jsx)(`span`,{className:`side-when num`,title:new Date(e.at).toLocaleString(),children:ve(e.at)}),(0,S.jsx)(`span`,{className:`m3-chev`,children:(0,S.jsx)(C,{name:`chevron_right`})})]})]},`${e.kind}:${e.href}:${e.at}`)})})]})}async function wi(e,t){let n=window.open(``,`_blank`);if(!n)return;let r=t?`${e}/${t}`:e;n.document.write(`<title>${Oi(r)}</title><body style="font-family:system-ui;padding:40px;color:#555">preparing ${Oi(r)}…</body>`);let i=t=>`/api/knowledge/${encodeURIComponent(e)}/concept?id=${encodeURIComponent(t)}`,a,o=``;try{let[n,r]=await Promise.all([t?Promise.resolve([t]):fetch(`/api/knowledge/${encodeURIComponent(e)}`).then(e=>e.json()).then(e=>e.concepts.map(e=>e.id)),fetch(`/api/meta`).then(e=>e.json()).catch(()=>({}))]);if(o=r.projectName??``,a=await Promise.all(n.map(e=>fetch(i(e)).then(e=>e.json()))),a.some(e=>typeof e?.id!=`string`))throw Error(`missing concept`)}catch{n.document.body.textContent=`could not load "${r}"`;return}let s=[],c=a.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}=Ei(Ti(e.body??``,null)),i=!e.title||e.title===e.id||e.title===e.id.split(`/`).pop(),{html:a,title:o}=Di(kr.sanitize(z.parse(n,{async:!1})),{title:e.title||e.id,meta:t,titleIsFallback:i});return s.push(o),`<article>
77
+ `):`(no output yet)`})]})}function Nr({chatId:e,slug:t,onClosed:n}){let[r,i]=(0,v.useState)(``);return(0,S.jsxs)(`aside`,{className:`vibeable-pane vibeable-pane-off`,"data-vibe":t,children:[(0,S.jsxs)(`div`,{className:`vibeable-bar`,children:[(0,S.jsx)(C,{name:`web`,className:`vibeable-bar-icon`}),(0,S.jsx)(`span`,{className:`vibeable-name`,children:t}),(0,S.jsxs)(`span`,{className:`vibeable-mode failed`,children:[(0,S.jsx)(`span`,{className:`lamp failed`}),`vibeables are off`]}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsx)(`button`,{className:`icon-btn`,onClick:()=>Ar(e,null).then(n).catch(e=>i(e.message)),title:`Detach the app from this chat`,"aria-label":`close preview`,children:(0,S.jsx)(C,{name:`close`})})]}),(0,S.jsxs)(`div`,{className:`vibeable-note`,children:[`This chat has `,(0,S.jsx)(`b`,{children:t}),` open, but vibeables were switched off in `,(0,S.jsx)(`a`,{href:`#/settings`,children:`settings`}),`. Turn them back on to see the preview, or detach the app.`]}),r&&(0,S.jsx)(`div`,{className:`vibeable-err`,children:(0,S.jsx)(`span`,{children:r})})]})}var Pr=`kw-vibeable-agent`;async function Fr(e,t){let n=await fetch(`/api/chats`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({agent:t,scope:{kind:`general`}})}),r=await n.json();if(!n.ok||!r.id)throw Error(r.error||`HTTP ${n.status}`);await Ar(r.id,e),k(`/agents/chats/${r.id}`)}function Ir(){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)(null),[f,p]=(0,v.useState)(()=>{try{let e=localStorage.getItem(Pr);return e===`codex`||e===`pi`?e:`claude`}catch{return`claude`}}),m=N(),h=(0,v.useCallback)(async()=>{try{let e=await fetch(`/api/vibeables`,{cache:`no-store`});if(!e.ok)throw Error(`HTTP ${e.status}`);t(await e.json()),r(``)}catch(e){r(e.message||`could not load vibeables`)}},[]);(0,v.useEffect)(()=>{let e=!0,t,n=async()=>{await h(),e&&(t=setTimeout(n,15e3))};return n(),()=>{e=!1,clearTimeout(t)}},[h]);let g=(e,t)=>s(n=>({...n,[e]:t})),_=e=>s(t=>{let n={...t};return delete n[e],n}),y=(e,t)=>l(n=>({...n,[e]:t.message})),b=async e=>{e.preventDefault();let t=i.trim();if(t&&!o.__new){g(`__new`,`create`),l(e=>({...e,__new:``}));try{let e=await fetch(`/api/vibeables`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:t})}),n=await e.json();if(!e.ok)throw Error(n.error||`HTTP ${e.status}`);a(``),await h()}catch(e){y(`__new`,e)}finally{_(`__new`)}}},x=async e=>{g(e,`open`);try{await Fr(e,f)}catch(t){y(e,t),_(e)}},w=async e=>{g(e,`remove`),d(null);try{let t=await fetch(`/api/vibeables/${encodeURIComponent(e)}`,{method:`DELETE`}),n=await t.json();if(!t.ok||!n.ok)throw Error(n.error||`failed`)}catch(t){y(e,t)}finally{_(e),h()}},T=e=>{p(e);try{localStorage.setItem(Pr,e)}catch{}},E=[...e?.vibeables??[]].sort((e,t)=>(t.updatedAt??``).localeCompare(e.updatedAt??``));return(0,S.jsxs)(`div`,{className:`settings-screen ws-screen vibeables-screen`,children:[(0,S.jsxs)(`div`,{className:`settings-head`,children:[(0,S.jsxs)(`h1`,{children:[(0,S.jsx)(C,{name:`web`,className:`ms-lg`}),` Vibeables`]}),(0,S.jsx)(`span`,{className:`spacer`}),e?.enabled&&(0,S.jsxs)(`span`,{className:`settings-note`,children:[E.length,` app`,E.length===1?``:`s`]}),n&&(0,S.jsx)(`span`,{className:`settings-err`,children:n})]}),e&&!e.enabled&&(0,S.jsx)(`section`,{className:`panel`,children:(0,S.jsx)(`div`,{className:`ws-empty`,children:e.error&&!/are off/.test(e.error)?(0,S.jsx)(`span`,{className:`settings-err`,children:e.error}):(0,S.jsxs)(S.Fragment,{children:[`Vibeables are off. Turn them on in `,(0,S.jsx)(`a`,{href:`#/settings`,children:`settings`}),` or add a `,(0,S.jsx)(`code`,{children:`vibeables:`}),` block to kraftwerk.yml.`]})})}),e?.enabled&&(0,S.jsxs)(`section`,{className:`panel`,children:[(0,S.jsxs)(`div`,{className:`panel-head`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`new vibeable`}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsxs)(`span`,{className:`settings-note`,children:[`one folder each under `,(0,S.jsx)(`code`,{title:e.root,children:e.root})]})]}),(0,S.jsxs)(`form`,{className:`agent-form`,onSubmit:e=>void b(e),children:[(0,S.jsxs)(`div`,{className:`agent-form-row`,children:[(0,S.jsxs)(`label`,{className:`agent-field`,style:{flex:1},children:[`name`,(0,S.jsx)(`input`,{value:i,placeholder:`e.g. team-dashboard`,onChange:e=>a(e.target.value),autoFocus:!0})]}),(0,S.jsxs)(`button`,{className:`ws-btn primary`,type:`submit`,disabled:!!o.__new||!i.trim(),children:[(0,S.jsx)(C,{name:o.__new?`progress_activity`:`add`,className:`ms-sm`}),o.__new?`creating…`:`create`]})]}),c.__new&&(0,S.jsx)(`div`,{className:`settings-err`,children:c.__new}),(0,S.jsx)(`div`,{className:`settings-note`,children:`A small app built live with an agent: a chat on the left, the app rendered on the right, every saved file shows up at once. Part of the workspace — commit it from the git screen.`})]})]}),e?.enabled&&(0,S.jsxs)(`section`,{className:`panel`,children:[(0,S.jsxs)(`div`,{className:`panel-head`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`vibeables · newest change first`}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsxs)(`label`,{className:`vibeables-agent`,children:[`open in chat with`,(0,S.jsxs)(`select`,{value:f,onChange:e=>T(e.target.value),"aria-label":`agent for new chats`,children:[(0,S.jsx)(`option`,{value:`claude`,children:`claude`}),(0,S.jsx)(`option`,{value:`codex`,children:`codex`}),(0,S.jsx)(`option`,{value:`pi`,children:`pi`})]})]})]}),E.length===0&&(0,S.jsx)(`div`,{className:`ws-empty`,children:`Nothing built yet — create one above, or press the vibeable button in any chat.`}),E.map(e=>{let t=o[e.slug],n=e.configError?{label:`config error`,cls:`missing`}:e.hasIndex?{label:e.dev?`dev`:`static`,cls:`running`}:{label:`no index.html yet`,cls:`stopped`};return(0,S.jsxs)(`div`,{className:`ws-row vibeable-row state-${n.cls}`,"data-vibeable":e.slug,children:[(0,S.jsx)(`span`,{className:`vibeable-repo-icon ws-icon`,children:(0,S.jsx)(C,{name:e.dev?`terminal`:`web`})}),(0,S.jsxs)(`div`,{className:`ws-main`,children:[(0,S.jsxs)(`div`,{className:`ws-title`,children:[(0,S.jsx)(`span`,{className:`ws-name`,children:e.slug}),(0,S.jsx)(`span`,{className:`ws-state ws-state-${n.cls}`,children:n.label}),e.updatedAt&&(0,S.jsxs)(`span`,{className:`vibeable-when`,title:e.updatedAt,children:[`changed `,ve(e.updatedAt)]})]}),e.dev&&(0,S.jsx)(`div`,{className:`ws-root`,title:`dev command from vibeable.yml`,children:(0,S.jsx)(`code`,{children:e.dev})}),m&&(0,S.jsx)(`div`,{className:`ws-root ws-dim`,title:e.path,children:e.path}),e.configError&&(0,S.jsx)(`div`,{className:`settings-err`,children:e.configError}),c[e.slug]&&(0,S.jsx)(`div`,{className:`settings-err`,children:c[e.slug]})]}),(0,S.jsxs)(`div`,{className:`ws-actions`,children:[(0,S.jsxs)(`button`,{className:`ws-btn primary`,disabled:!!t,onClick:()=>void x(e.slug),title:`Start a ${f} chat with this app in the preview pane`,children:[(0,S.jsx)(C,{name:t===`open`?`progress_activity`:`chat`,className:`ms-sm`}),` open in chat`]}),(0,S.jsxs)(`a`,{className:`ws-btn`,href:`/vibeables/${encodeURIComponent(e.slug)}/`,target:`_blank`,rel:`noopener`,title:`Open the static preview in a new tab`,children:[(0,S.jsx)(C,{name:`open_in_new`,className:`ms-sm`}),` preview`]}),u!==e.slug&&(0,S.jsxs)(`button`,{className:`ws-btn`,disabled:!!t,onClick:()=>d(e.slug),title:`Delete the folder; its history stays in the workspace git`,children:[(0,S.jsx)(C,{name:`delete`,className:`ms-sm`}),` remove`]}),u===e.slug&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`button`,{className:`ws-btn danger`,onClick:()=>void w(e.slug),children:[(0,S.jsx)(C,{name:`delete`,className:`ms-sm`}),` confirm remove`]}),(0,S.jsx)(`button`,{className:`ws-btn`,onClick:()=>d(null),children:`cancel`})]})]})]},e.slug)})]})]})}function Lr({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=F(`/api/channels`,!1,4e3),i=F(`/api/agents`,!1,15e3),a=r?.channels??[],o=t?a.find(e=>e.slug===t):void 0,s;return s=n===`new`?(0,S.jsx)(zr,{agents:i?.agents??[]}):n===`edit`&&o?(0,S.jsx)(zr,{channel:o,agents:i?.agents??[]},o.slug):n===`channel`&&o?(0,S.jsx)(`div`,{className:`chat-main`,children:(0,S.jsx)(qr,{id:o.chatId,channel:o,agents:i?.agents??[]},o.chatId)}):n===`channel`&&r?(0,S.jsx)(`div`,{className:`empty`,children:`channel not found`}):n===`channel`?(0,S.jsx)(`div`,{className:`empty`,children:`loading…`}):(0,S.jsx)(Rr,{count:a.length,root:r?.root}),(0,S.jsxs)(`div`,{className:`runs-screen channels-screen`,children:[(0,S.jsxs)(`aside`,{className:`runs-side`,children:[(0,S.jsxs)(`div`,{className:`side-head`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`channels`}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsxs)(A,{href:`/channels/new`,className:`open-raw`,children:[(0,S.jsx)(C,{name:`add`,className:`ms-sm`}),` new`]})]}),(0,S.jsxs)(`div`,{className:`side-list`,children:[a.map(e=>(0,S.jsxs)(A,{href:`/channels/${encodeURIComponent(e.slug)}`,className:`side-row ${e.slug===t?`active`:``}`,children:[(0,S.jsx)(`span`,{className:`lamp ${e.awaitingApproval?`blocked`:e.busy?`running`:`pending`}`,title:e.awaitingApproval?`waiting for your approval`:e.busy?`an agent is working`:void 0}),(0,S.jsxs)(`div`,{className:`side-row-body`,children:[(0,S.jsx)(`div`,{className:`side-row-top`,children:(0,S.jsxs)(`span`,{className:`side-wf`,children:[`#`,e.slug]})}),(0,S.jsxs)(`div`,{className:`side-row-sub`,children:[(0,S.jsxs)(`span`,{className:`side-req`,children:[e.name,e.members.length?` · ${e.members.map(e=>`@${e}`).join(` `)}`:``]}),(0,S.jsx)(`span`,{className:`side-when num`,children:_e(e.updatedAt)})]})]})]},e.slug)),r&&a.length===0&&(0,S.jsx)(`div`,{className:`viewer-note`,children:`no channels yet — create one, or add a coworker to an agent session`})]})]}),(0,S.jsx)(`div`,{className:`runs-main`,children:s})]})}function Rr({count:e,root:t}){return(0,S.jsx)(`div`,{className:`new-chat`,children:(0,S.jsxs)(`div`,{className:`panel new-chat-panel`,children:[(0,S.jsx)(`div`,{className:`panel-head`,children:(0,S.jsx)(`span`,{className:`microlabel`,children:`channels`})}),(0,S.jsxs)(`div`,{className:`panel-body`,style:{display:`grid`,gap:12},children:[(0,S.jsx)(`p`,{children:`A channel is a shared conversation with several agents at once — a Slack channel where the coworkers are agents. @mention an agent to wake it; agents hand work to each other by mentioning; a channel can name one responder that answers when nobody is mentioned.`}),(0,S.jsxs)(`p`,{children:[e===0?`No channels yet. `:`${e} channel${e===1?``:`s`}. `,`Definitions live in `,(0,S.jsx)(`code`,{children:t??`channels/`}),` and travel with the workspace.`]}),(0,S.jsx)(`div`,{children:(0,S.jsxs)(A,{href:`/channels/new`,className:`run-btn`,children:[(0,S.jsx)(C,{name:`add`,className:`ms-sm`}),` new channel`]})})]})]})})}function zr({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=await fetch(e?`/api/channels/${encodeURIComponent(e.slug)}`:`/api/channels`,{method:e?`PUT`:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:n,purpose:i,members:o,responder:c||null})}),r=await t.json();if(!t.ok||r.error)throw Error(r.error??`HTTP ${t.status}`);k(`/channels/${encodeURIComponent(r.slug)}`)}catch(e){p(e.message)}d(!1)}async function _(){e&&window.confirm(`Delete #${e.slug} and its transcript?`)&&(await fetch(`/api/channels/${encodeURIComponent(e.slug)}`,{method:`DELETE`}).catch(()=>{}),k(`/channels`))}return(0,S.jsx)(`div`,{className:`new-chat`,children:(0,S.jsxs)(`div`,{className:`panel new-chat-panel`,children:[(0,S.jsxs)(`div`,{className:`panel-head`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:e?`edit #${e.slug}`:`new channel`}),(0,S.jsx)(`span`,{className:`spacer`}),e&&(0,S.jsxs)(`button`,{className:`open-raw`,onClick:()=>void _(),children:[(0,S.jsx)(C,{name:`delete`,className:`ms-sm`}),` delete`]})]}),(0,S.jsxs)(`div`,{className:`agent-form`,children:[(0,S.jsxs)(`label`,{className:`agent-field`,children:[`name`,(0,S.jsx)(`input`,{value:n,placeholder:`e.g. Website relaunch`,onChange:e=>r(e.target.value),autoFocus:!0})]}),(0,S.jsxs)(`label`,{className:`agent-field`,children:[`purpose — one line the agents read`,(0,S.jsx)(`input`,{value:i,placeholder:`what this channel is for`,onChange:e=>a(e.target.value)})]}),(0,S.jsxs)(`div`,{className:`agent-field`,children:[`members — agents in this channel`,(0,S.jsxs)(`div`,{className:`wf-checks`,children:[m.map(e=>(0,S.jsxs)(`label`,{children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:o.includes(e.slug),onChange:t=>h(e.slug,t.target.checked)}),(0,S.jsxs)(`b`,{children:[e.emoji,` `,e.name]}),(0,S.jsxs)(`span`,{className:`opt-hint`,children:[` — @`,e.slug,e.description?` · ${e.description}`:``]})]},e.slug)),m.length===0&&(0,S.jsx)(`div`,{className:`viewer-note`,children:`no agents yet — create one on the agents screen first`})]})]}),(0,S.jsxs)(`label`,{className:`agent-field`,children:[`responder — answers when a message mentions nobody`,(0,S.jsxs)(`select`,{value:c,onChange:e=>l(e.target.value),children:[(0,S.jsx)(`option`,{value:``,children:`nobody (agents only answer when @mentioned)`}),o.map(e=>(0,S.jsxs)(`option`,{value:e,children:[`@`,e]},e))]})]}),f&&(0,S.jsxs)(`div`,{className:`msg error`,children:[(0,S.jsx)(C,{name:`error`,className:`ms-sm`}),` `,f]}),(0,S.jsxs)(`div`,{className:`agent-form-row`,children:[(0,S.jsx)(`button`,{className:`run-btn`,disabled:u||!n.trim()||o.length===0,onClick:()=>void g(),children:u?`saving…`:e?`save`:`create channel`}),(0,S.jsx)(A,{href:e?`/channels/${encodeURIComponent(e.slug)}`:`/channels`,className:`open-raw`,children:`cancel`})]})]})]})})}function Br({chatId:e,agentSlug:t,title:n,onClose:r}){let[i,a]=(0,v.useState)([]),[o,s]=(0,v.useState)(n||``),[c,l]=(0,v.useState)([]),[u,d]=(0,v.useState)(!1),[f,p]=(0,v.useState)(``);(0,v.useEffect)(()=>{fetch(`/api/agents`).then(e=>e.json()).then(e=>a(e.agents.filter(e=>!e.archived&&e.slug!==t))).catch(()=>{})},[t]);async function m(){d(!0),p(``);try{let n=await fetch(`/api/channels/from-chat`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({chatId:e,name:o,members:[t,...c],responder:t})}),i=await n.json();if(!n.ok||!i.slug)throw Error(i.error??`HTTP ${n.status}`);r(),k(`/channels/${encodeURIComponent(i.slug)}`)}catch(e){p(e.message)}d(!1)}return(0,S.jsx)(`div`,{className:`dialog-backdrop`,onMouseDown:e=>e.target===e.currentTarget&&r(),children:(0,S.jsxs)(`div`,{className:`dialog`,role:`dialog`,"aria-label":`Add a coworker`,children:[(0,S.jsxs)(`div`,{className:`panel-head`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`add a coworker`}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsx)(`button`,{className:`open-raw`,onClick:r,children:(0,S.jsx)(C,{name:`close`,className:`ms-sm`})})]}),(0,S.jsxs)(`div`,{className:`agent-form`,children:[(0,S.jsxs)(`p`,{className:`viewer-note`,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,S.jsxs)(`label`,{className:`agent-field`,children:[`channel name`,(0,S.jsx)(`input`,{value:o,placeholder:`e.g. Website relaunch`,onChange:e=>s(e.target.value),autoFocus:!0})]}),(0,S.jsxs)(`div`,{className:`agent-field`,children:[`invite`,(0,S.jsxs)(`div`,{className:`wf-checks`,children:[i.map(e=>(0,S.jsxs)(`label`,{children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:c.includes(e.slug),onChange:t=>l(n=>t.target.checked?[...n,e.slug]:n.filter(t=>t!==e.slug))}),(0,S.jsxs)(`b`,{children:[e.emoji,` `,e.name]}),(0,S.jsxs)(`span`,{className:`opt-hint`,children:[` — @`,e.slug,e.description?` · ${e.description}`:``]})]},e.slug)),i.length===0&&(0,S.jsx)(`div`,{className:`viewer-note`,children:`no other agents to invite yet`})]})]}),f&&(0,S.jsxs)(`div`,{className:`msg error`,children:[(0,S.jsx)(C,{name:`error`,className:`ms-sm`}),` `,f]}),(0,S.jsxs)(`div`,{className:`agent-form-row`,children:[(0,S.jsx)(`button`,{className:`run-btn`,disabled:u||!o.trim()||c.length===0,onClick:()=>void m(),children:u?`creating…`:`create channel`}),(0,S.jsx)(`button`,{className:`open-raw`,onClick:r,children:`cancel`})]})]})]})})}var Vr=`kw-me`;function Hr(){try{return localStorage.getItem(Vr)||``}catch{return``}}function Ur(e){try{localStorage.setItem(Vr,e)}catch{}}var Wr=[{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 Gr(e,t){let n=await(await fetch(`/api/chats`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({agent:e,scope:t})})).json();n.id&&k(n.scope?.kind===`agent`?`/agents/${encodeURIComponent(n.scope.slug)}/chat/${n.id}`:`/agents/chats/${n.id}`)}function Kr(){let[e,t]=(0,v.useState)(`claude`),[n,r]=(0,v.useState)(!0),[i,a]=(0,v.useState)(!1);return(0,S.jsxs)(`div`,{className:`new-chat`,children:[(0,S.jsx)(`div`,{className:`page-head`,children:(0,S.jsx)(`h1`,{children:`new chat`})}),(0,S.jsxs)(`section`,{className:`panel new-chat-panel`,children:[(0,S.jsx)(`div`,{className:`panel-head`,children:(0,S.jsx)(`span`,{className:`microlabel`,children:`agent`})}),(0,S.jsx)(`div`,{className:`agent-pick`,children:Wr.map(n=>(0,S.jsxs)(`button`,{className:`agent-pick-btn ${e===n.id?`active`:``}`,onClick:()=>t(n.id),children:[(0,S.jsx)(`b`,{children:n.label}),(0,S.jsx)(`span`,{children:n.hint})]},n.id))}),(0,S.jsx)(`div`,{className:`run-opts`,style:{padding:`0 16px 14px`},children:(0,S.jsxs)(`label`,{children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:n,onChange:e=>r(e.target.checked)}),`kraftwerk-aware`,(0,S.jsx)(`span`,{className:`opt-hint`,children:`— agent gets workflows + recent runs as context`})]})}),(0,S.jsx)(`div`,{style:{padding:`0 16px 16px`},children:(0,S.jsx)(`button`,{className:`run-btn`,disabled:i,onClick:async()=>{a(!0),await Gr(e,{kind:n?`kraftwerk`:`general`}),a(!1)},children:i?`starting…`:`start chat`})})]})]})}function qr({id:e,agentName:t,agentDescription:n,channel:r,agents:i}){let[a,o]=(0,v.useState)(null),[s,c]=(0,v.useState)([]),[l,u]=(0,v.useState)(!1),[d,f]=(0,v.useState)(!1),[p,m]=(0,v.useState)(!1),h=P();(0,v.useEffect)(()=>{let t=!0,n=null;return fetch(`/api/chats/${e}`).then(e=>e.ok?e.json():Promise.reject()).then(r=>{if(!t)return;o(r.meta),c(r.events);let i=r.events[r.events.length-1]?.seq??0;n=new EventSource(`/api/chats/${e}/events?after=${i}`),n.onmessage=e=>{let t=JSON.parse(e.data);c(e=>e.some(e=>e.seq===t.seq)?e:[...e,t])}}).catch(()=>t&&u(!0)),()=>{t=!1,n?.close()}},[e]);let g=(0,v.useMemo)(()=>{if(!r)return[];let e=new Set;for(let t of s)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]},[s,r]),_=(0,v.useMemo)(()=>{if(r)return g.length>0;for(let e=s.length-1;e>=0;e--){let t=s[e].type;if(t===`user_message`)return!0;if(t===`turn_end`||t===`error`)return!1}return!1},[s,r,g]),y=(0,v.useMemo)(()=>{if(a?.title)return a.title;let e=s.find(e=>e.type===`user_message`);return e&&e.type===`user_message`?e.text.replace(/\s+/g,` `).trim().slice(0,80):``},[a,s]);if((0,v.useEffect)(()=>a?r?(ne(`#${r.slug} · ${r.name}`),()=>ne(``)):(ne([t??(a.scope.kind===`agent`?a.scope.slug:a.agent),n,y||`new chat`].filter(Boolean).join(` · `)),()=>ne(``)):void 0,[a,y,t,n,r]),l)return(0,S.jsx)(`div`,{className:`empty`,children:`chat not found`});if(!a)return(0,S.jsx)(`div`,{className:`empty`,children:`loading…`});let b=new Map((i??[]).map(e=>[e.slug,e]));return r?(0,S.jsx)(`div`,{className:`chat-split`,children:(0,S.jsxs)(`div`,{className:`chat-thread channel-thread`,children:[(0,S.jsxs)(`div`,{className:`detail-head channel-head`,children:[(0,S.jsx)(`span`,{className:`lamp ${_?`running`:`ok`}`}),(0,S.jsxs)(`h1`,{children:[`#`,r.slug]}),(0,S.jsx)(`span`,{className:`channel-name`,children:r.name}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsxs)(A,{href:`/channels/${encodeURIComponent(r.slug)}/edit`,className:`open-raw`,title:`members, purpose, responder`,children:[(0,S.jsx)(C,{name:`tune`,className:`ms-sm`}),` members`]})]}),(0,S.jsxs)(`div`,{className:`channel-members`,children:[r.purpose&&(0,S.jsx)(`span`,{className:`channel-purpose`,children:r.purpose}),r.members.map(e=>{let t=b.get(e),n=g.includes(e);return(0,S.jsxs)(A,{href:`/agents/${encodeURIComponent(e)}/info`,className:`member-chip ${n?`working`:``}`,title:t?.description,children:[(0,S.jsxs)(`span`,{className:`agent-avatar sm`,children:[(0,S.jsx)(`span`,{"aria-hidden":!0,children:t?.emoji??`🤖`}),(0,S.jsx)(`span`,{className:`lamp ${n?`running`:`idle`}`})]}),(0,S.jsx)(`span`,{className:`member-name`,children:t?.name??e}),(0,S.jsxs)(`span`,{className:`member-handle`,children:[`@`,e]}),r.responder===e&&(0,S.jsx)(`span`,{className:`chip`,children:`responder`})]},e)})]}),(0,S.jsx)(Xr,{id:e,events:s,busy:_,channel:r,agentMap:b,working:g}),(0,S.jsx)(ti,{id:e,busy:_,scope:a.scope,channel:r,agentMap:b})]})}):(0,S.jsxs)(`div`,{className:`chat-split${a.vibeable?` open`:``}`,children:[(0,S.jsxs)(`div`,{className:`chat-thread`,children:[(0,S.jsxs)(`div`,{className:`detail-head`,children:[(0,S.jsx)(`span`,{className:`lamp ${_?`running`:`ok`}`}),(0,S.jsx)(`h1`,{children:y||`new chat`}),a.scope.kind===`agent`&&!a.scope.routine&&(0,S.jsxs)(`button`,{className:`ws-btn coworker-btn`,onClick:()=>m(!0),title:`Turn this session into a channel and invite more agents`,disabled:_,children:[(0,S.jsx)(C,{name:`group_add`,className:`ms-sm`}),` add coworker`]}),!a.vibeable&&h.vibeables&&(0,S.jsxs)(`button`,{className:`ws-btn vibeable-open`,onClick:()=>f(!0),title:`Build a small app live: a preview pane next to this chat`,disabled:_,children:[(0,S.jsx)(C,{name:`web`,className:`ms-sm`}),` vibeable`]}),(0,S.jsx)(`span`,{className:`chip agent`,children:a.agent}),a.scope.kind===`run`&&(0,S.jsx)(A,{href:`/runs/${a.scope.runId}`,className:`chip`,children:a.scope.runId}),a.scope.kind===`kraftwerk`&&(0,S.jsx)(`span`,{className:`chip`,children:`kraftwerk-aware`}),a.scope.kind===`knowledge`&&(0,S.jsxs)(A,{href:a.scope.bundle?`/knowledge/${encodeURIComponent(a.scope.bundle)}`:`/knowledge`,className:`chip`,children:[`knowledge`,a.scope.bundle?`:${a.scope.bundle}`:``]}),a.scope.kind===`agent`&&(0,S.jsxs)(A,{href:`/agents/${encodeURIComponent(a.scope.slug)}/info`,className:`chip`,children:[`agent:`,a.scope.slug]}),(0,S.jsx)(`span`,{className:`rid`,title:a.cwd,children:a.cwd})]}),(0,S.jsx)(Xr,{id:e,events:s,busy:_}),(0,S.jsx)(ti,{id:e,busy:_,scope:a.scope})]}),a.vibeable&&h.vibeables&&(0,S.jsx)(Mr,{chatId:e,slug:a.vibeable,agentBusy:_,onClosed:o},a.vibeable),a.vibeable&&!h.vibeables&&(0,S.jsx)(Nr,{chatId:e,slug:a.vibeable,onClosed:o}),d&&(0,S.jsx)(jr,{chatId:e,onClose:()=>f(!1),onOpened:e=>{o(e),f(!1)}}),p&&a.scope.kind===`agent`&&(0,S.jsx)(Br,{chatId:e,agentSlug:a.scope.slug,title:y,onClose:()=>m(!1)})]})}var Jr=(e,t)=>!e&&!t||!!e&&!!t&&e.kind===t.kind&&(e.kind===`human`?e.name===t.name:e.slug===t.slug);function Yr(e){let t=[],n=new Map,r=new Map;for(let i of e){let e=t[t.length-1];switch(i.type){case`user_message`:t.push({kind:`user`,text:i.text,key:`e${i.seq}`,from:i.from});break;case`text`:e?.kind===`agent`&&Jr(e.from,i.from)?e.text+=i.text:t.push({kind:`agent`,text:i.text,key:`e${i.seq}`,from:i.from});break;case`thought`:e?.kind===`thought`&&Jr(e.from,i.from)?e.text+=i.text:t.push({kind:`thought`,text:i.text,key:`e${i.seq}`,from:i.from});break;case`tool_call`:n.set(i.callId,t.length),t.push({kind:`tool`,callId:i.callId,title:i.title,toolKind:i.kind,status:i.status,key:`e${i.seq}`,from:i.from});break;case`tool_update`:{let e=n.get(i.callId);if(e!=null){let n=t[e];i.title&&(n.title=i.title),i.status&&(n.status=i.status)}break}case`permission_request`:r.set(i.requestId,t.length),t.push({kind:`permission`,requestId:i.requestId,title:i.title,options:i.options,resolved:void 0,key:`e${i.seq}`,from:i.from});break;case`permission_resolved`:{let e=r.get(i.requestId);e!=null&&(t[e].resolved=i.optionId);break}case`error`:t.push({kind:`error`,text:i.message,key:`e${i.seq}`,from:i.from})}}return t}function Xr({id:e,events:t,busy:n,channel:r,agentMap:i,working:a}){let o=N(),s=(0,v.useMemo)(()=>{let e=Yr(t);return o?e:e.filter(e=>e.kind!==`tool`&&e.kind!==`thought`)},[t,o]),c=(0,v.useRef)(null),l=(0,v.useRef)(!0);return(0,v.useEffect)(()=>{let e=c.current;e&&l.current&&(e.scrollTop=e.scrollHeight)},[s,n]),(0,S.jsxs)(`div`,{className:`chat-scroll`,ref:c,onScroll:e=>{let t=e.currentTarget;l.current=t.scrollHeight-t.scrollTop-t.clientHeight<60},children:[s.length===0&&(0,S.jsx)(`div`,{className:`empty`,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`}),s.map((t,n)=>{let a=s[n-1],o=r&&t.kind!==`error`&&(!a||!Jr(a.from,t.from)||a.kind===`error`)?t.from:void 0;return(0,S.jsxs)(`div`,{className:`turn ${t.from?.kind===`human`?`human`:t.from?.kind===`agent`?`agent`:``}`,children:[o&&(0,S.jsx)(Zr,{from:o,agentMap:i}),(0,S.jsx)($r,{b:t,chatId:e})]},t.key)}),n&&(0,S.jsxs)(`div`,{className:`chat-working`,children:[(0,S.jsx)(`span`,{className:`lamp running`}),` `,r&&a?.length?a.map(e=>`${i?.get(e)?.emoji??``} @${e}`).join(`, `)+(a.length===1?` is working…`:` are working…`):`working…`]})]})}function Zr({from:e,agentMap:t}){if(e.kind===`human`)return(0,S.jsxs)(`div`,{className:`byline human`,children:[(0,S.jsx)(`span`,{className:`byline-avatar`,children:e.name.slice(0,1).toUpperCase()}),(0,S.jsx)(`span`,{className:`byline-name`,children:e.name})]});let n=t?.get(e.slug);return(0,S.jsxs)(A,{href:`/agents/${encodeURIComponent(e.slug)}/info`,className:`byline agent`,children:[(0,S.jsx)(`span`,{className:`byline-avatar`,children:n?.emoji??`🤖`}),(0,S.jsx)(`span`,{className:`byline-name`,children:n?.name??e.slug}),(0,S.jsxs)(`span`,{className:`byline-handle`,children:[`@`,e.slug]})]})}function Qr({text:e}){let t=(0,v.useMemo)(()=>kr.sanitize(z.parse(e,{async:!1})),[e]);return(0,S.jsx)(`div`,{className:`msg agent md-body chat-md`,dangerouslySetInnerHTML:{__html:t}})}function $r({b:e,chatId:t}){switch(e.kind){case`user`:return(0,S.jsx)(`div`,{className:`msg user`,children:e.text});case`agent`:return(0,S.jsx)(Qr,{text:e.text});case`thought`:return(0,S.jsxs)(`details`,{className:`msg thought`,children:[(0,S.jsx)(`summary`,{children:`thinking`}),(0,S.jsx)(`div`,{children:e.text})]});case`tool`:return(0,S.jsxs)(`div`,{className:`tool-card ${e.status??``}`,children:[(0,S.jsx)(`span`,{className:`lamp ${e.status===`completed`?`ok`:e.status===`failed`?`failed`:`running`}`}),e.toolKind&&(0,S.jsx)(`span`,{className:`chip tool-kind`,children:e.toolKind}),(0,S.jsx)(`span`,{className:`tool-title`,children:e.title})]});case`permission`:return(0,S.jsx)(ei,{b:e,chatId:t});case`error`:return(0,S.jsxs)(`div`,{className:`msg error`,children:[(0,S.jsx)(C,{name:`error`,className:`ms-sm`}),` `,e.text]})}}function ei({b:e,chatId:t}){let[n,r]=(0,v.useState)(!1),i=e.resolved===void 0;async function a(n){r(!0),await fetch(`/api/chats/${t}/permission`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({requestId:e.requestId,optionId:n})}).catch(()=>{}),r(!1)}return(0,S.jsxs)(`div`,{className:`perm-card ${i?`pending`:``}`,children:[(0,S.jsxs)(`div`,{className:`perm-title`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`permission`}),` `,e.title]}),i?(0,S.jsx)(`div`,{className:`perm-actions`,children:e.options.map(e=>(0,S.jsx)(`button`,{className:`perm-btn ${e.kind?.startsWith(`allow`)?`allow`:`deny`}`,disabled:n,onClick:()=>a(e.optionId),children:e.name},e.optionId))}):(0,S.jsx)(`div`,{className:`perm-resolved`,children:e.resolved?`→ ${e.options.find(t=>t.optionId===e.resolved)?.name??e.resolved}`:`→ dismissed`})]})}function ti({id:e,busy:t,scope:n,channel:r,agentMap:i}){let[a,o]=(0,v.useState)(``),[s,c]=(0,v.useState)([]),[l,u]=(0,v.useState)(0),[d,f]=(0,v.useState)(!1),[p,m]=(0,v.useState)(Hr),[h,g]=(0,v.useState)(!1),_=(0,v.useRef)(null),y=t&&!r;(0,v.useEffect)(()=>{let e=!0;return(async()=>{try{let t=(await fetch(`/api/skills`).then(e=>e.json())).skills??[];if(n?.kind===`agent`){let[e,r]=await Promise.all([fetch(`/api/agents/${encodeURIComponent(n.slug)}`).then(e=>e.ok?e.json():null).catch(()=>null),fetch(`/api/agents/${encodeURIComponent(n.slug)}/skills`).then(e=>e.ok?e.json():null).catch(()=>null)]);if(e&&Array.isArray(e.skills)){let n=new Set(e.skills.map(e=>e.toLowerCase()));t=t.filter(e=>n.has(e.name.toLowerCase()))}let i=r?.skills??[],a=new Set(i.map(e=>e.name.toLowerCase()));t=[...i,...t.filter(e=>!a.has(e.name.toLowerCase()))]}e&&c(t)}catch{}})(),()=>{e=!1}},[e]);let b=/^\/([\w-]*)$/.exec(a)?.[1],x=b!==void 0&&!d?s.filter(e=>e.name.toLowerCase().startsWith(b.toLowerCase())):[],w=_.current?.selectionStart??a.length,T=r&&!d?/(^|\s)@([a-z0-9-]*)$/i.exec(a.slice(0,w)):null,E=T&&r?r.members.filter(e=>e.startsWith(T[2].toLowerCase())||(i?.get(e)?.name??``).toLowerCase().startsWith(T[2].toLowerCase())):[],D=[...x.map(e=>({id:`/${e.name}`,label:`/${e.name}`,hint:e.description,src:e.source,pick:()=>{o(`/${e.name} `),u(0)}})),...E.map(e=>({id:`@${e}`,label:`${i?.get(e)?.emoji??`🤖`} @${e}`,hint:i?.get(e)?.name,pick:()=>{let t=a.slice(0,w).replace(/@[a-z0-9-]*$/i,`@${e} `);o(t+a.slice(w)),u(0),requestAnimationFrame(()=>{let e=_.current;e&&(e.selectionStart=e.selectionEnd=t.length)})}}))],O=D.length>0,ee=Math.min(l,D.length-1);async function te(){let t=a.trim();t&&!y&&(o(``),await fetch(`/api/chats/${e}/message`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:t,...r?{from:p||`you`}:{}})}).catch(()=>{}))}return(0,S.jsxs)(`div`,{className:`composer`,children:[r&&(0,S.jsxs)(`div`,{className:`composer-me`,children:[`posting as`,` `,h?(0,S.jsx)(`input`,{autoFocus:!0,value:p,placeholder:`your name`,onChange:e=>m(e.target.value),onBlur:()=>{Ur(p.trim()),g(!1)},onKeyDown:e=>{(e.key===`Enter`||e.key===`Escape`)&&e.target.blur()}}):(0,S.jsxs)(`button`,{className:`me-name`,onClick:()=>g(!0),title:`change your name`,children:[p||`you`,` `,(0,S.jsx)(C,{name:`edit`,className:`ms-sm`})]})]}),O&&(0,S.jsx)(`div`,{className:`skill-menu`,children:D.map((e,t)=>(0,S.jsxs)(`button`,{className:t===ee?`active`:``,onMouseDown:t=>{t.preventDefault(),e.pick()},children:[(0,S.jsx)(`b`,{children:e.label}),e.hint&&(0,S.jsxs)(`span`,{children:[` — `,e.hint]}),e.src&&(0,S.jsx)(`span`,{className:`skill-src`,children:e.src})]},e.id))}),(0,S.jsx)(`textarea`,{ref:_,value:a,placeholder:y?`agent is working…`:r?`message the channel · @ to mention an agent, / for skills, Enter to send`:`message · Enter to send, Shift+Enter for newline, / for skills`,rows:Math.min(6,Math.max(1,a.split(`
78
+ `).length)),onChange:e=>{o(e.target.value),u(0),f(!1)},onKeyDown:e=>{if(O){if(e.key===`ArrowDown`)return e.preventDefault(),u((ee+1)%D.length);if(e.key===`ArrowUp`)return e.preventDefault(),u((ee-1+D.length)%D.length);if(e.key===`Tab`||e.key===`Enter`)return e.preventDefault(),D[ee].pick();if(e.key===`Escape`)return e.preventDefault(),f(!0)}e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),te())}}),t&&(0,S.jsxs)(`button`,{className:`stop-btn`,onClick:()=>fetch(`/api/chats/${e}/cancel`,{method:`POST`}).catch(()=>{}),children:[(0,S.jsx)(C,{name:`stop`,className:`ms-sm`}),` stop`]}),!y&&(0,S.jsxs)(`button`,{className:`run-btn`,disabled:!a.trim(),onClick:te,children:[(0,S.jsx)(C,{name:`send`,className:`ms-sm`}),` send`]})]})}function ni({id:e}){let t=F(`/api/runs`,!0),n=t?.runs??[];return(0,S.jsxs)(`div`,{className:`runs-screen`,children:[(0,S.jsxs)(`aside`,{className:`runs-side`,children:[(0,S.jsxs)(`div`,{className:`side-head`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`runs`}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsx)(`span`,{className:`microlabel num`,children:n.length})]}),(0,S.jsxs)(`div`,{className:`side-list`,children:[n.map(t=>(0,S.jsx)(ri,{r:t,active:t.id===e},t.id)),t&&n.length===0&&(0,S.jsx)(`div`,{className:`viewer-note`,children:`no runs yet`})]})]}),(0,S.jsx)(`div`,{className:`runs-main`,children:(0,S.jsx)(ii,{id:e},e)})]})}function ri({r:e,active:t}){return(0,S.jsxs)(A,{href:`/runs/${e.id}`,className:`side-row ${t?`active`:``}`,children:[(0,S.jsx)(be,{status:e.status}),(0,S.jsxs)(`div`,{className:`side-row-body`,children:[(0,S.jsxs)(`div`,{className:`side-row-top`,children:[(0,S.jsx)(`span`,{className:`side-wf`,children:e.workflow??`unknown`}),(0,S.jsx)(`span`,{className:`side-when num`,children:_e(e.startedAt)})]}),(0,S.jsxs)(`div`,{className:`side-row-sub`,children:[(0,S.jsx)(`span`,{className:`side-req`,title:e.request,children:e.status===`running`&&e.currentPhase?`${e.currentPhase}`:e.request??``}),(0,S.jsx)(`span`,{className:`side-meta num`,children:e.status===`running`?(0,S.jsx)(ye,{since:e.startedAt}):me(e.durationMs)})]})]})]})}function ii({id:e}){let t=F(`/api/runs/${e}`,!0),n=t?.status===`running`,[r,i]=(0,v.useState)(null),[a,o]=(0,v.useState)(!1),s=N();if(!t)return(0,S.jsx)(`div`,{className:`empty`,children:`loading…`});let c=t.files.some(e=>e.name===`runner.json`),l=r??(n?`run`:`artifacts`),u=s?t.files.length:t.files.filter(e=>!ui(e.name)).length;async function d(){o(!0),await fetch(`/api/runs/${e}/stop`,{method:`POST`}).catch(()=>{})}return(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`div`,{className:`detail-head`,children:[(0,S.jsx)(be,{status:t.status}),(0,S.jsx)(`h1`,{children:t.workflow?(0,S.jsx)(A,{href:`/workflows/${encodeURIComponent(t.workflow)}`,title:`open workflow`,children:t.workflow}):`unknown workflow`}),(0,S.jsx)(xe,{status:t.status}),c&&(0,S.jsxs)(`span`,{className:`chip sandbox-chip`,children:[(0,S.jsx)(C,{name:`science`,className:`ms-sm`}),` sandbox`]}),(0,S.jsx)(`span`,{className:`rid`,children:e.replace(/^run-/,``)}),n&&c&&(0,S.jsx)(`button`,{className:`stop-btn`,onClick:d,disabled:a,children:a?`stopping…`:(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(C,{name:`stop`,className:`ms-sm`}),` stop`]})}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsx)(`button`,{className:`open-raw`,title:`chat with an agent about this run`,onClick:()=>void Gr(`claude`,{kind:`run`,runId:e}),children:`⌬ discuss`}),(0,S.jsxs)(`nav`,{className:`tabs`,children:[(0,S.jsx)(`button`,{className:l===`run`?`active`:``,onClick:()=>i(`run`),children:`run`}),(0,S.jsxs)(`button`,{className:l===`artifacts`?`active`:``,onClick:()=>i(`artifacts`),children:[`artifacts `,(0,S.jsxs)(`span`,{className:`num`,children:[`(`,u,`)`]})]})]})]}),t.request&&(0,S.jsx)(`p`,{className:`detail-req`,children:t.request}),l===`run`?(0,S.jsx)(ai,{run:t,live:n}):(0,S.jsx)(fi,{id:e,files:t.files,live:n})]})}function ai({run:e,live:t}){return(0,S.jsxs)(`div`,{className:`run-tab`,children:[(0,S.jsxs)(`div`,{className:`statgrid`,children:[(0,S.jsxs)(`div`,{className:`stat`,children:[(0,S.jsx)(`div`,{className:`microlabel`,children:`phases`}),(0,S.jsxs)(`div`,{className:`v num`,children:[e.phasesDone,e.phasesTotal==null?``:` / ${e.phasesTotal}`]})]}),(0,S.jsxs)(`div`,{className:`stat`,children:[(0,S.jsx)(`div`,{className:`microlabel`,children:`duration`}),(0,S.jsx)(`div`,{className:`v num`,children:t?(0,S.jsx)(ye,{since:e.startedAt}):me(e.durationMs)})]}),(0,S.jsxs)(`div`,{className:`stat`,children:[(0,S.jsx)(`div`,{className:`microlabel`,children:`cost`}),(0,S.jsx)(`div`,{className:`v num`,children:I(e.costUsd??si(e.phases))})]}),(0,S.jsxs)(`div`,{className:`stat`,children:[(0,S.jsx)(`div`,{className:`microlabel`,children:`tokens in / out`}),(0,S.jsxs)(`div`,{className:`v num`,children:[he(oi(e.phases,`tokensIn`)),` / `,he(oi(e.phases,`tokensOut`))]})]})]}),(0,S.jsxs)(`section`,{className:`panel`,children:[(0,S.jsxs)(`div`,{className:`panel-head`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`phase timeline`}),(0,S.jsx)(`span`,{className:`spacer`}),t&&(0,S.jsxs)(`span`,{className:`live-note`,children:[(0,S.jsx)(`span`,{className:`lamp running`}),` live · polling`]})]}),(0,S.jsx)(`div`,{className:`phases`,children:e.phases.map(e=>(0,S.jsx)(ci,{p:e},e.phase))})]})]})}function oi(e,t){return e.reduce((e,n)=>e+(n[t]??0),0)}function si(e){return e.reduce((e,t)=>e+(t.costUsd??0),0)}function ci({p:e}){let t=e.gates.filter(e=>!e.passed);return(0,S.jsxs)(`div`,{className:`phase-row`,children:[(0,S.jsx)(be,{status:e.status}),(0,S.jsxs)(`div`,{className:`phase-top`,children:[(0,S.jsx)(`span`,{className:`phase-name`,children:e.phase}),e.kind===`agent`?(0,S.jsxs)(`span`,{className:`chip agent`,children:[e.agent,e.model?` · ${e.model}`:``]}):(0,S.jsx)(`span`,{className:`chip`,children:`script`}),(0,S.jsxs)(`span`,{className:`right num`,children:[e.attempts>1&&(0,S.jsxs)(`span`,{children:[`att `,e.attempts]}),e.status===`running`?(0,S.jsx)(ye,{since:e.startedAt}):e.durationMs!=null&&(0,S.jsx)(`span`,{children:me(e.durationMs)}),e.kind===`agent`&&e.tokensIn!=null&&(0,S.jsxs)(`span`,{children:[he(e.tokensIn),` / `,he(e.tokensOut)]}),e.costUsd!=null&&e.costUsd>0&&(0,S.jsx)(`span`,{children:I(e.costUsd)})]})]}),e.status===`running`&&e.lastActivity&&(0,S.jsx)(`div`,{className:`phase-activity`,children:e.lastActivity}),e.summary&&e.status!==`running`&&(0,S.jsx)(`div`,{className:`phase-sub`,children:e.summary}),e.gates.length>0&&(0,S.jsx)(`div`,{className:`gate-line`,children:e.gates.map(e=>(0,S.jsxs)(`span`,{className:`gate ${e.passed?``:`failed`}`,title:e.failure??``,children:[(0,S.jsx)(C,{name:e.passed?`check`:`close`,className:`ms-sm`}),` `,e.gate]},e.gate))}),t.map(e=>(0,S.jsx)(`div`,{className:`gate-fail-msg`,children:e.failure},e.gate))]})}var li=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`]);function ui(e){return e===`runner.json`||e.endsWith(`.jsonl`)||e.endsWith(`.log`)}function di(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)||li.has(t)?0:ui(e)?2:1},r=null;for(let t of e)(!r||n(t.name)<n(r.name))&&(r=t);return r?.name??null}function fi({id:e,files:t,live:n}){let[r,i]=(0,v.useState)(null),a=N(),o=(0,v.useMemo)(()=>a?t:t.filter(e=>!ui(e.name)),[t,a]);return(0,v.useEffect)(()=>{!a&&r&&ui(r)&&i(null)},[a,r]),(0,v.useEffect)(()=>{r||o.length===0||i(di(o))},[o,r]),(0,S.jsxs)(`div`,{className:`art-layout`,children:[(0,S.jsxs)(`section`,{className:`panel art-files`,children:[(0,S.jsx)(`div`,{className:`panel-head`,children:(0,S.jsxs)(`span`,{className:`microlabel`,children:[`files `,(0,S.jsxs)(`span`,{className:`num`,children:[`(`,o.length,`)`]})]})}),(0,S.jsxs)(`div`,{className:`file-list`,children:[o.map(e=>(0,S.jsxs)(`button`,{className:`file-row ${r===e.name?`active`:``}`,onClick:()=>i(e.name),children:[(0,S.jsx)(`span`,{className:`fname`,children:e.name}),(0,S.jsx)(`span`,{className:`fsize num`,children:ge(e.size)})]},e.name)),o.length===0&&(0,S.jsx)(`div`,{className:`viewer-note`,children:t.length>0?`no result files — raw run files live in expert mode`:`no files yet`})]})]}),(0,S.jsxs)(`section`,{className:`panel art-viewer`,children:[(0,S.jsxs)(`div`,{className:`panel-head`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:r??`viewer`}),(0,S.jsx)(`span`,{className:`spacer`}),r&&(0,S.jsx)(`a`,{className:`open-raw`,href:`/api/runs/${e}/file?name=${encodeURIComponent(r)}&raw=1`,target:`_blank`,children:`open raw ↗`})]}),r?(0,S.jsx)(pi,{id:e,name:r,live:n}):(0,S.jsx)(`div`,{className:`empty`,children:`select a file`})]})]})}function pi({id:e,name:t,live:n}){let r=t.split(`.`).pop()?.toLowerCase()??``,i=`/api/runs/${e}/file?name=${encodeURIComponent(t)}&raw=1`;return r===`html`?(0,S.jsx)(`div`,{className:`viewer`,children:(0,S.jsx)(`div`,{className:`viewer-body`,children:(0,S.jsx)(`iframe`,{src:i,sandbox:`allow-scripts`,allow:`clipboard-write`,title:t})})}):r===`pdf`?(0,S.jsx)(`div`,{className:`viewer`,children:(0,S.jsx)(`div`,{className:`viewer-body`,children:(0,S.jsx)(`iframe`,{src:i,title:t})})}):li.has(r)?(0,S.jsx)(`div`,{className:`viewer`,children:(0,S.jsx)(`div`,{className:`viewer-body`,children:(0,S.jsx)(`img`,{src:i,alt:t})})}):r===`md`||r===`markdown`?(0,S.jsx)(mi,{id:e,name:t,live:n}):(0,S.jsx)(hi,{id:e,name:t,live:n})}function mi({id:e,name:t,live:n}){let[r,i]=(0,v.useState)(`rendered`),a=F(`/api/runs/${e}/file?name=${encodeURIComponent(t)}`,n),o=(0,v.useMemo)(()=>a?kr.sanitize(z.parse(a.content,{async:!1})):``,[a?.content]);return(0,S.jsxs)(`div`,{className:`viewer`,children:[(0,S.jsxs)(`div`,{className:`viewer-note md-toolbar`,children:[(0,S.jsxs)(`div`,{className:`tabs`,children:[(0,S.jsx)(`button`,{className:r===`rendered`?`active`:``,onClick:()=>i(`rendered`),children:`rendered`}),(0,S.jsx)(`button`,{className:r===`source`?`active`:``,onClick:()=>i(`source`),children:`source`})]}),a?.truncated&&(0,S.jsxs)(`span`,{children:[`large file — showing the last `,ge(4e5)]})]}),(0,S.jsx)(`div`,{className:`viewer-body`,children:a?r===`rendered`?(0,S.jsx)(`div`,{className:`md-body`,dangerouslySetInnerHTML:{__html:o}}):(0,S.jsx)(`pre`,{children:a.content||`(empty)`}):(0,S.jsx)(`pre`,{children:`loading…`})})]})}function hi({id:e,name:t,live:n}){let r=F(`/api/runs/${e}/file?name=${encodeURIComponent(t)}`,n);return(0,S.jsxs)(`div`,{className:`viewer`,children:[r?.truncated&&(0,S.jsxs)(`div`,{className:`viewer-note`,children:[`large file — showing the last `,ge(4e5)]}),(0,S.jsx)(`div`,{className:`viewer-body`,children:(0,S.jsx)(`pre`,{children:r?r.content||`(empty)`:`loading…`})})]})}function gi(){let e=F(`/api/workflows`,!1),t=e?.workflows??[];return(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`div`,{className:`page-head`,children:[(0,S.jsx)(`h1`,{children:`Workflows`}),(0,S.jsxs)(`span`,{className:`count num`,children:[t.length,` discovered`]}),e?.root&&(0,S.jsx)(`span`,{className:`count mono`,children:e.root})]}),e&&t.length===0&&(0,S.jsxs)(`div`,{className:`empty`,children:[`No workflows found — expected `,(0,S.jsx)(`code`,{children:`src/workflows/`}),` or `,(0,S.jsx)(`code`,{children:`workflows/`}),` `,`next to the output folder.`]}),(0,S.jsx)(`div`,{className:`wf-grid`,children:t.map(e=>(0,S.jsxs)(A,{href:`/workflows/${e.slug}`,className:`wf-card`,children:[(0,S.jsxs)(`div`,{className:`wf-card-head`,children:[(0,S.jsx)(`span`,{className:`wf-name`,children:e.name??e.slug}),e.error&&(0,S.jsx)(`span`,{className:`status-word failed`,children:`broken`})]}),(0,S.jsx)(`p`,{className:`wf-desc`,children:e.error??e.description??``}),(0,S.jsxs)(`div`,{className:`wf-meta num`,children:[(0,S.jsxs)(`span`,{children:[e.agents,` agents`]}),(0,S.jsx)(`span`,{children:`·`}),(0,S.jsxs)(`span`,{children:[e.steps,` steps`]})]})]},e.slug))})]})}function _i({slug:e}){let t=F(`/api/workflows/${encodeURIComponent(e)}`,!1),n=F(`/api/runs`,!1);if(!t)return(0,S.jsx)(`div`,{className:`empty`,children:`loading…`});if(t.error)return(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(yi,{slug:t.slug}),(0,S.jsxs)(`div`,{className:`empty`,children:[(0,S.jsx)(`span`,{className:`status-word failed`,children:`broken workflow`}),(0,S.jsx)(`pre`,{style:{marginTop:12,textAlign:`left`},children:t.error})]})]});let r=new Map(t.agents.map((e,t)=>[e.id,t%4])),i=(n?.runs??[]).filter(e=>e.workflow===t.name).slice(0,8);return(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(yi,{slug:t.slug}),(0,S.jsxs)(`div`,{className:`detail-head`,children:[(0,S.jsx)(`h1`,{children:t.name??t.slug}),(0,S.jsx)(`span`,{className:`rid mono`,children:t.dir})]}),t.description&&(0,S.jsx)(`p`,{className:`detail-req`,children:t.description}),(0,S.jsxs)(`div`,{className:`statgrid`,children:[(0,S.jsxs)(`div`,{className:`stat`,children:[(0,S.jsx)(`div`,{className:`microlabel`,children:`agents`}),(0,S.jsx)(`div`,{className:`v num`,children:t.agents.length})]}),(0,S.jsxs)(`div`,{className:`stat`,children:[(0,S.jsx)(`div`,{className:`microlabel`,children:`steps`}),(0,S.jsxs)(`div`,{className:`v num`,children:[t.steps.length,` `,(0,S.jsxs)(`span`,{style:{color:`var(--muted)`,fontWeight:400},children:[`(`,t.steps.filter(e=>e.kind===`agent`).length,` agent ·`,` `,t.steps.filter(e=>e.kind===`script`).length,` script)`]})]})]}),t.workspace&&(0,S.jsxs)(`div`,{className:`stat`,style:{maxWidth:420},children:[(0,S.jsx)(`div`,{className:`microlabel`,children:`workspace`}),(0,S.jsx)(`div`,{className:`wf-workspace mono`,children:t.workspace})]})]}),(0,S.jsx)(vi,{slug:t.slug,lastRequest:i[0]?.request}),(0,S.jsxs)(`section`,{className:`panel`,style:{marginBottom:18},children:[(0,S.jsx)(`div`,{className:`panel-head`,children:(0,S.jsx)(`span`,{className:`microlabel`,children:`agents`})}),(0,S.jsxs)(`div`,{className:`agent-grid`,children:[t.agents.map(e=>(0,S.jsx)(bi,{a:e,idx:r.get(e.id)??0},e.id)),t.agents.length===0&&(0,S.jsx)(`div`,{className:`viewer-note`,children:`no agents — script-only workflow`})]})]}),(0,S.jsxs)(`div`,{className:`columns`,children:[(0,S.jsxs)(`section`,{className:`panel`,children:[(0,S.jsx)(`div`,{className:`panel-head`,children:(0,S.jsx)(`span`,{className:`microlabel`,children:`pipeline`})}),(0,S.jsx)(`div`,{className:`pipeline`,children:t.steps.map((e,t)=>(0,S.jsx)(xi,{s:e,i:t,idx:e.agent?r.get(e.agent)??0:null},e.name))})]}),(0,S.jsxs)(`div`,{style:{display:`grid`,gap:18},children:[(0,S.jsxs)(`section`,{className:`panel`,children:[(0,S.jsx)(`div`,{className:`panel-head`,children:(0,S.jsxs)(`span`,{className:`microlabel`,children:[`folder `,(0,S.jsxs)(`span`,{className:`num`,children:[`(`,t.files.length,` files)`]})]})}),(0,S.jsx)(`div`,{className:`file-list`,children:t.files.map(e=>(0,S.jsx)(`div`,{className:`file-row`,style:{cursor:`default`},children:(0,S.jsx)(`span`,{className:`fname`,children:e})},e))})]}),(0,S.jsxs)(`section`,{className:`panel`,children:[(0,S.jsx)(`div`,{className:`panel-head`,children:(0,S.jsxs)(`span`,{className:`microlabel`,children:[`recent runs `,(0,S.jsxs)(`span`,{className:`num`,children:[`(`,i.length,`)`]})]})}),(0,S.jsxs)(`div`,{className:`file-list`,children:[i.map(e=>(0,S.jsxs)(A,{href:`/runs/${e.id}`,className:`file-row`,children:[(0,S.jsx)(be,{status:e.status}),(0,S.jsx)(`span`,{className:`fname`,children:e.id.replace(/^run-/,``)}),(0,S.jsxs)(`span`,{className:`fsize num`,children:[me(e.durationMs),` · `,I(e.costUsd),` · `,_e(e.startedAt)]})]},e.id)),i.length===0&&(0,S.jsx)(`div`,{className:`viewer-note`,children:`no runs of this workflow yet`})]})]})]})]})]})}function vi({slug:e,lastRequest:t}){let[n,r]=(0,v.useState)(``),[i,a]=(0,v.useState)(!0),[o,s]=(0,v.useState)(!1),[c,l]=(0,v.useState)(!1),[u,d]=(0,v.useState)(null),f=F(`/api/workflows/${encodeURIComponent(e)}/run`,!1);(0,v.useEffect)(()=>{!n&&t&&r(t)},[t]);let p=f?.available&&f?.image,m=f?f.available?f.image?`isolated container per run`:"image missing — run `kraftwerk runner build`":`Docker not running — sandbox unavailable`:``;async function h(){if(n.trim()&&!c){l(!0),d(null);try{let t=await fetch(`/api/workflows/${encodeURIComponent(e)}/run`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({request:n.trim(),sandbox:i,ssh:o})}),r=await t.json();if(!t.ok)throw Error(r.error??`HTTP ${t.status}`);k(`/runs/${r.runId}`)}catch(e){d(e.message),l(!1)}}}return(0,S.jsxs)(`section`,{className:`panel run-panel`,style:{marginBottom:18},children:[(0,S.jsx)(`div`,{className:`panel-head`,children:(0,S.jsx)(`span`,{className:`microlabel`,children:`trigger run`})}),(0,S.jsxs)(`div`,{className:`run-form`,children:[(0,S.jsx)(`input`,{type:`text`,value:n,placeholder:`request — topic, URL, host …`,onChange:e=>r(e.target.value),onKeyDown:e=>e.key===`Enter`&&h()}),(0,S.jsx)(`button`,{className:`run-btn`,onClick:h,disabled:c||!n.trim()||i&&!p,children:c?`starting…`:(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(C,{name:`play_arrow`,className:`ms-sm`}),` `,i?`run in sandbox`:`run locally`]})})]}),(0,S.jsxs)(`div`,{className:`run-opts`,children:[(0,S.jsxs)(`label`,{children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:i,onChange:e=>a(e.target.checked)}),`docker sandbox `,m&&(0,S.jsxs)(`span`,{className:`opt-hint`,children:[`— `,m]})]}),(0,S.jsxs)(`label`,{children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:o,onChange:e=>s(e.target.checked),disabled:!i}),`forward SSH agent`]})]}),u&&(0,S.jsx)(`div`,{className:`gate-fail-msg`,children:u})]})}function yi({slug:e}){return(0,S.jsxs)(`nav`,{className:`crumbs`,children:[(0,S.jsx)(A,{href:`/workflows`,children:`workflows`}),(0,S.jsx)(`span`,{className:`sep`,children:`/`}),(0,S.jsx)(`span`,{className:`mono`,children:e})]})}function bi({a:e,idx:t}){return(0,S.jsxs)(`div`,{className:`agent-card aid-${t}`,children:[(0,S.jsxs)(`div`,{className:`agent-head`,children:[(0,S.jsx)(`span`,{className:`agent-dot`}),(0,S.jsx)(`b`,{children:e.name??e.id}),(0,S.jsxs)(`code`,{className:`agent-id`,children:[`[`,e.id,`]`]}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsxs)(`span`,{className:`chip`,children:[e.model??`default`,e.effort?` · ${e.effort}`:``]})]}),e.tools.length>0&&(0,S.jsx)(`div`,{className:`agent-tools`,children:e.tools.map(e=>(0,S.jsx)(`span`,{className:`tool-chip`,children:e},e))}),e.persona&&(0,S.jsx)(`p`,{className:`agent-persona`,children:e.persona})]})}function xi({s:e,i:t,idx:n}){let r=e.kind===`script`?e.script:e.prompt;return(0,S.jsxs)(`div`,{className:`step-node`,children:[(0,S.jsx)(`div`,{className:`step-index num ${n==null?`is-script`:`aid-${n}`}`,children:t+1}),(0,S.jsxs)(`div`,{className:`step-body`,children:[(0,S.jsxs)(`div`,{className:`phase-top`,children:[(0,S.jsx)(`span`,{className:`phase-name`,children:e.name}),e.kind===`agent`?(0,S.jsxs)(`span`,{className:`chip agent-chip aid-${n??0}`,children:[`agent · `,e.agent]}):(0,S.jsxs)(`span`,{className:`chip`,children:[`script`,e.sourceRef?` · ${e.sourceRef}`:``]})]}),r&&(0,S.jsxs)(`details`,{className:`step-source`,children:[(0,S.jsx)(`summary`,{children:e.kind===`agent`?`prompt`:`script`}),(0,S.jsx)(`pre`,{children:r})]}),e.gates.length>0&&(0,S.jsx)(`div`,{className:`gate-line`,children:e.gates.map(e=>(0,S.jsxs)(`span`,{className:`gate neutral`,children:[`⛨ `,e]},e))})]})]})}var Si=e=>e===`ok`?`ok`:e===`running`?`running`:e===`aborted`?`aborted`:`failed`,Ci=e=>e===`ok`?`done`:e===`running`?`working`:e===`aborted`?`stopped`:`failed`;function wi(e){return e.scope.kind===`channel`?`/channels/${e.scope.slug}`:e.scope.kind===`agent`?`/agents/${e.scope.slug}/chat/${e.id}`:`/agents/chats/${e.id}`}function Ti(e){switch(e.scope.kind){case`agent`:return e.scope.slug;case`channel`:return`#${e.scope.slug}`;case`run`:return e.scope.runId;case`knowledge`:return e.scope.bundle?`knowledge:${e.scope.bundle}`:`knowledge`;case`kraftwerk`:return`kraftwerk-aware`;default:return`general`}}function Ei(e){return e.length>64?`${e.slice(0,46)}…${e.slice(-14)}`:e}function Di(){let e=F(`/api/runs`,!1),t=F(`/api/chats`,!1),n=F(`/api/knowledge`,!1),r=F(`/api/agents`,!1),i=F(`/api/workflows`,!1),a=F(`/api/skills`,!1),o=F(`/api/meta`,!1),[s,c]=(0,v.useState)(`all`),l=e?.runs??[],u=t?.chats??[],d=n?.bundles??[],f=(a?.skills??[]).filter(e=>e.source===`workspace`),p=[[i?.workflows.length,`workflows`,`/workflows`],[e?l.length:void 0,`runs`,`/runs`],[n?d.length:void 0,`bundles`,`/knowledge`],[a?f.length:void 0,`skills`,`/skills`],[t?u.length:void 0,`chats`,`/agents/chats`]],m=l.filter(e=>e.status===`failed`&&Date.now()-Date.parse(e.updatedAt)<864e5);return(0,S.jsxs)(`div`,{className:`dash`,children:[(0,S.jsxs)(`div`,{className:`page-head`,children:[(0,S.jsxs)(`h1`,{children:[o?.projectIcon?`${o.projectIcon} `:``,o?.projectName||`workspace`]}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsx)(`span`,{className:`dash-mini`,children:p.map(([e,t,n])=>(0,S.jsxs)(A,{href:n,children:[(0,S.jsx)(`b`,{className:`num`,children:e??`…`}),` `,t]},t))}),(0,S.jsx)(Oi,{workflows:i?.workflows??[]})]}),(0,S.jsx)(ki,{agents:r?.agents.filter(e=>!e.archived),chats:u}),m.length>0&&s!==`failed`&&(0,S.jsxs)(`button`,{className:`dash-alert`,onClick:()=>c(`failed`),children:[`⚠ `,m.length,` run`,m.length===1?``:`s`,` failed in the last 24 h — review`]}),(0,S.jsx)(U,{runs:l,chats:u,bundles:d,agents:r?.agents??[],workflows:i?.workflows??[],filter:s,setFilter:c})]})}function Oi({workflows:e}){let[t,n]=(0,v.useState)(!1);return(0,v.useEffect)(()=>{if(!t)return;let e=e=>{e.target.closest(`.wf-pick-wrap`)||n(!1)};return window.addEventListener(`mousedown`,e),()=>window.removeEventListener(`mousedown`,e)},[t]),(0,S.jsxs)(`div`,{className:`dash-actions`,children:[(0,S.jsxs)(`button`,{className:`run-btn dash-newchat`,onClick:()=>k(`/agents/chats`),children:[(0,S.jsx)(C,{name:`forum`}),` new chat`]}),(0,S.jsxs)(`span`,{className:`wf-pick-wrap`,children:[(0,S.jsxs)(`button`,{className:`run-btn tonal`,"aria-haspopup":`menu`,"aria-expanded":t,onClick:()=>n(e=>!e),children:[(0,S.jsx)(C,{name:`play_arrow`}),` run workflow`]}),t&&(0,S.jsxs)(`div`,{className:`wf-pick-pop`,role:`menu`,children:[e.length===0&&(0,S.jsx)(`span`,{className:`wf-pick-empty`,children:`no workflows yet`}),e.map(e=>(0,S.jsxs)(A,{href:`/workflows/${encodeURIComponent(e.slug)}`,className:`wf-pick-item`,role:`menuitem`,children:[(0,S.jsx)(`span`,{className:`wf-pick-name`,children:e.name??e.slug}),e.description&&(0,S.jsx)(`span`,{className:`wf-pick-desc`,children:e.description})]},e.slug))]})]})]})}function ki({agents:e,chats:t}){let n=N();return e&&e.length===0?(0,S.jsx)(`section`,{className:`panel dash-agents-empty`,children:(0,S.jsx)(`div`,{className:`viewer-note`,children:n?(0,S.jsxs)(S.Fragment,{children:[`No agents yet — `,(0,S.jsx)(A,{href:`/agents/new`,children:`create your first agent`}),` and it will show up here, ready to chat.`]}):(0,S.jsx)(S.Fragment,{children:`No agents yet — ask an expert-mode user to create one.`})})}):(0,S.jsx)(`div`,{className:`dash-agents`,children:(e??[]).map(e=>{let n=t.filter(t=>t.scope.kind===`agent`&&t.scope.slug===e.slug),r=n.find(e=>e.awaitingApproval),i=n.find(e=>e.busy),a=()=>k(`/agents/${encodeURIComponent(e.slug)}`);return(0,S.jsxs)(`div`,{className:`dash-agent`,role:`link`,tabIndex:0,onClick:a,onKeyDown:e=>{e.key===`Enter`&&a()},children:[(0,S.jsxs)(`div`,{className:`dash-agent-id`,children:[(0,S.jsxs)(`span`,{className:`agent-avatar lg`,children:[(0,S.jsx)(`span`,{"aria-hidden":!0,children:e.emoji}),(0,S.jsx)(`span`,{className:`lamp ${i?`running`:`idle`}`})]}),(0,S.jsx)(`span`,{className:`dash-agent-name`,children:e.name}),e.description&&(0,S.jsx)(`span`,{className:`dash-agent-desc`,children:e.description})]}),(0,S.jsxs)(`div`,{className:`dash-agent-foot`,children:[(0,S.jsx)(`span`,{className:`dash-agent-state`,children:r?(0,S.jsx)(A,{href:`/agents/${encodeURIComponent(e.slug)}/chat/${r.id}`,className:`chip attention`,onClick:e=>e.stopPropagation(),children:`needs approval`}):i&&(0,S.jsx)(A,{href:`/agents/${encodeURIComponent(e.slug)}/chat/${i.id}`,onClick:e=>e.stopPropagation(),children:`working…`})}),(0,S.jsxs)(`button`,{className:`run-btn dash-chat-btn`,onClick:t=>{t.stopPropagation(),Gr(`claude`,{kind:`agent`,slug:e.slug})},children:[(0,S.jsx)(C,{name:`chat_bubble`,className:`ms-sm`}),` chat`]})]})]},e.slug)})})}function Ai(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 H=[[`all`,`all`],[`run`,`runs`],[`session`,`chats`],[`knowledge`,`knowledge`]];function U({runs:e,chats:t,bundles:n,agents:r,workflows:i,filter:a,setFilter:o}){let s=N(),c=(0,v.useMemo)(()=>{let o=[],c=e=>e?i.find(t=>t.slug===e)?.name??e:void 0;for(let t of e)o.push({at:t.updatedAt,kind:`run`,emoji:`⚙️`,title:c(t.workflow)??t.id,sub:t.request??``,href:`/runs/${t.id}`,lamp:Si(t.status),status:Ci(t.status)});for(let e of t){let t=e.scope.kind===`agent`?r.find(t=>e.scope.kind===`agent`&&t.slug===e.scope.slug):void 0;o.push({at:e.updatedAt,kind:`session`,emoji:t?t.emoji||`🤖`:`💬`,title:t?t.name:e.title||`new chat`,sub:t?`${e.title||`new chat`}${s?` · ${e.agent}`:``}`:s?`${e.agent} · ${Ti(e)}`:Ti(e),href:wi(e),lamp:e.awaitingApproval?`blocked`:e.busy?`running`:`ok`,status:e.awaitingApproval?`needs approval`:e.busy?`working`:void 0})}for(let e of n)e.updatedAt&&o.push({at:e.updatedAt,kind:`knowledge`,emoji:`📚`,title:e.name,sub:`${e.concepts} concepts`,href:`/knowledge/${encodeURIComponent(e.name)}`,lamp:`ok`});return(a===`all`?o:a===`failed`?o.filter(e=>e.kind===`run`&&e.lamp===`failed`):o.filter(e=>e.kind===a)).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)},[e,t,n,r,s,a]),l=``;return(0,S.jsxs)(`section`,{className:`panel dash-feed`,children:[(0,S.jsxs)(`div`,{className:`panel-head`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`activity`}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsxs)(`span`,{className:`dash-feed-filter`,children:[H.map(([e,t])=>(0,S.jsx)(`button`,{className:`feed-chip ${a===e?`on`:``}`,onClick:()=>o(e),children:t},e)),a===`failed`&&(0,S.jsxs)(`button`,{className:`feed-chip on failed`,onClick:()=>o(`all`),children:[`failed `,(0,S.jsx)(C,{name:`close`,className:`ms-sm`})]})]})]}),c.length===0?(0,S.jsx)(`div`,{className:`viewer-note`,children:a===`all`?`nothing yet — run a workflow or start a session`:`nothing here for this filter`}):(0,S.jsx)(`div`,{className:`m3-list`,children:c.map(e=>{let t=Ai(e),n=t===l?null:t;return l=t,(0,S.jsxs)(`div`,{className:`feed-group`,children:[n&&(0,S.jsx)(`div`,{className:`feed-day microlabel`,children:n}),(0,S.jsxs)(A,{href:e.href,className:`m3-row m3-link`,children:[(0,S.jsxs)(`span`,{className:`agent-avatar`,children:[(0,S.jsx)(`span`,{"aria-hidden":!0,children:e.emoji}),e.lamp===`running`&&(0,S.jsx)(`span`,{className:`lamp running`})]}),(0,S.jsx)(`span`,{className:`chip dash-kind ${e.kind}`,children:e.kind===`session`?`chat`:e.kind}),(0,S.jsxs)(`span`,{className:`m3-body`,children:[(0,S.jsx)(`span`,{className:`m3-head`,children:Ei(e.title)}),e.sub&&(0,S.jsx)(`span`,{className:`m3-sub`,children:Ei(e.sub)})]}),e.status&&(0,S.jsx)(`span`,{className:`chip status ${e.lamp}`,children:e.status}),(0,S.jsx)(`span`,{className:`side-when num`,title:new Date(e.at).toLocaleString(),children:ve(e.at)}),(0,S.jsx)(`span`,{className:`m3-chev`,children:(0,S.jsx)(C,{name:`chevron_right`})})]})]},`${e.kind}:${e.href}:${e.at}`)})})]})}async function ji(e,t){let n=window.open(``,`_blank`);if(!n)return;let r=t?`${e}/${t}`:e;n.document.write(`<title>${Fi(r)}</title><body style="font-family:system-ui;padding:40px;color:#555">preparing ${Fi(r)}…</body>`);let i=t=>`/api/knowledge/${encodeURIComponent(e)}/concept?id=${encodeURIComponent(t)}`,a,o=``;try{let[n,r]=await Promise.all([t?Promise.resolve([t]):fetch(`/api/knowledge/${encodeURIComponent(e)}`).then(e=>e.json()).then(e=>e.concepts.map(e=>e.id)),fetch(`/api/meta`).then(e=>e.json()).catch(()=>({}))]);if(o=r.projectName??``,a=await Promise.all(n.map(e=>fetch(i(e)).then(e=>e.json()))),a.some(e=>typeof e?.id!=`string`))throw Error(`missing concept`)}catch{n.document.body.textContent=`could not load "${r}"`;return}let s=[],c=a.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}=Ni(Mi(e.body??``,null)),i=!e.title||e.title===e.id||e.title===e.id.split(`/`).pop(),{html:a,title:o}=Pi(kr.sanitize(z.parse(n,{async:!1})),{title:e.title||e.id,meta:t,titleIsFallback:i});return s.push(o),`<article>
79
79
  ${a}
80
- ${r.length?`<ol class="notes">${r.map(e=>`<li id="fn-${Oi(e.id)}">${kr.sanitize(z.parseInline(e.text,{async:!1}))}</li>`).join(``)}</ol>`:``}
80
+ ${r.length?`<ol class="notes">${r.map(e=>`<li id="fn-${Fi(e.id)}">${kr.sanitize(z.parseInline(e.text,{async:!1}))}</li>`).join(``)}</ol>`:``}
81
81
  </article>`}).join(`
82
- `),l=new Date().toISOString().slice(0,10),u=o?`${Oi(o)} · ${Oi(e)}`:Oi(e),d=t?s[0]||r:e,f=t?``:`<h1 class="cover">${Oi(e)}</h1>
83
- <div class="cover-sub">${o?`${Oi(o)} · `:``}knowledge bundle · ${a.length} concept${a.length===1?``:`s`} · exported ${l}</div>`,p=`<!doctype html>
82
+ `),l=new Date().toISOString().slice(0,10),u=o?`${Fi(o)} · ${Fi(e)}`:Fi(e),d=t?s[0]||r:e,f=t?``:`<h1 class="cover">${Fi(e)}</h1>
83
+ <div class="cover-sub">${o?`${Fi(o)} · `:``}knowledge bundle · ${a.length} concept${a.length===1?``:`s`} · exported ${l}</div>`,p=`<!doctype html>
84
84
  <html>
85
85
  <head>
86
86
  <meta charset="utf-8">
87
- <title>${Oi(d)}</title>
87
+ <title>${Fi(d)}</title>
88
88
  <style>
89
89
  :root { color-scheme: light; }
90
90
  /* Page margins live in the sheet itself (repeating thead/tfoot cells +
@@ -200,19 +200,19 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
200
200
  </table>
201
201
  <script>setTimeout(() => window.print(), 400);<\/script>
202
202
  </body>
203
- </html>`;n.location.href=URL.createObjectURL(new Blob([p],{type:`text/html`}))}function Ti(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 Ei(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 Di(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>${Oi(r)}</h1><div class="meta">${Oi(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 Oi(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`)}function ki(e,t){return`/edit/${encodeURIComponent(e)}/${t.split(`/`).map(encodeURIComponent).join(`/`)}`}function Ai({bundle:e,conceptId:t}){let n=F(`/api/knowledge`,!1),r=n?.bundles??[];return(0,S.jsxs)(`div`,{className:`runs-screen`,children:[(0,S.jsxs)(`aside`,{className:`runs-side`,children:[(0,S.jsxs)(`div`,{className:`side-head`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`bundles`}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsxs)(A,{href:`/knowledge`,className:`open-raw`,children:[(0,S.jsx)(C,{name:`add`,className:`ms-sm`}),` new`]})]}),(0,S.jsxs)(`div`,{className:`side-list`,children:[r.map(t=>(0,S.jsxs)(A,{href:`/knowledge/${encodeURIComponent(t.name)}`,className:`side-row ${t.name===e?`active`:``}`,children:[(0,S.jsx)(`span`,{className:`lamp ok`}),(0,S.jsxs)(`div`,{className:`side-row-body`,children:[(0,S.jsxs)(`div`,{className:`side-row-top`,children:[(0,S.jsx)(`span`,{className:`side-wf`,children:t.name}),(0,S.jsx)(`span`,{className:`side-when num`,children:t.concepts})]}),(0,S.jsx)(`div`,{className:`side-row-sub`,children:(0,S.jsxs)(`span`,{className:`side-req`,children:[t.okfVersion?`okf ${t.okfVersion}`:`okf`,t.updatedAt?` · ${t.updatedAt.slice(0,10)}`:``]})})]})]},t.name)),n&&r.length===0&&(0,S.jsx)(`div`,{className:`viewer-note`,children:`no bundles yet`})]})]}),(0,S.jsx)(`div`,{className:`runs-main`,children:e?(0,S.jsx)(Mi,{name:e,conceptId:t},e):(0,S.jsx)(H,{root:n?.root})})]})}function H({root:e}){let[t,n]=(0,v.useState)(``),[r,i]=(0,v.useState)(``),[a,o]=(0,v.useState)(!1);async function s(){let e=t.trim();if(!e)return;o(!0),i(``);let n=await(await fetch(`/api/knowledge`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:e})})).json();o(!1),n.error?i(n.error):window.location.hash=`/knowledge/${encodeURIComponent(e)}`}return(0,S.jsxs)(`div`,{className:`new-chat`,children:[(0,S.jsx)(`div`,{className:`page-head`,children:(0,S.jsx)(`h1`,{children:`context & knowledge`})}),(0,S.jsxs)(`section`,{className:`panel new-chat-panel`,children:[(0,S.jsx)(`div`,{className:`panel-head`,children:(0,S.jsx)(`span`,{className:`microlabel`,children:`what lives here`})}),(0,S.jsxs)(`div`,{className:`know-intro`,children:[`Curated knowledge as `,(0,S.jsx)(`b`,{children:`OKF bundles`}),` (Open Knowledge Format v0.2): plain markdown files with YAML frontmatter`,e?(0,S.jsxs)(S.Fragment,{children:[` under `,(0,S.jsx)(`code`,{children:e})]}):null,`, readable by humans and agents, diffable in git. Agents write through`,` `,(0,S.jsx)(`code`,{children:`kraftwerk knowledge put`}),` (provenance is stamped automatically); you raise a concept's trust tier by verifying it here.`]}),(0,S.jsx)(`div`,{className:`panel-head`,children:(0,S.jsx)(`span`,{className:`microlabel`,children:`new bundle`})}),(0,S.jsxs)(`div`,{className:`know-newbundle`,children:[(0,S.jsx)(`input`,{value:t,placeholder:`bundle name, e.g. customer-support`,onChange:e=>n(e.target.value),onKeyDown:e=>e.key===`Enter`&&void s()}),(0,S.jsx)(`button`,{className:`run-btn`,disabled:!t.trim()||a,onClick:s,children:a?`creating…`:`create`})]}),r&&(0,S.jsxs)(`div`,{className:`msg error`,children:[(0,S.jsx)(C,{name:`error`,className:`ms-sm`}),` `,r]})]})]})}function U({tier:e}){return(0,S.jsx)(`span`,{className:`chip trust ${e}`,children:e})}var ji=`@activity`;function Mi({name:e,conceptId:t}){let n=F(`/api/knowledge/${encodeURIComponent(e)}`,!1);if(!n)return(0,S.jsx)(`div`,{className:`empty`,children:`loading…`});if(`error`in n)return(0,S.jsx)(`div`,{className:`empty`,children:`bundle not found`});let r=t===ji?`activity`:`pages`,i=n.concepts,a=r===`pages`?t&&i.some(e=>e.id===t)?t:i[0]?.id:void 0,o=`/knowledge/${encodeURIComponent(e)}`;return(0,S.jsxs)(`div`,{className:`agent-view`,children:[(0,S.jsxs)(`div`,{className:`page-head`,children:[(0,S.jsx)(`h1`,{children:e}),(0,S.jsxs)(`span`,{className:`count`,children:[i.length,` pages`]}),(0,S.jsxs)(`div`,{className:`tabs`,children:[(0,S.jsx)(A,{href:o,className:r===`pages`?`active`:``,children:`pages`}),(0,S.jsx)(A,{href:`${o}/${ji}`,className:r===`activity`?`active`:``,children:`activity`})]}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsxs)(`button`,{className:`open-raw`,onClick:()=>void wi(e),children:[(0,S.jsx)(C,{name:`picture_as_pdf`,className:`ms-sm`}),` export PDF`]}),(0,S.jsx)(`button`,{className:`run-btn`,onClick:()=>void Rr(`claude`,{kind:`knowledge`,bundle:e}),children:`curate in chat`})]}),r===`activity`?n.log?(0,S.jsx)(Ii,{name:e,log:n.log}):(0,S.jsx)(`section`,{className:`panel`,children:(0,S.jsx)(`div`,{className:`viewer-note`,children:`no activity yet`})}):i.length===0?(0,S.jsx)(`section`,{className:`panel`,children:(0,S.jsxs)(`div`,{className:`viewer-note`,children:[`No pages yet — start a chat to author some, or write one with`,` `,(0,S.jsxs)(`code`,{children:[`kraftwerk knowledge put `,e,`/<path>`]}),`.`]})}):(0,S.jsxs)(`div`,{className:`wiki`,children:[(0,S.jsx)(`aside`,{className:`wiki-side`,children:Li(i).map(({folder:e,concepts:t})=>(0,S.jsxs)(v.Fragment,{children:[e&&(0,S.jsxs)(`div`,{className:`wiki-folder`,children:[e,`/`]}),t.map(e=>(0,S.jsxs)(A,{href:`${o}/${e.id}`,className:`wiki-page ${e.id===a?`active`:``}`,title:`${e.id}.md`,children:[(0,S.jsx)(C,{name:Ni(e.type),className:`ms-sm`}),(0,S.jsx)(`span`,{className:`wiki-page-title`,children:e.title}),(e.stale||e.error)&&(0,S.jsx)(`span`,{className:`wiki-dot`,title:e.error??`stale`})]},e.id))]},e||`.`))}),(0,S.jsx)(`div`,{className:`wiki-main`,children:a&&(0,S.jsx)(Ri,{bundle:e,conceptId:a},a)})]})]})}function Ni(e){switch((e??``).toLowerCase()){case`reference`:return`article`;case`policy`:return`gavel`;case`guide`:case`howto`:return`route`;case`decision`:return`balance`;default:return`menu_book`}}function Pi(e){let t=[];for(let n of e.split(`
204
- `)){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 Fi(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,S.jsx)(A,{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 Ii({name:e,log:t}){let n=Pi(t),[r,i]=(0,v.useState)(!1);return(0,S.jsxs)(`section`,{className:`panel`,children:[(0,S.jsxs)(`div`,{className:`panel-head`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`activity`}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsx)(`button`,{className:`open-raw`,onClick:()=>i(!r),children:r?`timeline`:`raw log`})]}),r||n.length===0?(0,S.jsx)(`div`,{className:`viewer-body`,children:(0,S.jsx)(`pre`,{children:t})}):(0,S.jsx)(`div`,{className:`know-log`,children:n.map(t=>(0,S.jsxs)(v.Fragment,{children:[(0,S.jsx)(`div`,{className:`m3-subhead num`,children:t.date}),t.entries.map((t,n)=>(0,S.jsxs)(`div`,{className:`know-log-row`,children:[(0,S.jsx)(`span`,{className:`chip log-kind log-${t.kind}`,children:t.kind}),(0,S.jsx)(`span`,{className:`know-log-text`,children:Fi(e,t.text)})]},n))]},t.date))})]})}function Li(e){let t=new Map;for(let n of e){let e=n.id.includes(`/`)?n.id.slice(0,n.id.lastIndexOf(`/`)):``;(t.get(e)??t.set(e,[]).get(e)).push(n)}return[...t.keys()].sort((e,t)=>e===``?-1:t===``?1:e.localeCompare(t)).map(e=>({folder:e,concepts:t.get(e)}))}function Ri({bundle:e,conceptId:t}){let[n,r]=(0,v.useState)(null),[i,a]=(0,v.useState)(!1),[o,s]=(0,v.useState)(!1),[c,l]=(0,v.useState)(!1),[u,d]=(0,v.useState)(``),[f,p]=(0,v.useState)(!1),[m,h]=(0,v.useState)(``),[g,_]=(0,v.useState)(`rendered`),y=(0,v.useMemo)(()=>n?kr.sanitize(z.parse(Ti(n.body,e),{async:!1})):``,[n?.body,e]),b=()=>{fetch(`/api/knowledge/${encodeURIComponent(e)}/concept?id=${encodeURIComponent(t)}`).then(e=>e.ok?e.json():Promise.reject()).then(r).catch(()=>a(!0))};(0,v.useEffect)(()=>{if(c)return;let n=!0,i,o=async()=>{try{let i=await fetch(`/api/knowledge/${encodeURIComponent(e)}/concept?id=${encodeURIComponent(t)}`,{cache:`no-store`});if(i.ok){let e=await i.json();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,c]);async function x(){s(!0),await fetch(`/api/knowledge/${encodeURIComponent(e)}/verify`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({id:t})}).catch(()=>{}),s(!1),b()}async function w(){p(!0),h(``);let n=await fetch(`/api/knowledge/${encodeURIComponent(e)}/concept`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({id:t,content:u})}).then(e=>e.json()).catch(()=>({error:`save failed`}));p(!1),n.error?h(n.error):(r(n),l(!1))}return i?(0,S.jsx)(`div`,{className:`empty`,children:`concept not found`}):n?(0,S.jsxs)(`div`,{className:`agent-view`,children:[(0,S.jsxs)(`div`,{className:`detail-head`,children:[(0,S.jsx)(`h1`,{children:n.title}),n.type&&(0,S.jsx)(`span`,{className:`chip agent`,children:n.type}),(0,S.jsx)(U,{tier:n.trustTier}),n.status!==`stable`&&(0,S.jsx)(`span`,{className:`chip ${n.status}`,children:n.status}),n.stale&&(0,S.jsxs)(`span`,{className:`chip stale`,children:[`stale since `,n.staleAfter?.slice(0,10)]}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsxs)(A,{href:ki(e,n.id),className:`open-raw`,title:`Full-screen document editor with autosave`,children:[(0,S.jsx)(C,{name:`edit_document`,className:`ms-sm`}),` open in editor`]}),(0,S.jsxs)(`button`,{className:`open-raw`,onClick:()=>void wi(e,n.id),children:[(0,S.jsx)(C,{name:`picture_as_pdf`,className:`ms-sm`}),` export PDF`]}),(0,S.jsx)(`button`,{className:`run-btn`,disabled:o,onClick:x,children:o?`verifying…`:(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(C,{name:`check`,className:`ms-sm`}),` verify (human)`]})})]}),n.error&&(0,S.jsxs)(`div`,{className:`msg error`,children:[(0,S.jsx)(C,{name:`error`,className:`ms-sm`}),` `,n.error]}),(0,S.jsxs)(`div`,{className:`detail-cols`,children:[(0,S.jsxs)(`section`,{className:`panel`,children:[(0,S.jsxs)(`div`,{className:`panel-head`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`content`}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsxs)(`span`,{className:`side-meta`,children:[e,`/`,n.id,`.md`]}),c?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`button`,{className:`open-raw`,onClick:()=>{l(!1),h(``)},children:`cancel`}),(0,S.jsx)(`button`,{className:`open-raw`,disabled:f,onClick:w,children:f?`saving…`:(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(C,{name:`check`,className:`ms-sm`}),` save`]})})]}):(0,S.jsxs)(`button`,{className:`open-raw`,onClick:()=>{d(n.raw),l(!0),h(``)},children:[(0,S.jsx)(C,{name:`edit`,className:`ms-sm`}),` edit`]})]}),c?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`textarea`,{className:`concept-edit`,value:u,rows:Math.min(40,Math.max(18,u.split(`
205
- `).length+2)),onChange:e=>d(e.target.value),spellCheck:!1}),(0,S.jsxs)(`div`,{className:`viewer-note`,children:[`full file (frontmatter + markdown body) — saving stamps provenance as`,` `,(0,S.jsx)(`code`,{children:`human:user`}),` and logs an update.`]})]}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`div`,{className:`viewer-note md-toolbar`,children:(0,S.jsxs)(`div`,{className:`tabs`,children:[(0,S.jsx)(`button`,{className:g===`rendered`?`active`:``,onClick:()=>_(`rendered`),children:`rendered`}),(0,S.jsx)(`button`,{className:g===`source`?`active`:``,onClick:()=>_(`source`),children:`source`})]})}),(0,S.jsx)(`div`,{className:`viewer-body`,children:g===`rendered`?(0,S.jsx)(`div`,{className:`md-body concept-md`,dangerouslySetInnerHTML:{__html:y}}):(0,S.jsx)(`pre`,{children:n.body.trim()||`(empty body)`})})]}),m&&(0,S.jsxs)(`div`,{className:`msg error`,children:[(0,S.jsx)(C,{name:`error`,className:`ms-sm`}),` `,m]})]}),(0,S.jsxs)(`aside`,{className:`detail-rail`,children:[(0,S.jsxs)(`section`,{className:`panel`,children:[(0,S.jsx)(`div`,{className:`panel-head`,children:(0,S.jsx)(`span`,{className:`microlabel`,children:`about`})}),(0,S.jsxs)(`div`,{className:`rail-list`,children:[(0,S.jsxs)(`div`,{className:`rail-kv`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`trust`}),(0,S.jsx)(`span`,{className:`v`,children:(0,S.jsx)(U,{tier:n.trustTier})})]}),(0,S.jsxs)(`div`,{className:`rail-kv`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`generated`}),(0,S.jsx)(`span`,{className:`v ${n.generated?``:`dim`}`,children:n.generated?`${n.generated.by??`?`} · ${(n.generated.at??`?`).slice(0,10)}`:`not stamped`})]}),(0,S.jsxs)(`div`,{className:`rail-kv`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`verified`}),n.verified.length===0?(0,S.jsx)(`span`,{className:`v dim`,children:`never`}):n.verified.map((e,t)=>(0,S.jsxs)(`span`,{className:`v`,children:[e.by??`?`,` · `,(e.at??`?`).slice(0,10)]},t))]}),n.staleAfter&&(0,S.jsxs)(`div`,{className:`rail-kv`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`stale after`}),(0,S.jsxs)(`span`,{className:`v ${n.stale?``:`dim`}`,children:[n.staleAfter.slice(0,10),n.stale&&(0,S.jsx)(`span`,{className:`chip stale`,children:`stale`})]})]}),n.tags.length>0&&(0,S.jsxs)(`div`,{className:`rail-kv`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`tags`}),(0,S.jsx)(`span`,{className:`m3-chips`,children:n.tags.map(e=>(0,S.jsx)(`span`,{className:`chip`,children:e},e))})]})]})]}),n.sources.length>0&&(0,S.jsxs)(`section`,{className:`panel`,children:[(0,S.jsx)(`div`,{className:`panel-head`,children:(0,S.jsx)(`span`,{className:`microlabel`,children:`sources`})}),(0,S.jsx)(`div`,{className:`rail-list`,children:n.sources.map((e,t)=>(0,S.jsxs)(`div`,{className:`rail-kv`,children:[(0,S.jsxs)(`span`,{className:`v`,children:[e.resource?.startsWith(`http`)?(0,S.jsx)(`a`,{href:e.resource,target:`_blank`,rel:`noreferrer`,children:e.title??e.resource}):e.title??e.resource??`?`,e.id&&(0,S.jsxs)(`span`,{className:`know-id`,children:[`[^`,e.id,`]`]})]}),(0,S.jsx)(`span`,{className:`v dim`,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))})]})]})]})]}):(0,S.jsx)(`div`,{className:`empty`,children:`loading…`})}var zi={workspace:`workspace`,project:`.claude`,user:`global`,agent:`agent`};function Bi(e){return(0,S.jsx)(`span`,{className:`chip skill-src ${e}`,children:zi[e]})}function Vi({name:e}){let t=F(`/api/skills`,!1),n=t?.skills??[],r=n.filter(e=>e.source===`workspace`),i=n.filter(e=>e.source!==`workspace`),a=t=>(0,S.jsxs)(A,{href:`/skills/${encodeURIComponent(t.name)}`,className:`side-row ${t.name===e?`active`:``}`,children:[(0,S.jsx)(`span`,{className:`lamp ${t.source===`workspace`?`ok`:`dim`}`}),(0,S.jsxs)(`div`,{className:`side-row-body`,children:[(0,S.jsxs)(`div`,{className:`side-row-top`,children:[(0,S.jsxs)(`span`,{className:`side-wf`,children:[`/`,t.name]}),t.source!==`workspace`&&Bi(t.source)]}),(0,S.jsx)(`div`,{className:`side-row-sub`,children:(0,S.jsx)(`span`,{className:`side-req`,children:t.description||`no description`})})]})]},`${t.source}:${t.name}`);return(0,S.jsxs)(`div`,{className:`runs-screen`,children:[(0,S.jsxs)(`aside`,{className:`runs-side`,children:[(0,S.jsx)(`div`,{className:`side-head`,children:(0,S.jsx)(`span`,{className:`microlabel`,children:`workspace skills`})}),(0,S.jsxs)(`div`,{className:`side-list`,children:[r.map(a),t&&r.length===0&&(0,S.jsx)(`div`,{className:`viewer-note`,children:`no workspace skills yet`}),i.length>0&&(0,S.jsxs)(v.Fragment,{children:[(0,S.jsx)(`div`,{className:`side-head skills-local-head`,children:(0,S.jsx)(`span`,{className:`microlabel`,children:`local (this machine / repo)`})}),i.map(a)]})]})]}),(0,S.jsx)(`div`,{className:`runs-main`,children:e?(0,S.jsx)(Ui,{name:e},e):(0,S.jsx)(Hi,{root:t?.root,workspace:r})})]})}function Hi({root:e,workspace:t}){return(0,S.jsxs)(`div`,{className:`new-chat`,children:[(0,S.jsxs)(`div`,{className:`page-head`,children:[(0,S.jsx)(`h1`,{children:`skills`}),(0,S.jsxs)(`span`,{className:`count`,children:[t.length,` in workspace`]})]}),(0,S.jsxs)(`section`,{className:`panel new-chat-panel`,children:[(0,S.jsx)(`div`,{className:`panel-head`,children:(0,S.jsx)(`span`,{className:`microlabel`,children:`what lives here`})}),(0,S.jsxs)(`div`,{className:`know-intro`,children:[`Skills are reusable `,(0,S.jsx)(`b`,{children:`instruction packages`}),`: one folder per skill with a`,` `,(0,S.jsx)(`code`,{children:`SKILL.md`}),` (YAML frontmatter: name, description). `,(0,S.jsx)(`b`,{children:`Workspace skills`}),e?(0,S.jsxs)(S.Fragment,{children:[` live under `,(0,S.jsx)(`code`,{children:e})]}):null,`, are tracked in git and shared with everyone in this workspace — they are the ones to build on. Skills from`,` `,(0,S.jsx)(`code`,{children:`.claude/skills`}),` and your personal `,(0,S.jsx)(`code`,{children:`~/.claude/skills`}),` also work here, but stay repo-/machine-local. Invoke any skill in a session with`,` `,(0,S.jsx)(`code`,{children:`/<name>`}),`.`]}),(0,S.jsx)(`div`,{className:`panel-head`,children:(0,S.jsx)(`span`,{className:`microlabel`,children:`add a workspace skill`})}),(0,S.jsxs)(`div`,{className:`know-intro`,children:[`Create `,(0,S.jsxs)(`code`,{children:[e?`${e}/`:`skills/`,`<name>/SKILL.md`]}),`, commit it, done — it appears here and in every session's `,(0,S.jsx)(`code`,{children:`/`}),` menu.`]})]})]})}function Ui({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?kr.sanitize(z.parse(s,{async:!1})):``,[s]);return(0,v.useEffect)(()=>{fetch(`/api/skills/${encodeURIComponent(e)}`).then(e=>e.ok?e.json():Promise.reject()).then(n).catch(()=>i(!0))},[e]),r?(0,S.jsx)(`div`,{className:`empty`,children:`skill not found`}):t?(0,S.jsxs)(`div`,{className:`agent-view`,children:[(0,S.jsxs)(`div`,{className:`detail-head`,children:[(0,S.jsxs)(`h1`,{children:[`/`,t.name]}),Bi(t.source)]}),t.description&&(0,S.jsx)(`div`,{className:`know-intro skill-desc`,children:t.description}),(0,S.jsxs)(`div`,{className:`detail-cols`,children:[(0,S.jsxs)(`section`,{className:`panel`,children:[(0,S.jsxs)(`div`,{className:`panel-head`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`SKILL.md`}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsxs)(`div`,{className:`tabs`,children:[(0,S.jsx)(`button`,{className:a===`rendered`?`active`:``,onClick:()=>o(`rendered`),children:`rendered`}),(0,S.jsx)(`button`,{className:a===`source`?`active`:``,onClick:()=>o(`source`),children:`source`})]})]}),(0,S.jsx)(`div`,{className:`viewer-body`,children:a===`rendered`?(0,S.jsx)(`div`,{className:`md-body concept-md`,dangerouslySetInnerHTML:{__html:c}}):(0,S.jsx)(`pre`,{children:t.content.trim()||`(empty)`})})]}),(0,S.jsx)(`aside`,{className:`detail-rail`,children:(0,S.jsxs)(`section`,{className:`panel`,children:[(0,S.jsx)(`div`,{className:`panel-head`,children:(0,S.jsx)(`span`,{className:`microlabel`,children:`about`})}),(0,S.jsxs)(`div`,{className:`rail-list`,children:[(0,S.jsxs)(`div`,{className:`rail-kv`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`source`}),(0,S.jsx)(`span`,{className:`v`,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,S.jsxs)(`div`,{className:`rail-kv`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`path`}),(0,S.jsx)(`span`,{className:`v mono skill-path`,title:t.path,children:t.path})]}),(0,S.jsxs)(`div`,{className:`rail-kv`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`invoke`}),(0,S.jsxs)(`span`,{className:`v`,children:[(0,S.jsxs)(`code`,{children:[`/`,t.name]}),` in any session`]})]}),t.files.length>0&&(0,S.jsxs)(`div`,{className:`rail-kv`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`bundled files`}),t.files.map(e=>(0,S.jsx)(`span`,{className:`v mono`,children:e},e))]})]})]})})]})]}):(0,S.jsx)(`div`,{className:`empty`,children:`loading…`})}var Wi=[``,`low`,`medium`,`high`,`xhigh`,`max`],Gi=[`🤖`,`🧑‍💻`,`🎧`,`🛠️`,`📊`,`✍️`,`🔍`,`🧹`,`📦`,`🚀`];function Ki({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===`chat`?e[2]:n===`chats`?e[1]:void 0,i=F(`/api/agents`,!1),a=N(),[o,s]=(0,v.useState)(()=>{try{let e=JSON.parse(localStorage.getItem(`kw-agent-groups`)??`[]`);return Array.isArray(e)?e.map(String):[]}catch{return[]}}),[c,l]=(0,v.useState)(!1),[u,d]=(0,v.useState)(``),[f,p]=(0,v.useState)(null),[m,h]=(0,v.useState)(``),[g,_]=(0,v.useState)(null),[y,b]=(0,v.useState)(null),[x,w]=(0,v.useState)({}),T=(i?.agents??[]).map(e=>x[e.slug]===void 0?e:{...e,group:x[e.slug]||void 0});(0,v.useEffect)(()=>{w(e=>{let t={...e},n=!1;for(let e of i?.agents??[])t[e.slug]!==void 0&&(e.group??``)===t[e.slug]&&(delete t[e.slug],n=!0);return n?t:e})},[i]);let E=T.filter(e=>!e.archived),D=T.filter(e=>e.archived),[O,ee]=(0,v.useState)(!1),te=[...new Set([...E.map(e=>e.group??``).filter(Boolean),...o])].sort((e,t)=>e.localeCompare(t)),ne=E.filter(e=>!e.group);function k(e){s(e);try{localStorage.setItem(`kw-agent-groups`,JSON.stringify(e))}catch{}}function re(){let e=u.trim();l(!1),d(``),e&&!te.includes(e)&&k([...o,e])}function ie(e,t){p(null);let n=t.trim();if(n&&n!==e){for(let t of T.filter(t=>t.group===e))j(t.slug,n);o.includes(e)&&k([...new Set(o.map(t=>t===e?n:t))])}}async function j(e,t){if((T.find(t=>t.slug===e)?.group??``)!==t){w(n=>({...n,[e]:t}));try{let n=await fetch(`/api/agents/${encodeURIComponent(e)}`);if(!n.ok)throw Error();let r=await n.json();if(!(await fetch(`/api/agents/${encodeURIComponent(e)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({...r,group:t||void 0})})).ok)throw Error()}catch{w(t=>{let n={...t};return delete n[e],n})}}}let M=e=>a?{onDragOver:t=>{g!=null&&(t.preventDefault(),t.dataTransfer.dropEffect=`move`,y!==e&&b(e))},onDrop:t=>{t.preventDefault();let n=t.dataTransfer.getData(`text/plain`)||g;n&&j(n,e),_(null),b(null)}}:{},ae=e=>(0,S.jsxs)(A,{href:`/agents/${encodeURIComponent(e.slug)}`,className:`side-row ${e.slug===t?`active`:``} ${g===e.slug?`dragging`:``}`,draggable:a,onDragStart:t=>{t.dataTransfer.setData(`text/plain`,e.slug),t.dataTransfer.effectAllowed=`move`,_(e.slug)},onDragEnd:()=>{_(null),b(null)},children:[(0,S.jsx)(`span`,{className:`agent-avatar sm`,children:(0,S.jsx)(`span`,{"aria-hidden":!0,children:e.emoji})}),(0,S.jsxs)(`div`,{className:`side-row-body`,children:[(0,S.jsx)(`div`,{className:`side-row-top`,children:(0,S.jsx)(`span`,{className:`side-wf`,children:e.name})}),(0,S.jsx)(`div`,{className:`side-row-sub`,children:(0,S.jsx)(`span`,{className:`side-req`,children:e.description||e.harness})})]})]},e.slug),oe=e=>(0,S.jsxs)(A,{href:`/agents/${encodeURIComponent(e.slug)}/info`,className:`side-row archived-row ${e.slug===t?`active`:``}`,children:[(0,S.jsx)(`span`,{className:`agent-avatar sm`,children:(0,S.jsx)(`span`,{"aria-hidden":!0,children:e.emoji})}),(0,S.jsxs)(`div`,{className:`side-row-body`,children:[(0,S.jsx)(`div`,{className:`side-row-top`,children:(0,S.jsx)(`span`,{className:`side-wf`,children:e.name})}),(0,S.jsx)(`div`,{className:`side-row-sub`,children:(0,S.jsx)(`span`,{className:`side-req`,children:e.description||e.harness})})]})]},e.slug),se;se=n===`new`?(0,S.jsx)(ra,{},`new`):n===`edit`&&t?(0,S.jsx)(ra,{slug:t},t):n===`chat`&&t&&r?(0,S.jsx)(`div`,{className:`chat-main`,children:(0,S.jsx)(Br,{id:r,agentName:T.find(e=>e.slug===t)?.name??t,agentDescription:T.find(e=>e.slug===t)?.description},r)}):n===`chats`?r?(0,S.jsx)(`div`,{className:`chat-main`,children:(0,S.jsx)(Br,{id:r},r)}):(0,S.jsx)(zr,{}):n===`info`&&t?(0,S.jsx)($i,{slug:t},t):t?(0,S.jsx)(Yi,{slug:t},t):(0,S.jsx)(Qi,{hasAgents:E.length>0,root:i?.root});let ce=(n===`agent`||n===`info`||n===`chat`)&&t?T.find(e=>e.slug===t)?.knowledge??[]:[],[P,le]=(0,v.useState)(()=>localStorage.getItem(`kw-kside`)!==`hidden`),[ue,de]=(0,v.useState)(()=>Number(localStorage.getItem(`kw-kside-w`))||460),fe=ce.length>0&&P;function pe(e){le(e),localStorage.setItem(`kw-kside`,e?`open`:`hidden`)}function me(e){de(e),localStorage.setItem(`kw-kside-w`,String(e))}return(0,S.jsxs)(`div`,{className:`runs-screen agents-screen ${t||n===`chats`?`has-sessions`:``} ${fe?`has-knowledge`:``}`,style:fe?{"--kside-w":`${ue}px`}:void 0,children:[(0,S.jsxs)(`aside`,{className:`runs-side`,children:[(0,S.jsxs)(`div`,{className:`side-head`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`agents`}),(0,S.jsx)(`span`,{className:`spacer`}),a&&(0,S.jsxs)(A,{href:`/agents/new`,className:`open-raw`,children:[(0,S.jsx)(C,{name:`add`,className:`ms-sm`}),` new`]})]}),(0,S.jsxs)(`div`,{className:`side-list`,children:[(0,S.jsxs)(A,{href:`/agents/chats`,className:`side-row side-general ${n===`chats`?`active`:``}`,children:[(0,S.jsx)(`span`,{className:`agent-avatar sm`,children:(0,S.jsx)(`span`,{"aria-hidden":!0,children:`💬`})}),(0,S.jsxs)(`div`,{className:`side-row-body`,children:[(0,S.jsx)(`div`,{className:`side-row-top`,children:(0,S.jsx)(`span`,{className:`side-wf`,children:`General Chats`})}),(0,S.jsx)(`div`,{className:`side-row-sub`,children:(0,S.jsx)(`span`,{className:`side-req`,children:`chats without an agent`})})]})]}),(0,S.jsxs)(`div`,{className:`side-group ${g&&y===``?`drop-over`:``}`,...M(``),children:[ne.map(ae),g!=null&&ne.length===0&&(0,S.jsx)(`div`,{className:`side-group-empty`,children:`no group — drop here`})]}),te.map(e=>{let t=E.filter(t=>t.group===e);return(0,S.jsxs)(`div`,{className:`side-group ${g&&y===e?`drop-over`:``}`,...M(e),children:[(0,S.jsxs)(`div`,{className:`side-group-head`,children:[f===e?(0,S.jsx)(`input`,{className:`side-group-rename`,autoFocus:!0,value:m,onChange:e=>h(e.target.value),onKeyDown:t=>{t.key===`Enter`&&ie(e,m),t.key===`Escape`&&p(null)},onBlur:()=>ie(e,m)}):(0,S.jsx)(`span`,{className:`microlabel`,children:e}),(0,S.jsx)(`span`,{className:`side-group-count num`,children:t.length}),(0,S.jsx)(`span`,{className:`spacer`}),a&&f!==e&&(0,S.jsx)(`button`,{className:`side-group-x`,title:`Rename group`,onClick:()=>{p(e),h(e)},children:(0,S.jsx)(C,{name:`edit`,className:`ms-sm`})}),a&&t.length===0&&o.includes(e)&&(0,S.jsx)(`button`,{className:`side-group-x`,title:`Remove empty group`,onClick:()=>k(o.filter(t=>t!==e)),children:(0,S.jsx)(C,{name:`close`,className:`ms-sm`})})]}),t.map(ae),t.length===0&&(0,S.jsx)(`div`,{className:`side-group-empty`,children:a?`drag agents here`:`no agents`})]},e)}),D.length>0&&(0,S.jsxs)(`div`,{className:`side-group side-archived`,children:[(0,S.jsxs)(`button`,{className:`side-archived-toggle`,"aria-expanded":O,onClick:()=>ee(e=>!e),children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`archived`}),(0,S.jsx)(`span`,{className:`side-group-count num`,children:D.length}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsx)(C,{name:O?`expand_less`:`expand_more`,className:`ms-sm`})]}),O&&D.map(oe)]}),i&&T.length===0&&(0,S.jsx)(`div`,{className:`viewer-note`,children:`no agents yet`}),a&&(c?(0,S.jsx)(`div`,{className:`side-group-new`,children:(0,S.jsx)(`input`,{autoFocus:!0,value:u,placeholder:`group name, e.g. Team Content`,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&re(),e.key===`Escape`&&(l(!1),d(``))},onBlur:re})}):(0,S.jsxs)(`button`,{className:`side-group-add`,onClick:()=>l(!0),children:[(0,S.jsx)(C,{name:`add`,className:`ms-sm`}),` group`]}))]})]}),t&&(0,S.jsx)(Xi,{slug:t,chatId:r}),n===`chats`&&(0,S.jsx)(Zi,{chatId:r}),(0,S.jsx)(`div`,{className:`runs-main`,children:se}),fe&&(0,S.jsx)(qi,{bundles:ce,onHide:()=>pe(!1),onResize:me}),ce.length>0&&!P&&(0,S.jsxs)(`button`,{className:`kside-reopen`,onClick:()=>pe(!0),title:`Show knowledge sidebar`,children:[(0,S.jsx)(C,{name:`menu_book`,className:`ms-sm`}),` knowledge`]})]})}function qi({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 fetch(`/api/knowledge/${encodeURIComponent(e)}`,{cache:`no-store`}),r=n.ok?await n.json():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 fetch(`/api/knowledge/${encodeURIComponent(t)}/concept?id=${encodeURIComponent(n)}`,{cache:`no-store`}),i=e.ok?await e.json():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(await fetch(`/api/knowledge/${encodeURIComponent(e)}/concept`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({id:t,content:p})})).json();r.error?y(r.error):(c(e=>({...e,[n]:r})),f(null))}catch(e){y(e.message)}g(!1)}return(0,S.jsxs)(`aside`,{className:`runs-side knowledge-side`,children:[(0,S.jsx)(`div`,{className:`kside-resizer`,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,S.jsxs)(`div`,{className:`side-head`,children:[(0,S.jsxs)(`span`,{className:`kside-headline`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`knowledge`}),(0,S.jsx)(`span`,{className:`kside-hint`,children:`read & kept current by this agent`})]}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsxs)(`button`,{className:`open-raw`,onClick:t,title:`Hide knowledge sidebar`,children:[`hide `,(0,S.jsx)(C,{name:`close`,className:`ms-sm`})]})]}),(0,S.jsx)(`div`,{className:`side-list`,children:e.map(e=>{let t=r[e],n=l[e]===!0;return(0,S.jsxs)(`div`,{className:`kside-bundle`,children:[(0,S.jsxs)(`div`,{className:`kside-bundle-head`,children:[(0,S.jsxs)(`button`,{className:`kside-bundle-toggle`,"aria-expanded":!n,onClick:()=>u({...l,[e]:!n}),children:[(0,S.jsx)(`span`,{className:`kside-chev ${n?``:`open`}`,"aria-hidden":!0,children:(0,S.jsx)(C,{name:`chevron_right`,className:`ms-sm`})}),(0,S.jsx)(`span`,{className:`kside-bundle-name`,children:e}),t&&(0,S.jsx)(`span`,{className:`kside-count num`,children:t.concepts.length})]}),(0,S.jsx)(`button`,{className:`kside-open`,title:`Export this bundle as PDF`,onClick:()=>void wi(e),children:(0,S.jsx)(C,{name:`picture_as_pdf`,className:`ms-sm`})}),(0,S.jsx)(A,{href:`/knowledge/${encodeURIComponent(e)}`,className:`kside-open`,title:`Open this bundle on the knowledge screen`,children:`↗`})]}),!n&&t===null&&(0,S.jsx)(`div`,{className:`viewer-note`,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,S.jsxs)(`div`,{className:`kside-concept ${r?`open`:``}`,children:[(0,S.jsxs)(`button`,{className:`kside-row`,"aria-expanded":r,title:t.description||void 0,onClick:()=>b(e,t.id),children:[(0,S.jsx)(`span`,{className:`kside-chev ${r?`open`:``}`,"aria-hidden":!0,children:(0,S.jsx)(C,{name:`chevron_right`,className:`ms-sm`})}),(0,S.jsx)(`span`,{className:`kside-title`,children:t.title||t.id}),t.stale&&(0,S.jsx)(`span`,{className:`kside-stale`,title:`Past its stale-after date — ask the agent to re-verify it`,children:`stale`})]}),r&&(0,S.jsx)(`div`,{className:`kside-card`,ref:e=>e?.scrollIntoView({block:`nearest`}),children:s[n]===void 0?(0,S.jsx)(`div`,{className:`viewer-note`,children:`loading…`}):s[n]===null?(0,S.jsx)(`div`,{className:`viewer-note`,children:`could not load concept`}):d===n?(0,S.jsxs)(`div`,{className:`kside-edit`,children:[(0,S.jsx)(`textarea`,{className:`concept-edit`,value:p,rows:Math.min(28,Math.max(10,p.split(`
206
- `).length+2)),onChange:e=>m(e.target.value),spellCheck:!1}),(0,S.jsxs)(`div`,{className:`kside-actions`,children:[(0,S.jsx)(`button`,{className:`open-raw`,disabled:h,onClick:()=>f(null),children:`cancel`}),(0,S.jsx)(`button`,{className:`open-raw`,disabled:h,onClick:()=>x(e,t.id),children:h?`saving…`:(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(C,{name:`check`,className:`ms-sm`}),` save`]})})]}),_&&(0,S.jsxs)(`div`,{className:`msg error`,children:[(0,S.jsx)(C,{name:`error`,className:`ms-sm`}),` `,_]})]}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`div`,{className:`kside-card-bar`,children:[t.type&&(0,S.jsx)(`span`,{className:`kside-type`,children:t.type}),Ji(t)&&(0,S.jsxs)(`span`,{className:`kside-updated num`,children:[`updated `,_e(Ji(t))]}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsxs)(`button`,{className:`open-raw`,onClick:()=>{m(s[n].raw),f(n),y(``)},children:[(0,S.jsx)(C,{name:`edit`,className:`ms-sm`}),` edit`]}),(0,S.jsxs)(A,{href:ki(e,t.id),className:`open-raw`,title:`Full-screen document editor with autosave`,children:[(0,S.jsx)(C,{name:`edit_document`,className:`ms-sm`}),` editor`]}),(0,S.jsx)(A,{href:i,className:`open-raw`,children:`open ↗`})]}),(0,S.jsx)(`div`,{className:`kside-md md-body`,dangerouslySetInnerHTML:{__html:kr.sanitize(z.parse(s[n].body??``,{async:!1}))}})]})})]},t.id)}),!n&&t&&t.concepts.length===0&&(0,S.jsx)(`div`,{className:`viewer-note`,children:`no concepts yet`})]},e)})})]})}function Ji(e){return[e.generated?.at,...e.verified.map(e=>e.at)].filter(e=>typeof e==`string`&&e.length>0).sort().pop()}function Yi({slug:e}){let[t,n]=(0,v.useState)(!1);return(0,v.useEffect)(()=>{let t=!0;return n(!1),fetch(`/api/chats`).then(e=>e.json()).then(r=>{if(!t)return;let i=r.chats.find(t=>t.scope.kind===`agent`&&t.scope.slug===e);i?k(`/agents/${encodeURIComponent(e)}/chat/${i.id}`,{replace:!0}):n(!0)}).catch(()=>t&&n(!0)),()=>{t=!1}},[e]),t?(0,S.jsx)($i,{slug:e}):(0,S.jsx)(`div`,{className:`empty`,children:`loading…`})}function Xi({slug:e,chatId:t}){let n=F(`/api/chats`,!1),r=(n?.chats??[]).filter(t=>t.scope.kind===`agent`&&t.scope.slug===e),[i,a]=(0,v.useState)(!1);return(0,S.jsxs)(`aside`,{className:`runs-side`,children:[(0,S.jsxs)(`div`,{className:`side-head`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`sessions`}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsx)(A,{href:`/agents/${encodeURIComponent(e)}/info`,className:`open-raw`,title:`agent profile & settings`,children:`profile`}),(0,S.jsx)(`button`,{className:`open-raw`,disabled:i,onClick:async()=>{a(!0),await Rr(`claude`,{kind:`agent`,slug:e}),a(!1)},children:i?`…`:(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(C,{name:`add`,className:`ms-sm`}),` new`]})})]}),(0,S.jsxs)(`div`,{className:`side-list`,children:[r.map(n=>(0,S.jsxs)(A,{href:`/agents/${encodeURIComponent(e)}/chat/${n.id}`,className:`side-row ${n.id===t?`active`:``}`,children:[(0,S.jsx)(`span`,{className:`lamp ${n.awaitingApproval?`blocked`:n.busy?`running`:`pending`}`,title:n.awaitingApproval?`waiting for your approval`:void 0}),(0,S.jsxs)(`div`,{className:`side-row-body`,children:[(0,S.jsx)(`div`,{className:`side-row-top`,children:(0,S.jsx)(`span`,{className:`side-wf`,children:n.title||`new session`})}),(0,S.jsx)(`div`,{className:`side-row-sub`,children:(0,S.jsx)(`span`,{className:`side-when num`,children:_e(n.updatedAt)})})]}),(0,S.jsx)(`button`,{type:`button`,className:`row-x`,title:`delete session`,onClick:async r=>{r.preventDefault(),r.stopPropagation(),window.confirm(`Delete session "${n.title||n.id}"?`)&&(await fetch(`/api/chats/${n.id}`,{method:`DELETE`}).catch(()=>{}),n.id===t&&k(`/agents/${encodeURIComponent(e)}`))},children:(0,S.jsx)(C,{name:`close`,className:`ms-sm`})})]},n.id)),n&&r.length===0&&(0,S.jsx)(`div`,{className:`viewer-note`,children:`no sessions yet`})]})]})}function Zi({chatId:e}){let t=F(`/api/chats`,!1),n=(t?.chats??[]).filter(e=>e.scope.kind!==`agent`);return(0,S.jsxs)(`aside`,{className:`runs-side`,children:[(0,S.jsxs)(`div`,{className:`side-head`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`chats`}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsxs)(A,{href:`/agents/chats`,className:`open-raw`,children:[(0,S.jsx)(C,{name:`add`,className:`ms-sm`}),` new`]})]}),(0,S.jsxs)(`div`,{className:`side-list`,children:[n.map(t=>(0,S.jsxs)(A,{href:`/agents/chats/${t.id}`,className:`side-row ${t.id===e?`active`:``}`,children:[(0,S.jsx)(`span`,{className:`lamp ${t.awaitingApproval?`blocked`:t.busy?`running`:`pending`}`,title:t.awaitingApproval?`waiting for your approval`:void 0}),(0,S.jsxs)(`div`,{className:`side-row-body`,children:[(0,S.jsx)(`div`,{className:`side-row-top`,children:(0,S.jsx)(`span`,{className:`side-wf`,children:t.title||`new chat`})}),(0,S.jsxs)(`div`,{className:`side-row-sub`,children:[(0,S.jsxs)(`span`,{className:`side-req`,children:[t.agent,t.scope.kind===`run`?` · ${t.scope.runId}`:t.scope.kind===`kraftwerk`?` · kraftwerk`:t.scope.kind===`knowledge`?` · knowledge${t.scope.bundle?`:${t.scope.bundle}`:``}`:``]}),(0,S.jsx)(`span`,{className:`side-when num`,children:_e(t.updatedAt)})]})]}),(0,S.jsx)(`button`,{type:`button`,className:`row-x`,title:`delete chat`,onClick:async n=>{n.preventDefault(),n.stopPropagation(),window.confirm(`Delete chat "${t.title||t.id}"?`)&&(await fetch(`/api/chats/${t.id}`,{method:`DELETE`}).catch(()=>{}),t.id===e&&k(`/agents/chats`))},children:(0,S.jsx)(C,{name:`close`,className:`ms-sm`})})]},t.id)),t&&n.length===0&&(0,S.jsx)(`div`,{className:`viewer-note`,children:`no chats yet`})]})]})}function Qi({hasAgents:e,root:t}){let n=N();return(0,S.jsxs)(`div`,{className:`new-chat`,children:[(0,S.jsx)(`div`,{className:`page-head`,children:(0,S.jsx)(`h1`,{children:`agents`})}),(0,S.jsxs)(`section`,{className:`panel new-chat-panel`,children:[(0,S.jsx)(`div`,{className:`panel-head`,children:(0,S.jsx)(`span`,{className:`microlabel`,children:`what lives here`})}),(0,S.jsxs)(`div`,{className:`know-intro`,children:[`Your agents, set up like agents: each one has a name, a role (system prompt), a harness/model to run on, and the workflows that belong to its job. An agent lives in`,` `,(0,S.jsx)(`code`,{children:t?`${t}/<slug>/`:`agents/<slug>/`}),` as `,(0,S.jsx)(`code`,{children:`agent.yml`}),` +`,` `,(0,S.jsx)(`code`,{children:`system.md`}),` — git-tracked, so your team travels with the repo. Every session is a persistent conversation with that agent; it knows its connected workflows and knowledge bundles, runs the workflows for you, and keeps the knowledge current.`]}),n?(0,S.jsx)(`div`,{style:{padding:`0 16px 16px`},children:(0,S.jsx)(`button`,{className:`run-btn`,onClick:()=>k(`/agents/new`),children:(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(C,{name:`add`,className:`ms-sm`}),` `,e?`new agent`:`create your first agent`]})})}):(0,S.jsx)(`div`,{className:`settings-note`,style:{padding:`0 16px 16px`},children:`Creating agents needs expert mode — flip the switch in the top bar.`})]})]})}function $i({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)(!1),[l,u]=(0,v.useState)(``),[d,f]=(0,v.useState)(``),[p,m]=(0,v.useState)([]),[h,g]=(0,v.useState)(!0),[_,y]=(0,v.useState)(!1),[b,x]=(0,v.useState)(``),w=F(`/api/workflows`,!1),T=F(`/api/knowledge`,!1),E=F(`/api/skills`,!1);(0,v.useEffect)(()=>{let t=!0;return fetch(`/api/agents/${encodeURIComponent(e)}`).then(e=>e.ok?e.json():Promise.reject()).then(e=>t&&n(e)).catch(()=>t&&i(!0)),()=>{t=!1}},[e]);async function D(r){if(t){y(!0),x(``);try{let i=await(await fetch(`/api/agents/${encodeURIComponent(e)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({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,skills:t.skills,...r})})).json();i.error?x(i.error):(n(i),u(``))}catch(e){x(e.message)}y(!1)}}function O(e,t){m(t?[...p,e]:p.filter(t=>t!==e))}async function ee(t){y(!0),x(``);try{let r=await(await fetch(`/api/agents/${encodeURIComponent(e)}/archive`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({archived:t})})).json();r.error?x(r.error):n(r)}catch(e){x(e.message)}y(!1)}if(r)return(0,S.jsx)(`div`,{className:`empty`,children:`agent not found`});if(!t)return(0,S.jsx)(`div`,{className:`empty`,children:`loading…`});let te=e=>(0,S.jsxs)(`div`,{className:`agent-form-row`,style:{marginTop:8},children:[(0,S.jsx)(`button`,{className:`run-btn`,disabled:_,onClick:()=>void D(e),children:_?`saving…`:`save`}),(0,S.jsx)(`button`,{className:`open-raw`,disabled:_,onClick:()=>(u(``),x(``)),children:`cancel`})]});return(0,S.jsxs)(`div`,{className:`agent-view`,children:[(0,S.jsxs)(`div`,{className:`detail-head`,children:[(0,S.jsx)(`span`,{className:`agent-avatar lg`,children:(0,S.jsx)(`span`,{"aria-hidden":!0,children:t.emoji})}),(0,S.jsx)(`h1`,{children:t.name}),(0,S.jsx)(`span`,{className:`chip agent`,children:t.harness}),t.model&&(0,S.jsx)(`span`,{className:`chip`,children:t.model}),t.effort&&(0,S.jsxs)(`span`,{className:`chip`,children:[`effort: `,t.effort]}),t.archived&&(0,S.jsxs)(`span`,{className:`chip archived-chip`,children:[(0,S.jsx)(C,{name:`inventory_2`,className:`ms-sm`}),` archived`]}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsx)(A,{href:`/agents/${encodeURIComponent(e)}/edit`,className:`open-raw`,children:`edit`}),t.archived?(0,S.jsxs)(`button`,{className:`run-btn tonal`,disabled:_,onClick:()=>void ee(!1),children:[(0,S.jsx)(C,{name:`unarchive`,className:`ms-sm`}),` `,_?`…`:`unarchive`]}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`button`,{className:`open-raw`,disabled:_,title:`Hide this agent from the roster — restorable any time`,onClick:()=>void ee(!0),children:[(0,S.jsx)(C,{name:`archive`,className:`ms-sm`}),` archive`]}),(0,S.jsx)(`button`,{className:`run-btn`,disabled:a,onClick:async()=>{o(!0),await Rr(`claude`,{kind:`agent`,slug:e}),o(!1)},children:a?`starting…`:`new session`})]})]}),(0,S.jsxs)(`section`,{className:`panel`,children:[(0,S.jsxs)(`div`,{className:`m3-list`,children:[(0,S.jsxs)(`button`,{type:`button`,className:`m3-row m3-toggle`,onClick:()=>c(!s),children:[(0,S.jsx)(`span`,{className:`m3-ico`,children:(0,S.jsx)(C,{name:`badge`})}),(0,S.jsxs)(`span`,{className:`m3-body`,children:[(0,S.jsx)(`span`,{className:`m3-head`,children:`role`}),!s&&(0,S.jsx)(`span`,{className:`m3-sub m3-ellipsis`,children:(t.system||``).trim().split(`
203
+ </html>`;n.location.href=URL.createObjectURL(new Blob([p],{type:`text/html`}))}function Mi(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 Ni(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 Pi(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>${Fi(r)}</h1><div class="meta">${Fi(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 Fi(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`)}function Ii(e,t){return`/edit/${encodeURIComponent(e)}/${t.split(`/`).map(encodeURIComponent).join(`/`)}`}function Li({bundle:e,conceptId:t}){let n=F(`/api/knowledge`,!1),r=n?.bundles??[];return(0,S.jsxs)(`div`,{className:`runs-screen`,children:[(0,S.jsxs)(`aside`,{className:`runs-side`,children:[(0,S.jsxs)(`div`,{className:`side-head`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`bundles`}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsxs)(A,{href:`/knowledge`,className:`open-raw`,children:[(0,S.jsx)(C,{name:`add`,className:`ms-sm`}),` new`]})]}),(0,S.jsxs)(`div`,{className:`side-list`,children:[r.map(t=>(0,S.jsxs)(A,{href:`/knowledge/${encodeURIComponent(t.name)}`,className:`side-row ${t.name===e?`active`:``}`,children:[(0,S.jsx)(`span`,{className:`lamp ok`}),(0,S.jsxs)(`div`,{className:`side-row-body`,children:[(0,S.jsxs)(`div`,{className:`side-row-top`,children:[(0,S.jsx)(`span`,{className:`side-wf`,children:t.name}),(0,S.jsx)(`span`,{className:`side-when num`,children:t.concepts})]}),(0,S.jsx)(`div`,{className:`side-row-sub`,children:(0,S.jsxs)(`span`,{className:`side-req`,children:[t.okfVersion?`okf ${t.okfVersion}`:`okf`,t.updatedAt?` · ${t.updatedAt.slice(0,10)}`:``]})})]})]},t.name)),n&&r.length===0&&(0,S.jsx)(`div`,{className:`viewer-note`,children:`no bundles yet`})]})]}),(0,S.jsx)(`div`,{className:`runs-main`,children:e?(0,S.jsx)(Vi,{name:e,conceptId:t},e):(0,S.jsx)(Ri,{root:n?.root})})]})}function Ri({root:e}){let[t,n]=(0,v.useState)(``),[r,i]=(0,v.useState)(``),[a,o]=(0,v.useState)(!1);async function s(){let e=t.trim();if(!e)return;o(!0),i(``);let n=await(await fetch(`/api/knowledge`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:e})})).json();o(!1),n.error?i(n.error):window.location.hash=`/knowledge/${encodeURIComponent(e)}`}return(0,S.jsxs)(`div`,{className:`new-chat`,children:[(0,S.jsx)(`div`,{className:`page-head`,children:(0,S.jsx)(`h1`,{children:`context & knowledge`})}),(0,S.jsxs)(`section`,{className:`panel new-chat-panel`,children:[(0,S.jsx)(`div`,{className:`panel-head`,children:(0,S.jsx)(`span`,{className:`microlabel`,children:`what lives here`})}),(0,S.jsxs)(`div`,{className:`know-intro`,children:[`Curated knowledge as `,(0,S.jsx)(`b`,{children:`OKF bundles`}),` (Open Knowledge Format v0.2): plain markdown files with YAML frontmatter`,e?(0,S.jsxs)(S.Fragment,{children:[` under `,(0,S.jsx)(`code`,{children:e})]}):null,`, readable by humans and agents, diffable in git. Agents write through`,` `,(0,S.jsx)(`code`,{children:`kraftwerk knowledge put`}),` (provenance is stamped automatically); you raise a concept's trust tier by verifying it here.`]}),(0,S.jsx)(`div`,{className:`panel-head`,children:(0,S.jsx)(`span`,{className:`microlabel`,children:`new bundle`})}),(0,S.jsxs)(`div`,{className:`know-newbundle`,children:[(0,S.jsx)(`input`,{value:t,placeholder:`bundle name, e.g. customer-support`,onChange:e=>n(e.target.value),onKeyDown:e=>e.key===`Enter`&&void s()}),(0,S.jsx)(`button`,{className:`run-btn`,disabled:!t.trim()||a,onClick:s,children:a?`creating…`:`create`})]}),r&&(0,S.jsxs)(`div`,{className:`msg error`,children:[(0,S.jsx)(C,{name:`error`,className:`ms-sm`}),` `,r]})]})]})}function zi({tier:e}){return(0,S.jsx)(`span`,{className:`chip trust ${e}`,children:e})}var Bi=`@activity`;function Vi({name:e,conceptId:t}){let n=F(`/api/knowledge/${encodeURIComponent(e)}`,!1);if(!n)return(0,S.jsx)(`div`,{className:`empty`,children:`loading…`});if(`error`in n)return(0,S.jsx)(`div`,{className:`empty`,children:`bundle not found`});let r=t===Bi?`activity`:`pages`,i=n.concepts,a=r===`pages`?t&&i.some(e=>e.id===t)?t:i[0]?.id:void 0,o=`/knowledge/${encodeURIComponent(e)}`;return(0,S.jsxs)(`div`,{className:`agent-view`,children:[(0,S.jsxs)(`div`,{className:`page-head`,children:[(0,S.jsx)(`h1`,{children:e}),(0,S.jsxs)(`span`,{className:`count`,children:[i.length,` pages`]}),(0,S.jsxs)(`div`,{className:`tabs`,children:[(0,S.jsx)(A,{href:o,className:r===`pages`?`active`:``,children:`pages`}),(0,S.jsx)(A,{href:`${o}/${Bi}`,className:r===`activity`?`active`:``,children:`activity`})]}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsxs)(`button`,{className:`open-raw`,onClick:()=>void ji(e),children:[(0,S.jsx)(C,{name:`picture_as_pdf`,className:`ms-sm`}),` export PDF`]}),(0,S.jsx)(`button`,{className:`run-btn`,onClick:()=>void Gr(`claude`,{kind:`knowledge`,bundle:e}),children:`curate in chat`})]}),r===`activity`?n.log?(0,S.jsx)(Gi,{name:e,log:n.log}):(0,S.jsx)(`section`,{className:`panel`,children:(0,S.jsx)(`div`,{className:`viewer-note`,children:`no activity yet`})}):i.length===0?(0,S.jsx)(`section`,{className:`panel`,children:(0,S.jsxs)(`div`,{className:`viewer-note`,children:[`No pages yet — start a chat to author some, or write one with`,` `,(0,S.jsxs)(`code`,{children:[`kraftwerk knowledge put `,e,`/<path>`]}),`.`]})}):(0,S.jsxs)(`div`,{className:`wiki`,children:[(0,S.jsx)(`aside`,{className:`wiki-side`,children:Ki(i).map(({folder:e,concepts:t})=>(0,S.jsxs)(v.Fragment,{children:[e&&(0,S.jsxs)(`div`,{className:`wiki-folder`,children:[e,`/`]}),t.map(e=>(0,S.jsxs)(A,{href:`${o}/${e.id}`,className:`wiki-page ${e.id===a?`active`:``}`,title:`${e.id}.md`,children:[(0,S.jsx)(C,{name:Hi(e.type),className:`ms-sm`}),(0,S.jsx)(`span`,{className:`wiki-page-title`,children:e.title}),(e.stale||e.error)&&(0,S.jsx)(`span`,{className:`wiki-dot`,title:e.error??`stale`})]},e.id))]},e||`.`))}),(0,S.jsx)(`div`,{className:`wiki-main`,children:a&&(0,S.jsx)(qi,{bundle:e,conceptId:a},a)})]})]})}function Hi(e){switch((e??``).toLowerCase()){case`reference`:return`article`;case`policy`:return`gavel`;case`guide`:case`howto`:return`route`;case`decision`:return`balance`;default:return`menu_book`}}function Ui(e){let t=[];for(let n of e.split(`
204
+ `)){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 Wi(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,S.jsx)(A,{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 Gi({name:e,log:t}){let n=Ui(t),[r,i]=(0,v.useState)(!1);return(0,S.jsxs)(`section`,{className:`panel`,children:[(0,S.jsxs)(`div`,{className:`panel-head`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`activity`}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsx)(`button`,{className:`open-raw`,onClick:()=>i(!r),children:r?`timeline`:`raw log`})]}),r||n.length===0?(0,S.jsx)(`div`,{className:`viewer-body`,children:(0,S.jsx)(`pre`,{children:t})}):(0,S.jsx)(`div`,{className:`know-log`,children:n.map(t=>(0,S.jsxs)(v.Fragment,{children:[(0,S.jsx)(`div`,{className:`m3-subhead num`,children:t.date}),t.entries.map((t,n)=>(0,S.jsxs)(`div`,{className:`know-log-row`,children:[(0,S.jsx)(`span`,{className:`chip log-kind log-${t.kind}`,children:t.kind}),(0,S.jsx)(`span`,{className:`know-log-text`,children:Wi(e,t.text)})]},n))]},t.date))})]})}function Ki(e){let t=new Map;for(let n of e){let e=n.id.includes(`/`)?n.id.slice(0,n.id.lastIndexOf(`/`)):``;(t.get(e)??t.set(e,[]).get(e)).push(n)}return[...t.keys()].sort((e,t)=>e===``?-1:t===``?1:e.localeCompare(t)).map(e=>({folder:e,concepts:t.get(e)}))}function qi({bundle:e,conceptId:t}){let[n,r]=(0,v.useState)(null),[i,a]=(0,v.useState)(!1),[o,s]=(0,v.useState)(!1),[c,l]=(0,v.useState)(!1),[u,d]=(0,v.useState)(``),[f,p]=(0,v.useState)(!1),[m,h]=(0,v.useState)(``),[g,_]=(0,v.useState)(`rendered`),y=(0,v.useMemo)(()=>n?kr.sanitize(z.parse(Mi(n.body,e),{async:!1})):``,[n?.body,e]),b=()=>{fetch(`/api/knowledge/${encodeURIComponent(e)}/concept?id=${encodeURIComponent(t)}`).then(e=>e.ok?e.json():Promise.reject()).then(r).catch(()=>a(!0))};(0,v.useEffect)(()=>{if(c)return;let n=!0,i,o=async()=>{try{let i=await fetch(`/api/knowledge/${encodeURIComponent(e)}/concept?id=${encodeURIComponent(t)}`,{cache:`no-store`});if(i.ok){let e=await i.json();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,c]);async function x(){s(!0),await fetch(`/api/knowledge/${encodeURIComponent(e)}/verify`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({id:t})}).catch(()=>{}),s(!1),b()}async function w(){p(!0),h(``);let n=await fetch(`/api/knowledge/${encodeURIComponent(e)}/concept`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({id:t,content:u})}).then(e=>e.json()).catch(()=>({error:`save failed`}));p(!1),n.error?h(n.error):(r(n),l(!1))}return i?(0,S.jsx)(`div`,{className:`empty`,children:`concept not found`}):n?(0,S.jsxs)(`div`,{className:`agent-view`,children:[(0,S.jsxs)(`div`,{className:`detail-head`,children:[(0,S.jsx)(`h1`,{children:n.title}),n.type&&(0,S.jsx)(`span`,{className:`chip agent`,children:n.type}),(0,S.jsx)(zi,{tier:n.trustTier}),n.status!==`stable`&&(0,S.jsx)(`span`,{className:`chip ${n.status}`,children:n.status}),n.stale&&(0,S.jsxs)(`span`,{className:`chip stale`,children:[`stale since `,n.staleAfter?.slice(0,10)]}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsxs)(A,{href:Ii(e,n.id),className:`open-raw`,title:`Full-screen document editor with autosave`,children:[(0,S.jsx)(C,{name:`edit_document`,className:`ms-sm`}),` open in editor`]}),(0,S.jsxs)(`button`,{className:`open-raw`,onClick:()=>void ji(e,n.id),children:[(0,S.jsx)(C,{name:`picture_as_pdf`,className:`ms-sm`}),` export PDF`]}),(0,S.jsx)(`button`,{className:`run-btn`,disabled:o,onClick:x,children:o?`verifying…`:(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(C,{name:`check`,className:`ms-sm`}),` verify (human)`]})})]}),n.error&&(0,S.jsxs)(`div`,{className:`msg error`,children:[(0,S.jsx)(C,{name:`error`,className:`ms-sm`}),` `,n.error]}),(0,S.jsxs)(`div`,{className:`detail-cols`,children:[(0,S.jsxs)(`section`,{className:`panel`,children:[(0,S.jsxs)(`div`,{className:`panel-head`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`content`}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsxs)(`span`,{className:`side-meta`,children:[e,`/`,n.id,`.md`]}),c?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`button`,{className:`open-raw`,onClick:()=>{l(!1),h(``)},children:`cancel`}),(0,S.jsx)(`button`,{className:`open-raw`,disabled:f,onClick:w,children:f?`saving…`:(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(C,{name:`check`,className:`ms-sm`}),` save`]})})]}):(0,S.jsxs)(`button`,{className:`open-raw`,onClick:()=>{d(n.raw),l(!0),h(``)},children:[(0,S.jsx)(C,{name:`edit`,className:`ms-sm`}),` edit`]})]}),c?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`textarea`,{className:`concept-edit`,value:u,rows:Math.min(40,Math.max(18,u.split(`
205
+ `).length+2)),onChange:e=>d(e.target.value),spellCheck:!1}),(0,S.jsxs)(`div`,{className:`viewer-note`,children:[`full file (frontmatter + markdown body) — saving stamps provenance as`,` `,(0,S.jsx)(`code`,{children:`human:user`}),` and logs an update.`]})]}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`div`,{className:`viewer-note md-toolbar`,children:(0,S.jsxs)(`div`,{className:`tabs`,children:[(0,S.jsx)(`button`,{className:g===`rendered`?`active`:``,onClick:()=>_(`rendered`),children:`rendered`}),(0,S.jsx)(`button`,{className:g===`source`?`active`:``,onClick:()=>_(`source`),children:`source`})]})}),(0,S.jsx)(`div`,{className:`viewer-body`,children:g===`rendered`?(0,S.jsx)(`div`,{className:`md-body concept-md`,dangerouslySetInnerHTML:{__html:y}}):(0,S.jsx)(`pre`,{children:n.body.trim()||`(empty body)`})})]}),m&&(0,S.jsxs)(`div`,{className:`msg error`,children:[(0,S.jsx)(C,{name:`error`,className:`ms-sm`}),` `,m]})]}),(0,S.jsxs)(`aside`,{className:`detail-rail`,children:[(0,S.jsxs)(`section`,{className:`panel`,children:[(0,S.jsx)(`div`,{className:`panel-head`,children:(0,S.jsx)(`span`,{className:`microlabel`,children:`about`})}),(0,S.jsxs)(`div`,{className:`rail-list`,children:[(0,S.jsxs)(`div`,{className:`rail-kv`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`trust`}),(0,S.jsx)(`span`,{className:`v`,children:(0,S.jsx)(zi,{tier:n.trustTier})})]}),(0,S.jsxs)(`div`,{className:`rail-kv`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`generated`}),(0,S.jsx)(`span`,{className:`v ${n.generated?``:`dim`}`,children:n.generated?`${n.generated.by??`?`} · ${(n.generated.at??`?`).slice(0,10)}`:`not stamped`})]}),(0,S.jsxs)(`div`,{className:`rail-kv`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`verified`}),n.verified.length===0?(0,S.jsx)(`span`,{className:`v dim`,children:`never`}):n.verified.map((e,t)=>(0,S.jsxs)(`span`,{className:`v`,children:[e.by??`?`,` · `,(e.at??`?`).slice(0,10)]},t))]}),n.staleAfter&&(0,S.jsxs)(`div`,{className:`rail-kv`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`stale after`}),(0,S.jsxs)(`span`,{className:`v ${n.stale?``:`dim`}`,children:[n.staleAfter.slice(0,10),n.stale&&(0,S.jsx)(`span`,{className:`chip stale`,children:`stale`})]})]}),n.tags.length>0&&(0,S.jsxs)(`div`,{className:`rail-kv`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`tags`}),(0,S.jsx)(`span`,{className:`m3-chips`,children:n.tags.map(e=>(0,S.jsx)(`span`,{className:`chip`,children:e},e))})]})]})]}),n.sources.length>0&&(0,S.jsxs)(`section`,{className:`panel`,children:[(0,S.jsx)(`div`,{className:`panel-head`,children:(0,S.jsx)(`span`,{className:`microlabel`,children:`sources`})}),(0,S.jsx)(`div`,{className:`rail-list`,children:n.sources.map((e,t)=>(0,S.jsxs)(`div`,{className:`rail-kv`,children:[(0,S.jsxs)(`span`,{className:`v`,children:[e.resource?.startsWith(`http`)?(0,S.jsx)(`a`,{href:e.resource,target:`_blank`,rel:`noreferrer`,children:e.title??e.resource}):e.title??e.resource??`?`,e.id&&(0,S.jsxs)(`span`,{className:`know-id`,children:[`[^`,e.id,`]`]})]}),(0,S.jsx)(`span`,{className:`v dim`,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))})]})]})]})]}):(0,S.jsx)(`div`,{className:`empty`,children:`loading…`})}var Ji={workspace:`workspace`,project:`.claude`,user:`global`,agent:`agent`};function Yi(e){return(0,S.jsx)(`span`,{className:`chip skill-src ${e}`,children:Ji[e]})}function Xi({name:e}){let t=F(`/api/skills`,!1),n=t?.skills??[],r=n.filter(e=>e.source===`workspace`),i=n.filter(e=>e.source!==`workspace`),a=t=>(0,S.jsxs)(A,{href:`/skills/${encodeURIComponent(t.name)}`,className:`side-row ${t.name===e?`active`:``}`,children:[(0,S.jsx)(`span`,{className:`lamp ${t.source===`workspace`?`ok`:`dim`}`}),(0,S.jsxs)(`div`,{className:`side-row-body`,children:[(0,S.jsxs)(`div`,{className:`side-row-top`,children:[(0,S.jsxs)(`span`,{className:`side-wf`,children:[`/`,t.name]}),t.source!==`workspace`&&Yi(t.source)]}),(0,S.jsx)(`div`,{className:`side-row-sub`,children:(0,S.jsx)(`span`,{className:`side-req`,children:t.description||`no description`})})]})]},`${t.source}:${t.name}`);return(0,S.jsxs)(`div`,{className:`runs-screen`,children:[(0,S.jsxs)(`aside`,{className:`runs-side`,children:[(0,S.jsx)(`div`,{className:`side-head`,children:(0,S.jsx)(`span`,{className:`microlabel`,children:`workspace skills`})}),(0,S.jsxs)(`div`,{className:`side-list`,children:[r.map(a),t&&r.length===0&&(0,S.jsx)(`div`,{className:`viewer-note`,children:`no workspace skills yet`}),i.length>0&&(0,S.jsxs)(v.Fragment,{children:[(0,S.jsx)(`div`,{className:`side-head skills-local-head`,children:(0,S.jsx)(`span`,{className:`microlabel`,children:`local (this machine / repo)`})}),i.map(a)]})]})]}),(0,S.jsx)(`div`,{className:`runs-main`,children:e?(0,S.jsx)(Qi,{name:e},e):(0,S.jsx)(Zi,{root:t?.root,workspace:r})})]})}function Zi({root:e,workspace:t}){return(0,S.jsxs)(`div`,{className:`new-chat`,children:[(0,S.jsxs)(`div`,{className:`page-head`,children:[(0,S.jsx)(`h1`,{children:`skills`}),(0,S.jsxs)(`span`,{className:`count`,children:[t.length,` in workspace`]})]}),(0,S.jsxs)(`section`,{className:`panel new-chat-panel`,children:[(0,S.jsx)(`div`,{className:`panel-head`,children:(0,S.jsx)(`span`,{className:`microlabel`,children:`what lives here`})}),(0,S.jsxs)(`div`,{className:`know-intro`,children:[`Skills are reusable `,(0,S.jsx)(`b`,{children:`instruction packages`}),`: one folder per skill with a`,` `,(0,S.jsx)(`code`,{children:`SKILL.md`}),` (YAML frontmatter: name, description). `,(0,S.jsx)(`b`,{children:`Workspace skills`}),e?(0,S.jsxs)(S.Fragment,{children:[` live under `,(0,S.jsx)(`code`,{children:e})]}):null,`, are tracked in git and shared with everyone in this workspace — they are the ones to build on. Skills from`,` `,(0,S.jsx)(`code`,{children:`.claude/skills`}),` and your personal `,(0,S.jsx)(`code`,{children:`~/.claude/skills`}),` also work here, but stay repo-/machine-local. Invoke any skill in a session with`,` `,(0,S.jsx)(`code`,{children:`/<name>`}),`.`]}),(0,S.jsx)(`div`,{className:`panel-head`,children:(0,S.jsx)(`span`,{className:`microlabel`,children:`add a workspace skill`})}),(0,S.jsxs)(`div`,{className:`know-intro`,children:[`Create `,(0,S.jsxs)(`code`,{children:[e?`${e}/`:`skills/`,`<name>/SKILL.md`]}),`, commit it, done — it appears here and in every session's `,(0,S.jsx)(`code`,{children:`/`}),` menu.`]})]})]})}function Qi({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?kr.sanitize(z.parse(s,{async:!1})):``,[s]);return(0,v.useEffect)(()=>{fetch(`/api/skills/${encodeURIComponent(e)}`).then(e=>e.ok?e.json():Promise.reject()).then(n).catch(()=>i(!0))},[e]),r?(0,S.jsx)(`div`,{className:`empty`,children:`skill not found`}):t?(0,S.jsxs)(`div`,{className:`agent-view`,children:[(0,S.jsxs)(`div`,{className:`detail-head`,children:[(0,S.jsxs)(`h1`,{children:[`/`,t.name]}),Yi(t.source)]}),t.description&&(0,S.jsx)(`div`,{className:`know-intro skill-desc`,children:t.description}),(0,S.jsxs)(`div`,{className:`detail-cols`,children:[(0,S.jsxs)(`section`,{className:`panel`,children:[(0,S.jsxs)(`div`,{className:`panel-head`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`SKILL.md`}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsxs)(`div`,{className:`tabs`,children:[(0,S.jsx)(`button`,{className:a===`rendered`?`active`:``,onClick:()=>o(`rendered`),children:`rendered`}),(0,S.jsx)(`button`,{className:a===`source`?`active`:``,onClick:()=>o(`source`),children:`source`})]})]}),(0,S.jsx)(`div`,{className:`viewer-body`,children:a===`rendered`?(0,S.jsx)(`div`,{className:`md-body concept-md`,dangerouslySetInnerHTML:{__html:c}}):(0,S.jsx)(`pre`,{children:t.content.trim()||`(empty)`})})]}),(0,S.jsx)(`aside`,{className:`detail-rail`,children:(0,S.jsxs)(`section`,{className:`panel`,children:[(0,S.jsx)(`div`,{className:`panel-head`,children:(0,S.jsx)(`span`,{className:`microlabel`,children:`about`})}),(0,S.jsxs)(`div`,{className:`rail-list`,children:[(0,S.jsxs)(`div`,{className:`rail-kv`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`source`}),(0,S.jsx)(`span`,{className:`v`,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,S.jsxs)(`div`,{className:`rail-kv`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`path`}),(0,S.jsx)(`span`,{className:`v mono skill-path`,title:t.path,children:t.path})]}),(0,S.jsxs)(`div`,{className:`rail-kv`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`invoke`}),(0,S.jsxs)(`span`,{className:`v`,children:[(0,S.jsxs)(`code`,{children:[`/`,t.name]}),` in any session`]})]}),t.files.length>0&&(0,S.jsxs)(`div`,{className:`rail-kv`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`bundled files`}),t.files.map(e=>(0,S.jsx)(`span`,{className:`v mono`,children:e},e))]})]})]})})]})]}):(0,S.jsx)(`div`,{className:`empty`,children:`loading…`})}var $i=[``,`low`,`medium`,`high`,`xhigh`,`max`],ea=[`🤖`,`🧑‍💻`,`🎧`,`🛠️`,`📊`,`✍️`,`🔍`,`🧹`,`📦`,`🚀`];function ta({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===`chat`?e[2]:n===`chats`?e[1]:void 0,i=F(`/api/agents`,!1),a=N(),[o,s]=(0,v.useState)(()=>{try{let e=JSON.parse(localStorage.getItem(`kw-agent-groups`)??`[]`);return Array.isArray(e)?e.map(String):[]}catch{return[]}}),[c,l]=(0,v.useState)(!1),[u,d]=(0,v.useState)(``),[f,p]=(0,v.useState)(null),[m,h]=(0,v.useState)(``),[g,_]=(0,v.useState)(null),[y,b]=(0,v.useState)(null),[x,w]=(0,v.useState)({}),T=(i?.agents??[]).map(e=>x[e.slug]===void 0?e:{...e,group:x[e.slug]||void 0});(0,v.useEffect)(()=>{w(e=>{let t={...e},n=!1;for(let e of i?.agents??[])t[e.slug]!==void 0&&(e.group??``)===t[e.slug]&&(delete t[e.slug],n=!0);return n?t:e})},[i]);let E=T.filter(e=>!e.archived),D=T.filter(e=>e.archived),[O,ee]=(0,v.useState)(!1),te=[...new Set([...E.map(e=>e.group??``).filter(Boolean),...o])].sort((e,t)=>e.localeCompare(t)),ne=E.filter(e=>!e.group);function k(e){s(e);try{localStorage.setItem(`kw-agent-groups`,JSON.stringify(e))}catch{}}function re(){let e=u.trim();l(!1),d(``),e&&!te.includes(e)&&k([...o,e])}function ie(e,t){p(null);let n=t.trim();if(n&&n!==e){for(let t of T.filter(t=>t.group===e))j(t.slug,n);o.includes(e)&&k([...new Set(o.map(t=>t===e?n:t))])}}async function j(e,t){if((T.find(t=>t.slug===e)?.group??``)!==t){w(n=>({...n,[e]:t}));try{let n=await fetch(`/api/agents/${encodeURIComponent(e)}`);if(!n.ok)throw Error();let r=await n.json();if(!(await fetch(`/api/agents/${encodeURIComponent(e)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({...r,group:t||void 0})})).ok)throw Error()}catch{w(t=>{let n={...t};return delete n[e],n})}}}let M=e=>a?{onDragOver:t=>{g!=null&&(t.preventDefault(),t.dataTransfer.dropEffect=`move`,y!==e&&b(e))},onDrop:t=>{t.preventDefault();let n=t.dataTransfer.getData(`text/plain`)||g;n&&j(n,e),_(null),b(null)}}:{},ae=e=>(0,S.jsxs)(A,{href:`/agents/${encodeURIComponent(e.slug)}`,className:`side-row ${e.slug===t?`active`:``} ${g===e.slug?`dragging`:``}`,draggable:a,onDragStart:t=>{t.dataTransfer.setData(`text/plain`,e.slug),t.dataTransfer.effectAllowed=`move`,_(e.slug)},onDragEnd:()=>{_(null),b(null)},children:[(0,S.jsx)(`span`,{className:`agent-avatar sm`,children:(0,S.jsx)(`span`,{"aria-hidden":!0,children:e.emoji})}),(0,S.jsxs)(`div`,{className:`side-row-body`,children:[(0,S.jsx)(`div`,{className:`side-row-top`,children:(0,S.jsx)(`span`,{className:`side-wf`,children:e.name})}),(0,S.jsx)(`div`,{className:`side-row-sub`,children:(0,S.jsx)(`span`,{className:`side-req`,children:e.description||e.harness})})]})]},e.slug),oe=e=>(0,S.jsxs)(A,{href:`/agents/${encodeURIComponent(e.slug)}/info`,className:`side-row archived-row ${e.slug===t?`active`:``}`,children:[(0,S.jsx)(`span`,{className:`agent-avatar sm`,children:(0,S.jsx)(`span`,{"aria-hidden":!0,children:e.emoji})}),(0,S.jsxs)(`div`,{className:`side-row-body`,children:[(0,S.jsx)(`div`,{className:`side-row-top`,children:(0,S.jsx)(`span`,{className:`side-wf`,children:e.name})}),(0,S.jsx)(`div`,{className:`side-row-sub`,children:(0,S.jsx)(`span`,{className:`side-req`,children:e.description||e.harness})})]})]},e.slug),se;se=n===`new`?(0,S.jsx)(fa,{},`new`):n===`edit`&&t?(0,S.jsx)(fa,{slug:t},t):n===`chat`&&t&&r?(0,S.jsx)(`div`,{className:`chat-main`,children:(0,S.jsx)(qr,{id:r,agentName:T.find(e=>e.slug===t)?.name??t,agentDescription:T.find(e=>e.slug===t)?.description},r)}):n===`chats`?r?(0,S.jsx)(`div`,{className:`chat-main`,children:(0,S.jsx)(qr,{id:r},r)}):(0,S.jsx)(Kr,{}):n===`info`&&t?(0,S.jsx)(ca,{slug:t},t):t?(0,S.jsx)(ia,{slug:t},t):(0,S.jsx)(sa,{hasAgents:E.length>0,root:i?.root});let ce=(n===`agent`||n===`info`||n===`chat`)&&t?T.find(e=>e.slug===t)?.knowledge??[]:[],[P,le]=(0,v.useState)(()=>localStorage.getItem(`kw-kside`)!==`hidden`),[ue,de]=(0,v.useState)(()=>Number(localStorage.getItem(`kw-kside-w`))||460),fe=ce.length>0&&P;function pe(e){le(e),localStorage.setItem(`kw-kside`,e?`open`:`hidden`)}function me(e){de(e),localStorage.setItem(`kw-kside-w`,String(e))}return(0,S.jsxs)(`div`,{className:`runs-screen agents-screen ${t||n===`chats`?`has-sessions`:``} ${fe?`has-knowledge`:``}`,style:fe?{"--kside-w":`${ue}px`}:void 0,children:[(0,S.jsxs)(`aside`,{className:`runs-side`,children:[(0,S.jsxs)(`div`,{className:`side-head`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`agents`}),(0,S.jsx)(`span`,{className:`spacer`}),a&&(0,S.jsxs)(A,{href:`/agents/new`,className:`open-raw`,children:[(0,S.jsx)(C,{name:`add`,className:`ms-sm`}),` new`]})]}),(0,S.jsxs)(`div`,{className:`side-list`,children:[(0,S.jsxs)(A,{href:`/agents/chats`,className:`side-row side-general ${n===`chats`?`active`:``}`,children:[(0,S.jsx)(`span`,{className:`agent-avatar sm`,children:(0,S.jsx)(`span`,{"aria-hidden":!0,children:`💬`})}),(0,S.jsxs)(`div`,{className:`side-row-body`,children:[(0,S.jsx)(`div`,{className:`side-row-top`,children:(0,S.jsx)(`span`,{className:`side-wf`,children:`General Chats`})}),(0,S.jsx)(`div`,{className:`side-row-sub`,children:(0,S.jsx)(`span`,{className:`side-req`,children:`chats without an agent`})})]})]}),(0,S.jsxs)(`div`,{className:`side-group ${g&&y===``?`drop-over`:``}`,...M(``),children:[ne.map(ae),g!=null&&ne.length===0&&(0,S.jsx)(`div`,{className:`side-group-empty`,children:`no group — drop here`})]}),te.map(e=>{let t=E.filter(t=>t.group===e);return(0,S.jsxs)(`div`,{className:`side-group ${g&&y===e?`drop-over`:``}`,...M(e),children:[(0,S.jsxs)(`div`,{className:`side-group-head`,children:[f===e?(0,S.jsx)(`input`,{className:`side-group-rename`,autoFocus:!0,value:m,onChange:e=>h(e.target.value),onKeyDown:t=>{t.key===`Enter`&&ie(e,m),t.key===`Escape`&&p(null)},onBlur:()=>ie(e,m)}):(0,S.jsx)(`span`,{className:`microlabel`,children:e}),(0,S.jsx)(`span`,{className:`side-group-count num`,children:t.length}),(0,S.jsx)(`span`,{className:`spacer`}),a&&f!==e&&(0,S.jsx)(`button`,{className:`side-group-x`,title:`Rename group`,onClick:()=>{p(e),h(e)},children:(0,S.jsx)(C,{name:`edit`,className:`ms-sm`})}),a&&t.length===0&&o.includes(e)&&(0,S.jsx)(`button`,{className:`side-group-x`,title:`Remove empty group`,onClick:()=>k(o.filter(t=>t!==e)),children:(0,S.jsx)(C,{name:`close`,className:`ms-sm`})})]}),t.map(ae),t.length===0&&(0,S.jsx)(`div`,{className:`side-group-empty`,children:a?`drag agents here`:`no agents`})]},e)}),D.length>0&&(0,S.jsxs)(`div`,{className:`side-group side-archived`,children:[(0,S.jsxs)(`button`,{className:`side-archived-toggle`,"aria-expanded":O,onClick:()=>ee(e=>!e),children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`archived`}),(0,S.jsx)(`span`,{className:`side-group-count num`,children:D.length}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsx)(C,{name:O?`expand_less`:`expand_more`,className:`ms-sm`})]}),O&&D.map(oe)]}),i&&T.length===0&&(0,S.jsx)(`div`,{className:`viewer-note`,children:`no agents yet`}),a&&(c?(0,S.jsx)(`div`,{className:`side-group-new`,children:(0,S.jsx)(`input`,{autoFocus:!0,value:u,placeholder:`group name, e.g. Team Content`,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&re(),e.key===`Escape`&&(l(!1),d(``))},onBlur:re})}):(0,S.jsxs)(`button`,{className:`side-group-add`,onClick:()=>l(!0),children:[(0,S.jsx)(C,{name:`add`,className:`ms-sm`}),` group`]}))]})]}),t&&(0,S.jsx)(aa,{slug:t,chatId:r}),n===`chats`&&(0,S.jsx)(oa,{chatId:r}),(0,S.jsx)(`div`,{className:`runs-main`,children:se}),fe&&(0,S.jsx)(na,{bundles:ce,onHide:()=>pe(!1),onResize:me}),ce.length>0&&!P&&(0,S.jsxs)(`button`,{className:`kside-reopen`,onClick:()=>pe(!0),title:`Show knowledge sidebar`,children:[(0,S.jsx)(C,{name:`menu_book`,className:`ms-sm`}),` knowledge`]})]})}function na({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 fetch(`/api/knowledge/${encodeURIComponent(e)}`,{cache:`no-store`}),r=n.ok?await n.json():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 fetch(`/api/knowledge/${encodeURIComponent(t)}/concept?id=${encodeURIComponent(n)}`,{cache:`no-store`}),i=e.ok?await e.json():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(await fetch(`/api/knowledge/${encodeURIComponent(e)}/concept`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({id:t,content:p})})).json();r.error?y(r.error):(c(e=>({...e,[n]:r})),f(null))}catch(e){y(e.message)}g(!1)}return(0,S.jsxs)(`aside`,{className:`runs-side knowledge-side`,children:[(0,S.jsx)(`div`,{className:`kside-resizer`,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,S.jsxs)(`div`,{className:`side-head`,children:[(0,S.jsxs)(`span`,{className:`kside-headline`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`knowledge`}),(0,S.jsx)(`span`,{className:`kside-hint`,children:`read & kept current by this agent`})]}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsxs)(`button`,{className:`open-raw`,onClick:t,title:`Hide knowledge sidebar`,children:[`hide `,(0,S.jsx)(C,{name:`close`,className:`ms-sm`})]})]}),(0,S.jsx)(`div`,{className:`side-list`,children:e.map(e=>{let t=r[e],n=l[e]===!0;return(0,S.jsxs)(`div`,{className:`kside-bundle`,children:[(0,S.jsxs)(`div`,{className:`kside-bundle-head`,children:[(0,S.jsxs)(`button`,{className:`kside-bundle-toggle`,"aria-expanded":!n,onClick:()=>u({...l,[e]:!n}),children:[(0,S.jsx)(`span`,{className:`kside-chev ${n?``:`open`}`,"aria-hidden":!0,children:(0,S.jsx)(C,{name:`chevron_right`,className:`ms-sm`})}),(0,S.jsx)(`span`,{className:`kside-bundle-name`,children:e}),t&&(0,S.jsx)(`span`,{className:`kside-count num`,children:t.concepts.length})]}),(0,S.jsx)(`button`,{className:`kside-open`,title:`Export this bundle as PDF`,onClick:()=>void ji(e),children:(0,S.jsx)(C,{name:`picture_as_pdf`,className:`ms-sm`})}),(0,S.jsx)(A,{href:`/knowledge/${encodeURIComponent(e)}`,className:`kside-open`,title:`Open this bundle on the knowledge screen`,children:`↗`})]}),!n&&t===null&&(0,S.jsx)(`div`,{className:`viewer-note`,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,S.jsxs)(`div`,{className:`kside-concept ${r?`open`:``}`,children:[(0,S.jsxs)(`button`,{className:`kside-row`,"aria-expanded":r,title:t.description||void 0,onClick:()=>b(e,t.id),children:[(0,S.jsx)(`span`,{className:`kside-chev ${r?`open`:``}`,"aria-hidden":!0,children:(0,S.jsx)(C,{name:`chevron_right`,className:`ms-sm`})}),(0,S.jsx)(`span`,{className:`kside-title`,children:t.title||t.id}),t.stale&&(0,S.jsx)(`span`,{className:`kside-stale`,title:`Past its stale-after date — ask the agent to re-verify it`,children:`stale`})]}),r&&(0,S.jsx)(`div`,{className:`kside-card`,ref:e=>e?.scrollIntoView({block:`nearest`}),children:s[n]===void 0?(0,S.jsx)(`div`,{className:`viewer-note`,children:`loading…`}):s[n]===null?(0,S.jsx)(`div`,{className:`viewer-note`,children:`could not load concept`}):d===n?(0,S.jsxs)(`div`,{className:`kside-edit`,children:[(0,S.jsx)(`textarea`,{className:`concept-edit`,value:p,rows:Math.min(28,Math.max(10,p.split(`
206
+ `).length+2)),onChange:e=>m(e.target.value),spellCheck:!1}),(0,S.jsxs)(`div`,{className:`kside-actions`,children:[(0,S.jsx)(`button`,{className:`open-raw`,disabled:h,onClick:()=>f(null),children:`cancel`}),(0,S.jsx)(`button`,{className:`open-raw`,disabled:h,onClick:()=>x(e,t.id),children:h?`saving…`:(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(C,{name:`check`,className:`ms-sm`}),` save`]})})]}),_&&(0,S.jsxs)(`div`,{className:`msg error`,children:[(0,S.jsx)(C,{name:`error`,className:`ms-sm`}),` `,_]})]}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`div`,{className:`kside-card-bar`,children:[t.type&&(0,S.jsx)(`span`,{className:`kside-type`,children:t.type}),ra(t)&&(0,S.jsxs)(`span`,{className:`kside-updated num`,children:[`updated `,_e(ra(t))]}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsxs)(`button`,{className:`open-raw`,onClick:()=>{m(s[n].raw),f(n),y(``)},children:[(0,S.jsx)(C,{name:`edit`,className:`ms-sm`}),` edit`]}),(0,S.jsxs)(A,{href:Ii(e,t.id),className:`open-raw`,title:`Full-screen document editor with autosave`,children:[(0,S.jsx)(C,{name:`edit_document`,className:`ms-sm`}),` editor`]}),(0,S.jsx)(A,{href:i,className:`open-raw`,children:`open ↗`})]}),(0,S.jsx)(`div`,{className:`kside-md md-body`,dangerouslySetInnerHTML:{__html:kr.sanitize(z.parse(s[n].body??``,{async:!1}))}})]})})]},t.id)}),!n&&t&&t.concepts.length===0&&(0,S.jsx)(`div`,{className:`viewer-note`,children:`no concepts yet`})]},e)})})]})}function ra(e){return[e.generated?.at,...e.verified.map(e=>e.at)].filter(e=>typeof e==`string`&&e.length>0).sort().pop()}function ia({slug:e}){let[t,n]=(0,v.useState)(!1);return(0,v.useEffect)(()=>{let t=!0;return n(!1),fetch(`/api/chats`).then(e=>e.json()).then(r=>{if(!t)return;let i=r.chats.find(t=>t.scope.kind===`agent`&&t.scope.slug===e);i?k(`/agents/${encodeURIComponent(e)}/chat/${i.id}`,{replace:!0}):n(!0)}).catch(()=>t&&n(!0)),()=>{t=!1}},[e]),t?(0,S.jsx)(ca,{slug:e}):(0,S.jsx)(`div`,{className:`empty`,children:`loading…`})}function aa({slug:e,chatId:t}){let n=F(`/api/chats`,!1),r=(n?.chats??[]).filter(t=>t.scope.kind===`agent`&&t.scope.slug===e),[i,a]=(0,v.useState)(!1);return(0,S.jsxs)(`aside`,{className:`runs-side`,children:[(0,S.jsxs)(`div`,{className:`side-head`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`sessions`}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsx)(A,{href:`/agents/${encodeURIComponent(e)}/info`,className:`open-raw`,title:`agent profile & settings`,children:`profile`}),(0,S.jsx)(`button`,{className:`open-raw`,disabled:i,onClick:async()=>{a(!0),await Gr(`claude`,{kind:`agent`,slug:e}),a(!1)},children:i?`…`:(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(C,{name:`add`,className:`ms-sm`}),` new`]})})]}),(0,S.jsxs)(`div`,{className:`side-list`,children:[r.map(n=>(0,S.jsxs)(A,{href:`/agents/${encodeURIComponent(e)}/chat/${n.id}`,className:`side-row ${n.id===t?`active`:``}`,children:[(0,S.jsx)(`span`,{className:`lamp ${n.awaitingApproval?`blocked`:n.busy?`running`:`pending`}`,title:n.awaitingApproval?`waiting for your approval`:void 0}),(0,S.jsxs)(`div`,{className:`side-row-body`,children:[(0,S.jsx)(`div`,{className:`side-row-top`,children:(0,S.jsx)(`span`,{className:`side-wf`,children:n.title||`new session`})}),(0,S.jsx)(`div`,{className:`side-row-sub`,children:(0,S.jsx)(`span`,{className:`side-when num`,children:_e(n.updatedAt)})})]}),(0,S.jsx)(`button`,{type:`button`,className:`row-x`,title:`delete session`,onClick:async r=>{r.preventDefault(),r.stopPropagation(),window.confirm(`Delete session "${n.title||n.id}"?`)&&(await fetch(`/api/chats/${n.id}`,{method:`DELETE`}).catch(()=>{}),n.id===t&&k(`/agents/${encodeURIComponent(e)}`))},children:(0,S.jsx)(C,{name:`close`,className:`ms-sm`})})]},n.id)),n&&r.length===0&&(0,S.jsx)(`div`,{className:`viewer-note`,children:`no sessions yet`})]})]})}function oa({chatId:e}){let t=F(`/api/chats`,!1),n=(t?.chats??[]).filter(e=>e.scope.kind!==`agent`&&e.scope.kind!==`channel`);return(0,S.jsxs)(`aside`,{className:`runs-side`,children:[(0,S.jsxs)(`div`,{className:`side-head`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`chats`}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsxs)(A,{href:`/agents/chats`,className:`open-raw`,children:[(0,S.jsx)(C,{name:`add`,className:`ms-sm`}),` new`]})]}),(0,S.jsxs)(`div`,{className:`side-list`,children:[n.map(t=>(0,S.jsxs)(A,{href:`/agents/chats/${t.id}`,className:`side-row ${t.id===e?`active`:``}`,children:[(0,S.jsx)(`span`,{className:`lamp ${t.awaitingApproval?`blocked`:t.busy?`running`:`pending`}`,title:t.awaitingApproval?`waiting for your approval`:void 0}),(0,S.jsxs)(`div`,{className:`side-row-body`,children:[(0,S.jsx)(`div`,{className:`side-row-top`,children:(0,S.jsx)(`span`,{className:`side-wf`,children:t.title||`new chat`})}),(0,S.jsxs)(`div`,{className:`side-row-sub`,children:[(0,S.jsxs)(`span`,{className:`side-req`,children:[t.agent,t.scope.kind===`run`?` · ${t.scope.runId}`:t.scope.kind===`kraftwerk`?` · kraftwerk`:t.scope.kind===`knowledge`?` · knowledge${t.scope.bundle?`:${t.scope.bundle}`:``}`:``]}),(0,S.jsx)(`span`,{className:`side-when num`,children:_e(t.updatedAt)})]})]}),(0,S.jsx)(`button`,{type:`button`,className:`row-x`,title:`delete chat`,onClick:async n=>{n.preventDefault(),n.stopPropagation(),window.confirm(`Delete chat "${t.title||t.id}"?`)&&(await fetch(`/api/chats/${t.id}`,{method:`DELETE`}).catch(()=>{}),t.id===e&&k(`/agents/chats`))},children:(0,S.jsx)(C,{name:`close`,className:`ms-sm`})})]},t.id)),t&&n.length===0&&(0,S.jsx)(`div`,{className:`viewer-note`,children:`no chats yet`})]})]})}function sa({hasAgents:e,root:t}){let n=N();return(0,S.jsxs)(`div`,{className:`new-chat`,children:[(0,S.jsx)(`div`,{className:`page-head`,children:(0,S.jsx)(`h1`,{children:`agents`})}),(0,S.jsxs)(`section`,{className:`panel new-chat-panel`,children:[(0,S.jsx)(`div`,{className:`panel-head`,children:(0,S.jsx)(`span`,{className:`microlabel`,children:`what lives here`})}),(0,S.jsxs)(`div`,{className:`know-intro`,children:[`Your agents, set up like agents: each one has a name, a role (system prompt), a harness/model to run on, and the workflows that belong to its job. An agent lives in`,` `,(0,S.jsx)(`code`,{children:t?`${t}/<slug>/`:`agents/<slug>/`}),` as `,(0,S.jsx)(`code`,{children:`agent.yml`}),` +`,` `,(0,S.jsx)(`code`,{children:`system.md`}),` — git-tracked, so your team travels with the repo. Every session is a persistent conversation with that agent; it knows its connected workflows and knowledge bundles, runs the workflows for you, and keeps the knowledge current.`]}),n?(0,S.jsx)(`div`,{style:{padding:`0 16px 16px`},children:(0,S.jsx)(`button`,{className:`run-btn`,onClick:()=>k(`/agents/new`),children:(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(C,{name:`add`,className:`ms-sm`}),` `,e?`new agent`:`create your first agent`]})})}):(0,S.jsx)(`div`,{className:`settings-note`,style:{padding:`0 16px 16px`},children:`Creating agents needs expert mode — flip the switch in the top bar.`})]})]})}function ca({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)(!1),[l,u]=(0,v.useState)(``),[d,f]=(0,v.useState)(``),[p,m]=(0,v.useState)([]),[h,g]=(0,v.useState)(!0),[_,y]=(0,v.useState)(!1),[b,x]=(0,v.useState)(``),w=F(`/api/workflows`,!1),T=F(`/api/knowledge`,!1),E=F(`/api/skills`,!1);(0,v.useEffect)(()=>{let t=!0;return fetch(`/api/agents/${encodeURIComponent(e)}`).then(e=>e.ok?e.json():Promise.reject()).then(e=>t&&n(e)).catch(()=>t&&i(!0)),()=>{t=!1}},[e]);async function D(r){if(t){y(!0),x(``);try{let i=await(await fetch(`/api/agents/${encodeURIComponent(e)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({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,skills:t.skills,...r})})).json();i.error?x(i.error):(n(i),u(``))}catch(e){x(e.message)}y(!1)}}function O(e,t){m(t?[...p,e]:p.filter(t=>t!==e))}async function ee(t){y(!0),x(``);try{let r=await(await fetch(`/api/agents/${encodeURIComponent(e)}/archive`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({archived:t})})).json();r.error?x(r.error):n(r)}catch(e){x(e.message)}y(!1)}if(r)return(0,S.jsx)(`div`,{className:`empty`,children:`agent not found`});if(!t)return(0,S.jsx)(`div`,{className:`empty`,children:`loading…`});let te=e=>(0,S.jsxs)(`div`,{className:`agent-form-row`,style:{marginTop:8},children:[(0,S.jsx)(`button`,{className:`run-btn`,disabled:_,onClick:()=>void D(e),children:_?`saving…`:`save`}),(0,S.jsx)(`button`,{className:`open-raw`,disabled:_,onClick:()=>(u(``),x(``)),children:`cancel`})]});return(0,S.jsxs)(`div`,{className:`agent-view`,children:[(0,S.jsxs)(`div`,{className:`detail-head`,children:[(0,S.jsx)(`span`,{className:`agent-avatar lg`,children:(0,S.jsx)(`span`,{"aria-hidden":!0,children:t.emoji})}),(0,S.jsx)(`h1`,{children:t.name}),(0,S.jsx)(`span`,{className:`chip agent`,children:t.harness}),t.model&&(0,S.jsx)(`span`,{className:`chip`,children:t.model}),t.effort&&(0,S.jsxs)(`span`,{className:`chip`,children:[`effort: `,t.effort]}),t.archived&&(0,S.jsxs)(`span`,{className:`chip archived-chip`,children:[(0,S.jsx)(C,{name:`inventory_2`,className:`ms-sm`}),` archived`]}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsx)(A,{href:`/agents/${encodeURIComponent(e)}/edit`,className:`open-raw`,children:`edit`}),t.archived?(0,S.jsxs)(`button`,{className:`run-btn tonal`,disabled:_,onClick:()=>void ee(!1),children:[(0,S.jsx)(C,{name:`unarchive`,className:`ms-sm`}),` `,_?`…`:`unarchive`]}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`button`,{className:`open-raw`,disabled:_,title:`Hide this agent from the roster — restorable any time`,onClick:()=>void ee(!0),children:[(0,S.jsx)(C,{name:`archive`,className:`ms-sm`}),` archive`]}),(0,S.jsx)(`button`,{className:`run-btn`,disabled:a,onClick:async()=>{o(!0),await Gr(`claude`,{kind:`agent`,slug:e}),o(!1)},children:a?`starting…`:`new session`})]})]}),(0,S.jsxs)(`section`,{className:`panel`,children:[(0,S.jsxs)(`div`,{className:`m3-list`,children:[(0,S.jsxs)(`button`,{type:`button`,className:`m3-row m3-toggle`,onClick:()=>c(!s),children:[(0,S.jsx)(`span`,{className:`m3-ico`,children:(0,S.jsx)(C,{name:`badge`})}),(0,S.jsxs)(`span`,{className:`m3-body`,children:[(0,S.jsx)(`span`,{className:`m3-head`,children:`role`}),!s&&(0,S.jsx)(`span`,{className:`m3-sub m3-ellipsis`,children:(t.system||``).trim().split(`
207
207
  `)[0]||`empty — expand to give this agent a role`})]}),(0,S.jsx)(`span`,{className:`m3-chev ${s?`open`:``}`,children:(0,S.jsx)(C,{name:`expand_more`,className:`ms-sm`})})]}),s&&l!==`role`&&(0,S.jsxs)(`div`,{className:`m3-expand`,children:[(0,S.jsx)(`pre`,{children:t.system||`(empty — click edit to give this agent a role)`}),(0,S.jsxs)(`div`,{className:`agent-form-row`,style:{marginTop:10},children:[(0,S.jsxs)(`button`,{className:`open-raw`,onClick:()=>{f(t.system),u(`role`),x(``)},children:[(0,S.jsx)(C,{name:`edit`,className:`ms-sm`}),` edit role`]}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsxs)(`span`,{className:`m3-sub`,children:[`agents/`,t.slug,`/system.md`]})]})]}),s&&l===`role`&&(0,S.jsxs)(`div`,{className:`m3-expand`,children:[(0,S.jsx)(`textarea`,{className:`concept-edit`,rows:Math.min(24,Math.max(8,d.split(`
208
- `).length+2)),value:d,placeholder:`You are the ... for this project. Your job is ...`,onChange:e=>f(e.target.value),spellCheck:!1}),te({system:d})]}),(0,S.jsxs)(`div`,{className:`m3-row`,children:[(0,S.jsx)(`span`,{className:`m3-ico`,children:(0,S.jsx)(C,{name:`account_tree`})}),(0,S.jsxs)(`span`,{className:`m3-body`,children:[(0,S.jsx)(`span`,{className:`m3-head`,children:`workflows`}),l===`workflows`?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`div`,{className:`wf-checks`,children:[(w?.workflows??[]).map(e=>(0,S.jsxs)(`label`,{children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:p.includes(e.slug),onChange:t=>O(e.slug,t.target.checked)}),(0,S.jsx)(`b`,{children:e.slug}),e.description&&(0,S.jsxs)(`span`,{className:`opt-hint`,children:[` — `,e.description]})]},e.slug)),(w?.workflows??[]).length===0&&(0,S.jsx)(`div`,{className:`viewer-note`,children:`no workflows in this project`})]}),te({workflows:p})]}):t.workflows.length===0?(0,S.jsx)(`span`,{className:`m3-sub`,children:`none connected — the agent can run any workflow you connect`}):(0,S.jsx)(`span`,{className:`m3-chips`,children:t.workflows.map(e=>(0,S.jsx)(A,{href:`/workflows/${encodeURIComponent(e)}`,className:`chip`,children:e},e))})]}),l!==`workflows`&&(0,S.jsx)(`button`,{className:`open-raw`,onClick:()=>{m(t.workflows),u(`workflows`),x(``)},children:`edit`})]}),(0,S.jsxs)(`div`,{className:`m3-row`,children:[(0,S.jsx)(`span`,{className:`m3-ico`,children:(0,S.jsx)(C,{name:`menu_book`})}),(0,S.jsxs)(`span`,{className:`m3-body`,children:[(0,S.jsx)(`span`,{className:`m3-head`,children:`knowledge`}),l===`knowledge`?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`div`,{className:`wf-checks`,children:[(T?.bundles??[]).map(e=>(0,S.jsxs)(`label`,{children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:p.includes(e.name),onChange:t=>O(e.name,t.target.checked)}),(0,S.jsx)(`b`,{children:e.name}),(0,S.jsxs)(`span`,{className:`opt-hint`,children:[` — `,e.concepts,` concepts`]})]},e.name)),(T?.bundles??[]).length===0&&(0,S.jsx)(`div`,{className:`viewer-note`,children:`no knowledge bundles in this project`})]}),te({knowledge:p})]}):t.knowledge.length===0?(0,S.jsx)(`span`,{className:`m3-sub`,children:`none connected — connected bundles are read and kept current by the agent`}):(0,S.jsx)(`span`,{className:`m3-chips`,children:t.knowledge.map(e=>(0,S.jsx)(A,{href:`/knowledge/${encodeURIComponent(e)}`,className:`chip`,children:e},e))})]}),l!==`knowledge`&&(0,S.jsx)(`button`,{className:`open-raw`,onClick:()=>{m(t.knowledge),u(`knowledge`),x(``)},children:`edit`})]}),(0,S.jsxs)(`div`,{className:`m3-row`,children:[(0,S.jsx)(`span`,{className:`m3-ico`,children:(0,S.jsx)(C,{name:`extension`})}),(0,S.jsxs)(`span`,{className:`m3-body`,children:[(0,S.jsx)(`span`,{className:`m3-head`,children:`shared skills`}),l===`skills`?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`div`,{className:`wf-checks`,children:[(0,S.jsxs)(`label`,{children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:h,onChange:e=>g(e.target.checked)}),(0,S.jsx)(`b`,{children:`all skills`}),(0,S.jsx)(`span`,{className:`opt-hint`,children:` — every discovered skill, including future ones`})]}),!h&&(E?.skills??[]).map(e=>(0,S.jsxs)(`label`,{children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:p.includes(e.name),onChange:t=>O(e.name,t.target.checked)}),(0,S.jsxs)(`b`,{children:[`/`,e.name]}),e.description&&(0,S.jsxs)(`span`,{className:`opt-hint`,children:[` — `,e.description]})]},e.name)),!h&&(E?.skills??[]).length===0&&(0,S.jsx)(`div`,{className:`viewer-note`,children:`no skills found (.claude/skills, project or user)`})]}),te({skills:h?void 0:p})]}):t.skills===void 0?(0,S.jsx)(`span`,{className:`m3-sub`,children:`all discovered skills (default) — invoke with /name in a session`}):t.skills.length===0?(0,S.jsx)(`span`,{className:`m3-sub`,children:`none — this agent runs without skills`}):(0,S.jsx)(`span`,{className:`m3-chips`,children:t.skills.map(e=>(0,S.jsxs)(`span`,{className:`chip`,children:[`/`,e]},e))})]}),l!==`skills`&&(0,S.jsx)(`button`,{className:`open-raw`,onClick:()=>{g(t.skills===void 0),m(t.skills??[]),u(`skills`),x(``)},children:`edit`})]})]}),b&&(0,S.jsxs)(`div`,{className:`msg error`,children:[(0,S.jsx)(C,{name:`error`,className:`ms-sm`}),` `,b]})]}),(0,S.jsx)(ta,{slug:e}),(0,S.jsx)(na,{slug:e})]})}var ea=`---
208
+ `).length+2)),value:d,placeholder:`You are the ... for this project. Your job is ...`,onChange:e=>f(e.target.value),spellCheck:!1}),te({system:d})]}),(0,S.jsxs)(`div`,{className:`m3-row`,children:[(0,S.jsx)(`span`,{className:`m3-ico`,children:(0,S.jsx)(C,{name:`account_tree`})}),(0,S.jsxs)(`span`,{className:`m3-body`,children:[(0,S.jsx)(`span`,{className:`m3-head`,children:`workflows`}),l===`workflows`?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`div`,{className:`wf-checks`,children:[(w?.workflows??[]).map(e=>(0,S.jsxs)(`label`,{children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:p.includes(e.slug),onChange:t=>O(e.slug,t.target.checked)}),(0,S.jsx)(`b`,{children:e.slug}),e.description&&(0,S.jsxs)(`span`,{className:`opt-hint`,children:[` — `,e.description]})]},e.slug)),(w?.workflows??[]).length===0&&(0,S.jsx)(`div`,{className:`viewer-note`,children:`no workflows in this project`})]}),te({workflows:p})]}):t.workflows.length===0?(0,S.jsx)(`span`,{className:`m3-sub`,children:`none connected — the agent can run any workflow you connect`}):(0,S.jsx)(`span`,{className:`m3-chips`,children:t.workflows.map(e=>(0,S.jsx)(A,{href:`/workflows/${encodeURIComponent(e)}`,className:`chip`,children:e},e))})]}),l!==`workflows`&&(0,S.jsx)(`button`,{className:`open-raw`,onClick:()=>{m(t.workflows),u(`workflows`),x(``)},children:`edit`})]}),(0,S.jsxs)(`div`,{className:`m3-row`,children:[(0,S.jsx)(`span`,{className:`m3-ico`,children:(0,S.jsx)(C,{name:`menu_book`})}),(0,S.jsxs)(`span`,{className:`m3-body`,children:[(0,S.jsx)(`span`,{className:`m3-head`,children:`knowledge`}),l===`knowledge`?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`div`,{className:`wf-checks`,children:[(T?.bundles??[]).map(e=>(0,S.jsxs)(`label`,{children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:p.includes(e.name),onChange:t=>O(e.name,t.target.checked)}),(0,S.jsx)(`b`,{children:e.name}),(0,S.jsxs)(`span`,{className:`opt-hint`,children:[` — `,e.concepts,` concepts`]})]},e.name)),(T?.bundles??[]).length===0&&(0,S.jsx)(`div`,{className:`viewer-note`,children:`no knowledge bundles in this project`})]}),te({knowledge:p})]}):t.knowledge.length===0?(0,S.jsx)(`span`,{className:`m3-sub`,children:`none connected — connected bundles are read and kept current by the agent`}):(0,S.jsx)(`span`,{className:`m3-chips`,children:t.knowledge.map(e=>(0,S.jsx)(A,{href:`/knowledge/${encodeURIComponent(e)}`,className:`chip`,children:e},e))})]}),l!==`knowledge`&&(0,S.jsx)(`button`,{className:`open-raw`,onClick:()=>{m(t.knowledge),u(`knowledge`),x(``)},children:`edit`})]}),(0,S.jsxs)(`div`,{className:`m3-row`,children:[(0,S.jsx)(`span`,{className:`m3-ico`,children:(0,S.jsx)(C,{name:`extension`})}),(0,S.jsxs)(`span`,{className:`m3-body`,children:[(0,S.jsx)(`span`,{className:`m3-head`,children:`shared skills`}),l===`skills`?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`div`,{className:`wf-checks`,children:[(0,S.jsxs)(`label`,{children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:h,onChange:e=>g(e.target.checked)}),(0,S.jsx)(`b`,{children:`all skills`}),(0,S.jsx)(`span`,{className:`opt-hint`,children:` — every discovered skill, including future ones`})]}),!h&&(E?.skills??[]).map(e=>(0,S.jsxs)(`label`,{children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:p.includes(e.name),onChange:t=>O(e.name,t.target.checked)}),(0,S.jsxs)(`b`,{children:[`/`,e.name]}),e.description&&(0,S.jsxs)(`span`,{className:`opt-hint`,children:[` — `,e.description]})]},e.name)),!h&&(E?.skills??[]).length===0&&(0,S.jsx)(`div`,{className:`viewer-note`,children:`no skills found (.claude/skills, project or user)`})]}),te({skills:h?void 0:p})]}):t.skills===void 0?(0,S.jsx)(`span`,{className:`m3-sub`,children:`all discovered skills (default) — invoke with /name in a session`}):t.skills.length===0?(0,S.jsx)(`span`,{className:`m3-sub`,children:`none — this agent runs without skills`}):(0,S.jsx)(`span`,{className:`m3-chips`,children:t.skills.map(e=>(0,S.jsxs)(`span`,{className:`chip`,children:[`/`,e]},e))})]}),l!==`skills`&&(0,S.jsx)(`button`,{className:`open-raw`,onClick:()=>{g(t.skills===void 0),m(t.skills??[]),u(`skills`),x(``)},children:`edit`})]})]}),b&&(0,S.jsxs)(`div`,{className:`msg error`,children:[(0,S.jsx)(C,{name:`error`,className:`ms-sm`}),` `,b]})]}),(0,S.jsx)(ua,{slug:e}),(0,S.jsx)(da,{slug:e})]})}var la=`---
209
209
  description: What this skill is for (one line)
210
210
  ---
211
211
 
212
212
  Instructions this agent follows when the skill applies or is invoked with /<name>.
213
- `;function ta({slug:e}){let t=F(`/api/agents/${encodeURIComponent(e)}/skills`,!1)?.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 fetch(`/api/agents/${encodeURIComponent(e)}/skills/${encodeURIComponent(t)}`),i=await n.json().catch(()=>null);if(!n.ok||!i||i.error)return void s(i?.error??`could not load skill`);r({name:t,content:i.content??``,isNew:!1})}async function l(){if(!n)return;a(!0),s(``);let t=await(await fetch(`/api/agents/${encodeURIComponent(e)}/skills`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:n.name,content:n.content})})).json().catch(()=>({error:`save failed`}));a(!1),t.error?s(t.error):r(null)}async function u(t){window.confirm(`Delete skill "/${t}" of this agent (its folder is removed)?`)&&(await fetch(`/api/agents/${encodeURIComponent(e)}/skills/${encodeURIComponent(t)}`,{method:`DELETE`}).catch(()=>{}),n?.name===t&&r(null))}return(0,S.jsxs)(`section`,{className:`panel`,children:[(0,S.jsxs)(`div`,{className:`panel-head`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`own skills — only this agent`}),(0,S.jsx)(`span`,{className:`spacer`}),!n&&(0,S.jsxs)(`button`,{className:`open-raw`,onClick:()=>{r({name:``,content:ea,isNew:!0}),s(``)},children:[(0,S.jsx)(C,{name:`add`,className:`ms-sm`}),` new skill`]})]}),t.length===0&&!n&&(0,S.jsxs)(`div`,{className:`viewer-note`,children:[`none — skills in `,(0,S.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,S.jsx)(`div`,{className:`m3-list`,children:t.map(e=>(0,S.jsxs)(`div`,{className:`m3-row`,children:[(0,S.jsx)(`span`,{className:`m3-ico`,children:(0,S.jsx)(C,{name:`extension`})}),(0,S.jsxs)(`span`,{className:`m3-body`,children:[(0,S.jsxs)(`span`,{className:`m3-head`,children:[`/`,e.name]}),(0,S.jsx)(`span`,{className:`m3-sub`,children:e.description||(0,S.jsx)(`code`,{children:`SKILL.md`})})]}),(0,S.jsxs)(`button`,{className:`open-raw`,onClick:()=>void c(e.name),children:[(0,S.jsx)(C,{name:`edit`,className:`ms-sm`}),` edit`]}),(0,S.jsx)(`button`,{className:`open-raw`,onClick:()=>void u(e.name),children:(0,S.jsx)(C,{name:`close`,className:`ms-sm`})})]},e.name))}),n&&(0,S.jsxs)(`div`,{className:`agent-form`,children:[(0,S.jsx)(`div`,{className:`agent-form-row`,children:(0,S.jsxs)(`label`,{className:`agent-field`,style:{flex:1},children:[`name — invoked as /<name>`,(0,S.jsx)(`input`,{value:n.name,placeholder:`e.g. report-html`,disabled:!n.isNew,onChange:e=>r({...n,name:e.target.value})})]})}),(0,S.jsxs)(`label`,{className:`agent-field`,children:[`SKILL.md — frontmatter (description) + the instructions`,(0,S.jsx)(`textarea`,{className:`concept-edit`,rows:Math.min(28,Math.max(12,n.content.split(`
214
- `).length+2)),value:n.content,spellCheck:!1,onChange:e=>r({...n,content:e.target.value})})]}),(0,S.jsxs)(`div`,{className:`agent-form-row`,children:[(0,S.jsx)(`button`,{className:`run-btn`,disabled:i||!n.name.trim(),onClick:()=>void l(),children:i?`saving…`:`save`}),(0,S.jsx)(`button`,{className:`open-raw`,disabled:i,onClick:()=>r(null),children:`cancel`})]})]}),o&&(0,S.jsxs)(`div`,{className:`msg error`,children:[(0,S.jsx)(C,{name:`error`,className:`ms-sm`}),` `,o]})]})}function na({slug:e}){let t=F(`/api/agents/${encodeURIComponent(e)}/routines`,!1)?.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(await fetch(`/api/agents/${encodeURIComponent(e)}/routines`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(t)})).json();return!n.error||(a(n.error),!1)}async function l(t){s(t),a(``);let n=await(await fetch(`/api/agents/${encodeURIComponent(e)}/routines/${encodeURIComponent(t)}/run`,{method:`POST`})).json();s(``),n.error?a(n.error):n.chatId&&k(`/agents/${encodeURIComponent(e)}/chat/${n.chatId}`)}async function u(t){window.confirm(`Delete routine "${t}"?`)&&await fetch(`/api/agents/${encodeURIComponent(e)}/routines/${encodeURIComponent(t)}`,{method:`DELETE`}).catch(()=>{})}return(0,S.jsxs)(`section`,{className:`panel`,children:[(0,S.jsxs)(`div`,{className:`panel-head`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`routines — scheduled prompts`}),(0,S.jsx)(`span`,{className:`spacer`}),!n&&(0,S.jsxs)(`button`,{className:`open-raw`,onClick:()=>r({name:``,schedule:`0 9 * * 1-5`,prompt:``,enabled:!0}),children:[(0,S.jsx)(C,{name:`add`,className:`ms-sm`}),` new routine`]})]}),t.length===0&&!n&&(0,S.jsx)(`div`,{className:`viewer-note`,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,S.jsx)(`div`,{className:`m3-list`,children:t.map(t=>(0,S.jsxs)(`div`,{className:`m3-row`,children:[(0,S.jsx)(`span`,{className:`m3-ico`,children:(0,S.jsx)(C,{name:`schedule`})}),(0,S.jsxs)(`span`,{className:`m3-body`,children:[(0,S.jsxs)(`span`,{className:`m3-head`,children:[t.name,t.lastError&&(0,S.jsx)(`span`,{className:`chip stale`,title:t.lastError,children:`error`}),t.awaitingApproval&&t.lastChatId&&(0,S.jsx)(A,{href:`/agents/${encodeURIComponent(e)}/chat/${t.lastChatId}`,className:`chip attention`,title:`the last run asked for a permission nobody has answered yet`,children:`needs approval`})]}),(0,S.jsxs)(`span`,{className:`m3-sub`,children:[(0,S.jsx)(`code`,{children:t.schedule}),t.enabled?t.nextRunAt?` · next ${_e(t.nextRunAt)}`:``:` · paused`,` · `,t.lastChatId?(0,S.jsxs)(A,{href:`/agents/${encodeURIComponent(e)}/chat/${t.lastChatId}`,children:[`last run `,_e(t.lastRunAt)]}):`never ran`]})]}),(0,S.jsx)(`button`,{className:`open-raw`,disabled:o===t.id,onClick:()=>l(t.id),children:o===t.id?`starting…`:(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(C,{name:`play_arrow`,className:`ms-sm`}),` run`]})}),(0,S.jsx)(`button`,{className:`open-raw`,onClick:()=>r({id:t.id,name:t.name,schedule:t.schedule,prompt:t.prompt,enabled:t.enabled}),children:`edit`}),(0,S.jsx)(`button`,{className:`open-raw`,onClick:()=>void u(t.id),children:`delete`}),(0,S.jsxs)(`label`,{className:`m3-switch`,title:t.enabled?`enabled — click to pause`:`paused — click to enable`,children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:t.enabled,onChange:()=>void c({id:t.id,name:t.name,schedule:t.schedule,prompt:t.prompt,enabled:!t.enabled})}),(0,S.jsx)(`span`,{className:`m3-switch-track`})]})]},t.id))}),n&&(0,S.jsxs)(`div`,{className:`agent-form`,children:[(0,S.jsxs)(`div`,{className:`agent-form-row`,children:[(0,S.jsxs)(`label`,{className:`agent-field`,style:{flex:1},children:[`name`,(0,S.jsx)(`input`,{value:n.name,placeholder:`e.g. Morning report`,onChange:e=>r({...n,name:e.target.value})})]}),(0,S.jsxs)(`label`,{className:`agent-field`,style:{width:200},children:[`schedule (cron)`,(0,S.jsx)(`input`,{value:n.schedule,placeholder:`0 9 * * 1-5`,onChange:e=>r({...n,schedule:e.target.value})})]}),(0,S.jsxs)(`label`,{className:`agent-field wf-checks`,style:{width:90},children:[`enabled`,(0,S.jsxs)(`label`,{children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:n.enabled,onChange:e=>r({...n,enabled:e.target.checked})}),`on`]})]})]}),(0,S.jsxs)(`label`,{className:`agent-field`,children:[`prompt — what to ask this agent on each run`,(0,S.jsx)(`textarea`,{rows:5,value:n.prompt,placeholder:`Check ... and summarize what changed.`,onChange:e=>r({...n,prompt:e.target.value})})]}),(0,S.jsxs)(`div`,{className:`agent-form-row`,children:[(0,S.jsx)(`button`,{className:`run-btn`,disabled:!n.name.trim()||!n.prompt.trim(),onClick:async()=>{await c(n)&&r(null)},children:n.id?`save routine`:`create routine`}),(0,S.jsx)(`button`,{className:`open-raw`,onClick:()=>(r(null),a(``)),children:`cancel`})]})]}),i&&(0,S.jsxs)(`div`,{className:`msg error`,children:[(0,S.jsx)(C,{name:`error`,className:`ms-sm`}),` `,i]})]})}function ra({slug:e}){let[t,n]=(0,v.useState)(e?null:u()),[r,i]=(0,v.useState)(``),[a,o]=(0,v.useState)(!1),s=F(`/api/workflows`,!1)?.workflows??[],c=F(`/api/knowledge`,!1)?.bundles??[],l=F(`/api/skills`,!1)?.skills??[];(0,v.useEffect)(()=>{e&&fetch(`/api/agents/${encodeURIComponent(e)}`).then(e=>e.ok?e.json():Promise.reject()).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??[],skillsAll:e.skills===void 0,skills:e.skills??[]})).catch(()=>i(`agent not found`))},[e]);function u(){return{name:``,emoji:`🤖`,description:``,harness:`claude`,model:``,effort:``,group:``,system:``,workflows:[],knowledge:[],skillsAll:!0,skills:[]}}async function d(){if(!t)return;o(!0),i(``);let n=await(await fetch(e?`/api/agents/${encodeURIComponent(e)}`:`/api/agents`,{method:e?`PUT`:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({...t,skills:t.skillsAll?void 0:t.skills})})).json();o(!1),n.error?i(n.error):k(`/agents/${encodeURIComponent(n.slug)}/info`)}async function f(){e&&window.confirm(`Delete agent "${e}" and its definition folder?`)&&(await fetch(`/api/agents/${encodeURIComponent(e)}`,{method:`DELETE`}).catch(()=>{}),k(`/agents`))}if(!t)return(0,S.jsx)(`div`,{className:`empty`,children:r||`loading…`});let p=e=>n({...t,...e});return(0,S.jsxs)(`div`,{className:`new-chat`,children:[(0,S.jsx)(`div`,{className:`page-head`,children:(0,S.jsx)(`h1`,{children:e?`edit ${e}`:`new agent`})}),(0,S.jsx)(`section`,{className:`panel new-chat-panel`,children:(0,S.jsxs)(`div`,{className:`agent-form`,children:[(0,S.jsxs)(`div`,{className:`agent-form-row`,children:[(0,S.jsxs)(`label`,{className:`agent-field`,style:{flex:1},children:[`name`,(0,S.jsx)(`input`,{value:t.name,placeholder:`e.g. Max`,onChange:e=>p({name:e.target.value})})]}),(0,S.jsxs)(`label`,{className:`agent-field`,style:{width:90},children:[`emoji`,(0,S.jsx)(`input`,{value:t.emoji,onChange:e=>p({emoji:e.target.value})})]})]}),(0,S.jsx)(`div`,{className:`emoji-pick`,children:Gi.map(e=>(0,S.jsx)(`button`,{type:`button`,className:t.emoji===e?`active`:``,onClick:()=>p({emoji:e}),children:e},e))}),(0,S.jsxs)(`div`,{className:`agent-form-row`,children:[(0,S.jsxs)(`label`,{className:`agent-field`,style:{flex:1},children:[`description`,(0,S.jsx)(`input`,{value:t.description,placeholder:`one line: what this agent is for`,onChange:e=>p({description:e.target.value})})]}),(0,S.jsxs)(`label`,{className:`agent-field`,style:{width:180},children:[`group`,(0,S.jsx)(`input`,{value:t.group,placeholder:`none`,onChange:e=>p({group:e.target.value})})]})]}),(0,S.jsxs)(`div`,{className:`agent-form-row`,children:[(0,S.jsxs)(`label`,{className:`agent-field`,style:{width:140},children:[`harness`,(0,S.jsxs)(`select`,{value:t.harness,onChange:e=>p({harness:e.target.value}),children:[(0,S.jsx)(`option`,{value:`claude`,children:`claude`}),(0,S.jsx)(`option`,{value:`codex`,children:`codex`}),(0,S.jsx)(`option`,{value:`pi`,children:`pi`})]})]}),(0,S.jsxs)(`label`,{className:`agent-field`,style:{flex:1},children:[`model`,(0,S.jsx)(`input`,{value:t.model,placeholder:`harness default — e.g. sonnet, gpt-5.6-sol`,onChange:e=>p({model:e.target.value})})]}),(0,S.jsxs)(`label`,{className:`agent-field`,style:{width:140},children:[`effort`,(0,S.jsx)(`select`,{value:t.effort,onChange:e=>p({effort:e.target.value}),children:Wi.map(e=>(0,S.jsx)(`option`,{value:e,children:e||`default`},e))})]})]}),(0,S.jsxs)(`label`,{className:`agent-field`,children:[`system prompt — the agent's role`,(0,S.jsx)(`textarea`,{rows:10,value:t.system,placeholder:`You are the ... for this project. Your job is ...`,onChange:e=>p({system:e.target.value})})]}),(0,S.jsxs)(`div`,{className:`agent-field`,children:[(0,S.jsx)(`span`,{className:`agent-field-label`,children:`connected workflows — autoloaded into the agent's context; it can run them`}),(0,S.jsxs)(`div`,{className:`wf-checks`,children:[s.map(e=>(0,S.jsxs)(`label`,{children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:t.workflows.includes(e.slug),onChange:n=>p({workflows:n.target.checked?[...t.workflows,e.slug]:t.workflows.filter(t=>t!==e.slug)})}),(0,S.jsx)(`b`,{children:e.slug}),e.description&&(0,S.jsxs)(`span`,{className:`opt-hint`,children:[` — `,e.description]})]},e.slug)),s.length===0&&(0,S.jsx)(`div`,{className:`viewer-note`,children:`no workflows in this project`})]})]}),(0,S.jsxs)(`div`,{className:`agent-field`,children:[(0,S.jsx)(`span`,{className:`agent-field-label`,children:`connected knowledge — OKF bundles the agent consults and maintains`}),(0,S.jsxs)(`div`,{className:`wf-checks`,children:[c.map(e=>(0,S.jsxs)(`label`,{children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:t.knowledge.includes(e.name),onChange:n=>p({knowledge:n.target.checked?[...t.knowledge,e.name]:t.knowledge.filter(t=>t!==e.name)})}),(0,S.jsx)(`b`,{children:e.name}),(0,S.jsxs)(`span`,{className:`opt-hint`,children:[` — `,e.concepts,` concepts`]})]},e.name)),c.length===0&&(0,S.jsx)(`div`,{className:`viewer-note`,children:`no knowledge bundles in this project`})]})]}),(0,S.jsxs)(`div`,{className:`agent-field`,children:[(0,S.jsx)(`span`,{className:`agent-field-label`,children:`connected skills — workspace skill packages (see the skills tab); invoked with /name in sessions`}),(0,S.jsxs)(`div`,{className:`wf-checks`,children:[(0,S.jsxs)(`label`,{children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:t.skillsAll,onChange:e=>p({skillsAll:e.target.checked})}),(0,S.jsx)(`b`,{children:`all skills`}),(0,S.jsx)(`span`,{className:`opt-hint`,children:` — every discovered skill, including future ones`})]}),!t.skillsAll&&l.map(e=>(0,S.jsxs)(`label`,{children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:t.skills.includes(e.name),onChange:n=>p({skills:n.target.checked?[...t.skills,e.name]:t.skills.filter(t=>t!==e.name)})}),(0,S.jsxs)(`b`,{children:[`/`,e.name]}),e.description&&(0,S.jsxs)(`span`,{className:`opt-hint`,children:[` — `,e.description]})]},e.name)),!t.skillsAll&&l.length===0&&(0,S.jsx)(`div`,{className:`viewer-note`,children:`no skills found (.claude/skills, project or user)`})]})]}),r&&(0,S.jsxs)(`div`,{className:`msg error`,children:[(0,S.jsx)(C,{name:`error`,className:`ms-sm`}),` `,r]}),(0,S.jsxs)(`div`,{className:`agent-form-row`,children:[(0,S.jsx)(`button`,{className:`run-btn`,disabled:!t.name.trim()||a,onClick:d,children:a?`saving…`:e?`save`:`create`}),(0,S.jsx)(`span`,{className:`spacer`}),e&&(0,S.jsx)(`button`,{className:`stop-btn`,onClick:f,children:`delete agent`})]})]})})]})}var ia={enabled:!1,remote:`origin`,branch:``,interval:`300`,autosync:`pull`};function aa(e){let t=e.config.git;return t?{enabled:t.enabled!==!1,remote:t.remote??ia.remote,branch:t.branch??``,interval:String(t.interval??ia.interval),autosync:t.autosync??ia.autosync}:ia}var oa={enabled:!1,root:``};function sa(e){let t=e.config.repos;return t?{enabled:t.enabled!==!1,root:t.root??``}:oa}function ca(e){let t=e.config.vibeables;return t?{enabled:t.enabled!==!1,root:t.root??``}:oa}function la(){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)(ia),[f,p]=(0,v.useState)(oa),[m,h]=(0,v.useState)(oa),[g,_]=(0,v.useState)(!1),[y,b]=(0,v.useState)(!1),[x,w]=(0,v.useState)(!1),[T,E]=(0,v.useState)(``);(0,v.useEffect)(()=>{fetch(`/api/settings`).then(e=>e.json()).then(e=>{t(e),r(e.config.name??``),a(e.config.icon??``),s(e.config.color??``),l(e.config.switcher??[]),d(aa(e)),p(sa(e)),h(ca(e))}).catch(()=>E(`could not load settings`))},[]);let D=()=>{_(!0),w(!1),E(``)};async function O(){b(!0),E(``);try{let e=await fetch(`/api/settings`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({name:n,icon:i,color:o,switcher:c,git:{...u,interval:u.interval===``?void 0:Number(u.interval)},repos:f,vibeables:m})}),r=await e.json();if(!e.ok)throw Error(r.error||`save failed`);t(r),l(r.config.switcher??[]),d(aa(r)),p(sa(r)),h(ca(r)),_(!1),w(!0),window.dispatchEvent(new Event(`kw-meta-refresh`))}catch(e){E(e.message)}finally{b(!1)}}let ee=(e,t)=>{l(n=>n.map((n,r)=>r===e?{...n,...t}:n)),D()},te=e=>{d(t=>({...t,...e})),D()},ne=e=>{p(t=>({...t,...e})),D()},k=e=>{h(t=>({...t,...e})),D()};if(!e)return(0,S.jsx)(`div`,{className:`empty`,children:T||`loading…`});let re=[[`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,S.jsxs)(`div`,{className:`settings-screen`,children:[(0,S.jsxs)(`div`,{className:`settings-head`,children:[(0,S.jsxs)(`h1`,{children:[(0,S.jsx)(C,{name:`settings`,className:`ms-lg`}),` Settings`]}),(0,S.jsx)(`span`,{className:`spacer`}),T&&(0,S.jsx)(`span`,{className:`settings-err`,children:T}),x&&!g&&(0,S.jsxs)(`span`,{className:`settings-saved`,children:[(0,S.jsx)(C,{name:`check`,className:`ms-sm`}),` saved`]}),(0,S.jsx)(`button`,{className:`run-btn`,disabled:y||!g,onClick:()=>void O(),children:y?`saving…`:`save changes`})]}),(0,S.jsxs)(`section`,{className:`panel`,children:[(0,S.jsx)(`div`,{className:`panel-head`,children:(0,S.jsx)(`span`,{className:`microlabel`,children:`workspace`})}),(0,S.jsxs)(`div`,{className:`agent-form`,children:[(0,S.jsxs)(`div`,{className:`agent-form-row`,children:[(0,S.jsxs)(`label`,{className:`agent-field`,style:{width:90},children:[`icon`,(0,S.jsx)(`input`,{value:i,placeholder:`🤖`,onChange:e=>{a(e.target.value),D()}})]}),(0,S.jsxs)(`label`,{className:`agent-field`,style:{flex:1},children:[`name`,(0,S.jsx)(`input`,{value:n,placeholder:`my workspace`,onChange:e=>{r(e.target.value),D()}})]}),(0,S.jsxs)(`label`,{className:`agent-field settings-color`,style:{width:130},title:`Accent in the workspace switcher; empty = derived from the folder`,children:[`color`,(0,S.jsxs)(`span`,{className:`settings-color-row`,children:[(0,S.jsx)(`input`,{type:`color`,value:/^#[0-9a-f]{6}$/i.test(o)?o:`#888888`,onChange:e=>{s(e.target.value),D()}}),(0,S.jsx)(`input`,{value:o,placeholder:`auto`,onChange:e=>{s(e.target.value),D()}})]})]})]}),(0,S.jsx)(`div`,{className:`settings-note`,children:`Shown in the header, browser tab and to other workspaces discovering this one.`})]})]}),(0,S.jsxs)(`section`,{className:`panel`,children:[(0,S.jsxs)(`div`,{className:`panel-head`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`workspace switcher`}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsxs)(`button`,{className:`run-btn tonal`,onClick:()=>{l(e=>[...e,{name:``,url:`http://localhost:`}]),D()},children:[(0,S.jsx)(C,{name:`add`,className:`ms-sm`}),` add entry`]})]}),(0,S.jsxs)(`div`,{className:`agent-form`,children:[c.length===0&&(0,S.jsx)(`div`,{className:`settings-note`,children:`No manual entries.`}),c.map((e,t)=>(0,S.jsxs)(`div`,{className:`agent-form-row`,children:[(0,S.jsxs)(`label`,{className:`agent-field`,style:{width:70},children:[`icon`,(0,S.jsx)(`input`,{value:e.icon??``,placeholder:`•`,onChange:e=>ee(t,{icon:e.target.value})})]}),(0,S.jsxs)(`label`,{className:`agent-field`,style:{flex:1},children:[`name`,(0,S.jsx)(`input`,{value:e.name,placeholder:`other workspace`,onChange:e=>ee(t,{name:e.target.value})})]}),(0,S.jsxs)(`label`,{className:`agent-field`,style:{flex:1.4},children:[`url`,(0,S.jsx)(`input`,{value:e.url,placeholder:`http://localhost:1982`,onChange:e=>ee(t,{url:e.target.value})})]}),(0,S.jsx)(`button`,{className:`row-x settings-row-x`,title:`remove entry`,onClick:()=>{l(e=>e.filter((e,n)=>n!==t)),D()},children:(0,S.jsx)(C,{name:`close`,className:`ms-sm`})})]},t)),(0,S.jsx)(`div`,{className:`settings-note`,children:`Running workspaces on this machine are discovered automatically — manual entries are for remote instances or extra links.`})]})]}),(0,S.jsxs)(`section`,{className:`panel`,children:[(0,S.jsxs)(`div`,{className:`panel-head`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`git sync`}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsxs)(`a`,{className:`run-btn tonal`,href:`#/git`,children:[(0,S.jsx)(C,{name:`account_tree`,className:`ms-sm`}),` open git`]})]}),(0,S.jsxs)(`div`,{className:`agent-form`,children:[(0,S.jsxs)(`label`,{className:`settings-check`,children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:u.enabled,onChange:e=>te({enabled:e.target.checked})}),`sync workflows, knowledge, agents and skills with a git remote`]}),u.enabled&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`div`,{className:`agent-form-row`,children:[(0,S.jsxs)(`label`,{className:`agent-field`,style:{flex:1},children:[`remote`,(0,S.jsx)(`input`,{value:u.remote,placeholder:`origin`,onChange:e=>te({remote:e.target.value})})]}),(0,S.jsxs)(`label`,{className:`agent-field`,style:{flex:1},children:[`branch`,(0,S.jsx)(`input`,{value:u.branch,placeholder:`checked-out branch`,onChange:e=>te({branch:e.target.value})})]}),(0,S.jsxs)(`label`,{className:`agent-field`,style:{width:120},children:[`interval (s)`,(0,S.jsx)(`input`,{type:`number`,min:0,step:1,value:u.interval,placeholder:`300`,onChange:e=>te({interval:e.target.value})})]}),(0,S.jsxs)(`label`,{className:`agent-field`,style:{width:150},children:[`autosync`,(0,S.jsxs)(`select`,{value:u.autosync,onChange:e=>te({autosync:e.target.value}),children:[(0,S.jsx)(`option`,{value:`pull`,children:`fetch and pull`}),(0,S.jsx)(`option`,{value:`off`,children:`fetch only`})]})]})]}),(0,S.jsx)(`div`,{className:`settings-note`,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,S.jsxs)(`section`,{className:`panel`,children:[(0,S.jsxs)(`div`,{className:`panel-head`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`repositories`}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsxs)(`a`,{className:`run-btn tonal`,href:`#/repos`,children:[(0,S.jsx)(C,{name:`source`,className:`ms-sm`}),` open repositories`]})]}),(0,S.jsxs)(`div`,{className:`agent-form`,children:[(0,S.jsxs)(`label`,{className:`settings-check`,children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:f.enabled,onChange:e=>ne({enabled:e.target.checked})}),`keep git repositories the agents work on under one folder`]}),f.enabled&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`div`,{className:`agent-form-row`,children:(0,S.jsxs)(`label`,{className:`agent-field`,style:{flex:1},children:[`repos root`,(0,S.jsx)(`input`,{value:f.root,placeholder:`repos`,onChange:e=>ne({root:e.target.value})})]})}),(0,S.jsxs)(`div`,{className:`settings-note`,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,S.jsx)(`code`,{children:`kraftwerk repos add`}),`.`]})]})]})]}),(0,S.jsxs)(`section`,{className:`panel`,children:[(0,S.jsxs)(`div`,{className:`panel-head`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`vibeables`}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsxs)(`a`,{className:`run-btn tonal`,href:`#/vibeables`,children:[(0,S.jsx)(C,{name:`web`,className:`ms-sm`}),` open vibeables`]})]}),(0,S.jsxs)(`div`,{className:`agent-form`,children:[(0,S.jsxs)(`label`,{className:`settings-check`,children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:m.enabled,onChange:e=>k({enabled:e.target.checked})}),`build small apps live in a chat, with a preview pane next to the thread`]}),m.enabled&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`div`,{className:`agent-form-row`,children:(0,S.jsxs)(`label`,{className:`agent-field`,style:{flex:1},children:[`vibeables root`,(0,S.jsx)(`input`,{value:m.root,placeholder:`kraftwerk-data/vibeables`,onChange:e=>k({root:e.target.value})})]})}),(0,S.jsxs)(`div`,{className:`settings-note`,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,S.jsx)(`b`,{children:`vibeable`}),` button; the agent then works inside the app folder.`]})]})]})]}),(0,S.jsxs)(`section`,{className:`panel`,children:[(0,S.jsxs)(`div`,{className:`panel-head`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`paths & port`}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsx)(`code`,{className:`settings-file`,title:e.configPath,children:e.exists?e.configPath:`${e.configPath} (not created yet)`})]}),(0,S.jsx)(`div`,{className:`settings-kv-list`,children:re.map(([e,t,n])=>(0,S.jsxs)(`div`,{className:`settings-kv`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:e}),(0,S.jsx)(`code`,{children:t}),(0,S.jsx)(`span`,{className:`settings-kv-hint`,children:n})]},e))}),(0,S.jsxs)(`div`,{className:`settings-note`,style:{padding:`0 18px 14px`},children:[`Read-only here — edit `,(0,S.jsx)(`code`,{children:`kraftwerk.yml`}),` directly to change these.`]})]})]})}var ua={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`}};function da(){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 fetch(`/api/projects`,{cache:`no-store`});if(e.ok){t(await e.json()),r(``);return}r(e.status===404?`This workspace runs a kraftwerk without the projects API. Update it and restart its UI.`:`Could not load the project 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 pe(`/api/projects/${t}`,n);if(!r.ok)throw Error(r.error||`failed`);window.dispatchEvent(new Event(`kw-meta-refresh`))}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,S.jsxs)(`div`,{className:`settings-screen ws-screen`,children:[(0,S.jsxs)(`div`,{className:`settings-head`,children:[(0,S.jsxs)(`h1`,{children:[(0,S.jsx)(C,{name:`hub`,className:`ms-lg`}),` Workspaces`]}),(0,S.jsx)(`span`,{className:`spacer`}),e&&(0,S.jsxs)(`span`,{className:`settings-note`,children:[e.length,` known · `,p,` running`]}),e&&n&&(0,S.jsx)(`span`,{className:`settings-err`,children:n})]}),(0,S.jsxs)(`section`,{className:`panel`,children:[(0,S.jsxs)(`div`,{className:`panel-head`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`projects on this machine`}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsxs)(`span`,{className:`settings-note`,children:[`registry: `,(0,S.jsx)(`code`,{children:`~/.kraftwerk/projects`})]})]}),!e&&!n&&(0,S.jsx)(`div`,{className:`ws-empty`,children:`loading…`}),!e&&n&&(0,S.jsxs)(`div`,{className:`ws-empty ws-load-error`,children:[(0,S.jsx)(C,{name:`error`,className:`ms-sm`}),` `,n]}),e&&e.length===0&&(0,S.jsx)(`div`,{className:`ws-empty`,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);return(0,S.jsxs)(`div`,{className:`ws-row state-${e.state} ${e.current?`current`:``}`,children:[(0,S.jsx)(fe,{className:`ws-icon`,icon:e.icon,name:e.name,color:e.color,seed:e.root??e.url,ambiguous:h(e.icon)}),(0,S.jsxs)(`div`,{className:`ws-main`,children:[(0,S.jsxs)(`div`,{className:`ws-title`,children:[e.live&&!e.current?(0,S.jsx)(`a`,{href:e.url,className:`ws-name${e.named===!1?` unnamed`:``}`,children:e.name}):(0,S.jsx)(`span`,{className:`ws-name${e.named===!1?` unnamed`:``}`,children:e.name}),e.current&&(0,S.jsx)(`span`,{className:`switcher-hint`,children:`current`}),(0,S.jsxs)(`span`,{className:`ws-state ws-state-${e.state}`,children:[e.live&&(0,S.jsx)(`span`,{className:`live-dot`}),ua[e.state].label]}),ua[e.state].note&&(0,S.jsx)(`span`,{className:`ws-note`,children:ua[e.state].note})]}),(0,S.jsx)(`div`,{className:`ws-root`,title:e.root,children:e.rootLabel??(0,S.jsx)(`span`,{className:`ws-dim`,children:`no root recorded (started by an older version)`})}),(0,S.jsxs)(`div`,{className:`ws-meta`,children:[e.state!==`missing`&&e.state!==`orphaned`&&(0,S.jsx)(`span`,{children:e.url.replace(/^https?:\/\//,``)}),e.counts&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`span`,{children:[e.counts.agents,` agents`]}),(0,S.jsxs)(`span`,{children:[e.counts.workflows,` workflows`]}),(0,S.jsxs)(`span`,{children:[e.counts.runs,` runs`]}),(0,S.jsxs)(`span`,{children:[e.counts.chats,` chats`]})]}),e.lastStarted&&(0,S.jsxs)(`span`,{title:e.lastStarted,children:[`started `,ve(e.lastStarted)]}),!e.live&&e.lastStopped&&(0,S.jsxs)(`span`,{title:e.lastStopped,children:[`stopped `,ve(e.lastStopped)]}),e.startCount!=null&&(0,S.jsxs)(`span`,{children:[e.startCount,`× launched`]}),e.firstSeen&&(0,S.jsxs)(`span`,{title:e.firstSeen,children:[`first seen `,ve(e.firstSeen)]})]}),o[t]&&(0,S.jsx)(`div`,{className:`settings-err`,children:o[t]})]}),(0,S.jsxs)(`div`,{className:`ws-actions`,children:[e.live&&!e.current&&(0,S.jsxs)(`a`,{className:`ws-btn`,href:e.url,title:`Open this workspace`,children:[(0,S.jsx)(C,{name:`open_in_new`,className:`ms-sm`}),` open`]}),!e.live&&e.root&&e.exists!==!1&&!e.dirGone&&(0,S.jsxs)(`button`,{className:`ws-btn primary`,disabled:!!n,onClick:()=>void f(e,`start`),children:[(0,S.jsx)(C,{name:n===`start`?`progress_activity`:`play_arrow`,className:`ms-sm`}),n===`start`?`starting…`:`start`]}),e.live&&!e.current&&(0,S.jsxs)(`button`,{className:`ws-btn danger`,disabled:!!n,onClick:()=>void f(e,`stop`),children:[(0,S.jsx)(C,{name:n===`stop`?`progress_activity`:`stop`,className:`ms-sm`}),n===`stop`?`stopping…`:`stop`]}),r&&c!==t&&(0,S.jsxs)(`button`,{className:`ws-btn`,disabled:!!n,title:`Drop this project from the registry (files untouched)`,onClick:()=>l(t),children:[(0,S.jsx)(C,{name:`delete`,className:`ms-sm`}),` remove`]}),r&&c===t&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`button`,{className:`ws-btn danger`,onClick:()=>void f(e,`forget`),children:[(0,S.jsx)(C,{name:`delete`,className:`ms-sm`}),` confirm remove`]}),(0,S.jsx)(`button`,{className:`ws-btn`,onClick:()=>l(null),children:`cancel`})]})]})]},t)})]}),(0,S.jsxs)(`p`,{className:`settings-note`,children:[`Start launches `,(0,S.jsx)(`code`,{children:`kraftwerk ui`}),` detached in the project root (log in `,(0,S.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,S.jsx)(`code`,{children:`kraftwerk.yml`}),` — the same from the terminal:`,` `,(0,S.jsx)(`code`,{children:`kraftwerk projects`}),`.`]})]})}function fa(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 pa=[[/^(\+\+\+|---|diff |index )/,`d-meta`],[/^@@/,`d-hunk`],[/^\+/,`d-add`],[/^-/,`d-del`]],ma=e=>pa.find(([t])=>t.test(e))?.[1]??``;function ha({file:e}){let[t,n]=(0,v.useState)(null),[r,i]=(0,v.useState)(!1),[a,o]=(0,v.useState)(``);return(0,v.useEffect)(()=>{let t=!0;return fetch(`/api/git/diff?path=${encodeURIComponent(e)}`).then(e=>e.json()).then(e=>{t&&(n(e.diff??``),i(!!e.truncated),o(e.error??``))}).catch(()=>t&&o(`could not load the diff`)),()=>{t=!1}},[e]),a?(0,S.jsx)(`div`,{className:`git-diff git-diff-error`,children:a}):t===null?(0,S.jsx)(`div`,{className:`git-diff`,children:`loading…`}):t.trim()?(0,S.jsxs)(`pre`,{className:`git-diff`,children:[t.split(`
215
- `).map((e,t)=>(0,S.jsxs)(`span`,{className:ma(e),children:[e||` `,`
213
+ `;function ua({slug:e}){let t=F(`/api/agents/${encodeURIComponent(e)}/skills`,!1)?.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 fetch(`/api/agents/${encodeURIComponent(e)}/skills/${encodeURIComponent(t)}`),i=await n.json().catch(()=>null);if(!n.ok||!i||i.error)return void s(i?.error??`could not load skill`);r({name:t,content:i.content??``,isNew:!1})}async function l(){if(!n)return;a(!0),s(``);let t=await(await fetch(`/api/agents/${encodeURIComponent(e)}/skills`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:n.name,content:n.content})})).json().catch(()=>({error:`save failed`}));a(!1),t.error?s(t.error):r(null)}async function u(t){window.confirm(`Delete skill "/${t}" of this agent (its folder is removed)?`)&&(await fetch(`/api/agents/${encodeURIComponent(e)}/skills/${encodeURIComponent(t)}`,{method:`DELETE`}).catch(()=>{}),n?.name===t&&r(null))}return(0,S.jsxs)(`section`,{className:`panel`,children:[(0,S.jsxs)(`div`,{className:`panel-head`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`own skills — only this agent`}),(0,S.jsx)(`span`,{className:`spacer`}),!n&&(0,S.jsxs)(`button`,{className:`open-raw`,onClick:()=>{r({name:``,content:la,isNew:!0}),s(``)},children:[(0,S.jsx)(C,{name:`add`,className:`ms-sm`}),` new skill`]})]}),t.length===0&&!n&&(0,S.jsxs)(`div`,{className:`viewer-note`,children:[`none — skills in `,(0,S.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,S.jsx)(`div`,{className:`m3-list`,children:t.map(e=>(0,S.jsxs)(`div`,{className:`m3-row`,children:[(0,S.jsx)(`span`,{className:`m3-ico`,children:(0,S.jsx)(C,{name:`extension`})}),(0,S.jsxs)(`span`,{className:`m3-body`,children:[(0,S.jsxs)(`span`,{className:`m3-head`,children:[`/`,e.name]}),(0,S.jsx)(`span`,{className:`m3-sub`,children:e.description||(0,S.jsx)(`code`,{children:`SKILL.md`})})]}),(0,S.jsxs)(`button`,{className:`open-raw`,onClick:()=>void c(e.name),children:[(0,S.jsx)(C,{name:`edit`,className:`ms-sm`}),` edit`]}),(0,S.jsx)(`button`,{className:`open-raw`,onClick:()=>void u(e.name),children:(0,S.jsx)(C,{name:`close`,className:`ms-sm`})})]},e.name))}),n&&(0,S.jsxs)(`div`,{className:`agent-form`,children:[(0,S.jsx)(`div`,{className:`agent-form-row`,children:(0,S.jsxs)(`label`,{className:`agent-field`,style:{flex:1},children:[`name — invoked as /<name>`,(0,S.jsx)(`input`,{value:n.name,placeholder:`e.g. report-html`,disabled:!n.isNew,onChange:e=>r({...n,name:e.target.value})})]})}),(0,S.jsxs)(`label`,{className:`agent-field`,children:[`SKILL.md — frontmatter (description) + the instructions`,(0,S.jsx)(`textarea`,{className:`concept-edit`,rows:Math.min(28,Math.max(12,n.content.split(`
214
+ `).length+2)),value:n.content,spellCheck:!1,onChange:e=>r({...n,content:e.target.value})})]}),(0,S.jsxs)(`div`,{className:`agent-form-row`,children:[(0,S.jsx)(`button`,{className:`run-btn`,disabled:i||!n.name.trim(),onClick:()=>void l(),children:i?`saving…`:`save`}),(0,S.jsx)(`button`,{className:`open-raw`,disabled:i,onClick:()=>r(null),children:`cancel`})]})]}),o&&(0,S.jsxs)(`div`,{className:`msg error`,children:[(0,S.jsx)(C,{name:`error`,className:`ms-sm`}),` `,o]})]})}function da({slug:e}){let t=F(`/api/agents/${encodeURIComponent(e)}/routines`,!1)?.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(await fetch(`/api/agents/${encodeURIComponent(e)}/routines`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(t)})).json();return!n.error||(a(n.error),!1)}async function l(t){s(t),a(``);let n=await(await fetch(`/api/agents/${encodeURIComponent(e)}/routines/${encodeURIComponent(t)}/run`,{method:`POST`})).json();s(``),n.error?a(n.error):n.chatId&&k(`/agents/${encodeURIComponent(e)}/chat/${n.chatId}`)}async function u(t){window.confirm(`Delete routine "${t}"?`)&&await fetch(`/api/agents/${encodeURIComponent(e)}/routines/${encodeURIComponent(t)}`,{method:`DELETE`}).catch(()=>{})}return(0,S.jsxs)(`section`,{className:`panel`,children:[(0,S.jsxs)(`div`,{className:`panel-head`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`routines — scheduled prompts`}),(0,S.jsx)(`span`,{className:`spacer`}),!n&&(0,S.jsxs)(`button`,{className:`open-raw`,onClick:()=>r({name:``,schedule:`0 9 * * 1-5`,prompt:``,enabled:!0}),children:[(0,S.jsx)(C,{name:`add`,className:`ms-sm`}),` new routine`]})]}),t.length===0&&!n&&(0,S.jsx)(`div`,{className:`viewer-note`,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,S.jsx)(`div`,{className:`m3-list`,children:t.map(t=>(0,S.jsxs)(`div`,{className:`m3-row`,children:[(0,S.jsx)(`span`,{className:`m3-ico`,children:(0,S.jsx)(C,{name:`schedule`})}),(0,S.jsxs)(`span`,{className:`m3-body`,children:[(0,S.jsxs)(`span`,{className:`m3-head`,children:[t.name,t.lastError&&(0,S.jsx)(`span`,{className:`chip stale`,title:t.lastError,children:`error`}),t.awaitingApproval&&t.lastChatId&&(0,S.jsx)(A,{href:`/agents/${encodeURIComponent(e)}/chat/${t.lastChatId}`,className:`chip attention`,title:`the last run asked for a permission nobody has answered yet`,children:`needs approval`})]}),(0,S.jsxs)(`span`,{className:`m3-sub`,children:[(0,S.jsx)(`code`,{children:t.schedule}),t.enabled?t.nextRunAt?` · next ${_e(t.nextRunAt)}`:``:` · paused`,` · `,t.lastChatId?(0,S.jsxs)(A,{href:`/agents/${encodeURIComponent(e)}/chat/${t.lastChatId}`,children:[`last run `,_e(t.lastRunAt)]}):`never ran`]})]}),(0,S.jsx)(`button`,{className:`open-raw`,disabled:o===t.id,onClick:()=>l(t.id),children:o===t.id?`starting…`:(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(C,{name:`play_arrow`,className:`ms-sm`}),` run`]})}),(0,S.jsx)(`button`,{className:`open-raw`,onClick:()=>r({id:t.id,name:t.name,schedule:t.schedule,prompt:t.prompt,enabled:t.enabled}),children:`edit`}),(0,S.jsx)(`button`,{className:`open-raw`,onClick:()=>void u(t.id),children:`delete`}),(0,S.jsxs)(`label`,{className:`m3-switch`,title:t.enabled?`enabled — click to pause`:`paused — click to enable`,children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:t.enabled,onChange:()=>void c({id:t.id,name:t.name,schedule:t.schedule,prompt:t.prompt,enabled:!t.enabled})}),(0,S.jsx)(`span`,{className:`m3-switch-track`})]})]},t.id))}),n&&(0,S.jsxs)(`div`,{className:`agent-form`,children:[(0,S.jsxs)(`div`,{className:`agent-form-row`,children:[(0,S.jsxs)(`label`,{className:`agent-field`,style:{flex:1},children:[`name`,(0,S.jsx)(`input`,{value:n.name,placeholder:`e.g. Morning report`,onChange:e=>r({...n,name:e.target.value})})]}),(0,S.jsxs)(`label`,{className:`agent-field`,style:{width:200},children:[`schedule (cron)`,(0,S.jsx)(`input`,{value:n.schedule,placeholder:`0 9 * * 1-5`,onChange:e=>r({...n,schedule:e.target.value})})]}),(0,S.jsxs)(`label`,{className:`agent-field wf-checks`,style:{width:90},children:[`enabled`,(0,S.jsxs)(`label`,{children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:n.enabled,onChange:e=>r({...n,enabled:e.target.checked})}),`on`]})]})]}),(0,S.jsxs)(`label`,{className:`agent-field`,children:[`prompt — what to ask this agent on each run`,(0,S.jsx)(`textarea`,{rows:5,value:n.prompt,placeholder:`Check ... and summarize what changed.`,onChange:e=>r({...n,prompt:e.target.value})})]}),(0,S.jsxs)(`div`,{className:`agent-form-row`,children:[(0,S.jsx)(`button`,{className:`run-btn`,disabled:!n.name.trim()||!n.prompt.trim(),onClick:async()=>{await c(n)&&r(null)},children:n.id?`save routine`:`create routine`}),(0,S.jsx)(`button`,{className:`open-raw`,onClick:()=>(r(null),a(``)),children:`cancel`})]})]}),i&&(0,S.jsxs)(`div`,{className:`msg error`,children:[(0,S.jsx)(C,{name:`error`,className:`ms-sm`}),` `,i]})]})}function fa({slug:e}){let[t,n]=(0,v.useState)(e?null:u()),[r,i]=(0,v.useState)(``),[a,o]=(0,v.useState)(!1),s=F(`/api/workflows`,!1)?.workflows??[],c=F(`/api/knowledge`,!1)?.bundles??[],l=F(`/api/skills`,!1)?.skills??[];(0,v.useEffect)(()=>{e&&fetch(`/api/agents/${encodeURIComponent(e)}`).then(e=>e.ok?e.json():Promise.reject()).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??[],skillsAll:e.skills===void 0,skills:e.skills??[]})).catch(()=>i(`agent not found`))},[e]);function u(){return{name:``,emoji:`🤖`,description:``,harness:`claude`,model:``,effort:``,group:``,system:``,workflows:[],knowledge:[],skillsAll:!0,skills:[]}}async function d(){if(!t)return;o(!0),i(``);let n=await(await fetch(e?`/api/agents/${encodeURIComponent(e)}`:`/api/agents`,{method:e?`PUT`:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({...t,skills:t.skillsAll?void 0:t.skills})})).json();o(!1),n.error?i(n.error):k(`/agents/${encodeURIComponent(n.slug)}/info`)}async function f(){e&&window.confirm(`Delete agent "${e}" and its definition folder?`)&&(await fetch(`/api/agents/${encodeURIComponent(e)}`,{method:`DELETE`}).catch(()=>{}),k(`/agents`))}if(!t)return(0,S.jsx)(`div`,{className:`empty`,children:r||`loading…`});let p=e=>n({...t,...e});return(0,S.jsxs)(`div`,{className:`new-chat`,children:[(0,S.jsx)(`div`,{className:`page-head`,children:(0,S.jsx)(`h1`,{children:e?`edit ${e}`:`new agent`})}),(0,S.jsx)(`section`,{className:`panel new-chat-panel`,children:(0,S.jsxs)(`div`,{className:`agent-form`,children:[(0,S.jsxs)(`div`,{className:`agent-form-row`,children:[(0,S.jsxs)(`label`,{className:`agent-field`,style:{flex:1},children:[`name`,(0,S.jsx)(`input`,{value:t.name,placeholder:`e.g. Max`,onChange:e=>p({name:e.target.value})})]}),(0,S.jsxs)(`label`,{className:`agent-field`,style:{width:90},children:[`emoji`,(0,S.jsx)(`input`,{value:t.emoji,onChange:e=>p({emoji:e.target.value})})]})]}),(0,S.jsx)(`div`,{className:`emoji-pick`,children:ea.map(e=>(0,S.jsx)(`button`,{type:`button`,className:t.emoji===e?`active`:``,onClick:()=>p({emoji:e}),children:e},e))}),(0,S.jsxs)(`div`,{className:`agent-form-row`,children:[(0,S.jsxs)(`label`,{className:`agent-field`,style:{flex:1},children:[`description`,(0,S.jsx)(`input`,{value:t.description,placeholder:`one line: what this agent is for`,onChange:e=>p({description:e.target.value})})]}),(0,S.jsxs)(`label`,{className:`agent-field`,style:{width:180},children:[`group`,(0,S.jsx)(`input`,{value:t.group,placeholder:`none`,onChange:e=>p({group:e.target.value})})]})]}),(0,S.jsxs)(`div`,{className:`agent-form-row`,children:[(0,S.jsxs)(`label`,{className:`agent-field`,style:{width:140},children:[`harness`,(0,S.jsxs)(`select`,{value:t.harness,onChange:e=>p({harness:e.target.value}),children:[(0,S.jsx)(`option`,{value:`claude`,children:`claude`}),(0,S.jsx)(`option`,{value:`codex`,children:`codex`}),(0,S.jsx)(`option`,{value:`pi`,children:`pi`})]})]}),(0,S.jsxs)(`label`,{className:`agent-field`,style:{flex:1},children:[`model`,(0,S.jsx)(`input`,{value:t.model,placeholder:`harness default — e.g. sonnet, gpt-5.6-sol`,onChange:e=>p({model:e.target.value})})]}),(0,S.jsxs)(`label`,{className:`agent-field`,style:{width:140},children:[`effort`,(0,S.jsx)(`select`,{value:t.effort,onChange:e=>p({effort:e.target.value}),children:$i.map(e=>(0,S.jsx)(`option`,{value:e,children:e||`default`},e))})]})]}),(0,S.jsxs)(`label`,{className:`agent-field`,children:[`system prompt — the agent's role`,(0,S.jsx)(`textarea`,{rows:10,value:t.system,placeholder:`You are the ... for this project. Your job is ...`,onChange:e=>p({system:e.target.value})})]}),(0,S.jsxs)(`div`,{className:`agent-field`,children:[(0,S.jsx)(`span`,{className:`agent-field-label`,children:`connected workflows — autoloaded into the agent's context; it can run them`}),(0,S.jsxs)(`div`,{className:`wf-checks`,children:[s.map(e=>(0,S.jsxs)(`label`,{children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:t.workflows.includes(e.slug),onChange:n=>p({workflows:n.target.checked?[...t.workflows,e.slug]:t.workflows.filter(t=>t!==e.slug)})}),(0,S.jsx)(`b`,{children:e.slug}),e.description&&(0,S.jsxs)(`span`,{className:`opt-hint`,children:[` — `,e.description]})]},e.slug)),s.length===0&&(0,S.jsx)(`div`,{className:`viewer-note`,children:`no workflows in this project`})]})]}),(0,S.jsxs)(`div`,{className:`agent-field`,children:[(0,S.jsx)(`span`,{className:`agent-field-label`,children:`connected knowledge — OKF bundles the agent consults and maintains`}),(0,S.jsxs)(`div`,{className:`wf-checks`,children:[c.map(e=>(0,S.jsxs)(`label`,{children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:t.knowledge.includes(e.name),onChange:n=>p({knowledge:n.target.checked?[...t.knowledge,e.name]:t.knowledge.filter(t=>t!==e.name)})}),(0,S.jsx)(`b`,{children:e.name}),(0,S.jsxs)(`span`,{className:`opt-hint`,children:[` — `,e.concepts,` concepts`]})]},e.name)),c.length===0&&(0,S.jsx)(`div`,{className:`viewer-note`,children:`no knowledge bundles in this project`})]})]}),(0,S.jsxs)(`div`,{className:`agent-field`,children:[(0,S.jsx)(`span`,{className:`agent-field-label`,children:`connected skills — workspace skill packages (see the skills tab); invoked with /name in sessions`}),(0,S.jsxs)(`div`,{className:`wf-checks`,children:[(0,S.jsxs)(`label`,{children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:t.skillsAll,onChange:e=>p({skillsAll:e.target.checked})}),(0,S.jsx)(`b`,{children:`all skills`}),(0,S.jsx)(`span`,{className:`opt-hint`,children:` — every discovered skill, including future ones`})]}),!t.skillsAll&&l.map(e=>(0,S.jsxs)(`label`,{children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:t.skills.includes(e.name),onChange:n=>p({skills:n.target.checked?[...t.skills,e.name]:t.skills.filter(t=>t!==e.name)})}),(0,S.jsxs)(`b`,{children:[`/`,e.name]}),e.description&&(0,S.jsxs)(`span`,{className:`opt-hint`,children:[` — `,e.description]})]},e.name)),!t.skillsAll&&l.length===0&&(0,S.jsx)(`div`,{className:`viewer-note`,children:`no skills found (.claude/skills, project or user)`})]})]}),r&&(0,S.jsxs)(`div`,{className:`msg error`,children:[(0,S.jsx)(C,{name:`error`,className:`ms-sm`}),` `,r]}),(0,S.jsxs)(`div`,{className:`agent-form-row`,children:[(0,S.jsx)(`button`,{className:`run-btn`,disabled:!t.name.trim()||a,onClick:d,children:a?`saving…`:e?`save`:`create`}),(0,S.jsx)(`span`,{className:`spacer`}),e&&(0,S.jsx)(`button`,{className:`stop-btn`,onClick:f,children:`delete agent`})]})]})})]})}var pa={enabled:!1,remote:`origin`,branch:``,interval:`300`,autosync:`pull`};function ma(e){let t=e.config.git;return t?{enabled:t.enabled!==!1,remote:t.remote??pa.remote,branch:t.branch??``,interval:String(t.interval??pa.interval),autosync:t.autosync??pa.autosync}:pa}var ha={enabled:!1,root:``};function ga(e){let t=e.config.repos;return t?{enabled:t.enabled!==!1,root:t.root??``}:ha}function _a(e){let t=e.config.vibeables;return t?{enabled:t.enabled!==!1,root:t.root??``}:ha}function va(){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)(pa),[f,p]=(0,v.useState)(ha),[m,h]=(0,v.useState)(ha),[g,_]=(0,v.useState)(!1),[y,b]=(0,v.useState)(!1),[x,w]=(0,v.useState)(!1),[T,E]=(0,v.useState)(``);(0,v.useEffect)(()=>{fetch(`/api/settings`).then(e=>e.json()).then(e=>{t(e),r(e.config.name??``),a(e.config.icon??``),s(e.config.color??``),l(e.config.switcher??[]),d(ma(e)),p(ga(e)),h(_a(e))}).catch(()=>E(`could not load settings`))},[]);let D=()=>{_(!0),w(!1),E(``)};async function O(){b(!0),E(``);try{let e=await fetch(`/api/settings`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({name:n,icon:i,color:o,switcher:c,git:{...u,interval:u.interval===``?void 0:Number(u.interval)},repos:f,vibeables:m})}),r=await e.json();if(!e.ok)throw Error(r.error||`save failed`);t(r),l(r.config.switcher??[]),d(ma(r)),p(ga(r)),h(_a(r)),_(!1),w(!0),window.dispatchEvent(new Event(`kw-meta-refresh`))}catch(e){E(e.message)}finally{b(!1)}}let ee=(e,t)=>{l(n=>n.map((n,r)=>r===e?{...n,...t}:n)),D()},te=e=>{d(t=>({...t,...e})),D()},ne=e=>{p(t=>({...t,...e})),D()},k=e=>{h(t=>({...t,...e})),D()};if(!e)return(0,S.jsx)(`div`,{className:`empty`,children:T||`loading…`});let re=[[`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,S.jsxs)(`div`,{className:`settings-screen`,children:[(0,S.jsxs)(`div`,{className:`settings-head`,children:[(0,S.jsxs)(`h1`,{children:[(0,S.jsx)(C,{name:`settings`,className:`ms-lg`}),` Settings`]}),(0,S.jsx)(`span`,{className:`spacer`}),T&&(0,S.jsx)(`span`,{className:`settings-err`,children:T}),x&&!g&&(0,S.jsxs)(`span`,{className:`settings-saved`,children:[(0,S.jsx)(C,{name:`check`,className:`ms-sm`}),` saved`]}),(0,S.jsx)(`button`,{className:`run-btn`,disabled:y||!g,onClick:()=>void O(),children:y?`saving…`:`save changes`})]}),(0,S.jsxs)(`section`,{className:`panel`,children:[(0,S.jsx)(`div`,{className:`panel-head`,children:(0,S.jsx)(`span`,{className:`microlabel`,children:`workspace`})}),(0,S.jsxs)(`div`,{className:`agent-form`,children:[(0,S.jsxs)(`div`,{className:`agent-form-row`,children:[(0,S.jsxs)(`label`,{className:`agent-field`,style:{width:90},children:[`icon`,(0,S.jsx)(`input`,{value:i,placeholder:`🤖`,onChange:e=>{a(e.target.value),D()}})]}),(0,S.jsxs)(`label`,{className:`agent-field`,style:{flex:1},children:[`name`,(0,S.jsx)(`input`,{value:n,placeholder:`my workspace`,onChange:e=>{r(e.target.value),D()}})]}),(0,S.jsxs)(`label`,{className:`agent-field settings-color`,style:{width:130},title:`Accent in the workspace switcher; empty = derived from the folder`,children:[`color`,(0,S.jsxs)(`span`,{className:`settings-color-row`,children:[(0,S.jsx)(`input`,{type:`color`,value:/^#[0-9a-f]{6}$/i.test(o)?o:`#888888`,onChange:e=>{s(e.target.value),D()}}),(0,S.jsx)(`input`,{value:o,placeholder:`auto`,onChange:e=>{s(e.target.value),D()}})]})]})]}),(0,S.jsx)(`div`,{className:`settings-note`,children:`Shown in the header, browser tab and to other workspaces discovering this one.`})]})]}),(0,S.jsxs)(`section`,{className:`panel`,children:[(0,S.jsxs)(`div`,{className:`panel-head`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`workspace switcher`}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsxs)(`button`,{className:`run-btn tonal`,onClick:()=>{l(e=>[...e,{name:``,url:`http://localhost:`}]),D()},children:[(0,S.jsx)(C,{name:`add`,className:`ms-sm`}),` add entry`]})]}),(0,S.jsxs)(`div`,{className:`agent-form`,children:[c.length===0&&(0,S.jsx)(`div`,{className:`settings-note`,children:`No manual entries.`}),c.map((e,t)=>(0,S.jsxs)(`div`,{className:`agent-form-row`,children:[(0,S.jsxs)(`label`,{className:`agent-field`,style:{width:70},children:[`icon`,(0,S.jsx)(`input`,{value:e.icon??``,placeholder:`•`,onChange:e=>ee(t,{icon:e.target.value})})]}),(0,S.jsxs)(`label`,{className:`agent-field`,style:{flex:1},children:[`name`,(0,S.jsx)(`input`,{value:e.name,placeholder:`other workspace`,onChange:e=>ee(t,{name:e.target.value})})]}),(0,S.jsxs)(`label`,{className:`agent-field`,style:{flex:1.4},children:[`url`,(0,S.jsx)(`input`,{value:e.url,placeholder:`http://localhost:1982`,onChange:e=>ee(t,{url:e.target.value})})]}),(0,S.jsx)(`button`,{className:`row-x settings-row-x`,title:`remove entry`,onClick:()=>{l(e=>e.filter((e,n)=>n!==t)),D()},children:(0,S.jsx)(C,{name:`close`,className:`ms-sm`})})]},t)),(0,S.jsx)(`div`,{className:`settings-note`,children:`Running workspaces on this machine are discovered automatically — manual entries are for remote instances or extra links.`})]})]}),(0,S.jsxs)(`section`,{className:`panel`,children:[(0,S.jsxs)(`div`,{className:`panel-head`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`git sync`}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsxs)(`a`,{className:`run-btn tonal`,href:`#/git`,children:[(0,S.jsx)(C,{name:`account_tree`,className:`ms-sm`}),` open git`]})]}),(0,S.jsxs)(`div`,{className:`agent-form`,children:[(0,S.jsxs)(`label`,{className:`settings-check`,children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:u.enabled,onChange:e=>te({enabled:e.target.checked})}),`sync workflows, knowledge, agents and skills with a git remote`]}),u.enabled&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`div`,{className:`agent-form-row`,children:[(0,S.jsxs)(`label`,{className:`agent-field`,style:{flex:1},children:[`remote`,(0,S.jsx)(`input`,{value:u.remote,placeholder:`origin`,onChange:e=>te({remote:e.target.value})})]}),(0,S.jsxs)(`label`,{className:`agent-field`,style:{flex:1},children:[`branch`,(0,S.jsx)(`input`,{value:u.branch,placeholder:`checked-out branch`,onChange:e=>te({branch:e.target.value})})]}),(0,S.jsxs)(`label`,{className:`agent-field`,style:{width:120},children:[`interval (s)`,(0,S.jsx)(`input`,{type:`number`,min:0,step:1,value:u.interval,placeholder:`300`,onChange:e=>te({interval:e.target.value})})]}),(0,S.jsxs)(`label`,{className:`agent-field`,style:{width:150},children:[`autosync`,(0,S.jsxs)(`select`,{value:u.autosync,onChange:e=>te({autosync:e.target.value}),children:[(0,S.jsx)(`option`,{value:`pull`,children:`fetch and pull`}),(0,S.jsx)(`option`,{value:`off`,children:`fetch only`})]})]})]}),(0,S.jsx)(`div`,{className:`settings-note`,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,S.jsxs)(`section`,{className:`panel`,children:[(0,S.jsxs)(`div`,{className:`panel-head`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`repositories`}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsxs)(`a`,{className:`run-btn tonal`,href:`#/repos`,children:[(0,S.jsx)(C,{name:`source`,className:`ms-sm`}),` open repositories`]})]}),(0,S.jsxs)(`div`,{className:`agent-form`,children:[(0,S.jsxs)(`label`,{className:`settings-check`,children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:f.enabled,onChange:e=>ne({enabled:e.target.checked})}),`keep git repositories the agents work on under one folder`]}),f.enabled&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`div`,{className:`agent-form-row`,children:(0,S.jsxs)(`label`,{className:`agent-field`,style:{flex:1},children:[`repos root`,(0,S.jsx)(`input`,{value:f.root,placeholder:`repos`,onChange:e=>ne({root:e.target.value})})]})}),(0,S.jsxs)(`div`,{className:`settings-note`,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,S.jsx)(`code`,{children:`kraftwerk repos add`}),`.`]})]})]})]}),(0,S.jsxs)(`section`,{className:`panel`,children:[(0,S.jsxs)(`div`,{className:`panel-head`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`vibeables`}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsxs)(`a`,{className:`run-btn tonal`,href:`#/vibeables`,children:[(0,S.jsx)(C,{name:`web`,className:`ms-sm`}),` open vibeables`]})]}),(0,S.jsxs)(`div`,{className:`agent-form`,children:[(0,S.jsxs)(`label`,{className:`settings-check`,children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:m.enabled,onChange:e=>k({enabled:e.target.checked})}),`build small apps live in a chat, with a preview pane next to the thread`]}),m.enabled&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`div`,{className:`agent-form-row`,children:(0,S.jsxs)(`label`,{className:`agent-field`,style:{flex:1},children:[`vibeables root`,(0,S.jsx)(`input`,{value:m.root,placeholder:`kraftwerk-data/vibeables`,onChange:e=>k({root:e.target.value})})]})}),(0,S.jsxs)(`div`,{className:`settings-note`,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,S.jsx)(`b`,{children:`vibeable`}),` button; the agent then works inside the app folder.`]})]})]})]}),(0,S.jsxs)(`section`,{className:`panel`,children:[(0,S.jsxs)(`div`,{className:`panel-head`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`paths & port`}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsx)(`code`,{className:`settings-file`,title:e.configPath,children:e.exists?e.configPath:`${e.configPath} (not created yet)`})]}),(0,S.jsx)(`div`,{className:`settings-kv-list`,children:re.map(([e,t,n])=>(0,S.jsxs)(`div`,{className:`settings-kv`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:e}),(0,S.jsx)(`code`,{children:t}),(0,S.jsx)(`span`,{className:`settings-kv-hint`,children:n})]},e))}),(0,S.jsxs)(`div`,{className:`settings-note`,style:{padding:`0 18px 14px`},children:[`Read-only here — edit `,(0,S.jsx)(`code`,{children:`kraftwerk.yml`}),` directly to change these.`]})]})]})}var ya={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`}};function ba(){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 fetch(`/api/projects`,{cache:`no-store`});if(e.ok){t(await e.json()),r(``);return}r(e.status===404?`This workspace runs a kraftwerk without the projects API. Update it and restart its UI.`:`Could not load the project 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 pe(`/api/projects/${t}`,n);if(!r.ok)throw Error(r.error||`failed`);window.dispatchEvent(new Event(`kw-meta-refresh`))}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,S.jsxs)(`div`,{className:`settings-screen ws-screen`,children:[(0,S.jsxs)(`div`,{className:`settings-head`,children:[(0,S.jsxs)(`h1`,{children:[(0,S.jsx)(C,{name:`hub`,className:`ms-lg`}),` Workspaces`]}),(0,S.jsx)(`span`,{className:`spacer`}),e&&(0,S.jsxs)(`span`,{className:`settings-note`,children:[e.length,` known · `,p,` running`]}),e&&n&&(0,S.jsx)(`span`,{className:`settings-err`,children:n})]}),(0,S.jsxs)(`section`,{className:`panel`,children:[(0,S.jsxs)(`div`,{className:`panel-head`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`projects on this machine`}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsxs)(`span`,{className:`settings-note`,children:[`registry: `,(0,S.jsx)(`code`,{children:`~/.kraftwerk/projects`})]})]}),!e&&!n&&(0,S.jsx)(`div`,{className:`ws-empty`,children:`loading…`}),!e&&n&&(0,S.jsxs)(`div`,{className:`ws-empty ws-load-error`,children:[(0,S.jsx)(C,{name:`error`,className:`ms-sm`}),` `,n]}),e&&e.length===0&&(0,S.jsx)(`div`,{className:`ws-empty`,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);return(0,S.jsxs)(`div`,{className:`ws-row state-${e.state} ${e.current?`current`:``}`,children:[(0,S.jsx)(fe,{className:`ws-icon`,icon:e.icon,name:e.name,color:e.color,seed:e.root??e.url,ambiguous:h(e.icon)}),(0,S.jsxs)(`div`,{className:`ws-main`,children:[(0,S.jsxs)(`div`,{className:`ws-title`,children:[e.live&&!e.current?(0,S.jsx)(`a`,{href:e.url,className:`ws-name${e.named===!1?` unnamed`:``}`,children:e.name}):(0,S.jsx)(`span`,{className:`ws-name${e.named===!1?` unnamed`:``}`,children:e.name}),e.current&&(0,S.jsx)(`span`,{className:`switcher-hint`,children:`current`}),(0,S.jsxs)(`span`,{className:`ws-state ws-state-${e.state}`,children:[e.live&&(0,S.jsx)(`span`,{className:`live-dot`}),ya[e.state].label]}),ya[e.state].note&&(0,S.jsx)(`span`,{className:`ws-note`,children:ya[e.state].note})]}),(0,S.jsx)(`div`,{className:`ws-root`,title:e.root,children:e.rootLabel??(0,S.jsx)(`span`,{className:`ws-dim`,children:`no root recorded (started by an older version)`})}),(0,S.jsxs)(`div`,{className:`ws-meta`,children:[e.state!==`missing`&&e.state!==`orphaned`&&(0,S.jsx)(`span`,{children:e.url.replace(/^https?:\/\//,``)}),e.counts&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`span`,{children:[e.counts.agents,` agents`]}),(0,S.jsxs)(`span`,{children:[e.counts.workflows,` workflows`]}),(0,S.jsxs)(`span`,{children:[e.counts.runs,` runs`]}),(0,S.jsxs)(`span`,{children:[e.counts.chats,` chats`]})]}),e.lastStarted&&(0,S.jsxs)(`span`,{title:e.lastStarted,children:[`started `,ve(e.lastStarted)]}),!e.live&&e.lastStopped&&(0,S.jsxs)(`span`,{title:e.lastStopped,children:[`stopped `,ve(e.lastStopped)]}),e.startCount!=null&&(0,S.jsxs)(`span`,{children:[e.startCount,`× launched`]}),e.firstSeen&&(0,S.jsxs)(`span`,{title:e.firstSeen,children:[`first seen `,ve(e.firstSeen)]})]}),o[t]&&(0,S.jsx)(`div`,{className:`settings-err`,children:o[t]})]}),(0,S.jsxs)(`div`,{className:`ws-actions`,children:[e.live&&!e.current&&(0,S.jsxs)(`a`,{className:`ws-btn`,href:e.url,title:`Open this workspace`,children:[(0,S.jsx)(C,{name:`open_in_new`,className:`ms-sm`}),` open`]}),!e.live&&e.root&&e.exists!==!1&&!e.dirGone&&(0,S.jsxs)(`button`,{className:`ws-btn primary`,disabled:!!n,onClick:()=>void f(e,`start`),children:[(0,S.jsx)(C,{name:n===`start`?`progress_activity`:`play_arrow`,className:`ms-sm`}),n===`start`?`starting…`:`start`]}),e.live&&!e.current&&(0,S.jsxs)(`button`,{className:`ws-btn danger`,disabled:!!n,onClick:()=>void f(e,`stop`),children:[(0,S.jsx)(C,{name:n===`stop`?`progress_activity`:`stop`,className:`ms-sm`}),n===`stop`?`stopping…`:`stop`]}),r&&c!==t&&(0,S.jsxs)(`button`,{className:`ws-btn`,disabled:!!n,title:`Drop this project from the registry (files untouched)`,onClick:()=>l(t),children:[(0,S.jsx)(C,{name:`delete`,className:`ms-sm`}),` remove`]}),r&&c===t&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`button`,{className:`ws-btn danger`,onClick:()=>void f(e,`forget`),children:[(0,S.jsx)(C,{name:`delete`,className:`ms-sm`}),` confirm remove`]}),(0,S.jsx)(`button`,{className:`ws-btn`,onClick:()=>l(null),children:`cancel`})]})]})]},t)})]}),(0,S.jsxs)(`p`,{className:`settings-note`,children:[`Start launches `,(0,S.jsx)(`code`,{children:`kraftwerk ui`}),` detached in the project root (log in `,(0,S.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,S.jsx)(`code`,{children:`kraftwerk.yml`}),` — the same from the terminal:`,` `,(0,S.jsx)(`code`,{children:`kraftwerk projects`}),`.`]})]})}function xa(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 Sa=[[/^(\+\+\+|---|diff |index )/,`d-meta`],[/^@@/,`d-hunk`],[/^\+/,`d-add`],[/^-/,`d-del`]],Ca=e=>Sa.find(([t])=>t.test(e))?.[1]??``;function wa({file:e}){let[t,n]=(0,v.useState)(null),[r,i]=(0,v.useState)(!1),[a,o]=(0,v.useState)(``);return(0,v.useEffect)(()=>{let t=!0;return fetch(`/api/git/diff?path=${encodeURIComponent(e)}`).then(e=>e.json()).then(e=>{t&&(n(e.diff??``),i(!!e.truncated),o(e.error??``))}).catch(()=>t&&o(`could not load the diff`)),()=>{t=!1}},[e]),a?(0,S.jsx)(`div`,{className:`git-diff git-diff-error`,children:a}):t===null?(0,S.jsx)(`div`,{className:`git-diff`,children:`loading…`}):t.trim()?(0,S.jsxs)(`pre`,{className:`git-diff`,children:[t.split(`
215
+ `).map((e,t)=>(0,S.jsxs)(`span`,{className:Ca(e),children:[e||` `,`
216
216
  `]},t)),r&&(0,S.jsxs)(`span`,{className:`d-meta`,children:[`… diff truncated, see the rest in a terminal`,`
217
- `]})]}):(0,S.jsx)(`div`,{className:`git-diff`,children:`no textual diff (binary or empty)`})}function ga(){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.useCallback)(async()=>{try{let e=await fetch(`/api/git`,{cache:`no-store`});e.ok&&t(await e.json())}catch{}},[]);(0,v.useEffect)(()=>{let e=!0,t,n=async()=>{await m(),e&&(t=setTimeout(n,6e3))};return n(),()=>{e=!1,clearTimeout(t)}},[m]),(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 h=async(e,t)=>{l(e),d(``),p(``);try{let n=await pe(`/api/git/${e}`,t);n.ok?p(e===`push`?`pushed`:e===`pull`?`pulled`:`fetched`):d(n.error||`${e} failed`)}catch(t){d(t.message||`${e} failed`)}finally{l(``)}m()},g=async()=>{l(`commit`),d(``),p(``);try{let e=await pe(`/api/git/commit`,{paths:[...n],message:o});e.ok?(p(`committed ${n.size} file${n.size===1?``:`s`}`),r(new Set),s(``)):d(e.error||`commit failed`)}catch(e){d(e.message||`commit failed`)}finally{l(``)}m()};if(!e)return(0,S.jsx)(`div`,{className:`settings-screen`,children:(0,S.jsx)(`div`,{className:`ws-empty`,children:`loading…`})});if(!e.enabled)return(0,S.jsxs)(`div`,{className:`settings-screen`,children:[(0,S.jsx)(`div`,{className:`settings-head`,children:(0,S.jsxs)(`h1`,{children:[(0,S.jsx)(C,{name:`cloud_sync`,className:`ms-lg`}),` Git sync`]})}),(0,S.jsx)(`section`,{className:`panel`,children:(0,S.jsxs)(`div`,{className:`ws-empty`,children:[`Git sync is off. Turn it on in `,(0,S.jsx)(`a`,{href:`#/settings`,children:`settings`}),`, or add a `,(0,S.jsx)(`code`,{children:`git:`}),` block to kraftwerk.yml.`]})})]});let _=(e.files??[]).filter(e=>e.syncable),y=(e.files??[]).filter(e=>!e.syncable),b=(e,t)=>r(n=>{let r=new Set(n);return t?r.add(e):r.delete(e),r});return(0,S.jsxs)(`div`,{className:`settings-screen ws-screen`,children:[(0,S.jsxs)(`div`,{className:`settings-head`,children:[(0,S.jsxs)(`h1`,{children:[(0,S.jsx)(C,{name:`cloud_sync`,className:`ms-lg`}),` Git sync`]}),(0,S.jsx)(`span`,{className:`spacer`}),f&&(0,S.jsxs)(`span`,{className:`settings-saved`,children:[(0,S.jsx)(C,{name:`check`,className:`ms-sm`}),` `,f]}),u&&(0,S.jsx)(`span`,{className:`settings-err`,children:u})]}),(0,S.jsxs)(`section`,{className:`panel`,children:[(0,S.jsxs)(`div`,{className:`panel-head`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`branch`}),(0,S.jsx)(`span`,{className:`spacer`}),e.lastFetch&&(0,S.jsxs)(`span`,{className:`settings-note`,title:e.lastFetch,children:[`fetched `,ve(e.lastFetch)]}),e.lastError&&(0,S.jsxs)(`span`,{className:`settings-err git-sync-err`,title:e.lastError,children:[(0,S.jsx)(C,{name:`cloud_off`,className:`ms-sm`}),` `,e.lastError.split(`
218
- `)[0]]})]}),e.error?(0,S.jsxs)(`div`,{className:`ws-empty ws-load-error`,children:[(0,S.jsx)(C,{name:`error`,className:`ms-sm`}),` `,e.error]}):(0,S.jsxs)(`div`,{className:`git-head`,children:[(0,S.jsxs)(`div`,{className:`git-branch`,children:[(0,S.jsx)(C,{name:`account_tree`,className:`ms-sm`}),(0,S.jsx)(`strong`,{children:e.branch}),e.upstream?(0,S.jsxs)(`span`,{className:`settings-note`,children:[`tracking `,e.upstream]}):(0,S.jsx)(`span`,{className:`settings-note`,children:`no upstream yet, push sets one`})]}),(0,S.jsxs)(`div`,{className:`git-counts`,children:[e.diverged&&(0,S.jsx)(`span`,{className:`git-diverged`,children:`diverged, resolve in a terminal`}),!!e.behind&&(0,S.jsxs)(`span`,{className:`git-behind`,children:[e.behind,` behind`]}),!!e.ahead&&(0,S.jsxs)(`span`,{className:`git-ahead`,children:[e.ahead,` ahead`]}),!e.ahead&&!e.behind&&(0,S.jsx)(`span`,{className:`settings-note`,children:`up to date`})]}),(0,S.jsxs)(`div`,{className:`ws-actions`,children:[(0,S.jsxs)(`button`,{className:`ws-btn`,disabled:!!c,onClick:()=>void h(`fetch`),children:[(0,S.jsx)(C,{name:c===`fetch`?`progress_activity`:`refresh`,className:`ms-sm`}),` fetch`]}),(0,S.jsxs)(`button`,{className:`ws-btn`,disabled:!!c||!e.behind||e.diverged,title:e.diverged?`Diverged. Resolve in a terminal.`:`Fast-forward to the remote`,onClick:()=>void h(`pull`),children:[(0,S.jsx)(C,{name:c===`pull`?`progress_activity`:`download`,className:`ms-sm`}),` pull`]}),(0,S.jsxs)(`button`,{className:`ws-btn primary`,disabled:!!c||!e.ahead&&!!e.upstream,title:e.upstream?`Push to the upstream`:`Push and set the upstream`,onClick:()=>void h(`push`),children:[(0,S.jsx)(C,{name:c===`push`?`progress_activity`:`upload`,className:`ms-sm`}),` push`]})]})]})]}),(0,S.jsxs)(`section`,{className:`panel`,children:[(0,S.jsxs)(`div`,{className:`panel-head`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`changes`}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsx)(`span`,{className:`settings-note`,children:_.length===0?`workspace clean`:`${n.size} of ${_.length} selected`})]}),_.length===0&&y.length===0&&(0,S.jsx)(`div`,{className:`ws-empty`,children:`Nothing changed under the workspace paths.`}),_.map(e=>(0,S.jsxs)(`div`,{className:`git-row`,children:[(0,S.jsx)(`label`,{className:`git-pick`,children:(0,S.jsx)(`input`,{type:`checkbox`,checked:n.has(e.path),onChange:t=>b(e.path,t.target.checked)})}),(0,S.jsxs)(`button`,{className:`git-file`,onClick:()=>a(t=>{let n=new Set(t);return n.has(e.path)?n.delete(e.path):n.add(e.path),n}),children:[(0,S.jsx)(C,{name:i.has(e.path)?`expand_more`:`chevron_right`,className:`ms-sm`}),(0,S.jsx)(`span`,{className:`git-status s-${e.status}`,children:e.status}),(0,S.jsx)(`span`,{className:`git-path`,children:e.path})]}),i.has(e.path)&&(0,S.jsx)(ha,{file:e.path})]},e.path)),_.length>0&&(0,S.jsxs)(`div`,{className:`git-commit`,children:[(0,S.jsx)(`input`,{className:`git-message`,placeholder:`Commit message`,value:o,onChange:e=>s(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!c&&o.trim()&&n.size>0&&g()}}),(0,S.jsx)(`button`,{className:`ws-btn`,disabled:n.size===_.length,onClick:()=>r(new Set(_.map(e=>e.path))),children:`select all`}),(0,S.jsxs)(`button`,{className:`ws-btn primary`,disabled:!!c||n.size===0||!o.trim(),onClick:()=>void g(),children:[(0,S.jsx)(C,{name:c===`commit`?`progress_activity`:`check`,className:`ms-sm`}),`commit `,n.size||``]})]}),y.length>0&&(0,S.jsxs)(`details`,{className:`git-blocked`,children:[(0,S.jsxs)(`summary`,{children:[y.length,e.blockedHidden?`+`:``,` change`,y.length===1&&!e.blockedHidden?``:`s`,` outside the workspace paths`]}),y.map(e=>(0,S.jsxs)(`div`,{className:`git-row blocked`,children:[(0,S.jsx)(`span`,{className:`git-status s-blocked`,children:e.status}),(0,S.jsx)(`span`,{className:`git-path`,children:e.path}),(0,S.jsx)(`span`,{className:`settings-note`,children:e.reason})]},e.path)),!!e.blockedHidden&&(0,S.jsx)(`div`,{className:`git-row blocked`,children:(0,S.jsxs)(`span`,{className:`settings-note`,children:[`and `,e.blockedHidden,` more, not listed`]})})]})]}),(0,S.jsxs)(`p`,{className:`settings-note`,children:[`Synced paths: `,(e.scope??[]).map((e,t)=>(0,S.jsxs)(`span`,{children:[t>0&&`, `,(0,S.jsx)(`code`,{children:e})]},e)),`. Run artifacts and files like `,(0,S.jsx)(`code`,{children:`.env`}),` are never staged.`,` `,e.interval?`Fetches every ${fa(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 _a=e=>e.replace(/^https?:\/\//,``).replace(/^git@([^:]+):/,`$1/`).replace(/\.git$/,``),va=e=>e.error?{label:`unreadable`,cls:`missing`}:e.dirty?{label:`${e.dirty} changed`,cls:`died`}:e.ahead?{label:`${e.ahead} to push`,cls:`running`}:e.behind?{label:`${e.behind} behind`,cls:`stopped`}:{label:`clean`,cls:`running`},ya=e=>!!(e.error||e.dirty||e.ahead===void 0||e.ahead);function ba(){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=N(),w=(0,v.useCallback)(async()=>{try{let e=await fetch(`/api/repos`,{cache:`no-store`});if(!e.ok)throw Error(`HTTP ${e.status}`);t(await e.json()),r(``)}catch(e){r(e.message||`could not load repositories`)}},[]);(0,v.useEffect)(()=>{let e=!0,t,n=async()=>{await w(),e&&(t=setTimeout(n,15e3))};return n(),()=>{e=!1,clearTimeout(t)}},[w]);let T=async(e,t,n=!1)=>{a(n=>({...n,[e]:t})),s(t=>({...t,[e]:``})),l(null);try{let r=t===`update`?await fetch(`/api/repos/${encodeURIComponent(e)}/update`,{method:`POST`}):await fetch(`/api/repos/${encodeURIComponent(e)}${n?`?force=1`:``}`,{method:`DELETE`}),i=await r.json();if(!r.ok||!i.ok)throw Error(i.error||`failed`);i.error&&s(t=>({...t,[e]:i.error}))}catch(t){s(n=>({...n,[e]:t.message}))}finally{a(t=>{let n={...t};return delete n[e],n}),w()}},E=async e=>{if(e.preventDefault(),u.trim()&&!g){_(!0),b(``);try{let e=await fetch(`/api/repos`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({url:u.trim(),name:f.trim()||void 0,branch:m.trim()||void 0})}),t=await e.json();if(!e.ok)throw Error(t.error||`clone failed`);d(``),p(``),h(``),await w()}catch(e){b(e.message)}finally{_(!1)}}},D=[...e?.repos??[]].sort((e,t)=>(t.updatedAt??``).localeCompare(e.updatedAt??``));return(0,S.jsxs)(`div`,{className:`settings-screen ws-screen repos-screen`,children:[(0,S.jsxs)(`div`,{className:`settings-head`,children:[(0,S.jsxs)(`h1`,{children:[(0,S.jsx)(C,{name:`source`,className:`ms-lg`}),` Repositories`]}),(0,S.jsx)(`span`,{className:`spacer`}),e?.enabled&&(0,S.jsxs)(`span`,{className:`settings-note`,children:[D.length,` cloned`]}),n&&(0,S.jsx)(`span`,{className:`settings-err`,children:n})]}),e&&!e.enabled&&(0,S.jsx)(`section`,{className:`panel`,children:(0,S.jsx)(`div`,{className:`ws-empty`,children:e.error&&!/are off/.test(e.error)?(0,S.jsx)(`span`,{className:`settings-err`,children:e.error}):(0,S.jsxs)(S.Fragment,{children:[`Repositories are off. Turn them on in `,(0,S.jsx)(`a`,{href:`#/settings`,children:`settings`}),` or add a `,(0,S.jsx)(`code`,{children:`repos:`}),` block to kraftwerk.yml.`]})})}),e?.enabled&&(0,S.jsxs)(`section`,{className:`panel`,children:[(0,S.jsxs)(`div`,{className:`panel-head`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`add a repository`}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsxs)(`span`,{className:`settings-note`,children:[`clones into `,(0,S.jsx)(`code`,{title:e.root,children:e.root})]})]}),(0,S.jsxs)(`form`,{className:`agent-form`,onSubmit:e=>void E(e),children:[(0,S.jsxs)(`div`,{className:`agent-form-row`,children:[(0,S.jsxs)(`label`,{className:`agent-field`,style:{flex:2},children:[`url`,(0,S.jsx)(`input`,{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,S.jsxs)(`label`,{className:`agent-field`,style:{flex:1},children:[`name`,(0,S.jsx)(`input`,{value:f,placeholder:`from the url`,onChange:e=>p(e.target.value)})]}),(0,S.jsxs)(`label`,{className:`agent-field`,style:{width:140},children:[`branch`,(0,S.jsx)(`input`,{value:m,placeholder:`default`,onChange:e=>h(e.target.value)})]}),(0,S.jsxs)(`button`,{className:`ws-btn primary`,type:`submit`,disabled:g||!u.trim(),children:[(0,S.jsx)(C,{name:g?`progress_activity`:`download`,className:`ms-sm`}),g?`cloning…`:`clone`]})]}),y&&(0,S.jsx)(`div`,{className:`settings-err`,children:y}),(0,S.jsxs)(`div`,{className:`settings-note`,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,S.jsx)(`code`,{children:`kraftwerk repos add`}),`.`]})]})]}),e?.enabled&&(0,S.jsxs)(`section`,{className:`panel`,children:[(0,S.jsx)(`div`,{className:`panel-head`,children:(0,S.jsx)(`span`,{className:`microlabel`,children:`cloned repositories · newest change first`})}),D.length===0&&(0,S.jsx)(`div`,{className:`ws-empty`,children:`Nothing cloned yet.`}),D.map(e=>{let t=i[e.slug],n=va(e);return(0,S.jsxs)(`div`,{className:`ws-row repo-row state-${n.cls}`,"data-repo":e.slug,children:[(0,S.jsx)(`span`,{className:`switcher-icon ws-icon`,children:(0,S.jsx)(C,{name:`folder_data`})}),(0,S.jsxs)(`div`,{className:`ws-main`,children:[(0,S.jsxs)(`div`,{className:`ws-title`,children:[(0,S.jsx)(`span`,{className:`ws-name`,children:e.slug}),e.branch&&(0,S.jsx)(`span`,{className:`repo-branch`,children:e.branch}),(0,S.jsx)(`span`,{className:`ws-state ws-state-${n.cls}`,children:n.label}),e.updatedAt&&(0,S.jsxs)(`span`,{className:`vibeable-when`,title:e.updatedAt,children:[`changed `,ve(e.updatedAt)]})]}),e.url&&(0,S.jsx)(`div`,{className:`ws-root`,title:e.url,children:_a(e.url)}),x&&(0,S.jsx)(`div`,{className:`ws-root ws-dim`,title:e.path,children:e.path}),(0,S.jsxs)(`div`,{className:`ws-meta`,children:[e.head&&(0,S.jsxs)(`span`,{title:e.committedAt,children:[(0,S.jsx)(`code`,{children:e.head}),` `,e.subject,e.committedAt?` · ${ve(e.committedAt)}`:``]}),!!e.behind&&!!e.dirty&&(0,S.jsxs)(`span`,{children:[`behind by `,e.behind]}),e.error&&(0,S.jsx)(`span`,{className:`settings-err`,children:e.error})]}),o[e.slug]&&(0,S.jsx)(`div`,{className:`settings-err`,children:o[e.slug]})]}),(0,S.jsxs)(`div`,{className:`ws-actions`,children:[(0,S.jsxs)(`button`,{className:`ws-btn`,disabled:!!t,onClick:()=>void T(e.slug,`update`),title:`git fetch, then fast-forward when clean`,children:[(0,S.jsx)(C,{name:t===`update`?`progress_activity`:`sync`,className:`ms-sm`}),t===`update`?`updating…`:`update`]}),c!==e.slug&&(0,S.jsxs)(`button`,{className:`ws-btn`,disabled:!!t,onClick:()=>l(e.slug),title:`Delete the clone`,children:[(0,S.jsx)(C,{name:`delete`,className:`ms-sm`}),` remove`]}),c===e.slug&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`button`,{className:`ws-btn danger`,onClick:()=>void T(e.slug,`remove`,ya(e)),children:[(0,S.jsx)(C,{name:`delete`,className:`ms-sm`}),e.dirty||e.ahead?`delete with local changes`:ya(e)?`delete anyway`:`confirm remove`]}),(0,S.jsx)(`button`,{className:`ws-btn`,onClick:()=>l(null),children:`cancel`})]})]})]},e.slug)})]})]})}var xa=40,Sa=/Mac|iPhone|iPad/.test(navigator.platform),Ca=null,wa=e=>(e?.workspaces??[]).flatMap(e=>e.agents.map(t=>({agent:t,ws:e,key:`${e.url}|${t.slug}`})));function Ta(e,t){let n=t.toLowerCase().split(/\s+/).filter(Boolean);if(n.length===0)return e;let r=[];for(let t of e){let e=t.agent.name.toLowerCase(),i=[e,t.agent.slug,t.agent.description??``,t.agent.group??``,t.ws.name].join(` `).toLowerCase();if(!n.every(e=>i.includes(e)))continue;let a=e.startsWith(n[0])?0:e.includes(n[0])?1:2;r.push({hit:t,score:a})}return r.sort((e,t)=>e.score-t.score).map(e=>e.hit)}async function Ea(e){let t=`/agents/${encodeURIComponent(e.agent.slug)}`;if(e.ws.current)return k(t);let n=e.ws.live||!e.ws.root?e.ws.url:await re(e.ws.root);window.location.assign(`${n.replace(/\/+$/,``)}/#${t}`)}function Da(){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,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`button`,{type:`button`,className:`search-btn`,onClick:()=>t(!0),title:`jump to an agent`,"aria-label":`search agents`,children:[(0,S.jsx)(C,{name:`search`}),(0,S.jsx)(`kbd`,{className:`kbd`,children:Sa?`⌘K`:`Ctrl K`})]}),e&&(0,S.jsx)(Oa,{onClose:()=>t(!1)})]})}function Oa({onClose:e}){let[t,n]=(0,v.useState)(Ca),[r,i]=(0,v.useState)(Ca===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 fetch(`/api/search/agents`,{cache:`no-store`}).then(e=>e.ok?e.json():Promise.reject(Error(String(e.status)))).then(t=>{Ca=t,e&&n(t)}).catch(()=>e&&o(!0)).finally(()=>e&&i(!1)),()=>{e=!1}},[]);let g=(0,v.useMemo)(()=>wa(t),[t]),_=(0,v.useMemo)(()=>Ta(g,s).slice(0,xa),[g,s]),y=Math.min(l,Math.max(_.length-1,0));(0,v.useEffect)(()=>{(h.current?.children[y])?.scrollIntoView({block:`nearest`})},[y,_]);let b=t=>{if(!d){if(t.ws.current||t.ws.live){e(),Ea(t);return}f(t.key),m(``),Ea(t).catch(e=>{f(null),m(`${t.ws.name}: ${e.message}`)})}},x=t=>{if(t.key===`ArrowDown`)t.preventDefault(),u(_.length?(y+1)%_.length:0);else if(t.key===`ArrowUp`)t.preventDefault(),u(_.length?(y-1+_.length)%_.length:0);else if(t.key===`Enter`){t.preventDefault();let e=_[y];e&&b(e)}else t.key===`Escape`&&(t.preventDefault(),e())},w;return w=_.length>0?(0,S.jsx)(`ul`,{className:`palette-list`,role:`listbox`,"aria-label":`agents`,ref:h,children:_.map((e,t)=>(0,S.jsxs)(`li`,{role:`option`,"aria-selected":t===y,className:`palette-item${t===y?` active`:``}`,onMouseMove:()=>t!==y&&u(t),onClick:()=>b(e),children:[(0,S.jsx)(`span`,{className:`palette-emoji`,"aria-hidden":!0,children:e.agent.emoji}),(0,S.jsxs)(`span`,{className:`palette-text`,children:[(0,S.jsx)(`span`,{className:`palette-name`,children:e.agent.name}),e.agent.description&&(0,S.jsx)(`span`,{className:`palette-sub`,children:e.agent.description})]}),(0,S.jsxs)(`span`,{className:`palette-ws`,title:e.ws.current?`this workspace`:e.ws.url,children:[e.ws.icon&&(0,S.jsx)(`span`,{"aria-hidden":!0,children:e.ws.icon}),e.ws.name,d===e.key?(0,S.jsx)(C,{name:`progress_activity`,className:`ms-sm`}):e.ws.live?!e.ws.current&&(0,S.jsx)(C,{name:`open_in_new`,className:`ms-sm`}):(0,S.jsx)(`span`,{className:`palette-chip`,children:`stopped`})]})]},e.key))}):a?(0,S.jsx)(`div`,{className:`palette-empty`,children:`could not load the agents`}):r?(0,S.jsx)(`div`,{className:`palette-empty`,children:`looking for agents…`}):g.length===0?(0,S.jsxs)(`div`,{className:`palette-empty`,children:[`no agents yet — `,(0,S.jsx)(`a`,{href:`#/agents/new`,onClick:e,children:`create one`})]}):(0,S.jsxs)(`div`,{className:`palette-empty`,children:[`no agent matches “`,s,`”`]}),(0,S.jsx)(`div`,{className:`palette-backdrop`,onMouseDown:e,children:(0,S.jsxs)(`div`,{className:`palette`,role:`dialog`,"aria-label":`jump to an agent`,onMouseDown:e=>e.stopPropagation(),onKeyDown:x,children:[(0,S.jsxs)(`div`,{className:`palette-input`,children:[(0,S.jsx)(C,{name:`search`}),(0,S.jsx)(`input`,{autoFocus:!0,value:s,onChange:e=>{c(e.target.value),u(0)},placeholder:`jump to an agent…`,"aria-label":`search agents`,autoComplete:`off`,spellCheck:!1}),r&&t&&(0,S.jsx)(C,{name:`progress_activity`,className:`ms-sm`}),(0,S.jsx)(`kbd`,{className:`kbd`,children:`esc`})]}),w,(0,S.jsxs)(`div`,{className:`palette-foot`,children:[(0,S.jsxs)(`span`,{children:[(0,S.jsx)(`kbd`,{className:`kbd`,children:`↑`}),(0,S.jsx)(`kbd`,{className:`kbd`,children:`↓`}),` move`]}),(0,S.jsxs)(`span`,{children:[(0,S.jsx)(`kbd`,{className:`kbd`,children:`↵`}),` open`]}),d&&(0,S.jsxs)(`span`,{className:`palette-note`,children:[(0,S.jsx)(C,{name:`progress_activity`,className:`ms-sm`}),` starting the workspace…`]}),p&&(0,S.jsxs)(`span`,{className:`palette-warn`,title:p,children:[(0,S.jsx)(C,{name:`warning`,className:`ms-sm`}),` `,p]})]})]})})}var ka=`modulepreload`,Aa=function(e){return`/`+e},ja={},Ma=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e=document.getElementsByTagName(`link`),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?import.meta.resolve(e):new URL(e,import.meta.url).href}r=o(t.map(t=>{if(t=Aa(t,n),t=s(t),t in ja)return;ja[t]=!0;let r=t.endsWith(`.css`);for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.href===t&&(!r||i.rel===`stylesheet`))return}let i=document.createElement(`link`);if(i.rel=r?`stylesheet`:ka,r||(i.as=`script`),i.crossOrigin=``,i.href=t,a&&i.setAttribute(`nonce`,a),document.head.appendChild(i),r)return new Promise((e,n)=>{i.addEventListener(`load`,e),i.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${t}`)))})}))}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)})},Na=(0,v.lazy)(()=>Ma(()=>import(`./editor--4qv8VP5.js`).then(e=>({default:e.EditorScreen})),__vite__mapDeps([0,1,2,3,4,5,6])));function Pa(){let e=w().split(`/`).filter(Boolean),[t,n]=(0,v.useState)(``),[r,i]=(0,v.useState)(``),[a,o]=(0,v.useState)(``),[s,c]=(0,v.useState)(!0),[l,u]=(0,v.useState)(``),[d,f]=(0,v.useState)(``),[p,m]=(0,v.useState)(!1),[h,g]=(0,v.useState)(!1),[_,y]=(0,v.useState)(!1),[b,x]=(0,v.useState)([]);(0,v.useEffect)(()=>{let e=!0,t,r=async()=>{try{let t=await fetch(`/api/meta`,{cache:`no-store`}).then(e=>e.json());if(!e)return;n(t.projectName??``),i(t.projectIcon??``),o(t.projectColor??``),c(t.projectNamed!==!1),u(t.projectRootLabel??``),f(t.projectRoot??``),m(!!t.git),g(!!t.repos),y(!!t.vibeables),ce({git:!!t.git,repos:!!t.repos,vibeables:!!t.vibeables}),x(Array.isArray(t.switcher)?t.switcher:[])}catch{}e&&(t=setTimeout(r,3e4))};r();let a=()=>{clearTimeout(t),r()};return window.addEventListener(`kw-meta-refresh`,a),()=>{e=!1,clearTimeout(t),window.removeEventListener(`kw-meta-refresh`,a)}},[]),(0,v.useEffect)(()=>{if(te(t?`${t} — kraftwerk`:`kraftwerk inspector`),!r)return;let e=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><text y="0.9em" font-size="85">${r}</text></svg>`,n=document.querySelector(`link[rel="icon"]`);n||(n=document.createElement(`link`),n.rel=`icon`,document.head.appendChild(n)),n.href=`data:image/svg+xml,${encodeURIComponent(e)}`},[t,r]);let T;return T=e[0]===`runs`&&e[1]?(0,S.jsx)(qr,{id:e[1]}):e[0]===`runs`?(0,S.jsx)(Ha,{}):e[0]===`workflows`&&e[1]?(0,S.jsx)(ci,{slug:decodeURIComponent(e[1])}):e[0]===`workflows`?(0,S.jsx)(si,{}):e[0]===`chats`?(0,S.jsx)(Ki,{seg:e}):e[0]===`skills`?(0,S.jsx)(Vi,{name:e[1]?decodeURIComponent(e[1]):void 0}):e[0]===`settings`?(0,S.jsx)(la,{}):e[0]===`workspaces`?(0,S.jsx)(da,{}):e[0]===`git`?(0,S.jsx)(ga,{}):e[0]===`repos`?(0,S.jsx)(ba,{}):e[0]===`vibeables`?(0,S.jsx)(Ir,{}):e[0]===`agents`||e[0]===`team`?(0,S.jsx)(Ki,{seg:e.slice(1)}):e[0]===`knowledge`?(0,S.jsx)(Ai,{bundle:e[1]?decodeURIComponent(e[1]):void 0,conceptId:e.length>2?e.slice(2).map(decodeURIComponent).join(`/`):void 0}):(0,S.jsx)(vi,{}),e[0]===`edit`&&e[1]&&e.length>2?(0,S.jsx)(v.Suspense,{fallback:(0,S.jsx)(`div`,{className:`empty`,children:`loading editor…`}),children:(0,S.jsx)(Na,{bundle:decodeURIComponent(e[1]),conceptId:e.slice(2).map(decodeURIComponent).join(`/`)},e.slice(1).join(`/`))}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`header`,{className:`topbar`,style:{"--ws-c":ue(a,d||t)},children:[(0,S.jsxs)(`span`,{className:`wordmark`,children:[(0,S.jsx)(`a`,{href:`#/`,className:`home-link`,title:`Dashboard`,children:t?(0,S.jsx)(fe,{className:`home-tile`,icon:r,name:t,color:a,seed:d||t}):(0,S.jsx)(C,{name:`home`})}),t&&(0,S.jsx)(Va,{name:t,icon:r,color:a,named:s,root:l,seed:d||t,entries:b})]}),(0,S.jsxs)(`nav`,{children:[(0,S.jsxs)(`a`,{href:`#/agents`,children:[(0,S.jsx)(C,{name:`groups`}),` agents`]}),(0,S.jsxs)(`a`,{href:`#/knowledge`,children:[(0,S.jsx)(C,{name:`menu_book`}),` context & knowledge`]}),(0,S.jsxs)(`a`,{href:`#/workflows`,children:[(0,S.jsx)(C,{name:`account_tree`}),` workflows`]}),(0,S.jsxs)(`a`,{href:`#/runs`,children:[(0,S.jsx)(C,{name:`history`}),` workflow runs`]}),(0,S.jsxs)(`a`,{href:`#/skills`,children:[(0,S.jsx)(C,{name:`extension`}),` skills`]}),h&&(0,S.jsxs)(`a`,{href:`#/repos`,children:[(0,S.jsx)(C,{name:`source`}),` repositories`]}),_&&(0,S.jsxs)(`a`,{href:`#/vibeables`,children:[(0,S.jsx)(C,{name:`web`}),` vibeables`]}),p&&(0,S.jsx)(Fa,{})]}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsx)(Da,{}),(0,S.jsx)(qa,{}),(0,S.jsx)(Ua,{}),(0,S.jsx)(Wa,{}),(0,S.jsx)(Ja,{})]}),(0,S.jsx)(`main`,{className:`shell`,children:T})]})}function Fa(){let e=F(`/api/git`,!1,15e3),t=e?.files?.filter(e=>e.syncable).length??0;return(0,S.jsxs)(`a`,{href:`#/git`,children:[(0,S.jsx)(C,{name:`cloud_sync`}),` git`,!!e?.behind&&(0,S.jsxs)(`span`,{className:`git-badge behind`,children:[e.behind,`↓`]}),!!e?.ahead&&(0,S.jsxs)(`span`,{className:`git-badge ahead`,children:[e.ahead,`↑`]}),!e?.ahead&&!e?.behind&&!!t&&(0,S.jsx)(`span`,{className:`git-badge dirty`,children:t})]})}function Ia(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?:\/\//,``)}}function La({label:e}){return e?(0,S.jsx)(`span`,{className:`switcher-root`,title:e,children:(0,S.jsx)(`span`,{dir:`ltr`,children:e})}):null}function Ra({name:e,named:t}){let n=t===!1;return(0,S.jsx)(`span`,{className:`switcher-name${n?` unnamed`:``}`,title:n?`${e} — folder name; set name: in kraftwerk.yml`:e,children:e})}function za({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 re(e.root))}catch(e){r(`error`),a(e.message)}};return(0,S.jsxs)(`span`,{className:`switcher-item stopped ${o?`missing`:``}`,role:`menuitem`,style:{"--ws-c":ue(e.color,e.root??e.url)},children:[(0,S.jsx)(fe,{icon:e.icon,name:e.name,color:e.color,seed:e.root??e.url,ambiguous:t}),(0,S.jsxs)(`span`,{className:`switcher-text`,children:[(0,S.jsx)(Ra,{name:e.name,named:e.named}),n===`error`?(0,S.jsx)(`span`,{className:`switcher-sub switcher-err`,title:i,children:i}):o?(0,S.jsx)(`span`,{className:`switcher-sub`,children:`folder missing`}):(0,S.jsx)(La,{label:e.rootLabel})]}),(0,S.jsxs)(`span`,{className:`switcher-side`,children:[(0,S.jsx)(`span`,{className:`switcher-port`,children:Ia(e.url)}),(0,S.jsxs)(`button`,{className:`switcher-start`,disabled:o||n===`starting`,title:o?`The project folder no longer exists`:`Start the UI for this project`,onClick:e=>{e.stopPropagation(),s()},children:[n===`starting`?(0,S.jsx)(C,{name:`progress_activity`}):(0,S.jsx)(C,{name:`play_arrow`}),n===`starting`?`starting`:`start`]})]})]})}function Ba({entry:e,ambiguous:t}){let n=e.root??e.url;return(0,S.jsxs)(`a`,{className:`switcher-item${e.live?` live`:``}`,role:`menuitem`,href:e.url,style:{"--ws-c":ue(e.color,n)},children:[(0,S.jsx)(fe,{icon:e.icon,name:e.name,color:e.color,seed:n,ambiguous:t}),(0,S.jsxs)(`span`,{className:`switcher-text`,children:[(0,S.jsx)(Ra,{name:e.name,named:e.named}),(0,S.jsx)(La,{label:e.rootLabel??(e.root?void 0:e.url.replace(/^https?:\/\//,``))})]}),(0,S.jsx)(`span`,{className:`switcher-side`,children:(0,S.jsxs)(`span`,{className:`switcher-port`,children:[e.live&&(0,S.jsx)(`span`,{className:`live-dot`,title:`running`}),Ia(e.url)]})})]})}function Va({name:e,icon:t,color:n,named:r,root:i,seed:a,entries:o}){let[s,c]=(0,v.useState)(!1),l=N();if((0,v.useEffect)(()=>{if(!s)return;let e=e=>{e.target.closest(`.switcher-wrap`)||c(!1)};return window.addEventListener(`mousedown`,e),()=>window.removeEventListener(`mousedown`,e)},[s]),o.length===0)return(0,S.jsx)(`span`,{className:`env-name`,title:i||`Project (kraftwerk.yml: name)`,children:e});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,S.jsxs)(`span`,{className:`switcher-wrap`,children:[(0,S.jsxs)(`button`,{className:`env-name env-switch`,title:i?`${i} — switch workspace`:`Switch workspace`,"aria-haspopup":`menu`,"aria-expanded":s,onClick:()=>c(e=>!e),children:[e,(0,S.jsx)(C,{name:`expand_more`})]}),s&&(0,S.jsxs)(`div`,{className:`switcher-pop`,role:`menu`,children:[(0,S.jsx)(`div`,{className:`switcher-head`,children:`Workspaces`}),(0,S.jsxs)(`span`,{className:`switcher-item current`,"aria-current":`true`,style:{"--ws-c":ue(n,p)},children:[(0,S.jsx)(fe,{icon:t,name:e,color:n,seed:p,ambiguous:d(t)}),(0,S.jsxs)(`span`,{className:`switcher-text`,children:[(0,S.jsx)(Ra,{name:e,named:r}),i?(0,S.jsx)(La,{label:i}):(0,S.jsx)(`span`,{className:`switcher-sub`,children:`this workspace`})]}),(0,S.jsx)(`span`,{className:`switcher-side`,children:(0,S.jsx)(C,{name:`check`,className:`switcher-check`})})]}),f.map(e=>(0,S.jsxs)(`div`,{className:`switcher-group switcher-group-${e.key}`,role:`group`,"aria-label":e.label,children:[(0,S.jsx)(`div`,{className:`switcher-group-head`,children:e.label}),e.items.map(e=>e.live===!1&&e.root?(0,S.jsx)(za,{entry:e,ambiguous:d(e.icon)},e.root):(0,S.jsx)(Ba,{entry:e,ambiguous:d(e.icon)},e.root??e.url))]},e.key)),l&&(0,S.jsxs)(`a`,{className:`switcher-foot`,href:`#/workspaces`,role:`menuitem`,onClick:()=>c(!1),children:[(0,S.jsx)(C,{name:`hub`}),` manage workspaces`]})]})]})}function Ha(){let[e,t]=(0,v.useState)(null);return(0,v.useEffect)(()=>{let e=!0;return fetch(`/api/runs`).then(e=>e.json()).then(n=>{e&&(n.runs.length>0?k(`/runs/${n.runs[0].id}`,{replace:!0}):t({outputDir:n.outputDir}))}).catch(()=>{}),()=>{e=!1}},[]),e?(0,S.jsxs)(`div`,{className:`empty`,children:[`No runs found in `,(0,S.jsx)(`code`,{children:e.outputDir}),`. Start one with`,` `,(0,S.jsx)(`code`,{children:`kraftwerk run <workflow> <request>`}),` or from a workflow page.`]}):(0,S.jsx)(`div`,{className:`empty`,children:`loading…`})}function Ua(){let[e,t]=(0,v.useState)(null),[n,r]=(0,v.useState)(!1);(0,v.useEffect)(()=>{let e=!0,n,r=async()=>{try{let n=await fetch(`/api/meta`,{cache:`no-store`}).then(e=>e.json());e&&t(n)}catch{}e&&(n=setTimeout(r,3e4))};return r(),()=>{e=!1,clearTimeout(n)}},[]);let i=e?.restartable&&e.diskVersion&&e.diskVersion!==e.version?e.diskVersion:null;async function a(){if(i){r(!0),await fetch(`/api/restart`,{method:`POST`}).catch(()=>{});for(let e=0;e<60;e++){await new Promise(e=>setTimeout(e,500));try{if((await fetch(`/api/meta`,{cache:`no-store`}).then(e=>e.json())).version===i)break}catch{}}location.reload()}}return!i&&!n?null:(0,S.jsx)(`button`,{className:`relaunch-note`,disabled:n,title:`v${i} is installed on disk, the server still runs v${e?.version}. Click to relaunch with the new version.`,onClick:()=>void a(),children:n?`relaunching…`:(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(C,{name:`restart_alt`,className:`ms-sm`}),` v`,i,` ready — relaunch`]})})}function Wa(){let e=N();return(0,S.jsxs)(`button`,{className:`expert-toggle ${e?`on`:``}`,title:e?`Expert mode on — full detail`:`Expert mode off — simplified view`,"aria-pressed":e,onClick:()=>ae(!e),children:[(0,S.jsx)(`span`,{className:`expert-track`,children:(0,S.jsx)(`span`,{className:`expert-knob`})}),`expert`]})}var Ga={approval:`gavel`,routine_done:`schedule`,routine_failed:`schedule`,run_done:`account_tree`,run_failed:`account_tree`},Ka=`kw.notif.toast.dismissed`;function qa(){let[e,t]=(0,v.useState)(!1),n=F(`/api/notifications`,!1,5e3),[r,i]=(0,v.useState)(()=>typeof Notification>`u`?`unsupported`:Notification.permission),[a,o]=(0,v.useState)(()=>{try{return localStorage.getItem(Ka)===`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,p=f?.items??[],m=f?.unread??0;(0,v.useEffect)(()=>ee(m),[m]),(0,v.useEffect)(()=>{if(n){if(!s.current){s.current=new Set(p.map(e=>e.id));return}for(let e of p)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(),g(e),t.close()}}catch{}}},[n]),(0,v.useEffect)(()=>{if(!e)return;let n=e=>{e.target.closest(`.notif-wrap`)||t(!1)};return window.addEventListener(`mousedown`,n),()=>window.removeEventListener(`mousedown`,n)},[e]);async function h(e,t){try{let n=await fetch(e,{method:e.endsWith(`/notifications`)?`DELETE`:`POST`,headers:{"content-type":`application/json`},body:t===void 0?void 0:JSON.stringify(t)});if(!n.ok)return;let r=await n.json();l(`items`in r?r:{items:[],unread:0})}catch{}}function g(e){t(!1),e.readAt||h(`/api/notifications/read`,{ids:[e.id]}),k(e.href)}async function _(e){d(e.id);try{let n=await(await fetch(`/api/notifications/${encodeURIComponent(e.id)}/diagnose`,{method:`POST`})).json();n.href?(t(!1),k(n.href)):n.error&&alert(n.error)}catch{}d(null)}async function y(){typeof Notification>`u`||i(await Notification.requestPermission())}function b(){o(!0);try{localStorage.setItem(Ka,`1`)}catch{}}let x=r==="default"&&!a;return(0,S.jsxs)(`span`,{className:`notif-wrap`,children:[(0,S.jsxs)(`button`,{className:`info-btn notif-btn ${m?`has-unread`:``}`,title:m?`${m} item${m===1?``:`s`} need your attention`:`Notifications`,"aria-label":`Notifications`,onClick:()=>t(e=>!e),children:[(0,S.jsx)(C,{name:m?`notifications_active`:`notifications`}),m>0&&(0,S.jsx)(`span`,{className:`notif-badge`,children:m>99?`99+`:m})]}),e&&(0,S.jsxs)(`div`,{className:`info-pop notif-pop`,role:`menu`,children:[(0,S.jsxs)(`div`,{className:`notif-head`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`notifications`}),(0,S.jsx)(`span`,{className:`spacer`}),m>0&&(0,S.jsx)(`button`,{className:`open-raw`,onClick:()=>void h(`/api/notifications/read`),children:`mark all read`}),p.length>0&&(0,S.jsx)(`button`,{className:`open-raw`,onClick:()=>void h(`/api/notifications`),children:`clear`})]}),x&&(0,S.jsxs)(`div`,{className:`notif-hint`,children:[(0,S.jsx)(`span`,{children:`Get a system notification when something needs you, even with this tab in the background.`}),(0,S.jsxs)(`span`,{className:`notif-hint-actions`,children:[(0,S.jsx)(`button`,{className:`ws-btn primary`,onClick:()=>void y(),children:`enable`}),(0,S.jsx)(`button`,{className:`ws-btn`,onClick:b,children:`not now`})]})]}),r===`denied`&&(0,S.jsx)(`div`,{className:`notif-hint muted`,children:`Browser notifications are blocked for this site — allow them in the address bar to get system alerts.`}),p.length===0?(0,S.jsx)(`div`,{className:`notif-empty`,children:`nothing needs you right now`}):(0,S.jsx)(`div`,{className:`notif-list`,children:p.slice(0,50).map(e=>(0,S.jsxs)(`div`,{className:`notif-row ${e.readAt?``:`unread`} ${e.kind}`,role:`button`,tabIndex:0,onClick:()=>g(e),onKeyDown:t=>{t.key===`Enter`&&g(e)},children:[(0,S.jsx)(`span`,{className:`notif-ico`,children:(0,S.jsx)(C,{name:Ga[e.kind]})}),(0,S.jsxs)(`span`,{className:`notif-body`,children:[(0,S.jsx)(`span`,{className:`notif-title`,children:e.title}),e.body&&(0,S.jsx)(`span`,{className:`notif-sub`,children:e.body}),e.diagnose&&(0,S.jsx)(`span`,{className:`notif-actions`,children:(0,S.jsxs)(`button`,{className:`ws-btn notif-diagnose`,disabled:u===e.id,title:`Open a chat that finds the cause and proposes the fix`,onClick:t=>{t.stopPropagation(),_(e)},children:[(0,S.jsx)(C,{name:u===e.id?`progress_activity`:`troubleshoot`,className:`ms-sm`}),u===e.id?`starting…`:`diagnose`]})})]}),(0,S.jsx)(`span`,{className:`notif-when num`,children:ve(e.at)})]},e.id))})]})]})}function Ja(){let[e,t]=(0,v.useState)(!1),[n,r]=(0,v.useState)(null),[i,a]=(0,v.useState)(null),[o,s]=(0,v.useState)(``);(0,v.useEffect)(()=>{if(!e)return;fetch(`/api/runs`).then(e=>e.json()).then(r).catch(()=>{}),fetch(`/api/workflows`).then(e=>e.json()).then(a).catch(()=>{}),fetch(`/api/meta`).then(e=>e.json()).then(e=>s(e.version)).catch(()=>{});let n=e=>{e.target.closest(`.info-wrap`)||t(!1)};return window.addEventListener(`mousedown`,n),()=>window.removeEventListener(`mousedown`,n)},[e]);let c=n?.runs[0];return(0,S.jsxs)(`span`,{className:`info-wrap`,children:[(0,S.jsx)(`button`,{className:`info-btn`,title:`Project info`,"aria-label":`Project info`,onClick:()=>t(e=>!e),children:(0,S.jsx)(C,{name:`info`})}),e&&(0,S.jsxs)(`div`,{className:`info-pop`,children:[(0,S.jsxs)(`div`,{className:`info-row`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`Workflows`}),(0,S.jsx)(`span`,{className:`info-v`,children:i?`${i.workflows.length} discovered`:`…`}),(0,S.jsx)(`code`,{className:`info-path`,title:i?.root,children:i?.root??``})]}),(0,S.jsxs)(`div`,{className:`info-row`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`Runs`}),(0,S.jsxs)(`span`,{className:`info-v`,children:[n?`${n.runs.length} total`:`…`,c?` · latest ${c.status}`:``]}),(0,S.jsx)(`code`,{className:`info-path`,title:n?.outputDir,children:n?.outputDir??``})]}),(0,S.jsxs)(`div`,{className:`info-row info-actions`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`Workspace`}),(0,S.jsxs)(`a`,{className:`update-btn`,href:`#/settings`,onClick:()=>t(!1),children:[(0,S.jsx)(C,{name:`settings`,className:`ms-sm`}),` settings`]})]}),(0,S.jsxs)(`div`,{className:`info-row info-actions`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`Theme`}),(0,S.jsx)(Za,{})]}),(0,S.jsxs)(`div`,{className:`info-row info-actions`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`Version`}),(0,S.jsx)(`span`,{className:`info-v mono`,children:o?`kraftwerk ${o}`:`…`}),(0,S.jsx)(Xa,{})]})]})]})}function Ya(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 Xa(){let[e,t]=(0,v.useState)(`idle`),[n,r]=(0,v.useState)(null);async function i(){t(`busy`);try{let e=await fetch(`/api/update-check`,{cache:`no-store`}),n=await e.json();if(!e.ok||!n.latest)throw Error();r(n),t(`done`)}catch{t(`err`)}}return e===`done`&&n?Ya(n.current,n.latest)?(0,S.jsxs)(`span`,{className:`update-result newer`,children:[`v`,n.latest,` available — `,(0,S.jsxs)(`code`,{children:[`npm i -g `,n.name,`@latest`]})]}):(0,S.jsxs)(`span`,{className:`update-result`,children:[(0,S.jsx)(C,{name:`check`,className:`ms-sm`}),` up to date`]}):(0,S.jsx)(`button`,{className:`update-btn`,disabled:e===`busy`,onClick:()=>void i(),children:e===`busy`?`checking…`:e===`err`?`npm unreachable — retry`:(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(C,{name:`sync`,className:`ms-sm`}),` check for updates`]})})}function Za(){return(0,S.jsx)(`button`,{className:`theme-btn`,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,S.jsx)(v.StrictMode,{children:(0,S.jsx)(Pa,{})}));export{x as a,o as c,ne as i,s as l,C as n,h as o,k as r,d as s,Ma as t,l as u};
217
+ `]})]}):(0,S.jsx)(`div`,{className:`git-diff`,children:`no textual diff (binary or empty)`})}function Ta(){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.useCallback)(async()=>{try{let e=await fetch(`/api/git`,{cache:`no-store`});e.ok&&t(await e.json())}catch{}},[]);(0,v.useEffect)(()=>{let e=!0,t,n=async()=>{await m(),e&&(t=setTimeout(n,6e3))};return n(),()=>{e=!1,clearTimeout(t)}},[m]),(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 h=async(e,t)=>{l(e),d(``),p(``);try{let n=await pe(`/api/git/${e}`,t);n.ok?p(e===`push`?`pushed`:e===`pull`?`pulled`:`fetched`):d(n.error||`${e} failed`)}catch(t){d(t.message||`${e} failed`)}finally{l(``)}m()},g=async()=>{l(`commit`),d(``),p(``);try{let e=await pe(`/api/git/commit`,{paths:[...n],message:o});e.ok?(p(`committed ${n.size} file${n.size===1?``:`s`}`),r(new Set),s(``)):d(e.error||`commit failed`)}catch(e){d(e.message||`commit failed`)}finally{l(``)}m()};if(!e)return(0,S.jsx)(`div`,{className:`settings-screen`,children:(0,S.jsx)(`div`,{className:`ws-empty`,children:`loading…`})});if(!e.enabled)return(0,S.jsxs)(`div`,{className:`settings-screen`,children:[(0,S.jsx)(`div`,{className:`settings-head`,children:(0,S.jsxs)(`h1`,{children:[(0,S.jsx)(C,{name:`cloud_sync`,className:`ms-lg`}),` Git sync`]})}),(0,S.jsx)(`section`,{className:`panel`,children:(0,S.jsxs)(`div`,{className:`ws-empty`,children:[`Git sync is off. Turn it on in `,(0,S.jsx)(`a`,{href:`#/settings`,children:`settings`}),`, or add a `,(0,S.jsx)(`code`,{children:`git:`}),` block to kraftwerk.yml.`]})})]});let _=(e.files??[]).filter(e=>e.syncable),y=(e.files??[]).filter(e=>!e.syncable),b=(e,t)=>r(n=>{let r=new Set(n);return t?r.add(e):r.delete(e),r});return(0,S.jsxs)(`div`,{className:`settings-screen ws-screen`,children:[(0,S.jsxs)(`div`,{className:`settings-head`,children:[(0,S.jsxs)(`h1`,{children:[(0,S.jsx)(C,{name:`cloud_sync`,className:`ms-lg`}),` Git sync`]}),(0,S.jsx)(`span`,{className:`spacer`}),f&&(0,S.jsxs)(`span`,{className:`settings-saved`,children:[(0,S.jsx)(C,{name:`check`,className:`ms-sm`}),` `,f]}),u&&(0,S.jsx)(`span`,{className:`settings-err`,children:u})]}),(0,S.jsxs)(`section`,{className:`panel`,children:[(0,S.jsxs)(`div`,{className:`panel-head`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`branch`}),(0,S.jsx)(`span`,{className:`spacer`}),e.lastFetch&&(0,S.jsxs)(`span`,{className:`settings-note`,title:e.lastFetch,children:[`fetched `,ve(e.lastFetch)]}),e.lastError&&(0,S.jsxs)(`span`,{className:`settings-err git-sync-err`,title:e.lastError,children:[(0,S.jsx)(C,{name:`cloud_off`,className:`ms-sm`}),` `,e.lastError.split(`
218
+ `)[0]]})]}),e.error?(0,S.jsxs)(`div`,{className:`ws-empty ws-load-error`,children:[(0,S.jsx)(C,{name:`error`,className:`ms-sm`}),` `,e.error]}):(0,S.jsxs)(`div`,{className:`git-head`,children:[(0,S.jsxs)(`div`,{className:`git-branch`,children:[(0,S.jsx)(C,{name:`account_tree`,className:`ms-sm`}),(0,S.jsx)(`strong`,{children:e.branch}),e.upstream?(0,S.jsxs)(`span`,{className:`settings-note`,children:[`tracking `,e.upstream]}):(0,S.jsx)(`span`,{className:`settings-note`,children:`no upstream yet, push sets one`})]}),(0,S.jsxs)(`div`,{className:`git-counts`,children:[e.diverged&&(0,S.jsx)(`span`,{className:`git-diverged`,children:`diverged, resolve in a terminal`}),!!e.behind&&(0,S.jsxs)(`span`,{className:`git-behind`,children:[e.behind,` behind`]}),!!e.ahead&&(0,S.jsxs)(`span`,{className:`git-ahead`,children:[e.ahead,` ahead`]}),!e.ahead&&!e.behind&&(0,S.jsx)(`span`,{className:`settings-note`,children:`up to date`})]}),(0,S.jsxs)(`div`,{className:`ws-actions`,children:[(0,S.jsxs)(`button`,{className:`ws-btn`,disabled:!!c,onClick:()=>void h(`fetch`),children:[(0,S.jsx)(C,{name:c===`fetch`?`progress_activity`:`refresh`,className:`ms-sm`}),` fetch`]}),(0,S.jsxs)(`button`,{className:`ws-btn`,disabled:!!c||!e.behind||e.diverged,title:e.diverged?`Diverged. Resolve in a terminal.`:`Fast-forward to the remote`,onClick:()=>void h(`pull`),children:[(0,S.jsx)(C,{name:c===`pull`?`progress_activity`:`download`,className:`ms-sm`}),` pull`]}),(0,S.jsxs)(`button`,{className:`ws-btn primary`,disabled:!!c||!e.ahead&&!!e.upstream,title:e.upstream?`Push to the upstream`:`Push and set the upstream`,onClick:()=>void h(`push`),children:[(0,S.jsx)(C,{name:c===`push`?`progress_activity`:`upload`,className:`ms-sm`}),` push`]})]})]})]}),(0,S.jsxs)(`section`,{className:`panel`,children:[(0,S.jsxs)(`div`,{className:`panel-head`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`changes`}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsx)(`span`,{className:`settings-note`,children:_.length===0?`workspace clean`:`${n.size} of ${_.length} selected`})]}),_.length===0&&y.length===0&&(0,S.jsx)(`div`,{className:`ws-empty`,children:`Nothing changed under the workspace paths.`}),_.map(e=>(0,S.jsxs)(`div`,{className:`git-row`,children:[(0,S.jsx)(`label`,{className:`git-pick`,children:(0,S.jsx)(`input`,{type:`checkbox`,checked:n.has(e.path),onChange:t=>b(e.path,t.target.checked)})}),(0,S.jsxs)(`button`,{className:`git-file`,onClick:()=>a(t=>{let n=new Set(t);return n.has(e.path)?n.delete(e.path):n.add(e.path),n}),children:[(0,S.jsx)(C,{name:i.has(e.path)?`expand_more`:`chevron_right`,className:`ms-sm`}),(0,S.jsx)(`span`,{className:`git-status s-${e.status}`,children:e.status}),(0,S.jsx)(`span`,{className:`git-path`,children:e.path})]}),i.has(e.path)&&(0,S.jsx)(wa,{file:e.path})]},e.path)),_.length>0&&(0,S.jsxs)(`div`,{className:`git-commit`,children:[(0,S.jsx)(`input`,{className:`git-message`,placeholder:`Commit message`,value:o,onChange:e=>s(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!c&&o.trim()&&n.size>0&&g()}}),(0,S.jsx)(`button`,{className:`ws-btn`,disabled:n.size===_.length,onClick:()=>r(new Set(_.map(e=>e.path))),children:`select all`}),(0,S.jsxs)(`button`,{className:`ws-btn primary`,disabled:!!c||n.size===0||!o.trim(),onClick:()=>void g(),children:[(0,S.jsx)(C,{name:c===`commit`?`progress_activity`:`check`,className:`ms-sm`}),`commit `,n.size||``]})]}),y.length>0&&(0,S.jsxs)(`details`,{className:`git-blocked`,children:[(0,S.jsxs)(`summary`,{children:[y.length,e.blockedHidden?`+`:``,` change`,y.length===1&&!e.blockedHidden?``:`s`,` outside the workspace paths`]}),y.map(e=>(0,S.jsxs)(`div`,{className:`git-row blocked`,children:[(0,S.jsx)(`span`,{className:`git-status s-blocked`,children:e.status}),(0,S.jsx)(`span`,{className:`git-path`,children:e.path}),(0,S.jsx)(`span`,{className:`settings-note`,children:e.reason})]},e.path)),!!e.blockedHidden&&(0,S.jsx)(`div`,{className:`git-row blocked`,children:(0,S.jsxs)(`span`,{className:`settings-note`,children:[`and `,e.blockedHidden,` more, not listed`]})})]})]}),(0,S.jsxs)(`p`,{className:`settings-note`,children:[`Synced paths: `,(e.scope??[]).map((e,t)=>(0,S.jsxs)(`span`,{children:[t>0&&`, `,(0,S.jsx)(`code`,{children:e})]},e)),`. Run artifacts and files like `,(0,S.jsx)(`code`,{children:`.env`}),` are never staged.`,` `,e.interval?`Fetches every ${xa(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 Ea=e=>e.replace(/^https?:\/\//,``).replace(/^git@([^:]+):/,`$1/`).replace(/\.git$/,``),Da=e=>e.error?{label:`unreadable`,cls:`missing`}:e.dirty?{label:`${e.dirty} changed`,cls:`died`}:e.ahead?{label:`${e.ahead} to push`,cls:`running`}:e.behind?{label:`${e.behind} behind`,cls:`stopped`}:{label:`clean`,cls:`running`},Oa=e=>!!(e.error||e.dirty||e.ahead===void 0||e.ahead);function ka(){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=N(),w=(0,v.useCallback)(async()=>{try{let e=await fetch(`/api/repos`,{cache:`no-store`});if(!e.ok)throw Error(`HTTP ${e.status}`);t(await e.json()),r(``)}catch(e){r(e.message||`could not load repositories`)}},[]);(0,v.useEffect)(()=>{let e=!0,t,n=async()=>{await w(),e&&(t=setTimeout(n,15e3))};return n(),()=>{e=!1,clearTimeout(t)}},[w]);let T=async(e,t,n=!1)=>{a(n=>({...n,[e]:t})),s(t=>({...t,[e]:``})),l(null);try{let r=t===`update`?await fetch(`/api/repos/${encodeURIComponent(e)}/update`,{method:`POST`}):await fetch(`/api/repos/${encodeURIComponent(e)}${n?`?force=1`:``}`,{method:`DELETE`}),i=await r.json();if(!r.ok||!i.ok)throw Error(i.error||`failed`);i.error&&s(t=>({...t,[e]:i.error}))}catch(t){s(n=>({...n,[e]:t.message}))}finally{a(t=>{let n={...t};return delete n[e],n}),w()}},E=async e=>{if(e.preventDefault(),u.trim()&&!g){_(!0),b(``);try{let e=await fetch(`/api/repos`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({url:u.trim(),name:f.trim()||void 0,branch:m.trim()||void 0})}),t=await e.json();if(!e.ok)throw Error(t.error||`clone failed`);d(``),p(``),h(``),await w()}catch(e){b(e.message)}finally{_(!1)}}},D=[...e?.repos??[]].sort((e,t)=>(t.updatedAt??``).localeCompare(e.updatedAt??``));return(0,S.jsxs)(`div`,{className:`settings-screen ws-screen repos-screen`,children:[(0,S.jsxs)(`div`,{className:`settings-head`,children:[(0,S.jsxs)(`h1`,{children:[(0,S.jsx)(C,{name:`source`,className:`ms-lg`}),` Repositories`]}),(0,S.jsx)(`span`,{className:`spacer`}),e?.enabled&&(0,S.jsxs)(`span`,{className:`settings-note`,children:[D.length,` cloned`]}),n&&(0,S.jsx)(`span`,{className:`settings-err`,children:n})]}),e&&!e.enabled&&(0,S.jsx)(`section`,{className:`panel`,children:(0,S.jsx)(`div`,{className:`ws-empty`,children:e.error&&!/are off/.test(e.error)?(0,S.jsx)(`span`,{className:`settings-err`,children:e.error}):(0,S.jsxs)(S.Fragment,{children:[`Repositories are off. Turn them on in `,(0,S.jsx)(`a`,{href:`#/settings`,children:`settings`}),` or add a `,(0,S.jsx)(`code`,{children:`repos:`}),` block to kraftwerk.yml.`]})})}),e?.enabled&&(0,S.jsxs)(`section`,{className:`panel`,children:[(0,S.jsxs)(`div`,{className:`panel-head`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`add a repository`}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsxs)(`span`,{className:`settings-note`,children:[`clones into `,(0,S.jsx)(`code`,{title:e.root,children:e.root})]})]}),(0,S.jsxs)(`form`,{className:`agent-form`,onSubmit:e=>void E(e),children:[(0,S.jsxs)(`div`,{className:`agent-form-row`,children:[(0,S.jsxs)(`label`,{className:`agent-field`,style:{flex:2},children:[`url`,(0,S.jsx)(`input`,{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,S.jsxs)(`label`,{className:`agent-field`,style:{flex:1},children:[`name`,(0,S.jsx)(`input`,{value:f,placeholder:`from the url`,onChange:e=>p(e.target.value)})]}),(0,S.jsxs)(`label`,{className:`agent-field`,style:{width:140},children:[`branch`,(0,S.jsx)(`input`,{value:m,placeholder:`default`,onChange:e=>h(e.target.value)})]}),(0,S.jsxs)(`button`,{className:`ws-btn primary`,type:`submit`,disabled:g||!u.trim(),children:[(0,S.jsx)(C,{name:g?`progress_activity`:`download`,className:`ms-sm`}),g?`cloning…`:`clone`]})]}),y&&(0,S.jsx)(`div`,{className:`settings-err`,children:y}),(0,S.jsxs)(`div`,{className:`settings-note`,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,S.jsx)(`code`,{children:`kraftwerk repos add`}),`.`]})]})]}),e?.enabled&&(0,S.jsxs)(`section`,{className:`panel`,children:[(0,S.jsx)(`div`,{className:`panel-head`,children:(0,S.jsx)(`span`,{className:`microlabel`,children:`cloned repositories · newest change first`})}),D.length===0&&(0,S.jsx)(`div`,{className:`ws-empty`,children:`Nothing cloned yet.`}),D.map(e=>{let t=i[e.slug],n=Da(e);return(0,S.jsxs)(`div`,{className:`ws-row repo-row state-${n.cls}`,"data-repo":e.slug,children:[(0,S.jsx)(`span`,{className:`switcher-icon ws-icon`,children:(0,S.jsx)(C,{name:`folder_data`})}),(0,S.jsxs)(`div`,{className:`ws-main`,children:[(0,S.jsxs)(`div`,{className:`ws-title`,children:[(0,S.jsx)(`span`,{className:`ws-name`,children:e.slug}),e.branch&&(0,S.jsx)(`span`,{className:`repo-branch`,children:e.branch}),(0,S.jsx)(`span`,{className:`ws-state ws-state-${n.cls}`,children:n.label}),e.updatedAt&&(0,S.jsxs)(`span`,{className:`vibeable-when`,title:e.updatedAt,children:[`changed `,ve(e.updatedAt)]})]}),e.url&&(0,S.jsx)(`div`,{className:`ws-root`,title:e.url,children:Ea(e.url)}),x&&(0,S.jsx)(`div`,{className:`ws-root ws-dim`,title:e.path,children:e.path}),(0,S.jsxs)(`div`,{className:`ws-meta`,children:[e.head&&(0,S.jsxs)(`span`,{title:e.committedAt,children:[(0,S.jsx)(`code`,{children:e.head}),` `,e.subject,e.committedAt?` · ${ve(e.committedAt)}`:``]}),!!e.behind&&!!e.dirty&&(0,S.jsxs)(`span`,{children:[`behind by `,e.behind]}),e.error&&(0,S.jsx)(`span`,{className:`settings-err`,children:e.error})]}),o[e.slug]&&(0,S.jsx)(`div`,{className:`settings-err`,children:o[e.slug]})]}),(0,S.jsxs)(`div`,{className:`ws-actions`,children:[(0,S.jsxs)(`button`,{className:`ws-btn`,disabled:!!t,onClick:()=>void T(e.slug,`update`),title:`git fetch, then fast-forward when clean`,children:[(0,S.jsx)(C,{name:t===`update`?`progress_activity`:`sync`,className:`ms-sm`}),t===`update`?`updating…`:`update`]}),c!==e.slug&&(0,S.jsxs)(`button`,{className:`ws-btn`,disabled:!!t,onClick:()=>l(e.slug),title:`Delete the clone`,children:[(0,S.jsx)(C,{name:`delete`,className:`ms-sm`}),` remove`]}),c===e.slug&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`button`,{className:`ws-btn danger`,onClick:()=>void T(e.slug,`remove`,Oa(e)),children:[(0,S.jsx)(C,{name:`delete`,className:`ms-sm`}),e.dirty||e.ahead?`delete with local changes`:Oa(e)?`delete anyway`:`confirm remove`]}),(0,S.jsx)(`button`,{className:`ws-btn`,onClick:()=>l(null),children:`cancel`})]})]})]},e.slug)})]})]})}var Aa=40,ja=/Mac|iPhone|iPad/.test(navigator.platform),Ma=null,Na=e=>(e?.workspaces??[]).flatMap(e=>e.agents.map(t=>({agent:t,ws:e,key:`${e.url}|${t.slug}`})));function Pa(e,t){let n=t.toLowerCase().split(/\s+/).filter(Boolean);if(n.length===0)return e;let r=[];for(let t of e){let e=t.agent.name.toLowerCase(),i=[e,t.agent.slug,t.agent.description??``,t.agent.group??``,t.ws.name].join(` `).toLowerCase();if(!n.every(e=>i.includes(e)))continue;let a=e.startsWith(n[0])?0:e.includes(n[0])?1:2;r.push({hit:t,score:a})}return r.sort((e,t)=>e.score-t.score).map(e=>e.hit)}async function Fa(e){let t=`/agents/${encodeURIComponent(e.agent.slug)}`;if(e.ws.current)return k(t);let n=e.ws.live||!e.ws.root?e.ws.url:await re(e.ws.root);window.location.assign(`${n.replace(/\/+$/,``)}/#${t}`)}function Ia(){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,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`button`,{type:`button`,className:`search-btn`,onClick:()=>t(!0),title:`jump to an agent`,"aria-label":`search agents`,children:[(0,S.jsx)(C,{name:`search`}),(0,S.jsx)(`kbd`,{className:`kbd`,children:ja?`⌘K`:`Ctrl K`})]}),e&&(0,S.jsx)(La,{onClose:()=>t(!1)})]})}function La({onClose:e}){let[t,n]=(0,v.useState)(Ma),[r,i]=(0,v.useState)(Ma===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 fetch(`/api/search/agents`,{cache:`no-store`}).then(e=>e.ok?e.json():Promise.reject(Error(String(e.status)))).then(t=>{Ma=t,e&&n(t)}).catch(()=>e&&o(!0)).finally(()=>e&&i(!1)),()=>{e=!1}},[]);let g=(0,v.useMemo)(()=>Na(t),[t]),_=(0,v.useMemo)(()=>Pa(g,s).slice(0,Aa),[g,s]),y=Math.min(l,Math.max(_.length-1,0));(0,v.useEffect)(()=>{(h.current?.children[y])?.scrollIntoView({block:`nearest`})},[y,_]);let b=t=>{if(!d){if(t.ws.current||t.ws.live){e(),Fa(t);return}f(t.key),m(``),Fa(t).catch(e=>{f(null),m(`${t.ws.name}: ${e.message}`)})}},x=t=>{if(t.key===`ArrowDown`)t.preventDefault(),u(_.length?(y+1)%_.length:0);else if(t.key===`ArrowUp`)t.preventDefault(),u(_.length?(y-1+_.length)%_.length:0);else if(t.key===`Enter`){t.preventDefault();let e=_[y];e&&b(e)}else t.key===`Escape`&&(t.preventDefault(),e())},w;return w=_.length>0?(0,S.jsx)(`ul`,{className:`palette-list`,role:`listbox`,"aria-label":`agents`,ref:h,children:_.map((e,t)=>(0,S.jsxs)(`li`,{role:`option`,"aria-selected":t===y,className:`palette-item${t===y?` active`:``}`,onMouseMove:()=>t!==y&&u(t),onClick:()=>b(e),children:[(0,S.jsx)(`span`,{className:`palette-emoji`,"aria-hidden":!0,children:e.agent.emoji}),(0,S.jsxs)(`span`,{className:`palette-text`,children:[(0,S.jsx)(`span`,{className:`palette-name`,children:e.agent.name}),e.agent.description&&(0,S.jsx)(`span`,{className:`palette-sub`,children:e.agent.description})]}),(0,S.jsxs)(`span`,{className:`palette-ws`,title:e.ws.current?`this workspace`:e.ws.url,children:[e.ws.icon&&(0,S.jsx)(`span`,{"aria-hidden":!0,children:e.ws.icon}),e.ws.name,d===e.key?(0,S.jsx)(C,{name:`progress_activity`,className:`ms-sm`}):e.ws.live?!e.ws.current&&(0,S.jsx)(C,{name:`open_in_new`,className:`ms-sm`}):(0,S.jsx)(`span`,{className:`palette-chip`,children:`stopped`})]})]},e.key))}):a?(0,S.jsx)(`div`,{className:`palette-empty`,children:`could not load the agents`}):r?(0,S.jsx)(`div`,{className:`palette-empty`,children:`looking for agents…`}):g.length===0?(0,S.jsxs)(`div`,{className:`palette-empty`,children:[`no agents yet — `,(0,S.jsx)(`a`,{href:`#/agents/new`,onClick:e,children:`create one`})]}):(0,S.jsxs)(`div`,{className:`palette-empty`,children:[`no agent matches “`,s,`”`]}),(0,S.jsx)(`div`,{className:`palette-backdrop`,onMouseDown:e,children:(0,S.jsxs)(`div`,{className:`palette`,role:`dialog`,"aria-label":`jump to an agent`,onMouseDown:e=>e.stopPropagation(),onKeyDown:x,children:[(0,S.jsxs)(`div`,{className:`palette-input`,children:[(0,S.jsx)(C,{name:`search`}),(0,S.jsx)(`input`,{autoFocus:!0,value:s,onChange:e=>{c(e.target.value),u(0)},placeholder:`jump to an agent…`,"aria-label":`search agents`,autoComplete:`off`,spellCheck:!1}),r&&t&&(0,S.jsx)(C,{name:`progress_activity`,className:`ms-sm`}),(0,S.jsx)(`kbd`,{className:`kbd`,children:`esc`})]}),w,(0,S.jsxs)(`div`,{className:`palette-foot`,children:[(0,S.jsxs)(`span`,{children:[(0,S.jsx)(`kbd`,{className:`kbd`,children:`↑`}),(0,S.jsx)(`kbd`,{className:`kbd`,children:`↓`}),` move`]}),(0,S.jsxs)(`span`,{children:[(0,S.jsx)(`kbd`,{className:`kbd`,children:`↵`}),` open`]}),d&&(0,S.jsxs)(`span`,{className:`palette-note`,children:[(0,S.jsx)(C,{name:`progress_activity`,className:`ms-sm`}),` starting the workspace…`]}),p&&(0,S.jsxs)(`span`,{className:`palette-warn`,title:p,children:[(0,S.jsx)(C,{name:`warning`,className:`ms-sm`}),` `,p]})]})]})})}var Ra=`modulepreload`,za=function(e){return`/`+e},Ba={},Va=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e=document.getElementsByTagName(`link`),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?import.meta.resolve(e):new URL(e,import.meta.url).href}r=o(t.map(t=>{if(t=za(t,n),t=s(t),t in Ba)return;Ba[t]=!0;let r=t.endsWith(`.css`);for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.href===t&&(!r||i.rel===`stylesheet`))return}let i=document.createElement(`link`);if(i.rel=r?`stylesheet`:Ra,r||(i.as=`script`),i.crossOrigin=``,i.href=t,a&&i.setAttribute(`nonce`,a),document.head.appendChild(i),r)return new Promise((e,n)=>{i.addEventListener(`load`,e),i.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${t}`)))})}))}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)})},Ha=(0,v.lazy)(()=>Va(()=>import(`./editor-BiyVJ7Wz.js`).then(e=>({default:e.EditorScreen})),__vite__mapDeps([0,1,2,3,4,5,6])));function Ua(){let e=w().split(`/`).filter(Boolean),[t,n]=(0,v.useState)(``),[r,i]=(0,v.useState)(``),[a,o]=(0,v.useState)(``),[s,c]=(0,v.useState)(!0),[l,u]=(0,v.useState)(``),[d,f]=(0,v.useState)(``),[p,m]=(0,v.useState)(!1),[h,g]=(0,v.useState)(!1),[_,y]=(0,v.useState)(!1),[b,x]=(0,v.useState)([]);(0,v.useEffect)(()=>{let e=!0,t,r=async()=>{try{let t=await fetch(`/api/meta`,{cache:`no-store`}).then(e=>e.json());if(!e)return;n(t.projectName??``),i(t.projectIcon??``),o(t.projectColor??``),c(t.projectNamed!==!1),u(t.projectRootLabel??``),f(t.projectRoot??``),m(!!t.git),g(!!t.repos),y(!!t.vibeables),ce({git:!!t.git,repos:!!t.repos,vibeables:!!t.vibeables}),x(Array.isArray(t.switcher)?t.switcher:[])}catch{}e&&(t=setTimeout(r,3e4))};r();let a=()=>{clearTimeout(t),r()};return window.addEventListener(`kw-meta-refresh`,a),()=>{e=!1,clearTimeout(t),window.removeEventListener(`kw-meta-refresh`,a)}},[]),(0,v.useEffect)(()=>{if(te(t?`${t} — kraftwerk`:`kraftwerk inspector`),!r)return;let e=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><text y="0.9em" font-size="85">${r}</text></svg>`,n=document.querySelector(`link[rel="icon"]`);n||(n=document.createElement(`link`),n.rel=`icon`,document.head.appendChild(n)),n.href=`data:image/svg+xml,${encodeURIComponent(e)}`},[t,r]);let T;return T=e[0]===`runs`&&e[1]?(0,S.jsx)(ni,{id:e[1]}):e[0]===`runs`?(0,S.jsx)(Za,{}):e[0]===`workflows`&&e[1]?(0,S.jsx)(_i,{slug:decodeURIComponent(e[1])}):e[0]===`workflows`?(0,S.jsx)(gi,{}):e[0]===`chats`?(0,S.jsx)(ta,{seg:e}):e[0]===`skills`?(0,S.jsx)(Xi,{name:e[1]?decodeURIComponent(e[1]):void 0}):e[0]===`settings`?(0,S.jsx)(va,{}):e[0]===`workspaces`?(0,S.jsx)(ba,{}):e[0]===`git`?(0,S.jsx)(Ta,{}):e[0]===`repos`?(0,S.jsx)(ka,{}):e[0]===`vibeables`?(0,S.jsx)(Ir,{}):e[0]===`agents`||e[0]===`team`?(0,S.jsx)(ta,{seg:e.slice(1)}):e[0]===`channels`?(0,S.jsx)(Lr,{seg:e.slice(1)}):e[0]===`knowledge`?(0,S.jsx)(Li,{bundle:e[1]?decodeURIComponent(e[1]):void 0,conceptId:e.length>2?e.slice(2).map(decodeURIComponent).join(`/`):void 0}):(0,S.jsx)(Di,{}),e[0]===`edit`&&e[1]&&e.length>2?(0,S.jsx)(v.Suspense,{fallback:(0,S.jsx)(`div`,{className:`empty`,children:`loading editor…`}),children:(0,S.jsx)(Ha,{bundle:decodeURIComponent(e[1]),conceptId:e.slice(2).map(decodeURIComponent).join(`/`)},e.slice(1).join(`/`))}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`header`,{className:`topbar`,style:{"--ws-c":ue(a,d||t)},children:[(0,S.jsxs)(`span`,{className:`wordmark`,children:[(0,S.jsx)(`a`,{href:`#/`,className:`home-link`,title:`Dashboard`,children:t?(0,S.jsx)(fe,{className:`home-tile`,icon:r,name:t,color:a,seed:d||t}):(0,S.jsx)(C,{name:`home`})}),t&&(0,S.jsx)(Xa,{name:t,icon:r,color:a,named:s,root:l,seed:d||t,entries:b})]}),(0,S.jsxs)(`nav`,{children:[(0,S.jsxs)(`a`,{href:`#/agents`,children:[(0,S.jsx)(C,{name:`groups`}),` agents`]}),(0,S.jsxs)(`a`,{href:`#/channels`,children:[(0,S.jsx)(C,{name:`forum`}),` channels`]}),(0,S.jsxs)(`a`,{href:`#/knowledge`,children:[(0,S.jsx)(C,{name:`menu_book`}),` context & knowledge`]}),(0,S.jsxs)(`a`,{href:`#/workflows`,children:[(0,S.jsx)(C,{name:`account_tree`}),` workflows`]}),(0,S.jsxs)(`a`,{href:`#/runs`,children:[(0,S.jsx)(C,{name:`history`}),` workflow runs`]}),(0,S.jsxs)(`a`,{href:`#/skills`,children:[(0,S.jsx)(C,{name:`extension`}),` skills`]}),h&&(0,S.jsxs)(`a`,{href:`#/repos`,children:[(0,S.jsx)(C,{name:`source`}),` repositories`]}),_&&(0,S.jsxs)(`a`,{href:`#/vibeables`,children:[(0,S.jsx)(C,{name:`web`}),` vibeables`]}),p&&(0,S.jsx)(Wa,{})]}),(0,S.jsx)(`span`,{className:`spacer`}),(0,S.jsx)(Ia,{}),(0,S.jsx)(no,{}),(0,S.jsx)(Qa,{}),(0,S.jsx)($a,{}),(0,S.jsx)(ro,{})]}),(0,S.jsx)(`main`,{className:`shell`,children:T})]})}function Wa(){let e=F(`/api/git`,!1,15e3),t=e?.files?.filter(e=>e.syncable).length??0;return(0,S.jsxs)(`a`,{href:`#/git`,children:[(0,S.jsx)(C,{name:`cloud_sync`}),` git`,!!e?.behind&&(0,S.jsxs)(`span`,{className:`git-badge behind`,children:[e.behind,`↓`]}),!!e?.ahead&&(0,S.jsxs)(`span`,{className:`git-badge ahead`,children:[e.ahead,`↑`]}),!e?.ahead&&!e?.behind&&!!t&&(0,S.jsx)(`span`,{className:`git-badge dirty`,children:t})]})}function Ga(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?:\/\//,``)}}function Ka({label:e}){return e?(0,S.jsx)(`span`,{className:`switcher-root`,title:e,children:(0,S.jsx)(`span`,{dir:`ltr`,children:e})}):null}function qa({name:e,named:t}){let n=t===!1;return(0,S.jsx)(`span`,{className:`switcher-name${n?` unnamed`:``}`,title:n?`${e} — folder name; set name: in kraftwerk.yml`:e,children:e})}function Ja({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 re(e.root))}catch(e){r(`error`),a(e.message)}};return(0,S.jsxs)(`span`,{className:`switcher-item stopped ${o?`missing`:``}`,role:`menuitem`,style:{"--ws-c":ue(e.color,e.root??e.url)},children:[(0,S.jsx)(fe,{icon:e.icon,name:e.name,color:e.color,seed:e.root??e.url,ambiguous:t}),(0,S.jsxs)(`span`,{className:`switcher-text`,children:[(0,S.jsx)(qa,{name:e.name,named:e.named}),n===`error`?(0,S.jsx)(`span`,{className:`switcher-sub switcher-err`,title:i,children:i}):o?(0,S.jsx)(`span`,{className:`switcher-sub`,children:`folder missing`}):(0,S.jsx)(Ka,{label:e.rootLabel})]}),(0,S.jsxs)(`span`,{className:`switcher-side`,children:[(0,S.jsx)(`span`,{className:`switcher-port`,children:Ga(e.url)}),(0,S.jsxs)(`button`,{className:`switcher-start`,disabled:o||n===`starting`,title:o?`The project folder no longer exists`:`Start the UI for this project`,onClick:e=>{e.stopPropagation(),s()},children:[n===`starting`?(0,S.jsx)(C,{name:`progress_activity`}):(0,S.jsx)(C,{name:`play_arrow`}),n===`starting`?`starting`:`start`]})]})]})}function Ya({entry:e,ambiguous:t}){let n=e.root??e.url;return(0,S.jsxs)(`a`,{className:`switcher-item${e.live?` live`:``}`,role:`menuitem`,href:e.url,style:{"--ws-c":ue(e.color,n)},children:[(0,S.jsx)(fe,{icon:e.icon,name:e.name,color:e.color,seed:n,ambiguous:t}),(0,S.jsxs)(`span`,{className:`switcher-text`,children:[(0,S.jsx)(qa,{name:e.name,named:e.named}),(0,S.jsx)(Ka,{label:e.rootLabel??(e.root?void 0:e.url.replace(/^https?:\/\//,``))})]}),(0,S.jsx)(`span`,{className:`switcher-side`,children:(0,S.jsxs)(`span`,{className:`switcher-port`,children:[e.live&&(0,S.jsx)(`span`,{className:`live-dot`,title:`running`}),Ga(e.url)]})})]})}function Xa({name:e,icon:t,color:n,named:r,root:i,seed:a,entries:o}){let[s,c]=(0,v.useState)(!1),l=N();if((0,v.useEffect)(()=>{if(!s)return;let e=e=>{e.target.closest(`.switcher-wrap`)||c(!1)};return window.addEventListener(`mousedown`,e),()=>window.removeEventListener(`mousedown`,e)},[s]),o.length===0)return(0,S.jsx)(`span`,{className:`env-name`,title:i||`Project (kraftwerk.yml: name)`,children:e});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,S.jsxs)(`span`,{className:`switcher-wrap`,children:[(0,S.jsxs)(`button`,{className:`env-name env-switch`,title:i?`${i} — switch workspace`:`Switch workspace`,"aria-haspopup":`menu`,"aria-expanded":s,onClick:()=>c(e=>!e),children:[e,(0,S.jsx)(C,{name:`expand_more`})]}),s&&(0,S.jsxs)(`div`,{className:`switcher-pop`,role:`menu`,children:[(0,S.jsx)(`div`,{className:`switcher-head`,children:`Workspaces`}),(0,S.jsxs)(`span`,{className:`switcher-item current`,"aria-current":`true`,style:{"--ws-c":ue(n,p)},children:[(0,S.jsx)(fe,{icon:t,name:e,color:n,seed:p,ambiguous:d(t)}),(0,S.jsxs)(`span`,{className:`switcher-text`,children:[(0,S.jsx)(qa,{name:e,named:r}),i?(0,S.jsx)(Ka,{label:i}):(0,S.jsx)(`span`,{className:`switcher-sub`,children:`this workspace`})]}),(0,S.jsx)(`span`,{className:`switcher-side`,children:(0,S.jsx)(C,{name:`check`,className:`switcher-check`})})]}),f.map(e=>(0,S.jsxs)(`div`,{className:`switcher-group switcher-group-${e.key}`,role:`group`,"aria-label":e.label,children:[(0,S.jsx)(`div`,{className:`switcher-group-head`,children:e.label}),e.items.map(e=>e.live===!1&&e.root?(0,S.jsx)(Ja,{entry:e,ambiguous:d(e.icon)},e.root):(0,S.jsx)(Ya,{entry:e,ambiguous:d(e.icon)},e.root??e.url))]},e.key)),l&&(0,S.jsxs)(`a`,{className:`switcher-foot`,href:`#/workspaces`,role:`menuitem`,onClick:()=>c(!1),children:[(0,S.jsx)(C,{name:`hub`}),` manage workspaces`]})]})]})}function Za(){let[e,t]=(0,v.useState)(null);return(0,v.useEffect)(()=>{let e=!0;return fetch(`/api/runs`).then(e=>e.json()).then(n=>{e&&(n.runs.length>0?k(`/runs/${n.runs[0].id}`,{replace:!0}):t({outputDir:n.outputDir}))}).catch(()=>{}),()=>{e=!1}},[]),e?(0,S.jsxs)(`div`,{className:`empty`,children:[`No runs found in `,(0,S.jsx)(`code`,{children:e.outputDir}),`. Start one with`,` `,(0,S.jsx)(`code`,{children:`kraftwerk run <workflow> <request>`}),` or from a workflow page.`]}):(0,S.jsx)(`div`,{className:`empty`,children:`loading…`})}function Qa(){let[e,t]=(0,v.useState)(null),[n,r]=(0,v.useState)(!1);(0,v.useEffect)(()=>{let e=!0,n,r=async()=>{try{let n=await fetch(`/api/meta`,{cache:`no-store`}).then(e=>e.json());e&&t(n)}catch{}e&&(n=setTimeout(r,3e4))};return r(),()=>{e=!1,clearTimeout(n)}},[]);let i=e?.restartable&&e.diskVersion&&e.diskVersion!==e.version?e.diskVersion:null;async function a(){if(i){r(!0),await fetch(`/api/restart`,{method:`POST`}).catch(()=>{});for(let e=0;e<60;e++){await new Promise(e=>setTimeout(e,500));try{if((await fetch(`/api/meta`,{cache:`no-store`}).then(e=>e.json())).version===i)break}catch{}}location.reload()}}return!i&&!n?null:(0,S.jsx)(`button`,{className:`relaunch-note`,disabled:n,title:`v${i} is installed on disk, the server still runs v${e?.version}. Click to relaunch with the new version.`,onClick:()=>void a(),children:n?`relaunching…`:(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(C,{name:`restart_alt`,className:`ms-sm`}),` v`,i,` ready — relaunch`]})})}function $a(){let e=N();return(0,S.jsxs)(`button`,{className:`expert-toggle ${e?`on`:``}`,title:e?`Expert mode on — full detail`:`Expert mode off — simplified view`,"aria-pressed":e,onClick:()=>ae(!e),children:[(0,S.jsx)(`span`,{className:`expert-track`,children:(0,S.jsx)(`span`,{className:`expert-knob`})}),`expert`]})}var eo={approval:`gavel`,routine_done:`schedule`,routine_failed:`schedule`,run_done:`account_tree`,run_failed:`account_tree`},to=`kw.notif.toast.dismissed`;function no(){let[e,t]=(0,v.useState)(!1),n=F(`/api/notifications`,!1,5e3),[r,i]=(0,v.useState)(()=>typeof Notification>`u`?`unsupported`:Notification.permission),[a,o]=(0,v.useState)(()=>{try{return localStorage.getItem(to)===`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,p=f?.items??[],m=f?.unread??0;(0,v.useEffect)(()=>ee(m),[m]),(0,v.useEffect)(()=>{if(n){if(!s.current){s.current=new Set(p.map(e=>e.id));return}for(let e of p)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(),g(e),t.close()}}catch{}}},[n]),(0,v.useEffect)(()=>{if(!e)return;let n=e=>{e.target.closest(`.notif-wrap`)||t(!1)};return window.addEventListener(`mousedown`,n),()=>window.removeEventListener(`mousedown`,n)},[e]);async function h(e,t){try{let n=await fetch(e,{method:e.endsWith(`/notifications`)?`DELETE`:`POST`,headers:{"content-type":`application/json`},body:t===void 0?void 0:JSON.stringify(t)});if(!n.ok)return;let r=await n.json();l(`items`in r?r:{items:[],unread:0})}catch{}}function g(e){t(!1),e.readAt||h(`/api/notifications/read`,{ids:[e.id]}),k(e.href)}async function _(e){d(e.id);try{let n=await(await fetch(`/api/notifications/${encodeURIComponent(e.id)}/diagnose`,{method:`POST`})).json();n.href?(t(!1),k(n.href)):n.error&&alert(n.error)}catch{}d(null)}async function y(){typeof Notification>`u`||i(await Notification.requestPermission())}function b(){o(!0);try{localStorage.setItem(to,`1`)}catch{}}let x=r==="default"&&!a;return(0,S.jsxs)(`span`,{className:`notif-wrap`,children:[(0,S.jsxs)(`button`,{className:`info-btn notif-btn ${m?`has-unread`:``}`,title:m?`${m} item${m===1?``:`s`} need your attention`:`Notifications`,"aria-label":`Notifications`,onClick:()=>t(e=>!e),children:[(0,S.jsx)(C,{name:m?`notifications_active`:`notifications`}),m>0&&(0,S.jsx)(`span`,{className:`notif-badge`,children:m>99?`99+`:m})]}),e&&(0,S.jsxs)(`div`,{className:`info-pop notif-pop`,role:`menu`,children:[(0,S.jsxs)(`div`,{className:`notif-head`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`notifications`}),(0,S.jsx)(`span`,{className:`spacer`}),m>0&&(0,S.jsx)(`button`,{className:`open-raw`,onClick:()=>void h(`/api/notifications/read`),children:`mark all read`}),p.length>0&&(0,S.jsx)(`button`,{className:`open-raw`,onClick:()=>void h(`/api/notifications`),children:`clear`})]}),x&&(0,S.jsxs)(`div`,{className:`notif-hint`,children:[(0,S.jsx)(`span`,{children:`Get a system notification when something needs you, even with this tab in the background.`}),(0,S.jsxs)(`span`,{className:`notif-hint-actions`,children:[(0,S.jsx)(`button`,{className:`ws-btn primary`,onClick:()=>void y(),children:`enable`}),(0,S.jsx)(`button`,{className:`ws-btn`,onClick:b,children:`not now`})]})]}),r===`denied`&&(0,S.jsx)(`div`,{className:`notif-hint muted`,children:`Browser notifications are blocked for this site — allow them in the address bar to get system alerts.`}),p.length===0?(0,S.jsx)(`div`,{className:`notif-empty`,children:`nothing needs you right now`}):(0,S.jsx)(`div`,{className:`notif-list`,children:p.slice(0,50).map(e=>(0,S.jsxs)(`div`,{className:`notif-row ${e.readAt?``:`unread`} ${e.kind}`,role:`button`,tabIndex:0,onClick:()=>g(e),onKeyDown:t=>{t.key===`Enter`&&g(e)},children:[(0,S.jsx)(`span`,{className:`notif-ico`,children:(0,S.jsx)(C,{name:eo[e.kind]})}),(0,S.jsxs)(`span`,{className:`notif-body`,children:[(0,S.jsx)(`span`,{className:`notif-title`,children:e.title}),e.body&&(0,S.jsx)(`span`,{className:`notif-sub`,children:e.body}),e.diagnose&&(0,S.jsx)(`span`,{className:`notif-actions`,children:(0,S.jsxs)(`button`,{className:`ws-btn notif-diagnose`,disabled:u===e.id,title:`Open a chat that finds the cause and proposes the fix`,onClick:t=>{t.stopPropagation(),_(e)},children:[(0,S.jsx)(C,{name:u===e.id?`progress_activity`:`troubleshoot`,className:`ms-sm`}),u===e.id?`starting…`:`diagnose`]})})]}),(0,S.jsx)(`span`,{className:`notif-when num`,children:ve(e.at)})]},e.id))})]})]})}function ro(){let[e,t]=(0,v.useState)(!1),[n,r]=(0,v.useState)(null),[i,a]=(0,v.useState)(null),[o,s]=(0,v.useState)(``);(0,v.useEffect)(()=>{if(!e)return;fetch(`/api/runs`).then(e=>e.json()).then(r).catch(()=>{}),fetch(`/api/workflows`).then(e=>e.json()).then(a).catch(()=>{}),fetch(`/api/meta`).then(e=>e.json()).then(e=>s(e.version)).catch(()=>{});let n=e=>{e.target.closest(`.info-wrap`)||t(!1)};return window.addEventListener(`mousedown`,n),()=>window.removeEventListener(`mousedown`,n)},[e]);let c=n?.runs[0];return(0,S.jsxs)(`span`,{className:`info-wrap`,children:[(0,S.jsx)(`button`,{className:`info-btn`,title:`Project info`,"aria-label":`Project info`,onClick:()=>t(e=>!e),children:(0,S.jsx)(C,{name:`info`})}),e&&(0,S.jsxs)(`div`,{className:`info-pop`,children:[(0,S.jsxs)(`div`,{className:`info-row`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`Workflows`}),(0,S.jsx)(`span`,{className:`info-v`,children:i?`${i.workflows.length} discovered`:`…`}),(0,S.jsx)(`code`,{className:`info-path`,title:i?.root,children:i?.root??``})]}),(0,S.jsxs)(`div`,{className:`info-row`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`Runs`}),(0,S.jsxs)(`span`,{className:`info-v`,children:[n?`${n.runs.length} total`:`…`,c?` · latest ${c.status}`:``]}),(0,S.jsx)(`code`,{className:`info-path`,title:n?.outputDir,children:n?.outputDir??``})]}),(0,S.jsxs)(`div`,{className:`info-row info-actions`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`Workspace`}),(0,S.jsxs)(`a`,{className:`update-btn`,href:`#/settings`,onClick:()=>t(!1),children:[(0,S.jsx)(C,{name:`settings`,className:`ms-sm`}),` settings`]})]}),(0,S.jsxs)(`div`,{className:`info-row info-actions`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`Theme`}),(0,S.jsx)(oo,{})]}),(0,S.jsxs)(`div`,{className:`info-row info-actions`,children:[(0,S.jsx)(`span`,{className:`microlabel`,children:`Version`}),(0,S.jsx)(`span`,{className:`info-v mono`,children:o?`kraftwerk ${o}`:`…`}),(0,S.jsx)(ao,{})]})]})]})}function io(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 ao(){let[e,t]=(0,v.useState)(`idle`),[n,r]=(0,v.useState)(null);async function i(){t(`busy`);try{let e=await fetch(`/api/update-check`,{cache:`no-store`}),n=await e.json();if(!e.ok||!n.latest)throw Error();r(n),t(`done`)}catch{t(`err`)}}return e===`done`&&n?io(n.current,n.latest)?(0,S.jsxs)(`span`,{className:`update-result newer`,children:[`v`,n.latest,` available — `,(0,S.jsxs)(`code`,{children:[`npm i -g `,n.name,`@latest`]})]}):(0,S.jsxs)(`span`,{className:`update-result`,children:[(0,S.jsx)(C,{name:`check`,className:`ms-sm`}),` up to date`]}):(0,S.jsx)(`button`,{className:`update-btn`,disabled:e===`busy`,onClick:()=>void i(),children:e===`busy`?`checking…`:e===`err`?`npm unreachable — retry`:(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(C,{name:`sync`,className:`ms-sm`}),` check for updates`]})})}function oo(){return(0,S.jsx)(`button`,{className:`theme-btn`,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,S.jsx)(v.StrictMode,{children:(0,S.jsx)(Ua,{})}));export{x as a,o as c,ne as i,s as l,C as n,h as o,k as r,d as s,Va as t,l as u};