@wrongstack/webui-hq 0.305.1 → 0.306.2
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-c5Z3RmRO.js → alerts-C0ahAgyj.js} +1 -1
- package/dist/assets/{brain-yFwqzSQm.js → brain-DxZxkdy0.js} +1 -1
- package/dist/assets/{cockpit-DYI1Mtmj.js → cockpit-CnFi0HLk.js} +1 -1
- package/dist/assets/{control-DgiLstey.js → control-D4n1t2nX.js} +1 -1
- package/dist/assets/{cost-CjUmg7Cz.js → cost-qSQMT1ZD.js} +1 -1
- package/dist/assets/{fleet-map-DPFffNsC.js → fleet-map-CjeZ6E-P.js} +1 -1
- package/dist/assets/{fleet-topology-DGriqRY0.js → fleet-topology-BcXKnYKF.js} +4 -3
- package/dist/assets/{index-BlKmioWF.js → index-Ch5wZYYG.js} +2 -2
- package/dist/assets/{kanban-xZUo4Rvz.js → kanban-CsIHI3Wr.js} +1 -1
- package/dist/assets/{live-console-oOSsUGsT.js → live-console-CIxhBhTg.js} +1 -1
- package/dist/assets/{mailbox-DyoU-DxV.js → mailbox-DnJYghSf.js} +1 -1
- package/dist/assets/{settings-OX1daA1q.js → settings-CiwxymER.js} +1 -1
- package/dist/assets/{trends-BPRMod5a.js → trends-C8_-duaz.js} +1 -1
- package/dist/assets/{use-backfilled-events-BGysB4Zn.js → use-backfilled-events-B4G6jrJe.js} +1 -1
- package/dist/assets/{worktree-CYeNZBRN.js → worktree-CC8bd1Ev.js} +1 -1
- package/dist/index.html +1 -1
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{D as t,Kt as n,Lt as r,Zt as i,b as a,dt as o}from"./icons-C4ljWs50.js";import{i as s}from"./markdown--Y3iks7c.js";import{p as c,s as l,u}from"./index-
|
|
1
|
+
import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{D as t,Kt as n,Lt as r,Zt as i,b as a,dt as o}from"./icons-C4ljWs50.js";import{i as s}from"./markdown--Y3iks7c.js";import{p as c,s as l,u}from"./index-Ch5wZYYG.js";var d=e(i(),1),f=s();function p(){let{alerts:e,snapshot:i,commandStatuses:s}=u(c(e=>({alerts:e.alerts,snapshot:e.snapshot,commandStatuses:e.commandStatuses}))),[p,g]=(0,d.useState)([]),[_,v]=(0,d.useState)([]);(0,d.useEffect)(()=>{let e=!1,t=()=>{l(`/api/alerts`).then(t=>{e||(g(t.active),v(t.history))}).catch(()=>{})};t();let n=setInterval(t,15e3);return()=>{e=!0,clearInterval(n)}},[]);let y=e.slice(-50).reverse(),b=p.filter(e=>e.severity===`error`).length,x=p.filter(e=>e.severity===`warn`).length,S=(i?.projects??[]).filter(e=>e.governance?.signal.level===`warning`||e.governance?.signal.level===`unavailable`),C=(i?.liveSessions??[]).flatMap(e=>(e.agents??[]).filter(e=>e.status===`waiting_user`||e.status===`error`).map(t=>({agent:t,session:e}))),w=s.filter(e=>e.ackStatus===`failed`||e.ackStatus===`rejected`),T=(i?.clients??[]).filter(e=>!e.connected),E=p.length+S.length+C.length+w.length+T.length,D=E===0&&y.length===0;return(0,f.jsxs)(`div`,{className:`hq-screen hq-alerts-screen`,children:[(0,f.jsxs)(`section`,{className:`hq-screen-hero hq-alerts-hero`,"aria-label":`Alert command summary`,children:[(0,f.jsxs)(`div`,{children:[(0,f.jsx)(`span`,{className:`hq-section-kicker`,children:`Operator attention center`}),(0,f.jsx)(`h2`,{children:D?`Fleet quiet`:`Fleet requires review`}),(0,f.jsx)(`p`,{children:`Alerts, waiting agents, governance warnings and failed commands are resolved into one prioritized operator queue.`})]}),(0,f.jsxs)(`div`,{className:`hq-hero-metrics`,children:[(0,f.jsx)(h,{label:`needs action`,value:E,tone:E>0?`warn`:`ok`}),(0,f.jsx)(h,{label:`waiting agents`,value:C.length,tone:C.length>0?`warn`:`ok`}),(0,f.jsx)(h,{label:`governance`,value:S.length,tone:S.length>0?`error`:`ok`}),(0,f.jsx)(h,{label:`failed commands`,value:w.length,tone:w.length>0?`error`:`ok`})]})]}),(0,f.jsxs)(`section`,{className:`hq-attention-section`,"aria-label":`Cross-system attention signals`,children:[(0,f.jsxs)(`div`,{className:`hq-section-head`,children:[(0,f.jsxs)(`div`,{children:[(0,f.jsx)(`span`,{className:`hq-section-kicker`,children:`Priority queue`}),(0,f.jsx)(`h3`,{children:`Cross-system signals`})]}),(0,f.jsx)(`span`,{className:`hq-pill `+(E>0?`warn`:`active`),children:E>0?`${E} need review`:`all clear`})]}),E===0?(0,f.jsx)(`div`,{className:`hq-empty hq-pad-md`,children:`No cross-system signals need operator action.`}):(0,f.jsxs)(`div`,{className:`hq-attention-grid`,children:[C.length>0?(0,f.jsx)(m,{icon:n,tone:`warn`,label:`Agent attention`,value:C.length,detail:`${C[0]?.agent.name??C[0]?.agent.id??`Agent`} · ${C[0]?.agent.status}`,action:`Open console`,view:`console`}):null,S.length>0?(0,f.jsx)(m,{icon:o,tone:`error`,label:`Governance advisory`,value:S.length,detail:`${S[0]?.projectName??`Project`} · ${S[0]?.governance?.signal.code??`warning`}`,action:`Open fleet`,view:`fleet`}):null,w.length>0?(0,f.jsx)(m,{icon:t,tone:`error`,label:`Command failures`,value:w.length,detail:`${w[0]?.type??`command`} · ${w[0]?.ackStatus??`failed`}`,action:`Open audit`,view:`control`}):null,T.length>0?(0,f.jsx)(m,{icon:a,tone:`warn`,label:`Disconnected clients`,value:T.length,detail:T[0]?.hostname??T[0]?.clientId??`Client`,action:`Open fleet`,view:`fleet`}):null,p.length>0?(0,f.jsx)(m,{icon:r,tone:b>0?`error`:`warn`,label:`Active alert rules`,value:p.length,detail:`${b} errors · ${x} warnings`,action:`Review below`}):null]})]}),(0,f.jsxs)(`section`,{className:`hq-priority-section`,"aria-label":`Active alerts`,children:[(0,f.jsxs)(`div`,{className:`hq-section-head`,children:[(0,f.jsxs)(`div`,{children:[(0,f.jsx)(`span`,{className:`hq-section-kicker`,children:`Now`}),(0,f.jsxs)(`h3`,{children:[`Active Alerts (`,p.length,`)`]})]}),p.length>0?(0,f.jsx)(`span`,{className:`hq-pill warn`,children:`operator attention`}):null]}),p.length>0?(0,f.jsx)(`div`,{className:`hq-alert-priority-grid`,children:p.map(e=>(0,f.jsxs)(`div`,{className:`hq-card hq-alert-card hq-card-severity `+e.severity,children:[(0,f.jsxs)(`div`,{className:`hq-row`,children:[(0,f.jsx)(`span`,{className:`hq-pill `+e.severity,children:e.severity}),(0,f.jsx)(`span`,{className:`hq-text-bright`,children:e.ruleId}),(0,f.jsxs)(`span`,{className:`hq-mono hq-ml-auto hq-text-dim`,children:[`since `,new Date(e.firstFiredAt).toLocaleTimeString()]})]}),(0,f.jsx)(`div`,{className:`hq-row-detail`,children:e.message})]},e.id))}):(0,f.jsx)(`div`,{className:`hq-empty hq-empty-ornate`,children:`No active alert rules are firing. The live feed below will wake this rail when cost, stale-session or failure thresholds trip.`})]}),(0,f.jsxs)(`div`,{className:`hq-two-column hq-alerts-columns`,children:[(0,f.jsxs)(`section`,{children:[(0,f.jsxs)(`div`,{className:`hq-section-head compact`,children:[(0,f.jsxs)(`div`,{children:[(0,f.jsx)(`span`,{className:`hq-section-kicker`,children:`Signal stream`}),(0,f.jsx)(`h3`,{children:`Live Alert Feed`})]}),(0,f.jsxs)(`span`,{className:`hq-mono hq-row-subtle`,children:[`last `,y.length]})]}),y.length===0?(0,f.jsx)(`div`,{className:`hq-empty hq-pad-md`,children:`No live alerts. Alerts fire when fleet rules trigger.`}):(0,f.jsx)(`div`,{className:`hq-card hq-alert-feed-card`,children:y.map(e=>(0,f.jsxs)(`div`,{className:`hq-row hq-alert-feed-row`,children:[(0,f.jsx)(`span`,{className:`hq-pill `+e.severity,children:e.severity}),(0,f.jsx)(`span`,{className:`hq-text-muted`,children:e.message}),(0,f.jsx)(`span`,{className:`hq-mono hq-ml-auto hq-text-dim`,children:new Date(e.timestamp).toLocaleTimeString()})]},e.timestamp))})]}),(0,f.jsxs)(`section`,{children:[(0,f.jsxs)(`div`,{className:`hq-section-head compact`,children:[(0,f.jsxs)(`div`,{children:[(0,f.jsx)(`span`,{className:`hq-section-kicker`,children:`Archive`}),(0,f.jsx)(`h3`,{children:`Alert History`})]}),(0,f.jsxs)(`span`,{className:`hq-mono hq-row-subtle`,children:[_.length,` total`]})]}),(0,f.jsx)(`div`,{className:`hq-card hq-alert-history-card`,children:_.length===0?(0,f.jsx)(`div`,{className:`hq-empty hq-pad-md`,children:`No historical alerts.`}):_.slice(-30).reverse().map(e=>(0,f.jsxs)(`div`,{className:`hq-row hq-alert-history-row`,children:[(0,f.jsx)(`span`,{className:`hq-pill `+e.severity,children:e.severity}),(0,f.jsx)(`span`,{className:`hq-mono`,children:e.ruleId}),(0,f.jsx)(`span`,{className:`hq-text-muted`,children:e.message}),(0,f.jsx)(`span`,{className:`hq-mono hq-ml-auto hq-text-dim`,children:new Date(e.lastFiredAt).toLocaleTimeString()})]},e.id))})]})]})]})}function m({icon:e,tone:t,label:n,value:r,detail:i,action:a,view:o}){return(0,f.jsxs)(`article`,{className:`hq-attention-card`,"data-tone":t,children:[(0,f.jsx)(`span`,{className:`hq-attention-icon`,children:(0,f.jsx)(e,{size:17})}),(0,f.jsxs)(`div`,{children:[(0,f.jsx)(`span`,{children:n}),(0,f.jsx)(`strong`,{children:r}),(0,f.jsx)(`small`,{children:i})]}),o===void 0?(0,f.jsx)(`span`,{className:`hq-attention-action-label`,children:a}):(0,f.jsx)(`button`,{type:`button`,onClick:()=>u.getState().setActiveView(o),children:a})]})}function h({label:e,value:t,tone:n}){return(0,f.jsxs)(`div`,{className:`hq-hero-metric`,"data-tone":n,children:[(0,f.jsx)(`strong`,{children:t}),(0,f.jsx)(`span`,{children:e})]})}export{p as AlertsView};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{At as t,Ft as n,Wt as r,Zt as i,at as a,c as o,jt as s,t as c}from"./icons-C4ljWs50.js";import{i as l}from"./markdown--Y3iks7c.js";import{t as u}from"./use-backfilled-events-
|
|
1
|
+
import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{At as t,Ft as n,Wt as r,Zt as i,at as a,c as o,jt as s,t as c}from"./icons-C4ljWs50.js";import{i as l}from"./markdown--Y3iks7c.js";import{t as u}from"./use-backfilled-events-B4G6jrJe.js";var d=e(i(),1),f=l(),p={decision_requested:{label:`Requested`,Icon:s,cls:`info`},decision_answered:{label:`Answered`,Icon:n,cls:`active`},decision_ask_human:{label:`Ask Human`,Icon:a,cls:`warn`},decision_denied:{label:`Denied`,Icon:t,cls:`error`},human_answered:{label:`Human`,Icon:o,cls:`info`},intervention:{label:`Intervention`,Icon:c,cls:`warn`}};function m(){let{events:e,loading:t}=u(`brain.event`,200),n=e.slice(-200).reverse(),i=(0,d.useMemo)(()=>{let e=0,t=0,r=0,i=0,a=0;for(let o of n){let n=o.payload;n.kind===`decision_requested`&&(e+=1),n.kind===`decision_answered`&&(t+=1),(n.kind===`decision_ask_human`||n.kind===`human_answered`)&&(r+=1),n.kind===`intervention`&&(i+=1),(n.risk===`high`||n.risk===`critical`)&&(a+=1)}return{requested:e,answered:t,human:r,interventions:i,highRisk:a}},[n]);return n.length===0?(0,f.jsx)(`div`,{className:`hq-empty hq-empty-ornate`,children:t?`Loading brain history…`:`No brain decisions yet. Brain events appear when autonomous consumers route decisions through the Brain.`}):(0,f.jsxs)(`div`,{className:`hq-screen hq-brain-screen`,children:[(0,f.jsxs)(`section`,{className:`hq-screen-hero hq-brain-hero`,"aria-label":`Brain decision summary`,children:[(0,f.jsxs)(`div`,{children:[(0,f.jsx)(`span`,{className:`hq-section-kicker`,children:`Decision ledger`}),(0,f.jsx)(`h2`,{children:`Brain arbitration timeline`}),(0,f.jsx)(`p`,{children:`Requests, answers, human escalations and interventions are shown as a governed decision trail instead of a flat event stream.`})]}),(0,f.jsxs)(`div`,{className:`hq-hero-metrics`,children:[(0,f.jsx)(h,{label:`requested`,value:i.requested}),(0,f.jsx)(h,{label:`answered`,value:i.answered,tone:`ok`}),(0,f.jsx)(h,{label:`human`,value:i.human,tone:i.human>0?`warn`:void 0}),(0,f.jsx)(h,{label:`high risk`,value:i.highRisk,tone:i.highRisk>0?`error`:`ok`})]})]}),(0,f.jsxs)(`div`,{className:`hq-section-head`,children:[(0,f.jsxs)(`div`,{children:[(0,f.jsxs)(`span`,{className:`hq-section-kicker`,children:[`Latest `,n.length]}),(0,f.jsx)(`h3`,{children:`Decision trail`})]}),i.interventions>0?(0,f.jsxs)(`span`,{className:`hq-pill warn`,children:[i.interventions,` interventions`]}):null]}),(0,f.jsx)(`div`,{className:`hq-decision-timeline`,children:n.map(e=>{let t=e.payload,n=p[t.kind]??{label:t.kind,Icon:r,cls:`info`};return(0,f.jsxs)(`article`,{className:`hq-card hq-decision-card ${n.cls}`,children:[(0,f.jsx)(`div`,{className:`hq-decision-marker`,"aria-hidden":`true`,children:(0,f.jsx)(n.Icon,{size:15,className:`hq-kind-icon ${n.cls}`})}),(0,f.jsxs)(`div`,{className:`hq-decision-body`,children:[(0,f.jsxs)(`div`,{className:`hq-row`,children:[(0,f.jsx)(`span`,{className:`hq-text-bright`,children:n.label}),t.source!==void 0&&(0,f.jsx)(`span`,{className:`hq-pill info`,children:t.source}),t.risk!==void 0&&(0,f.jsxs)(`span`,{className:`hq-pill ${t.risk===`high`||t.risk===`critical`?`error`:`warn`}`,children:[t.risk,` risk`]}),(0,f.jsx)(`span`,{className:`hq-mono hq-row-time`,children:new Date(t.at).toLocaleTimeString()})]}),t.question!==void 0&&(0,f.jsx)(`div`,{className:`hq-mono hq-row-detail`,children:t.question}),t.decision!==void 0&&(0,f.jsx)(`div`,{className:`hq-row hq-row-detail`,children:(0,f.jsxs)(`span`,{className:`hq-pill active`,children:[`→ `,t.decision]})}),t.detail!==void 0&&(0,f.jsx)(`div`,{className:`hq-mono hq-row-subtle`,children:t.detail}),t.kind===`intervention`&&(0,f.jsxs)(`div`,{className:`hq-row hq-row-detail`,children:[(0,f.jsx)(`span`,{className:`hq-pill warn`,children:t.interventionKind}),(0,f.jsx)(`span`,{className:`hq-pill`,children:t.intervened?`steered`:`observed`})]})]})]},e.id)})})]})}function h({label:e,value:t,tone:n}){return(0,f.jsxs)(`div`,{className:`hq-hero-metric`,"data-tone":n,children:[(0,f.jsx)(`strong`,{children:t}),(0,f.jsx)(`span`,{children:e})]})}export{m as BrainView};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{D as t,Jt as n,Kt as r,P as i,Pt as a,Xt as o,Zt as s,dt as ee,h as te,qt as c,wt as ne,y as re}from"./icons-C4ljWs50.js";import{i as l}from"./markdown--Y3iks7c.js";import{c as ie,p as ae,s as u,u as d}from"./index-BlKmioWF.js";var f=e(s(),1),p=l();function m(){let{snapshot:e,alerts:n,selectedClientId:s,connected:l}=d(ae(e=>({snapshot:e.snapshot,alerts:e.alerts,selectedClientId:e.selectedClientId,connected:e.connected}))),m=e,b=m?.totals,x=m?.machines??[],S=m?.projects??[],C=m?.clients??[],w=m?.liveSessions??[],T=S.filter(e=>e.governance!==void 0),E=T.filter(e=>e.governance?.signal.level===`warning`||e.governance?.signal.level===`unavailable`),D=C.filter(e=>e.capabilities.includes(`control.receive`)),O=s??D[0]?.clientId??null,k=D.find(e=>e.clientId===O)??D[0]??null,[A,j]=(0,f.useState)([]),[M,ce]=(0,f.useState)([]),[N,P]=(0,f.useState)(null),[F,I]=(0,f.useState)(null),[L,R]=(0,f.useState)(null),[z,B]=(0,f.useState)(null),[V,H]=(0,f.useState)(null),[U,W]=(0,f.useState)(null);(0,f.useEffect)(()=>{let e=!1,t=()=>{u(`/api/system/health`).then(t=>{e||(H(t),W(null))}).catch(t=>{e||W(t instanceof Error?t.message:String(t))})};t();let n=setInterval(t,3e4);return()=>{e=!0,clearInterval(n)}},[]),(0,f.useEffect)(()=>{let e=!1,t=()=>{u(`/api/alerts`).then(t=>{e||(j(t.active),ce(t.history),P(null))}).catch(t=>{e||P(t instanceof Error?t.message:String(t))})};t();let n=setInterval(t,15e3);return()=>{e=!0,clearInterval(n)}},[]);let G=(0,f.useMemo)(()=>{let e=n.slice(-30).reverse().map(e=>({severity:typeof e.severity==`string`?e.severity:`info`,ruleId:e.type??`hq.alert`,message:typeof e.message==`string`?e.message:`Alert envelope received`,timestamp:typeof e.timestamp==`string`?e.timestamp:new Date().toISOString()})),t=[...A??[],...M??[]].slice(-30).reverse().map(e=>({severity:typeof e.severity==`string`?e.severity:`info`,ruleId:typeof e.ruleId==`string`?e.ruleId:`alert`,message:typeof e.message==`string`?e.message:``,timestamp:typeof e.lastFiredAt==`string`?e.lastFiredAt:typeof e.firstFiredAt==`string`?e.firstFiredAt:new Date().toISOString()})),r=[...e,...t],i=new Set,a=[];for(let e of r){let t=`${e.ruleId}|${e.message}|${e.timestamp}`;if(!i.has(t)&&(i.add(t),a.push(e),a.length>=12))break}return a},[n,A,M]),K=(0,f.useMemo)(()=>{let e=0,t=0,n=0,r=0,i=0;for(let a of w){a.status===`active`&&(i+=1);for(let i of a.agents??[])e+=1,i.status===`running`||i.status===`streaming`?t+=1:i.status===`waiting_user`?n+=1:i.status===`error`&&(r+=1)}return{total:e,busy:t,waiting:n,errored:r,activeSessions:i}},[w]),q=(0,f.useMemo)(()=>[...S].sort((e,t)=>t.totalCostUsd-e.totalCostUsd).slice(0,4),[S]);async function J(e){if(k!==null){I(e),R(null),B(null);try{let t=e===`pause-noisy`?{subject:`HQ quick action: pause noisy agents`,body:`HQ operator requests: pause non-critical/noisy agent work, reduce chatter, and keep only essential status updates until resumed.`,priority:`high`}:{subject:`HQ quick action: status request`,body:`HQ operator requests a concise status broadcast from active agents: current task, blocker if any, and next expected action.`,priority:`normal`},n=await ie(k.clientId,`broadcast`,t);R(`queued ${n.commandId}`)}catch(e){B(e instanceof Error?e.message:String(e))}finally{I(null)}}}let Y=m?.fleets??[],X=(0,f.useMemo)(()=>{let e=0,t=0,n=0,r=0,i=0;for(let a of Y)typeof a.usedSpawns==`number`&&typeof a.maxSpawns==`number`&&(r+=1,e+=a.usedSpawns,Number.isFinite(a.maxSpawns)&&(t+=a.maxSpawns),typeof a.remainingSpawns==`number`&&Number.isFinite(a.remainingSpawns)&&(n+=a.remainingSpawns),a.ceilingMismatch&&(i+=1));return r>0?{used:e,max:t,remaining:n,known:r,mismatch:i}:null},[Y]),le=[{title:`Fleet`,view:`fleet`,cta:`open fleet`,icon:i,wide:!0,body:(0,p.jsxs)(`div`,{className:`hq-cockpit-grid`,children:[(0,p.jsx)(_,{label:`machines`,value:x.length}),(0,p.jsx)(_,{label:`clients`,value:C.length}),(0,p.jsx)(_,{label:`sessions`,value:K.activeSessions,accent:K.activeSessions>0?`green`:void 0}),(0,p.jsx)(_,{label:`agents`,value:K.total}),(0,p.jsx)(_,{label:`busy`,value:K.busy,accent:K.busy>0?`green`:void 0}),(0,p.jsx)(_,{label:`waiting`,value:K.waiting,accent:K.waiting>0?`warn`:void 0}),(0,p.jsx)(_,{label:`errored`,value:K.errored,accent:K.errored>0?`error`:void 0}),(0,p.jsx)(_,{label:`cost $`,value:(b?.totalCostUsd??0).toFixed(2),accent:`green`}),X&&(0,p.jsx)(_,{label:`spawns`,value:`${X.used}/${Number.isFinite(X.max)?X.max:`∞`}`,accent:X.mismatch>0?`warn`:void 0}),X&&(0,p.jsx)(_,{label:`spawns left`,value:Number.isFinite(X.remaining)?X.remaining:`∞`,accent:X.remaining===0?`error`:void 0})]})}],ue={title:`Auth Tokens`,view:`settings`,cta:`open settings`,icon:te,body:(0,p.jsx)(oe,{tokenStats:b?.tokenStats})},de={title:`Governance Advisory`,view:`fleet`,cta:`open fleet`,icon:ee,tone:E.length>0?`attention`:`positive`,body:T.length===0?(0,p.jsx)(`div`,{className:`hq-empty hq-cockpit-empty`,children:`No project governance snapshots yet.`}):(0,p.jsx)(`div`,{className:`hq-cockpit-alert-list`,children:T.map(e=>{let t=e.governance;return t===void 0?null:(0,p.jsxs)(`div`,{className:`hq-cockpit-alert-row`,children:[(0,p.jsx)(`span`,{className:`hq-pill ${t.signal.level===`healthy`?`green`:t.signal.level===`notice`?`warn`:`error`}`,children:t.signal.level}),(0,p.jsx)(`span`,{children:e.projectName}),(0,p.jsx)(`span`,{className:`hq-mono hq-cockpit-alert-msg`,children:t.signal.code}),(0,p.jsx)(`span`,{className:`hq-mono hq-text-dim hq-ml-auto`,children:t.signal.executionDisposition})]},e.projectId)})})},Z={title:`Alerts`,view:`alerts`,cta:`open alerts`,icon:c,tone:G.length>0?`attention`:`positive`,wide:!0,body:G.length===0?(0,p.jsx)(`div`,{className:`hq-empty hq-cockpit-empty`,children:`No alerts in the last few minutes.`}):(0,p.jsx)(`div`,{className:`hq-cockpit-alert-list`,children:G.map((e,t)=>(0,p.jsxs)(`div`,{className:`hq-cockpit-alert-row`,children:[(0,p.jsx)(`span`,{className:`hq-pill `+y(e.severity),children:e.severity}),(0,p.jsx)(`span`,{className:`hq-mono`,children:e.ruleId}),(0,p.jsx)(`span`,{className:`hq-cockpit-alert-msg`,children:e.message}),(0,p.jsx)(`span`,{className:`hq-mono hq-text-dim hq-ml-auto`,children:v(e.timestamp)})]},`${e.ruleId}-${e.timestamp}-${t}`))})},fe={title:`Cost`,view:`cost`,cta:`open cost`,icon:a,wide:!0,body:q.length===0?(0,p.jsx)(`div`,{className:`hq-empty hq-cockpit-empty`,children:`No cost data yet — connect some clients.`}):(0,p.jsx)(`div`,{className:`hq-cockpit-cost-list`,children:q.map(e=>{let t=(b?.totalCostUsd??0)>0?e.totalCostUsd/b.totalCostUsd*100:0;return(0,p.jsxs)(`div`,{className:`hq-cockpit-cost-row`,children:[(0,p.jsxs)(`div`,{className:`hq-cockpit-cost-line`,children:[(0,p.jsx)(`span`,{className:`hq-cockpit-cost-name`,children:e.projectName}),(0,p.jsx)(`span`,{className:`hq-mono hq-text-dim`,children:e.projectId}),(0,p.jsxs)(`span`,{className:`hq-mono hq-cockpit-cost-amount hq-ml-auto`,children:[`$`,e.totalCostUsd.toFixed(4)]}),(0,p.jsxs)(`span`,{className:`hq-mono hq-text-dim`,children:[t.toFixed(1),`%`]})]}),(0,p.jsx)(`div`,{className:`hq-cockpit-cost-bar`,role:`progressbar`,"aria-label":`${e.projectName} share of fleet cost`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Number(t.toFixed(1)),children:(0,p.jsx)(`span`,{style:{width:`${Math.max(2,t)}%`}})}),(0,p.jsxs)(`div`,{className:`hq-cockpit-cost-meta`,children:[(0,p.jsxs)(`span`,{children:[e.activeSessions,` sessions`]}),(0,p.jsxs)(`span`,{children:[e.activeSubagents,` subagents`]}),(0,p.jsxs)(`span`,{children:[e.activeClients,` clients`]})]})]},e.projectId)})})},Q=(A?.length??0)+E.length,$=!l||V?.status===`degraded`?`degraded`:Q>0?`attention`:`nominal`;return(0,p.jsxs)(`div`,{className:`hq-cockpit-screen`,children:[(0,p.jsxs)(`section`,{className:`hq-cockpit-hero`,"data-tone":$,children:[(0,p.jsxs)(`div`,{className:`hq-cockpit-hero-copy`,children:[(0,p.jsxs)(`div`,{className:`hq-cockpit-kicker`,children:[(0,p.jsx)(`span`,{className:`hq-cockpit-pulse`,"aria-hidden":`true`}),$===`degraded`?`Link degraded`:$===`attention`?`Attention needed`:`Systems nominal`]}),(0,p.jsx)(`h2`,{children:`Operational picture`}),(0,p.jsx)(`p`,{children:`Live fleet health, agent activity, governance and spend — resolved into one command surface.`}),(0,p.jsxs)(`div`,{className:`hq-cockpit-hero-meta`,children:[(0,p.jsx)(`span`,{children:m?.generatedAt?`Snapshot ${v(m.generatedAt)}`:`Awaiting first snapshot`}),(0,p.jsxs)(`span`,{children:[D.length,` command-ready clients`]})]}),(0,p.jsxs)(`div`,{className:`hq-cockpit-signals`,role:`status`,"aria-label":`Operational signals`,children:[(A?.length??0)>0&&(0,p.jsxs)(`span`,{className:`hq-pill error`,children:[A?.length??0,` active alerts`]}),E.length>0&&(0,p.jsxs)(`span`,{className:`hq-pill error`,children:[E.length,` governance advisories`]}),N!==null&&(0,p.jsx)(`span`,{className:`hq-pill error`,children:N})]})]}),(0,p.jsxs)(`fieldset`,{className:`hq-cockpit-hero-metrics`,"aria-label":`Fleet headline metrics`,children:[(0,p.jsx)(g,{icon:r,label:`Active agents`,value:b?.activeAgents??0,detail:`${K.busy} working`}),(0,p.jsx)(g,{icon:o,label:`Live sessions`,value:b?.activeSessions??0,detail:`${x.length} machines`}),(0,p.jsx)(g,{icon:c,label:`Attention`,value:Q,detail:Q>0?`review signals`:`all clear`,tone:Q>0?`attention`:`positive`}),(0,p.jsx)(g,{icon:a,label:`Total cost`,value:`$${(b?.totalCostUsd??0).toFixed(2)}`,detail:`${S.length} projects`,tone:`positive`})]})]}),(0,p.jsxs)(`section`,{className:`hq-cockpit-command-bar`,"aria-label":`Cockpit quick actions`,children:[(0,p.jsxs)(`div`,{className:`hq-cockpit-command-copy`,children:[(0,p.jsx)(`span`,{className:`hq-cockpit-command-icon`,children:(0,p.jsx)(ne,{size:17})}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`strong`,{children:`Command strip`}),(0,p.jsx)(`span`,{className:`hq-mono`,children:k===null?`No controllable client connected`:`Target ${se(k.clientId)}`})]})]}),(0,p.jsxs)(`div`,{className:`hq-cockpit-actions-buttons`,children:[(0,p.jsx)(`button`,{type:`button`,className:`hq-btn secondary`,disabled:k===null||F!==null,onClick:()=>void J(`pause-noisy`),children:F===`pause-noisy`?`Queuing…`:`Pause noisy agents`}),(0,p.jsx)(`button`,{type:`button`,className:`hq-btn secondary`,disabled:k===null||F!==null,onClick:()=>void J(`status-request`),children:F===`status-request`?`Queuing…`:`Request fleet status`}),(0,p.jsxs)(`button`,{type:`button`,className:`hq-btn hq-cockpit-primary-action`,onClick:()=>d.getState().setActiveView(`control`),children:[(0,p.jsx)(t,{size:13}),` Open control`]})]}),L!==null&&(0,p.jsx)(`span`,{className:`hq-pill info`,children:L}),z!==null&&(0,p.jsx)(`span`,{className:`hq-pill error`,children:z})]}),(0,p.jsxs)(`div`,{className:`hq-cockpit-section-label`,children:[(0,p.jsx)(`span`,{children:`Live intelligence`}),(0,p.jsx)(`span`,{children:N===null?`${S.length} projects in scope`:N})]}),(0,p.jsxs)(`div`,{className:`hq-cockpit-bento`,children:[(V!==null||U!==null)&&(0,p.jsxs)(`div`,{className:`hq-card hq-cockpit-section`,"data-tone":V?.status===`degraded`?`attention`:`positive`,children:[(0,p.jsx)(h,{icon:re,title:`System Health`,cta:`open settings`,onClick:()=>d.getState().setActiveView(`settings`)}),U===null?V===null?null:(0,p.jsxs)(`div`,{className:`hq-cockpit-grid`,children:[(0,p.jsx)(_,{label:`status`,value:V.status,accent:V.status===`healthy`?`green`:`error`}),(0,p.jsx)(_,{label:`event log`,value:V.uptime.eventLogSize}),(0,p.jsx)(_,{label:`connections`,value:V.connections.total}),(0,p.jsx)(_,{label:`active`,value:V.connections.active,accent:V.connections.active>0?`green`:void 0}),(0,p.jsx)(_,{label:`stale`,value:V.connections.stale,accent:V.connections.stale>3?`warn`:void 0})]}):(0,p.jsx)(`div`,{className:`hq-empty hq-cockpit-empty`,children:U})]}),[...le,de,ue,Z,fe].map(e=>(0,p.jsxs)(`div`,{className:`hq-card hq-cockpit-section`,"data-tone":e.tone,"data-wide":e.wide,children:[(0,p.jsx)(h,{icon:e.icon,title:e.title,cta:e.cta,onClick:()=>d.getState().setActiveView(e.view)}),e.body]},e.title))]})]})}function h({icon:e,title:t,cta:r,onClick:i}){return(0,p.jsxs)(`div`,{className:`hq-cockpit-card-head`,children:[(0,p.jsx)(`span`,{className:`hq-cockpit-card-icon`,children:(0,p.jsx)(e,{size:15})}),(0,p.jsx)(`span`,{className:`hq-cockpit-section-title`,children:t}),(0,p.jsxs)(`button`,{type:`button`,className:`hq-cockpit-card-link`,onClick:i,children:[r,(0,p.jsx)(n,{size:13})]})]})}function g({icon:e,label:t,value:n,detail:r,tone:i}){return(0,p.jsxs)(`div`,{className:`hq-cockpit-hero-metric`,"data-tone":i,children:[(0,p.jsx)(e,{size:15}),(0,p.jsx)(`span`,{children:t}),(0,p.jsx)(`strong`,{children:n}),(0,p.jsx)(`small`,{children:r})]})}function _({label:e,value:t,accent:n}){return(0,p.jsxs)(`div`,{className:`hq-stat`+(n?` ${n}`:``),children:[(0,p.jsx)(`span`,{className:`hq-stat-num`,children:t}),(0,p.jsx)(`span`,{className:`hq-stat-label`,children:e})]})}function oe({tokenStats:e}){if(e===void 0)return(0,p.jsx)(`div`,{className:`hq-empty hq-cockpit-empty`,children:`Token expiry stats unavailable on this HQ version.`});let{browserTotal:t,clientTotal:n,expired:r,expiringSoon:i}=e,a=t+n;return(0,p.jsxs)(`fieldset`,{className:`hq-cockpit-grid`,"aria-label":`Auth token stats`,style:{border:0,margin:0,padding:0},children:[(0,p.jsx)(_,{label:`browser`,value:t}),(0,p.jsx)(_,{label:`client`,value:n}),(0,p.jsx)(_,{label:`total`,value:a}),(0,p.jsx)(_,{label:`expired`,value:r,accent:r>0?`error`:void 0}),(0,p.jsx)(_,{label:`expiring soon`,value:i,accent:i>0?`warn`:void 0})]})}function se(e){return e.length<=18?e:`${e.slice(0,9)}…${e.slice(-6)}`}function v(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleTimeString()}function y(e){return e===`critical`||e===`error`||e===`high`?`error`:e===`warn`||e===`warning`||e===`medium`?`warn`:e===`info`||e===`low`?`info`:`idle`}export{m as CockpitView};
|
|
1
|
+
import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{D as t,Jt as n,Kt as r,P as i,Pt as a,Xt as o,Zt as s,dt as ee,h as te,qt as c,wt as ne,y as re}from"./icons-C4ljWs50.js";import{i as l}from"./markdown--Y3iks7c.js";import{c as ie,p as ae,s as u,u as d}from"./index-Ch5wZYYG.js";var f=e(s(),1),p=l();function m(){let{snapshot:e,alerts:n,selectedClientId:s,connected:l}=d(ae(e=>({snapshot:e.snapshot,alerts:e.alerts,selectedClientId:e.selectedClientId,connected:e.connected}))),m=e,b=m?.totals,x=m?.machines??[],S=m?.projects??[],C=m?.clients??[],w=m?.liveSessions??[],T=S.filter(e=>e.governance!==void 0),E=T.filter(e=>e.governance?.signal.level===`warning`||e.governance?.signal.level===`unavailable`),D=C.filter(e=>e.capabilities.includes(`control.receive`)),O=s??D[0]?.clientId??null,k=D.find(e=>e.clientId===O)??D[0]??null,[A,j]=(0,f.useState)([]),[M,ce]=(0,f.useState)([]),[N,P]=(0,f.useState)(null),[F,I]=(0,f.useState)(null),[L,R]=(0,f.useState)(null),[z,B]=(0,f.useState)(null),[V,H]=(0,f.useState)(null),[U,W]=(0,f.useState)(null);(0,f.useEffect)(()=>{let e=!1,t=()=>{u(`/api/system/health`).then(t=>{e||(H(t),W(null))}).catch(t=>{e||W(t instanceof Error?t.message:String(t))})};t();let n=setInterval(t,3e4);return()=>{e=!0,clearInterval(n)}},[]),(0,f.useEffect)(()=>{let e=!1,t=()=>{u(`/api/alerts`).then(t=>{e||(j(t.active),ce(t.history),P(null))}).catch(t=>{e||P(t instanceof Error?t.message:String(t))})};t();let n=setInterval(t,15e3);return()=>{e=!0,clearInterval(n)}},[]);let G=(0,f.useMemo)(()=>{let e=n.slice(-30).reverse().map(e=>({severity:typeof e.severity==`string`?e.severity:`info`,ruleId:e.type??`hq.alert`,message:typeof e.message==`string`?e.message:`Alert envelope received`,timestamp:typeof e.timestamp==`string`?e.timestamp:new Date().toISOString()})),t=[...A??[],...M??[]].slice(-30).reverse().map(e=>({severity:typeof e.severity==`string`?e.severity:`info`,ruleId:typeof e.ruleId==`string`?e.ruleId:`alert`,message:typeof e.message==`string`?e.message:``,timestamp:typeof e.lastFiredAt==`string`?e.lastFiredAt:typeof e.firstFiredAt==`string`?e.firstFiredAt:new Date().toISOString()})),r=[...e,...t],i=new Set,a=[];for(let e of r){let t=`${e.ruleId}|${e.message}|${e.timestamp}`;if(!i.has(t)&&(i.add(t),a.push(e),a.length>=12))break}return a},[n,A,M]),K=(0,f.useMemo)(()=>{let e=0,t=0,n=0,r=0,i=0;for(let a of w){a.status===`active`&&(i+=1);for(let i of a.agents??[])e+=1,i.status===`running`||i.status===`streaming`?t+=1:i.status===`waiting_user`?n+=1:i.status===`error`&&(r+=1)}return{total:e,busy:t,waiting:n,errored:r,activeSessions:i}},[w]),q=(0,f.useMemo)(()=>[...S].sort((e,t)=>t.totalCostUsd-e.totalCostUsd).slice(0,4),[S]);async function J(e){if(k!==null){I(e),R(null),B(null);try{let t=e===`pause-noisy`?{subject:`HQ quick action: pause noisy agents`,body:`HQ operator requests: pause non-critical/noisy agent work, reduce chatter, and keep only essential status updates until resumed.`,priority:`high`}:{subject:`HQ quick action: status request`,body:`HQ operator requests a concise status broadcast from active agents: current task, blocker if any, and next expected action.`,priority:`normal`},n=await ie(k.clientId,`broadcast`,t);R(`queued ${n.commandId}`)}catch(e){B(e instanceof Error?e.message:String(e))}finally{I(null)}}}let Y=m?.fleets??[],X=(0,f.useMemo)(()=>{let e=0,t=0,n=0,r=0,i=0;for(let a of Y)typeof a.usedSpawns==`number`&&typeof a.maxSpawns==`number`&&(r+=1,e+=a.usedSpawns,Number.isFinite(a.maxSpawns)&&(t+=a.maxSpawns),typeof a.remainingSpawns==`number`&&Number.isFinite(a.remainingSpawns)&&(n+=a.remainingSpawns),a.ceilingMismatch&&(i+=1));return r>0?{used:e,max:t,remaining:n,known:r,mismatch:i}:null},[Y]),le=[{title:`Fleet`,view:`fleet`,cta:`open fleet`,icon:i,wide:!0,body:(0,p.jsxs)(`div`,{className:`hq-cockpit-grid`,children:[(0,p.jsx)(_,{label:`machines`,value:x.length}),(0,p.jsx)(_,{label:`clients`,value:C.length}),(0,p.jsx)(_,{label:`sessions`,value:K.activeSessions,accent:K.activeSessions>0?`green`:void 0}),(0,p.jsx)(_,{label:`agents`,value:K.total}),(0,p.jsx)(_,{label:`busy`,value:K.busy,accent:K.busy>0?`green`:void 0}),(0,p.jsx)(_,{label:`waiting`,value:K.waiting,accent:K.waiting>0?`warn`:void 0}),(0,p.jsx)(_,{label:`errored`,value:K.errored,accent:K.errored>0?`error`:void 0}),(0,p.jsx)(_,{label:`cost $`,value:(b?.totalCostUsd??0).toFixed(2),accent:`green`}),X&&(0,p.jsx)(_,{label:`spawns`,value:`${X.used}/${Number.isFinite(X.max)?X.max:`∞`}`,accent:X.mismatch>0?`warn`:void 0}),X&&(0,p.jsx)(_,{label:`spawns left`,value:Number.isFinite(X.remaining)?X.remaining:`∞`,accent:X.remaining===0?`error`:void 0})]})}],ue={title:`Auth Tokens`,view:`settings`,cta:`open settings`,icon:te,body:(0,p.jsx)(oe,{tokenStats:b?.tokenStats})},de={title:`Governance Advisory`,view:`fleet`,cta:`open fleet`,icon:ee,tone:E.length>0?`attention`:`positive`,body:T.length===0?(0,p.jsx)(`div`,{className:`hq-empty hq-cockpit-empty`,children:`No project governance snapshots yet.`}):(0,p.jsx)(`div`,{className:`hq-cockpit-alert-list`,children:T.map(e=>{let t=e.governance;return t===void 0?null:(0,p.jsxs)(`div`,{className:`hq-cockpit-alert-row`,children:[(0,p.jsx)(`span`,{className:`hq-pill ${t.signal.level===`healthy`?`green`:t.signal.level===`notice`?`warn`:`error`}`,children:t.signal.level}),(0,p.jsx)(`span`,{children:e.projectName}),(0,p.jsx)(`span`,{className:`hq-mono hq-cockpit-alert-msg`,children:t.signal.code}),(0,p.jsx)(`span`,{className:`hq-mono hq-text-dim hq-ml-auto`,children:t.signal.executionDisposition})]},e.projectId)})})},Z={title:`Alerts`,view:`alerts`,cta:`open alerts`,icon:c,tone:G.length>0?`attention`:`positive`,wide:!0,body:G.length===0?(0,p.jsx)(`div`,{className:`hq-empty hq-cockpit-empty`,children:`No alerts in the last few minutes.`}):(0,p.jsx)(`div`,{className:`hq-cockpit-alert-list`,children:G.map((e,t)=>(0,p.jsxs)(`div`,{className:`hq-cockpit-alert-row`,children:[(0,p.jsx)(`span`,{className:`hq-pill `+y(e.severity),children:e.severity}),(0,p.jsx)(`span`,{className:`hq-mono`,children:e.ruleId}),(0,p.jsx)(`span`,{className:`hq-cockpit-alert-msg`,children:e.message}),(0,p.jsx)(`span`,{className:`hq-mono hq-text-dim hq-ml-auto`,children:v(e.timestamp)})]},`${e.ruleId}-${e.timestamp}-${t}`))})},fe={title:`Cost`,view:`cost`,cta:`open cost`,icon:a,wide:!0,body:q.length===0?(0,p.jsx)(`div`,{className:`hq-empty hq-cockpit-empty`,children:`No cost data yet — connect some clients.`}):(0,p.jsx)(`div`,{className:`hq-cockpit-cost-list`,children:q.map(e=>{let t=(b?.totalCostUsd??0)>0?e.totalCostUsd/b.totalCostUsd*100:0;return(0,p.jsxs)(`div`,{className:`hq-cockpit-cost-row`,children:[(0,p.jsxs)(`div`,{className:`hq-cockpit-cost-line`,children:[(0,p.jsx)(`span`,{className:`hq-cockpit-cost-name`,children:e.projectName}),(0,p.jsx)(`span`,{className:`hq-mono hq-text-dim`,children:e.projectId}),(0,p.jsxs)(`span`,{className:`hq-mono hq-cockpit-cost-amount hq-ml-auto`,children:[`$`,e.totalCostUsd.toFixed(4)]}),(0,p.jsxs)(`span`,{className:`hq-mono hq-text-dim`,children:[t.toFixed(1),`%`]})]}),(0,p.jsx)(`div`,{className:`hq-cockpit-cost-bar`,role:`progressbar`,"aria-label":`${e.projectName} share of fleet cost`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Number(t.toFixed(1)),children:(0,p.jsx)(`span`,{style:{width:`${Math.max(2,t)}%`}})}),(0,p.jsxs)(`div`,{className:`hq-cockpit-cost-meta`,children:[(0,p.jsxs)(`span`,{children:[e.activeSessions,` sessions`]}),(0,p.jsxs)(`span`,{children:[e.activeSubagents,` subagents`]}),(0,p.jsxs)(`span`,{children:[e.activeClients,` clients`]})]})]},e.projectId)})})},Q=(A?.length??0)+E.length,$=!l||V?.status===`degraded`?`degraded`:Q>0?`attention`:`nominal`;return(0,p.jsxs)(`div`,{className:`hq-cockpit-screen`,children:[(0,p.jsxs)(`section`,{className:`hq-cockpit-hero`,"data-tone":$,children:[(0,p.jsxs)(`div`,{className:`hq-cockpit-hero-copy`,children:[(0,p.jsxs)(`div`,{className:`hq-cockpit-kicker`,children:[(0,p.jsx)(`span`,{className:`hq-cockpit-pulse`,"aria-hidden":`true`}),$===`degraded`?`Link degraded`:$===`attention`?`Attention needed`:`Systems nominal`]}),(0,p.jsx)(`h2`,{children:`Operational picture`}),(0,p.jsx)(`p`,{children:`Live fleet health, agent activity, governance and spend — resolved into one command surface.`}),(0,p.jsxs)(`div`,{className:`hq-cockpit-hero-meta`,children:[(0,p.jsx)(`span`,{children:m?.generatedAt?`Snapshot ${v(m.generatedAt)}`:`Awaiting first snapshot`}),(0,p.jsxs)(`span`,{children:[D.length,` command-ready clients`]})]}),(0,p.jsxs)(`div`,{className:`hq-cockpit-signals`,role:`status`,"aria-label":`Operational signals`,children:[(A?.length??0)>0&&(0,p.jsxs)(`span`,{className:`hq-pill error`,children:[A?.length??0,` active alerts`]}),E.length>0&&(0,p.jsxs)(`span`,{className:`hq-pill error`,children:[E.length,` governance advisories`]}),N!==null&&(0,p.jsx)(`span`,{className:`hq-pill error`,children:N})]})]}),(0,p.jsxs)(`fieldset`,{className:`hq-cockpit-hero-metrics`,"aria-label":`Fleet headline metrics`,children:[(0,p.jsx)(g,{icon:r,label:`Active agents`,value:b?.activeAgents??0,detail:`${K.busy} working`}),(0,p.jsx)(g,{icon:o,label:`Live sessions`,value:b?.activeSessions??0,detail:`${x.length} machines`}),(0,p.jsx)(g,{icon:c,label:`Attention`,value:Q,detail:Q>0?`review signals`:`all clear`,tone:Q>0?`attention`:`positive`}),(0,p.jsx)(g,{icon:a,label:`Total cost`,value:`$${(b?.totalCostUsd??0).toFixed(2)}`,detail:`${S.length} projects`,tone:`positive`})]})]}),(0,p.jsxs)(`section`,{className:`hq-cockpit-command-bar`,"aria-label":`Cockpit quick actions`,children:[(0,p.jsxs)(`div`,{className:`hq-cockpit-command-copy`,children:[(0,p.jsx)(`span`,{className:`hq-cockpit-command-icon`,children:(0,p.jsx)(ne,{size:17})}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`strong`,{children:`Command strip`}),(0,p.jsx)(`span`,{className:`hq-mono`,children:k===null?`No controllable client connected`:`Target ${se(k.clientId)}`})]})]}),(0,p.jsxs)(`div`,{className:`hq-cockpit-actions-buttons`,children:[(0,p.jsx)(`button`,{type:`button`,className:`hq-btn secondary`,disabled:k===null||F!==null,onClick:()=>void J(`pause-noisy`),children:F===`pause-noisy`?`Queuing…`:`Pause noisy agents`}),(0,p.jsx)(`button`,{type:`button`,className:`hq-btn secondary`,disabled:k===null||F!==null,onClick:()=>void J(`status-request`),children:F===`status-request`?`Queuing…`:`Request fleet status`}),(0,p.jsxs)(`button`,{type:`button`,className:`hq-btn hq-cockpit-primary-action`,onClick:()=>d.getState().setActiveView(`control`),children:[(0,p.jsx)(t,{size:13}),` Open control`]})]}),L!==null&&(0,p.jsx)(`span`,{className:`hq-pill info`,children:L}),z!==null&&(0,p.jsx)(`span`,{className:`hq-pill error`,children:z})]}),(0,p.jsxs)(`div`,{className:`hq-cockpit-section-label`,children:[(0,p.jsx)(`span`,{children:`Live intelligence`}),(0,p.jsx)(`span`,{children:N===null?`${S.length} projects in scope`:N})]}),(0,p.jsxs)(`div`,{className:`hq-cockpit-bento`,children:[(V!==null||U!==null)&&(0,p.jsxs)(`div`,{className:`hq-card hq-cockpit-section`,"data-tone":V?.status===`degraded`?`attention`:`positive`,children:[(0,p.jsx)(h,{icon:re,title:`System Health`,cta:`open settings`,onClick:()=>d.getState().setActiveView(`settings`)}),U===null?V===null?null:(0,p.jsxs)(`div`,{className:`hq-cockpit-grid`,children:[(0,p.jsx)(_,{label:`status`,value:V.status,accent:V.status===`healthy`?`green`:`error`}),(0,p.jsx)(_,{label:`event log`,value:V.uptime.eventLogSize}),(0,p.jsx)(_,{label:`connections`,value:V.connections.total}),(0,p.jsx)(_,{label:`active`,value:V.connections.active,accent:V.connections.active>0?`green`:void 0}),(0,p.jsx)(_,{label:`stale`,value:V.connections.stale,accent:V.connections.stale>3?`warn`:void 0})]}):(0,p.jsx)(`div`,{className:`hq-empty hq-cockpit-empty`,children:U})]}),[...le,de,ue,Z,fe].map(e=>(0,p.jsxs)(`div`,{className:`hq-card hq-cockpit-section`,"data-tone":e.tone,"data-wide":e.wide,children:[(0,p.jsx)(h,{icon:e.icon,title:e.title,cta:e.cta,onClick:()=>d.getState().setActiveView(e.view)}),e.body]},e.title))]})]})}function h({icon:e,title:t,cta:r,onClick:i}){return(0,p.jsxs)(`div`,{className:`hq-cockpit-card-head`,children:[(0,p.jsx)(`span`,{className:`hq-cockpit-card-icon`,children:(0,p.jsx)(e,{size:15})}),(0,p.jsx)(`span`,{className:`hq-cockpit-section-title`,children:t}),(0,p.jsxs)(`button`,{type:`button`,className:`hq-cockpit-card-link`,onClick:i,children:[r,(0,p.jsx)(n,{size:13})]})]})}function g({icon:e,label:t,value:n,detail:r,tone:i}){return(0,p.jsxs)(`div`,{className:`hq-cockpit-hero-metric`,"data-tone":i,children:[(0,p.jsx)(e,{size:15}),(0,p.jsx)(`span`,{children:t}),(0,p.jsx)(`strong`,{children:n}),(0,p.jsx)(`small`,{children:r})]})}function _({label:e,value:t,accent:n}){return(0,p.jsxs)(`div`,{className:`hq-stat`+(n?` ${n}`:``),children:[(0,p.jsx)(`span`,{className:`hq-stat-num`,children:t}),(0,p.jsx)(`span`,{className:`hq-stat-label`,children:e})]})}function oe({tokenStats:e}){if(e===void 0)return(0,p.jsx)(`div`,{className:`hq-empty hq-cockpit-empty`,children:`Token expiry stats unavailable on this HQ version.`});let{browserTotal:t,clientTotal:n,expired:r,expiringSoon:i}=e,a=t+n;return(0,p.jsxs)(`fieldset`,{className:`hq-cockpit-grid`,"aria-label":`Auth token stats`,style:{border:0,margin:0,padding:0},children:[(0,p.jsx)(_,{label:`browser`,value:t}),(0,p.jsx)(_,{label:`client`,value:n}),(0,p.jsx)(_,{label:`total`,value:a}),(0,p.jsx)(_,{label:`expired`,value:r,accent:r>0?`error`:void 0}),(0,p.jsx)(_,{label:`expiring soon`,value:i,accent:i>0?`warn`:void 0})]})}function se(e){return e.length<=18?e:`${e.slice(0,9)}…${e.slice(-6)}`}function v(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleTimeString()}function y(e){return e===`critical`||e===`error`||e===`high`?`error`:e===`warn`||e===`warning`||e===`medium`?`warn`:e===`info`||e===`low`?`info`:`idle`}export{m as CockpitView};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{B as t,Kt as n,M as r,R as i,Zt as a,f as o,l as ee,q as s,t as c}from"./icons-C4ljWs50.js";import{i as l}from"./markdown--Y3iks7c.js";import{c as te,o as ne,p as re,r as u,s as ie,u as d}from"./index-BlKmioWF.js";var f=e(a(),1),p=l(),m={steer:{label:`steer`,icon:(0,p.jsx)(c,{size:13}),desc:`High-priority course correction — interrupts the agent at the next turn.`},btw:{label:`btw`,icon:(0,p.jsx)(i,{size:13}),desc:`Non-urgent FYI — rides alongside the run without interrupting it.`},queue:{label:`queue`,icon:(0,p.jsx)(s,{size:13}),desc:`Queue a prompt — picked up after the current run finishes.`},abort:{label:`abort`,icon:(0,p.jsx)(r,{size:13}),desc:`Stop the leader run or every subagent on the client. Destructive.`,danger:!0},spawn:{label:`spawn`,icon:(0,p.jsx)(n,{size:13}),desc:`Launch a role subagent (bug-hunter, critic, …) with an optional task.`},broadcast:{label:`broadcast`,icon:(0,p.jsx)(t,{size:13}),desc:`Mailbox message to every agent in the client’s project.`},"run-command":{label:`run-command`,icon:(0,p.jsx)(o,{size:13}),desc:`Route a shell command to the client. RCE-gated (--hq-allow-exec + control.execute).`,danger:!0}};function h(){let{snapshot:e,selectedClientId:t,commandStatuses:n}=d(re(e=>({snapshot:e.snapshot,selectedClientId:e.selectedClientId,commandStatuses:e.commandStatuses}))),r=(e?.clients??[]).filter(e=>e.capabilities.includes(`control.receive`)),i=r.some(e=>e.clientId===t)?t:r[0]?.clientId??null,a=r.find(e=>e.clientId===i)??null,s=a===null?void 0:(e?.liveSessions??[]).find(e=>e.clientId===a.clientId||e.machineId===a.machineId&&e.projectId===a.projectId&&e.pid!==void 0&&e.pid===a.pid),c=ne().control,[l,h]=(0,f.useState)(c.cmdType),[y,b]=(0,f.useState)(`compose`),[x,ce]=(0,f.useState)(c.steerTo),[S,C]=(0,f.useState)(c.steerSubject),[w,le]=(0,f.useState)(c.steerBody),[T,ue]=(0,f.useState)(c.spawnRole),[E,de]=(0,f.useState)(c.spawnTask),[D,O]=(0,f.useState)(c.abortTarget),[k,fe]=(0,f.useState)(c.broadcastSubject),[A,pe]=(0,f.useState)(c.broadcastBody),[j,me]=(0,f.useState)(``),[M,he]=(0,f.useState)(``),[N,P]=(0,f.useState)(``),[F,I]=(0,f.useState)(null),[L,R]=(0,f.useState)(null),[z,B]=(0,f.useState)(!1),[V,H]=(0,f.useState)([]),[ge,U]=(0,f.useState)(!1),[W,G]=(0,f.useState)(null),[_e,ve]=(0,f.useState)(null),K=(0,f.useMemo)(()=>be(),[l,x,S,w,T,E,D,k,A,j,M]),q=K.risk===`danger`,J=l===`run-command`?`RUN`:`ABORT`,Y=i!==null&&K.disabledReason===null&&(!q||N===J),X=K.disabledReason===null&&i!==null;function Z(){b(`compose`),P(``),R(null),I(null)}function ye(e){h(e),u({cmdType:e}),Z()}async function Q(){U(!0),G(null);try{let e=await ie(`/api/commands?limit=25`);H(e.commands.slice().reverse())}catch(e){G(e instanceof Error?e.message:String(e))}finally{U(!1)}}(0,f.useEffect)(()=>{Q();let e=setInterval(()=>{document.hidden||Q()},15e3);return()=>clearInterval(e)},[]),(0,f.useEffect)(()=>{n.length!==0&&H(e=>{let t=new Map(e.map(e=>[e.commandId,e]));for(let e of n)t.set(e.commandId,e);return[...t.values()].sort((e,t)=>t.enqueuedAt.localeCompare(e.enqueuedAt)).slice(0,25)})},[n]);async function $(){if(!(i===null||!Y)){B(!0),R(null),I(null);try{let e=await te(i,K.type,K.payload);I(`queued ${K.type} command ${e.commandId}`),ve(e.commandId),b(`compose`),P(``),Q()}catch(e){R(e instanceof Error?e.message:String(e))}finally{B(!1)}}}(0,f.useEffect)(()=>{let e=e=>{e.key!==`Enter`||!(e.ctrlKey||e.metaKey)||(e.preventDefault(),y===`compose`&&X?(b(`preview`),I(null),R(null)):y===`preview`&&Y&&!z&&$())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)});function be(){if(l===`steer`||l===`btw`||l===`queue`){let e=w.trim(),t=l===`steer`?`Send high-priority steer to`:l===`btw`?`Post a non-urgent FYI (btw) to`:`Queue a prompt for`;return{type:l,payload:{to:x||`leader`,subject:S||`HQ ${l}`,body:w,priority:l===`steer`?`high`:`normal`},disabledReason:e.length===0?`Message body is required.`:null,risk:`normal`,summary:`${t} ${x||`leader`}.`}}if(l===`run-command`){let e=j.trim();return{type:`run-command`,payload:{command:j,...M.trim()?{cwd:M.trim()}:{}},disabledReason:e.length===0?`Command is required.`:null,risk:`danger`,summary:`Route a shell command to the client (requires --hq-allow-exec + control.execute; delivered as a steer, the agent’s permission policy still applies).`}}if(l===`abort`)return{type:`abort`,payload:{target:D},disabledReason:null,risk:`danger`,summary:D===`fleet`?`Abort all subagents on the selected client.`:`Abort the selected target on the selected client.`};if(l===`spawn`){let e=E.trim();return{type:`spawn`,payload:{role:T,...e?{task:e}:{}},disabledReason:T.trim().length===0?`Role is required.`:null,risk:`normal`,summary:`Spawn a ${T} subagent${e?` with an initial task`:``}.`}}let e=A.trim();return{type:`broadcast`,payload:{subject:k||`HQ broadcast`,body:A,priority:`normal`},disabledReason:e.length===0?`Broadcast body is required.`:null,risk:`normal`,summary:`Broadcast a normal-priority mailbox message to the selected client project.`}}return r.length===0?(0,p.jsxs)(`div`,{className:`hq-control-zero`,children:[(0,p.jsx)(`span`,{className:`hq-control-zero-icon`,"aria-hidden":`true`,children:(0,p.jsx)(o,{size:26})}),(0,p.jsx)(`span`,{className:`hq-section-kicker`,children:`Command plane offline`}),(0,p.jsx)(`h2`,{children:`No command-ready clients`}),(0,p.jsxs)(`p`,{children:[`Connect a CLI, TUI or WebUI client advertising `,(0,p.jsx)(`code`,{children:`control.receive`}),` to unlock staged remote commands and their audit trail.`]}),(0,p.jsx)(`button`,{type:`button`,className:`hq-btn secondary`,onClick:()=>d.getState().setActiveView(`fleet`),children:`Inspect Fleet Map`})]}):(0,p.jsxs)(`div`,{className:`hq-screen hq-control-screen`,"data-stage":y,"data-risk":K.risk,children:[(0,p.jsxs)(`section`,{className:`hq-screen-hero hq-control-hero`,"aria-label":`Command plane summary`,children:[(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`span`,{className:`hq-section-kicker`,children:`Command plane`}),(0,p.jsx)(`h2`,{children:`Remote execution, with guardrails`}),(0,p.jsx)(`p`,{children:`Select a live client, compose the exact intent, inspect its payload and dispatch only after the risk gate is satisfied.`}),(0,p.jsxs)(`div`,{className:`hq-control-hero-state`,children:[(0,p.jsx)(`span`,{className:`hq-pill active`,children:`control channel ready`}),(0,p.jsxs)(`span`,{className:`hq-pill `+(K.risk===`danger`?`error`:`info`),children:[K.risk,` risk`]}),F===null?null:(0,p.jsx)(`span`,{className:`hq-pill active`,children:F})]})]}),(0,p.jsxs)(`div`,{className:`hq-hero-metrics`,children:[(0,p.jsx)(g,{label:`targets`,value:r.length}),(0,p.jsx)(g,{label:`live sessions`,value:e?.liveSessions?.length??0}),(0,p.jsx)(g,{label:`stage`,value:y,tone:y===`preview`?`warn`:void 0}),(0,p.jsx)(g,{label:`recent audit`,value:V.length})]})]}),(0,p.jsxs)(`div`,{className:`hq-control-grid`,children:[(0,p.jsxs)(`div`,{className:`hq-control-composer`,children:[(0,p.jsx)(`div`,{className:`hq-card-title`,children:`Command Target`}),(0,p.jsxs)(`div`,{className:`hq-card hq-control-target`,children:[(0,p.jsx)(`label`,{className:`hq-label`,htmlFor:`hq-control-client`,children:`Client`}),(0,p.jsx)(`select`,{id:`hq-control-client`,className:`hq-select`,value:i??``,onChange:e=>{d.getState().selectClient(e.target.value),Z()},children:r.map(t=>(0,p.jsx)(`option`,{value:t.clientId,children:ae(t,e)},t.clientId))}),a!==null&&(0,p.jsxs)(`div`,{className:`hq-control-meta`,children:[(0,p.jsxs)(`span`,{children:[(0,p.jsx)(`strong`,{children:`kind`}),` `,a.kind]}),(0,p.jsxs)(`span`,{children:[(0,p.jsx)(`strong`,{children:`host`}),` `,a.hostname??`unknown`]}),(0,p.jsxs)(`span`,{children:[(0,p.jsx)(`strong`,{children:`project`}),` `,a.projectId]}),(0,p.jsxs)(`span`,{children:[(0,p.jsx)(`strong`,{children:`client`}),` `,_(a.clientId)]}),s!==void 0&&(0,p.jsxs)(`span`,{children:[(0,p.jsx)(`strong`,{children:`session`}),` `,_(s.sessionId),` ·`,` `,s.agentCount,` agents`]})]})]}),(0,p.jsx)(`div`,{className:`hq-card-title`,children:`Command Type`}),(0,p.jsxs)(`fieldset`,{className:`hq-control-steps`,"aria-label":`Control command stages`,children:[(0,p.jsx)(`span`,{className:`hq-step active`,children:`1 compose`}),(0,p.jsx)(`span`,{className:`hq-step`+(y===`preview`?` active`:``),children:`2 preview`}),(0,p.jsx)(`span`,{className:`hq-step`+(F===null?``:` active`),children:`3 queued`})]}),(0,p.jsx)(`div`,{className:`hq-control-types`,children:Object.keys(m).map(e=>{let t=m[e];return(0,p.jsxs)(`button`,{type:`button`,title:t.desc,className:`hq-control-type`+(l===e?` selected`:``)+(t.danger===!0?` danger`:``),onClick:()=>ye(e),children:[t.icon,t.label]},e)})}),(0,p.jsxs)(`div`,{className:`hq-control-typedesc`,children:[m[l].danger===!0&&(0,p.jsx)(ee,{size:12}),m[l].desc]}),(0,p.jsxs)(`div`,{className:`hq-mt-12`,children:[(l===`steer`||l===`btw`||l===`queue`)&&(0,p.jsxs)(`div`,{className:`hq-card`,children:[(0,p.jsxs)(`label`,{className:`hq-label`,htmlFor:`hq-control-recipient`,children:[`To (agent address — e.g. `,(0,p.jsx)(`code`,{children:`leader`}),`, `,(0,p.jsx)(`code`,{children:`leader@sessionTag`}),`, or a subagent id)`]}),(0,p.jsx)(`input`,{id:`hq-control-recipient`,className:`hq-input`,value:x,onChange:e=>{ce(e.target.value),u({steerTo:e.target.value})},placeholder:`leader`}),(0,p.jsx)(`label`,{className:`hq-label hq-mt-8`,htmlFor:`hq-control-subject`,children:`Subject`}),(0,p.jsx)(`input`,{id:`hq-control-subject`,className:`hq-input`,value:S,onChange:e=>{C(e.target.value),u({steerSubject:e.target.value})}}),(0,p.jsx)(`label`,{className:`hq-label hq-mt-8`,htmlFor:`hq-control-body`,children:`Body`}),(0,p.jsx)(`textarea`,{id:`hq-control-body`,className:`hq-textarea`,value:w,onChange:e=>{le(e.target.value),u({steerBody:e.target.value})}})]}),l===`abort`&&(0,p.jsxs)(`div`,{className:`hq-card hq-card-danger`,children:[(0,p.jsx)(`label`,{className:`hq-label`,htmlFor:`hq-control-abort-target`,children:`Target`}),(0,p.jsxs)(`select`,{id:`hq-control-abort-target`,className:`hq-select`,value:D,onChange:e=>{O(e.target.value),u({abortTarget:e.target.value})},children:[(0,p.jsx)(`option`,{value:`leader`,children:`leader (session leader)`}),(0,p.jsx)(`option`,{value:`fleet`,children:`fleet (all subagents)`})]}),(0,p.jsxs)(`div`,{className:`hq-control-warning`,children:[`Abort is destructive. Preview requires typing `,(0,p.jsx)(`strong`,{children:`ABORT`}),` before dispatch.`]})]}),l===`spawn`&&(0,p.jsxs)(`div`,{className:`hq-card`,children:[(0,p.jsx)(`label`,{className:`hq-label`,htmlFor:`hq-control-spawn-role`,children:`Role`}),(0,p.jsxs)(`select`,{id:`hq-control-spawn-role`,className:`hq-select`,value:T,onChange:e=>{ue(e.target.value),u({spawnRole:e.target.value})},children:[(0,p.jsx)(`option`,{value:`bug-hunter`,children:`bug-hunter`}),(0,p.jsx)(`option`,{value:`refactor-planner`,children:`refactor-planner`}),(0,p.jsx)(`option`,{value:`critic`,children:`critic`}),(0,p.jsx)(`option`,{value:`security-scanner`,children:`security-scanner`}),(0,p.jsx)(`option`,{value:`code-reviewer`,children:`code-reviewer`})]}),(0,p.jsx)(`label`,{className:`hq-label hq-mt-8`,htmlFor:`hq-control-spawn-task`,children:`Task (optional)`}),(0,p.jsx)(`textarea`,{id:`hq-control-spawn-task`,className:`hq-textarea`,value:E,onChange:e=>{de(e.target.value),u({spawnTask:e.target.value})},placeholder:`Describe the task…`})]}),l===`run-command`&&(0,p.jsxs)(`div`,{className:`hq-card hq-card-danger`,children:[(0,p.jsx)(`label`,{className:`hq-label`,htmlFor:`hq-control-run-command`,children:`Shell command`}),(0,p.jsx)(`textarea`,{id:`hq-control-run-command`,className:`hq-textarea`,value:j,onChange:e=>me(e.target.value),placeholder:`pnpm test`}),(0,p.jsx)(`label`,{className:`hq-label hq-mt-8`,htmlFor:`hq-control-run-cwd`,children:`Working directory (optional — defaults to the agent's project root)`}),(0,p.jsx)(`input`,{id:`hq-control-run-cwd`,className:`hq-input`,value:M,onChange:e=>he(e.target.value),placeholder:``}),(0,p.jsxs)(`div`,{className:`hq-control-warning`,children:[`RCE-gated: the client must run with `,(0,p.jsx)(`code`,{children:`--hq-allow-exec`}),` and your token needs the `,(0,p.jsx)(`code`,{children:`control.execute`}),` capability — otherwise the server rejects this. Preview requires typing `,(0,p.jsx)(`strong`,{children:`RUN`}),` before dispatch.`]})]}),l===`broadcast`&&(0,p.jsxs)(`div`,{className:`hq-card`,children:[(0,p.jsx)(`label`,{className:`hq-label`,htmlFor:`hq-control-broadcast-subject`,children:`Subject`}),(0,p.jsx)(`input`,{id:`hq-control-broadcast-subject`,className:`hq-input`,value:k,onChange:e=>{fe(e.target.value),u({broadcastSubject:e.target.value})}}),(0,p.jsx)(`label`,{className:`hq-label hq-mt-8`,htmlFor:`hq-control-broadcast-body`,children:`Body`}),(0,p.jsx)(`textarea`,{id:`hq-control-broadcast-body`,className:`hq-textarea`,value:A,onChange:e=>{pe(e.target.value),u({broadcastBody:e.target.value})}})]})]}),(0,p.jsx)(`div`,{className:`hq-card-title`,children:`Dispatch Gate`}),(0,p.jsxs)(`div`,{className:`hq-card hq-command-preview`+(K.risk===`danger`?` hq-card-danger`:``),children:[(0,p.jsxs)(`div`,{className:`hq-row`,children:[(0,p.jsx)(`span`,{className:`hq-pill `+(K.risk===`danger`?`error`:`info`),children:K.risk}),(0,p.jsx)(`span`,{children:K.summary}),K.disabledReason!==null&&(0,p.jsx)(`span`,{className:`hq-pill warn`,children:K.disabledReason})]}),y===`preview`?(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(`div`,{className:`hq-msg-sublabel`,children:`payload preview`}),(0,p.jsx)(`pre`,{className:`hq-msg-pre`,children:JSON.stringify({clientId:i,type:K.type,payload:K.payload},null,2)}),q&&(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(`label`,{className:`hq-label hq-mt-12`,htmlFor:`hq-control-confirm`,children:`Confirm destructive dispatch`}),(0,p.jsx)(`input`,{id:`hq-control-confirm`,className:`hq-input`,value:N,onChange:e=>P(e.target.value),placeholder:`Type ${J}`})]}),(0,p.jsxs)(`div`,{className:`hq-row hq-mt-12`,children:[(0,p.jsx)(`button`,{type:`button`,className:`hq-btn`,disabled:z||!Y,onClick:()=>void $(),title:`Ctrl+Enter`,children:z?`Dispatching…`:`Dispatch Command`}),(0,p.jsx)(`button`,{type:`button`,className:`hq-btn secondary`,disabled:z,onClick:Z,children:`Back to Compose`})]})]}):(0,p.jsx)(`button`,{type:`button`,className:`hq-btn`,disabled:!X,onClick:()=>{b(`preview`),I(null),R(null)},title:`Ctrl+Enter`,children:`Preview Command`})]}),F&&(0,p.jsx)(`div`,{className:`hq-pill active hq-mt-12`,children:F}),L&&(0,p.jsx)(`div`,{className:`hq-pill error hq-mt-12`,children:L})]}),(0,p.jsxs)(`div`,{className:`hq-control-audit`,children:[(0,p.jsx)(`div`,{className:`hq-card-title`,children:`Command Audit`}),(0,p.jsxs)(`div`,{className:`hq-card hq-command-audit`,children:[(0,p.jsxs)(`div`,{className:`hq-row`,children:[(0,p.jsxs)(`span`,{className:`hq-pill info`,children:[`recent `,V.length]}),ge&&(0,p.jsx)(`span`,{className:`hq-pill idle`,children:`refreshing`}),W!==null&&(0,p.jsx)(`span`,{className:`hq-pill error`,children:W}),(0,p.jsx)(`button`,{type:`button`,className:`hq-btn secondary hq-ml-auto`,onClick:()=>void Q(),children:`Refresh`})]}),V.length===0?(0,p.jsx)(`div`,{className:`hq-empty hq-cockpit-empty`,children:`No command audit entries yet.`}):(0,p.jsx)(`div`,{className:`hq-audit-list`,children:V.map(e=>(0,p.jsxs)(`div`,{className:`hq-audit-row`+(e.commandId===_e?` just-dispatched`:``)+(i!==null&&e.clientId===i?``:` other-client`),children:[(0,p.jsxs)(`div`,{className:`hq-audit-main`,children:[(0,p.jsx)(`span`,{className:`hq-pill `+oe(e),children:e.status}),(0,p.jsx)(`span`,{className:`hq-pill info`,children:e.type}),(0,p.jsx)(`span`,{className:`hq-mono`,children:_(e.commandId)}),e.ackStatus!==void 0&&(0,p.jsxs)(`span`,{className:`hq-pill `+se(e.ackStatus),children:[`ack `,e.ackStatus]})]}),(0,p.jsxs)(`div`,{className:`hq-audit-meta`,children:[(0,p.jsxs)(`span`,{children:[(0,p.jsx)(`strong`,{children:`client`}),` `,_(e.clientId)]}),(0,p.jsxs)(`span`,{children:[(0,p.jsx)(`strong`,{children:`by`}),` `,e.enqueuedBy]}),(0,p.jsxs)(`span`,{children:[(0,p.jsx)(`strong`,{children:`queued`}),` `,v(e.enqueuedAt)]}),e.ackedAt!==void 0&&(0,p.jsxs)(`span`,{children:[(0,p.jsx)(`strong`,{children:`acked`}),` `,v(e.ackedAt)]})]}),e.ackMessage!==void 0&&e.ackMessage.length>0&&(0,p.jsx)(`div`,{className:`hq-audit-message`,children:e.ackMessage})]},e.commandId))})]})]})]})]})}function g({label:e,value:t,tone:n}){return(0,p.jsxs)(`div`,{className:`hq-hero-metric`,"data-tone":n,children:[(0,p.jsx)(`strong`,{children:t}),(0,p.jsx)(`span`,{children:e})]})}function _(e){return e.length>18?`${e.slice(0,10)}…${e.slice(-6)}`:e}function ae(e,t){let n=t?.projects.find(t=>t.projectId===e.projectId),r=(t?.liveSessions??[]).find(t=>t.clientId===e.clientId||t.machineId===e.machineId&&t.projectId===e.projectId&&t.pid!==void 0&&t.pid===e.pid);return`${e.hostname??e.machineId} › ${n?.projectName??e.projectId} › ${`${e.kind.toUpperCase()}${e.pid===void 0?``:` · pid ${e.pid}`}`} › ${_(r?.sessionId??e.clientId)}`}function v(e,t=Date.now()){let n=new Date(e);if(Number.isNaN(n.getTime()))return e;let r=Math.max(0,t-n.getTime());return r<6e4?`${Math.floor(r/1e3)}s ago`:r<36e5?`${Math.floor(r/6e4)}m ago`:n.toLocaleTimeString()}function oe(e){return e.ackStatus===`failed`||e.ackStatus===`rejected`?`error`:e.status===`acked`?`active`:e.status===`delivered`?`info`:e.status===`queued`?`warn`:`idle`}function se(e){return e===`failed`||e===`rejected`?`error`:e===`completed`?`active`:`info`}export{h as ControlView};
|
|
1
|
+
import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{B as t,Kt as n,M as r,R as i,Zt as a,f as o,l as ee,q as s,t as c}from"./icons-C4ljWs50.js";import{i as l}from"./markdown--Y3iks7c.js";import{c as te,o as ne,p as re,r as u,s as ie,u as d}from"./index-Ch5wZYYG.js";var f=e(a(),1),p=l(),m={steer:{label:`steer`,icon:(0,p.jsx)(c,{size:13}),desc:`High-priority course correction — interrupts the agent at the next turn.`},btw:{label:`btw`,icon:(0,p.jsx)(i,{size:13}),desc:`Non-urgent FYI — rides alongside the run without interrupting it.`},queue:{label:`queue`,icon:(0,p.jsx)(s,{size:13}),desc:`Queue a prompt — picked up after the current run finishes.`},abort:{label:`abort`,icon:(0,p.jsx)(r,{size:13}),desc:`Stop the leader run or every subagent on the client. Destructive.`,danger:!0},spawn:{label:`spawn`,icon:(0,p.jsx)(n,{size:13}),desc:`Launch a role subagent (bug-hunter, critic, …) with an optional task.`},broadcast:{label:`broadcast`,icon:(0,p.jsx)(t,{size:13}),desc:`Mailbox message to every agent in the client’s project.`},"run-command":{label:`run-command`,icon:(0,p.jsx)(o,{size:13}),desc:`Route a shell command to the client. RCE-gated (--hq-allow-exec + control.execute).`,danger:!0}};function h(){let{snapshot:e,selectedClientId:t,commandStatuses:n}=d(re(e=>({snapshot:e.snapshot,selectedClientId:e.selectedClientId,commandStatuses:e.commandStatuses}))),r=(e?.clients??[]).filter(e=>e.capabilities.includes(`control.receive`)),i=r.some(e=>e.clientId===t)?t:r[0]?.clientId??null,a=r.find(e=>e.clientId===i)??null,s=a===null?void 0:(e?.liveSessions??[]).find(e=>e.clientId===a.clientId||e.machineId===a.machineId&&e.projectId===a.projectId&&e.pid!==void 0&&e.pid===a.pid),c=ne().control,[l,h]=(0,f.useState)(c.cmdType),[y,b]=(0,f.useState)(`compose`),[x,ce]=(0,f.useState)(c.steerTo),[S,C]=(0,f.useState)(c.steerSubject),[w,le]=(0,f.useState)(c.steerBody),[T,ue]=(0,f.useState)(c.spawnRole),[E,de]=(0,f.useState)(c.spawnTask),[D,O]=(0,f.useState)(c.abortTarget),[k,fe]=(0,f.useState)(c.broadcastSubject),[A,pe]=(0,f.useState)(c.broadcastBody),[j,me]=(0,f.useState)(``),[M,he]=(0,f.useState)(``),[N,P]=(0,f.useState)(``),[F,I]=(0,f.useState)(null),[L,R]=(0,f.useState)(null),[z,B]=(0,f.useState)(!1),[V,H]=(0,f.useState)([]),[ge,U]=(0,f.useState)(!1),[W,G]=(0,f.useState)(null),[_e,ve]=(0,f.useState)(null),K=(0,f.useMemo)(()=>be(),[l,x,S,w,T,E,D,k,A,j,M]),q=K.risk===`danger`,J=l===`run-command`?`RUN`:`ABORT`,Y=i!==null&&K.disabledReason===null&&(!q||N===J),X=K.disabledReason===null&&i!==null;function Z(){b(`compose`),P(``),R(null),I(null)}function ye(e){h(e),u({cmdType:e}),Z()}async function Q(){U(!0),G(null);try{let e=await ie(`/api/commands?limit=25`);H(e.commands.slice().reverse())}catch(e){G(e instanceof Error?e.message:String(e))}finally{U(!1)}}(0,f.useEffect)(()=>{Q();let e=setInterval(()=>{document.hidden||Q()},15e3);return()=>clearInterval(e)},[]),(0,f.useEffect)(()=>{n.length!==0&&H(e=>{let t=new Map(e.map(e=>[e.commandId,e]));for(let e of n)t.set(e.commandId,e);return[...t.values()].sort((e,t)=>t.enqueuedAt.localeCompare(e.enqueuedAt)).slice(0,25)})},[n]);async function $(){if(!(i===null||!Y)){B(!0),R(null),I(null);try{let e=await te(i,K.type,K.payload);I(`queued ${K.type} command ${e.commandId}`),ve(e.commandId),b(`compose`),P(``),Q()}catch(e){R(e instanceof Error?e.message:String(e))}finally{B(!1)}}}(0,f.useEffect)(()=>{let e=e=>{e.key!==`Enter`||!(e.ctrlKey||e.metaKey)||(e.preventDefault(),y===`compose`&&X?(b(`preview`),I(null),R(null)):y===`preview`&&Y&&!z&&$())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)});function be(){if(l===`steer`||l===`btw`||l===`queue`){let e=w.trim(),t=l===`steer`?`Send high-priority steer to`:l===`btw`?`Post a non-urgent FYI (btw) to`:`Queue a prompt for`;return{type:l,payload:{to:x||`leader`,subject:S||`HQ ${l}`,body:w,priority:l===`steer`?`high`:`normal`},disabledReason:e.length===0?`Message body is required.`:null,risk:`normal`,summary:`${t} ${x||`leader`}.`}}if(l===`run-command`){let e=j.trim();return{type:`run-command`,payload:{command:j,...M.trim()?{cwd:M.trim()}:{}},disabledReason:e.length===0?`Command is required.`:null,risk:`danger`,summary:`Route a shell command to the client (requires --hq-allow-exec + control.execute; delivered as a steer, the agent’s permission policy still applies).`}}if(l===`abort`)return{type:`abort`,payload:{target:D},disabledReason:null,risk:`danger`,summary:D===`fleet`?`Abort all subagents on the selected client.`:`Abort the selected target on the selected client.`};if(l===`spawn`){let e=E.trim();return{type:`spawn`,payload:{role:T,...e?{task:e}:{}},disabledReason:T.trim().length===0?`Role is required.`:null,risk:`normal`,summary:`Spawn a ${T} subagent${e?` with an initial task`:``}.`}}let e=A.trim();return{type:`broadcast`,payload:{subject:k||`HQ broadcast`,body:A,priority:`normal`},disabledReason:e.length===0?`Broadcast body is required.`:null,risk:`normal`,summary:`Broadcast a normal-priority mailbox message to the selected client project.`}}return r.length===0?(0,p.jsxs)(`div`,{className:`hq-control-zero`,children:[(0,p.jsx)(`span`,{className:`hq-control-zero-icon`,"aria-hidden":`true`,children:(0,p.jsx)(o,{size:26})}),(0,p.jsx)(`span`,{className:`hq-section-kicker`,children:`Command plane offline`}),(0,p.jsx)(`h2`,{children:`No command-ready clients`}),(0,p.jsxs)(`p`,{children:[`Connect a CLI, TUI or WebUI client advertising `,(0,p.jsx)(`code`,{children:`control.receive`}),` to unlock staged remote commands and their audit trail.`]}),(0,p.jsx)(`button`,{type:`button`,className:`hq-btn secondary`,onClick:()=>d.getState().setActiveView(`fleet`),children:`Inspect Fleet Map`})]}):(0,p.jsxs)(`div`,{className:`hq-screen hq-control-screen`,"data-stage":y,"data-risk":K.risk,children:[(0,p.jsxs)(`section`,{className:`hq-screen-hero hq-control-hero`,"aria-label":`Command plane summary`,children:[(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`span`,{className:`hq-section-kicker`,children:`Command plane`}),(0,p.jsx)(`h2`,{children:`Remote execution, with guardrails`}),(0,p.jsx)(`p`,{children:`Select a live client, compose the exact intent, inspect its payload and dispatch only after the risk gate is satisfied.`}),(0,p.jsxs)(`div`,{className:`hq-control-hero-state`,children:[(0,p.jsx)(`span`,{className:`hq-pill active`,children:`control channel ready`}),(0,p.jsxs)(`span`,{className:`hq-pill `+(K.risk===`danger`?`error`:`info`),children:[K.risk,` risk`]}),F===null?null:(0,p.jsx)(`span`,{className:`hq-pill active`,children:F})]})]}),(0,p.jsxs)(`div`,{className:`hq-hero-metrics`,children:[(0,p.jsx)(g,{label:`targets`,value:r.length}),(0,p.jsx)(g,{label:`live sessions`,value:e?.liveSessions?.length??0}),(0,p.jsx)(g,{label:`stage`,value:y,tone:y===`preview`?`warn`:void 0}),(0,p.jsx)(g,{label:`recent audit`,value:V.length})]})]}),(0,p.jsxs)(`div`,{className:`hq-control-grid`,children:[(0,p.jsxs)(`div`,{className:`hq-control-composer`,children:[(0,p.jsx)(`div`,{className:`hq-card-title`,children:`Command Target`}),(0,p.jsxs)(`div`,{className:`hq-card hq-control-target`,children:[(0,p.jsx)(`label`,{className:`hq-label`,htmlFor:`hq-control-client`,children:`Client`}),(0,p.jsx)(`select`,{id:`hq-control-client`,className:`hq-select`,value:i??``,onChange:e=>{d.getState().selectClient(e.target.value),Z()},children:r.map(t=>(0,p.jsx)(`option`,{value:t.clientId,children:ae(t,e)},t.clientId))}),a!==null&&(0,p.jsxs)(`div`,{className:`hq-control-meta`,children:[(0,p.jsxs)(`span`,{children:[(0,p.jsx)(`strong`,{children:`kind`}),` `,a.kind]}),(0,p.jsxs)(`span`,{children:[(0,p.jsx)(`strong`,{children:`host`}),` `,a.hostname??`unknown`]}),(0,p.jsxs)(`span`,{children:[(0,p.jsx)(`strong`,{children:`project`}),` `,a.projectId]}),(0,p.jsxs)(`span`,{children:[(0,p.jsx)(`strong`,{children:`client`}),` `,_(a.clientId)]}),s!==void 0&&(0,p.jsxs)(`span`,{children:[(0,p.jsx)(`strong`,{children:`session`}),` `,_(s.sessionId),` ·`,` `,s.agentCount,` agents`]})]})]}),(0,p.jsx)(`div`,{className:`hq-card-title`,children:`Command Type`}),(0,p.jsxs)(`fieldset`,{className:`hq-control-steps`,"aria-label":`Control command stages`,children:[(0,p.jsx)(`span`,{className:`hq-step active`,children:`1 compose`}),(0,p.jsx)(`span`,{className:`hq-step`+(y===`preview`?` active`:``),children:`2 preview`}),(0,p.jsx)(`span`,{className:`hq-step`+(F===null?``:` active`),children:`3 queued`})]}),(0,p.jsx)(`div`,{className:`hq-control-types`,children:Object.keys(m).map(e=>{let t=m[e];return(0,p.jsxs)(`button`,{type:`button`,title:t.desc,className:`hq-control-type`+(l===e?` selected`:``)+(t.danger===!0?` danger`:``),onClick:()=>ye(e),children:[t.icon,t.label]},e)})}),(0,p.jsxs)(`div`,{className:`hq-control-typedesc`,children:[m[l].danger===!0&&(0,p.jsx)(ee,{size:12}),m[l].desc]}),(0,p.jsxs)(`div`,{className:`hq-mt-12`,children:[(l===`steer`||l===`btw`||l===`queue`)&&(0,p.jsxs)(`div`,{className:`hq-card`,children:[(0,p.jsxs)(`label`,{className:`hq-label`,htmlFor:`hq-control-recipient`,children:[`To (agent address — e.g. `,(0,p.jsx)(`code`,{children:`leader`}),`, `,(0,p.jsx)(`code`,{children:`leader@sessionTag`}),`, or a subagent id)`]}),(0,p.jsx)(`input`,{id:`hq-control-recipient`,className:`hq-input`,value:x,onChange:e=>{ce(e.target.value),u({steerTo:e.target.value})},placeholder:`leader`}),(0,p.jsx)(`label`,{className:`hq-label hq-mt-8`,htmlFor:`hq-control-subject`,children:`Subject`}),(0,p.jsx)(`input`,{id:`hq-control-subject`,className:`hq-input`,value:S,onChange:e=>{C(e.target.value),u({steerSubject:e.target.value})}}),(0,p.jsx)(`label`,{className:`hq-label hq-mt-8`,htmlFor:`hq-control-body`,children:`Body`}),(0,p.jsx)(`textarea`,{id:`hq-control-body`,className:`hq-textarea`,value:w,onChange:e=>{le(e.target.value),u({steerBody:e.target.value})}})]}),l===`abort`&&(0,p.jsxs)(`div`,{className:`hq-card hq-card-danger`,children:[(0,p.jsx)(`label`,{className:`hq-label`,htmlFor:`hq-control-abort-target`,children:`Target`}),(0,p.jsxs)(`select`,{id:`hq-control-abort-target`,className:`hq-select`,value:D,onChange:e=>{O(e.target.value),u({abortTarget:e.target.value})},children:[(0,p.jsx)(`option`,{value:`leader`,children:`leader (session leader)`}),(0,p.jsx)(`option`,{value:`fleet`,children:`fleet (all subagents)`})]}),(0,p.jsxs)(`div`,{className:`hq-control-warning`,children:[`Abort is destructive. Preview requires typing `,(0,p.jsx)(`strong`,{children:`ABORT`}),` before dispatch.`]})]}),l===`spawn`&&(0,p.jsxs)(`div`,{className:`hq-card`,children:[(0,p.jsx)(`label`,{className:`hq-label`,htmlFor:`hq-control-spawn-role`,children:`Role`}),(0,p.jsxs)(`select`,{id:`hq-control-spawn-role`,className:`hq-select`,value:T,onChange:e=>{ue(e.target.value),u({spawnRole:e.target.value})},children:[(0,p.jsx)(`option`,{value:`bug-hunter`,children:`bug-hunter`}),(0,p.jsx)(`option`,{value:`refactor-planner`,children:`refactor-planner`}),(0,p.jsx)(`option`,{value:`critic`,children:`critic`}),(0,p.jsx)(`option`,{value:`security-scanner`,children:`security-scanner`}),(0,p.jsx)(`option`,{value:`code-reviewer`,children:`code-reviewer`})]}),(0,p.jsx)(`label`,{className:`hq-label hq-mt-8`,htmlFor:`hq-control-spawn-task`,children:`Task (optional)`}),(0,p.jsx)(`textarea`,{id:`hq-control-spawn-task`,className:`hq-textarea`,value:E,onChange:e=>{de(e.target.value),u({spawnTask:e.target.value})},placeholder:`Describe the task…`})]}),l===`run-command`&&(0,p.jsxs)(`div`,{className:`hq-card hq-card-danger`,children:[(0,p.jsx)(`label`,{className:`hq-label`,htmlFor:`hq-control-run-command`,children:`Shell command`}),(0,p.jsx)(`textarea`,{id:`hq-control-run-command`,className:`hq-textarea`,value:j,onChange:e=>me(e.target.value),placeholder:`pnpm test`}),(0,p.jsx)(`label`,{className:`hq-label hq-mt-8`,htmlFor:`hq-control-run-cwd`,children:`Working directory (optional — defaults to the agent's project root)`}),(0,p.jsx)(`input`,{id:`hq-control-run-cwd`,className:`hq-input`,value:M,onChange:e=>he(e.target.value),placeholder:``}),(0,p.jsxs)(`div`,{className:`hq-control-warning`,children:[`RCE-gated: the client must run with `,(0,p.jsx)(`code`,{children:`--hq-allow-exec`}),` and your token needs the `,(0,p.jsx)(`code`,{children:`control.execute`}),` capability — otherwise the server rejects this. Preview requires typing `,(0,p.jsx)(`strong`,{children:`RUN`}),` before dispatch.`]})]}),l===`broadcast`&&(0,p.jsxs)(`div`,{className:`hq-card`,children:[(0,p.jsx)(`label`,{className:`hq-label`,htmlFor:`hq-control-broadcast-subject`,children:`Subject`}),(0,p.jsx)(`input`,{id:`hq-control-broadcast-subject`,className:`hq-input`,value:k,onChange:e=>{fe(e.target.value),u({broadcastSubject:e.target.value})}}),(0,p.jsx)(`label`,{className:`hq-label hq-mt-8`,htmlFor:`hq-control-broadcast-body`,children:`Body`}),(0,p.jsx)(`textarea`,{id:`hq-control-broadcast-body`,className:`hq-textarea`,value:A,onChange:e=>{pe(e.target.value),u({broadcastBody:e.target.value})}})]})]}),(0,p.jsx)(`div`,{className:`hq-card-title`,children:`Dispatch Gate`}),(0,p.jsxs)(`div`,{className:`hq-card hq-command-preview`+(K.risk===`danger`?` hq-card-danger`:``),children:[(0,p.jsxs)(`div`,{className:`hq-row`,children:[(0,p.jsx)(`span`,{className:`hq-pill `+(K.risk===`danger`?`error`:`info`),children:K.risk}),(0,p.jsx)(`span`,{children:K.summary}),K.disabledReason!==null&&(0,p.jsx)(`span`,{className:`hq-pill warn`,children:K.disabledReason})]}),y===`preview`?(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(`div`,{className:`hq-msg-sublabel`,children:`payload preview`}),(0,p.jsx)(`pre`,{className:`hq-msg-pre`,children:JSON.stringify({clientId:i,type:K.type,payload:K.payload},null,2)}),q&&(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(`label`,{className:`hq-label hq-mt-12`,htmlFor:`hq-control-confirm`,children:`Confirm destructive dispatch`}),(0,p.jsx)(`input`,{id:`hq-control-confirm`,className:`hq-input`,value:N,onChange:e=>P(e.target.value),placeholder:`Type ${J}`})]}),(0,p.jsxs)(`div`,{className:`hq-row hq-mt-12`,children:[(0,p.jsx)(`button`,{type:`button`,className:`hq-btn`,disabled:z||!Y,onClick:()=>void $(),title:`Ctrl+Enter`,children:z?`Dispatching…`:`Dispatch Command`}),(0,p.jsx)(`button`,{type:`button`,className:`hq-btn secondary`,disabled:z,onClick:Z,children:`Back to Compose`})]})]}):(0,p.jsx)(`button`,{type:`button`,className:`hq-btn`,disabled:!X,onClick:()=>{b(`preview`),I(null),R(null)},title:`Ctrl+Enter`,children:`Preview Command`})]}),F&&(0,p.jsx)(`div`,{className:`hq-pill active hq-mt-12`,children:F}),L&&(0,p.jsx)(`div`,{className:`hq-pill error hq-mt-12`,children:L})]}),(0,p.jsxs)(`div`,{className:`hq-control-audit`,children:[(0,p.jsx)(`div`,{className:`hq-card-title`,children:`Command Audit`}),(0,p.jsxs)(`div`,{className:`hq-card hq-command-audit`,children:[(0,p.jsxs)(`div`,{className:`hq-row`,children:[(0,p.jsxs)(`span`,{className:`hq-pill info`,children:[`recent `,V.length]}),ge&&(0,p.jsx)(`span`,{className:`hq-pill idle`,children:`refreshing`}),W!==null&&(0,p.jsx)(`span`,{className:`hq-pill error`,children:W}),(0,p.jsx)(`button`,{type:`button`,className:`hq-btn secondary hq-ml-auto`,onClick:()=>void Q(),children:`Refresh`})]}),V.length===0?(0,p.jsx)(`div`,{className:`hq-empty hq-cockpit-empty`,children:`No command audit entries yet.`}):(0,p.jsx)(`div`,{className:`hq-audit-list`,children:V.map(e=>(0,p.jsxs)(`div`,{className:`hq-audit-row`+(e.commandId===_e?` just-dispatched`:``)+(i!==null&&e.clientId===i?``:` other-client`),children:[(0,p.jsxs)(`div`,{className:`hq-audit-main`,children:[(0,p.jsx)(`span`,{className:`hq-pill `+oe(e),children:e.status}),(0,p.jsx)(`span`,{className:`hq-pill info`,children:e.type}),(0,p.jsx)(`span`,{className:`hq-mono`,children:_(e.commandId)}),e.ackStatus!==void 0&&(0,p.jsxs)(`span`,{className:`hq-pill `+se(e.ackStatus),children:[`ack `,e.ackStatus]})]}),(0,p.jsxs)(`div`,{className:`hq-audit-meta`,children:[(0,p.jsxs)(`span`,{children:[(0,p.jsx)(`strong`,{children:`client`}),` `,_(e.clientId)]}),(0,p.jsxs)(`span`,{children:[(0,p.jsx)(`strong`,{children:`by`}),` `,e.enqueuedBy]}),(0,p.jsxs)(`span`,{children:[(0,p.jsx)(`strong`,{children:`queued`}),` `,v(e.enqueuedAt)]}),e.ackedAt!==void 0&&(0,p.jsxs)(`span`,{children:[(0,p.jsx)(`strong`,{children:`acked`}),` `,v(e.ackedAt)]})]}),e.ackMessage!==void 0&&e.ackMessage.length>0&&(0,p.jsx)(`div`,{className:`hq-audit-message`,children:e.ackMessage})]},e.commandId))})]})]})]})]})}function g({label:e,value:t,tone:n}){return(0,p.jsxs)(`div`,{className:`hq-hero-metric`,"data-tone":n,children:[(0,p.jsx)(`strong`,{children:t}),(0,p.jsx)(`span`,{children:e})]})}function _(e){return e.length>18?`${e.slice(0,10)}…${e.slice(-6)}`:e}function ae(e,t){let n=t?.projects.find(t=>t.projectId===e.projectId),r=(t?.liveSessions??[]).find(t=>t.clientId===e.clientId||t.machineId===e.machineId&&t.projectId===e.projectId&&t.pid!==void 0&&t.pid===e.pid);return`${e.hostname??e.machineId} › ${n?.projectName??e.projectId} › ${`${e.kind.toUpperCase()}${e.pid===void 0?``:` · pid ${e.pid}`}`} › ${_(r?.sessionId??e.clientId)}`}function v(e,t=Date.now()){let n=new Date(e);if(Number.isNaN(n.getTime()))return e;let r=Math.max(0,t-n.getTime());return r<6e4?`${Math.floor(r/1e3)}s ago`:r<36e5?`${Math.floor(r/6e4)}m ago`:n.toLocaleTimeString()}function oe(e){return e.ackStatus===`failed`||e.ackStatus===`rejected`?`error`:e.status===`acked`?`active`:e.status===`delivered`?`info`:e.status===`queued`?`warn`:`idle`}function se(e){return e===`failed`||e===`rejected`?`error`:e===`completed`?`active`:`info`}export{h as ControlView};
|
|
@@ -1 +1 @@
|
|
|
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{u as r}from"./index-
|
|
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{u as r}from"./index-Ch5wZYYG.js";var i=e(t(),1),a=n();function o(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function s(){let e=r(e=>e.snapshot),t=e?.projects??[],n=e?.liveSessions??[],s=e?.totals.totalCostUsd??0,l=(0,i.useMemo)(()=>n.map(e=>{let t=0,n=0,r=new Set;for(let i of e.agents)t+=i.costUsd??0,n+=(i.tokensIn??0)+(i.tokensOut??0),i.model!==void 0&&r.add(i.model);return{s:e,cost:t,tokens:n,models:[...r]}}).filter(e=>e.cost>0||e.tokens>0).sort((e,t)=>t.cost-e.cost),[n]);if(t.length===0)return(0,a.jsx)(`div`,{className:`hq-empty hq-empty-ornate`,children:`No cost data yet — connect some clients.`});let u=[...t].sort((e,t)=>t.totalCostUsd-e.totalCostUsd),d=u[0],f=d&&s>0?d.totalCostUsd/s*100:0,p=l.reduce((e,t)=>e+t.tokens,0);return(0,a.jsxs)(`div`,{className:`hq-screen hq-cost-screen`,children:[(0,a.jsxs)(`section`,{className:`hq-screen-hero hq-cost-hero`,"aria-label":`Cost command summary`,children:[(0,a.jsxs)(`div`,{children:[(0,a.jsx)(`span`,{className:`hq-section-kicker`,children:`Economics`}),(0,a.jsxs)(`h2`,{children:[`$`,s.toFixed(4)]}),(0,a.jsx)(`p`,{children:`Fleet spend is ranked by project first, then drilled down into costed sessions and model fingerprints.`})]}),(0,a.jsxs)(`div`,{className:`hq-hero-metrics`,children:[(0,a.jsx)(c,{label:`projects`,value:t.length}),(0,a.jsx)(c,{label:`costed sessions`,value:l.length}),(0,a.jsx)(c,{label:`tokens`,value:o(p)}),(0,a.jsx)(c,{label:`top share`,value:`${f.toFixed(0)}%`,tone:f>60?`warn`:void 0})]})]}),(0,a.jsxs)(`section`,{className:`hq-priority-section`,"aria-label":`Project cost ranking`,children:[(0,a.jsxs)(`div`,{className:`hq-section-head`,children:[(0,a.jsxs)(`div`,{children:[(0,a.jsx)(`span`,{className:`hq-section-kicker`,children:`Spend distribution`}),(0,a.jsx)(`h3`,{children:`By Project`})]}),d?(0,a.jsxs)(`span`,{className:`hq-pill info`,children:[`leader: `,d.projectName]}):null]}),(0,a.jsx)(`div`,{className:`hq-cost-rank-list`,children:u.map((e,t)=>{let n=s>0?e.totalCostUsd/s*100:0;return(0,a.jsxs)(`article`,{className:`hq-card hq-cost-project-card`,children:[(0,a.jsxs)(`div`,{className:`hq-cost-rank`,children:[`#`,t+1]}),(0,a.jsxs)(`div`,{className:`hq-cost-project-main`,children:[(0,a.jsxs)(`div`,{className:`hq-row`,children:[(0,a.jsx)(`span`,{className:`hq-text-bright`,children:e.projectName}),(0,a.jsx)(`span`,{className:`hq-mono hq-row-subtle`,children:e.projectId}),(0,a.jsxs)(`span`,{className:`hq-cost-amount`,children:[`$`,e.totalCostUsd.toFixed(4)]}),(0,a.jsxs)(`span`,{className:`hq-mono hq-row-subtle`,children:[n.toFixed(1),`%`]})]}),(0,a.jsx)(`div`,{className:`hq-share-track`,children:(0,a.jsx)(`div`,{className:`hq-share-fill`,style:{width:`${n}%`}})}),(0,a.jsxs)(`div`,{className:`hq-row hq-row-detail`,children:[(0,a.jsxs)(`span`,{className:`hq-pill info`,children:[e.activeSessions,` sessions`]}),(0,a.jsxs)(`span`,{className:`hq-pill active`,children:[e.activeSubagents,` subagents`]}),(0,a.jsxs)(`span`,{className:`hq-pill idle`,children:[e.activeClients,` clients`]})]})]})]},e.projectId)})})]}),l.length>0&&(0,a.jsxs)(`section`,{children:[(0,a.jsxs)(`div`,{className:`hq-section-head compact`,children:[(0,a.jsxs)(`div`,{children:[(0,a.jsx)(`span`,{className:`hq-section-kicker`,children:`Drilldown`}),(0,a.jsx)(`h3`,{children:`By Session`})]}),(0,a.jsxs)(`span`,{className:`hq-mono hq-row-subtle`,children:[l.length,` costed`]})]}),(0,a.jsx)(`div`,{className:`hq-card hq-cost-session-card`,children:l.map(({s:e,cost:t,tokens:n,models:i})=>(0,a.jsxs)(`button`,{type:`button`,className:`hq-row hq-row-click hq-cost-session-row`,onClick:()=>{r.getState().selectSession(e.sessionId),r.getState().setActiveView(`console`)},title:`Open in Console`,children:[(0,a.jsx)(`span`,{className:`hq-text-bright`,children:e.projectName}),(0,a.jsx)(`span`,{className:`hq-pill idle`,children:e.clientKind}),i.map(e=>(0,a.jsx)(`span`,{className:`hq-pill info`,children:e},e)),(0,a.jsxs)(`span`,{className:`hq-mono hq-row-subtle`,children:[o(n),` tok`]}),(0,a.jsxs)(`span`,{className:`hq-cost-amount`,children:[`$`,t.toFixed(4)]})]},e.sessionId))})]})]})}function c({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{s as CostView};
|