@wrongstack/webui 0.319.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (218) hide show
  1. package/dist/assets/AgentRosterView-B_J6SvVF.js +12 -0
  2. package/dist/assets/AnalyticsDashboard-BgZiiiDb.js +1 -0
  3. package/dist/assets/AudienceMemoryPanel-CPuksIMN.js +3 -0
  4. package/dist/assets/ChangesView-CmZeNwbw.js +1 -0
  5. package/dist/assets/ChimeraReviewsView-CpfSkgQ2.js +1 -0
  6. package/dist/assets/ChronicleDashboard-B6lhZGjz.js +1 -0
  7. package/dist/assets/CodeEditor-Daz1yqjF.js +2 -0
  8. package/dist/assets/CodeMap-D-H9FNUJ.js +1 -0
  9. package/dist/assets/ConfirmModal-CjsZbvo3.js +1 -0
  10. package/dist/assets/CronJobsPanel-DGKW_zwc.js +1 -0
  11. package/dist/assets/{DeadCodeScanPanel-DooqnEMF.js → DeadCodeScanPanel-Cn5bSfLv.js} +1 -1
  12. package/dist/assets/DebugDashboard-Uh9QLbEk.js +1 -0
  13. package/dist/assets/DesignGalleryView-Da1QtI5b.js +1 -0
  14. package/dist/assets/GoalView-BgVxzzzS.js +1 -0
  15. package/dist/assets/KanbanView-_JvZKFyI.js +3 -0
  16. package/dist/assets/MailboxDetailView-26bVSSbU.js +1 -0
  17. package/dist/assets/MemoryDrawer-C5sEdVvj.js +1 -0
  18. package/dist/assets/MemoryManager-BqWzNt8w.js +1 -0
  19. package/dist/assets/ModelPicker-DqRzzv5J.js +1 -0
  20. package/dist/assets/ProcessMonitor-ygFLD5zk.js +1 -0
  21. package/dist/assets/PromptJournalView-B65KxlYi.js +1 -0
  22. package/dist/assets/QueuePanel-CJlIV0pX.js +1 -0
  23. package/dist/assets/RefreshDebugView-CNovrSAn.js +1 -0
  24. package/dist/assets/RequirementIntakeView-BnrQSVE_.js +1 -0
  25. package/dist/assets/SageTabs-CJqOqiY7.js +2 -0
  26. package/dist/assets/SddFlowGraph-CNOyn5N9.js +1 -0
  27. package/dist/assets/SddHub-mFjsa_Zl.js +2 -0
  28. package/dist/assets/SessionInspectView-MEmxIEzB.js +1 -0
  29. package/dist/assets/SessionList-DmcQJmzw.js +1 -0
  30. package/dist/assets/SessionsDashboard-BCYViJlx.js +1 -0
  31. package/dist/assets/SetupScreen-BwnSJt7v.js +1 -0
  32. package/dist/assets/SkillDetailView-ebz2dRUQ.js +3 -0
  33. package/dist/assets/TechStackView-DESDpUDA.js +2 -0
  34. package/dist/assets/TerminalPanel-BiWnldbB.js +1 -0
  35. package/dist/assets/{activity-C7dkJqBU.js → activity-87Kr1xrI.js} +2 -2
  36. package/dist/assets/{activity-D1rp3dH9.js → activity-CCW2-qSA.js} +2 -2
  37. package/dist/assets/activity-CXLMCm4J.js +10 -0
  38. package/dist/assets/{activity-BU6MNvBJ.js → activity-CmzV075e.js} +2 -2
  39. package/dist/assets/{activity-C_18AaRY.js → activity-D2D6_ljD.js} +2 -2
  40. package/dist/assets/{activity-CpnSsE22.js → activity-Dt348P4m.js} +2 -2
  41. package/dist/assets/{activity-hTPcI4q1.js → activity-FxWZooaS.js} +2 -2
  42. package/dist/assets/button-rqi3MczV.js +1 -0
  43. package/dist/assets/chat-store-BcfvHUUj.js +1 -0
  44. package/dist/assets/{codemap-activity-store-Br4b57a0.js → codemap-activity-store-CWi-Yd9Z.js} +1 -1
  45. package/dist/assets/codemap-index-store-3M7F08K_.js +1 -0
  46. package/dist/assets/dialog-xJxaQi60.js +1 -0
  47. package/dist/assets/empty-state-BxilAuC3.js +1 -0
  48. package/dist/assets/i18n-DBqM1FUM.js +2 -0
  49. package/dist/assets/index-TDhvFXb0.js +144 -0
  50. package/dist/assets/input-ClZR-odw.js +1 -0
  51. package/dist/assets/{mailbox-store-B9DIvRgo.js → mailbox-store-yydAVjyj.js} +1 -1
  52. package/dist/assets/{markdown-Kp5uSgOw.js → markdown-BP6Z3HKc.js} +24 -24
  53. package/dist/assets/{monaco-BCqJp2xW.js → monaco-_kWjHrlo.js} +204 -204
  54. package/dist/assets/{monaco-theme-CR1QvFi2.js → monaco-theme-Dmx6JuoU.js} +1 -1
  55. package/dist/assets/react-core-BNmTiJ-I.js +9 -0
  56. package/dist/assets/{roster-ws-BQUI8QuW.js → roster-ws-n_N7K9tX.js} +1 -1
  57. package/dist/assets/{settings-BGvRM3vJ.js → settings-B1vpPbTt.js} +1 -1
  58. package/dist/assets/{settings-D-LlBmzO.js → settings-BZnHCnGT.js} +1 -1
  59. package/dist/assets/{settings-1o1gooaL.js → settings-BcB2BIE2.js} +1 -1
  60. package/dist/assets/{settings-Cy_xp4Jt.js → settings-D9AQ5wLT2.js} +1 -1
  61. package/dist/assets/{settings-BV8EFmpH.js → settings-DiVpBZQ2.js} +1 -1
  62. package/dist/assets/{settings-nWMBX3xS.js → settings-DwbEJvxt.js} +1 -1
  63. package/dist/assets/settings-WuyKla3E.js +1 -0
  64. package/dist/assets/setup-B-xPcuTH.js +1 -0
  65. package/dist/assets/setup-B9oerXTs.js +1 -0
  66. package/dist/assets/setup-BWlr07i_.js +1 -0
  67. package/dist/assets/setup-CQ4-lz5u.js +1 -0
  68. package/dist/assets/setup-Cmq_aIjv.js +1 -0
  69. package/dist/assets/setup-DK5JTuqw.js +1 -0
  70. package/dist/assets/setup-qooXjj4V.js +1 -0
  71. package/dist/assets/shared-D8dubdNH.js +1 -0
  72. package/dist/assets/stores-Cfei1ViB.js +7 -0
  73. package/dist/assets/ui-store-CLXDcLPI.js +1 -0
  74. package/dist/assets/useWebSocket-AYEcpb1U.js +27 -0
  75. package/dist/assets/{utils-DQ9Exx8j.js → utils-BpBOwXlT.js} +1 -1
  76. package/dist/assets/vector-memory-panel-BwPPCCbh.js +1 -0
  77. package/dist/assets/{vendor-BMdWcCR4.css → vendor-BShi5_Dg.css} +1 -1
  78. package/dist/assets/vendor-BshlG0z-.js +125 -0
  79. package/dist/assets/view-navigation-CvWJeGMc.js +1 -0
  80. package/dist/assets/vite-preload-Czpn1I53.js +1 -0
  81. package/dist/assets/ws-client-C_IqS0t4.js +22 -0
  82. package/dist/assets/xyflow-BNn76cbK.js +7 -0
  83. package/dist/assets/xyflow-DLioOiRN.css +1 -0
  84. package/dist/components/AgentOfficeView/AgentLane.d.ts +10 -0
  85. package/dist/components/AgentOfficeView/BreakRoom.d.ts +10 -0
  86. package/dist/components/AgentOfficeView/ClientOfficeHeader.d.ts +6 -0
  87. package/dist/components/AgentOfficeView/OfficeBriefing.d.ts +8 -0
  88. package/dist/components/AgentOfficeView/parcels.d.ts +27 -0
  89. package/dist/components/AgentOfficeView.d.ts +2 -10
  90. package/dist/components/ChatInput/chat-input-bars.d.ts +30 -0
  91. package/dist/components/ChatInput/session-draft.d.ts +46 -0
  92. package/dist/components/ChatInput/use-chat-keydown.d.ts +21 -0
  93. package/dist/components/ChatInput/use-chat-submit.d.ts +40 -0
  94. package/dist/components/ChatInput/use-paste-drop.d.ts +1 -1
  95. package/dist/components/ChatInput/use-speech-recognition.d.ts +1 -1
  96. package/dist/components/ChatInput.d.ts +3 -3
  97. package/dist/components/DependencyGraph.d.ts +1 -1
  98. package/dist/components/DiffView.d.ts +1 -1
  99. package/dist/components/FileActivityDrawer/ContextTab.d.ts +21 -0
  100. package/dist/components/FileActivityDrawer/LogsTab.d.ts +13 -0
  101. package/dist/components/FileActivityDrawer/OverviewTab.d.ts +14 -0
  102. package/dist/components/FileActivityDrawer/SkeletonTab.d.ts +5 -0
  103. package/dist/components/FileActivityDrawer/types.d.ts +58 -0
  104. package/dist/components/FileActivityDrawer.d.ts +1 -40
  105. package/dist/components/MainViewSlot.d.ts +16 -0
  106. package/dist/components/MemoryManager/DeleteMemoryDialog.d.ts +3 -2
  107. package/dist/components/MessageBubble/ToolLedgerCard.d.ts +1 -1
  108. package/dist/components/SettingsPanel/brain-section-options.d.ts +6 -0
  109. package/dist/components/SetupScreen/CustomProviderSection.d.ts +1 -1
  110. package/dist/components/ViewRouter.d.ts +12 -4
  111. package/dist/components/agents/AgentRosterCard.d.ts +1 -1
  112. package/dist/components/context-editor/ContextWindowEditor.d.ts +1 -1
  113. package/dist/components/ui/dropdown-menu.d.ts +1 -1
  114. package/dist/components/vector-memory-panel/index.d.ts +1 -1
  115. package/dist/components/view-registry.d.ts +73 -0
  116. package/dist/hooks/useServerMessage.d.ts +71 -0
  117. package/dist/hooks/ws-handlers/session-context-handlers.d.ts +20 -0
  118. package/dist/index.css +788 -788
  119. package/dist/index.html +25 -25
  120. package/dist/index.js +48077 -45298
  121. package/dist/lib/platform.d.ts +40 -0
  122. package/dist/lib/view-navigation.d.ts +27 -2
  123. package/dist/lib/ws-client-auth.d.ts +17 -0
  124. package/dist/lib/ws-client-connection.d.ts +26 -0
  125. package/dist/lib/ws-client-contracts.d.ts +10 -0
  126. package/dist/lib/ws-client-echo.d.ts +46 -0
  127. package/dist/lib/ws-client-queue.d.ts +18 -0
  128. package/dist/lib/ws-client-session-methods.d.ts +54 -0
  129. package/dist/lib/ws-client-swap.d.ts +53 -0
  130. package/dist/lib/ws-client.d.ts +40 -71
  131. package/dist/manifest.json +1 -1
  132. package/dist/stores/context-editor-store.d.ts +1 -1
  133. package/dist/stores/council-log-store.d.ts +6 -0
  134. package/dist/stores/index.d.ts +2 -2
  135. package/dist/stores/session-tab-store.d.ts +8 -0
  136. package/dist/stores/types.d.ts +10 -1
  137. package/dist/stores/ui-store-chrome.d.ts +12 -0
  138. package/dist/stores/ui-store-persist.d.ts +4 -0
  139. package/dist/stores/ui-store-types.d.ts +379 -0
  140. package/dist/stores/ui-store.d.ts +7 -467
  141. package/dist/stores/viz-graph-helpers.d.ts +18 -0
  142. package/dist/stores/viz-pipeline.d.ts +7 -0
  143. package/dist/stores/viz-store.d.ts +3 -123
  144. package/dist/stores/viz-types.d.ts +124 -0
  145. package/dist/types/brain.d.ts +3 -0
  146. package/dist/types/client-message.d.ts +8 -0
  147. package/dist/types/runtime.d.ts +7 -0
  148. package/dist/types/sage.d.ts +7 -0
  149. package/dist/types/server-message-chimera.d.ts +161 -0
  150. package/dist/types/server-message-files.d.ts +195 -0
  151. package/dist/types/server-message-fleet.d.ts +148 -0
  152. package/dist/types/server-message-mcp.d.ts +199 -0
  153. package/dist/types/server-message-system.d.ts +399 -0
  154. package/dist/types/server-message.d.ts +12 -1098
  155. package/dist/types/skills-design.d.ts +7 -0
  156. package/dist/types/system.d.ts +16 -0
  157. package/package.json +9 -9
  158. package/dist/assets/AgentRosterView-BVpIFQwi.js +0 -9
  159. package/dist/assets/AnalyticsDashboard-nqlWJi6M.js +0 -1
  160. package/dist/assets/AudienceMemoryPanel-BT6C4Jkw.js +0 -3
  161. package/dist/assets/ChangesView-CN7NWDeV.js +0 -1
  162. package/dist/assets/ChimeraReviewsView-BNQE5kRx.js +0 -1
  163. package/dist/assets/ChronicleDashboard-BWMkG_hu.js +0 -1
  164. package/dist/assets/CodeEditor-DZ2k-Mz5.js +0 -2
  165. package/dist/assets/CodeMap-CLOuNLqN.js +0 -1
  166. package/dist/assets/ConfirmModal-B6BGiiN8.js +0 -1
  167. package/dist/assets/CronJobsPanel-CsMIoWVQ.js +0 -1
  168. package/dist/assets/DebugDashboard-C0tmxxV8.js +0 -1
  169. package/dist/assets/DesignGalleryView-lc-XRmVG.js +0 -1
  170. package/dist/assets/GoalView-BuYUc4OB.js +0 -1
  171. package/dist/assets/KanbanView-DQK6adut.js +0 -3
  172. package/dist/assets/MailboxDetailView-CBV3-Hf2.js +0 -1
  173. package/dist/assets/MemoryDrawer-rPf-1Ulk.js +0 -1
  174. package/dist/assets/MemoryManager-B_ZJhOqq.js +0 -1
  175. package/dist/assets/ModelPicker-CLs0qQgg.js +0 -1
  176. package/dist/assets/OfficeMapPanel-DnbdkXL1.js +0 -4
  177. package/dist/assets/ProcessMonitor-CHNNqCk9.js +0 -1
  178. package/dist/assets/PromptJournalView-Biu4DknM.js +0 -1
  179. package/dist/assets/QueuePanel-CzTXq6j4.js +0 -1
  180. package/dist/assets/RefreshDebugView-d9iU3sFX.js +0 -1
  181. package/dist/assets/RequirementIntakeView-g9dzUTVw.js +0 -1
  182. package/dist/assets/SageTabs-Bw6PDwy3.js +0 -2
  183. package/dist/assets/SddFlowGraph-Bj_Aqq5B.js +0 -1
  184. package/dist/assets/SddHub-Cdow0Exb.js +0 -2
  185. package/dist/assets/SessionInspectView-je_xLISf.js +0 -1
  186. package/dist/assets/SessionList-4y1uuB-y.js +0 -1
  187. package/dist/assets/SessionsDashboard-DkaNF5lx.js +0 -1
  188. package/dist/assets/SetupScreen-DWzbXvmU.js +0 -1
  189. package/dist/assets/SkillDetailView-Bjq8GkDB.js +0 -3
  190. package/dist/assets/SpecsView-ok8HZ8ws.js +0 -1
  191. package/dist/assets/TechStackView-CQ9AdoBa.js +0 -2
  192. package/dist/assets/TerminalPanel-cbM6oQWQ.js +0 -1
  193. package/dist/assets/activity-CtTKsSX6.js +0 -10
  194. package/dist/assets/button-DNyYztcH.js +0 -1
  195. package/dist/assets/chat-store-oW_-zcJP.js +0 -1
  196. package/dist/assets/codemap-index-store-tSmlp7Uz.js +0 -1
  197. package/dist/assets/dialog-BTHxOi5z.js +0 -1
  198. package/dist/assets/empty-state-DBQN80mK.js +0 -1
  199. package/dist/assets/i18n-D06uU1PM.js +0 -2
  200. package/dist/assets/index-Cwjer17r.js +0 -144
  201. package/dist/assets/input-CTGeYzNe.js +0 -1
  202. package/dist/assets/settings-Ci_RMpCQ.js +0 -1
  203. package/dist/assets/setup-B0D9CK3-.js +0 -1
  204. package/dist/assets/setup-B58YVaGU.js +0 -1
  205. package/dist/assets/setup-C2H9Uv0Q.js +0 -1
  206. package/dist/assets/setup-CzM4dkkU.js +0 -1
  207. package/dist/assets/setup-Di56FlHP.js +0 -1
  208. package/dist/assets/setup-Dwt58Mpz.js +0 -1
  209. package/dist/assets/setup-DznVdlJy.js +0 -1
  210. package/dist/assets/shared-CLfD85oZ.js +0 -1
  211. package/dist/assets/stores-C7Vvce-6.js +0 -7
  212. package/dist/assets/ui-store-Dm7ujR9u.js +0 -1
  213. package/dist/assets/useWebSocket-9lfOsI_r.js +0 -27
  214. package/dist/assets/vector-memory-panel-B4bQhdHe.js +0 -1
  215. package/dist/assets/vendor-enc0q-Va.js +0 -139
  216. package/dist/assets/view-navigation-wOKaM_Rf.js +0 -1
  217. package/dist/assets/ws-client-DtTZLD8e.js +0 -22
  218. /package/dist/assets/{OfficeMapPanel-Ce7myLNH.css → AgentRosterView-Ce7myLNH.css} +0 -0
