@wrongstack/webui-hq 0.308.1 → 0.308.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-DBRfVjlr.js → alerts-CASro-zg.js} +1 -1
- package/dist/assets/{brain-BfTT2rcN.js → brain-yIDgS4vG.js} +1 -1
- package/dist/assets/{cockpit-BCvNdJd1.js → cockpit-qMcwPuag.js} +1 -1
- package/dist/assets/{control-DK48cpDK.js → control-YiwRf48C.js} +1 -1
- package/dist/assets/{cost-C9xhTig0.js → cost-EYiQcvHV.js} +1 -1
- package/dist/assets/{fleet-map-CsNaWo-Y.js → fleet-map-Chbzo4P_.js} +1 -1
- package/dist/assets/{fleet-topology-BrormAze.js → fleet-topology-I_zBJHSw.js} +1 -1
- package/dist/assets/index-C5Ihi44B.js +2 -0
- package/dist/assets/{kanban-BDIXTULT.js → kanban-ClEZyv0J.js} +1 -1
- package/dist/assets/{live-console-jFj-vYax.js → live-console-DXTeZHNx.js} +1 -1
- package/dist/assets/{mailbox-DtW6lHxd.js → mailbox-Z7GgSK__.js} +1 -1
- package/dist/assets/{settings-CJ13PbSG.js → settings-L17p0Bjr.js} +1 -1
- package/dist/assets/{trends-DAHAke9f.js → trends-B1FxOq-M.js} +1 -1
- package/dist/assets/{use-backfilled-events-DG-l6cEz.js → use-backfilled-events-CbvvmZr7.js} +1 -1
- package/dist/assets/{worktree-BaEL3foY.js → worktree-DgKbrwbZ.js} +1 -1
- package/dist/index.html +1 -1
- package/package.json +4 -4
- package/dist/assets/index-Da_ivWpO.js +0 -2
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/cockpit-qMcwPuag.js","assets/rolldown-runtime-hePW80VL.js","assets/icons-I81S_8cW.js","assets/markdown-C4I0Caum.js","assets/fleet-map-Chbzo4P_.js","assets/vendor-CWm0VQZ2.js","assets/fleet-topology-I_zBJHSw.js","assets/live-console-DXTeZHNx.js","assets/mailbox-Z7GgSK__.js","assets/use-backfilled-events-CbvvmZr7.js","assets/kanban-ClEZyv0J.js","assets/cost-EYiQcvHV.js","assets/brain-yIDgS4vG.js","assets/worktree-DgKbrwbZ.js","assets/trends-B1FxOq-M.js","assets/alerts-CASro-zg.js","assets/control-YiwRf48C.js","assets/settings-L17p0Bjr.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{$ as t,A as n,Ct as r,F as i,Ft as a,Gt as o,I as s,O as c,Pt as l,S as u,Tt as d,Ut as f,W as p,Xt as ee,Zt as m,a as te,bt as ne,d as re,h,i as ie,j as ae,kt as oe,l as g,n as se,nt as _,o as ce,qt as v,rt as y,ut as b,v as le,w as x,y as S,yt as ue,z as C}from"./icons-I81S_8cW.js";import{t as de}from"./vendor-CWm0VQZ2.js";import{i as w}from"./markdown-C4I0Caum.js";(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var T={maxReconnectAttempts:10,initialBackoffMs:1e3,maxBackoffMs:3e4,backoffMultiplier:2,jitterRatio:0,queueLimit:1e3,heartbeatIntervalMs:0,heartbeatTimeoutMs:0};function E(){return{phase:`idle`,reconnectAttempt:0,lastActivityAt:null,stopped:!1}}function fe(e){return e.stopped?e:{...e,phase:`connecting`}}function pe(e,t=Date.now()){return{...e,phase:`open`,reconnectAttempt:0,lastActivityAt:t,stopped:!1}}function D(e,t=Date.now()){return{...e,lastActivityAt:t}}function me(e){return{...e,phase:`closed`,stopped:!0}}function he(e,t,n=Date.now(),r=Math.random){if(e.stopped||e.reconnectAttempt>=t.maxReconnectAttempts)return{state:{...e,phase:`closed`},plan:null};let i=e.reconnectAttempt+1,a=Math.min(t.initialBackoffMs*t.backoffMultiplier**(i-1),t.maxBackoffMs),o=(r()*2-1)*t.jitterRatio,s=Math.max(0,Math.round(a*(1+o)));return{state:{...e,phase:`reconnecting`,reconnectAttempt:i},plan:{attempt:i,delayMs:s,retryAt:n+s}}}function O(e,t,n=Date.now()){return e.phase!==`open`||e.lastActivityAt===null||t.heartbeatIntervalMs<=0?!1:n-e.lastActivityAt>t.heartbeatIntervalMs+t.heartbeatTimeoutMs}var ge=`abort,ping,user_message,tool.confirm_result,topic.advice,completion.request,model.switch,model.refine,model.fallback_choice,autonomy.switch,context.clear,context.compact,context.debug,context.editor.open,context.editor.validate,context.editor.apply,context.mode.create,context.mode.delete,context.mode.switch,context.mode.update,context.modes.list,context.repair,mode.switch,modes.list,session.checkpoints,session.delete,session.inspect,session.new,session.rename,session.resume,session.rewind,session.save,sessions.list,side_effects.list,stats.get,todo.update,todos.clear,todos.get,todos.remove`.split(`,`),_e=[`collab.join`,`collab.leave`,`collab.annotate`,`collab.resolve`,`collab.request_pause`,`collab.resume`,`collab.grant_control`,`collab.inject_tool`,`mailbox.action`,`mailbox.agents`,`mailbox.clear`,`mailbox.compact`,`mailbox.messages`,`mailbox.purge`,`mailbox.send`],ve=`brain.ask,brain.config.get,brain.config.set,brain.risk,brain.status,chronicle.facet,chronicle.facets,chronicle.graph,chronicle.metrics,chronicle.query,chronicle.status,config.doctor,design.list,design.materialize,design.set,design.state,design.swap,design.tune,design.use,design.verify,memory.list,memory.sage.backfillRecoverable,memory.sage.candidateResolve,memory.sage.delete,memory.sage.forFile,memory.sage.get,memory.sage.graph,memory.sage.list,memory.sage.listCandidates,memory.sage.listPage,memory.sage.recover,memory.sage.remember,memory.sage.searchBreakdown,memory.sage.update`.split(`,`),ye=`auth.oauth.cancel,auth.oauth.code,auth.oauth.start,mcp.add,mcp.disable,mcp.discover,mcp.enable,mcp.list,mcp.prompt.get,mcp.prompts,mcp.remove,mcp.resource.read,mcp.resources,mcp.restart,mcp.sleep,mcp.update,mcp.wake,prompts.content,prompts.create,prompts.favorite,prompts.journal,prompts.list,prompts.recent,prompts.search,prompts.used,skills.content,skills.create,skills.edit,skills.export,skills.install,skills.list,skills.uninstall,skills.update`.split(`,`),be=`goal-state.get,goal.addTask,goal.assess,goal.assignTask,goal.clear,goal.get,goal.list,goal.load,goal.moveTask,goal.pause,goal.resume,goal.retryTask,goal.revert,goal.runTask,goal.save,goal.selectPhase,goal.start,goal.state,goal.status,goal.stop,goal.taskStatus,goal.toggleAutonomous,plan.get,plan.item.update,plan.template_use,task.update,tasks.get`.split(`,`),xe=`sdd.board.cancel_task,sdd.board.cleanup_worktrees,sdd.board.delete_task,sdd.board.destroy,sdd.board.get,sdd.board.list,sdd.board.pause,sdd.board.reassign,sdd.board.resume,sdd.board.retry,sdd.board.retry_all_failed,sdd.board.rollback,sdd.board.set_task_fallbacks,sdd.board.set_task_model,sdd.board.set_task_verification,sdd.board.split_task,sdd.board.stop,sdd.run.from_graph,sdd.run.from_spec,sdd.run.start,sdd.spec.approve,sdd.spec.discard,sdd.spec.get,sdd.spec.message,sdd.spec.rewind,sdd.spec.start,specs.get,specs.list,specs.taskStatus`.split(`,`),Se=`files.create,files.delete,files.list,files.move,files.read,files.rename,files.skeleton,files.tree,files.write,git.changes,git.diff,git.info,projects.add,projects.list,projects.select,working_dir.set,worktree.cleanup,worktree.diff,worktree.merge,worktree.remove,worktree.scan,shell.open,process.kill,process.killAll,process.list,terminal.close,terminal.create,terminal.input,terminal.resize`.split(`,`),Ce=`codebase.index.server.shutdown,connections.health,connections.service_action,diag.get,key.add,key.delete,key.set_active,key.update,prefs.get,prefs.update,provider.add,provider.clear_models,provider.custom_models.remove,provider.custom_models.set,provider.models,provider.models.search,provider.probe,provider.remove,provider.status.clear,provider.status.get,provider.status.retry,provider.undo_clear,provider.update,providers.list,providers.saved,tool.disable,tool.enable,tools.list,webui.shutdown`.split(`,`),we=`error,log,pong,side_effects,agent.status_changed,agent.timeline.message,client.status_update,chimera.report_available,compaction.failed,completion.result,context.compacted,context.debug,context.editor.snapshot,context.editor.validation,context.editor.applied,context.mode.changed,context.modes.list,context.repaired,ctx.max_context,ctx.pct,delegate.completed,delegate.started,iteration.completed,iteration.limit_reached,iteration.started,model.refine_result,modes.list,provider.active_blocked,provider.error,provider.fallback,provider.fallback_pending,provider.response,provider.retry,provider.status_changed,provider.stream_error,provider.text_delta,provider.thinking_delta,run.result,session.checkpoints,session.damaged,session.end,session.inspect,session.rewound,session.start,session.stats,sessions.list,sessions.status_update,stats.get,token.cost_estimate_unavailable,token.threshold,tool.confirm_needed,tool.disabled,tool.enabled,tool.executed,tool.loop_detected,tool.progress,tool.started,topic.advice_result,tools.list,trust.persisted`.split(`,`),Te=[`collab.annotation.added`,`collab.annotation.resolved`,`collab.event`,`collab.injection.granted`,`collab.participant.joined`,`collab.participant.left`,`collab.pause.granted`,`collab.pause.released`,`collab.state`,`mailbox.action_result`,`mailbox.agent_registered`,`mailbox.agent_deregistered`,`mailbox.agents`,`mailbox.cleared`,`mailbox.compacted`,`mailbox.event`,`mailbox.messages`,`mailbox.sent`,`mailbox.purged`,`mailbox.received`,`subagent.budget_extended`,`subagent.event`],Ee=`brain.answer,brain.config,brain.event,brain.status,chronicle.error,chronicle.facet_result,chronicle.facets_result,chronicle.graph_result,chronicle.metrics_result,chronicle.query_result,chronicle.status_result,config.doctor.result,design.list,design.materialize,design.set,design.state,design.swap,design.tune,design.use,design.verify,memory.event,memory.list,memory.sage.backfillRecoverable,memory.sage.candidateResolve,memory.sage.delete,memory.sage.forFile,memory.sage.get,memory.sage.graph,memory.sage.list,memory.sage.listCandidates,memory.sage.listPage,memory.sage.recover,memory.sage.remember,memory.sage.searchBreakdown,memory.sage.update`.split(`,`),De=`mcp.content.error,mcp.content.selected,mcp.list,mcp.operation_result,mcp.prompts,mcp.resources,mcp.server.added,mcp.server.connected,mcp.server.disconnected,mcp.server.discovered,mcp.server.error,mcp.server.reconnected,mcp.server.removed,mcp.server.sleeping,mcp.server.updated,mcp.server.waking,prompts.content,prompts.created,prompts.favorite,prompts.journal,prompts.list,prompts.recent,prompts.search,prompts.used,skills.content,skills.created,skills.edited,skills.exported,skills.installed,skills.list,skills.uninstalled,skills.updated`.split(`,`),Oe=`budget.decision,budget.threshold_reached,coordinator.stats,coordinator.status,eternal.iteration,fleet.concurrency_update,goal-state.updated,goal.assess.result,goal.list,goal.paused,goal.resumed,goal.saved,goal.error,goal.stopped,goal.failed,goal.completed,goal.cleared,goal.reverted,goal.progress,goal.state,in_flight.ended,in_flight.started,plan.updated,task.completed,task.failed,task.pending,task.started,tasks.updated,todos.cleared,todos.updated`.split(`,`),ke=[`kanban.task.activity`,`sdd.board.lifecycle_result`,`sdd.board.list`,`sdd.board.snapshot`,`sdd.run.started`,`sdd.spec.agent_text`,`sdd.spec.error`,`sdd.spec.snapshot`,`specs.detail`,`specs.list`],Ae=[`consensus.vote_cast`,`consensus.vote_initiated`,`consensus.vote_resolved`,`cron.job_fired`,`cron.snapshot`,`techstack.job.cancelled`,`techstack.job.failed`,`techstack.job.progress`,`techstack.job.started`,`techstack.report.delivered`,`techstack.report.ready`,`techstack.snapshot.updated`,`techstack.workspace.completed`],je=`checkpoint.written,codemap.file_event,codemap.index_updated,codemap.tool_executed,codemap.tool_started,file.saved,files.created,files.deleted,files.list,files.moved,files.read,files.renamed,files.skeleton_result,files.tree,files.tree.changed,files.written,git.changes,git.diff,git.info,process.list,projects.added,projects.list,projects.selected,terminal.exit,terminal.output,working_dir.changed,worktree.cleanup_result,worktree.diff_result,worktree.event,worktree.merge_result,worktree.orphans,worktree.state`.split(`,`),Me=[`auth.oauth.status`,`codebase.index.server.shutdown_result`,`connections.auto_heal_status`,`connections.health_error`,`connections.health_result`,`connections.service_action_result`,`diag.get`,`key.operation_result`,`model.switch_result`,`prefs.updated`,`provider.catalog`,`provider.models`,`provider.models.search_result`,`provider.probe`,`provider.status.snapshot`,`providers.saved`],Ne=[...ge,..._e,...Se,...Ce,...be,...xe,...ve,...ye],Pe=[...we,...Te,...je,...Me,...Oe,...ke,...Ae,...Ee,...De];new Set(Ne),new Set(Pe);function k(e){return typeof e==`object`&&e&&!Array.isArray(e)?e:null}function A(e,t=0){return typeof e==`number`&&Number.isFinite(e)?e:t}function Fe(e){return e===void 0||Array.isArray(e)}function Ie(e){return A(e.activeProjects)===e.activeProjects&&A(e.activeClients)===e.activeClients&&A(e.activeSessions)===e.activeSessions&&A(e.activeSubagents)===e.activeSubagents&&A(e.unreadMailboxMessages)===e.unreadMailboxMessages&&A(e.incompleteMailboxMessages)===e.incompleteMailboxMessages&&A(e.totalCostUsd)===e.totalCostUsd}function Le(e){if(e.type!==`hq.snapshot`)return null;let t=k(e.snapshot),n=t?k(t.totals):null;return!t||typeof t.generatedAt!=`string`||!Array.isArray(t.clients)||!Array.isArray(t.projects)||!Array.isArray(t.sessions)||!Array.isArray(t.fleets)||!Array.isArray(t.mailboxes)||!n||!Ie(n)||!Fe(t.machines)||!Fe(t.liveSessions)||!Fe(t.mcpServers)?null:{kind:`hq-snapshot`,snapshot:t}}function Re(e){if(e.type!==`hq.event`)return null;let t=k(e.event);return!t||typeof t.id!=`string`||typeof t.type!=`string`||typeof t.timestamp!=`string`||typeof t.clientId!=`string`||typeof t.projectId!=`string`||typeof t.seq!=`number`?null:{kind:`hq-event`,event:t}}function ze(e){return e.type!==`hq.alert`||typeof e.severity!=`string`||![`info`,`warn`,`error`].includes(e.severity)||typeof e.message!=`string`||typeof e.timestamp!=`string`?null:{kind:`hq-alert`,alert:e}}function Be(e){if(e.type!==`hq.command_status`)return null;let t=k(e.command);return!t||typeof t.commandId!=`string`||typeof t.type!=`string`||typeof t.clientId!=`string`||typeof t.enqueuedBy!=`string`||typeof t.enqueuedAt!=`string`||typeof t.status!=`string`||![`queued`,`delivered`,`acked`].includes(t.status)?null:{kind:`hq-command-status`,command:t}}var j=e(m(),1),Ve=de(),He=e=>Symbol.iterator in e,Ue=e=>`entries`in e,We=(e,t)=>{let n=e instanceof Map?e:new Map(e.entries()),r=t instanceof Map?t:new Map(t.entries());if(n.size!==r.size)return!1;for(let[e,t]of n)if(!r.has(e)||!Object.is(t,r.get(e)))return!1;return!0},Ge=(e,t)=>{let n=e[Symbol.iterator](),r=t[Symbol.iterator](),i=n.next(),a=r.next();for(;!i.done&&!a.done;){if(!Object.is(i.value,a.value))return!1;i=n.next(),a=r.next()}return!!i.done&&!!a.done};function Ke(e,t){return Object.is(e,t)?!0:typeof e!=`object`||!e||typeof t!=`object`||!t||Object.getPrototypeOf(e)!==Object.getPrototypeOf(t)?!1:He(e)&&He(t)?Ue(e)&&Ue(t)?We(e,t):Ge(e,t):We({entries:()=>Object.entries(e)},{entries:()=>Object.entries(t)})}function qe(e){let t=j.useRef(void 0);return n=>{let r=e(n);return Ke(t.current,r)?t.current:t.current=r}}var M=`wrongstack.hq.token.v1`;function Je(){if(typeof window>`u`)return null;try{let e=new URLSearchParams(window.location.search).get(`token`);return e!==null&&e.length>0?e:null}catch{return null}}function N(){if(typeof window>`u`)return null;try{return window.localStorage??null}catch{return null}}function P(){if(typeof window>`u`)return null;try{return window.sessionStorage??null}catch{return null}}function F(){try{let e=N()?.getItem(M)??null;if(e!==null&&e.length>0)return e}catch{}return Ye()}function Ye(){try{let e=P()?.getItem(M)??null;if(e===null||e.length===0)return null;let t=!1;try{let n=N();n!==null&&(n.setItem(M,e),t=n.getItem(M)===e)}catch{}if(t)try{P()?.removeItem(M)}catch{}return e}catch{return null}}function I(e){try{N()?.setItem(M,e)}catch{}}function L(){try{N()?.removeItem(M)}catch{}try{P()?.removeItem(M)}catch{}}function Xe(){let e=Je();return e===null?F():(I(e),e)}function Ze(){if(typeof window>`u`)return;let e=Je();if(e!==null&&(I(e),F()===e))try{let e=new URL(window.location.href);e.searchParams.delete(`token`),window.history.replaceState(null,``,`${e.pathname}${e.search}${e.hash}`)}catch{}}function Qe(){let e=Xe();return e===null?{}:{Authorization:`Bearer ${e}`}}function R(e,t){let n={...t?.headers??{},...Qe()};return fetch(e,{...t,headers:n})}function $e(e){let t=e.trim();if(!/[?&]token=/.test(t))return t;try{let e=typeof window>`u`?`http://127.0.0.1/`:window.location.href;return new URL(t,e).searchParams.get(`token`)?.trim()||t}catch{return t}}async function et(e){return fetch(`/api/auth/upgrade`,{method:`POST`,headers:{Authorization:`Bearer ${e}`},credentials:`same-origin`,signal:AbortSignal.timeout(1e4)})}async function tt(e){let t=$e(e);if(t.length===0)return{ok:!1,message:`Enter a browser token.`};try{let e=await et(t),n={};try{n=await e.json()}catch{}if(e.ok&&n.loggedIn===!0)return I(t),{ok:!0};let r=n.error;return{ok:!1,message:typeof r==`string`?r:typeof r?.message==`string`?r.message:e.status===401?`The browser token was rejected. It may be invalid, expired, or revoked.`:`HQ could not start a browser session with this token.`}}catch{return{ok:!1,message:`Could not reach the HQ server. Try again.`}}}function nt(){if(typeof window>`u`)return null;try{let e=window.location.hash;if(!e.startsWith(`#bootstrap=`))return null;let t=e.slice(11);return t.length>0?t:null}catch{return null}}function rt(){if(!(typeof window>`u`))try{let e=new URL(window.location.href);e.hash.startsWith(`#bootstrap=`)&&(e.hash=``,window.history.replaceState(null,``,`${e.pathname}${e.search}`))}catch{}}async function it(){let e=nt();if(e===null)return!1;try{return(await fetch(`/api/auth/bootstrap`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({code:e}),credentials:`same-origin`,signal:AbortSignal.timeout(1e4)})).ok?(rt(),L(),!0):!1}catch{return!1}}async function at(){let e=F();if(e===null)return!1;try{let t=await et(e);return!(!t.ok||(await t.json()).loggedIn!==!0)}catch{return!1}}var ot=e=>{let t,n=new Set,r=(e,r)=>{let i=typeof e==`function`?e(t):e;if(!Object.is(i,t)){let e=t;t=r??(typeof i!=`object`||!i)?i:Object.assign({},t,i),n.forEach(n=>n(t,e))}},i=()=>t,a={setState:r,getState:i,getInitialState:()=>o,subscribe:e=>(n.add(e),()=>n.delete(e))},o=t=e(r,i,a);return a},st=(e=>e?ot(e):ot),ct=e=>e;function lt(e,t=ct){let n=j.useSyncExternalStore(e.subscribe,j.useCallback(()=>t(e.getState()),[e,t]),j.useCallback(()=>t(e.getInitialState()),[e,t]));return j.useDebugValue(n),n}var ut=e=>{let t=st(e),n=e=>lt(t,e);return Object.assign(n,t),n},dt=(e=>e?ut(e):ut),ft=6e3,pt=0,mt=dt()(e=>({toasts:[],addToast:(t,n=`info`,r=ft,i)=>{let a=`toast-${++pt}-${Date.now()}`,o={id:a,message:t,severity:n,createdAt:Date.now(),ttlMs:r,action:i};e(e=>({toasts:[...e.toasts.slice(-4),o]})),r>0&&setTimeout(()=>{e(e=>({toasts:e.toasts.filter(e=>e.id!==a)}))},r)},removeToast:t=>e(e=>({toasts:e.toasts.filter(e=>e.id!==t)})),clearToasts:()=>e({toasts:[]})})),z=w(),ht={error:(0,z.jsx)(oe,{size:16,"aria-hidden":`true`}),warning:(0,z.jsx)(g,{size:16,"aria-hidden":`true`}),info:(0,z.jsx)(_,{size:16,"aria-hidden":`true`}),success:(0,z.jsx)(a,{size:16,"aria-hidden":`true`})};function gt(){let{toasts:e,removeToast:t}=mt(qe(e=>({toasts:e.toasts,removeToast:e.removeToast})));return e.length===0?null:(0,z.jsx)(`div`,{className:`hq-toast-container`,role:`status`,"aria-live":`polite`,"aria-label":`Notifications`,children:e.map(e=>(0,z.jsxs)(`div`,{className:`hq-toast hq-toast--${e.severity}`,"data-severity":e.severity,children:[(0,z.jsx)(`span`,{className:`hq-toast-icon`,children:ht[e.severity]}),(0,z.jsx)(`span`,{className:`hq-toast-message`,children:e.message}),e.action?(0,z.jsx)(`span`,{className:`hq-toast-action`,children:e.action}):null,(0,z.jsx)(`button`,{type:`button`,className:`hq-toast-close`,"aria-label":`Dismiss notification`,onClick:()=>t(e.id),children:(0,z.jsx)(se,{size:12})})]},e.id))})}var _t=new Set([`graceful`,`crash`,`heartbeat-timeout`,`auth-revoked`]),B=`__hq_peer__`;function vt(e){return e===void 0||typeof e==`string`}function yt(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=e;return!(typeof t.projectId!=`string`||t.projectId.length===0||typeof t.machineId!=`string`||t.machineId.length===0||typeof t.leaderClientId!=`string`||t.leaderClientId.length===0||typeof t.previousLeaderHandle!=`string`||t.previousLeaderHandle.length===0||typeof t.reason!=`string`||!_t.has(t.reason)||typeof t.detectedAt!=`string`||!Number.isFinite(Date.parse(t.detectedAt))||!vt(t.rehydrateHint)||t.rehydrateHint!==void 0&&t.rehydrateHint.length>280||!vt(t.rehydrateCommandId))}function bt(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=e;return!(typeof t.projectId!=`string`||t.projectId.length===0||typeof t.machineId!=`string`||t.machineId.length===0||typeof t.leaderClientId!=`string`||t.leaderClientId.length===0||typeof t.previousLeaderHandle!=`string`||t.previousLeaderHandle.length===0||typeof t.reason!=`string`||!_t.has(t.reason)||typeof t.detectedAt!=`string`||!Number.isFinite(Date.parse(t.detectedAt)))}function xt(e,t){let n=t.liveSessions??[],r=e.selectedSessionId===null?void 0:n.find(t=>t.sessionId===e.selectedSessionId),i=e.selectedAgentId===null||r?.agents.some(t=>t.id===e.selectedAgentId)===!0,a=e.selectedClientId===null||t.clients.some(t=>t.clientId===e.selectedClientId);return{snapshot:t,...e.selectedSessionId!==null&&r===void 0?{selectedSessionId:null,selectedAgentId:null}:i?{}:{selectedAgentId:null},...a?{}:{selectedClientId:null}}}function St(e,t){return e.timestamp===t.timestamp&&e.severity===t.severity&&e.message===t.message}var V=dt()(e=>({snapshot:null,events:[],alerts:[],commandStatuses:[],activeView:`cockpit`,selectedSessionId:null,selectedAgentId:null,selectedClientId:null,connected:!1,authRequired:!1,resumeCursors:{},needsSnapshotRefresh:!1,peerRehydrate:null,setActiveView:t=>e({activeView:t}),selectSession:(t,n=null)=>e({selectedSessionId:t,selectedAgentId:n}),selectAgent:(t,n)=>e({selectedSessionId:t,selectedAgentId:n}),selectClient:t=>e({selectedClientId:t}),markAuthRequired:()=>e(e=>e.authRequired?{}:{authRequired:!0}),_hydrateSnapshot:t=>e(e=>e.snapshot===null?xt(e,t):{}),_onSnapshot:t=>e(e=>{let n=e.snapshot;return n!==null&&typeof n.generatedAt==`string`&&typeof t.generatedAt==`string`&&Date.parse(t.generatedAt)<Date.parse(n.generatedAt)?{}:{...xt(e,t),connected:!0}}),_resetResumeCursors:()=>e({resumeCursors:{}}),_onEvent:t=>e(e=>{let n=e.events.some(e=>e.id===t.id),r=n?{}:{events:[...e.events,t].slice(-500)},i=t.type===`peer.rehydrate`||t.type===`peer.lost`?e=>({}):n=>{let r=e.resumeCursors[n]??0,i=t.seq,a=r>0&&i>0&&i<=r/2&&t.type!==`client.hello`;return i>r||a?{resumeCursors:{...e.resumeCursors,[n]:i}}:{}};if(t.type===`peer.rehydrate`){if(!yt(t.payload))return r;let e={kind:`peer.rehydrate`,payload:t.payload,receivedAt:new Date().toISOString()};return{...r,...i(B),...n?{}:{peerRehydrate:e}}}if(t.type===`peer.lost`){if(!bt(t.payload))return r;let e={kind:`peer.lost`,payload:t.payload,receivedAt:new Date().toISOString()};return{...r,...i(B),...n?{}:{peerRehydrate:e}}}return{...r,...i(t.clientId)}}),_onAlert:t=>e(e=>e.alerts.some(e=>St(e,t))?{}:{alerts:[...e.alerts,t].slice(-100)}),_onCommandStatus:t=>e(e=>{let n=e.commandStatuses.findIndex(e=>e.commandId===t.commandId);if(n<0)return{commandStatuses:[...e.commandStatuses,t].slice(-200)};let r=[...e.commandStatuses];return r[n]=t,{commandStatuses:r}}),_setConnected:t=>e({connected:t}),_setNeedsSnapshotRefresh:t=>e(e=>e.needsSnapshotRefresh===t?{}:{needsSnapshotRefresh:t}),_dismissPeerRehydrate:()=>e({peerRehydrate:null})}));async function H(e){let t;try{t=await R(e)}catch{throw Error(`Network error fetching ${e}`)}if(t.status===401)throw V.getState().markAuthRequired(),Error(`401 Unauthorized fetching ${e} — browser token required`);if(!t.ok)throw Error(`${t.status} ${t.statusText}`);try{return await t.json()}catch{throw Error(`Invalid JSON response from ${e}: ${t.status}`)}}async function Ct(e){let t;try{t=await R(`/api/mailbox-send`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)})}catch{throw Error(`Network error sending mailbox message`)}if(t.status===401)throw V.getState().markAuthRequired(),Error(`401 Unauthorized — browser token required`);if(!t.ok){let e=await t.json().catch(()=>null),n=typeof e?.error==`string`?e.error:t.statusText||`HTTP ${t.status}`;throw Error(n)}try{return await t.json()}catch{throw Error(`Invalid JSON response from mailbox-send API`)}}async function wt(e,t,n){let r;try{r=await R(`/api/command`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({clientId:e,type:t,payload:n})})}catch{throw Error(`Network error sending command`)}if(r.status===401)throw V.getState().markAuthRequired(),Error(`401 Unauthorized — browser token required`);if(!r.ok){let e=(await r.json().catch(()=>null))?.error??(r.statusText||`HTTP ${r.status}`);throw Error(e)}try{return await r.json()}catch{throw Error(`Invalid JSON response from command API`)}}var Tt=`wrongstack.hq.local-prefs.v1`,U={appearance:{theme:`dark`},fleet:{scope:`all`,layout:`map`,machineId:``,projectId:``},console:{delivery:`steer`,subject:``,body:``},control:{cmdType:`steer`,abortTarget:`leader`,spawnRole:`bug-hunter`,spawnTask:``,steerTo:`leader`,steerSubject:``,steerBody:``,broadcastSubject:``,broadcastBody:``},mailbox:{query:``,types:[],priorities:[],includeCompleted:!0}},W=null,Et=new Set;function G(){for(let e of Et)e()}function K(e){return typeof structuredClone==`function`?structuredClone(e):JSON.parse(JSON.stringify(e))}function q(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Dt(){if(typeof window>`u`||window.localStorage===void 0)return K(U);try{let e=window.localStorage.getItem(Tt);return e===null?K(U):Ot(JSON.parse(e))}catch{return K(U)}}function Ot(e){if(!q(e))return K(U);let t=q(e.appearance)?e.appearance:{},n=q(e.fleet)?e.fleet:{},r=q(e.console)?e.console:{},i=q(e.control)?e.control:{},a=q(e.mailbox)?e.mailbox:{};return{appearance:{theme:t.theme===`light`?`light`:`dark`},fleet:{scope:n.scope===`machine`||n.scope===`project`?n.scope:`all`,layout:n.layout===`compact`?`compact`:`map`,machineId:typeof n.machineId==`string`?n.machineId:``,projectId:typeof n.projectId==`string`?n.projectId:``},console:{delivery:r.delivery===`btw`||r.delivery===`queue`?r.delivery:`steer`,subject:typeof r.subject==`string`?r.subject:``,body:typeof r.body==`string`?r.body:``},control:{cmdType:i.cmdType===`btw`||i.cmdType===`queue`||i.cmdType===`abort`||i.cmdType===`spawn`||i.cmdType===`broadcast`||i.cmdType===`run-command`?i.cmdType:U.control.cmdType,abortTarget:i.abortTarget===`fleet`?`fleet`:`leader`,spawnRole:typeof i.spawnRole==`string`&&i.spawnRole.length>0?i.spawnRole:U.control.spawnRole,spawnTask:typeof i.spawnTask==`string`?i.spawnTask:U.control.spawnTask,steerTo:typeof i.steerTo==`string`?i.steerTo:U.control.steerTo,steerSubject:typeof i.steerSubject==`string`?i.steerSubject:U.control.steerSubject,steerBody:typeof i.steerBody==`string`?i.steerBody:U.control.steerBody,broadcastSubject:typeof i.broadcastSubject==`string`?i.broadcastSubject:U.control.broadcastSubject,broadcastBody:typeof i.broadcastBody==`string`?i.broadcastBody:U.control.broadcastBody},mailbox:{query:typeof a.query==`string`?a.query:U.mailbox.query,types:Array.isArray(a.types)?a.types.filter(e=>typeof e==`string`):[],priorities:Array.isArray(a.priorities)?a.priorities.filter(e=>typeof e==`string`):[],includeCompleted:typeof a.includeCompleted!=`boolean`||a.includeCompleted}}}function J(){return W===null&&(W=Dt()),W}function Y(e){if(!(typeof window>`u`||window.localStorage===void 0))try{window.localStorage.setItem(Tt,JSON.stringify(e))}catch{}}function kt(e){return Et.add(e),()=>Et.delete(e)}function At(){return J()}function jt(){return U}function Mt(){return(0,j.useSyncExternalStore)(kt,At,jt)}function Nt(e){let t=J();W={...t,control:{...t.control,...e}},Y(W),G()}function Pt(e){let t=J();W={...t,appearance:{...t.appearance,...e}},Y(W),G()}function Ft(e){let t=J();W={...t,fleet:{...t.fleet,...e}},Y(W),G()}function It(e){let t=J();W={...t,console:{...t.console,...e}},Y(W),G()}function Lt(e){let t=J();W={...t,mailbox:{...t.mailbox,...e}},Y(W),G()}function Rt({value:e,onChange:t,onKeyDown:n,inputRef:r,placeholder:i,autoComplete:a,minLength:o,maxLength:s,className:c,id:l}){let[u,d]=(0,j.useState)(!1);return(0,z.jsxs)(`div`,{className:`hq-password-input-wrapper`,children:[(0,z.jsx)(`input`,{ref:r,id:l,type:u?`text`:`password`,className:c??`hq-token-input`,placeholder:i,autoComplete:a,minLength:o,maxLength:s,value:e,onChange:e=>t(e.target.value),onKeyDown:n}),(0,z.jsx)(`button`,{type:`button`,className:`hq-password-toggle`,onMouseDown:e=>e.preventDefault(),onClick:()=>d(e=>!e),"aria-label":u?`Hide password`:`Show password`,"aria-pressed":u,children:u?(0,z.jsx)(ne,{size:14}):(0,z.jsx)(ue,{size:14})})]})}function zt({hadToken:e,onAuthenticated:t=()=>window.location.reload()}){let[n,r]=(0,j.useState)(null),[i,a]=(0,j.useState)(null);(0,j.useEffect)(()=>{fetch(`/api/auth/status`).then(async e=>{if(!e.ok)throw Error(`HTTP ${e.status}`);return await e.json()}).then(r).catch(()=>a(`Could not load HQ auth status.`))},[]);let o=n?.tokenMode??!0,s=n?.passwordMode??!1,[c,l]=(0,j.useState)(null),u=c??(e&&o?`token`:s?`password`:`token`);return i?(0,z.jsx)(`div`,{className:`hq-token-gate`,children:(0,z.jsxs)(`div`,{className:`hq-token-card`,children:[(0,z.jsx)(`div`,{className:`hq-brand`,children:`WrongStack HQ`}),(0,z.jsx)(`div`,{className:`hq-token-title`,children:`Auth status unavailable`}),(0,z.jsx)(`p`,{className:`hq-token-text`,children:i})]})}):n?(0,z.jsx)(`div`,{className:`hq-token-gate`,children:(0,z.jsxs)(`div`,{className:`hq-token-card`,children:[(0,z.jsx)(`div`,{className:`hq-brand`,children:`WrongStack HQ`}),o&&s?(0,z.jsxs)(`div`,{className:`hq-token-tabs`,children:[(0,z.jsx)(`button`,{type:`button`,className:`hq-token-tab`+(u===`token`?` active`:``),onClick:()=>l(`token`),children:`Browser token`}),(0,z.jsx)(`button`,{type:`button`,className:`hq-token-tab`+(u===`password`?` active`:``),onClick:()=>l(`password`),children:`Password`})]}):null,u===`token`||!s?(0,z.jsx)(Bt,{hadToken:e,onAuthenticated:t}):(0,z.jsx)(Vt,{})]})}):(0,z.jsx)(`div`,{className:`hq-token-gate`,children:(0,z.jsxs)(`div`,{className:`hq-token-card`,children:[(0,z.jsx)(`div`,{className:`hq-brand`,children:`WrongStack HQ`}),(0,z.jsx)(`div`,{className:`hq-token-title`,children:`Checking auth mode…`})]})})}function Bt({hadToken:e,onAuthenticated:t}){let[n,r]=(0,j.useState)(``),[i,a]=(0,j.useState)(null),[o,s]=(0,j.useState)(!1),c=(0,j.useRef)(null),l=(0,j.useRef)(!1);(0,j.useEffect)(()=>{c.current?.focus()},[]);let u=async()=>{if(o||l.current||n.trim().length===0)return;l.current=!0,s(!0),a(null);let e=await tt(n);if(e.ok){t();return}a(e.message??`The browser token was rejected.`),l.current=!1,s(!1)};return(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`div`,{className:`hq-token-title`,children:`Browser token required`}),(0,z.jsx)(`p`,{className:`hq-token-text`,children:e?`The saved token was rejected — it may have been revoked or the server was reset. Paste a current browser token.`:`This HQ server runs in token mode. Open a terminal and run wstack hq token create to mint a browser token, then paste the token value here. A complete legacy ?token= URL also works.`}),i?(0,z.jsx)(`p`,{className:`hq-token-error`,children:i}):null,(0,z.jsx)(Rt,{inputRef:c,value:n,onChange:r,onKeyDown:e=>{e.key===`Enter`&&u()},placeholder:`browser token`,autoComplete:`off`}),(0,z.jsx)(`button`,{type:`button`,className:`hq-token-submit`,onClick:()=>void u(),disabled:n.trim().length===0||o,children:o?`Connecting…`:`Connect`}),(0,z.jsxs)(`p`,{className:`hq-token-hint`,children:[`Open a terminal and run `,(0,z.jsx)(`code`,{children:`wstack hq token create`}),`, then paste the`,` `,(0,z.jsx)(`code`,{children:`token:`}),` value here. The secret is shown only once — it cannot be recovered from `,(0,z.jsx)(`code`,{children:`~/.wrongstack/hq/auth.json`}),` (only its hash is stored). Run`,` `,(0,z.jsx)(`code`,{children:`wstack hq help`}),` for all token commands.`]})]})}function Vt(){let[e,t]=(0,j.useState)(``),[n,r]=(0,j.useState)(``),[i,a]=(0,j.useState)(!1),[o,s]=(0,j.useState)(null),[c,l]=(0,j.useState)(!1),u=(0,j.useRef)(null),d=(0,j.useRef)(null),f=(0,j.useRef)(!1),p=(0,j.useRef)(!1);(0,j.useEffect)(()=>{if(i){d.current?.focus();return}u.current?.focus()},[i]);let ee=async()=>{if(c||f.current)return;let t=e;if(t.length!==0){f.current=!0,l(!0),s(null);try{let e=await fetch(`/api/login`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({password:t})});if(!e.ok){let t=`Login failed.`;try{let n=(await e.json()).error;typeof n==`string`?t=n:typeof n?.message==`string`&&(t=n.message)}catch{}s(t),f.current=!1,l(!1);return}if((await e.json()).totpRequired){a(!0),f.current=!1,l(!1);return}L(),window.location.reload()}catch{s(`Network error.`),f.current=!1,l(!1)}}},m=async()=>{if(c||p.current)return;let e=n.trim();if(e.length!==0){p.current=!0,l(!0),s(null);try{let t=e.includes(`-`)?{recoveryCode:e}:{code:e.replace(/\D/g,``).slice(0,6)},n=await fetch(`/api/login/verify`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)});if(!n.ok){let e=`Verification failed.`;try{let t=(await n.json()).error;typeof t==`string`?e=t:typeof t?.message==`string`&&(e=t.message)}catch{}s(e),p.current=!1,l(!1);return}L(),window.location.reload()}catch{s(`Network error.`),p.current=!1,l(!1)}}};return i?(0,z.jsxs)(z.Fragment,{children:[o?(0,z.jsx)(`p`,{className:`hq-token-error`,children:o}):null,(0,z.jsx)(`label`,{className:`hq-token-label`,htmlFor:`hq-totp-code`,children:`Authenticator code`}),(0,z.jsx)(`input`,{ref:d,id:`hq-totp-code`,className:`hq-token-input`,type:`text`,autoComplete:`one-time-code`,placeholder:`000000 or recovery code`,value:n,onChange:e=>r(e.target.value.slice(0,32)),onKeyDown:e=>{e.key===`Enter`&&m()}}),(0,z.jsx)(`button`,{type:`button`,className:`hq-token-submit`,onClick:()=>void m(),disabled:n.trim().length===0||c,children:c?`Verifying…`:`Verify`}),(0,z.jsx)(`button`,{type:`button`,className:`hq-token-hint`,onClick:()=>{a(!1),r(``),s(null)},children:`← Back to password`}),(0,z.jsx)(`p`,{className:`hq-token-hint`,children:`Enter the 6-digit code from your authenticator app, or paste a recovery code.`})]}):(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`div`,{className:`hq-token-title`,children:`Password required`}),(0,z.jsx)(`p`,{className:`hq-token-text`,children:`This HQ server is protected by a password. Enter it to open the dashboard.`}),o?(0,z.jsx)(`p`,{className:`hq-token-error`,children:o}):null,(0,z.jsx)(Rt,{inputRef:u,value:e,onChange:t,onKeyDown:e=>{e.key===`Enter`&&ee()},placeholder:`password`,autoComplete:`current-password`}),(0,z.jsx)(`button`,{type:`button`,className:`hq-token-submit`,onClick:()=>void ee(),disabled:e.length===0||c,children:c?`Logging in…`:`Log in`}),(0,z.jsxs)(`p`,{className:`hq-token-hint`,children:[`Set or change the password with `,(0,z.jsx)(`code`,{children:`wstack --hq --password <secret>`}),`.`]})]})}var Ht=`modulepreload`,Ut=function(e){return`/`+e},Wt={},X=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e=document.getElementsByTagName(`link`),i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?import.meta.resolve(e):new URL(e,import.meta.url).href}r=o(t.map(t=>{if(t=Ut(t,n),t=s(t),t in Wt)return;Wt[t]=!0;let r=t.endsWith(`.css`);for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.href===t&&(!r||i.rel===`stylesheet`))return}let i=document.createElement(`link`);if(i.rel=r?`stylesheet`:Ht,r||(i.as=`script`),i.crossOrigin=``,i.href=t,a&&i.setAttribute(`nonce`,a),document.head.appendChild(i),r)return new Promise((e,n)=>{i.addEventListener(`load`,e),i.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${t}`)))})}))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},Gt=216e5,Z=[{id:`cockpit`,label:`Cockpit`,eyebrow:`Fleet overview`,description:`Health, active work, alerts, cost and command shortcuts.`,group:`Operations`,icon:t,shortcut:1},{id:`fleet`,label:`Fleet Map`,eyebrow:`Topology`,description:`Machines, projects, terminals and agents in one live graph.`,group:`Operations`,icon:i,shortcut:2},{id:`console`,label:`Live Console`,eyebrow:`Transcripts`,description:`Stream and inspect session or agent conversations.`,group:`Operations`,icon:C,shortcut:3},{id:`mailbox`,label:`Mailbox`,eyebrow:`Coordination`,description:`Cross-project messages, unread work and direct delivery.`,group:`Operations`,icon:y,shortcut:4},{id:`kanban`,label:`Kanban`,eyebrow:`Project work`,description:`Read-only project boards synchronized across clones and machines.`,group:`Operations`,icon:d},{id:`alerts`,label:`Attention`,eyebrow:`Operator inbox`,description:`Alerts, waiting agents, governance warnings and failed commands.`,group:`Intelligence`,icon:v,shortcut:5},{id:`cost`,label:`Cost`,eyebrow:`Economics`,description:`Project, provider and model spending distribution.`,group:`Intelligence`,icon:l,shortcut:6},{id:`trends`,label:`Trends`,eyebrow:`Telemetry`,description:`Cost, token and tool activity over time.`,group:`Intelligence`,icon:f,shortcut:7},{id:`brain`,label:`Brain`,eyebrow:`Decisions`,description:`Autonomous decisions, escalations and interventions.`,group:`Intelligence`,icon:o,shortcut:8},{id:`worktree`,label:`Worktrees`,eyebrow:`Workspace`,description:`Distributed branches, worktrees and ownership state.`,group:`System`,icon:b,shortcut:9},{id:`control`,label:`Control`,eyebrow:`Command plane`,description:`Steer, queue, broadcast and audit remote commands.`,group:`System`,icon:c,shortcut:0},{id:`settings`,label:`Security`,eyebrow:`Access control`,description:`Manage the HQ browser password, authentication and active credentials.`,group:`System`,icon:S}],Kt=[`Operations`,`Intelligence`,`System`],qt={cockpit:(0,j.lazy)(()=>X(()=>import(`./cockpit-qMcwPuag.js`).then(e=>({default:e.CockpitView})),__vite__mapDeps([0,1,2,3]))),fleet:(0,j.lazy)(()=>X(()=>import(`./fleet-map-Chbzo4P_.js`).then(e=>({default:e.FleetMapView})),__vite__mapDeps([4,1,2,5,3,6]))),console:(0,j.lazy)(()=>X(()=>import(`./live-console-DXTeZHNx.js`).then(e=>({default:e.LiveConsoleView})),__vite__mapDeps([7,1,2,3,6,5]))),mailbox:(0,j.lazy)(()=>X(()=>import(`./mailbox-Z7GgSK__.js`).then(e=>({default:e.MailboxView})),__vite__mapDeps([8,1,2,3,9]))),kanban:(0,j.lazy)(()=>X(()=>import(`./kanban-ClEZyv0J.js`).then(e=>({default:e.KanbanView})),__vite__mapDeps([10,1,2,3]))),cost:(0,j.lazy)(()=>X(()=>import(`./cost-EYiQcvHV.js`).then(e=>({default:e.CostView})),__vite__mapDeps([11,1,2,3]))),brain:(0,j.lazy)(()=>X(()=>import(`./brain-yIDgS4vG.js`).then(e=>({default:e.BrainView})),__vite__mapDeps([12,1,2,3,9]))),worktree:(0,j.lazy)(()=>X(()=>import(`./worktree-DgKbrwbZ.js`).then(e=>({default:e.WorktreeView})),__vite__mapDeps([13,1,2,3,9]))),trends:(0,j.lazy)(()=>X(()=>import(`./trends-B1FxOq-M.js`).then(e=>({default:e.TrendsView})),__vite__mapDeps([14,1,2,3]))),alerts:(0,j.lazy)(()=>X(()=>import(`./alerts-CASro-zg.js`).then(e=>({default:e.AlertsView})),__vite__mapDeps([15,1,2,3]))),control:(0,j.lazy)(()=>X(()=>import(`./control-YiwRf48C.js`).then(e=>({default:e.ControlView})),__vite__mapDeps([16,1,2,3]))),settings:(0,j.lazy)(()=>X(()=>import(`./settings-L17p0Bjr.js`).then(e=>({default:e.SettingsView})),__vite__mapDeps([17,1,2,3])))};function Jt(e){return Z.find(t=>t.id===e)??Z[0]}var Yt=class extends j.Component{state={error:null};static getDerivedStateFromError(e){return{error:e instanceof Error?e.message:String(e)}}componentDidUpdate(e){e.view!==this.props.view&&this.state.error!==null&&this.setState({error:null})}render(){return this.state.error===null?this.props.children:(0,z.jsxs)(`div`,{className:`hq-view-error`,role:`alert`,children:[(0,z.jsx)(h,{size:22}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`strong`,{children:`This HQ surface stopped safely.`}),(0,z.jsx)(`p`,{children:this.state.error})]}),(0,z.jsxs)(`button`,{type:`button`,className:`hq-btn secondary`,onClick:()=>this.setState({error:null}),children:[(0,z.jsx)(x,{size:13}),`Retry view`]})]})}};function Xt(){let{snapshot:e,alerts:t,commandStatuses:r,activeView:i,authRequired:a,connected:o,peerRehydrate:c}=V(qe(e=>({snapshot:e.snapshot,alerts:e.alerts,commandStatuses:e.commandStatuses,activeView:e.activeView,authRequired:e.authRequired,connected:e.connected,peerRehydrate:e.peerRehydrate}))),[d,f]=(0,j.useState)(()=>typeof window>`u`||window.innerWidth>=1180),[m,ne]=(0,j.useState)(null),[h,oe]=(0,j.useState)(null),[g,se]=(0,j.useState)(!1),[_,v]=(0,j.useState)(!1),[y,b]=(0,j.useState)(``),[x,S]=(0,j.useState)(0),ue=(0,j.useRef)(null),{theme:C}=Mt().appearance,de=(0,j.useRef)(!1),w=(0,j.useRef)(!1);(0,j.useEffect)(()=>{w.current&&o===!1?mt.getState().addToast(`Connection lost — reconnecting with backoff…`,`warning`,4e3):w.current&&de.current===!1&&o===!0&&mt.getState().addToast(`Reconnected to HQ server`,`success`,3e3),o&&(w.current=!0),de.current=o},[o]),(0,j.useEffect)(()=>(document.documentElement.dataset.hqTheme=C,()=>{delete document.documentElement.dataset.hqTheme}),[C]),(0,j.useEffect)(()=>{let e=!1;return H(`/api/snapshot`).then(t=>{e||V.getState()._hydrateSnapshot(t)}).catch(()=>{}),()=>{e=!0}},[]),(0,j.useEffect)(()=>{let e=!1;return H(`/api/auth/status`).then(t=>{e||oe(t)}).catch(()=>{}),()=>{e=!0}},[]),(0,j.useEffect)(()=>{let e=!1,t=()=>{H(`/api/system/update`).then(t=>{e||ne(t)}).catch(()=>{})};t();let n=window.setInterval(t,Gt);return()=>{e=!0,window.clearInterval(n)}},[]),(0,j.useEffect)(()=>{_&&ue.current?.focus()},[_]),(0,j.useEffect)(()=>{let e=e=>{if((e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`k`){e.preventDefault(),v(e=>!e),b(``),S(0);return}if((e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`b`){e.preventDefault(),f(e=>!e);return}if(e.altKey&&/^\d$/.test(e.key)){let t=Number(e.key),n=Z.find(e=>e.shortcut===t);n&&(e.preventDefault(),V.getState().setActiveView(n.id));return}if(e.key===`Escape`&&_){e.preventDefault(),v(!1);return}e.key===`Escape`&&d&&window.innerWidth<900&&f(!1)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[_,d]);let T=(0,j.useMemo)(()=>{let e=y.trim().toLowerCase();return e.length===0?Z:Z.filter(t=>[t.label,t.eyebrow,t.description,t.group].join(` `).toLowerCase().includes(e))},[y]);if(a)return(0,z.jsx)(zt,{hadToken:Xe()!==null});let E=e?.totals,fe=E?.unreadMailboxMessages??0,pe=t.filter(e=>e.severity!==`info`).length+(e?.projects??[]).filter(e=>e.governance?.signal.level===`warning`||e.governance?.signal.level===`unavailable`).length+(e?.liveSessions??[]).flatMap(e=>e.agents??[]).filter(e=>e.status===`waiting_user`||e.status===`error`).length+(e?.clients??[]).filter(e=>!e.connected).length+r.filter(e=>e.ackStatus===`failed`||e.ackStatus===`rejected`).length,D=Jt(i),me=D.icon,he=qt[i],O=e=>{V.getState().setActiveView(e),v(!1),b(``),S(0),window.innerWidth<900&&f(!1)},ge=async()=>{se(!0);try{await R(`/api/logout`,{method:`POST`})}finally{L(),window.location.reload()}};return(0,z.jsxs)(`div`,{className:`hq-app`,"data-theme":C,"data-testid":`hq-workbench`,children:[(0,z.jsx)(`button`,{type:`button`,className:`hq-sidebar-scrim`,"data-open":d,"aria-label":`Close HQ navigation`,onClick:()=>f(!1)}),(0,z.jsxs)(`aside`,{className:`hq-secondary-nav`,"data-open":d,"aria-label":`HQ navigation`,children:[(0,z.jsxs)(`div`,{className:`hq-secondary-header`,children:[(0,z.jsxs)(`div`,{className:`hq-secondary-brand`,children:[(0,z.jsx)(`img`,{src:`/wrongstack.svg`,alt:``,"aria-hidden":`true`,draggable:!1}),(0,z.jsxs)(`div`,{className:`hq-secondary-copy`,children:[(0,z.jsx)(`span`,{className:`hq-secondary-eyebrow`,children:`Command center`}),(0,z.jsx)(`strong`,{children:`WrongStack HQ`})]})]}),(0,z.jsx)(`button`,{type:`button`,className:`hq-icon-button hq-secondary-close`,"aria-label":`Collapse HQ navigation`,title:`Collapse navigation (Ctrl+B)`,onClick:()=>f(!1),children:(0,z.jsx)(ae,{size:16})})]}),(0,z.jsx)(`div`,{className:`hq-secondary-scroll`,children:Kt.map(e=>(0,z.jsxs)(`section`,{className:`hq-nav-group`,children:[(0,z.jsx)(`div`,{className:`hq-nav-group-label`,children:e}),Z.filter(t=>t.group===e).map(e=>{let t=e.icon,n=e.id===`mailbox`?fe:e.id===`alerts`?pe:0;return(0,z.jsxs)(`button`,{type:`button`,className:`hq-nav-item`,"data-active":i===e.id,"aria-current":i===e.id?`page`:void 0,onClick:()=>O(e.id),children:[(0,z.jsx)(t,{size:15}),(0,z.jsx)(`span`,{children:e.label}),e.shortcut===void 0?null:(0,z.jsxs)(`kbd`,{children:[`Alt+`,e.shortcut]}),n>0?(0,z.jsx)(`span`,{className:`hq-nav-badge`,children:n}):null]},e.id)})]},e))}),(0,z.jsxs)(`div`,{className:`hq-secondary-footer`,children:[(0,z.jsxs)(`div`,{className:`hq-link-state`,"data-live":o,children:[(0,z.jsx)(`span`,{className:`hq-link-dot`}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`strong`,{children:o?`Connected`:`Reconnecting`}),(0,z.jsxs)(`span`,{children:[E?.activeMachines??0,` machines · `,E?.activeClients??0,` clients`]})]})]}),(0,z.jsx)(`span`,{className:`hq-build-label`,children:`@wrongstack/webui-hq`})]})]}),(0,z.jsxs)(`section`,{className:`hq-workbench`,"data-update-available":m?.outdated===!0,children:[(0,z.jsxs)(`header`,{className:`hq-header`,children:[(0,z.jsx)(`button`,{type:`button`,className:`hq-icon-button hq-sidebar-toggle`,"aria-label":d?`Collapse HQ navigation`:`Expand HQ navigation`,"aria-expanded":d,title:`Toggle navigation (Ctrl+B)`,onClick:()=>f(e=>!e),children:d?(0,z.jsx)(ae,{size:17}):(0,z.jsx)(n,{size:17})}),(0,z.jsx)(`div`,{className:`hq-view-icon`,"aria-hidden":`true`,children:(0,z.jsx)(me,{size:18})}),(0,z.jsxs)(`div`,{className:`hq-view-identity`,children:[(0,z.jsx)(`span`,{children:D.eyebrow}),(0,z.jsx)(`h1`,{children:D.label}),(0,z.jsx)(`p`,{children:D.description})]}),(0,z.jsxs)(`div`,{className:`hq-top-metrics`,children:[(0,z.jsx)(Q,{icon:le,label:`Machines`,value:E?.activeMachines??0}),(0,z.jsx)(Q,{icon:ce,label:`Agents`,value:E?.activeAgents??0}),(0,z.jsx)(Q,{icon:ee,label:`Sessions`,value:E?.activeSessions??0}),(0,z.jsx)(Q,{icon:l,label:`Cost`,value:`$${(E?.totalCostUsd??0).toFixed(2)}`,accent:!0})]}),(0,z.jsxs)(`button`,{type:`button`,className:`hq-command-trigger`,"aria-label":`Open HQ command palette`,"aria-expanded":_,onClick:()=>{v(!0),b(``),S(0)},children:[(0,z.jsx)(u,{size:14}),(0,z.jsx)(`span`,{children:`Jump to`}),(0,z.jsx)(`kbd`,{children:`Ctrl K`})]}),(0,z.jsxs)(`div`,{className:`hq-connection-pill`,"data-live":o,children:[o?(0,z.jsx)(ie,{size:13}):(0,z.jsx)(te,{size:13}),o?`Live`:`Reconnecting`]}),(0,z.jsx)(`button`,{type:`button`,className:`hq-icon-button hq-theme-toggle`,"aria-label":`Switch to ${C===`dark`?`light`:`dark`} mode`,title:`Switch to ${C===`dark`?`light`:`dark`} mode`,onClick:()=>Pt({theme:C===`dark`?`light`:`dark`}),children:C===`dark`?(0,z.jsx)(re,{size:16}):(0,z.jsx)(s,{size:16})}),h?.tokenMode||h?.passwordMode?(0,z.jsx)(`button`,{type:`button`,className:`hq-icon-button`,"aria-label":`Log out of HQ`,title:`Log out and clear this tab's HQ credentials`,disabled:g,onClick:()=>void ge(),children:(0,z.jsx)(p,{size:16})}):null]}),m?.outdated?(0,z.jsx)(Qt,{status:m}):null,c?(0,z.jsx)(Zt,{envelope:c}):null,(0,z.jsx)(`main`,{className:`hq-main`,id:`hq-main`,tabIndex:-1,children:(0,z.jsx)(Yt,{view:i,children:(0,z.jsx)(j.Suspense,{fallback:(0,z.jsx)($t,{label:D.label}),children:(0,z.jsx)(he,{})})})})]}),_?(0,z.jsxs)(`div`,{className:`hq-command-layer`,role:`presentation`,children:[(0,z.jsx)(`button`,{type:`button`,className:`hq-command-scrim`,"aria-label":`Close HQ command palette`,onClick:()=>v(!1)}),(0,z.jsxs)(`dialog`,{open:!0,className:`hq-command-palette`,"aria-label":`HQ command palette`,children:[(0,z.jsxs)(`div`,{className:`hq-command-search`,children:[(0,z.jsx)(u,{size:17,"aria-hidden":`true`}),(0,z.jsx)(`input`,{ref:ue,type:`search`,value:y,"aria-label":`Search HQ views`,placeholder:`Search views, telemetry and controls…`,onChange:e=>{b(e.target.value),S(0)},onKeyDown:e=>{e.key===`ArrowDown`?(e.preventDefault(),S(e=>T.length===0?0:(e+1)%T.length)):e.key===`ArrowUp`?(e.preventDefault(),S(e=>T.length===0?0:(e-1+T.length)%T.length)):e.key===`Enter`&&T[x]&&(e.preventDefault(),O(T[x].id))}}),(0,z.jsx)(`kbd`,{children:`Esc`})]}),(0,z.jsx)(`div`,{className:`hq-command-results`,role:`listbox`,"aria-label":`HQ destinations`,children:T.length===0?(0,z.jsxs)(`div`,{className:`hq-command-empty`,children:[`No HQ surface matches “`,y,`”.`]}):T.map((e,t)=>{let n=e.icon;return(0,z.jsxs)(`button`,{type:`button`,className:`hq-command-result`,role:`option`,"aria-selected":x===t,"data-current":i===e.id,onMouseEnter:()=>S(t),onClick:()=>O(e.id),children:[(0,z.jsx)(`span`,{className:`hq-command-result-icon`,children:(0,z.jsx)(n,{size:16})}),(0,z.jsxs)(`span`,{className:`hq-command-result-copy`,children:[(0,z.jsx)(`strong`,{children:e.label}),(0,z.jsx)(`small`,{children:e.description})]}),(0,z.jsx)(`span`,{className:`hq-command-result-group`,children:e.group}),e.shortcut===void 0?null:(0,z.jsxs)(`kbd`,{children:[`Alt `,e.shortcut]})]},e.id)})}),(0,z.jsxs)(`footer`,{className:`hq-command-footer`,children:[(0,z.jsxs)(`span`,{children:[(0,z.jsx)(`kbd`,{children:`↑↓`}),` select`]}),(0,z.jsxs)(`span`,{children:[(0,z.jsx)(`kbd`,{children:`Enter`}),` open`]}),(0,z.jsxs)(`span`,{children:[(0,z.jsx)(`kbd`,{children:`Esc`}),` close`]}),(0,z.jsxs)(`span`,{children:[T.length,` destinations`]})]})]})]}):null,(0,z.jsx)(gt,{})]})}function Zt({envelope:e}){let t=e.kind===`peer.rehydrate`?`Leader session lost — survivor clients can rehydrate`:`Leader session lost — no survivor clients reported`,n=e.kind===`peer.rehydrate`&&e.payload.rehydrateHint?e.payload.rehydrateHint:`${e.payload.previousLeaderHandle} on ${e.payload.machineId} ended (${e.payload.reason}).`;return(0,z.jsxs)(`aside`,{className:`hq-peer-rehydrate-notice`,role:`status`,"aria-live":`polite`,children:[(0,z.jsx)(g,{size:16,"aria-hidden":`true`}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`strong`,{children:t}),(0,z.jsx)(`span`,{children:n})]}),(0,z.jsx)(`button`,{type:`button`,onClick:()=>V.getState()._dismissPeerRehydrate(),title:`Dismiss peer lifecycle notice`,children:`Dismiss`})]})}function Qt({status:e}){let[t,n]=(0,j.useState)(!1),i=async()=>{try{await navigator.clipboard.writeText(e.command),n(!0),window.setTimeout(()=>n(!1),1500)}catch{n(!1)}};return(0,z.jsxs)(`aside`,{className:`hq-update-notice`,role:`status`,"aria-live":`polite`,children:[(0,z.jsx)(g,{size:16,"aria-hidden":`true`}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`strong`,{children:`WrongStack update available`}),(0,z.jsxs)(`span`,{children:[`v`,e.current,` → v`,e.latest,`. Run `,(0,z.jsx)(`code`,{children:e.command}),` in your terminal, then restart HQ.`]})]}),(0,z.jsxs)(`button`,{type:`button`,onClick:()=>void i(),title:`Copy update command`,children:[(0,z.jsx)(r,{size:13,"aria-hidden":`true`}),t?`Copied`:`Copy command`]})]})}function Q({icon:e,label:t,value:n,accent:r=!1}){return(0,z.jsxs)(`div`,{className:`hq-top-metric`,"data-accent":r,children:[(0,z.jsx)(e,{size:12}),(0,z.jsx)(`span`,{children:t}),(0,z.jsx)(`strong`,{children:n})]})}function $t({label:e}){return(0,z.jsxs)(`div`,{className:`hq-view-loading`,role:`status`,children:[(0,z.jsx)(c,{size:18}),(0,z.jsxs)(`span`,{children:[`Loading `,e,`…`]})]})}var en=25e3,tn=1e4,nn=3e4,rn=32;function an(e){let t=e.toLowerCase().replace(/^\[(.*)\]$/,`$1`);if(t===`localhost`)return!0;let n=t.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/);if(n){if(n[1]!==`127`)return!1;for(let e of n.slice(1))if(Number(e)>255)return!1;return!0}return t===`::1`||t===`0:0:0:0:0:0:0:1`||t.startsWith(`::ffff:127.`)}function on(e){if(!Number.isFinite(e))return 0;let t=Math.max(0,Math.trunc(e));return Number.isSafeInteger(t)?t:0}var sn=class{ws=null;handlers=new Set;stateHandlers=new Set;reconnectAttempt=0;connectionState=E();reconnectTimer=null;heartbeatTimer=null;lastMessageAt=0;stopped=!1;_state=`disconnected`;_url;resumeCursor;maxRetries;heartbeatIntervalMs;heartbeatTimeoutMs;maxBackoffMs;constructor(e){if(this.maxRetries=e?.maxRetries??1/0,this.heartbeatIntervalMs=e?.heartbeatIntervalMs??en,this.heartbeatTimeoutMs=e?.heartbeatTimeoutMs??tn,this.maxBackoffMs=e?.maxBackoffMs??nn,this.resumeCursor=e?.resumeCursor??(()=>({})),e?.url)this._url=e.url;else{let e=typeof window<`u`?window.location:{host:`127.0.0.1:3499`,protocol:`http:`,hostname:`127.0.0.1`},t=e.protocol===`https:`?`wss:`:`ws:`,n=Xe(),r=an(e.hostname),i=`${t}//${e.host}/ws/browser`;this._url=n!==null&&r?`${i}?token=${encodeURIComponent(n)}`:i}}get url(){return this._url}get state(){return this._state}get isConnected(){return this.ws?.readyState===WebSocket.OPEN}connect(){if(this.stopped||this.ws!==null)return;this.connectionState=fe(this.connectionState),this.emitState(`connecting`);let e;try{e=new WebSocket(this._url)}catch{this.scheduleReconnect();return}this.ws=e,e.onopen=()=>{this.ws===e&&(this.reconnectAttempt=0,this.connectionState=pe(this.connectionState),this.lastMessageAt=Date.now(),this.connectionState=D(this.connectionState,this.lastMessageAt),this.emitState(`connected`),this.sendResume(),this.startHeartbeat())},e.onmessage=t=>{if(this.ws===e){this.lastMessageAt=Date.now(),this.connectionState=D(this.connectionState,this.lastMessageAt);try{let e=JSON.parse(typeof t.data==`string`?t.data:``);for(let t of this.handlers)try{t(e)}catch{}}catch{}}},e.onclose=()=>this.handleClose(e,`close`),e.onerror=()=>this.handleClose(e,`error`)}close(){this.stopped=!0,this.connectionState=me(this.connectionState),this.stopHeartbeat(),this.reconnectTimer!==null&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this.ws?.close(1e3,`client closed`),this.ws=null,this.emitState(`disconnected`)}setResumeCursorProvider(e){this.resumeCursor=e}on(e){return this.handlers.add(e),()=>this.handlers.delete(e)}onStateChange(e){return this.stateHandlers.add(e),e(this._state),()=>this.stateHandlers.delete(e)}handleClose(e,t){this.ws===e&&(this.ws=null,this.stopHeartbeat(),this.scheduleReconnect())}scheduleReconnect(){if(this.stopped||this.reconnectTimer!==null)return;let e=he(this.connectionState,{...T,maxReconnectAttempts:this.maxRetries,maxBackoffMs:this.maxBackoffMs,heartbeatIntervalMs:this.heartbeatIntervalMs,heartbeatTimeoutMs:this.heartbeatTimeoutMs,jitterRatio:.5});if(this.connectionState=e.state,this.reconnectAttempt=e.state.reconnectAttempt,!e.plan){this.emitState(`disconnected`);return}this.emitState(`reconnecting`),this.reconnectTimer=setTimeout(()=>{this.reconnectTimer=null,this.connect()},e.plan.delayMs)}sendResume(){if(this.ws?.readyState===WebSocket.OPEN)try{for(let e of this.resumeFrames())this.ws.send(JSON.stringify(e))}catch{}}resumeFrames(){try{let e=this.resumeCursor(),t=typeof e.entries==`function`?e.entries():Object.entries(e),n=[];for(let[e,r]of t){if(typeof e!=`string`||e.length===0)continue;let t=on(r);n.push({clientId:e,lastSeqSeen:t})}n.sort((e,t)=>t.lastSeqSeen===e.lastSeqSeen?e.clientId.localeCompare(t.clientId):t.lastSeqSeen-e.lastSeqSeen);let r=n.find(({clientId:e})=>e===B),i=r===void 0?rn:31,a=n.filter(({clientId:e})=>e!==B).slice(0,i);return r!==void 0&&a.unshift(r),a.map(({clientId:e,lastSeqSeen:t})=>({type:`client.resume`,clientId:e,lastSeqSeen:t}))}catch{return[]}}get isHeartbeatTimedOut(){return this.ws===null||O(this.connectionState,{...T,heartbeatIntervalMs:this.heartbeatIntervalMs,heartbeatTimeoutMs:this.heartbeatTimeoutMs})}startHeartbeat(){this.stopHeartbeat(),this.lastMessageAt=Date.now(),this.heartbeatTimer=setInterval(()=>{this.isHeartbeatTimedOut&&this.ws!==null&&(this.ws.close(4e3,`heartbeat timeout`),this.ws=null,this.scheduleReconnect())},this.heartbeatIntervalMs)}stopHeartbeat(){this.heartbeatTimer!==null&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}emitState(e){this._state=e;for(let t of this.stateHandlers)try{t(e)}catch{}}},$=null;function cn(e){if($===null)return $=new sn(e),$.connect(),$;if(e?.resumeCursor!==void 0&&$.setResumeCursorProvider(e.resumeCursor),e===void 0)return $;let t=[];return e.url!==void 0&&e.url!==$.url&&t.push(`url: ${e.url} vs ${$.url}`),e.heartbeatIntervalMs!==void 0&&e.heartbeatIntervalMs!==$.heartbeatIntervalMs&&t.push(`heartbeatIntervalMs: ${e.heartbeatIntervalMs} vs ${$.heartbeatIntervalMs}`),e.heartbeatTimeoutMs!==void 0&&e.heartbeatTimeoutMs!==$.heartbeatTimeoutMs&&t.push(`heartbeatTimeoutMs: ${e.heartbeatTimeoutMs} vs ${$.heartbeatTimeoutMs}`),e.maxBackoffMs!==void 0&&e.maxBackoffMs!==$.maxBackoffMs&&t.push(`maxBackoffMs: ${e.maxBackoffMs} vs ${$.maxBackoffMs}`),e.maxRetries!==void 0&&e.maxRetries!==$.maxRetries&&t.push(`maxRetries: ${e.maxRetries} vs ${$.maxRetries}`),t.length>0&&typeof console<`u`&&console.warn(`[hq-ws-client] getHqClient() called with options that conflict with the live singleton; ignoring: ${t.join(`, `)}. Call closeHqClient() first if you need to reconfigure.`),$}var ln=document.getElementById(`root`);ln!==null&&it().finally(()=>{Ze(),at();let e=cn({resumeCursor:()=>V.getState().resumeCursors});e.onStateChange(e=>{V.getState()._setConnected(e===`connected`)});let t=null,n=()=>{t===null&&(V.getState()._setNeedsSnapshotRefresh(!1),t=H(`/api/snapshot`).then(e=>{V.getState()._onSnapshot(e)}).catch(()=>void 0).finally(()=>{t=null}))};V.subscribe((e,t)=>{e.needsSnapshotRefresh&&!t.needsSnapshotRefresh&&n()}),e.on(e=>{if(e.type===`hq.snapshot`){let t=Le(e);t&&V.getState()._onSnapshot(t.snapshot)}else if(e.type===`hq.event`){let t=Re(e);t&&V.getState()._onEvent(t.event)}else if(e.type===`hq.alert`){let t=ze(e);t&&V.getState()._onAlert(t.alert)}else if(e.type===`hq.command_status`){let t=Be(e);t&&V.getState()._onCommandStatus(t.command)}else if(e.type===`hq.resume_gap`)for(let t of e.envelopes){let e=Re({type:`hq.event`,event:t});e&&V.getState()._onEvent(e.event)}else e.type===`hq.resume_reject`&&(V.getState()._resetResumeCursors(),V.getState()._setNeedsSnapshotRefresh(!0))}),(0,Ve.createRoot)(ln).render((0,z.jsx)(j.StrictMode,{children:(0,z.jsx)(Xt,{})}))});export{Lt as a,wt as c,R as d,L as f,Ft as i,Ct as l,It as n,Mt as o,qe as p,Nt as r,H as s,Rt as t,V as u};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Dt as t,E as n,Ft as r,Mt as i,Nt as a,Xt as o,Zt as s,c,et as l,l as u,n as d,ut as f,xt as p}from"./icons-I81S_8cW.js";import{i as m}from"./markdown-C4I0Caum.js";import{s as h,u as g}from"./index-Da_ivWpO.js";var _=e(s(),1),v=m();function y({task:e,board:n,webuiUrl:i,dependencyTitles:a,onClose:o}){let s=e.dependsOn.map(e=>({id:e,title:a?.get(e)??e.slice(0,8)}));return(0,v.jsxs)(`aside`,{className:`hq-kanban-inspector`,"aria-label":`Task detail`,children:[(0,v.jsxs)(`header`,{className:`hq-kanban-inspector-header`,children:[(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`span`,{className:`hq-pill ${e.status}`,children:e.status.replaceAll(`_`,` `)}),(0,v.jsx)(`span`,{className:`hq-kanban-priority ${e.priority}`,children:e.priority})]}),(0,v.jsx)(`button`,{type:`button`,onClick:o,"aria-label":`Close inspector`,className:`hq-inspector-close`,children:(0,v.jsx)(d,{size:16})})]}),(0,v.jsx)(`h2`,{className:`hq-kanban-inspector-title`,children:e.title}),(0,v.jsx)(`span`,{className:`hq-mono hq-kanban-inspector-id`,children:e.id}),e.description?(0,v.jsxs)(`section`,{className:`hq-kanban-inspector-section`,children:[(0,v.jsx)(`h3`,{children:`Description`}),(0,v.jsx)(`p`,{className:`hq-kanban-inspector-description`,children:e.description})]}):null,(0,v.jsxs)(`section`,{className:`hq-kanban-inspector-section`,children:[(0,v.jsx)(`h3`,{children:`Details`}),(0,v.jsxs)(`dl`,{className:`hq-kanban-inspector-details`,children:[(0,v.jsxs)(`div`,{className:`hq-kanban-inspector-row`,children:[(0,v.jsxs)(`dt`,{children:[(0,v.jsx)(l,{size:13}),`Board`]}),(0,v.jsx)(`dd`,{children:n.title})]}),e.assignee?(0,v.jsxs)(`div`,{className:`hq-kanban-inspector-row`,children:[(0,v.jsxs)(`dt`,{children:[(0,v.jsx)(c,{size:13}),`Assignee`]}),(0,v.jsxs)(`dd`,{children:[e.assignee,e.assignmentStatus?(0,v.jsxs)(`span`,{className:`hq-mono`,style:{marginLeft:6,opacity:.7},children:[`(`,e.assignmentStatus,`)`]}):null]})]}):null,e.dueDate?(0,v.jsxs)(`div`,{className:`hq-kanban-inspector-row`,children:[(0,v.jsxs)(`dt`,{children:[(0,v.jsx)(t,{size:13}),`Due`]}),(0,v.jsx)(`dd`,{children:new Date(e.dueDate).toLocaleString()})]}):null,e.columnId?(0,v.jsxs)(`div`,{className:`hq-kanban-inspector-row`,children:[(0,v.jsxs)(`dt`,{children:[(0,v.jsx)(l,{size:13}),`Column`]}),(0,v.jsx)(`dd`,{children:n.columns.find(t=>t.id===e.columnId)?.title??e.columnId})]}):null]})]}),e.labels.length>0?(0,v.jsxs)(`section`,{className:`hq-kanban-inspector-section`,children:[(0,v.jsx)(`h3`,{children:`Labels`}),(0,v.jsx)(`div`,{className:`hq-kanban-inspector-labels`,children:e.labels.map(e=>(0,v.jsx)(`span`,{className:`hq-pill info`,children:e},e))})]}):null,s.length>0?(0,v.jsxs)(`section`,{className:`hq-kanban-inspector-section`,children:[(0,v.jsxs)(`h3`,{children:[(0,v.jsx)(f,{size:13}),`Dependencies (`,s.length,`)`]}),(0,v.jsx)(`ul`,{className:`hq-kanban-inspector-deps`,children:s.map(t=>(0,v.jsxs)(`li`,{children:[(0,v.jsx)(`span`,{className:`hq-mono`,children:t.id.slice(0,8)}),(0,v.jsx)(`span`,{children:t.title}),e.status===`completed`?(0,v.jsx)(r,{size:13,className:`is-done`}):null]},t.id))})]}):null,e.status===`blocked`||e.status===`failed`?(0,v.jsxs)(`div`,{className:`hq-kanban-inspector-alert`,children:[(0,v.jsx)(u,{size:14}),(0,v.jsxs)(`span`,{children:[`This task is `,e.status,` and may need attention.`]})]}):null,i?(0,v.jsx)(`footer`,{className:`hq-kanban-inspector-footer`,children:(0,v.jsxs)(`a`,{href:i,target:`_blank`,rel:`noopener noreferrer`,className:`hq-button hq-button-primary`,children:[(0,v.jsx)(p,{size:14}),`Open in WebUI`]})}):null]})}function b({board:e}){let n=x(e),s=n.blocked===0&&n.failed===0;return(0,v.jsxs)(`div`,{className:`hq-kanban-queue-health`,role:`status`,"aria-label":`Queue health`,children:[(0,v.jsx)(`span`,{className:`hq-kanban-qh-label`,children:`Queue health`}),n.startable>0?(0,v.jsxs)(`span`,{className:`hq-kanban-qh-pill ready`,title:`Claimable tasks`,children:[(0,v.jsx)(i,{size:12}),n.startable,` ready`]}):null,n.running>0?(0,v.jsxs)(`span`,{className:`hq-kanban-qh-pill running`,title:`Running assignments`,children:[(0,v.jsx)(o,{size:12}),n.running,` running`]}):null,n.review>0?(0,v.jsxs)(`span`,{className:`hq-kanban-qh-pill review`,title:`In review`,children:[(0,v.jsx)(t,{size:12}),n.review,` review`]}):null,n.blocked>0?(0,v.jsxs)(`span`,{className:`hq-kanban-qh-pill blocked`,title:`Manually blocked`,children:[(0,v.jsx)(a,{size:12}),n.blocked,` blocked`]}):null,n.failed>0?(0,v.jsxs)(`span`,{className:`hq-kanban-qh-pill failed`,title:`Failed tasks`,children:[(0,v.jsx)(u,{size:12}),n.failed,` failed`]}):null,s?(0,v.jsxs)(`span`,{className:`hq-kanban-qh-pill healthy`,title:`No issues detected`,children:[(0,v.jsx)(r,{size:12}),`healthy`]}):null]})}function x(e){let t={startable:0,running:0,review:0,blocked:0,failed:0},n=new Set;for(let t of e.columns)for(let e of t.tasks)e.status===`completed`&&n.add(e.id);for(let r of e.columns)for(let e of r.tasks){let r=e.assignmentStatus===`running`||e.assignmentStatus===`queued`;switch((e.status===`in_progress`||e.assignmentStatus===`running`)&&t.running++,!r&&(e.status===`pending`||e.status===`ready`)&&e.dependsOn.every(e=>n.has(e))&&t.startable++,e.status){case`review`:t.review++;break;case`blocked`:t.blocked++;break;case`failed`:t.failed++}}return t}var S=new Set([`low`,`medium`,`high`,`critical`]),C=new Set([`pending`,`ready`,`in_progress`,`review`,`completed`,`blocked`,`failed`,`archived`]);function w(e){return`/api/projects/${encodeURIComponent(e)}/kanban`}function T(e){return e.boards.map(e=>E(e)).filter(e=>e!==null).sort((e,t)=>t.updatedAt.localeCompare(e.updatedAt))}function E(e){let t=e.board;if(t.id!==e.boardId)return null;let n=k(t.columns).map(D).filter(e=>e!==null),r=k(t.tasks).map(O).filter(e=>e!==null),i=new Set(n.map(e=>e.id)),a=new Set(r.map(e=>e.columnId).filter(e=>!i.has(e)));for(let e of a)n.push({id:e,title:e.length>0?e:`Unmapped`,order:2**53-1});let o=n.sort((e,t)=>e.order-t.order||e.title.localeCompare(t.title)).map(e=>({...e,tasks:r.filter(t=>t.columnId===e.id).sort((e,t)=>e.order-t.order||e.title.localeCompare(t.title))}));return{id:e.boardId,title:M(t.title)??e.boardId,description:M(t.description),tags:j(t.tags),revision:e.revision,updatedAt:e.updatedAt,activePresence:k(t.presence).filter(e=>e.active===!0).length,taskCount:r.length,completedTaskCount:r.filter(e=>e.status===`completed`).length,activeTaskCount:r.filter(e=>e.status===`in_progress`||e.status===`review`).length,blockedTaskCount:r.filter(e=>e.status===`blocked`||e.status===`failed`).length,columns:o}}function D(e){let t=M(e.id),n=M(e.title);return!t||!n?null:{id:t,title:n,color:M(e.color),order:N(e.order)??0,wipLimit:N(e.wipLimit)}}function O(e){let t=M(e.id),n=M(e.title),r=M(e.columnId);if(!t||!n||r===void 0)return null;let i=A(e.assignment);return{id:t,title:n,description:M(e.description),columnId:r,order:N(e.order)??0,priority:P(e.priority,S)??`medium`,status:P(e.status,C)??`pending`,assignee:M(e.assignee)??M(e.assignedAgent)??M(i?.name)??M(i?.agentId),assignmentStatus:M(i?.status),labels:j(e.labels),dependsOn:j(e.dependsOn),dueDate:M(e.dueDate)}}function k(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&!Array.isArray(e)):[]}function A(e){return typeof e==`object`&&e&&!Array.isArray(e)?e:void 0}function j(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function M(e){return typeof e==`string`?e:void 0}function N(e){return typeof e==`number`&&Number.isFinite(e)?e:void 0}function P(e,t){return typeof e==`string`&&t.has(e)?e:void 0}var F=1e4,I=[];function L(){let e=g(e=>e.snapshot?.projects??I),t=g(e=>{for(let t=e.events.length-1;t>=0;t--){let n=e.events[t];if(n?.type===`kanban.snapshot`)return n.id}return null}),[r,i]=(0,_.useState)(``),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(null),[l,d]=(0,_.useState)(!1),[f,p]=(0,_.useState)(!1),[m,x]=(0,_.useState)(null),S=(0,_.useRef)(0),C=(0,_.useRef)(t);(0,_.useEffect)(()=>{if(e.length===0){i(``),c(null);return}e.some(e=>e.projectId===r)||i(e[0].projectId)},[r,e]);let E=(0,_.useCallback)(async(e=!1)=>{if(!r)return;let t=++S.current;e?d(!0):p(!0);try{let e=await h(w(r));if(t!==S.current)return;c(e),x(null)}catch(e){if(t!==S.current)return;x(e instanceof Error?e.message:String(e))}finally{t===S.current&&(d(!1),p(!1))}},[r]);(0,_.useEffect)(()=>{S.current++,c(null),o(``),x(null)},[r]),(0,_.useEffect)(()=>{if(!r)return;E(!0);let e=window.setInterval(()=>void E(!1),F);return()=>{S.current++,window.clearInterval(e)}},[E,r]),(0,_.useEffect)(()=>{t!==null&&t!==C.current&&(C.current=t,r&&E(!1))},[t,E,r]);let D=(0,_.useMemo)(()=>s?T(s):[],[s]);(0,_.useEffect)(()=>{D.length===0?o(``):D.some(e=>e.id===a)||o(D[0].id)},[a,D]);let O=D.find(e=>e.id===a)??null,k=e.find(e=>e.projectId===r)??null,[A,j]=(0,_.useState)(null);(0,_.useEffect)(()=>{j(null)},[a]);let M=(0,_.useMemo)(()=>{if(!O||!A)return null;for(let e of O.columns){let t=e.tasks.find(e=>e.id===A);if(t)return t}return null},[O,A]),N=(0,_.useMemo)(()=>{if(!O)return new Map;let e=new Map;for(let t of O.columns)for(let n of t.tasks)e.set(n.id,n.title);return e},[O]);return e.length===0?(0,v.jsx)(`div`,{className:`hq-empty`,children:`No HQ projects are available. Connect a WrongStack client to publish its project identity and Kanban snapshot.`}):(0,v.jsxs)(`div`,{className:`hq-kanban-view`,children:[(0,v.jsx)(R,{projects:e,projectId:r,onProjectChange:e=>i(e),boards:D,boardId:a,onBoardChange:o,generatedAt:s?.generatedAt,refreshing:f,onRefresh:()=>void E(!1)}),m?(0,v.jsxs)(`div`,{className:`hq-kanban-error`,role:`alert`,children:[(0,v.jsx)(u,{size:15}),(0,v.jsx)(`span`,{children:m}),(0,v.jsx)(`button`,{type:`button`,onClick:()=>void E(!0),children:`Retry`})]}):null,l&&s===null?(0,v.jsxs)(`div`,{className:`hq-view-loading`,role:`status`,children:[(0,v.jsx)(n,{size:18}),(0,v.jsx)(`span`,{children:`Loading project boards…`})]}):O?(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)(z,{project:k,board:O,boardCount:D.length}),(0,v.jsx)(b,{board:O}),(0,v.jsxs)(`div`,{className:`hq-kanban-main`,children:[(0,v.jsx)(V,{board:O,onTaskClick:j,selectedTaskId:A}),M?(0,v.jsx)(y,{task:M,board:O,dependencyTitles:N,onClose:()=>j(null)}):null]})]}):(0,v.jsxs)(`div`,{className:`hq-empty`,children:[`This project has not published a Kanban board yet. Create one with `,(0,v.jsx)(`code`,{children:`/kanban`}),` `,`from any connected clone.`]})]})}function R({projects:e,projectId:t,onProjectChange:r,boards:i,boardId:a,onBoardChange:o,generatedAt:s,refreshing:c,onRefresh:l}){return(0,v.jsxs)(`div`,{className:`hq-kanban-toolbar`,children:[(0,v.jsxs)(`label`,{children:[(0,v.jsx)(`span`,{children:`Project`}),(0,v.jsx)(`select`,{className:`hq-select`,"aria-label":`Kanban project`,value:t,onChange:e=>r(e.target.value),children:e.map(e=>(0,v.jsx)(`option`,{value:e.projectId,children:e.projectName},e.projectId))})]}),(0,v.jsxs)(`label`,{children:[(0,v.jsx)(`span`,{children:`Board`}),(0,v.jsxs)(`select`,{className:`hq-select`,"aria-label":`Kanban board`,value:a,disabled:i.length===0,onChange:e=>o(e.target.value),children:[i.length===0?(0,v.jsx)(`option`,{value:``,children:`No boards`}):null,i.map(e=>(0,v.jsx)(`option`,{value:e.id,children:e.title},e.id))]})]}),(0,v.jsxs)(`div`,{className:`hq-kanban-sync`,children:[(0,v.jsx)(`span`,{children:s?`Synced ${W(s)}`:`Waiting for snapshot`}),(0,v.jsxs)(`button`,{type:`button`,onClick:l,disabled:c,"aria-label":`Refresh Kanban`,children:[(0,v.jsx)(n,{size:14,className:c?`is-spinning`:void 0}),`Refresh`]})]})]})}function z({project:e,board:t,boardCount:n}){return(0,v.jsxs)(`section`,{className:`hq-kanban-summary`,children:[(0,v.jsxs)(`div`,{className:`hq-kanban-heading`,children:[(0,v.jsxs)(`div`,{children:[(0,v.jsxs)(`span`,{children:[e?.projectName??`Project`,` · Kanban`]}),(0,v.jsx)(`h2`,{children:t.title}),t.description?(0,v.jsx)(`p`,{children:t.description}):null]}),(0,v.jsxs)(`div`,{className:`hq-kanban-board-meta`,children:[(0,v.jsxs)(`span`,{className:`hq-mono`,children:[`rev `,t.revision]}),(0,v.jsx)(`span`,{children:W(t.updatedAt)}),t.activePresence>0?(0,v.jsxs)(`span`,{className:`hq-pill active`,children:[t.activePresence,` active`]}):null]})]}),t.tags.length>0?(0,v.jsx)(`div`,{className:`hq-kanban-tags`,children:t.tags.map(e=>(0,v.jsx)(`span`,{className:`hq-pill info`,children:e},e))}):null,(0,v.jsxs)(`div`,{className:`hq-kanban-stats`,children:[(0,v.jsx)(B,{label:`Boards`,value:n}),(0,v.jsx)(B,{label:`Tasks`,value:t.taskCount}),(0,v.jsx)(B,{label:`Active`,value:t.activeTaskCount,tone:`active`}),(0,v.jsx)(B,{label:`Blocked`,value:t.blockedTaskCount,tone:`blocked`}),(0,v.jsx)(B,{label:`Done`,value:t.completedTaskCount,tone:`done`})]})]})}function B({label:e,value:t,tone:n}){return(0,v.jsxs)(`div`,{className:`hq-kanban-stat`,"data-tone":n,children:[(0,v.jsx)(`strong`,{children:t}),(0,v.jsx)(`span`,{children:e})]})}function V({board:e,onTaskClick:t,selectedTaskId:n}){return e.columns.length===0?(0,v.jsx)(`div`,{className:`hq-empty`,children:`This board does not have any columns yet.`}):(0,v.jsx)(`section`,{className:`hq-kanban-board`,"aria-label":`${e.title} Kanban board`,style:{"--hq-kanban-columns":Math.max(1,e.columns.length)},children:e.columns.map(e=>{let r=e.wipLimit!==void 0&&e.tasks.filter(e=>e.status!==`completed`).length>e.wipLimit;return(0,v.jsxs)(`div`,{className:`hq-kanban-column`,"data-over-limit":r,children:[(0,v.jsxs)(`header`,{style:e.color?{borderTopColor:e.color}:void 0,children:[(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`strong`,{children:e.title}),e.wipLimit===void 0?null:(0,v.jsxs)(`span`,{children:[`WIP `,e.tasks.length,`/`,e.wipLimit]})]}),(0,v.jsx)(`span`,{className:`hq-kanban-column-count`,children:e.tasks.length})]}),(0,v.jsx)(`div`,{className:`hq-kanban-column-body`,children:e.tasks.length===0?(0,v.jsx)(`div`,{className:`hq-kanban-column-empty`,children:`No cards`}):e.tasks.map(e=>(0,v.jsx)(H,{task:e,isSelected:e.id===n,onClick:()=>t(e.id)},e.id))})]},e.id)})})}function H({task:e,isSelected:n=!1,onClick:i}){return(0,v.jsxs)(`button`,{type:`button`,className:`hq-kanban-task`,"data-priority":e.priority,"data-selected":n,onClick:i,children:[(0,v.jsxs)(`div`,{className:`hq-kanban-task-topline`,children:[(0,v.jsx)(`span`,{className:`hq-pill ${e.status}`,children:e.status.replaceAll(`_`,` `)}),(0,v.jsx)(`span`,{className:`hq-kanban-priority ${e.priority}`,children:e.priority})]}),(0,v.jsx)(`h3`,{children:e.title}),e.description?(0,v.jsx)(`p`,{children:e.description}):null,e.labels.length>0?(0,v.jsx)(`div`,{className:`hq-kanban-task-labels`,children:e.labels.slice(0,4).map(e=>(0,v.jsx)(`span`,{children:e},e))}):null,(0,v.jsxs)(`footer`,{children:[e.assignee?(0,v.jsxs)(`span`,{title:e.assignmentStatus??`assigned`,children:[(0,v.jsx)(c,{size:12}),e.assignee]}):null,e.dependsOn.length>0?(0,v.jsxs)(`span`,{title:`${e.dependsOn.length} dependencies`,children:[(0,v.jsx)(f,{size:12}),e.dependsOn.length]}):null,e.dueDate?(0,v.jsxs)(`span`,{title:`Due ${new Date(e.dueDate).toLocaleString()}`,children:[(0,v.jsx)(t,{size:12}),U(e.dueDate)]}):null,e.status===`completed`?(0,v.jsx)(r,{size:13,className:`is-done`}):null]})]})}function U(e){let t=new Date(e);return Number.isFinite(t.getTime())?t.toLocaleDateString(void 0,{month:`short`,day:`numeric`}):e}function W(e){let t=Date.parse(e);if(!Number.isFinite(t))return e;let n=Math.max(0,Math.floor((Date.now()-t)/1e3));if(n<10)return`just now`;if(n<60)return`${n}s ago`;let r=Math.floor(n/60);if(r<60)return`${r}m ago`;let i=Math.floor(r/60);return i<24?`${i}h ago`:`${Math.floor(i/24)}d ago`}export{L as KanbanView};
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Dt as t,E as n,Ft as r,Mt as i,Nt as a,Xt as o,Zt as s,c,et as l,l as u,n as d,ut as f,xt as p}from"./icons-I81S_8cW.js";import{i as m}from"./markdown-C4I0Caum.js";import{s as h,u as g}from"./index-C5Ihi44B.js";var _=e(s(),1),v=m();function y({task:e,board:n,webuiUrl:i,dependencyTitles:a,onClose:o}){let s=e.dependsOn.map(e=>({id:e,title:a?.get(e)??e.slice(0,8)}));return(0,v.jsxs)(`aside`,{className:`hq-kanban-inspector`,"aria-label":`Task detail`,children:[(0,v.jsxs)(`header`,{className:`hq-kanban-inspector-header`,children:[(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`span`,{className:`hq-pill ${e.status}`,children:e.status.replaceAll(`_`,` `)}),(0,v.jsx)(`span`,{className:`hq-kanban-priority ${e.priority}`,children:e.priority})]}),(0,v.jsx)(`button`,{type:`button`,onClick:o,"aria-label":`Close inspector`,className:`hq-inspector-close`,children:(0,v.jsx)(d,{size:16})})]}),(0,v.jsx)(`h2`,{className:`hq-kanban-inspector-title`,children:e.title}),(0,v.jsx)(`span`,{className:`hq-mono hq-kanban-inspector-id`,children:e.id}),e.description?(0,v.jsxs)(`section`,{className:`hq-kanban-inspector-section`,children:[(0,v.jsx)(`h3`,{children:`Description`}),(0,v.jsx)(`p`,{className:`hq-kanban-inspector-description`,children:e.description})]}):null,(0,v.jsxs)(`section`,{className:`hq-kanban-inspector-section`,children:[(0,v.jsx)(`h3`,{children:`Details`}),(0,v.jsxs)(`dl`,{className:`hq-kanban-inspector-details`,children:[(0,v.jsxs)(`div`,{className:`hq-kanban-inspector-row`,children:[(0,v.jsxs)(`dt`,{children:[(0,v.jsx)(l,{size:13}),`Board`]}),(0,v.jsx)(`dd`,{children:n.title})]}),e.assignee?(0,v.jsxs)(`div`,{className:`hq-kanban-inspector-row`,children:[(0,v.jsxs)(`dt`,{children:[(0,v.jsx)(c,{size:13}),`Assignee`]}),(0,v.jsxs)(`dd`,{children:[e.assignee,e.assignmentStatus?(0,v.jsxs)(`span`,{className:`hq-mono`,style:{marginLeft:6,opacity:.7},children:[`(`,e.assignmentStatus,`)`]}):null]})]}):null,e.dueDate?(0,v.jsxs)(`div`,{className:`hq-kanban-inspector-row`,children:[(0,v.jsxs)(`dt`,{children:[(0,v.jsx)(t,{size:13}),`Due`]}),(0,v.jsx)(`dd`,{children:new Date(e.dueDate).toLocaleString()})]}):null,e.columnId?(0,v.jsxs)(`div`,{className:`hq-kanban-inspector-row`,children:[(0,v.jsxs)(`dt`,{children:[(0,v.jsx)(l,{size:13}),`Column`]}),(0,v.jsx)(`dd`,{children:n.columns.find(t=>t.id===e.columnId)?.title??e.columnId})]}):null]})]}),e.labels.length>0?(0,v.jsxs)(`section`,{className:`hq-kanban-inspector-section`,children:[(0,v.jsx)(`h3`,{children:`Labels`}),(0,v.jsx)(`div`,{className:`hq-kanban-inspector-labels`,children:e.labels.map(e=>(0,v.jsx)(`span`,{className:`hq-pill info`,children:e},e))})]}):null,s.length>0?(0,v.jsxs)(`section`,{className:`hq-kanban-inspector-section`,children:[(0,v.jsxs)(`h3`,{children:[(0,v.jsx)(f,{size:13}),`Dependencies (`,s.length,`)`]}),(0,v.jsx)(`ul`,{className:`hq-kanban-inspector-deps`,children:s.map(t=>(0,v.jsxs)(`li`,{children:[(0,v.jsx)(`span`,{className:`hq-mono`,children:t.id.slice(0,8)}),(0,v.jsx)(`span`,{children:t.title}),e.status===`completed`?(0,v.jsx)(r,{size:13,className:`is-done`}):null]},t.id))})]}):null,e.status===`blocked`||e.status===`failed`?(0,v.jsxs)(`div`,{className:`hq-kanban-inspector-alert`,children:[(0,v.jsx)(u,{size:14}),(0,v.jsxs)(`span`,{children:[`This task is `,e.status,` and may need attention.`]})]}):null,i?(0,v.jsx)(`footer`,{className:`hq-kanban-inspector-footer`,children:(0,v.jsxs)(`a`,{href:i,target:`_blank`,rel:`noopener noreferrer`,className:`hq-button hq-button-primary`,children:[(0,v.jsx)(p,{size:14}),`Open in WebUI`]})}):null]})}function b({board:e}){let n=x(e),s=n.blocked===0&&n.failed===0;return(0,v.jsxs)(`div`,{className:`hq-kanban-queue-health`,role:`status`,"aria-label":`Queue health`,children:[(0,v.jsx)(`span`,{className:`hq-kanban-qh-label`,children:`Queue health`}),n.startable>0?(0,v.jsxs)(`span`,{className:`hq-kanban-qh-pill ready`,title:`Claimable tasks`,children:[(0,v.jsx)(i,{size:12}),n.startable,` ready`]}):null,n.running>0?(0,v.jsxs)(`span`,{className:`hq-kanban-qh-pill running`,title:`Running assignments`,children:[(0,v.jsx)(o,{size:12}),n.running,` running`]}):null,n.review>0?(0,v.jsxs)(`span`,{className:`hq-kanban-qh-pill review`,title:`In review`,children:[(0,v.jsx)(t,{size:12}),n.review,` review`]}):null,n.blocked>0?(0,v.jsxs)(`span`,{className:`hq-kanban-qh-pill blocked`,title:`Manually blocked`,children:[(0,v.jsx)(a,{size:12}),n.blocked,` blocked`]}):null,n.failed>0?(0,v.jsxs)(`span`,{className:`hq-kanban-qh-pill failed`,title:`Failed tasks`,children:[(0,v.jsx)(u,{size:12}),n.failed,` failed`]}):null,s?(0,v.jsxs)(`span`,{className:`hq-kanban-qh-pill healthy`,title:`No issues detected`,children:[(0,v.jsx)(r,{size:12}),`healthy`]}):null]})}function x(e){let t={startable:0,running:0,review:0,blocked:0,failed:0},n=new Set;for(let t of e.columns)for(let e of t.tasks)e.status===`completed`&&n.add(e.id);for(let r of e.columns)for(let e of r.tasks){let r=e.assignmentStatus===`running`||e.assignmentStatus===`queued`;switch((e.status===`in_progress`||e.assignmentStatus===`running`)&&t.running++,!r&&(e.status===`pending`||e.status===`ready`)&&e.dependsOn.every(e=>n.has(e))&&t.startable++,e.status){case`review`:t.review++;break;case`blocked`:t.blocked++;break;case`failed`:t.failed++}}return t}var S=new Set([`low`,`medium`,`high`,`critical`]),C=new Set([`pending`,`ready`,`in_progress`,`review`,`completed`,`blocked`,`failed`,`archived`]);function w(e){return`/api/projects/${encodeURIComponent(e)}/kanban`}function T(e){return e.boards.map(e=>E(e)).filter(e=>e!==null).sort((e,t)=>t.updatedAt.localeCompare(e.updatedAt))}function E(e){let t=e.board;if(t.id!==e.boardId)return null;let n=k(t.columns).map(D).filter(e=>e!==null),r=k(t.tasks).map(O).filter(e=>e!==null),i=new Set(n.map(e=>e.id)),a=new Set(r.map(e=>e.columnId).filter(e=>!i.has(e)));for(let e of a)n.push({id:e,title:e.length>0?e:`Unmapped`,order:2**53-1});let o=n.sort((e,t)=>e.order-t.order||e.title.localeCompare(t.title)).map(e=>({...e,tasks:r.filter(t=>t.columnId===e.id).sort((e,t)=>e.order-t.order||e.title.localeCompare(t.title))}));return{id:e.boardId,title:M(t.title)??e.boardId,description:M(t.description),tags:j(t.tags),revision:e.revision,updatedAt:e.updatedAt,activePresence:k(t.presence).filter(e=>e.active===!0).length,taskCount:r.length,completedTaskCount:r.filter(e=>e.status===`completed`).length,activeTaskCount:r.filter(e=>e.status===`in_progress`||e.status===`review`).length,blockedTaskCount:r.filter(e=>e.status===`blocked`||e.status===`failed`).length,columns:o}}function D(e){let t=M(e.id),n=M(e.title);return!t||!n?null:{id:t,title:n,color:M(e.color),order:N(e.order)??0,wipLimit:N(e.wipLimit)}}function O(e){let t=M(e.id),n=M(e.title),r=M(e.columnId);if(!t||!n||r===void 0)return null;let i=A(e.assignment);return{id:t,title:n,description:M(e.description),columnId:r,order:N(e.order)??0,priority:P(e.priority,S)??`medium`,status:P(e.status,C)??`pending`,assignee:M(e.assignee)??M(e.assignedAgent)??M(i?.name)??M(i?.agentId),assignmentStatus:M(i?.status),labels:j(e.labels),dependsOn:j(e.dependsOn),dueDate:M(e.dueDate)}}function k(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&!Array.isArray(e)):[]}function A(e){return typeof e==`object`&&e&&!Array.isArray(e)?e:void 0}function j(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function M(e){return typeof e==`string`?e:void 0}function N(e){return typeof e==`number`&&Number.isFinite(e)?e:void 0}function P(e,t){return typeof e==`string`&&t.has(e)?e:void 0}var F=1e4,I=[];function L(){let e=g(e=>e.snapshot?.projects??I),t=g(e=>{for(let t=e.events.length-1;t>=0;t--){let n=e.events[t];if(n?.type===`kanban.snapshot`)return n.id}return null}),[r,i]=(0,_.useState)(``),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(null),[l,d]=(0,_.useState)(!1),[f,p]=(0,_.useState)(!1),[m,x]=(0,_.useState)(null),S=(0,_.useRef)(0),C=(0,_.useRef)(t);(0,_.useEffect)(()=>{if(e.length===0){i(``),c(null);return}e.some(e=>e.projectId===r)||i(e[0].projectId)},[r,e]);let E=(0,_.useCallback)(async(e=!1)=>{if(!r)return;let t=++S.current;e?d(!0):p(!0);try{let e=await h(w(r));if(t!==S.current)return;c(e),x(null)}catch(e){if(t!==S.current)return;x(e instanceof Error?e.message:String(e))}finally{t===S.current&&(d(!1),p(!1))}},[r]);(0,_.useEffect)(()=>{S.current++,c(null),o(``),x(null)},[r]),(0,_.useEffect)(()=>{if(!r)return;E(!0);let e=window.setInterval(()=>void E(!1),F);return()=>{S.current++,window.clearInterval(e)}},[E,r]),(0,_.useEffect)(()=>{t!==null&&t!==C.current&&(C.current=t,r&&E(!1))},[t,E,r]);let D=(0,_.useMemo)(()=>s?T(s):[],[s]);(0,_.useEffect)(()=>{D.length===0?o(``):D.some(e=>e.id===a)||o(D[0].id)},[a,D]);let O=D.find(e=>e.id===a)??null,k=e.find(e=>e.projectId===r)??null,[A,j]=(0,_.useState)(null);(0,_.useEffect)(()=>{j(null)},[a]);let M=(0,_.useMemo)(()=>{if(!O||!A)return null;for(let e of O.columns){let t=e.tasks.find(e=>e.id===A);if(t)return t}return null},[O,A]),N=(0,_.useMemo)(()=>{if(!O)return new Map;let e=new Map;for(let t of O.columns)for(let n of t.tasks)e.set(n.id,n.title);return e},[O]);return e.length===0?(0,v.jsx)(`div`,{className:`hq-empty`,children:`No HQ projects are available. Connect a WrongStack client to publish its project identity and Kanban snapshot.`}):(0,v.jsxs)(`div`,{className:`hq-kanban-view`,children:[(0,v.jsx)(R,{projects:e,projectId:r,onProjectChange:e=>i(e),boards:D,boardId:a,onBoardChange:o,generatedAt:s?.generatedAt,refreshing:f,onRefresh:()=>void E(!1)}),m?(0,v.jsxs)(`div`,{className:`hq-kanban-error`,role:`alert`,children:[(0,v.jsx)(u,{size:15}),(0,v.jsx)(`span`,{children:m}),(0,v.jsx)(`button`,{type:`button`,onClick:()=>void E(!0),children:`Retry`})]}):null,l&&s===null?(0,v.jsxs)(`div`,{className:`hq-view-loading`,role:`status`,children:[(0,v.jsx)(n,{size:18}),(0,v.jsx)(`span`,{children:`Loading project boards…`})]}):O?(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)(z,{project:k,board:O,boardCount:D.length}),(0,v.jsx)(b,{board:O}),(0,v.jsxs)(`div`,{className:`hq-kanban-main`,children:[(0,v.jsx)(V,{board:O,onTaskClick:j,selectedTaskId:A}),M?(0,v.jsx)(y,{task:M,board:O,dependencyTitles:N,onClose:()=>j(null)}):null]})]}):(0,v.jsxs)(`div`,{className:`hq-empty`,children:[`This project has not published a Kanban board yet. Create one with `,(0,v.jsx)(`code`,{children:`/kanban`}),` `,`from any connected clone.`]})]})}function R({projects:e,projectId:t,onProjectChange:r,boards:i,boardId:a,onBoardChange:o,generatedAt:s,refreshing:c,onRefresh:l}){return(0,v.jsxs)(`div`,{className:`hq-kanban-toolbar`,children:[(0,v.jsxs)(`label`,{children:[(0,v.jsx)(`span`,{children:`Project`}),(0,v.jsx)(`select`,{className:`hq-select`,"aria-label":`Kanban project`,value:t,onChange:e=>r(e.target.value),children:e.map(e=>(0,v.jsx)(`option`,{value:e.projectId,children:e.projectName},e.projectId))})]}),(0,v.jsxs)(`label`,{children:[(0,v.jsx)(`span`,{children:`Board`}),(0,v.jsxs)(`select`,{className:`hq-select`,"aria-label":`Kanban board`,value:a,disabled:i.length===0,onChange:e=>o(e.target.value),children:[i.length===0?(0,v.jsx)(`option`,{value:``,children:`No boards`}):null,i.map(e=>(0,v.jsx)(`option`,{value:e.id,children:e.title},e.id))]})]}),(0,v.jsxs)(`div`,{className:`hq-kanban-sync`,children:[(0,v.jsx)(`span`,{children:s?`Synced ${W(s)}`:`Waiting for snapshot`}),(0,v.jsxs)(`button`,{type:`button`,onClick:l,disabled:c,"aria-label":`Refresh Kanban`,children:[(0,v.jsx)(n,{size:14,className:c?`is-spinning`:void 0}),`Refresh`]})]})]})}function z({project:e,board:t,boardCount:n}){return(0,v.jsxs)(`section`,{className:`hq-kanban-summary`,children:[(0,v.jsxs)(`div`,{className:`hq-kanban-heading`,children:[(0,v.jsxs)(`div`,{children:[(0,v.jsxs)(`span`,{children:[e?.projectName??`Project`,` · Kanban`]}),(0,v.jsx)(`h2`,{children:t.title}),t.description?(0,v.jsx)(`p`,{children:t.description}):null]}),(0,v.jsxs)(`div`,{className:`hq-kanban-board-meta`,children:[(0,v.jsxs)(`span`,{className:`hq-mono`,children:[`rev `,t.revision]}),(0,v.jsx)(`span`,{children:W(t.updatedAt)}),t.activePresence>0?(0,v.jsxs)(`span`,{className:`hq-pill active`,children:[t.activePresence,` active`]}):null]})]}),t.tags.length>0?(0,v.jsx)(`div`,{className:`hq-kanban-tags`,children:t.tags.map(e=>(0,v.jsx)(`span`,{className:`hq-pill info`,children:e},e))}):null,(0,v.jsxs)(`div`,{className:`hq-kanban-stats`,children:[(0,v.jsx)(B,{label:`Boards`,value:n}),(0,v.jsx)(B,{label:`Tasks`,value:t.taskCount}),(0,v.jsx)(B,{label:`Active`,value:t.activeTaskCount,tone:`active`}),(0,v.jsx)(B,{label:`Blocked`,value:t.blockedTaskCount,tone:`blocked`}),(0,v.jsx)(B,{label:`Done`,value:t.completedTaskCount,tone:`done`})]})]})}function B({label:e,value:t,tone:n}){return(0,v.jsxs)(`div`,{className:`hq-kanban-stat`,"data-tone":n,children:[(0,v.jsx)(`strong`,{children:t}),(0,v.jsx)(`span`,{children:e})]})}function V({board:e,onTaskClick:t,selectedTaskId:n}){return e.columns.length===0?(0,v.jsx)(`div`,{className:`hq-empty`,children:`This board does not have any columns yet.`}):(0,v.jsx)(`section`,{className:`hq-kanban-board`,"aria-label":`${e.title} Kanban board`,style:{"--hq-kanban-columns":Math.max(1,e.columns.length)},children:e.columns.map(e=>{let r=e.wipLimit!==void 0&&e.tasks.filter(e=>e.status!==`completed`).length>e.wipLimit;return(0,v.jsxs)(`div`,{className:`hq-kanban-column`,"data-over-limit":r,children:[(0,v.jsxs)(`header`,{style:e.color?{borderTopColor:e.color}:void 0,children:[(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`strong`,{children:e.title}),e.wipLimit===void 0?null:(0,v.jsxs)(`span`,{children:[`WIP `,e.tasks.length,`/`,e.wipLimit]})]}),(0,v.jsx)(`span`,{className:`hq-kanban-column-count`,children:e.tasks.length})]}),(0,v.jsx)(`div`,{className:`hq-kanban-column-body`,children:e.tasks.length===0?(0,v.jsx)(`div`,{className:`hq-kanban-column-empty`,children:`No cards`}):e.tasks.map(e=>(0,v.jsx)(H,{task:e,isSelected:e.id===n,onClick:()=>t(e.id)},e.id))})]},e.id)})})}function H({task:e,isSelected:n=!1,onClick:i}){return(0,v.jsxs)(`button`,{type:`button`,className:`hq-kanban-task`,"data-priority":e.priority,"data-selected":n,onClick:i,children:[(0,v.jsxs)(`div`,{className:`hq-kanban-task-topline`,children:[(0,v.jsx)(`span`,{className:`hq-pill ${e.status}`,children:e.status.replaceAll(`_`,` `)}),(0,v.jsx)(`span`,{className:`hq-kanban-priority ${e.priority}`,children:e.priority})]}),(0,v.jsx)(`h3`,{children:e.title}),e.description?(0,v.jsx)(`p`,{children:e.description}):null,e.labels.length>0?(0,v.jsx)(`div`,{className:`hq-kanban-task-labels`,children:e.labels.slice(0,4).map(e=>(0,v.jsx)(`span`,{children:e},e))}):null,(0,v.jsxs)(`footer`,{children:[e.assignee?(0,v.jsxs)(`span`,{title:e.assignmentStatus??`assigned`,children:[(0,v.jsx)(c,{size:12}),e.assignee]}):null,e.dependsOn.length>0?(0,v.jsxs)(`span`,{title:`${e.dependsOn.length} dependencies`,children:[(0,v.jsx)(f,{size:12}),e.dependsOn.length]}):null,e.dueDate?(0,v.jsxs)(`span`,{title:`Due ${new Date(e.dueDate).toLocaleString()}`,children:[(0,v.jsx)(t,{size:12}),U(e.dueDate)]}):null,e.status===`completed`?(0,v.jsx)(r,{size:13,className:`is-done`}):null]})]})}function U(e){let t=new Date(e);return Number.isFinite(t.getTime())?t.toLocaleDateString(void 0,{month:`short`,day:`numeric`}):e}function W(e){let t=Date.parse(e);if(!Number.isFinite(t))return e;let n=Math.max(0,Math.floor((Date.now()-t)/1e3));if(n<10)return`just now`;if(n<60)return`${n}s ago`;let r=Math.floor(n/60);if(r<60)return`${r}m ago`;let i=Math.floor(r/60);return i<24?`${i}h ago`:`${Math.floor(i/24)}d ago`}export{L as KanbanView};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Bt as t,Kt as n,N as r,O as i,R as a,T as o,Yt as s,Zt as c,f as l,mt as u,x as d,z as f}from"./icons-I81S_8cW.js";import{i as p}from"./markdown-C4I0Caum.js";import{c as m,n as h,o as g,p as _,u as v}from"./index-Da_ivWpO.js";import{c as ee,l as te,s as y,t as b,u as x}from"./fleet-topology-BrormAze.js";var S=e(c(),1);function C(e,t,n){if(e===null||t===null)return null;let r=(e.liveSessions??[]).find(e=>e.sessionId===t);if(r===void 0)return null;let i=e.sessions.find(e=>e.sessionId===t)?.clientId,a=r.clientId??i,o=e.clients.find(e=>e.connected&&e.clientId===a),s=e.clients.filter(e=>e.connected&&e.machineId===r.machineId&&e.projectId===r.projectId&&(r.pid===void 0||e.pid===r.pid)),c=(o?.capabilities.includes(`control.receive`)===!0?o:void 0)??s.find(e=>e.kind===r.clientKind&&e.capabilities.includes(`control.receive`))??s.find(e=>e.capabilities.includes(`control.receive`))??o??s[0],l=n===null?null:r.agents.find(e=>e.id===n)??null,u=n===null||n===`leader`?`leader`:n,d=e.clients.some(e=>e.connected&&e.projectId===r.projectId&&e.capabilities.includes(`mailbox.serve`));return{session:r,client:c??null,agent:l,recipient:u,controllable:c?.capabilities.includes(`control.receive`)===!0,mailboxServeActive:d}}var w=p();function T(e){let t=b(e),n=[],r=new Map,i=new Map,a=new Map,o=e=>`machine:${e.machineId}`,s=e=>`project:${e.machineId}:${e.projectId}`;for(let e of t.nodes){if(e.kind!==`machine`)continue;let t={id:e.id,label:e.label,sub:e.sub,projects:[]};r.set(e.id,t),n.push(t)}for(let e of t.nodes){if(e.kind!==`project`)continue;let t=r.get(o(e));if(t===void 0)continue;let n={id:e.id,label:e.label,clients:[]};i.set(e.id,n),t.projects.push(n)}for(let e of t.nodes){if(e.kind!==`terminal`||e.sessionId===void 0||e.serviceMode!==void 0)continue;let t=i.get(s(e));if(t===void 0)continue;let n={clientId:e.clientId,sessionId:e.sessionId,label:e.label,clientKind:e.clientKind,status:e.status,synthetic:e.isSyntheticSession===!0,agents:[]};a.set(e.sessionId,n),t.clients.push(n)}for(let e of t.nodes){if(e.kind!==`agent`||e.sessionId===void 0||e.agentId===void 0)continue;let t=a.get(e.sessionId);t!==void 0&&t.agents.push({id:e.agentId,label:e.label,status:e.status})}return n.map(e=>({...e,projects:e.projects.filter(e=>e.clients.length>0)})).filter(e=>e.projects.length>0)}function E(e){return e===`active`||e===`running`||e===`streaming`?`active`:e===`waiting_user`?`warn`:e===`error`||e===`stale`||e===`closing`?`error`:`idle`}function D({snapshot:e,selectedSessionId:r,selectedAgentId:i}){let o=(0,S.useMemo)(()=>T(e),[e]),[s,c]=(0,S.useState)(new Set),d=e=>c(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n});return o.length===0?(0,w.jsx)(`div`,{className:`hq-fleetnav`,children:(0,w.jsx)(`div`,{className:`hq-empty hq-pad-md`,children:`No live sessions. Open a WrongStack CLI/TUI/WebUI connected to HQ.`})}):(0,w.jsx)(`div`,{className:`hq-fleetnav`,role:`tree`,"aria-label":`Fleet navigator`,children:o.map(e=>{let o=!s.has(e.id);return(0,w.jsxs)(`div`,{className:`hq-nav-machine`,children:[(0,w.jsxs)(`button`,{type:`button`,className:`hq-nav-row machine`,onClick:()=>d(e.id),"aria-expanded":o,children:[(0,w.jsx)(t,{size:12,className:`hq-nav-caret`+(o?` open`:``)}),(0,w.jsx)(a,{size:13}),(0,w.jsx)(`span`,{className:`hq-nav-label`,title:e.sub??e.label,children:e.label})]}),o&&e.projects.map(e=>{let a=!s.has(e.id);return(0,w.jsxs)(`div`,{className:`hq-nav-project`,children:[(0,w.jsxs)(`button`,{type:`button`,className:`hq-nav-row project`,onClick:()=>d(e.id),"aria-expanded":a,children:[(0,w.jsx)(t,{size:12,className:`hq-nav-caret`+(a?` open`:``)}),(0,w.jsx)(u,{size:13}),(0,w.jsx)(`span`,{className:`hq-nav-label`,title:e.label,children:e.label})]}),a&&e.clients.map(e=>{let a=!s.has(e.sessionId),o=r===e.sessionId&&i===null;return(0,w.jsxs)(`div`,{className:`hq-nav-client`,children:[(0,w.jsxs)(`div`,{className:`hq-nav-clientrow`,children:[e.agents.length>0?(0,w.jsx)(`button`,{type:`button`,className:`hq-nav-caretbtn`,onClick:()=>d(e.sessionId),"aria-label":a?`Collapse`:`Expand`,children:(0,w.jsx)(t,{size:12,className:`hq-nav-caret`+(a?` open`:``)})}):(0,w.jsx)(`span`,{className:`hq-nav-caretbtn`}),(0,w.jsxs)(`button`,{type:`button`,className:`hq-nav-row client`+(o?` selected`:``),disabled:e.synthetic,onClick:()=>{e.synthetic||(v.getState().selectSession(e.sessionId),e.clientId!==void 0&&v.getState().selectClient(e.clientId))},title:e.synthetic?`waiting for session telemetry`:e.label,children:[(0,w.jsx)(`span`,{className:`hq-nav-dot `+E(e.status)}),(0,w.jsx)(l,{size:12}),(0,w.jsx)(`span`,{className:`hq-nav-label`,children:e.label}),e.agents.length>0&&(0,w.jsx)(`span`,{className:`hq-nav-count`,children:e.agents.length})]})]}),a&&e.agents.map(t=>{let a=r===e.sessionId&&i===t.id;return(0,w.jsxs)(`button`,{type:`button`,className:`hq-nav-row agent`+(a?` selected`:``),onClick:()=>{v.getState().selectAgent(e.sessionId,t.id),e.clientId!==void 0&&v.getState().selectClient(e.clientId)},title:t.label,children:[(0,w.jsx)(`span`,{className:`hq-nav-dot `+E(t.status)}),(0,w.jsx)(n,{size:12}),(0,w.jsx)(`span`,{className:`hq-nav-label`,children:t.label})]},t.id)})]},e.sessionId)})]},e.id)})]},e.id)})})}function O(e){return e===`completed`?`active`:e===`failed`||e===`rejected`?`error`:e===`delivered`||e===`accepted`?`info`:`warn`}function k({receipt:e,lifecycle:t}){let n=new Date(e.createdAt).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`,second:`2-digit`}),i=(0,w.jsx)(`span`,{className:`hq-pill ${O(t)}`,children:t});return e.type===`abort`?(0,w.jsx)(`div`,{className:`hq-chat-turn system hq-command-turn`,"data-command-id":e.commandId,children:(0,w.jsxs)(`span`,{className:`hq-chat-system-line`,children:[(0,w.jsx)(r,{size:12}),` `,e.preview,` `,i,(0,w.jsx)(`span`,{className:`hq-chat-clock`,children:n})]})}):(0,w.jsx)(`div`,{className:`hq-chat-turn user hq-command-turn`,"data-command-id":e.commandId,children:(0,w.jsxs)(`div`,{className:`hq-chat-bubble user`,children:[(0,w.jsxs)(`div`,{className:`hq-chat-role`,children:[`you → `,e.target,` · `,e.type,` `,i,(0,w.jsx)(`span`,{className:`hq-chat-clock`,children:n})]}),(0,w.jsx)(`div`,{className:`hq-chat-prose`,children:e.preview})]})})}function A(){let{selectedSessionId:e,selectedAgentId:t,snapshot:a,commandStatuses:c}=v(_(e=>({selectedSessionId:e.selectedSessionId,selectedAgentId:e.selectedAgentId,snapshot:e.snapshot,commandStatuses:e.commandStatuses}))),l=e,u=t,p=u!==null,b=g().console,[T,E]=(0,S.useState)(b.delivery),[O,A]=(0,S.useState)(b.subject),[M,N]=(0,S.useState)(b.body),[P,F]=(0,S.useState)(!1),[I,L]=(0,S.useState)(null),[ne,R]=(0,S.useState)(!1),[z,B]=(0,S.useState)(!1),[V,H]=(0,S.useState)([]),U=te(l,u),{entries:W,meta:G,stats:K}=U,q=(0,S.useMemo)(()=>V.filter(e=>{if(e.type===`abort`)return!0;let t=Date.parse(e.createdAt);return!W.some(n=>n.role===`user`&&n.text.trim()===e.preview&&Math.abs(Date.parse(n.ts)-t)<12e4)}),[W,V]);(0,S.useEffect)(()=>{if(!U.pinned||q.length===0)return;let e=window.requestAnimationFrame(()=>{U.listRef.current?.scrollToIndex(W.length+q.length-1,{align:`end`})});return()=>window.cancelAnimationFrame(e)},[U.listRef,U.pinned,W.length,q.length]);let J=()=>{U.jumpToLatest(),window.requestAnimationFrame(()=>{U.listRef.current?.scrollToIndex(W.length+q.length-1,{align:`end`})})},Y=(0,S.useMemo)(()=>C(a,l,u),[u,l,a]),X=Y?.agent??null,Z=Y?.recipient===`leader`,Q=X?.name??(Z?`Leader agent`:Y?.recipient??`agent`);(0,S.useEffect)(()=>{let e=Y?.client?.clientId;e!==void 0&&v.getState().selectClient(e),L(null),R(!1),B(!1),H([])},[Y?.client?.clientId,l,u]);let $=async()=>{if(Y?.client===null||Y?.client===void 0||!Y.controllable||M.trim().length===0)return;F(!0),L(null);let e=M.trim();try{let t=await m(Y.client.clientId,T,{to:Y.recipient,subject:O.trim()||`HQ ${T}`,body:e,priority:T===`steer`?`high`:`normal`});N(``),h({body:``}),H(n=>[...n,{commandId:t.commandId,type:T,target:Q,preview:e,createdAt:new Date().toISOString()}].slice(-8)),L({tone:`ok`,text:`${T} queued for ${Q} · ${t.commandId}`})}catch(e){L({tone:`error`,text:e instanceof Error?e.message:String(e)})}finally{F(!1)}},re=async()=>{if(Y?.client!==null&&Y?.client!==void 0){F(!0),L(null);try{let e=await m(Y.client.clientId,`abort`,{target:Y.recipient});if(H(t=>[...t,{commandId:e.commandId,type:`abort`,target:Q,preview:`Interrupt ${Q}`,createdAt:new Date().toISOString()}].slice(-8)),Z&&z){let e=await m(Y.client.clientId,`abort`,{target:`fleet`});H(t=>[...t,{commandId:e.commandId,type:`abort`,target:`all subagents`,preview:`Interrupt every subagent on this client`,createdAt:new Date().toISOString()}].slice(-8))}L({tone:`ok`,text:Z&&z?`Leader interrupt queued; all subagents will be interrupted too.`:`${Q} interrupt queued.`}),R(!1)}catch(e){L({tone:`error`,text:e instanceof Error?e.message:String(e)})}finally{F(!1)}}};return(0,w.jsxs)(`div`,{className:`hq-console-shell`,children:[(0,w.jsxs)(`header`,{className:`hq-console-overview`,children:[(0,w.jsxs)(`div`,{className:`hq-console-overview-copy`,children:[(0,w.jsx)(`span`,{className:`hq-console-live-dot`,"data-live":Y!==null,"aria-hidden":`true`}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`span`,{children:`Live transcript`}),(0,w.jsx)(`strong`,{children:l===null?`Select an endpoint`:p?X?.name??u:G.projectName??Q}),(0,w.jsx)(`small`,{children:l===null?`Choose a client or agent from the fleet navigator`:Y?.controllable===!0?`${Q} · control channel ready`:`${Q} · transcript is read-only`})]})]}),(0,w.jsxs)(`fieldset`,{className:`hq-console-overview-metrics`,"aria-label":`Transcript totals`,children:[(0,w.jsx)(j,{label:`turns`,value:K.turns+q.length}),(0,w.jsx)(j,{label:`tools`,value:K.tools}),(0,w.jsx)(j,{label:`running`,value:K.running,tone:K.running>0?`active`:void 0}),(0,w.jsx)(j,{label:`errors`,value:K.errors,tone:K.errors>0?`error`:void 0})]})]}),(0,w.jsx)(D,{snapshot:a??null,selectedSessionId:l,selectedAgentId:u}),(0,w.jsxs)(`div`,{className:`hq-console`,children:[(0,w.jsxs)(`div`,{className:`hq-chat-header`,children:[(0,w.jsx)(f,{size:15,className:`hq-chat-header-icon`}),(0,w.jsx)(`span`,{className:`hq-card-title hq-title-inline`,children:`Console`}),p&&(0,w.jsxs)(`span`,{className:`hq-pill active`,children:[(0,w.jsx)(n,{size:12}),` `,X?.name??u]}),G.projectName!==void 0&&!p&&(0,w.jsx)(`span`,{className:`hq-pill`,children:G.projectName}),Y!==null&&(0,w.jsxs)(`span`,{className:`hq-pill info`,title:Y.client?.clientId,children:[Y.session.hostname??Y.session.machineId,` ·`,` `,Y.session.clientKind.toUpperCase()]}),Y?.mailboxServeActive===!0&&(0,w.jsx)(`span`,{className:`hq-pill active`,children:`mailbox serve`}),G.source!==void 0&&(0,w.jsx)(`span`,{className:`hq-pill`,title:G.source===`disk`?`disk = full history replayed from this machine`:`stream = live ring only (remote or not yet persisted)`,children:G.source===`disk`?`full history`:`live ring`}),(0,w.jsxs)(`span`,{className:`hq-chat-counts`,children:[(0,w.jsxs)(`span`,{className:`hq-pill`,children:[K.turns+q.length,` turns`]}),(0,w.jsxs)(`span`,{className:`hq-pill`,children:[K.tools,` tools`]}),K.running>0&&(0,w.jsxs)(`span`,{className:`hq-pill running`,children:[K.running,` running`]}),K.errors>0&&(0,w.jsxs)(`span`,{className:`hq-pill error`,children:[K.errors,` err`]}),!p&&!U.full&&G.total>W.length&&(0,w.jsxs)(`button`,{type:`button`,className:`hq-btn secondary hq-chat-fullbtn`,onClick:()=>U.setFull(!0),title:`History is truncated — load all ${G.total} turns`,children:[(0,w.jsx)(o,{size:12}),` load all `,G.total]})]})]}),l===null?(0,w.jsxs)(`div`,{className:`hq-console-empty`,children:[(0,w.jsx)(`span`,{"aria-hidden":`true`,children:(0,w.jsx)(f,{size:24})}),(0,w.jsx)(`strong`,{children:`Choose a conversation`}),(0,w.jsx)(`small`,{children:`Pick a live client or agent from the fleet navigator to inspect its transcript.`})]}):U.loading&&W.length===0&&q.length===0?(0,w.jsx)(`div`,{className:`hq-empty`,children:p?`Loading agent history…`:`Loading transcript…`}):U.error===null?(0,w.jsxs)(`div`,{className:`hq-chat-scroll`,children:[W.length===0&&q.length===0?(0,w.jsx)(`div`,{className:`hq-empty`,children:p?`No messages from ${X?.name??u??`this agent`} yet.`:`No transcript entries yet.`}):(0,w.jsxs)(x,{ref:U.listRef,onScroll:U.onScroll,className:`hq-chat-vlist`,children:[W.map((e,t)=>(0,w.jsx)(`div`,{className:`hq-chat-rowpad`,children:(0,w.jsx)(y,{entry:e,running:U.isRunningAt(e,t)})},ee(e,t))),q.map(e=>{let t=c.find(t=>t.commandId===e.commandId),n=t?.ackStatus??t?.status??`queued`;return(0,w.jsx)(`div`,{className:`hq-chat-rowpad`,"aria-live":`polite`,children:(0,w.jsx)(k,{receipt:e,lifecycle:n})},`receipt:${e.commandId}`)})]}),!U.pinned&&(W.length>0||q.length>0)&&(0,w.jsx)(`button`,{type:`button`,className:`hq-chat-jump`,onClick:J,title:`Jump to latest`,children:(0,w.jsx)(s,{size:14})})]}):(0,w.jsxs)(`div`,{className:`hq-empty`,children:[`Error: `,U.error]}),l!==null&&(0,w.jsxs)(`div`,{className:`hq-console-composer`,children:[(0,w.jsxs)(`div`,{className:`hq-console-composer-head`,children:[(0,w.jsxs)(`span`,{children:[(0,w.jsx)(i,{size:13}),` Send to `,(0,w.jsx)(`strong`,{children:Q})]}),(0,w.jsx)(`span`,{className:`hq-pill ${Y?.controllable===!0?`active`:`error`}`,children:Y?.controllable===!0?`control live`:`read-only client`})]}),(0,w.jsxs)(`div`,{className:`hq-console-compose-row`,children:[(0,w.jsxs)(`select`,{className:`hq-select hq-console-delivery`,"aria-label":`Message delivery mode`,value:T,onChange:e=>{let t=e.target.value;E(t),h({delivery:t})},children:[(0,w.jsx)(`option`,{value:`steer`,children:`Steer now`}),(0,w.jsx)(`option`,{value:`btw`,children:`BTW / FYI`}),(0,w.jsx)(`option`,{value:`queue`,children:`Queue next`})]}),(0,w.jsx)(`input`,{className:`hq-input hq-console-subject`,"aria-label":`Message subject`,placeholder:`HQ ${T} (optional subject)`,value:O,onChange:e=>{A(e.target.value),h({subject:e.target.value})}}),(0,w.jsxs)(`button`,{type:`button`,className:`hq-btn danger hq-console-interrupt`,disabled:P||Y?.controllable!==!0,onClick:()=>{B(!1),R(!0)},children:[(0,w.jsx)(r,{size:13}),` Interrupt`]})]}),(0,w.jsxs)(`div`,{className:`hq-console-compose-row hq-console-message-row`,children:[(0,w.jsx)(`textarea`,{className:`hq-textarea hq-console-message`,"aria-label":`Message ${Q}`,placeholder:`Message ${Q}…`,rows:2,value:M,onChange:e=>{N(e.target.value),h({body:e.target.value})},onKeyDown:e=>{e.key===`Enter`&&(e.ctrlKey||e.metaKey)&&(e.preventDefault(),$())}}),(0,w.jsxs)(`button`,{type:`button`,className:`hq-btn primary hq-console-send`,disabled:P||M.trim().length===0||Y?.controllable!==!0,onClick:()=>void $(),children:[(0,w.jsx)(d,{size:13}),` `,P?`Queueing…`:`Send`]})]}),(0,w.jsxs)(`div`,{className:`hq-console-compose-foot`,children:[(0,w.jsx)(`span`,{children:`Ctrl+Enter sends · steer interrupts at the next safe turn`}),I!==null&&(0,w.jsx)(`span`,{className:`hq-console-status ${I.tone}`,children:I.text})]})]})]}),ne&&Y!==null&&(0,w.jsxs)(`div`,{className:`hq-confirm-layer`,role:`presentation`,children:[(0,w.jsx)(`button`,{type:`button`,className:`hq-confirm-scrim`,"aria-label":`Cancel interrupt`,onClick:()=>R(!1)}),(0,w.jsxs)(`section`,{className:`hq-confirm-dialog`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`hq-interrupt-title`,children:[(0,w.jsx)(r,{size:22,className:`hq-confirm-danger`}),(0,w.jsxs)(`div`,{children:[(0,w.jsxs)(`h2`,{id:`hq-interrupt-title`,children:[`Interrupt `,Q,`?`]}),(0,w.jsx)(`p`,{children:`The current run will stop at its cancellation boundary.`})]}),Z&&(0,w.jsxs)(`label`,{className:`hq-confirm-check`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:z,onChange:e=>B(e.target.checked)}),`Also interrupt every subagent on this client`]}),(0,w.jsxs)(`div`,{className:`hq-confirm-actions`,children:[(0,w.jsx)(`button`,{type:`button`,className:`hq-btn secondary`,onClick:()=>R(!1),children:`Cancel`}),(0,w.jsxs)(`button`,{type:`button`,className:`hq-btn danger`,disabled:P,onClick:()=>void re(),children:[(0,w.jsx)(r,{size:13}),` Confirm interrupt`]})]})]})]})]})}function j({label:e,value:t,tone:n}){return(0,w.jsxs)(`div`,{className:`hq-console-overview-metric`,"data-tone":n,children:[(0,w.jsx)(`strong`,{children:t}),(0,w.jsx)(`span`,{children:e})]})}export{A as LiveConsoleView};
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Bt as t,Kt as n,N as r,O as i,R as a,T as o,Yt as s,Zt as c,f as l,mt as u,x as d,z as f}from"./icons-I81S_8cW.js";import{i as p}from"./markdown-C4I0Caum.js";import{c as m,n as h,o as g,p as _,u as v}from"./index-C5Ihi44B.js";import{c as ee,l as te,s as y,t as b,u as x}from"./fleet-topology-I_zBJHSw.js";var S=e(c(),1);function C(e,t,n){if(e===null||t===null)return null;let r=(e.liveSessions??[]).find(e=>e.sessionId===t);if(r===void 0)return null;let i=e.sessions.find(e=>e.sessionId===t)?.clientId,a=r.clientId??i,o=e.clients.find(e=>e.connected&&e.clientId===a),s=e.clients.filter(e=>e.connected&&e.machineId===r.machineId&&e.projectId===r.projectId&&(r.pid===void 0||e.pid===r.pid)),c=(o?.capabilities.includes(`control.receive`)===!0?o:void 0)??s.find(e=>e.kind===r.clientKind&&e.capabilities.includes(`control.receive`))??s.find(e=>e.capabilities.includes(`control.receive`))??o??s[0],l=n===null?null:r.agents.find(e=>e.id===n)??null,u=n===null||n===`leader`?`leader`:n,d=e.clients.some(e=>e.connected&&e.projectId===r.projectId&&e.capabilities.includes(`mailbox.serve`));return{session:r,client:c??null,agent:l,recipient:u,controllable:c?.capabilities.includes(`control.receive`)===!0,mailboxServeActive:d}}var w=p();function T(e){let t=b(e),n=[],r=new Map,i=new Map,a=new Map,o=e=>`machine:${e.machineId}`,s=e=>`project:${e.machineId}:${e.projectId}`;for(let e of t.nodes){if(e.kind!==`machine`)continue;let t={id:e.id,label:e.label,sub:e.sub,projects:[]};r.set(e.id,t),n.push(t)}for(let e of t.nodes){if(e.kind!==`project`)continue;let t=r.get(o(e));if(t===void 0)continue;let n={id:e.id,label:e.label,clients:[]};i.set(e.id,n),t.projects.push(n)}for(let e of t.nodes){if(e.kind!==`terminal`||e.sessionId===void 0||e.serviceMode!==void 0)continue;let t=i.get(s(e));if(t===void 0)continue;let n={clientId:e.clientId,sessionId:e.sessionId,label:e.label,clientKind:e.clientKind,status:e.status,synthetic:e.isSyntheticSession===!0,agents:[]};a.set(e.sessionId,n),t.clients.push(n)}for(let e of t.nodes){if(e.kind!==`agent`||e.sessionId===void 0||e.agentId===void 0)continue;let t=a.get(e.sessionId);t!==void 0&&t.agents.push({id:e.agentId,label:e.label,status:e.status})}return n.map(e=>({...e,projects:e.projects.filter(e=>e.clients.length>0)})).filter(e=>e.projects.length>0)}function E(e){return e===`active`||e===`running`||e===`streaming`?`active`:e===`waiting_user`?`warn`:e===`error`||e===`stale`||e===`closing`?`error`:`idle`}function D({snapshot:e,selectedSessionId:r,selectedAgentId:i}){let o=(0,S.useMemo)(()=>T(e),[e]),[s,c]=(0,S.useState)(new Set),d=e=>c(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n});return o.length===0?(0,w.jsx)(`div`,{className:`hq-fleetnav`,children:(0,w.jsx)(`div`,{className:`hq-empty hq-pad-md`,children:`No live sessions. Open a WrongStack CLI/TUI/WebUI connected to HQ.`})}):(0,w.jsx)(`div`,{className:`hq-fleetnav`,role:`tree`,"aria-label":`Fleet navigator`,children:o.map(e=>{let o=!s.has(e.id);return(0,w.jsxs)(`div`,{className:`hq-nav-machine`,children:[(0,w.jsxs)(`button`,{type:`button`,className:`hq-nav-row machine`,onClick:()=>d(e.id),"aria-expanded":o,children:[(0,w.jsx)(t,{size:12,className:`hq-nav-caret`+(o?` open`:``)}),(0,w.jsx)(a,{size:13}),(0,w.jsx)(`span`,{className:`hq-nav-label`,title:e.sub??e.label,children:e.label})]}),o&&e.projects.map(e=>{let a=!s.has(e.id);return(0,w.jsxs)(`div`,{className:`hq-nav-project`,children:[(0,w.jsxs)(`button`,{type:`button`,className:`hq-nav-row project`,onClick:()=>d(e.id),"aria-expanded":a,children:[(0,w.jsx)(t,{size:12,className:`hq-nav-caret`+(a?` open`:``)}),(0,w.jsx)(u,{size:13}),(0,w.jsx)(`span`,{className:`hq-nav-label`,title:e.label,children:e.label})]}),a&&e.clients.map(e=>{let a=!s.has(e.sessionId),o=r===e.sessionId&&i===null;return(0,w.jsxs)(`div`,{className:`hq-nav-client`,children:[(0,w.jsxs)(`div`,{className:`hq-nav-clientrow`,children:[e.agents.length>0?(0,w.jsx)(`button`,{type:`button`,className:`hq-nav-caretbtn`,onClick:()=>d(e.sessionId),"aria-label":a?`Collapse`:`Expand`,children:(0,w.jsx)(t,{size:12,className:`hq-nav-caret`+(a?` open`:``)})}):(0,w.jsx)(`span`,{className:`hq-nav-caretbtn`}),(0,w.jsxs)(`button`,{type:`button`,className:`hq-nav-row client`+(o?` selected`:``),disabled:e.synthetic,onClick:()=>{e.synthetic||(v.getState().selectSession(e.sessionId),e.clientId!==void 0&&v.getState().selectClient(e.clientId))},title:e.synthetic?`waiting for session telemetry`:e.label,children:[(0,w.jsx)(`span`,{className:`hq-nav-dot `+E(e.status)}),(0,w.jsx)(l,{size:12}),(0,w.jsx)(`span`,{className:`hq-nav-label`,children:e.label}),e.agents.length>0&&(0,w.jsx)(`span`,{className:`hq-nav-count`,children:e.agents.length})]})]}),a&&e.agents.map(t=>{let a=r===e.sessionId&&i===t.id;return(0,w.jsxs)(`button`,{type:`button`,className:`hq-nav-row agent`+(a?` selected`:``),onClick:()=>{v.getState().selectAgent(e.sessionId,t.id),e.clientId!==void 0&&v.getState().selectClient(e.clientId)},title:t.label,children:[(0,w.jsx)(`span`,{className:`hq-nav-dot `+E(t.status)}),(0,w.jsx)(n,{size:12}),(0,w.jsx)(`span`,{className:`hq-nav-label`,children:t.label})]},t.id)})]},e.sessionId)})]},e.id)})]},e.id)})})}function O(e){return e===`completed`?`active`:e===`failed`||e===`rejected`?`error`:e===`delivered`||e===`accepted`?`info`:`warn`}function k({receipt:e,lifecycle:t}){let n=new Date(e.createdAt).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`,second:`2-digit`}),i=(0,w.jsx)(`span`,{className:`hq-pill ${O(t)}`,children:t});return e.type===`abort`?(0,w.jsx)(`div`,{className:`hq-chat-turn system hq-command-turn`,"data-command-id":e.commandId,children:(0,w.jsxs)(`span`,{className:`hq-chat-system-line`,children:[(0,w.jsx)(r,{size:12}),` `,e.preview,` `,i,(0,w.jsx)(`span`,{className:`hq-chat-clock`,children:n})]})}):(0,w.jsx)(`div`,{className:`hq-chat-turn user hq-command-turn`,"data-command-id":e.commandId,children:(0,w.jsxs)(`div`,{className:`hq-chat-bubble user`,children:[(0,w.jsxs)(`div`,{className:`hq-chat-role`,children:[`you → `,e.target,` · `,e.type,` `,i,(0,w.jsx)(`span`,{className:`hq-chat-clock`,children:n})]}),(0,w.jsx)(`div`,{className:`hq-chat-prose`,children:e.preview})]})})}function A(){let{selectedSessionId:e,selectedAgentId:t,snapshot:a,commandStatuses:c}=v(_(e=>({selectedSessionId:e.selectedSessionId,selectedAgentId:e.selectedAgentId,snapshot:e.snapshot,commandStatuses:e.commandStatuses}))),l=e,u=t,p=u!==null,b=g().console,[T,E]=(0,S.useState)(b.delivery),[O,A]=(0,S.useState)(b.subject),[M,N]=(0,S.useState)(b.body),[P,F]=(0,S.useState)(!1),[I,L]=(0,S.useState)(null),[ne,R]=(0,S.useState)(!1),[z,B]=(0,S.useState)(!1),[V,H]=(0,S.useState)([]),U=te(l,u),{entries:W,meta:G,stats:K}=U,q=(0,S.useMemo)(()=>V.filter(e=>{if(e.type===`abort`)return!0;let t=Date.parse(e.createdAt);return!W.some(n=>n.role===`user`&&n.text.trim()===e.preview&&Math.abs(Date.parse(n.ts)-t)<12e4)}),[W,V]);(0,S.useEffect)(()=>{if(!U.pinned||q.length===0)return;let e=window.requestAnimationFrame(()=>{U.listRef.current?.scrollToIndex(W.length+q.length-1,{align:`end`})});return()=>window.cancelAnimationFrame(e)},[U.listRef,U.pinned,W.length,q.length]);let J=()=>{U.jumpToLatest(),window.requestAnimationFrame(()=>{U.listRef.current?.scrollToIndex(W.length+q.length-1,{align:`end`})})},Y=(0,S.useMemo)(()=>C(a,l,u),[u,l,a]),X=Y?.agent??null,Z=Y?.recipient===`leader`,Q=X?.name??(Z?`Leader agent`:Y?.recipient??`agent`);(0,S.useEffect)(()=>{let e=Y?.client?.clientId;e!==void 0&&v.getState().selectClient(e),L(null),R(!1),B(!1),H([])},[Y?.client?.clientId,l,u]);let $=async()=>{if(Y?.client===null||Y?.client===void 0||!Y.controllable||M.trim().length===0)return;F(!0),L(null);let e=M.trim();try{let t=await m(Y.client.clientId,T,{to:Y.recipient,subject:O.trim()||`HQ ${T}`,body:e,priority:T===`steer`?`high`:`normal`});N(``),h({body:``}),H(n=>[...n,{commandId:t.commandId,type:T,target:Q,preview:e,createdAt:new Date().toISOString()}].slice(-8)),L({tone:`ok`,text:`${T} queued for ${Q} · ${t.commandId}`})}catch(e){L({tone:`error`,text:e instanceof Error?e.message:String(e)})}finally{F(!1)}},re=async()=>{if(Y?.client!==null&&Y?.client!==void 0){F(!0),L(null);try{let e=await m(Y.client.clientId,`abort`,{target:Y.recipient});if(H(t=>[...t,{commandId:e.commandId,type:`abort`,target:Q,preview:`Interrupt ${Q}`,createdAt:new Date().toISOString()}].slice(-8)),Z&&z){let e=await m(Y.client.clientId,`abort`,{target:`fleet`});H(t=>[...t,{commandId:e.commandId,type:`abort`,target:`all subagents`,preview:`Interrupt every subagent on this client`,createdAt:new Date().toISOString()}].slice(-8))}L({tone:`ok`,text:Z&&z?`Leader interrupt queued; all subagents will be interrupted too.`:`${Q} interrupt queued.`}),R(!1)}catch(e){L({tone:`error`,text:e instanceof Error?e.message:String(e)})}finally{F(!1)}}};return(0,w.jsxs)(`div`,{className:`hq-console-shell`,children:[(0,w.jsxs)(`header`,{className:`hq-console-overview`,children:[(0,w.jsxs)(`div`,{className:`hq-console-overview-copy`,children:[(0,w.jsx)(`span`,{className:`hq-console-live-dot`,"data-live":Y!==null,"aria-hidden":`true`}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`span`,{children:`Live transcript`}),(0,w.jsx)(`strong`,{children:l===null?`Select an endpoint`:p?X?.name??u:G.projectName??Q}),(0,w.jsx)(`small`,{children:l===null?`Choose a client or agent from the fleet navigator`:Y?.controllable===!0?`${Q} · control channel ready`:`${Q} · transcript is read-only`})]})]}),(0,w.jsxs)(`fieldset`,{className:`hq-console-overview-metrics`,"aria-label":`Transcript totals`,children:[(0,w.jsx)(j,{label:`turns`,value:K.turns+q.length}),(0,w.jsx)(j,{label:`tools`,value:K.tools}),(0,w.jsx)(j,{label:`running`,value:K.running,tone:K.running>0?`active`:void 0}),(0,w.jsx)(j,{label:`errors`,value:K.errors,tone:K.errors>0?`error`:void 0})]})]}),(0,w.jsx)(D,{snapshot:a??null,selectedSessionId:l,selectedAgentId:u}),(0,w.jsxs)(`div`,{className:`hq-console`,children:[(0,w.jsxs)(`div`,{className:`hq-chat-header`,children:[(0,w.jsx)(f,{size:15,className:`hq-chat-header-icon`}),(0,w.jsx)(`span`,{className:`hq-card-title hq-title-inline`,children:`Console`}),p&&(0,w.jsxs)(`span`,{className:`hq-pill active`,children:[(0,w.jsx)(n,{size:12}),` `,X?.name??u]}),G.projectName!==void 0&&!p&&(0,w.jsx)(`span`,{className:`hq-pill`,children:G.projectName}),Y!==null&&(0,w.jsxs)(`span`,{className:`hq-pill info`,title:Y.client?.clientId,children:[Y.session.hostname??Y.session.machineId,` ·`,` `,Y.session.clientKind.toUpperCase()]}),Y?.mailboxServeActive===!0&&(0,w.jsx)(`span`,{className:`hq-pill active`,children:`mailbox serve`}),G.source!==void 0&&(0,w.jsx)(`span`,{className:`hq-pill`,title:G.source===`disk`?`disk = full history replayed from this machine`:`stream = live ring only (remote or not yet persisted)`,children:G.source===`disk`?`full history`:`live ring`}),(0,w.jsxs)(`span`,{className:`hq-chat-counts`,children:[(0,w.jsxs)(`span`,{className:`hq-pill`,children:[K.turns+q.length,` turns`]}),(0,w.jsxs)(`span`,{className:`hq-pill`,children:[K.tools,` tools`]}),K.running>0&&(0,w.jsxs)(`span`,{className:`hq-pill running`,children:[K.running,` running`]}),K.errors>0&&(0,w.jsxs)(`span`,{className:`hq-pill error`,children:[K.errors,` err`]}),!p&&!U.full&&G.total>W.length&&(0,w.jsxs)(`button`,{type:`button`,className:`hq-btn secondary hq-chat-fullbtn`,onClick:()=>U.setFull(!0),title:`History is truncated — load all ${G.total} turns`,children:[(0,w.jsx)(o,{size:12}),` load all `,G.total]})]})]}),l===null?(0,w.jsxs)(`div`,{className:`hq-console-empty`,children:[(0,w.jsx)(`span`,{"aria-hidden":`true`,children:(0,w.jsx)(f,{size:24})}),(0,w.jsx)(`strong`,{children:`Choose a conversation`}),(0,w.jsx)(`small`,{children:`Pick a live client or agent from the fleet navigator to inspect its transcript.`})]}):U.loading&&W.length===0&&q.length===0?(0,w.jsx)(`div`,{className:`hq-empty`,children:p?`Loading agent history…`:`Loading transcript…`}):U.error===null?(0,w.jsxs)(`div`,{className:`hq-chat-scroll`,children:[W.length===0&&q.length===0?(0,w.jsx)(`div`,{className:`hq-empty`,children:p?`No messages from ${X?.name??u??`this agent`} yet.`:`No transcript entries yet.`}):(0,w.jsxs)(x,{ref:U.listRef,onScroll:U.onScroll,className:`hq-chat-vlist`,children:[W.map((e,t)=>(0,w.jsx)(`div`,{className:`hq-chat-rowpad`,children:(0,w.jsx)(y,{entry:e,running:U.isRunningAt(e,t)})},ee(e,t))),q.map(e=>{let t=c.find(t=>t.commandId===e.commandId),n=t?.ackStatus??t?.status??`queued`;return(0,w.jsx)(`div`,{className:`hq-chat-rowpad`,"aria-live":`polite`,children:(0,w.jsx)(k,{receipt:e,lifecycle:n})},`receipt:${e.commandId}`)})]}),!U.pinned&&(W.length>0||q.length>0)&&(0,w.jsx)(`button`,{type:`button`,className:`hq-chat-jump`,onClick:J,title:`Jump to latest`,children:(0,w.jsx)(s,{size:14})})]}):(0,w.jsxs)(`div`,{className:`hq-empty`,children:[`Error: `,U.error]}),l!==null&&(0,w.jsxs)(`div`,{className:`hq-console-composer`,children:[(0,w.jsxs)(`div`,{className:`hq-console-composer-head`,children:[(0,w.jsxs)(`span`,{children:[(0,w.jsx)(i,{size:13}),` Send to `,(0,w.jsx)(`strong`,{children:Q})]}),(0,w.jsx)(`span`,{className:`hq-pill ${Y?.controllable===!0?`active`:`error`}`,children:Y?.controllable===!0?`control live`:`read-only client`})]}),(0,w.jsxs)(`div`,{className:`hq-console-compose-row`,children:[(0,w.jsxs)(`select`,{className:`hq-select hq-console-delivery`,"aria-label":`Message delivery mode`,value:T,onChange:e=>{let t=e.target.value;E(t),h({delivery:t})},children:[(0,w.jsx)(`option`,{value:`steer`,children:`Steer now`}),(0,w.jsx)(`option`,{value:`btw`,children:`BTW / FYI`}),(0,w.jsx)(`option`,{value:`queue`,children:`Queue next`})]}),(0,w.jsx)(`input`,{className:`hq-input hq-console-subject`,"aria-label":`Message subject`,placeholder:`HQ ${T} (optional subject)`,value:O,onChange:e=>{A(e.target.value),h({subject:e.target.value})}}),(0,w.jsxs)(`button`,{type:`button`,className:`hq-btn danger hq-console-interrupt`,disabled:P||Y?.controllable!==!0,onClick:()=>{B(!1),R(!0)},children:[(0,w.jsx)(r,{size:13}),` Interrupt`]})]}),(0,w.jsxs)(`div`,{className:`hq-console-compose-row hq-console-message-row`,children:[(0,w.jsx)(`textarea`,{className:`hq-textarea hq-console-message`,"aria-label":`Message ${Q}`,placeholder:`Message ${Q}…`,rows:2,value:M,onChange:e=>{N(e.target.value),h({body:e.target.value})},onKeyDown:e=>{e.key===`Enter`&&(e.ctrlKey||e.metaKey)&&(e.preventDefault(),$())}}),(0,w.jsxs)(`button`,{type:`button`,className:`hq-btn primary hq-console-send`,disabled:P||M.trim().length===0||Y?.controllable!==!0,onClick:()=>void $(),children:[(0,w.jsx)(d,{size:13}),` `,P?`Queueing…`:`Send`]})]}),(0,w.jsxs)(`div`,{className:`hq-console-compose-foot`,children:[(0,w.jsx)(`span`,{children:`Ctrl+Enter sends · steer interrupts at the next safe turn`}),I!==null&&(0,w.jsx)(`span`,{className:`hq-console-status ${I.tone}`,children:I.text})]})]})]}),ne&&Y!==null&&(0,w.jsxs)(`div`,{className:`hq-confirm-layer`,role:`presentation`,children:[(0,w.jsx)(`button`,{type:`button`,className:`hq-confirm-scrim`,"aria-label":`Cancel interrupt`,onClick:()=>R(!1)}),(0,w.jsxs)(`section`,{className:`hq-confirm-dialog`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`hq-interrupt-title`,children:[(0,w.jsx)(r,{size:22,className:`hq-confirm-danger`}),(0,w.jsxs)(`div`,{children:[(0,w.jsxs)(`h2`,{id:`hq-interrupt-title`,children:[`Interrupt `,Q,`?`]}),(0,w.jsx)(`p`,{children:`The current run will stop at its cancellation boundary.`})]}),Z&&(0,w.jsxs)(`label`,{className:`hq-confirm-check`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:z,onChange:e=>B(e.target.checked)}),`Also interrupt every subagent on this client`]}),(0,w.jsxs)(`div`,{className:`hq-confirm-actions`,children:[(0,w.jsx)(`button`,{type:`button`,className:`hq-btn secondary`,onClick:()=>R(!1),children:`Cancel`}),(0,w.jsxs)(`button`,{type:`button`,className:`hq-btn danger`,disabled:P,onClick:()=>void re(),children:[(0,w.jsx)(r,{size:13}),` Confirm interrupt`]})]})]})]})]})}function j({label:e,value:t,tone:n}){return(0,w.jsxs)(`div`,{className:`hq-console-overview-metric`,"data-tone":n,children:[(0,w.jsx)(`strong`,{children:t}),(0,w.jsx)(`span`,{children:e})]})}export{A as LiveConsoleView};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{B as t,D as n,H as r,It as i,P as a,S as o,U as s,V as c,Y as l,Z as u,Zt as d,_ as f,dt as p,et as m,k as h,l as g,rt as _,s as v}from"./icons-I81S_8cW.js";import{i as y}from"./markdown-C4I0Caum.js";import{a as b,d as x,l as S,o as C,u as w}from"./index-Da_ivWpO.js";import{t as T}from"./use-backfilled-events-DG-l6cEz.js";var E=e(d(),1),D=y(),O=[{value:`note`,label:`note — general information`},{value:`ask`,label:`ask — reply required`},{value:`assign`,label:`assign — work ownership`},{value:`steer`,label:`steer — redirect the current work`},{value:`btw`,label:`btw — FYI, no action required`},{value:`queue`,label:`queue — note for the next agent`},{value:`broadcast`,label:`broadcast — all agents in the project`},{value:`status`,label:`status — meaningful checkpoint`},{value:`result`,label:`result — completed output/evidence`},{value:`review`,label:`review — passive inspection request`}];function k({projects:e,sender:t}){let n=t??S,[r,i]=(0,E.useState)(!1),[a,o]=(0,E.useState)(``),[c,l]=(0,E.useState)(`steer`),[u,d]=(0,E.useState)(`leader`),[f,p]=(0,E.useState)(`normal`),[m,h]=(0,E.useState)(!1),[g,_]=(0,E.useState)(``),[v,y]=(0,E.useState)(``),[b,x]=(0,E.useState)({phase:`idle`}),C=a||e[0]?.projectId||``,w=b.phase!==`sending`&&v.trim().length>0&&C.length>0,T=async()=>{if(w){x({phase:`sending`});try{let e=await n({projectId:C,type:c,...c===`broadcast`?{}:{to:u.trim()||`leader`},subject:g.trim()||`HQ prompt`,body:v.trim(),priority:f,audience:m?`leaders`:`all`});x({phase:`sent`,messageId:e.messageId}),y(``)}catch(e){x({phase:`error`,message:e instanceof Error?e.message:String(e)})}}};return r?(0,D.jsxs)(`div`,{className:`hq-card hq-composer`,children:[(0,D.jsxs)(`div`,{className:`hq-row hq-row-baseline`,children:[(0,D.jsx)(`span`,{className:`hq-card-title hq-title-inline`,children:`Send to project mailbox`}),(0,D.jsx)(`span`,{className:`hq-composer-hint`,children:`lands in the mailbox file — picked up by the next agent, no live client needed`}),(0,D.jsx)(`button`,{type:`button`,className:`hq-toggle hq-ml-auto`,"aria-label":`Collapse composer`,onClick:()=>i(!1),children:`▾`})]}),(0,D.jsxs)(`div`,{className:`hq-composer-grid`,children:[(0,D.jsxs)(`label`,{className:`hq-composer-field`,children:[(0,D.jsx)(`span`,{children:`project`}),(0,D.jsx)(`select`,{className:`hq-select`,value:C,onChange:e=>o(e.target.value),children:e.map(e=>(0,D.jsx)(`option`,{value:e.projectId,children:e.label??e.projectId},e.projectId))})]}),(0,D.jsxs)(`label`,{className:`hq-composer-field`,children:[(0,D.jsx)(`span`,{children:`type`}),(0,D.jsx)(`select`,{className:`hq-select`,value:c,onChange:e=>l(e.target.value),children:O.map(e=>(0,D.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),c!==`broadcast`&&(0,D.jsxs)(`label`,{className:`hq-composer-field`,children:[(0,D.jsx)(`span`,{children:`to`}),(0,D.jsx)(`input`,{className:`hq-input`,value:u,placeholder:`leader`,onChange:e=>d(e.target.value)})]}),(0,D.jsxs)(`label`,{className:`hq-composer-field`,children:[(0,D.jsx)(`span`,{children:`audience`}),(0,D.jsxs)(`select`,{className:`hq-select`,value:m?`leaders`:`all`,onChange:e=>h(e.target.value===`leaders`),children:[(0,D.jsx)(`option`,{value:`all`,children:`all agents`}),(0,D.jsx)(`option`,{value:`leaders`,children:`leaders only — subagents cannot consume`})]})]}),(0,D.jsxs)(`label`,{className:`hq-composer-field`,children:[(0,D.jsx)(`span`,{children:`priority`}),(0,D.jsxs)(`select`,{className:`hq-select`,value:f,onChange:e=>p(e.target.value),children:[(0,D.jsx)(`option`,{value:`high`,children:`high`}),(0,D.jsx)(`option`,{value:`normal`,children:`normal`}),(0,D.jsx)(`option`,{value:`low`,children:`low`})]})]})]}),(0,D.jsx)(`input`,{className:`hq-input`,value:g,placeholder:`subject (optional)`,onChange:e=>_(e.target.value)}),(0,D.jsx)(`textarea`,{className:`hq-input hq-composer-body`,value:v,rows:3,placeholder:`Message body — e.g. “after the current task, run the full test suite”`,onChange:e=>y(e.target.value)}),(0,D.jsxs)(`div`,{className:`hq-row`,children:[(0,D.jsx)(`button`,{type:`button`,className:`hq-btn`,disabled:!w,onClick:()=>void T(),children:b.phase===`sending`?`Sending…`:`Send`}),b.phase===`sent`&&(0,D.jsxs)(`span`,{className:`hq-composer-status ok`,children:[`delivered`,b.messageId===void 0?``:` · ${b.messageId.slice(0,8)}`]}),b.phase===`error`&&(0,D.jsx)(`span`,{className:`hq-composer-status err`,title:b.message,children:b.message})]})]}):(0,D.jsxs)(`div`,{className:`hq-composer-bar`,children:[(0,D.jsxs)(`button`,{type:`button`,className:`hq-btn`,disabled:e.length===0,title:e.length===0?`No projects reported yet — connect a client first`:`Write a message into a project mailbox (works with zero connected agents)`,onClick:()=>i(!0),children:[(0,D.jsx)(s,{size:13}),` Compose`]}),b.phase===`sent`&&(0,D.jsxs)(`span`,{className:`hq-composer-status ok`,children:[`delivered`,b.messageId===void 0?``:` · ${b.messageId.slice(0,8)}`]})]})}function A(e){if(typeof e!=`object`||!e)return!1;let t=e;return typeof t.mailboxId==`string`&&(t.scope===`project`||t.scope===`global`)&&Array.isArray(t.messages)&&Array.isArray(t.agents)&&typeof t.totals==`object`&&t.totals!==null}function j(e){if(typeof e!=`object`||!e)return!1;let t=e;return typeof t.mailboxId==`string`&&typeof t.action==`string`&&(t.message===void 0||typeof t.message==`object`)}function M(e,t){let n=e.get(t);return n===void 0&&(n={projectId:t,messages:[],countersFromSnapshot:!1,onlineAgentCount:0,highPriorityCount:0,unreadCount:0,incompleteCount:0},e.set(t,n)),n}function N(e){let t=0,n=0,r=0;for(let i of e){let e=i.message;e.priority===`high`&&(t+=1),e.completed||(r+=1,(e.readCount??0)===0&&(n+=1))}return{highPriorityCount:t,unreadCount:n,incompleteCount:r}}function P(e){let t=new Map;for(let n of e)(t.get(n.message.mailId)===void 0||n.source===`event`)&&t.set(n.message.mailId,n);return Array.from(t.values()).sort((e,t)=>t.message.timestamp.localeCompare(e.message.timestamp))}function F(e,t){let n=new Map;if(e!==null)for(let t of e.mailboxes){let e=M(n,t.projectId);e.mailboxId=t.mailboxId,e.scope=t.scope,e.onlineAgentCount=t.onlineAgentCount,e.highPriorityCount=t.highPriorityCount,e.unreadCount=t.unreadCount,e.incompleteCount=t.incompleteCount,e.countersFromSnapshot=!0}for(let e of t){if(e.type!==`mailbox.snapshot`||!A(e.payload))continue;let t=e.payload,r=M(n,e.projectId);r.mailboxId=t.mailboxId,r.scope=t.scope;for(let n of t.messages)r.messages.push({message:n,source:`snapshot`,key:`s:${e.id}:${n.messageId}`,projectId:e.projectId})}let r=new Map;for(let e of t){if(e.type!==`mailbox.event`||!j(e.payload))continue;let t=e.payload,i=M(n,e.projectId);i.mailboxId=t.mailboxId,i.scope=i.scope??`project`,t.message!==void 0&&!r.has(t.message.mailId)&&(r.set(t.message.mailId,i),i.messages.push({message:t.message,source:`event`,key:`e:${t.message.mailId}:${e.seq}`,projectId:e.projectId})),t.agent?.online&&(i.onlineAgentCount+=1)}for(let e of n.values())if(e.messages=P(e.messages),!e.countersFromSnapshot){let t=N(e.messages);e.highPriorityCount=t.highPriorityCount,e.unreadCount=t.unreadCount,e.incompleteCount=t.incompleteCount}let i=Array.from(n.values()).sort((e,t)=>{let n=e.messages[0]?.message.timestamp??``;return(t.messages[0]?.message.timestamp??``).localeCompare(n)});return{projects:i,hasAnyActivity:i.some(e=>e.messages.length>0)}}var I=Object.freeze({types:new Set,priorities:new Set,projectIds:new Set,includeCompleted:!0,query:``});function ee(e,t){switch(t.type){case`toggle-type`:{let n=new Set(e.types);return n.has(t.value)?n.delete(t.value):n.add(t.value),{...e,types:n}}case`toggle-priority`:{let n=new Set(e.priorities);return n.has(t.value)?n.delete(t.value):n.add(t.value),{...e,priorities:n}}case`toggle-project`:{let n=new Set(e.projectIds);return n.has(t.value)?n.delete(t.value):n.add(t.value),{...e,projectIds:n}}case`set-query`:return{...e,query:t.value};case`set-include-completed`:return{...e,includeCompleted:t.value};case`clear-all`:return I;default:return e}}function te(e,t={}){let n=t.includeCompleted??!0,r=t.types&&t.types.length>0?new Set(t.types):null,i=t.priorities&&t.priorities.length>0?new Set(t.priorities):null,a=t.projectIds&&t.projectIds.length>0?new Set(t.projectIds):null,o=t.query?.trim().toLowerCase()??``,s=t.limit??500,c=[];for(let t of e){let e=t.message;!n&&e.completed||r&&!r.has(e.type)||i&&!i.has(e.priority)||a||o.length>0&&!`${e.subject}\n${e.from}\n${e.to}\n${e.bodyPreview??``}`.toLowerCase().includes(o)||c.push({key:t.key,flat:t})}c.sort((e,t)=>{let n=t.flat.message.timestamp.localeCompare(e.flat.message.timestamp);return n===0?e.flat.message.mailId.localeCompare(t.flat.message.mailId):n});let l=c.length,u=l>s,d=u?c.slice(0,s):c;return{totalMatched:l,returned:d.length,truncated:u,entries:d}}function L(e,t,n={}){let{projectIds:r,...i}=n,a=F(e,t),o=[],s=r!==void 0&&r.length>0?new Set(r):null;for(let e of a.projects)s&&!s.has(e.projectId)||(o=o.concat(e.messages));return te(o,i)}function R(e){if(typeof e!=`object`||!e)return!1;let t=e;if(typeof t.error==`string`)return!0;if(typeof t.error!=`object`||t.error===null)return!1;let n=t.error;return typeof n.code==`string`&&typeof n.message==`string`}async function z(e){let t=`/api/mailbox/messages/${encodeURIComponent(e.mailId)}/action`,n=await x(t,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)});if(n.status===401&&w.getState().markAuthRequired(),!n.ok){let e=`${n.status} ${n.statusText}`;try{let t=await n.json();R(t)&&(e=typeof t.error==`string`?t.error:`${t.error.code}: ${t.error.message}`)}catch{}throw Error(`mailbox action failed — ${e}`)}return await n.json()}var B={markRead:e=>z({...e,action:`mark-read`}),acknowledge:e=>z({...e,action:`acknowledge`}),reopen:e=>z({...e,action:`reopen`}),softDelete:e=>z({...e,action:`soft-delete`}),restore:e=>z({...e,action:`restore`})};function V({mailId:e,actorId:t,projectId:n,isDeleted:r=!1,onAction:i,disabled:a=!1}){let[o,s]=(0,E.useState)(null),[c,l]=(0,E.useState)(null),u=async(t,n)=>{if(!(a||o!==null)){s(t),l(null);try{await n(),i?.(e,t)}catch(e){l(e instanceof Error?e.message:String(e))}finally{s(null)}}},d={mailId:e,readerId:t,projectId:n};return(0,D.jsxs)(`div`,{className:`hq-msg-actions`,children:[!r&&(0,D.jsx)(`button`,{type:`button`,className:`hq-btn secondary`,disabled:a||o!==null,onClick:()=>u(`mark-read`,()=>B.markRead(d)),children:o===`mark-read`?`…`:`Mark read`}),!r&&(0,D.jsx)(`button`,{type:`button`,className:`hq-btn`,disabled:a||o!==null,onClick:()=>u(`acknowledge`,()=>B.acknowledge(d)),children:o===`acknowledge`?`…`:`Acknowledge`}),!r&&(0,D.jsx)(`button`,{type:`button`,className:`hq-btn secondary`,disabled:a||o!==null,onClick:()=>u(`reopen`,()=>B.reopen(d)),children:o===`reopen`?`…`:`Reopen`}),!r&&(0,D.jsx)(`button`,{type:`button`,className:`hq-btn danger`,disabled:a||o!==null,onClick:()=>u(`soft-delete`,()=>B.softDelete(d)),children:o===`soft-delete`?`…`:`Delete`}),r&&(0,D.jsx)(`button`,{type:`button`,className:`hq-btn secondary`,disabled:a||o!==null,onClick:()=>u(`restore`,()=>B.restore(d)),children:o===`restore`?`…`:`Restore`}),c!==null&&(0,D.jsx)(`span`,{className:`hq-msg-action-error`,title:c,children:c})]})}function H(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString()}function U(e){return e.length<=14?e:`${e.slice(0,8)}…${e.slice(-4)}`}var W={note:{icon:a,tone:`info`},ask:{icon:u,tone:`warn`},assign:{icon:h,tone:`warn`},steer:{icon:u,tone:`warn`},btw:{icon:t,tone:`info`},broadcast:{icon:c,tone:`info`},status:{icon:p,tone:`idle`},result:{icon:i,tone:`running`},review:{icon:o,tone:`info`},control:{icon:f,tone:`error`}};Object.keys(W);var G=`hq-operator`;function K({flat:e,defaultExpanded:t}){let[n,i]=(0,E.useState)(!!t),a=e.message,o=a.hasBody||a.bodyPreview!==void 0&&a.bodyPreview.length>0,s=W[a.type]??{icon:r,tone:`info`},c=s.icon,l=`${a.from} → ${a.to}`;return(0,D.jsxs)(`div`,{className:`hq-msg`+(a.completed?` done`:``),children:[(0,D.jsxs)(`div`,{className:`hq-msg-head`,children:[(0,D.jsx)(`span`,{className:`hq-msg-icon`,title:a.type,children:(0,D.jsx)(c,{size:13})}),(0,D.jsx)(`span`,{className:`hq-pill `+s.tone,children:a.type}),a.audience===`leaders`&&(0,D.jsx)(`span`,{className:`hq-pill info`,children:`leaders only`}),a.priority===`high`&&(0,D.jsx)(`span`,{className:`hq-pill error`,children:`high`}),a.priority===`low`&&(0,D.jsx)(`span`,{className:`hq-pill idle`,children:`low`}),(0,D.jsx)(`span`,{className:`hq-msg-subject`,title:a.subject,children:a.subject||`(no subject)`}),(0,D.jsx)(`span`,{className:`hq-mono hq-msg-route`,children:l}),(0,D.jsx)(`span`,{className:`hq-mono hq-msg-time`,title:a.timestamp,children:H(a.timestamp)}),(0,D.jsx)(`span`,{className:`hq-mono hq-msg-id`,children:U(a.messageId)}),(0,D.jsx)(`span`,{className:`hq-msg-flag `+(a.completed?`done`:`open`),children:a.completed?`completed${a.completedBy===void 0?``:` by ${a.completedBy}`}`:`open`}),o&&(0,D.jsx)(`button`,{type:`button`,className:`hq-toggle hq-msg-toggle`,onClick:()=>i(e=>!e),"aria-expanded":n,"aria-label":n?`Collapse body`:`Expand body`,children:n?`▾`:`▸`})]}),n&&(0,D.jsxs)(`div`,{className:`hq-msg-body`,children:[a.bodyPreview!==void 0&&a.bodyPreview.length>0?(0,D.jsx)(`pre`,{className:`hq-msg-pre`,children:a.bodyPreview}):(0,D.jsx)(`div`,{className:`hq-empty hq-pad-sm`,children:`(empty body)`}),a.outcomePreview!==void 0&&a.outcomePreview.length>0&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`div`,{className:`hq-msg-sublabel`,children:`outcome`}),(0,D.jsx)(`pre`,{className:`hq-msg-pre`,children:a.outcomePreview})]}),(0,D.jsxs)(`div`,{className:`hq-msg-meta`,children:[(0,D.jsxs)(`span`,{children:[(0,D.jsx)(`strong`,{children:`source:`}),` `,e.source]}),a.replyTo!==void 0&&(0,D.jsxs)(`span`,{children:[(0,D.jsx)(`strong`,{children:`reply to:`}),` `,U(a.replyTo)]}),a.senderSessionId!==void 0&&(0,D.jsxs)(`span`,{children:[(0,D.jsx)(`strong`,{children:`sender session:`}),` `,U(a.senderSessionId)]}),(a.readCount??0)>0&&(0,D.jsxs)(`span`,{children:[(0,D.jsx)(`strong`,{children:`reads:`}),` `,a.readCount]}),a.unreadCount!==void 0&&a.unreadCount>0&&(0,D.jsxs)(`span`,{children:[(0,D.jsx)(`strong`,{children:`unread:`}),` `,a.unreadCount]}),a.task!==void 0&&(0,D.jsxs)(`span`,{children:[(0,D.jsx)(`strong`,{children:`task:`}),` `,a.task.taskId??`—`,a.task.agentName===void 0?``:` · ${a.task.agentName}`,a.task.status===void 0?``:` (${a.task.status})`]})]}),e.projectId!==void 0&&(0,D.jsx)(V,{mailId:a.mailId,actorId:G,projectId:e.projectId})]})]})}var q=[`ask`,`assign`,`steer`,`review`,`result`,`status`,`broadcast`,`note`,`btw`,`control`],J=[`high`,`normal`,`low`];function Y({snapshot:e,events:t}={}){let n=w(e=>e.snapshot),r=e===void 0?n:e,i=t===void 0?w.getState().events:t,a=C(),o=(0,E.useMemo)(()=>{let e=a.mailbox;return{types:new Set(e.types),priorities:new Set(e.priorities),projectIds:new Set,includeCompleted:e.includeCompleted,query:e.query}},[a.mailbox]),[s,c]=(0,E.useReducer)(ee,o);(0,E.useEffect)(()=>{b({query:s.query,types:Array.from(s.types),priorities:Array.from(s.priorities),includeCompleted:s.includeCompleted})},[s.query,s.types,s.priorities,s.includeCompleted]);let l=(0,E.useMemo)(()=>F(r??null,i).projects.map(e=>({projectId:e.projectId,count:e.messages.length})),[r,i]),u=(0,E.useMemo)(()=>L(r??null,i,{types:Array.from(s.types),priorities:Array.from(s.priorities),projectIds:Array.from(s.projectIds),includeCompleted:s.includeCompleted,query:s.query||void 0,limit:500}),[r,i,s]),d=s.types.size+s.priorities.size+s.projectIds.size+ +!s.includeCompleted+ +(s.query.trim().length>0);return(0,D.jsxs)(`div`,{children:[(0,D.jsxs)(`div`,{className:`hq-card-title`,children:[`Live mailbox feed · `,u.returned,` of `,u.totalMatched,` message`,u.totalMatched===1?``:`s`,u.truncated?` · refined to fit`:``]}),(0,D.jsxs)(`div`,{className:`hq-card hq-mailbox-filterbar`,children:[(0,D.jsx)(`label`,{className:`hq-label`,htmlFor:`mailbox-live-query`,children:`Search`}),(0,D.jsx)(`input`,{id:`mailbox-live-query`,className:`hq-input`,value:s.query,onChange:e=>c({type:`set-query`,value:e.target.value}),placeholder:`subject / sender / recipient / body…`}),(0,D.jsx)(X,{title:`Types`,children:q.map(e=>(0,D.jsx)(Z,{selected:s.types.has(e),label:e,onClick:()=>c({type:`toggle-type`,value:e})},e))}),(0,D.jsx)(X,{title:`Priority`,children:J.map(e=>(0,D.jsx)(Z,{selected:s.priorities.has(e),label:e,tone:e===`high`?`error`:e===`low`?`idle`:`info`,onClick:()=>c({type:`toggle-priority`,value:e})},e))}),l.length>0&&(0,D.jsx)(X,{title:`Projects`,children:l.map(e=>(0,D.jsx)(Z,{selected:s.projectIds.has(e.projectId),label:`${e.projectId} (${e.count})`,onClick:()=>c({type:`toggle-project`,value:e.projectId})},e.projectId))}),(0,D.jsxs)(`div`,{className:`hq-row hq-mailbox-filter-actions`,children:[(0,D.jsxs)(`label`,{className:`hq-check`,children:[(0,D.jsx)(`input`,{type:`checkbox`,checked:s.includeCompleted,onChange:e=>c({type:`set-include-completed`,value:e.target.checked})}),`include completed`]}),(0,D.jsxs)(`button`,{type:`button`,className:`hq-btn secondary`,disabled:d===0,onClick:()=>c({type:`clear-all`}),children:[`Clear filters`,d>0?` (${d})`:``]})]})]}),u.entries.length===0?(0,D.jsx)(`div`,{className:`hq-empty`,children:`No mailbox activity matches the current filters.`}):(0,D.jsx)(`div`,{className:`hq-msg-list hq-live-feed`,children:u.entries.map((e,t)=>(0,D.jsx)(K,{flat:e.flat,defaultExpanded:t===0&&s.query.trim().length>0},e.key))})]})}function X({title:e,children:t}){return(0,D.jsxs)(`div`,{className:`hq-filter-section`,children:[(0,D.jsx)(`div`,{className:`hq-msg-sublabel`,children:e}),(0,D.jsx)(`div`,{className:`hq-filter-chip-row`,children:t})]})}function Z({selected:e,label:t,onClick:n,tone:r=`info`}){return(0,D.jsx)(`button`,{type:`button`,className:`hq-filter-chip hq-pill ${r}${e?` selected`:``}`,"aria-pressed":e,onClick:n,children:t})}function ne(){let e=w(e=>e.snapshot),[t,r]=(0,E.useState)(`live`),{events:i}=T(`mailbox.event`,300),a=i,{projects:o,hasAnyActivity:s}=(0,E.useMemo)(()=>F(e,a),[e,a]),c=e?.totals.unreadMailboxMessages??0,u=e?.totals.incompleteMailboxMessages??0,d=(e?.mailboxes??[]).reduce((e,t)=>e+t.messageCount,0),f=(e?.mailboxes??[]).reduce((e,t)=>e+t.highPriorityCount,0),p=(e?.mailboxes??[]).reduce((e,t)=>e+t.onlineAgentCount,0),h=(0,E.useMemo)(()=>{let t=new Map;for(let n of e?.projects??[])t.set(n.projectId,{projectId:n.projectId,label:n.projectName});for(let e of o)t.has(e.projectId)||t.set(e.projectId,{projectId:e.projectId});return Array.from(t.values())},[e,o]);return o.length===0&&h.length===0?(0,D.jsxs)(`div`,{className:`hq-mailbox-zero`,children:[(0,D.jsx)(`span`,{className:`hq-mailbox-zero-icon`,"aria-hidden":`true`,children:(0,D.jsx)(_,{size:26})}),(0,D.jsx)(`span`,{className:`hq-section-kicker`,children:`Coordination inbox`}),(0,D.jsx)(`h2`,{children:`Waiting for mailbox traffic`}),(0,D.jsx)(`p`,{children:`Connected projects, inter-agent messages and durable prompts will appear here as soon as a client reports mailbox activity.`})]}):(0,D.jsxs)(`div`,{className:`hq-screen hq-mailbox-screen`,children:[(0,D.jsxs)(`section`,{className:`hq-screen-hero hq-mailbox-hero`,"aria-label":`Mailbox command summary`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`span`,{className:`hq-section-kicker`,children:`Coordination inbox`}),(0,D.jsx)(`h2`,{children:c>0?`${c} message${c===1?``:`s`} ${c===1?`needs`:`need`} review`:`Coordination is clear`}),(0,D.jsx)(`p`,{children:`Live cross-project traffic, durable prompts and unresolved coordination work share one operator inbox.`}),(0,D.jsxs)(`div`,{className:`hq-mailbox-hero-state`,children:[(0,D.jsxs)(`span`,{className:`hq-pill active`,children:[(0,D.jsx)(n,{size:11}),` live sync`]}),(0,D.jsxs)(`span`,{className:`hq-mono hq-text-dim`,children:[`Mailbox Activity — `,o.length,` project`,o.length===1?``:`s`,` ·`,` `,c,` unread · `,u,` incomplete`,s?` · detailed messages available`:``]})]})]}),(0,D.jsxs)(`div`,{className:`hq-hero-metrics`,children:[(0,D.jsx)(Q,{label:`messages`,value:d}),(0,D.jsx)(Q,{label:`unread`,value:c,tone:c>0?`warn`:`ok`}),(0,D.jsx)(Q,{label:`high priority`,value:f,tone:f>0?`error`:`ok`}),(0,D.jsx)(Q,{label:`online agents`,value:p,tone:p>0?`ok`:void 0})]})]}),(0,D.jsxs)(`div`,{className:`hq-mailbox-command-strip`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`strong`,{children:`Durable delivery`}),(0,D.jsx)(`span`,{children:`Write directly to a project mailbox, even when no agent is currently connected.`})]}),(0,D.jsx)(k,{projects:h})]}),(0,D.jsxs)(`div`,{className:`hq-mailbox-workspace-head`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`span`,{className:`hq-section-kicker`,children:`Message workspace`}),(0,D.jsx)(`strong`,{children:t===`live`?`Unified timeline`:`Project channels`})]}),(0,D.jsxs)(`div`,{className:`hq-mailbox-modebar`,role:`tablist`,"aria-label":`Mailbox view mode`,children:[(0,D.jsxs)(`button`,{type:`button`,role:`tab`,className:`hq-btn secondary`+(t===`live`?` hq-btn-selected`:``),"aria-selected":t===`live`,onClick:()=>r(`live`),children:[(0,D.jsx)(l,{size:13}),` Live feed`]}),(0,D.jsxs)(`button`,{type:`button`,role:`tab`,className:`hq-btn secondary`+(t===`grouped`?` hq-btn-selected`:``),"aria-selected":t===`grouped`,onClick:()=>r(`grouped`),children:[(0,D.jsx)(m,{size:13}),` Grouped by project`]})]})]}),(0,D.jsx)(`div`,{className:`hq-mailbox-workspace`,children:t===`live`?(0,D.jsx)(Y,{snapshot:e,events:a}):o.map(e=>(0,D.jsx)(re,{group:e},e.projectId))})]})}function Q({label:e,value:t,tone:n}){return(0,D.jsxs)(`div`,{className:`hq-hero-metric hq-mailbox-metric`,"data-tone":n,children:[(0,D.jsx)(n===`error`?g:e===`online agents`?v:_,{size:13}),(0,D.jsx)(`strong`,{children:t}),(0,D.jsx)(`span`,{children:e})]})}function re({group:e}){let[t,n]=(0,E.useState)(!0);return(0,D.jsxs)(`div`,{className:`hq-card hq-mailbox-project-card`,children:[(0,D.jsxs)(`div`,{className:`hq-row hq-row-baseline`,children:[(0,D.jsx)(`button`,{type:`button`,className:`hq-toggle`,onClick:()=>n(e=>!e),"aria-label":t?`Collapse project messages`:`Expand project messages`,children:t?`▾`:`▸`}),(0,D.jsx)(`span`,{className:`hq-text-bright`,children:e.projectId}),e.scope!==void 0&&(0,D.jsx)(`span`,{className:`hq-pill info`,children:e.scope}),e.mailboxId!==void 0&&(0,D.jsx)(`span`,{className:`hq-mono hq-text-dim`,children:e.mailboxId}),(0,D.jsxs)(`span`,{className:`hq-mono hq-text-dim hq-ml-auto`,children:[e.messages.length,` message`,e.messages.length===1?``:`s`]})]}),(0,D.jsxs)(`div`,{className:`hq-grid hq-mt-8`,style:{gridTemplateColumns:`repeat(5,1fr)`},children:[(0,D.jsx)($,{label:`messages`,value:e.messages.length}),(0,D.jsx)($,{label:`unread`,value:e.unreadCount,accent:e.unreadCount>0?`amber`:void 0}),(0,D.jsx)($,{label:`incomplete`,value:e.incompleteCount,accent:e.incompleteCount>0?`red`:void 0}),(0,D.jsx)($,{label:`high-priority`,value:e.highPriorityCount,accent:e.highPriorityCount>0?`red`:void 0}),(0,D.jsx)($,{label:`online agents`,value:e.onlineAgentCount,accent:e.onlineAgentCount>0?`green`:void 0})]}),t&&e.messages.length>0&&(0,D.jsx)(`div`,{className:`hq-msg-list hq-mt-12`,children:e.messages.map(e=>(0,D.jsx)(K,{flat:e},e.key))}),t&&e.messages.length===0&&(0,D.jsx)(`div`,{className:`hq-empty hq-cockpit-empty`,children:`Snapshot counters reported for this project, but no detailed mailbox events have streamed yet.`})]})}function $({label:e,value:t,accent:n}){return(0,D.jsxs)(`div`,{className:`hq-text-center`,children:[(0,D.jsx)(`div`,{className:`hq-stat-num`,style:{color:n===`amber`?`var(--amber)`:n===`red`?`var(--red)`:n===`green`?`var(--green)`:`var(--text)`},children:t}),(0,D.jsx)(`div`,{className:`hq-stat-label`,children:e})]})}export{ne as MailboxView};
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{B as t,D as n,H as r,It as i,P as a,S as o,U as s,V as c,Y as l,Z as u,Zt as d,_ as f,dt as p,et as m,k as h,l as g,rt as _,s as v}from"./icons-I81S_8cW.js";import{i as y}from"./markdown-C4I0Caum.js";import{a as b,d as x,l as S,o as C,u as w}from"./index-C5Ihi44B.js";import{t as T}from"./use-backfilled-events-CbvvmZr7.js";var E=e(d(),1),D=y(),O=[{value:`note`,label:`note — general information`},{value:`ask`,label:`ask — reply required`},{value:`assign`,label:`assign — work ownership`},{value:`steer`,label:`steer — redirect the current work`},{value:`btw`,label:`btw — FYI, no action required`},{value:`queue`,label:`queue — note for the next agent`},{value:`broadcast`,label:`broadcast — all agents in the project`},{value:`status`,label:`status — meaningful checkpoint`},{value:`result`,label:`result — completed output/evidence`},{value:`review`,label:`review — passive inspection request`}];function k({projects:e,sender:t}){let n=t??S,[r,i]=(0,E.useState)(!1),[a,o]=(0,E.useState)(``),[c,l]=(0,E.useState)(`steer`),[u,d]=(0,E.useState)(`leader`),[f,p]=(0,E.useState)(`normal`),[m,h]=(0,E.useState)(!1),[g,_]=(0,E.useState)(``),[v,y]=(0,E.useState)(``),[b,x]=(0,E.useState)({phase:`idle`}),C=a||e[0]?.projectId||``,w=b.phase!==`sending`&&v.trim().length>0&&C.length>0,T=async()=>{if(w){x({phase:`sending`});try{let e=await n({projectId:C,type:c,...c===`broadcast`?{}:{to:u.trim()||`leader`},subject:g.trim()||`HQ prompt`,body:v.trim(),priority:f,audience:m?`leaders`:`all`});x({phase:`sent`,messageId:e.messageId}),y(``)}catch(e){x({phase:`error`,message:e instanceof Error?e.message:String(e)})}}};return r?(0,D.jsxs)(`div`,{className:`hq-card hq-composer`,children:[(0,D.jsxs)(`div`,{className:`hq-row hq-row-baseline`,children:[(0,D.jsx)(`span`,{className:`hq-card-title hq-title-inline`,children:`Send to project mailbox`}),(0,D.jsx)(`span`,{className:`hq-composer-hint`,children:`lands in the mailbox file — picked up by the next agent, no live client needed`}),(0,D.jsx)(`button`,{type:`button`,className:`hq-toggle hq-ml-auto`,"aria-label":`Collapse composer`,onClick:()=>i(!1),children:`▾`})]}),(0,D.jsxs)(`div`,{className:`hq-composer-grid`,children:[(0,D.jsxs)(`label`,{className:`hq-composer-field`,children:[(0,D.jsx)(`span`,{children:`project`}),(0,D.jsx)(`select`,{className:`hq-select`,value:C,onChange:e=>o(e.target.value),children:e.map(e=>(0,D.jsx)(`option`,{value:e.projectId,children:e.label??e.projectId},e.projectId))})]}),(0,D.jsxs)(`label`,{className:`hq-composer-field`,children:[(0,D.jsx)(`span`,{children:`type`}),(0,D.jsx)(`select`,{className:`hq-select`,value:c,onChange:e=>l(e.target.value),children:O.map(e=>(0,D.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),c!==`broadcast`&&(0,D.jsxs)(`label`,{className:`hq-composer-field`,children:[(0,D.jsx)(`span`,{children:`to`}),(0,D.jsx)(`input`,{className:`hq-input`,value:u,placeholder:`leader`,onChange:e=>d(e.target.value)})]}),(0,D.jsxs)(`label`,{className:`hq-composer-field`,children:[(0,D.jsx)(`span`,{children:`audience`}),(0,D.jsxs)(`select`,{className:`hq-select`,value:m?`leaders`:`all`,onChange:e=>h(e.target.value===`leaders`),children:[(0,D.jsx)(`option`,{value:`all`,children:`all agents`}),(0,D.jsx)(`option`,{value:`leaders`,children:`leaders only — subagents cannot consume`})]})]}),(0,D.jsxs)(`label`,{className:`hq-composer-field`,children:[(0,D.jsx)(`span`,{children:`priority`}),(0,D.jsxs)(`select`,{className:`hq-select`,value:f,onChange:e=>p(e.target.value),children:[(0,D.jsx)(`option`,{value:`high`,children:`high`}),(0,D.jsx)(`option`,{value:`normal`,children:`normal`}),(0,D.jsx)(`option`,{value:`low`,children:`low`})]})]})]}),(0,D.jsx)(`input`,{className:`hq-input`,value:g,placeholder:`subject (optional)`,onChange:e=>_(e.target.value)}),(0,D.jsx)(`textarea`,{className:`hq-input hq-composer-body`,value:v,rows:3,placeholder:`Message body — e.g. “after the current task, run the full test suite”`,onChange:e=>y(e.target.value)}),(0,D.jsxs)(`div`,{className:`hq-row`,children:[(0,D.jsx)(`button`,{type:`button`,className:`hq-btn`,disabled:!w,onClick:()=>void T(),children:b.phase===`sending`?`Sending…`:`Send`}),b.phase===`sent`&&(0,D.jsxs)(`span`,{className:`hq-composer-status ok`,children:[`delivered`,b.messageId===void 0?``:` · ${b.messageId.slice(0,8)}`]}),b.phase===`error`&&(0,D.jsx)(`span`,{className:`hq-composer-status err`,title:b.message,children:b.message})]})]}):(0,D.jsxs)(`div`,{className:`hq-composer-bar`,children:[(0,D.jsxs)(`button`,{type:`button`,className:`hq-btn`,disabled:e.length===0,title:e.length===0?`No projects reported yet — connect a client first`:`Write a message into a project mailbox (works with zero connected agents)`,onClick:()=>i(!0),children:[(0,D.jsx)(s,{size:13}),` Compose`]}),b.phase===`sent`&&(0,D.jsxs)(`span`,{className:`hq-composer-status ok`,children:[`delivered`,b.messageId===void 0?``:` · ${b.messageId.slice(0,8)}`]})]})}function A(e){if(typeof e!=`object`||!e)return!1;let t=e;return typeof t.mailboxId==`string`&&(t.scope===`project`||t.scope===`global`)&&Array.isArray(t.messages)&&Array.isArray(t.agents)&&typeof t.totals==`object`&&t.totals!==null}function j(e){if(typeof e!=`object`||!e)return!1;let t=e;return typeof t.mailboxId==`string`&&typeof t.action==`string`&&(t.message===void 0||typeof t.message==`object`)}function M(e,t){let n=e.get(t);return n===void 0&&(n={projectId:t,messages:[],countersFromSnapshot:!1,onlineAgentCount:0,highPriorityCount:0,unreadCount:0,incompleteCount:0},e.set(t,n)),n}function N(e){let t=0,n=0,r=0;for(let i of e){let e=i.message;e.priority===`high`&&(t+=1),e.completed||(r+=1,(e.readCount??0)===0&&(n+=1))}return{highPriorityCount:t,unreadCount:n,incompleteCount:r}}function P(e){let t=new Map;for(let n of e)(t.get(n.message.mailId)===void 0||n.source===`event`)&&t.set(n.message.mailId,n);return Array.from(t.values()).sort((e,t)=>t.message.timestamp.localeCompare(e.message.timestamp))}function F(e,t){let n=new Map;if(e!==null)for(let t of e.mailboxes){let e=M(n,t.projectId);e.mailboxId=t.mailboxId,e.scope=t.scope,e.onlineAgentCount=t.onlineAgentCount,e.highPriorityCount=t.highPriorityCount,e.unreadCount=t.unreadCount,e.incompleteCount=t.incompleteCount,e.countersFromSnapshot=!0}for(let e of t){if(e.type!==`mailbox.snapshot`||!A(e.payload))continue;let t=e.payload,r=M(n,e.projectId);r.mailboxId=t.mailboxId,r.scope=t.scope;for(let n of t.messages)r.messages.push({message:n,source:`snapshot`,key:`s:${e.id}:${n.messageId}`,projectId:e.projectId})}let r=new Map;for(let e of t){if(e.type!==`mailbox.event`||!j(e.payload))continue;let t=e.payload,i=M(n,e.projectId);i.mailboxId=t.mailboxId,i.scope=i.scope??`project`,t.message!==void 0&&!r.has(t.message.mailId)&&(r.set(t.message.mailId,i),i.messages.push({message:t.message,source:`event`,key:`e:${t.message.mailId}:${e.seq}`,projectId:e.projectId})),t.agent?.online&&(i.onlineAgentCount+=1)}for(let e of n.values())if(e.messages=P(e.messages),!e.countersFromSnapshot){let t=N(e.messages);e.highPriorityCount=t.highPriorityCount,e.unreadCount=t.unreadCount,e.incompleteCount=t.incompleteCount}let i=Array.from(n.values()).sort((e,t)=>{let n=e.messages[0]?.message.timestamp??``;return(t.messages[0]?.message.timestamp??``).localeCompare(n)});return{projects:i,hasAnyActivity:i.some(e=>e.messages.length>0)}}var I=Object.freeze({types:new Set,priorities:new Set,projectIds:new Set,includeCompleted:!0,query:``});function ee(e,t){switch(t.type){case`toggle-type`:{let n=new Set(e.types);return n.has(t.value)?n.delete(t.value):n.add(t.value),{...e,types:n}}case`toggle-priority`:{let n=new Set(e.priorities);return n.has(t.value)?n.delete(t.value):n.add(t.value),{...e,priorities:n}}case`toggle-project`:{let n=new Set(e.projectIds);return n.has(t.value)?n.delete(t.value):n.add(t.value),{...e,projectIds:n}}case`set-query`:return{...e,query:t.value};case`set-include-completed`:return{...e,includeCompleted:t.value};case`clear-all`:return I;default:return e}}function te(e,t={}){let n=t.includeCompleted??!0,r=t.types&&t.types.length>0?new Set(t.types):null,i=t.priorities&&t.priorities.length>0?new Set(t.priorities):null,a=t.projectIds&&t.projectIds.length>0?new Set(t.projectIds):null,o=t.query?.trim().toLowerCase()??``,s=t.limit??500,c=[];for(let t of e){let e=t.message;!n&&e.completed||r&&!r.has(e.type)||i&&!i.has(e.priority)||a||o.length>0&&!`${e.subject}\n${e.from}\n${e.to}\n${e.bodyPreview??``}`.toLowerCase().includes(o)||c.push({key:t.key,flat:t})}c.sort((e,t)=>{let n=t.flat.message.timestamp.localeCompare(e.flat.message.timestamp);return n===0?e.flat.message.mailId.localeCompare(t.flat.message.mailId):n});let l=c.length,u=l>s,d=u?c.slice(0,s):c;return{totalMatched:l,returned:d.length,truncated:u,entries:d}}function L(e,t,n={}){let{projectIds:r,...i}=n,a=F(e,t),o=[],s=r!==void 0&&r.length>0?new Set(r):null;for(let e of a.projects)s&&!s.has(e.projectId)||(o=o.concat(e.messages));return te(o,i)}function R(e){if(typeof e!=`object`||!e)return!1;let t=e;if(typeof t.error==`string`)return!0;if(typeof t.error!=`object`||t.error===null)return!1;let n=t.error;return typeof n.code==`string`&&typeof n.message==`string`}async function z(e){let t=`/api/mailbox/messages/${encodeURIComponent(e.mailId)}/action`,n=await x(t,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)});if(n.status===401&&w.getState().markAuthRequired(),!n.ok){let e=`${n.status} ${n.statusText}`;try{let t=await n.json();R(t)&&(e=typeof t.error==`string`?t.error:`${t.error.code}: ${t.error.message}`)}catch{}throw Error(`mailbox action failed — ${e}`)}return await n.json()}var B={markRead:e=>z({...e,action:`mark-read`}),acknowledge:e=>z({...e,action:`acknowledge`}),reopen:e=>z({...e,action:`reopen`}),softDelete:e=>z({...e,action:`soft-delete`}),restore:e=>z({...e,action:`restore`})};function V({mailId:e,actorId:t,projectId:n,isDeleted:r=!1,onAction:i,disabled:a=!1}){let[o,s]=(0,E.useState)(null),[c,l]=(0,E.useState)(null),u=async(t,n)=>{if(!(a||o!==null)){s(t),l(null);try{await n(),i?.(e,t)}catch(e){l(e instanceof Error?e.message:String(e))}finally{s(null)}}},d={mailId:e,readerId:t,projectId:n};return(0,D.jsxs)(`div`,{className:`hq-msg-actions`,children:[!r&&(0,D.jsx)(`button`,{type:`button`,className:`hq-btn secondary`,disabled:a||o!==null,onClick:()=>u(`mark-read`,()=>B.markRead(d)),children:o===`mark-read`?`…`:`Mark read`}),!r&&(0,D.jsx)(`button`,{type:`button`,className:`hq-btn`,disabled:a||o!==null,onClick:()=>u(`acknowledge`,()=>B.acknowledge(d)),children:o===`acknowledge`?`…`:`Acknowledge`}),!r&&(0,D.jsx)(`button`,{type:`button`,className:`hq-btn secondary`,disabled:a||o!==null,onClick:()=>u(`reopen`,()=>B.reopen(d)),children:o===`reopen`?`…`:`Reopen`}),!r&&(0,D.jsx)(`button`,{type:`button`,className:`hq-btn danger`,disabled:a||o!==null,onClick:()=>u(`soft-delete`,()=>B.softDelete(d)),children:o===`soft-delete`?`…`:`Delete`}),r&&(0,D.jsx)(`button`,{type:`button`,className:`hq-btn secondary`,disabled:a||o!==null,onClick:()=>u(`restore`,()=>B.restore(d)),children:o===`restore`?`…`:`Restore`}),c!==null&&(0,D.jsx)(`span`,{className:`hq-msg-action-error`,title:c,children:c})]})}function H(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString()}function U(e){return e.length<=14?e:`${e.slice(0,8)}…${e.slice(-4)}`}var W={note:{icon:a,tone:`info`},ask:{icon:u,tone:`warn`},assign:{icon:h,tone:`warn`},steer:{icon:u,tone:`warn`},btw:{icon:t,tone:`info`},broadcast:{icon:c,tone:`info`},status:{icon:p,tone:`idle`},result:{icon:i,tone:`running`},review:{icon:o,tone:`info`},control:{icon:f,tone:`error`}};Object.keys(W);var G=`hq-operator`;function K({flat:e,defaultExpanded:t}){let[n,i]=(0,E.useState)(!!t),a=e.message,o=a.hasBody||a.bodyPreview!==void 0&&a.bodyPreview.length>0,s=W[a.type]??{icon:r,tone:`info`},c=s.icon,l=`${a.from} → ${a.to}`;return(0,D.jsxs)(`div`,{className:`hq-msg`+(a.completed?` done`:``),children:[(0,D.jsxs)(`div`,{className:`hq-msg-head`,children:[(0,D.jsx)(`span`,{className:`hq-msg-icon`,title:a.type,children:(0,D.jsx)(c,{size:13})}),(0,D.jsx)(`span`,{className:`hq-pill `+s.tone,children:a.type}),a.audience===`leaders`&&(0,D.jsx)(`span`,{className:`hq-pill info`,children:`leaders only`}),a.priority===`high`&&(0,D.jsx)(`span`,{className:`hq-pill error`,children:`high`}),a.priority===`low`&&(0,D.jsx)(`span`,{className:`hq-pill idle`,children:`low`}),(0,D.jsx)(`span`,{className:`hq-msg-subject`,title:a.subject,children:a.subject||`(no subject)`}),(0,D.jsx)(`span`,{className:`hq-mono hq-msg-route`,children:l}),(0,D.jsx)(`span`,{className:`hq-mono hq-msg-time`,title:a.timestamp,children:H(a.timestamp)}),(0,D.jsx)(`span`,{className:`hq-mono hq-msg-id`,children:U(a.messageId)}),(0,D.jsx)(`span`,{className:`hq-msg-flag `+(a.completed?`done`:`open`),children:a.completed?`completed${a.completedBy===void 0?``:` by ${a.completedBy}`}`:`open`}),o&&(0,D.jsx)(`button`,{type:`button`,className:`hq-toggle hq-msg-toggle`,onClick:()=>i(e=>!e),"aria-expanded":n,"aria-label":n?`Collapse body`:`Expand body`,children:n?`▾`:`▸`})]}),n&&(0,D.jsxs)(`div`,{className:`hq-msg-body`,children:[a.bodyPreview!==void 0&&a.bodyPreview.length>0?(0,D.jsx)(`pre`,{className:`hq-msg-pre`,children:a.bodyPreview}):(0,D.jsx)(`div`,{className:`hq-empty hq-pad-sm`,children:`(empty body)`}),a.outcomePreview!==void 0&&a.outcomePreview.length>0&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`div`,{className:`hq-msg-sublabel`,children:`outcome`}),(0,D.jsx)(`pre`,{className:`hq-msg-pre`,children:a.outcomePreview})]}),(0,D.jsxs)(`div`,{className:`hq-msg-meta`,children:[(0,D.jsxs)(`span`,{children:[(0,D.jsx)(`strong`,{children:`source:`}),` `,e.source]}),a.replyTo!==void 0&&(0,D.jsxs)(`span`,{children:[(0,D.jsx)(`strong`,{children:`reply to:`}),` `,U(a.replyTo)]}),a.senderSessionId!==void 0&&(0,D.jsxs)(`span`,{children:[(0,D.jsx)(`strong`,{children:`sender session:`}),` `,U(a.senderSessionId)]}),(a.readCount??0)>0&&(0,D.jsxs)(`span`,{children:[(0,D.jsx)(`strong`,{children:`reads:`}),` `,a.readCount]}),a.unreadCount!==void 0&&a.unreadCount>0&&(0,D.jsxs)(`span`,{children:[(0,D.jsx)(`strong`,{children:`unread:`}),` `,a.unreadCount]}),a.task!==void 0&&(0,D.jsxs)(`span`,{children:[(0,D.jsx)(`strong`,{children:`task:`}),` `,a.task.taskId??`—`,a.task.agentName===void 0?``:` · ${a.task.agentName}`,a.task.status===void 0?``:` (${a.task.status})`]})]}),e.projectId!==void 0&&(0,D.jsx)(V,{mailId:a.mailId,actorId:G,projectId:e.projectId})]})]})}var q=[`ask`,`assign`,`steer`,`review`,`result`,`status`,`broadcast`,`note`,`btw`,`control`],J=[`high`,`normal`,`low`];function Y({snapshot:e,events:t}={}){let n=w(e=>e.snapshot),r=e===void 0?n:e,i=t===void 0?w.getState().events:t,a=C(),o=(0,E.useMemo)(()=>{let e=a.mailbox;return{types:new Set(e.types),priorities:new Set(e.priorities),projectIds:new Set,includeCompleted:e.includeCompleted,query:e.query}},[a.mailbox]),[s,c]=(0,E.useReducer)(ee,o);(0,E.useEffect)(()=>{b({query:s.query,types:Array.from(s.types),priorities:Array.from(s.priorities),includeCompleted:s.includeCompleted})},[s.query,s.types,s.priorities,s.includeCompleted]);let l=(0,E.useMemo)(()=>F(r??null,i).projects.map(e=>({projectId:e.projectId,count:e.messages.length})),[r,i]),u=(0,E.useMemo)(()=>L(r??null,i,{types:Array.from(s.types),priorities:Array.from(s.priorities),projectIds:Array.from(s.projectIds),includeCompleted:s.includeCompleted,query:s.query||void 0,limit:500}),[r,i,s]),d=s.types.size+s.priorities.size+s.projectIds.size+ +!s.includeCompleted+ +(s.query.trim().length>0);return(0,D.jsxs)(`div`,{children:[(0,D.jsxs)(`div`,{className:`hq-card-title`,children:[`Live mailbox feed · `,u.returned,` of `,u.totalMatched,` message`,u.totalMatched===1?``:`s`,u.truncated?` · refined to fit`:``]}),(0,D.jsxs)(`div`,{className:`hq-card hq-mailbox-filterbar`,children:[(0,D.jsx)(`label`,{className:`hq-label`,htmlFor:`mailbox-live-query`,children:`Search`}),(0,D.jsx)(`input`,{id:`mailbox-live-query`,className:`hq-input`,value:s.query,onChange:e=>c({type:`set-query`,value:e.target.value}),placeholder:`subject / sender / recipient / body…`}),(0,D.jsx)(X,{title:`Types`,children:q.map(e=>(0,D.jsx)(Z,{selected:s.types.has(e),label:e,onClick:()=>c({type:`toggle-type`,value:e})},e))}),(0,D.jsx)(X,{title:`Priority`,children:J.map(e=>(0,D.jsx)(Z,{selected:s.priorities.has(e),label:e,tone:e===`high`?`error`:e===`low`?`idle`:`info`,onClick:()=>c({type:`toggle-priority`,value:e})},e))}),l.length>0&&(0,D.jsx)(X,{title:`Projects`,children:l.map(e=>(0,D.jsx)(Z,{selected:s.projectIds.has(e.projectId),label:`${e.projectId} (${e.count})`,onClick:()=>c({type:`toggle-project`,value:e.projectId})},e.projectId))}),(0,D.jsxs)(`div`,{className:`hq-row hq-mailbox-filter-actions`,children:[(0,D.jsxs)(`label`,{className:`hq-check`,children:[(0,D.jsx)(`input`,{type:`checkbox`,checked:s.includeCompleted,onChange:e=>c({type:`set-include-completed`,value:e.target.checked})}),`include completed`]}),(0,D.jsxs)(`button`,{type:`button`,className:`hq-btn secondary`,disabled:d===0,onClick:()=>c({type:`clear-all`}),children:[`Clear filters`,d>0?` (${d})`:``]})]})]}),u.entries.length===0?(0,D.jsx)(`div`,{className:`hq-empty`,children:`No mailbox activity matches the current filters.`}):(0,D.jsx)(`div`,{className:`hq-msg-list hq-live-feed`,children:u.entries.map((e,t)=>(0,D.jsx)(K,{flat:e.flat,defaultExpanded:t===0&&s.query.trim().length>0},e.key))})]})}function X({title:e,children:t}){return(0,D.jsxs)(`div`,{className:`hq-filter-section`,children:[(0,D.jsx)(`div`,{className:`hq-msg-sublabel`,children:e}),(0,D.jsx)(`div`,{className:`hq-filter-chip-row`,children:t})]})}function Z({selected:e,label:t,onClick:n,tone:r=`info`}){return(0,D.jsx)(`button`,{type:`button`,className:`hq-filter-chip hq-pill ${r}${e?` selected`:``}`,"aria-pressed":e,onClick:n,children:t})}function ne(){let e=w(e=>e.snapshot),[t,r]=(0,E.useState)(`live`),{events:i}=T(`mailbox.event`,300),a=i,{projects:o,hasAnyActivity:s}=(0,E.useMemo)(()=>F(e,a),[e,a]),c=e?.totals.unreadMailboxMessages??0,u=e?.totals.incompleteMailboxMessages??0,d=(e?.mailboxes??[]).reduce((e,t)=>e+t.messageCount,0),f=(e?.mailboxes??[]).reduce((e,t)=>e+t.highPriorityCount,0),p=(e?.mailboxes??[]).reduce((e,t)=>e+t.onlineAgentCount,0),h=(0,E.useMemo)(()=>{let t=new Map;for(let n of e?.projects??[])t.set(n.projectId,{projectId:n.projectId,label:n.projectName});for(let e of o)t.has(e.projectId)||t.set(e.projectId,{projectId:e.projectId});return Array.from(t.values())},[e,o]);return o.length===0&&h.length===0?(0,D.jsxs)(`div`,{className:`hq-mailbox-zero`,children:[(0,D.jsx)(`span`,{className:`hq-mailbox-zero-icon`,"aria-hidden":`true`,children:(0,D.jsx)(_,{size:26})}),(0,D.jsx)(`span`,{className:`hq-section-kicker`,children:`Coordination inbox`}),(0,D.jsx)(`h2`,{children:`Waiting for mailbox traffic`}),(0,D.jsx)(`p`,{children:`Connected projects, inter-agent messages and durable prompts will appear here as soon as a client reports mailbox activity.`})]}):(0,D.jsxs)(`div`,{className:`hq-screen hq-mailbox-screen`,children:[(0,D.jsxs)(`section`,{className:`hq-screen-hero hq-mailbox-hero`,"aria-label":`Mailbox command summary`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`span`,{className:`hq-section-kicker`,children:`Coordination inbox`}),(0,D.jsx)(`h2`,{children:c>0?`${c} message${c===1?``:`s`} ${c===1?`needs`:`need`} review`:`Coordination is clear`}),(0,D.jsx)(`p`,{children:`Live cross-project traffic, durable prompts and unresolved coordination work share one operator inbox.`}),(0,D.jsxs)(`div`,{className:`hq-mailbox-hero-state`,children:[(0,D.jsxs)(`span`,{className:`hq-pill active`,children:[(0,D.jsx)(n,{size:11}),` live sync`]}),(0,D.jsxs)(`span`,{className:`hq-mono hq-text-dim`,children:[`Mailbox Activity — `,o.length,` project`,o.length===1?``:`s`,` ·`,` `,c,` unread · `,u,` incomplete`,s?` · detailed messages available`:``]})]})]}),(0,D.jsxs)(`div`,{className:`hq-hero-metrics`,children:[(0,D.jsx)(Q,{label:`messages`,value:d}),(0,D.jsx)(Q,{label:`unread`,value:c,tone:c>0?`warn`:`ok`}),(0,D.jsx)(Q,{label:`high priority`,value:f,tone:f>0?`error`:`ok`}),(0,D.jsx)(Q,{label:`online agents`,value:p,tone:p>0?`ok`:void 0})]})]}),(0,D.jsxs)(`div`,{className:`hq-mailbox-command-strip`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`strong`,{children:`Durable delivery`}),(0,D.jsx)(`span`,{children:`Write directly to a project mailbox, even when no agent is currently connected.`})]}),(0,D.jsx)(k,{projects:h})]}),(0,D.jsxs)(`div`,{className:`hq-mailbox-workspace-head`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`span`,{className:`hq-section-kicker`,children:`Message workspace`}),(0,D.jsx)(`strong`,{children:t===`live`?`Unified timeline`:`Project channels`})]}),(0,D.jsxs)(`div`,{className:`hq-mailbox-modebar`,role:`tablist`,"aria-label":`Mailbox view mode`,children:[(0,D.jsxs)(`button`,{type:`button`,role:`tab`,className:`hq-btn secondary`+(t===`live`?` hq-btn-selected`:``),"aria-selected":t===`live`,onClick:()=>r(`live`),children:[(0,D.jsx)(l,{size:13}),` Live feed`]}),(0,D.jsxs)(`button`,{type:`button`,role:`tab`,className:`hq-btn secondary`+(t===`grouped`?` hq-btn-selected`:``),"aria-selected":t===`grouped`,onClick:()=>r(`grouped`),children:[(0,D.jsx)(m,{size:13}),` Grouped by project`]})]})]}),(0,D.jsx)(`div`,{className:`hq-mailbox-workspace`,children:t===`live`?(0,D.jsx)(Y,{snapshot:e,events:a}):o.map(e=>(0,D.jsx)(re,{group:e},e.projectId))})]})}function Q({label:e,value:t,tone:n}){return(0,D.jsxs)(`div`,{className:`hq-hero-metric hq-mailbox-metric`,"data-tone":n,children:[(0,D.jsx)(n===`error`?g:e===`online agents`?v:_,{size:13}),(0,D.jsx)(`strong`,{children:t}),(0,D.jsx)(`span`,{children:e})]})}function re({group:e}){let[t,n]=(0,E.useState)(!0);return(0,D.jsxs)(`div`,{className:`hq-card hq-mailbox-project-card`,children:[(0,D.jsxs)(`div`,{className:`hq-row hq-row-baseline`,children:[(0,D.jsx)(`button`,{type:`button`,className:`hq-toggle`,onClick:()=>n(e=>!e),"aria-label":t?`Collapse project messages`:`Expand project messages`,children:t?`▾`:`▸`}),(0,D.jsx)(`span`,{className:`hq-text-bright`,children:e.projectId}),e.scope!==void 0&&(0,D.jsx)(`span`,{className:`hq-pill info`,children:e.scope}),e.mailboxId!==void 0&&(0,D.jsx)(`span`,{className:`hq-mono hq-text-dim`,children:e.mailboxId}),(0,D.jsxs)(`span`,{className:`hq-mono hq-text-dim hq-ml-auto`,children:[e.messages.length,` message`,e.messages.length===1?``:`s`]})]}),(0,D.jsxs)(`div`,{className:`hq-grid hq-mt-8`,style:{gridTemplateColumns:`repeat(5,1fr)`},children:[(0,D.jsx)($,{label:`messages`,value:e.messages.length}),(0,D.jsx)($,{label:`unread`,value:e.unreadCount,accent:e.unreadCount>0?`amber`:void 0}),(0,D.jsx)($,{label:`incomplete`,value:e.incompleteCount,accent:e.incompleteCount>0?`red`:void 0}),(0,D.jsx)($,{label:`high-priority`,value:e.highPriorityCount,accent:e.highPriorityCount>0?`red`:void 0}),(0,D.jsx)($,{label:`online agents`,value:e.onlineAgentCount,accent:e.onlineAgentCount>0?`green`:void 0})]}),t&&e.messages.length>0&&(0,D.jsx)(`div`,{className:`hq-msg-list hq-mt-12`,children:e.messages.map(e=>(0,D.jsx)(K,{flat:e},e.key))}),t&&e.messages.length===0&&(0,D.jsx)(`div`,{className:`hq-empty hq-cockpit-empty`,children:`Snapshot counters reported for this project, but no detailed mailbox events have streamed yet.`})]})}function $({label:e,value:t,accent:n}){return(0,D.jsxs)(`div`,{className:`hq-text-center`,children:[(0,D.jsx)(`div`,{className:`hq-stat-num`,style:{color:n===`amber`?`var(--amber)`:n===`red`?`var(--red)`:n===`green`?`var(--green)`:`var(--text)`},children:t}),(0,D.jsx)(`div`,{className:`hq-stat-label`,children:e})]})}export{ne as MailboxView};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{r as e,t}from"./rolldown-runtime-hePW80VL.js";import{Ct as n,G as r,L as i,O as a,W as o,Zt as s,h as c,m as l,p as u,tt as d}from"./icons-I81S_8cW.js";import{i as f}from"./markdown-C4I0Caum.js";import{d as p,f as m,t as h}from"./index-
|
|
1
|
+
import{r as e,t}from"./rolldown-runtime-hePW80VL.js";import{Ct as n,G as r,L as i,O as a,W as o,Zt as s,h as c,m as l,p as u,tt as d}from"./icons-I81S_8cW.js";import{i as f}from"./markdown-C4I0Caum.js";import{d as p,f as m,t as h}from"./index-C5Ihi44B.js";var g=t(((e,t)=>{t.exports=function(){return typeof Promise==`function`&&Promise.prototype&&Promise.prototype.then}})),_=t((e=>{var t,n=[0,26,44,70,100,134,172,196,242,292,346,404,466,532,581,655,733,815,901,991,1085,1156,1258,1364,1474,1588,1706,1828,1921,2051,2185,2323,2465,2611,2761,2876,3034,3196,3362,3532,3706];e.getSymbolSize=function(e){if(!e)throw Error(`"version" cannot be null or undefined`);if(e<1||e>40)throw Error(`"version" should be in range from 1 to 40`);return e*4+17},e.getSymbolTotalCodewords=function(e){return n[e]},e.getBCHDigit=function(e){let t=0;for(;e!==0;)t++,e>>>=1;return t},e.setToSJISFunction=function(e){if(typeof e!=`function`)throw Error(`"toSJISFunc" is not a valid function.`);t=e},e.isKanjiModeEnabled=function(){return t!==void 0},e.toSJIS=function(e){return t(e)}})),v=t((e=>{e.L={bit:1},e.M={bit:0},e.Q={bit:3},e.H={bit:2};function t(t){if(typeof t!=`string`)throw Error(`Param is not a string`);switch(t.toLowerCase()){case`l`:case`low`:return e.L;case`m`:case`medium`:return e.M;case`q`:case`quartile`:return e.Q;case`h`:case`high`:return e.H;default:throw Error(`Unknown EC Level: `+t)}}e.isValid=function(e){return e&&e.bit!==void 0&&e.bit>=0&&e.bit<4},e.from=function(n,r){if(e.isValid(n))return n;try{return t(n)}catch{return r}}})),y=t(((e,t)=>{function n(){this.buffer=[],this.length=0}n.prototype={get:function(e){let t=Math.floor(e/8);return(this.buffer[t]>>>7-e%8&1)==1},put:function(e,t){for(let n=0;n<t;n++)this.putBit((e>>>t-n-1&1)==1)},getLengthInBits:function(){return this.length},putBit:function(e){let t=Math.floor(this.length/8);this.buffer.length<=t&&this.buffer.push(0),e&&(this.buffer[t]|=128>>>this.length%8),this.length++}},t.exports=n})),b=t(((e,t)=>{function n(e){if(!e||e<1)throw Error(`BitMatrix size must be defined and greater than 0`);this.size=e,this.data=new Uint8Array(e*e),this.reservedBit=new Uint8Array(e*e)}n.prototype.set=function(e,t,n,r){let i=e*this.size+t;this.data[i]=n,r&&(this.reservedBit[i]=!0)},n.prototype.get=function(e,t){return this.data[e*this.size+t]},n.prototype.xor=function(e,t,n){this.data[e*this.size+t]^=n},n.prototype.isReserved=function(e,t){return this.reservedBit[e*this.size+t]},t.exports=n})),x=t((e=>{var t=_().getSymbolSize;e.getRowColCoords=function(e){if(e===1)return[];let n=Math.floor(e/7)+2,r=t(e),i=r===145?26:Math.ceil((r-13)/(2*n-2))*2,a=[r-7];for(let e=1;e<n-1;e++)a[e]=a[e-1]-i;return a.push(6),a.reverse()},e.getPositions=function(t){let n=[],r=e.getRowColCoords(t),i=r.length;for(let e=0;e<i;e++)for(let t=0;t<i;t++)e===0&&t===0||e===0&&t===i-1||e===i-1&&t===0||n.push([r[e],r[t]]);return n}})),S=t((e=>{var t=_().getSymbolSize,n=7;e.getPositions=function(e){let r=t(e);return[[0,0],[r-n,0],[0,r-n]]}})),C=t((e=>{e.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};var t={N1:3,N2:3,N3:40,N4:10};e.isValid=function(e){return e!=null&&e!==``&&!isNaN(e)&&e>=0&&e<=7},e.from=function(t){return e.isValid(t)?parseInt(t,10):void 0},e.getPenaltyN1=function(e){let n=e.size,r=0,i=0,a=0,o=null,s=null;for(let c=0;c<n;c++){i=a=0,o=s=null;for(let l=0;l<n;l++){let n=e.get(c,l);n===o?i++:(i>=5&&(r+=t.N1+(i-5)),o=n,i=1),n=e.get(l,c),n===s?a++:(a>=5&&(r+=t.N1+(a-5)),s=n,a=1)}i>=5&&(r+=t.N1+(i-5)),a>=5&&(r+=t.N1+(a-5))}return r},e.getPenaltyN2=function(e){let n=e.size,r=0;for(let t=0;t<n-1;t++)for(let i=0;i<n-1;i++){let n=e.get(t,i)+e.get(t,i+1)+e.get(t+1,i)+e.get(t+1,i+1);(n===4||n===0)&&r++}return r*t.N2},e.getPenaltyN3=function(e){let n=e.size,r=0,i=0,a=0;for(let t=0;t<n;t++){i=a=0;for(let o=0;o<n;o++)i=i<<1&2047|e.get(t,o),o>=10&&(i===1488||i===93)&&r++,a=a<<1&2047|e.get(o,t),o>=10&&(a===1488||a===93)&&r++}return r*t.N3},e.getPenaltyN4=function(e){let n=0,r=e.data.length;for(let t=0;t<r;t++)n+=e.data[t];return Math.abs(Math.ceil(n*100/r/5)-10)*t.N4};function n(t,n,r){switch(t){case e.Patterns.PATTERN000:return(n+r)%2==0;case e.Patterns.PATTERN001:return n%2==0;case e.Patterns.PATTERN010:return r%3==0;case e.Patterns.PATTERN011:return(n+r)%3==0;case e.Patterns.PATTERN100:return(Math.floor(n/2)+Math.floor(r/3))%2==0;case e.Patterns.PATTERN101:return n*r%2+n*r%3==0;case e.Patterns.PATTERN110:return(n*r%2+n*r%3)%2==0;case e.Patterns.PATTERN111:return(n*r%3+(n+r)%2)%2==0;default:throw Error(`bad maskPattern:`+t)}}e.applyMask=function(e,t){let r=t.size;for(let i=0;i<r;i++)for(let a=0;a<r;a++)t.isReserved(a,i)||t.xor(a,i,n(e,a,i))},e.getBestMask=function(t,n){let r=Object.keys(e.Patterns).length,i=0,a=1/0;for(let o=0;o<r;o++){n(o),e.applyMask(o,t);let r=e.getPenaltyN1(t)+e.getPenaltyN2(t)+e.getPenaltyN3(t)+e.getPenaltyN4(t);e.applyMask(o,t),r<a&&(a=r,i=o)}return i}})),w=t((e=>{var t=v(),n=[1,1,1,1,1,1,1,1,1,1,2,2,1,2,2,4,1,2,4,4,2,4,4,4,2,4,6,5,2,4,6,6,2,5,8,8,4,5,8,8,4,5,8,11,4,8,10,11,4,9,12,16,4,9,16,16,6,10,12,18,6,10,17,16,6,11,16,19,6,13,18,21,7,14,21,25,8,16,20,25,8,17,23,25,9,17,23,34,9,18,25,30,10,20,27,32,12,21,29,35,12,23,34,37,12,25,34,40,13,26,35,42,14,28,38,45,15,29,40,48,16,31,43,51,17,33,45,54,18,35,48,57,19,37,51,60,19,38,53,63,20,40,56,66,21,43,59,70,22,45,62,74,24,47,65,77,25,49,68,81],r=[7,10,13,17,10,16,22,28,15,26,36,44,20,36,52,64,26,48,72,88,36,64,96,112,40,72,108,130,48,88,132,156,60,110,160,192,72,130,192,224,80,150,224,264,96,176,260,308,104,198,288,352,120,216,320,384,132,240,360,432,144,280,408,480,168,308,448,532,180,338,504,588,196,364,546,650,224,416,600,700,224,442,644,750,252,476,690,816,270,504,750,900,300,560,810,960,312,588,870,1050,336,644,952,1110,360,700,1020,1200,390,728,1050,1260,420,784,1140,1350,450,812,1200,1440,480,868,1290,1530,510,924,1350,1620,540,980,1440,1710,570,1036,1530,1800,570,1064,1590,1890,600,1120,1680,1980,630,1204,1770,2100,660,1260,1860,2220,720,1316,1950,2310,750,1372,2040,2430];e.getBlocksCount=function(e,r){switch(r){case t.L:return n[(e-1)*4+0];case t.M:return n[(e-1)*4+1];case t.Q:return n[(e-1)*4+2];case t.H:return n[(e-1)*4+3];default:return}},e.getTotalCodewordsCount=function(e,n){switch(n){case t.L:return r[(e-1)*4+0];case t.M:return r[(e-1)*4+1];case t.Q:return r[(e-1)*4+2];case t.H:return r[(e-1)*4+3];default:return}}})),T=t((e=>{var t=new Uint8Array(512),n=new Uint8Array(256);(function(){let e=1;for(let r=0;r<255;r++)t[r]=e,n[e]=r,e<<=1,e&256&&(e^=285);for(let e=255;e<512;e++)t[e]=t[e-255]})(),e.log=function(e){if(e<1)throw Error(`log(`+e+`)`);return n[e]},e.exp=function(e){return t[e]},e.mul=function(e,r){return e===0||r===0?0:t[n[e]+n[r]]}})),E=t((e=>{var t=T();e.mul=function(e,n){let r=new Uint8Array(e.length+n.length-1);for(let i=0;i<e.length;i++)for(let a=0;a<n.length;a++)r[i+a]^=t.mul(e[i],n[a]);return r},e.mod=function(e,n){let r=new Uint8Array(e);for(;r.length-n.length>=0;){let e=r[0];for(let i=0;i<n.length;i++)r[i]^=t.mul(n[i],e);let i=0;for(;i<r.length&&r[i]===0;)i++;r=r.slice(i)}return r},e.generateECPolynomial=function(n){let r=new Uint8Array([1]);for(let i=0;i<n;i++)r=e.mul(r,new Uint8Array([1,t.exp(i)]));return r}})),D=t(((e,t)=>{var n=E();function r(e){this.genPoly=void 0,this.degree=e,this.degree&&this.initialize(this.degree)}r.prototype.initialize=function(e){this.degree=e,this.genPoly=n.generateECPolynomial(this.degree)},r.prototype.encode=function(e){if(!this.genPoly)throw Error(`Encoder not initialized`);let t=new Uint8Array(e.length+this.degree);t.set(e);let r=n.mod(t,this.genPoly),i=this.degree-r.length;if(i>0){let e=new Uint8Array(this.degree);return e.set(r,i),e}return r},t.exports=r})),O=t((e=>{e.isValid=function(e){return!isNaN(e)&&e>=1&&e<=40}})),k=t((e=>{var t=`[0-9]+`,n=`[A-Z $%*+\\-./:]+`,r=`(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+`;r=r.replace(/u/g,`\\u`);var i=`(?:(?![A-Z0-9 $%*+\\-./:]|`+r+`)(?:.|[\r
|
|
2
2
|
]))+`;e.KANJI=new RegExp(r,`g`),e.BYTE_KANJI=RegExp(`[^A-Z0-9 $%*+\\-./:]+`,`g`),e.BYTE=new RegExp(i,`g`),e.NUMERIC=new RegExp(t,`g`),e.ALPHANUMERIC=new RegExp(n,`g`);var a=RegExp(`^`+r+`$`),o=RegExp(`^[0-9]+$`),s=RegExp(`^[A-Z0-9 $%*+\\-./:]+$`);e.testKanji=function(e){return a.test(e)},e.testNumeric=function(e){return o.test(e)},e.testAlphanumeric=function(e){return s.test(e)}})),A=t((e=>{var t=O(),n=k();e.NUMERIC={id:`Numeric`,bit:1,ccBits:[10,12,14]},e.ALPHANUMERIC={id:`Alphanumeric`,bit:2,ccBits:[9,11,13]},e.BYTE={id:`Byte`,bit:4,ccBits:[8,16,16]},e.KANJI={id:`Kanji`,bit:8,ccBits:[8,10,12]},e.MIXED={bit:-1},e.getCharCountIndicator=function(e,n){if(!e.ccBits)throw Error(`Invalid mode: `+e);if(!t.isValid(n))throw Error(`Invalid version: `+n);return n>=1&&n<10?e.ccBits[0]:n<27?e.ccBits[1]:e.ccBits[2]},e.getBestModeForData=function(t){return n.testNumeric(t)?e.NUMERIC:n.testAlphanumeric(t)?e.ALPHANUMERIC:n.testKanji(t)?e.KANJI:e.BYTE},e.toString=function(e){if(e&&e.id)return e.id;throw Error(`Invalid mode`)},e.isValid=function(e){return e&&e.bit&&e.ccBits};function r(t){if(typeof t!=`string`)throw Error(`Param is not a string`);switch(t.toLowerCase()){case`numeric`:return e.NUMERIC;case`alphanumeric`:return e.ALPHANUMERIC;case`kanji`:return e.KANJI;case`byte`:return e.BYTE;default:throw Error(`Unknown mode: `+t)}}e.from=function(t,n){if(e.isValid(t))return t;try{return r(t)}catch{return n}}})),j=t((e=>{var t=_(),n=w(),r=v(),i=A(),a=O(),o=7973,s=t.getBCHDigit(o);function c(t,n,r){for(let i=1;i<=40;i++)if(n<=e.getCapacity(i,r,t))return i}function l(e,t){return i.getCharCountIndicator(e,t)+4}function u(e,t){let n=0;return e.forEach(function(e){let r=l(e.mode,t);n+=r+e.getBitsLength()}),n}function d(t,n){for(let r=1;r<=40;r++)if(u(t,r)<=e.getCapacity(r,n,i.MIXED))return r}e.from=function(e,t){return a.isValid(e)?parseInt(e,10):t},e.getCapacity=function(e,r,o){if(!a.isValid(e))throw Error(`Invalid QR Code version`);o===void 0&&(o=i.BYTE);let s=(t.getSymbolTotalCodewords(e)-n.getTotalCodewordsCount(e,r))*8;if(o===i.MIXED)return s;let c=s-l(o,e);switch(o){case i.NUMERIC:return Math.floor(c/10*3);case i.ALPHANUMERIC:return Math.floor(c/11*2);case i.KANJI:return Math.floor(c/13);case i.BYTE:default:return Math.floor(c/8)}},e.getBestVersionForData=function(e,t){let n,i=r.from(t,r.M);if(Array.isArray(e)){if(e.length>1)return d(e,i);if(e.length===0)return 1;n=e[0]}else n=e;return c(n.mode,n.getLength(),i)},e.getEncodedBits=function(e){if(!a.isValid(e)||e<7)throw Error(`Invalid QR Code version`);let n=e<<12;for(;t.getBCHDigit(n)-s>=0;)n^=o<<t.getBCHDigit(n)-s;return e<<12|n}})),M=t((e=>{var t=_(),n=1335,r=21522,i=t.getBCHDigit(n);e.getEncodedBits=function(e,a){let o=e.bit<<3|a,s=o<<10;for(;t.getBCHDigit(s)-i>=0;)s^=n<<t.getBCHDigit(s)-i;return(o<<10|s)^r}})),N=t(((e,t)=>{var n=A();function r(e){this.mode=n.NUMERIC,this.data=e.toString()}r.getBitsLength=function(e){return 10*Math.floor(e/3)+(e%3?e%3*3+1:0)},r.prototype.getLength=function(){return this.data.length},r.prototype.getBitsLength=function(){return r.getBitsLength(this.data.length)},r.prototype.write=function(e){let t,n,r;for(t=0;t+3<=this.data.length;t+=3)n=this.data.substr(t,3),r=parseInt(n,10),e.put(r,10);let i=this.data.length-t;i>0&&(n=this.data.substr(t),r=parseInt(n,10),e.put(r,i*3+1))},t.exports=r})),P=t(((e,t)=>{var n=A(),r=`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:`.split(``);function i(e){this.mode=n.ALPHANUMERIC,this.data=e}i.getBitsLength=function(e){return 11*Math.floor(e/2)+e%2*6},i.prototype.getLength=function(){return this.data.length},i.prototype.getBitsLength=function(){return i.getBitsLength(this.data.length)},i.prototype.write=function(e){let t;for(t=0;t+2<=this.data.length;t+=2){let n=r.indexOf(this.data[t])*45;n+=r.indexOf(this.data[t+1]),e.put(n,11)}this.data.length%2&&e.put(r.indexOf(this.data[t]),6)},t.exports=i})),F=t(((e,t)=>{var n=A();function r(e){this.mode=n.BYTE,this.data=typeof e==`string`?new TextEncoder().encode(e):new Uint8Array(e)}r.getBitsLength=function(e){return e*8},r.prototype.getLength=function(){return this.data.length},r.prototype.getBitsLength=function(){return r.getBitsLength(this.data.length)},r.prototype.write=function(e){for(let t=0,n=this.data.length;t<n;t++)e.put(this.data[t],8)},t.exports=r})),I=t(((e,t)=>{var n=A(),r=_();function i(e){this.mode=n.KANJI,this.data=e}i.getBitsLength=function(e){return e*13},i.prototype.getLength=function(){return this.data.length},i.prototype.getBitsLength=function(){return i.getBitsLength(this.data.length)},i.prototype.write=function(e){let t;for(t=0;t<this.data.length;t++){let n=r.toSJIS(this.data[t]);if(n>=33088&&n<=40956)n-=33088;else if(n>=57408&&n<=60351)n-=49472;else throw Error(`Invalid SJIS character: `+this.data[t]+`
|
|
3
3
|
Make sure your charset is UTF-8`);n=(n>>>8&255)*192+(n&255),e.put(n,13)}},t.exports=i})),L=t(((e,t)=>{var n={single_source_shortest_paths:function(e,t,r){var i={},a={};a[t]=0;var o=n.PriorityQueue.make();o.push(t,0);for(var s,c,l,u,d,f,p,m,h;!o.empty();)for(l in s=o.pop(),c=s.value,u=s.cost,d=e[c]||{},d)d.hasOwnProperty(l)&&(f=d[l],p=u+f,m=a[l],h=a[l]===void 0,(h||m>p)&&(a[l]=p,o.push(l,p),i[l]=c));if(r!==void 0&&a[r]===void 0){var g=[`Could not find a path from `,t,` to `,r,`.`].join(``);throw Error(g)}return i},extract_shortest_path_from_predecessor_list:function(e,t){for(var n=[],r=t;r;)n.push(r),e[r],r=e[r];return n.reverse(),n},find_path:function(e,t,r){var i=n.single_source_shortest_paths(e,t,r);return n.extract_shortest_path_from_predecessor_list(i,r)},PriorityQueue:{make:function(e){var t=n.PriorityQueue,r={},i;for(i in e||={},t)t.hasOwnProperty(i)&&(r[i]=t[i]);return r.queue=[],r.sorter=e.sorter||t.default_sorter,r},default_sorter:function(e,t){return e.cost-t.cost},push:function(e,t){var n={value:e,cost:t};this.queue.push(n),this.queue.sort(this.sorter)},pop:function(){return this.queue.shift()},empty:function(){return this.queue.length===0}}};t!==void 0&&(t.exports=n)})),R=t((e=>{var t=A(),n=N(),r=P(),i=F(),a=I(),o=k(),s=_(),c=L();function l(e){return unescape(encodeURIComponent(e)).length}function u(e,t,n){let r=[],i;for(;(i=e.exec(n))!==null;)r.push({data:i[0],index:i.index,mode:t,length:i[0].length});return r}function d(e){let n=u(o.NUMERIC,t.NUMERIC,e),r=u(o.ALPHANUMERIC,t.ALPHANUMERIC,e),i,a;return s.isKanjiModeEnabled()?(i=u(o.BYTE,t.BYTE,e),a=u(o.KANJI,t.KANJI,e)):(i=u(o.BYTE_KANJI,t.BYTE,e),a=[]),n.concat(r,i,a).sort(function(e,t){return e.index-t.index}).map(function(e){return{data:e.data,mode:e.mode,length:e.length}})}function f(e,o){switch(o){case t.NUMERIC:return n.getBitsLength(e);case t.ALPHANUMERIC:return r.getBitsLength(e);case t.KANJI:return a.getBitsLength(e);case t.BYTE:return i.getBitsLength(e)}}function p(e){return e.reduce(function(e,t){let n=e.length-1>=0?e[e.length-1]:null;return n&&n.mode===t.mode?(e[e.length-1].data+=t.data,e):(e.push(t),e)},[])}function m(e){let n=[];for(let r=0;r<e.length;r++){let i=e[r];switch(i.mode){case t.NUMERIC:n.push([i,{data:i.data,mode:t.ALPHANUMERIC,length:i.length},{data:i.data,mode:t.BYTE,length:i.length}]);break;case t.ALPHANUMERIC:n.push([i,{data:i.data,mode:t.BYTE,length:i.length}]);break;case t.KANJI:n.push([i,{data:i.data,mode:t.BYTE,length:l(i.data)}]);break;case t.BYTE:n.push([{data:i.data,mode:t.BYTE,length:l(i.data)}])}}return n}function h(e,n){let r={},i={start:{}},a=[`start`];for(let o=0;o<e.length;o++){let s=e[o],c=[];for(let e=0;e<s.length;e++){let l=s[e],u=``+o+e;c.push(u),r[u]={node:l,lastCount:0},i[u]={};for(let e=0;e<a.length;e++){let o=a[e];r[o]&&r[o].node.mode===l.mode?(i[o][u]=f(r[o].lastCount+l.length,l.mode)-f(r[o].lastCount,l.mode),r[o].lastCount+=l.length):(r[o]&&(r[o].lastCount=l.length),i[o][u]=f(l.length,l.mode)+4+t.getCharCountIndicator(l.mode,n))}}a=c}for(let e=0;e<a.length;e++)i[a[e]].end=0;return{map:i,table:r}}function g(e,o){let c,l=t.getBestModeForData(e);if(c=t.from(o,l),c!==t.BYTE&&c.bit<l.bit)throw Error(`"`+e+`" cannot be encoded with mode `+t.toString(c)+`.
|
|
4
4
|
Suggested mode is: `+t.toString(l));switch(c===t.KANJI&&!s.isKanjiModeEnabled()&&(c=t.BYTE),c){case t.NUMERIC:return new n(e);case t.ALPHANUMERIC:return new r(e);case t.KANJI:return new a(e);case t.BYTE:return new i(e)}}e.fromArray=function(e){return e.reduce(function(e,t){return typeof t==`string`?e.push(g(t,null)):t.data&&e.push(g(t.data,t.mode)),e},[])},e.fromString=function(t,n){let r=h(m(d(t,s.isKanjiModeEnabled())),n),i=c.find_path(r.map,`start`,`end`),a=[];for(let e=1;e<i.length-1;e++)a.push(r.table[i[e]].node);return e.fromArray(p(a))},e.rawSplit=function(t){return e.fromArray(d(t,s.isKanjiModeEnabled()))}})),z=t((e=>{var t=_(),n=v(),r=y(),i=b(),a=x(),o=S(),s=C(),c=w(),l=D(),u=j(),d=M(),f=A(),p=R();function m(e,t){let n=e.size,r=o.getPositions(t);for(let t=0;t<r.length;t++){let i=r[t][0],a=r[t][1];for(let t=-1;t<=7;t++)if(!(i+t<=-1||n<=i+t))for(let r=-1;r<=7;r++)a+r<=-1||n<=a+r||(t>=0&&t<=6&&(r===0||r===6)||r>=0&&r<=6&&(t===0||t===6)||t>=2&&t<=4&&r>=2&&r<=4?e.set(i+t,a+r,!0,!0):e.set(i+t,a+r,!1,!0))}}function h(e){let t=e.size;for(let n=8;n<t-8;n++){let t=n%2==0;e.set(n,6,t,!0),e.set(6,n,t,!0)}}function g(e,t){let n=a.getPositions(t);for(let t=0;t<n.length;t++){let r=n[t][0],i=n[t][1];for(let t=-2;t<=2;t++)for(let n=-2;n<=2;n++)t===-2||t===2||n===-2||n===2||t===0&&n===0?e.set(r+t,i+n,!0,!0):e.set(r+t,i+n,!1,!0)}}function T(e,t){let n=e.size,r=u.getEncodedBits(t),i,a,o;for(let t=0;t<18;t++)i=Math.floor(t/3),a=t%3+n-8-3,o=(r>>t&1)==1,e.set(i,a,o,!0),e.set(a,i,o,!0)}function E(e,t,n){let r=e.size,i=d.getEncodedBits(t,n),a,o;for(a=0;a<15;a++)o=(i>>a&1)==1,a<6?e.set(a,8,o,!0):a<8?e.set(a+1,8,o,!0):e.set(r-15+a,8,o,!0),a<8?e.set(8,r-a-1,o,!0):a<9?e.set(8,15-a-1+1,o,!0):e.set(8,15-a-1,o,!0);e.set(r-8,8,1,!0)}function O(e,t){let n=e.size,r=-1,i=n-1,a=7,o=0;for(let s=n-1;s>0;s-=2)for(s===6&&s--;;){for(let n=0;n<2;n++)if(!e.isReserved(i,s-n)){let r=!1;o<t.length&&(r=(t[o]>>>a&1)==1),e.set(i,s-n,r),a--,a===-1&&(o++,a=7)}if(i+=r,i<0||n<=i){i-=r,r=-r;break}}}function k(e,n,i){let a=new r;i.forEach(function(t){a.put(t.mode.bit,4),a.put(t.getLength(),f.getCharCountIndicator(t.mode,e)),t.write(a)});let o=(t.getSymbolTotalCodewords(e)-c.getTotalCodewordsCount(e,n))*8;for(a.getLengthInBits()+4<=o&&a.put(0,4);a.getLengthInBits()%8!=0;)a.putBit(0);let s=(o-a.getLengthInBits())/8;for(let e=0;e<s;e++)a.put(e%2?17:236,8);return N(a,e,n)}function N(e,n,r){let i=t.getSymbolTotalCodewords(n),a=i-c.getTotalCodewordsCount(n,r),o=c.getBlocksCount(n,r),s=o-i%o,u=Math.floor(i/o),d=Math.floor(a/o),f=d+1,p=u-d,m=new l(p),h=0,g=Array(o),_=Array(o),v=0,y=new Uint8Array(e.buffer);for(let e=0;e<o;e++){let t=e<s?d:f;g[e]=y.slice(h,h+t),_[e]=m.encode(g[e]),h+=t,v=Math.max(v,t)}let b=new Uint8Array(i),x=0,S,C;for(S=0;S<v;S++)for(C=0;C<o;C++)S<g[C].length&&(b[x++]=g[C][S]);for(S=0;S<p;S++)for(C=0;C<o;C++)b[x++]=_[C][S];return b}function P(e,n,r,a){let o;if(Array.isArray(e))o=p.fromArray(e);else if(typeof e==`string`){let t=n;if(!t){let n=p.rawSplit(e);t=u.getBestVersionForData(n,r)}o=p.fromString(e,t||40)}else throw Error(`Invalid data`);let c=u.getBestVersionForData(o,r);if(!c)throw Error(`The amount of data is too big to be stored in a QR Code`);if(!n)n=c;else if(n<c)throw Error(`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Zt as t}from"./icons-I81S_8cW.js";import{i as n}from"./markdown-C4I0Caum.js";import{s as r}from"./index-
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Zt as t}from"./icons-I81S_8cW.js";import{i as n}from"./markdown-C4I0Caum.js";import{s as r}from"./index-C5Ihi44B.js";var i=e(t(),1),a=n();function o({points:e,color:t,height:n=140,format:r,emptyLabel:o=`no data`}){let[s,c]=(0,i.useState)(null),l=(0,i.useId)(),u=n,d=u-10-22,f=(0,i.useMemo)(()=>Math.max(...e.map(e=>e.value),0),[e]);if(e.length===0||f<=0)return(0,a.jsx)(`div`,{className:`hq-chart-empty`,children:o});let p=e.length,m=666/p,h=Math.max(2,Math.min(18,m-2)),g=e=>10+d*(1-e/f),_=[f*.25,f*.5,f*.75,f],v=Math.max(1,Math.round(p/5)),y=e=>new Date(e).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`}),b=s===null?void 0:e[s];return(0,a.jsxs)(`div`,{className:`hq-chart`,children:[(0,a.jsxs)(`svg`,{viewBox:`0 0 720 ${u}`,className:`hq-chart-svg`,role:`img`,"aria-label":`Time series chart with ${e.length} data points`,onMouseLeave:()=>c(null),onMouseMove:t=>{let n=t.currentTarget.getBoundingClientRect(),r=(t.clientX-n.left)/n.width*720,i=Math.floor((r-46)/m);c(i>=0&&i<e.length?i:null)},children:[(0,a.jsx)(`clipPath`,{id:l,children:(0,a.jsx)(`rect`,{x:46,y:10,width:666,height:d})}),_.map((e,t)=>(0,a.jsxs)(`g`,{children:[(0,a.jsx)(`line`,{x1:46,x2:712,y1:g(e),y2:g(e),className:`hq-chart-grid`}),(0,a.jsx)(`text`,{x:40,y:g(e)+3,className:`hq-chart-ytick`,textAnchor:`end`,children:r(e)})]},t)),(0,a.jsx)(`line`,{x1:46,x2:712,y1:10+d,y2:10+d,className:`hq-chart-axis`}),(0,a.jsx)(`g`,{clipPath:`url(#${l})`,children:e.map((e,n)=>{let r=46+n*m+(m-h)/2,i=g(e.value),o=10+d-i;return o<=0?null:(0,a.jsx)(`rect`,{x:r,y:i,width:h,height:o,rx:Math.min(3,h/2),fill:t,opacity:s===null||s===n?1:.45},n)})}),e.map((e,t)=>t%v===0?(0,a.jsx)(`text`,{x:46+t*m+m/2,y:u-6,className:`hq-chart-xtick`,textAnchor:`middle`,children:y(e.ts)},t):null),(0,a.jsx)(`rect`,{x:46,y:10,width:666,height:d,fill:`transparent`})]}),b!==void 0&&(0,a.jsxs)(`div`,{className:`hq-chart-tooltip`,children:[(0,a.jsx)(`span`,{className:`hq-chart-tooltip-swatch`,style:{background:t}}),(0,a.jsx)(`span`,{className:`hq-chart-tooltip-value`,children:r(b.value)}),(0,a.jsx)(`span`,{className:`hq-chart-tooltip-time`,children:y(b.ts)})]})]})}var s=[{label:`1h`,ms:36e5},{label:`6h`,ms:216e5},{label:`24h`,ms:864e5},{label:`7d`,ms:6048e5}];function c(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(Math.round(e))}function l(e,t){let n=new Map;for(let r of e){let e=r[t];if(e!==void 0)for(let[t,r]of Object.entries(e)){let e=n.get(t);e===void 0?n.set(t,{...r}):(e.costUsd+=r.costUsd,e.inputTokens+=r.inputTokens,e.outputTokens+=r.outputTokens,e.cacheRead=(e.cacheRead??0)+(r.cacheRead??0),e.cacheWrite=(e.cacheWrite??0)+(r.cacheWrite??0))}}return[...n.entries()].map(([e,t])=>({key:e,entry:t})).sort((e,t)=>t.entry.costUsd-e.entry.costUsd)}function u(){let[e,t]=(0,i.useState)([]),[n,u]=(0,i.useState)(null),[f,p]=(0,i.useState)(s[2].ms);(0,i.useEffect)(()=>{let e=!1,n=()=>{r(`/api/trends/cost`).then(n=>{e||(t(n.samples),u(null))}).catch(t=>{e||u(t.message)})};n();let i=setInterval(n,3e4);return()=>{e=!0,clearInterval(i)}},[]);let{shown:m,totalCost:h,totalTokens:g,totalTools:_,byModel:v,byProvider:y,totalCacheRead:b,totalCacheWrite:x}=(0,i.useMemo)(()=>{let t=Date.now()-f,n=e.filter(e=>e.ts>=t),r=n.length>0?n:e.slice(-24),i=r.reduce((e,t)=>e+t.costUsd,0),a=r.reduce((e,t)=>e+t.inputTokens+t.outputTokens,0),o=r.reduce((e,t)=>e+t.toolCalls,0),s=l(r,`byModel`);return{shown:r,totalCost:i,totalTokens:a,totalTools:o,byModel:s,byProvider:l(r,`byProvider`),totalCacheRead:s.reduce((e,t)=>e+(t.entry.cacheRead??0),0),totalCacheWrite:s.reduce((e,t)=>e+(t.entry.cacheWrite??0),0)}},[e,f]);if(n!==null)return(0,a.jsxs)(`div`,{className:`hq-empty hq-empty-ornate`,children:[`Error loading trends: `,n]});if(e.length===0)return(0,a.jsx)(`div`,{className:`hq-empty hq-empty-ornate`,children:`No trend data yet. Trends accumulate as cost signals arrive.`});let S=v.length>0,C=b+x>0?b/(b+x)*100:null,w=s.find(e=>e.ms===f)?.label??`custom`;return(0,a.jsxs)(`div`,{className:`hq-screen hq-trends-screen`,children:[(0,a.jsxs)(`section`,{className:`hq-screen-hero hq-trends-hero`,"aria-label":`Telemetry trend summary`,children:[(0,a.jsxs)(`div`,{children:[(0,a.jsx)(`span`,{className:`hq-section-kicker`,children:`Telemetry runway`}),(0,a.jsxs)(`h2`,{children:[w,` signal window`]}),(0,a.jsx)(`p`,{children:`Cost, tokens and tool activity are split into single-purpose charts so spikes stay attributable without dual-axis ambiguity.`})]}),(0,a.jsxs)(`div`,{className:`hq-hero-metrics`,children:[(0,a.jsx)(d,{label:`cost`,value:`$${h.toFixed(4)}`}),(0,a.jsx)(d,{label:`tokens`,value:c(g),tone:`warn`}),(0,a.jsx)(d,{label:`tool calls`,value:_.toLocaleString(),tone:`ok`}),C===null?null:(0,a.jsx)(d,{label:`cache hit`,value:`${C.toFixed(0)}%`})]})]}),(0,a.jsxs)(`div`,{className:`hq-filter-row hq-trends-filter-row`,children:[s.map(e=>(0,a.jsx)(`button`,{type:`button`,className:`hq-pill hq-filter-chip${f===e.ms?` selected`:``}`,onClick:()=>p(e.ms),children:e.label},e.label)),(0,a.jsxs)(`span`,{className:`hq-mono hq-row-subtle hq-ml-auto`,children:[m.length,` × 5-min buckets`]})]}),(0,a.jsxs)(`section`,{className:`hq-chart-gallery`,"aria-label":`Trend charts`,children:[(0,a.jsxs)(`div`,{className:`hq-card hq-chart-card primary`,children:[(0,a.jsx)(`div`,{className:`hq-section-head compact`,children:(0,a.jsxs)(`div`,{children:[(0,a.jsx)(`span`,{className:`hq-section-kicker`,children:`Spend`}),(0,a.jsx)(`h3`,{children:`Cost (USD)`})]})}),(0,a.jsx)(o,{points:m.map(e=>({ts:e.ts,value:e.costUsd})),color:`var(--chart-1)`,format:e=>`$${e>=1?e.toFixed(2):e.toFixed(4)}`})]}),(0,a.jsxs)(`div`,{className:`hq-card hq-chart-card`,children:[(0,a.jsx)(`div`,{className:`hq-section-head compact`,children:(0,a.jsxs)(`div`,{children:[(0,a.jsx)(`span`,{className:`hq-section-kicker`,children:`Volume`}),(0,a.jsx)(`h3`,{children:`Tokens (in + out)`})]})}),(0,a.jsx)(o,{points:m.map(e=>({ts:e.ts,value:e.inputTokens+e.outputTokens})),color:`var(--chart-2)`,format:c})]}),(0,a.jsxs)(`div`,{className:`hq-card hq-chart-card`,children:[(0,a.jsx)(`div`,{className:`hq-section-head compact`,children:(0,a.jsxs)(`div`,{children:[(0,a.jsx)(`span`,{className:`hq-section-kicker`,children:`Activity`}),(0,a.jsx)(`h3`,{children:`Tool calls`})]})}),(0,a.jsx)(o,{points:m.map(e=>({ts:e.ts,value:e.toolCalls})),color:`var(--chart-3)`,format:e=>String(Math.round(e))})]})]}),S&&(0,a.jsxs)(`section`,{className:`hq-two-column hq-trends-breakdowns`,children:[(0,a.jsxs)(`div`,{children:[(0,a.jsx)(`div`,{className:`hq-section-head compact`,children:(0,a.jsxs)(`div`,{children:[(0,a.jsx)(`span`,{className:`hq-section-kicker`,children:`Model economics`}),(0,a.jsx)(`h3`,{children:`By Model`})]})}),(0,a.jsx)(`div`,{className:`hq-card hq-breakdown-card`,children:v.map(({key:e,entry:t})=>{let n=h>0?t.costUsd/h*100:0;return(0,a.jsxs)(`div`,{className:`hq-row hq-breakdown-row`,children:[(0,a.jsx)(`span`,{className:`hq-text-bright`,children:e}),(0,a.jsxs)(`span`,{className:`hq-mono hq-row-subtle`,children:[c(t.inputTokens),`→`,c(t.outputTokens),t.cacheRead!==void 0||t.cacheWrite!==void 0?` · cache ${c((t.cacheRead??0)+(t.cacheWrite??0))}`:``]}),(0,a.jsxs)(`span`,{className:`hq-cost-amount hq-ml-auto`,children:[`$`,t.costUsd.toFixed(4)]}),(0,a.jsxs)(`span`,{className:`hq-mono hq-row-subtle`,children:[n.toFixed(1),`%`]})]},e)})})]}),y.length>1&&(0,a.jsxs)(`div`,{children:[(0,a.jsx)(`div`,{className:`hq-section-head compact`,children:(0,a.jsxs)(`div`,{children:[(0,a.jsx)(`span`,{className:`hq-section-kicker`,children:`Provider split`}),(0,a.jsx)(`h3`,{children:`By Provider`})]})}),(0,a.jsx)(`div`,{className:`hq-card hq-breakdown-card`,children:y.map(({key:e,entry:t})=>{let n=h>0?t.costUsd/h*100:0;return(0,a.jsxs)(`div`,{className:`hq-row hq-breakdown-row`,children:[(0,a.jsx)(`span`,{className:`hq-text-bright`,children:e}),(0,a.jsxs)(`span`,{className:`hq-cost-amount hq-ml-auto`,children:[`$`,t.costUsd.toFixed(4)]}),(0,a.jsxs)(`span`,{className:`hq-mono hq-row-subtle`,children:[n.toFixed(1),`%`]})]},e)})})]})]})]})}function d({label:e,value:t,tone:n}){return(0,a.jsxs)(`div`,{className:`hq-hero-metric`,"data-tone":n,children:[(0,a.jsx)(`strong`,{children:t}),(0,a.jsx)(`span`,{children:e})]})}export{u as TrendsView};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Zt as t}from"./icons-I81S_8cW.js";import{s as n,u as r}from"./index-
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Zt as t}from"./icons-I81S_8cW.js";import{s as n,u as r}from"./index-C5Ihi44B.js";var i=e(t(),1);function a(e,t=200){let a=r(e=>e.events),[o,s]=(0,i.useState)([]),[c,l]=(0,i.useState)(!0);return(0,i.useEffect)(()=>{let r=!1;return n(`/api/events?type=${encodeURIComponent(e)}&limit=${t}`).then(e=>{r||(s([...e.events??[]].reverse()),l(!1))}).catch(()=>{r||l(!1)}),()=>{r=!0}},[e,t]),{events:(0,i.useMemo)(()=>{let t=new Set,n=[];for(let r of o)r.type!==e||t.has(r.id)||(t.add(r.id),n.push(r));for(let r of a)r.type!==e||t.has(r.id)||(t.add(r.id),n.push(r));return n},[o,a,e]),loading:c}}export{a as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Ht as t,M as n,Zt as r,ct as i,kt as a,l as o,u as s}from"./icons-I81S_8cW.js";import{i as c}from"./markdown-C4I0Caum.js";import{t as l}from"./use-backfilled-events-
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Ht as t,M as n,Zt as r,ct as i,kt as a,l as o,u as s}from"./icons-I81S_8cW.js";import{i as c}from"./markdown-C4I0Caum.js";import{t as l}from"./use-backfilled-events-CbvvmZr7.js";var u=e(r(),1),d=c(),f={allocated:{Icon:n,cls:`info`},committed:{Icon:t,cls:`active`},merged:{Icon:i,cls:`active`},conflict:{Icon:o,cls:`warn`},released:{Icon:s,cls:`idle`},failed:{Icon:a,cls:`error`}};function p({e}){let t=e.payload,r=f[t.kind]??{Icon:n,cls:`info`};return(0,d.jsxs)(`div`,{className:`hq-row hq-worktree-event-line`,children:[(0,d.jsx)(r.Icon,{size:14,className:`hq-kind-icon ${r.cls}`}),(0,d.jsx)(`span`,{className:`hq-text-bright`,children:t.kind}),t.branch!==void 0&&(0,d.jsx)(`span`,{className:`hq-pill info`,children:t.branch}),t.kind===`committed`&&(0,d.jsxs)(`span`,{className:`hq-mono hq-diffstat`,children:[(0,d.jsxs)(`span`,{className:`hq-diff-add-count`,children:[`+`,t.insertions??0]}),` `,(0,d.jsxs)(`span`,{className:`hq-diff-del-count`,children:[`−`,t.deletions??0]}),` in `,t.files??0,` file(s)`,` `,t.sha===void 0?``:`(${t.sha.slice(0,7)})`]}),t.kind===`conflict`&&t.conflictFiles!==void 0&&(0,d.jsxs)(`span`,{className:`hq-mono hq-row-error`,children:[`conflicts: `,t.conflictFiles.join(`, `)]}),t.kind===`failed`&&(0,d.jsx)(`span`,{className:`hq-mono hq-row-error`,children:t.error}),(0,d.jsx)(`span`,{className:`hq-mono hq-row-time`,children:new Date(e.timestamp).toLocaleTimeString()})]})}function m(){let{events:e,loading:t}=l(`worktree.event`,300),r=(0,u.useMemo)(()=>{let t=new Map;for(let n of e){let e=n.payload.ownerId??`(unknown)`,r=t.get(e)??[];r.push(n),t.set(e,r)}return Array.from(t.entries()).reverse()},[e]),i=(0,u.useMemo)(()=>{let e=0,t=0,n=0,i=0;for(let[,a]of r){let r=a.at(-1)?.payload;r?.kind===`merged`||r?.kind===`released`?t+=1:e+=1,a.some(e=>e.payload.kind===`conflict`)&&(n+=1),a.some(e=>e.payload.kind===`failed`)&&(i+=1)}return{open:e,merged:t,conflicts:n,failed:i}},[r]);return r.length===0?(0,d.jsx)(`div`,{className:`hq-empty hq-empty-ornate`,children:t?`Loading worktree history…`:`No worktree events yet. These appear when Goal allocates or merges git worktrees for parallel phases.`}):(0,d.jsxs)(`div`,{className:`hq-screen hq-worktree-screen`,children:[(0,d.jsxs)(`section`,{className:`hq-screen-hero hq-worktree-hero`,"aria-label":`Worktree lifecycle summary`,children:[(0,d.jsxs)(`div`,{children:[(0,d.jsx)(`span`,{className:`hq-section-kicker`,children:`Workspace lanes`}),(0,d.jsx)(`h2`,{children:`Parallel branch lifecycle`}),(0,d.jsx)(`p`,{children:`Each owner gets a lane so allocation, commits, conflicts, merges and release events read as an ordered build path.`})]}),(0,d.jsxs)(`div`,{className:`hq-hero-metrics`,children:[(0,d.jsx)(h,{label:`lanes`,value:r.length}),(0,d.jsx)(h,{label:`open`,value:i.open,tone:i.open>0?`warn`:`ok`}),(0,d.jsx)(h,{label:`merged/released`,value:i.merged,tone:`ok`}),(0,d.jsx)(h,{label:`conflicts`,value:i.conflicts+i.failed,tone:i.conflicts+i.failed>0?`error`:`ok`})]})]}),(0,d.jsx)(`div`,{className:`hq-worktree-lanes`,children:r.map(([e,t])=>{let r=t[t.length-1].payload,i=f[r.kind]??{Icon:n,cls:`info`};return(0,d.jsxs)(`article`,{className:`hq-card hq-worktree-lane`,children:[(0,d.jsxs)(`div`,{className:`hq-row hq-lane-head`,children:[(0,d.jsx)(`span`,{className:`hq-mono hq-text-bright`,children:e}),(0,d.jsx)(`span`,{className:`hq-pill ${i.cls}`,children:r.kind}),(0,d.jsxs)(`span`,{className:`hq-mono hq-row-time`,children:[t.length,` events`]})]}),(0,d.jsx)(`div`,{className:`hq-worktree-event-list`,children:t.map(e=>(0,d.jsx)(p,{e},e.id))})]},e)})})]})}function h({label:e,value:t,tone:n}){return(0,d.jsxs)(`div`,{className:`hq-hero-metric`,"data-tone":n,children:[(0,d.jsx)(`strong`,{children:t}),(0,d.jsx)(`span`,{children:e})]})}export{m as WorktreeView};
|
package/dist/index.html
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<link rel="icon" type="image/svg+xml" href="/wrongstack.svg" />
|
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
7
|
<title>WrongStack HQ</title>
|
|
8
|
-
<script type="module" crossorigin src="/assets/index-
|
|
8
|
+
<script type="module" crossorigin src="/assets/index-C5Ihi44B.js"></script>
|
|
9
9
|
<link rel="modulepreload" crossorigin href="/assets/rolldown-runtime-hePW80VL.js">
|
|
10
10
|
<link rel="modulepreload" crossorigin href="/assets/icons-I81S_8cW.js">
|
|
11
11
|
<link rel="modulepreload" crossorigin href="/assets/vendor-CWm0VQZ2.js">
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wrongstack/webui-hq",
|
|
3
|
-
"version": "0.308.
|
|
3
|
+
"version": "0.308.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "HQ Command Center dashboard — offline React app for the cross-machine coordination surface (port 3499).",
|
|
6
6
|
"type": "module",
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
"remark-gfm": "^4.0.1",
|
|
24
24
|
"virtua": "^0.50.1",
|
|
25
25
|
"zustand": "5.0.15",
|
|
26
|
-
"@wrongstack/
|
|
27
|
-
"@wrongstack/
|
|
28
|
-
"@wrongstack/
|
|
26
|
+
"@wrongstack/core": "0.308.2",
|
|
27
|
+
"@wrongstack/webui-server": "0.308.2",
|
|
28
|
+
"@wrongstack/tools": "0.308.2"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@types/node": "^26.2.0",
|