@wrongstack/webui-hq 0.306.4 → 0.307.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.
- package/dist/assets/{alerts-C0ahAgyj.js → alerts-arUs8l44.js} +1 -1
- package/dist/assets/{brain-DxZxkdy0.js → brain-CM6F_7Jo.js} +1 -1
- package/dist/assets/cockpit-Cv6RhS0-.js +1 -0
- package/dist/assets/{control-D4n1t2nX.js → control-BASp4A58.js} +1 -1
- package/dist/assets/{cost-qSQMT1ZD.js → cost-Cq3Z9d5u.js} +1 -1
- package/dist/assets/fleet-map-CJ_yja4v.js +7 -0
- package/dist/assets/fleet-topology-Ce8_j1Tt.js +16 -0
- package/dist/assets/{icons-C4ljWs50.js → icons-I81S_8cW.js} +1 -1
- package/dist/assets/index-D2OiUMCL.js +2 -0
- package/dist/assets/kanban-CBJGu2iP.js +1 -0
- package/dist/assets/live-console-CAVtYJkI.js +1 -0
- package/dist/assets/mailbox-DoMKpxBw.js +1 -0
- package/dist/assets/{markdown--Y3iks7c.js → markdown-C4I0Caum.js} +9 -9
- package/dist/assets/{rolldown-runtime-QTnfLwEv.js → rolldown-runtime-hePW80VL.js} +1 -1
- package/dist/assets/{settings-CiwxymER.js → settings-Bdm9tRck.js} +4 -4
- package/dist/assets/trends-Bi8t1I2q.js +1 -0
- package/dist/assets/{use-backfilled-events-B4G6jrJe.js → use-backfilled-events-BpKv9cpJ.js} +1 -1
- package/dist/assets/vendor-CWm0VQZ2.js +9 -0
- package/dist/assets/{worktree-CC8bd1Ev.js → worktree-Bh9BO2Px.js} +1 -1
- package/dist/index.html +5 -5
- package/package.json +13 -13
- package/dist/assets/cockpit-CnFi0HLk.js +0 -1
- package/dist/assets/fleet-map-CjeZ6E-P.js +0 -7
- package/dist/assets/fleet-topology-BcXKnYKF.js +0 -16
- package/dist/assets/index-Ch5wZYYG.js +0 -2
- package/dist/assets/kanban-CsIHI3Wr.js +0 -1
- package/dist/assets/live-console-CIxhBhTg.js +0 -1
- package/dist/assets/mailbox-DnJYghSf.js +0 -1
- package/dist/assets/trends-C8_-duaz.js +0 -1
- package/dist/assets/vendor-BwY1EM_9.js +0 -9
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{Bt as t,C as n,Ct as r,Et as i,Ft as a,Ht as o,K as s,Ot as c,Rt as l,S as u,St as d,Vt as f,Wt as p,Y as m,Zt as h,_ as g,_t as _,ft as v,g as y,gt as b,ht as x,it as S,j as C,kt as w,lt as T,ot as E,pt as D,r as O,st as k,ut as A,vt as j,zt as M}from"./icons-C4ljWs50.js";import{n as ee}from"./vendor-BwY1EM_9.js";import{i as te,n as ne,r as re,t as ie}from"./markdown--Y3iks7c.js";import{s as ae,u as oe}from"./index-Ch5wZYYG.js";var N=te(),P=e(h(),1),se=ee(),F=null,{min:I,max:L,abs:ce,floor:le}=Math,ue=(e,t,n)=>I(n,L(t,e)),de=e=>[...e].sort((e,t)=>e-t),fe=typeof queueMicrotask==`function`?queueMicrotask:e=>{Promise.resolve().then(e)},R=()=>{let e;return[new Promise(t=>{e=t}),e]},pe=e=>{let t;return()=>(e&&=(t=e(),void 0),t)},z=(e,t,n)=>{let r=n?`unshift`:`push`;for(let n=0;n<t;n++)e[r](-1);return e},me=(e,t)=>{let n=e.t[t];return n===-1?e.o:n},he=(e,t,n)=>{let r=e.t[t]===-1;return e.t[t]=n,e.i=I(t,e.i),r},B=(e,t)=>{if(!e.l)return 0;if(e.i>=t)return e.u[t];e.i<0&&(e.u[0]=0,e.i=0);let n=e.i,r=e.u[n];for(;n<t;)r+=me(e,n),e.u[++n]=r;return e.i=t,r},V=(e,t,n=0,r=e.l-1)=>{let i=n;for(;n<=r;){let a=le((n+r)/2);B(e,a)<=t?(i=a,n=a+1):r=a-1}return ue(i,0,e.l-1)},ge=(e,t,n)=>{let r=t-e.l;return e.i=n?-1:I(t-1,e.i),e.l=t,r>0?(z(e.u,r),z(e.t,r,n),e.o*r):(e.u.splice(r),(n?e.t.splice(0,-r):e.t.splice(r)).reduce((t,n)=>t-(n===-1?e.o:n),0))},_e=typeof window<`u`,ve=e=>e.documentElement,ye=e=>e.ownerDocument,be=e=>e.defaultView,xe=pe(()=>!!/iP(hone|od|ad)/.test(navigator.userAgent)||navigator.platform===`MacIntel`&&navigator.maxTouchPoints>0),Se=pe(()=>`scrollBehavior`in ve(document).style),Ce=e=>L(e.h(),e.p()),we=(e,t=40,n=0,r,i=!1)=>{let a=!!n,o=1,s=0,c=0,l=0,u=0,d=0,f=0,p=0,m=0,h=F,g=[0,a?L(n-1,0):-1],_=0,v=!1,y=((e,t,n)=>({o:t,t:n?z(n.slice(0,I(e,n.length)),L(0,e-n.length)):z([],e),l:e,i:-1,u:z([],e+1)}))(e,r?r[1]:t,r&&r[0]),b=new Set,x=()=>l-c,S=()=>x()+d+u,C=(e,t)=>((e,t,n,r)=>{if(r=I(r,e.l-1),B(e,r)<=t){let i=V(e,n,r);return[V(e,t,r,i),i]}{let i=V(e,t,void 0,r);return[i,V(e,n,i)]}})(y,e,t,g[0]),w=()=>B(y,y.l),T=(e,t)=>{let n=B(y,e)-d;return t?w()-n-E(e):n},E=e=>me(y,e),D=(e,t=-1)=>y.t[e]===t,O=e=>{e&&(xe()&&p!==0||h&&m===1?d+=e:u+=e)};return{v:()=>{b.clear()},m:()=>o,_:()=>(e=>[e.t.slice(),e.o])(y),S:(e=200)=>{if(!v||a)return g;let t,n;if(f)[t,n]=g;else{let r=L(0,S()),a=r+s;i||(e=L(0,e),p!==1&&(r-=e),p!==2&&(a+=e)),[t,n]=g=C(L(0,r),L(0,a)),h&&(t=I(t,h[0]),n=L(n,h[1]))}return[L(t,0),I(n,y.l-1)]},$:e=>V(y,e-c),I:D,k:T,R:E,T:()=>y.l,C:()=>l,M:()=>p!==0,p:()=>s,O:()=>c,h:w,H:()=>(f=u,u=0,[f,m===2]),W:(e,t)=>{let n=[e,t];return b.add(n),()=>{b.delete(n)}},B:(e,t)=>{let n,r,g=0;switch(e){case 1:{if(t===l&&m===0)break;let e=f;f=0;let n=t-l,i=ce(n);e&&i<ce(e)+1||m!==0||(p=n<0?2:1),a&&=!1,l=t,g=4;let o=x();o>=-s&&o<=w()&&(g+=1,r=i>s);break}case 2:g=8,p!==0&&(n=!0,g+=1),p=0,m=0,h=F;break;case 3:{let e=t.filter(([e,t])=>!D(e,t));if(!e.length)break;O(e.reduce((e,[t,n])=>{let r;if(m===2)r=!0;else if(h&&m===1)r=t<h[0];else{let e=x(),n=T(t),i=E(t);r=p!==1&&m===0?n+i<=e:n<e&&n+i<e+s}return r&&(e+=n-E(t)),e},0));for(let[t,n]of e){let e=E(t),r=he(y,t,n);i&&(_+=r?n:n-e)}i&&s&&_>s&&(O(((e,t)=>{let n=0,r=[];e.t.forEach((e,i)=>{e!==-1&&(r.push(e),i<t&&n++)}),e.i=-1;let i=de(r),a=i.length,o=a/2|0,s=a%2==0?(i[o-1]+i[o])/2:i[o],c=e.o;return((e.o=s)-c)*L(t-n,0)})(y,V(y,S()))),i=!1),g=3,r=!0;break}case 4:s!==t&&(s||(v=r=!0),s=t,g=3);break;case 5:t[1]?(O(ge(y,t[0],!0)),m=2,g=1):(ge(y,t[0]),g=1);break;case 6:c=t;break;case 7:m=1;break;case 8:h=C(t,t+s),g=1}g&&(o=1+(2147483647&o),n&&d&&(u+=d,d=0),b.forEach(([e,t])=>{g&e&&t(r)}))}}},H=setTimeout,U=(e,t)=>t?-e:e,Te=(e,t,n,r,i,a)=>{let o=Date.now,s=0,c=!1,l=!1,u=!1,d=!1,f=(()=>{let t,n=()=>{t!=F&&clearTimeout(t)},r=()=>{n(),t=H(()=>{t=F,(()=>{if(c||l)return c=!1,void f();u=!1,e.B(2)})()},150)};return r.J=n,r})(),p=()=>{s=o(),u&&(d=!0),a&&e.B(6,a()),e.B(1,r()),f()},m=t=>{if(c||!e.M()||t.ctrlKey)return;let r=o()-s;150>r&&50<r&&(n?t.deltaX:t.deltaY)&&(c=!0)},h=()=>{l=!0,u=d=!1},g=()=>{l=!1,xe()&&(u=!0)};return t.addEventListener(`scroll`,p),t.addEventListener(`wheel`,m,{passive:!0}),t.addEventListener(`touchstart`,h,{passive:!0}),t.addEventListener(`touchend`,g,{passive:!0}),{A:()=>{t.removeEventListener(`scroll`,p),t.removeEventListener(`wheel`,m),t.removeEventListener(`touchstart`,h),t.removeEventListener(`touchend`,g),f.J()},L:()=>{let[t,n]=e.H();t&&(i(t,n,d),d=!1,n&&e.p()>e.h()&&e.B(1,r()))}}},Ee=(e,t,n)=>{let r;return[async(i,a)=>{if(!await t())return;r&&r();let o=()=>{let[t,n]=R();return r=()=>{n(!1)},e.p()&&H(r,150),[t,e.W(2,()=>{n(!0)})]};if(a&&Se())e.B(8,i()),fe(async()=>{for(;;){let t=!0;for(let[n,r]=e.S();n<=r;n++)if(e.I(n)){t=!1;break}if(t)break;let[n,r]=o();try{if(!await n)return}finally{r()}}e.B(7),n(i(),a)});else for(;;){let[t,r]=o();try{if(e.B(7),n(i()),!await t)return}finally{r()}}},()=>{r&&r()}]},De=(e,t)=>{let n,r,i=R(),a=!1,o=t?`scrollLeft`:`scrollTop`,s=t?`overflowX`:`overflowY`,[c,l]=Ee(e,()=>i[0],(e,r)=>{e=U(e,a),r?n.scrollTo({[t?`left`:`top`]:e,behavior:`smooth`}):n[o]=e});return{N(c,u){n=u,t&&(a=getComputedStyle(u).direction===`rtl`),r=Te(e,u,t,()=>U(u[o],a),(t,n,r)=>{if(r){let e=u.style,t=e[s];e[s]=`hidden`,H(()=>{e[s]=t})}u[o]=U(e.C()+t,a),n&&l()}),i[1](!0)},v(){r&&r.A(),i[1](!1),i=R()},P:()=>a,V(e){c(()=>e)},X(t){t+=e.C(),c(()=>t)},Y(t,{align:n,smooth:r,offset:i=0}={}){if(t=ue(t,0,e.T()-1),n===`nearest`){let r=e.k(t),i=e.C();if(r<i)n=`start`;else{if(!(r+e.R(t)>i+e.p()))return;n=`end`}}c(()=>i+e.O()+e.k(t)+(n===`end`?e.R(t)-e.p():n===`center`?(e.R(t)-e.p())/2:0),r)},q:()=>{r&&r.L()}}},Oe=e=>{let t;return{j(n){(t||=new(be(ye(n))).ResizeObserver(e)).observe(n)},D(e){t.unobserve(e)},A(){t&&t.disconnect()}}},ke=(e,t)=>{let n,r=t?`width`:`height`,i=new WeakMap,a=Oe(t=>{let a=[];for(let{target:o,contentRect:s}of t)if(o.offsetParent)if(o===n)e.B(4,s[r]);else{let e=i.get(o);e!=F&&a.push([e,s[r]])}a.length&&e.B(3,a)});return{G(e){a.j(n=e)},U:(e,t)=>(i.set(e,t),a.j(e),()=>{i.delete(e),a.D(e)}),v:a.A}},W=_e?P.useLayoutEffect:P.useEffect,G=`current`,Ae=(e,t)=>{if(Array.isArray(e))for(let n of e)Ae(n,t);else e==null||typeof e==`boolean`||t.push(e)},je=(e,t)=>e.key??`_`+t,Me=e=>{let t=(0,P.useRef)(null);return t[G]||(t[G]=e())},Ne=e=>{let t=(0,P.useRef)(e);return W(()=>{t[G]=e},[e]),t},Pe=(0,P.memo)(({Z:e,ee:t,te:n,oe:r,ne:i,re:a,se:o,ie:s})=>{let c=(0,P.useRef)(null);W(()=>t(c[G],n),[n]);let l=(0,P.useMemo)(()=>{let e={contain:`layout style`,position:i&&s?void 0:`absolute`,[o?`height`:`width`]:`100%`,[o?`top`:`left`]:0,[o?`left`:`top`]:r,visibility:!i||s?void 0:`hidden`};return o&&(e.display=`inline-flex`),e},[r,i,s,o]);return(0,N.jsx)(a,typeof a==`string`?{ref:c,style:l,children:e}:{ref:c,style:l,index:n,children:e})}),Fe=(e,t)=>(0,P.useMemo)(()=>{if(typeof e==`function`)return[n=>e(t[n],n),t.length];let n=(e=>{let t=[];return Ae(e,t),t})(e);return[e=>n[e],n.length]},[e,t]),Ie=(0,P.forwardRef)(({children:e,data:t,bufferSize:n,itemSize:r,shift:i,horizontal:a,keepMounted:o,cache:s,startMargin:c=0,ssrCount:l,as:u=`div`,item:d=`div`,scrollRef:f,onScroll:p,onScrollEnd:m},h)=>{let[g,_]=Fe(e,t),v=(0,P.useRef)(null),y=(0,P.useRef)(!!l),b=Ne(p),x=Ne(m),[S,C,w,T]=Me(()=>{let e=!!a,t=we(_,r,l,s,!r);return[t,ke(t,e),De(t,e),e]});_!==S.T()&&S.B(5,[_,i]),c!==S.O()&&S.B(6,c);let[E,D]=(0,P.useReducer)(S.m,void 0,S.m),O=S.M(),k=S.h(),A=w.P(),j=[],M=e=>{let t=g(e);return(0,N.jsx)(Pe,{ee:C.U,te:e,oe:S.k(e,A),ne:S.I(e),re:d,Z:t,se:T,ie:y[G]},je(t,e))};if(W(()=>{y[G]=!1,S.W(1,e=>{e?(0,se.flushSync)(D):D()}),S.W(4,()=>{b[G]&&b[G](S.C())}),S.W(8,()=>{x[G]&&x[G]()});let e=v[G],t=t=>{C.G(t),w.N(e,t)};return f?fe(()=>{f[G]&&t(f[G])}):t(e.parentElement),()=>{S.v(),C.v(),w.v()}},[]),W(()=>{w.q()},[E]),(0,P.useImperativeHandle)(h,()=>({get cache(){return S._()},get scrollOffset(){return S.C()},get scrollSize(){return Ce(S)},get viewportSize(){return S.p()},findItemIndex:S.$,getItemOffset:S.k,getItemSize:S.R,scrollToIndex:w.Y,scrollTo:w.V,scrollBy:w.X}),[]),o){let e=new Set(o);for(let[t,r]=S.S(n);t<=r;t++)e.add(t);de([...e]).forEach(e=>{j.push(M(e))})}else for(let[e,t]=S.S(n);e<=t;e++)j.push(M(e));return(0,N.jsx)(u,{ref:v,style:{contain:`size style`,overflowAnchor:`none`,flex:`none`,position:`relative`,width:T?k:`100%`,height:T?`100%`:k,pointerEvents:O?`none`:void 0},children:j})}),Le=(0,P.forwardRef)(({children:e,data:t,bufferSize:n,itemSize:r,shift:i,horizontal:a,keepMounted:o,cache:s,ssrCount:c,item:l,onScroll:u,onScrollEnd:d,style:f,...p},m)=>(0,N.jsx)(`div`,{...p,style:{display:a?`inline-block`:`block`,[a?`overflowX`:`overflowY`]:`auto`,contain:`strict`,width:`100%`,height:`100%`,...f},children:(0,N.jsx)(Ie,{ref:m,data:t,bufferSize:n,itemSize:r,shift:i,horizontal:a,keepMounted:o,cache:s,ssrCount:c,item:l,onScroll:u,onScrollEnd:d,children:e})}));function K(){return{entries:[],seen:new Set,consumedBatches:new Set,openTools:new Map,rev:0}}function Re(e){return(e.role===`tool`||e.role===`error`)&&e.toolUseId!==void 0&&e.toolInput===void 0}function ze(e){return e.toolUseId!==void 0&&e.toolInput!==void 0?`tu:${e.toolUseId}`:`${e.ts}|${e.role}|${e.tool??``}|${e.text}`}function Be(e,t){let n={...t};if(Re(n)){let t=n.toolUseId===void 0?void 0:e.openTools.get(n.toolUseId);if(t!==void 0){let r={...e.entries[t]};r.text=n.text||``,n.durationMs!==void 0&&(r.durationMs=n.durationMs),n.isError&&(r.role=`error`,r.isError=!0),e.entries[t]=r;return}}let r=ze(n);e.seen.has(r)||(e.seen.add(r),n.role===`tool`&&n.toolUseId!==void 0&&n.toolInput!==void 0&&e.openTools.set(n.toolUseId,e.entries.length),e.entries.push(n))}function Ve(e,t){let n=K();n.rev=e.rev+1;for(let e of t)Be(n,e);return n}function He(e,t,n){if(n.length===0)return e;let r=t===void 0?`k:${ze(n[0])}:${n.length}`:`${t}:${n.length}`;if(e.consumedBatches.has(r))return e;let i={entries:[...e.entries],seen:new Set(e.seen),consumedBatches:new Set(e.consumedBatches),openTools:new Map(e.openTools),rev:e.rev+1};i.consumedBatches.add(r);for(let e of n)Be(i,e);return i}function q(e){return e.role===`tool`&&e.toolInput!==void 0&&e.text===``&&e.durationMs===void 0&&e.isError!==!0}function Ue(e,t){return`${t}:${e.ts}:${e.role}:${e.toolUseId??``}`}function We(e){let t=[],n=e=>(e.role===`assistant`||e.role===`thinking`)&&e.tool===void 0&&e.toolUseId===void 0&&e.isError!==!0;for(let r of e){let e=t[t.length-1];e!==void 0&&n(r)&&n(e)&&e.role===r.role&&(e.agentId??``)===(r.agentId??``)?t[t.length-1]={...e,text:e.text+r.text}:t.push(r)}return t}function Ge(e){let t=e.kind===`thinking`?`thinking`:e.kind===`tool_use`||e.kind===`tool_result`?`tool`:e.kind===`error`?`error`:e.kind===`system`||e.kind===`status`?`system`:`assistant`;return{ts:e.ts,role:t,text:e.content,...e.toolName===void 0?{}:{tool:e.toolName},...e.kind===`error`?{isError:!0}:{},agentId:e.subagentId}}function Ke(e,t){let n=oe(e=>e.events),r=t!==null&&t!==`leader`,[i,a]=(0,P.useState)(K),[o,s]=(0,P.useState)(!1),[c,l]=(0,P.useState)(null),[u,d]=(0,P.useState)(!1),[f,p]=(0,P.useState)({total:0}),m=(0,P.useRef)(null),[h,g]=(0,P.useState)(!0),_=(0,P.useRef)(!0),v=e=>{_.current=e,g(e)},y=(0,P.useRef)(i);y.current=i;let[b,x]=(0,P.useState)([]),[S,C]=(0,P.useState)(!1);(0,P.useEffect)(()=>{if(x([]),t===null||e===null||!r)return;let n=!1;return C(!0),ae(`/api/sessions/${encodeURIComponent(e)}/agents/${encodeURIComponent(t)}/messages?full=1`).then(e=>{n||(x((e.entries??[]).map(e=>({...e,agentId:t}))),p(t=>({...t,source:e.source})),C(!1))}).catch(()=>{n||C(!1)}),()=>{n=!0}},[t,e,r]);let w=(0,P.useMemo)(()=>{if(!r||t===null)return[];let i=n.filter(t=>t.type===`agent.message`&&(t.sessionId===void 0||t.sessionId===e)).map(e=>e.payload).filter(e=>e.subagentId===t).map(e=>({...Ge(e),agentId:t})),a=new Set,o=[];for(let e of[...b,...i]){let t=`${e.ts}|${e.role}|${e.text}`;a.has(t)||(a.add(t),o.push(e))}return We(o)},[b,n,t,e,r]);(0,P.useEffect)(()=>{if(e===null||r)return;let t=!1;return s(!0),l(null),_.current=!0,g(!0),ae(`/api/sessions/${encodeURIComponent(e)}/events?${u?`full=1`:`limit=1000`}`).then(e=>{t||(a(t=>Ve(t,e.entries)),p({source:e.source,projectName:e.projectName,total:e.total}),s(!1))}).catch(e=>{t||(l(e.message),s(!1))}),()=>{t=!0}},[e,u,r]),(0,P.useEffect)(()=>{a(K()),p({total:0}),d(!1)},[e,t]),(0,P.useEffect)(()=>{if(e===null||r)return;let t=y.current;for(let r of n){if(r.type!==`session.transcript`||r.sessionId!==e)continue;let n=r.payload;Array.isArray(n.entries)&&(t=He(t,n.fromSeq,n.entries))}t!==y.current&&a(t)},[n,e,r]);let T=(0,P.useMemo)(()=>We(i.entries),[i.entries]),E=r?w:T;(0,P.useEffect)(()=>{_.current&&E.length>0&&m.current?.scrollToIndex(E.length-1,{align:`end`})},[E.length,i.rev]);let D=()=>{let e=m.current;e&&v(e.scrollSize-e.scrollOffset-e.viewportSize<80)},O=()=>{v(!0),m.current?.scrollToIndex(E.length-1,{align:`end`})},k=Math.max(0,E.length-8),A=(e,t)=>q(e)&&t>=k,j=(0,P.useMemo)(()=>{let e=0,t=0,n=0;for(let r=0;r<E.length;r++){let i=E[r];i.tool!==void 0&&e++,(i.role===`error`||i.isError)&&t++,q(i)&&r>=k&&n++}return{turns:E.length,tools:e,errors:t,running:n}},[E,k]);return{entries:E,loading:r?S:o,error:c,meta:f,full:u,setFull:d,stats:j,isRunningAt:A,listRef:m,onScroll:D,pinned:h,jumpToLatest:O}}function qe({text:e,label:t}){let[n,i]=(0,P.useState)(!1);return(0,N.jsxs)(`button`,{type:`button`,className:`hq-copy-btn`,onClick:()=>{navigator.clipboard?.writeText(e).then(()=>{i(!0),setTimeout(()=>i(!1),1200)},()=>{})},title:`Copy to clipboard`,children:[n?(0,N.jsx)(o,{size:12}):(0,N.jsx)(r,{size:12}),t!==void 0&&(0,N.jsx)(`span`,{children:n?`copied`:t})]})}function J(e){return e==null||typeof e==`boolean`?``:typeof e==`string`||typeof e==`number`?String(e):Array.isArray(e)?e.map(J).join(``):(0,P.isValidElement)(e)?J(e.props.children):``}var Je={a:({children:e,href:t})=>(0,N.jsx)(`a`,{href:t,target:`_blank`,rel:`noopener noreferrer`,children:e}),table:({children:e})=>(0,N.jsx)(`div`,{className:`hq-md-table-wrap`,children:(0,N.jsx)(`table`,{children:e})}),pre:({children:e})=>{let t=Array.isArray(e)?e[0]:e,n=(0,P.isValidElement)(t)?t.props:void 0,r=/language-(\w+)/.exec(n?.className??``)?.[1],i=J(n?.children).replace(/\n$/,``),a=i===``?0:i.split(`
|
|
2
|
-
`).length;return(0,N.jsxs)(`div`,{className:`hq-md-code`,children:[(0,N.jsxs)(`div`,{className:`hq-md-code-bar`,children:[(0,N.jsx)(`span`,{className:`hq-md-code-lang`,children:r??`text`}),(0,N.jsxs)(`span`,{className:`hq-md-code-meta`,children:[a,` line`,a===1?``:`s`]}),(0,N.jsx)(qe,{text:i})]}),(0,N.jsx)(`pre`,{children:e})]})}},Ye=(0,P.memo)(function({text:e}){return(0,N.jsx)(`div`,{className:`hq-md`,children:(0,N.jsx)(re,{remarkPlugins:[ie],rehypePlugins:[ne],components:Je,children:e})})}),Xe={file:{color:`#60a5fa`},edit:{color:`#fbbf24`},search:{color:`#a78bfa`},folder:{color:`#38bdf8`},terminal:{color:`#67e8f9`},web:{color:`#34d399`},git:{color:`#a3e635`},tree:{color:`#22d3ee`},code:{color:`#818cf8`},test:{color:`#4ade80`},package:{color:`#f472b6`},document:{color:`#94a3b8`},scaffold:{color:`#c084fc`},todo:{color:`#facc15`},plan:{color:`#2dd4bf`},task:{color:`#5eead4`},meta:{color:`#cbd5e1`},index:{color:`#06b6d4`},json:{color:`#eab308`},diff:{color:`#93c5fd`},logs:{color:`#a3a3a3`},settings:{color:`#9ca3af`},brain:{color:`#e879f9`},fallback:{color:`#9ca3af`}},Ze={read:`file`,cat:`file`,view:`file`,write:`file`,create:`file`,edit:`edit`,replace:`edit`,str_replace:`edit`,multi_edit:`edit`,patch:`edit`,grep:`search`,search:`search`,rg:`search`,ripgrep:`search`,glob:`folder`,find:`search`,folder:`folder`,ls:`folder`,list:`folder`,set_working_dir:`folder`,tree:`tree`,bash:`terminal`,shell:`terminal`,sh:`terminal`,exec:`terminal`,run:`terminal`,command:`terminal`,fetch:`web`,web_fetch:`web`,web_search:`web`,git:`git`,diff:`diff`,lint:`code`,format:`settings`,typecheck:`code`,language_info:`code`,language:`code`,language_package:`package`,test:`test`,install:`package`,outdated:`package`,audit:`package`,document:`document`,scaffold:`scaffold`,todo:`todo`,plan:`plan`,task:`task`,json:`json`,index:`index`,logs:`logs`,mode:`meta`,tool_search:`meta`,tool_use:`meta`,batch_tool_use:`meta`,tool_help:`meta`,remember:`brain`,forget:`brain`,search_memory:`brain`,find_related_memories:`brain`,memory_for_file:`brain`,memory_for_path:`brain`,memory_search:`brain`,memory_graph:`brain`,memory_verify:`brain`,memory_hygiene:`brain`,memory_candidates:`brain`,lsp_diagnostics:`code`,lsp_definition:`search`,lsp_completion:`code`,lsp_rename:`edit`,"codebase-lsp-search":`index`};function Qe(e){return e?Ze[e.toLowerCase()]??`fallback`:`fallback`}var $e={file:b,edit:_,search:u,folder:D,terminal:y,web:k,git:A,tree:v,code:i,test:x,package:C,document:n,scaffold:E,todo:s,plan:c,task:m,meta:O,index:d,json:j,diff:T,logs:S,settings:g,brain:p,fallback:O};function et(e){let t=Qe(e??``);return{Icon:$e[t],color:Xe[t].color}}var tt=[`path`,`file_path`,`pattern`,`symbol`,`command`,`cmd`,`url`,`query`,`description`,`content`];function Y(e,t){return e.length>t?`${e.slice(0,t-1)}\u2026`:e}function X(e){let t=e.file_path??e.path??e.filepath;return typeof t==`string`?t:``}function nt(e){try{return JSON.stringify(e)}catch{return String(e)}}function rt(e){if(typeof e==`string`){let t=e.trim();if(t.startsWith(`{`)||t.startsWith(`[`))try{let e=JSON.parse(t);if(e&&typeof e==`object`)return{obj:e,raw:e}}catch{}return{obj:null,raw:e}}return e&&typeof e==`object`?{obj:e,raw:e}:{obj:null,raw:e}}function it(e,t){if(t==null||t===``)return``;let{obj:n,raw:r}=rt(t);if(!n)return Y(String(r),120);let i=(e??``).toLowerCase();if(/^todo(_?write)?$|^todos$/.test(i)||Array.isArray(n.todos)){let e=n.todos??[];if(Array.isArray(e)){let t=e.filter(e=>e?.status===`completed`).length,n=e.filter(e=>e?.status===`in_progress`).length,r=[`${e.length} todo${e.length===1?``:`s`}`];return t>0&&r.push(`${t} done`),n>0&&r.push(`${n} in-progress`),r.join(` · `)}}if(/batch|parallel/.test(i)||Array.isArray(n.tool_uses)||Array.isArray(n.calls)){let e=n.tool_uses??n.calls??n.batch;if(Array.isArray(e)){let t=new Set;for(let n of e)n&&typeof n==`object`&&`name`in n?t.add(String(n.name)):n&&typeof n==`object`&&`tool`in n&&t.add(String(n.tool));let n=[...t].slice(0,3).join(`, `),r=t.size>3?` +${t.size-3}`:``;return`${e.length} sub-tool${e.length===1?``:`s`}${n?` \xB7 ${n}${r}`:``}`}}if(i===`patch`&&typeof n.patch==`string`&&n.patch){let e=(n.patch.match(/^\+\+\+ /gm)??[]).length;return e>0?`patch \xB7 ${e} file${e===1?``:`s`}`:`patch \xB7 ${n.patch.split(`
|
|
3
|
-
`).length} lines`}if(/^(edit|str_replace|edit_file|patch)$/.test(i)){let e=X(n),t=typeof n.old_string==`string`?n.old_string:``,r=typeof n.new_string==`string`?n.new_string:``,i=t?t.split(`
|
|
4
|
-
`).length:0,a=r?r.split(`
|
|
5
|
-
`).length:0;return`edit ${e||`(file)`}${i||a?` (${i} \u2192 ${a} lines)`:``}`}if(/^(write|write_file|create_file|new_file)$/.test(i)){let e=X(n),t=typeof n.content==`string`?n.content:``,r=t?t.split(`
|
|
6
|
-
`).length:0;return`write ${e||`(file)`}${r?` \xB7 ${r} lines`:``}`}if(/^(bash|shell|sh|exec|run|run_command|run_shell|command)$/.test(i)){let e=n.command??n.cmd??n.script;if(typeof e==`string`)return`$ ${Y(e,110)}`}if(/^(fetch|http|web|web_fetch|web_search|webfetch|curl|request)$/.test(i)){let e=n.url;if(typeof e==`string`)return`${(n.method??`GET`).toUpperCase()} ${Y(e,100)}`}if(/^(grep|search|ripgrep|rg)$/.test(i)){let e=n.pattern,t=n.path??n.glob??n.type;if(typeof e==`string`)return t?`grep ${Y(e,60)} in ${t}`:`grep ${Y(e,100)}`}if(/^(glob|find)$/.test(i)){let e=n.pattern??n.glob;if(typeof e==`string`)return`glob ${Y(e,80)}`}if(/^tree$/.test(i)){let e=typeof n.path==`string`?n.path:``,t=typeof n.depth==`number`?n.depth:null;return`tree ${e||`.`}${t===null?``:` (depth ${t})`}`}if(/^diff$/.test(i)){let e=typeof n.a==`string`?n.a:``,t=typeof n.b==`string`?n.b:``;if(e||t)return`diff ${e&&t?`${e}..${t}`:e||t}`;let r=[];if(Array.isArray(n.files))for(let e of n.files)typeof e==`string`&&r.push(e);else if(typeof n.files==`string`)for(let e of n.files.split(`,`)){let t=e.trim();t&&r.push(t)}if(r.length===1)return`diff ${Y(String(r[0]),80)}`;if(r.length>1)return`diff ${r.length} files`}if(/^replace$/.test(i)){let e=typeof n.pattern==`string`?n.pattern:``;if(e){let t=``;if(typeof n.files==`string`){let e=n.files.split(`,`).map(e=>e.trim()).filter(Boolean);t=e.length>1?`${e.length} files`:e[0]??``}else Array.isArray(n.files)&&n.files.length>0&&(t=n.files.length===1?String(n.files[0]):`${n.files.length} files`);return`replace ${Y(e,60)}${t?` in ${Y(t,50)}`:``}`}}if(/^(read|read_file|cat|view)$/.test(i)){let e=X(n),t=n.offset,r=n.limit;if(e&&(typeof t==`number`||typeof r==`number`)){let n=t??0;return`read ${e} (${n}\u2026${typeof r==`number`?n+r:``})`}if(e)return`read ${e}`}for(let e of tt){let t=n[e];if(typeof t==`string`&&t.length>0)return`${e}: ${Y(t,100)}`}return Y(nt(r),120)}[`function __clip(s,n){ s=String(s==null?"":s); return s.length>n ? s.slice(0,n-1)+"\\u2026" : s; }`,`function toolInputSummary(name, rawInput){`,` if(rawInput==null || rawInput==="") return "";`,` var obj=null, raw=rawInput;`,` if(typeof rawInput==="string"){`,` var s=rawInput.trim();`,` if(s.charAt(0)==="{" || s.charAt(0)==="["){ try{ var pj=JSON.parse(s); if(pj && typeof pj==="object"){ obj=pj; raw=pj; } }catch(_e){} }`,` } else if(rawInput && typeof rawInput==="object"){ obj=rawInput; raw=rawInput; }`,` if(!obj) return __clip(String(raw),120);`,` var n=String(name==null?"":name).toLowerCase();`,` if(/^todo(_?write)?$|^todos$/.test(n) || Array.isArray(obj.todos)){`,` var todos=obj.todos||[];`,` if(Array.isArray(todos)){`,` var done=0, wip=0, ti;`,` for(ti=0; ti<todos.length; ti++){ var st=todos[ti]&&todos[ti].status; if(st==="completed") done++; else if(st==="in_progress") wip++; }`,` var tp=[todos.length+" todo"+(todos.length===1?"":"s")];`,` if(done>0) tp.push(done+" done"); if(wip>0) tp.push(wip+" in-progress");`,` return tp.join(" \\u00b7 ");`,` }`,` }`,` if(/batch|parallel/.test(n) || Array.isArray(obj.tool_uses) || Array.isArray(obj.calls)){`,` var list=obj.tool_uses||obj.calls||obj.batch;`,` if(Array.isArray(list)){`,` var names={}, ord=[], li, it, nm;`,` for(li=0; li<list.length; li++){ it=list[li]; if(it && typeof it==="object"){ nm=("name" in it)?it.name:(("tool" in it)?it.tool:null); if(nm!=null){ nm=String(nm); if(!names[nm]){ names[nm]=1; ord.push(nm); } } } }`,` var preview=ord.slice(0,3).join(", ");`,` var more=ord.length>3 ? " +"+(ord.length-3) : "";`,` return list.length+" sub-tool"+(list.length===1?"":"s")+(preview?(" \\u00b7 "+preview+more):"");`,` }`,` }`,` var fp;`,` if(n==="patch" && typeof obj.patch==="string" && obj.patch){`,` var pfm=obj.patch.match(/^\\+\\+\\+ /gm);`,` var pfc=pfm?pfm.length:0;`,` if(pfc>0) return "patch \\u00b7 "+pfc+" file"+(pfc===1?"":"s");`,` return "patch \\u00b7 "+obj.patch.split("\\n").length+" lines";`,` }`,` if(/^(edit|str_replace|edit_file|patch)$/.test(n)){`,` fp=(obj.file_path!=null?obj.file_path:(obj.path!=null?obj.path:obj.filepath));`,` var oldS=typeof obj.old_string==="string"?obj.old_string:"";`,` var newS=typeof obj.new_string==="string"?obj.new_string:"";`,` var ol=oldS?oldS.split("\\n").length:0, nl=newS?newS.split("\\n").length:0;`,` var efp=typeof fp==="string"?fp:"";`,` return "edit "+(efp||"(file)")+((ol||nl)?(" ("+ol+" \\u2192 "+nl+" lines)"):"");`,` }`,` if(/^(write|write_file|create_file|new_file)$/.test(n)){`,` fp=(obj.file_path!=null?obj.file_path:(obj.path!=null?obj.path:obj.filepath));`,` var wc=typeof obj.content==="string"?obj.content:"";`,` var wl=wc?wc.split("\\n").length:0;`,` var wfp=typeof fp==="string"?fp:"";`,` return "write "+(wfp||"(file)")+(wl?(" \\u00b7 "+wl+" lines"):"");`,` }`,` if(/^(bash|shell|sh|exec|run|run_command|run_shell|command)$/.test(n)){`,` var cmd=(obj.command!=null?obj.command:(obj.cmd!=null?obj.cmd:obj.script));`,` if(typeof cmd==="string") return "$ "+__clip(cmd,110);`,` }`,` if(/^(fetch|http|web|web_fetch|web_search|webfetch|curl|request)$/.test(n)){`,` if(typeof obj.url==="string"){ var mth=(typeof obj.method==="string"?obj.method:"GET"); return mth.toUpperCase()+" "+__clip(obj.url,100); }`,` }`,` if(/^(grep|search|ripgrep|rg)$/.test(n)){`,` var pat=obj.pattern, scope=(obj.path!=null?obj.path:(obj.glob!=null?obj.glob:obj.type));`,` if(typeof pat==="string"){ return scope ? ("grep "+__clip(pat,60)+" in "+scope) : ("grep "+__clip(pat,100)); }`,` }`,` if(/^(glob|find)$/.test(n)){`,` var gp=(obj.pattern!=null?obj.pattern:obj.glob);`,` if(typeof gp==="string") return "glob "+__clip(gp,80);`,` }`,` if(/^tree$/.test(n)){`,` var trp=typeof obj.path==="string"?obj.path:"";`,` var trd=typeof obj.depth==="number"?obj.depth:null;`,` return "tree "+(trp||".")+(trd!==null?(" (depth "+trd+")"):"");`,` }`,` if(/^diff$/.test(n)){`,` var da=typeof obj.a==="string"?obj.a:"", db=typeof obj.b==="string"?obj.b:"";`,` if(da||db) return "diff "+((da&&db)?(da+".."+db):(da||db));`,` var dfl=[], dfi, dpi;`,` if(Array.isArray(obj.files)){ for(dfi=0; dfi<obj.files.length; dfi++){ if(typeof obj.files[dfi]==="string") dfl.push(obj.files[dfi]); } }`,` else if(typeof obj.files==="string"){ var dparts=obj.files.split(","); for(dpi=0; dpi<dparts.length; dpi++){ var dt=dparts[dpi].trim(); if(dt) dfl.push(dt); } }`,` if(dfl.length===1) return "diff "+__clip(String(dfl[0]),80);`,` if(dfl.length>1) return "diff "+dfl.length+" files";`,` }`,` if(/^replace$/.test(n)){`,` var rpat=typeof obj.pattern==="string"?obj.pattern:"";`,` if(rpat){`,` var rscope="";`,` if(typeof obj.files==="string"){`,` var rparts=[], rsi;`,` var rraw=obj.files.split(",");`,` for(rsi=0; rsi<rraw.length; rsi++){ var rt=rraw[rsi].trim(); if(rt) rparts.push(rt); }`,` rscope=rparts.length>1?(rparts.length+" files"):(rparts.length===1?rparts[0]:"");`,` } else if(Array.isArray(obj.files) && obj.files.length>0){`,` rscope=obj.files.length===1?String(obj.files[0]):(obj.files.length+" files");`,` }`,` return "replace "+__clip(rpat,60)+(rscope?(" in "+__clip(rscope,50)):"");`,` }`,` }`,` if(/^(read|read_file|cat|view)$/.test(n)){`,` fp=(obj.file_path!=null?obj.file_path:(obj.path!=null?obj.path:obj.filepath));`,` if(typeof fp==="string" && fp){`,` var off=obj.offset, lim=obj.limit;`,` if(typeof off==="number" || typeof lim==="number"){ var start=(typeof off==="number"?off:0); var end=(typeof lim==="number"?(start+lim):""); return "read "+fp+" ("+start+"\\u2026"+end+")"; }`,` return "read "+fp;`,` }`,` }`,` var HEAD=["path","file_path","pattern","symbol","command","cmd","url","query","description","content"], hi;`,` for(hi=0; hi<HEAD.length; hi++){ var hv=obj[HEAD[hi]]; if(typeof hv==="string" && hv.length>0){ return HEAD[hi]+": "+__clip(hv,100); } }`,` var jsonStr; try{ jsonStr=JSON.stringify(raw); }catch(_e2){ jsonStr=String(raw); }`,` return __clip(jsonStr,120);`,`}`].join(`
|
|
7
|
-
`);function at(e){let t=(e??``).toLowerCase().replace(/^mcp__[^_]+__/,``);return/^(edit|str_replace|edit_file|patch|apply_patch|multiedit)$/.test(t)?`edit`:/^(write|write_file|create_file|new_file)$/.test(t)?`write`:/^(bash|shell|exec|run|run_command|run_shell|powershell|terminal)$/.test(t)?`bash`:/^(read|read_file|cat|open)$/.test(t)?`read`:/^(grep|search|ripgrep|glob|find)$/.test(t)?`search`:/^(fetch|http|web|webfetch|websearch|curl|request)$/.test(t)?`fetch`:/todo/.test(t)?`todo`:`generic`}function ot(e){if(e===void 0)return;let t=e.trim();if(!(t===``||t[0]!==`{`&&t[0]!==`[`))try{return JSON.parse(t)}catch{return}}function st(e,t){return t===void 0||t===``||t===`{}`?``:it(e,t)}function ct(e){let t=ot(e);if(t===void 0)return e??``;try{return JSON.stringify(t,null,2)}catch{return e??``}}function lt(e){let t=ot(e);if(typeof t!=`object`||!t)return null;let n=t.todos;if(!Array.isArray(n))return null;let r=[];for(let e of n){if(!e||typeof e!=`object`)continue;let t=e,n=t.status===`completed`?`completed`:t.status===`in_progress`?`in_progress`:`pending`,i=typeof t.content==`string`?t.content:typeof t.subject==`string`?t.subject:typeof t.title==`string`?t.title:``;r.push({status:n,content:i})}return r.length>0?r:null}function ut(e){return e===void 0||!Number.isFinite(e)||e<0?``:e<1e3?`${Math.round(e)}ms`:e<6e4?`${(e/1e3).toFixed(+(e<1e4))}s`:`${Math.floor(e/6e4)}m${Math.round(e%6e4/1e3)}s`}function dt(e){return e?e.replace(/^mcp__([^_]+)__/,`$1:`):`tool`}function ft(e){if(!e)return``;let t=new Date(e);return Number.isNaN(t.getTime())?``:t.toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`,second:`2-digit`})}function pt(e){if(typeof e==`string`){let t=e.trim();if(t.startsWith(`{`)||t.startsWith(`[`))try{let e=JSON.parse(t);if(e&&typeof e==`object`)return e}catch{return null}return null}return e&&typeof e==`object`?e:null}function mt(e,t){if(!e)return null;let n=pt(t);if(!n)return null;let r=e.toLowerCase(),i=String(n.file_path??n.path??``);switch(r){case`edit`:case`str_replace`:case`edit_file`:case`multi_edit`:{let e=typeof n.old_string==`string`?n.old_string:``,t=typeof n.new_string==`string`?n.new_string:``;return!e&&!t?null:{mode:`lcs`,oldText:e,newText:t,caption:`edit ${i}`.trim()}}case`write`:case`write_file`:case`create_file`:{let e=typeof n.content==`string`?n.content:``;return e?{mode:`lcs`,oldText:``,newText:e,caption:`write ${i} (new)`.trim()}:null}case`patch`:{let e=typeof n.patch==`string`?n.patch:``;return e.trim()?{mode:`unified`,patchText:e,caption:i?`patch ${i}`:`patch`}:null}default:return null}}function ht(e,t){let n=e.split(`
|
|
8
|
-
`),r=t.split(`
|
|
9
|
-
`);if(n.length>5e3||r.length>5e3)return null;let i=n.length,a=r.length,o=Array.from({length:i+1},()=>Array(a+1).fill(0));for(let e=i-1;e>=0;e--)for(let t=a-1;t>=0;t--)o[e][t]=n[e]===r[t]?o[e+1][t+1]+1:Math.max(o[e+1][t],o[e][t+1]);let s=[],c=0,l=0;for(;c<i&&l<a;)n[c]===r[l]?(s.push({kind:`ctx`,text:n[c]}),c++,l++):o[c+1][l]>=o[c][l+1]?(s.push({kind:`del`,text:n[c]}),c++):(s.push({kind:`add`,text:r[l]}),l++);for(;c<i;)s.push({kind:`del`,text:n[c++]});for(;l<a;)s.push({kind:`add`,text:r[l++]});return s}function gt(e){let t=[],n=e.split(`
|
|
10
|
-
`);for(let e of n)e.startsWith(`@@`)||e.startsWith(`--- `)||e.startsWith(`+++ `)||e.startsWith(`diff `)||e.startsWith(`index `)||e.startsWith(`\\ `)?t.push({kind:`meta`,text:e}):e.startsWith(`+`)?t.push({kind:`add`,text:e.slice(1)}):e.startsWith(`-`)?t.push({kind:`del`,text:e.slice(1)}):t.push({kind:`ctx`,text:e.startsWith(` `)?e.slice(1):e});return t.length>0&&t[t.length-1].kind===`ctx`&&t[t.length-1].text===``&&t.pop(),t}function _t(e,t){let n=mt(e,t);return n?n.mode===`unified`?{caption:n.caption,rows:gt(n.patchText)}:{caption:n.caption,rows:ht(n.oldText,n.newText)}:null}[`var DIFF_MAX_LINES = 5000;`,`function __diffObj(input){`,` if(typeof input==="string"){ var s=input.trim(); if(s.charAt(0)==="{"||s.charAt(0)==="["){ try{ var p=JSON.parse(s); if(p&&typeof p==="object") return p; }catch(_e){} } return null; }`,` if(input&&typeof input==="object") return input; return null;`,`}`,`function diffFromToolInput(name, input){`,` if(!name) return null;`,` var obj=__diffObj(input); if(!obj) return null;`,` var n=String(name).toLowerCase();`,` var fp=String(obj.file_path!=null?obj.file_path:(obj.path!=null?obj.path:""));`,` if(n==="edit"||n==="str_replace"||n==="edit_file"||n==="multi_edit"){`,` var oldT=typeof obj.old_string==="string"?obj.old_string:"";`,` var newT=typeof obj.new_string==="string"?obj.new_string:"";`,` if(!oldT&&!newT) return null;`,` return { mode:"lcs", oldText:oldT, newText:newT, caption:("edit "+fp).replace(/\\s+$/,"") };`,` }`,` if(n==="write"||n==="write_file"||n==="create_file"){`,` var c=typeof obj.content==="string"?obj.content:"";`,` if(!c) return null;`,` return { mode:"lcs", oldText:"", newText:c, caption:("write "+fp+" (new)").replace(/\\s+/g," ").replace(/\\s+$/,"") };`,` }`,` if(n==="patch"){`,` var pt=typeof obj.patch==="string"?obj.patch:"";`,` if(!pt.replace(/\\s/g,"")) return null;`,` return { mode:"unified", patchText:pt, caption: fp ? ("patch "+fp) : "patch" };`,` }`,` return null;`,`}`,`function computeLineDiff(oldText, newText){`,` var a=oldText.split("\\n"), b=newText.split("\\n");`,` if(a.length>DIFF_MAX_LINES||b.length>DIFF_MAX_LINES) return null;`,` var nn=a.length, mm=b.length, i, j;`,` var dp=new Array(nn+1); for(i=0;i<=nn;i++){ dp[i]=new Array(mm+1); for(j=0;j<=mm;j++) dp[i][j]=0; }`,` for(i=nn-1;i>=0;i--){ for(j=mm-1;j>=0;j--){ dp[i][j]= a[i]===b[j] ? dp[i+1][j+1]+1 : Math.max(dp[i+1][j], dp[i][j+1]); } }`,` var rows=[]; i=0; j=0;`,` while(i<nn&&j<mm){ if(a[i]===b[j]){ rows.push({kind:"ctx",text:a[i]}); i++; j++; } else if(dp[i+1][j]>=dp[i][j+1]){ rows.push({kind:"del",text:a[i]}); i++; } else { rows.push({kind:"add",text:b[j]}); j++; } }`,` while(i<nn){ rows.push({kind:"del",text:a[i]}); i++; }`,` while(j<mm){ rows.push({kind:"add",text:b[j]}); j++; }`,` return rows;`,`}`,`function parseUnifiedDiff(patchText){`,` var rows=[], lines=patchText.split("\\n"), k, raw;`,` for(k=0;k<lines.length;k++){ raw=lines[k];`,` if(raw.indexOf("@@")===0||raw.indexOf("--- ")===0||raw.indexOf("+++ ")===0||raw.indexOf("diff ")===0||raw.indexOf("index ")===0||raw.indexOf("\\\\ ")===0){ rows.push({kind:"meta",text:raw}); }`,` else if(raw.charAt(0)==="+"){ rows.push({kind:"add",text:raw.slice(1)}); }`,` else if(raw.charAt(0)==="-"){ rows.push({kind:"del",text:raw.slice(1)}); }`,` else { rows.push({kind:"ctx",text: raw.charAt(0)===" " ? raw.slice(1) : raw}); }`,` }`,` if(rows.length>0 && rows[rows.length-1].kind==="ctx" && rows[rows.length-1].text===""){ rows.pop(); }`,` return rows;`,`}`,`function diffRowsFromToolInput(name, input){`,` var d=diffFromToolInput(name, input); if(!d) return null;`,` if(d.mode==="unified") return { caption:d.caption, rows:parseUnifiedDiff(d.patchText) };`,` return { caption:d.caption, rows:computeLineDiff(d.oldText, d.newText) };`,`}`].join(`
|
|
11
|
-
`);var vt={add:`+`,del:`-`,ctx:` `,meta:`@`};function yt({toolName:e,toolInput:t}){let n=(0,P.useMemo)(()=>_t(e,t),[e,t]);if(!n)return null;let{caption:r,rows:i}=n;if(i===null)return(0,N.jsxs)(`div`,{className:`hq-tool-empty`,children:[`diff too large to render — `,r]});let a=i.filter(e=>e.kind===`add`).length,o=i.filter(e=>e.kind===`del`).length;return(0,N.jsxs)(`div`,{className:`hq-diff`,children:[(0,N.jsxs)(`div`,{className:`hq-diff-stat`,children:[(0,N.jsx)(`span`,{className:`hq-diff-path`,title:r,children:r}),(0,N.jsxs)(`span`,{className:`hq-diff-add-count`,children:[`+`,a]}),(0,N.jsxs)(`span`,{className:`hq-diff-del-count`,children:[`-`,o]})]}),(0,N.jsx)(`pre`,{className:`hq-diff-body`,children:i.map((e,t)=>(0,N.jsxs)(`span`,{className:`hq-diff-line ${e.kind}`,children:[(0,N.jsx)(`span`,{className:`hq-diff-gutter`,children:vt[e.kind]}),e.text||` `]},t))})]})}function bt(e,t){return mt(e,t)!==null}var xt=25,Z=12;function Q({text:e,isError:t,wrap:n,framed:r=!0}){let i=(0,P.useMemo)(()=>e.split(`
|
|
12
|
-
`),[e]),a=i.length>xt,[o,s]=(0,P.useState)(!a),c=o?e:i.slice(0,Z).join(`
|
|
13
|
-
`);return(0,N.jsxs)(`div`,{className:`hq-result${r?``:` bare`}`,children:[(0,N.jsx)(`pre`,{className:`hq-result-pre ${n?`wrap`:`nowrap`}${t?` err`:``}`,children:c}),a&&(0,N.jsx)(`button`,{type:`button`,className:`hq-result-toggle`,onClick:()=>s(e=>!e),children:o?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(l,{size:12}),` collapse to `,Z,` lines`]}):(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(M,{size:12}),` show all `,i.length,` lines (+`,i.length-Z,` more)`]})})]})}function St(e,t){let n=t.trim();if(/^\s*\d+→/m.test(t.slice(0,200)))return{kind:`numbered`};if(n.startsWith(`{`)&&n.endsWith(`}`)||n.startsWith(`[`)&&n.endsWith(`]`))try{let e=JSON.parse(n);if(typeof e==`object`&&e)return{kind:`json`,value:e}}catch{}let r=!!e&&/^(bash|shell|exec|run|powershell)/i.test(e),i=t.match(/(?:^|\n)\s*(?:\[?exit(?:\s*code)?\]?\s*[:=]?\s*)(\d+)\s*$/i),a=t.match(/(?:^|\s)(\d+\s*ms|\d+\.\d+s)\s*$/i);if(r||i){let e=t;return i&&(e=t.slice(0,i.index).trimEnd()),{kind:`bash`,stdout:e,exitCode:i?Number(i[1]):void 0,duration:a?.[1]}}return{kind:`plain`}}function Ct({value:e,isError:n}){let r=(0,P.useMemo)(()=>{try{return JSON.stringify(e,null,2)}catch{return String(e)}},[e]),i=r.split(`
|
|
14
|
-
`).length,[a,o]=(0,P.useState)(i<30);return(0,N.jsxs)(`div`,{className:`hq-result${n?` err-frame`:``}`,children:[(0,N.jsxs)(`button`,{type:`button`,className:`hq-result-jsonbar`,onClick:()=>o(e=>!e),children:[(0,N.jsxs)(`span`,{className:`hq-result-jsonbar-left`,children:[a?(0,N.jsx)(f,{size:12}):(0,N.jsx)(t,{size:12}),(0,N.jsxs)(`span`,{children:[`JSON · `,i,` lines`]})]}),(0,N.jsx)(`span`,{children:a?`collapse`:`expand`})]}),a&&(0,N.jsx)(`pre`,{className:`hq-result-pre nowrap${n?` err`:``}`,children:r})]})}function wt({toolName:e,result:t,isError:n}){let r=(0,P.useMemo)(()=>St(e,t),[e,t]);return r.kind===`json`?(0,N.jsx)(Ct,{value:r.value,isError:n}):r.kind===`numbered`?(0,N.jsx)(Q,{text:t,isError:n,wrap:!1}):r.kind===`bash`?(0,N.jsxs)(`div`,{className:`hq-result hq-result-bash`,children:[r.stdout!==void 0&&r.stdout!==``&&(0,N.jsx)(Q,{text:r.stdout,isError:n,wrap:!0,framed:!1}),(r.exitCode!==void 0||r.duration!==void 0)&&(0,N.jsxs)(`div`,{className:`hq-result-exit${r.exitCode!==void 0&&r.exitCode!==0?` bad`:``}`,children:[r.exitCode!==void 0&&(0,N.jsxs)(`span`,{children:[`exit code `,r.exitCode]}),r.duration!==void 0&&(0,N.jsx)(`span`,{children:r.duration})]})]}):(0,N.jsx)(Q,{text:t,isError:n,wrap:!0})}var Tt={completed:`✔`,in_progress:`▶`,pending:`○`};function Et({todos:e}){let t=e.filter(e=>e.status===`completed`).length;return(0,N.jsxs)(`div`,{className:`hq-tool-section`,children:[(0,N.jsxs)(`div`,{className:`hq-tool-section-label`,children:[`todos · `,t,`/`,e.length,` done`]}),(0,N.jsx)(`ul`,{className:`hq-todo-list`,children:e.map((e,t)=>(0,N.jsxs)(`li`,{className:`hq-todo ${e.status}`,children:[(0,N.jsx)(`span`,{className:`hq-todo-mark`,children:Tt[e.status]}),(0,N.jsx)(`span`,{className:`hq-todo-text`,children:e.content||`(empty)`})]},t))})]})}function Dt({entry:e}){let t=at(e.tool),n=bt(e.tool,e.toolInput),r=t===`todo`?lt(e.toolInput):null,i=e.text??``,a=i.trim()!==``;return(0,N.jsxs)(`div`,{className:`hq-tool-body`,children:[n?(0,N.jsxs)(`div`,{className:`hq-tool-section`,children:[(0,N.jsx)(`div`,{className:`hq-tool-section-label`,children:`changes`}),(0,N.jsx)(yt,{toolName:e.tool,toolInput:e.toolInput}),a&&!e.isError&&(0,N.jsx)(`div`,{className:`hq-tool-result-note`,children:i.split(`
|
|
15
|
-
`)[0]})]}):r?(0,N.jsx)(Et,{todos:r}):e.toolInput!==void 0&&e.toolInput!==`{}`&&(0,N.jsxs)(`div`,{className:`hq-tool-section`,children:[(0,N.jsx)(`div`,{className:`hq-tool-section-label`,children:`input`}),(0,N.jsx)(`pre`,{className:`hq-tool-pre`,children:ct(e.toolInput)})]}),!n&&a&&(0,N.jsxs)(`div`,{className:`hq-tool-section`,children:[(0,N.jsxs)(`div`,{className:`hq-tool-section-head`,children:[(0,N.jsx)(`span`,{className:`hq-tool-section-label`,children:e.isError?`error`:`output`}),(0,N.jsx)(qe,{text:i,label:`copy`})]}),(0,N.jsx)(wt,{toolName:e.tool,result:i,isError:e.isError})]}),!a&&!e.isError&&!r&&!n&&(0,N.jsx)(`div`,{className:`hq-tool-empty`,children:`(no output)`})]})}function Ot({entry:e,running:n}){let[r,i]=(0,P.useState)(!1),o=st(e.tool,e.toolInput),s=ut(e.durationMs),c=dt(e.tool),{Icon:l,color:u}=et(e.tool);return(0,N.jsxs)(`div`,{className:`hq-chat-turn tool ${e.isError?`err`:``}`,children:[(0,N.jsxs)(`button`,{type:`button`,className:`hq-tool-head`,onClick:()=>i(e=>!e),children:[(0,N.jsx)(`span`,{className:`hq-tool-caret`,children:r?(0,N.jsx)(f,{size:13}):(0,N.jsx)(t,{size:13})}),(0,N.jsx)(`span`,{className:`hq-tool-icon`,style:{color:u},children:(0,N.jsx)(l,{size:14})}),(0,N.jsx)(`span`,{className:`hq-tool-name`,children:c}),o!==``&&(0,N.jsx)(`span`,{className:`hq-tool-summary`,children:o}),s!==``&&(0,N.jsx)(`span`,{className:`hq-tool-dur`,children:s}),(0,N.jsx)(`span`,{className:`hq-tool-status`,"aria-hidden":!0,children:n?(0,N.jsx)(`span`,{className:`hq-tool-running-dot`,title:`running`}):e.isError?(0,N.jsx)(w,{size:14,className:`hq-status-err`}):(0,N.jsx)(a,{size:14,className:`hq-status-ok`})})]}),r&&(0,N.jsx)(Dt,{entry:e})]})}function kt({entry:e}){let[n,r]=(0,P.useState)(!1),i=e.text.split(`
|
|
16
|
-
`)[0]??``;return(0,N.jsxs)(`div`,{className:`hq-chat-turn thinking`,children:[(0,N.jsxs)(`button`,{type:`button`,className:`hq-thinking-head`,onClick:()=>r(e=>!e),children:[(0,N.jsx)(`span`,{className:`hq-tool-caret`,children:n?(0,N.jsx)(f,{size:13}):(0,N.jsx)(t,{size:13})}),(0,N.jsx)(p,{size:13,className:`hq-thinking-icon`}),(0,N.jsx)(`span`,{className:`hq-thinking-label`,children:`thinking`}),!n&&(0,N.jsx)(`span`,{className:`hq-thinking-peek`,children:i})]}),n&&(0,N.jsx)(`div`,{className:`hq-thinking-body`,children:(0,N.jsx)(Ye,{text:e.text})})]})}var At=(0,P.memo)(function({entry:e,running:t}){let n=ft(e.ts);return e.role===`tool`||e.role===`error`&&e.toolInput!==void 0?(0,N.jsx)(Ot,{entry:e,running:t??q(e)}):e.role===`thinking`?(0,N.jsx)(kt,{entry:e}):e.role===`user`?(0,N.jsx)(`div`,{className:`hq-chat-turn user`,children:(0,N.jsxs)(`div`,{className:`hq-chat-bubble user`,children:[(0,N.jsxs)(`div`,{className:`hq-chat-role`,children:[`you`,e.agentId===void 0?``:` · ${e.agentId}`,n!==``&&(0,N.jsx)(`span`,{className:`hq-chat-clock`,children:n})]}),(0,N.jsx)(`div`,{className:`hq-chat-prose`,children:e.text})]})}):e.role===`assistant`?(0,N.jsx)(`div`,{className:`hq-chat-turn assistant`,children:(0,N.jsxs)(`div`,{className:`hq-chat-bubble assistant`,children:[(0,N.jsxs)(`div`,{className:`hq-chat-role`,children:[`agent`,e.agentId===void 0?``:` · ${e.agentId}`,n!==``&&(0,N.jsx)(`span`,{className:`hq-chat-clock`,children:n})]}),(0,N.jsx)(Ye,{text:e.text})]})}):e.role===`error`?(0,N.jsx)(`div`,{className:`hq-chat-turn error`,children:(0,N.jsxs)(`div`,{className:`hq-chat-bubble error`,children:[(0,N.jsxs)(`div`,{className:`hq-chat-role err`,children:[`error`,n!==``&&(0,N.jsx)(`span`,{className:`hq-chat-clock`,children:n})]}),(0,N.jsx)(`pre`,{className:`hq-tool-pre err`,children:e.text})]})}):e.text.trim()===``?null:(0,N.jsx)(`div`,{className:`hq-chat-turn system`,children:(0,N.jsxs)(`span`,{className:`hq-chat-system-line`,children:[e.text,n!==``&&(0,N.jsx)(`span`,{className:`hq-chat-clock`,children:n})]})})});function jt(e,t,n){if(t===`all`||n===void 0||n.length===0)return e;let r=new Set;if(t===`machine`)for(let t of e.nodes)t.machineId===n&&r.add(t.id);else{let t=new Set;for(let i of e.nodes)i.projectId===n&&(r.add(i.id),i.machineId!==void 0&&t.add(i.machineId));for(let n of e.nodes)n.kind===`machine`&&n.machineId!==void 0&&t.has(n.machineId)&&r.add(n.id)}return{nodes:e.nodes.filter(e=>r.has(e.id)),edges:e.edges.filter(e=>r.has(e.source)&&r.has(e.target))}}function Mt(e,t){let n=t.trim().toLocaleLowerCase();if(n.length===0)return e;let r=new Map(e.nodes.map(e=>[e.id,e])),i=new Map,a=new Map;for(let t of e.edges){i.set(t.target,t.source);let e=a.get(t.source)??[];e.push(t.target),a.set(t.source,e)}let o=new Set,s=new Set,c=e=>{let t=e;for(;t!==void 0&&!o.has(t);)o.add(t),t=i.get(t)},l=e=>{if(!s.has(e)){s.add(e),o.add(e);for(let t of a.get(e)??[])l(t)}};for(let t of e.nodes)[t.kind,t.label,t.sub,t.status,t.clientKind,t.serviceMode,t.machineId,t.projectId,t.clientId,t.sessionId,t.agentId,...t.chips].filter(e=>typeof e==`string`).join(` `).toLocaleLowerCase().includes(n)&&(c(t.id),l(t.id));for(let e of[...o])r.has(e)||o.delete(e);return{nodes:e.nodes.filter(e=>o.has(e.id)),edges:e.edges.filter(e=>o.has(e.source)&&o.has(e.target))}}function Nt(e){let t=new Map(e.nodes.map(e=>[e.id,e])),n=new Set(e.edges.map(e=>e.target)),r=new Map;for(let t of e.edges){let e=r.get(t.source)??[];e.push(t.target),r.set(t.source,e)}let i=[],a=new Set,o=e=>{if(a.has(e))return;a.add(e);let n=t.get(e);n!==void 0&&i.push(n);for(let t of r.get(e)??[])o(t)};for(let t of e.nodes)n.has(t.id)||o(t.id);for(let t of e.nodes)o(t.id);return i}function Pt(e){return e===`machine`?0:e===`project`?1:e===`terminal`?2:3}function Ft(e){let t=e.filter(e=>e.kind===`machine`),n=new Map,r=new Map,i=new Map;for(let t of e)if(t.kind===`project`&&t.machineId!==void 0){let e=n.get(t.machineId)??[];e.push(t),n.set(t.machineId,e)}else if(t.kind===`terminal`){let e=Lt(t.machineId??``,t.projectId??``),n=r.get(e)??[];n.push(t),r.set(e,n)}else if(t.kind===`agent`&&t.sessionId!==void 0){let e=i.get(t.sessionId)??[];e.push(t),i.set(t.sessionId,e)}let a=new Map,o=0,s=e=>e.length===0?0:((e[0]??0)+(e[e.length-1]??0))/2;for(let e of t){let t=n.get(e.machineId??``)??[],c=[];for(let e of t){let t=r.get(e.id)??[],n=[];for(let e of t){let t=i.get(e.sessionId??``)??[],r;if(t.length>0){let e=[];for(let n of t)a.set(n.id,o),e.push(o),o+=118;r=s(e)}else r=o,o+=118;a.set(e.id,r),n.push(r),o+=18}let l;n.length>0?l=s(n):(l=o,o+=118),a.set(e.id,l),c.push(l),o+=42}c.length>0?a.set(e.id,s(c)):(a.set(e.id,o),o+=118),o+=64}let c=new Map;for(let t of e)c.set(t.id,{x:Pt(t.kind)*300,y:a.get(t.id)??0});return c}function It(e){return`machine:${e}`}function Lt(e,t){return`project:${e}:${t}`}function Rt(e){return`terminal:${e}`}function zt(e,t){return`agent:${e}:${t}`}function $(e,t,n,r){let i=`${n}->${r}`;t.has(i)||(t.add(i),e.push({id:i,source:n,target:r}))}function Bt(e,t){return e?.projectName??t?.projectName??`unknown project`}function Vt(e,t){let n=e?.projectRootDisplay??t?.projectRoot;if(!(n===void 0||n.length===0))return n.length>54?`…${n.slice(-51)}`:n}function Ht(e){return e.clientKind===`mailbox`?`MAILBOX SERVE · ${e.pid??e.sessionId.slice(-8)}`:`${e.clientKind.toUpperCase()} · ${e.sessionId.length>18?`…${e.sessionId.slice(-14)}`:e.sessionId}`}function Ut(e,t){return{sessionId:e.sessionId??`client:${e.clientId}`,clientId:e.clientId,clientKind:e.kind,machineId:e.machineId,...e.hostname===void 0?{}:{hostname:e.hostname},...e.pid===void 0?{}:{pid:e.pid},projectId:e.projectId,projectName:t?.projectName??e.projectId,projectRoot:t?.projectRootDisplay??``,...t?.gitBranch===void 0?{}:{gitBranch:t.gitBranch},status:e.connected&&e.capabilities.includes(`mailbox.serve`)?`active`:e.connected?`idle`:`stale`,startedAt:e.connectedAt??e.lastSeenAt,lastActivityAt:e.lastSeenAt,agentCount:0,agents:[]}}function Wt(e,t,n,r){let i=t.get(e),a=n.find(t=>t.machineId===e),o=r.find(t=>t.machineId===e),s=i?.hostname??a?.hostname??o?.hostname??e,c=i?.sessionCount??n.filter(t=>t.machineId===e).length,l=i?.agentCount??n.reduce((t,n)=>t+(n.machineId===e?n.agents.length:0),0),u=i?.clientCount??r.filter(t=>t.machineId===e&&t.connected).length,d=r.filter(t=>t.machineId===e&&t.connected&&t.capabilities.includes(`mailbox.serve`)).length;return{label:s,sub:e,chips:[`${u} client${u===1?``:`s`}`,`${c} terminal${c===1?``:`s`}`,`${l} agent${l===1?``:`s`}`,...d>0?[`mailbox serve ×${d}`]:[]]}}function Gt(e){if(e===null)return{nodes:[],edges:[]};let t=[],n=[],r=new Set,i=new Set,a=new Map((e.machines??[]).map(e=>[e.machineId,e])),o=new Map((e.projects??[]).map(e=>[e.projectId,e])),s=[...e.liveSessions??[]],c=new Set(s.map(e=>e.sessionId)),l=new Set(s.filter(e=>e.pid!==void 0).map(e=>`${e.machineId}:${e.pid}`)),u=Date.parse(e.generatedAt);for(let t of e.clients??[]){if(!t.connected)continue;let e=t.capabilities?.includes(`mailbox.serve`)===!0;if(!t.capabilities?.includes(`session.summary`)&&!e||t.pid!==void 0&&l.has(`${t.machineId}:${t.pid}`))continue;let n=Date.parse(t.connectedAt??t.lastSeenAt);if(!e&&Number.isFinite(u)&&Number.isFinite(n)&&u-n>45e3)continue;let r=t.sessionId??`client:${t.clientId}`;c.has(r)||(s.push(Ut(t,o.get(t.projectId))),c.add(r))}let d=new Set;for(let t of e.machines??[])d.add(t.machineId);for(let e of s)d.add(e.machineId);for(let t of e.clients??[])t.connected&&d.add(t.machineId);for(let n of d){let i=It(n),o=Wt(n,a,s,e.clients??[]);t.push({id:i,kind:`machine`,label:o.label,sub:o.sub,chips:o.chips,machineId:n}),r.add(i)}let f=s.sort((e,t)=>{let n=e.machineId.localeCompare(t.machineId);if(n!==0)return n;let r=e.projectName.localeCompare(t.projectName);return r===0?e.sessionId.localeCompare(t.sessionId):r});for(let a of f){let s=a.machineId,c=o.get(a.projectId),l=Lt(s,a.projectId);if(!r.has(l)){let n=[`${c?.activeClients??f.filter(e=>e.machineId===s&&e.projectId===a.projectId).length} client${(c?.activeClients??0)===1?``:`s`}`,`${c?.activeSessions??f.filter(e=>e.machineId===s&&e.projectId===a.projectId).length} terminal${(c?.activeSessions??0)===1?``:`s`}`];c?.gitBranch!==void 0&&n.push(c.gitBranch),(e.clients??[]).filter(e=>e.connected&&e.machineId===s&&e.projectId===a.projectId&&e.capabilities.includes(`mailbox.serve`)).length>0&&n.push(`mailbox serve`),t.push({id:l,kind:`project`,label:Bt(c,a),sub:Vt(c,a),status:c?.status??a.status,chips:n,machineId:s,projectId:a.projectId}),r.add(l)}$(n,i,It(s),l);let u=Rt(a.sessionId);if(!r.has(u)){let e=a.sessionId.startsWith(`client:`)&&a.agents.length===0,n=a.clientKind===`mailbox`?`mailbox-serve`:void 0,i=[n===`mailbox-serve`?`mailbox serve`:a.clientKind,a.status,...n===void 0?[`${a.agentCount} agent${a.agentCount===1?``:`s`}`]:[]];a.gitBranch!==void 0&&i.push(a.gitBranch),t.push({id:u,kind:`terminal`,label:Ht(a),sub:n===`mailbox-serve`?`mailbox HTTP bridge`:e?`waiting for session telemetry`:a.projectName,status:a.status,chips:i,machineId:s,projectId:a.projectId,...a.clientId===void 0?{}:{clientId:a.clientId},sessionId:a.sessionId,clientKind:a.clientKind,session:a,isSyntheticSession:e,...n===void 0?{}:{serviceMode:n}}),r.add(u)}$(n,i,l,u);for(let e of a.agents){let r=zt(a.sessionId,e.id);t.push({id:r,kind:`agent`,label:e.name||e.id,sub:e.currentTool??e.partialText,status:e.status,chips:[e.status,`${e.iterations} iter`,`${e.toolCalls} tools`,...e.model===void 0?[]:[e.model]],machineId:s,projectId:a.projectId,...a.clientId===void 0?{}:{clientId:a.clientId},sessionId:a.sessionId,agentId:e.id,agent:e,session:a}),$(n,i,u,r)}}return{nodes:t,edges:n}}export{Ft as a,Ue as c,Pt as i,Ke as l,jt as n,Nt as o,Mt as r,At as s,Gt as t,Le as u};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/cockpit-CnFi0HLk.js","assets/rolldown-runtime-QTnfLwEv.js","assets/icons-C4ljWs50.js","assets/markdown--Y3iks7c.js","assets/fleet-map-CjeZ6E-P.js","assets/vendor-BwY1EM_9.js","assets/fleet-topology-BcXKnYKF.js","assets/live-console-CIxhBhTg.js","assets/mailbox-DnJYghSf.js","assets/use-backfilled-events-B4G6jrJe.js","assets/kanban-CsIHI3Wr.js","assets/cost-qSQMT1ZD.js","assets/brain-DxZxkdy0.js","assets/worktree-CC8bd1Ev.js","assets/trends-C8_-duaz.js","assets/alerts-C0ahAgyj.js","assets/control-D4n1t2nX.js","assets/settings-CiwxymER.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{A as t,Ct as n,D as r,F as i,Ft as a,Gt as o,P as s,Pt as c,Q as l,R as u,S as d,Tt as f,U as p,Ut as m,Xt as ee,Zt as te,a as ne,bt as re,d as ie,h as ae,i as oe,k as se,kt as ce,l as h,n as g,nt as _,o as le,qt as v,tt as y,ut as b,v as x,w as ue,y as de,yt as S}from"./icons-C4ljWs50.js";import{t as fe}from"./vendor-BwY1EM_9.js";import{i as C}from"./markdown--Y3iks7c.js";(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),e.crossOrigin===`use-credentials`?t.credentials=`include`:e.crossOrigin===`anonymous`?t.credentials=`omit`:t.credentials=`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var w={maxReconnectAttempts:10,initialBackoffMs:1e3,maxBackoffMs:3e4,backoffMultiplier:2,jitterRatio:0,queueLimit:1e3,heartbeatIntervalMs:0,heartbeatTimeoutMs:0};function T(){return{phase:`idle`,reconnectAttempt:0,lastActivityAt:null,stopped:!1}}function pe(e){return e.stopped?e:{...e,phase:`connecting`}}function me(e,t=Date.now()){return{...e,phase:`open`,reconnectAttempt:0,lastActivityAt:t,stopped:!1}}function E(e,t=Date.now()){return{...e,lastActivityAt:t}}function he(e){return{...e,phase:`closed`,stopped:!0}}function ge(e,t,n=Date.now(),r=Math.random){if(e.stopped||e.reconnectAttempt>=t.maxReconnectAttempts)return{state:{...e,phase:`closed`},plan:null};let i=e.reconnectAttempt+1,a=Math.min(t.initialBackoffMs*t.backoffMultiplier**(i-1),t.maxBackoffMs),o=(r()*2-1)*t.jitterRatio,s=Math.max(0,Math.round(a*(1+o)));return{state:{...e,phase:`reconnecting`,reconnectAttempt:i},plan:{attempt:i,delayMs:s,retryAt:n+s}}}function D(e,t,n=Date.now()){return e.phase!==`open`||e.lastActivityAt===null||t.heartbeatIntervalMs<=0?!1:n-e.lastActivityAt>t.heartbeatIntervalMs+t.heartbeatTimeoutMs}var _e=`abort,ping,user_message,tool.confirm_result,topic.advice,completion.request,model.switch,model.refine,model.fallback_choice,autonomy.switch,context.clear,context.compact,context.debug,context.editor.open,context.editor.validate,context.editor.apply,context.mode.create,context.mode.delete,context.mode.switch,context.mode.update,context.modes.list,context.repair,mode.switch,modes.list,session.checkpoints,session.delete,session.inspect,session.new,session.rename,session.resume,session.rewind,session.save,sessions.list,side_effects.list,stats.get,todo.update,todos.clear,todos.get,todos.remove`.split(`,`),ve=[`collab.join`,`collab.leave`,`collab.annotate`,`collab.resolve`,`collab.request_pause`,`collab.resume`,`collab.grant_control`,`collab.inject_tool`,`mailbox.action`,`mailbox.agents`,`mailbox.clear`,`mailbox.compact`,`mailbox.messages`,`mailbox.purge`,`mailbox.send`],ye=`brain.ask,brain.config.get,brain.config.set,brain.risk,brain.status,chronicle.facet,chronicle.facets,chronicle.graph,chronicle.metrics,chronicle.query,chronicle.status,config.doctor,design.list,design.materialize,design.set,design.state,design.swap,design.tune,design.use,design.verify,memory.list,memory.sage.backfillRecoverable,memory.sage.candidateResolve,memory.sage.delete,memory.sage.forFile,memory.sage.get,memory.sage.graph,memory.sage.list,memory.sage.listCandidates,memory.sage.listPage,memory.sage.recover,memory.sage.remember,memory.sage.update`.split(`,`),be=`auth.oauth.cancel,auth.oauth.code,auth.oauth.start,mcp.add,mcp.disable,mcp.discover,mcp.enable,mcp.list,mcp.prompt.get,mcp.prompts,mcp.remove,mcp.resource.read,mcp.resources,mcp.restart,mcp.sleep,mcp.update,mcp.wake,prompts.content,prompts.create,prompts.favorite,prompts.list,prompts.recent,prompts.search,prompts.used,skills.content,skills.create,skills.edit,skills.export,skills.install,skills.list,skills.uninstall,skills.update`.split(`,`),xe=`goal-state.get,goal.addTask,goal.assess,goal.assignTask,goal.clear,goal.get,goal.list,goal.load,goal.moveTask,goal.pause,goal.resume,goal.retryTask,goal.revert,goal.runTask,goal.save,goal.selectPhase,goal.start,goal.state,goal.status,goal.stop,goal.taskStatus,goal.toggleAutonomous,plan.get,plan.item.update,plan.template_use,task.update,tasks.get`.split(`,`),Se=`sdd.board.cancel_task,sdd.board.cleanup_worktrees,sdd.board.delete_task,sdd.board.destroy,sdd.board.get,sdd.board.list,sdd.board.pause,sdd.board.reassign,sdd.board.resume,sdd.board.retry,sdd.board.retry_all_failed,sdd.board.rollback,sdd.board.set_task_fallbacks,sdd.board.set_task_model,sdd.board.set_task_verification,sdd.board.split_task,sdd.board.stop,sdd.run.from_graph,sdd.run.from_spec,sdd.run.start,sdd.spec.approve,sdd.spec.discard,sdd.spec.get,sdd.spec.message,sdd.spec.start,specs.get,specs.list,specs.taskStatus`.split(`,`),Ce=[`files.list`,`files.read`,`files.tree`,`files.write`,`git.changes`,`git.diff`,`git.info`,`projects.add`,`projects.list`,`projects.select`,`working_dir.set`,`worktree.cleanup`,`worktree.diff`,`worktree.merge`,`worktree.remove`,`worktree.scan`,`shell.open`,`process.kill`,`process.killAll`,`process.list`,`terminal.close`,`terminal.create`,`terminal.input`,`terminal.resize`],we=`codebase.index.server.shutdown,connections.health,connections.service_action,diag.get,key.add,key.delete,key.set_active,key.update,prefs.get,prefs.update,provider.add,provider.clear_models,provider.custom_models.remove,provider.custom_models.set,provider.models,provider.models.search,provider.probe,provider.remove,provider.status.clear,provider.status.get,provider.status.retry,provider.undo_clear,provider.update,providers.list,providers.saved,tool.disable,tool.enable,tools.list,webui.shutdown`.split(`,`),Te=`error,log,pong,side_effects,agent.status_changed,agent.timeline.message,client.status_update,chimera.report_available,compaction.failed,completion.result,context.compacted,context.debug,context.editor.snapshot,context.editor.validation,context.editor.applied,context.mode.changed,context.modes.list,context.repaired,ctx.max_context,ctx.pct,delegate.completed,delegate.started,iteration.completed,iteration.limit_reached,iteration.started,model.refine_result,modes.list,provider.active_blocked,provider.error,provider.fallback,provider.fallback_pending,provider.response,provider.retry,provider.status_changed,provider.stream_error,provider.text_delta,provider.thinking_delta,run.result,session.checkpoints,session.damaged,session.end,session.inspect,session.rewound,session.start,session.stats,sessions.list,sessions.status_update,stats.get,token.cost_estimate_unavailable,token.threshold,tool.confirm_needed,tool.disabled,tool.enabled,tool.executed,tool.loop_detected,tool.progress,tool.started,topic.advice_result,tools.list,trust.persisted`.split(`,`),Ee=[`collab.annotation.added`,`collab.annotation.resolved`,`collab.event`,`collab.injection.granted`,`collab.participant.joined`,`collab.participant.left`,`collab.pause.granted`,`collab.pause.released`,`collab.state`,`mailbox.action_result`,`mailbox.agent_registered`,`mailbox.agent_deregistered`,`mailbox.agents`,`mailbox.cleared`,`mailbox.compacted`,`mailbox.event`,`mailbox.messages`,`mailbox.sent`,`mailbox.purged`,`mailbox.received`,`subagent.budget_extended`,`subagent.event`],De=`brain.answer,brain.config,brain.event,brain.status,chronicle.error,chronicle.facet_result,chronicle.facets_result,chronicle.graph_result,chronicle.metrics_result,chronicle.query_result,chronicle.status_result,config.doctor.result,design.list,design.materialize,design.set,design.state,design.swap,design.tune,design.use,design.verify,memory.event,memory.list,memory.sage.backfillRecoverable,memory.sage.candidateResolve,memory.sage.delete,memory.sage.forFile,memory.sage.get,memory.sage.graph,memory.sage.list,memory.sage.listCandidates,memory.sage.listPage,memory.sage.recover,memory.sage.remember,memory.sage.update`.split(`,`),Oe=`mcp.content.error,mcp.content.selected,mcp.list,mcp.operation_result,mcp.prompts,mcp.resources,mcp.server.added,mcp.server.connected,mcp.server.disconnected,mcp.server.discovered,mcp.server.error,mcp.server.reconnected,mcp.server.removed,mcp.server.sleeping,mcp.server.updated,mcp.server.waking,prompts.content,prompts.created,prompts.favorite,prompts.list,prompts.recent,prompts.search,prompts.used,skills.content,skills.created,skills.edited,skills.exported,skills.installed,skills.list,skills.uninstalled,skills.updated`.split(`,`),ke=`budget.decision,budget.threshold_reached,coordinator.stats,coordinator.status,eternal.iteration,fleet.concurrency_update,goal-state.updated,goal.assess.result,goal.list,goal.paused,goal.resumed,goal.saved,goal.error,goal.stopped,goal.failed,goal.completed,goal.cleared,goal.reverted,goal.progress,goal.state,in_flight.ended,in_flight.started,plan.updated,task.completed,task.failed,task.pending,task.started,tasks.updated,todos.cleared,todos.updated`.split(`,`),Ae=[`kanban.task.activity`,`sdd.board.lifecycle_result`,`sdd.board.list`,`sdd.board.snapshot`,`sdd.run.started`,`sdd.spec.agent_text`,`sdd.spec.error`,`sdd.spec.snapshot`,`specs.detail`,`specs.list`],je=[`consensus.vote_cast`,`consensus.vote_initiated`,`consensus.vote_resolved`,`cron.job_fired`,`cron.snapshot`,`techstack.job.cancelled`,`techstack.job.failed`,`techstack.job.progress`,`techstack.job.started`,`techstack.report.delivered`,`techstack.report.ready`,`techstack.snapshot.updated`,`techstack.workspace.completed`],Me=`checkpoint.written,codemap.file_event,codemap.index_updated,codemap.tool_executed,codemap.tool_started,file.saved,files.list,files.read,files.tree,files.written,git.changes,git.diff,git.info,process.list,projects.added,projects.list,projects.selected,terminal.exit,terminal.output,working_dir.changed,worktree.cleanup_result,worktree.diff_result,worktree.event,worktree.merge_result,worktree.orphans,worktree.state`.split(`,`),Ne=[`auth.oauth.status`,`codebase.index.server.shutdown_result`,`connections.health_error`,`connections.health_result`,`connections.service_action_result`,`diag.get`,`key.operation_result`,`model.switch_result`,`prefs.updated`,`provider.catalog`,`provider.models`,`provider.models.search_result`,`provider.probe`,`provider.status.snapshot`,`providers.saved`],Pe=[..._e,...ve,...Ce,...we,...xe,...Se,...ye,...be],Fe=[...Te,...Ee,...Me,...Ne,...ke,...Ae,...je,...De,...Oe];new Set(Pe),new Set(Fe);function O(e){return typeof e==`object`&&e&&!Array.isArray(e)?e:null}function k(e,t=0){return typeof e==`number`&&Number.isFinite(e)?e:t}function A(e){return e===void 0||Array.isArray(e)}function Ie(e){return k(e.activeProjects)===e.activeProjects&&k(e.activeClients)===e.activeClients&&k(e.activeSessions)===e.activeSessions&&k(e.activeSubagents)===e.activeSubagents&&k(e.unreadMailboxMessages)===e.unreadMailboxMessages&&k(e.incompleteMailboxMessages)===e.incompleteMailboxMessages&&k(e.totalCostUsd)===e.totalCostUsd}function Le(e){if(e.type!==`hq.snapshot`)return null;let t=O(e.snapshot),n=t?O(t.totals):null;return!t||typeof t.generatedAt!=`string`||!Array.isArray(t.clients)||!Array.isArray(t.projects)||!Array.isArray(t.sessions)||!Array.isArray(t.fleets)||!Array.isArray(t.mailboxes)||!n||!Ie(n)||!A(t.machines)||!A(t.liveSessions)||!A(t.mcpServers)?null:{kind:`hq-snapshot`,snapshot:t}}function Re(e){if(e.type!==`hq.event`)return null;let t=O(e.event);return!t||typeof t.id!=`string`||typeof t.type!=`string`||typeof t.timestamp!=`string`||typeof t.clientId!=`string`||typeof t.projectId!=`string`||typeof t.seq!=`number`?null:{kind:`hq-event`,event:t}}function ze(e){return e.type!==`hq.alert`||typeof e.severity!=`string`||![`info`,`warn`,`error`].includes(e.severity)||typeof e.message!=`string`||typeof e.timestamp!=`string`?null:{kind:`hq-alert`,alert:e}}function Be(e){if(e.type!==`hq.command_status`)return null;let t=O(e.command);return!t||typeof t.commandId!=`string`||typeof t.type!=`string`||typeof t.clientId!=`string`||typeof t.enqueuedBy!=`string`||typeof t.enqueuedAt!=`string`||typeof t.status!=`string`||![`queued`,`delivered`,`acked`].includes(t.status)?null:{kind:`hq-command-status`,command:t}}var j=e(te(),1),Ve=fe(),He=e=>Symbol.iterator in e,Ue=e=>`entries`in e,We=(e,t)=>{let n=e instanceof Map?e:new Map(e.entries()),r=t instanceof Map?t:new Map(t.entries());if(n.size!==r.size)return!1;for(let[e,t]of n)if(!r.has(e)||!Object.is(t,r.get(e)))return!1;return!0},Ge=(e,t)=>{let n=e[Symbol.iterator](),r=t[Symbol.iterator](),i=n.next(),a=r.next();for(;!i.done&&!a.done;){if(!Object.is(i.value,a.value))return!1;i=n.next(),a=r.next()}return!!i.done&&!!a.done};function Ke(e,t){return Object.is(e,t)?!0:typeof e!=`object`||!e||typeof t!=`object`||!t||Object.getPrototypeOf(e)!==Object.getPrototypeOf(t)?!1:He(e)&&He(t)?Ue(e)&&Ue(t)?We(e,t):Ge(e,t):We({entries:()=>Object.entries(e)},{entries:()=>Object.entries(t)})}function M(e){let t=j.useRef(void 0);return n=>{let r=e(n);return Ke(t.current,r)?t.current:t.current=r}}var N=`wrongstack.hq.token.v1`;function qe(){if(typeof window>`u`)return null;try{let e=new URLSearchParams(window.location.search).get(`token`);return e!==null&&e.length>0?e:null}catch{return null}}function P(){if(typeof window>`u`)return null;try{return window.localStorage??null}catch{return null}}function F(){if(typeof window>`u`)return null;try{return window.sessionStorage??null}catch{return null}}function I(){try{let e=P()?.getItem(N)??null;if(e!==null&&e.length>0)return e}catch{}return Je()}function Je(){try{let e=F()?.getItem(N)??null;if(e===null||e.length===0)return null;let t=!1;try{let n=P();n!==null&&(n.setItem(N,e),t=n.getItem(N)===e)}catch{}if(t)try{F()?.removeItem(N)}catch{}return e}catch{return null}}function Ye(e){try{P()?.setItem(N,e)}catch{}}function L(){try{P()?.removeItem(N)}catch{}try{F()?.removeItem(N)}catch{}}function Xe(){let e=qe();return e===null?I():(Ye(e),e)}function Ze(){if(typeof window>`u`)return;let e=qe();if(e!==null&&(Ye(e),I()===e))try{let e=new URL(window.location.href);e.searchParams.delete(`token`),window.history.replaceState(null,``,`${e.pathname}${e.search}${e.hash}`)}catch{}}function Qe(){let e=Xe();return e===null?{}:{Authorization:`Bearer ${e}`}}function R(e,t){let n={...t?.headers??{},...Qe()};return fetch(e,{...t,headers:n})}function $e(e){let t=e.trim();if(!/[?&]token=/.test(t))return t;try{let e=typeof window>`u`?`http://127.0.0.1/`:window.location.href;return new URL(t,e).searchParams.get(`token`)?.trim()||t}catch{return t}}async function et(e){return fetch(`/api/auth/upgrade`,{method:`POST`,headers:{Authorization:`Bearer ${e}`},credentials:`same-origin`,signal:AbortSignal.timeout(1e4)})}async function tt(e){let t=$e(e);if(t.length===0)return{ok:!1,message:`Enter a browser token.`};try{let e=await et(t),n={};try{n=await e.json()}catch{}if(e.ok&&n.loggedIn===!0)return Ye(t),{ok:!0};let r=n.error;return{ok:!1,message:typeof r==`string`?r:typeof r?.message==`string`?r.message:e.status===401?`The browser token was rejected. It may be invalid, expired, or revoked.`:`HQ could not start a browser session with this token.`}}catch{return{ok:!1,message:`Could not reach the HQ server. Try again.`}}}function nt(){if(typeof window>`u`)return null;try{let e=window.location.hash;if(!e.startsWith(`#bootstrap=`))return null;let t=e.slice(11);return t.length>0?t:null}catch{return null}}function rt(){if(!(typeof window>`u`))try{let e=new URL(window.location.href);e.hash.startsWith(`#bootstrap=`)&&(e.hash=``,window.history.replaceState(null,``,`${e.pathname}${e.search}`))}catch{}}async function it(){let e=nt();if(e===null)return!1;try{return(await fetch(`/api/auth/bootstrap`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({code:e}),credentials:`same-origin`,signal:AbortSignal.timeout(1e4)})).ok?(rt(),L(),!0):!1}catch{return!1}}async function at(){let e=I();if(e===null)return!1;try{let t=await et(e);return!(!t.ok||(await t.json()).loggedIn!==!0)}catch{return!1}}var ot=e=>{let t,n=new Set,r=(e,r)=>{let i=typeof e==`function`?e(t):e;if(!Object.is(i,t)){let e=t;t=r??(typeof i!=`object`||!i)?i:Object.assign({},t,i),n.forEach(n=>n(t,e))}},i=()=>t,a={setState:r,getState:i,getInitialState:()=>o,subscribe:e=>(n.add(e),()=>n.delete(e))},o=t=e(r,i,a);return a},st=(e=>e?ot(e):ot),ct=e=>e;function lt(e,t=ct){let n=j.useSyncExternalStore(e.subscribe,j.useCallback(()=>t(e.getState()),[e,t]),j.useCallback(()=>t(e.getInitialState()),[e,t]));return j.useDebugValue(n),n}var ut=e=>{let t=st(e),n=e=>lt(t,e);return Object.assign(n,t),n},dt=(e=>e?ut(e):ut),ft=6e3,pt=0,mt=dt()(e=>({toasts:[],addToast:(t,n=`info`,r=ft,i)=>{let a=`toast-${++pt}-${Date.now()}`,o={id:a,message:t,severity:n,createdAt:Date.now(),ttlMs:r,action:i};e(e=>({toasts:[...e.toasts.slice(-4),o]})),r>0&&setTimeout(()=>{e(e=>({toasts:e.toasts.filter(e=>e.id!==a)}))},r)},removeToast:t=>e(e=>({toasts:e.toasts.filter(e=>e.id!==t)})),clearToasts:()=>e({toasts:[]})})),z=C(),ht={error:(0,z.jsx)(ce,{size:16,"aria-hidden":`true`}),warning:(0,z.jsx)(h,{size:16,"aria-hidden":`true`}),info:(0,z.jsx)(y,{size:16,"aria-hidden":`true`}),success:(0,z.jsx)(a,{size:16,"aria-hidden":`true`})};function gt(){let{toasts:e,removeToast:t}=mt(M(e=>({toasts:e.toasts,removeToast:e.removeToast})));return e.length===0?null:(0,z.jsx)(`div`,{className:`hq-toast-container`,role:`status`,"aria-live":`polite`,"aria-label":`Notifications`,children:e.map(e=>(0,z.jsxs)(`div`,{className:`hq-toast hq-toast--${e.severity}`,"data-severity":e.severity,children:[(0,z.jsx)(`span`,{className:`hq-toast-icon`,children:ht[e.severity]}),(0,z.jsx)(`span`,{className:`hq-toast-message`,children:e.message}),e.action?(0,z.jsx)(`span`,{className:`hq-toast-action`,children:e.action}):null,(0,z.jsx)(`button`,{type:`button`,className:`hq-toast-close`,"aria-label":`Dismiss notification`,onClick:()=>t(e.id),children:(0,z.jsx)(g,{size:12})})]},e.id))})}var _t=new Set([`graceful`,`crash`,`heartbeat-timeout`,`auth-revoked`]),B=`__hq_peer__`;function vt(e){return e===void 0||typeof e==`string`}function yt(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=e;return!(typeof t.projectId!=`string`||t.projectId.length===0||typeof t.machineId!=`string`||t.machineId.length===0||typeof t.leaderClientId!=`string`||t.leaderClientId.length===0||typeof t.previousLeaderHandle!=`string`||t.previousLeaderHandle.length===0||typeof t.reason!=`string`||!_t.has(t.reason)||typeof t.detectedAt!=`string`||!Number.isFinite(Date.parse(t.detectedAt))||!vt(t.rehydrateHint)||t.rehydrateHint!==void 0&&t.rehydrateHint.length>280||!vt(t.rehydrateCommandId))}function bt(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=e;return!(typeof t.projectId!=`string`||t.projectId.length===0||typeof t.machineId!=`string`||t.machineId.length===0||typeof t.leaderClientId!=`string`||t.leaderClientId.length===0||typeof t.previousLeaderHandle!=`string`||t.previousLeaderHandle.length===0||typeof t.reason!=`string`||!_t.has(t.reason)||typeof t.detectedAt!=`string`||!Number.isFinite(Date.parse(t.detectedAt)))}function xt(e,t){let n=t.liveSessions??[],r=e.selectedSessionId===null?void 0:n.find(t=>t.sessionId===e.selectedSessionId),i=e.selectedAgentId===null||r?.agents.some(t=>t.id===e.selectedAgentId)===!0,a=e.selectedClientId===null||t.clients.some(t=>t.clientId===e.selectedClientId);return{snapshot:t,...e.selectedSessionId!==null&&r===void 0?{selectedSessionId:null,selectedAgentId:null}:i?{}:{selectedAgentId:null},...a?{}:{selectedClientId:null}}}function St(e,t){return e.timestamp===t.timestamp&&e.severity===t.severity&&e.message===t.message}var V=dt()(e=>({snapshot:null,events:[],alerts:[],commandStatuses:[],activeView:`cockpit`,selectedSessionId:null,selectedAgentId:null,selectedClientId:null,connected:!1,authRequired:!1,resumeCursors:{},needsSnapshotRefresh:!1,peerRehydrate:null,setActiveView:t=>e({activeView:t}),selectSession:(t,n=null)=>e({selectedSessionId:t,selectedAgentId:n}),selectAgent:(t,n)=>e({selectedSessionId:t,selectedAgentId:n}),selectClient:t=>e({selectedClientId:t}),markAuthRequired:()=>e(e=>e.authRequired?{}:{authRequired:!0}),_hydrateSnapshot:t=>e(e=>e.snapshot===null?xt(e,t):{}),_onSnapshot:t=>e(e=>{let n=e.snapshot;return n!==null&&typeof n.generatedAt==`string`&&typeof t.generatedAt==`string`&&Date.parse(t.generatedAt)<Date.parse(n.generatedAt)?{}:{...xt(e,t),connected:!0}}),_resetResumeCursors:()=>e({resumeCursors:{}}),_onEvent:t=>e(e=>{let n=e.events.some(e=>e.id===t.id),r=n?{}:{events:[...e.events,t].slice(-500)},i=t.type===`peer.rehydrate`||t.type===`peer.lost`?e=>({}):n=>{let r=e.resumeCursors[n]??0,i=t.seq,a=r>0&&i>0&&i<=r/2&&t.type!==`client.hello`;return i>r||a?{resumeCursors:{...e.resumeCursors,[n]:i}}:{}};if(t.type===`peer.rehydrate`){if(!yt(t.payload))return r;let e={kind:`peer.rehydrate`,payload:t.payload,receivedAt:new Date().toISOString()};return{...r,...i(B),...n?{}:{peerRehydrate:e}}}if(t.type===`peer.lost`){if(!bt(t.payload))return r;let e={kind:`peer.lost`,payload:t.payload,receivedAt:new Date().toISOString()};return{...r,...i(B),...n?{}:{peerRehydrate:e}}}return{...r,...i(t.clientId)}}),_onAlert:t=>e(e=>e.alerts.some(e=>St(e,t))?{}:{alerts:[...e.alerts,t].slice(-100)}),_onCommandStatus:t=>e(e=>{let n=e.commandStatuses.findIndex(e=>e.commandId===t.commandId);if(n<0)return{commandStatuses:[...e.commandStatuses,t].slice(-200)};let r=[...e.commandStatuses];return r[n]=t,{commandStatuses:r}}),_setConnected:t=>e({connected:t}),_setNeedsSnapshotRefresh:t=>e(e=>e.needsSnapshotRefresh===t?{}:{needsSnapshotRefresh:t}),_dismissPeerRehydrate:()=>e({peerRehydrate:null})}));async function H(e){let t;try{t=await R(e)}catch{throw Error(`Network error fetching ${e}`)}if(t.status===401)throw V.getState().markAuthRequired(),Error(`401 Unauthorized fetching ${e} — browser token required`);if(!t.ok)throw Error(`${t.status} ${t.statusText}`);try{return await t.json()}catch{throw Error(`Invalid JSON response from ${e}: ${t.status}`)}}async function Ct(e){let t;try{t=await R(`/api/mailbox-send`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)})}catch{throw Error(`Network error sending mailbox message`)}if(t.status===401)throw V.getState().markAuthRequired(),Error(`401 Unauthorized — browser token required`);if(!t.ok){let e=await t.json().catch(()=>null),n=typeof e?.error==`string`?e.error:t.statusText||`HTTP ${t.status}`;throw Error(n)}try{return await t.json()}catch{throw Error(`Invalid JSON response from mailbox-send API`)}}async function wt(e,t,n){let r;try{r=await R(`/api/command`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({clientId:e,type:t,payload:n})})}catch{throw Error(`Network error sending command`)}if(r.status===401)throw V.getState().markAuthRequired(),Error(`401 Unauthorized — browser token required`);if(!r.ok){let e=(await r.json().catch(()=>null))?.error??(r.statusText||`HTTP ${r.status}`);throw Error(e)}try{return await r.json()}catch{throw Error(`Invalid JSON response from command API`)}}var Tt=`wrongstack.hq.local-prefs.v1`,U={appearance:{theme:`dark`},fleet:{scope:`all`,layout:`map`,machineId:``,projectId:``},console:{delivery:`steer`,subject:``,body:``},control:{cmdType:`steer`,abortTarget:`leader`,spawnRole:`bug-hunter`,spawnTask:``,steerTo:`leader`,steerSubject:``,steerBody:``,broadcastSubject:``,broadcastBody:``},mailbox:{query:``,types:[],priorities:[],includeCompleted:!0}},W=null,Et=new Set;function G(){for(let e of Et)e()}function K(e){return typeof structuredClone==`function`?structuredClone(e):JSON.parse(JSON.stringify(e))}function q(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Dt(){if(typeof window>`u`||window.localStorage===void 0)return K(U);try{let e=window.localStorage.getItem(Tt);return e===null?K(U):Ot(JSON.parse(e))}catch{return K(U)}}function Ot(e){if(!q(e))return K(U);let t=q(e.appearance)?e.appearance:{},n=q(e.fleet)?e.fleet:{},r=q(e.console)?e.console:{},i=q(e.control)?e.control:{},a=q(e.mailbox)?e.mailbox:{};return{appearance:{theme:t.theme===`light`?`light`:`dark`},fleet:{scope:n.scope===`machine`||n.scope===`project`?n.scope:`all`,layout:n.layout===`compact`?`compact`:`map`,machineId:typeof n.machineId==`string`?n.machineId:``,projectId:typeof n.projectId==`string`?n.projectId:``},console:{delivery:r.delivery===`btw`||r.delivery===`queue`?r.delivery:`steer`,subject:typeof r.subject==`string`?r.subject:``,body:typeof r.body==`string`?r.body:``},control:{cmdType:i.cmdType===`btw`||i.cmdType===`queue`||i.cmdType===`abort`||i.cmdType===`spawn`||i.cmdType===`broadcast`||i.cmdType===`run-command`?i.cmdType:U.control.cmdType,abortTarget:i.abortTarget===`fleet`?`fleet`:`leader`,spawnRole:typeof i.spawnRole==`string`&&i.spawnRole.length>0?i.spawnRole:U.control.spawnRole,spawnTask:typeof i.spawnTask==`string`?i.spawnTask:U.control.spawnTask,steerTo:typeof i.steerTo==`string`?i.steerTo:U.control.steerTo,steerSubject:typeof i.steerSubject==`string`?i.steerSubject:U.control.steerSubject,steerBody:typeof i.steerBody==`string`?i.steerBody:U.control.steerBody,broadcastSubject:typeof i.broadcastSubject==`string`?i.broadcastSubject:U.control.broadcastSubject,broadcastBody:typeof i.broadcastBody==`string`?i.broadcastBody:U.control.broadcastBody},mailbox:{query:typeof a.query==`string`?a.query:U.mailbox.query,types:Array.isArray(a.types)?a.types.filter(e=>typeof e==`string`):[],priorities:Array.isArray(a.priorities)?a.priorities.filter(e=>typeof e==`string`):[],includeCompleted:typeof a.includeCompleted!=`boolean`||a.includeCompleted}}}function J(){return W===null&&(W=Dt()),W}function Y(e){if(!(typeof window>`u`||window.localStorage===void 0))try{window.localStorage.setItem(Tt,JSON.stringify(e))}catch{}}function kt(e){return Et.add(e),()=>Et.delete(e)}function At(){return J()}function jt(){return U}function Mt(){return(0,j.useSyncExternalStore)(kt,At,jt)}function Nt(e){let t=J();W={...t,control:{...t.control,...e}},Y(W),G()}function Pt(e){let t=J();W={...t,appearance:{...t.appearance,...e}},Y(W),G()}function Ft(e){let t=J();W={...t,fleet:{...t.fleet,...e}},Y(W),G()}function It(e){let t=J();W={...t,console:{...t.console,...e}},Y(W),G()}function Lt(e){let t=J();W={...t,mailbox:{...t.mailbox,...e}},Y(W),G()}function Rt({value:e,onChange:t,onKeyDown:n,inputRef:r,placeholder:i,autoComplete:a,minLength:o,maxLength:s,className:c,id:l}){let[u,d]=(0,j.useState)(!1);return(0,z.jsxs)(`div`,{className:`hq-password-input-wrapper`,children:[(0,z.jsx)(`input`,{ref:r,id:l,type:u?`text`:`password`,className:c??`hq-token-input`,placeholder:i,autoComplete:a,minLength:o,maxLength:s,value:e,onChange:e=>t(e.target.value),onKeyDown:n}),(0,z.jsx)(`button`,{type:`button`,className:`hq-password-toggle`,onMouseDown:e=>e.preventDefault(),onClick:()=>d(e=>!e),"aria-label":u?`Hide password`:`Show password`,"aria-pressed":u,children:u?(0,z.jsx)(re,{size:14}):(0,z.jsx)(S,{size:14})})]})}function zt({hadToken:e,onAuthenticated:t=()=>window.location.reload()}){let[n,r]=(0,j.useState)(null),[i,a]=(0,j.useState)(null);(0,j.useEffect)(()=>{fetch(`/api/auth/status`).then(async e=>{if(!e.ok)throw Error(`HTTP ${e.status}`);return await e.json()}).then(r).catch(()=>a(`Could not load HQ auth status.`))},[]);let o=n?.tokenMode??!0,s=n?.passwordMode??!1,[c,l]=(0,j.useState)(null),u=c??(e&&o?`token`:s?`password`:`token`);return i?(0,z.jsx)(`div`,{className:`hq-token-gate`,children:(0,z.jsxs)(`div`,{className:`hq-token-card`,children:[(0,z.jsx)(`div`,{className:`hq-brand`,children:`WrongStack HQ`}),(0,z.jsx)(`div`,{className:`hq-token-title`,children:`Auth status unavailable`}),(0,z.jsx)(`p`,{className:`hq-token-text`,children:i})]})}):n?(0,z.jsx)(`div`,{className:`hq-token-gate`,children:(0,z.jsxs)(`div`,{className:`hq-token-card`,children:[(0,z.jsx)(`div`,{className:`hq-brand`,children:`WrongStack HQ`}),o&&s?(0,z.jsxs)(`div`,{className:`hq-token-tabs`,children:[(0,z.jsx)(`button`,{type:`button`,className:`hq-token-tab`+(u===`token`?` active`:``),onClick:()=>l(`token`),children:`Browser token`}),(0,z.jsx)(`button`,{type:`button`,className:`hq-token-tab`+(u===`password`?` active`:``),onClick:()=>l(`password`),children:`Password`})]}):null,u===`token`||!s?(0,z.jsx)(Bt,{hadToken:e,onAuthenticated:t}):(0,z.jsx)(Vt,{})]})}):(0,z.jsx)(`div`,{className:`hq-token-gate`,children:(0,z.jsxs)(`div`,{className:`hq-token-card`,children:[(0,z.jsx)(`div`,{className:`hq-brand`,children:`WrongStack HQ`}),(0,z.jsx)(`div`,{className:`hq-token-title`,children:`Checking auth mode…`})]})})}function Bt({hadToken:e,onAuthenticated:t}){let[n,r]=(0,j.useState)(``),[i,a]=(0,j.useState)(null),[o,s]=(0,j.useState)(!1),c=(0,j.useRef)(null),l=(0,j.useRef)(!1);(0,j.useEffect)(()=>{c.current?.focus()},[]);let u=async()=>{if(o||l.current||n.trim().length===0)return;l.current=!0,s(!0),a(null);let e=await tt(n);if(e.ok){t();return}a(e.message??`The browser token was rejected.`),l.current=!1,s(!1)};return(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`div`,{className:`hq-token-title`,children:`Browser token required`}),(0,z.jsx)(`p`,{className:`hq-token-text`,children:e?`The saved token was rejected — it may have been revoked or the server was reset. Paste a current browser token.`:`This HQ server runs in token mode. Open a terminal and run wstack hq token create to mint a browser token, then paste the token value here. A complete legacy ?token= URL also works.`}),i?(0,z.jsx)(`p`,{className:`hq-token-error`,children:i}):null,(0,z.jsx)(Rt,{inputRef:c,value:n,onChange:r,onKeyDown:e=>{e.key===`Enter`&&u()},placeholder:`browser token`,autoComplete:`off`}),(0,z.jsx)(`button`,{type:`button`,className:`hq-token-submit`,onClick:()=>void u(),disabled:n.trim().length===0||o,children:o?`Connecting…`:`Connect`}),(0,z.jsxs)(`p`,{className:`hq-token-hint`,children:[`Open a terminal and run `,(0,z.jsx)(`code`,{children:`wstack hq token create`}),`, then paste the`,` `,(0,z.jsx)(`code`,{children:`token:`}),` value here. The secret is shown only once — it cannot be recovered from `,(0,z.jsx)(`code`,{children:`~/.wrongstack/hq/auth.json`}),` (only its hash is stored). Run`,` `,(0,z.jsx)(`code`,{children:`wstack hq help`}),` for all token commands.`]})]})}function Vt(){let[e,t]=(0,j.useState)(``),[n,r]=(0,j.useState)(``),[i,a]=(0,j.useState)(!1),[o,s]=(0,j.useState)(null),[c,l]=(0,j.useState)(!1),u=(0,j.useRef)(null),d=(0,j.useRef)(null),f=(0,j.useRef)(!1),p=(0,j.useRef)(!1);(0,j.useEffect)(()=>{if(i){d.current?.focus();return}u.current?.focus()},[i]);let m=async()=>{if(c||f.current)return;let t=e;if(t.length!==0){f.current=!0,l(!0),s(null);try{let e=await fetch(`/api/login`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({password:t})});if(!e.ok){let t=`Login failed.`;try{let n=(await e.json()).error;typeof n==`string`?t=n:typeof n?.message==`string`&&(t=n.message)}catch{}s(t),f.current=!1,l(!1);return}if((await e.json()).totpRequired){a(!0),f.current=!1,l(!1);return}L(),window.location.reload()}catch{s(`Network error.`),f.current=!1,l(!1)}}},ee=async()=>{if(c||p.current)return;let e=n.trim();if(e.length!==0){p.current=!0,l(!0),s(null);try{let t=e.includes(`-`)?{recoveryCode:e}:{code:e.replace(/\D/g,``).slice(0,6)},n=await fetch(`/api/login/verify`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)});if(!n.ok){let e=`Verification failed.`;try{let t=(await n.json()).error;typeof t==`string`?e=t:typeof t?.message==`string`&&(e=t.message)}catch{}s(e),p.current=!1,l(!1);return}L(),window.location.reload()}catch{s(`Network error.`),p.current=!1,l(!1)}}};return i?(0,z.jsxs)(z.Fragment,{children:[o?(0,z.jsx)(`p`,{className:`hq-token-error`,children:o}):null,(0,z.jsx)(`label`,{className:`hq-token-label`,htmlFor:`hq-totp-code`,children:`Authenticator code`}),(0,z.jsx)(`input`,{ref:d,id:`hq-totp-code`,className:`hq-token-input`,type:`text`,autoComplete:`one-time-code`,placeholder:`000000 or recovery code`,value:n,onChange:e=>r(e.target.value.slice(0,32)),onKeyDown:e=>{e.key===`Enter`&&ee()}}),(0,z.jsx)(`button`,{type:`button`,className:`hq-token-submit`,onClick:()=>void ee(),disabled:n.trim().length===0||c,children:c?`Verifying…`:`Verify`}),(0,z.jsx)(`button`,{type:`button`,className:`hq-token-hint`,onClick:()=>{a(!1),r(``),s(null)},children:`← Back to password`}),(0,z.jsx)(`p`,{className:`hq-token-hint`,children:`Enter the 6-digit code from your authenticator app, or paste a recovery code.`})]}):(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`div`,{className:`hq-token-title`,children:`Password required`}),(0,z.jsx)(`p`,{className:`hq-token-text`,children:`This HQ server is protected by a password. Enter it to open the dashboard.`}),o?(0,z.jsx)(`p`,{className:`hq-token-error`,children:o}):null,(0,z.jsx)(Rt,{inputRef:u,value:e,onChange:t,onKeyDown:e=>{e.key===`Enter`&&m()},placeholder:`password`,autoComplete:`current-password`}),(0,z.jsx)(`button`,{type:`button`,className:`hq-token-submit`,onClick:()=>void m(),disabled:e.length===0||c,children:c?`Logging in…`:`Log in`}),(0,z.jsxs)(`p`,{className:`hq-token-hint`,children:[`Set or change the password with `,(0,z.jsx)(`code`,{children:`wstack --hq --password <secret>`}),`.`]})]})}var Ht=`modulepreload`,Ut=function(e){return`/`+e},Wt={},X=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=Ut(t,n),t=s(t),t in Wt)return;Wt[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`:Ht,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)})},Gt=360*60*1e3,Z=[{id:`cockpit`,label:`Cockpit`,eyebrow:`Fleet overview`,description:`Health, active work, alerts, cost and command shortcuts.`,group:`Operations`,icon:l,shortcut:1},{id:`fleet`,label:`Fleet Map`,eyebrow:`Topology`,description:`Machines, projects, terminals and agents in one live graph.`,group:`Operations`,icon:s,shortcut:2},{id:`console`,label:`Live Console`,eyebrow:`Transcripts`,description:`Stream and inspect session or agent conversations.`,group:`Operations`,icon:u,shortcut:3},{id:`mailbox`,label:`Mailbox`,eyebrow:`Coordination`,description:`Cross-project messages, unread work and direct delivery.`,group:`Operations`,icon:_,shortcut:4},{id:`kanban`,label:`Kanban`,eyebrow:`Project work`,description:`Read-only project boards synchronized across clones and machines.`,group:`Operations`,icon:f},{id:`alerts`,label:`Attention`,eyebrow:`Operator inbox`,description:`Alerts, waiting agents, governance warnings and failed commands.`,group:`Intelligence`,icon:v,shortcut:5},{id:`cost`,label:`Cost`,eyebrow:`Economics`,description:`Project, provider and model spending distribution.`,group:`Intelligence`,icon:c,shortcut:6},{id:`trends`,label:`Trends`,eyebrow:`Telemetry`,description:`Cost, token and tool activity over time.`,group:`Intelligence`,icon:m,shortcut:7},{id:`brain`,label:`Brain`,eyebrow:`Decisions`,description:`Autonomous decisions, escalations and interventions.`,group:`Intelligence`,icon:o,shortcut:8},{id:`worktree`,label:`Worktrees`,eyebrow:`Workspace`,description:`Distributed branches, worktrees and ownership state.`,group:`System`,icon:b,shortcut:9},{id:`control`,label:`Control`,eyebrow:`Command plane`,description:`Steer, queue, broadcast and audit remote commands.`,group:`System`,icon:r,shortcut:0},{id:`settings`,label:`Security`,eyebrow:`Access control`,description:`Manage the HQ browser password, authentication and active credentials.`,group:`System`,icon:x}],Kt=[`Operations`,`Intelligence`,`System`],qt={cockpit:(0,j.lazy)(()=>X(()=>import(`./cockpit-CnFi0HLk.js`).then(e=>({default:e.CockpitView})),__vite__mapDeps([0,1,2,3]))),fleet:(0,j.lazy)(()=>X(()=>import(`./fleet-map-CjeZ6E-P.js`).then(e=>({default:e.FleetMapView})),__vite__mapDeps([4,1,2,5,3,6]))),console:(0,j.lazy)(()=>X(()=>import(`./live-console-CIxhBhTg.js`).then(e=>({default:e.LiveConsoleView})),__vite__mapDeps([7,1,2,3,6,5]))),mailbox:(0,j.lazy)(()=>X(()=>import(`./mailbox-DnJYghSf.js`).then(e=>({default:e.MailboxView})),__vite__mapDeps([8,1,2,3,9]))),kanban:(0,j.lazy)(()=>X(()=>import(`./kanban-CsIHI3Wr.js`).then(e=>({default:e.KanbanView})),__vite__mapDeps([10,1,2,3]))),cost:(0,j.lazy)(()=>X(()=>import(`./cost-qSQMT1ZD.js`).then(e=>({default:e.CostView})),__vite__mapDeps([11,1,2,3]))),brain:(0,j.lazy)(()=>X(()=>import(`./brain-DxZxkdy0.js`).then(e=>({default:e.BrainView})),__vite__mapDeps([12,1,2,3,9]))),worktree:(0,j.lazy)(()=>X(()=>import(`./worktree-CC8bd1Ev.js`).then(e=>({default:e.WorktreeView})),__vite__mapDeps([13,1,2,3,9]))),trends:(0,j.lazy)(()=>X(()=>import(`./trends-C8_-duaz.js`).then(e=>({default:e.TrendsView})),__vite__mapDeps([14,1,2,3]))),alerts:(0,j.lazy)(()=>X(()=>import(`./alerts-C0ahAgyj.js`).then(e=>({default:e.AlertsView})),__vite__mapDeps([15,1,2,3]))),control:(0,j.lazy)(()=>X(()=>import(`./control-D4n1t2nX.js`).then(e=>({default:e.ControlView})),__vite__mapDeps([16,1,2,3]))),settings:(0,j.lazy)(()=>X(()=>import(`./settings-CiwxymER.js`).then(e=>({default:e.SettingsView})),__vite__mapDeps([17,1,2,3])))};function Jt(e){return Z.find(t=>t.id===e)??Z[0]}var Yt=class extends j.Component{state={error:null};static getDerivedStateFromError(e){return{error:e instanceof Error?e.message:String(e)}}componentDidUpdate(e){e.view!==this.props.view&&this.state.error!==null&&this.setState({error:null})}render(){return this.state.error===null?this.props.children:(0,z.jsxs)(`div`,{className:`hq-view-error`,role:`alert`,children:[(0,z.jsx)(ae,{size:22}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`strong`,{children:`This HQ surface stopped safely.`}),(0,z.jsx)(`p`,{children:this.state.error})]}),(0,z.jsxs)(`button`,{type:`button`,className:`hq-btn secondary`,onClick:()=>this.setState({error:null}),children:[(0,z.jsx)(ue,{size:13}),`Retry view`]})]})}};function Xt(){let{snapshot:e,alerts:n,commandStatuses:r,activeView:a,authRequired:o,connected:s,peerRehydrate:l}=V(M(e=>({snapshot:e.snapshot,alerts:e.alerts,commandStatuses:e.commandStatuses,activeView:e.activeView,authRequired:e.authRequired,connected:e.connected,peerRehydrate:e.peerRehydrate}))),[u,f]=(0,j.useState)(()=>typeof window>`u`||window.innerWidth>=1180),[m,te]=(0,j.useState)(null),[re,ae]=(0,j.useState)(null),[ce,h]=(0,j.useState)(!1),[g,_]=(0,j.useState)(!1),[v,y]=(0,j.useState)(``),[b,x]=(0,j.useState)(0),ue=(0,j.useRef)(null),{theme:S}=Mt().appearance,fe=(0,j.useRef)(!1),C=(0,j.useRef)(!1);(0,j.useEffect)(()=>{C.current&&s===!1?mt.getState().addToast(`Connection lost — reconnecting with backoff…`,`warning`,4e3):C.current&&fe.current===!1&&s===!0&&mt.getState().addToast(`Reconnected to HQ server`,`success`,3e3),s&&(C.current=!0),fe.current=s},[s]),(0,j.useEffect)(()=>(document.documentElement.dataset.hqTheme=S,()=>{delete document.documentElement.dataset.hqTheme}),[S]),(0,j.useEffect)(()=>{let e=!1;return H(`/api/snapshot`).then(t=>{e||V.getState()._hydrateSnapshot(t)}).catch(()=>{}),()=>{e=!0}},[]),(0,j.useEffect)(()=>{let e=!1;return H(`/api/auth/status`).then(t=>{e||ae(t)}).catch(()=>{}),()=>{e=!0}},[]),(0,j.useEffect)(()=>{let e=!1,t=()=>{H(`/api/system/update`).then(t=>{e||te(t)}).catch(()=>{})};t();let n=window.setInterval(t,Gt);return()=>{e=!0,window.clearInterval(n)}},[]),(0,j.useEffect)(()=>{g&&ue.current?.focus()},[g]),(0,j.useEffect)(()=>{let e=e=>{if((e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`k`){e.preventDefault(),_(e=>!e),y(``),x(0);return}if((e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`b`){e.preventDefault(),f(e=>!e);return}if(e.altKey&&/^\d$/.test(e.key)){let t=Number(e.key),n=Z.find(e=>e.shortcut===t);n&&(e.preventDefault(),V.getState().setActiveView(n.id));return}if(e.key===`Escape`&&g){e.preventDefault(),_(!1);return}e.key===`Escape`&&u&&window.innerWidth<900&&f(!1)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[g,u]);let w=(0,j.useMemo)(()=>{let e=v.trim().toLowerCase();return e.length===0?Z:Z.filter(t=>[t.label,t.eyebrow,t.description,t.group].join(` `).toLowerCase().includes(e))},[v]);if(o)return(0,z.jsx)(zt,{hadToken:Xe()!==null});let T=e?.totals,pe=T?.unreadMailboxMessages??0,me=n.filter(e=>e.severity!==`info`).length+(e?.projects??[]).filter(e=>e.governance?.signal.level===`warning`||e.governance?.signal.level===`unavailable`).length+(e?.liveSessions??[]).flatMap(e=>e.agents??[]).filter(e=>e.status===`waiting_user`||e.status===`error`).length+(e?.clients??[]).filter(e=>!e.connected).length+r.filter(e=>e.ackStatus===`failed`||e.ackStatus===`rejected`).length,E=Jt(a),he=E.icon,ge=qt[a],D=e=>{V.getState().setActiveView(e),_(!1),y(``),x(0),window.innerWidth<900&&f(!1)},_e=async()=>{h(!0);try{await R(`/api/logout`,{method:`POST`})}finally{L(),window.location.reload()}};return(0,z.jsxs)(`div`,{className:`hq-app`,"data-theme":S,"data-testid":`hq-workbench`,children:[(0,z.jsx)(`button`,{type:`button`,className:`hq-sidebar-scrim`,"data-open":u,"aria-label":`Close HQ navigation`,onClick:()=>f(!1)}),(0,z.jsxs)(`aside`,{className:`hq-secondary-nav`,"data-open":u,"aria-label":`HQ navigation`,children:[(0,z.jsxs)(`div`,{className:`hq-secondary-header`,children:[(0,z.jsxs)(`div`,{className:`hq-secondary-brand`,children:[(0,z.jsx)(`img`,{src:`/wrongstack.svg`,alt:``,"aria-hidden":`true`,draggable:!1}),(0,z.jsxs)(`div`,{className:`hq-secondary-copy`,children:[(0,z.jsx)(`span`,{className:`hq-secondary-eyebrow`,children:`Command center`}),(0,z.jsx)(`strong`,{children:`WrongStack HQ`})]})]}),(0,z.jsx)(`button`,{type:`button`,className:`hq-icon-button hq-secondary-close`,"aria-label":`Collapse HQ navigation`,title:`Collapse navigation (Ctrl+B)`,onClick:()=>f(!1),children:(0,z.jsx)(t,{size:16})})]}),(0,z.jsx)(`div`,{className:`hq-secondary-scroll`,children:Kt.map(e=>(0,z.jsxs)(`section`,{className:`hq-nav-group`,children:[(0,z.jsx)(`div`,{className:`hq-nav-group-label`,children:e}),Z.filter(t=>t.group===e).map(e=>{let t=e.icon,n=e.id===`mailbox`?pe:e.id===`alerts`?me:0;return(0,z.jsxs)(`button`,{type:`button`,className:`hq-nav-item`,"data-active":a===e.id,"aria-current":a===e.id?`page`:void 0,onClick:()=>D(e.id),children:[(0,z.jsx)(t,{size:15}),(0,z.jsx)(`span`,{children:e.label}),e.shortcut===void 0?null:(0,z.jsxs)(`kbd`,{children:[`Alt+`,e.shortcut]}),n>0?(0,z.jsx)(`span`,{className:`hq-nav-badge`,children:n}):null]},e.id)})]},e))}),(0,z.jsxs)(`div`,{className:`hq-secondary-footer`,children:[(0,z.jsxs)(`div`,{className:`hq-link-state`,"data-live":s,children:[(0,z.jsx)(`span`,{className:`hq-link-dot`}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`strong`,{children:s?`Connected`:`Reconnecting`}),(0,z.jsxs)(`span`,{children:[T?.activeMachines??0,` machines · `,T?.activeClients??0,` clients`]})]})]}),(0,z.jsx)(`span`,{className:`hq-build-label`,children:`@wrongstack/webui-hq`})]})]}),(0,z.jsxs)(`section`,{className:`hq-workbench`,"data-update-available":m?.outdated===!0,children:[(0,z.jsxs)(`header`,{className:`hq-header`,children:[(0,z.jsx)(`button`,{type:`button`,className:`hq-icon-button hq-sidebar-toggle`,"aria-label":u?`Collapse HQ navigation`:`Expand HQ navigation`,"aria-expanded":u,title:`Toggle navigation (Ctrl+B)`,onClick:()=>f(e=>!e),children:u?(0,z.jsx)(t,{size:17}):(0,z.jsx)(se,{size:17})}),(0,z.jsx)(`div`,{className:`hq-view-icon`,"aria-hidden":`true`,children:(0,z.jsx)(he,{size:18})}),(0,z.jsxs)(`div`,{className:`hq-view-identity`,children:[(0,z.jsx)(`span`,{children:E.eyebrow}),(0,z.jsx)(`h1`,{children:E.label}),(0,z.jsx)(`p`,{children:E.description})]}),(0,z.jsxs)(`div`,{className:`hq-top-metrics`,children:[(0,z.jsx)(Q,{icon:de,label:`Machines`,value:T?.activeMachines??0}),(0,z.jsx)(Q,{icon:le,label:`Agents`,value:T?.activeAgents??0}),(0,z.jsx)(Q,{icon:ee,label:`Sessions`,value:T?.activeSessions??0}),(0,z.jsx)(Q,{icon:c,label:`Cost`,value:`$${(T?.totalCostUsd??0).toFixed(2)}`,accent:!0})]}),(0,z.jsxs)(`button`,{type:`button`,className:`hq-command-trigger`,"aria-label":`Open HQ command palette`,"aria-expanded":g,onClick:()=>{_(!0),y(``),x(0)},children:[(0,z.jsx)(d,{size:14}),(0,z.jsx)(`span`,{children:`Jump to`}),(0,z.jsx)(`kbd`,{children:`Ctrl K`})]}),(0,z.jsxs)(`div`,{className:`hq-connection-pill`,"data-live":s,children:[s?(0,z.jsx)(oe,{size:13}):(0,z.jsx)(ne,{size:13}),s?`Live`:`Reconnecting`]}),(0,z.jsx)(`button`,{type:`button`,className:`hq-icon-button hq-theme-toggle`,"aria-label":`Switch to ${S===`dark`?`light`:`dark`} mode`,title:`Switch to ${S===`dark`?`light`:`dark`} mode`,onClick:()=>Pt({theme:S===`dark`?`light`:`dark`}),children:S===`dark`?(0,z.jsx)(ie,{size:16}):(0,z.jsx)(i,{size:16})}),re?.tokenMode||re?.passwordMode?(0,z.jsx)(`button`,{type:`button`,className:`hq-icon-button`,"aria-label":`Log out of HQ`,title:`Log out and clear this tab's HQ credentials`,disabled:ce,onClick:()=>void _e(),children:(0,z.jsx)(p,{size:16})}):null]}),m?.outdated?(0,z.jsx)(Qt,{status:m}):null,l?(0,z.jsx)(Zt,{envelope:l}):null,(0,z.jsx)(`main`,{className:`hq-main`,id:`hq-main`,tabIndex:-1,children:(0,z.jsx)(Yt,{view:a,children:(0,z.jsx)(j.Suspense,{fallback:(0,z.jsx)($t,{label:E.label}),children:(0,z.jsx)(ge,{})})})})]}),g?(0,z.jsxs)(`div`,{className:`hq-command-layer`,role:`presentation`,children:[(0,z.jsx)(`button`,{type:`button`,className:`hq-command-scrim`,"aria-label":`Close HQ command palette`,onClick:()=>_(!1)}),(0,z.jsxs)(`dialog`,{open:!0,className:`hq-command-palette`,"aria-label":`HQ command palette`,children:[(0,z.jsxs)(`div`,{className:`hq-command-search`,children:[(0,z.jsx)(d,{size:17,"aria-hidden":`true`}),(0,z.jsx)(`input`,{ref:ue,type:`search`,value:v,"aria-label":`Search HQ views`,placeholder:`Search views, telemetry and controls…`,onChange:e=>{y(e.target.value),x(0)},onKeyDown:e=>{e.key===`ArrowDown`?(e.preventDefault(),x(e=>w.length===0?0:(e+1)%w.length)):e.key===`ArrowUp`?(e.preventDefault(),x(e=>w.length===0?0:(e-1+w.length)%w.length)):e.key===`Enter`&&w[b]&&(e.preventDefault(),D(w[b].id))}}),(0,z.jsx)(`kbd`,{children:`Esc`})]}),(0,z.jsx)(`div`,{className:`hq-command-results`,role:`listbox`,"aria-label":`HQ destinations`,children:w.length===0?(0,z.jsxs)(`div`,{className:`hq-command-empty`,children:[`No HQ surface matches “`,v,`”.`]}):w.map((e,t)=>{let n=e.icon;return(0,z.jsxs)(`button`,{type:`button`,className:`hq-command-result`,role:`option`,"aria-selected":b===t,"data-current":a===e.id,onMouseEnter:()=>x(t),onClick:()=>D(e.id),children:[(0,z.jsx)(`span`,{className:`hq-command-result-icon`,children:(0,z.jsx)(n,{size:16})}),(0,z.jsxs)(`span`,{className:`hq-command-result-copy`,children:[(0,z.jsx)(`strong`,{children:e.label}),(0,z.jsx)(`small`,{children:e.description})]}),(0,z.jsx)(`span`,{className:`hq-command-result-group`,children:e.group}),e.shortcut===void 0?null:(0,z.jsxs)(`kbd`,{children:[`Alt `,e.shortcut]})]},e.id)})}),(0,z.jsxs)(`footer`,{className:`hq-command-footer`,children:[(0,z.jsxs)(`span`,{children:[(0,z.jsx)(`kbd`,{children:`↑↓`}),` select`]}),(0,z.jsxs)(`span`,{children:[(0,z.jsx)(`kbd`,{children:`Enter`}),` open`]}),(0,z.jsxs)(`span`,{children:[(0,z.jsx)(`kbd`,{children:`Esc`}),` close`]}),(0,z.jsxs)(`span`,{children:[w.length,` destinations`]})]})]})]}):null,(0,z.jsx)(gt,{})]})}function Zt({envelope:e}){let t=e.kind===`peer.rehydrate`?`Leader session lost — survivor clients can rehydrate`:`Leader session lost — no survivor clients reported`,n=e.kind===`peer.rehydrate`&&e.payload.rehydrateHint?e.payload.rehydrateHint:`${e.payload.previousLeaderHandle} on ${e.payload.machineId} ended (${e.payload.reason}).`;return(0,z.jsxs)(`aside`,{className:`hq-peer-rehydrate-notice`,role:`status`,"aria-live":`polite`,children:[(0,z.jsx)(h,{size:16,"aria-hidden":`true`}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`strong`,{children:t}),(0,z.jsx)(`span`,{children:n})]}),(0,z.jsx)(`button`,{type:`button`,onClick:()=>V.getState()._dismissPeerRehydrate(),title:`Dismiss peer lifecycle notice`,children:`Dismiss`})]})}function Qt({status:e}){let[t,r]=(0,j.useState)(!1),i=async()=>{try{await navigator.clipboard.writeText(e.command),r(!0),window.setTimeout(()=>r(!1),1500)}catch{r(!1)}};return(0,z.jsxs)(`aside`,{className:`hq-update-notice`,role:`status`,"aria-live":`polite`,children:[(0,z.jsx)(h,{size:16,"aria-hidden":`true`}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`strong`,{children:`WrongStack update available`}),(0,z.jsxs)(`span`,{children:[`v`,e.current,` → v`,e.latest,`. Run `,(0,z.jsx)(`code`,{children:e.command}),` in your terminal, then restart HQ.`]})]}),(0,z.jsxs)(`button`,{type:`button`,onClick:()=>void i(),title:`Copy update command`,children:[(0,z.jsx)(n,{size:13,"aria-hidden":`true`}),t?`Copied`:`Copy command`]})]})}function Q({icon:e,label:t,value:n,accent:r=!1}){return(0,z.jsxs)(`div`,{className:`hq-top-metric`,"data-accent":r,children:[(0,z.jsx)(e,{size:12}),(0,z.jsx)(`span`,{children:t}),(0,z.jsx)(`strong`,{children:n})]})}function $t({label:e}){return(0,z.jsxs)(`div`,{className:`hq-view-loading`,role:`status`,children:[(0,z.jsx)(r,{size:18}),(0,z.jsxs)(`span`,{children:[`Loading `,e,`…`]})]})}var en=25e3,tn=1e4,nn=3e4,rn=32;function an(e){let t=e.toLowerCase().replace(/^\[(.*)\]$/,`$1`);if(t===`localhost`)return!0;let n=t.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/);if(n){if(n[1]!==`127`)return!1;for(let e of n.slice(1))if(Number(e)>255)return!1;return!0}return t===`::1`||t===`0:0:0:0:0:0:0:1`||t.startsWith(`::ffff:127.`)}function on(e){if(!Number.isFinite(e))return 0;let t=Math.max(0,Math.trunc(e));return Number.isSafeInteger(t)?t:0}var sn=class{ws=null;handlers=new Set;stateHandlers=new Set;reconnectAttempt=0;connectionState=T();reconnectTimer=null;heartbeatTimer=null;lastMessageAt=0;stopped=!1;_state=`disconnected`;_url;resumeCursor;maxRetries;heartbeatIntervalMs;heartbeatTimeoutMs;maxBackoffMs;constructor(e){if(this.maxRetries=e?.maxRetries??1/0,this.heartbeatIntervalMs=e?.heartbeatIntervalMs??en,this.heartbeatTimeoutMs=e?.heartbeatTimeoutMs??tn,this.maxBackoffMs=e?.maxBackoffMs??nn,this.resumeCursor=e?.resumeCursor??(()=>({})),e?.url)this._url=e.url;else{let e=typeof window<`u`?window.location:{host:`127.0.0.1:3499`,protocol:`http:`,hostname:`127.0.0.1`},t=e.protocol===`https:`?`wss:`:`ws:`,n=Xe(),r=an(e.hostname),i=`${t}//${e.host}/ws/browser`;this._url=n!==null&&r?`${i}?token=${encodeURIComponent(n)}`:i}}get url(){return this._url}get state(){return this._state}get isConnected(){return this.ws?.readyState===WebSocket.OPEN}connect(){if(this.stopped||this.ws!==null)return;this.connectionState=pe(this.connectionState),this.emitState(`connecting`);let e;try{e=new WebSocket(this._url)}catch{this.scheduleReconnect();return}this.ws=e,e.onopen=()=>{this.ws===e&&(this.reconnectAttempt=0,this.connectionState=me(this.connectionState),this.lastMessageAt=Date.now(),this.connectionState=E(this.connectionState,this.lastMessageAt),this.emitState(`connected`),this.sendResume(),this.startHeartbeat())},e.onmessage=t=>{if(this.ws===e){this.lastMessageAt=Date.now(),this.connectionState=E(this.connectionState,this.lastMessageAt);try{let e=JSON.parse(typeof t.data==`string`?t.data:``);for(let t of this.handlers)try{t(e)}catch{}}catch{}}},e.onclose=()=>this.handleClose(e,`close`),e.onerror=()=>this.handleClose(e,`error`)}close(){this.stopped=!0,this.connectionState=he(this.connectionState),this.stopHeartbeat(),this.reconnectTimer!==null&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this.ws?.close(1e3,`client closed`),this.ws=null,this.emitState(`disconnected`)}setResumeCursorProvider(e){this.resumeCursor=e}on(e){return this.handlers.add(e),()=>this.handlers.delete(e)}onStateChange(e){return this.stateHandlers.add(e),e(this._state),()=>this.stateHandlers.delete(e)}handleClose(e,t){this.ws===e&&(this.ws=null,this.stopHeartbeat(),this.scheduleReconnect())}scheduleReconnect(){if(this.stopped||this.reconnectTimer!==null)return;let e=ge(this.connectionState,{...w,maxReconnectAttempts:this.maxRetries,maxBackoffMs:this.maxBackoffMs,heartbeatIntervalMs:this.heartbeatIntervalMs,heartbeatTimeoutMs:this.heartbeatTimeoutMs,jitterRatio:.5});if(this.connectionState=e.state,this.reconnectAttempt=e.state.reconnectAttempt,!e.plan){this.emitState(`disconnected`);return}this.emitState(`reconnecting`),this.reconnectTimer=setTimeout(()=>{this.reconnectTimer=null,this.connect()},e.plan.delayMs)}sendResume(){if(this.ws?.readyState===WebSocket.OPEN)try{for(let e of this.resumeFrames())this.ws.send(JSON.stringify(e))}catch{}}resumeFrames(){try{let e=this.resumeCursor(),t=typeof e.entries==`function`?e.entries():Object.entries(e),n=[];for(let[e,r]of t){if(typeof e!=`string`||e.length===0)continue;let t=on(r);n.push({clientId:e,lastSeqSeen:t})}n.sort((e,t)=>t.lastSeqSeen===e.lastSeqSeen?e.clientId.localeCompare(t.clientId):t.lastSeqSeen-e.lastSeqSeen);let r=n.find(({clientId:e})=>e===B),i=r===void 0?rn:rn-1,a=n.filter(({clientId:e})=>e!==B).slice(0,i);return r!==void 0&&a.unshift(r),a.map(({clientId:e,lastSeqSeen:t})=>({type:`client.resume`,clientId:e,lastSeqSeen:t}))}catch{return[]}}get isHeartbeatTimedOut(){return this.ws===null||D(this.connectionState,{...w,heartbeatIntervalMs:this.heartbeatIntervalMs,heartbeatTimeoutMs:this.heartbeatTimeoutMs})}startHeartbeat(){this.stopHeartbeat(),this.lastMessageAt=Date.now(),this.heartbeatTimer=setInterval(()=>{this.isHeartbeatTimedOut&&this.ws!==null&&(this.ws.close(4e3,`heartbeat timeout`),this.ws=null,this.scheduleReconnect())},this.heartbeatIntervalMs)}stopHeartbeat(){this.heartbeatTimer!==null&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}emitState(e){this._state=e;for(let t of this.stateHandlers)try{t(e)}catch{}}},$=null;function cn(e){if($===null)return $=new sn(e),$.connect(),$;if(e?.resumeCursor!==void 0&&$.setResumeCursorProvider(e.resumeCursor),e===void 0)return $;let t=[];return e.url!==void 0&&e.url!==$.url&&t.push(`url: ${e.url} vs ${$.url}`),e.heartbeatIntervalMs!==void 0&&e.heartbeatIntervalMs!==$.heartbeatIntervalMs&&t.push(`heartbeatIntervalMs: ${e.heartbeatIntervalMs} vs ${$.heartbeatIntervalMs}`),e.heartbeatTimeoutMs!==void 0&&e.heartbeatTimeoutMs!==$.heartbeatTimeoutMs&&t.push(`heartbeatTimeoutMs: ${e.heartbeatTimeoutMs} vs ${$.heartbeatTimeoutMs}`),e.maxBackoffMs!==void 0&&e.maxBackoffMs!==$.maxBackoffMs&&t.push(`maxBackoffMs: ${e.maxBackoffMs} vs ${$.maxBackoffMs}`),e.maxRetries!==void 0&&e.maxRetries!==$.maxRetries&&t.push(`maxRetries: ${e.maxRetries} vs ${$.maxRetries}`),t.length>0&&typeof console<`u`&&console.warn(`[hq-ws-client] getHqClient() called with options that conflict with the live singleton; ignoring: ${t.join(`, `)}. Call closeHqClient() first if you need to reconfigure.`),$}var ln=document.getElementById(`root`);ln!==null&&it().finally(()=>{Ze(),at();let e=cn({resumeCursor:()=>V.getState().resumeCursors});e.onStateChange(e=>{V.getState()._setConnected(e===`connected`)});let t=null,n=()=>{t===null&&(V.getState()._setNeedsSnapshotRefresh(!1),t=H(`/api/snapshot`).then(e=>{V.getState()._onSnapshot(e)}).catch(()=>void 0).finally(()=>{t=null}))};V.subscribe((e,t)=>{e.needsSnapshotRefresh&&!t.needsSnapshotRefresh&&n()}),e.on(e=>{if(e.type===`hq.snapshot`){let t=Le(e);t&&V.getState()._onSnapshot(t.snapshot)}else if(e.type===`hq.event`){let t=Re(e);t&&V.getState()._onEvent(t.event)}else if(e.type===`hq.alert`){let t=ze(e);t&&V.getState()._onAlert(t.alert)}else if(e.type===`hq.command_status`){let t=Be(e);t&&V.getState()._onCommandStatus(t.command)}else if(e.type===`hq.resume_gap`)for(let t of e.envelopes){let e=Re({type:`hq.event`,event:t});e&&V.getState()._onEvent(e.event)}else e.type===`hq.resume_reject`&&(V.getState()._resetResumeCursors(),V.getState()._setNeedsSnapshotRefresh(!0))}),(0,Ve.createRoot)(ln).render((0,z.jsx)(j.StrictMode,{children:(0,z.jsx)(Xt,{})}))});export{Lt as a,wt as c,R as d,L as f,Ft as i,Ct as l,It as n,Mt as o,M as p,Nt as r,H as s,Rt as t,V as u};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{$ as t,Dt as n,Ft as r,Mt as i,Nt as a,T as o,Xt as s,Zt as c,c as l,l as u,n as d,ut as f,xt as p}from"./icons-C4ljWs50.js";import{i as m}from"./markdown--Y3iks7c.js";import{s as h,u as g}from"./index-Ch5wZYYG.js";var _=e(c(),1),v=m();function y({task:e,board:i,webuiUrl:a,dependencyTitles:o,onClose:s}){let c=e.dependsOn.map(e=>({id:e,title:o?.get(e)??e.slice(0,8)}));return(0,v.jsxs)(`aside`,{className:`hq-kanban-inspector`,"aria-label":`Task detail`,children:[(0,v.jsxs)(`header`,{className:`hq-kanban-inspector-header`,children:[(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`span`,{className:`hq-pill ${e.status}`,children:e.status.replaceAll(`_`,` `)}),(0,v.jsx)(`span`,{className:`hq-kanban-priority ${e.priority}`,children:e.priority})]}),(0,v.jsx)(`button`,{type:`button`,onClick:s,"aria-label":`Close inspector`,className:`hq-inspector-close`,children:(0,v.jsx)(d,{size:16})})]}),(0,v.jsx)(`h2`,{className:`hq-kanban-inspector-title`,children:e.title}),(0,v.jsx)(`span`,{className:`hq-mono hq-kanban-inspector-id`,children:e.id}),e.description?(0,v.jsxs)(`section`,{className:`hq-kanban-inspector-section`,children:[(0,v.jsx)(`h3`,{children:`Description`}),(0,v.jsx)(`p`,{className:`hq-kanban-inspector-description`,children:e.description})]}):null,(0,v.jsxs)(`section`,{className:`hq-kanban-inspector-section`,children:[(0,v.jsx)(`h3`,{children:`Details`}),(0,v.jsxs)(`dl`,{className:`hq-kanban-inspector-details`,children:[(0,v.jsxs)(`div`,{className:`hq-kanban-inspector-row`,children:[(0,v.jsxs)(`dt`,{children:[(0,v.jsx)(t,{size:13}),`Board`]}),(0,v.jsx)(`dd`,{children:i.title})]}),e.assignee?(0,v.jsxs)(`div`,{className:`hq-kanban-inspector-row`,children:[(0,v.jsxs)(`dt`,{children:[(0,v.jsx)(l,{size:13}),`Assignee`]}),(0,v.jsxs)(`dd`,{children:[e.assignee,e.assignmentStatus?(0,v.jsxs)(`span`,{className:`hq-mono`,style:{marginLeft:6,opacity:.7},children:[`(`,e.assignmentStatus,`)`]}):null]})]}):null,e.dueDate?(0,v.jsxs)(`div`,{className:`hq-kanban-inspector-row`,children:[(0,v.jsxs)(`dt`,{children:[(0,v.jsx)(n,{size:13}),`Due`]}),(0,v.jsx)(`dd`,{children:new Date(e.dueDate).toLocaleString()})]}):null,e.columnId?(0,v.jsxs)(`div`,{className:`hq-kanban-inspector-row`,children:[(0,v.jsxs)(`dt`,{children:[(0,v.jsx)(t,{size:13}),`Column`]}),(0,v.jsx)(`dd`,{children:i.columns.find(t=>t.id===e.columnId)?.title??e.columnId})]}):null]})]}),e.labels.length>0?(0,v.jsxs)(`section`,{className:`hq-kanban-inspector-section`,children:[(0,v.jsx)(`h3`,{children:`Labels`}),(0,v.jsx)(`div`,{className:`hq-kanban-inspector-labels`,children:e.labels.map(e=>(0,v.jsx)(`span`,{className:`hq-pill info`,children:e},e))})]}):null,c.length>0?(0,v.jsxs)(`section`,{className:`hq-kanban-inspector-section`,children:[(0,v.jsxs)(`h3`,{children:[(0,v.jsx)(f,{size:13}),`Dependencies (`,c.length,`)`]}),(0,v.jsx)(`ul`,{className:`hq-kanban-inspector-deps`,children:c.map(t=>(0,v.jsxs)(`li`,{children:[(0,v.jsx)(`span`,{className:`hq-mono`,children:t.id.slice(0,8)}),(0,v.jsx)(`span`,{children:t.title}),e.status===`completed`?(0,v.jsx)(r,{size:13,className:`is-done`}):null]},t.id))})]}):null,e.status===`blocked`||e.status===`failed`?(0,v.jsxs)(`div`,{className:`hq-kanban-inspector-alert`,children:[(0,v.jsx)(u,{size:14}),(0,v.jsxs)(`span`,{children:[`This task is `,e.status,` and may need attention.`]})]}):null,a?(0,v.jsx)(`footer`,{className:`hq-kanban-inspector-footer`,children:(0,v.jsxs)(`a`,{href:a,target:`_blank`,rel:`noopener noreferrer`,className:`hq-button hq-button-primary`,children:[(0,v.jsx)(p,{size:14}),`Open in WebUI`]})}):null]})}function b({board:e}){let t=x(e),o=t.blocked===0&&t.failed===0;return(0,v.jsxs)(`div`,{className:`hq-kanban-queue-health`,role:`status`,"aria-label":`Queue health`,children:[(0,v.jsx)(`span`,{className:`hq-kanban-qh-label`,children:`Queue health`}),t.startable>0?(0,v.jsxs)(`span`,{className:`hq-kanban-qh-pill ready`,title:`Claimable tasks`,children:[(0,v.jsx)(i,{size:12}),t.startable,` ready`]}):null,t.running>0?(0,v.jsxs)(`span`,{className:`hq-kanban-qh-pill running`,title:`Running assignments`,children:[(0,v.jsx)(s,{size:12}),t.running,` running`]}):null,t.review>0?(0,v.jsxs)(`span`,{className:`hq-kanban-qh-pill review`,title:`In review`,children:[(0,v.jsx)(n,{size:12}),t.review,` review`]}):null,t.blocked>0?(0,v.jsxs)(`span`,{className:`hq-kanban-qh-pill blocked`,title:`Manually blocked`,children:[(0,v.jsx)(a,{size:12}),t.blocked,` blocked`]}):null,t.failed>0?(0,v.jsxs)(`span`,{className:`hq-kanban-qh-pill failed`,title:`Failed tasks`,children:[(0,v.jsx)(u,{size:12}),t.failed,` failed`]}):null,o?(0,v.jsxs)(`span`,{className:`hq-kanban-qh-pill healthy`,title:`No issues detected`,children:[(0,v.jsx)(r,{size:12}),`healthy`]}):null]})}function x(e){let t={startable:0,running:0,review:0,blocked:0,failed:0},n=new Set;for(let t of e.columns)for(let e of t.tasks)e.status===`completed`&&n.add(e.id);for(let r of e.columns)for(let e of r.tasks){let r=e.assignmentStatus===`running`||e.assignmentStatus===`queued`;switch((e.status===`in_progress`||e.assignmentStatus===`running`)&&t.running++,!r&&(e.status===`pending`||e.status===`ready`)&&e.dependsOn.every(e=>n.has(e))&&t.startable++,e.status){case`review`:t.review++;break;case`blocked`:t.blocked++;break;case`failed`:t.failed++;break}}return t}var S=new Set([`low`,`medium`,`high`,`critical`]),C=new Set([`pending`,`ready`,`in_progress`,`review`,`completed`,`blocked`,`failed`,`archived`]);function w(e){return`/api/projects/${encodeURIComponent(e)}/kanban`}function T(e){return e.boards.map(e=>E(e)).filter(e=>e!==null).sort((e,t)=>t.updatedAt.localeCompare(e.updatedAt))}function E(e){let t=e.board;if(t.id!==e.boardId)return null;let n=k(t.columns).map(D).filter(e=>e!==null),r=k(t.tasks).map(O).filter(e=>e!==null),i=new Set(n.map(e=>e.id)),a=new Set(r.map(e=>e.columnId).filter(e=>!i.has(e)));for(let e of a)n.push({id:e,title:e.length>0?e:`Unmapped`,order:2**53-1});let o=n.sort((e,t)=>e.order-t.order||e.title.localeCompare(t.title)).map(e=>({...e,tasks:r.filter(t=>t.columnId===e.id).sort((e,t)=>e.order-t.order||e.title.localeCompare(t.title))}));return{id:e.boardId,title:M(t.title)??e.boardId,description:M(t.description),tags:j(t.tags),revision:e.revision,updatedAt:e.updatedAt,activePresence:k(t.presence).filter(e=>e.active===!0).length,taskCount:r.length,completedTaskCount:r.filter(e=>e.status===`completed`).length,activeTaskCount:r.filter(e=>e.status===`in_progress`||e.status===`review`).length,blockedTaskCount:r.filter(e=>e.status===`blocked`||e.status===`failed`).length,columns:o}}function D(e){let t=M(e.id),n=M(e.title);return!t||!n?null:{id:t,title:n,color:M(e.color),order:N(e.order)??0,wipLimit:N(e.wipLimit)}}function O(e){let t=M(e.id),n=M(e.title),r=M(e.columnId);if(!t||!n||r===void 0)return null;let i=A(e.assignment);return{id:t,title:n,description:M(e.description),columnId:r,order:N(e.order)??0,priority:P(e.priority,S)??`medium`,status:P(e.status,C)??`pending`,assignee:M(e.assignee)??M(e.assignedAgent)??M(i?.name)??M(i?.agentId),assignmentStatus:M(i?.status),labels:j(e.labels),dependsOn:j(e.dependsOn),dueDate:M(e.dueDate)}}function k(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&!Array.isArray(e)):[]}function A(e){return typeof e==`object`&&e&&!Array.isArray(e)?e:void 0}function j(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function M(e){return typeof e==`string`?e:void 0}function N(e){return typeof e==`number`&&Number.isFinite(e)?e:void 0}function P(e,t){return typeof e==`string`&&t.has(e)?e:void 0}var F=1e4,I=[];function L(){let e=g(e=>e.snapshot?.projects??I),t=g(e=>{for(let t=e.events.length-1;t>=0;t--){let n=e.events[t];if(n?.type===`kanban.snapshot`)return n.id}return null}),[n,r]=(0,_.useState)(``),[i,a]=(0,_.useState)(``),[s,c]=(0,_.useState)(null),[l,d]=(0,_.useState)(!1),[f,p]=(0,_.useState)(!1),[m,x]=(0,_.useState)(null),S=(0,_.useRef)(0),C=(0,_.useRef)(t);(0,_.useEffect)(()=>{if(e.length===0){r(``),c(null);return}e.some(e=>e.projectId===n)||r(e[0].projectId)},[n,e]);let E=(0,_.useCallback)(async(e=!1)=>{if(!n)return;let t=++S.current;e?d(!0):p(!0);try{let e=await h(w(n));if(t!==S.current)return;c(e),x(null)}catch(e){if(t!==S.current)return;x(e instanceof Error?e.message:String(e))}finally{t===S.current&&(d(!1),p(!1))}},[n]);(0,_.useEffect)(()=>{S.current++,c(null),a(``),x(null)},[n]),(0,_.useEffect)(()=>{if(!n)return;E(!0);let e=window.setInterval(()=>void E(!1),F);return()=>{S.current++,window.clearInterval(e)}},[E,n]),(0,_.useEffect)(()=>{t===null||t===C.current||(C.current=t,n&&E(!1))},[t,E,n]);let D=(0,_.useMemo)(()=>s?T(s):[],[s]);(0,_.useEffect)(()=>{D.length===0?a(``):D.some(e=>e.id===i)||a(D[0].id)},[i,D]);let O=D.find(e=>e.id===i)??null,k=e.find(e=>e.projectId===n)??null,[A,j]=(0,_.useState)(null);(0,_.useEffect)(()=>{j(null)},[i]);let M=(0,_.useMemo)(()=>{if(!O||!A)return null;for(let e of O.columns){let t=e.tasks.find(e=>e.id===A);if(t)return t}return null},[O,A]),N=(0,_.useMemo)(()=>{if(!O)return new Map;let e=new Map;for(let t of O.columns)for(let n of t.tasks)e.set(n.id,n.title);return e},[O]);return e.length===0?(0,v.jsx)(`div`,{className:`hq-empty`,children:`No HQ projects are available. Connect a WrongStack client to publish its project identity and Kanban snapshot.`}):(0,v.jsxs)(`div`,{className:`hq-kanban-view`,children:[(0,v.jsx)(R,{projects:e,projectId:n,onProjectChange:e=>r(e),boards:D,boardId:i,onBoardChange:a,generatedAt:s?.generatedAt,refreshing:f,onRefresh:()=>void E(!1)}),m?(0,v.jsxs)(`div`,{className:`hq-kanban-error`,role:`alert`,children:[(0,v.jsx)(u,{size:15}),(0,v.jsx)(`span`,{children:m}),(0,v.jsx)(`button`,{type:`button`,onClick:()=>void E(!0),children:`Retry`})]}):null,l&&s===null?(0,v.jsxs)(`div`,{className:`hq-view-loading`,role:`status`,children:[(0,v.jsx)(o,{size:18}),(0,v.jsx)(`span`,{children:`Loading project boards…`})]}):O?(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)(z,{project:k,board:O,boardCount:D.length}),(0,v.jsx)(b,{board:O}),(0,v.jsxs)(`div`,{className:`hq-kanban-main`,children:[(0,v.jsx)(V,{board:O,onTaskClick:j,selectedTaskId:A}),M?(0,v.jsx)(y,{task:M,board:O,dependencyTitles:N,onClose:()=>j(null)}):null]})]}):(0,v.jsxs)(`div`,{className:`hq-empty`,children:[`This project has not published a Kanban board yet. Create one with `,(0,v.jsx)(`code`,{children:`/kanban`}),` `,`from any connected clone.`]})]})}function R({projects:e,projectId:t,onProjectChange:n,boards:r,boardId:i,onBoardChange:a,generatedAt:s,refreshing:c,onRefresh:l}){return(0,v.jsxs)(`div`,{className:`hq-kanban-toolbar`,children:[(0,v.jsxs)(`label`,{children:[(0,v.jsx)(`span`,{children:`Project`}),(0,v.jsx)(`select`,{className:`hq-select`,"aria-label":`Kanban project`,value:t,onChange:e=>n(e.target.value),children:e.map(e=>(0,v.jsx)(`option`,{value:e.projectId,children:e.projectName},e.projectId))})]}),(0,v.jsxs)(`label`,{children:[(0,v.jsx)(`span`,{children:`Board`}),(0,v.jsxs)(`select`,{className:`hq-select`,"aria-label":`Kanban board`,value:i,disabled:r.length===0,onChange:e=>a(e.target.value),children:[r.length===0?(0,v.jsx)(`option`,{value:``,children:`No boards`}):null,r.map(e=>(0,v.jsx)(`option`,{value:e.id,children:e.title},e.id))]})]}),(0,v.jsxs)(`div`,{className:`hq-kanban-sync`,children:[(0,v.jsx)(`span`,{children:s?`Synced ${W(s)}`:`Waiting for snapshot`}),(0,v.jsxs)(`button`,{type:`button`,onClick:l,disabled:c,"aria-label":`Refresh Kanban`,children:[(0,v.jsx)(o,{size:14,className:c?`is-spinning`:void 0}),`Refresh`]})]})]})}function z({project:e,board:t,boardCount:n}){return(0,v.jsxs)(`section`,{className:`hq-kanban-summary`,children:[(0,v.jsxs)(`div`,{className:`hq-kanban-heading`,children:[(0,v.jsxs)(`div`,{children:[(0,v.jsxs)(`span`,{children:[e?.projectName??`Project`,` · Kanban`]}),(0,v.jsx)(`h2`,{children:t.title}),t.description?(0,v.jsx)(`p`,{children:t.description}):null]}),(0,v.jsxs)(`div`,{className:`hq-kanban-board-meta`,children:[(0,v.jsxs)(`span`,{className:`hq-mono`,children:[`rev `,t.revision]}),(0,v.jsx)(`span`,{children:W(t.updatedAt)}),t.activePresence>0?(0,v.jsxs)(`span`,{className:`hq-pill active`,children:[t.activePresence,` active`]}):null]})]}),t.tags.length>0?(0,v.jsx)(`div`,{className:`hq-kanban-tags`,children:t.tags.map(e=>(0,v.jsx)(`span`,{className:`hq-pill info`,children:e},e))}):null,(0,v.jsxs)(`div`,{className:`hq-kanban-stats`,children:[(0,v.jsx)(B,{label:`Boards`,value:n}),(0,v.jsx)(B,{label:`Tasks`,value:t.taskCount}),(0,v.jsx)(B,{label:`Active`,value:t.activeTaskCount,tone:`active`}),(0,v.jsx)(B,{label:`Blocked`,value:t.blockedTaskCount,tone:`blocked`}),(0,v.jsx)(B,{label:`Done`,value:t.completedTaskCount,tone:`done`})]})]})}function B({label:e,value:t,tone:n}){return(0,v.jsxs)(`div`,{className:`hq-kanban-stat`,"data-tone":n,children:[(0,v.jsx)(`strong`,{children:t}),(0,v.jsx)(`span`,{children:e})]})}function V({board:e,onTaskClick:t,selectedTaskId:n}){return e.columns.length===0?(0,v.jsx)(`div`,{className:`hq-empty`,children:`This board does not have any columns yet.`}):(0,v.jsx)(`section`,{className:`hq-kanban-board`,"aria-label":`${e.title} Kanban board`,style:{"--hq-kanban-columns":Math.max(1,e.columns.length)},children:e.columns.map(e=>(0,v.jsxs)(`div`,{className:`hq-kanban-column`,"data-over-limit":e.wipLimit!==void 0&&e.tasks.filter(e=>e.status!==`completed`).length>e.wipLimit,children:[(0,v.jsxs)(`header`,{style:e.color?{borderTopColor:e.color}:void 0,children:[(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`strong`,{children:e.title}),e.wipLimit===void 0?null:(0,v.jsxs)(`span`,{children:[`WIP `,e.tasks.length,`/`,e.wipLimit]})]}),(0,v.jsx)(`span`,{className:`hq-kanban-column-count`,children:e.tasks.length})]}),(0,v.jsx)(`div`,{className:`hq-kanban-column-body`,children:e.tasks.length===0?(0,v.jsx)(`div`,{className:`hq-kanban-column-empty`,children:`No cards`}):e.tasks.map(e=>(0,v.jsx)(H,{task:e,isSelected:e.id===n,onClick:()=>t(e.id)},e.id))})]},e.id))})}function H({task:e,isSelected:t=!1,onClick:i}){return(0,v.jsxs)(`button`,{type:`button`,className:`hq-kanban-task`,"data-priority":e.priority,"data-selected":t,onClick:i,children:[(0,v.jsxs)(`div`,{className:`hq-kanban-task-topline`,children:[(0,v.jsx)(`span`,{className:`hq-pill ${e.status}`,children:e.status.replaceAll(`_`,` `)}),(0,v.jsx)(`span`,{className:`hq-kanban-priority ${e.priority}`,children:e.priority})]}),(0,v.jsx)(`h3`,{children:e.title}),e.description?(0,v.jsx)(`p`,{children:e.description}):null,e.labels.length>0?(0,v.jsx)(`div`,{className:`hq-kanban-task-labels`,children:e.labels.slice(0,4).map(e=>(0,v.jsx)(`span`,{children:e},e))}):null,(0,v.jsxs)(`footer`,{children:[e.assignee?(0,v.jsxs)(`span`,{title:e.assignmentStatus??`assigned`,children:[(0,v.jsx)(l,{size:12}),e.assignee]}):null,e.dependsOn.length>0?(0,v.jsxs)(`span`,{title:`${e.dependsOn.length} dependencies`,children:[(0,v.jsx)(f,{size:12}),e.dependsOn.length]}):null,e.dueDate?(0,v.jsxs)(`span`,{title:`Due ${new Date(e.dueDate).toLocaleString()}`,children:[(0,v.jsx)(n,{size:12}),U(e.dueDate)]}):null,e.status===`completed`?(0,v.jsx)(r,{size:13,className:`is-done`}):null]})]})}function U(e){let t=new Date(e);return Number.isFinite(t.getTime())?t.toLocaleDateString(void 0,{month:`short`,day:`numeric`}):e}function W(e){let t=Date.parse(e);if(!Number.isFinite(t))return e;let n=Math.max(0,Math.floor((Date.now()-t)/1e3));if(n<10)return`just now`;if(n<60)return`${n}s ago`;let r=Math.floor(n/60);if(r<60)return`${r}m ago`;let i=Math.floor(r/60);return i<24?`${i}h ago`:`${Math.floor(i/24)}d ago`}export{L as KanbanView};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{Bt as t,D as n,Kt as r,L as i,M as a,R as o,Yt as s,Zt as c,f as l,mt as u,rt as d,x as f}from"./icons-C4ljWs50.js";import{i as p}from"./markdown--Y3iks7c.js";import{c as m,n as h,o as ee,p as g,u as _}from"./index-Ch5wZYYG.js";import{c as te,l as v,s as y,t as b,u as x}from"./fleet-topology-BcXKnYKF.js";var S=e(c(),1);function C(e,t,n){if(e===null||t===null)return null;let r=(e.liveSessions??[]).find(e=>e.sessionId===t);if(r===void 0)return null;let i=e.sessions.find(e=>e.sessionId===t)?.clientId,a=r.clientId??i,o=e.clients.find(e=>e.connected&&e.clientId===a),s=e.clients.filter(e=>e.connected&&e.machineId===r.machineId&&e.projectId===r.projectId&&(r.pid===void 0||e.pid===r.pid)),c=(o?.capabilities.includes(`control.receive`)===!0?o:void 0)??s.find(e=>e.kind===r.clientKind&&e.capabilities.includes(`control.receive`))??s.find(e=>e.capabilities.includes(`control.receive`))??o??s[0],l=n===null?null:r.agents.find(e=>e.id===n)??null,u=n===null||n===`leader`?`leader`:n,d=e.clients.some(e=>e.connected&&e.projectId===r.projectId&&e.capabilities.includes(`mailbox.serve`));return{session:r,client:c??null,agent:l,recipient:u,controllable:c?.capabilities.includes(`control.receive`)===!0,mailboxServeActive:d}}var w=p();function T(e){let t=b(e),n=[],r=new Map,i=new Map,a=new Map,o=e=>`machine:${e.machineId}`,s=e=>`project:${e.machineId}:${e.projectId}`;for(let e of t.nodes){if(e.kind!==`machine`)continue;let t={id:e.id,label:e.label,sub:e.sub,projects:[]};r.set(e.id,t),n.push(t)}for(let e of t.nodes){if(e.kind!==`project`)continue;let t=r.get(o(e));if(t===void 0)continue;let n={id:e.id,label:e.label,clients:[]};i.set(e.id,n),t.projects.push(n)}for(let e of t.nodes){if(e.kind!==`terminal`||e.sessionId===void 0||e.serviceMode!==void 0)continue;let t=i.get(s(e));if(t===void 0)continue;let n={clientId:e.clientId,sessionId:e.sessionId,label:e.label,clientKind:e.clientKind,status:e.status,synthetic:e.isSyntheticSession===!0,agents:[]};a.set(e.sessionId,n),t.clients.push(n)}for(let e of t.nodes){if(e.kind!==`agent`||e.sessionId===void 0||e.agentId===void 0)continue;let t=a.get(e.sessionId);t!==void 0&&t.agents.push({id:e.agentId,label:e.label,status:e.status})}return n.map(e=>({...e,projects:e.projects.filter(e=>e.clients.length>0)})).filter(e=>e.projects.length>0)}function E(e){return e===`active`||e===`running`||e===`streaming`?`active`:e===`waiting_user`?`warn`:e===`error`||e===`stale`||e===`closing`?`error`:`idle`}function D({snapshot:e,selectedSessionId:n,selectedAgentId:a}){let o=(0,S.useMemo)(()=>T(e),[e]),[s,c]=(0,S.useState)(new Set),d=e=>c(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n});return o.length===0?(0,w.jsx)(`div`,{className:`hq-fleetnav`,children:(0,w.jsx)(`div`,{className:`hq-empty hq-pad-md`,children:`No live sessions. Open a WrongStack CLI/TUI/WebUI connected to HQ.`})}):(0,w.jsx)(`div`,{className:`hq-fleetnav`,role:`tree`,"aria-label":`Fleet navigator`,children:o.map(e=>{let o=!s.has(e.id);return(0,w.jsxs)(`div`,{className:`hq-nav-machine`,children:[(0,w.jsxs)(`button`,{type:`button`,className:`hq-nav-row machine`,onClick:()=>d(e.id),"aria-expanded":o,children:[(0,w.jsx)(t,{size:12,className:`hq-nav-caret`+(o?` open`:``)}),(0,w.jsx)(i,{size:13}),(0,w.jsx)(`span`,{className:`hq-nav-label`,title:e.sub??e.label,children:e.label})]}),o&&e.projects.map(e=>{let i=!s.has(e.id);return(0,w.jsxs)(`div`,{className:`hq-nav-project`,children:[(0,w.jsxs)(`button`,{type:`button`,className:`hq-nav-row project`,onClick:()=>d(e.id),"aria-expanded":i,children:[(0,w.jsx)(t,{size:12,className:`hq-nav-caret`+(i?` open`:``)}),(0,w.jsx)(u,{size:13}),(0,w.jsx)(`span`,{className:`hq-nav-label`,title:e.label,children:e.label})]}),i&&e.clients.map(e=>{let i=!s.has(e.sessionId),o=n===e.sessionId&&a===null;return(0,w.jsxs)(`div`,{className:`hq-nav-client`,children:[(0,w.jsxs)(`div`,{className:`hq-nav-clientrow`,children:[e.agents.length>0?(0,w.jsx)(`button`,{type:`button`,className:`hq-nav-caretbtn`,onClick:()=>d(e.sessionId),"aria-label":i?`Collapse`:`Expand`,children:(0,w.jsx)(t,{size:12,className:`hq-nav-caret`+(i?` open`:``)})}):(0,w.jsx)(`span`,{className:`hq-nav-caretbtn`}),(0,w.jsxs)(`button`,{type:`button`,className:`hq-nav-row client`+(o?` selected`:``),disabled:e.synthetic,onClick:()=>{e.synthetic||(_.getState().selectSession(e.sessionId),e.clientId!==void 0&&_.getState().selectClient(e.clientId))},title:e.synthetic?`waiting for session telemetry`:e.label,children:[(0,w.jsx)(`span`,{className:`hq-nav-dot `+E(e.status)}),(0,w.jsx)(l,{size:12}),(0,w.jsx)(`span`,{className:`hq-nav-label`,children:e.label}),e.agents.length>0&&(0,w.jsx)(`span`,{className:`hq-nav-count`,children:e.agents.length})]})]}),i&&e.agents.map(t=>(0,w.jsxs)(`button`,{type:`button`,className:`hq-nav-row agent`+(n===e.sessionId&&a===t.id?` selected`:``),onClick:()=>{_.getState().selectAgent(e.sessionId,t.id),e.clientId!==void 0&&_.getState().selectClient(e.clientId)},title:t.label,children:[(0,w.jsx)(`span`,{className:`hq-nav-dot `+E(t.status)}),(0,w.jsx)(r,{size:12}),(0,w.jsx)(`span`,{className:`hq-nav-label`,children:t.label})]},t.id))]},e.sessionId)})]},e.id)})]},e.id)})})}function O(e){return e===`completed`?`active`:e===`failed`||e===`rejected`?`error`:e===`delivered`||e===`accepted`?`info`:`warn`}function k({receipt:e,lifecycle:t}){let n=new Date(e.createdAt).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`,second:`2-digit`}),r=(0,w.jsx)(`span`,{className:`hq-pill ${O(t)}`,children:t});return e.type===`abort`?(0,w.jsx)(`div`,{className:`hq-chat-turn system hq-command-turn`,"data-command-id":e.commandId,children:(0,w.jsxs)(`span`,{className:`hq-chat-system-line`,children:[(0,w.jsx)(a,{size:12}),` `,e.preview,` `,r,(0,w.jsx)(`span`,{className:`hq-chat-clock`,children:n})]})}):(0,w.jsx)(`div`,{className:`hq-chat-turn user hq-command-turn`,"data-command-id":e.commandId,children:(0,w.jsxs)(`div`,{className:`hq-chat-bubble user`,children:[(0,w.jsxs)(`div`,{className:`hq-chat-role`,children:[`you → `,e.target,` · `,e.type,` `,r,(0,w.jsx)(`span`,{className:`hq-chat-clock`,children:n})]}),(0,w.jsx)(`div`,{className:`hq-chat-prose`,children:e.preview})]})})}function A(){let{selectedSessionId:e,selectedAgentId:t,snapshot:i,commandStatuses:c}=_(g(e=>({selectedSessionId:e.selectedSessionId,selectedAgentId:e.selectedAgentId,snapshot:e.snapshot,commandStatuses:e.commandStatuses}))),l=e,u=t,p=u!==null,b=ee().console,[T,E]=(0,S.useState)(b.delivery),[O,A]=(0,S.useState)(b.subject),[M,N]=(0,S.useState)(b.body),[P,F]=(0,S.useState)(!1),[I,L]=(0,S.useState)(null),[ne,R]=(0,S.useState)(!1),[z,B]=(0,S.useState)(!1),[V,H]=(0,S.useState)([]),U=v(l,u),{entries:W,meta:G,stats:K}=U,q=(0,S.useMemo)(()=>V.filter(e=>{if(e.type===`abort`)return!0;let t=Date.parse(e.createdAt);return!W.some(n=>n.role===`user`&&n.text.trim()===e.preview&&Math.abs(Date.parse(n.ts)-t)<12e4)}),[W,V]);(0,S.useEffect)(()=>{if(!U.pinned||q.length===0)return;let e=window.requestAnimationFrame(()=>{U.listRef.current?.scrollToIndex(W.length+q.length-1,{align:`end`})});return()=>window.cancelAnimationFrame(e)},[U.listRef,U.pinned,W.length,q.length]);let J=()=>{U.jumpToLatest(),window.requestAnimationFrame(()=>{U.listRef.current?.scrollToIndex(W.length+q.length-1,{align:`end`})})},Y=(0,S.useMemo)(()=>C(i,l,u),[u,l,i]),X=Y?.agent??null,Z=Y?.recipient===`leader`,Q=X?.name??(Z?`Leader agent`:Y?.recipient??`agent`);(0,S.useEffect)(()=>{let e=Y?.client?.clientId;e!==void 0&&_.getState().selectClient(e),L(null),R(!1),B(!1),H([])},[Y?.client?.clientId,l,u]);let $=async()=>{if(Y?.client===null||Y?.client===void 0||!Y.controllable||M.trim().length===0)return;F(!0),L(null);let e=M.trim();try{let t=await m(Y.client.clientId,T,{to:Y.recipient,subject:O.trim()||`HQ ${T}`,body:e,priority:T===`steer`?`high`:`normal`});N(``),h({body:``}),H(n=>[...n,{commandId:t.commandId,type:T,target:Q,preview:e,createdAt:new Date().toISOString()}].slice(-8)),L({tone:`ok`,text:`${T} queued for ${Q} · ${t.commandId}`})}catch(e){L({tone:`error`,text:e instanceof Error?e.message:String(e)})}finally{F(!1)}},re=async()=>{if(!(Y?.client===null||Y?.client===void 0)){F(!0),L(null);try{let e=await m(Y.client.clientId,`abort`,{target:Y.recipient});if(H(t=>[...t,{commandId:e.commandId,type:`abort`,target:Q,preview:`Interrupt ${Q}`,createdAt:new Date().toISOString()}].slice(-8)),Z&&z){let e=await m(Y.client.clientId,`abort`,{target:`fleet`});H(t=>[...t,{commandId:e.commandId,type:`abort`,target:`all subagents`,preview:`Interrupt every subagent on this client`,createdAt:new Date().toISOString()}].slice(-8))}L({tone:`ok`,text:Z&&z?`Leader interrupt queued; all subagents will be interrupted too.`:`${Q} interrupt queued.`}),R(!1)}catch(e){L({tone:`error`,text:e instanceof Error?e.message:String(e)})}finally{F(!1)}}};return(0,w.jsxs)(`div`,{className:`hq-console-shell`,children:[(0,w.jsxs)(`header`,{className:`hq-console-overview`,children:[(0,w.jsxs)(`div`,{className:`hq-console-overview-copy`,children:[(0,w.jsx)(`span`,{className:`hq-console-live-dot`,"data-live":Y!==null,"aria-hidden":`true`}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`span`,{children:`Live transcript`}),(0,w.jsx)(`strong`,{children:l===null?`Select an endpoint`:p?X?.name??u:G.projectName??Q}),(0,w.jsx)(`small`,{children:l===null?`Choose a client or agent from the fleet navigator`:Y?.controllable===!0?`${Q} · control channel ready`:`${Q} · transcript is read-only`})]})]}),(0,w.jsxs)(`fieldset`,{className:`hq-console-overview-metrics`,"aria-label":`Transcript totals`,children:[(0,w.jsx)(j,{label:`turns`,value:K.turns+q.length}),(0,w.jsx)(j,{label:`tools`,value:K.tools}),(0,w.jsx)(j,{label:`running`,value:K.running,tone:K.running>0?`active`:void 0}),(0,w.jsx)(j,{label:`errors`,value:K.errors,tone:K.errors>0?`error`:void 0})]})]}),(0,w.jsx)(D,{snapshot:i??null,selectedSessionId:l,selectedAgentId:u}),(0,w.jsxs)(`div`,{className:`hq-console`,children:[(0,w.jsxs)(`div`,{className:`hq-chat-header`,children:[(0,w.jsx)(o,{size:15,className:`hq-chat-header-icon`}),(0,w.jsx)(`span`,{className:`hq-card-title hq-title-inline`,children:`Console`}),p&&(0,w.jsxs)(`span`,{className:`hq-pill active`,children:[(0,w.jsx)(r,{size:12}),` `,X?.name??u]}),G.projectName!==void 0&&!p&&(0,w.jsx)(`span`,{className:`hq-pill`,children:G.projectName}),Y!==null&&(0,w.jsxs)(`span`,{className:`hq-pill info`,title:Y.client?.clientId,children:[Y.session.hostname??Y.session.machineId,` ·`,` `,Y.session.clientKind.toUpperCase()]}),Y?.mailboxServeActive===!0&&(0,w.jsx)(`span`,{className:`hq-pill active`,children:`mailbox serve`}),G.source!==void 0&&(0,w.jsx)(`span`,{className:`hq-pill`,title:G.source===`disk`?`disk = full history replayed from this machine`:`stream = live ring only (remote or not yet persisted)`,children:G.source===`disk`?`full history`:`live ring`}),(0,w.jsxs)(`span`,{className:`hq-chat-counts`,children:[(0,w.jsxs)(`span`,{className:`hq-pill`,children:[K.turns+q.length,` turns`]}),(0,w.jsxs)(`span`,{className:`hq-pill`,children:[K.tools,` tools`]}),K.running>0&&(0,w.jsxs)(`span`,{className:`hq-pill running`,children:[K.running,` running`]}),K.errors>0&&(0,w.jsxs)(`span`,{className:`hq-pill error`,children:[K.errors,` err`]}),!p&&!U.full&&G.total>W.length&&(0,w.jsxs)(`button`,{type:`button`,className:`hq-btn secondary hq-chat-fullbtn`,onClick:()=>U.setFull(!0),title:`History is truncated — load all ${G.total} turns`,children:[(0,w.jsx)(d,{size:12}),` load all `,G.total]})]})]}),l===null?(0,w.jsxs)(`div`,{className:`hq-console-empty`,children:[(0,w.jsx)(`span`,{"aria-hidden":`true`,children:(0,w.jsx)(o,{size:24})}),(0,w.jsx)(`strong`,{children:`Choose a conversation`}),(0,w.jsx)(`small`,{children:`Pick a live client or agent from the fleet navigator to inspect its transcript.`})]}):U.loading&&W.length===0&&q.length===0?(0,w.jsx)(`div`,{className:`hq-empty`,children:p?`Loading agent history…`:`Loading transcript…`}):U.error===null?(0,w.jsxs)(`div`,{className:`hq-chat-scroll`,children:[W.length===0&&q.length===0?(0,w.jsx)(`div`,{className:`hq-empty`,children:p?`No messages from ${X?.name??u??`this agent`} yet.`:`No transcript entries yet.`}):(0,w.jsxs)(x,{ref:U.listRef,onScroll:U.onScroll,className:`hq-chat-vlist`,children:[W.map((e,t)=>(0,w.jsx)(`div`,{className:`hq-chat-rowpad`,children:(0,w.jsx)(y,{entry:e,running:U.isRunningAt(e,t)})},te(e,t))),q.map(e=>{let t=c.find(t=>t.commandId===e.commandId);return(0,w.jsx)(`div`,{className:`hq-chat-rowpad`,"aria-live":`polite`,children:(0,w.jsx)(k,{receipt:e,lifecycle:t?.ackStatus??t?.status??`queued`})},`receipt:${e.commandId}`)})]}),!U.pinned&&(W.length>0||q.length>0)&&(0,w.jsx)(`button`,{type:`button`,className:`hq-chat-jump`,onClick:J,title:`Jump to latest`,children:(0,w.jsx)(s,{size:14})})]}):(0,w.jsxs)(`div`,{className:`hq-empty`,children:[`Error: `,U.error]}),l!==null&&(0,w.jsxs)(`div`,{className:`hq-console-composer`,children:[(0,w.jsxs)(`div`,{className:`hq-console-composer-head`,children:[(0,w.jsxs)(`span`,{children:[(0,w.jsx)(n,{size:13}),` Send to `,(0,w.jsx)(`strong`,{children:Q})]}),(0,w.jsx)(`span`,{className:`hq-pill ${Y?.controllable===!0?`active`:`error`}`,children:Y?.controllable===!0?`control live`:`read-only client`})]}),(0,w.jsxs)(`div`,{className:`hq-console-compose-row`,children:[(0,w.jsxs)(`select`,{className:`hq-select hq-console-delivery`,"aria-label":`Message delivery mode`,value:T,onChange:e=>{let t=e.target.value;E(t),h({delivery:t})},children:[(0,w.jsx)(`option`,{value:`steer`,children:`Steer now`}),(0,w.jsx)(`option`,{value:`btw`,children:`BTW / FYI`}),(0,w.jsx)(`option`,{value:`queue`,children:`Queue next`})]}),(0,w.jsx)(`input`,{className:`hq-input hq-console-subject`,"aria-label":`Message subject`,placeholder:`HQ ${T} (optional subject)`,value:O,onChange:e=>{A(e.target.value),h({subject:e.target.value})}}),(0,w.jsxs)(`button`,{type:`button`,className:`hq-btn danger hq-console-interrupt`,disabled:P||Y?.controllable!==!0,onClick:()=>{B(!1),R(!0)},children:[(0,w.jsx)(a,{size:13}),` Interrupt`]})]}),(0,w.jsxs)(`div`,{className:`hq-console-compose-row hq-console-message-row`,children:[(0,w.jsx)(`textarea`,{className:`hq-textarea hq-console-message`,"aria-label":`Message ${Q}`,placeholder:`Message ${Q}…`,rows:2,value:M,onChange:e=>{N(e.target.value),h({body:e.target.value})},onKeyDown:e=>{e.key===`Enter`&&(e.ctrlKey||e.metaKey)&&(e.preventDefault(),$())}}),(0,w.jsxs)(`button`,{type:`button`,className:`hq-btn primary hq-console-send`,disabled:P||M.trim().length===0||Y?.controllable!==!0,onClick:()=>void $(),children:[(0,w.jsx)(f,{size:13}),` `,P?`Queueing…`:`Send`]})]}),(0,w.jsxs)(`div`,{className:`hq-console-compose-foot`,children:[(0,w.jsx)(`span`,{children:`Ctrl+Enter sends · steer interrupts at the next safe turn`}),I!==null&&(0,w.jsx)(`span`,{className:`hq-console-status ${I.tone}`,children:I.text})]})]})]}),ne&&Y!==null&&(0,w.jsxs)(`div`,{className:`hq-confirm-layer`,role:`presentation`,children:[(0,w.jsx)(`button`,{type:`button`,className:`hq-confirm-scrim`,"aria-label":`Cancel interrupt`,onClick:()=>R(!1)}),(0,w.jsxs)(`section`,{className:`hq-confirm-dialog`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`hq-interrupt-title`,children:[(0,w.jsx)(a,{size:22,className:`hq-confirm-danger`}),(0,w.jsxs)(`div`,{children:[(0,w.jsxs)(`h2`,{id:`hq-interrupt-title`,children:[`Interrupt `,Q,`?`]}),(0,w.jsx)(`p`,{children:`The current run will stop at its cancellation boundary.`})]}),Z&&(0,w.jsxs)(`label`,{className:`hq-confirm-check`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:z,onChange:e=>B(e.target.checked)}),`Also interrupt every subagent on this client`]}),(0,w.jsxs)(`div`,{className:`hq-confirm-actions`,children:[(0,w.jsx)(`button`,{type:`button`,className:`hq-btn secondary`,onClick:()=>R(!1),children:`Cancel`}),(0,w.jsxs)(`button`,{type:`button`,className:`hq-btn danger`,disabled:P,onClick:()=>void re(),children:[(0,w.jsx)(a,{size:13}),` Confirm interrupt`]})]})]})]})]})}function j({label:e,value:t,tone:n}){return(0,w.jsxs)(`div`,{className:`hq-console-overview-metric`,"data-tone":n,children:[(0,w.jsx)(`strong`,{children:t}),(0,w.jsx)(`span`,{children:e})]})}export{A as LiveConsoleView};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{$ as t,B as n,E as r,H as i,It as a,J as o,N as s,O as c,S as l,V as u,X as d,Zt as f,_ as p,dt as m,l as h,nt as g,s as _,z as v}from"./icons-C4ljWs50.js";import{i as y}from"./markdown--Y3iks7c.js";import{a as b,d as x,l as S,o as C,u as w}from"./index-Ch5wZYYG.js";import{t as T}from"./use-backfilled-events-B4G6jrJe.js";var E=e(f(),1),D=y(),O=[{value:`note`,label:`note — general information`},{value:`ask`,label:`ask — reply required`},{value:`assign`,label:`assign — work ownership`},{value:`steer`,label:`steer — redirect the current work`},{value:`btw`,label:`btw — FYI, no action required`},{value:`queue`,label:`queue — note for the next agent`},{value:`broadcast`,label:`broadcast — all agents in the project`},{value:`status`,label:`status — meaningful checkpoint`},{value:`result`,label:`result — completed output/evidence`},{value:`review`,label:`review — passive inspection request`}];function k({projects:e,sender:t}){let n=t??S,[r,a]=(0,E.useState)(!1),[o,s]=(0,E.useState)(``),[c,l]=(0,E.useState)(`steer`),[u,d]=(0,E.useState)(`leader`),[f,p]=(0,E.useState)(`normal`),[m,h]=(0,E.useState)(!1),[g,_]=(0,E.useState)(``),[v,y]=(0,E.useState)(``),[b,x]=(0,E.useState)({phase:`idle`}),C=o||e[0]?.projectId||``,w=b.phase!==`sending`&&v.trim().length>0&&C.length>0,T=async()=>{if(w){x({phase:`sending`});try{let e=await n({projectId:C,type:c,...c===`broadcast`?{}:{to:u.trim()||`leader`},subject:g.trim()||`HQ prompt`,body:v.trim(),priority:f,audience:m?`leaders`:`all`});x({phase:`sent`,messageId:e.messageId}),y(``)}catch(e){x({phase:`error`,message:e instanceof Error?e.message:String(e)})}}};return r?(0,D.jsxs)(`div`,{className:`hq-card hq-composer`,children:[(0,D.jsxs)(`div`,{className:`hq-row hq-row-baseline`,children:[(0,D.jsx)(`span`,{className:`hq-card-title hq-title-inline`,children:`Send to project mailbox`}),(0,D.jsx)(`span`,{className:`hq-composer-hint`,children:`lands in the mailbox file — picked up by the next agent, no live client needed`}),(0,D.jsx)(`button`,{type:`button`,className:`hq-toggle hq-ml-auto`,"aria-label":`Collapse composer`,onClick:()=>a(!1),children:`▾`})]}),(0,D.jsxs)(`div`,{className:`hq-composer-grid`,children:[(0,D.jsxs)(`label`,{className:`hq-composer-field`,children:[(0,D.jsx)(`span`,{children:`project`}),(0,D.jsx)(`select`,{className:`hq-select`,value:C,onChange:e=>s(e.target.value),children:e.map(e=>(0,D.jsx)(`option`,{value:e.projectId,children:e.label??e.projectId},e.projectId))})]}),(0,D.jsxs)(`label`,{className:`hq-composer-field`,children:[(0,D.jsx)(`span`,{children:`type`}),(0,D.jsx)(`select`,{className:`hq-select`,value:c,onChange:e=>l(e.target.value),children:O.map(e=>(0,D.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),c!==`broadcast`&&(0,D.jsxs)(`label`,{className:`hq-composer-field`,children:[(0,D.jsx)(`span`,{children:`to`}),(0,D.jsx)(`input`,{className:`hq-input`,value:u,placeholder:`leader`,onChange:e=>d(e.target.value)})]}),(0,D.jsxs)(`label`,{className:`hq-composer-field`,children:[(0,D.jsx)(`span`,{children:`audience`}),(0,D.jsxs)(`select`,{className:`hq-select`,value:m?`leaders`:`all`,onChange:e=>h(e.target.value===`leaders`),children:[(0,D.jsx)(`option`,{value:`all`,children:`all agents`}),(0,D.jsx)(`option`,{value:`leaders`,children:`leaders only — subagents cannot consume`})]})]}),(0,D.jsxs)(`label`,{className:`hq-composer-field`,children:[(0,D.jsx)(`span`,{children:`priority`}),(0,D.jsxs)(`select`,{className:`hq-select`,value:f,onChange:e=>p(e.target.value),children:[(0,D.jsx)(`option`,{value:`high`,children:`high`}),(0,D.jsx)(`option`,{value:`normal`,children:`normal`}),(0,D.jsx)(`option`,{value:`low`,children:`low`})]})]})]}),(0,D.jsx)(`input`,{className:`hq-input`,value:g,placeholder:`subject (optional)`,onChange:e=>_(e.target.value)}),(0,D.jsx)(`textarea`,{className:`hq-input hq-composer-body`,value:v,rows:3,placeholder:`Message body — e.g. “after the current task, run the full test suite”`,onChange:e=>y(e.target.value)}),(0,D.jsxs)(`div`,{className:`hq-row`,children:[(0,D.jsx)(`button`,{type:`button`,className:`hq-btn`,disabled:!w,onClick:()=>void T(),children:b.phase===`sending`?`Sending…`:`Send`}),b.phase===`sent`&&(0,D.jsxs)(`span`,{className:`hq-composer-status ok`,children:[`delivered`,b.messageId===void 0?``:` · ${b.messageId.slice(0,8)}`]}),b.phase===`error`&&(0,D.jsx)(`span`,{className:`hq-composer-status err`,title:b.message,children:b.message})]})]}):(0,D.jsxs)(`div`,{className:`hq-composer-bar`,children:[(0,D.jsxs)(`button`,{type:`button`,className:`hq-btn`,disabled:e.length===0,title:e.length===0?`No projects reported yet — connect a client first`:`Write a message into a project mailbox (works with zero connected agents)`,onClick:()=>a(!0),children:[(0,D.jsx)(i,{size:13}),` Compose`]}),b.phase===`sent`&&(0,D.jsxs)(`span`,{className:`hq-composer-status ok`,children:[`delivered`,b.messageId===void 0?``:` · ${b.messageId.slice(0,8)}`]})]})}function A(e){if(typeof e!=`object`||!e)return!1;let t=e;return typeof t.mailboxId==`string`&&(t.scope===`project`||t.scope===`global`)&&Array.isArray(t.messages)&&Array.isArray(t.agents)&&typeof t.totals==`object`&&t.totals!==null}function j(e){if(typeof e!=`object`||!e)return!1;let t=e;return typeof t.mailboxId==`string`&&typeof t.action==`string`&&(t.message===void 0||typeof t.message==`object`)}function M(e,t){let n=e.get(t);return n===void 0&&(n={projectId:t,messages:[],countersFromSnapshot:!1,onlineAgentCount:0,highPriorityCount:0,unreadCount:0,incompleteCount:0},e.set(t,n)),n}function N(e){let t=0,n=0,r=0;for(let i of e){let e=i.message;e.priority===`high`&&(t+=1),e.completed||(r+=1,(e.readCount??0)===0&&(n+=1))}return{highPriorityCount:t,unreadCount:n,incompleteCount:r}}function P(e){let t=new Map;for(let n of e)(t.get(n.message.mailId)===void 0||n.source===`event`)&&t.set(n.message.mailId,n);return Array.from(t.values()).sort((e,t)=>t.message.timestamp.localeCompare(e.message.timestamp))}function F(e,t){let n=new Map;if(e!==null)for(let t of e.mailboxes){let e=M(n,t.projectId);e.mailboxId=t.mailboxId,e.scope=t.scope,e.onlineAgentCount=t.onlineAgentCount,e.highPriorityCount=t.highPriorityCount,e.unreadCount=t.unreadCount,e.incompleteCount=t.incompleteCount,e.countersFromSnapshot=!0}for(let e of t){if(e.type!==`mailbox.snapshot`||!A(e.payload))continue;let t=e.payload,r=M(n,e.projectId);r.mailboxId=t.mailboxId,r.scope=t.scope;for(let n of t.messages)r.messages.push({message:n,source:`snapshot`,key:`s:${e.id}:${n.messageId}`,projectId:e.projectId})}let r=new Map;for(let e of t){if(e.type!==`mailbox.event`||!j(e.payload))continue;let t=e.payload,i=M(n,e.projectId);i.mailboxId=t.mailboxId,i.scope=i.scope??`project`,t.message!==void 0&&!r.has(t.message.mailId)&&(r.set(t.message.mailId,i),i.messages.push({message:t.message,source:`event`,key:`e:${t.message.mailId}:${e.seq}`,projectId:e.projectId})),t.agent?.online&&(i.onlineAgentCount+=1)}for(let e of n.values())if(e.messages=P(e.messages),!e.countersFromSnapshot){let t=N(e.messages);e.highPriorityCount=t.highPriorityCount,e.unreadCount=t.unreadCount,e.incompleteCount=t.incompleteCount}let i=Array.from(n.values()).sort((e,t)=>{let n=e.messages[0]?.message.timestamp??``;return(t.messages[0]?.message.timestamp??``).localeCompare(n)});return{projects:i,hasAnyActivity:i.some(e=>e.messages.length>0)}}var I=Object.freeze({types:new Set,priorities:new Set,projectIds:new Set,includeCompleted:!0,query:``});function ee(e,t){switch(t.type){case`toggle-type`:{let n=new Set(e.types);return n.has(t.value)?n.delete(t.value):n.add(t.value),{...e,types:n}}case`toggle-priority`:{let n=new Set(e.priorities);return n.has(t.value)?n.delete(t.value):n.add(t.value),{...e,priorities:n}}case`toggle-project`:{let n=new Set(e.projectIds);return n.has(t.value)?n.delete(t.value):n.add(t.value),{...e,projectIds:n}}case`set-query`:return{...e,query:t.value};case`set-include-completed`:return{...e,includeCompleted:t.value};case`clear-all`:return I;default:return e}}function te(e,t={}){let n=t.includeCompleted??!0,r=t.types&&t.types.length>0?new Set(t.types):null,i=t.priorities&&t.priorities.length>0?new Set(t.priorities):null,a=t.projectIds&&t.projectIds.length>0?new Set(t.projectIds):null,o=t.query?.trim().toLowerCase()??``,s=t.limit??500,c=[];for(let t of e){let e=t.message;!n&&e.completed||r&&!r.has(e.type)||i&&!i.has(e.priority)||a||o.length>0&&!`${e.subject}\n${e.from}\n${e.to}\n${e.bodyPreview??``}`.toLowerCase().includes(o)||c.push({key:t.key,flat:t})}c.sort((e,t)=>{let n=t.flat.message.timestamp.localeCompare(e.flat.message.timestamp);return n===0?e.flat.message.mailId.localeCompare(t.flat.message.mailId):n});let l=c.length,u=l>s,d=u?c.slice(0,s):c;return{totalMatched:l,returned:d.length,truncated:u,entries:d}}function L(e,t,n={}){let{projectIds:r,...i}=n,a=F(e,t),o=[],s=r!==void 0&&r.length>0?new Set(r):null;for(let e of a.projects)s&&!s.has(e.projectId)||(o=o.concat(e.messages));return te(o,i)}function R(e){if(typeof e!=`object`||!e)return!1;let t=e;if(typeof t.error==`string`)return!0;if(typeof t.error!=`object`||t.error===null)return!1;let n=t.error;return typeof n.code==`string`&&typeof n.message==`string`}async function z(e){let t=await x(`/api/mailbox/messages/${encodeURIComponent(e.mailId)}/action`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)});if(t.status===401&&w.getState().markAuthRequired(),!t.ok){let e=`${t.status} ${t.statusText}`;try{let n=await t.json();R(n)&&(e=typeof n.error==`string`?n.error:`${n.error.code}: ${n.error.message}`)}catch{}throw Error(`mailbox action failed — ${e}`)}return await t.json()}var B={markRead:e=>z({...e,action:`mark-read`}),acknowledge:e=>z({...e,action:`acknowledge`}),reopen:e=>z({...e,action:`reopen`}),softDelete:e=>z({...e,action:`soft-delete`}),restore:e=>z({...e,action:`restore`})};function V({mailId:e,actorId:t,projectId:n,isDeleted:r=!1,onAction:i,disabled:a=!1}){let[o,s]=(0,E.useState)(null),[c,l]=(0,E.useState)(null),u=async(t,n)=>{if(!(a||o!==null)){s(t),l(null);try{await n(),i?.(e,t)}catch(e){l(e instanceof Error?e.message:String(e))}finally{s(null)}}},d={mailId:e,readerId:t,projectId:n};return(0,D.jsxs)(`div`,{className:`hq-msg-actions`,children:[!r&&(0,D.jsx)(`button`,{type:`button`,className:`hq-btn secondary`,disabled:a||o!==null,onClick:()=>u(`mark-read`,()=>B.markRead(d)),children:o===`mark-read`?`…`:`Mark read`}),!r&&(0,D.jsx)(`button`,{type:`button`,className:`hq-btn`,disabled:a||o!==null,onClick:()=>u(`acknowledge`,()=>B.acknowledge(d)),children:o===`acknowledge`?`…`:`Acknowledge`}),!r&&(0,D.jsx)(`button`,{type:`button`,className:`hq-btn secondary`,disabled:a||o!==null,onClick:()=>u(`reopen`,()=>B.reopen(d)),children:o===`reopen`?`…`:`Reopen`}),!r&&(0,D.jsx)(`button`,{type:`button`,className:`hq-btn danger`,disabled:a||o!==null,onClick:()=>u(`soft-delete`,()=>B.softDelete(d)),children:o===`soft-delete`?`…`:`Delete`}),r&&(0,D.jsx)(`button`,{type:`button`,className:`hq-btn secondary`,disabled:a||o!==null,onClick:()=>u(`restore`,()=>B.restore(d)),children:o===`restore`?`…`:`Restore`}),c!==null&&(0,D.jsx)(`span`,{className:`hq-msg-action-error`,title:c,children:c})]})}function H(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString()}function U(e){return e.length<=14?e:`${e.slice(0,8)}…${e.slice(-4)}`}var W={note:{icon:s,tone:`info`},ask:{icon:d,tone:`warn`},assign:{icon:c,tone:`warn`},steer:{icon:d,tone:`warn`},btw:{icon:v,tone:`info`},broadcast:{icon:n,tone:`info`},status:{icon:m,tone:`idle`},result:{icon:a,tone:`running`},review:{icon:l,tone:`info`},control:{icon:p,tone:`error`}};Object.keys(W);var G=`hq-operator`;function K({flat:e,defaultExpanded:t}){let[n,r]=(0,E.useState)(!!t),i=e.message,a=i.hasBody||i.bodyPreview!==void 0&&i.bodyPreview.length>0,o=W[i.type]??{icon:u,tone:`info`},s=o.icon,c=`${i.from} → ${i.to}`;return(0,D.jsxs)(`div`,{className:`hq-msg`+(i.completed?` done`:``),children:[(0,D.jsxs)(`div`,{className:`hq-msg-head`,children:[(0,D.jsx)(`span`,{className:`hq-msg-icon`,title:i.type,children:(0,D.jsx)(s,{size:13})}),(0,D.jsx)(`span`,{className:`hq-pill `+o.tone,children:i.type}),i.audience===`leaders`&&(0,D.jsx)(`span`,{className:`hq-pill info`,children:`leaders only`}),i.priority===`high`&&(0,D.jsx)(`span`,{className:`hq-pill error`,children:`high`}),i.priority===`low`&&(0,D.jsx)(`span`,{className:`hq-pill idle`,children:`low`}),(0,D.jsx)(`span`,{className:`hq-msg-subject`,title:i.subject,children:i.subject||`(no subject)`}),(0,D.jsx)(`span`,{className:`hq-mono hq-msg-route`,children:c}),(0,D.jsx)(`span`,{className:`hq-mono hq-msg-time`,title:i.timestamp,children:H(i.timestamp)}),(0,D.jsx)(`span`,{className:`hq-mono hq-msg-id`,children:U(i.messageId)}),(0,D.jsx)(`span`,{className:`hq-msg-flag `+(i.completed?`done`:`open`),children:i.completed?`completed${i.completedBy===void 0?``:` by ${i.completedBy}`}`:`open`}),a&&(0,D.jsx)(`button`,{type:`button`,className:`hq-toggle hq-msg-toggle`,onClick:()=>r(e=>!e),"aria-expanded":n,"aria-label":n?`Collapse body`:`Expand body`,children:n?`▾`:`▸`})]}),n&&(0,D.jsxs)(`div`,{className:`hq-msg-body`,children:[i.bodyPreview!==void 0&&i.bodyPreview.length>0?(0,D.jsx)(`pre`,{className:`hq-msg-pre`,children:i.bodyPreview}):(0,D.jsx)(`div`,{className:`hq-empty hq-pad-sm`,children:`(empty body)`}),i.outcomePreview!==void 0&&i.outcomePreview.length>0&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`div`,{className:`hq-msg-sublabel`,children:`outcome`}),(0,D.jsx)(`pre`,{className:`hq-msg-pre`,children:i.outcomePreview})]}),(0,D.jsxs)(`div`,{className:`hq-msg-meta`,children:[(0,D.jsxs)(`span`,{children:[(0,D.jsx)(`strong`,{children:`source:`}),` `,e.source]}),i.replyTo!==void 0&&(0,D.jsxs)(`span`,{children:[(0,D.jsx)(`strong`,{children:`reply to:`}),` `,U(i.replyTo)]}),i.senderSessionId!==void 0&&(0,D.jsxs)(`span`,{children:[(0,D.jsx)(`strong`,{children:`sender session:`}),` `,U(i.senderSessionId)]}),(i.readCount??0)>0&&(0,D.jsxs)(`span`,{children:[(0,D.jsx)(`strong`,{children:`reads:`}),` `,i.readCount]}),i.unreadCount!==void 0&&i.unreadCount>0&&(0,D.jsxs)(`span`,{children:[(0,D.jsx)(`strong`,{children:`unread:`}),` `,i.unreadCount]}),i.task!==void 0&&(0,D.jsxs)(`span`,{children:[(0,D.jsx)(`strong`,{children:`task:`}),` `,i.task.taskId??`—`,i.task.agentName===void 0?``:` · ${i.task.agentName}`,i.task.status===void 0?``:` (${i.task.status})`]})]}),e.projectId!==void 0&&(0,D.jsx)(V,{mailId:i.mailId,actorId:G,projectId:e.projectId})]})]})}var q=[`ask`,`assign`,`steer`,`review`,`result`,`status`,`broadcast`,`note`,`btw`,`control`],J=[`high`,`normal`,`low`];function Y({snapshot:e,events:t}={}){let n=w(e=>e.snapshot),r=e===void 0?n:e,i=t===void 0?w.getState().events:t,a=C(),[o,s]=(0,E.useReducer)(ee,(0,E.useMemo)(()=>{let e=a.mailbox;return{types:new Set(e.types),priorities:new Set(e.priorities),projectIds:new Set,includeCompleted:e.includeCompleted,query:e.query}},[a.mailbox]));(0,E.useEffect)(()=>{b({query:o.query,types:Array.from(o.types),priorities:Array.from(o.priorities),includeCompleted:o.includeCompleted})},[o.query,o.types,o.priorities,o.includeCompleted]);let c=(0,E.useMemo)(()=>F(r??null,i).projects.map(e=>({projectId:e.projectId,count:e.messages.length})),[r,i]),l=(0,E.useMemo)(()=>L(r??null,i,{types:Array.from(o.types),priorities:Array.from(o.priorities),projectIds:Array.from(o.projectIds),includeCompleted:o.includeCompleted,query:o.query||void 0,limit:500}),[r,i,o]),u=o.types.size+o.priorities.size+o.projectIds.size+ +!o.includeCompleted+ +(o.query.trim().length>0);return(0,D.jsxs)(`div`,{children:[(0,D.jsxs)(`div`,{className:`hq-card-title`,children:[`Live mailbox feed · `,l.returned,` of `,l.totalMatched,` message`,l.totalMatched===1?``:`s`,l.truncated?` · refined to fit`:``]}),(0,D.jsxs)(`div`,{className:`hq-card hq-mailbox-filterbar`,children:[(0,D.jsx)(`label`,{className:`hq-label`,htmlFor:`mailbox-live-query`,children:`Search`}),(0,D.jsx)(`input`,{id:`mailbox-live-query`,className:`hq-input`,value:o.query,onChange:e=>s({type:`set-query`,value:e.target.value}),placeholder:`subject / sender / recipient / body…`}),(0,D.jsx)(X,{title:`Types`,children:q.map(e=>(0,D.jsx)(Z,{selected:o.types.has(e),label:e,onClick:()=>s({type:`toggle-type`,value:e})},e))}),(0,D.jsx)(X,{title:`Priority`,children:J.map(e=>(0,D.jsx)(Z,{selected:o.priorities.has(e),label:e,tone:e===`high`?`error`:e===`low`?`idle`:`info`,onClick:()=>s({type:`toggle-priority`,value:e})},e))}),c.length>0&&(0,D.jsx)(X,{title:`Projects`,children:c.map(e=>(0,D.jsx)(Z,{selected:o.projectIds.has(e.projectId),label:`${e.projectId} (${e.count})`,onClick:()=>s({type:`toggle-project`,value:e.projectId})},e.projectId))}),(0,D.jsxs)(`div`,{className:`hq-row hq-mailbox-filter-actions`,children:[(0,D.jsxs)(`label`,{className:`hq-check`,children:[(0,D.jsx)(`input`,{type:`checkbox`,checked:o.includeCompleted,onChange:e=>s({type:`set-include-completed`,value:e.target.checked})}),`include completed`]}),(0,D.jsxs)(`button`,{type:`button`,className:`hq-btn secondary`,disabled:u===0,onClick:()=>s({type:`clear-all`}),children:[`Clear filters`,u>0?` (${u})`:``]})]})]}),l.entries.length===0?(0,D.jsx)(`div`,{className:`hq-empty`,children:`No mailbox activity matches the current filters.`}):(0,D.jsx)(`div`,{className:`hq-msg-list hq-live-feed`,children:l.entries.map((e,t)=>(0,D.jsx)(K,{flat:e.flat,defaultExpanded:t===0&&o.query.trim().length>0},e.key))})]})}function X({title:e,children:t}){return(0,D.jsxs)(`div`,{className:`hq-filter-section`,children:[(0,D.jsx)(`div`,{className:`hq-msg-sublabel`,children:e}),(0,D.jsx)(`div`,{className:`hq-filter-chip-row`,children:t})]})}function Z({selected:e,label:t,onClick:n,tone:r=`info`}){return(0,D.jsx)(`button`,{type:`button`,className:`hq-filter-chip hq-pill ${r}${e?` selected`:``}`,"aria-pressed":e,onClick:n,children:t})}function ne(){let e=w(e=>e.snapshot),[n,i]=(0,E.useState)(`live`),{events:a}=T(`mailbox.event`,300),s=a,{projects:c,hasAnyActivity:l}=(0,E.useMemo)(()=>F(e,s),[e,s]),u=e?.totals.unreadMailboxMessages??0,d=e?.totals.incompleteMailboxMessages??0,f=(e?.mailboxes??[]).reduce((e,t)=>e+t.messageCount,0),p=(e?.mailboxes??[]).reduce((e,t)=>e+t.highPriorityCount,0),m=(e?.mailboxes??[]).reduce((e,t)=>e+t.onlineAgentCount,0),h=(0,E.useMemo)(()=>{let t=new Map;for(let n of e?.projects??[])t.set(n.projectId,{projectId:n.projectId,label:n.projectName});for(let e of c)t.has(e.projectId)||t.set(e.projectId,{projectId:e.projectId});return Array.from(t.values())},[e,c]);return c.length===0&&h.length===0?(0,D.jsxs)(`div`,{className:`hq-mailbox-zero`,children:[(0,D.jsx)(`span`,{className:`hq-mailbox-zero-icon`,"aria-hidden":`true`,children:(0,D.jsx)(g,{size:26})}),(0,D.jsx)(`span`,{className:`hq-section-kicker`,children:`Coordination inbox`}),(0,D.jsx)(`h2`,{children:`Waiting for mailbox traffic`}),(0,D.jsx)(`p`,{children:`Connected projects, inter-agent messages and durable prompts will appear here as soon as a client reports mailbox activity.`})]}):(0,D.jsxs)(`div`,{className:`hq-screen hq-mailbox-screen`,children:[(0,D.jsxs)(`section`,{className:`hq-screen-hero hq-mailbox-hero`,"aria-label":`Mailbox command summary`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`span`,{className:`hq-section-kicker`,children:`Coordination inbox`}),(0,D.jsx)(`h2`,{children:u>0?`${u} message${u===1?``:`s`} ${u===1?`needs`:`need`} review`:`Coordination is clear`}),(0,D.jsx)(`p`,{children:`Live cross-project traffic, durable prompts and unresolved coordination work share one operator inbox.`}),(0,D.jsxs)(`div`,{className:`hq-mailbox-hero-state`,children:[(0,D.jsxs)(`span`,{className:`hq-pill active`,children:[(0,D.jsx)(r,{size:11}),` live sync`]}),(0,D.jsxs)(`span`,{className:`hq-mono hq-text-dim`,children:[`Mailbox Activity — `,c.length,` project`,c.length===1?``:`s`,` ·`,` `,u,` unread · `,d,` incomplete`,l?` · detailed messages available`:``]})]})]}),(0,D.jsxs)(`div`,{className:`hq-hero-metrics`,children:[(0,D.jsx)(Q,{label:`messages`,value:f}),(0,D.jsx)(Q,{label:`unread`,value:u,tone:u>0?`warn`:`ok`}),(0,D.jsx)(Q,{label:`high priority`,value:p,tone:p>0?`error`:`ok`}),(0,D.jsx)(Q,{label:`online agents`,value:m,tone:m>0?`ok`:void 0})]})]}),(0,D.jsxs)(`div`,{className:`hq-mailbox-command-strip`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`strong`,{children:`Durable delivery`}),(0,D.jsx)(`span`,{children:`Write directly to a project mailbox, even when no agent is currently connected.`})]}),(0,D.jsx)(k,{projects:h})]}),(0,D.jsxs)(`div`,{className:`hq-mailbox-workspace-head`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`span`,{className:`hq-section-kicker`,children:`Message workspace`}),(0,D.jsx)(`strong`,{children:n===`live`?`Unified timeline`:`Project channels`})]}),(0,D.jsxs)(`div`,{className:`hq-mailbox-modebar`,role:`tablist`,"aria-label":`Mailbox view mode`,children:[(0,D.jsxs)(`button`,{type:`button`,role:`tab`,className:`hq-btn secondary`+(n===`live`?` hq-btn-selected`:``),"aria-selected":n===`live`,onClick:()=>i(`live`),children:[(0,D.jsx)(o,{size:13}),` Live feed`]}),(0,D.jsxs)(`button`,{type:`button`,role:`tab`,className:`hq-btn secondary`+(n===`grouped`?` hq-btn-selected`:``),"aria-selected":n===`grouped`,onClick:()=>i(`grouped`),children:[(0,D.jsx)(t,{size:13}),` Grouped by project`]})]})]}),(0,D.jsx)(`div`,{className:`hq-mailbox-workspace`,children:n===`live`?(0,D.jsx)(Y,{snapshot:e,events:s}):c.map(e=>(0,D.jsx)(re,{group:e},e.projectId))})]})}function Q({label:e,value:t,tone:n}){return(0,D.jsxs)(`div`,{className:`hq-hero-metric hq-mailbox-metric`,"data-tone":n,children:[(0,D.jsx)(n===`error`?h:e===`online agents`?_:g,{size:13}),(0,D.jsx)(`strong`,{children:t}),(0,D.jsx)(`span`,{children:e})]})}function re({group:e}){let[t,n]=(0,E.useState)(!0);return(0,D.jsxs)(`div`,{className:`hq-card hq-mailbox-project-card`,children:[(0,D.jsxs)(`div`,{className:`hq-row hq-row-baseline`,children:[(0,D.jsx)(`button`,{type:`button`,className:`hq-toggle`,onClick:()=>n(e=>!e),"aria-label":t?`Collapse project messages`:`Expand project messages`,children:t?`▾`:`▸`}),(0,D.jsx)(`span`,{className:`hq-text-bright`,children:e.projectId}),e.scope!==void 0&&(0,D.jsx)(`span`,{className:`hq-pill info`,children:e.scope}),e.mailboxId!==void 0&&(0,D.jsx)(`span`,{className:`hq-mono hq-text-dim`,children:e.mailboxId}),(0,D.jsxs)(`span`,{className:`hq-mono hq-text-dim hq-ml-auto`,children:[e.messages.length,` message`,e.messages.length===1?``:`s`]})]}),(0,D.jsxs)(`div`,{className:`hq-grid hq-mt-8`,style:{gridTemplateColumns:`repeat(5,1fr)`},children:[(0,D.jsx)($,{label:`messages`,value:e.messages.length}),(0,D.jsx)($,{label:`unread`,value:e.unreadCount,accent:e.unreadCount>0?`amber`:void 0}),(0,D.jsx)($,{label:`incomplete`,value:e.incompleteCount,accent:e.incompleteCount>0?`red`:void 0}),(0,D.jsx)($,{label:`high-priority`,value:e.highPriorityCount,accent:e.highPriorityCount>0?`red`:void 0}),(0,D.jsx)($,{label:`online agents`,value:e.onlineAgentCount,accent:e.onlineAgentCount>0?`green`:void 0})]}),t&&e.messages.length>0&&(0,D.jsx)(`div`,{className:`hq-msg-list hq-mt-12`,children:e.messages.map(e=>(0,D.jsx)(K,{flat:e},e.key))}),t&&e.messages.length===0&&(0,D.jsx)(`div`,{className:`hq-empty hq-cockpit-empty`,children:`Snapshot counters reported for this project, but no detailed mailbox events have streamed yet.`})]})}function $({label:e,value:t,accent:n}){return(0,D.jsxs)(`div`,{className:`hq-text-center`,children:[(0,D.jsx)(`div`,{className:`hq-stat-num`,style:{color:n===`amber`?`var(--amber)`:n===`red`?`var(--red)`:n===`green`?`var(--green)`:`var(--text)`},children:t}),(0,D.jsx)(`div`,{className:`hq-stat-label`,children:e})]})}export{ne as MailboxView};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{Zt as t}from"./icons-C4ljWs50.js";import{i as n}from"./markdown--Y3iks7c.js";import{s as r}from"./index-Ch5wZYYG.js";var i=e(t(),1),a=n();function o({points:e,color:t,height:n=140,format:r,emptyLabel:o=`no data`}){let[s,c]=(0,i.useState)(null),l=(0,i.useId)(),u=n,d=u-10-22,f=(0,i.useMemo)(()=>Math.max(...e.map(e=>e.value),0),[e]);if(e.length===0||f<=0)return(0,a.jsx)(`div`,{className:`hq-chart-empty`,children:o});let p=e.length,m=666/p,h=Math.max(2,Math.min(18,m-2)),g=e=>10+d*(1-e/f),_=[f*.25,f*.5,f*.75,f],v=Math.max(1,Math.round(p/5)),y=e=>new Date(e).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`}),b=s===null?void 0:e[s];return(0,a.jsxs)(`div`,{className:`hq-chart`,children:[(0,a.jsxs)(`svg`,{viewBox:`0 0 720 ${u}`,className:`hq-chart-svg`,role:`img`,"aria-label":`Time series chart with ${e.length} data points`,onMouseLeave:()=>c(null),onMouseMove:t=>{let n=t.currentTarget.getBoundingClientRect(),r=(t.clientX-n.left)/n.width*720,i=Math.floor((r-46)/m);c(i>=0&&i<e.length?i:null)},children:[(0,a.jsx)(`clipPath`,{id:l,children:(0,a.jsx)(`rect`,{x:46,y:10,width:666,height:d})}),_.map((e,t)=>(0,a.jsxs)(`g`,{children:[(0,a.jsx)(`line`,{x1:46,x2:712,y1:g(e),y2:g(e),className:`hq-chart-grid`}),(0,a.jsx)(`text`,{x:40,y:g(e)+3,className:`hq-chart-ytick`,textAnchor:`end`,children:r(e)})]},t)),(0,a.jsx)(`line`,{x1:46,x2:712,y1:10+d,y2:10+d,className:`hq-chart-axis`}),(0,a.jsx)(`g`,{clipPath:`url(#${l})`,children:e.map((e,n)=>{let r=46+n*m+(m-h)/2,i=g(e.value),o=10+d-i;return o<=0?null:(0,a.jsx)(`rect`,{x:r,y:i,width:h,height:o,rx:Math.min(3,h/2),fill:t,opacity:s===null||s===n?1:.45},n)})}),e.map((e,t)=>t%v===0?(0,a.jsx)(`text`,{x:46+t*m+m/2,y:u-6,className:`hq-chart-xtick`,textAnchor:`middle`,children:y(e.ts)},t):null),(0,a.jsx)(`rect`,{x:46,y:10,width:666,height:d,fill:`transparent`})]}),b!==void 0&&(0,a.jsxs)(`div`,{className:`hq-chart-tooltip`,children:[(0,a.jsx)(`span`,{className:`hq-chart-tooltip-swatch`,style:{background:t}}),(0,a.jsx)(`span`,{className:`hq-chart-tooltip-value`,children:r(b.value)}),(0,a.jsx)(`span`,{className:`hq-chart-tooltip-time`,children:y(b.ts)})]})]})}var s=[{label:`1h`,ms:3600*1e3},{label:`6h`,ms:360*60*1e3},{label:`24h`,ms:1440*60*1e3},{label:`7d`,ms:10080*60*1e3}];function c(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(Math.round(e))}function l(e,t){let n=new Map;for(let r of e){let e=r[t];if(e!==void 0)for(let[t,r]of Object.entries(e)){let e=n.get(t);e===void 0?n.set(t,{...r}):(e.costUsd+=r.costUsd,e.inputTokens+=r.inputTokens,e.outputTokens+=r.outputTokens,e.cacheRead=(e.cacheRead??0)+(r.cacheRead??0),e.cacheWrite=(e.cacheWrite??0)+(r.cacheWrite??0))}}return[...n.entries()].map(([e,t])=>({key:e,entry:t})).sort((e,t)=>t.entry.costUsd-e.entry.costUsd)}function u(){let[e,t]=(0,i.useState)([]),[n,u]=(0,i.useState)(null),[f,p]=(0,i.useState)(s[2].ms);(0,i.useEffect)(()=>{let e=!1,n=()=>{r(`/api/trends/cost`).then(n=>{e||(t(n.samples),u(null))}).catch(t=>{e||u(t.message)})};n();let i=setInterval(n,3e4);return()=>{e=!0,clearInterval(i)}},[]);let{shown:m,totalCost:h,totalTokens:g,totalTools:_,byModel:v,byProvider:y,totalCacheRead:b,totalCacheWrite:x}=(0,i.useMemo)(()=>{let t=Date.now()-f,n=e.filter(e=>e.ts>=t),r=n.length>0?n:e.slice(-24),i=r.reduce((e,t)=>e+t.costUsd,0),a=r.reduce((e,t)=>e+t.inputTokens+t.outputTokens,0),o=r.reduce((e,t)=>e+t.toolCalls,0),s=l(r,`byModel`);return{shown:r,totalCost:i,totalTokens:a,totalTools:o,byModel:s,byProvider:l(r,`byProvider`),totalCacheRead:s.reduce((e,t)=>e+(t.entry.cacheRead??0),0),totalCacheWrite:s.reduce((e,t)=>e+(t.entry.cacheWrite??0),0)}},[e,f]);if(n!==null)return(0,a.jsxs)(`div`,{className:`hq-empty hq-empty-ornate`,children:[`Error loading trends: `,n]});if(e.length===0)return(0,a.jsx)(`div`,{className:`hq-empty hq-empty-ornate`,children:`No trend data yet. Trends accumulate as cost signals arrive.`});let S=v.length>0,C=b+x>0?b/(b+x)*100:null,w=s.find(e=>e.ms===f)?.label??`custom`;return(0,a.jsxs)(`div`,{className:`hq-screen hq-trends-screen`,children:[(0,a.jsxs)(`section`,{className:`hq-screen-hero hq-trends-hero`,"aria-label":`Telemetry trend summary`,children:[(0,a.jsxs)(`div`,{children:[(0,a.jsx)(`span`,{className:`hq-section-kicker`,children:`Telemetry runway`}),(0,a.jsxs)(`h2`,{children:[w,` signal window`]}),(0,a.jsx)(`p`,{children:`Cost, tokens and tool activity are split into single-purpose charts so spikes stay attributable without dual-axis ambiguity.`})]}),(0,a.jsxs)(`div`,{className:`hq-hero-metrics`,children:[(0,a.jsx)(d,{label:`cost`,value:`$${h.toFixed(4)}`}),(0,a.jsx)(d,{label:`tokens`,value:c(g),tone:`warn`}),(0,a.jsx)(d,{label:`tool calls`,value:_.toLocaleString(),tone:`ok`}),C===null?null:(0,a.jsx)(d,{label:`cache hit`,value:`${C.toFixed(0)}%`})]})]}),(0,a.jsxs)(`div`,{className:`hq-filter-row hq-trends-filter-row`,children:[s.map(e=>(0,a.jsx)(`button`,{type:`button`,className:`hq-pill hq-filter-chip${f===e.ms?` selected`:``}`,onClick:()=>p(e.ms),children:e.label},e.label)),(0,a.jsxs)(`span`,{className:`hq-mono hq-row-subtle hq-ml-auto`,children:[m.length,` × 5-min buckets`]})]}),(0,a.jsxs)(`section`,{className:`hq-chart-gallery`,"aria-label":`Trend charts`,children:[(0,a.jsxs)(`div`,{className:`hq-card hq-chart-card primary`,children:[(0,a.jsx)(`div`,{className:`hq-section-head compact`,children:(0,a.jsxs)(`div`,{children:[(0,a.jsx)(`span`,{className:`hq-section-kicker`,children:`Spend`}),(0,a.jsx)(`h3`,{children:`Cost (USD)`})]})}),(0,a.jsx)(o,{points:m.map(e=>({ts:e.ts,value:e.costUsd})),color:`var(--chart-1)`,format:e=>`$${e>=1?e.toFixed(2):e.toFixed(4)}`})]}),(0,a.jsxs)(`div`,{className:`hq-card hq-chart-card`,children:[(0,a.jsx)(`div`,{className:`hq-section-head compact`,children:(0,a.jsxs)(`div`,{children:[(0,a.jsx)(`span`,{className:`hq-section-kicker`,children:`Volume`}),(0,a.jsx)(`h3`,{children:`Tokens (in + out)`})]})}),(0,a.jsx)(o,{points:m.map(e=>({ts:e.ts,value:e.inputTokens+e.outputTokens})),color:`var(--chart-2)`,format:c})]}),(0,a.jsxs)(`div`,{className:`hq-card hq-chart-card`,children:[(0,a.jsx)(`div`,{className:`hq-section-head compact`,children:(0,a.jsxs)(`div`,{children:[(0,a.jsx)(`span`,{className:`hq-section-kicker`,children:`Activity`}),(0,a.jsx)(`h3`,{children:`Tool calls`})]})}),(0,a.jsx)(o,{points:m.map(e=>({ts:e.ts,value:e.toolCalls})),color:`var(--chart-3)`,format:e=>String(Math.round(e))})]})]}),S&&(0,a.jsxs)(`section`,{className:`hq-two-column hq-trends-breakdowns`,children:[(0,a.jsxs)(`div`,{children:[(0,a.jsx)(`div`,{className:`hq-section-head compact`,children:(0,a.jsxs)(`div`,{children:[(0,a.jsx)(`span`,{className:`hq-section-kicker`,children:`Model economics`}),(0,a.jsx)(`h3`,{children:`By Model`})]})}),(0,a.jsx)(`div`,{className:`hq-card hq-breakdown-card`,children:v.map(({key:e,entry:t})=>{let n=h>0?t.costUsd/h*100:0;return(0,a.jsxs)(`div`,{className:`hq-row hq-breakdown-row`,children:[(0,a.jsx)(`span`,{className:`hq-text-bright`,children:e}),(0,a.jsxs)(`span`,{className:`hq-mono hq-row-subtle`,children:[c(t.inputTokens),`→`,c(t.outputTokens),t.cacheRead!==void 0||t.cacheWrite!==void 0?` · cache ${c((t.cacheRead??0)+(t.cacheWrite??0))}`:``]}),(0,a.jsxs)(`span`,{className:`hq-cost-amount hq-ml-auto`,children:[`$`,t.costUsd.toFixed(4)]}),(0,a.jsxs)(`span`,{className:`hq-mono hq-row-subtle`,children:[n.toFixed(1),`%`]})]},e)})})]}),y.length>1&&(0,a.jsxs)(`div`,{children:[(0,a.jsx)(`div`,{className:`hq-section-head compact`,children:(0,a.jsxs)(`div`,{children:[(0,a.jsx)(`span`,{className:`hq-section-kicker`,children:`Provider split`}),(0,a.jsx)(`h3`,{children:`By Provider`})]})}),(0,a.jsx)(`div`,{className:`hq-card hq-breakdown-card`,children:y.map(({key:e,entry:t})=>{let n=h>0?t.costUsd/h*100:0;return(0,a.jsxs)(`div`,{className:`hq-row hq-breakdown-row`,children:[(0,a.jsx)(`span`,{className:`hq-text-bright`,children:e}),(0,a.jsxs)(`span`,{className:`hq-cost-amount hq-ml-auto`,children:[`$`,t.costUsd.toFixed(4)]}),(0,a.jsxs)(`span`,{className:`hq-mono hq-row-subtle`,children:[n.toFixed(1),`%`]})]},e)})})]})]})]})}function d({label:e,value:t,tone:n}){return(0,a.jsxs)(`div`,{className:`hq-hero-metric`,"data-tone":n,children:[(0,a.jsx)(`strong`,{children:t}),(0,a.jsx)(`span`,{children:e})]})}export{u as TrendsView};
|