@@ -0,0 +1,12 @@
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{L as t,M as n,P as r,V as i,Z as a,k as o,kt as s,q as c,t as l,u,vt as d,z as f}from"./ws-client-C_IqS0t4.js";import{i as p,t as m}from"./react-core-BNmTiJ-I.js";import{Aa as h,Bi as g,Bn as _,Bt as v,Ci as y,Ct as b,Da as x,Et as S,Fa as C,Fn as w,G as T,Ir as E,J as D,Jn as O,K as k,Ki as A,Kn as j,Ln as M,Lt as N,Nr as ee,Nt as P,On as F,Qi as te,Ra as ne,Ri as re,Rn as ie,Rr as ae,Si as I,Ut as oe,Vr as L,Vt as R,Wn as se,Y as ce,aa as le,ai as ue,bi as z,ci as B,di as de,et as fe,ft as pe,hr as me,ht as V,ia as H,jr as he,ki as ge,li as _e,lr as ve,lt as ye,mn as be,mr as xe,nt as Se,oa as Ce,q as we,qi as Te,rr as Ee,si as De,ta as Oe,tn as ke,tr as Ae,wa as je,wi as Me,wn as Ne}from"./vendor-BshlG0z-.js";import"./i18n-DBqM1FUM.js";import{a as Pe,c as Fe,d as Ie,f as Le,g as Re,h as ze,i as Be,l as Ve,n as He,o as Ue,p as We,r as Ge,s as Ke,t as qe,u as Je}from"./xyflow-BNn76cbK.js";import{t as U}from"./utils-BpBOwXlT.js";import{n as Ye}from"./ui-store-CLXDcLPI.js";import{t as Xe}from"./chat-store-BcfvHUUj.js";import{c as Ze,l as W,u as Qe}from"./stores-Cfei1ViB.js";import{r as $e}from"./mailbox-store-yydAVjyj.js";import{i as et}from"./view-navigation-CvWJeGMc.js";import{n as tt,t as nt}from"./ModelPicker-DqRzzv5J.js";import{c as rt}from"./markdown-BP6Z3HKc.js";import{S as it,a as at,c as ot,m as st,o as ct,s as lt,v as ut,y as dt}from"./index-TDhvFXb0.js";import{t as G}from"./roster-ws-n_N7K9tX.js";import{AudienceMemoryPanel as ft}from"./AudienceMemoryPanel-CPuksIMN.js";var K=e(p(),1),q=m(),pt=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`],mt=[[`timeoutMs`,`Total timeout (ms)`],[`idleTimeoutMs`,`Idle timeout (ms)`],[`maxIterations`,`Max iterations`],[`maxToolCalls`,`Max tool calls`],[`maxTokens`,`Max tokens`],[`maxCostUsd`,`Max cost (USD)`]];function ht(e){return`${e.provider}/${e.model}`}function gt(e){let t=e.indexOf(`/`);return t<0?{provider:``,model:e}:{provider:e.slice(0,t),model:e.slice(t+1)}}function _t(e){return Array.isArray(e)?e.join(`, `):``}function vt(e){return[...new Set(e.split(/[\n,]+/).map(e=>e.trim()).filter(Boolean))]}function yt({initialConfig:e,systemProtected:t,saving:n,onSave:r,onCancel:i}){let{t:a}=C(),[o,s]=(0,K.useState)(()=>structuredClone(e)),c=tt(!0),l=o.modelPolicy,u=(0,K.useMemo)(()=>(l?.allowed??[]).map(ht),[l?.allowed]),d=(0,K.useMemo)(()=>(l?.fallbacks??[]).map(ht),[l?.fallbacks]),f=e=>s(t=>({...t,...e})),p=(e,t)=>{let n=vt(t);s(t=>{let r={...t};return n.length?r[e]=n:delete r[e],r})},m=(e,t)=>{s(n=>{let r={...n.budget??{}};t===``?delete r[e]:r[e]=Number(t);let i={...n};return Object.keys(r).length?i.budget=r:delete i.budget,i})},h=e=>{let t=e.map(gt),n=new Set(e);s(e=>({...e,modelPolicy:{allowed:t,fallbacks:(e.modelPolicy?.fallbacks??[]).filter(e=>n.has(ht(e))),strict:e.modelPolicy?.strict??!0}}))};return(0,q.jsxs)(`div`,{className:`space-y-4 rounded-lg border border-border bg-card/40 p-4`,children:[t&&(0,q.jsxs)(`div`,{className:`flex gap-2 rounded-md border border-warning/30 bg-warning/5 p-2 text-[11px] text-muted-foreground`,children:[(0,q.jsx)(P,{className:`mt-0.5 h-4 w-4 shrink-0 text-warning`}),(0,q.jsx)(`span`,{children:a(`activity:runtimePolicy.protectedSystemAgentRequiredToolsAnd`)})]}),(0,q.jsxs)(`section`,{className:`space-y-2`,children:[(0,q.jsx)(`h4`,{className:`text-xs font-semibold`,children:a(`activity:runtimePolicy.providerAndModelPolicy`)}),(0,q.jsx)(nt,{candidates:c,provider:o.provider,value:o.model,placeholder:a(`activity:runtimePolicy.useProjectDefaultModel`),resetLabel:`Use project default`,onReset:()=>{s(e=>{let t={...e};return delete t.provider,delete t.model,t})},onPick:(e,t)=>{let n=`${t}/${e}`;f({provider:t,model:e}),l&&!u.includes(n)&&h([...u,n])}}),(0,q.jsxs)(`label`,{className:`flex items-center gap-2 text-[11px]`,children:[(0,q.jsx)(`input`,{type:`checkbox`,checked:!!l,onChange:e=>{if(e.target.checked){let e=o.provider&&o.model?[{provider:o.provider,model:o.model}]:c[0]?[{provider:c[0].provider,model:c[0].model}]:[];e.length&&f({modelPolicy:{allowed:e,strict:!0}})}else s(e=>{let t={...e};return delete t.modelPolicy,t})}}),a(`activity:runtimePolicy.restrictThisAgentToAnExplicit`)]}),l&&(0,q.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,q.jsxs)(`div`,{className:`space-y-1`,children:[(0,q.jsx)(`span`,{className:`text-[10px] font-medium`,children:a(`activity:runtimePolicy.allowedModels`)}),(0,q.jsx)(st,{value:u,candidates:c,onChange:h,placeholder:a(`activity:runtimePolicy.addAllowedModel`),emptyHint:`At least one model is required`})]}),(0,q.jsxs)(`div`,{className:`space-y-1`,children:[(0,q.jsx)(`span`,{className:`text-[10px] font-medium`,children:a(`activity:runtimePolicy.orderedFallbackChain`)}),(0,q.jsx)(st,{value:d,candidates:c,onChange:e=>{let t=[...new Set([...u,...e])];s(n=>({...n,modelPolicy:{allowed:t.map(gt),fallbacks:e.map(gt),strict:n.modelPolicy?.strict??!0}}))},placeholder:a(`activity:runtimePolicy.addFallbackModel`),emptyHint:`No fallback; primary failure stops the task`})]})]})]}),(0,q.jsx)(`section`,{className:`grid gap-3 sm:grid-cols-3`,children:[[`tools`,`Tools`,`read_file, search, bash`],[`skillNames`,`Skills`,`security-check, browser`],[`allowedCapabilities`,`Capabilities`,`fs.read, fs.write`]].map(([e,t,n])=>(0,q.jsxs)(`label`,{className:`space-y-1 text-[10px]`,children:[(0,q.jsx)(`span`,{className:`font-medium`,children:t}),(0,q.jsx)(`textarea`,{value:_t(o[e]),onChange:t=>p(e,t.target.value),placeholder:n,className:`h-20 w-full resize-y rounded border border-border bg-background p-2 font-mono`})]},e))}),(0,q.jsxs)(`section`,{className:`space-y-2`,children:[(0,q.jsx)(`h4`,{className:`text-xs font-semibold`,children:a(`activity:runtimePolicy.workspaceAndIsolation`)}),(0,q.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,q.jsxs)(`label`,{className:`space-y-1 text-[10px]`,children:[(0,q.jsx)(`span`,{children:a(`activity:runtimePolicy.projectRelativeWorkingDirectory`)}),(0,q.jsx)(`input`,{value:o.cwd??``,onChange:e=>f({cwd:e.target.value||void 0}),placeholder:a(`activity:runtimePolicy.packagesWebui`),className:`h-8 w-full rounded border border-border bg-background px-2 font-mono`})]}),(0,q.jsxs)(`label`,{className:`space-y-1 text-[10px]`,children:[(0,q.jsx)(`span`,{children:a(`activity:runtimePolicy.gitWorktreeIsolation`)}),(0,q.jsxs)(`select`,{value:String(o.worktree??`auto`),onChange:e=>f({worktree:e.target.value}),className:`h-8 w-full rounded border border-border bg-background px-2`,children:[(0,q.jsx)(`option`,{value:`auto`,children:a(`activity:runtimePolicy.automatic`)}),(0,q.jsx)(`option`,{value:`required`,children:a(`activity:runtimePolicy.required`)}),(0,q.jsx)(`option`,{value:`off`,children:a(`activity:runtimePolicy.off`)})]})]})]})]}),(0,q.jsxs)(`section`,{className:`space-y-2`,children:[(0,q.jsx)(`h4`,{className:`text-xs font-semibold`,children:a(`activity:runtimePolicy.limits`)}),(0,q.jsx)(`div`,{className:`grid gap-2 sm:grid-cols-3`,children:mt.map(([e,t])=>(0,q.jsxs)(`label`,{className:`space-y-1 text-[10px]`,children:[(0,q.jsx)(`span`,{children:t}),(0,q.jsx)(`input`,{type:`number`,min:`0`,step:e===`maxCostUsd`?`0.01`:`1`,value:o.budget?.[e]??``,onChange:t=>m(e,t.target.value),className:`h-8 w-full rounded border border-border bg-background px-2`})]},e))})]}),(0,q.jsxs)(`section`,{className:`space-y-2`,children:[(0,q.jsxs)(`label`,{className:`flex items-center gap-2 text-xs font-semibold`,children:[(0,q.jsx)(`input`,{type:`checkbox`,checked:!!o.availability,onChange:e=>{e.target.checked?f({availability:{timezone:Intl.DateTimeFormat().resolvedOptions().timeZone||`UTC`,days:[1,2,3,4,5],start:`09:00`,end:`18:00`,mode:t?`advisory`:`enforce`}}):s(e=>{let t={...e};return delete t.availability,t})}}),a(`activity:runtimePolicy.workingHours`)]}),o.availability&&(0,q.jsxs)(`div`,{className:`space-y-2 rounded border border-border p-2`,children:[(0,q.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:pt.map((e,t)=>(0,q.jsxs)(`label`,{className:`flex items-center gap-1 text-[10px]`,children:[(0,q.jsx)(`input`,{type:`checkbox`,checked:o.availability?.days.includes(t)??!1,onChange:e=>{let n=o.availability;if(!n)return;let r=e.target.checked?[...new Set([...n.days,t])].sort():n.days.filter(e=>e!==t);f({availability:{...n,days:r}})}}),e]},e))}),(0,q.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-4`,children:[(0,q.jsx)(`input`,{value:o.availability.timezone,onChange:e=>f({availability:{...o.availability,timezone:e.target.value}}),placeholder:a(`activity:runtimePolicy.europeKiev`),className:`h-8 rounded border border-border bg-background px-2 text-[10px]`}),(0,q.jsx)(`input`,{type:`time`,value:o.availability.start,onChange:e=>f({availability:{...o.availability,start:e.target.value}}),className:`h-8 rounded border border-border bg-background px-2 text-[10px]`}),(0,q.jsx)(`input`,{type:`time`,value:o.availability.end,onChange:e=>f({availability:{...o.availability,end:e.target.value}}),className:`h-8 rounded border border-border bg-background px-2 text-[10px]`}),(0,q.jsxs)(`select`,{value:t?`advisory`:o.availability.mode??`enforce`,disabled:t,onChange:e=>f({availability:{...o.availability,mode:e.target.value}}),className:`h-8 rounded border border-border bg-background px-2 text-[10px]`,children:[(0,q.jsx)(`option`,{value:`enforce`,children:a(`activity:runtimePolicy.enforce`)}),(0,q.jsx)(`option`,{value:`advisory`,children:a(`activity:runtimePolicy.advisory`)})]})]})]})]}),(0,q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,q.jsx)(`button`,{type:`button`,disabled:n||!!(l&&l.allowed.length===0),onClick:()=>r(o),className:`rounded bg-primary px-3 py-1.5 text-xs text-primary-foreground disabled:opacity-50`,children:n?`Saving…`:`Save runtime policy`}),(0,q.jsx)(`button`,{type:`button`,onClick:i,className:`rounded border border-border px-3 py-1.5 text-xs hover:bg-accent`,children:a(`activity:runtimePolicy.cancel`)})]})]})}function bt({customStats:e,catalog:t}){let{t:n}=C(),r=(0,K.useCallback)(e=>n(`activity:rosterRoles.${e.role}.name`,{defaultValue:e.name}),[n]),i=(0,K.useCallback)(e=>n(`activity:rosterRoles.${e.role}.summary`,{defaultValue:e.summary}),[n]),[a,o]=(0,K.useState)(``),[s,c]=(0,K.useState)(null),l=(0,K.useMemo)(()=>new Set(e.filter(e=>e.exists||e.hasIdentity||e.hasConfig||e.hasKnowledge).map(e=>e.role)),[e]),u=(0,K.useMemo)(()=>{if(!a.trim())return t;let e=a.toLowerCase();return t.filter(t=>t.role.includes(e)||r(t).toLowerCase().includes(e)||i(t).toLowerCase().includes(e))},[t,a,r,i]),d=(0,K.useCallback)(t=>e.find(e=>e.role===t),[e]),f=u;return(0,q.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden`,children:[(0,q.jsx)(`div`,{className:`shrink-0 px-3 py-2 border-b border-border/50`,children:(0,q.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg border border-border/60 bg-background px-3 py-1.5`,children:[(0,q.jsx)(R,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,q.jsx)(`input`,{type:`text`,value:a,onChange:e=>o(e.target.value),placeholder:n(`activity:agentRoster.searchPlaceholder`),className:`flex-1 bg-transparent text-xs outline-none placeholder:text-muted-foreground/50`}),a&&(0,q.jsx)(`button`,{type:`button`,onClick:()=>o(``),className:`text-muted-foreground hover:text-foreground`,children:(0,q.jsx)(k,{className:`h-3 w-3`})})]})}),(0,q.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-3`,children:[(0,q.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-2`,children:f.map(e=>{let t=d(e.role),a=l.has(e.role),o=s===e.role;return(0,q.jsxs)(`div`,{className:U(`rounded-lg border bg-card transition-colors`,o?`border-primary/40 ring-1 ring-primary/20`:`border-border/60 hover:border-primary/30`),children:[(0,q.jsxs)(`button`,{type:`button`,onClick:()=>c(o?null:e.role),className:`w-full text-left p-3`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,q.jsx)(H,{className:`h-4 w-4 shrink-0 text-primary`}),(0,q.jsx)(`span`,{className:`text-sm font-semibold truncate`,children:r(e)}),(0,q.jsxs)(`code`,{className:`text-[9px] text-muted-foreground font-mono shrink-0`,children:[`@`,e.role]})]}),(0,q.jsx)(A,{className:U(`h-3.5 w-3.5 shrink-0 text-muted-foreground transition-transform`,o&&`rotate-180`)})]}),(0,q.jsx)(`p`,{className:`text-[10px] text-muted-foreground mt-1 leading-relaxed line-clamp-2`,children:i(e)}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2 mt-1.5`,children:[(0,q.jsx)(`span`,{className:`text-[9px] text-muted-foreground tabular-nums`,children:n(`activity:agentRoster.toolsCount`,{count:e.tools})}),e.budget.maxIterations&&(0,q.jsx)(`span`,{className:`text-[9px] text-muted-foreground tabular-nums`,children:n(`activity:agentRoster.maxItShort`,{count:e.budget.maxIterations,value:e.budget.maxIterations.toLocaleString()})}),a&&(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 rounded bg-brand-2/10 px-1 py-0.5 text-[8px] text-brand-2 font-medium`,children:[(0,q.jsx)(ae,{className:`h-2.5 w-2.5`}),` `,n(`activity:agentRoster.customizedBadge`)]}),t?.needsSummarization&&(0,q.jsx)(`span`,{className:`text-[9px] text-warning`,children:n(`activity:agentRoster.needsSummary`)})]})]}),o&&(0,q.jsxs)(`div`,{className:`border-t border-border/50 px-3 py-2 space-y-2`,children:[(0,q.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,q.jsxs)(`div`,{className:`rounded bg-muted/30 p-1.5`,children:[(0,q.jsx)(`span`,{className:`text-[8px] text-muted-foreground uppercase tracking-wider`,children:n(`activity:agentRoster.maxIterations`)}),(0,q.jsx)(`div`,{className:`text-xs font-mono mt-0.5`,children:e.budget.maxIterations?.toLocaleString()??`—`})]}),(0,q.jsxs)(`div`,{className:`rounded bg-muted/30 p-1.5`,children:[(0,q.jsx)(`span`,{className:`text-[8px] text-muted-foreground uppercase tracking-wider`,children:n(`activity:agentRoster.timeout`)}),(0,q.jsx)(`div`,{className:`text-xs font-mono mt-0.5`,children:e.budget.timeoutMs?`${Math.round(e.budget.timeoutMs/6e4)}m`:`—`})]}),(0,q.jsxs)(`div`,{className:`rounded bg-muted/30 p-1.5`,children:[(0,q.jsx)(`span`,{className:`text-[8px] text-muted-foreground uppercase tracking-wider`,children:n(`activity:agentRoster.maxToolCalls`)}),(0,q.jsx)(`div`,{className:`text-xs font-mono mt-0.5`,children:e.budget.maxToolCalls?.toLocaleString()??`—`})]}),(0,q.jsxs)(`div`,{className:`rounded bg-muted/30 p-1.5`,children:[(0,q.jsx)(`span`,{className:`text-[8px] text-muted-foreground uppercase tracking-wider`,children:n(`activity:agentRoster.customizedBadge`)}),(0,q.jsx)(`div`,{className:`text-xs font-mono mt-0.5`,children:n(a?`common:action.yes`:`common:action.no`)})]})]}),a&&t&&(0,q.jsxs)(`div`,{className:`rounded bg-accent/30 p-2 space-y-1`,children:[(0,q.jsx)(`span`,{className:`text-[9px] font-medium text-muted-foreground`,children:n(`activity:agentRoster.projectCustomizations`)}),(0,q.jsxs)(`div`,{className:`flex flex-wrap gap-2 text-[9px]`,children:[t.hasIdentity&&(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-0.5`,children:[(0,q.jsx)(ae,{className:`h-2.5 w-2.5 text-primary`}),` identity.md`]}),t.entryCount>0&&(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-0.5`,children:[(0,q.jsx)(B,{className:`h-2.5 w-2.5 text-brand-2`}),` `,n(`activity:agentRoster.learnedEntriesCount`,{count:t.entryCount})]}),t.hasConfig&&(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-0.5`,children:[(0,q.jsx)(N,{className:`h-2.5 w-2.5 text-muted-foreground`}),` config.json`]}),t.sessionCaptureCount>0&&(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-0.5`,children:[(0,q.jsx)(x,{className:`h-2.5 w-2.5 text-success`}),` `,n(`activity:agentRoster.sessionCapturesCount`,{count:t.sessionCaptureCount})]})]})]})]})]},e.role)})}),f.length===0&&(0,q.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-40 text-muted-foreground`,children:[(0,q.jsx)(R,{className:`h-8 w-8 mb-2 opacity-30`}),(0,q.jsx)(`p`,{className:`text-sm`,children:n(`activity:agentRoster.noAgentsMatch`,{query:a})})]})]}),(0,q.jsxs)(`div`,{className:`shrink-0 border-t border-border/50 px-3 py-2 text-[10px] text-muted-foreground flex items-center gap-2`,children:[(0,q.jsxs)(`span`,{children:[(0,q.jsx)(`strong`,{children:t.length}),` `,n(`activity:agentRoster.footerRosterRoles`,{count:t.length})]}),(0,q.jsx)(`span`,{className:`text-muted-foreground/50`,children:`·`}),(0,q.jsxs)(`span`,{className:`text-brand-2`,children:[(0,q.jsx)(`strong`,{children:l.size}),` `,n(`activity:agentRoster.footerCustomized`,{count:l.size})]}),(0,q.jsx)(`span`,{className:`text-muted-foreground/50`,children:`·`}),(0,q.jsxs)(`span`,{children:[(0,q.jsx)(`strong`,{children:e.reduce((e,t)=>e+t.entryCount,0)}),` `,n(`activity:agentRoster.footerTotalLearned`,{count:e.reduce((e,t)=>e+t.entryCount,0)})]})]})]})}var xt=[{id:`live`,icon:(0,q.jsx)(x,{className:`h-4 w-4`}),labelKey:`activity:agentRoster.tabLive`},{id:`officemap`,icon:(0,q.jsx)(te,{className:`h-4 w-4`}),labelKey:`activity:agentRoster.tabOfficeMap`},{id:`catalog`,icon:(0,q.jsx)(le,{className:`h-4 w-4`}),labelKey:`activity:agentRoster.tabCatalog`},{id:`learning`,icon:(0,q.jsx)(Ce,{className:`h-4 w-4`}),labelKey:`activity:agentRoster.tabLearning`},{id:`memory`,icon:(0,q.jsx)(Oe,{className:`h-4 w-4`}),labelKey:`activity:agentRoster.tabMemory`},{id:`customize`,icon:(0,q.jsx)(N,{className:`h-4 w-4`}),labelKey:`activity:agentRoster.tabCustomize`}],St=[{role:`generic`,name:`Generic Project Agent`,summary:`Flexible template that can be cloned into independently learning project roles.`,tools:0,budget:{maxIterations:2500,maxToolCalls:7500}},{role:`audit-log`,name:`Audit Log`,summary:`Analyzes session logs, event streams, and system traces.`,tools:12,budget:{timeoutMs:108e5,maxIterations:2500,maxToolCalls:7500}},{role:`bug-hunter`,name:`Bug Hunter`,summary:`Scans code for bugs, code smells, and anti-patterns.`,tools:15,budget:{timeoutMs:18e6,maxIterations:4e3,maxToolCalls:1e4}},{role:`refactor-planner`,name:`Refactor Planner`,summary:`Analyzes code structure and produces phased refactoring plans.`,tools:14,budget:{timeoutMs:144e5,maxIterations:3e3,maxToolCalls:9e3}},{role:`security-scanner`,name:`Security Scanner`,summary:`Scans code, configs, and dependencies for security issues.`,tools:18,budget:{timeoutMs:18e6,maxIterations:4e3,maxToolCalls:1e4}},{role:`critic`,name:`Critic`,summary:`Evaluates decisions, plans, and implementations.`,tools:10,budget:{timeoutMs:108e5,maxIterations:2e3,maxToolCalls:5e3}},{role:`shadow-agent`,name:`Shadow Agent`,summary:`Background monitoring agent that watches fleet health.`,tools:8,budget:{timeoutMs:36e6,maxIterations:500,maxToolCalls:2e3}},{role:`executor`,name:`Executor`,summary:`General-purpose task executor for delegated work.`,tools:20,budget:{timeoutMs:72e5,maxIterations:1500,maxToolCalls:4e3}},{role:`chimera`,name:`Chimera`,summary:`Post-session code quality review of changed files.`,tools:10,budget:{timeoutMs:72e5,maxIterations:1e3,maxToolCalls:3e3}},{role:`researcher`,name:`Researcher`,summary:`Web research and data gathering specialist.`,tools:8,budget:{timeoutMs:72e5,maxIterations:1e3,maxToolCalls:3e3}},{role:`tech-stack`,name:`Tech Stack Validator`,summary:`Validates package/library/framework choices.`,tools:9,budget:{timeoutMs:72e5,maxIterations:1e3,maxToolCalls:3e3}},{role:`orchestrator`,name:`Orchestrator`,summary:`Coordinates multi-agent task execution.`,tools:12,budget:{timeoutMs:144e5,maxIterations:3e3,maxToolCalls:8e3}},{role:`supervisor`,name:`Supervisor`,summary:`Oversees subagent execution and handles escalations.`,tools:10,budget:{timeoutMs:144e5,maxIterations:2e3,maxToolCalls:6e3}},{role:`quality-gate`,name:`Quality Gate`,summary:`Enforces quality gates on implementations.`,tools:8,budget:{timeoutMs:72e5,maxIterations:1e3,maxToolCalls:3e3}},{role:`architect`,name:`Architect`,summary:`Makes design and architecture decisions.`,tools:14,budget:{timeoutMs:144e5,maxIterations:3e3,maxToolCalls:8e3}},{role:`prompt-engineer`,name:`Prompt Engineer`,summary:`Designs and optimizes system prompts.`,tools:8,budget:{timeoutMs:72e5,maxIterations:1e3,maxToolCalls:3e3}},{role:`mnemosyne`,name:`Mnemosyne`,summary:`Memory curator — reviews and maintains SAGE integrity.`,tools:6,budget:{timeoutMs:72e5,maxIterations:500,maxToolCalls:2e3}},{role:`autophase`,name:`AutoPhase`,summary:`Manages multi-phase autonomous task execution.`,tools:10,budget:{timeoutMs:144e5,maxIterations:2e3,maxToolCalls:6e3}}];function Ct({customStats:e,rosterLoading:t,onRefresh:n}){let{t:r}=C();return(0,q.jsx)(`div`,{className:`shrink-0 border-b border-border/70 bg-card/80 px-4 py-2.5`,children:(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-2 flex-nowrap min-w-0`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 overflow-hidden`,children:[(0,q.jsx)(`div`,{className:`flex items-center justify-center w-8 h-8 shrink-0 rounded-lg bg-primary/10`,children:(0,q.jsx)(Ae,{className:`h-4 w-4 text-primary`})}),(0,q.jsxs)(`div`,{className:`min-w-0 overflow-hidden`,children:[(0,q.jsx)(`h1`,{className:`text-sm font-semibold truncate`,children:r(`activity:agentRoster.heading`)}),(0,q.jsx)(`p`,{className:`text-[10px] text-muted-foreground truncate`,children:r(`activity:agentRoster.headerSummary`,{customized:e.filter(e=>e.exists||e.hasIdentity||e.hasConfig||e.hasKnowledge).length,entries:e.reduce((e,t)=>e+t.entryCount,0)})})]})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[t&&(0,q.jsx)(j,{className:`h-4 w-4 animate-spin text-muted-foreground shrink-0`}),(0,q.jsxs)(`button`,{type:`button`,onClick:n,className:`inline-flex items-center gap-1 rounded border border-border/50 px-2 py-1 text-[10px] hover:bg-accent transition-colors shrink-0 whitespace-nowrap`,title:r(`activity:agentRoster.refreshRosterData`),children:[(0,q.jsx)(ke,{className:`h-3 w-3`}),` `,r(`common:action.refresh`)]})]})]})})}function wt({activeTab:e,onTabChange:t}){let{t:n}=C();return(0,q.jsx)(`div`,{className:`shrink-0 border-b border-border/50 bg-muted/20 px-3 flex gap-0`,children:xt.map(r=>(0,q.jsxs)(`button`,{type:`button`,onClick:()=>t(r.id),className:U(`flex items-center gap-1.5 px-3 py-2 text-[10px] font-medium border-b-2 transition-colors`,e===r.id?`border-primary text-primary`:`border-transparent text-muted-foreground hover:text-foreground hover:border-muted-foreground/30`),children:[r.icon,n(r.labelKey)]},r.id))})}var Tt={running:{led:`bg-success`,badge:`bg-success/12 text-success`,icon:(0,q.jsx)(`span`,{className:`led text-success led-pulse`}),color:`text-success`},completed:{led:`bg-success`,badge:`bg-success/12 text-success`,icon:(0,q.jsx)(re,{className:`h-3.5 w-3.5`}),color:`text-success`},failed:{led:`bg-destructive`,badge:`bg-destructive/15 text-destructive`,icon:(0,q.jsx)(ge,{className:`h-3.5 w-3.5`}),color:`text-destructive`},timeout:{led:`bg-warning`,badge:`bg-muted text-muted-foreground`,icon:(0,q.jsx)(y,{className:`h-3.5 w-3.5`}),color:`text-warning`},stopped:{led:`bg-muted-foreground`,badge:`bg-muted text-muted-foreground`,icon:(0,q.jsx)(`span`,{className:`led text-muted-foreground`}),color:`text-muted-foreground`},idle:{led:`bg-muted-foreground`,badge:`bg-muted text-muted-foreground`,icon:(0,q.jsx)(`span`,{className:`led text-muted-foreground`}),color:`text-muted-foreground`}},Et=`__no_session__`,Dt=new Map,Ot=new Set;s(e=>{Dt.delete(e),Ot.add(e)});function kt(e){let t=Math.floor(e/1e3);if(t<60)return`${t}s`;let n=Math.floor(t/60);if(n<60)return`${n}m ${t%60}s`;let r=Math.floor(n/60);return r<24?`${r}h ${n%60}m`:`${Math.floor(r/24)}d`}function At(e){if(e==null||!Number.isFinite(e)||e<=0)return`$0`;if(e<.01){let t=e.toFixed(5);return t===`0.00000`?`$0`:`$`+t.replace(/(\d)0+$/,`$1`).replace(/\.$/,``)}return`$`+e.toFixed(3)}function jt({nowTick:e}){let{t}=C(),a=n(e=>e.agents),o=d(),s=r(o??void 0),[c,l]=(0,K.useState)(null),[u,f]=(0,K.useState)(`all`),p=(0,K.useRef)(o??Et);(0,K.useLayoutEffect)(()=>{let e=p.current;Ot.has(e)||Dt.set(e,{selectedId:c,filter:u});let t=o??Et,n=Dt.get(t);Ot.delete(t),l(n?.selectedId??null),f(n?.filter??`all`),p.current=t},[o]);let m=(0,K.useMemo)(()=>Array.from(a.values()).filter(e=>i(e.sessionId,o)),[a,o]),h=(0,K.useMemo)(()=>{let e=[...m];return e.sort((e,t)=>{let n=e.status===`running`?0:1,r=t.status===`running`?0:1;return n===r?t.startedAt-e.startedAt:n-r}),u===`all`?e:u===`running`?e.filter(e=>e.status===`running`):u===`done`?e.filter(e=>e.status===`completed`):u===`failed`?e.filter(e=>e.status===`failed`||e.status===`timeout`):e},[m,u]),g=(0,K.useMemo)(()=>{let e=0,t=0,n=0;for(let r of m)r.status===`running`?e++:r.status===`completed`?t++:(r.status===`failed`||r.status===`timeout`)&&n++;return{running:e,completed:t,failed:n,total:m.length}},[m]),_=n(e=>e.clearFinishedAgents),v=c?h.find(e=>e.id===c):null;(0,K.useLayoutEffect)(()=>{c&&!m.some(e=>e.id===c)&&l(null)},[c,m]);let y=(0,K.useCallback)(e=>{let t=Ye.getState();e?(t.setInspectorFocusedAgentId(e),t.setInspectorTab(`agents`)):t.setInspectorTab(`fleet`),t.setInspectorOpen(!0)},[]);return h.length===0?(0,q.jsx)(`div`,{className:`flex flex-1 items-center justify-center text-muted-foreground`,children:(0,q.jsxs)(`div`,{className:`text-center space-y-3`,children:[(0,q.jsx)(H,{className:`h-10 w-10 mx-auto opacity-30`}),(0,q.jsx)(`p`,{className:`text-sm`,children:t(`activity:agentRoster.noActiveFleetAgents`)}),(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground/70`,children:t(`activity:agentRoster.liveEmpty`)})]})}):(0,q.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 overflow-hidden`,children:[(0,q.jsxs)(`div`,{className:U(`flex flex-col min-h-0 min-w-0 overflow-hidden`,v?`w-80 shrink-0 border-r border-border/50`:`flex-1`),children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0 px-3 py-2 border-b border-border/50`,children:[[`all`,`running`,`done`,`failed`].map(e=>(0,q.jsxs)(`button`,{type:`button`,onClick:()=>f(e),className:U(`rounded px-2 py-0.5 text-[10px] font-medium transition-colors`,u===e?`bg-primary/10 text-primary`:`text-muted-foreground hover:text-foreground hover:bg-muted/50`),children:[e===`all`&&t(`activity:agentRoster.filterAll`,{count:g.total}),e===`running`&&t(`activity:agentRoster.filterRunning`,{count:g.running}),e===`done`&&t(`activity:agentRoster.filterDone`,{count:g.completed}),e===`failed`&&t(`activity:agentRoster.filterFailed`,{count:g.failed})]},e)),(0,q.jsx)(`span`,{className:`flex-1`}),(0,q.jsxs)(`button`,{type:`button`,onClick:()=>et(`agents`),className:`inline-flex items-center gap-0.5 rounded px-1.5 py-0.5 text-[10px] text-muted-foreground hover:text-foreground hover:bg-muted/50 transition-colors`,title:t(`activity:agentRoster.openAgentsPanel`),children:[(0,q.jsx)(H,{className:`h-3 w-3`}),t(`activity:agentRoster.openAgentsPanel`)]}),g.completed+g.failed>0&&(0,q.jsxs)(`button`,{type:`button`,onClick:()=>_(o),className:`inline-flex items-center gap-0.5 rounded px-1.5 py-0.5 text-[10px] text-muted-foreground hover:text-destructive hover:bg-destructive/10 transition-colors`,children:[(0,q.jsx)(pe,{className:`h-2.5 w-2.5`}),` `,t(`activity:agentRoster.clear`)]})]}),(0,q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-2 space-y-1`,children:h.map(e=>(0,q.jsxs)(`button`,{type:`button`,onClick:()=>l(c===e.id?null:e.id),className:U(`w-full text-left rounded-lg border px-3 py-2 transition-colors flex items-center gap-2`,c===e.id?`border-primary/50 bg-primary/[0.06]`:`border-border/60 hover:border-primary/30 hover:bg-primary/[0.03]`),children:[(0,q.jsx)(`span`,{className:U(`led shrink-0`,Tt[e.status]?.led??`bg-muted-foreground`,e.status===`running`&&`led-pulse`)}),(0,q.jsx)(`span`,{className:`text-xs font-semibold min-w-0 truncate max-w-[7rem]`,children:e.name}),e.id===s&&(0,q.jsx)(_e,{className:`h-3 w-3 shrink-0 text-warning`}),e.model&&(0,q.jsx)(`span`,{className:`text-[9px] text-muted-foreground font-mono truncate max-w-[6rem] shrink-0`,children:e.model}),(0,q.jsxs)(`span`,{className:`text-[9px] text-muted-foreground tabular-nums shrink-0`,children:[e.iteration,`it · `,e.toolCalls,`t`]}),e.status===`running`&&(0,q.jsx)(`span`,{className:`text-[9px] text-primary tabular-nums shrink-0 ml-auto`,children:kt(Date.now()-e.startedAt)}),e.status!==`running`&&(0,q.jsx)(`span`,{className:U(`text-[9px] tabular-nums shrink-0 ml-auto`,Tt[e.status]?.color??`text-muted-foreground`),children:e.status}),e.costUsd>0&&(0,q.jsx)(`span`,{className:`text-[9px] text-success tabular-nums font-medium shrink-0`,children:At(e.costUsd)}),e.status===`running`&&e.currentTool&&(0,q.jsxs)(`span`,{className:`text-[9px] text-primary font-mono truncate max-w-[6rem] shrink-0`,children:[`→ `,e.currentTool]})]},e.id))}),(0,q.jsxs)(`div`,{className:`shrink-0 border-t border-border/50 px-3 py-2 flex items-center gap-2 text-[10px] text-muted-foreground`,children:[(0,q.jsx)(`span`,{className:`font-medium tabular-nums`,children:g.total}),` `,t(`activity:agentRoster.agentsTotal`),(0,q.jsx)(`span`,{className:`text-muted-foreground/50`,children:`·`}),(0,q.jsx)(`span`,{className:`text-success tabular-nums`,children:g.running}),` running`,(0,q.jsx)(`span`,{className:`text-muted-foreground/50`,children:`·`}),(0,q.jsx)(`span`,{className:`tabular-nums`,children:g.completed}),` done`,g.failed>0&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`span`,{className:`text-muted-foreground/50`,children:`·`}),(0,q.jsx)(`span`,{className:`text-destructive tabular-nums`,children:g.failed}),` failed`]}),(0,q.jsx)(`span`,{className:`flex-1`}),(0,q.jsxs)(`button`,{type:`button`,onClick:()=>y(),className:`inline-flex items-center gap-1 rounded border border-border/50 px-2 py-1 hover:bg-accent transition-colors`,children:[(0,q.jsx)(Ee,{className:`h-3 w-3`}),t(`activity:agentRoster.fleetInspector`)]})]})]}),v&&(0,q.jsx)(`div`,{className:`flex-1 min-h-0 min-w-0 overflow-y-auto p-4`,children:(0,q.jsx)(Mt,{agent:v,nowTick:e})})]})}function Mt({agent:e,nowTick:t}){let{t:n}=C(),i=e.status===`running`?kt(t-e.startedAt):e.completedAt?kt(e.completedAt-e.startedAt):`-`,a=Math.min(100,Math.max(0,e.ctxPct)),o=e.currentTool||e.lastTool,s=r(e.sessionId);return(0,q.jsxs)(`div`,{className:`space-y-4`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,q.jsx)(`div`,{className:`flex items-center justify-center w-10 h-10 rounded-lg bg-primary/10`,children:(0,q.jsx)(H,{className:`h-5 w-5 text-primary`})}),(0,q.jsxs)(`div`,{children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(`span`,{className:`text-base font-semibold`,children:e.name}),e.id===s&&(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded border border-warning/30 bg-warning/10 px-1.5 py-0.5 text-[9px] font-medium text-warning`,children:[(0,q.jsx)(_e,{className:`h-2.5 w-2.5`}),` `,n(`activity:agentRoster.leader`)]})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] text-muted-foreground`,children:[(0,q.jsx)(`span`,{className:U(`led`,Tt[e.status]?.led,e.status===`running`&&`led-pulse`)}),(0,q.jsx)(`span`,{children:e.status}),e.model&&(0,q.jsxs)(`span`,{children:[`· `,e.provider,`/`,e.model]}),(0,q.jsxs)(`span`,{children:[`· `,i]})]})]})]}),(0,q.jsxs)(`div`,{className:`grid grid-cols-4 gap-2`,children:[(0,q.jsxs)(`div`,{className:`rounded-lg border bg-card p-2`,children:[(0,q.jsx)(`span`,{className:`text-[9px] text-muted-foreground uppercase tracking-wider`,children:n(`activity:agentRoster.iterations`)}),(0,q.jsx)(`div`,{className:`text-lg font-mono font-semibold mt-0.5`,children:e.iteration})]}),(0,q.jsxs)(`div`,{className:`rounded-lg border bg-card p-2`,children:[(0,q.jsx)(`span`,{className:`text-[9px] text-muted-foreground uppercase tracking-wider`,children:n(`activity:agentRoster.toolCalls`)}),(0,q.jsx)(`div`,{className:`text-lg font-mono font-semibold mt-0.5`,children:e.toolCalls})]}),(0,q.jsxs)(`div`,{className:`rounded-lg border bg-card p-2`,children:[(0,q.jsx)(`span`,{className:`text-[9px] text-muted-foreground uppercase tracking-wider`,children:n(`activity:agentRoster.cost`)}),(0,q.jsx)(`div`,{className:`text-lg font-mono font-semibold mt-0.5 text-success`,children:At(e.costUsd)})]}),(0,q.jsxs)(`div`,{className:`rounded-lg border bg-card p-2`,children:[(0,q.jsx)(`span`,{className:`text-[9px] text-muted-foreground uppercase tracking-wider`,children:n(`activity:agentRoster.context`)}),(0,q.jsxs)(`div`,{className:`text-lg font-mono font-semibold mt-0.5`,children:[a,`%`]})]})]}),e.maxContext>0&&(0,q.jsxs)(`div`,{className:`space-y-1`,children:[(0,q.jsxs)(`div`,{className:`flex justify-between text-[10px]`,children:[(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:n(`activity:agentRoster.contextWindow`)}),(0,q.jsxs)(`span`,{className:U(`tabular font-medium`,a>=85?`text-destructive`:a>=70?`text-warning`:`text-success`),children:[e.ctxTokens.toLocaleString(),` / `,e.maxContext.toLocaleString(),` tokens`]})]}),(0,q.jsx)(`div`,{className:`h-2 w-full overflow-hidden rounded-full bg-muted`,children:(0,q.jsx)(`div`,{className:U(`h-full rounded-full transition-all`,a>=85?`bg-destructive`:a>=70?`bg-warning`:`bg-primary`),style:{width:`${Math.max(2,a)}%`}})})]}),o&&(0,q.jsxs)(`div`,{className:U(`flex items-center gap-2 rounded-lg border px-3 py-2`,e.status===`running`?`border-primary/30 bg-primary/[0.04]`:`border-border bg-muted/30`),children:[(0,q.jsx)(we,{className:U(`h-4 w-4`,e.status===`running`?`text-primary animate-pulse`:`text-muted-foreground`)}),(0,q.jsx)(`span`,{className:`text-sm font-mono`,children:e.currentTool??e.lastTool}),(0,q.jsx)(`span`,{className:`text-[10px] text-muted-foreground ml-auto`,children:e.currentTool?n(`activity:agentRoster.running`):`Last tool`})]}),e.error&&(0,q.jsxs)(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 p-3`,children:[(0,q.jsx)(`span`,{className:`text-[10px] font-semibold text-destructive uppercase tracking-wider`,children:n(`activity:agentRoster.error`)}),(0,q.jsx)(`p`,{className:`text-xs text-destructive/90 mt-1`,children:e.error.message})]}),e.toolLog.length>0&&(0,q.jsxs)(`div`,{className:`space-y-1`,children:[(0,q.jsxs)(`span`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wider`,children:[`Tool Log (`,e.toolLog.length,`)`]}),(0,q.jsx)(`div`,{className:`space-y-0.5`,children:e.toolLog.slice(0,10).map((e,t)=>(0,q.jsxs)(`div`,{className:U(`flex items-center gap-2 rounded px-2 py-1 text-[10px] font-mono`,e.ok?`bg-muted/30`:`bg-destructive/5 border border-destructive/20`),children:[(0,q.jsx)(`span`,{className:U(`led shrink-0`,e.ok?`text-success`:`text-destructive`)}),(0,q.jsx)(`span`,{className:`truncate flex-1`,children:e.name}),(0,q.jsxs)(`span`,{className:`tabular text-muted-foreground`,children:[e.durationMs,`ms`]}),!e.ok&&(0,q.jsx)(`span`,{className:`text-destructive`,children:`✗`})]},`${e.name}-${t}`))})]}),e.budgetWarning&&(0,q.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg bg-warning/10 border border-warning/25 text-xs`,children:[(0,q.jsx)(T,{className:`h-3.5 w-3.5 text-warning shrink-0`}),(0,q.jsxs)(`span`,{className:`text-warning`,children:[`Budget: `,e.budgetWarning.kind,` limit (`,e.budgetWarning.used,`/`,e.budgetWarning.limit,`)`]})]})]})}function Nt({populated:e,selectedRole:t,onSelectRole:n,onBulkOptimize:r,bulkOptimizing:i}){let{t:a}=C(),o=e.filter(e=>e.needsSummarization);return(0,q.jsxs)(`div`,{className:U(`flex flex-col min-h-0 min-w-0 overflow-hidden border-r border-border/50`,t?`w-80 shrink-0`:`flex-1`),children:[(0,q.jsxs)(`div`,{className:`shrink-0 px-3 py-2 border-b border-border/50`,children:[(0,q.jsxs)(`h3`,{className:`text-xs font-semibold flex items-center gap-1.5`,children:[(0,q.jsx)(B,{className:`h-3.5 w-3.5 text-brand-2`}),a(`activity:agentRoster.allRosterAgents`)]}),o.length>0&&(0,q.jsxs)(`div`,{className:`mt-2 flex flex-col gap-1.5 rounded border border-warning/40 bg-warning/10 px-2 py-1.5`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(T,{className:`h-3 w-3 text-warning shrink-0`}),(0,q.jsxs)(`span`,{className:`text-[10px] text-warning leading-tight`,children:[o.length,` agent`,o.length>1?`s`:``,` need`,o.length===1?`s`:``,` optimization`]}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>{let e=o[0];e&&n(e.role)},className:`ml-auto text-[9px] text-warning underline hover:text-warning/80 shrink-0`,children:a(`activity:agentRoster.review`)})]}),(0,q.jsxs)(`button`,{type:`button`,onClick:()=>r(o.map(e=>e.role)),disabled:i,className:`flex items-center justify-center gap-1 rounded bg-warning/20 border border-warning/40 px-2 py-1 text-[10px] font-medium text-warning hover:bg-warning/30 transition-colors disabled:opacity-50`,children:[i?(0,q.jsx)(j,{className:`h-3 w-3 animate-spin`}):(0,q.jsx)(T,{className:`h-3 w-3`}),i?a(`activity:agentRoster.optimizing`):a(`activity:agentRoster.optimizeAll`,{count:o.length})]})]})]}),(0,q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-2 space-y-1`,children:e.map(e=>(0,q.jsxs)(`button`,{type:`button`,onClick:()=>n(e.role),className:U(`w-full text-left rounded-lg border px-3 py-2 transition-colors`,t===e.role?`border-primary/50 bg-primary/[0.06]`:`border-border/60 hover:border-primary/30`,e.needsSummarization&&t!==e.role&&`border-warning/40`),children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsx)(`span`,{className:`text-xs font-semibold`,children:e.role}),(0,q.jsx)(`span`,{className:U(`text-[9px] tabular-nums`,e.learningEnabled?`text-success`:`text-muted-foreground`),children:e.learningEnabled?a(`activity:agentRoster.learning`):a(`activity:agentRoster.paused`)})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2 mt-1 text-[9px] text-muted-foreground`,children:[(0,q.jsxs)(`span`,{className:`tabular-nums`,children:[e.entryCount,` entries`]}),e.sessionCaptureCount>0&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`span`,{className:`text-muted-foreground/50`,children:`·`}),(0,q.jsxs)(`span`,{className:`text-success tabular-nums`,children:[`+`,e.sessionCaptureCount]})]}),typeof e.directiveHitRate==`number`&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`span`,{className:`text-muted-foreground/50`,children:`·`}),(0,q.jsxs)(`span`,{className:U(`tabular-nums`,e.directiveHitRate>=.7?`text-success`:e.directiveHitRate<.4&&`text-warning`),title:`Share of directive applications that ended in a successful task`,children:[Math.round(e.directiveHitRate*100),`%`]})]}),e.lastCapture&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`span`,{className:`text-muted-foreground/50`,children:`·`}),(0,q.jsx)(`span`,{children:new Date(e.lastCapture).toLocaleDateString()})]}),e.needsSummarization&&(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 text-warning font-medium`,children:[(0,q.jsx)(T,{className:`h-2.5 w-2.5`}),`optimize`]})]})]},e.role))})]})}var Pt={size:`buffer reached the size threshold`,"pending-skills":`directives are waiting to reach their skill`,disabled:`auto-optimization is off`,"learning-paused":`learning is paused for this agent`,"too-few-entries":`not enough directives yet`,"below-threshold":`below the threshold`,"cooling-down":`recently optimized — cooling down`};function Ft({selectedRole:e,selectedStats:t,saving:n,setLearningEnabled:r,optimizing:i,runOptimize:a,autoStatus:o,consolidatedContent:s,loadConsolidated:c,setConsolidatedContent:l,skills:u,toggleSkillBody:d,toggleSkillPin:f,openSkill:p,retired:m,showRetired:h,setShowRetired:g,loadEntries:_,loadingEntries:v,reviewEntries:y,reviewDecisions:b,setReviewEntries:x,setReviewDecisions:w,applyReview:E,teachInput:D,setTeachInput:O,runTeach:k,teachFeedback:A}){let{t:M}=C();return(0,q.jsxs)(`div`,{className:`space-y-4`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsx)(`h3`,{className:`text-base font-semibold`,children:e}),(0,q.jsx)(`div`,{className:`flex gap-1`,children:(0,q.jsxs)(`button`,{type:`button`,onClick:()=>r(e,!t.learningEnabled),disabled:n,className:U(`inline-flex items-center gap-1 rounded border px-2 py-1 text-[10px] transition-colors disabled:opacity-50`,t.learningEnabled?`border-success/40 text-success hover:bg-success/10`:`border-border/50 text-muted-foreground hover:bg-accent`),children:[(0,q.jsx)(B,{className:`h-3 w-3`}),` `,t.learningEnabled?M(`activity:agentRoster.learningOn`):M(`activity:agentRoster.learningPaused`)]})})]}),(0,q.jsxs)(`div`,{className:`grid grid-cols-3 gap-2`,children:[(0,q.jsxs)(`div`,{className:`rounded-lg border bg-card p-2`,children:[(0,q.jsx)(`span`,{className:`text-[9px] text-muted-foreground uppercase tracking-wider`,children:M(`activity:agentRoster.entries`)}),(0,q.jsx)(`div`,{className:`text-lg font-mono font-semibold mt-0.5`,children:t.entryCount})]}),(0,q.jsxs)(`div`,{className:`rounded-lg border bg-card p-2`,children:[(0,q.jsx)(`span`,{className:`text-[9px] text-muted-foreground uppercase tracking-wider`,children:M(`activity:agentRoster.size`)}),(0,q.jsxs)(`div`,{className:`text-lg font-mono font-semibold mt-0.5`,children:[t.totalBytes,`B`]})]}),(0,q.jsxs)(`div`,{className:`rounded-lg border bg-card p-2`,children:[(0,q.jsx)(`span`,{className:`text-[9px] text-muted-foreground uppercase tracking-wider`,children:M(`activity:agentRoster.lifetimeCaptures`)}),(0,q.jsx)(`div`,{className:`text-lg font-mono font-semibold mt-0.5`,children:t.lifetimeCaptureCount})]}),(0,q.jsxs)(`div`,{className:`rounded-lg border bg-card p-2`,children:[(0,q.jsx)(`span`,{className:`text-[9px] text-muted-foreground uppercase tracking-wider`,children:M(`activity:agentRoster.lastCapture`)}),(0,q.jsx)(`div`,{className:`text-lg font-mono font-semibold mt-0.5`,children:t.lastCapture?new Date(t.lastCapture).toLocaleDateString():`—`})]}),(0,q.jsxs)(`div`,{className:`rounded-lg border bg-card p-2`,title:`Share of directive applications that ended in a successful task. Blank until a directive has actually been exercised on one.`,children:[(0,q.jsx)(`span`,{className:`text-[9px] text-muted-foreground uppercase tracking-wider`,children:M(`activity:agentRoster.hitRate`)}),(0,q.jsxs)(`div`,{className:U(`text-lg font-mono font-semibold mt-0.5`,typeof t.directiveHitRate==`number`&&(t.directiveHitRate>=.7?`text-success`:t.directiveHitRate<.4&&`text-warning`)),children:[typeof t.directiveHitRate==`number`?`${Math.round(t.directiveHitRate*100)}%`:`—`,typeof t.appliedEntryCount==`number`&&t.appliedEntryCount>0&&(0,q.jsxs)(`span`,{className:`text-[9px] text-muted-foreground font-sans ml-1`,children:[`of `,t.appliedEntryCount]})]})]}),(0,q.jsxs)(`div`,{className:`rounded-lg border bg-card p-2`,title:`Directives that have never been exercised on a task. Anchors — exact commands, paths, package names — are what let the runtime tell that a directive was applied.`,children:[(0,q.jsx)(`span`,{className:`text-[9px] text-muted-foreground uppercase tracking-wider`,children:M(`activity:agentRoster.neverUsed`)}),(0,q.jsx)(`div`,{className:`text-lg font-mono font-semibold mt-0.5`,children:typeof t.deadEntryCount==`number`?t.deadEntryCount:`—`})]})]}),t.needsSummarization&&(0,q.jsxs)(`div`,{className:`flex items-center gap-3 text-xs text-warning bg-warning/10 rounded-lg px-3 py-2.5`,children:[(0,q.jsx)(ye,{className:`h-4 w-4 shrink-0`}),(0,q.jsx)(`span`,{className:`flex-1`,children:M(`activity:agentRoster.learningsLimitExceeded`,{bytes:t.totalBytes.toLocaleString()})}),(0,q.jsxs)(`button`,{type:`button`,onClick:()=>a(e),disabled:i,className:`inline-flex items-center gap-1 rounded bg-warning/20 text-warning border border-warning/40 px-2.5 py-1 text-[10px] font-medium hover:bg-warning/30 transition-colors disabled:opacity-50 shrink-0`,children:[i?(0,q.jsx)(j,{className:`h-3 w-3 animate-spin`}):(0,q.jsx)(T,{className:`h-3 w-3`}),i?M(`activity:agentRoster.optimizing`):`Optimize Now`]})]}),(0,q.jsxs)(`div`,{className:`space-y-2 border border-border rounded-lg p-3 bg-card`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,q.jsx)(S,{className:`h-4 w-4 text-primary`}),(0,q.jsx)(`span`,{className:`text-xs font-semibold`,children:M(`activity:agentRoster.optimizeLearnings`)})]}),(0,q.jsxs)(`button`,{type:`button`,onClick:()=>a(e),disabled:i||t.entryCount===0,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs text-primary-foreground hover:bg-primary/90 transition-colors disabled:opacity-50`,title:t.entryCount===0?`No raw entries to optimize`:`Synthesize raw entries into a consolidated, narrowly-scoped document`,children:[i?(0,q.jsx)(j,{className:`h-3.5 w-3.5 animate-spin`}):(0,q.jsx)(T,{className:`h-3.5 w-3.5`}),i?M(`activity:agentRoster.optimizing`):`Optimize`]})]}),o&&(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px]`,children:[(0,q.jsx)(`span`,{className:U(`inline-block h-1.5 w-1.5 rounded-full`,o.enabled?o.eligible?`bg-warning`:`bg-success`:`bg-muted-foreground`)}),(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:o.enabled?o.eligible?`Queued automatically: ${Pt[o.reason]??o.reason}.`:`Automatic — ${Pt[o.reason]??o.reason}.`:`Automatic optimization is off — run it manually.`})]}),(0,q.jsxs)(`p`,{className:`text-[10px] text-muted-foreground leading-relaxed`,children:[`Synthesizes all `,t.entryCount,` raw entries into a single reviewed document — narrowly scoped to this agent's skills, preserving every fact but reducing context volume. The result replaces raw entries in the agent's prompt.`]}),t.isConsolidated&&t.consolidation&&(0,q.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] text-muted-foreground pt-1 border-t border-border/50`,children:[(0,q.jsx)(re,{className:`h-3 w-3 text-success`}),(0,q.jsxs)(`span`,{children:[`Consolidated`,` `,new Date(t.consolidation.consolidatedAt).toLocaleDateString(),` ·`,` `,t.consolidation.sourceBytes,`B →`,` `,t.consolidation.consolidatedBytes,`B`,t.consolidation.sourceEntryCount<t.entryCount&&(0,q.jsxs)(`span`,{className:`text-warning ml-1`,children:[`· `,t.entryCount-t.consolidation.sourceEntryCount,` `,M(`activity:agentRoster.newPending`)]})]}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>{s===null?c(e):l(null)},className:`ml-auto underline text-primary hover:text-primary/80`,children:s===null?M(`activity:agentRoster.viewAction`):`Hide`})]}),s!==null&&(0,q.jsxs)(`div`,{className:`mt-2 max-h-72 overflow-y-auto rounded border border-border/50 bg-background/50 p-2`,children:[(0,q.jsxs)(`div`,{className:`text-[10px] text-muted-foreground mb-1 font-medium`,children:[`Consolidated knowledge for `,e]}),(0,q.jsx)(`pre`,{className:`text-[10px] whitespace-pre-wrap font-sans leading-relaxed`,children:s||`(empty)`})]})]}),u&&u.length>0&&(0,q.jsxs)(`div`,{className:`space-y-2 border border-border rounded-lg p-3 bg-card`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,q.jsx)(Ce,{className:`h-4 w-4 text-brand-2`}),(0,q.jsx)(`span`,{className:`text-xs font-semibold`,children:`Skills`}),(0,q.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[u.filter(e=>e.developed).length,` of `,u.length,` developed for this project`]})]}),(0,q.jsxs)(`p`,{className:`text-[10px] text-muted-foreground leading-relaxed`,children:[`A developed skill carries a project addendum injected right after the bundled skill body — the agent reads one skill, refined for this codebase. Only the highest-ranked few are loaded per spawn; `,(0,q.jsx)(`span`,{className:`text-primary`,children:`loaded`}),` marks those.`]}),(0,q.jsx)(`div`,{className:`space-y-1`,children:u.map(t=>(0,q.jsxs)(`div`,{className:`rounded border border-border/60`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5`,children:[(0,q.jsx)(`button`,{type:`button`,onClick:()=>d(e,t.skill),disabled:!t.developed,className:U(`text-[11px] font-mono text-left flex-1 truncate`,t.developed?`text-primary hover:underline`:`text-muted-foreground cursor-default`),children:t.skill}),t.eager&&(0,q.jsx)(`span`,{className:`text-[9px] rounded bg-primary/15 text-primary px-1.5 py-0.5`,title:`Ranked high enough to be loaded into a spawn of this role`,children:`loaded`}),t.developed&&(0,q.jsx)(`span`,{className:`text-[9px] rounded bg-success/15 text-success px-1.5 py-0.5`,children:`developed`}),t.affinity&&(0,q.jsxs)(`span`,{className:`text-[9px] text-muted-foreground tabular-nums`,children:[t.affinity.learned>0&&`${t.affinity.learned} learned · `,t.affinity.succeeded,`✓/`,t.affinity.failed,`✗`]}),typeof t.score==`number`&&(0,q.jsx)(`span`,{className:`text-[9px] text-muted-foreground tabular-nums`,title:`Project affinity score — higher is loaded first`,children:t.score.toFixed(2)}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>f(e,t.skill,!t.affinity?.pinned),className:U(`text-[9px] rounded border px-1.5 py-0.5 transition-colors`,t.affinity?.pinned?`border-primary/50 text-primary`:`border-border/50 text-muted-foreground hover:bg-accent`),children:t.affinity?.pinned?`pinned`:`pin`})]}),p?.skill===t.skill&&(0,q.jsx)(`div`,{className:`max-h-60 overflow-y-auto border-t border-border/50 bg-background/50 p-2`,children:(0,q.jsx)(`pre`,{className:`text-[10px] whitespace-pre-wrap font-sans leading-relaxed`,children:p.content||`(empty)`})})]},t.skill))})]}),m&&m.length>0&&(0,q.jsxs)(`div`,{className:`space-y-2 border border-border rounded-lg p-3 bg-card`,children:[(0,q.jsxs)(`button`,{type:`button`,onClick:()=>g(e=>!e),className:`flex w-full items-center gap-1.5 text-left`,children:[(0,q.jsx)(ye,{className:`h-4 w-4 text-warning`}),(0,q.jsx)(`span`,{className:`text-xs font-semibold`,children:`Retired`}),(0,q.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[m.length,` directive`,m.length===1?``:`s`,` no longer injected`]}),(0,q.jsx)(`span`,{className:`ml-auto text-[10px] text-muted-foreground`,children:h?`hide`:`show`})]}),h&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`p`,{className:`text-[10px] text-muted-foreground leading-relaxed`,children:`Each of these was exercised repeatedly and kept correlating with failed tasks, so it was removed from the buffer and scrubbed out of the distilled documents.`}),(0,q.jsx)(`ul`,{className:`space-y-1`,children:m.map(e=>(0,q.jsxs)(`li`,{className:`rounded border border-border/60 px-2 py-1.5 text-[10px] leading-relaxed`,children:[e.skill&&(0,q.jsx)(`span`,{className:`mr-1.5 rounded bg-muted px-1 py-0.5 font-mono text-[9px] text-muted-foreground`,children:e.skill}),(0,q.jsx)(`span`,{className:`text-muted-foreground line-through`,children:e.what})]},e.what))})]})]}),t.entryCount>0&&(0,q.jsxs)(`div`,{className:`space-y-2`,children:[(0,q.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,q.jsxs)(`button`,{type:`button`,onClick:()=>_(e),disabled:v,className:`inline-flex items-center gap-1 rounded border border-border/50 px-3 py-1.5 text-xs hover:bg-accent transition-colors`,children:[v?(0,q.jsx)(j,{className:`h-3 w-3 animate-spin`}):(0,q.jsx)(le,{className:`h-3 w-3`}),`Review Learned Entries (`,t.entryCount,`)`]})}),y&&(0,q.jsxs)(`div`,{className:`space-y-2 border border-border rounded-lg p-3 bg-card`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsxs)(`span`,{className:`text-xs font-medium`,children:[y.filter((e,t)=>b[t]!==`drop`).length,`/`,y.length,` kept`]}),(0,q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,q.jsx)(`button`,{type:`button`,onClick:E,disabled:n,className:`inline-flex items-center gap-1 rounded bg-primary px-2 py-1 text-[10px] text-primary-foreground hover:bg-primary/90 transition-colors`,children:n?M(`activity:agentRoster.applying`):`Apply Selection`}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>{x(null),w({})},className:`inline-flex items-center gap-1 rounded border border-border/50 px-2 py-1 text-[10px] hover:bg-accent transition-colors`,children:M(`activity:agentRoster.cancel`)})]})]}),(0,q.jsx)(`div`,{className:`max-h-72 overflow-y-auto space-y-2`,children:y.map((e,t)=>{let n=b[t]??`keep`,r=e.length>200?e.slice(0,200)+`…`:e;return(0,q.jsx)(`div`,{className:U(`rounded-lg border p-2 transition-colors`,n===`drop`?`border-destructive/40 bg-destructive/5 opacity-60`:`border-border`),children:(0,q.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,q.jsx)(`pre`,{className:`text-[10px] whitespace-pre-wrap flex-1 leading-relaxed font-sans`,children:r}),(0,q.jsxs)(`div`,{className:`flex gap-1 shrink-0`,children:[(0,q.jsx)(`button`,{type:`button`,onClick:()=>w(e=>({...e,[t]:`keep`})),className:U(`px-2 py-1 text-[9px] rounded`,n===`keep`?`bg-success/20 text-success`:`bg-muted text-muted-foreground`),children:M(`activity:agentRoster.keep`)}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>w(e=>({...e,[t]:`drop`})),className:U(`px-2 py-1 text-[9px] rounded`,n===`drop`?`bg-destructive/20 text-destructive`:`bg-muted text-muted-foreground`),children:M(`activity:agentRoster.drop`)})]})]})},t)})})]})]}),(0,q.jsxs)(`div`,{className:`space-y-2 pt-4 border-t border-border`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1 text-sm font-medium`,children:[(0,q.jsx)(Ce,{className:`h-4 w-4 text-brand-2`}),` `,M(`activity:agentRoster.teachThisAgent`)]}),(0,q.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:M(`activity:agentRoster.describeACommandPatternOrBehavior`)}),(0,q.jsx)(`textarea`,{className:`w-full h-20 text-xs p-2 bg-card border border-border rounded resize-y`,value:D,onChange:e=>O(e.target.value),placeholder:M(`activity:agentRoster.eGAlwaysUsePnpmForThisProject`)}),(0,q.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,q.jsxs)(`button`,{type:`button`,onClick:k,disabled:!D.trim()||n,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs text-primary-foreground hover:bg-primary/90 transition-colors disabled:opacity-50`,children:[(0,q.jsx)(Ce,{className:`h-3.5 w-3.5`}),` `,M(`activity:agentRoster.teach`)]}),A&&(0,q.jsx)(`span`,{className:U(`text-xs`,A.ok?`text-success`:`text-destructive`),children:A.msg})]})]})]})}function It({customStats:e,onRefresh:t}){let{t:n}=C(),[r,i]=(0,K.useState)(null),[a,o]=(0,K.useState)(null),[s,u]=(0,K.useState)({}),[d,f]=(0,K.useState)(``),[p,m]=(0,K.useState)(null),[h,g]=(0,K.useState)(!1),[_,v]=(0,K.useState)(!1),[y,b]=(0,K.useState)(null),[x,S]=(0,K.useState)(!1),[w,T]=(0,K.useState)(!1),[E,D]=(0,K.useState)(null),[O,k]=(0,K.useState)(null),[A,j]=(0,K.useState)(!1),[M,N]=(0,K.useState)(null),[ee,P]=(0,K.useState)(null),F=(0,K.useMemo)(()=>[...e].sort((e,t)=>e.role.localeCompare(t.role)),[e]),te=(0,K.useMemo)(()=>r?F.find(e=>e.role===r):null,[r,F]),ne=(0,K.useCallback)(async e=>{v(!0),o(null);try{let t=await G(`agent-roster.read-learned`,{role:e});o(t.entries??[]),u({})}catch{}v(!1)},[]),re=(0,K.useCallback)(async()=>{if(!r||!a)return;g(!0);let e=a.filter((e,t)=>s[t]!==`drop`).join(`
2
+
3
+ ---
4
+
5
+ `);try{await G(`agent-roster.update-learned`,{role:r,content:e}),o(null),u({})}catch{}g(!1)},[r,a,s]),ie=(0,K.useCallback)(async()=>{if(!(!r||!d.trim())){m(null),g(!0);try{let e=`> Taught ${new Date().toISOString().slice(0,10)}\n\n${d.trim()}`;(await G(`agent-roster.append-learned`,{role:r,content:e})).success?(m({ok:!0,msg:n(`activity:customRoster.behaviorSaved`)}),f(``),t()):m({ok:!1,msg:n(`activity:agentRoster.saveFailed`)})}catch(e){m({ok:!1,msg:e instanceof Error?e.message:n(`activity:agentRoster.failed`)})}g(!1)}},[t,r,d,n]),ae=(0,K.useCallback)(async(e,r)=>{g(!0),m(null);try{let i=await G(`agent-roster.update-learning`,{role:e,enabled:r});if(i.error)throw Error(i.error);m({ok:!0,msg:n(r?`activity:agentRoster.learningResumed`:`activity:agentRoster.autoLearningPaused`)}),t()}catch(e){m({ok:!1,msg:e instanceof Error?e.message:n(`activity:agentRoster.policyUpdateFailed`)})}finally{g(!1)}},[t,n]),I=(0,K.useCallback)(async e=>{try{let t=await G(`agent-roster.auto-optimize-status`,{role:e}),n=t.roles?.find(t=>t.role===e);N(n?{enabled:t.policy?.enabled!==!1,eligible:n.eligible,reason:n.reason}:null)}catch{N(null)}},[]),oe=(0,K.useCallback)(async e=>{try{let t=await G(`agent-roster.skills`,{role:e});D(t.skills??[])}catch{D([])}},[]),L=(0,K.useCallback)(async e=>{try{let t=await G(`agent-roster.quarantine`,{role:e});k(t.retired??[])}catch{k([])}},[]),R=(0,K.useCallback)(async(e,t)=>{if(ee?.skill===t){P(null);return}try{let n=await G(`agent-roster.read-skill`,{role:e,skill:t});P({skill:t,content:n.content??``})}catch{P({skill:t,content:``})}},[ee]),se=(0,K.useCallback)(async(e,t,n)=>{try{await G(`agent-roster.pin-skill`,{role:e,skill:t,pinned:n}),await oe(e)}catch{}},[oe]),ce=(0,K.useCallback)(async e=>{try{let t=await G(`agent-roster.read-consolidated`,{role:e});b(t.isConsolidated?t.content:null)}catch{b(null)}},[]);return{selectedRole:r,reviewEntries:a,setReviewEntries:o,reviewDecisions:s,setReviewDecisions:u,teachInput:d,setTeachInput:f,teachFeedback:p,saving:h,loadingEntries:_,consolidatedContent:y,setConsolidatedContent:b,optimizing:x,bulkOptimizing:w,skills:E,retired:O,showRetired:A,setShowRetired:j,autoStatus:M,openSkill:ee,populated:F,selectedStats:te,loadEntries:ne,applyReview:re,runTeach:ie,setLearningEnabled:ae,toggleSkillBody:R,toggleSkillPin:se,loadConsolidated:ce,runOptimize:(0,K.useCallback)(async e=>{S(!0),m(null);try{let r=await G(`agent-roster.consolidate`,{role:e});if(r.error)throw Error(r.error);if(r.rawEntryCount===0){m({ok:!1,msg:n(`activity:agentRoster.noRawEntries`)});return}if(r.consolidated){await t(),await ce(e),await oe(e),await I(e),await L(e),m({ok:!0,msg:n(`activity:agentRoster.optimizedOk`)}),c.success(r.model?n(`activity:agentRoster.consolidatedWithModel`,{model:r.model}):n(`activity:agentRoster.consolidatedPlain`));return}if(r.emptySynthesis){m({ok:!1,msg:n(`activity:agentRoster.emptySynthesis`)}),c.error(n(`activity:agentRoster.optimizationEmptyToast`));return}let i=r.instruction;if(!i)throw Error(`No consolidation instruction generated`);let a=Xe.getState();a.addMessage({role:`user`,content:i}),a.setLoading(!0),l().sendMessage(i);let o=Ye.getState();o.setSidebarOpen(!1),o.setCurrentView(`chat`),m({ok:!0,msg:n(`activity:agentRoster.noActiveModelMsg`)}),c.info(n(`activity:agentRoster.noActiveModelToast`))}catch(e){m({ok:!1,msg:e instanceof Error?e.message:n(`activity:agentRoster.optimizationFailed`)}),c.error(e instanceof Error?e.message:n(`activity:agentRoster.optimizationFailed`))}finally{S(!1)}},[t,ce,oe,I,L,n]),runBulkOptimize:(0,K.useCallback)(async e=>{if(e.length!==0){T(!0),m(null);try{let t=[],n=0,i=0,a=``,o=[];for(let r of e)try{let e=await G(`agent-roster.consolidate`,{role:r});e.error?(i++,a=e.error):e.consolidated?t.push(r):e.rawEntryCount===0?n++:e.emptySynthesis?(i++,a=`Model returned an empty result`):e.instruction?o.push({role:r,instruction:e.instruction}):(i++,a=`No consolidation produced`)}catch(e){i++,a=e instanceof Error?e.message:String(e)}if(r&&t.includes(r)&&await ce(r),o.length>0){let e=`Optimize the learned data for ${o.length} agent${o.length>1?`s`:``}. For each agent below, read its raw learned entries, synthesize them into a single narrowly-scoped document preserving every fact, and save the result to its consolidated.md file.\n\n`+o.map(e=>`## Agent: ${e.role}\n\n${e.instruction}`).join(`
6
+
7
+ ---
8
+
9
+ `),t=Xe.getState();t.addMessage({role:`user`,content:e}),t.setLoading(!0),l().sendMessage(e);let n=Ye.getState();n.setSidebarOpen(!1),n.setCurrentView(`chat`)}if(t.length===0&&o.length===0){if(i>0){let t=n>0?` ${n} skipped.`:``,r=`Bulk consolidate failed for ${i} of ${e.length} agent${e.length>1?`s`:``}.${a?` Last error: ${a}`:``}${t}`;m({ok:!1,msg:r});return}let t=n>0?`Bulk optimize: ${n} skipped (no entries to optimize).`:`No agents had optimizable entries.`;m({ok:!0,msg:t}),c.info(t,6e3);return}let s=[];t.length>0&&s.push(`${t.length} consolidated`),o.length>0&&s.push(`${o.length} sent to chat`),n>0&&s.push(`${n} skipped`),i>0&&s.push(`${i} failed`);let u=`Bulk optimize: ${s.join(`, `)}.`;m({ok:i===0,msg:u}),t.length>0&&o.length===0?c.success(u,6e3):c.info(u,6e3)}catch(e){m({ok:!1,msg:e instanceof Error?e.message:n(`activity:agentRoster.bulkOptimizationFailed`)}),c.error(e instanceof Error?e.message:n(`activity:agentRoster.bulkOptimizationFailed`))}finally{T(!1)}}},[r,ce,n]),selectRole:(0,K.useCallback)(e=>{i(e),o(null),b(null),P(null),k(null),j(!1),oe(e),I(e),L(e)},[oe,I,L])}}function Lt({customStats:e,onRefresh:t}){let{t:n}=C(),r=It({customStats:e,onRefresh:t});return r.populated.length===0?(0,q.jsx)(`div`,{className:`flex flex-1 items-center justify-center text-muted-foreground`,children:(0,q.jsxs)(`div`,{className:`text-center space-y-3`,children:[(0,q.jsx)(B,{className:`h-10 w-10 mx-auto opacity-30`}),(0,q.jsx)(`p`,{className:`text-sm`,children:n(`activity:agentRoster.noSelfLearningDataYet`)}),(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground/70`,children:n(`activity:agentRoster.learningsEmpty`)})]})}):(0,q.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 overflow-hidden`,children:[(0,q.jsx)(Nt,{populated:r.populated,selectedRole:r.selectedRole,onSelectRole:r.selectRole,onBulkOptimize:r.runBulkOptimize,bulkOptimizing:r.bulkOptimizing}),(0,q.jsxs)(`div`,{className:`flex-1 min-h-0 min-w-0 overflow-y-auto p-4`,children:[!r.selectedRole&&(0,q.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground`,children:n(`activity:agentRoster.selectAnAgentToViewLearning`)}),r.selectedRole&&r.selectedStats&&(0,q.jsx)(Ft,{selectedRole:r.selectedRole,selectedStats:r.selectedStats,saving:r.saving,setLearningEnabled:r.setLearningEnabled,optimizing:r.optimizing,runOptimize:r.runOptimize,autoStatus:r.autoStatus,consolidatedContent:r.consolidatedContent,loadConsolidated:r.loadConsolidated,setConsolidatedContent:r.setConsolidatedContent,skills:r.skills,toggleSkillBody:r.toggleSkillBody,toggleSkillPin:r.toggleSkillPin,openSkill:r.openSkill,retired:r.retired,showRetired:r.showRetired,setShowRetired:r.setShowRetired,loadEntries:r.loadEntries,loadingEntries:r.loadingEntries,reviewEntries:r.reviewEntries,reviewDecisions:r.reviewDecisions,setReviewEntries:r.setReviewEntries,setReviewDecisions:r.setReviewDecisions,applyReview:r.applyReview,teachInput:r.teachInput,setTeachInput:r.setTeachInput,runTeach:r.runTeach,teachFeedback:r.teachFeedback})]})]})}function Rt(e){return typeof e==`object`&&e&&!Array.isArray(e)?e:{}}function zt(e){return typeof e==`number`&&Number.isFinite(e)?e:void 0}function J(e){return typeof e==`string`&&e.trim()?e.trim():void 0}function Y(e,t){for(let n of t){let t=J(e[n]);if(t)return t}}function X(e,t){for(let n of t){let t=zt(e[n]);if(t!==void 0)return t}}function Bt(e){return e.split(/[\\/]/).filter(Boolean).pop()??e}function Vt(e){return e?e.split(/\r?\n/).length:0}function Ht(e){let t=0,n=0;for(let r of e.split(/\r?\n/))r.startsWith(`+++`)||r.startsWith(`---`)||(r.startsWith(`+`)&&(t+=1),r.startsWith(`-`)&&(n+=1));return t||n?{added:t,removed:n}:null}function Ut(e){let t=e.split(/\r?\n/,1)[0]?.trim()??e;return t.length>72?`${t.slice(0,69)}…`:t}function Wt(e){let t=e.toLowerCase().replace(/[.:/-]+/g,`_`);return/^(read|view|open_file|read_file)|file_read/.test(t)?`read`:/^(write|create|save)|file_write/.test(t)?`write`:/edit|update|patch|replace|apply_patch/.test(t)?`edit`:/bash|shell|terminal|exec|command|powershell|cmd/.test(t)?`terminal`:/fetch|browser|browse|http|url|web/.test(t)?`web`:/search|grep|find|glob|query/.test(t)?`search`:/memory|recall|remember/.test(t)?`memory`:`other`}function Gt(e,t){let n=(Array.isArray(e.fileTargets)?e.fileTargets:[]).flatMap(e=>{let t=Rt(e),n=Y(t,[`filePath`,`file_path`,`path`]);return n?[{filePath:n,operation:J(t.operation),line:X(t,[`line`,`startLine`,`start_line`]),endLine:X(t,[`endLine`,`end_line`])}]:[]});if(n.length>0)return n;let r=Y(t,[`file_path`,`filePath`,`path`,`filename`,`target_file`,`targetFile`]);return r?[{filePath:r,line:X(t,[`line`,`start_line`,`startLine`,`offset`]),endLine:X(t,[`end_line`,`endLine`])}]:[]}function Kt(e,t){let n=e?.line??X(t,[`line`,`start_line`,`startLine`,`offset`]),r=e?.endLine??X(t,[`end_line`,`endLine`]),i=X(t,[`limit`,`line_count`,`lineCount`]);return r===void 0&&n!==void 0&&i!==void 0&&i>0&&(r=n+i-1),n!==void 0&&r!==void 0?{start:n,end:r,label:`L${n}–${r}`}:n===void 0?{}:{start:n,label:`L${n}`}}function qt(e,t,n,r,i,a){let o=Kt(a,n),s=a?.filePath??Y(n,[`file_path`,`filePath`,`path`,`filename`]),c=s?Bt(s):void 0;if(e===`read`)return{target:s,summary:i===void 0?o.label?`${o.label} queued to read`:`Reading file`:`${i.toLocaleString()} lines read`,lineLabel:o.label};if(e===`write`){let e=Y(n,[`content`,`text`,`data`]),t=X(r,[`inputLines`])??(e?Vt(e):void 0);return{target:s,summary:t===void 0?`Writing file`:`${t.toLocaleString()} lines written`,lineLabel:o.label}}if(e===`edit`){let e=Y(n,[`patch`,`diff`]),t=e?Ht(e):null,i=Y(n,[`old_string`,`oldString`,`search`]),a=Y(n,[`new_string`,`newString`,`replacement`]),c=X(r,[`addedLines`]),l=X(r,[`removedLines`]),u=X(r,[`oldLines`]),d=X(r,[`newLines`]);return{target:s,summary:t||c!==void 0||l!==void 0?`+${t?.added??c??0} / −${t?.removed??l??0} lines`:i!==void 0||a!==void 0||u!==void 0||d!==void 0?`${i?Vt(i):u??0} → ${a?Vt(a):d??0} lines`:o.label?`${o.label} updated`:`Updating file`,lineLabel:o.label}}if(e===`terminal`){let e=Y(n,[`command`,`cmd`,`script`,`shell`])??t;return{summary:Ut(e),target:e}}if(e===`web`){let e=Y(n,[`url`,`href`,`uri`]),t=Y(n,[`query`,`q`,`search`]);return{target:e??t,summary:e?`Fetched ${e}`:t?`Looked up “${t}”`:`Went online`}}if(e===`search`){let e=Y(n,[`query`,`pattern`,`q`,`search`])??c;return{target:s??e,summary:e?`Searched “${e}”`:`Searching project`}}if(e===`memory`){let e=Y(n,[`query`,`text`,`key`]);return{target:e,summary:e?`Recalled “${e}”`:`Checking memory`}}return{target:s,summary:c?`${t} · ${c}`:t}}function Jt(e,t){let n=J(t.name)??J(t.toolName);if(n)return n;if(e.kind===`agent:tool`)return e.target??void 0;if(e.kind.startsWith(`tool:`))return e.source}function Yt(e,t,n){return J(t.agentId)??J(t.subagentId)??(e.kind===`agent:tool`?e.source:void 0)??(e.source!==n&&e.source!==`filesystem`?e.source:void 0)??`leader`}function Xt(e){return J(e.parentSessionId)??J(e.sessionId)}function Zt(e,t){return e.kind===`tool:started`||e.kind===`tool:progress`?`running`:t.ok===!1?`failed`:`succeeded`}function Qt(e){if(![`tool:started`,`tool:progress`,`tool:executed`,`agent:tool`].includes(e.kind))return null;let t=Rt(e.data),n=Jt(e,t);if(!n)return null;let r=Yt(e,t,n),i=t.input,a=Rt(i),o=Gt(t,a),s=zt(t.outputLines),c=Wt(n),l=qt(c,n,a,t,s,o[0]),u=J(t.id),d=Math.floor(e.timestamp/2e3),f=Zt(e,t),p=zt(t.durationMs);return{id:u?`${r}:${u}`:`${r}:${n}:${d}`,agentId:r,agentName:J(t.agentName),sessionId:Xt(t),toolName:n,kind:c,status:f,startedAt:f===`running`?e.timestamp:Math.max(0,e.timestamp-(p??0)),...f===`running`?{}:{completedAt:e.timestamp},durationMs:p,target:l.target,summary:l.summary,lineLabel:l.lineLabel,outputLines:s,outputBytes:zt(t.outputBytes),outputTokens:zt(t.outputTokens),input:i,output:J(t.output),fileTargets:o,raw:e.raw??t}}function $t(e,t,n){return e?.length?an(e.map(e=>({id:`snapshot:${n??`session`}:${t}:${e.id}`,kind:`tool:executed`,timestamp:e.completedAt,source:t,target:e.name,label:e.name,data:{...e,agentId:t,sessionId:n},flowGroup:`agent:${t}`})),t,n):[]}function en(e){return e?.length?e.map(e=>({id:e.id,direction:e.direction,from:e.from,to:e.to,type:e.type,subject:e.subject,body:``,priority:`normal`,timestamp:new Date(e.at).toISOString(),timestampMs:e.at,unread:e.direction===`incoming`})).sort((e,t)=>t.timestampMs-e.timestampMs).slice(0,12):[]}function tn(e,t,n=3e4){let r=new Map;e.forEach((e,t)=>{for(let n of[e.agent.serverId,e.agent.mailboxId,e.agent.name]){let e=Z(n);e&&!r.has(e)&&r.set(e,t)}});let i=new Set,a=[];for(let o of e){let e=o.mail[0];if(!e||i.has(e.id)||t-e.timestampMs>n)continue;let s=r.get(Z(e.from)),c=r.get(Z(e.to));s!==void 0&&c!==void 0&&s!==c&&(i.add(e.id),a.push({id:e.id,mail:e,fromIndex:s,toIndex:c}))}return a}function nn(e,t){return e.toLowerCase()===t.toLowerCase()}function Z(e){return e?.trim().toLowerCase()??``}function rn(e,t,n){let r=new Set([t.serverId,t.mailboxId,t.name].map(Z).filter(e=>e.length>0)),i=n?`@session:${Z(n)}`:``,a=Z(t.role),o=Z(t.serverId)===`leader`||Z(t.serverId).startsWith(`leader@`)||a===`lead`||a===`leader`;return e.flatMap(e=>{let t=Z(e.from),n=Z(e.to),a=r.has(t),s=n===`*`||n===`all`||i.length>0&&n===i,c=(e.audience!==`leaders`||o)&&(r.has(n)||o&&s);if(!c&&!a)return[];let l=Date.parse(e.timestamp);return[{...e,direction:c?`incoming`:`outgoing`,timestampMs:Number.isFinite(l)?l:0,unread:c&&!Object.keys(e.readBy??{}).some(e=>r.has(Z(e)))}]}).sort((e,t)=>t.timestampMs-e.timestampMs).slice(0,8)}function an(e,t,n){let r=new Map;for(let i=e.length-1;i>=0;--i){let a=e[i];if(!a)continue;let o=Qt(a);if(!o||!nn(o.agentId,t)||n&&o.sessionId&&o.sessionId!==n)continue;let s=r.get(o.id);r.set(o.id,s?{...s,...o,startedAt:Math.min(s.startedAt,o.startedAt),fileTargets:o.fileTargets.length>0?o.fileTargets:s.fileTargets,input:o.input??s.input,output:o.output??s.output,raw:o.raw??s.raw}:o)}let i=[...r.values()].sort((e,t)=>(t.completedAt??t.startedAt)-(e.completedAt??e.startedAt));return i.filter((e,t)=>e.input!==void 0||e.fileTargets.length>0||e.output!==void 0||!i.some((n,r)=>r!==t&&n.toolName===e.toolName&&(n.input!==void 0||n.fileTargets.length>0||n.output!==void 0)&&Math.abs((n.completedAt??n.startedAt)-(e.completedAt??e.startedAt))<2500))}function on(e,t,n){let r=Wt(t),i={read:`Reading a file`,write:`Writing a file`,edit:`Updating code`,terminal:`Running a command`,web:`Working online`,search:`Searching project`,memory:`Checking memory`,other:t};return{id:`${e}:live:${t}`,agentId:e,sessionId:n,toolName:t,kind:r,status:`running`,startedAt:Date.now(),summary:i[r],fileTargets:[]}}var sn={read:R,write:L,edit:L,terminal:b,web:ue,search:he,memory:M,other:I};function cn(e,t=46){if(!e||e.length<=t)return e;let n=e.split(/[\\/]/).slice(-2).join(`/`);return n.length<=t?`…/${n}`:`…${e.slice(-(t-1))}`}function ln(e){return e===void 0?`—`:e<1e3?`${Math.round(e)} ms`:`${(e/1e3).toFixed(+(e<1e4))} s`}function un(e){if(e===void 0)return``;if(typeof e==`string`)return e;try{return JSON.stringify(e,null,2)}catch{return String(e)}}function dn({label:e,value:t}){return(0,q.jsxs)(`div`,{className:`agent-office__detail-row`,children:[(0,q.jsx)(`span`,{children:e}),(0,q.jsx)(`strong`,{children:t})]})}function fn({selected:e,onClose:t}){let{t:n}=C(),{call:r,agentName:i}=e,a=sn[r.kind],o=un(r.input),s=un(r.output);return(0,q.jsxs)(`aside`,{className:`agent-office__detail`,"aria-label":`${r.toolName} details`,children:[(0,q.jsxs)(`div`,{className:`agent-office__detail-header`,children:[(0,q.jsx)(`div`,{className:U(`agent-office__detail-icon`,`is-${r.kind}`),children:(0,q.jsx)(a,{"aria-hidden":`true`})}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`span`,{children:n(`activity:agentOffice.toolCall`)}),(0,q.jsx)(`h2`,{children:r.toolName})]}),(0,q.jsx)(`button`,{type:`button`,onClick:t,"aria-label":n(`activity:agentOffice.closeDetails`),children:(0,q.jsx)(k,{})})]}),(0,q.jsxs)(`div`,{className:`agent-office__detail-status`,children:[(0,q.jsx)(`span`,{className:U(`agent-office__status-dot`,r.status===`running`&&`is-active`,r.status===`failed`&&`is-failed`)}),(0,q.jsx)(`strong`,{children:r.summary}),(0,q.jsx)(`span`,{children:r.status})]}),(0,q.jsxs)(`section`,{className:`agent-office__detail-section`,children:[(0,q.jsx)(`h3`,{children:n(`activity:agentOffice.execution`)}),(0,q.jsx)(dn,{label:n(`activity:agentOffice.agent`),value:i}),(0,q.jsx)(dn,{label:n(`activity:agentOffice.started`),value:new Date(r.startedAt).toLocaleTimeString()}),(0,q.jsx)(dn,{label:n(`activity:agentOffice.duration`),value:ln(r.durationMs)}),r.sessionId&&(0,q.jsx)(dn,{label:n(`activity:agentOffice.session`),value:cn(r.sessionId,28)})]}),(r.target||r.fileTargets.length>0)&&(0,q.jsxs)(`section`,{className:`agent-office__detail-section`,children:[(0,q.jsx)(`h3`,{children:n(`activity:agentOffice.target`)}),r.target&&(0,q.jsx)(`code`,{className:`agent-office__target-code`,children:r.target}),r.fileTargets.map((e,t)=>(0,q.jsxs)(`div`,{className:`agent-office__file-target`,children:[(0,q.jsx)(E,{"aria-hidden":`true`}),(0,q.jsx)(`span`,{children:e.filePath}),(e.line||e.endLine)&&(0,q.jsxs)(`strong`,{children:[`L`,e.line??1,e.endLine?`–${e.endLine}`:``]})]},`${e.filePath}:${t}`))]}),(r.outputLines!==void 0||r.outputBytes!==void 0||r.outputTokens!==void 0)&&(0,q.jsxs)(`section`,{className:`agent-office__detail-section`,children:[(0,q.jsx)(`h3`,{children:n(`activity:agentOffice.resultSize`)}),(0,q.jsxs)(`div`,{className:`agent-office__metric-grid`,children:[r.outputLines!==void 0&&(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`strong`,{children:r.outputLines.toLocaleString()}),(0,q.jsx)(`span`,{children:n(`activity:agentOffice.lines`)})]}),r.outputBytes!==void 0&&(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`strong`,{children:r.outputBytes.toLocaleString()}),(0,q.jsx)(`span`,{children:n(`activity:agentOffice.bytes`)})]}),r.outputTokens!==void 0&&(0,q.jsxs)(`div`,{children:[(0,q.jsxs)(`strong`,{children:[`≈`,r.outputTokens.toLocaleString()]}),(0,q.jsx)(`span`,{children:n(`activity:agentOffice.tokens`)})]})]})]}),o&&(0,q.jsxs)(`section`,{className:`agent-office__detail-section`,children:[(0,q.jsx)(`h3`,{children:n(`activity:agentOffice.input`)}),(0,q.jsx)(`pre`,{children:(0,q.jsx)(`code`,{children:o})})]}),s&&(0,q.jsxs)(`section`,{className:`agent-office__detail-section`,children:[(0,q.jsx)(`h3`,{children:n(`activity:agentOffice.outputPreview`)}),(0,q.jsx)(`pre`,{children:(0,q.jsx)(`code`,{children:s})})]})]})}function pn({selected:e,onClose:t}){let{t:n}=C(),{mail:r,agentName:i}=e;return(0,q.jsxs)(`aside`,{className:`agent-office__detail`,"aria-label":`${r.subject} details`,children:[(0,q.jsxs)(`div`,{className:`agent-office__detail-header`,children:[(0,q.jsx)(`div`,{className:`agent-office__detail-icon is-mail`,children:(0,q.jsx)(_,{"aria-hidden":`true`})}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`span`,{children:r.direction===`incoming`?`INCOMING MAIL`:`OUTGOING MAIL`}),(0,q.jsx)(`h2`,{children:r.subject})]}),(0,q.jsx)(`button`,{type:`button`,onClick:t,"aria-label":n(`activity:agentOffice.closeMailDetails`),children:(0,q.jsx)(k,{})})]}),(0,q.jsxs)(`div`,{className:`agent-office__detail-status`,children:[(0,q.jsx)(`span`,{className:U(`agent-office__status-dot`,r.unread&&`is-active`)}),(0,q.jsxs)(`strong`,{children:[r.from,` → `,r.to]}),(0,q.jsx)(`span`,{children:r.type}),r.audience===`leaders`&&(0,q.jsxs)(`span`,{children:[(0,q.jsx)(se,{className:`h-3 w-3`}),` `,n(`activity:mailbox.audienceLeaders`)]})]}),(0,q.jsxs)(`section`,{className:`agent-office__detail-section`,children:[(0,q.jsx)(`h3`,{children:n(`activity:mailbox.messages`)}),(0,q.jsx)(dn,{label:n(`activity:agentOffice.agent`),value:i}),(0,q.jsx)(dn,{label:n(`activity:agentOffice.started`),value:new Date(r.timestampMs).toLocaleTimeString()}),(0,q.jsx)(dn,{label:n(`activity:agentOffice.priority`),value:r.priority}),(0,q.jsx)(dn,{label:n(`activity:agentOffice.route`),value:`${r.from} → ${r.to}`})]}),(0,q.jsxs)(`section`,{className:`agent-office__detail-section`,children:[(0,q.jsx)(`h3`,{children:r.subject}),(0,q.jsx)(`div`,{className:`agent-office__mail-body`,children:r.body})]})]})}function mn({selected:e,onClose:t}){let{t:n}=C();return(0,q.jsxs)(`aside`,{className:`agent-office__detail`,"aria-label":`${e.agentName} task details`,children:[(0,q.jsxs)(`div`,{className:`agent-office__detail-header`,children:[(0,q.jsx)(`div`,{className:`agent-office__detail-icon is-task`,children:(0,q.jsx)(O,{"aria-hidden":`true`})}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`span`,{children:n(`activity:agentOffice.currentTask`)}),(0,q.jsx)(`h2`,{children:e.agentName})]}),(0,q.jsx)(`button`,{type:`button`,onClick:t,"aria-label":n(`activity:agentOffice.closeTaskDetails`),children:(0,q.jsx)(k,{})})]}),(0,q.jsxs)(`section`,{className:`agent-office__detail-section`,children:[(0,q.jsx)(`h3`,{children:n(`activity:agentOffice.task`)}),e.taskId&&(0,q.jsx)(dn,{label:`ID`,value:e.taskId}),(0,q.jsx)(`div`,{className:`agent-office__task-body`,children:e.task})]})]})}function hn({selected:e,onClose:t}){let{t:n}=C(),r=e.todos.filter(e=>e.status!==`completed`).length;return(0,q.jsxs)(`aside`,{className:`agent-office__detail`,"aria-label":`${e.officeLabel} briefing`,children:[(0,q.jsxs)(`div`,{className:`agent-office__detail-header`,children:[(0,q.jsx)(`div`,{className:`agent-office__detail-icon is-briefing`,children:(0,q.jsx)(w,{"aria-hidden":`true`})}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`span`,{children:e.instructionActive?n(`activity:agentOffice.activeInstruction`):n(`activity:agentOffice.officeBriefing`)}),(0,q.jsx)(`h2`,{children:e.officeLabel})]}),(0,q.jsx)(`button`,{type:`button`,onClick:t,"aria-label":n(`activity:agentOffice.closeOfficeBriefing`),children:(0,q.jsx)(k,{})})]}),(0,q.jsxs)(`div`,{className:`agent-office__detail-status`,children:[(0,q.jsx)(`span`,{className:U(`agent-office__status-dot`,(e.instructionActive||r>0)&&`is-active`)}),(0,q.jsx)(`strong`,{children:e.telemetryConnected?n(`activity:agentOffice.activeTodos`):n(`activity:agentOffice.telemetryWaiting`)}),(0,q.jsx)(`span`,{children:e.telemetryConnected?r:`—`})]}),(0,q.jsxs)(`section`,{className:`agent-office__detail-section`,children:[(0,q.jsx)(`h3`,{children:e.instructionActive?n(`activity:agentOffice.activeInstruction`):n(`activity:agentOffice.leaderPrompt`)}),e.promptAt!==void 0&&(0,q.jsx)(dn,{label:n(`activity:agentOffice.promptReceived`),value:new Date(e.promptAt).toLocaleString()}),(0,q.jsx)(`div`,{className:`agent-office__task-body`,children:e.prompt??(e.telemetryConnected?n(`activity:agentOffice.noPrompt`):n(`activity:agentOffice.telemetryWaiting`))})]}),(0,q.jsxs)(`section`,{className:`agent-office__detail-section`,children:[(0,q.jsx)(`h3`,{children:n(`activity:agentOffice.todos`)}),(0,q.jsx)(`div`,{className:`agent-office__todo-detail-list`,children:e.telemetryConnected?e.todos.length>0?e.todos.map(e=>(0,q.jsxs)(`div`,{className:U(`agent-office__todo-detail`,`is-${e.status}`),children:[(0,q.jsx)(`span`,{"aria-hidden":`true`}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`strong`,{children:e.content}),(0,q.jsx)(`small`,{children:n(`activity:agentOffice.todoStatus.${e.status}`)})]})]},e.id)):(0,q.jsx)(`span`,{className:`agent-office__history-empty`,children:n(`activity:agentOffice.noActiveTodos`)}):(0,q.jsx)(`span`,{className:`agent-office__history-empty`,children:n(`activity:agentOffice.todoTelemetryWaiting`)})})]})]})}function gn({selected:e,onClose:t}){return e.kind===`tool`?(0,q.jsx)(fn,{selected:e,onClose:t}):e.kind===`mail`?(0,q.jsx)(pn,{selected:e,onClose:t}):e.kind===`task`?(0,q.jsx)(mn,{selected:e,onClose:t}):(0,q.jsx)(hn,{selected:e,onClose:t})}var _n=[`bot`,`cactus`,`duck`,`radio`],vn={leader:`plum`,builder:`ocean`,researcher:`mint`,reviewer:`rose`,planner:`amber`,operator:`graphite`},yn={leader:0,builder:1,researcher:2,reviewer:3,planner:4,operator:5},bn={read:R,write:L,edit:L,terminal:b,web:ue,search:he,memory:M,other:I},xn={leader:te,builder:I,researcher:R,reviewer:Te,planner:O,operator:b};function Sn(e){if(e.serverId===`leader`||e.serverId.startsWith(`leader@`))return`leader`;let t=[e.role,e.name,e.currentTask].filter(Boolean).join(` `).toLowerCase();return/review|critic|audit|security|test|qa|verify|checker/.test(t)?`reviewer`:/research|analyst|explor|investig|search|hunter|recon/.test(t)?`researcher`:/plan|architect|design|coordinat|strateg|spec/.test(t)?`planner`:/build|implement|code|develop|engineer|refactor|fix|frontend|backend/.test(t)?`builder`:`operator`}function Cn(e,t){let n=2166136261;for(let t=0;t<e.length;t+=1)n^=e.charCodeAt(t),n=Math.imul(n,16777619);let r=n>>>0;return{palette:vn[t],layout:r%4,clutter:Math.floor(r/4)%3,avatar:yn[t],motion:Math.floor(r/31)%4,charm:_n[Math.floor(r/47)%_n.length]}}function wn(e,t=22){let n=e.split(`/`).filter(Boolean).pop()??e;return n.length>t?`${n.slice(0,t-1)}…`:n}function Tn(e,t=46){if(!e||e.length<=t)return e;let n=e.split(/[\\/]/).slice(-2).join(`/`);return n.length<=t?`…/${n}`:`…${e.slice(-(t-1))}`}function En(e,t,n=12e4){let{agent:r,client:i,current:a,history:o,mail:s}=e,c=r.status===`active`||r.status===`streaming`,l=a?.startedAt??o[0]?.completedAt??o[0]?.startedAt,u=[l,s[0]?.timestampMs].filter(e=>e!==void 0),d=Date.parse(i.startedAt??``),f=Number.isFinite(d)?d:0,p=u.length>0?Math.max(...u,f):f>0?f:void 0,m=p===void 0?1/0:Math.max(0,t-p);if(!c||a!==void 0||m<n)return{waiting:!1,idleMs:m,reason:`no-work`,anchor:``,anchorId:void 0,anchorAt:p};if(i.todos===void 0&&r.toolCalls===0)return{waiting:!0,idleMs:m,reason:`telemetry`,anchor:r.currentTask??``,anchorId:void 0,anchorAt:p};let h=s[0],g=h!==void 0&&h.direction===`outgoing`&&(l===void 0||h.timestampMs>l)?h:void 0;return g===void 0?{waiting:!0,idleMs:m,reason:`no-work`,anchor:r.currentTask||o[0]?.summary||``,anchorId:void 0,anchorAt:p}:{waiting:!0,idleMs:m,reason:`mail-reply`,anchor:g.subject,anchorId:g.id,anchorAt:p}}function Dn(e,t){let n=Math.max(0,Math.floor((t-e)/1e3));if(n<5)return`now`;if(n<60)return`${n}s`;let r=Math.floor(n/60);return r<60?`${r}m`:`${Math.floor(r/60)}h`}function On(e,t){if(!e)return`—`;let n=Date.parse(e);if(!Number.isFinite(n))return`—`;let r=Math.max(0,Math.floor((t-n)/1e3));return r<60?`${r}s`:r<3600?`${Math.floor(r/60)}m`:r<86400?`${Math.floor(r/3600)}h`:`${Math.floor(r/86400)}d`}function kn(e){let t=new Set,n=new Set,r=new Set,i=0,a=0,o={files:0,reads:0,writes:0,edits:0,linesAdded:0,linesRemoved:0,terminalCalls:0,incomingMail:0,outgoingMail:0};for(let s of e){let e=s.agent.activity;for(let n of e?.filesTouched??[])t.add(n);o.reads+=e?.reads??0,o.writes+=e?.writes??0,o.edits+=e?.edits??0,o.linesAdded+=e?.linesAdded??0,o.linesRemoved+=e?.linesRemoved??0,o.terminalCalls+=e?.terminalCalls??0,i+=e?.mailReceived??0,a+=e?.mailSent??0;for(let e of s.mail)(e.direction===`incoming`?n:r).add(e.id)}return o.files=t.size,o.incomingMail=Math.max(i,n.size),o.outgoingMail=Math.max(a,r.size),o}function An(e,t,n){return n.map((n,r)=>({...on(e.serverId,n.name,t.sessionId),id:`${e.serverId}:log:${n.at}:${r}`,kind:Wt(n.name),status:n.ok?`succeeded`:`failed`,startedAt:Math.max(0,n.at-n.durationMs),completedAt:n.at,durationMs:n.durationMs,summary:n.ok?`${n.name} completed`:`${n.name} failed`}))}function jn(...e){let t=[];for(let n of e.flat()){let e=n.completedAt??n.startedAt;t.some(t=>(t.id===n.id||t.toolName===n.toolName)&&Math.abs((t.completedAt??t.startedAt)-e)<2500)||t.push(n)}return t.sort((e,t)=>(t.completedAt??t.startedAt)-(e.completedAt??e.startedAt))}function Mn(...e){let t=new Map;for(let n of e.flat())t.set(n.id,n);return[...t.values()].sort((e,t)=>t.timestampMs-e.timestampMs).slice(0,12)}function Nn({kind:e,active:t}){let n=bn[e];return(0,q.jsxs)(`span`,{className:U(`agent-office__tool-glyph`,`is-${e}`,t&&`is-active`),children:[e===`read`&&(0,q.jsx)(E,{className:`agent-office__file-underlay`,"aria-hidden":`true`}),(0,q.jsx)(n,{"aria-hidden":`true`})]})}function Pn({active:e,failed:t,role:n,variant:r,motion:i}){let a=xn[n];return(0,q.jsxs)(`div`,{className:U(`agent-office__avatar`,`is-${n}`,`is-avatar-${r}`,`is-motion-${i}`,e&&`is-active`,!e&&!t&&`is-idle`,t&&`is-failed`),"aria-hidden":`true`,children:[(0,q.jsx)(`span`,{className:`agent-office__avatar-chair`}),(0,q.jsx)(`span`,{className:`agent-office__avatar-body`}),(0,q.jsxs)(`span`,{className:`agent-office__avatar-head`,children:[(0,q.jsx)(`span`,{className:`agent-office__avatar-hair`}),(0,q.jsx)(`span`,{className:`agent-office__avatar-face`}),(0,q.jsx)(`span`,{className:`agent-office__avatar-mouth`}),(0,q.jsx)(`span`,{className:`agent-office__avatar-headset`})]}),(0,q.jsx)(`span`,{className:`agent-office__avatar-arm`}),(0,q.jsx)(`span`,{className:`agent-office__avatar-prop`}),(0,q.jsx)(`span`,{className:`agent-office__avatar-role-badge`,children:(0,q.jsx)(a,{})})]})}function Fn({call:e,compact:t=!1,onSelect:n}){let r=e.status===`running`;return(0,q.jsxs)(`button`,{type:`button`,className:U(`agent-office__parcel`,`is-${e.kind}`,t&&`is-compact`,r&&`is-running`,e.status===`failed`&&`is-failed`),onClick:n,"aria-label":`${e.toolName}: ${e.summary}`,children:[(0,q.jsx)(Nn,{kind:e.kind,active:r}),(0,q.jsxs)(`span`,{className:`agent-office__parcel-copy`,children:[(0,q.jsxs)(`span`,{className:`agent-office__parcel-topline`,children:[(0,q.jsx)(`strong`,{children:e.toolName}),e.lineLabel&&(0,q.jsx)(`span`,{className:`agent-office__line-chip`,children:e.lineLabel})]}),!t&&e.target&&(0,q.jsx)(`span`,{className:`agent-office__parcel-target`,children:Tn(e.target)}),(0,q.jsx)(`span`,{className:`agent-office__parcel-summary`,children:e.summary})]}),(0,q.jsx)(`span`,{className:`agent-office__parcel-state`,"aria-hidden":`true`,children:r?(0,q.jsx)(`span`,{className:`agent-office__pulse-dot`}):e.status===`failed`?(0,q.jsx)(k,{}):(0,q.jsx)(Te,{})})]})}function In({mail:e,compact:t=!1,onSelect:n}){let r=e.direction===`incoming`;return(0,q.jsxs)(`button`,{type:`button`,className:U(`agent-office__mail-parcel`,t&&`is-compact`,r?`is-incoming`:`is-outgoing`,e.unread&&`is-unread`),onClick:n,"aria-label":`${r?`Incoming`:`Outgoing`} mail: ${e.subject}`,children:[(0,q.jsx)(`span`,{className:`agent-office__mail-icon`,children:r?(0,q.jsx)(ve,{"aria-hidden":`true`}):(0,q.jsx)(v,{"aria-hidden":`true`})}),(0,q.jsxs)(`span`,{className:`agent-office__parcel-copy`,children:[(0,q.jsx)(`strong`,{children:r?`${e.from} →`:`→ ${e.to}`}),(0,q.jsx)(`span`,{className:`agent-office__parcel-summary`,children:e.subject})]}),(0,q.jsx)(_,{"aria-hidden":`true`})]})}function Ln({active:e}){let{t}=C();return(0,q.jsxs)(`div`,{className:`agent-office__parcel agent-office__parcel--empty`,children:[(0,q.jsx)(`span`,{className:`agent-office__tool-glyph`,children:(0,q.jsx)(I,{"aria-hidden":`true`})}),(0,q.jsxs)(`span`,{className:`agent-office__parcel-copy`,children:[(0,q.jsx)(`strong`,{children:t(e?`activity:agentOffice.thinking`:`activity:agentOffice.waiting`)}),(0,q.jsx)(`span`,{children:t(e?`activity:agentOffice.preparing`:`activity:agentOffice.deskReady`)})]})]})}function Rn({model:e,now:n,onSelect:r,routedMailIds:i}){let{t:a}=C(),o=W(e=>e.waitThresholdMs),{agent:s,client:c,current:l,display:u,history:d,mail:p}=e,m=s.status===`active`||s.status===`streaming`,h=s.status===`error`,g=p[0],v=Sn(s),y=Cn(`${c.sessionId}:${s.serverId}:${s.name}`,v),b=En(e,n,o),S=b.reason===`mail-reply`?p.some(e=>e.id===b.anchorId):!!s.currentTask,w=Number.isFinite(b.idleMs)?Dn(n-b.idleMs,n):`—`,T=b.waiting?b.reason===`mail-reply`?a(`activity:agentOffice.waitingForReply`,{subject:b.anchor||a(`activity:agentOffice.waitingMailFallback`),duration:w}):b.reason===`telemetry`?a(`activity:agentOffice.waitingTelemetry`):a(`activity:agentOffice.waitingNoWork`,{duration:w,last:b.anchor||a(`activity:agentOffice.waitingNothingYet`)}):void 0,E=g&&n-g.timestampMs<3e4&&!i?.has(g.id)&&b.anchorId!==g.id,D=d.slice(0,6),k=D[0]?.completedAt??D[0]?.startedAt??u?.completedAt??u?.startedAt,A=l?`is-tool-${l.kind}`:void 0,j=l?l.summary:u?u.summary:b.waiting?T??a(`activity:agentOffice.waiting`):a(m?`activity:agentOffice.preparing`:`activity:agentOffice.waiting`);return(0,q.jsxs)(`article`,{className:U(`agent-office__lane`,`is-desk-${y.palette}`,`is-layout-${y.layout}`,`is-clutter-${y.clutter}`,m&&`is-active`,h&&`is-failed`,b.waiting&&`is-waiting`),children:[(0,q.jsxs)(`div`,{className:`agent-office__identity`,children:[(0,q.jsxs)(`div`,{className:`agent-office__identity-line`,children:[(0,q.jsx)(`span`,{className:U(`agent-office__status-dot`,m&&`is-active`,h&&`is-failed`)}),(0,q.jsx)(`strong`,{title:s.name,children:s.name}),(0,q.jsxs)(`span`,{className:`agent-office__agent-verified`,title:s.presenceSource===`registry`?`Verified by live session registry`:`Verified by local fleet state`,children:[(0,q.jsx)(Te,{"aria-hidden":`true`}),s.presenceSource===`registry`?`LIVE`:`LOCAL`]})]}),b.waiting&&S&&(0,q.jsxs)(`button`,{type:`button`,className:U(`agent-office__wait-badge`,`is-${b.reason}`),title:T,"aria-label":T,onClick:()=>{if(b.reason===`mail-reply`){let e=p.find(e=>e.id===b.anchorId);e&&r({kind:`mail`,mail:e,agentName:s.name});return}s.currentTask&&r({kind:`task`,task:s.currentTask,taskId:s.taskId,agentName:s.name})},children:[(0,q.jsx)(Me,{"aria-hidden":`true`}),(0,q.jsx)(`span`,{children:w})]}),b.waiting&&!S&&(0,q.jsxs)(`span`,{role:`status`,className:U(`agent-office__wait-badge`,`is-${b.reason}`),title:T,"aria-label":T,children:[(0,q.jsx)(Me,{"aria-hidden":`true`}),(0,q.jsx)(`span`,{children:w})]}),(0,q.jsx)(`span`,{className:`agent-office__role`,children:s.role??(s.serverId===`leader`||s.serverId.startsWith(`leader@`)?a(`activity:agentOffice.leadAgent`):a(`activity:agentOffice.agent`))}),(0,q.jsxs)(`div`,{className:`agent-office__agent-meta`,children:[(0,q.jsx)(`span`,{children:c.branch?`⎇ ${c.branch}`:c.type.toUpperCase()}),(0,q.jsx)(`span`,{children:a(`activity:agentOffice.callsCount`,{count:s.toolCalls})}),s.model&&(0,q.jsx)(`span`,{className:`agent-office__model-chip`,title:s.model,children:wn(s.model)})]}),s.currentTask&&(0,q.jsxs)(`button`,{type:`button`,className:`agent-office__agent-task`,onClick:()=>r({kind:`task`,task:s.currentTask??``,taskId:s.taskId,agentName:s.name}),children:[(0,q.jsx)(O,{"aria-hidden":`true`}),(0,q.jsxs)(`span`,{children:[(0,q.jsx)(`strong`,{children:a(`activity:agentOffice.currentTask`)}),(0,q.jsx)(`small`,{children:s.currentTask})]})]}),!s.currentTask&&m&&(0,q.jsxs)(`div`,{className:`agent-office__agent-task is-missing`,children:[(0,q.jsx)(x,{"aria-hidden":`true`}),(0,q.jsxs)(`span`,{children:[(0,q.jsx)(`strong`,{children:a(`activity:agentOffice.currentTask`)}),(0,q.jsx)(`small`,{children:c.todos===void 0?a(`activity:agentOffice.telemetryWaiting`):a(`activity:agentOffice.taskNotReported`)})]})]}),g&&(0,q.jsxs)(`button`,{type:`button`,className:U(`agent-office__identity-mail`,g.unread&&`is-unread`),onClick:()=>r({kind:`mail`,mail:g,agentName:s.name}),"aria-label":`${p.length} mail messages. Latest: ${g.subject}`,children:[(0,q.jsx)(_,{"aria-hidden":`true`}),(0,q.jsxs)(`span`,{children:[(0,q.jsxs)(`strong`,{children:[p.length,` MAIL`]}),(0,q.jsx)(`small`,{children:g.subject})]})]})]}),(0,q.jsxs)(`div`,{className:U(`agent-office__scene`,A),children:[(0,q.jsxs)(`div`,{className:`agent-office__window`,"aria-hidden":`true`,children:[(0,q.jsx)(`span`,{}),(0,q.jsx)(`span`,{}),(0,q.jsx)(`span`,{})]}),(0,q.jsxs)(`div`,{className:`agent-office__plant`,"aria-hidden":`true`,children:[(0,q.jsx)(`span`,{}),(0,q.jsx)(`i`,{}),(0,q.jsx)(`b`,{})]}),(0,q.jsxs)(`div`,{className:`agent-office__desk-zone`,"aria-hidden":`true`,children:[(0,q.jsx)(Pn,{active:m,failed:h,role:v,variant:y.avatar,motion:y.motion}),(0,q.jsx)(`span`,{className:`agent-office__monitor`,children:u?(0,q.jsx)(Nn,{kind:u.kind,active:l!==void 0}):(0,q.jsx)(I,{})}),(0,q.jsxs)(`span`,{className:`agent-office__activity-fx`,children:[(0,q.jsx)(`span`,{}),(0,q.jsx)(`i`,{}),(0,q.jsx)(`b`,{})]}),(0,q.jsx)(`span`,{className:`agent-office__desk`}),(0,q.jsx)(`span`,{className:`agent-office__desk-lamp`}),(0,q.jsxs)(`span`,{className:`agent-office__desk-clutter`,children:[(0,q.jsx)(`i`,{}),(0,q.jsx)(`b`,{})]}),(0,q.jsxs)(`span`,{className:U(`agent-office__desk-charm`,`is-${y.charm}`),children:[(0,q.jsx)(`i`,{}),(0,q.jsx)(`b`,{})]}),(0,q.jsxs)(`span`,{className:U(`agent-office__mug`,`is-${v}`),children:[(0,q.jsx)(`i`,{"aria-hidden":`true`}),(0,q.jsx)(`b`,{"aria-hidden":`true`})]})]}),E&&(0,q.jsx)(`div`,{className:U(`agent-office__mail-flyby`,`is-${g.direction}`),children:(0,q.jsx)(In,{mail:g,compact:!0,onSelect:()=>r({kind:`mail`,mail:g,agentName:s.name})},g.id)}),(0,q.jsxs)(`div`,{className:U(`agent-office__conveyor`,l&&`is-moving`),children:[(0,q.jsxs)(`div`,{className:`agent-office__belt`,"aria-hidden":`true`,children:[(0,q.jsx)(`span`,{}),(0,q.jsx)(`span`,{}),(0,q.jsx)(`span`,{}),(0,q.jsx)(`span`,{}),(0,q.jsx)(`span`,{}),(0,q.jsx)(`span`,{})]}),(0,q.jsx)(`div`,{className:`agent-office__current-action`,children:u?(0,q.jsx)(Fn,{call:u,onSelect:()=>r({kind:`tool`,call:u,agentName:s.name})},u.id):(0,q.jsx)(Ln,{active:m})})]})]}),(0,q.jsxs)(`div`,{className:`agent-office__history`,children:[(0,q.jsxs)(`div`,{className:`agent-office__history-heading`,children:[(0,q.jsx)(`span`,{children:a(`activity:agentOffice.recent`)}),k!==void 0&&(0,q.jsx)(`span`,{children:Dn(k,n)})]}),(0,q.jsx)(`div`,{className:`agent-office__history-list`,children:D.length>0?D.map(e=>(0,q.jsx)(Fn,{call:e,compact:!0,onSelect:()=>r({kind:`tool`,call:e,agentName:s.name})},`tool:${e.id}`)):(0,q.jsx)(`span`,{className:`agent-office__history-empty`,children:s.toolCalls>0&&s.recentTools===void 0&&s.activity===void 0?a(`activity:agentOffice.telemetryReconnect`):a(`activity:agentOffice.noCalls`)})})]}),(0,q.jsxs)(`div`,{className:`agent-office__desk-metrics`,children:[(0,q.jsxs)(`span`,{className:`agent-office__metric`,title:`${a(`activity:agentOffice.tokens`)}: in ${f(s.tokensIn)} / out ${f(s.tokensOut)}`,children:[(0,q.jsx)(`strong`,{children:f(s.tokensIn+s.tokensOut)}),(0,q.jsx)(`small`,{children:`TOK`})]}),(0,q.jsxs)(`span`,{className:`agent-office__metric`,title:a(`activity:agentOffice.cost`),children:[(0,q.jsx)(`strong`,{children:t(s.costUsd)}),(0,q.jsx)(`small`,{children:`COST`})]}),(0,q.jsxs)(`span`,{className:`agent-office__metric`,title:a(`activity:agentOffice.contextUsed`),children:[(0,q.jsx)(`strong`,{children:s.ctxPct===void 0?`—`:`${Math.round(s.ctxPct)}%`}),(0,q.jsx)(`small`,{children:`CTX`}),s.ctxPct!==void 0&&(0,q.jsx)(`i`,{className:U(`agent-office__ctx-bar`,s.ctxPct>=80&&`is-high`),children:(0,q.jsx)(`b`,{style:{width:`${Math.min(100,Math.max(0,s.ctxPct))}%`}})})]}),(0,q.jsxs)(`span`,{className:`agent-office__metric agent-office__metric-action`,title:j,children:[(0,q.jsx)(x,{"aria-hidden":`true`}),(0,q.jsx)(`small`,{children:j})]})]})]})}function zn(e){return e.agent.status===`active`||e.agent.status===`streaming`||e.agent.status===`error`}function Bn({agents:e,now:t,onSelect:n}){let{t:r}=C();return(0,q.jsxs)(`section`,{className:`agent-office__lounge`,"aria-label":r(`activity:agentOffice.breakRoom`),children:[(0,q.jsxs)(`header`,{className:`agent-office__lounge-heading`,children:[(0,q.jsx)(z,{"aria-hidden":`true`}),(0,q.jsx)(`strong`,{children:r(`activity:agentOffice.breakRoom`)}),(0,q.jsx)(`span`,{children:r(`activity:agentOffice.onBreak`,{count:e.length})})]}),(0,q.jsx)(`div`,{className:`agent-office__lounge-seats`,children:e.map(e=>{let{agent:i,history:a,mail:o}=e,s=Sn(i),c=xn[s],l=o.filter(e=>e.unread).length,u=a[0]?.completedAt??a[0]?.startedAt,d=o[0],f=()=>{i.currentTask?n({kind:`task`,task:i.currentTask,taskId:i.taskId,agentName:i.name}):d&&n({kind:`mail`,mail:d,agentName:i.name})},p=!!i.currentTask||!!d;return(0,q.jsxs)(`button`,{type:`button`,className:U(`agent-office__lounge-seat`,`is-${s}`),onClick:f,disabled:!p,children:[(0,q.jsx)(`span`,{className:`agent-office__lounge-avatar`,children:(0,q.jsx)(c,{"aria-hidden":`true`})}),(0,q.jsxs)(`span`,{className:`agent-office__lounge-copy`,children:[(0,q.jsx)(`strong`,{children:i.name}),(0,q.jsx)(`small`,{children:i.role??r(`activity:agentOffice.agent`)})]}),(0,q.jsxs)(`span`,{className:`agent-office__lounge-meta`,children:[u!==void 0&&(0,q.jsx)(`span`,{children:Dn(u,t)}),l>0&&(0,q.jsxs)(`span`,{className:`agent-office__lounge-mail`,children:[(0,q.jsx)(_,{"aria-hidden":`true`}),` `,l]})]})]},e.key)})})]})}function Vn({office:e,now:t}){let{t:n}=C(),{client:r,agents:i,stats:a}=e,o=r.lastHeartbeatAt?Date.parse(r.lastHeartbeatAt):NaN,s=Number.isFinite(o)&&t-o<2e4,c=Number.isFinite(o)&&!s,l=i.some(({agent:e})=>e.presenceSource===`registry`),u=s?`VERIFIED`:c?`DELAYED`:l?`REGISTRY`:`LOCAL`,d=i.some(({agent:e})=>e.recentTools!==void 0||e.activity!==void 0),f=i.some(({agent:e})=>e.toolCalls>0&&e.recentTools===void 0&&e.activity===void 0);return(0,q.jsxs)(`header`,{className:`agent-office__client-header`,children:[(0,q.jsxs)(`div`,{className:`agent-office__client-title`,children:[(0,q.jsx)(`span`,{className:`agent-office__client-icon`,children:(0,q.jsx)(te,{"aria-hidden":`true`})}),(0,q.jsxs)(`div`,{className:`agent-office__client-copy`,children:[(0,q.jsx)(`strong`,{children:r.label}),(0,q.jsx)(`span`,{children:r.sublabel||r.sessionId})]}),(0,q.jsxs)(`div`,{className:`agent-office__client-presence`,children:[(0,q.jsxs)(`span`,{className:`agent-office__client-agent-count`,children:[i.length,` `,n(`activity:agentOffice.agents`)]}),(0,q.jsxs)(`span`,{className:U(`agent-office__presence-chip`,!c&&`is-live`,c&&`is-legacy`),children:[(0,q.jsx)(D,{"aria-hidden":`true`}),` `,u]}),(0,q.jsxs)(`span`,{className:`agent-office__presence-chip`,children:[(0,q.jsx)(Me,{"aria-hidden":`true`}),` `,On(r.startedAt,t),` UP`]}),(0,q.jsxs)(`span`,{className:U(`agent-office__presence-chip`,f?`is-legacy`:d&&`is-telemetry`),children:[(0,q.jsx)(x,{"aria-hidden":`true`}),f?`RECONNECT`:d?`TOOLS LIVE`:`READY`]})]})]}),(0,q.jsxs)(`fieldset`,{className:`agent-office__client-stats`,"aria-label":n(`activity:agentOffice.sessionActivityTotals`),children:[(0,q.jsxs)(`span`,{title:n(`activity:agentOffice.uniqueFilesTouched`),children:[(0,q.jsx)(ee,{}),` `,(0,q.jsx)(`strong`,{children:a.files}),` `,n(`activity:agentOffice.files`)]}),(0,q.jsxs)(`span`,{title:n(`activity:agentOffice.fileReads`),children:[(0,q.jsx)(R,{}),` `,(0,q.jsx)(`strong`,{children:a.reads}),` `,n(`activity:agentOffice.read`)]}),(0,q.jsxs)(`span`,{title:n(`activity:agentOffice.filesWritten`),children:[(0,q.jsx)(L,{}),` `,(0,q.jsx)(`strong`,{children:a.writes}),` `,n(`activity:agentOffice.write`)]}),(0,q.jsxs)(`span`,{title:n(`activity:agentOffice.filesEdited`),children:[(0,q.jsx)(L,{}),` `,(0,q.jsx)(`strong`,{children:a.edits}),` `,n(`activity:agentOffice.edit`)]}),(0,q.jsxs)(`span`,{className:`agent-office__client-delta`,title:n(`activity:agentOffice.linesAddedAndRemoved`),children:[(0,q.jsxs)(`strong`,{children:[`+`,a.linesAdded]}),` / `,(0,q.jsxs)(`b`,{children:[`−`,a.linesRemoved]})]}),(0,q.jsxs)(`span`,{title:n(`activity:agentOffice.terminalCommands`),children:[(0,q.jsx)(b,{}),` `,(0,q.jsx)(`strong`,{children:a.terminalCalls}),` `,n(`activity:agentOffice.term`)]}),(0,q.jsxs)(`span`,{title:n(`activity:agentOffice.incomingAndOutgoingMail`),children:[(0,q.jsx)(_,{}),` `,(0,q.jsx)(`strong`,{children:a.incomingMail}),`↓ `,(0,q.jsx)(`strong`,{children:a.outgoingMail}),`↑`]})]})]})}function Hn({office:e,now:t,onSelect:n}){let{t:r}=C(),{client:i}=e,a=i.todos!==void 0,o=i.todos??[],s=o.filter(e=>e.status!==`completed`),c=o.length-s.length,l=!!i.activeInstruction,u=i.activeInstruction??i.latestPrompt,d=i.latestPromptAt!==void 0&&t-i.latestPromptAt<3e4,f=()=>n({kind:`briefing`,officeLabel:i.label,prompt:u,promptAt:i.latestPromptAt,instructionActive:l,telemetryConnected:a,todos:o});return(0,q.jsxs)(`section`,{className:`agent-office__briefing`,"aria-label":r(`activity:agentOffice.officeBriefing`),children:[(0,q.jsxs)(`button`,{type:`button`,className:U(`agent-office__prompt-card`,l&&`is-active`,d&&`is-fresh`,!a&&`is-waiting`),onClick:f,children:[(0,q.jsx)(`span`,{className:`agent-office__briefing-icon is-prompt`,children:(0,q.jsx)(w,{"aria-hidden":`true`})}),(0,q.jsxs)(`span`,{className:`agent-office__briefing-copy`,children:[(0,q.jsx)(`span`,{children:r(l?`activity:agentOffice.activeInstruction`:`activity:agentOffice.leaderPrompt`)}),(0,q.jsx)(`strong`,{children:u??r(a?`activity:agentOffice.noPrompt`:`activity:agentOffice.telemetryWaiting`)})]}),l&&(0,q.jsxs)(`span`,{className:`agent-office__instruction-live`,children:[(0,q.jsx)(`i`,{"aria-hidden":`true`}),` `,r(`activity:agentOffice.live`)]}),i.latestPromptAt!==void 0&&(0,q.jsx)(`time`,{dateTime:new Date(i.latestPromptAt).toISOString(),children:Dn(i.latestPromptAt,t)})]}),(0,q.jsxs)(`button`,{type:`button`,className:U(`agent-office__todo-board`,s.length>0&&`has-active`,!a&&`is-waiting`),onClick:f,children:[(0,q.jsxs)(`span`,{className:`agent-office__todo-heading`,children:[(0,q.jsxs)(`span`,{children:[(0,q.jsx)(O,{"aria-hidden":`true`}),` `,r(`activity:agentOffice.activeTodos`)]}),(0,q.jsx)(`strong`,{children:a?r(`activity:agentOffice.todoProgress`,{done:c,total:o.length}):r(`activity:agentOffice.syncWaiting`)})]}),(0,q.jsxs)(`span`,{className:`agent-office__todo-preview`,children:[a?s.length>0?s.slice(0,3).map(e=>(0,q.jsxs)(`span`,{className:U(`agent-office__todo-line`,`is-${e.status}`),children:[(0,q.jsx)(`i`,{"aria-hidden":`true`}),(0,q.jsx)(`span`,{children:e.activeForm||e.content})]},e.id)):(0,q.jsxs)(`span`,{className:`agent-office__todo-empty`,children:[(0,q.jsx)(re,{"aria-hidden":`true`}),o.length>0?r(`activity:agentOffice.allTodosDone`):r(`activity:agentOffice.noActiveTodos`)]}):(0,q.jsxs)(`span`,{className:`agent-office__todo-empty is-waiting`,children:[(0,q.jsx)(x,{"aria-hidden":`true`}),r(`activity:agentOffice.todoTelemetryWaiting`)]}),s.length>3&&(0,q.jsx)(`span`,{className:`agent-office__todo-more`,children:r(`activity:agentOffice.moreTodos`,{count:s.length-3})})]})]})]})}function Un(e){return e==null||!Number.isFinite(e)?`0`:e<1e3?String(Math.round(e)):e<1e6?`${(e/1e3).toFixed(1)}k`:`${(e/1e6).toFixed(1)}M`}function Wn(e,t){if(!e)return`never`;let n=Date.parse(e);if(!Number.isFinite(n))return`never`;let r=Math.max(0,Math.round((t-n)/1e3));return r<60?`${r}s ago`:r<3600?`${Math.round(r/60)}m ago`:r<86400?`${Math.round(r/3600)}h ago`:`${Math.round(r/86400)}d ago`}function Gn(e,t){if(!e)return``;let n=Date.parse(e);if(!Number.isFinite(n))return``;let r=Math.max(0,Math.round((t-n)/1e3));return r<60?`${r}s`:r<3600?`${Math.round(r/60)}m`:`${Math.round(r/3600)}h`}function Kn(e){if(!e)return;let t=e.split(`/`);return t[t.length-1]?.slice(0,18)}function qn(e,t=56){if(!e)return;let n=e.replace(/\s+/g,` `).trim();if(n)return n.length<=t?n:t<=1?`…`:`${n.slice(0,t-1).trimEnd()}…`}var Jn=370,Yn=640,Xn=380,Zn=190,Qn=150,$n=100;function er(e,t){if(e.length===0)return{positions:new Map,columns:0,rows:0,columnWidth:Xn};let n=Math.max(1,...e.map(e=>e.agentCount)),r=Math.max(Xn,Math.min(3,n)*Zn+80),i=e=>270+Math.max(1,...e.map(e=>Math.ceil(Math.max(1,e.agentCount)/3)))*Qn,a=Math.max(320,t.width),o=Math.max(240,t.height),s=1,c=-1/0,l=1/0;for(let t=1;t<=e.length;t+=1){let n=[];for(let r=0;r<e.length;r+=t)n.push(i(e.slice(r,r+t)));let u=n.length,d=Math.max(660,Math.min(t,e.length)*r),f=320+n.reduce((e,t)=>e+t,0)+Math.max(0,u-1)*$n,p=Math.min(a/d,o/f),m=Math.abs(Math.log(d/f/(a/o)));(p>c+1e-9||Math.abs(p-c)<=1e-9&&m<l)&&(s=t,c=p,l=m)}let u=new Map,d=Jn;for(let t=0;t<e.length;t+=s){let n=e.slice(t,t+s);n.forEach((e,t)=>{u.set(e.id,{x:600+(t-(n.length-1)/2)*r,y:d})}),d+=i(n)+$n}return{positions:u,columns:s,rows:Math.ceil(e.length/s),columnWidth:r}}function tr(e,t,n,r=Yn){let i=Math.min(3,n),a=Math.floor(t/i),o=t%i;return{x:e-(Math.min(i,n-a*i)-1)*Zn/2+o*Zn,y:r+a*Qn}}function nr(e){return e===`tui`?`tui`:e===`repl`||e===`cli`?`repl`:`webui`}function rr(e){return e===`tui`?`TUI`:e===`repl`?`REPL`:`WebUI`}function ir(e){switch(e){case`running`:case`active`:return`active`;case`idle`:return`idle`;case`completed`:return`completed`;case`failed`:case`error`:return`error`;case`stopped`:return`offline`;default:return`idle`}}function ar(e){if(e)return e.split(`/`).filter(Boolean).pop()??e}function or(e){let t=ar(e)??e??``;return t.length>10?`…${t.slice(-8)}`:t}function sr(e,t){let n=ar(t);if(n)return e.find(e=>ar(e.sessionId)===n)}function cr(e,t){let n=ir(t.status);return{officeId:`${e}__agent-${t.id}`,serverId:t.id,name:t.name??t.id,status:n,iteration:t.iteration??0,toolCalls:t.toolCalls??0,costUsd:t.costUsd??0,tokensIn:t.tokensIn??0,tokensOut:t.tokensOut??0,ctxPct:t.ctxPct,model:t.model,currentTool:t.currentTool,currentTask:t.description,taskId:t.taskId,presenceSource:`fleet`}}function lr(e,t){return e===`cli`?`CLI`:e===`repl`?`REPL`:rr(t)}function ur(e,t,n=[],r=new Map,i=Date.now()){let a=new Set,o=[];for(let n of e){let e=nr(n.clientType),r=lr(n.clientType,e),i=`client-${n.pid??n.sessionId}`,s=[],c=!1;for(let e of n.agents){a.add(e.id);let n=t.get(e.id),r=ir(n?.status??e.status);(r===`active`||r===`streaming`)&&(c=!0),s.push({officeId:`${i}__agent-${e.id}`,serverId:e.id,name:n?.name??e.name??e.id,status:r,iteration:n?.iteration??e.iterations??0,toolCalls:n?.toolCalls??e.toolCalls??0,costUsd:n?.costUsd??e.costUsd??0,tokensIn:n?.tokensIn??e.tokensIn??0,tokensOut:n?.tokensOut??e.tokensOut??0,ctxPct:n?.ctxPct??e.ctxPct,model:n?.model??e.model,lastActivityAt:e.lastActivityAt,currentTool:n?.currentTool??e.currentTool,currentTask:e.currentTask??n?.description,taskId:e.taskId??n?.taskId,recentTools:e.recentTools,recentMail:e.recentMail,activity:e.activity,presenceSource:`registry`})}let l=n.status===`closing`||n.status===`stale`||n.status===`lost`?`offline`:c?`active`:`idle`,u=n.agents.find(e=>e.id===`leader`);o.push({id:i,type:e,label:`${r} · ${n.pid?`PID ${n.pid}`:or(n.sessionId)}`,sublabel:[`session ${or(n.sessionId)}`,n.gitBranch?`⎇ ${n.gitBranch}`:``,n.workingDir?n.workingDir.split(/[\\/]/).filter(Boolean).pop():``].filter(Boolean).join(` · `),status:l,sessionId:n.sessionId,pid:n.pid,branch:n.gitBranch,workingDir:n.workingDir,startedAt:n.startedAt,lastHeartbeatAt:n.lastHeartbeatAt,latestPrompt:u?.latestPrompt,latestPromptAt:u?.latestPromptAt,activeInstruction:u?.status===`running`||u?.status===`streaming`?u.latestPrompt??u.currentTask:void 0,todos:u?.todos,agents:s})}for(let e of n.filter(e=>e.online)){let t=sr(o,e.sessionId);if(!t)continue;let n=e.name.trim().toLowerCase(),r=t.agents.find(t=>t.serverId===e.agentId||t.name.trim().toLowerCase()===n);r&&(a.add(e.agentId),r.mailboxId=e.agentId,r.role=e.role,r.currentTask=r.currentTask??e.currentTask,r.currentTool=r.currentTool??e.currentTool)}let s=[...t.values()].filter(e=>!a.has(e.id)),c,l=()=>{if(c)return c;let e=o.find(e=>e.type===`webui`);return e?(c=e,e):(c={id:`client-self`,type:`webui`,label:`This WebUI`,sublabel:`Web UI`,status:`idle`,agents:[]},o.push(c),c)};for(let e of s){let t=sr(o,e.sessionId)??l(),n=cr(t.id,e);(n.status===`active`||n.status===`streaming`)&&t.status!==`offline`&&(t.status=`active`),t.agents.push(n),a.add(e.id)}for(let[e,t]of r){if(a.has(e)||i-t.finishedAt>9e5)continue;let n=sr(o,t.agent.sessionId);n&&n.agents.push(cr(n.id,t.agent))}return o.length===0&&o.push({id:`client-self`,type:`webui`,label:`This WebUI`,sublabel:`Web UI · connecting…`,status:`idle`,agents:[]}),o}function dr(e){return e.startsWith(`tool`)?`hsl(var(--warning))`:e.startsWith(`mailbox`)?`hsl(var(--info))`:e.startsWith(`provider`)?`hsl(var(--primary))`:e.startsWith(`agent`)||e.startsWith(`subagent`)?`hsl(var(--success))`:e.includes(`error`)?`hsl(var(--destructive))`:`hsl(var(--primary))`}var fr=new Set([`completed`,`failed`,`timeout`,`stopped`]);function pr(e){let t=(0,K.useRef)(new Map).current;return(0,K.useMemo)(()=>{let n=Date.now(),r=new Set;for(let i of e.values())if(r.add(i.id),fr.has(i.status)){let e=t.get(i.id);e?e.agent=i:t.set(i.id,{agent:i,finishedAt:i.completedAt??n})}else t.delete(i.id);for(let[e,n]of[...t.entries()])!r.has(e)&&!fr.has(n.agent.status)&&t.set(e,{agent:{...n.agent,status:`stopped`},finishedAt:n.finishedAt});for(let[e,r]of t)n-r.finishedAt>9e5&&t.delete(e);return{map:t,now:n}},[e,t])}function mr(){let{t:e}=C(),t=Qe(e=>e.liveSessions),r=Qe(e=>e.aggregate),i=n(e=>e.agents),o=$e(e=>e.agents),s=$e(e=>e.messages),c=u(e=>e.toolEvents),l=a(e=>e.projectName),d=pr(i),[f,p]=(0,K.useState)(null),m=(0,K.useMemo)(()=>ur(t,i,o,d.map,d.now),[t,i,o,d]),h=(0,K.useMemo)(()=>m.flatMap(e=>e.agents.map(t=>{let n=jn(an(c,t.serverId,e.sessionId),$t(t.recentTools,t.serverId,e.sessionId),An(t,e,i.get(t.serverId)?.toolLog??[])),r=t.status===`active`||t.status===`streaming`,a=n.find(e=>e.status===`running`);!a&&r&&t.currentTool&&(a=on(t.serverId,t.currentTool,e.sessionId));let o=a??n[0],l=n.filter(e=>e.status!==`running`).slice(0,6),u=Mn(en(t.recentMail),rn(s,t,e.sessionId));return{key:t.officeId,client:e,agent:t,calls:n,current:a,display:o,history:l,mail:u}})),[m,i,s,c]),g=(0,K.useMemo)(()=>m.map(e=>{let t=h.filter(t=>t.client.id===e.id);return{client:e,agents:t,stats:kn(t)}}).filter(e=>e.agents.length>0),[m,h]),v=h.filter(({agent:e})=>e.status===`active`||e.status===`streaming`).length,y=l||t.find(e=>e.projectName)?.projectName||e(`activity:office.fleetHq`),b=Date.now();return(0,q.jsxs)(`div`,{className:`agent-office`,children:[(0,q.jsxs)(`header`,{className:`agent-office__header`,children:[(0,q.jsxs)(`div`,{className:`agent-office__title`,children:[(0,q.jsx)(`span`,{className:`agent-office__brand-mark`,children:(0,q.jsx)(te,{"aria-hidden":`true`})}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`span`,{children:e(`activity:agentOffice.liveProjectOffice`)}),(0,q.jsx)(`h1`,{children:y})]})]}),(0,q.jsxs)(`div`,{className:`agent-office__live-pill`,children:[(0,q.jsx)(`span`,{}),` `,e(`activity:agentOffice.live`)]}),(0,q.jsxs)(`div`,{className:`agent-office__summary`,children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(H,{}),(0,q.jsx)(`strong`,{children:h.length}),(0,q.jsx)(`span`,{children:e(`activity:agentOffice.agents`)})]}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(T,{}),(0,q.jsx)(`strong`,{children:v}),(0,q.jsx)(`span`,{children:e(`activity:agentOffice.working`)})]}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(x,{}),(0,q.jsx)(`strong`,{children:r.toolCalls.toLocaleString()}),(0,q.jsx)(`span`,{children:e(`activity:agentOffice.toolCalls`)})]})]})]}),(0,q.jsx)(`main`,{className:`agent-office__floor`,children:h.length>0?g.map(t=>{let n=t.agents.filter(zn),r=t.agents.filter(e=>!zn(e)),i=tn(n,b),a=new Set(i.map(e=>e.id));return(0,q.jsxs)(`section`,{className:`agent-office__client-office`,children:[(0,q.jsx)(Vn,{office:t,now:b}),(0,q.jsx)(Hn,{office:t,now:b,onSelect:p}),n.length>0&&(0,q.jsxs)(`div`,{className:`agent-office__column-headings`,"aria-hidden":`true`,children:[(0,q.jsx)(`span`,{children:e(`activity:agentOffice.team`)}),(0,q.jsx)(`span`,{children:e(`activity:agentOffice.liveDesk`)}),(0,q.jsx)(`span`,{children:e(`activity:agentOffice.lastActions`)})]}),(0,q.jsxs)(`div`,{className:`agent-office__client-desks`,children:[n.map(e=>(0,q.jsx)(Rn,{model:e,now:b,onSelect:p,routedMailIds:a},e.key)),i.length>0&&(0,q.jsx)(`div`,{className:`agent-office__mail-routes`,"aria-hidden":`true`,children:i.map(e=>(0,q.jsx)(`div`,{className:`agent-office__mail-route`,style:{"--from":`${(e.fromIndex+.5)/n.length*100}%`,"--to":`${(e.toIndex+.5)/n.length*100}%`},children:(0,q.jsx)(`span`,{className:`agent-office__mail-route-parcel`,children:(0,q.jsx)(_,{"aria-hidden":`true`})})},e.id))}),n.length===0&&(0,q.jsxs)(`div`,{className:`agent-office__desks-empty`,children:[(0,q.jsx)(z,{"aria-hidden":`true`}),e(`activity:agentOffice.desksEmpty`)]})]}),r.length>0&&(0,q.jsx)(Bn,{agents:r,now:b,onSelect:p})]},t.client.id)}):(0,q.jsxs)(`div`,{className:`agent-office__empty-state`,children:[(0,q.jsx)(`span`,{children:(0,q.jsx)(D,{"aria-hidden":`true`})}),(0,q.jsx)(`h2`,{children:e(`activity:agentOffice.readyTitle`)}),(0,q.jsx)(`p`,{children:e(`activity:agentOffice.readyBody`)})]})}),(0,q.jsxs)(`footer`,{className:`agent-office__footer`,children:[(0,q.jsxs)(`span`,{children:[(0,q.jsx)(`span`,{className:`agent-office__status-dot is-active`}),` `,e(`activity:agentOffice.liveEvent`)]}),(0,q.jsxs)(`span`,{children:[(0,q.jsx)(me,{}),` `,e(`activity:agentOffice.connectedSessions`,{count:t.length})]}),(0,q.jsxs)(`span`,{children:[(0,q.jsx)(Me,{}),` `,e(`activity:agentOffice.detailHint`)]})]}),f&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`button`,{type:`button`,className:`agent-office__detail-backdrop`,onClick:()=>p(null),"aria-label":e(`activity:agentOffice.closeToolDetails`)}),(0,q.jsx)(gn,{selected:f,onClose:()=>p(null)})]})]})}function hr(e){if(e<1e3)return`${e}ms`;let t=Math.round(e/100);return t<600?`${(t/10).toFixed(1)}s`:`${Math.floor(t/600)}m ${Math.round(t%600/10)}s`}var gr={user:{Icon:Se,labelKey:`activity:message.roleYou`,avatarBg:`bg-primary`,avatarColor:`text-primary-foreground`,avatarRing:`ring-2 ring-offset-2 ring-offset-background ring-primary/20`,bubbleBg:`bg-transparent`,bubbleBorder:`border-primary/40`,textColor:`text-foreground`},assistant:{Icon:H,labelKey:`activity:message.roleAssistant`,avatarBg:`bg-accent`,avatarColor:`text-accent-foreground`,avatarRing:`ring-2 ring-offset-2 ring-offset-background ring-accent/20`,bubbleBg:`bg-card`,bubbleBorder:`border-border`,textColor:`text-foreground`},tool:{Icon:V,labelKey:`activity:message.roleTool`,avatarBg:`bg-secondary`,avatarColor:`text-secondary-foreground`,avatarRing:`ring-2 ring-offset-2 ring-offset-background ring-secondary/20`,bubbleBg:`bg-muted/80`,bubbleBorder:`border-border`,textColor:`text-foreground`},system:{Icon:H,labelKey:`activity:transcript.kindSystem`,avatarBg:`bg-muted`,avatarColor:`text-muted-foreground`,avatarRing:`ring-2 ring-offset-2 ring-offset-background ring-muted/20`,bubbleBg:`bg-muted/50`,bubbleBorder:`border-border`,textColor:`text-muted-foreground`},error:{Icon:g,labelKey:`activity:transcript.kindError`,avatarBg:`bg-destructive`,avatarColor:`text-destructive-foreground`,avatarRing:`ring-2 ring-offset-2 ring-offset-background ring-destructive/20`,bubbleBg:`bg-destructive/5`,bubbleBorder:`border-destructive/20`,textColor:`text-destructive`}};function _r({entry:e}){let{t}=C();return e.role===`error`?(0,q.jsx)(lt,{text:e.text}):e.role===`tool`?(0,q.jsxs)(`div`,{className:`flex flex-col gap-1.5 tool-details`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 text-sm font-medium text-foreground`,children:[(0,q.jsx)(V,{className:`h-3 w-3`}),(0,q.jsx)(`span`,{className:`font-mono`,children:e.tool??t(`activity:watch.toolFallback`)}),e.durationMs!==void 0&&(0,q.jsxs)(`span`,{className:`ml-auto text-[10px] text-muted-foreground font-normal tabular-nums`,children:[(0,q.jsx)(y,{className:`h-3 w-3 inline mr-0.5 align-text-bottom`}),hr(e.durationMs)]})]}),e.input!==void 0&&e.input!==null&&(0,q.jsx)(`div`,{className:`p-3 bg-muted/50 rounded-lg overflow-x-auto`,children:(0,q.jsx)(at,{input:e.input})}),e.output!==void 0&&e.output!==null?(0,q.jsx)(`div`,{className:`text-sm leading-relaxed markdown-content`,children:typeof e.output==`string`?(0,q.jsx)(ct,{remarkPlugins:[rt],rehypePlugins:dt,components:ut,children:e.output}):(0,q.jsx)(`pre`,{className:`whitespace-pre-wrap font-mono text-xs bg-card rounded-lg p-2 border border-border overflow-x-auto`,children:JSON.stringify(e.output,null,2)})}):e.text?(0,q.jsx)(`div`,{className:`text-sm leading-relaxed markdown-content`,children:(0,q.jsx)(ct,{remarkPlugins:[rt],rehypePlugins:dt,components:ut,children:e.text})}):null,e.isError&&(0,q.jsxs)(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 px-3 py-2`,children:[(0,q.jsx)(`span`,{className:`text-xs font-medium text-destructive`,children:t(`activity:watch.toolFailed`)}),e.text&&(0,q.jsx)(`pre`,{className:`mt-1 text-xs whitespace-pre-wrap text-destructive/80`,children:e.text})]})]}):(0,q.jsx)(`div`,{className:`text-sm leading-relaxed markdown-content`,children:(0,q.jsx)(ct,{remarkPlugins:[rt],rehypePlugins:dt,components:ut,children:e.text})})}function vr({entry:e,isContinuation:t=!1}){let{t:n}=C(),r=gr[e.role],i=r.Icon;return(0,q.jsxs)(`div`,{className:`group flex gap-3 animate-message msg-bubble rounded-lg transition-shadow`,children:[t?(0,q.jsx)(`div`,{className:`flex-shrink-0 w-8`}):(0,q.jsx)(`div`,{className:U(`flex-shrink-0 w-8 h-8 rounded-full flex items-center justify-center`,r.avatarBg,r.avatarColor,r.avatarRing),children:(0,q.jsx)(i,{className:`h-4 w-4`})}),(0,q.jsxs)(`div`,{className:`flex flex-col gap-1.5 min-w-0 flex-1`,children:[!t&&(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(`span`,{className:U(`text-xs font-medium`,r.textColor),children:e.role===`tool`&&e.tool?e.tool:n(r.labelKey)}),(0,q.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:new Date(e.ts).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})}),e.role===`tool`&&e.durationMs!==void 0&&(0,q.jsxs)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[`· `,hr(e.durationMs)]})]}),(0,q.jsx)(`div`,{className:U(`rounded-2xl px-4 py-3 border`,e.role===`user`&&`rounded-br-md`,e.role===`assistant`&&`rounded-bl-md`,e.role===`tool`&&`rounded-bl-sm`,e.role===`system`&&`rounded-bl-sm opacity-70`,e.role===`error`&&`rounded-bl-sm`,r.bubbleBg,r.bubbleBorder),children:(0,q.jsx)(`div`,{className:U(`text-sm leading-relaxed markdown-content`,r.textColor),children:(0,q.jsx)(_r,{entry:e})})}),e.text&&e.role!==`error`&&(0,q.jsx)(`div`,{className:`opacity-0 group-hover:opacity-100 transition-opacity`,children:(0,q.jsx)(ot,{text:e.text,label:n(`common:action.copy`)})})]})]})}var yr=[`steer`,`ask`,`assign`,`note`],br=2500;function xr({sessionId:e,limit:t=200}){let[n,r]=(0,K.useState)(null),{t:i}=C(),[a,o]=(0,K.useState)(null),[s,c]=(0,K.useState)(``),[l,u]=(0,K.useState)(!1),[d,f]=(0,K.useState)(null),[p,m]=(0,K.useState)(`steer`),[h,g]=(0,K.useState)(`high`),[_,v]=(0,K.useState)([]),[y,b]=(0,K.useState)(!1),x=(0,K.useRef)(null),S=(0,K.useRef)(!0),w=(0,K.useRef)(!0),T=Qe(e=>e.liveSessions),E=(0,K.useMemo)(()=>T.find(t=>t.sessionId===e),[T,e]),D=(0,K.useMemo)(()=>{let e=E;return e?`${e.status}|${e.agents.map(e=>`${e.id}:${e.status}:${e.toolCalls??0}:${e.iterations??0}`).join(`,`)}`:``},[E]),O=E?.status===`active`||(E?.agents.some(e=>e.status===`running`||e.status===`streaming`)??!1),k=(0,K.useMemo)(()=>{if(!E)return null;let e=E.agents.find(e=>e.status===`running`||e.status===`streaming`);return e?.currentTool?`🔧 ${e.currentTool}`:e?i(`activity:sessionWatch.working`,{name:e.name??e.id}):null},[E,i]),A=(0,K.useMemo)(()=>{if(!E)return null;let e=E.agents.find(e=>e.partialText&&(e.status===`streaming`||e.status===`running`))??E.agents.find(e=>e.partialText);return e?.partialText?{label:e.id===`leader`?i(`activity:sessionWatch.claude`):e.name||e.id,text:e.partialText}:null},[E,i]),j=(0,K.useCallback)(async()=>{try{let n=await fetch(`/api/sessions/${encodeURIComponent(e)}/events?limit=${t}`);if(!n.ok)throw Error(`HTTP ${n.status}`);let i=await n.json();w.current&&(r(i),o(null))}catch(e){w.current&&o(e instanceof Error?e.message:String(e))}},[e,t]),M=(0,K.useCallback)(async()=>{try{let t=await fetch(`/api/sessions/${encodeURIComponent(e)}/mailbox`);if(!t.ok)return;let n=await t.json();w.current&&Array.isArray(n.thread)&&v(n.thread)}catch{}},[e]);(0,K.useEffect)(()=>{w.current=!0,r(null),o(null),v([]),j(),M();let e=setInterval(()=>{document.hidden||(j(),M())},br);return()=>{w.current=!1,clearInterval(e)}},[j,M]),(0,K.useEffect)(()=>{D&&j()},[D,j]),(0,K.useEffect)(()=>{S.current&&x.current&&(x.current.scrollTop=x.current.scrollHeight)},[n,A]);let N=()=>{let e=x.current;e&&(S.current=e.scrollHeight-e.scrollTop-e.clientHeight<40)},ee=async()=>{let t=s.trim();if(!(!t||l)){u(!0),f(null);try{let n=await fetch(`/api/sessions/${encodeURIComponent(e)}/message`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({text:t,type:p,priority:h})});if(!n.ok)throw Error(`HTTP ${n.status}`);c(``),f(O?ne.t(`activity:sessionWatch.sentRunning`):ne.t(`activity:sessionWatch.sentIdle`)),M()}catch(e){f(ne.t(`activity:sessionWatch.sentFailed`,{error:e instanceof Error?e.message:String(e)}))}finally{u(!1)}}},P=async()=>{if(!y){b(!0),f(null);try{let t=await fetch(`/api/sessions/${encodeURIComponent(e)}/interrupt`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({reason:ne.t(`activity:sessionWatch.interruptReason`)})});if(!t.ok)throw Error(`HTTP ${t.status}`);f(ne.t(`activity:sessionWatch.interruptSent`)),M()}catch(e){f(ne.t(`activity:sessionWatch.interruptFailed`,{error:e instanceof Error?e.message:String(e)}))}finally{b(!1)}}},F=n?.entries??[];return(0,q.jsxs)(`div`,{className:`flex h-full min-h-0 min-w-0 flex-col`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between mb-1.5 shrink-0`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] uppercase tracking-wide text-muted-foreground`,children:[(0,q.jsx)(`span`,{className:U(`h-1.5 w-1.5 rounded-full`,O?`bg-success animate-pulse`:`bg-muted-foreground`)}),i(`activity:sessionWatch.liveStream`)]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[n&&(0,q.jsxs)(`div`,{className:`text-[10px] text-muted-foreground`,children:[i(`activity:sessionWatch.events`,{count:n.total}),` · `,n.status]}),O&&(0,q.jsx)(`button`,{type:`button`,onClick:()=>void P(),disabled:y,title:i(`activity:sessionWatch.interruptTitle`),className:`rounded border border-destructive/40 bg-destructive/15 px-1.5 py-0.5 text-[10px] text-destructive hover:bg-destructive/25 disabled:opacity-40 transition-colors`,children:i(y?`activity:sessionWatch.interrupting`:`activity:sessionWatch.interrupt`)})]})]}),k&&(0,q.jsxs)(`div`,{className:`mb-1.5 shrink-0 text-[10px] text-foreground truncate`,children:[`▶ `,k]}),a&&(0,q.jsxs)(`div`,{className:`text-[11px] text-destructive mb-1 shrink-0`,children:[`· `,a]}),(0,q.jsxs)(`div`,{ref:x,onScroll:N,className:`min-h-0 min-w-0 flex-1 overflow-y-auto overscroll-contain space-y-1.5 pr-1`,children:[F.length===0&&!a&&(0,q.jsx)(`div`,{className:`text-[11px] text-muted-foreground italic`,children:i(`activity:sessionWatch.loading`)}),F.map((e,t)=>(0,q.jsx)(vr,{entry:e,isContinuation:t>0&&F[t-1].role===e.role},`${e.ts}-${t}`)),A&&(0,q.jsxs)(`div`,{className:`flex gap-3 animate-message`,children:[(0,q.jsx)(`div`,{className:`flex-shrink-0 w-8 h-8 rounded-full flex items-center justify-center bg-accent text-accent-foreground ring-2 ring-offset-2 ring-offset-background ring-accent/20`,children:(0,q.jsx)(H,{className:`h-4 w-4 animate-pulse`})}),(0,q.jsxs)(`div`,{className:`flex flex-col gap-1.5 max-w-[85%] min-w-0`,children:[(0,q.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground px-1`,children:A.label}),(0,q.jsx)(`div`,{className:`rounded-2xl rounded-bl-md px-4 py-3 bg-card border border-border`,children:(0,q.jsxs)(`span`,{className:`text-sm leading-relaxed text-foreground whitespace-pre-wrap break-words`,children:[A.text,(0,q.jsx)(`span`,{className:`animate-pulse text-primary`,children:`▋`})]})})]})]})]}),_.length>0&&(0,q.jsxs)(`div`,{className:`mt-2 pt-2 border-t border-border shrink-0 max-h-28 overflow-y-auto space-y-1`,children:[(0,q.jsx)(`div`,{className:`text-[9px] uppercase tracking-wide text-muted-foreground`,children:i(`activity:mailbox.messages`)}),_.slice(-6).map(e=>{let t=e.completed?i(`activity:sessionWatch.done`):e.readByLeader?i(`activity:sessionWatch.read`):i(`activity:sessionWatch.delivered`);return(0,q.jsxs)(`div`,{className:`text-[10px] leading-snug`,children:[(0,q.jsx)(`span`,{className:U(`font-semibold mr-1.5`,e.fromLeader?`text-accent`:`text-primary`),children:e.fromLeader?i(`activity:sessionWatch.agent`):i(`activity:sessionWatch.you`)}),(0,q.jsx)(`span`,{className:`text-foreground whitespace-pre-wrap break-words`,children:e.body}),!e.fromLeader&&(0,q.jsx)(`span`,{className:U(`ml-1.5 text-[9px]`,e.completed?`text-success`:e.readByLeader?`text-primary`:`text-muted-foreground`),children:t})]},e.id)})]}),(0,q.jsxs)(`div`,{className:`mt-2 pt-2 border-t border-border shrink-0`,children:[(0,q.jsxs)(`div`,{className:`mb-1 flex items-center gap-1.5`,children:[(0,q.jsx)(`select`,{value:p,onChange:e=>m(e.target.value),title:i(`activity:sessionWatch.msgType.${p}Hint`),className:`rounded bg-muted border border-border px-1.5 py-0.5 text-[10px] text-foreground focus:outline-none focus:ring-1 focus:ring-ring`,children:yr.map(e=>(0,q.jsx)(`option`,{value:e,children:i(`activity:sessionWatch.msgType.${e}Label`)},e))}),(0,q.jsxs)(`select`,{value:h,onChange:e=>g(e.target.value),title:i(`activity:sessionWatch.priority`),className:`rounded bg-muted border border-border px-1.5 py-0.5 text-[10px] text-foreground focus:outline-none focus:ring-1 focus:ring-ring`,children:[(0,q.jsx)(`option`,{value:`high`,children:`high`}),(0,q.jsx)(`option`,{value:`normal`,children:`normal`}),(0,q.jsx)(`option`,{value:`low`,children:`low`})]})]}),(0,q.jsxs)(`div`,{className:`flex items-end gap-1.5`,children:[(0,q.jsx)(`textarea`,{value:s,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),ee())},rows:2,placeholder:i(`activity:sessionWatch.placeholder`,{label:i(`activity:sessionWatch.msgType.${p}Label`)}),className:`flex-1 resize-none rounded-md bg-muted border border-border px-2 py-1 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring`}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>void ee(),disabled:l||!s.trim(),className:`shrink-0 rounded-md bg-primary text-primary-foreground px-2.5 py-1.5 text-xs hover:bg-primary/90 disabled:opacity-40 disabled:cursor-not-allowed transition-colors`,children:l?`…`:i(`activity:sessionWatch.send`)})]}),d&&(0,q.jsx)(`div`,{className:`mt-1 text-[10px] text-muted-foreground`,children:d}),(0,q.jsx)(`div`,{className:`mt-0.5 text-[9px] text-muted-foreground`,children:i(`activity:sessionWatch.sendHint`)})]})]})}var Q={primary:`hsl(var(--primary))`,info:`hsl(var(--info))`,success:`hsl(var(--success))`,warning:`hsl(var(--warning))`,destructive:`hsl(var(--destructive))`,muted:`hsl(var(--muted-foreground))`},Sr=.12;function Cr(e){return Math.min(100,Math.max(0,e??0))}function wr({status:e,small:t,activity:n=0}){let r=t?`w-2 h-2`:`w-3 h-3`,i=t?4+n*4:6+n*6,a={idle:`bg-muted-foreground`,active:`bg-success`,streaming:`bg-primary`,completed:`bg-primary`,error:`bg-destructive`,offline:`bg-muted-foreground/60`},o={idle:Q.muted,active:Q.success,streaming:Q.primary,completed:Q.primary,error:Q.destructive,offline:Q.muted};return(0,q.jsx)(`span`,{className:U(`rounded-full`,r,n>0&&`animate-pulse`,a[e]),style:{boxShadow:n>0?`0 0 ${i}px ${o[e]}`:void 0}})}function Tr(){let e={opacity:0,width:1,height:1,minWidth:0,border:`none`,background:`transparent`};return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(Pe,{type:`target`,position:ze.Top,style:e,isConnectable:!1}),(0,q.jsx)(Pe,{type:`source`,position:ze.Bottom,style:e,isConnectable:!1})]})}function Er({data:e}){let{t}=C();return(0,q.jsxs)(`div`,{className:`mt-2 flex items-center justify-between border-t border-border/60 pt-1.5 text-[10px] text-muted-foreground`,children:[(0,q.jsxs)(`span`,{children:[(0,q.jsx)(`span`,{className:`font-mono text-foreground`,children:e.agentCount??0}),` `,t(`activity:office.agentsSuffix`)]}),e.startedAt&&(0,q.jsx)(`span`,{children:t(`activity:office.upPrefix`,{time:Gn(e.startedAt,Date.now())})})]})}function Dr({data:e}){let{t}=C(),n=e.status===`active`||e.status===`streaming`,r=e.status===`error`,i=e.status===`offline`,a=e.color||Q.info;return(0,q.jsxs)(`div`,{className:U(`rounded-xl border-2 p-4 min-w-[180px] transition-all backdrop-blur-sm`,n&&`shadow-lg shadow-primary/15`,r&&`border-destructive/50 bg-destructive/10`,i&&`border-border/70 bg-muted/35 opacity-60`,!n&&!r&&!i&&`border-primary/30 bg-primary/10`),children:[(0,q.jsx)(Tr,{}),(0,q.jsxs)(`div`,{className:`flex items-center gap-3 mb-3`,children:[(0,q.jsx)(`div`,{className:U(`flex items-center justify-center w-10 h-10 rounded-lg`,n?`bg-primary/15`:`bg-primary/10`),children:(0,q.jsx)(F,{className:`h-5 w-5`,style:{color:a}})}),(0,q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,q.jsx)(`div`,{className:`text-xs font-bold truncate`,style:{color:a},children:e.label}),(0,q.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:t(`activity:office.webuiClient`)})]}),(0,q.jsx)(wr,{status:e.status,activity:e.vizActivity??0})]}),e.sublabel&&(0,q.jsx)(`div`,{className:`mb-2 truncate text-[10px] text-muted-foreground`,children:e.sublabel}),(0,q.jsx)(`div`,{className:`flex items-center gap-2 text-[10px] text-muted-foreground`,children:i?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(ce,{className:`h-3 w-3 text-muted-foreground`}),(0,q.jsx)(`span`,{children:t(`activity:office.disconnected`)})]}):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(D,{className:`h-3 w-3 text-success`}),(0,q.jsx)(`span`,{children:t(`activity:office.connected`)})]})}),n&&(0,q.jsx)(`div`,{className:`mt-2 h-1 overflow-hidden rounded-full bg-primary/20`,children:(0,q.jsx)(`div`,{className:`h-full animate-pulse bg-primary`,style:{width:`60%`}})}),(0,q.jsx)(Er,{data:e})]})}function Or({data:e}){let{t}=C(),n=e.status===`active`||e.status===`streaming`,r=e.status===`error`,i=e.color||Q.success;return(0,q.jsxs)(`div`,{className:U(`rounded-xl border-2 p-4 min-w-[180px] transition-all backdrop-blur-sm`,n&&`shadow-lg shadow-success/15`,r&&`border-destructive/50 bg-destructive/10`,!n&&!r&&`border-success/30 bg-success/10`),children:[(0,q.jsx)(Tr,{}),(0,q.jsxs)(`div`,{className:`flex items-center gap-3 mb-3`,children:[(0,q.jsx)(`div`,{className:U(`flex items-center justify-center w-10 h-10 rounded-lg`,n?`bg-success/15`:`bg-success/10`),children:(0,q.jsx)(V,{className:`h-5 w-5`,style:{color:i}})}),(0,q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,q.jsx)(`div`,{className:`text-xs font-bold truncate`,style:{color:i},children:e.label}),(0,q.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:t(`activity:office.tuiClient`)})]}),(0,q.jsx)(wr,{status:e.status,activity:e.vizActivity??0})]}),e.sublabel&&(0,q.jsx)(`div`,{className:`mb-2 truncate text-[10px] text-muted-foreground`,children:e.sublabel}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] text-muted-foreground`,children:[(0,q.jsx)(V,{className:`h-3 w-3 text-success`}),(0,q.jsx)(`span`,{children:t(`activity:office.terminal`)})]}),(0,q.jsx)(Er,{data:e})]})}function kr({data:e}){let{t}=C(),n=e.status===`active`||e.status===`streaming`,r=e.color||Q.warning;return(0,q.jsxs)(`div`,{className:U(`rounded-xl border-2 p-4 min-w-[160px] transition-all backdrop-blur-sm`,n&&`shadow-lg shadow-warning/15`,!n&&`border-warning/30 bg-warning/10`),children:[(0,q.jsx)(Tr,{}),(0,q.jsxs)(`div`,{className:`flex items-center gap-3 mb-3`,children:[(0,q.jsx)(`div`,{className:U(`flex items-center justify-center w-10 h-10 rounded-lg`,n?`bg-warning/15`:`bg-warning/10`),children:(0,q.jsx)(V,{className:`h-5 w-5`,style:{color:r}})}),(0,q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,q.jsx)(`div`,{className:`text-xs font-bold truncate`,style:{color:r},children:e.label}),(0,q.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:t(`activity:office.repl`)})]}),(0,q.jsx)(wr,{status:e.status,activity:e.vizActivity??0})]}),e.sublabel&&(0,q.jsx)(`div`,{className:`mb-1 truncate text-[10px] text-muted-foreground`,children:e.sublabel}),(0,q.jsx)(Er,{data:e})]})}function Ar({data:e}){let{t}=C(),n=e.status===`active`||e.status===`streaming`,r=e.color||Q.primary;return(0,q.jsxs)(`div`,{className:`relative min-w-[200px] rounded-xl border-2 border-border/70 bg-card/90 p-4 shadow-lg backdrop-blur-sm transition-all`,children:[(0,q.jsx)(Tr,{}),(0,q.jsx)(`div`,{className:`absolute -top-3 left-1/2 -translate-x-1/2 rounded-full bg-primary px-2 py-0.5 text-[11px] font-bold text-primary-foreground`,children:t(`activity:office.coordinator`)}),(0,q.jsxs)(`div`,{className:`flex items-center gap-3 mb-3 mt-2`,children:[(0,q.jsx)(`div`,{className:U(`flex items-center justify-center w-12 h-12 rounded-xl`,n?`bg-primary/15`:`bg-primary/10`),children:(0,q.jsx)(de,{className:`h-6 w-6`,style:{color:r}})}),(0,q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,q.jsx)(`div`,{className:`text-sm font-bold truncate`,style:{color:r},children:e.label}),(0,q.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:e.sublabel||t(`activity:office.fleetSummary`)})]}),(0,q.jsx)(wr,{status:e.status,activity:e.vizActivity??0})]}),(0,q.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 text-[10px] mb-2`,children:[(0,q.jsxs)(`div`,{className:`rounded bg-muted/40 p-1.5 text-center`,children:[(0,q.jsxs)(`div`,{className:`font-mono`,children:[(0,q.jsx)(`span`,{className:`text-success`,children:e.agentsActive||0}),(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:` / `}),(0,q.jsx)(`span`,{className:`text-primary`,children:e.agentsTotal||0})]}),(0,q.jsx)(`div`,{className:`text-muted-foreground`,children:t(`activity:officeMap.agents`)})]}),(0,q.jsxs)(`div`,{className:`rounded bg-muted/40 p-1.5 text-center`,children:[(0,q.jsx)(`div`,{className:`font-mono text-warning`,children:(e.toolCalls||0).toLocaleString()}),(0,q.jsx)(`div`,{className:`text-muted-foreground`,children:t(`activity:office.toolCallsLabel`)})]}),(0,q.jsxs)(`div`,{className:`rounded bg-muted/40 p-1.5 text-center`,children:[(0,q.jsx)(`div`,{className:`font-mono text-foreground`,children:Un(e.tokensIn)}),(0,q.jsx)(`div`,{className:`text-muted-foreground`,children:t(`activity:office.tokensLabel`)})]}),(0,q.jsxs)(`div`,{className:`rounded bg-muted/40 p-1.5 text-center`,children:[(0,q.jsxs)(`div`,{className:`font-mono text-success`,children:[`$`,(e.costUsd||0).toFixed(3)]}),(0,q.jsx)(`div`,{className:`text-muted-foreground`,children:t(`activity:office.cost`)})]})]}),n&&(0,q.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] text-primary`,children:[(0,q.jsx)(`span`,{className:`h-2 w-2 animate-pulse rounded-full bg-primary`}),t(`activity:office.coordinatingFleet`)]})]})}function jr({data:e}){let{t}=C(),n=e.status===`active`||e.status===`streaming`,r=e.status===`error`,i=e.status===`completed`,a=e.color||Q.primary,o=Cr(e.ctxPct);return(0,q.jsxs)(`div`,{className:U(`w-[170px] min-w-0 max-w-[170px] overflow-hidden rounded-lg border p-3 transition-all backdrop-blur-sm`,n&&`border-primary/50 bg-primary/10 shadow-lg shadow-primary/10`,r&&`border-destructive/50 bg-destructive/10`,i&&`border-border/70 bg-muted/35`,!n&&!r&&!i&&`border-primary/30 bg-primary/10`),children:[(0,q.jsx)(Tr,{}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[(0,q.jsx)(H,{className:`h-4 w-4 shrink-0`,style:{color:a}}),(0,q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,q.jsx)(`div`,{className:`text-[11px] font-bold truncate`,style:{color:a},children:e.label}),e.model&&(0,q.jsx)(`div`,{className:`truncate text-[10px] text-muted-foreground`,children:Kn(e.model)})]}),(0,q.jsx)(wr,{status:e.status,small:!0,activity:e.vizActivity??0})]}),e.currentTask&&(0,q.jsxs)(`div`,{className:`mb-1.5 flex min-w-0 items-center gap-1 overflow-hidden text-[11px] text-primary`,children:[(0,q.jsx)(`span`,{className:U(`h-1.5 w-1.5 shrink-0 rounded-full bg-primary`,n&&`animate-pulse`)}),(0,q.jsx)(`span`,{className:`min-w-0 truncate font-mono`,title:e.currentTask,children:qn(e.currentTask,72)})]}),(0,q.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-2 gap-y-0.5 text-[11px] mb-1.5`,children:[(0,q.jsxs)(`div`,{className:`flex justify-between`,children:[(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:`iter`}),(0,q.jsx)(`span`,{className:`font-mono text-foreground`,children:e.iteration||0})]}),(0,q.jsxs)(`div`,{className:`flex justify-between`,children:[(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:`tools`}),(0,q.jsx)(`span`,{className:`font-mono text-warning`,children:e.toolCalls||0})]}),(0,q.jsxs)(`div`,{className:`flex justify-between`,children:[(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:`tok`}),(0,q.jsx)(`span`,{className:`font-mono text-foreground`,children:Un((e.tokensIn||0)+(e.tokensOut||0))})]}),(0,q.jsxs)(`div`,{className:`flex justify-between`,children:[(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:`cost`}),(0,q.jsxs)(`span`,{className:`font-mono text-success`,children:[`$`,(e.costUsd||0).toFixed(3)]})]})]}),o>0&&(0,q.jsxs)(`div`,{className:`mb-1`,children:[(0,q.jsxs)(`div`,{className:`mb-0.5 flex justify-between text-[10px] text-muted-foreground`,children:[(0,q.jsx)(`span`,{children:`ctx`}),(0,q.jsxs)(`span`,{className:U(`font-mono`,o>=90?`text-destructive`:o>=70?`text-warning`:`text-muted-foreground`),children:[o,`%`]})]}),(0,q.jsx)(`div`,{className:`h-1 overflow-hidden rounded-full bg-muted`,children:(0,q.jsx)(`div`,{className:U(`h-full`,o>=90?`bg-destructive`:o>=70?`bg-warning`:`bg-primary`),style:{width:`${o}%`}})})]}),e.lastActivityAt&&(0,q.jsxs)(`div`,{className:U(`flex items-center gap-1 text-[10px]`,n?`text-muted-foreground/70`:`text-muted-foreground`),children:[i&&(0,q.jsx)(`span`,{className:`text-success`,children:t(`activity:office.donePrefix`)}),r&&(0,q.jsx)(`span`,{className:`text-destructive`,children:t(`activity:office.failedPrefix`)}),(0,q.jsx)(`span`,{children:t(`activity:office.seenPrefix`,{time:Wn(e.lastActivityAt,Date.now())})})]})]})}function Mr({data:e}){let{t}=C();return(0,q.jsxs)(`div`,{className:U(`rounded-lg border border-dashed p-3 min-w-[120px] transition-all opacity-40`,`border-border/70 bg-muted/30`),children:[(0,q.jsx)(Tr,{}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,q.jsx)(je,{className:`h-4 w-4 text-muted-foreground`}),(0,q.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,q.jsx)(`div`,{className:`truncate text-[10px] text-muted-foreground`,children:e.label})}),(0,q.jsx)(wr,{status:e.status,small:!0,activity:e.vizActivity??0})]}),(0,q.jsx)(`div`,{className:`text-[11px] text-muted-foreground`,children:t(`activity:office.availableDesk`)})]})}function Nr({data:e}){let{t}=C(),n=e.color||Q.warning,r=(e.unreadCount||0)>0;return(0,q.jsxs)(`div`,{className:U(`rounded-xl border-2 p-4 min-w-[160px] transition-all backdrop-blur-sm`,r&&`border-warning/50 bg-warning/10 shadow-lg shadow-warning/10`,!r&&`border-warning/30 bg-warning/6`),children:[(0,q.jsx)(Tr,{}),(0,q.jsxs)(`div`,{className:`flex items-center gap-3 mb-3`,children:[(0,q.jsx)(`div`,{className:U(`flex items-center justify-center w-10 h-10 rounded-lg`,r?`bg-warning/18`:`bg-warning/10`),children:(0,q.jsx)(_,{className:`h-5 w-5`,style:{color:n}})}),(0,q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,q.jsx)(`div`,{className:`text-xs font-bold`,style:{color:n},children:t(`activity:office.mailboxHub`)}),(0,q.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:r?t(`activity:office.unreadSuffix`,{count:e.unreadCount||0}):t(`activity:office.allClear`)})]}),r&&(0,q.jsx)(`div`,{className:`flex h-5 w-5 items-center justify-center rounded-full bg-warning text-[10px] font-bold text-background`,children:e.unreadCount})]}),(0,q.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 text-[10px]`,children:[(0,q.jsxs)(`div`,{className:`rounded bg-muted/40 p-1.5 text-center`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-center gap-1 text-warning`,children:[(0,q.jsx)(v,{className:`h-3 w-3`}),(0,q.jsx)(`span`,{children:e.messageCount||0})]}),(0,q.jsx)(`div`,{className:`text-muted-foreground`,children:t(`activity:office.total`)})]}),(0,q.jsxs)(`div`,{className:`rounded bg-muted/40 p-1.5 text-center`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-center gap-1 text-success`,children:[(0,q.jsx)(ve,{className:`h-3 w-3`}),(0,q.jsx)(`span`,{children:e.unreadCount||0})]}),(0,q.jsx)(`div`,{className:`text-muted-foreground`,children:t(`activity:office.unreadLabel`)})]})]}),e.sublabel&&(0,q.jsxs)(`div`,{className:`mt-2 truncate border-t border-border/60 pt-1.5 text-[11px] text-muted-foreground`,children:[`✉ `,e.sublabel]})]})}var Pr={webui:Dr,tui:Or,repl:kr,coordinator:Ar,agent:jr,mailbox:Nr,desk:Mr};function Fr({broadcastOpen:e,labels:t,onArrange:n,onBroadcastToggle:r,onFeedToggle:i,showFeed:a}){return(0,q.jsxs)(Ke,{position:`top-right`,className:`flex items-center gap-2`,children:[(0,q.jsxs)(`button`,{type:`button`,onClick:n,title:t.arrangeTitle,className:`flex items-center gap-1.5 rounded-md border border-border/70 bg-card/90 px-2.5 py-1.5 text-xs text-foreground shadow-sm transition-colors hover:bg-accent`,children:[(0,q.jsx)(Ee,{className:`h-3.5 w-3.5`}),t.arrange]}),(0,q.jsxs)(`button`,{type:`button`,onClick:i,title:t.feedTitle,className:U(`flex items-center gap-1.5 px-2.5 py-1.5 rounded-md border text-xs transition-colors`,a?`border-primary/35 bg-primary/10 text-primary`:`border-border/70 bg-card/90 text-muted-foreground hover:bg-accent hover:text-foreground`),children:[(0,q.jsx)(oe,{className:`h-3.5 w-3.5`}),t.feed]}),(0,q.jsxs)(`button`,{type:`button`,onClick:r,title:t.broadcastTitle,className:U(`flex items-center gap-1.5 px-2.5 py-1.5 rounded-md border text-xs transition-colors`,e?`border-warning/35 bg-warning/10 text-warning`:`border-border/70 bg-card/90 text-muted-foreground hover:bg-accent hover:text-foreground`),children:[(0,q.jsx)(v,{className:`h-3.5 w-3.5`}),t.broadcast]})]})}function Ir(){return(0,q.jsx)(Ue,{className:`rounded-lg border border-border/70 bg-card/90`,nodeColor:e=>{switch(e.data.kind){case`coordinator`:return Q.primary;case`webui`:return Q.info;case`tui`:return Q.success;case`repl`:case`mailbox`:return Q.warning;default:return Q.primary}},maskColor:`hsl(var(--background) / 0.72)`})}function Lr({closeTitle:e,label:t,onClose:n,sessionId:r,streamTitle:i}){return(0,q.jsxs)(`div`,{className:`absolute inset-y-0 right-0 z-30 flex w-[min(680px,92%)] flex-col border-l border-border bg-background shadow-2xl`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between border-b border-border px-4 py-2.5 shrink-0 bg-card`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,q.jsx)(H,{className:`h-4 w-4 text-primary shrink-0`}),(0,q.jsxs)(`div`,{className:`min-w-0`,children:[(0,q.jsx)(`div`,{className:`truncate text-sm font-bold text-foreground`,children:t}),(0,q.jsx)(`div`,{className:`text-[10px] uppercase tracking-wide text-muted-foreground`,children:i})]})]}),(0,q.jsx)(`button`,{type:`button`,onClick:n,title:e,className:`text-muted-foreground hover:text-foreground text-xl leading-none shrink-0`,children:`×`})]}),(0,q.jsx)(`div`,{className:`flex-1 min-h-0 p-4`,children:(0,q.jsx)(xr,{sessionId:r,limit:500})})]})}var Rr={wire:({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:i,targetPosition:a,data:o,selected:s})=>{let c=o?.color||Q.primary,l=W(e=>e.animateEdges),u=o?.animated&&l?Math.max(.15,o?.intensity??.6):0,[d,f,p]=Re({sourceX:e,sourceY:t,sourcePosition:i??ze.Bottom,targetX:n,targetY:r,targetPosition:a??ze.Top,curvature:.28}),m=5+u*7,h=5+u*4,g=m+h,_=`${Math.max(.5,1.6-u).toFixed(2)}s`;return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`path`,{d,fill:`none`,stroke:c,strokeWidth:s?2.5:1.4,strokeOpacity:s?.9:.28,className:`react-flow__edge-path`}),u>.05&&(0,q.jsx)(`path`,{d,fill:`none`,stroke:c,strokeWidth:2.2,strokeOpacity:.45+u*.5,strokeDasharray:`${m} ${h}`,strokeLinecap:`round`,style:{filter:`drop-shadow(0 0 ${2+u*4}px ${c})`},children:(0,q.jsx)(`animate`,{attributeName:`stroke-dashoffset`,from:g,to:`0`,dur:_,repeatCount:`indefinite`})}),o?.label&&u>.1&&(0,q.jsx)(Be,{children:(0,q.jsx)(`div`,{style:{position:`absolute`,transform:`translate(-50%, -50%) translate(${f}px, ${p}px)`},className:`pointer-events-none max-w-[220px] truncate whitespace-nowrap rounded-full border border-border/70 bg-card/90 px-1.5 py-0.5 text-[8px] font-medium text-foreground backdrop-blur-sm`,children:o.label})})]})}};function zr(){let{t:e}=C(),{clientCounts:t,currentSession:n,totalAgents:r,activeAgents:i,aggregate:a}=Qe(h(e=>({clientCounts:e.clientCounts,currentSession:e.currentSession,totalAgents:e.totalAgents,activeAgents:e.activeAgents,aggregate:e.aggregate}))),o=t.tui+t.webui+t.repl,s=e=>e?.toLocaleString()??`0`;return(0,q.jsxs)(`div`,{className:`absolute left-4 top-20 z-10 rounded-xl border border-border/70 bg-card/90 p-3 text-foreground shadow-xl backdrop-blur`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,q.jsx)(x,{className:`h-3.5 w-3.5 text-success`}),(0,q.jsx)(`span`,{className:`text-[10px] font-bold uppercase text-muted-foreground`,children:e(`activity:office.sessionStats`)})]}),(0,q.jsxs)(`div`,{className:`space-y-1.5 text-[10px]`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,q.jsx)(fe,{className:`h-3 w-3 text-muted-foreground`}),(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:e(`activity:office.clients`)})]}),(0,q.jsxs)(`span`,{className:`font-mono text-foreground`,children:[i,` `,(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:`/`}),` `,(0,q.jsx)(`span`,{className:`text-success`,children:o})]})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-3 pl-4 text-[9px]`,children:[t.tui>0&&(0,q.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,q.jsx)(V,{className:`h-2.5 w-2.5 text-success`}),(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:e(`activity:hud.tui`)}),(0,q.jsx)(`span`,{className:`font-mono text-success`,children:t.tui})]}),t.webui>0&&(0,q.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,q.jsx)(F,{className:`h-2.5 w-2.5 text-primary`}),(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:e(`activity:hud.webui`)}),(0,q.jsx)(`span`,{className:`font-mono text-primary`,children:t.webui})]}),t.repl>0&&(0,q.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,q.jsx)(V,{className:`h-2.5 w-2.5 text-warning`}),(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:e(`activity:hud.repl`)}),(0,q.jsx)(`span`,{className:`font-mono text-warning`,children:t.repl})]})]}),(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,q.jsx)(H,{className:`h-3 w-3 text-muted-foreground`}),(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:e(`activity:officeMap.agents`)})]}),(0,q.jsxs)(`span`,{className:`font-mono text-foreground`,children:[i,` `,(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:`/`}),` `,(0,q.jsx)(`span`,{className:`text-primary`,children:r})]})]}),n.model&&(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,q.jsx)(de,{className:`h-3 w-3 text-muted-foreground`}),(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:e(`activity:officeMap.model`)})]}),(0,q.jsx)(`span`,{className:`max-w-[120px] truncate font-mono text-primary`,title:n.model,children:n.model.split(`/`).pop()?.slice(0,16)})]}),n.mode&&(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,q.jsx)(T,{className:`h-3 w-3 text-muted-foreground`}),(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:e(`activity:officeMap.mode`)})]}),(0,q.jsx)(`span`,{className:U(`font-mono uppercase text-[9px] px-1.5 py-0.5 rounded`,n.mode===`auto`&&`bg-primary/10 text-primary`,n.mode===`suggest`&&`bg-success/10 text-success`,n.mode===`off`&&`bg-muted text-muted-foreground`,![`auto`,`suggest`,`off`].includes(n.mode||``)&&`bg-muted text-muted-foreground`),children:n.mode})]}),(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,q.jsx)(xe,{className:`h-3 w-3 text-muted-foreground`}),(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:e(`activity:office.toolCallsLabel`)})]}),(0,q.jsx)(`span`,{className:`font-mono text-warning`,children:s(a.toolCalls)})]}),(0,q.jsxs)(`div`,{className:`mt-1.5 space-y-1 border-t border-border/70 pt-1.5`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,q.jsx)(`span`,{className:`text-[8px] text-muted-foreground`,children:`IN`}),(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:e(`activity:office.input`)})]}),(0,q.jsx)(`span`,{className:`font-mono text-[9px] text-foreground`,children:s(a.tokensIn)})]}),(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,q.jsx)(`span`,{className:`text-[8px] text-muted-foreground`,children:e(`activity:hud.out`)}),(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:e(`activity:office.output`)})]}),(0,q.jsx)(`span`,{className:`font-mono text-[9px] text-foreground`,children:s(a.tokensOut)})]})]}),(0,q.jsxs)(`div`,{className:`mt-1.5 flex items-center justify-between gap-4 border-t border-border/70 pt-1.5`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,q.jsx)(De,{className:`h-3 w-3 text-muted-foreground`}),(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:e(`activity:office.cost`)})]}),(0,q.jsx)(`span`,{className:`font-mono font-medium text-success`,children:(e=>e==null?`$0.0000`:`$${e.toFixed(4)}`)(a.costUsd)})]})]})]})}function Br({events:e,now:t}){let{t:n}=C(),r=e.slice(0,14);return(0,q.jsx)(`div`,{className:`absolute bottom-0 left-0 right-0 z-10 pointer-events-none px-3 pb-3`,children:(0,q.jsxs)(`div`,{className:`pointer-events-auto mx-auto max-w-3xl rounded-lg border border-border/70 bg-card/90 px-3 py-2 shadow-xl backdrop-blur`,children:[(0,q.jsxs)(`div`,{className:`mb-1.5 flex items-center gap-1.5 text-[10px] uppercase text-primary`,children:[(0,q.jsx)(x,{className:`h-3 w-3`}),n(`activity:office.liveActivity`)]}),r.length===0?(0,q.jsx)(`div`,{className:`text-[11px] italic text-muted-foreground`,children:n(`activity:office.waitingActivity`)}):(0,q.jsx)(`div`,{className:`flex flex-col gap-0.5 max-h-32 overflow-hidden`,children:r.map(e=>{let r=Math.max(0,Math.round((t-e.timestamp)/1e3));return(0,q.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] leading-tight`,children:[(0,q.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full shrink-0`,style:{backgroundColor:dr(e.kind)}}),(0,q.jsx)(`span`,{className:`flex-1 truncate text-foreground`,children:e.label}),(0,q.jsx)(`span`,{className:`shrink-0 tabular-nums text-muted-foreground`,children:r<1?n(`activity:office.now`):`${r}s`})]},e.id)})})]})})}function Vr(){let{t:e}=C();return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{className:`absolute bottom-4 left-4 z-10 rounded-lg border border-border/70 bg-card/90 p-3 text-[10px] shadow-xl backdrop-blur`,children:[(0,q.jsx)(`div`,{className:`mb-2 font-bold text-foreground`,children:e(`activity:office.legendStatus`)}),(0,q.jsxs)(`div`,{className:`space-y-1`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(`span`,{className:`h-2 w-2 animate-pulse rounded-full bg-success`}),(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:e(`activity:office.legendActive`)})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(`span`,{className:`h-2 w-2 rounded-full bg-muted-foreground`}),(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:e(`activity:office.legendIdle`)})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(`span`,{className:`h-2 w-2 animate-pulse rounded-full bg-destructive`}),(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:e(`activity:office.legendError`)})]})]})]}),(0,q.jsxs)(`div`,{className:`absolute bottom-4 right-4 z-10 rounded-lg border border-border/70 bg-card/90 p-3 text-[10px] shadow-xl backdrop-blur`,children:[(0,q.jsx)(`div`,{className:`mb-2 font-bold text-foreground`,children:e(`activity:office.legendConnections`)}),(0,q.jsxs)(`div`,{className:`space-y-1`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(`span`,{className:`text-warning`,children:`✉`}),(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:e(`activity:office.legendMail`)})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(`span`,{className:`text-primary`,children:`→`}),(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:e(`activity:office.legendTask`)})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(`span`,{className:`text-success`,children:`●`}),(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:e(`activity:office.legendStatusConn`)})]})]})]})]})}function Hr({draft:e,isSending:t,result:n,onClose:r,onDraftChange:i,onSend:a}){let{t:o}=C();return(0,q.jsxs)(`div`,{className:`absolute right-4 top-16 z-30 w-80 rounded-xl border border-warning/35 bg-card/95 p-3 shadow-2xl backdrop-blur`,children:[(0,q.jsxs)(`div`,{className:`mb-1.5 flex items-center justify-between`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-semibold text-warning`,children:[(0,q.jsx)(v,{className:`h-3.5 w-3.5`}),` `,o(`activity:office.broadcastToAll`)]}),(0,q.jsx)(`button`,{type:`button`,onClick:r,className:`text-base leading-none text-muted-foreground hover:text-foreground`,children:`×`})]}),(0,q.jsx)(`textarea`,{value:e,onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),a())},rows:3,placeholder:o(`activity:office.broadcastPlaceholder`),className:`w-full resize-none rounded-md border border-border/70 bg-background/70 px-2 py-1 text-[11px] text-foreground placeholder:text-muted-foreground focus:border-warning/45 focus:outline-none`}),(0,q.jsxs)(`div`,{className:`mt-1.5 flex items-center justify-between`,children:[(0,q.jsx)(`span`,{className:`text-[9px] text-muted-foreground`,children:o(`activity:office.broadcastSendHint`)}),(0,q.jsx)(`button`,{type:`button`,onClick:a,disabled:t||!e.trim(),className:`rounded-md border border-warning/35 bg-warning/12 px-2.5 py-1 text-[11px] text-warning transition-colors hover:bg-warning/18 disabled:cursor-not-allowed disabled:opacity-40`,children:t?`…`:o(`activity:office.broadcast`)})]}),n&&(0,q.jsx)(`div`,{className:`mt-1 text-[10px] text-muted-foreground`,children:n})]})}function $({k:e,v:t,accent:n}){return(0,q.jsxs)(`div`,{className:`flex justify-between gap-3`,children:[(0,q.jsx)(`span`,{className:`text-muted-foreground shrink-0`,children:e}),(0,q.jsx)(`span`,{className:U(`font-mono truncate text-right`,n??`text-foreground/80`),children:t})]})}function Ur({selectedNode:e,selectedAgentTranscript:t,mailboxMessages:n,onClose:r,onOpenWatch:i}){let{t:a}=C(),o=e.data,s=Date.now(),c=o.kind===`agent`,l=o.kind===`webui`||o.kind===`tui`||o.kind===`repl`,u=(o.tokensIn||0)+(o.tokensOut||0),d=Cr(o.ctxPct);return(0,q.jsxs)(`div`,{className:U(`absolute top-20 right-4 bg-background border border-border rounded-lg p-4 shadow-xl z-20`,o.kind===`agent`?`w-[28rem] max-w-[calc(100%-2rem)]`:o.sessionId?`w-80`:`w-64`),children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[o.kind===`webui`&&(0,q.jsx)(F,{className:`h-4 w-4 text-info`}),o.kind===`tui`&&(0,q.jsx)(V,{className:`h-4 w-4 text-success`}),o.kind===`coordinator`&&(0,q.jsx)(de,{className:`h-4 w-4 text-primary`}),o.kind===`agent`&&(0,q.jsx)(H,{className:`h-4 w-4 text-primary`}),o.kind===`mailbox`&&(0,q.jsx)(_,{className:`h-4 w-4 text-warning`}),(0,q.jsx)(`span`,{className:`text-sm font-bold text-foreground`,children:o.label})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[o.sessionId&&(0,q.jsx)(`button`,{type:`button`,title:a(`activity:office.openFullView`),onClick:()=>i({sessionId:o.sessionId,label:o.label}),className:`text-muted-foreground hover:text-primary`,children:(0,q.jsx)(ie,{className:`h-3.5 w-3.5`})}),(0,q.jsx)(`button`,{type:`button`,onClick:r,className:`text-muted-foreground hover:text-foreground text-lg leading-none`,children:`×`})]})]}),(0,q.jsxs)(`div`,{className:`space-y-1.5 text-xs`,children:[(0,q.jsx)($,{k:`Status`,v:String(o.status).toUpperCase(),accent:U(o.status===`active`&&`text-success`,o.status===`streaming`&&`text-primary`,o.status===`error`&&`text-destructive`,o.status===`idle`&&`text-muted-foreground`,o.status===`offline`&&`text-muted-foreground/70`)}),c&&(0,q.jsxs)(q.Fragment,{children:[o.model&&(0,q.jsx)($,{k:`Model`,v:Kn(o.model),accent:`text-primary`}),o.currentTask&&(0,q.jsxs)(`div`,{className:`pt-1`,children:[(0,q.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:a(`activity:agentOffice.currentTask`)}),(0,q.jsx)(`div`,{className:`mt-1 max-h-32 overflow-y-auto whitespace-pre-wrap break-words font-mono text-[10px] text-primary`,children:o.currentTask})]}),(0,q.jsx)($,{k:`Iterations`,v:o.iteration||0,accent:`text-primary`}),(0,q.jsx)($,{k:`Tool calls`,v:o.toolCalls||0,accent:`text-warning`}),(0,q.jsx)($,{k:`Tokens in`,v:Un(o.tokensIn)}),(0,q.jsx)($,{k:`Tokens out`,v:Un(o.tokensOut)}),(0,q.jsx)($,{k:`Tokens total`,v:Un(u)}),d>0&&(0,q.jsx)($,{k:`Context`,v:`${d}%`,accent:d>=90?`text-destructive`:d>=70?`text-warning`:`text-foreground/70`}),(0,q.jsx)($,{k:`Cost`,v:`$${(o.costUsd||0).toFixed(4)}`,accent:`text-success`}),o.lastActivityAt&&(0,q.jsx)($,{k:`Last seen`,v:Wn(o.lastActivityAt,s),accent:`text-muted-foreground`}),(0,q.jsx)(`div`,{className:`pt-2`,children:(0,q.jsx)(it,{entries:t,agentName:o.label,compact:!0,maxHeightClassName:`max-h-64`})})]}),l&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)($,{k:`Surface`,v:rr(o.kind),accent:`text-foreground/80`}),o.branch&&(0,q.jsx)($,{k:`Branch`,v:`⎇ ${o.branch}`,accent:`text-foreground/70`}),o.pid!=null&&(0,q.jsx)($,{k:`PID`,v:o.pid}),o.workingDir&&(0,q.jsx)($,{k:`Dir`,v:o.workingDir,accent:`text-muted-foreground`}),(0,q.jsx)($,{k:`Agents`,v:o.agentCount??0,accent:`text-primary`}),o.startedAt&&(0,q.jsx)($,{k:`Uptime`,v:Gn(o.startedAt,s),accent:`text-foreground/70`})]}),o.kind===`mailbox`&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)($,{k:`Total messages`,v:o.messageCount||0,accent:`text-warning`}),(0,q.jsx)($,{k:`Unread`,v:o.unreadCount||0,accent:`text-warning`}),n.length>0&&(0,q.jsxs)(`div`,{className:`mt-1 space-y-1 border-t border-border pt-2`,children:[(0,q.jsx)(`div`,{className:`text-[10px] uppercase tracking-wide text-muted-foreground`,children:a(`activity:office.recent`)}),[...n].sort((e,t)=>Date.parse(t.timestamp)-Date.parse(e.timestamp)).slice(0,6).map(e=>{let t=!e.completed&&(e.readByCount??0)===0;return(0,q.jsxs)(`div`,{className:`flex items-start gap-1.5 text-[10px]`,children:[(0,q.jsx)(`span`,{className:U(`mt-1 h-1.5 w-1.5 shrink-0 rounded-full`,t?`bg-warning`:e.completed?`bg-success`:`bg-muted`)}),(0,q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,q.jsx)(`div`,{className:`truncate text-foreground/80`,children:e.subject||a(`activity:office.noSubject`)}),(0,q.jsxs)(`div`,{className:`truncate font-mono text-[9px] text-muted-foreground`,children:[e.from,` → `,e.to,` · `,Wn(e.timestamp,s),e.audience===`leaders`?` · ${a(`activity:mailbox.audienceLeaders`)}`:``]})]})]},e.id)})]})]}),o.kind===`coordinator`&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)($,{k:`Connections`,v:o.connections||0,accent:`text-primary`}),(0,q.jsx)($,{k:`Iterations`,v:o.iteration||0,accent:`text-primary`})]}),(c||l)&&o.sessionId&&(0,q.jsx)(`div`,{className:`mt-2 border-t border-border pt-2 h-72`,children:(0,q.jsx)(xr,{sessionId:o.sessionId})})]})]})}function Wr(e){let t=e.split(`__agent-`)[0];return t&&t!==e?`${t}->${e}`:`coordinator->${e}`}function Gr(){let{t:e}=C(),{fitView:t}=We(),r=(0,K.useRef)(null),[i,s]=(0,K.useState)({width:1280,height:720});(0,K.useEffect)(()=>{let e=r.current;if(!e)return;let t=()=>{let{width:t,height:n}=e.getBoundingClientRect();t<1||n<1||s(e=>Math.abs(e.width-t)<2&&Math.abs(e.height-n)<2?e:{width:t,height:n})};t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[]);let c=u(e=>e.events),l=n(e=>e.agents),d=n(e=>e.agentTranscripts),f=n(e=>e.leaderId),p=Qe(e=>e.liveSessions),m=$e(e=>e.messages),h=$e(e=>e.agents),g=a(e=>e.session),_=pr(l),v=(0,K.useMemo)(()=>ur(p,l,h,_.map,_.now),[p,l,h,_]),y=W(e=>e.showHud),b=W(e=>e.showLegend),x=W(e=>e.showMinimap),S=W(e=>e.showControls),w=W(e=>e.showFeed),T=W(e=>e.setShowFeed),E=W(e=>e.background),[D,O,k]=Le([]),[A,j,M]=Ie([]),[N,ee]=(0,K.useState)(null),[P,F]=(0,K.useState)(null),[ne,re]=(0,K.useState)(!1),[ie,ae]=(0,K.useState)(``),[I,oe]=(0,K.useState)(!1),[L,R]=(0,K.useState)(null),se=(0,K.useMemo)(()=>{if(N?.data.kind!==`agent`)return o;let e=N.data.serverId??(N.id.includes(`__agent-`)?N.id.split(`__agent-`).pop():N.id.replace(/^agent-/,``));return e?d.get(e)??o:o},[d,N]),ce=(0,K.useCallback)(async()=>{let e=ie.trim();if(!(!e||I)){oe(!0),R(null);try{let t=await fetch(`/api/fleet/broadcast`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({text:e})});if(!t.ok)throw Error(`HTTP ${t.status}`);let n=await t.json();ae(``),R(`Delivered to ${n.delivered??0}/${n.targets??0} session(s)`)}catch(e){R(`Failed: ${e instanceof Error?e.message:String(e)}`)}finally{oe(!1)}}},[ie,I]),le=(0,K.useRef)(new Map),ue=4e3,z=(0,K.useRef)(new Map),B=(0,K.useRef)(new Map),de=(0,K.useRef)(new Map),fe=(0,K.useRef)(new Map),pe=(0,K.useRef)(``);(0,K.useEffect)(()=>{let n=[],r=[],a=Date.now(),o=er(v.map(e=>({id:e.id,agentCount:e.agents.length})),i),s=m.filter(e=>!e.completed&&(e.readByCount??0)===0).length,c=m.length?[...m].sort((e,t)=>Date.parse(t.timestamp)-Date.parse(e.timestamp))[0]:void 0;n.push({id:`mailbox`,type:`mailbox`,position:{x:830,y:50},data:{label:e(`activity:office.mailboxHub`),kind:`mailbox`,status:s>0?`active`:`idle`,unreadCount:s,messageCount:m.length,sublabel:c?`${c.from} → ${c.to}: ${c.subject}`:void 0,color:Q.warning}});let u=0,d=0,p=0,h=0,g=0;for(let e of v)for(let t of e.agents)d+=1,(t.status===`active`||t.status===`streaming`)&&(u+=1),p+=t.toolCalls,h+=t.costUsd,g+=t.tokensIn+t.tokensOut;let _=f?l.get(f):null,y=u>0;n.push({id:`coordinator`,type:`coordinator`,position:{x:370,y:50},data:{label:e(`activity:office.fleetHqLabel`),sublabel:e(`activity:office.clientsSuffix`,{count:v.length}),kind:`coordinator`,status:_?.status===`failed`?`error`:y?`active`:`idle`,connections:v.length,agentsActive:u,agentsTotal:d,toolCalls:p,costUsd:h,tokensIn:g,color:Q.primary}});let b={tui:Q.success,webui:Q.info,repl:Q.warning};for(let t of v){let i=o.positions.get(t.id)??{x:600,y:370},c=i.x,l=i.y,u=b[t.type],d=t.status===`active`;if(n.push({id:t.id,type:t.type,position:{x:c,y:l},data:{label:t.label,sublabel:t.sublabel,kind:t.type,status:t.status,sessionId:t.sessionId,pid:t.pid,branch:t.branch,workingDir:t.workingDir,startedAt:t.startedAt,agentCount:t.agents.length,color:u}}),r.push({id:`${t.id}->coordinator`,source:t.id,target:`coordinator`,type:`wire`,animated:d,data:{color:u,animated:d,label:e(`activity:office.controlLabel`),flowType:`task`}}),r.push({id:`mailbox->${t.id}`,source:`mailbox`,target:t.id,type:`wire`,animated:s>0,data:{color:Q.warning,animated:s>0,label:s>0?`${s}`:void 0,flowType:`mail`}}),t.agents.length===0){n.push({id:`desk-${t.id}`,type:`desk`,position:{x:c,y:l+270},data:{label:e(`activity:office.idleDesk`),kind:`agent`,status:`idle`,color:Q.muted}});continue}t.agents.forEach((i,o)=>{let s=i.status===`active`||i.status===`streaming`,u=fe.current.get(i.serverId);if(u&&(i.toolCalls>u.toolCalls||i.iteration>u.iteration)||s){le.current.set(i.officeId,a+ue);let e=B.current.get(i.officeId)??0;B.current.set(i.officeId,Math.min(1,e+(1-e)*.5));for(let e of[`${t.id}->${i.officeId}`,`${t.id}->coordinator`]){let t=z.current.get(e)??0;z.current.set(e,Math.min(1,t+.5))}}fe.current.set(i.serverId,{toolCalls:i.toolCalls,iteration:i.iteration}),n.push({id:i.officeId,type:`agent`,position:tr(c,o,t.agents.length,l+270),data:{label:i.name,kind:`agent`,status:i.status,serverId:i.serverId,sessionId:t.sessionId,currentTask:i.currentTask,iteration:i.iteration,toolCalls:i.toolCalls,costUsd:i.costUsd,tokensIn:i.tokensIn,tokensOut:i.tokensOut,ctxPct:i.ctxPct,model:i.model,lastActivityAt:i.lastActivityAt,color:Q.primary}}),r.push({id:`${t.id}->${i.officeId}`,source:t.id,target:i.officeId,type:`wire`,animated:s,data:{color:Q.primary,animated:s,label:s?qn(i.currentTask,48)??e(`activity:office.taskFallback`):void 0,flowType:`task`}})})}let x=new Set(v.flatMap(e=>e.agents.map(e=>e.serverId)));for(let e of[...fe.current.keys()])x.has(e)||fe.current.delete(e);for(let[e,t]of[...le.current])t<=a&&le.current.delete(e);let S=n.map(e=>{let t=le.current.get(e.id),n=B.current.get(e.id)??0;return t&&t>a&&e.data.status!==`error`&&e.data.status!==`offline`?{...e,data:{...e.data,status:`active`,vizActivity:n}}:{...e,data:{...e.data,vizActivity:n}}}),C=r.map(e=>{let t=z.current.get(e.id)??0;return t>.05?{...e,animated:!0,data:{...e.data,animated:!0,intensity:t}}:e}),w=new Map;for(let e of S)w.set(e.id,{...e.position});de.current=w,O(S),j(C);let T=[`${Math.round(i.width)}x${Math.round(i.height)}`,`${o.columns}x${o.rows}`,v.map(e=>`${e.id}:${e.agents.length}`).join(`|`),S.map(e=>e.id).sort().join(`|`)].join(`:`);if(T!==pe.current){pe.current=T;let e=setTimeout(()=>t({padding:Sr,duration:300}),50);return()=>clearTimeout(e)}},[v,f,l,m,g,i,ue,O,j,t]);let me=(0,K.useMemo)(()=>{let e=v.flatMap(e=>e.agents.map(t=>({clientId:e.id,clientType:e.type,officeId:t.officeId,serverId:t.serverId}))),t=new Map;for(let n of e)(!t.has(n.serverId)||n.clientType===`webui`)&&t.set(n.serverId,n.officeId);return{renderedAgents:e,serverIdToOffice:t,clientIds:v.map(e=>e.id)}},[v]),V=(0,K.useCallback)(e=>{let t=e=>me.serverIdToOffice.get(e)??`agent-${e}`;switch(e.kind){case`mailbox:send`:case`mailbox:deliver`:return{nodes:[`mailbox`],edges:e.kind===`mailbox:send`?me.clientIds.map(e=>`mailbox->${e}`):[],status:`active`};case`agent:spawned`:{let n=t(e.source);return{nodes:[`coordinator`,n],edges:[Wr(n)],status:`active`}}case`agent:tool`:case`tool:started`:case`tool:progress`:{let n=t(e.source);return{nodes:[`coordinator`,n],edges:[Wr(n)],status:e.kind===`tool:progress`||e.kind===`tool:started`?`streaming`:`active`}}case`tool:executed`:{let n=t(e.target??e.source);return{nodes:[n],edges:[Wr(n)],status:`active`}}case`provider:call`:case`provider:delta`:case`provider:response`:return{nodes:[`coordinator`],edges:[],status:e.kind===`provider:delta`?`streaming`:`active`};case`iteration:start`:case`iteration:end`:return{nodes:[`coordinator`],edges:me.renderedAgents.map(e=>Wr(e.officeId)),status:e.kind===`iteration:start`?`streaming`:`active`};case`agent:text`:{let n=t(e.source);return{nodes:[n],edges:[Wr(n)],status:`streaming`}}case`agent:status`:{let n=t(e.source);return{nodes:[`coordinator`,n],edges:[Wr(n)],status:e.data&&typeof e.data==`object`&&`status`in e.data&&String(e.data.status)===`failed`?`error`:`completed`}}case`agent:ctx`:return{nodes:[t(e.source)],edges:[],status:`active`};case`budget:extended`:return{nodes:[`coordinator`,t(e.source)],edges:[],status:`active`};case`context:compacted`:case`context:repaired`:return{nodes:[`coordinator`],edges:[],status:`active`};case`error`:return{nodes:e.source?[t(e.source)]:[],edges:[],status:`error`};case`cost:update`:return{nodes:[`coordinator`],edges:[],status:`active`};case`fleet:snapshot`:{let n=e.data?.sessions??[],r=[`coordinator`];for(let e of n)if(e.agents)for(let n of e.agents){let e=t(n.id);r.includes(e)||r.push(e)}return{nodes:r,edges:[],status:`active`}}default:return{nodes:[],edges:[],status:`idle`}}},[me]),H=(0,K.useRef)(null),he=(0,K.useRef)(!1);(0,K.useEffect)(()=>{if(c.length===0)return;if(!he.current){he.current=!0,H.current=c[0]?.id??null;return}let e=H.current;H.current=c[0]?.id??null;let t=e?c.findIndex(t=>t.id===e):-1;if(t===0)return;let n=t===-1?c.length:t,r=Date.now(),i=new Map,a=new Set;for(let e=n-1;e>=0;e--){let t=c[e];if(!t)continue;let{nodes:n,edges:o,status:s}=V(t);for(let e of n){le.current.set(e,r+ue);let t=B.current.get(e)??0;B.current.set(e,Math.min(1,t+(1-t)*.5)),i.set(e,s)}for(let e of o){let t=z.current.get(e)??0;z.current.set(e,Math.min(1,t+.5)),a.add(e)}}i.size>0&&O(e=>e.map(e=>{let t=i.get(e.id);return t===void 0?e:{...e,data:{...e.data,status:t,vizActivity:B.current.get(e.id)??0}}})),a.size>0&&j(e=>e.map(e=>a.has(e.id)?{...e,animated:!0,data:{...e.data,animated:!0,intensity:z.current.get(e.id)??1}}:e))},[c,V,O,j,ue]),(0,K.useEffect)(()=>{let e=setInterval(()=>{let e=new Map,t=!1;for(let[n,r]of z.current){let i=r*.85;i<.05?(z.current.delete(n),e.set(n,{intensity:0,animated:!1}),t=!0):(z.current.set(n,i),e.set(n,{intensity:i,animated:!0}),t=!0)}t&&j(t=>t.map(t=>{let n=e.get(t.id);return n?{...t,animated:n.animated,data:{...t.data,animated:n.animated,intensity:n.intensity}}:t}));let n=new Map,r=!1;for(let[e,t]of B.current){let i=t*.9;i<.03?(B.current.delete(e),n.set(e,0),r=!0):(B.current.set(e,i),n.set(e,i),r=!0)}r&&O(e=>e.map(e=>{let t=n.get(e.id);return t===void 0?e:{...e,data:{...e.data,vizActivity:t}}}))},1e3);return()=>clearInterval(e)},[j,O]);let ge=(0,K.useCallback)(e=>j(t=>Ve({...e,type:`wire`},t)),[j]),_e=(0,K.useCallback)((e,t)=>{ee(t)},[]),ve=(0,K.useCallback)(()=>{ee(null)},[]);(0,K.useEffect)(()=>{if(!P)return;let e=e=>{e.key===`Escape`&&F(null)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[P]);let ye=(0,K.useCallback)(()=>{O(e=>e.map(e=>{let t=de.current.get(e.id);return t?{...e,position:{...t}}:e})),setTimeout(()=>t({padding:Sr,duration:300}),50)},[O,t]),[,be]=(0,K.useState)(0);return(0,K.useEffect)(()=>{let e=setInterval(()=>{document.hidden||be(e=>e+1)},2e3);return()=>clearInterval(e)},[]),(0,q.jsxs)(`div`,{ref:r,className:`relative h-full w-full overflow-hidden bg-[hsl(var(--surface-2)/0.55)]`,children:[(0,q.jsx)(`div`,{className:`absolute inset-0 opacity-[0.03]`,style:{backgroundImage:`
10
+ linear-gradient(hsl(var(--foreground) / 0.1) 1px, transparent 1px),
11
+ linear-gradient(90deg, hsl(var(--foreground) / 0.1) 1px, transparent 1px)
12
+ `,backgroundSize:`40px 40px`}}),y&&(0,q.jsx)(zr,{}),(0,q.jsx)(`div`,{className:`absolute top-3 left-1/2 -translate-x-1/2 z-10`,children:(0,q.jsx)(`div`,{className:`rounded-lg border border-border/70 bg-card/90 px-4 py-2 shadow-xl backdrop-blur`,children:(0,q.jsxs)(`div`,{className:`flex items-center gap-2 text-xs font-bold text-foreground`,children:[(0,q.jsx)(te,{className:`h-4 w-4 text-primary`}),e(`activity:office.fleetHq`),(0,q.jsx)(`span`,{className:`ml-2 h-2 w-2 animate-pulse rounded-full bg-success`}),(0,q.jsx)(`span`,{className:`text-[10px] font-normal text-muted-foreground`,children:e(`activity:office.live`)})]})})}),b&&(0,q.jsx)(Vr,{}),(0,q.jsxs)(Je,{nodes:D,edges:A,onNodesChange:k,onEdgesChange:M,onConnect:ge,onNodeClick:_e,onPaneClick:ve,nodeTypes:Pr,edgeTypes:Rr,fitView:!0,fitViewOptions:{padding:Sr},minZoom:.15,maxZoom:1.5,defaultEdgeOptions:{type:`wire`},proOptions:{hideAttribution:!0},children:[(0,q.jsx)(Fr,{broadcastOpen:ne,labels:{arrange:e(`activity:office.arrange`),arrangeTitle:e(`activity:office.arrangeTitle`),broadcast:e(`activity:office.broadcast`),broadcastTitle:e(`activity:office.broadcastTitle`),feed:e(`activity:office.feed`),feedTitle:e(`activity:office.feedTitle`)},onArrange:ye,onBroadcastToggle:()=>re(e=>!e),onFeedToggle:()=>T(!w),showFeed:w}),E!==`none`&&(0,q.jsx)(qe,{variant:E===`lines`?He.Lines:E===`cross`?He.Cross:He.Dots,gap:20,size:1,color:`hsl(var(--border) / 0.35)`}),S&&(0,q.jsx)(Ge,{className:`rounded-lg border border-border/70 bg-card/90 [&>button]:bg-card [&>button]:text-foreground`}),x&&(0,q.jsx)(Ir,{})]}),w&&(0,q.jsx)(Br,{events:c,now:Date.now()}),ne&&(0,q.jsx)(Hr,{draft:ie,isSending:I,result:L,onClose:()=>re(!1),onDraftChange:ae,onSend:()=>void ce()}),N&&(0,q.jsx)(Ur,{selectedNode:N,selectedAgentTranscript:se,mailboxMessages:m,onClose:ve,onOpenWatch:F}),P&&(0,q.jsx)(Lr,{closeTitle:e(`activity:office.closeEsc`),label:P.label,onClose:()=>F(null),sessionId:P.sessionId,streamTitle:e(`activity:office.fullOperationStream`)})]})}function Kr(){let{t:e}=C(),t=W(e=>e.viewMode),n=W(e=>e.setViewMode),r=[{id:`office`,label:e(`activity:agentOffice.office`),description:e(`activity:agentOffice.officeDescription`),icon:be},{id:`topology`,label:e(`activity:agentOffice.topology`),description:e(`activity:agentOffice.topologyDescription`),icon:Ne}],i=(e,t)=>{let i;if(e.key===`ArrowLeft`&&(i=(t-1+r.length)%r.length),e.key===`ArrowRight`&&(i=(t+1)%r.length),e.key===`Home`&&(i=0),e.key===`End`&&(i=r.length-1),i===void 0)return;e.preventDefault();let a=r[i];a&&(n(a.id),e.currentTarget.parentElement?.querySelectorAll(`[role="tab"]`)[i]?.focus())};return(0,q.jsxs)(`div`,{className:`flex h-full min-h-0 w-full flex-col bg-background`,children:[(0,q.jsx)(`nav`,{"aria-label":`${e(`activity:agentOffice.office`)} / ${e(`activity:agentOffice.topology`)}`,className:`relative z-[60] shrink-0 border-b border-border bg-card/95 px-3 pt-2 shadow-[0_8px_28px_hsl(var(--shadow-color)/0.1)] backdrop-blur-xl sm:px-5`,children:(0,q.jsx)(`div`,{role:`tablist`,"aria-orientation":`horizontal`,className:`mx-auto grid w-full max-w-3xl grid-cols-2 gap-1`,children:r.map((e,r)=>{let a=e.icon,o=t===e.id;return(0,q.jsxs)(`button`,{id:`office-map-tab-${e.id}`,type:`button`,role:`tab`,"aria-selected":o,"aria-controls":`office-map-view-panel`,tabIndex:o?0:-1,onClick:()=>n(e.id),onKeyDown:e=>i(e,r),className:U(`group relative flex min-w-0 items-center gap-2.5 border-b-2 px-3 py-2.5 text-left transition-all duration-200 sm:gap-3 sm:px-5`,o?`border-primary bg-primary/[0.07] text-foreground`:`border-transparent text-muted-foreground hover:border-border hover:bg-accent/60 hover:text-foreground`),children:[(0,q.jsx)(`span`,{className:U(`grid h-8 w-8 shrink-0 place-items-center rounded-lg border transition-colors`,o?`border-primary/35 bg-primary/15 text-primary`:`border-border bg-background/70 text-muted-foreground group-hover:text-foreground`),children:(0,q.jsx)(a,{className:`h-4 w-4`,"aria-hidden":`true`})}),(0,q.jsxs)(`span`,{className:`min-w-0`,children:[(0,q.jsx)(`strong`,{className:`block truncate font-display text-xs font-semibold sm:text-sm`,children:e.label}),(0,q.jsx)(`small`,{className:`hidden truncate font-mono text-[9px] font-normal text-muted-foreground sm:block`,children:e.description})]}),(0,q.jsx)(`span`,{"aria-hidden":`true`,className:U(`ml-auto h-1.5 w-1.5 shrink-0 rounded-full transition-all`,o?`bg-primary shadow-[0_0_0_4px_hsl(var(--primary)/0.12)]`:`bg-border`)})]},e.id)})})}),(0,q.jsx)(`div`,{id:`office-map-view-panel`,role:`tabpanel`,"aria-labelledby":`office-map-tab-${t}`,className:`relative min-h-0 flex-1`,children:t===`office`?(0,q.jsx)(mr,{}):(0,q.jsx)(Fe,{children:(0,q.jsx)(Gr,{})})})]})}function qr({label:e,checked:t,onChange:n}){return(0,q.jsxs)(`button`,{type:`button`,onClick:()=>n(!t),className:`flex w-full items-center justify-between px-2 py-1.5 rounded text-xs hover:bg-accent/50 transition-colors`,children:[(0,q.jsx)(`span`,{className:`text-foreground`,children:e}),(0,q.jsx)(`span`,{className:U(`relative inline-flex h-4 w-7 shrink-0 items-center rounded-full transition-colors`,t?`bg-primary`:`bg-muted`),children:(0,q.jsx)(`span`,{className:U(`inline-block h-3 w-3 transform rounded-full bg-background transition-transform`,t?`translate-x-3.5`:`translate-x-0.5`)})})]})}var Jr=[{value:`dots`,labelKey:`bgDots`},{value:`lines`,labelKey:`bgLines`},{value:`cross`,labelKey:`bgCross`},{value:`none`,labelKey:`bgNone`}];function Yr(){let{t:e}=C(),{showHud:t,showLegend:n,showMinimap:r,showControls:i,animateEdges:a,background:o,waitThresholdMs:s,setShowHud:c,setShowLegend:l,setShowMinimap:u,setShowControls:d,setAnimateEdges:f,setBackground:p,setWaitThresholdMs:m}=W(h(e=>({showHud:e.showHud,showLegend:e.showLegend,showMinimap:e.showMinimap,showControls:e.showControls,animateEdges:e.animateEdges,background:e.background,waitThresholdMs:e.waitThresholdMs,setShowHud:e.setShowHud,setShowLegend:e.setShowLegend,setShowMinimap:e.setShowMinimap,setShowControls:e.setShowControls,setAnimateEdges:e.setAnimateEdges,setBackground:e.setBackground,setWaitThresholdMs:e.setWaitThresholdMs}))),{clientCounts:g,currentSession:_,totalAgents:v,activeAgents:y}=Qe(h(e=>({clientCounts:e.clientCounts,currentSession:e.currentSession,totalAgents:e.totalAgents,activeAgents:e.activeAgents}))),b=g.tui+g.webui+g.repl;return(0,q.jsxs)(`div`,{className:`flex h-full min-h-0 min-w-0 flex-col gap-4 overflow-y-auto overscroll-contain p-3`,children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`div`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wide mb-2`,children:e(`activity:officeMap.liveHeading`)}),(0,q.jsxs)(`div`,{className:`space-y-1.5 text-xs`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsxs)(`span`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,q.jsx)(fe,{className:`h-3.5 w-3.5`}),` `,e(`activity:officeMap.clients`)]}),(0,q.jsx)(`span`,{className:`font-mono`,children:b})]}),(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsxs)(`span`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,q.jsx)(H,{className:`h-3.5 w-3.5`}),` `,e(`activity:officeMap.agents`)]}),(0,q.jsxs)(`span`,{className:`font-mono`,children:[y,(0,q.jsxs)(`span`,{className:`text-muted-foreground`,children:[` / `,v]})]})]}),_.model&&(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsxs)(`span`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,q.jsx)(de,{className:`h-3.5 w-3.5`}),` `,e(`activity:officeMap.model`)]}),(0,q.jsx)(`span`,{className:`font-mono truncate max-w-[140px]`,title:_.model,children:_.model.split(`/`).pop()})]}),_.mode&&(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsxs)(`span`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,q.jsx)(T,{className:`h-3.5 w-3.5`}),` `,e(`activity:officeMap.mode`)]}),(0,q.jsx)(`span`,{className:`font-mono uppercase text-xs`,children:_.mode})]}),(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsxs)(`span`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,q.jsx)(x,{className:`h-3.5 w-3.5`}),` `,e(`activity:officeMap.toolCalls`)]}),(0,q.jsx)(`span`,{className:`font-mono`,children:(e=>e?.toLocaleString()??`0`)(_.toolCalls)})]})]})]}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`div`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wide mb-1`,children:e(`activity:officeMap.displayHeading`)}),(0,q.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,q.jsx)(qr,{label:e(`activity:officeMap.statsHud`),checked:t,onChange:c}),(0,q.jsx)(qr,{label:e(`activity:officeMap.legends`),checked:n,onChange:l}),(0,q.jsx)(qr,{label:e(`activity:officeMap.minimap`),checked:r,onChange:u}),(0,q.jsx)(qr,{label:e(`activity:officeMap.zoomControls`),checked:i,onChange:d}),(0,q.jsx)(qr,{label:e(`activity:officeMap.animateWires`),checked:a,onChange:f})]})]}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`div`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wide mb-1.5 px-2`,children:e(`activity:officeMap.backgroundHeading`)}),(0,q.jsx)(`div`,{className:`flex flex-wrap gap-1 px-2`,children:Jr.map(t=>(0,q.jsx)(`button`,{type:`button`,onClick:()=>p(t.value),className:U(`px-2 py-1 text-xs rounded transition-colors`,o===t.value?`bg-primary text-primary-foreground`:`bg-muted text-muted-foreground hover:bg-accent`),children:e(`activity:officeMap.${t.labelKey}`)},t.value))})]}),(0,q.jsxs)(`div`,{children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 mb-1.5 px-2 text-xs font-semibold text-muted-foreground uppercase tracking-wide`,children:[(0,q.jsx)(Me,{className:`h-3 w-3`}),e(`activity:officeMap.waitThresholdHeading`)]}),(0,q.jsx)(`p`,{className:`mb-1.5 px-2 text-[11px] text-muted-foreground`,children:e(`activity:officeMap.waitThresholdHint`)}),(0,q.jsx)(`div`,{className:`flex flex-wrap gap-1 px-2`,children:Ze.map(e=>(0,q.jsx)(`button`,{type:`button`,onClick:()=>m(e),className:U(`px-2 py-1 text-xs rounded transition-colors font-mono`,s===e?`bg-primary text-primary-foreground`:`bg-muted text-muted-foreground hover:bg-accent`),children:Xr(e)},e))})]})]})}function Xr(e){let t=e/1e3;return t%60==0&&t>=60?`${t/60}m`:`${t}s`}function Zr(){let[e,t]=(0,K.useState)([]),[n,r]=(0,K.useState)(St),[i,a]=(0,K.useState)(!1),[o,s]=(0,K.useState)(null),c=(0,K.useCallback)(async()=>{a(!0),s(null);try{let e=await G(`agent-roster.list`,{});e.stats&&t(e.stats),e.catalog?.length&&r(e.catalog)}catch(e){s(e instanceof Error?e.message:`Failed to load roster`)}a(!1)},[]);return(0,K.useEffect)(()=>{c()},[c]),(0,K.useEffect)(()=>{let e=null,t=l().on(`agent-roster.updated`,()=>{e&&clearTimeout(e),e=setTimeout(()=>{e=null,c()},300)});return()=>{e&&clearTimeout(e),t()}},[c]),{customStats:e,catalog:n,rosterLoading:i,rosterError:o,loadRoster:c}}function Qr({customStats:e,catalog:t,onRefresh:n}){let{t:r}=C(),[i,a]=(0,K.useState)(null),[o,s]=(0,K.useState)(null),[c,u]=(0,K.useState)(``),[d,f]=(0,K.useState)(null),[p,m]=(0,K.useState)(!1),[h,g]=(0,K.useState)(null),[_,v]=(0,K.useState)(!1),[y,b]=(0,K.useState)({name:``,role:``,baseRole:`generic`,purpose:``,taskTypes:``}),x=(0,K.useMemo)(()=>i?e.find(e=>e.role===i):null,[i,e]),w=(0,K.useMemo)(()=>{let e=t.find(e=>e.role===i);return e?.systemProtected??!e?.custom},[t,i]),T=(0,K.useCallback)(async(e,t)=>{m(!0),g(null),a(e);try{let n=await G(`agent-roster.read-customization`,{role:e});u(t===`config`?`${JSON.stringify(n.config??{},null,2)}\n`:n[t]??``),s(t),f(null)}catch(e){g(e instanceof Error?e.message:r(`activity:agentRoster.loadCustomizationFailed`))}finally{m(!1)}},[]),E=(0,K.useCallback)(async e=>{m(!0),g(null),a(e);try{let t=await G(`agent-roster.read-customization`,{role:e});f(t.config??{}),s(null)}catch(e){g(e instanceof Error?e.message:r(`activity:agentRoster.loadRuntimePolicyFailed`))}finally{m(!1)}},[]),D=(0,K.useCallback)(async e=>{if(i){m(!0),g(null);try{await G(`agent-roster.update-config`,{role:i,config:e}),f(null),n()}catch(e){g(e instanceof Error?e.message:r(`activity:agentRoster.runtimePolicySaveFailed`))}finally{m(!1)}}},[n,i]),O=(0,K.useCallback)(async()=>{if(!(!i||!o)){m(!0);try{let e={identity:`agent-roster.update-identity`,learned:`agent-roster.update-learned`,config:`agent-roster.update-config`},t={role:i};if(o===`config`)try{t.config=JSON.parse(c)}catch{g(`config.json must contain valid JSON`),m(!1);return}else t.content=c;await G(e[o],t),s(null),g(null),n()}catch(e){g(e instanceof Error?e.message:r(`activity:agentRoster.saveFailed`))}m(!1)}},[i,o,c,n]),k=(0,K.useCallback)(async()=>{if(i)try{let e=await G(`agent-roster.llm-improve`,{role:i,prompt:`Improve this agent for optimal project performance`});if(!e.instruction)throw Error(`No improvement instruction generated`);let t=Xe.getState();t.addMessage({role:`user`,content:e.instruction}),t.setLoading(!0),l().sendMessage(e.instruction);let n=Ye.getState();n.setSidebarOpen(!1),n.setCurrentView(`chat`)}catch(e){g(e instanceof Error?e.message:r(`activity:agentRoster.llmImprovementFailed`))}},[i]),A=(0,K.useCallback)(async e=>{if(window.confirm(r(`activity:agentRoster.resetConfirm`,{role:e})))try{await G(`agent-roster.reset`,{role:e}),a(null),n()}catch{}},[n]),j=(0,K.useCallback)(async()=>{let e=y.taskTypes.split(/[\n,]+/).map(e=>e.trim()).filter(Boolean);m(!0),g(null);try{let t=await G(`agent-roster.create`,{name:y.name,role:y.role,baseRole:y.baseRole,purpose:y.purpose,taskTypes:e});v(!1),b({name:``,role:``,baseRole:`generic`,purpose:``,taskTypes:``}),a(t.role),n()}catch(e){g(e instanceof Error?e.message:r(`activity:agentRoster.agentCreationFailed`))}finally{m(!1)}},[y,n]),M=(0,K.useMemo)(()=>[...e].sort((e,t)=>{let n=+!!e.hasIdentity+ +(e.entryCount>0)+ +!!e.hasConfig;return+!!t.hasIdentity+ +(t.entryCount>0)+ +!!t.hasConfig-n}),[e]);return(0,q.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 overflow-hidden`,children:[(0,q.jsxs)(`div`,{className:`w-80 shrink-0 border-r border-border/50 flex flex-col overflow-hidden`,children:[(0,q.jsx)(`div`,{className:`shrink-0 border-b border-border/50 px-3 py-2`,children:(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,q.jsxs)(`h3`,{className:`flex items-center gap-1.5 text-xs font-semibold`,children:[(0,q.jsx)(N,{className:`h-3.5 w-3.5`}),r(`activity:agentRoster.projectAgents`)]}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>{v(!0),a(null),f(null),g(null)},className:`rounded border border-primary/40 px-1.5 py-1 text-[9px] text-primary hover:bg-primary/10`,children:r(`activity:agentRoster.clone`)})]})}),(0,q.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-2 space-y-1`,children:[M.map(e=>(0,q.jsxs)(`button`,{type:`button`,onClick:()=>{a(e.role),f(null),s(null)},className:U(`w-full text-left rounded-lg border px-3 py-2 transition-colors`,i===e.role?`border-primary/50 bg-primary/[0.06]`:`border-border/60 hover:border-primary/30`),children:[(0,q.jsx)(`div`,{className:`text-xs font-semibold`,children:e.role}),(0,q.jsxs)(`div`,{className:`flex gap-2 mt-0.5 text-[9px] text-muted-foreground`,children:[e.hasIdentity&&(0,q.jsx)(`span`,{className:`text-primary`,children:`id`}),e.entryCount>0&&(0,q.jsxs)(`span`,{className:`text-brand-2`,children:[e.entryCount,`e`]}),e.hasConfig&&(0,q.jsx)(`span`,{children:`cfg`})]})]},e.role)),M.length===0&&(0,q.jsx)(`div`,{className:`text-[10px] text-muted-foreground text-center py-4`,children:r(`activity:agentRoster.noCustomizations`)})]})]}),(0,q.jsxs)(`div`,{className:`flex-1 min-h-0 min-w-0 overflow-y-auto p-4`,children:[_&&(0,q.jsxs)(`div`,{className:`max-w-2xl space-y-4`,children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`h3`,{className:`text-base font-semibold`,children:r(`activity:agentRoster.createOrCloneTitle`)}),(0,q.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:r(`activity:agentRoster.createOrCloneHint`)})]}),(0,q.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[(0,q.jsx)(`span`,{className:`font-medium`,children:r(`activity:agentRoster.cloneFromRole`)}),(0,q.jsx)(`select`,{value:y.baseRole,onChange:e=>b(t=>({...t,baseRole:e.target.value})),className:`h-9 w-full rounded border border-border bg-card px-2`,children:[...t].sort((e,t)=>e.name.localeCompare(t.name)).map(e=>(0,q.jsxs)(`option`,{value:e.role,children:[e.name,` (`,e.role,`)`]},e.role))}),(0,q.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:r(`activity:agentRoster.cloneHint`)})]}),(0,q.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,q.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[(0,q.jsx)(`span`,{className:`font-medium`,children:r(`activity:agentRoster.displayName`)}),(0,q.jsx)(`input`,{value:y.name,onChange:e=>b(t=>({...t,name:e.target.value})),placeholder:r(`activity:agentRoster.abc`),className:`h-9 w-full rounded border border-border bg-card px-2`})]}),(0,q.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[(0,q.jsx)(`span`,{className:`font-medium`,children:r(`activity:agentRoster.roleIdOptional`)}),(0,q.jsx)(`input`,{value:y.role,onChange:e=>b(t=>({...t,role:e.target.value})),placeholder:r(`activity:agentRoster.abcGeneratedFromName`),className:`h-9 w-full rounded border border-border bg-card px-2 font-mono`})]})]}),(0,q.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[(0,q.jsx)(`span`,{className:`font-medium`,children:r(`activity:agentRoster.purpose`)}),(0,q.jsx)(`textarea`,{value:y.purpose,onChange:e=>b(t=>({...t,purpose:e.target.value})),placeholder:r(`activity:agentRoster.descriptionPlaceholder`),className:`h-24 w-full resize-y rounded border border-border bg-card p-2`})]}),(0,q.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[(0,q.jsx)(`span`,{className:`font-medium`,children:r(`activity:agentRoster.taskTypesCommaOrOnePer`)}),(0,q.jsx)(`textarea`,{value:y.taskTypes,onChange:e=>b(t=>({...t,taskTypes:e.target.value})),placeholder:r(`activity:agentRoster.taskTypesPlaceholder`),className:`h-24 w-full resize-y rounded border border-border bg-card p-2`})]}),h&&(0,q.jsx)(`p`,{className:`text-xs text-destructive`,children:h}),(0,q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,q.jsx)(`button`,{type:`button`,onClick:j,disabled:p||!y.name.trim()||y.purpose.trim().length<10||!y.taskTypes.trim(),className:`rounded bg-primary px-3 py-1.5 text-xs text-primary-foreground disabled:opacity-50`,children:p?r(`activity:agentRoster.creating`):`Clone Agent`}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>v(!1),className:`rounded border border-border px-3 py-1.5 text-xs hover:bg-accent`,children:r(`activity:agentRoster.cancel`)})]})]}),!_&&!i&&(0,q.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground`,children:r(`activity:agentRoster.selectAnAgentToEditCustomizations`)}),!_&&i&&x&&(0,q.jsxs)(`div`,{className:`space-y-4 max-w-2xl`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsx)(`h3`,{className:`text-base font-semibold`,children:i}),(0,q.jsxs)(`div`,{className:`flex gap-1`,children:[(0,q.jsxs)(`button`,{type:`button`,onClick:k,className:`inline-flex items-center gap-1 rounded border border-border/50 px-2 py-1 text-[10px] hover:bg-accent transition-colors`,children:[(0,q.jsx)(S,{className:`h-3 w-3 text-brand-2`}),` `,r(`activity:agentRoster.llmImprove`)]}),(0,q.jsxs)(`button`,{type:`button`,onClick:()=>A(i),className:`inline-flex items-center gap-1 rounded border border-destructive/30 px-2 py-1 text-[10px] text-destructive hover:bg-destructive/10 transition-colors`,children:[(0,q.jsx)(pe,{className:`h-3 w-3`}),` `,r(`activity:agentRoster.reset`)]})]})]}),(0,q.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[x.hasIdentity&&(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded bg-primary/10 px-2 py-1 text-[10px] text-primary`,children:[(0,q.jsx)(ae,{className:`h-3 w-3`}),` identity.md`]}),x.hasConfig&&(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded bg-muted px-2 py-1 text-[10px] text-muted-foreground`,children:[(0,q.jsx)(N,{className:`h-3 w-3`}),` config.json`]}),x.hasKnowledge&&(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded bg-muted px-2 py-1 text-[10px] text-muted-foreground`,children:[(0,q.jsx)(B,{className:`h-3 w-3`}),` knowledge.json`]}),x.entryCount>0&&(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded bg-brand-2/10 px-2 py-1 text-[10px] text-brand-2`,children:[(0,q.jsx)(le,{className:`h-3 w-3`}),` `,x.entryCount,` learned entries`]})]}),(0,q.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,q.jsxs)(`button`,{type:`button`,onClick:()=>T(i,`identity`),className:`inline-flex items-center gap-1 rounded border border-border/50 px-3 py-1.5 text-xs hover:bg-accent transition-colors`,children:[(0,q.jsx)(ae,{className:`h-3.5 w-3.5`}),` `,r(`activity:agentRoster.editIdentityMd`)]}),(0,q.jsxs)(`button`,{type:`button`,onClick:()=>T(i,`learned`),className:`inline-flex items-center gap-1 rounded border border-border/50 px-3 py-1.5 text-xs hover:bg-accent transition-colors`,children:[(0,q.jsx)(le,{className:`h-3.5 w-3.5`}),` `,r(`activity:agentRoster.editLearnedMd`)]}),(0,q.jsxs)(`button`,{type:`button`,onClick:()=>E(i),className:`inline-flex items-center gap-1 rounded border border-primary/40 bg-primary/5 px-3 py-1.5 text-xs text-primary hover:bg-primary/10 transition-colors`,children:[(0,q.jsx)(P,{className:`h-3.5 w-3.5`}),` `,r(`activity:agentRoster.runtimePolicy`)]}),(0,q.jsxs)(`button`,{type:`button`,onClick:()=>T(i,`config`),className:`inline-flex items-center gap-1 rounded border border-border/50 px-3 py-1.5 text-xs hover:bg-accent transition-colors`,children:[(0,q.jsx)(N,{className:`h-3.5 w-3.5`}),` `,r(`activity:agentRoster.editConfigJson`)]})]}),h&&(0,q.jsx)(`p`,{className:`text-xs text-destructive`,children:h}),d&&(0,q.jsx)(yt,{initialConfig:d,systemProtected:w,saving:p,onSave:D,onCancel:()=>f(null)},i),o&&(0,q.jsxs)(`div`,{className:`space-y-2`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsxs)(`span`,{className:`text-xs font-medium`,children:[o,`.md / `,o,`.json`]}),(0,q.jsxs)(`div`,{className:`flex gap-1`,children:[(0,q.jsx)(`button`,{type:`button`,onClick:O,disabled:p,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs text-primary-foreground hover:bg-primary/90 transition-colors disabled:opacity-50`,children:r(p?`activity:agentRoster.saving`:`common:action.save`)}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>s(null),className:`inline-flex items-center gap-1 rounded border border-border/50 px-3 py-1.5 text-xs hover:bg-accent transition-colors`,children:r(`activity:agentRoster.cancel`)})]})]}),(0,q.jsx)(`textarea`,{className:`w-full h-48 font-mono text-xs p-2 bg-card border border-border rounded resize-y`,value:c,onChange:e=>u(e.target.value),placeholder:o===`config`?`{ "tools": [...], "budget": {...} }`:`# Project identity for ${i}\n\nDescribe this agent's role…`})]})]})]})]})}function $r({className:e,initialTab:t=`live`}){let{t:n}=C(),r=Ye(e=>e.agentRosterActiveTab),i=Ye(e=>e.setAgentRosterActiveTab),[a,o]=(0,K.useState)(t),s=r??a,c=(0,K.useCallback)(e=>{o(e),typeof i==`function`&&i(e)},[i]),[l,u]=(0,K.useState)(Date.now()),{customStats:d,catalog:f,rosterLoading:p,rosterError:m,loadRoster:h}=Zr();return(0,K.useEffect)(()=>{let e=setInterval(()=>{document.hidden||u(Date.now())},2e3);return()=>clearInterval(e)},[]),(0,q.jsxs)(`div`,{className:U(`flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden`,e),children:[(0,q.jsx)(Ct,{customStats:d,rosterLoading:p,onRefresh:h}),(0,q.jsx)(wt,{activeTab:s,onTabChange:c}),(0,q.jsxs)(`div`,{className:`flex min-h-0 min-w-0 w-full flex-1 overflow-hidden bg-background/50`,children:[m&&(0,q.jsxs)(`div`,{className:`flex items-center justify-center w-full text-destructive text-xs gap-2`,children:[(0,q.jsx)(ye,{className:`h-4 w-4`}),m,(0,q.jsx)(`button`,{type:`button`,onClick:h,className:`underline`,children:n(`activity:agentRoster.retry`)})]}),s===`live`&&(0,q.jsx)(jt,{nowTick:l}),s===`officemap`&&(0,q.jsxs)(`div`,{className:`flex min-h-0 min-w-0 w-full`,children:[(0,q.jsx)(`div`,{className:`min-h-0 min-w-0 flex-1 overflow-hidden`,children:(0,q.jsx)(Kr,{})}),(0,q.jsx)(`aside`,{className:`w-60 shrink-0 overflow-y-auto border-l border-border/60`,children:(0,q.jsx)(Yr,{})})]}),s===`catalog`&&(0,q.jsx)(bt,{customStats:d,catalog:f}),s===`learning`&&(0,q.jsx)(Lt,{customStats:d,onRefresh:h}),s===`memory`&&(0,q.jsx)(ft,{}),s===`customize`&&(0,q.jsx)(Qr,{customStats:d,catalog:f,onRefresh:h})]})]})}export{$r as AgentRosterView};
@@ -0,0 +1 @@
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{et as t,t as n}from"./ws-client-C_IqS0t4.js";import{i as r,t as i}from"./react-core-BNmTiJ-I.js";import{Da as a,Fa as o,Kn as s,Nn as c,Xi as l,di as u,et as d,ht as f,lt as p,si as m,ut as h}from"./vendor-BshlG0z-.js";import"./i18n-DBqM1FUM.js";import"./stores-Cfei1ViB.js";import{b as g,g as _,x as v}from"./index-TDhvFXb0.js";var y=e(r(),1),b=i();function x(e){let t=Math.floor(e/1e3);if(t<60)return`${t}s`;let n=Math.floor(t/60);if(n<60)return`${n}m ${t%60}s`;let r=Math.floor(n/60);return r<24?`${r}h ${n%60}m`:`${Math.floor(r/24)}d`}function S(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e)}function C(e){return e<.01?`$${e.toFixed(4)}`:`$${e.toFixed(2)}`}function w(e){return new Date(e).toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`,second:`2-digit`})}function T(e){return e.includes(`error`)||e.includes(`fail`)?`text-destructive`:e.includes(`warn`)?`text-warning`:e.includes(`success`)||e.includes(`complete`)?`text-success`:`text-muted-foreground`}function E({icon:e,label:t,value:n,sub:r,color:i=`text-muted-foreground`}){return(0,b.jsxs)(`div`,{className:`flex items-start gap-3 rounded-xl border border-border/70 bg-card/75 p-4 shadow-sm`,children:[(0,b.jsx)(`div`,{className:`mt-0.5 ${i}`,children:e}),(0,b.jsxs)(`div`,{className:`min-w-0`,children:[(0,b.jsx)(`div`,{className:`text-2xl font-semibold tabular-nums text-foreground`,children:n}),(0,b.jsx)(`div`,{className:`mt-0.5 text-xs text-muted-foreground`,children:t}),r?(0,b.jsx)(`div`,{className:`mt-1 text-xs text-muted-foreground/70`,children:r}):null]})]})}function D(){let{t:e}=o(),[r,i]=(0,y.useState)(null),[D,O]=(0,y.useState)([]),[k,A]=(0,y.useState)([]),[j,M]=(0,y.useState)(null),[N,P]=(0,y.useState)(!0),[F,I]=(0,y.useState)(!1),L=(0,y.useRef)(null),R=(0,y.useCallback)(async()=>{try{let e=await fetch(`/api/analytics/summary`);if(e.ok){let t=await e.json();i(t)}}catch{}},[]),z=(0,y.useCallback)(async()=>{try{let e=await fetch(`/api/analytics?limit=50`);if(e.ok){let t=await e.json();O(t.events)}}catch{}},[]),B=(0,y.useCallback)(async()=>{try{let e=await fetch(`/api/sessions`);if(e.ok){let t=await e.json();A(t)}}catch{}},[]),V=(0,y.useCallback)(async()=>{if(F)return;I(!0);let e=null,r=null;try{let i=n(t.getState().wsUrl);L.current=i,r=i.on(`stats.get`,t=>{let n=t.payload;M(n),I(!1),r?.(),e!==null&&clearTimeout(e)}),i.getStats({echoToChat:!1}),e=setTimeout(()=>{r?.(),I(!1)},8e3)}catch{r?.(),e!==null&&clearTimeout(e),I(!1)}},[F]);(0,y.useEffect)(()=>{let e=()=>{Promise.all([R(),z(),B(),V()]).finally(()=>P(!1))};e();let t=setInterval(e,1e4);return()=>clearInterval(t)},[R,z,B,V]);let{totalAgents:H,activeAgents:U,totalToolCalls:W,totalIterations:G}=(0,y.useMemo)(()=>{let e=0,t=0,n=0,r=0;for(let i of k)for(let a of i.agents)e++,a.status===`running`&&t++,n+=a.toolCalls,r+=a.iterations;return{totalAgents:e,activeAgents:t,totalToolCalls:n,totalIterations:r}},[k]),K=(0,y.useMemo)(()=>r?Object.entries(r.categoryBreakdown).sort((e,t)=>t[1]-e[1]).slice(0,8):[],[r]),q=(0,y.useMemo)(()=>r?Object.entries(r.eventBreakdown).sort((e,t)=>t[1]-e[1]).slice(0,10):[],[r]),J=(0,y.useMemo)(()=>{if(!r)return 0;let e=0;for(let[t,n]of Object.entries(r.eventBreakdown))t.toLowerCase().includes(`error`)&&(e+=n);return e},[r]),Y=(0,y.useMemo)(()=>{if(!r)return 0;let e=0;for(let[t,n]of Object.entries(r.eventBreakdown))t.toLowerCase().includes(`warn`)&&(e+=n);return e},[r]),X=(0,y.useMemo)(()=>[...D].reverse(),[D]),Z=v(X,20);return N?(0,b.jsx)(`div`,{className:`flex h-full min-h-0 items-center justify-center bg-[hsl(var(--surface-2)/0.45)] p-4`,children:(0,b.jsxs)(`div`,{className:`ws-surface flex items-center gap-2 rounded-xl px-4 py-3 text-sm text-muted-foreground`,children:[(0,b.jsx)(s,{className:`h-4 w-4 animate-spin text-primary`}),e(`activity:analytics.loading`)]})}):(0,b.jsx)(`div`,{ref:_(`analytics`),className:`h-full min-h-0 min-w-0 overflow-y-auto overscroll-contain bg-[hsl(var(--surface-2)/0.45)] p-4 sm:p-6`,children:(0,b.jsxs)(`div`,{className:`mx-auto flex w-full max-w-7xl flex-col gap-5`,children:[(0,b.jsx)(`div`,{className:`rounded-xl border border-border/70 bg-card/75 p-4 shadow-sm`,children:(0,b.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between`,children:[(0,b.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,b.jsx)(l,{className:`h-4 w-4 text-primary`}),(0,b.jsx)(`h1`,{className:`truncate text-base font-semibold`,children:e(`activity:analytics.heading`)})]}),(0,b.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e(`activity:analytics.autoRefresh`)})]})}),(0,b.jsxs)(`div`,{className:`min-w-0 space-y-5`,children:[(0,b.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-3 lg:grid-cols-6 gap-3`,children:[(0,b.jsx)(E,{icon:(0,b.jsx)(a,{className:`h-4 w-4`}),label:e(`activity:analytics.liveSessions`),value:k.length,color:`text-primary`}),(0,b.jsx)(E,{icon:(0,b.jsx)(d,{className:`h-4 w-4`}),label:e(`activity:analytics.agents`),value:`${U}/${H}`,sub:U>0?e(`activity:analytics.agentsActive`,{count:U}):void 0,color:`text-success`}),(0,b.jsx)(E,{icon:(0,b.jsx)(c,{className:`h-4 w-4`}),label:e(`activity:analytics.totalEvents`),value:r?.totalEvents??0,sub:e(`activity:analytics.categoriesSub`,{count:r?.uniqueCategories??0}),color:`text-warning`}),(0,b.jsx)(E,{icon:(0,b.jsx)(f,{className:`h-4 w-4`}),label:e(`activity:analytics.toolCalls`),value:W,sub:e(`activity:analytics.iterationsSub`,{count:G}),color:`text-success`}),(0,b.jsx)(E,{icon:(0,b.jsx)(m,{className:`h-4 w-4`}),label:e(`activity:analytics.sessionCost`),value:j?C(j.cost):`—`,sub:j?e(`activity:analytics.tokensSub`,{input:S(j.usage.input),output:S(j.usage.output)}):void 0,color:`text-primary`}),(0,b.jsx)(E,{icon:(0,b.jsx)(u,{className:`h-4 w-4`}),label:e(`activity:analytics.sessionDuration`),value:j?x(j.elapsedMs):`—`,sub:j?e(`activity:analytics.messagesSub`,{count:j.messages}):void 0,color:`text-muted-foreground`})]}),(0,b.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4`,children:[(0,b.jsxs)(`div`,{className:`rounded-xl border border-border/70 bg-card/75 p-4 shadow-sm`,children:[(0,b.jsxs)(`h3`,{className:`mb-3 flex items-center gap-2 text-xs font-semibold uppercase text-muted-foreground`,children:[(0,b.jsx)(h,{className:`h-3.5 w-3.5 text-primary`}),e(`activity:analytics.eventsByCategory`)]}),K.length===0?(0,b.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`activity:analytics.noEvents`)}):(0,b.jsx)(`div`,{className:`space-y-1.5`,children:K.map(([e,t])=>{let n=K[0]?.[1]??1,r=Math.round(t/n*100);return(0,b.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,7rem)_minmax(0,1fr)_2.5rem] items-center gap-2 text-xs`,children:[(0,b.jsx)(`span`,{className:`min-w-0 truncate text-foreground`,children:e}),(0,b.jsx)(`div`,{className:`h-4 overflow-hidden rounded-full bg-muted`,children:(0,b.jsx)(`div`,{className:`h-full rounded-full bg-primary/70 transition-all`,style:{width:`${Math.max(r,4)}%`}})}),(0,b.jsx)(`span`,{className:`text-right tabular-nums text-muted-foreground`,children:t})]},e)})})]}),(0,b.jsxs)(`div`,{className:`rounded-xl border border-border/70 bg-card/75 p-4 shadow-sm`,children:[(0,b.jsxs)(`h3`,{className:`mb-3 flex items-center gap-2 text-xs font-semibold uppercase text-muted-foreground`,children:[(0,b.jsx)(l,{className:`h-3.5 w-3.5 text-warning`}),e(`activity:analytics.topEvents`)]}),q.length===0?(0,b.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`activity:analytics.noEvents`)}):(0,b.jsx)(`div`,{className:`space-y-1.5`,children:q.map(([e,t])=>{let n=q[0]?.[1]??1,r=Math.round(t/n*100);return(0,b.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,9rem)_minmax(0,1fr)_2.5rem] items-center gap-2 text-xs`,children:[(0,b.jsx)(`span`,{className:`min-w-0 truncate ${T(e)}`,children:e}),(0,b.jsx)(`div`,{className:`h-4 overflow-hidden rounded-full bg-muted`,children:(0,b.jsx)(`div`,{className:`h-full rounded-full bg-warning/70 transition-all`,style:{width:`${Math.max(r,4)}%`}})}),(0,b.jsx)(`span`,{className:`text-right tabular-nums text-muted-foreground`,children:t})]},e)})})]})]}),(0,b.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4`,children:[(0,b.jsxs)(`div`,{className:`rounded-xl border border-border/70 bg-card/75 p-4 shadow-sm`,children:[(0,b.jsxs)(`h3`,{className:`mb-3 flex items-center gap-2 text-xs font-semibold uppercase text-muted-foreground`,children:[(0,b.jsx)(m,{className:`h-3.5 w-3.5 text-primary`}),e(`activity:analytics.activeSessionUsage`)]}),j?(0,b.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 text-xs`,children:[(0,b.jsxs)(`div`,{className:`min-w-0 rounded-lg border border-border/70 bg-background/50 px-3 py-2`,children:[(0,b.jsx)(`span`,{className:`text-muted-foreground`,children:e(`activity:analytics.provider`)}),(0,b.jsx)(`p`,{className:`mt-0.5 truncate font-mono text-foreground`,children:j.provider})]}),(0,b.jsxs)(`div`,{className:`min-w-0 rounded-lg border border-border/70 bg-background/50 px-3 py-2`,children:[(0,b.jsx)(`span`,{className:`text-muted-foreground`,children:e(`activity:analytics.model`)}),(0,b.jsx)(`p`,{className:`mt-0.5 truncate font-mono text-foreground`,children:j.model})]}),(0,b.jsxs)(`div`,{className:`rounded-lg border border-border/70 bg-background/50 px-3 py-2`,children:[(0,b.jsx)(`span`,{className:`text-muted-foreground`,children:e(`activity:analytics.inputTokens`)}),(0,b.jsx)(`p`,{className:`mt-0.5 tabular-nums text-foreground`,children:S(j.usage.input)})]}),(0,b.jsxs)(`div`,{className:`rounded-lg border border-border/70 bg-background/50 px-3 py-2`,children:[(0,b.jsx)(`span`,{className:`text-muted-foreground`,children:e(`activity:analytics.outputTokens`)}),(0,b.jsx)(`p`,{className:`mt-0.5 tabular-nums text-foreground`,children:S(j.usage.output)})]}),(0,b.jsxs)(`div`,{className:`rounded-lg border border-border/70 bg-background/50 px-3 py-2`,children:[(0,b.jsx)(`span`,{className:`text-muted-foreground`,children:e(`activity:analytics.cacheRatio`)}),(0,b.jsxs)(`p`,{className:`mt-0.5 tabular-nums text-foreground`,children:[(j.cache.hitRatio*100).toFixed(1),`%`]})]}),(0,b.jsxs)(`div`,{className:`rounded-lg border border-border/70 bg-background/50 px-3 py-2`,children:[(0,b.jsx)(`span`,{className:`text-muted-foreground`,children:e(`activity:analytics.filesRead`)}),(0,b.jsx)(`p`,{className:`mt-0.5 tabular-nums text-foreground`,children:j.readFiles})]}),(j.cache.providers?.length??0)>0?(0,b.jsxs)(`div`,{className:`col-span-2 rounded-lg border border-border/70 bg-background/50 px-3 py-2`,children:[(0,b.jsx)(`span`,{className:`text-muted-foreground`,children:`Provider cache breakdown`}),(0,b.jsx)(`div`,{className:`mt-1.5 space-y-1`,children:j.cache.providers?.map(e=>(0,b.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-x-3 font-mono`,children:[(0,b.jsx)(`span`,{className:`text-foreground`,children:e.provider}),(0,b.jsxs)(`span`,{className:`tabular-nums text-success`,children:[(e.hitRatio*100).toFixed(1),`% hit`]}),(0,b.jsxs)(`span`,{className:`tabular-nums text-muted-foreground`,children:[S(e.cacheRead),` read ·`,` `,S(e.cacheWrite),` write`]})]},e.provider))})]}):null]}):(0,b.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`activity:analytics.noSession`)})]}),(0,b.jsxs)(`div`,{className:`rounded-xl border border-border/70 bg-card/75 p-4 shadow-sm`,children:[(0,b.jsxs)(`h3`,{className:`mb-3 flex items-center gap-2 text-xs font-semibold uppercase text-muted-foreground`,children:[(0,b.jsx)(p,{className:`h-3.5 w-3.5 text-warning`}),e(`activity:analytics.healthErrors`)]}),(0,b.jsx)(`div`,{className:`space-y-2 text-xs`,children:r?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsxs)(`div`,{className:`flex justify-between`,children:[(0,b.jsx)(`span`,{className:`text-muted-foreground`,children:e(`activity:analytics.errorEvents`)}),(0,b.jsx)(`span`,{className:`tabular-nums text-destructive`,children:J})]}),(0,b.jsxs)(`div`,{className:`flex justify-between`,children:[(0,b.jsx)(`span`,{className:`text-muted-foreground`,children:e(`activity:analytics.warningEvents`)}),(0,b.jsx)(`span`,{className:`tabular-nums text-warning`,children:Y})]}),(0,b.jsxs)(`div`,{className:`flex justify-between`,children:[(0,b.jsx)(`span`,{className:`text-muted-foreground`,children:e(`activity:analytics.cacheHitRate`)}),(0,b.jsx)(`span`,{className:`tabular-nums text-success`,children:j?`${(j.cache.hitRatio*100).toFixed(1)}%`:`—`})]}),(0,b.jsxs)(`div`,{className:`flex justify-between`,children:[(0,b.jsx)(`span`,{className:`text-muted-foreground`,children:e(`activity:analytics.totalCategories`)}),(0,b.jsx)(`span`,{className:`tabular-nums text-foreground`,children:r.uniqueCategories})]})]}):(0,b.jsx)(`p`,{className:`text-muted-foreground`,children:e(`activity:analytics.waitingData`)})})]})]}),(0,b.jsxs)(`div`,{className:`rounded-xl border border-border/70 bg-card/75 p-4 shadow-sm`,children:[(0,b.jsxs)(`h3`,{className:`mb-3 flex items-center gap-2 text-xs font-semibold uppercase text-muted-foreground`,children:[(0,b.jsx)(a,{className:`h-3.5 w-3.5 text-primary`}),e(`activity:analytics.recentEvents`)]}),D.length===0?(0,b.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`activity:analytics.noRecentEvents`)}):(0,b.jsx)(`div`,{className:`max-h-64 space-y-1 overflow-y-auto`,children:Z.pageItems.map((e,t)=>(0,b.jsxs)(`div`,{className:`grid grid-cols-[4rem_minmax(0,7rem)_minmax(0,6rem)_minmax(0,1fr)] items-start gap-2 rounded px-2 py-1 text-xs hover:bg-muted/60`,children:[(0,b.jsx)(`span`,{className:`tabular-nums text-muted-foreground/70`,children:w(e.timestamp)}),(0,b.jsx)(`span`,{className:`min-w-0 truncate ${T(e.event)}`,children:e.event}),(0,b.jsx)(`span`,{className:`min-w-0 truncate text-muted-foreground`,children:e.category}),(0,b.jsx)(`span`,{className:`min-w-0 truncate text-foreground/80`,children:e.label??e.sessionId??``})]},`${e.timestamp}-${t}`))}),(0,b.jsx)(g,{page:Z.page,pageSize:Z.pageSize,totalItems:Z.totalItems,onPageChange:Z.setPage,compact:!0,itemLabel:`events`,className:`mt-3 rounded-lg border`})]})]})]})})}export{D as AnalyticsDashboard};
@@ -0,0 +1,3 @@
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,t as n}from"./react-core-BNmTiJ-I.js";import{Er as r,Fa as i,K as a,Mt as o,Vt as s,_t as c,ft as l,oi as u,ot as d,sn as f,tn as p}from"./vendor-BshlG0z-.js";import"./i18n-DBqM1FUM.js";import{t as m}from"./useWebSocket-AYEcpb1U.js";import{t as h}from"./utils-BpBOwXlT.js";import{a as g,i as _,n as v,o as y,r as b,t as x}from"./dialog-xJxaQi60.js";import{t as S}from"./button-rqi3MczV.js";import{t as C}from"./input-ClZR-odw.js";import{b as w,x as T}from"./index-TDhvFXb0.js";import{g as E,i as D,r as O,y as k}from"./shared-D8dubdNH.js";var A=e(t(),1),j=n();function M(e){if(!Array.isArray(e))return;let t=[...new Set(e.filter(e=>typeof e==`string`).map(e=>e.trim()).filter(Boolean))];return t.length>0?t:void 0}function N(e){if(!e||typeof e!=`object`||Array.isArray(e))return;let t=e,n={roles:M(t.roles),taskTypes:M(t.taskTypes),modes:M(t.modes)};return n.roles||n.taskTypes||n.modes?n:void 0}function ee(e){let t=e.trim().replace(/^```(?:json)?\s*/i,``).replace(/\s*```$/,``),n=JSON.parse(t);if(!Array.isArray(n))throw Error(`Input must be a JSON array.`);let r=[],i=0;for(let e of n){if(!e||typeof e!=`object`||Array.isArray(e)){i++;continue}let t=e,n=typeof t.text==`string`?t.text.trim():``,a=N(t.audience);if(!n||!a){i++;continue}let o=typeof t.kind==`string`&&D.some(e=>e===t.kind)?t.kind:void 0,s=M(t.tags);r.push({text:n,audience:a,kind:o,tags:s,importance:typeof t.importance==`number`?t.importance:void 0,confidence:typeof t.confidence==`number`?t.confidence:void 0})}return{entries:r,skipped:i}}function P(e,t){if(!t)return!0;let n=e.audience;return[e.text,e.kind,e.status,...n?.roles??[],...n?.taskTypes??[],...n?.modes??[]].join(` `).toLocaleLowerCase().includes(t.toLocaleLowerCase())}function F(e,t){return[...new Set(e.flatMap(e=>e.audience?.[t]??[]).filter(e=>e.length>0))].sort((e,t)=>e.localeCompare(t))}function I(){let{t:e}=i(),t=m(),[n,o]=(0,A.useState)([]),[D,O]=(0,A.useState)(!0),[k,M]=(0,A.useState)(null),[N,I]=(0,A.useState)(``),[z,B]=(0,A.useState)(!1),[ae,V]=(0,A.useState)(!1),[H,U]=(0,A.useState)(null),[W,G]=(0,A.useState)(!1),[K,q]=(0,A.useState)(!1),J=(0,A.useRef)(null),Y=(0,A.useCallback)(()=>{O(!0),M(null),t.listSageMemories({echoToChat:!1})},[t.listSageMemories]);(0,A.useEffect)(()=>{let n=t.client,r=n.on(`memory.sage.list`,e=>{let t=e.payload;t.error?M({tone:`error`,text:t.error}):o(t.memories??[]),O(!1)}),i=n.on(`memory.sage.remember`,e=>{let t=e.payload;if(G(!1),t.error){M({tone:`error`,text:t.error});return}t.memory&&(o(e=>[t.memory,...e.filter(e=>e.id!==t.memory.id)]),B(!1))}),a=n.on(`memory.sage.update`,t=>{let n=t.payload;n.error?M({tone:`error`,text:n.error}):n.memory&&(o(e=>e.map(e=>e.id===n.memory.id?n.memory:e)),n.memory.audience||M({tone:`success`,text:e(`activity:audienceMem.scopeRemoved`)}))}),s=n.on(`memory.sage.delete`,t=>{let n=t.payload,r=J.current;n.success&&r?(o(e=>e.filter(e=>e.id!==r)),M({tone:`success`,text:e(`activity:audienceMem.deleted`)}),U(null),q(!1),J.current=null):n.success?Y():(M({tone:`error`,text:n.message??`Could not delete the memory.`}),q(!1),J.current=null)});return Y(),()=>{r(),i(),a(),s()}},[Y,t.client]);let X=(0,A.useMemo)(()=>n.filter(e=>{let t=e.audience;return!!(t&&(t.roles?.length||t.taskTypes?.length||t.modes?.length))}),[n]),Z=N.trim(),Q=(0,A.useMemo)(()=>X.filter(e=>P(e,Z)),[Z,X]),$=T(Q,16,Z),oe=(0,A.useMemo)(()=>F(X,`roles`),[X]),se=(0,A.useMemo)(()=>F(X,`taskTypes`),[X]),ce=(0,A.useMemo)(()=>F(X,`modes`),[X]),le=e=>{M(null),t.updateSage(e,{audience:void 0},{echoToChat:!1})},ue=()=>{H&&(J.current=H,q(!0),M(null),t.deleteSage(H,`Removed from the audience memory panel.`))},de=async()=>{let t=X.map(e=>({id:e.id,text:e.text,kind:e.kind,status:e.status,audience:e.audience,tags:e.tags,importance:e.importance,confidence:e.confidence}));try{if(!navigator.clipboard)throw Error(`Clipboard access is unavailable.`);await navigator.clipboard.writeText(JSON.stringify(t,null,2)),M({tone:`success`,text:e(`activity:audienceMem.copiedAsJson`,{count:t.length})})}catch(t){M({tone:`error`,text:t instanceof Error?t.message:e(`activity:audienceMem.copyFailed`)})}};return(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)(`section`,{className:`flex h-full min-h-0 flex-col bg-card/20`,"aria-labelledby":`audience-memory-title`,children:[(0,j.jsxs)(`div`,{className:`shrink-0 border-b border-border/60 p-3`,children:[(0,j.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,j.jsx)(`div`,{className:`min-w-0`,children:(0,j.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,j.jsx)(`span`,{className:`flex size-7 shrink-0 items-center justify-center rounded-md border border-primary/20 bg-primary/10 text-primary`,children:(0,j.jsx)(c,{className:`size-3.5`})}),(0,j.jsxs)(`div`,{className:`min-w-0`,children:[(0,j.jsx)(`h2`,{id:`audience-memory-title`,className:`truncate text-sm font-semibold`,children:e(`activity:audienceMem.heading`)}),(0,j.jsx)(`p`,{className:`truncate text-[10px] text-muted-foreground`,children:e(`activity:audienceMem.subheading`)})]})]})}),(0,j.jsxs)(S,{variant:`default`,size:`sm`,className:`h-7 shrink-0 gap-1 px-2 text-xs`,onClick:()=>B(!0),children:[(0,j.jsx)(f,{className:`size-3`}),e(`common:action.add`)]})]}),(0,j.jsxs)(`div`,{className:`mt-3 grid grid-cols-4 gap-px overflow-hidden rounded-md border border-border/60 bg-border/60`,children:[(0,j.jsx)(L,{value:X.length,label:e(`activity:audienceMem.statMemories`)}),(0,j.jsx)(L,{value:oe.length,label:e(`activity:audienceMem.statRoles`)}),(0,j.jsx)(L,{value:se.length,label:e(`activity:audienceMem.statTasks`)}),(0,j.jsx)(L,{value:ce.length,label:e(`activity:audienceMem.statModes`)})]}),(0,j.jsxs)(`div`,{className:`mt-3 flex items-center gap-1.5`,children:[(0,j.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[(0,j.jsx)(s,{className:`pointer-events-none absolute left-2.5 top-1/2 size-3.5 -translate-y-1/2 text-muted-foreground`}),(0,j.jsx)(C,{value:N,onChange:e=>I(e.target.value),placeholder:e(`activity:audienceMem.searchTextRoleTaskOrMode`),"aria-label":e(`activity:audienceMem.searchAudienceMemories`),className:`h-8 pl-8 pr-8 text-xs`}),N&&(0,j.jsx)(`button`,{type:`button`,className:`absolute right-2 top-1/2 -translate-y-1/2 rounded-sm p-0.5 text-muted-foreground hover:text-foreground`,onClick:()=>I(``),"aria-label":e(`activity:audienceMem.clearAudienceMemorySearch`),children:(0,j.jsx)(a,{className:`size-3`})})]}),(0,j.jsx)(S,{variant:`ghost`,size:`icon`,className:`size-8 shrink-0`,onClick:Y,"aria-label":e(`activity:audienceMem.refreshAudienceMemories`),title:e(`activity:audienceMem.refresh`),children:(0,j.jsx)(p,{className:h(`size-3.5`,D&&`animate-spin`)})}),(0,j.jsx)(S,{variant:`ghost`,size:`icon`,className:`size-8 shrink-0`,onClick:()=>V(!0),"aria-label":e(`activity:audienceMem.importAudienceMemories`),title:e(`activity:audienceMem.importJson`),children:(0,j.jsx)(d,{className:`size-3.5`})}),(0,j.jsx)(S,{variant:`ghost`,size:`icon`,className:`size-8 shrink-0`,onClick:()=>void de(),"aria-label":e(`activity:audienceMem.copyAudienceMemoriesAsJson`),title:e(`activity:audienceMem.copyJson`),disabled:X.length===0,children:(0,j.jsx)(u,{className:`size-3.5`})})]})]}),k&&(0,j.jsxs)(`div`,{role:k.tone===`error`?`alert`:`status`,className:h(`mx-3 mt-3 flex shrink-0 items-start justify-between gap-2 rounded-md border px-2.5 py-2 text-[11px]`,k.tone===`error`?`border-destructive/30 bg-destructive/5 text-destructive`:`border-success/30 bg-success/5 text-success`),children:[(0,j.jsx)(`span`,{children:k.text}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>M(null),className:`shrink-0 rounded-sm opacity-70 hover:opacity-100`,"aria-label":e(`activity:audienceMem.dismissMessage`),children:(0,j.jsx)(a,{className:`size-3`})})]}),(0,j.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[!D&&X.length>0&&(0,j.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between px-3 pb-1.5 pt-3 text-[10px] text-muted-foreground`,children:[(0,j.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,j.jsx)(r,{className:`size-3`}),Z?`${Q.length} of ${X.length}`:`${X.length} scoped`]}),Z&&(0,j.jsx)(`button`,{type:`button`,className:`hover:text-foreground`,onClick:()=>I(``),children:e(`activity:audienceMem.clearFilter`)})]}),(0,j.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-3`,children:[D?(0,j.jsx)(te,{}):X.length===0?(0,j.jsx)(ne,{onAdd:()=>B(!0)}):Q.length===0?(0,j.jsxs)(`div`,{className:`flex h-full min-h-32 flex-col items-center justify-center px-4 text-center`,children:[(0,j.jsx)(s,{className:`mb-2 size-5 text-muted-foreground/60`}),(0,j.jsx)(`p`,{className:`text-xs font-medium`,children:e(`activity:audienceMem.noMatching`)}),(0,j.jsx)(`p`,{className:`mt-1 text-[10px] text-muted-foreground`,children:e(`activity:audienceMem.noMatchingHint`)}),(0,j.jsx)(S,{variant:`ghost`,size:`sm`,className:`mt-2 h-7 text-xs`,onClick:()=>I(``),children:e(`activity:audienceMemoryPanel.clearSearch`)})]}):(0,j.jsx)(`ul`,{className:`space-y-2`,children:$.pageItems.map(e=>(0,j.jsx)(R,{memory:e,onFilter:I,onClearScope:()=>le(e.id),onDelete:()=>U(e.id)},e.id))}),(0,j.jsx)(w,{page:$.page,pageSize:$.pageSize,totalItems:$.totalItems,onPageChange:$.setPage,compact:!0,itemLabel:`memories`})]})]})]}),(0,j.jsx)(re,{open:z,busy:W,onOpenChange:e=>{W||B(e)},onCreate:e=>{M(null),G(!0),t.rememberSage({text:e.text,kind:e.kind,audience:{roles:e.roles.length>0?e.roles:void 0,taskTypes:e.taskTypes.length>0?e.taskTypes:void 0,modes:e.modes.length>0?e.modes:void 0}},{echoToChat:!1})}}),(0,j.jsx)(ie,{open:ae,onOpenChange:V,onImport:n=>{try{let{entries:r,skipped:i}=ee(n);if(r.length===0)return M({tone:`error`,text:e(`activity:audienceMem.noValidInJson`)}),!1;for(let e of r)t.rememberSage(e,{echoToChat:!1});return M({tone:`success`,text:e(`activity:audienceMem.queuedForImport`,{count:r.length})+(i?e(`activity:audienceMem.skippedSuffix`,{count:i}):`.`)}),V(!1),!0}catch(t){return M({tone:`error`,text:t instanceof Error?t.message:e(`activity:customRoster.invalidJson`)}),!1}}}),(0,j.jsx)(x,{open:!!H,onOpenChange:e=>{!e&&!K&&U(null)},children:(0,j.jsxs)(v,{className:`max-w-md`,children:[(0,j.jsxs)(g,{children:[(0,j.jsx)(y,{children:e(`activity:audienceMem.deleteTitle`)}),(0,j.jsx)(b,{children:e(`activity:audienceMem.deleteBody`)})]}),(0,j.jsx)(`div`,{className:`rounded-md border border-border/70 bg-background/45 p-3 text-xs text-muted-foreground`,children:E(n.find(e=>e.id===H)?.text??``,180)}),(0,j.jsxs)(_,{children:[(0,j.jsx)(S,{variant:`outline`,onClick:()=>U(null),disabled:K,children:`Cancel`}),(0,j.jsxs)(S,{variant:`destructive`,onClick:ue,disabled:K,children:[(0,j.jsx)(l,{className:`size-4`}),K?`Deleting…`:`Delete memory`]})]})]})})]})}function L({value:e,label:t}){return(0,j.jsxs)(`div`,{className:`bg-card/95 px-1.5 py-2 text-center`,children:[(0,j.jsx)(`p`,{className:`text-sm font-semibold tabular-nums`,children:e}),(0,j.jsx)(`p`,{className:`truncate text-[9px] uppercase tracking-wide text-muted-foreground`,children:t})]})}function R({memory:e,onFilter:t,onClearScope:n,onDelete:r}){let{t:a}=i();return(0,j.jsxs)(`li`,{className:`group rounded-md border border-border/65 bg-card/55 p-2.5 transition-colors hover:border-border hover:bg-card/85`,children:[(0,j.jsx)(`p`,{className:`break-words text-xs leading-5`,children:e.text}),e.audience&&(0,j.jsx)(z,{audience:e.audience,onFilter:t}),(0,j.jsxs)(`div`,{className:`mt-2 flex items-center justify-between gap-2 border-t border-border/45 pt-2`,children:[(0,j.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5 text-[9px] uppercase tracking-wide text-muted-foreground`,children:[(0,j.jsx)(`span`,{className:`truncate`,children:O[e.kind]??e.kind}),(0,j.jsx)(`span`,{"aria-hidden":`true`,children:`·`}),(0,j.jsx)(`span`,{children:e.status})]}),(0,j.jsxs)(`div`,{className:`flex shrink-0 items-center gap-0.5`,children:[(0,j.jsx)(S,{variant:`ghost`,size:`icon`,className:`size-6`,onClick:n,"aria-label":`Remove audience scope from ${E(e.text,42)}`,title:a(`activity:audienceMem.makeGeneralMemory`),children:(0,j.jsx)(o,{className:`size-3`})}),(0,j.jsx)(S,{variant:`ghost`,size:`icon`,className:`size-6 text-destructive hover:text-destructive`,onClick:r,"aria-label":`Delete ${E(e.text,42)}`,title:a(`activity:audienceMem.delete`),children:(0,j.jsx)(l,{className:`size-3`})})]})]})]})}function z({audience:e,onFilter:t}){let n=[...(e.roles??[]).map(e=>({label:`role`,value:e})),...(e.taskTypes??[]).map(e=>({label:`task`,value:e})),...(e.modes??[]).map(e=>({label:`mode`,value:e}))];return(0,j.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-1`,children:n.map(({label:e,value:n})=>(0,j.jsxs)(`button`,{type:`button`,className:`max-w-full truncate rounded border border-primary/15 bg-primary/7 px-1.5 py-0.5 font-mono text-[9px] text-primary/90 transition-colors hover:border-primary/35 hover:bg-primary/12`,onClick:()=>t(n),title:`Filter by ${e}: ${n}`,children:[e,`:`,n]},`${e}:${n}`))})}function te(){let{t:e}=i();return(0,j.jsx)(`div`,{className:`space-y-2 pt-3`,role:`status`,"aria-label":e(`activity:audienceMem.loadingAudienceMemories`),children:[0,1,2].map(e=>(0,j.jsxs)(`div`,{className:`animate-pulse rounded-md border border-border/50 p-3`,children:[(0,j.jsx)(`div`,{className:`h-2.5 w-full rounded bg-muted`}),(0,j.jsx)(`div`,{className:`mt-2 h-2.5 w-2/3 rounded bg-muted`}),(0,j.jsx)(`div`,{className:`mt-3 h-4 w-24 rounded bg-muted`})]},e))})}function ne({onAdd:e}){let{t}=i();return(0,j.jsxs)(`div`,{className:`flex h-full min-h-44 flex-col items-center justify-center px-5 text-center`,children:[(0,j.jsx)(`span`,{className:`mb-3 flex size-10 items-center justify-center rounded-full border border-dashed border-primary/35 bg-primary/5 text-primary`,children:(0,j.jsx)(c,{className:`size-4`})}),(0,j.jsx)(`p`,{className:`text-xs font-medium`,children:t(`activity:audienceMem.emptyTitle`)}),(0,j.jsx)(`p`,{className:`mt-1 max-w-52 text-[10px] leading-4 text-muted-foreground`,children:t(`activity:audienceMem.emptyBody`)}),(0,j.jsxs)(S,{variant:`outline`,size:`sm`,className:`mt-3 h-7 gap-1 text-xs`,onClick:e,children:[(0,j.jsx)(f,{className:`size-3`}),t(`activity:audienceMem.addScoped`)]})]})}function re({open:e,busy:t,onOpenChange:n,onCreate:r}){let{t:a}=i(),[o,s]=(0,A.useState)(``),[c,l]=(0,A.useState)(`workflow`),[u,d]=(0,A.useState)(``),[f,p]=(0,A.useState)(``),[m,h]=(0,A.useState)(``);(0,A.useEffect)(()=>{e||(s(``),l(`workflow`),d(``),p(``),h(``))},[e]);let C=k(u),w=k(f),T=k(m),E=o.trim().length>0&&(C.length>0||w.length>0||T.length>0);return(0,j.jsx)(x,{open:e,onOpenChange:n,children:(0,j.jsxs)(v,{className:`max-w-xl`,children:[(0,j.jsxs)(g,{children:[(0,j.jsx)(y,{children:a(`activity:audienceMem.createTitle`)}),(0,j.jsx)(b,{children:a(`activity:audienceMem.createBody`)})]}),(0,j.jsxs)(`div`,{className:`space-y-4`,children:[(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{htmlFor:`audience-memory-text`,className:`mb-1.5 block text-xs font-medium`,children:a(`activity:audienceMem.fieldMemory`)}),(0,j.jsx)(`textarea`,{id:`audience-memory-text`,value:o,onChange:e=>s(e.target.value),placeholder:a(`activity:audienceMem.whatShouldMatchingAgentsRemember`),rows:4,autoFocus:!0,className:`w-full resize-y rounded-md border border-input bg-background px-3 py-2 text-sm outline-none placeholder:text-muted-foreground focus-visible:ring-2 focus-visible:ring-ring`})]}),(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{htmlFor:`audience-memory-kind`,className:`mb-1.5 block text-xs font-medium`,children:a(`activity:audienceMem.fieldKind`)}),(0,j.jsx)(`select`,{id:`audience-memory-kind`,value:c,onChange:e=>l(e.target.value),className:`h-9 w-full rounded-md border border-input bg-background px-3 text-xs outline-none focus-visible:ring-2 focus-visible:ring-ring`,children:D.map(e=>(0,j.jsx)(`option`,{value:e,children:O[e]??e},e))})]}),(0,j.jsxs)(`fieldset`,{className:`space-y-3 rounded-md border border-border/70 bg-background/35 p-3`,children:[(0,j.jsx)(`legend`,{className:`px-1 text-xs font-medium`,children:a(`activity:audienceMem.selectors`)}),(0,j.jsx)(B,{id:`audience-memory-roles`,label:a(`activity:audienceMem.statRoles`),value:u,onChange:d,placeholder:a(`activity:audienceMem.reviewerRefactorPlanner`)}),(0,j.jsx)(B,{id:`audience-memory-task-types`,label:a(`activity:audienceMem.fieldTaskTypes`),value:f,onChange:p,placeholder:a(`activity:audienceMem.reviewRefactorBugfix`)}),(0,j.jsx)(B,{id:`audience-memory-modes`,label:a(`activity:audienceMem.statModes`),value:m,onChange:h,placeholder:a(`activity:audienceMem.teachCodeReview`)}),(0,j.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:a(`activity:audienceMem.selectorsHint`)})]})]}),(0,j.jsxs)(_,{children:[(0,j.jsx)(S,{variant:`outline`,onClick:()=>n(!1),disabled:t,children:a(`common:action.cancel`)}),(0,j.jsx)(S,{onClick:()=>r({text:o.trim(),kind:c,roles:C,taskTypes:w,modes:T}),disabled:!E||t,children:t?`Remembering…`:`Remember`})]})]})})}function B({id:e,label:t,value:n,placeholder:r,onChange:i}){return(0,j.jsxs)(`div`,{className:`grid gap-1.5 sm:grid-cols-[6rem_1fr] sm:items-center`,children:[(0,j.jsx)(`label`,{htmlFor:e,className:`text-[11px] font-medium text-muted-foreground`,children:t}),(0,j.jsx)(C,{id:e,value:n,onChange:e=>i(e.target.value),placeholder:r,className:`h-8 font-mono text-xs`})]})}function ie({open:e,onOpenChange:t,onImport:n}){let{t:r}=i(),[a,o]=(0,A.useState)(``);return(0,A.useEffect)(()=>{e||o(``)},[e]),(0,j.jsx)(x,{open:e,onOpenChange:t,children:(0,j.jsxs)(v,{className:`max-w-xl`,children:[(0,j.jsxs)(g,{children:[(0,j.jsx)(y,{children:r(`activity:audienceMem.importTitle`)}),(0,j.jsxs)(b,{children:[r(`activity:audienceMem.importBodyBefore`),` `,(0,j.jsx)(`code`,{children:r(`activity:audienceMemoryPanel.memoryAudienceExport`)}),`.`,` `,r(`activity:audienceMem.importBodyAfter`)]})]}),(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{htmlFor:`audience-memory-import`,className:`mb-1.5 block text-xs font-medium`,children:r(`activity:audienceMem.jsonArray`)}),(0,j.jsx)(`textarea`,{id:`audience-memory-import`,value:a,onChange:e=>o(e.target.value),placeholder:`[
2
+ { "text": "…", "audience": { "roles": ["reviewer"] } }
3
+ ]`,rows:10,autoFocus:!0,spellCheck:!1,className:`w-full resize-y rounded-md border border-input bg-background p-3 font-mono text-xs outline-none placeholder:text-muted-foreground focus-visible:ring-2 focus-visible:ring-ring`})]}),(0,j.jsxs)(_,{children:[(0,j.jsx)(S,{variant:`outline`,onClick:()=>t(!1),children:r(`common:action.cancel`)}),(0,j.jsxs)(S,{onClick:()=>n(a),disabled:!a.trim(),children:[(0,j.jsx)(d,{className:`size-4`}),r(`activity:audienceMem.importAction`)]})]})]})})}export{I as AudienceMemoryPanel};
@@ -0,0 +1 @@
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Q as t,et as n,t as r}from"./ws-client-C_IqS0t4.js";import{i,t as a}from"./react-core-BNmTiJ-I.js";import{Fa as o,Kn as s,Kr as c,Kt as l,kn as u,qi as d,qt as f,sn as p,st as m,tn as h,vi as g}from"./vendor-BshlG0z-.js";import"./i18n-DBqM1FUM.js";import{t as _}from"./useWebSocket-AYEcpb1U.js";import{t as v}from"./utils-BpBOwXlT.js";import"./stores-Cfei1ViB.js";import{O as y}from"./index-TDhvFXb0.js";import{i as b,r as x,s as S,t as C}from"./monaco-_kWjHrlo.js";import{t as w}from"./empty-state-BxilAuC3.js";import{t as T}from"./monaco-theme-Dmx6JuoU.js";var E=e(i(),1),D=a();b.config({monaco:C});var O={ts:`typescript`,tsx:`typescript`,js:`javascript`,jsx:`javascript`,mjs:`javascript`,json:`json`,css:`css`,scss:`scss`,html:`html`,md:`markdown`,py:`python`,go:`go`,rs:`rust`,java:`java`,c:`c`,cpp:`cpp`,cs:`csharp`,rb:`ruby`,php:`php`,sh:`shell`,bash:`shell`,yml:`yaml`,yaml:`yaml`,toml:`toml`,sql:`sql`};function k(e){return O[e.split(`.`).pop()?.toLowerCase()??``]??`plaintext`}function A({path:e,oldText:t,newText:i}){let{t:a}=o(),c=(0,E.useRef)(null),[u,f]=(0,E.useState)(!1),[p,m]=(0,E.useState)(!1),[h,g]=(0,E.useState)(null);(0,E.useEffect)(()=>{f(!1),m(!1),g(null)},[]);let _=(0,E.useCallback)(e=>{c.current=e,S.setTheme(T()),e.getModifiedEditor().onDidChangeModelContent(()=>f(!0))},[]),v=(0,E.useCallback)(()=>{let t=c.current?.getModifiedEditor().getValue();if(t==null)return;m(!0);let i=r(n.getState().wsUrl),a=i.on(`files.written`,t=>{t.type===`files.written`&&t.payload.filePath===e&&(a(),clearTimeout(o),m(!1),t.payload.success&&(f(!1),g(Date.now())))}),o=setTimeout(()=>{a(),m(!1)},5e3);i.send({type:`files.write`,payload:i.withSession({filePath:e,content:t})})},[e]),y=k(e);return(0,D.jsxs)(`div`,{className:`flex h-full min-h-0 min-w-0 flex-1 flex-col overflow-hidden`,children:[(0,D.jsxs)(`div`,{className:`flex min-w-0 items-center justify-between gap-2 px-2 py-1.5 border-b border-border/40`,children:[(0,D.jsx)(`span`,{className:`text-xs font-mono text-muted-foreground truncate`,children:e}),(0,D.jsxs)(`button`,{type:`button`,onClick:v,disabled:!u||p,className:`inline-flex items-center gap-1.5 h-7 px-2.5 rounded-md border border-border text-xs font-medium disabled:opacity-40 enabled:hover:bg-muted transition-colors`,title:a(`activity:monacoDiff.applyTitle`),children:[p?(0,D.jsx)(s,{className:`h-3.5 w-3.5 animate-spin`}):h&&!u?(0,D.jsx)(d,{className:`h-3.5 w-3.5 text-success`}):(0,D.jsx)(l,{className:`h-3.5 w-3.5`}),a(p?`activity:monacoDiff.applying`:h&&!u?`activity:monacoDiff.applied`:`activity:monacoDiff.apply`)]})]}),(0,D.jsx)(`div`,{className:`min-h-0 min-w-0 flex-1 overflow-hidden`,children:(0,D.jsx)(x,{original:t,modified:i,language:y,theme:T(),onMount:_,options:{renderSideBySide:!0,readOnly:!1,originalEditable:!1,minimap:{enabled:!1},fontSize:13,scrollBeyondLastLine:!1,automaticLayout:!0}})})]})}var j=1e4;function M({className:e}){let{t:i}=o(),{stageGit:a,unstageGit:l,discardGit:d}=_(),b=t(e=>e.selectedPath),x=t(e=>e.files),S=t(e=>e.diff),C=t(e=>e.loadingDiff),T=x.find(e=>e.path===b),[O,k]=(0,E.useState)(`unified`),[M,N]=(0,E.useState)(!1),P=!!b&&(C||!S);(0,E.useEffect)(()=>{if(N(!1),!P)return;let e=setTimeout(()=>N(!0),j);return()=>clearTimeout(e)},[P,b]);let F=()=>{b&&(N(!1),t.getState().setDiffLoading(!0),r(n.getState().wsUrl).getGitDiff?.(b))};if(!b)return(0,D.jsx)(w,{icon:(0,D.jsx)(c,{className:`h-6 w-6`}),title:i(`activity:changesView.sourceChanges`),description:i(`activity:changes.selectPrompt`),className:e});let I=S&&!S.error&&!S.binary&&!S.tooLarge;return(0,D.jsx)(`div`,{className:v(`flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden bg-[hsl(var(--surface-2)/0.45)] p-3`,e),children:(0,D.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden rounded-xl border border-border/70 bg-card/75 shadow-sm`,children:[(0,D.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-between gap-2 border-b border-border/70 px-3 py-2`,children:[(0,D.jsxs)(`div`,{className:`min-w-0 flex items-center gap-2`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`div`,{className:`text-[10px] font-semibold uppercase text-muted-foreground`,children:i(`activity:changesView.sourceControl`)}),(0,D.jsx)(`div`,{className:`truncate font-mono text-xs text-foreground`,title:b,children:b})]}),T?.staged&&(0,D.jsx)(`span`,{className:`rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-medium text-primary uppercase`,children:`Staged`})]}),(0,D.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,D.jsx)(`div`,{className:`flex items-center gap-1 border-r border-border/70 pr-2`,children:T?.staged?(0,D.jsxs)(`button`,{type:`button`,onClick:()=>l?.(b),title:`Unstage this file`,className:`inline-flex h-8 items-center gap-1 rounded-md border border-border px-2 text-xs text-muted-foreground hover:bg-muted hover:text-foreground transition-colors`,children:[(0,D.jsx)(u,{className:`h-3.5 w-3.5`}),` Unstage`]}):(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`button`,{type:`button`,onClick:()=>a?.(b),title:`Stage this file`,className:`inline-flex h-8 items-center gap-1 rounded-md border border-border px-2 text-xs text-muted-foreground hover:bg-muted hover:text-foreground transition-colors`,children:[(0,D.jsx)(p,{className:`h-3.5 w-3.5`}),` Stage`]}),(0,D.jsxs)(`button`,{type:`button`,onClick:()=>{window.confirm(`Discard changes in ${b}? This cannot be undone.`)&&d?.(b)},title:`Discard changes in this file`,className:`inline-flex h-8 items-center gap-1 rounded-md border border-border px-2 text-xs text-muted-foreground hover:bg-destructive/10 hover:text-destructive transition-colors`,children:[(0,D.jsx)(m,{className:`h-3.5 w-3.5`}),` Discard`]})]})}),I&&(0,D.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,D.jsxs)(`button`,{type:`button`,onClick:()=>k(`unified`),title:i(`activity:changes.unifiedTitle`),className:v(`inline-flex h-8 items-center gap-1 rounded-md border px-2 text-xs transition-colors`,O===`unified`?`border-primary/40 bg-primary/10 text-primary`:`border-border text-muted-foreground hover:bg-muted`),children:[(0,D.jsx)(f,{className:`h-3.5 w-3.5`}),` `,i(`activity:changes.unified`)]}),(0,D.jsxs)(`button`,{type:`button`,onClick:()=>k(`edit`),title:i(`activity:changes.editTitle`),className:v(`inline-flex h-8 items-center gap-1 rounded-md border px-2 text-xs transition-colors`,O===`edit`?`border-primary/40 bg-primary/10 text-primary`:`border-border text-muted-foreground hover:bg-muted`),children:[(0,D.jsx)(g,{className:`h-3.5 w-3.5`}),` `,i(`activity:changes.edit`)]})]})]})]}),(0,D.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden`,children:C||!S?M?(0,D.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col items-center justify-center gap-3 p-4 text-center`,children:[(0,D.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:i(`activity:changes.diffTimeout`)}),(0,D.jsxs)(`button`,{type:`button`,onClick:F,className:`inline-flex h-8 items-center gap-1.5 rounded-md border border-border px-3 text-xs text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,children:[(0,D.jsx)(h,{className:`h-3.5 w-3.5`}),` `,i(`common:action.retry`)]})]}):(0,D.jsxs)(`div`,{className:`flex min-h-0 flex-1 items-center justify-center gap-2 text-sm text-muted-foreground`,children:[(0,D.jsx)(s,{className:`h-4 w-4 animate-spin`}),` `,i(`activity:changes.loadingDiff`)]}):S.error?(0,D.jsx)(`div`,{className:`flex min-h-0 flex-1 items-center justify-center text-sm text-destructive`,children:S.error}):S.binary?(0,D.jsx)(`div`,{className:`flex min-h-0 flex-1 items-center justify-center text-sm text-muted-foreground`,children:i(`activity:changes.binary`)}):S.tooLarge?(0,D.jsx)(`div`,{className:`flex min-h-0 flex-1 items-center justify-center text-sm text-muted-foreground`,children:i(`activity:changes.tooLarge`)}):O===`edit`?(0,D.jsx)(A,{path:S.path,oldText:S.oldText??``,newText:S.newText??``},S.path):(0,D.jsx)(y,{oldText:S.oldText,newText:S.newText,caption:S.path,fill:!0})})]})})}export{M as ChangesView};