@wrongstack/webui-hq 0.303.0 → 0.305.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.
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{Wt as t}from"./icons-kYa9YuNu.js";import{i as n}from"./markdown-mWU1fYYi.js";import{p as r,s as i,u as a}from"./index-DIscZlJt.js";var o=e(t(),1),s=n();function c(){let e=a(r(e=>e.alerts)),[t,n]=(0,o.useState)([]),[c,u]=(0,o.useState)([]);(0,o.useEffect)(()=>{let e=!1,t=()=>{i(`/api/alerts`).then(t=>{e||(n(t.active),u(t.history))}).catch(()=>{})};t();let r=setInterval(t,15e3);return()=>{e=!0,clearInterval(r)}},[]);let d=e.slice(-50).reverse(),f=t.filter(e=>e.severity===`error`).length,p=t.filter(e=>e.severity===`warn`).length,m=t.length===0&&d.length===0;return(0,s.jsxs)(`div`,{className:`hq-screen hq-alerts-screen`,children:[(0,s.jsxs)(`section`,{className:`hq-screen-hero hq-alerts-hero`,"aria-label":`Alert command summary`,children:[(0,s.jsxs)(`div`,{children:[(0,s.jsx)(`span`,{className:`hq-section-kicker`,children:`Attention rail`}),(0,s.jsx)(`h2`,{children:m?`Fleet quiet`:`Fleet requires review`}),(0,s.jsx)(`p`,{children:`Active rules, live envelopes and historical transitions are separated so urgent alerts stay above routine telemetry.`})]}),(0,s.jsxs)(`div`,{className:`hq-hero-metrics`,children:[(0,s.jsx)(l,{label:`active`,value:t.length,tone:t.length>0?`warn`:`ok`}),(0,s.jsx)(l,{label:`errors`,value:f,tone:f>0?`error`:`ok`}),(0,s.jsx)(l,{label:`warnings`,value:p,tone:p>0?`warn`:`ok`}),(0,s.jsx)(l,{label:`live feed`,value:d.length})]})]}),(0,s.jsxs)(`section`,{className:`hq-priority-section`,"aria-label":`Active alerts`,children:[(0,s.jsxs)(`div`,{className:`hq-section-head`,children:[(0,s.jsxs)(`div`,{children:[(0,s.jsx)(`span`,{className:`hq-section-kicker`,children:`Now`}),(0,s.jsxs)(`h3`,{children:[`Active Alerts (`,t.length,`)`]})]}),t.length>0?(0,s.jsx)(`span`,{className:`hq-pill warn`,children:`operator attention`}):null]}),t.length>0?(0,s.jsx)(`div`,{className:`hq-alert-priority-grid`,children:t.map(e=>(0,s.jsxs)(`div`,{className:`hq-card hq-alert-card hq-card-severity `+e.severity,children:[(0,s.jsxs)(`div`,{className:`hq-row`,children:[(0,s.jsx)(`span`,{className:`hq-pill `+e.severity,children:e.severity}),(0,s.jsx)(`span`,{className:`hq-text-bright`,children:e.ruleId}),(0,s.jsxs)(`span`,{className:`hq-mono hq-ml-auto hq-text-dim`,children:[`since `,new Date(e.firstFiredAt).toLocaleTimeString()]})]}),(0,s.jsx)(`div`,{className:`hq-row-detail`,children:e.message})]},e.id))}):(0,s.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,s.jsxs)(`div`,{className:`hq-two-column hq-alerts-columns`,children:[(0,s.jsxs)(`section`,{children:[(0,s.jsxs)(`div`,{className:`hq-section-head compact`,children:[(0,s.jsxs)(`div`,{children:[(0,s.jsx)(`span`,{className:`hq-section-kicker`,children:`Signal stream`}),(0,s.jsx)(`h3`,{children:`Live Alert Feed`})]}),(0,s.jsxs)(`span`,{className:`hq-mono hq-row-subtle`,children:[`last `,d.length]})]}),d.length===0?(0,s.jsx)(`div`,{className:`hq-empty hq-pad-md`,children:`No live alerts. Alerts fire when fleet rules trigger.`}):(0,s.jsx)(`div`,{className:`hq-card hq-alert-feed-card`,children:d.map(e=>(0,s.jsxs)(`div`,{className:`hq-row hq-alert-feed-row`,children:[(0,s.jsx)(`span`,{className:`hq-pill `+e.severity,children:e.severity}),(0,s.jsx)(`span`,{className:`hq-text-muted`,children:e.message}),(0,s.jsx)(`span`,{className:`hq-mono hq-ml-auto hq-text-dim`,children:new Date(e.timestamp).toLocaleTimeString()})]},e.timestamp))})]}),(0,s.jsxs)(`section`,{children:[(0,s.jsxs)(`div`,{className:`hq-section-head compact`,children:[(0,s.jsxs)(`div`,{children:[(0,s.jsx)(`span`,{className:`hq-section-kicker`,children:`Archive`}),(0,s.jsx)(`h3`,{children:`Alert History`})]}),(0,s.jsxs)(`span`,{className:`hq-mono hq-row-subtle`,children:[c.length,` total`]})]}),(0,s.jsx)(`div`,{className:`hq-card hq-alert-history-card`,children:c.length===0?(0,s.jsx)(`div`,{className:`hq-empty hq-pad-md`,children:`No historical alerts.`}):c.slice(-30).reverse().map(e=>(0,s.jsxs)(`div`,{className:`hq-row hq-alert-history-row`,children:[(0,s.jsx)(`span`,{className:`hq-pill `+e.severity,children:e.severity}),(0,s.jsx)(`span`,{className:`hq-mono`,children:e.ruleId}),(0,s.jsx)(`span`,{className:`hq-text-muted`,children:e.message}),(0,s.jsx)(`span`,{className:`hq-mono hq-ml-auto hq-text-dim`,children:new Date(e.lastFiredAt).toLocaleTimeString()})]},e.id))})]})]})]})}function l({label:e,value:t,tone:n}){return(0,s.jsxs)(`div`,{className:`hq-hero-metric`,"data-tone":n,children:[(0,s.jsx)(`strong`,{children:t}),(0,s.jsx)(`span`,{children:e})]})}export{c as AlertsView};
1
+ import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{Wt as t}from"./icons-kYa9YuNu.js";import{i as n}from"./markdown-mWU1fYYi.js";import{p as r,s as i,u as a}from"./index-2juseZBv.js";var o=e(t(),1),s=n();function c(){let e=a(r(e=>e.alerts)),[t,n]=(0,o.useState)([]),[c,u]=(0,o.useState)([]);(0,o.useEffect)(()=>{let e=!1,t=()=>{i(`/api/alerts`).then(t=>{e||(n(t.active),u(t.history))}).catch(()=>{})};t();let r=setInterval(t,15e3);return()=>{e=!0,clearInterval(r)}},[]);let d=e.slice(-50).reverse(),f=t.filter(e=>e.severity===`error`).length,p=t.filter(e=>e.severity===`warn`).length,m=t.length===0&&d.length===0;return(0,s.jsxs)(`div`,{className:`hq-screen hq-alerts-screen`,children:[(0,s.jsxs)(`section`,{className:`hq-screen-hero hq-alerts-hero`,"aria-label":`Alert command summary`,children:[(0,s.jsxs)(`div`,{children:[(0,s.jsx)(`span`,{className:`hq-section-kicker`,children:`Attention rail`}),(0,s.jsx)(`h2`,{children:m?`Fleet quiet`:`Fleet requires review`}),(0,s.jsx)(`p`,{children:`Active rules, live envelopes and historical transitions are separated so urgent alerts stay above routine telemetry.`})]}),(0,s.jsxs)(`div`,{className:`hq-hero-metrics`,children:[(0,s.jsx)(l,{label:`active`,value:t.length,tone:t.length>0?`warn`:`ok`}),(0,s.jsx)(l,{label:`errors`,value:f,tone:f>0?`error`:`ok`}),(0,s.jsx)(l,{label:`warnings`,value:p,tone:p>0?`warn`:`ok`}),(0,s.jsx)(l,{label:`live feed`,value:d.length})]})]}),(0,s.jsxs)(`section`,{className:`hq-priority-section`,"aria-label":`Active alerts`,children:[(0,s.jsxs)(`div`,{className:`hq-section-head`,children:[(0,s.jsxs)(`div`,{children:[(0,s.jsx)(`span`,{className:`hq-section-kicker`,children:`Now`}),(0,s.jsxs)(`h3`,{children:[`Active Alerts (`,t.length,`)`]})]}),t.length>0?(0,s.jsx)(`span`,{className:`hq-pill warn`,children:`operator attention`}):null]}),t.length>0?(0,s.jsx)(`div`,{className:`hq-alert-priority-grid`,children:t.map(e=>(0,s.jsxs)(`div`,{className:`hq-card hq-alert-card hq-card-severity `+e.severity,children:[(0,s.jsxs)(`div`,{className:`hq-row`,children:[(0,s.jsx)(`span`,{className:`hq-pill `+e.severity,children:e.severity}),(0,s.jsx)(`span`,{className:`hq-text-bright`,children:e.ruleId}),(0,s.jsxs)(`span`,{className:`hq-mono hq-ml-auto hq-text-dim`,children:[`since `,new Date(e.firstFiredAt).toLocaleTimeString()]})]}),(0,s.jsx)(`div`,{className:`hq-row-detail`,children:e.message})]},e.id))}):(0,s.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,s.jsxs)(`div`,{className:`hq-two-column hq-alerts-columns`,children:[(0,s.jsxs)(`section`,{children:[(0,s.jsxs)(`div`,{className:`hq-section-head compact`,children:[(0,s.jsxs)(`div`,{children:[(0,s.jsx)(`span`,{className:`hq-section-kicker`,children:`Signal stream`}),(0,s.jsx)(`h3`,{children:`Live Alert Feed`})]}),(0,s.jsxs)(`span`,{className:`hq-mono hq-row-subtle`,children:[`last `,d.length]})]}),d.length===0?(0,s.jsx)(`div`,{className:`hq-empty hq-pad-md`,children:`No live alerts. Alerts fire when fleet rules trigger.`}):(0,s.jsx)(`div`,{className:`hq-card hq-alert-feed-card`,children:d.map(e=>(0,s.jsxs)(`div`,{className:`hq-row hq-alert-feed-row`,children:[(0,s.jsx)(`span`,{className:`hq-pill `+e.severity,children:e.severity}),(0,s.jsx)(`span`,{className:`hq-text-muted`,children:e.message}),(0,s.jsx)(`span`,{className:`hq-mono hq-ml-auto hq-text-dim`,children:new Date(e.timestamp).toLocaleTimeString()})]},e.timestamp))})]}),(0,s.jsxs)(`section`,{children:[(0,s.jsxs)(`div`,{className:`hq-section-head compact`,children:[(0,s.jsxs)(`div`,{children:[(0,s.jsx)(`span`,{className:`hq-section-kicker`,children:`Archive`}),(0,s.jsx)(`h3`,{children:`Alert History`})]}),(0,s.jsxs)(`span`,{className:`hq-mono hq-row-subtle`,children:[c.length,` total`]})]}),(0,s.jsx)(`div`,{className:`hq-card hq-alert-history-card`,children:c.length===0?(0,s.jsx)(`div`,{className:`hq-empty hq-pad-md`,children:`No historical alerts.`}):c.slice(-30).reverse().map(e=>(0,s.jsxs)(`div`,{className:`hq-row hq-alert-history-row`,children:[(0,s.jsx)(`span`,{className:`hq-pill `+e.severity,children:e.severity}),(0,s.jsx)(`span`,{className:`hq-mono`,children:e.ruleId}),(0,s.jsx)(`span`,{className:`hq-text-muted`,children:e.message}),(0,s.jsx)(`span`,{className:`hq-mono hq-ml-auto hq-text-dim`,children:new Date(e.lastFiredAt).toLocaleTimeString()})]},e.id))})]})]})]})}function l({label:e,value:t,tone:n}){return(0,s.jsxs)(`div`,{className:`hq-hero-metric`,"data-tone":n,children:[(0,s.jsx)(`strong`,{children:t}),(0,s.jsx)(`span`,{children:e})]})}export{c as AlertsView};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{At as t,Et as n,Rt as r,Tt as i,Wt as a,s as o,t as s,tt as c}from"./icons-kYa9YuNu.js";import{i as l}from"./markdown-mWU1fYYi.js";import{t as u}from"./use-backfilled-events-C3CQ5XjI.js";var d=e(a(),1),f=l(),p={decision_requested:{label:`Requested`,Icon:n,cls:`info`},decision_answered:{label:`Answered`,Icon:t,cls:`active`},decision_ask_human:{label:`Ask Human`,Icon:c,cls:`warn`},decision_denied:{label:`Denied`,Icon:i,cls:`error`},human_answered:{label:`Human`,Icon:o,cls:`info`},intervention:{label:`Intervention`,Icon:s,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
+ import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{At as t,Et as n,Rt as r,Tt as i,Wt as a,s as o,t as s,tt as c}from"./icons-kYa9YuNu.js";import{i as l}from"./markdown-mWU1fYYi.js";import{t as u}from"./use-backfilled-events-jhv9zwHj.js";var d=e(a(),1),f=l(),p={decision_requested:{label:`Requested`,Icon:n,cls:`info`},decision_answered:{label:`Answered`,Icon:t,cls:`active`},decision_ask_human:{label:`Ask Human`,Icon:c,cls:`warn`},decision_denied:{label:`Denied`,Icon:i,cls:`error`},human_answered:{label:`Human`,Icon:o,cls:`info`},intervention:{label:`Intervention`,Icon:s,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{Wt as t,v as n}from"./icons-kYa9YuNu.js";import{i as r}from"./markdown-mWU1fYYi.js";import{c as i,p as a,s as o,u as s}from"./index-DIscZlJt.js";var c=e(t(),1),l=r();function u(){let{snapshot:e,alerts:t,selectedClientId:r,connected:u}=s(a(e=>({snapshot:e.snapshot,alerts:e.alerts,selectedClientId:e.selectedClientId,connected:e.connected}))),g=e,_=g?.totals,v=g?.machines??[],y=g?.projects??[],b=g?.clients??[],x=g?.liveSessions??[],S=y.filter(e=>e.governance!==void 0),C=S.filter(e=>e.governance?.signal.level===`warning`||e.governance?.signal.level===`unavailable`),w=b.filter(e=>e.capabilities.includes(`control.receive`)),T=r??w[0]?.clientId??null,E=w.find(e=>e.clientId===T)??w[0]??null,[D,O]=(0,c.useState)([]),[k,A]=(0,c.useState)([]),[j,M]=(0,c.useState)(null),[N,P]=(0,c.useState)(null),[F,I]=(0,c.useState)(null),[L,R]=(0,c.useState)(null),[z,B]=(0,c.useState)(null),[V,H]=(0,c.useState)(null);(0,c.useEffect)(()=>{let e=!1,t=()=>{o(`/api/system/health`).then(t=>{e||(B(t),H(null))}).catch(t=>{e||H(t instanceof Error?t.message:String(t))})};t();let n=setInterval(t,3e4);return()=>{e=!0,clearInterval(n)}},[]),(0,c.useEffect)(()=>{let e=!1,t=()=>{o(`/api/alerts`).then(t=>{e||(O(t.active),A(t.history),M(null))}).catch(t=>{e||M(t instanceof Error?t.message:String(t))})};t();let n=setInterval(t,15e3);return()=>{e=!0,clearInterval(n)}},[]);let U=(0,c.useMemo)(()=>{let e=t.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()})),n=[...D??[],...k??[]].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,...n],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},[t,D,k]),W=(0,c.useMemo)(()=>{let e=0,t=0,n=0,r=0,i=0;for(let a of x){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}},[x]),G=(0,c.useMemo)(()=>[...y].sort((e,t)=>t.totalCostUsd-e.totalCostUsd).slice(0,4),[y]);async function K(e){if(E!==null){P(e),I(null),R(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 i(E.clientId,`broadcast`,t);I(`queued ${n.commandId}`)}catch(e){R(e instanceof Error?e.message:String(e))}finally{P(null)}}}let q=g?.fleets??[],J=(0,c.useMemo)(()=>{let e=0,t=0,n=0,r=0,i=0;for(let a of q)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},[q]),Y=[{title:`Fleet`,view:`fleet`,cta:`open fleet`,body:(0,l.jsxs)(`div`,{className:`hq-cockpit-grid`,children:[(0,l.jsx)(d,{label:`machines`,value:v.length}),(0,l.jsx)(d,{label:`clients`,value:b.length}),(0,l.jsx)(d,{label:`sessions`,value:W.activeSessions,accent:W.activeSessions>0?`green`:void 0}),(0,l.jsx)(d,{label:`agents`,value:W.total}),(0,l.jsx)(d,{label:`busy`,value:W.busy,accent:W.busy>0?`green`:void 0}),(0,l.jsx)(d,{label:`waiting`,value:W.waiting,accent:W.waiting>0?`warn`:void 0}),(0,l.jsx)(d,{label:`errored`,value:W.errored,accent:W.errored>0?`error`:void 0}),(0,l.jsx)(d,{label:`cost $`,value:(_?.totalCostUsd??0).toFixed(2),accent:`green`}),J&&(0,l.jsx)(d,{label:`spawns`,value:`${J.used}/${Number.isFinite(J.max)?J.max:`∞`}`,accent:J.mismatch>0?`warn`:void 0}),J&&(0,l.jsx)(d,{label:`spawns left`,value:Number.isFinite(J.remaining)?J.remaining:`∞`,accent:J.remaining===0?`error`:void 0})]})}],X={title:`Auth Tokens`,view:`settings`,cta:`open settings`,body:(0,l.jsx)(f,{tokenStats:_?.tokenStats})},Z={title:`Governance Advisory`,view:`fleet`,cta:`open fleet`,body:S.length===0?(0,l.jsx)(`div`,{className:`hq-empty hq-cockpit-empty`,children:`No project governance snapshots yet.`}):(0,l.jsx)(`div`,{className:`hq-cockpit-alert-list`,children:S.map(e=>{let t=e.governance;return t===void 0?null:(0,l.jsxs)(`div`,{className:`hq-cockpit-alert-row`,children:[(0,l.jsx)(`span`,{className:`hq-pill ${t.signal.level===`healthy`?`green`:t.signal.level===`notice`?`warn`:`error`}`,children:t.signal.level}),(0,l.jsx)(`span`,{children:e.projectName}),(0,l.jsx)(`span`,{className:`hq-mono hq-cockpit-alert-msg`,children:t.signal.code}),(0,l.jsx)(`span`,{className:`hq-mono hq-text-dim hq-ml-auto`,children:t.signal.executionDisposition})]},e.projectId)})})},Q={title:`Alerts`,view:`alerts`,cta:`open alerts`,body:U.length===0?(0,l.jsx)(`div`,{className:`hq-empty hq-cockpit-empty`,children:`No alerts in the last few minutes.`}):(0,l.jsx)(`div`,{className:`hq-cockpit-alert-list`,children:U.map((e,t)=>(0,l.jsxs)(`div`,{className:`hq-cockpit-alert-row`,children:[(0,l.jsx)(`span`,{className:`hq-pill `+h(e.severity),children:e.severity}),(0,l.jsx)(`span`,{className:`hq-mono`,children:e.ruleId}),(0,l.jsx)(`span`,{className:`hq-cockpit-alert-msg`,children:e.message}),(0,l.jsx)(`span`,{className:`hq-mono hq-text-dim hq-ml-auto`,children:m(e.timestamp)})]},`${e.ruleId}-${e.timestamp}-${t}`))})},$={title:`Cost`,view:`cost`,cta:`open cost`,body:G.length===0?(0,l.jsx)(`div`,{className:`hq-empty hq-cockpit-empty`,children:`No cost data yet — connect some clients.`}):(0,l.jsx)(`div`,{className:`hq-cockpit-cost-list`,children:G.map(e=>{let t=(_?.totalCostUsd??0)>0?e.totalCostUsd/_.totalCostUsd*100:0;return(0,l.jsxs)(`div`,{className:`hq-cockpit-cost-row`,children:[(0,l.jsxs)(`div`,{className:`hq-cockpit-cost-line`,children:[(0,l.jsx)(`span`,{className:`hq-cockpit-cost-name`,children:e.projectName}),(0,l.jsx)(`span`,{className:`hq-mono hq-text-dim`,children:e.projectId}),(0,l.jsxs)(`span`,{className:`hq-mono hq-cockpit-cost-amount hq-ml-auto`,children:[`$`,e.totalCostUsd.toFixed(4)]}),(0,l.jsxs)(`span`,{className:`hq-mono hq-text-dim`,children:[t.toFixed(1),`%`]})]}),(0,l.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,l.jsx)(`span`,{style:{width:`${Math.max(2,t)}%`}})}),(0,l.jsxs)(`div`,{className:`hq-cockpit-cost-meta`,children:[(0,l.jsxs)(`span`,{children:[e.activeSessions,` sessions`]}),(0,l.jsxs)(`span`,{children:[e.activeSubagents,` subagents`]}),(0,l.jsxs)(`span`,{children:[e.activeClients,` clients`]})]})]},e.projectId)})})};return(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`div`,{className:`hq-card-title`,children:`Cockpit`}),(0,l.jsxs)(`div`,{className:`hq-card hq-cockpit-summary`,children:[(0,l.jsxs)(`div`,{className:`hq-row`,children:[(0,l.jsx)(`span`,{className:`hq-pill info`,children:u?`connected`:`reconnecting`}),(0,l.jsxs)(`span`,{className:`hq-pill`,children:[_?.activeMachines??0,` machines`]}),(0,l.jsxs)(`span`,{className:`hq-pill`,children:[_?.activeSessions??0,` sessions`]}),(0,l.jsxs)(`span`,{className:`hq-pill`,children:[_?.activeAgents??0,` agents`]}),(0,l.jsxs)(`span`,{className:`hq-pill green`,children:[`$`,(_?.totalCostUsd??0).toFixed(2)]}),(D?.length??0)>0&&(0,l.jsxs)(`span`,{className:`hq-pill error`,children:[D?.length??0,` active alerts`]}),C.length>0&&(0,l.jsxs)(`span`,{className:`hq-pill error`,children:[C.length,` governance advisories`]}),j!==null&&(0,l.jsx)(`span`,{className:`hq-pill error`,children:j}),(0,l.jsx)(`button`,{type:`button`,className:`hq-btn secondary hq-ml-auto`,onClick:()=>s.getState().setActiveView(`fleet`),children:`Open Fleet`})]}),(0,l.jsxs)(`section`,{className:`hq-cockpit-actions`,"aria-label":`Cockpit quick actions`,children:[(0,l.jsxs)(`div`,{className:`hq-cockpit-actions-copy`,children:[(0,l.jsx)(`span`,{className:`hq-cockpit-section-title`,children:`Quick Actions`}),(0,l.jsx)(`span`,{className:`hq-mono`,children:E===null?`no controllable client connected`:`target ${p(E.clientId)}`})]}),(0,l.jsxs)(`div`,{className:`hq-cockpit-actions-buttons`,children:[(0,l.jsx)(`button`,{type:`button`,className:`hq-btn secondary`,disabled:E===null||N!==null,onClick:()=>void K(`pause-noisy`),children:N===`pause-noisy`?`Queuing…`:`Pause noisy agents`}),(0,l.jsx)(`button`,{type:`button`,className:`hq-btn secondary`,disabled:E===null||N!==null,onClick:()=>void K(`status-request`),children:N===`status-request`?`Queuing…`:`Broadcast status request`}),(0,l.jsx)(`button`,{type:`button`,className:`hq-btn secondary`,onClick:()=>s.getState().setActiveView(`control`),children:`Open Control`})]}),F!==null&&(0,l.jsx)(`span`,{className:`hq-pill info`,children:F}),L!==null&&(0,l.jsx)(`span`,{className:`hq-pill error`,children:L})]})]}),z!==null||V!==null?(0,l.jsxs)(`div`,{className:`hq-card hq-cockpit-section`,children:[(0,l.jsxs)(`div`,{className:`hq-row`,children:[(0,l.jsxs)(`span`,{className:`hq-cockpit-section-title`,children:[(0,l.jsx)(n,{size:14,style:{marginRight:`0.375rem`}}),`System Health`]}),(0,l.jsx)(`button`,{type:`button`,className:`hq-btn secondary hq-ml-auto`,onClick:()=>s.getState().setActiveView(`settings`),children:`open settings`})]}),V===null?z===null?null:(0,l.jsxs)(`div`,{className:`hq-cockpit-grid`,children:[(0,l.jsx)(d,{label:`status`,value:z.status,accent:z.status===`healthy`?`green`:`error`}),(0,l.jsx)(d,{label:`event log`,value:z.uptime.eventLogSize}),(0,l.jsx)(d,{label:`connections`,value:z.connections.total}),(0,l.jsx)(d,{label:`active`,value:z.connections.active,accent:z.connections.active>0?`green`:void 0}),(0,l.jsx)(d,{label:`stale`,value:z.connections.stale,accent:z.connections.stale>3?`warn`:void 0})]}):(0,l.jsx)(`div`,{className:`hq-empty hq-cockpit-empty`,children:V})]}):null,[...Y,Z,X,Q,$].map(e=>(0,l.jsxs)(`div`,{className:`hq-card hq-cockpit-section`,children:[(0,l.jsxs)(`div`,{className:`hq-row`,children:[(0,l.jsx)(`span`,{className:`hq-cockpit-section-title`,children:e.title}),(0,l.jsx)(`button`,{type:`button`,className:`hq-btn secondary hq-ml-auto`,onClick:()=>s.getState().setActiveView(e.view),children:e.cta})]}),e.body]},e.title))]})}function d({label:e,value:t,accent:n}){return(0,l.jsxs)(`div`,{className:`hq-stat`+(n?` ${n}`:``),children:[(0,l.jsx)(`span`,{className:`hq-stat-num`,children:t}),(0,l.jsx)(`span`,{className:`hq-stat-label`,children:e})]})}function f({tokenStats:e}){if(e===void 0)return(0,l.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,l.jsxs)(`fieldset`,{className:`hq-cockpit-grid`,"aria-label":`Auth token stats`,style:{border:0,margin:0,padding:0},children:[(0,l.jsx)(d,{label:`browser`,value:t}),(0,l.jsx)(d,{label:`client`,value:n}),(0,l.jsx)(d,{label:`total`,value:a}),(0,l.jsx)(d,{label:`expired`,value:r,accent:r>0?`error`:void 0}),(0,l.jsx)(d,{label:`expiring soon`,value:i,accent:i>0?`warn`:void 0})]})}function p(e){return e.length<=18?e:`${e.slice(0,9)}…${e.slice(-6)}`}function m(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleTimeString()}function h(e){return e===`critical`||e===`error`||e===`high`?`error`:e===`warn`||e===`warning`||e===`medium`?`warn`:e===`info`||e===`low`?`info`:`idle`}export{u as CockpitView};
1
+ import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{Wt as t,v as n}from"./icons-kYa9YuNu.js";import{i as r}from"./markdown-mWU1fYYi.js";import{c as i,p as a,s as o,u as s}from"./index-2juseZBv.js";var c=e(t(),1),l=r();function u(){let{snapshot:e,alerts:t,selectedClientId:r,connected:u}=s(a(e=>({snapshot:e.snapshot,alerts:e.alerts,selectedClientId:e.selectedClientId,connected:e.connected}))),g=e,_=g?.totals,v=g?.machines??[],y=g?.projects??[],b=g?.clients??[],x=g?.liveSessions??[],S=y.filter(e=>e.governance!==void 0),C=S.filter(e=>e.governance?.signal.level===`warning`||e.governance?.signal.level===`unavailable`),w=b.filter(e=>e.capabilities.includes(`control.receive`)),T=r??w[0]?.clientId??null,E=w.find(e=>e.clientId===T)??w[0]??null,[D,O]=(0,c.useState)([]),[k,A]=(0,c.useState)([]),[j,M]=(0,c.useState)(null),[N,P]=(0,c.useState)(null),[F,I]=(0,c.useState)(null),[L,R]=(0,c.useState)(null),[z,B]=(0,c.useState)(null),[V,H]=(0,c.useState)(null);(0,c.useEffect)(()=>{let e=!1,t=()=>{o(`/api/system/health`).then(t=>{e||(B(t),H(null))}).catch(t=>{e||H(t instanceof Error?t.message:String(t))})};t();let n=setInterval(t,3e4);return()=>{e=!0,clearInterval(n)}},[]),(0,c.useEffect)(()=>{let e=!1,t=()=>{o(`/api/alerts`).then(t=>{e||(O(t.active),A(t.history),M(null))}).catch(t=>{e||M(t instanceof Error?t.message:String(t))})};t();let n=setInterval(t,15e3);return()=>{e=!0,clearInterval(n)}},[]);let U=(0,c.useMemo)(()=>{let e=t.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()})),n=[...D??[],...k??[]].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,...n],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},[t,D,k]),W=(0,c.useMemo)(()=>{let e=0,t=0,n=0,r=0,i=0;for(let a of x){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}},[x]),G=(0,c.useMemo)(()=>[...y].sort((e,t)=>t.totalCostUsd-e.totalCostUsd).slice(0,4),[y]);async function K(e){if(E!==null){P(e),I(null),R(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 i(E.clientId,`broadcast`,t);I(`queued ${n.commandId}`)}catch(e){R(e instanceof Error?e.message:String(e))}finally{P(null)}}}let q=g?.fleets??[],J=(0,c.useMemo)(()=>{let e=0,t=0,n=0,r=0,i=0;for(let a of q)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},[q]),Y=[{title:`Fleet`,view:`fleet`,cta:`open fleet`,body:(0,l.jsxs)(`div`,{className:`hq-cockpit-grid`,children:[(0,l.jsx)(d,{label:`machines`,value:v.length}),(0,l.jsx)(d,{label:`clients`,value:b.length}),(0,l.jsx)(d,{label:`sessions`,value:W.activeSessions,accent:W.activeSessions>0?`green`:void 0}),(0,l.jsx)(d,{label:`agents`,value:W.total}),(0,l.jsx)(d,{label:`busy`,value:W.busy,accent:W.busy>0?`green`:void 0}),(0,l.jsx)(d,{label:`waiting`,value:W.waiting,accent:W.waiting>0?`warn`:void 0}),(0,l.jsx)(d,{label:`errored`,value:W.errored,accent:W.errored>0?`error`:void 0}),(0,l.jsx)(d,{label:`cost $`,value:(_?.totalCostUsd??0).toFixed(2),accent:`green`}),J&&(0,l.jsx)(d,{label:`spawns`,value:`${J.used}/${Number.isFinite(J.max)?J.max:`∞`}`,accent:J.mismatch>0?`warn`:void 0}),J&&(0,l.jsx)(d,{label:`spawns left`,value:Number.isFinite(J.remaining)?J.remaining:`∞`,accent:J.remaining===0?`error`:void 0})]})}],X={title:`Auth Tokens`,view:`settings`,cta:`open settings`,body:(0,l.jsx)(f,{tokenStats:_?.tokenStats})},Z={title:`Governance Advisory`,view:`fleet`,cta:`open fleet`,body:S.length===0?(0,l.jsx)(`div`,{className:`hq-empty hq-cockpit-empty`,children:`No project governance snapshots yet.`}):(0,l.jsx)(`div`,{className:`hq-cockpit-alert-list`,children:S.map(e=>{let t=e.governance;return t===void 0?null:(0,l.jsxs)(`div`,{className:`hq-cockpit-alert-row`,children:[(0,l.jsx)(`span`,{className:`hq-pill ${t.signal.level===`healthy`?`green`:t.signal.level===`notice`?`warn`:`error`}`,children:t.signal.level}),(0,l.jsx)(`span`,{children:e.projectName}),(0,l.jsx)(`span`,{className:`hq-mono hq-cockpit-alert-msg`,children:t.signal.code}),(0,l.jsx)(`span`,{className:`hq-mono hq-text-dim hq-ml-auto`,children:t.signal.executionDisposition})]},e.projectId)})})},Q={title:`Alerts`,view:`alerts`,cta:`open alerts`,body:U.length===0?(0,l.jsx)(`div`,{className:`hq-empty hq-cockpit-empty`,children:`No alerts in the last few minutes.`}):(0,l.jsx)(`div`,{className:`hq-cockpit-alert-list`,children:U.map((e,t)=>(0,l.jsxs)(`div`,{className:`hq-cockpit-alert-row`,children:[(0,l.jsx)(`span`,{className:`hq-pill `+h(e.severity),children:e.severity}),(0,l.jsx)(`span`,{className:`hq-mono`,children:e.ruleId}),(0,l.jsx)(`span`,{className:`hq-cockpit-alert-msg`,children:e.message}),(0,l.jsx)(`span`,{className:`hq-mono hq-text-dim hq-ml-auto`,children:m(e.timestamp)})]},`${e.ruleId}-${e.timestamp}-${t}`))})},$={title:`Cost`,view:`cost`,cta:`open cost`,body:G.length===0?(0,l.jsx)(`div`,{className:`hq-empty hq-cockpit-empty`,children:`No cost data yet — connect some clients.`}):(0,l.jsx)(`div`,{className:`hq-cockpit-cost-list`,children:G.map(e=>{let t=(_?.totalCostUsd??0)>0?e.totalCostUsd/_.totalCostUsd*100:0;return(0,l.jsxs)(`div`,{className:`hq-cockpit-cost-row`,children:[(0,l.jsxs)(`div`,{className:`hq-cockpit-cost-line`,children:[(0,l.jsx)(`span`,{className:`hq-cockpit-cost-name`,children:e.projectName}),(0,l.jsx)(`span`,{className:`hq-mono hq-text-dim`,children:e.projectId}),(0,l.jsxs)(`span`,{className:`hq-mono hq-cockpit-cost-amount hq-ml-auto`,children:[`$`,e.totalCostUsd.toFixed(4)]}),(0,l.jsxs)(`span`,{className:`hq-mono hq-text-dim`,children:[t.toFixed(1),`%`]})]}),(0,l.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,l.jsx)(`span`,{style:{width:`${Math.max(2,t)}%`}})}),(0,l.jsxs)(`div`,{className:`hq-cockpit-cost-meta`,children:[(0,l.jsxs)(`span`,{children:[e.activeSessions,` sessions`]}),(0,l.jsxs)(`span`,{children:[e.activeSubagents,` subagents`]}),(0,l.jsxs)(`span`,{children:[e.activeClients,` clients`]})]})]},e.projectId)})})};return(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`div`,{className:`hq-card-title`,children:`Cockpit`}),(0,l.jsxs)(`div`,{className:`hq-card hq-cockpit-summary`,children:[(0,l.jsxs)(`div`,{className:`hq-row`,children:[(0,l.jsx)(`span`,{className:`hq-pill info`,children:u?`connected`:`reconnecting`}),(0,l.jsxs)(`span`,{className:`hq-pill`,children:[_?.activeMachines??0,` machines`]}),(0,l.jsxs)(`span`,{className:`hq-pill`,children:[_?.activeSessions??0,` sessions`]}),(0,l.jsxs)(`span`,{className:`hq-pill`,children:[_?.activeAgents??0,` agents`]}),(0,l.jsxs)(`span`,{className:`hq-pill green`,children:[`$`,(_?.totalCostUsd??0).toFixed(2)]}),(D?.length??0)>0&&(0,l.jsxs)(`span`,{className:`hq-pill error`,children:[D?.length??0,` active alerts`]}),C.length>0&&(0,l.jsxs)(`span`,{className:`hq-pill error`,children:[C.length,` governance advisories`]}),j!==null&&(0,l.jsx)(`span`,{className:`hq-pill error`,children:j}),(0,l.jsx)(`button`,{type:`button`,className:`hq-btn secondary hq-ml-auto`,onClick:()=>s.getState().setActiveView(`fleet`),children:`Open Fleet`})]}),(0,l.jsxs)(`section`,{className:`hq-cockpit-actions`,"aria-label":`Cockpit quick actions`,children:[(0,l.jsxs)(`div`,{className:`hq-cockpit-actions-copy`,children:[(0,l.jsx)(`span`,{className:`hq-cockpit-section-title`,children:`Quick Actions`}),(0,l.jsx)(`span`,{className:`hq-mono`,children:E===null?`no controllable client connected`:`target ${p(E.clientId)}`})]}),(0,l.jsxs)(`div`,{className:`hq-cockpit-actions-buttons`,children:[(0,l.jsx)(`button`,{type:`button`,className:`hq-btn secondary`,disabled:E===null||N!==null,onClick:()=>void K(`pause-noisy`),children:N===`pause-noisy`?`Queuing…`:`Pause noisy agents`}),(0,l.jsx)(`button`,{type:`button`,className:`hq-btn secondary`,disabled:E===null||N!==null,onClick:()=>void K(`status-request`),children:N===`status-request`?`Queuing…`:`Broadcast status request`}),(0,l.jsx)(`button`,{type:`button`,className:`hq-btn secondary`,onClick:()=>s.getState().setActiveView(`control`),children:`Open Control`})]}),F!==null&&(0,l.jsx)(`span`,{className:`hq-pill info`,children:F}),L!==null&&(0,l.jsx)(`span`,{className:`hq-pill error`,children:L})]})]}),z!==null||V!==null?(0,l.jsxs)(`div`,{className:`hq-card hq-cockpit-section`,children:[(0,l.jsxs)(`div`,{className:`hq-row`,children:[(0,l.jsxs)(`span`,{className:`hq-cockpit-section-title`,children:[(0,l.jsx)(n,{size:14,style:{marginRight:`0.375rem`}}),`System Health`]}),(0,l.jsx)(`button`,{type:`button`,className:`hq-btn secondary hq-ml-auto`,onClick:()=>s.getState().setActiveView(`settings`),children:`open settings`})]}),V===null?z===null?null:(0,l.jsxs)(`div`,{className:`hq-cockpit-grid`,children:[(0,l.jsx)(d,{label:`status`,value:z.status,accent:z.status===`healthy`?`green`:`error`}),(0,l.jsx)(d,{label:`event log`,value:z.uptime.eventLogSize}),(0,l.jsx)(d,{label:`connections`,value:z.connections.total}),(0,l.jsx)(d,{label:`active`,value:z.connections.active,accent:z.connections.active>0?`green`:void 0}),(0,l.jsx)(d,{label:`stale`,value:z.connections.stale,accent:z.connections.stale>3?`warn`:void 0})]}):(0,l.jsx)(`div`,{className:`hq-empty hq-cockpit-empty`,children:V})]}):null,[...Y,Z,X,Q,$].map(e=>(0,l.jsxs)(`div`,{className:`hq-card hq-cockpit-section`,children:[(0,l.jsxs)(`div`,{className:`hq-row`,children:[(0,l.jsx)(`span`,{className:`hq-cockpit-section-title`,children:e.title}),(0,l.jsx)(`button`,{type:`button`,className:`hq-btn secondary hq-ml-auto`,onClick:()=>s.getState().setActiveView(e.view),children:e.cta})]}),e.body]},e.title))]})}function d({label:e,value:t,accent:n}){return(0,l.jsxs)(`div`,{className:`hq-stat`+(n?` ${n}`:``),children:[(0,l.jsx)(`span`,{className:`hq-stat-num`,children:t}),(0,l.jsx)(`span`,{className:`hq-stat-label`,children:e})]})}function f({tokenStats:e}){if(e===void 0)return(0,l.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,l.jsxs)(`fieldset`,{className:`hq-cockpit-grid`,"aria-label":`Auth token stats`,style:{border:0,margin:0,padding:0},children:[(0,l.jsx)(d,{label:`browser`,value:t}),(0,l.jsx)(d,{label:`client`,value:n}),(0,l.jsx)(d,{label:`total`,value:a}),(0,l.jsx)(d,{label:`expired`,value:r,accent:r>0?`error`:void 0}),(0,l.jsx)(d,{label:`expiring soon`,value:i,accent:i>0?`warn`:void 0})]})}function p(e){return e.length<=18?e:`${e.slice(0,9)}…${e.slice(-6)}`}function m(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleTimeString()}function h(e){return e===`critical`||e===`error`||e===`high`?`error`:e===`warn`||e===`warning`||e===`medium`?`warn`:e===`info`||e===`low`?`info`:`idle`}export{u as CockpitView};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{Bt as t,F as n,L as r,W as i,Wt as a,c as ee,d as o,k as s,t as c}from"./icons-kYa9YuNu.js";import{i as l}from"./markdown-mWU1fYYi.js";import{c as te,o as ne,p as re,r as u,s as d,u as f}from"./index-DIscZlJt.js";var p=e(a(),1),m=l(),h={steer:{label:`steer`,icon:(0,m.jsx)(c,{size:13}),desc:`High-priority course correction — interrupts the agent at the next turn.`},btw:{label:`btw`,icon:(0,m.jsx)(n,{size:13}),desc:`Non-urgent FYI — rides alongside the run without interrupting it.`},queue:{label:`queue`,icon:(0,m.jsx)(i,{size:13}),desc:`Queue a prompt — picked up after the current run finishes.`},abort:{label:`abort`,icon:(0,m.jsx)(s,{size:13}),desc:`Stop the leader run or every subagent on the client. Destructive.`,danger:!0},spawn:{label:`spawn`,icon:(0,m.jsx)(t,{size:13}),desc:`Launch a role subagent (bug-hunter, critic, …) with an optional task.`},broadcast:{label:`broadcast`,icon:(0,m.jsx)(r,{size:13}),desc:`Mailbox message to every agent in the client’s project.`},"run-command":{label:`run-command`,icon:(0,m.jsx)(o,{size:13}),desc:`Route a shell command to the client. RCE-gated (--hq-allow-exec + control.execute).`,danger:!0}};function g(){let{snapshot:e,selectedClientId:t,commandStatuses:n}=f(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,o=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),s=ne().control,[c,l]=(0,p.useState)(s.cmdType),[g,b]=(0,p.useState)(`compose`),[x,oe]=(0,p.useState)(s.steerTo),[S,se]=(0,p.useState)(s.steerSubject),[C,w]=(0,p.useState)(s.steerBody),[T,ce]=(0,p.useState)(s.spawnRole),[E,le]=(0,p.useState)(s.spawnTask),[D,O]=(0,p.useState)(s.abortTarget),[k,ue]=(0,p.useState)(s.broadcastSubject),[A,de]=(0,p.useState)(s.broadcastBody),[j,fe]=(0,p.useState)(``),[M,pe]=(0,p.useState)(``),[N,P]=(0,p.useState)(``),[F,I]=(0,p.useState)(null),[L,R]=(0,p.useState)(null),[z,B]=(0,p.useState)(!1),[V,H]=(0,p.useState)([]),[me,U]=(0,p.useState)(!1),[W,G]=(0,p.useState)(null),[he,ge]=(0,p.useState)(null),K=(0,p.useMemo)(()=>ve(),[c,x,S,C,T,E,D,k,A,j,M]),q=K.risk===`danger`,J=c===`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 _e(e){l(e),u({cmdType:e}),Z()}async function Q(){U(!0),G(null);try{let e=await d(`/api/commands?limit=25`);H(e.commands.slice().reverse())}catch(e){G(e instanceof Error?e.message:String(e))}finally{U(!1)}}(0,p.useEffect)(()=>{Q();let e=setInterval(()=>{document.hidden||Q()},15e3);return()=>clearInterval(e)},[]),(0,p.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}`),ge(e.commandId),b(`compose`),P(``),Q()}catch(e){R(e instanceof Error?e.message:String(e))}finally{B(!1)}}}(0,p.useEffect)(()=>{let e=e=>{e.key!==`Enter`||!(e.ctrlKey||e.metaKey)||(e.preventDefault(),g===`compose`&&X?(b(`preview`),I(null),R(null)):g===`preview`&&Y&&!z&&$())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)});function ve(){if(c===`steer`||c===`btw`||c===`queue`){let e=C.trim(),t=c===`steer`?`Send high-priority steer to`:c===`btw`?`Post a non-urgent FYI (btw) to`:`Queue a prompt for`;return{type:c,payload:{to:x||`leader`,subject:S||`HQ ${c}`,body:C,priority:c===`steer`?`high`:`normal`},disabledReason:e.length===0?`Message body is required.`:null,risk:`normal`,summary:`${t} ${x||`leader`}.`}}if(c===`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(c===`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(c===`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,m.jsxs)(`div`,{className:`hq-empty`,children:[`No controllable clients connected. Clients must advertise the `,(0,m.jsx)(`code`,{children:`control.receive`}),` `,`capability (CLI/TUI/WebUI surfaces do this automatically when connected to HQ).`]}):(0,m.jsxs)(`div`,{className:`hq-control-grid`,children:[(0,m.jsxs)(`div`,{className:`hq-control-composer`,children:[(0,m.jsx)(`div`,{className:`hq-card-title`,children:`Command Target`}),(0,m.jsxs)(`div`,{className:`hq-card hq-control-target`,children:[(0,m.jsx)(`label`,{className:`hq-label`,htmlFor:`hq-control-client`,children:`Client`}),(0,m.jsx)(`select`,{id:`hq-control-client`,className:`hq-select`,value:i??``,onChange:e=>{f.getState().selectClient(e.target.value),Z()},children:r.map(t=>(0,m.jsx)(`option`,{value:t.clientId,children:ie(t,e)},t.clientId))}),a!==null&&(0,m.jsxs)(`div`,{className:`hq-control-meta`,children:[(0,m.jsxs)(`span`,{children:[(0,m.jsx)(`strong`,{children:`kind`}),` `,a.kind]}),(0,m.jsxs)(`span`,{children:[(0,m.jsx)(`strong`,{children:`host`}),` `,a.hostname??`unknown`]}),(0,m.jsxs)(`span`,{children:[(0,m.jsx)(`strong`,{children:`project`}),` `,a.projectId]}),(0,m.jsxs)(`span`,{children:[(0,m.jsx)(`strong`,{children:`client`}),` `,_(a.clientId)]}),o!==void 0&&(0,m.jsxs)(`span`,{children:[(0,m.jsx)(`strong`,{children:`session`}),` `,_(o.sessionId),` ·`,` `,o.agentCount,` agents`]})]})]}),(0,m.jsx)(`div`,{className:`hq-card-title`,children:`Command Type`}),(0,m.jsxs)(`fieldset`,{className:`hq-control-steps`,"aria-label":`Control command stages`,children:[(0,m.jsx)(`span`,{className:`hq-step active`,children:`1 compose`}),(0,m.jsx)(`span`,{className:`hq-step`+(g===`preview`?` active`:``),children:`2 preview`}),(0,m.jsx)(`span`,{className:`hq-step`+(F===null?``:` active`),children:`3 queued`})]}),(0,m.jsx)(`div`,{className:`hq-control-types`,children:Object.keys(h).map(e=>{let t=h[e];return(0,m.jsxs)(`button`,{type:`button`,title:t.desc,className:`hq-control-type`+(c===e?` selected`:``)+(t.danger===!0?` danger`:``),onClick:()=>_e(e),children:[t.icon,t.label]},e)})}),(0,m.jsxs)(`div`,{className:`hq-control-typedesc`,children:[h[c].danger===!0&&(0,m.jsx)(ee,{size:12}),h[c].desc]}),(0,m.jsxs)(`div`,{className:`hq-mt-12`,children:[(c===`steer`||c===`btw`||c===`queue`)&&(0,m.jsxs)(`div`,{className:`hq-card`,children:[(0,m.jsxs)(`label`,{className:`hq-label`,htmlFor:`hq-control-recipient`,children:[`To (agent address — e.g. `,(0,m.jsx)(`code`,{children:`leader`}),`, `,(0,m.jsx)(`code`,{children:`leader@sessionTag`}),`, or a subagent id)`]}),(0,m.jsx)(`input`,{id:`hq-control-recipient`,className:`hq-input`,value:x,onChange:e=>{oe(e.target.value),u({steerTo:e.target.value})},placeholder:`leader`}),(0,m.jsx)(`label`,{className:`hq-label hq-mt-8`,htmlFor:`hq-control-subject`,children:`Subject`}),(0,m.jsx)(`input`,{id:`hq-control-subject`,className:`hq-input`,value:S,onChange:e=>{se(e.target.value),u({steerSubject:e.target.value})}}),(0,m.jsx)(`label`,{className:`hq-label hq-mt-8`,htmlFor:`hq-control-body`,children:`Body`}),(0,m.jsx)(`textarea`,{id:`hq-control-body`,className:`hq-textarea`,value:C,onChange:e=>{w(e.target.value),u({steerBody:e.target.value})}})]}),c===`abort`&&(0,m.jsxs)(`div`,{className:`hq-card hq-card-danger`,children:[(0,m.jsx)(`label`,{className:`hq-label`,htmlFor:`hq-control-abort-target`,children:`Target`}),(0,m.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,m.jsx)(`option`,{value:`leader`,children:`leader (session leader)`}),(0,m.jsx)(`option`,{value:`fleet`,children:`fleet (all subagents)`})]}),(0,m.jsxs)(`div`,{className:`hq-control-warning`,children:[`Abort is destructive. Preview requires typing `,(0,m.jsx)(`strong`,{children:`ABORT`}),` before dispatch.`]})]}),c===`spawn`&&(0,m.jsxs)(`div`,{className:`hq-card`,children:[(0,m.jsx)(`label`,{className:`hq-label`,htmlFor:`hq-control-spawn-role`,children:`Role`}),(0,m.jsxs)(`select`,{id:`hq-control-spawn-role`,className:`hq-select`,value:T,onChange:e=>{ce(e.target.value),u({spawnRole:e.target.value})},children:[(0,m.jsx)(`option`,{value:`bug-hunter`,children:`bug-hunter`}),(0,m.jsx)(`option`,{value:`refactor-planner`,children:`refactor-planner`}),(0,m.jsx)(`option`,{value:`critic`,children:`critic`}),(0,m.jsx)(`option`,{value:`security-scanner`,children:`security-scanner`}),(0,m.jsx)(`option`,{value:`code-reviewer`,children:`code-reviewer`})]}),(0,m.jsx)(`label`,{className:`hq-label hq-mt-8`,htmlFor:`hq-control-spawn-task`,children:`Task (optional)`}),(0,m.jsx)(`textarea`,{id:`hq-control-spawn-task`,className:`hq-textarea`,value:E,onChange:e=>{le(e.target.value),u({spawnTask:e.target.value})},placeholder:`Describe the task…`})]}),c===`run-command`&&(0,m.jsxs)(`div`,{className:`hq-card hq-card-danger`,children:[(0,m.jsx)(`label`,{className:`hq-label`,htmlFor:`hq-control-run-command`,children:`Shell command`}),(0,m.jsx)(`textarea`,{id:`hq-control-run-command`,className:`hq-textarea`,value:j,onChange:e=>fe(e.target.value),placeholder:`pnpm test`}),(0,m.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,m.jsx)(`input`,{id:`hq-control-run-cwd`,className:`hq-input`,value:M,onChange:e=>pe(e.target.value),placeholder:``}),(0,m.jsxs)(`div`,{className:`hq-control-warning`,children:[`RCE-gated: the client must run with `,(0,m.jsx)(`code`,{children:`--hq-allow-exec`}),` and your token needs the `,(0,m.jsx)(`code`,{children:`control.execute`}),` capability — otherwise the server rejects this. Preview requires typing `,(0,m.jsx)(`strong`,{children:`RUN`}),` before dispatch.`]})]}),c===`broadcast`&&(0,m.jsxs)(`div`,{className:`hq-card`,children:[(0,m.jsx)(`label`,{className:`hq-label`,htmlFor:`hq-control-broadcast-subject`,children:`Subject`}),(0,m.jsx)(`input`,{id:`hq-control-broadcast-subject`,className:`hq-input`,value:k,onChange:e=>{ue(e.target.value),u({broadcastSubject:e.target.value})}}),(0,m.jsx)(`label`,{className:`hq-label hq-mt-8`,htmlFor:`hq-control-broadcast-body`,children:`Body`}),(0,m.jsx)(`textarea`,{id:`hq-control-broadcast-body`,className:`hq-textarea`,value:A,onChange:e=>{de(e.target.value),u({broadcastBody:e.target.value})}})]})]}),(0,m.jsx)(`div`,{className:`hq-card-title`,children:`Dispatch Gate`}),(0,m.jsxs)(`div`,{className:`hq-card hq-command-preview`+(K.risk===`danger`?` hq-card-danger`:``),children:[(0,m.jsxs)(`div`,{className:`hq-row`,children:[(0,m.jsx)(`span`,{className:`hq-pill `+(K.risk===`danger`?`error`:`info`),children:K.risk}),(0,m.jsx)(`span`,{children:K.summary}),K.disabledReason!==null&&(0,m.jsx)(`span`,{className:`hq-pill warn`,children:K.disabledReason})]}),g===`preview`?(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(`div`,{className:`hq-msg-sublabel`,children:`payload preview`}),(0,m.jsx)(`pre`,{className:`hq-msg-pre`,children:JSON.stringify({clientId:i,type:K.type,payload:K.payload},null,2)}),q&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(`label`,{className:`hq-label hq-mt-12`,htmlFor:`hq-control-confirm`,children:`Confirm destructive dispatch`}),(0,m.jsx)(`input`,{id:`hq-control-confirm`,className:`hq-input`,value:N,onChange:e=>P(e.target.value),placeholder:`Type ${J}`})]}),(0,m.jsxs)(`div`,{className:`hq-row hq-mt-12`,children:[(0,m.jsx)(`button`,{type:`button`,className:`hq-btn`,disabled:z||!Y,onClick:()=>void $(),title:`Ctrl+Enter`,children:z?`Dispatching…`:`Dispatch Command`}),(0,m.jsx)(`button`,{type:`button`,className:`hq-btn secondary`,disabled:z,onClick:Z,children:`Back to Compose`})]})]}):(0,m.jsx)(`button`,{type:`button`,className:`hq-btn`,disabled:!X,onClick:()=>{b(`preview`),I(null),R(null)},title:`Ctrl+Enter`,children:`Preview Command`})]}),F&&(0,m.jsx)(`div`,{className:`hq-pill active hq-mt-12`,children:F}),L&&(0,m.jsx)(`div`,{className:`hq-pill error hq-mt-12`,children:L})]}),(0,m.jsxs)(`div`,{className:`hq-control-audit`,children:[(0,m.jsx)(`div`,{className:`hq-card-title`,children:`Command Audit`}),(0,m.jsxs)(`div`,{className:`hq-card hq-command-audit`,children:[(0,m.jsxs)(`div`,{className:`hq-row`,children:[(0,m.jsxs)(`span`,{className:`hq-pill info`,children:[`recent `,V.length]}),me&&(0,m.jsx)(`span`,{className:`hq-pill idle`,children:`refreshing`}),W!==null&&(0,m.jsx)(`span`,{className:`hq-pill error`,children:W}),(0,m.jsx)(`button`,{type:`button`,className:`hq-btn secondary hq-ml-auto`,onClick:()=>void Q(),children:`Refresh`})]}),V.length===0?(0,m.jsx)(`div`,{className:`hq-empty hq-cockpit-empty`,children:`No command audit entries yet.`}):(0,m.jsx)(`div`,{className:`hq-audit-list`,children:V.map(e=>(0,m.jsxs)(`div`,{className:`hq-audit-row`+(e.commandId===he?` just-dispatched`:``)+(i!==null&&e.clientId===i?``:` other-client`),children:[(0,m.jsxs)(`div`,{className:`hq-audit-main`,children:[(0,m.jsx)(`span`,{className:`hq-pill `+ae(e),children:e.status}),(0,m.jsx)(`span`,{className:`hq-pill info`,children:e.type}),(0,m.jsx)(`span`,{className:`hq-mono`,children:_(e.commandId)}),e.ackStatus!==void 0&&(0,m.jsxs)(`span`,{className:`hq-pill `+y(e.ackStatus),children:[`ack `,e.ackStatus]})]}),(0,m.jsxs)(`div`,{className:`hq-audit-meta`,children:[(0,m.jsxs)(`span`,{children:[(0,m.jsx)(`strong`,{children:`client`}),` `,_(e.clientId)]}),(0,m.jsxs)(`span`,{children:[(0,m.jsx)(`strong`,{children:`by`}),` `,e.enqueuedBy]}),(0,m.jsxs)(`span`,{children:[(0,m.jsx)(`strong`,{children:`queued`}),` `,v(e.enqueuedAt)]}),e.ackedAt!==void 0&&(0,m.jsxs)(`span`,{children:[(0,m.jsx)(`strong`,{children:`acked`}),` `,v(e.ackedAt)]})]}),e.ackMessage!==void 0&&e.ackMessage.length>0&&(0,m.jsx)(`div`,{className:`hq-audit-message`,children:e.ackMessage})]},e.commandId))})]})]})]})}function _(e){return e.length>18?`${e.slice(0,10)}…${e.slice(-6)}`:e}function ie(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 ae(e){return e.ackStatus===`failed`||e.ackStatus===`rejected`?`error`:e.status===`acked`?`active`:e.status===`delivered`?`info`:e.status===`queued`?`warn`:`idle`}function y(e){return e===`failed`||e===`rejected`?`error`:e===`completed`?`active`:`info`}export{g as ControlView};
1
+ import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{Bt as t,F as n,L as r,W as i,Wt as a,c as ee,d as o,k as s,t as c}from"./icons-kYa9YuNu.js";import{i as l}from"./markdown-mWU1fYYi.js";import{c as te,o as ne,p as re,r as u,s as d,u as f}from"./index-2juseZBv.js";var p=e(a(),1),m=l(),h={steer:{label:`steer`,icon:(0,m.jsx)(c,{size:13}),desc:`High-priority course correction — interrupts the agent at the next turn.`},btw:{label:`btw`,icon:(0,m.jsx)(n,{size:13}),desc:`Non-urgent FYI — rides alongside the run without interrupting it.`},queue:{label:`queue`,icon:(0,m.jsx)(i,{size:13}),desc:`Queue a prompt — picked up after the current run finishes.`},abort:{label:`abort`,icon:(0,m.jsx)(s,{size:13}),desc:`Stop the leader run or every subagent on the client. Destructive.`,danger:!0},spawn:{label:`spawn`,icon:(0,m.jsx)(t,{size:13}),desc:`Launch a role subagent (bug-hunter, critic, …) with an optional task.`},broadcast:{label:`broadcast`,icon:(0,m.jsx)(r,{size:13}),desc:`Mailbox message to every agent in the client’s project.`},"run-command":{label:`run-command`,icon:(0,m.jsx)(o,{size:13}),desc:`Route a shell command to the client. RCE-gated (--hq-allow-exec + control.execute).`,danger:!0}};function g(){let{snapshot:e,selectedClientId:t,commandStatuses:n}=f(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,o=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),s=ne().control,[c,l]=(0,p.useState)(s.cmdType),[g,b]=(0,p.useState)(`compose`),[x,oe]=(0,p.useState)(s.steerTo),[S,se]=(0,p.useState)(s.steerSubject),[C,w]=(0,p.useState)(s.steerBody),[T,ce]=(0,p.useState)(s.spawnRole),[E,le]=(0,p.useState)(s.spawnTask),[D,O]=(0,p.useState)(s.abortTarget),[k,ue]=(0,p.useState)(s.broadcastSubject),[A,de]=(0,p.useState)(s.broadcastBody),[j,fe]=(0,p.useState)(``),[M,pe]=(0,p.useState)(``),[N,P]=(0,p.useState)(``),[F,I]=(0,p.useState)(null),[L,R]=(0,p.useState)(null),[z,B]=(0,p.useState)(!1),[V,H]=(0,p.useState)([]),[me,U]=(0,p.useState)(!1),[W,G]=(0,p.useState)(null),[he,ge]=(0,p.useState)(null),K=(0,p.useMemo)(()=>ve(),[c,x,S,C,T,E,D,k,A,j,M]),q=K.risk===`danger`,J=c===`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 _e(e){l(e),u({cmdType:e}),Z()}async function Q(){U(!0),G(null);try{let e=await d(`/api/commands?limit=25`);H(e.commands.slice().reverse())}catch(e){G(e instanceof Error?e.message:String(e))}finally{U(!1)}}(0,p.useEffect)(()=>{Q();let e=setInterval(()=>{document.hidden||Q()},15e3);return()=>clearInterval(e)},[]),(0,p.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}`),ge(e.commandId),b(`compose`),P(``),Q()}catch(e){R(e instanceof Error?e.message:String(e))}finally{B(!1)}}}(0,p.useEffect)(()=>{let e=e=>{e.key!==`Enter`||!(e.ctrlKey||e.metaKey)||(e.preventDefault(),g===`compose`&&X?(b(`preview`),I(null),R(null)):g===`preview`&&Y&&!z&&$())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)});function ve(){if(c===`steer`||c===`btw`||c===`queue`){let e=C.trim(),t=c===`steer`?`Send high-priority steer to`:c===`btw`?`Post a non-urgent FYI (btw) to`:`Queue a prompt for`;return{type:c,payload:{to:x||`leader`,subject:S||`HQ ${c}`,body:C,priority:c===`steer`?`high`:`normal`},disabledReason:e.length===0?`Message body is required.`:null,risk:`normal`,summary:`${t} ${x||`leader`}.`}}if(c===`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(c===`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(c===`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,m.jsxs)(`div`,{className:`hq-empty`,children:[`No controllable clients connected. Clients must advertise the `,(0,m.jsx)(`code`,{children:`control.receive`}),` `,`capability (CLI/TUI/WebUI surfaces do this automatically when connected to HQ).`]}):(0,m.jsxs)(`div`,{className:`hq-control-grid`,children:[(0,m.jsxs)(`div`,{className:`hq-control-composer`,children:[(0,m.jsx)(`div`,{className:`hq-card-title`,children:`Command Target`}),(0,m.jsxs)(`div`,{className:`hq-card hq-control-target`,children:[(0,m.jsx)(`label`,{className:`hq-label`,htmlFor:`hq-control-client`,children:`Client`}),(0,m.jsx)(`select`,{id:`hq-control-client`,className:`hq-select`,value:i??``,onChange:e=>{f.getState().selectClient(e.target.value),Z()},children:r.map(t=>(0,m.jsx)(`option`,{value:t.clientId,children:ie(t,e)},t.clientId))}),a!==null&&(0,m.jsxs)(`div`,{className:`hq-control-meta`,children:[(0,m.jsxs)(`span`,{children:[(0,m.jsx)(`strong`,{children:`kind`}),` `,a.kind]}),(0,m.jsxs)(`span`,{children:[(0,m.jsx)(`strong`,{children:`host`}),` `,a.hostname??`unknown`]}),(0,m.jsxs)(`span`,{children:[(0,m.jsx)(`strong`,{children:`project`}),` `,a.projectId]}),(0,m.jsxs)(`span`,{children:[(0,m.jsx)(`strong`,{children:`client`}),` `,_(a.clientId)]}),o!==void 0&&(0,m.jsxs)(`span`,{children:[(0,m.jsx)(`strong`,{children:`session`}),` `,_(o.sessionId),` ·`,` `,o.agentCount,` agents`]})]})]}),(0,m.jsx)(`div`,{className:`hq-card-title`,children:`Command Type`}),(0,m.jsxs)(`fieldset`,{className:`hq-control-steps`,"aria-label":`Control command stages`,children:[(0,m.jsx)(`span`,{className:`hq-step active`,children:`1 compose`}),(0,m.jsx)(`span`,{className:`hq-step`+(g===`preview`?` active`:``),children:`2 preview`}),(0,m.jsx)(`span`,{className:`hq-step`+(F===null?``:` active`),children:`3 queued`})]}),(0,m.jsx)(`div`,{className:`hq-control-types`,children:Object.keys(h).map(e=>{let t=h[e];return(0,m.jsxs)(`button`,{type:`button`,title:t.desc,className:`hq-control-type`+(c===e?` selected`:``)+(t.danger===!0?` danger`:``),onClick:()=>_e(e),children:[t.icon,t.label]},e)})}),(0,m.jsxs)(`div`,{className:`hq-control-typedesc`,children:[h[c].danger===!0&&(0,m.jsx)(ee,{size:12}),h[c].desc]}),(0,m.jsxs)(`div`,{className:`hq-mt-12`,children:[(c===`steer`||c===`btw`||c===`queue`)&&(0,m.jsxs)(`div`,{className:`hq-card`,children:[(0,m.jsxs)(`label`,{className:`hq-label`,htmlFor:`hq-control-recipient`,children:[`To (agent address — e.g. `,(0,m.jsx)(`code`,{children:`leader`}),`, `,(0,m.jsx)(`code`,{children:`leader@sessionTag`}),`, or a subagent id)`]}),(0,m.jsx)(`input`,{id:`hq-control-recipient`,className:`hq-input`,value:x,onChange:e=>{oe(e.target.value),u({steerTo:e.target.value})},placeholder:`leader`}),(0,m.jsx)(`label`,{className:`hq-label hq-mt-8`,htmlFor:`hq-control-subject`,children:`Subject`}),(0,m.jsx)(`input`,{id:`hq-control-subject`,className:`hq-input`,value:S,onChange:e=>{se(e.target.value),u({steerSubject:e.target.value})}}),(0,m.jsx)(`label`,{className:`hq-label hq-mt-8`,htmlFor:`hq-control-body`,children:`Body`}),(0,m.jsx)(`textarea`,{id:`hq-control-body`,className:`hq-textarea`,value:C,onChange:e=>{w(e.target.value),u({steerBody:e.target.value})}})]}),c===`abort`&&(0,m.jsxs)(`div`,{className:`hq-card hq-card-danger`,children:[(0,m.jsx)(`label`,{className:`hq-label`,htmlFor:`hq-control-abort-target`,children:`Target`}),(0,m.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,m.jsx)(`option`,{value:`leader`,children:`leader (session leader)`}),(0,m.jsx)(`option`,{value:`fleet`,children:`fleet (all subagents)`})]}),(0,m.jsxs)(`div`,{className:`hq-control-warning`,children:[`Abort is destructive. Preview requires typing `,(0,m.jsx)(`strong`,{children:`ABORT`}),` before dispatch.`]})]}),c===`spawn`&&(0,m.jsxs)(`div`,{className:`hq-card`,children:[(0,m.jsx)(`label`,{className:`hq-label`,htmlFor:`hq-control-spawn-role`,children:`Role`}),(0,m.jsxs)(`select`,{id:`hq-control-spawn-role`,className:`hq-select`,value:T,onChange:e=>{ce(e.target.value),u({spawnRole:e.target.value})},children:[(0,m.jsx)(`option`,{value:`bug-hunter`,children:`bug-hunter`}),(0,m.jsx)(`option`,{value:`refactor-planner`,children:`refactor-planner`}),(0,m.jsx)(`option`,{value:`critic`,children:`critic`}),(0,m.jsx)(`option`,{value:`security-scanner`,children:`security-scanner`}),(0,m.jsx)(`option`,{value:`code-reviewer`,children:`code-reviewer`})]}),(0,m.jsx)(`label`,{className:`hq-label hq-mt-8`,htmlFor:`hq-control-spawn-task`,children:`Task (optional)`}),(0,m.jsx)(`textarea`,{id:`hq-control-spawn-task`,className:`hq-textarea`,value:E,onChange:e=>{le(e.target.value),u({spawnTask:e.target.value})},placeholder:`Describe the task…`})]}),c===`run-command`&&(0,m.jsxs)(`div`,{className:`hq-card hq-card-danger`,children:[(0,m.jsx)(`label`,{className:`hq-label`,htmlFor:`hq-control-run-command`,children:`Shell command`}),(0,m.jsx)(`textarea`,{id:`hq-control-run-command`,className:`hq-textarea`,value:j,onChange:e=>fe(e.target.value),placeholder:`pnpm test`}),(0,m.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,m.jsx)(`input`,{id:`hq-control-run-cwd`,className:`hq-input`,value:M,onChange:e=>pe(e.target.value),placeholder:``}),(0,m.jsxs)(`div`,{className:`hq-control-warning`,children:[`RCE-gated: the client must run with `,(0,m.jsx)(`code`,{children:`--hq-allow-exec`}),` and your token needs the `,(0,m.jsx)(`code`,{children:`control.execute`}),` capability — otherwise the server rejects this. Preview requires typing `,(0,m.jsx)(`strong`,{children:`RUN`}),` before dispatch.`]})]}),c===`broadcast`&&(0,m.jsxs)(`div`,{className:`hq-card`,children:[(0,m.jsx)(`label`,{className:`hq-label`,htmlFor:`hq-control-broadcast-subject`,children:`Subject`}),(0,m.jsx)(`input`,{id:`hq-control-broadcast-subject`,className:`hq-input`,value:k,onChange:e=>{ue(e.target.value),u({broadcastSubject:e.target.value})}}),(0,m.jsx)(`label`,{className:`hq-label hq-mt-8`,htmlFor:`hq-control-broadcast-body`,children:`Body`}),(0,m.jsx)(`textarea`,{id:`hq-control-broadcast-body`,className:`hq-textarea`,value:A,onChange:e=>{de(e.target.value),u({broadcastBody:e.target.value})}})]})]}),(0,m.jsx)(`div`,{className:`hq-card-title`,children:`Dispatch Gate`}),(0,m.jsxs)(`div`,{className:`hq-card hq-command-preview`+(K.risk===`danger`?` hq-card-danger`:``),children:[(0,m.jsxs)(`div`,{className:`hq-row`,children:[(0,m.jsx)(`span`,{className:`hq-pill `+(K.risk===`danger`?`error`:`info`),children:K.risk}),(0,m.jsx)(`span`,{children:K.summary}),K.disabledReason!==null&&(0,m.jsx)(`span`,{className:`hq-pill warn`,children:K.disabledReason})]}),g===`preview`?(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(`div`,{className:`hq-msg-sublabel`,children:`payload preview`}),(0,m.jsx)(`pre`,{className:`hq-msg-pre`,children:JSON.stringify({clientId:i,type:K.type,payload:K.payload},null,2)}),q&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(`label`,{className:`hq-label hq-mt-12`,htmlFor:`hq-control-confirm`,children:`Confirm destructive dispatch`}),(0,m.jsx)(`input`,{id:`hq-control-confirm`,className:`hq-input`,value:N,onChange:e=>P(e.target.value),placeholder:`Type ${J}`})]}),(0,m.jsxs)(`div`,{className:`hq-row hq-mt-12`,children:[(0,m.jsx)(`button`,{type:`button`,className:`hq-btn`,disabled:z||!Y,onClick:()=>void $(),title:`Ctrl+Enter`,children:z?`Dispatching…`:`Dispatch Command`}),(0,m.jsx)(`button`,{type:`button`,className:`hq-btn secondary`,disabled:z,onClick:Z,children:`Back to Compose`})]})]}):(0,m.jsx)(`button`,{type:`button`,className:`hq-btn`,disabled:!X,onClick:()=>{b(`preview`),I(null),R(null)},title:`Ctrl+Enter`,children:`Preview Command`})]}),F&&(0,m.jsx)(`div`,{className:`hq-pill active hq-mt-12`,children:F}),L&&(0,m.jsx)(`div`,{className:`hq-pill error hq-mt-12`,children:L})]}),(0,m.jsxs)(`div`,{className:`hq-control-audit`,children:[(0,m.jsx)(`div`,{className:`hq-card-title`,children:`Command Audit`}),(0,m.jsxs)(`div`,{className:`hq-card hq-command-audit`,children:[(0,m.jsxs)(`div`,{className:`hq-row`,children:[(0,m.jsxs)(`span`,{className:`hq-pill info`,children:[`recent `,V.length]}),me&&(0,m.jsx)(`span`,{className:`hq-pill idle`,children:`refreshing`}),W!==null&&(0,m.jsx)(`span`,{className:`hq-pill error`,children:W}),(0,m.jsx)(`button`,{type:`button`,className:`hq-btn secondary hq-ml-auto`,onClick:()=>void Q(),children:`Refresh`})]}),V.length===0?(0,m.jsx)(`div`,{className:`hq-empty hq-cockpit-empty`,children:`No command audit entries yet.`}):(0,m.jsx)(`div`,{className:`hq-audit-list`,children:V.map(e=>(0,m.jsxs)(`div`,{className:`hq-audit-row`+(e.commandId===he?` just-dispatched`:``)+(i!==null&&e.clientId===i?``:` other-client`),children:[(0,m.jsxs)(`div`,{className:`hq-audit-main`,children:[(0,m.jsx)(`span`,{className:`hq-pill `+ae(e),children:e.status}),(0,m.jsx)(`span`,{className:`hq-pill info`,children:e.type}),(0,m.jsx)(`span`,{className:`hq-mono`,children:_(e.commandId)}),e.ackStatus!==void 0&&(0,m.jsxs)(`span`,{className:`hq-pill `+y(e.ackStatus),children:[`ack `,e.ackStatus]})]}),(0,m.jsxs)(`div`,{className:`hq-audit-meta`,children:[(0,m.jsxs)(`span`,{children:[(0,m.jsx)(`strong`,{children:`client`}),` `,_(e.clientId)]}),(0,m.jsxs)(`span`,{children:[(0,m.jsx)(`strong`,{children:`by`}),` `,e.enqueuedBy]}),(0,m.jsxs)(`span`,{children:[(0,m.jsx)(`strong`,{children:`queued`}),` `,v(e.enqueuedAt)]}),e.ackedAt!==void 0&&(0,m.jsxs)(`span`,{children:[(0,m.jsx)(`strong`,{children:`acked`}),` `,v(e.ackedAt)]})]}),e.ackMessage!==void 0&&e.ackMessage.length>0&&(0,m.jsx)(`div`,{className:`hq-audit-message`,children:e.ackMessage})]},e.commandId))})]})]})]})}function _(e){return e.length>18?`${e.slice(0,10)}…${e.slice(-6)}`:e}function ie(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 ae(e){return e.ackStatus===`failed`||e.ackStatus===`rejected`?`error`:e.status===`acked`?`active`:e.status===`delivered`?`info`:e.status===`queued`?`warn`:`idle`}function y(e){return e===`failed`||e===`rejected`?`error`:e===`completed`?`active`:`info`}export{g as ControlView};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{Wt as t}from"./icons-kYa9YuNu.js";import{i as n}from"./markdown-mWU1fYYi.js";import{u as r}from"./index-DIscZlJt.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};
1
+ import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{Wt as t}from"./icons-kYa9YuNu.js";import{i as n}from"./markdown-mWU1fYYi.js";import{u as r}from"./index-2juseZBv.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};