agent-relay-server 0.108.0 → 0.109.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 (163) hide show
  1. package/docs/openapi.json +115 -1
  2. package/package.json +2 -2
  3. package/public/assets/MessageBubble-XgN61quY.js +4 -0
  4. package/public/assets/{MessageBubble-DYJezSjU.js.map → MessageBubble-XgN61quY.js.map} +1 -1
  5. package/public/assets/PlanGraphPanel-LY-msOsr.js +2 -0
  6. package/public/assets/PlanGraphPanel-LY-msOsr.js.map +1 -0
  7. package/public/assets/activity-D0EotVU9.js +2 -0
  8. package/public/assets/activity-D0EotVU9.js.map +1 -0
  9. package/public/assets/{agent-profiles-Di2w5U1o.js → agent-profiles-CAGvryb9.js} +2 -2
  10. package/public/assets/{agent-profiles-Di2w5U1o.js.map → agent-profiles-CAGvryb9.js.map} +1 -1
  11. package/public/assets/agents-CXXZ_sU9.js +2 -0
  12. package/public/assets/{agents-GSJXvmU1.js.map → agents-CXXZ_sU9.js.map} +1 -1
  13. package/public/assets/{analytics-B9USQLl5.js → analytics-Q6Dl_CE9.js} +3 -3
  14. package/public/assets/{analytics-B9USQLl5.js.map → analytics-Q6Dl_CE9.js.map} +1 -1
  15. package/public/assets/{automation-XRePs1dT.js → automation-zig0cp23.js} +2 -2
  16. package/public/assets/{automation-XRePs1dT.js.map → automation-zig0cp23.js.map} +1 -1
  17. package/public/assets/{badge-D8fABzMs.js → badge-kdQDWO6e.js} +2 -2
  18. package/public/assets/{badge-D8fABzMs.js.map → badge-kdQDWO6e.js.map} +1 -1
  19. package/public/assets/{branch-state-badge-C_VNyER3.js → branch-state-badge-BRjUWyMT.js} +2 -2
  20. package/public/assets/{branch-state-badge-C_VNyER3.js.map → branch-state-badge-BRjUWyMT.js.map} +1 -1
  21. package/public/assets/{button-KASZcscA.js → button-BKFvNXa3.js} +2 -2
  22. package/public/assets/{button-KASZcscA.js.map → button-BKFvNXa3.js.map} +1 -1
  23. package/public/assets/card-B0y1i_2D.js +2 -0
  24. package/public/assets/{card-Cds0MWME.js.map → card-B0y1i_2D.js.map} +1 -1
  25. package/public/assets/{channels-DACvNoC2.js → channels-DOYB1iiA.js} +2 -2
  26. package/public/assets/{channels-DACvNoC2.js.map → channels-DOYB1iiA.js.map} +1 -1
  27. package/public/assets/chat-C3QlsFBd.js +2 -0
  28. package/public/assets/{chat-D_0uHgB6.js.map → chat-C3QlsFBd.js.map} +1 -1
  29. package/public/assets/{connectors-C0B38LUK.js → connectors-C5CeK-2M.js} +2 -2
  30. package/public/assets/{connectors-C0B38LUK.js.map → connectors-C5CeK-2M.js.map} +1 -1
  31. package/public/assets/{copy-button-d9DFNX9v.js → copy-button-aLaiAkv2.js} +2 -2
  32. package/public/assets/{copy-button-d9DFNX9v.js.map → copy-button-aLaiAkv2.js.map} +1 -1
  33. package/public/assets/{display-1J__Ti1K.js → display-_5kFrHJh.js} +3 -3
  34. package/public/assets/{display-1J__Ti1K.js.map → display-_5kFrHJh.js.map} +1 -1
  35. package/public/assets/{dist-DOAjFOS4.js → dist-BDYU37NZ.js} +2 -2
  36. package/public/assets/{dist-DOAjFOS4.js.map → dist-BDYU37NZ.js.map} +1 -1
  37. package/public/assets/dist-BnfqT2cl.js +2 -0
  38. package/public/assets/{dist-DC-TqTz2.js.map → dist-BnfqT2cl.js.map} +1 -1
  39. package/public/assets/dist-CF28Y5wI.js +2 -0
  40. package/public/assets/{dist-CBVZk9U8.js.map → dist-CF28Y5wI.js.map} +1 -1
  41. package/public/assets/{dist-DTXKbk2K.js → dist-DDh8a_SK.js} +2 -2
  42. package/public/assets/{dist-DTXKbk2K.js.map → dist-DDh8a_SK.js.map} +1 -1
  43. package/public/assets/{dist-BbUJ1Vht.js → dist-DKoRwEZq.js} +2 -2
  44. package/public/assets/{dist-BbUJ1Vht.js.map → dist-DKoRwEZq.js.map} +1 -1
  45. package/public/assets/{dist-UhEAFdvZ.js → dist-DQPz52Zx.js} +2 -2
  46. package/public/assets/{dist-UhEAFdvZ.js.map → dist-DQPz52Zx.js.map} +1 -1
  47. package/public/assets/{dist-CgqfdHSt.js → dist-D_qcpfbI.js} +2 -2
  48. package/public/assets/{dist-CgqfdHSt.js.map → dist-D_qcpfbI.js.map} +1 -1
  49. package/public/assets/{dist-DybScJmm.js → dist-DnyQI0qt.js} +2 -2
  50. package/public/assets/{dist-DybScJmm.js.map → dist-DnyQI0qt.js.map} +1 -1
  51. package/public/assets/{dist-BwwlmyBq.js → dist-EO8jbi2F.js} +2 -2
  52. package/public/assets/{dist-BwwlmyBq.js.map → dist-EO8jbi2F.js.map} +1 -1
  53. package/public/assets/{dist-BlZvUZZB.js → dist-avJPT3qF.js} +2 -2
  54. package/public/assets/{dist-BlZvUZZB.js.map → dist-avJPT3qF.js.map} +1 -1
  55. package/public/assets/dist-cyag2tir.js +2 -0
  56. package/public/assets/{dist-DreO5AcZ.js.map → dist-cyag2tir.js.map} +1 -1
  57. package/public/assets/{es2015-DUjFyjDp.js → es2015-C9FSEGd7.js} +2 -2
  58. package/public/assets/{es2015-DUjFyjDp.js.map → es2015-C9FSEGd7.js.map} +1 -1
  59. package/public/assets/{formatted-body-impl-BKWCAjBd.js → formatted-body-impl-DCQSVyWB.js} +2 -2
  60. package/public/assets/{formatted-body-impl-BKWCAjBd.js.map → formatted-body-impl-DCQSVyWB.js.map} +1 -1
  61. package/public/assets/index-D6hQkte1.css +2 -0
  62. package/public/assets/index-RCbIyk26.js +23 -0
  63. package/public/assets/index-RCbIyk26.js.map +1 -0
  64. package/public/assets/{input-CtHfLn1i.js → input-DfN6sUbX.js} +2 -2
  65. package/public/assets/{input-CtHfLn1i.js.map → input-DfN6sUbX.js.map} +1 -1
  66. package/public/assets/{insights-BzNoYvDe.js → insights-CsLs6NbL.js} +2 -2
  67. package/public/assets/{insights-BzNoYvDe.js.map → insights-CsLs6NbL.js.map} +1 -1
  68. package/public/assets/{integrations-DLzJpt9G.js → integrations-CztQfrI7.js} +2 -2
  69. package/public/assets/{integrations-DLzJpt9G.js.map → integrations-CztQfrI7.js.map} +1 -1
  70. package/public/assets/{lib-l-JkMVR9.js → lib-DRRHEqRZ.js} +2 -2
  71. package/public/assets/{lib-l-JkMVR9.js.map → lib-DRRHEqRZ.js.map} +1 -1
  72. package/public/assets/{lucide-react-C4eXYCwx.js → lucide-react-DmbfpRvJ.js} +2 -2
  73. package/public/assets/{lucide-react-C4eXYCwx.js.map → lucide-react-DmbfpRvJ.js.map} +1 -1
  74. package/public/assets/{maintenance-B6_0-ECm.js → maintenance-BN5F0Lnc.js} +2 -2
  75. package/public/assets/{maintenance-B6_0-ECm.js.map → maintenance-BN5F0Lnc.js.map} +1 -1
  76. package/public/assets/managed-agents-R_LI9qS5.js +4 -0
  77. package/public/assets/{managed-agents-CpzKXDtV.js.map → managed-agents-R_LI9qS5.js.map} +1 -1
  78. package/public/assets/markdown-preview-impl-DQlmK_ev.js +2 -0
  79. package/public/assets/{markdown-preview-impl-DxBnlJ2k.js.map → markdown-preview-impl-DQlmK_ev.js.map} +1 -1
  80. package/public/assets/memory-kn4bgMXC.js +2 -0
  81. package/public/assets/{memory-Bnm7ILWL.js.map → memory-kn4bgMXC.js.map} +1 -1
  82. package/public/assets/{messages-D9LkocTc.js → messages-Dv3Tv7zC.js} +2 -2
  83. package/public/assets/{messages-D9LkocTc.js.map → messages-Dv3Tv7zC.js.map} +1 -1
  84. package/public/assets/{orchestrators-C__JfrNr.js → orchestrators-DcNLRMzk.js} +2 -2
  85. package/public/assets/{orchestrators-C__JfrNr.js.map → orchestrators-DcNLRMzk.js.map} +1 -1
  86. package/public/assets/overview-BOLzPSSC.js +2 -0
  87. package/public/assets/{overview-BQ0b0V7Q.js.map → overview-BOLzPSSC.js.map} +1 -1
  88. package/public/assets/{pairs-ChyeBs0Z.js → pairs-B4r0egpx.js} +2 -2
  89. package/public/assets/{pairs-ChyeBs0Z.js.map → pairs-B4r0egpx.js.map} +1 -1
  90. package/public/assets/projects-cOeuiMjl.js +2 -0
  91. package/public/assets/{projects-v5Kp1Oaq.js.map → projects-cOeuiMjl.js.map} +1 -1
  92. package/public/assets/prompt-settings-E7-6Osj4.js +2 -0
  93. package/public/assets/{prompt-settings-YhAOlYc6.js.map → prompt-settings-E7-6Osj4.js.map} +1 -1
  94. package/public/assets/{react-dom-BMF4hNzG.js → react-dom-jQ4Vs380.js} +2 -2
  95. package/public/assets/{react-dom-BMF4hNzG.js.map → react-dom-jQ4Vs380.js.map} +1 -1
  96. package/public/assets/registry-CTN3jOnb.js +2 -0
  97. package/public/assets/{registry-DZoAfrzx.js.map → registry-CTN3jOnb.js.map} +1 -1
  98. package/public/assets/{security-DRCj00eA.js → security-BctIcBZb.js} +2 -2
  99. package/public/assets/{security-DRCj00eA.js.map → security-BctIcBZb.js.map} +1 -1
  100. package/public/assets/{select-ZOpLw2Fd.js → select-BndvVb0A.js} +2 -2
  101. package/public/assets/{select-ZOpLw2Fd.js.map → select-BndvVb0A.js.map} +1 -1
  102. package/public/assets/settings-B_tRq-P4.js +6 -0
  103. package/public/assets/{settings-DGgwr9WH.js.map → settings-B_tRq-P4.js.map} +1 -1
  104. package/public/assets/store-DDWg67Pg.js +9 -0
  105. package/public/assets/store-DDWg67Pg.js.map +1 -0
  106. package/public/assets/tasks-BgTTxVET.js +2 -0
  107. package/public/assets/tasks-BgTTxVET.js.map +1 -0
  108. package/public/assets/teams-DJiLBEgF.js +2 -0
  109. package/public/assets/{teams-BJpaoG2m.js.map → teams-DJiLBEgF.js.map} +1 -1
  110. package/public/assets/{terminal-viewer-impl-CQhh6oXa.js → terminal-viewer-impl-BLdiyCNR.js} +3 -3
  111. package/public/assets/{terminal-viewer-impl-CQhh6oXa.js.map → terminal-viewer-impl-BLdiyCNR.js.map} +1 -1
  112. package/public/assets/{types-BiJFuTiL.js → types-DSwhOFcJ.js} +2 -2
  113. package/public/assets/types-DSwhOFcJ.js.map +1 -0
  114. package/public/assets/{use-keyboard-viewport-RYMALvu1.js → use-keyboard-viewport-Dw2CHZ50.js} +2 -2
  115. package/public/assets/{use-keyboard-viewport-RYMALvu1.js.map → use-keyboard-viewport-Dw2CHZ50.js.map} +1 -1
  116. package/public/assets/user-avatar-rt59cEsc.js +2 -0
  117. package/public/assets/{user-avatar-BYGrUx1U.js.map → user-avatar-rt59cEsc.js.map} +1 -1
  118. package/public/assets/{work-queue-BH2-mARc.js → work-queue-BYRdBuLR.js} +2 -2
  119. package/public/assets/{work-queue-BH2-mARc.js.map → work-queue-BYRdBuLR.js.map} +1 -1
  120. package/public/assets/workspaces-DCRT3l9H.js +3 -0
  121. package/public/assets/workspaces-DCRT3l9H.js.map +1 -0
  122. package/public/index.html +23 -23
  123. package/runner/plugins/claude/.claude-plugin/plugin.json +1 -1
  124. package/src/db/migrations.ts +21 -1
  125. package/src/db/schema.ts +7 -1
  126. package/src/mcp-dispatch-tools.ts +45 -16
  127. package/src/mcp-task-memory-tools.ts +4 -21
  128. package/src/routes/index.ts +4 -1
  129. package/src/routes/messages.ts +6 -6
  130. package/src/routes/tasks.ts +60 -1
  131. package/src/security.ts +4 -0
  132. package/src/task-authz.ts +52 -0
  133. package/public/assets/MessageBubble-DYJezSjU.js +0 -4
  134. package/public/assets/PlanGraphPanel-MWcVw38W.js +0 -2
  135. package/public/assets/PlanGraphPanel-MWcVw38W.js.map +0 -1
  136. package/public/assets/activity-Db3X3dg8.js +0 -2
  137. package/public/assets/activity-Db3X3dg8.js.map +0 -1
  138. package/public/assets/agents-GSJXvmU1.js +0 -2
  139. package/public/assets/card-Cds0MWME.js +0 -2
  140. package/public/assets/chat-D_0uHgB6.js +0 -2
  141. package/public/assets/dist-CBVZk9U8.js +0 -2
  142. package/public/assets/dist-DC-TqTz2.js +0 -2
  143. package/public/assets/dist-DreO5AcZ.js +0 -2
  144. package/public/assets/index-BjjzI2LT.css +0 -2
  145. package/public/assets/index-DlBSuzd2.js +0 -23
  146. package/public/assets/index-DlBSuzd2.js.map +0 -1
  147. package/public/assets/managed-agents-CpzKXDtV.js +0 -4
  148. package/public/assets/markdown-preview-impl-DxBnlJ2k.js +0 -2
  149. package/public/assets/memory-Bnm7ILWL.js +0 -2
  150. package/public/assets/overview-BQ0b0V7Q.js +0 -2
  151. package/public/assets/projects-v5Kp1Oaq.js +0 -2
  152. package/public/assets/prompt-settings-YhAOlYc6.js +0 -2
  153. package/public/assets/registry-DZoAfrzx.js +0 -2
  154. package/public/assets/settings-DGgwr9WH.js +0 -6
  155. package/public/assets/store-Bnag1kY-.js +0 -9
  156. package/public/assets/store-Bnag1kY-.js.map +0 -1
  157. package/public/assets/tasks-DUTu8ZhA.js +0 -2
  158. package/public/assets/tasks-DUTu8ZhA.js.map +0 -1
  159. package/public/assets/teams-BJpaoG2m.js +0 -2
  160. package/public/assets/types-BiJFuTiL.js.map +0 -1
  161. package/public/assets/user-avatar-BYGrUx1U.js +0 -2
  162. package/public/assets/workspaces-DldYyXZR.js +0 -3
  163. package/public/assets/workspaces-DldYyXZR.js.map +0 -1
@@ -1,4 +0,0 @@
1
- import{r as e}from"./chunk-CilyBKbf.js";import{B as t,E as n,H as r,Jn as i,M as a,Qn as o,Vt as s,W as c,Yn as l,Zn as u,g as d,h as f,m as p,ur as m,v as h,y as g}from"./lucide-react-C4eXYCwx.js";import{f as _,t as v}from"./store-Bnag1kY-.js";import{o as y}from"./types-BiJFuTiL.js";import{K as b,h as x,q as S}from"./display-1J__Ti1K.js";import{t as C}from"./badge-D8fABzMs.js";import{t as w}from"./button-KASZcscA.js";import{t as T}from"./copy-button-d9DFNX9v.js";import{_ as E,v as D,y as O}from"./index-DlBSuzd2.js";var k=e(m(),1),A=u(),j={running:`bg-emerald-500/15 text-emerald-400 border-emerald-500/30`,starting:`bg-blue-500/15 text-blue-400 border-blue-500/30`,stopping:`bg-yellow-500/15 text-yellow-400 border-yellow-500/30`,backoff:`bg-red-500/15 text-red-400 border-red-500/30`,failed:`bg-red-500/15 text-red-400 border-red-500/30`,stopped:`bg-muted text-muted-foreground border-border`};function M({status:e}){return(0,A.jsx)(`span`,{className:l(`inline-flex items-center rounded border px-2 py-0.5 text-xs font-medium`,j[e]),children:e})}var N={running:`bg-emerald-500/20 text-emerald-400`,starting:`bg-blue-500/20 text-blue-400`,stopping:`bg-yellow-500/20 text-yellow-400`,stopped:`bg-zinc-500/20 text-zinc-400`,backoff:`bg-red-500/20 text-red-400`,failed:`bg-red-500/20 text-red-400`};function P({item:e,agent:t,orchestrators:r,now:a,onClose:c,initialDiagnostics:l}){let[u,d]=(0,k.useState)(l??null),[f,m]=(0,k.useState)(!1),[g,_]=(0,k.useState)(null);(0,k.useEffect)(()=>{if(l){d(l);return}let t=!1;return m(!0),_(null),o(`GET`,`/spawn-policy/`+encodeURIComponent(e.policy.name)+`/diagnostics?limit=80`).then(e=>{t||d(e)}).catch(e=>{t||(d(null),_(e.message))}).finally(()=>{t||m(!1)}),()=>{t=!0}},[e.policy.name,e.state.updatedAt,l]);let v=r.find(t=>t.id===e.policy.orchestratorId),y=(0,k.useMemo)(()=>F(e,v),[e,v]),S=u?.timeline??[],O=L(S,t),j=u?.crashReport??null,P=I(e,y),R=t?E(a,t):null;return(0,A.jsxs)(`section`,{className:`rounded-md border border-border bg-card p-3 space-y-3`,children:[(0,A.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-2`,children:[(0,A.jsxs)(`div`,{className:`min-w-0`,children:[(0,A.jsxs)(`h2`,{className:`flex items-center gap-1.5 text-sm font-semibold`,children:[(0,A.jsx)(h,{className:`h-4 w-4 text-muted-foreground`}),e.policy.label||e.policy.name,` Diagnostics`]}),(0,A.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Spawn config, live attachments, recent lifecycle, and logs.`})]}),(0,A.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,A.jsx)(T,{value:()=>z(e,t,v,y,S,j,O),label:`Copy Bundle`,showText:!0,size:`sm`,variant:`outline`,className:`h-8 text-xs`}),(0,A.jsx)(w,{variant:`outline`,size:`sm`,onClick:c,children:`Close`})]})]}),g&&(0,A.jsx)(`div`,{className:`rounded border border-red-500/20 bg-red-500/5 px-2 py-1.5 text-xs text-red-300`,children:g}),f&&!u&&(0,A.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`Loading diagnostics...`}),(0,A.jsxs)(`div`,{className:`grid gap-3 lg:grid-cols-2`,children:[(0,A.jsx)(B,{title:`Spawn Command`,icon:(0,A.jsx)(s,{className:`h-3.5 w-3.5`}),children:(0,A.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-3 gap-y-1 text-xs`,children:[(0,A.jsx)(V,{label:`Provider`,value:e.policy.provider}),e.policy.model&&(0,A.jsx)(V,{label:`Model`,value:e.policy.model}),e.policy.effort&&(0,A.jsx)(V,{label:`Effort`,value:e.policy.effort}),(0,A.jsx)(V,{label:`Approval`,value:e.policy.permissionMode}),(0,A.jsx)(V,{label:`Mode`,value:e.policy.mode}),e.policy.profile&&(0,A.jsx)(V,{label:`Profile`,value:e.policy.profile}),e.policy.rig&&(0,A.jsx)(V,{label:`Rig`,value:e.policy.rig}),(0,A.jsx)(V,{label:`CWD`,value:e.policy.cwd,className:`col-span-2`,mono:!0}),e.policy.providerArgs.length>0&&(0,A.jsx)(V,{label:`Provider Args`,value:e.policy.providerArgs.join(` `),className:`col-span-2`,mono:!0}),e.policy.tags.length>0&&(0,A.jsx)(H,{label:`Tags`,values:e.policy.tags}),e.policy.capabilities.length>0&&(0,A.jsx)(H,{label:`Caps`,values:e.policy.capabilities})]})}),(0,A.jsx)(B,{title:`Runtime`,icon:(0,A.jsx)(n,{className:`h-3.5 w-3.5`}),children:(0,A.jsxs)(`div`,{className:`space-y-2 text-xs`,children:[(0,A.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,A.jsx)(`span`,{className:`text-muted-foreground`,children:`Lifecycle`}),(0,A.jsx)(M,{status:e.state.status}),(0,A.jsx)(C,{className:N[e.state.status]||`bg-zinc-500/20 text-zinc-400`,children:e.state.status})]}),(0,A.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-3 gap-y-1`,children:[(0,A.jsx)(V,{label:`Orchestrator`,value:v?`${v.hostname} (${v.id})`:e.policy.orchestratorId}),v?.version&&(0,A.jsx)(V,{label:`Orch Version`,value:v.version}),y?.pid&&(0,A.jsx)(V,{label:`PID`,value:String(y.pid),mono:!0}),y?.supervisor&&(0,A.jsx)(V,{label:`Supervisor`,value:y.supervisor}),y?.systemdUnit&&(0,A.jsx)(V,{label:`Systemd`,value:y.systemdUnit,mono:!0,className:`col-span-2`}),y?.sessionName&&(0,A.jsx)(V,{label:`Session`,value:y.sessionName,mono:!0}),y?.terminalSession&&(0,A.jsx)(V,{label:`Terminal`,value:y.terminalAvailable?`${y.terminalSession} (available)`:`${y.terminalSession} (not attachable)`,mono:!0}),y?.spawnRequestId&&(0,A.jsx)(V,{label:`Spawn ID`,value:y.spawnRequestId,mono:!0,className:`col-span-2`}),y?.startedAt&&(0,A.jsx)(V,{label:`Started`,value:x(y.startedAt)}),e.state.restartCount!==void 0&&(0,A.jsx)(V,{label:`Restarts`,value:String(e.state.restartCount)}),e.state.consecutiveFailures!==void 0&&(0,A.jsx)(V,{label:`Failures`,value:String(e.state.consecutiveFailures)}),e.state.backoffUntil&&(0,A.jsx)(V,{label:`Backoff`,value:e.state.backoffUntil>a?b(a,e.state.backoffUntil):`expired`})]}),R&&(0,A.jsxs)(`div`,{className:`rounded border border-yellow-500/20 bg-yellow-500/5 px-2 py-1.5 text-yellow-100/80`,children:[`Stuck busy: `,R.kind,` stale for `,b(a,a-R.staleForMs)]}),e.state.lastError&&(0,A.jsx)(U,{title:`Last Error`,body:e.state.lastError})]})})]}),(O||j)&&(0,A.jsx)(B,{title:`Post-Mortem`,icon:(0,A.jsx)(p,{className:`h-3.5 w-3.5`}),children:(0,A.jsxs)(`div`,{className:`space-y-2 text-xs`,children:[j&&(0,A.jsxs)(`div`,{className:`rounded border border-red-500/20 bg-red-500/5 px-2 py-1.5`,children:[(0,A.jsx)(`div`,{className:`font-medium text-red-200`,children:j.diagnosis.summary}),(0,A.jsxs)(`div`,{className:`mt-0.5 text-red-200/70`,children:[`Cause `,j.diagnosis.cause,` · `,j.diagnosis.confidence]})]}),O&&(0,A.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-3 gap-y-1`,children:[(0,A.jsx)(V,{label:`Exit`,value:O.lastError,className:`col-span-2`}),O.detectedAt&&(0,A.jsx)(V,{label:`Detected`,value:b(a,O.detectedAt)}),typeof O.runtimeMs==`number`&&(0,A.jsx)(V,{label:`Runtime`,value:`${Math.max(0,Math.round(O.runtimeMs/1e3))}s`}),O.systemd?.unit&&(0,A.jsx)(V,{label:`Unit`,value:O.systemd.unit,mono:!0,className:`col-span-2`}),O.systemd?.result&&(0,A.jsx)(V,{label:`Systemd Result`,value:O.systemd.result}),O.logFile&&(0,A.jsx)(V,{label:`Log`,value:O.logFile,mono:!0,className:`col-span-2`})]}),O?.logTail?.length?(0,A.jsx)(`pre`,{className:`max-h-32 overflow-auto whitespace-pre-wrap break-words rounded border border-border bg-zinc-950 p-2 text-[11px] leading-4 text-zinc-100`,children:O.logTail.slice(-8).join(`
2
- `)}):null]})}),(0,A.jsx)(B,{title:`Recent Events (${S.length})`,icon:(0,A.jsx)(i,{className:`h-3.5 w-3.5`}),children:S.length===0?(0,A.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`No recent lifecycle events or command outcomes.`}):(0,A.jsx)(`div`,{className:`space-y-1`,children:S.slice(0,12).map((e,t)=>(0,A.jsxs)(`div`,{className:`grid grid-cols-[5.5rem_5rem_1fr] gap-2 text-xs`,children:[(0,A.jsx)(`span`,{className:`text-muted-foreground tabular-nums`,children:b(a,e.ts)}),(0,A.jsx)(C,{variant:`outline`,className:`h-5 justify-center text-[10px]`,children:e.source}),(0,A.jsxs)(`div`,{className:`min-w-0`,children:[(0,A.jsx)(`div`,{className:`truncate font-medium`,title:e.title,children:e.title}),e.detail&&(0,A.jsx)(`div`,{className:`break-words text-muted-foreground`,children:e.detail.length>160?e.detail.slice(0,160)+`...`:e.detail}),typeof e.metadata?.id==`string`&&(0,A.jsxs)(`div`,{className:`font-mono text-[10px] text-muted-foreground`,children:[`command `,e.metadata.id]})]})]},`${e.source}-${e.ts}-${e.kind}-${t}`))})}),v&&P&&(0,A.jsx)(B,{title:`Log Tail`,icon:(0,A.jsx)(s,{className:`h-3.5 w-3.5`}),children:(0,A.jsx)(D,{orchestratorId:v.id,session:P,lines:120})})]})}function F(e,t){return t?.managedAgents.find(t=>t.policyName===e.policy.name||e.state.agentId&&t.agentId===e.state.agentId||e.state.spawnRequestId&&t.spawnRequestId===e.state.spawnRequestId||e.state.tmuxSession&&(t.sessionName===e.state.tmuxSession||t.tmuxSession===e.state.tmuxSession))}function I(e,t){return t?.terminalSession||t?.sessionName||t?.tmuxSession||e.state.tmuxSession}function L(e,t){let n=R(t?.meta?.lastExit);if(n)return n;for(let t of e){let e=R(t.metadata?.lastExit);if(e)return e}return null}function R(e){if(!y(e)||typeof e.lastError!=`string`)return null;let t=y(e.systemd)?e.systemd:void 0;return{lastError:e.lastError,detectedAt:typeof e.detectedAt==`number`?e.detectedAt:void 0,runtimeMs:typeof e.runtimeMs==`number`?e.runtimeMs:void 0,logFile:typeof e.logFile==`string`?e.logFile:void 0,logBytes:typeof e.logBytes==`number`?e.logBytes:void 0,logEmpty:typeof e.logEmpty==`boolean`?e.logEmpty:void 0,logTail:Array.isArray(e.logTail)?e.logTail.filter(e=>typeof e==`string`):void 0,systemd:t?{unit:typeof t.unit==`string`?t.unit:void 0,activeState:typeof t.activeState==`string`?t.activeState:void 0,subState:typeof t.subState==`string`?t.subState:void 0,result:typeof t.result==`string`?t.result:void 0}:void 0,unavailable:Array.isArray(e.unavailable)?e.unavailable.filter(e=>typeof e==`string`):void 0}}function z(e,t,n,r,i,a,o){let s=[`# Managed Agent Diagnostics`,`Policy: ${e.policy.name}`,`Lifecycle: ${e.state.status}`,`Provider: ${e.policy.provider}`,`CWD: ${e.policy.cwd}`,`Approval: ${e.policy.permissionMode}`];if(e.policy.model&&s.push(`Model: ${e.policy.model}`),e.policy.effort&&s.push(`Effort: ${e.policy.effort}`),e.policy.profile&&s.push(`Profile: ${e.policy.profile}`),e.policy.tags.length&&s.push(`Tags: ${e.policy.tags.join(`, `)}`),e.policy.capabilities.length&&s.push(`Caps: ${e.policy.capabilities.join(`, `)}`),t&&s.push(`Agent: ${t.id} (${t.status})`),n&&s.push(`Orchestrator: ${n.hostname} (${n.id})`,`Orchestrator status: ${n.status}`),r&&(s.push(``,`## Runtime`),r.pid&&s.push(`PID: ${r.pid}`),r.supervisor&&s.push(`Supervisor: ${r.supervisor}`),r.systemdUnit&&s.push(`Systemd: ${r.systemdUnit}`),r.sessionName&&s.push(`Session: ${r.sessionName}`),r.terminalSession&&s.push(`Terminal: ${r.terminalSession} (${r.terminalAvailable?`available`:`not attachable`})`),r.spawnRequestId&&s.push(`Spawn request: ${r.spawnRequestId}`)),(e.state.lastError||a||o)&&(s.push(``,`## Post-Mortem`),e.state.lastError&&s.push(`Last error: ${e.state.lastError}`),a&&s.push(`Crash: ${a.diagnosis.cause}/${a.diagnosis.confidence} - ${a.diagnosis.summary}`),o?.lastError&&s.push(`Exit: ${o.lastError}`),o?.logTail?.length&&s.push(``,`Log tail:`,...o.logTail.slice(-8))),i.length){s.push(``,`## Recent Events`);for(let e of i.slice(0,12)){let t=typeof e.metadata?.id==`string`?` (${e.metadata.id})`:``;s.push(`- ${new Date(S(e.ts)).toISOString()} [${e.source}] ${e.title}${t}${e.detail?`: ${e.detail}`:``}`)}}return s.join(`
3
- `)}function B({title:e,icon:t,children:n}){return(0,A.jsxs)(`div`,{className:`rounded-md border border-border p-2.5`,children:[(0,A.jsxs)(`h3`,{className:`mb-2 flex items-center gap-1.5 text-xs font-medium text-muted-foreground`,children:[t,e]}),n]})}function V({label:e,value:t,className:n=``,mono:r=!1}){return(0,A.jsxs)(`div`,{className:`min-w-0 ${n}`,children:[(0,A.jsx)(`span`,{className:`text-muted-foreground`,children:e}),(0,A.jsx)(`div`,{className:`truncate ${r?`font-mono`:``}`,title:t,children:t})]})}function H({label:e,values:t}){return(0,A.jsxs)(`div`,{className:`col-span-2`,children:[(0,A.jsx)(`span`,{className:`text-muted-foreground`,children:e}),(0,A.jsx)(`div`,{className:`mt-0.5 flex flex-wrap gap-1`,children:t.map(e=>(0,A.jsx)(C,{variant:`outline`,className:`text-[10px]`,children:e},e))})]})}function U({title:e,body:t}){return(0,A.jsxs)(`div`,{className:`rounded border border-red-500/20 bg-red-500/5 px-2 py-1.5`,children:[(0,A.jsx)(`span`,{className:`text-muted-foreground`,children:e}),(0,A.jsx)(`div`,{className:`mt-0.5 break-words text-red-300/80`,children:t})]})}function W(e,t){let n=t?.meta?.tmuxSession;return typeof n==`string`&&n.trim()?n:e.state.tmuxSession}function G(e,t){return W(e,t)?!!t?.providerCapabilities?.terminal?.live?.read:!1}function K(e,t){return G(e,t)?!!t?.providerCapabilities?.terminal?.live?.write:!1}function q(){let e=v(e=>e.managedPolicies),n=v(e=>e.agentsById),i=v(e=>e.orchestrators),o=v(e=>e.fetchManagedPolicies),l=v(e=>e.fetchOrchestrators),u=v(e=>e.apiCall),p=v(e=>e.openPolicyCreate),m=v(e=>e.openPolicyEdit),y=v(e=>e.deletePolicy),b=_(),[S,C]=(0,k.useState)(null),[T,E]=(0,k.useState)(null),[j,N]=(0,k.useState)(null);(0,k.useEffect)(()=>{Promise.all([o(),l()])},[]);async function F(e,t){await u(`POST`,`/spawn-policy/${encodeURIComponent(e)}/${t}`,{surface:{component:`managed-agents`}}),await o()}let I=j?e.find(e=>e.policy.name===j)??null:null;return(0,A.jsxs)(`div`,{className:`space-y-4`,children:[(0,A.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,A.jsxs)(`div`,{children:[(0,A.jsx)(`h1`,{className:`text-2xl font-semibold`,children:`Managed Agents`}),(0,A.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Spawn policies, lifecycle state, and headless session logs.`})]}),(0,A.jsxs)(w,{onClick:p,size:`sm`,children:[(0,A.jsx)(t,{className:`h-4 w-4 mr-1`}),`Create Policy`]})]}),e.length===0&&(0,A.jsx)(`div`,{className:`rounded-md border border-border px-3 py-8 text-center text-sm text-muted-foreground`,children:`No managed agents configured`}),(0,A.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2 lg:grid-cols-3`,children:e.map(e=>{let t=e.state.agentId?n[e.state.agentId]:void 0,i=W(e,t);return(0,A.jsxs)(`div`,{className:`rounded-md border border-border bg-card p-3 space-y-2`,children:[(0,A.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,A.jsxs)(`div`,{className:`min-w-0`,children:[(0,A.jsx)(`div`,{className:`font-medium text-sm truncate`,children:e.policy.label||e.policy.name}),(0,A.jsxs)(`div`,{className:`text-xs text-muted-foreground truncate`,children:[e.policy.mode,` · `,e.policy.cwd]})]}),(0,A.jsx)(M,{status:e.state.status})]}),(0,A.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-4 gap-y-1 text-xs`,children:[(0,A.jsx)(`div`,{className:`text-muted-foreground`,children:`Provider`}),(0,A.jsx)(`div`,{children:e.policy.provider}),(0,A.jsx)(`div`,{className:`text-muted-foreground`,children:`Agent`}),(0,A.jsx)(`div`,{className:`font-mono truncate`,children:e.state.agentId||`-`}),(0,A.jsx)(`div`,{className:`text-muted-foreground`,children:`Restarts`}),(0,A.jsx)(`div`,{children:e.state.restartCount}),(e.state.backoffUntil||e.state.lastError)&&(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(`div`,{className:`text-muted-foreground`,children:e.state.backoffUntil?`Backoff`:`Error`}),(0,A.jsx)(`div`,{className:`truncate`,children:e.state.backoffUntil?x(e.state.backoffUntil):e.state.lastError})]})]}),(0,A.jsxs)(`div`,{className:`flex flex-wrap gap-1 pt-1 border-t border-border`,children:[(0,A.jsx)(w,{size:`icon`,variant:`outline`,className:`h-7 w-7`,onClick:()=>F(e.policy.name,`start`),title:`Start`,children:(0,A.jsx)(r,{className:`h-3.5 w-3.5`})}),(0,A.jsx)(w,{size:`icon`,variant:`outline`,className:`h-7 w-7`,onClick:()=>F(e.policy.name,`stop`),title:`Stop`,children:(0,A.jsx)(g,{className:`h-3.5 w-3.5`})}),(0,A.jsx)(w,{size:`icon`,variant:`outline`,className:`h-7 w-7`,onClick:()=>F(e.policy.name,`restart`),title:`Restart`,children:(0,A.jsx)(a,{className:`h-3.5 w-3.5`})}),(0,A.jsx)(w,{size:`icon`,variant:`outline`,className:`h-7 w-7`,onClick:()=>C(e),disabled:!e.state.tmuxSession,title:`Logs`,children:(0,A.jsx)(s,{className:`h-3.5 w-3.5`})}),(0,A.jsx)(w,{size:`icon`,variant:`outline`,className:`h-7 w-7`,onClick:()=>i&&E({item:e,session:i}),disabled:!G(e,t),title:`Terminal`,children:(0,A.jsx)(d,{className:`h-3.5 w-3.5`})}),(0,A.jsx)(w,{size:`icon`,variant:j===e.policy.name?`secondary`:`outline`,className:`h-7 w-7`,onClick:()=>N(t=>t===e.policy.name?null:e.policy.name),title:`Diagnostics`,children:(0,A.jsx)(h,{className:`h-3.5 w-3.5`})}),(0,A.jsx)(w,{size:`icon`,variant:`outline`,className:`h-7 w-7`,onClick:()=>m(e.policy),title:`Edit`,children:(0,A.jsx)(c,{className:`h-3.5 w-3.5`})}),(0,A.jsx)(w,{size:`icon`,variant:`outline`,className:`h-7 w-7`,onClick:()=>y(e.policy.name),title:`Delete`,children:(0,A.jsx)(f,{className:`h-3.5 w-3.5`})})]})]},e.policy.name)})}),I&&(0,A.jsx)(P,{item:I,agent:I.state.agentId?n[I.state.agentId]:void 0,orchestrators:i,now:b,onClose:()=>N(null)}),S?.state.tmuxSession&&(0,A.jsxs)(`div`,{className:`space-y-2`,children:[(0,A.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,A.jsxs)(`h2`,{className:`text-lg font-semibold`,children:[S.policy.name,` Logs`]}),(0,A.jsx)(w,{variant:`outline`,size:`sm`,onClick:()=>C(null),children:`Close`})]}),(0,A.jsx)(D,{orchestratorId:S.policy.orchestratorId,session:S.state.tmuxSession})]}),(0,A.jsx)(O,{open:!!T,onOpenChange:e=>{e||E(null)},orchestratorId:T?.item.policy.orchestratorId??``,session:T?.session??``,interactive:T?K(T.item,T.item.state.agentId?n[T.item.state.agentId]:void 0):!1})]})}export{q as ManagedAgentsView};
4
- //# sourceMappingURL=managed-agents-CpzKXDtV.js.map
@@ -1,2 +0,0 @@
1
- import{Zn as e}from"./lucide-react-C4eXYCwx.js";import{M as t,j as n}from"./index-DlBSuzd2.js";import{i as r,n as i,r as a,t as o}from"./lib-l-JkMVR9.js";var s=e(),c={...a,attributes:{...a.attributes,code:[...a.attributes?.code||[],[`className`,/^language-[\w-]+$/]]}};function l(e){return!e||!/^https?:\/\//i.test(e)?{}:{target:`_blank`,rel:`noreferrer`}}function u({content:e,path:a}){return(0,s.jsx)(`div`,{className:`markdown-preview max-w-none overflow-hidden p-4 text-sm leading-6`,children:(0,s.jsx)(r,{remarkPlugins:[o],rehypePlugins:[[i,c]],components:{a({href:e,children:t}){return(0,s.jsx)(`a`,{href:e,...l(e),children:t})},img({src:e,alt:t}){return e?(0,s.jsx)(n,{src:e,alt:t,className:`max-w-full`}):null},code({className:e,children:n,...r}){let i=/language-([\w-]+)/.exec(e||``),o=String(n).replace(/\n$/,``);return i?(0,s.jsx)(t,{content:o,path:`${a}.${i[1]}`,languageHint:i[1],compact:!0}):(0,s.jsx)(`code`,{className:e,...r,children:n})}},children:e})})}export{u as MarkdownPreview};
2
- //# sourceMappingURL=markdown-preview-impl-DxBnlJ2k.js.map
@@ -1,2 +0,0 @@
1
- import{r as e}from"./chunk-CilyBKbf.js";import{$t as t,B as n,G as r,I as ee,O as te,Zn as i,h as ne,jn as re,k as a,ur as o}from"./lucide-react-C4eXYCwx.js";import{f as ie,t as s}from"./store-Bnag1kY-.js";import{K as c,d as ae,h as l}from"./display-1J__Ti1K.js";import{t as u}from"./badge-D8fABzMs.js";import{t as d}from"./button-KASZcscA.js";import{t as f}from"./input-CtHfLn1i.js";import{R as oe,r as se,u as p}from"./index-DlBSuzd2.js";import{o as m,r as h,s as g,t as _}from"./card-Cds0MWME.js";var v=e(o(),1),y=i(),b=[`organization`,`role`,`project`,`task`,`interaction`,`agent`],ce=[`private`,`project`,`org`,`public`],le=[`public`,`normal`,`sensitive`,`secret`],x=[`reported`,`inferred`,`verified`];function S(){return{type:`project`,scope:`default`,title:``,content:``,tags:``,visibility:`project`,sensitivity:`normal`,confidence:`reported`,relevanceScore:`0.7`}}function C(e){return{type:e.type,scope:e.scope,title:e.title,content:e.content,tags:e.tags.join(`, `),visibility:e.visibility,sensitivity:e.sensitivity,confidence:e.confidence,relevanceScore:String(e.relevanceScore)}}function w(e){return e.split(`,`).map(e=>e.trim()).filter(Boolean)}function T(e){let t={limit:100};e.type&&(t.type=e.type),e.scope.trim()&&(t.scope=e.scope.trim()),e.visibility&&(t.visibility=e.visibility);let n=w(e.tags);if(n.length&&(t.tags=n),e.minRelevance.trim()){let n=Number(e.minRelevance);Number.isFinite(n)&&(t.minRelevance=Math.max(0,Math.min(1,n)))}return t}function E(e){return e===`secret`?`bg-red-500/10 text-red-400 border-red-500/30`:e===`sensitive`?`bg-yellow-500/10 text-yellow-400 border-yellow-500/30`:e===`public`?`bg-blue-500/10 text-blue-400 border-blue-500/30`:`bg-zinc-500/10 text-zinc-400 border-zinc-500/30`}function D(e){return e>=.8?`text-emerald-400`:e>=.5?`text-yellow-400`:`text-zinc-400`}function ue(e){return e?Object.entries(e).map(([e,t])=>`${e}=${Array.isArray(t)?t.join(` `):String(t)}`).join(` `):`default`}function de(e){return e.filter(e=>![`system`,`user`,`channel`].includes(e.kind||``))}function O(){let e=ie(),i=s(e=>e.agents),o=s(e=>e.memories),O=s(e=>e.memoryTotal),A=s(e=>e.memoryStats),j=s(e=>e.memoryBrokerInfo),M=s(e=>e.memoryFilters),N=s(e=>e.selectedMemoryId),pe=s(e=>e.memoryLoading),P=s(e=>e.set),me=s(e=>e.fetchMemories),he=s(e=>e.refreshMemory),F=s(e=>e.saveMemory),I=s(e=>e.deleteMemory),L=s(e=>e.injectMemory),R=o.find(e=>e.id===N),[z,B]=(0,v.useState)(`create`),[V,H]=(0,v.useState)(S),[U,W]=(0,v.useState)(``),[G,ge]=(0,v.useState)(`manual`),[K,_e]=(0,v.useState)(`1600`),[q,ve]=(0,v.useState)(`8`),[J,ye]=(0,v.useState)(``),Y=(0,v.useMemo)(()=>de(i),[i]);(0,v.useEffect)(()=>{!U&&Y[0]&&W(Y[0].id)},[Y,U]),(0,v.useEffect)(()=>{R&&z===`edit`&&H(C(R))},[R?.id,z]);let X=(0,v.useMemo)(()=>{let e=M.search.trim().toLowerCase();return e?o.filter(t=>[t.id,t.type,t.scope,t.title,t.content,...t.tags].some(t=>String(t).toLowerCase().includes(e))):o},[o,M.search]);function Z(e){P({memoryFilters:{...M,...e}})}async function be(){let e=Number(V.relevanceScore),t={title:V.title.trim(),content:V.content.trim(),tags:w(V.tags),visibility:V.visibility,sensitivity:V.sensitivity,confidence:V.confidence,relevanceScore:Number.isFinite(e)?Math.max(0,Math.min(1,e)):.7};if(z===`edit`&&R){await F(t,R.id);return}await F({...t,type:V.type,scope:V.scope.trim()}),B(`create`),H(S())}async function Q(e){if(!U)return;let t=await L({agentId:U,memoryIds:e,query:e?.length?void 0:T(M),reason:G.trim()||`manual`,budget:{maxTokens:Math.max(200,Number(K)||1600),maxMemories:Math.max(1,Number(q)||8),priorityCutoff:3}});t?.command?.id&&ye(t.command.id)}function xe(){B(`create`),H(S())}function Se(){R&&(B(`edit`),H(C(R)))}let Ce=V.title.trim()&&V.content.trim()&&(z===`edit`||V.scope.trim()),$=ue(j?.config);return(0,y.jsxs)(`div`,{className:`space-y-4`,children:[(0,y.jsxs)(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[(0,y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,y.jsx)(re,{className:`w-5 h-5 text-muted-foreground`}),(0,y.jsx)(`h2`,{className:`text-lg font-semibold`,children:`Memory`}),(0,y.jsx)(u,{variant:`secondary`,children:A?.total??O}),j&&(0,y.jsx)(u,{className:j.external?`bg-blue-500/15 text-blue-400 border-blue-500/30`:`bg-emerald-500/15 text-emerald-400 border-emerald-500/30`,children:j.type})]}),(0,y.jsxs)(d,{size:`sm`,variant:`outline`,className:`gap-1.5`,onClick:()=>he(),children:[(0,y.jsx)(ee,{className:`w-3.5 h-3.5 ${pe?`animate-spin`:``}`}),`Refresh`]})]}),(0,y.jsxs)(`div`,{className:`grid gap-3 xl:grid-cols-[1.2fr_0.8fr]`,children:[(0,y.jsxs)(_,{children:[(0,y.jsx)(m,{className:`py-3 px-4`,children:(0,y.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,y.jsxs)(g,{className:`text-sm font-medium flex items-center gap-2`,children:[(0,y.jsx)(t,{className:`w-4 h-4 text-muted-foreground`}),`Broker`]}),j?.capabilities&&(0,y.jsx)(`div`,{className:`flex flex-wrap gap-1 justify-end`,children:Object.entries(j.capabilities).filter(([,e])=>!!e).map(([e])=>(0,y.jsx)(u,{variant:`outline`,className:`text-[10px] px-1.5 py-0`,children:e},e))})]})}),(0,y.jsxs)(h,{className:`px-4 pb-4 space-y-3`,children:[(0,y.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-5 gap-2`,children:[(0,y.jsx)(k,{label:`total`,value:A?.total??O}),(0,y.jsx)(k,{label:`project`,value:A?.byType?.project??0}),(0,y.jsx)(k,{label:`task`,value:A?.byType?.task??0}),(0,y.jsx)(k,{label:`agent`,value:A?.byType?.agent??0}),(0,y.jsx)(k,{label:`sensitive`,value:(A?.bySensitivity?.sensitive??0)+(A?.bySensitivity?.secret??0)})]}),(0,y.jsx)(`div`,{className:`font-mono text-xs text-muted-foreground truncate`,title:$,children:$})]})]}),(0,y.jsxs)(_,{children:[(0,y.jsx)(m,{className:`py-3 px-4`,children:(0,y.jsx)(g,{className:`text-sm font-medium`,children:`Inject`})}),(0,y.jsxs)(h,{className:`px-4 pb-4 space-y-2`,children:[(0,y.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2`,children:[(0,y.jsxs)(`select`,{className:`rounded-md border border-input bg-background px-2 py-1.5 text-sm`,value:U,onChange:e=>W(e.target.value),children:[(0,y.jsx)(`option`,{value:``,children:`Agent`}),Y.map(e=>(0,y.jsx)(`option`,{value:e.id,children:ae(e)},e.id))]}),(0,y.jsx)(f,{value:G,onChange:e=>ge(e.target.value),placeholder:`reason`}),(0,y.jsx)(f,{value:K,onChange:e=>_e(e.target.value),inputMode:`numeric`,placeholder:`tokens`}),(0,y.jsx)(f,{value:q,onChange:e=>ve(e.target.value),inputMode:`numeric`,placeholder:`memories`})]}),(0,y.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,y.jsxs)(d,{size:`sm`,className:`gap-1.5`,disabled:!U||!R,onClick:()=>R&&Q([R.id]),children:[(0,y.jsx)(te,{className:`w-3.5 h-3.5`}),`Selected`]}),(0,y.jsxs)(d,{size:`sm`,variant:`outline`,className:`gap-1.5`,disabled:!U,onClick:()=>Q(),children:[(0,y.jsx)(a,{className:`w-3.5 h-3.5`}),`Filtered`]}),J&&(0,y.jsx)(u,{variant:`outline`,className:`font-mono text-[10px]`,children:J})]})]})]})]}),(0,y.jsxs)(`div`,{className:`grid gap-4 xl:grid-cols-[minmax(0,1fr)_420px]`,children:[(0,y.jsxs)(`div`,{className:`space-y-3`,children:[(0,y.jsx)(_,{children:(0,y.jsx)(h,{className:`p-3`,children:(0,y.jsxs)(`div`,{className:`grid grid-cols-2 lg:grid-cols-6 gap-2`,children:[(0,y.jsx)(f,{className:`lg:col-span-2`,value:M.search,onChange:e=>Z({search:e.target.value}),placeholder:`Search visible memories`}),(0,y.jsxs)(`select`,{className:`rounded-md border border-input bg-background px-2 py-1.5 text-sm`,value:M.type,onChange:e=>Z({type:e.target.value}),children:[(0,y.jsx)(`option`,{value:``,children:`All types`}),b.map(e=>(0,y.jsx)(`option`,{value:e,children:e},e))]}),(0,y.jsx)(f,{value:M.scope,onChange:e=>Z({scope:e.target.value}),placeholder:`scope`}),(0,y.jsx)(f,{value:M.tags,onChange:e=>Z({tags:e.target.value}),placeholder:`tags`}),(0,y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,y.jsx)(f,{value:M.minRelevance,onChange:e=>Z({minRelevance:e.target.value}),placeholder:`score`}),(0,y.jsx)(d,{size:`sm`,variant:`outline`,className:`h-8 px-2`,onClick:()=>me(),children:(0,y.jsx)(a,{className:`w-4 h-4`})})]})]})})}),(0,y.jsx)(p,{className:`h-[calc(100dvh-24rem)] min-h-[360px]`,children:(0,y.jsxs)(`div`,{className:`space-y-2 pr-2`,children:[X.length===0&&(0,y.jsx)(`div`,{className:`text-center text-sm text-muted-foreground py-16`,children:`No memories`}),X.map(t=>(0,y.jsx)(fe,{memory:t,selected:t.id===N,now:e,onSelect:()=>P({selectedMemoryId:t.id})},t.id))]})})]}),(0,y.jsxs)(_,{children:[(0,y.jsx)(m,{className:`py-3 px-4`,children:(0,y.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,y.jsx)(g,{className:`text-sm font-medium`,children:z===`edit`?`Edit Memory`:`New Memory`}),(0,y.jsxs)(`div`,{className:`flex gap-1`,children:[(0,y.jsx)(d,{size:`sm`,variant:`ghost`,className:`h-7 px-2`,onClick:xe,title:`New memory`,children:(0,y.jsx)(n,{className:`w-3.5 h-3.5`})}),(0,y.jsx)(d,{size:`sm`,variant:`ghost`,className:`h-7 px-2`,onClick:Se,disabled:!R,title:`Edit selected`,children:(0,y.jsx)(r,{className:`w-3.5 h-3.5`})}),(0,y.jsx)(d,{size:`sm`,variant:`ghost`,className:`h-7 px-2 text-red-400 hover:text-red-300`,disabled:!R,onClick:()=>R&&I(R.id),title:`Delete selected`,children:(0,y.jsx)(ne,{className:`w-3.5 h-3.5`})})]})]})}),(0,y.jsxs)(h,{className:`px-4 pb-4 space-y-3`,children:[R&&(0,y.jsxs)(y.Fragment,{children:[(0,y.jsxs)(`div`,{className:`space-y-2`,children:[(0,y.jsxs)(`div`,{className:`flex flex-wrap gap-1`,children:[(0,y.jsx)(u,{variant:`secondary`,children:R.type}),(0,y.jsx)(u,{variant:`outline`,children:R.scope}),(0,y.jsx)(u,{className:E(R.sensitivity),children:R.sensitivity}),(0,y.jsx)(u,{variant:`outline`,className:D(R.relevanceScore),children:R.relevanceScore.toFixed(2)})]}),(0,y.jsxs)(`div`,{className:`text-xs text-muted-foreground`,title:l(R.updatedAt),children:[`updated `,c(e,R.updatedAt)]}),(0,y.jsx)(`p`,{className:`text-sm font-medium`,children:R.title}),(0,y.jsx)(`p`,{className:`text-xs text-muted-foreground whitespace-pre-wrap max-h-24 overflow-auto`,children:R.content})]}),(0,y.jsx)(oe,{})]}),(0,y.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,y.jsx)(`select`,{className:`rounded-md border border-input bg-background px-2 py-1.5 text-sm`,disabled:z===`edit`,value:V.type,onChange:e=>H({...V,type:e.target.value}),children:b.map(e=>(0,y.jsx)(`option`,{value:e,children:e},e))}),(0,y.jsx)(f,{disabled:z===`edit`,value:V.scope,onChange:e=>H({...V,scope:e.target.value}),placeholder:`scope`}),(0,y.jsx)(f,{className:`col-span-2`,value:V.title,onChange:e=>H({...V,title:e.target.value}),placeholder:`title`}),(0,y.jsx)(se,{className:`col-span-2 min-h-32`,value:V.content,onChange:e=>H({...V,content:e.target.value}),placeholder:`content`}),(0,y.jsx)(f,{className:`col-span-2`,value:V.tags,onChange:e=>H({...V,tags:e.target.value}),placeholder:`tags`}),(0,y.jsx)(`select`,{className:`rounded-md border border-input bg-background px-2 py-1.5 text-sm`,value:V.visibility,onChange:e=>H({...V,visibility:e.target.value}),children:ce.map(e=>(0,y.jsx)(`option`,{value:e,children:e},e))}),(0,y.jsx)(`select`,{className:`rounded-md border border-input bg-background px-2 py-1.5 text-sm`,value:V.sensitivity,onChange:e=>H({...V,sensitivity:e.target.value}),children:le.map(e=>(0,y.jsx)(`option`,{value:e,children:e},e))}),(0,y.jsx)(`select`,{className:`rounded-md border border-input bg-background px-2 py-1.5 text-sm`,value:V.confidence,onChange:e=>H({...V,confidence:e.target.value}),children:x.map(e=>(0,y.jsx)(`option`,{value:e,children:e},e))}),(0,y.jsx)(f,{value:V.relevanceScore,onChange:e=>H({...V,relevanceScore:e.target.value}),inputMode:`decimal`,placeholder:`score`})]}),(0,y.jsx)(d,{size:`sm`,className:`w-full`,disabled:!Ce,onClick:be,children:z===`edit`?`Save memory`:`Create memory`})]})]})]})]})}function k({label:e,value:t}){return(0,y.jsxs)(`div`,{className:`rounded-md border border-border bg-muted/20 px-3 py-2`,children:[(0,y.jsx)(`div`,{className:`text-lg font-semibold tabular-nums`,children:t}),(0,y.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:e})]})}function fe({memory:e,selected:t,now:n,onSelect:r}){return(0,y.jsx)(`button`,{onClick:r,className:`w-full text-left rounded-md border p-3 transition-colors ${t?`border-primary bg-primary/5`:`border-border bg-card hover:border-zinc-600`}`,children:(0,y.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,y.jsxs)(`div`,{className:`min-w-0`,children:[(0,y.jsxs)(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:[(0,y.jsx)(u,{variant:`secondary`,className:`text-[10px]`,children:e.type}),(0,y.jsx)(u,{variant:`outline`,className:`text-[10px] font-mono`,children:e.scope}),(0,y.jsx)(u,{className:`text-[10px] ${E(e.sensitivity)}`,children:e.sensitivity})]}),(0,y.jsx)(`div`,{className:`font-medium text-sm mt-2 truncate`,children:e.title}),(0,y.jsx)(`div`,{className:`text-xs text-muted-foreground line-clamp-2 mt-1`,children:e.content}),e.tags.length>0&&(0,y.jsx)(`div`,{className:`flex gap-1 flex-wrap mt-2`,children:e.tags.slice(0,8).map(e=>(0,y.jsxs)(u,{variant:`outline`,className:`text-[10px] text-zinc-400`,children:[`#`,e]},e))})]}),(0,y.jsxs)(`div`,{className:`text-right shrink-0 space-y-1`,children:[(0,y.jsx)(`div`,{className:`text-sm font-semibold tabular-nums ${D(e.relevanceScore)}`,children:e.relevanceScore.toFixed(2)}),(0,y.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,title:l(e.updatedAt),children:c(n,e.updatedAt)}),e.accessCount>0&&(0,y.jsxs)(`div`,{className:`text-[10px] text-muted-foreground`,children:[e.accessCount,` hits`]})]})]})})}export{O as MemoryView};
2
- //# sourceMappingURL=memory-Bnm7ILWL.js.map
@@ -1,2 +0,0 @@
1
- import{r as e}from"./chunk-CilyBKbf.js";import{Ct as t,Jn as n,Pn as r,Zn as i,l as a,m as o,mt as s,ot as c,pt as l,tt as u,ur as d}from"./lucide-react-C4eXYCwx.js";import{f,t as p}from"./store-Bnag1kY-.js";import{K as m,M as h,X as g,d as _,f as v,g as y,lt as b,q as x}from"./display-1J__Ti1K.js";import{t as S}from"./badge-D8fABzMs.js";import{D as C,G as w,H as T,O as E,R as D,U as O,u as k}from"./index-DlBSuzd2.js";import{o as A,r as j,s as M,t as N}from"./card-Cds0MWME.js";var P=e(d(),1),F=i();function I(){let e=p(e=>e.stats),i=p(e=>e.agents),d=p(e=>e.messages),I=p(e=>e.health),L=f(),R=p(e=>e.agentsById),z=p(e=>e.switchView),B=p(e=>e.runHealthAction),V=p(e=>e.managedPolicies),H=p(e=>e.showOffline),U=w(),W=O(),G=T(),K=(0,P.useMemo)(()=>{let e=g(i,!1,V);return H||(e=e.filter(e=>e.status!==`offline`)),[...e].sort((e,t)=>(b[e.status]??9)-(b[t.status]??9)||x(t.lastSeen)-x(e.lastSeen))},[i,H,V]),q=K.slice(0,20),J=[...d].sort((e,t)=>t.id-e.id).slice(0,15),Y=I&&I.status!==`ok`?y(I.checks||[]):[];function X(e){z(e)}return(0,F.jsxs)(`div`,{className:`space-y-6`,children:[(0,F.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,F.jsxs)(N,{className:`cursor-pointer hover:border-zinc-600 transition-colors`,onClick:()=>X(`agents`),children:[(0,F.jsx)(A,{className:`pb-1 pt-4 px-4`,children:(0,F.jsxs)(M,{className:`text-xs font-medium text-muted-foreground flex items-center gap-1.5`,children:[(0,F.jsx)(a,{className:`w-3.5 h-3.5`}),`Agents`]})}),(0,F.jsxs)(j,{className:`px-4 pb-4`,children:[(0,F.jsx)(`div`,{className:`text-2xl font-bold`,children:K.length}),(0,F.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:[U,` online`]})]})]}),(0,F.jsxs)(N,{className:`cursor-pointer hover:border-zinc-600 transition-colors`,onClick:()=>X(`agents`),children:[(0,F.jsx)(A,{className:`pb-1 pt-4 px-4`,children:(0,F.jsxs)(M,{className:`text-xs font-medium text-muted-foreground flex items-center gap-1.5`,children:[(0,F.jsx)(n,{className:`w-3.5 h-3.5`}),`Busy`]})}),(0,F.jsxs)(j,{className:`px-4 pb-4`,children:[(0,F.jsx)(`div`,{className:`text-2xl font-bold`,children:W}),(0,F.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:`in a turn now`})]})]}),(0,F.jsxs)(N,{className:`cursor-pointer hover:border-zinc-600 transition-colors`,onClick:()=>X(`messages`),children:[(0,F.jsx)(A,{className:`pb-1 pt-4 px-4`,children:(0,F.jsxs)(M,{className:`text-xs font-medium text-muted-foreground flex items-center gap-1.5`,children:[(0,F.jsx)(u,{className:`w-3.5 h-3.5`}),`Messages 24h`]})}),(0,F.jsxs)(j,{className:`px-4 pb-4`,children:[(0,F.jsx)(`div`,{className:`text-2xl font-bold`,children:e.messagesLast24h??`—`}),(0,F.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:`last 24 hours`})]})]}),(0,F.jsxs)(N,{className:`cursor-pointer hover:border-zinc-600 transition-colors`,onClick:()=>X(`messages`),children:[(0,F.jsx)(A,{className:`pb-1 pt-4 px-4`,children:(0,F.jsxs)(M,{className:`text-xs font-medium text-muted-foreground flex items-center gap-1.5`,children:[(0,F.jsx)(c,{className:`w-3.5 h-3.5`}),`Total Messages`]})}),(0,F.jsxs)(j,{className:`px-4 pb-4`,children:[(0,F.jsx)(`div`,{className:`text-2xl font-bold`,children:e.messages??`—`}),(0,F.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:`all time`})]})]})]}),Y.length>0&&(0,F.jsxs)(N,{className:`border-yellow-500/40 bg-yellow-500/5`,children:[(0,F.jsx)(A,{className:`pb-2 pt-4 px-4`,children:(0,F.jsxs)(M,{className:`text-sm font-medium text-yellow-400 flex items-center gap-2`,children:[(0,F.jsx)(o,{className:`w-4 h-4`}),`Health Alerts (`,Y.length,`)`]})}),(0,F.jsx)(j,{className:`px-4 pb-4 space-y-2`,children:Y.map(e=>(0,F.jsxs)(`div`,{className:`text-sm space-y-1`,children:[(0,F.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,F.jsx)(S,{variant:`outline`,className:e.status===`error`?`border-red-500/40 text-red-400`:`border-yellow-500/40 text-yellow-400`,children:e.status}),(0,F.jsx)(`span`,{className:`font-medium`,children:e.name})]}),(0,F.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.detail}),e.subjects.length>0&&(0,F.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:e.subjects.map(e=>(0,F.jsxs)(S,{variant:`secondary`,className:`max-w-full truncate text-[11px]`,title:[e.id,e.status,e.detail].filter(Boolean).join(` · `),children:[e.label||e.id,e.status?` · ${e.status}`:``,e.detail?` · ${e.detail}`:``]},e.id))}),e.actions.length>0&&(0,F.jsx)(`div`,{className:`flex flex-wrap gap-1.5 pt-0.5`,children:e.actions.slice(0,3).map(e=>(0,F.jsx)(`button`,{onClick:()=>B(e),className:`text-xs text-blue-400 hover:text-blue-300 underline underline-offset-2`,children:e.label},e.label))})]},e.name))})]}),(0,F.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-3 gap-4`,children:[(0,F.jsx)(N,{className:`cursor-pointer hover:border-zinc-600 transition-colors ${G.unreadInbox>0?`border-red-500/40`:``}`,onClick:()=>X(`chat`),children:(0,F.jsxs)(j,{className:`p-4 flex items-center gap-3`,children:[(0,F.jsx)(`div`,{className:`p-2 rounded-lg ${G.unreadInbox>0?`bg-red-500/15`:`bg-zinc-800`}`,children:(0,F.jsx)(t,{className:`w-4 h-4 ${G.unreadInbox>0?`text-red-400`:`text-zinc-400`}`})}),(0,F.jsxs)(`div`,{children:[(0,F.jsx)(`div`,{className:`text-lg font-bold`,children:G.unreadInbox}),(0,F.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`Unread`})]})]})}),(0,F.jsx)(N,{className:`cursor-pointer hover:border-zinc-600 transition-colors ${G.pendingPairInvites>0?`border-yellow-500/40`:``}`,onClick:()=>X(`pairs`),children:(0,F.jsxs)(j,{className:`p-4 flex items-center gap-3`,children:[(0,F.jsx)(`div`,{className:`p-2 rounded-lg ${G.pendingPairInvites>0?`bg-yellow-500/15`:`bg-zinc-800`}`,children:(0,F.jsx)(s,{className:`w-4 h-4 ${G.pendingPairInvites>0?`text-yellow-400`:`text-zinc-400`}`})}),(0,F.jsxs)(`div`,{children:[(0,F.jsx)(`div`,{className:`text-lg font-bold`,children:G.pendingPairInvites}),(0,F.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`Pair invites`})]})]})}),(0,F.jsx)(N,{className:`cursor-pointer hover:border-zinc-600 transition-colors ${G.claimableTasks>0?`border-orange-500/40`:``}`,onClick:()=>X(`work`),children:(0,F.jsxs)(j,{className:`p-4 flex items-center gap-3`,children:[(0,F.jsx)(`div`,{className:`p-2 rounded-lg ${G.claimableTasks>0?`bg-orange-500/15`:`bg-zinc-800`}`,children:(0,F.jsx)(l,{className:`w-4 h-4 ${G.claimableTasks>0?`text-orange-400`:`text-zinc-400`}`})}),(0,F.jsxs)(`div`,{children:[(0,F.jsx)(`div`,{className:`text-lg font-bold`,children:G.claimableTasks}),(0,F.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`Claimable waiting`})]})]})})]}),(0,F.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-6`,children:[(0,F.jsxs)(N,{children:[(0,F.jsx)(A,{className:`pb-2 pt-4 px-4`,children:(0,F.jsxs)(M,{className:`text-sm font-medium flex items-center gap-2`,children:[(0,F.jsx)(r,{className:`w-4 h-4 text-muted-foreground`}),`Agents`,(0,F.jsx)(`span`,{className:`ml-auto text-xs text-muted-foreground font-normal`,children:q.length})]})}),(0,F.jsx)(j,{className:`px-0 pb-0`,children:(0,F.jsx)(k,{className:`h-[340px]`,children:q.length===0?(0,F.jsx)(`div`,{className:`px-4 pb-4 text-sm text-muted-foreground`,children:`No agents registered.`}):(0,F.jsx)(`div`,{className:`space-y-0`,children:q.map((e,t)=>(0,F.jsxs)(`div`,{children:[t>0&&(0,F.jsx)(D,{}),(0,F.jsxs)(`div`,{className:`flex items-center gap-2.5 px-4 py-2.5 hover:bg-zinc-800/50 transition-colors cursor-pointer`,onClick:()=>p.getState().openAgentDetail(e),children:[(0,F.jsx)(E,{agent:e,now:L}),(0,F.jsx)(C,{agent:e}),(0,F.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,F.jsx)(`div`,{className:`text-sm font-medium truncate`,children:_(e)}),e.tags.length>0&&(0,F.jsx)(`div`,{className:`flex gap-1 mt-0.5 flex-wrap`,children:e.tags.slice(0,2).map(e=>(0,F.jsx)(S,{variant:`outline`,className:`text-[9px] px-1 py-0 h-4`,children:e},e))})]}),(0,F.jsx)(`span`,{className:`text-xs text-muted-foreground shrink-0`,children:m(L,e.lastSeen)})]})]},e.id))})})})]}),(0,F.jsxs)(N,{children:[(0,F.jsx)(A,{className:`pb-2 pt-4 px-4`,children:(0,F.jsxs)(M,{className:`text-sm font-medium flex items-center gap-2`,children:[(0,F.jsx)(n,{className:`w-4 h-4 text-muted-foreground`}),`Recent Activity`,(0,F.jsx)(`span`,{className:`ml-auto text-xs text-muted-foreground font-normal`,children:J.length})]})}),(0,F.jsx)(j,{className:`px-0 pb-0`,children:(0,F.jsx)(k,{className:`h-[340px]`,children:J.length===0?(0,F.jsx)(`div`,{className:`px-4 pb-4 text-sm text-muted-foreground`,children:`No recent messages.`}):(0,F.jsx)(`div`,{className:`space-y-0`,children:J.map((e,t)=>(0,F.jsxs)(`div`,{children:[t>0&&(0,F.jsx)(D,{}),(0,F.jsxs)(`div`,{className:`px-4 py-2.5 hover:bg-zinc-800/50 transition-colors`,children:[(0,F.jsxs)(`div`,{className:`flex items-center gap-1 text-xs text-muted-foreground mb-0.5`,children:[(0,F.jsx)(`span`,{className:`text-foreground font-medium truncate max-w-[100px]`,children:v(e.from,R)}),(0,F.jsx)(`span`,{children:`→`}),(0,F.jsx)(`span`,{className:`truncate max-w-[100px]`,children:v(e.to,R)}),(0,F.jsxs)(`span`,{className:`ml-auto shrink-0 tabular-nums`,children:[(0,F.jsxs)(`span`,{className:`opacity-40 mr-1`,children:[`#`,e.id]}),m(L,e.createdAt)]})]}),(0,F.jsx)(`div`,{className:`text-xs text-foreground line-clamp-2 leading-snug`,children:h(e)})]})]},e.id))})})})]})]})]})}export{I as OverviewView};
2
- //# sourceMappingURL=overview-BQ0b0V7Q.js.map
@@ -1,2 +0,0 @@
1
- import{r as e}from"./chunk-CilyBKbf.js";import{I as t,Lt as n,Nn as r,Qn as i,Vt as a,Zn as o,ur as s,yt as c}from"./lucide-react-C4eXYCwx.js";import{t as l}from"./store-Bnag1kY-.js";import{a as u}from"./types-BiJFuTiL.js";import{K as d}from"./display-1J__Ti1K.js";import{t as f}from"./badge-D8fABzMs.js";import{t as p}from"./button-KASZcscA.js";import{t as m}from"./copy-button-d9DFNX9v.js";import{o as h,r as g,s as _,t as v}from"./card-Cds0MWME.js";var y=e(s(),1),b=o(),x=[`rule`,`decision`,`fact`,`memory`],S={rule:`Rules`,decision:`Decisions`,fact:`Facts`,memory:`Memory`};function C(e){return e===`ingested`?`bg-blue-500/10 text-blue-400 border-blue-500/30`:e===`promoted`?`bg-emerald-500/10 text-emerald-400 border-emerald-500/30`:`bg-zinc-500/10 text-zinc-400 border-zinc-500/30`}var w=320;function T({entry:e,ownerName:t,now:n}){let[r,i]=(0,y.useState)(!1),a=e.body??``,o=a.length>w,s=r||!o?a:a.slice(0,w).trimEnd()+`…`;return(0,b.jsxs)(`div`,{className:`rounded-md border border-border bg-card/60 p-3`,children:[(0,b.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,b.jsx)(`span`,{className:`text-sm font-medium`,children:e.title}),(0,b.jsx)(f,{variant:`outline`,className:`text-[10px] ${C(e.source)}`,children:e.source}),e.inherited&&(0,b.jsxs)(f,{variant:`outline`,className:`gap-1 border-amber-500/30 bg-amber-500/10 text-[10px] text-amber-400`,children:[(0,b.jsx)(c,{className:`h-3 w-3`}),`inherited`,t?` · ${t}`:``]}),(0,b.jsx)(`span`,{className:`ml-auto text-[10px] text-muted-foreground`,children:d(n,e.updatedAt)})]}),a&&(0,b.jsxs)(`div`,{className:`mt-2`,children:[(0,b.jsx)(`pre`,{className:`whitespace-pre-wrap break-words font-mono text-xs text-muted-foreground`,children:s}),o&&(0,b.jsx)(`button`,{type:`button`,className:`mt-1 text-[11px] font-medium text-primary hover:underline`,onClick:()=>i(e=>!e),children:r?`Show less`:`Show more`})]}),e.tags.length>0&&(0,b.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-1`,children:e.tags.map(e=>(0,b.jsx)(f,{variant:`secondary`,className:`h-4 px-1 text-[9px]`,children:e},e))})]})}function E(){let e=l(e=>e.projectFocusId),o=l(e=>e.consumeProjectFocus),[s,c]=(0,y.useState)([]),[C,w]=(0,y.useState)(``),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(null),[A,j]=(0,y.useState)([]),[M,N]=(0,y.useState)(!0),[P,F]=(0,y.useState)(!1),[I,L]=(0,y.useState)(null),[R,z]=(0,y.useState)(()=>Date.now());async function B(){L(null);try{let t=await i(`GET`,`/projects${E?`?includeArchived=true`:``}`);c(t.projects),z(Date.now());let n=e,r=e=>t.projects.some(t=>t.id===e||t.slug===e);n&&r(n)?(w(n),o()):w(e=>e&&r(e)?e:t.projects[0]?.id??``)}catch(e){L(u(e))}finally{N(!1)}}(0,y.useEffect)(()=>{B()},[E]),(0,y.useEffect)(()=>{e&&s.some(t=>t.id===e||t.slug===e)&&(w(e),o())},[e]),(0,y.useEffect)(()=>{if(!C){k(null),j([]);return}let e=!1;return F(!0),Promise.all([i(`GET`,`/projects/${encodeURIComponent(C)}`),i(`GET`,`/projects/${encodeURIComponent(C)}/entries?includeInherited=true`)]).then(([t,n])=>{e||(k(t),j(n.entries),z(Date.now()))}).catch(t=>{e||L(u(t))}).finally(()=>{e||F(!1)}),()=>{e=!0}},[C]);let V=(0,y.useMemo)(()=>{let e=new Map;for(let t of s)e.set(t.id,t.title||t.slug);return e},[s]),H=(0,y.useMemo)(()=>A.filter(e=>e.source===`ingested`),[A]),U=(0,y.useMemo)(()=>{let e=new Map;for(let t of A){if(t.source===`ingested`)continue;let n=e.get(t.kind)??[];n.push(t),e.set(t.kind,n)}return e},[A]),W=A.filter(e=>!e.inherited).length,G=A.length-W;return(0,b.jsxs)(`div`,{className:`space-y-4 p-4`,children:[(0,b.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,b.jsx)(r,{className:`size-5 text-primary`}),(0,b.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Projects`}),(0,b.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`durable knowledge scope · epic #403`}),(0,b.jsxs)(`select`,{className:`ml-auto h-8 rounded-md border border-border bg-card px-2 text-sm text-foreground`,value:C,onChange:e=>w(e.target.value),disabled:s.length===0,children:[s.length===0&&(0,b.jsx)(`option`,{value:``,children:`No projects`}),s.map(e=>(0,b.jsxs)(`option`,{value:e.id,children:[e.title||e.slug,e.status===`archived`?` (archived)`:``]},e.id))]}),(0,b.jsxs)(`label`,{className:`flex items-center gap-1.5 text-xs text-muted-foreground select-none`,children:[(0,b.jsx)(`input`,{type:`checkbox`,className:`rounded`,checked:E,onChange:e=>D(e.target.checked)}),`Archived`]}),(0,b.jsxs)(p,{variant:`outline`,size:`sm`,onClick:()=>void B(),children:[(0,b.jsx)(t,{className:`size-4`}),` Refresh`]})]}),I&&(0,b.jsx)(`div`,{className:`rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-sm text-destructive`,children:I}),!M&&s.length===0&&(0,b.jsx)(v,{children:(0,b.jsxs)(g,{className:`py-10 text-center text-sm text-muted-foreground`,children:[`No projects yet. Projects are created through the relay `,(0,b.jsx)(`code`,{className:`font-mono text-xs`,children:`relay_project_*`}),` MCP tools (or bootstrapped from a root's CLAUDE.md).`]})}),O&&(0,b.jsxs)(b.Fragment,{children:[(0,b.jsxs)(v,{children:[(0,b.jsx)(h,{children:(0,b.jsxs)(_,{className:`flex flex-wrap items-center gap-2`,children:[(0,b.jsx)(`span`,{children:O.project.title||O.project.slug}),(0,b.jsx)(f,{variant:`outline`,className:`font-mono text-[10px]`,children:O.project.slug}),(0,b.jsx)(f,{variant:O.project.status===`active`?`secondary`:`outline`,className:`text-[10px]`,children:O.project.status}),(0,b.jsxs)(`span`,{className:`ml-auto text-xs font-normal text-muted-foreground`,children:[W,` own · `,G,` inherited · updated `,d(R,O.project.updatedAt)]})]})}),(O.project.description||O.project.issueRepo)&&(0,b.jsxs)(g,{className:`space-y-2 pt-0 text-sm text-muted-foreground`,children:[O.project.description&&(0,b.jsx)(`div`,{children:O.project.description}),O.project.issueRepo&&(0,b.jsxs)(`a`,{href:`https://github.com/${O.project.issueRepo}`,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1.5 text-primary hover:underline`,children:[(0,b.jsx)(n,{className:`size-3.5`}),(0,b.jsx)(`span`,{className:`font-mono text-xs`,children:O.project.issueRepo})]})]})]}),(0,b.jsxs)(v,{children:[(0,b.jsx)(h,{children:(0,b.jsxs)(_,{className:`flex items-center gap-2 text-base`,children:[(0,b.jsx)(n,{className:`size-4 text-muted-foreground`}),` Roots`,(0,b.jsxs)(`span`,{className:`text-xs font-normal text-muted-foreground`,children:[`(`,O.roots.length,`)`]})]})}),(0,b.jsx)(g,{children:O.roots.length===0?(0,b.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:`No roots bound. A project resolves to agents by the repo paths registered here.`}):(0,b.jsx)(`div`,{className:`space-y-1.5`,children:O.roots.map(e=>(0,b.jsxs)(`div`,{className:`flex items-center gap-2 rounded border border-border bg-card/60 px-2 py-1`,children:[(0,b.jsx)(`span`,{className:`flex-1 truncate font-mono text-xs text-muted-foreground`,title:e.rootPath,children:e.rootPath}),(0,b.jsx)(m,{value:e.rootPath,label:`Copy root path`,size:`icon`,className:`h-6 w-6`,iconClassName:`h-3 w-3`})]},e.rootPath))})})]}),H.length>0&&(0,b.jsxs)(v,{children:[(0,b.jsx)(h,{children:(0,b.jsxs)(_,{className:`flex items-center gap-2 text-base`,children:[(0,b.jsx)(a,{className:`size-4 text-blue-400`}),` Ingested CLAUDE.md`,(0,b.jsxs)(`span`,{className:`text-xs font-normal text-muted-foreground`,children:[`(`,H.length,`)`]})]})}),(0,b.jsx)(g,{className:`space-y-2`,children:H.map(e=>(0,b.jsx)(T,{entry:e,ownerName:e.inherited?V.get(e.projectId):void 0,now:R},e.id))})]}),P&&A.length===0?(0,b.jsx)(`div`,{className:`py-8 text-center text-sm text-muted-foreground`,children:`Loading entries…`}):A.length===0?(0,b.jsx)(v,{children:(0,b.jsx)(g,{className:`py-8 text-center text-sm text-muted-foreground`,children:`No entries yet. Agents write durable rules, decisions, facts, and memory here via the relay MCP tools.`})}):x.filter(e=>U.has(e)).map(e=>{let t=U.get(e);return(0,b.jsxs)(v,{children:[(0,b.jsx)(h,{children:(0,b.jsxs)(_,{className:`flex items-center gap-2 text-base`,children:[S[e],(0,b.jsxs)(`span`,{className:`text-xs font-normal text-muted-foreground`,children:[`(`,t.length,`)`]})]})}),(0,b.jsx)(g,{className:`space-y-2`,children:t.map(e=>(0,b.jsx)(T,{entry:e,ownerName:e.inherited?V.get(e.projectId):void 0,now:R},e.id))})]},e)})]})]})}export{E as ProjectsView};
2
- //# sourceMappingURL=projects-v5Kp1Oaq.js.map
@@ -1,2 +0,0 @@
1
- import{r as e}from"./chunk-CilyBKbf.js";import{A as t,I as n,Mn as r,N as i,Qn as a,Vt as o,Yn as s,Zn as c,_n as l,ur as u}from"./lucide-react-C4eXYCwx.js";import{a as d}from"./types-BiJFuTiL.js";import{K as f}from"./display-1J__Ti1K.js";import{t as p}from"./badge-D8fABzMs.js";import{t as m}from"./button-KASZcscA.js";import{r as h}from"./index-DlBSuzd2.js";import{a as g,i as _,o as v,r as y,s as ee,t as b}from"./card-Cds0MWME.js";var x=e(u(),1),S=c(),C=`all`;function w(e){return e.split(/[^a-zA-Z0-9]+/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `)}function T(e){return Array.isArray(e)?[...e].sort((e,t)=>{let n=e.category.localeCompare(t.category);if(n!==0)return n;let r=e.title.localeCompare(t.title);return r===0?e.slug.localeCompare(t.slug):r}):[]}function E(){let[e,c]=(0,x.useState)([]),[u,E]=(0,x.useState)(!0),[D,O]=(0,x.useState)(``),[k,A]=(0,x.useState)(``),[j,M]=(0,x.useState)(``),[N,P]=(0,x.useState)(C),[F,I]=(0,x.useState)(``),[L,R]=(0,x.useState)({}),[z,B]=(0,x.useState)(``),[V,H]=(0,x.useState)(()=>Date.now());async function U(){E(!0),O(``);try{c(T((await a(`GET`,`/settings/prompts`)).templates)),H(Date.now())}catch(e){O(d(e))}finally{E(!1)}}(0,x.useEffect)(()=>{U()},[]);let W=(0,x.useMemo)(()=>{let t=new Map;for(let n of e)t.set(n.category,(t.get(n.category)??0)+1);return[...t.entries()].sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>({key:e,count:t,label:w(e)}))},[e]),G=N===C||W.some(e=>e.key===N)?N:C,K=(0,x.useMemo)(()=>G===C?e:e.filter(e=>e.category===G),[G,e]),q=K.some(e=>e.slug===F)?F:K[0]?.slug??``,J=K.find(e=>e.slug===q)??null,Y=J?L[J.slug]??J.template:``,X=J?Y!==J.template:!1,Z=e.filter(e=>e.template!==e.defaultTemplate).length,Q=J?z===J.slug:!1;function te(e){I(e),A(``),M(``)}function $(e){c(t=>T(t.map(t=>t.slug===e.slug?e:t))),R(t=>({...t,[e.slug]:e.template})),H(Date.now())}async function ne(){if(!(!J||!X)){B(J.slug),A(``),M(``);try{let e=await a(`PUT`,`/settings/prompts/${encodeURIComponent(J.slug)}`,{template:Y});$(e),M(`Saved ${e.title}.`)}catch(e){A(d(e))}finally{B(``)}}}async function re(){if(!(!J||J.template===J.defaultTemplate)){B(J.slug),A(``),M(``);try{let e=await a(`POST`,`/settings/prompts/${encodeURIComponent(J.slug)}/reset`);$(e),M(`Reset ${e.title} to the built-in default.`)}catch(e){A(d(e))}finally{B(``)}}}function ie(){J&&(R(e=>({...e,[J.slug]:J.template})),A(``),M(`Unsaved edits discarded.`))}return(0,S.jsxs)(`div`,{className:`space-y-4 p-4`,children:[(0,S.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Prompts`}),(0,S.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`View and edit the externalized prompt templates used across Relay lifecycle, routing, workspace, and automation flows.`})]}),(0,S.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,S.jsxs)(p,{variant:`outline`,className:`gap-1`,children:[(0,S.jsx)(o,{className:`size-3`}),e.length,` template`,e.length===1?``:`s`]}),(0,S.jsxs)(p,{variant:`outline`,className:s(`gap-1`,Z>0&&`border-amber-500/40 bg-amber-500/10 text-amber-300`),children:[Z,` modified`]}),(0,S.jsxs)(m,{variant:`outline`,size:`sm`,onClick:()=>void U(),disabled:u,children:[(0,S.jsx)(n,{className:s(`size-4`,u&&`animate-spin`)}),`Refresh`]})]})]}),D&&(0,S.jsxs)(`div`,{className:`flex items-start gap-2 rounded-lg border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive`,children:[(0,S.jsx)(l,{className:`mt-0.5 size-4`}),(0,S.jsx)(`span`,{children:D})]}),u&&e.length===0?(0,S.jsx)(b,{size:`sm`,children:(0,S.jsx)(y,{className:`text-sm text-muted-foreground`,children:`Loading prompt templates…`})}):e.length===0?(0,S.jsx)(b,{children:(0,S.jsx)(y,{className:`py-10 text-center text-sm text-muted-foreground`,children:`No prompt templates are available yet.`})}):(0,S.jsxs)(`div`,{className:`grid gap-4 xl:grid-cols-[220px_minmax(0,0.9fr)_minmax(0,1.1fr)]`,children:[(0,S.jsxs)(`nav`,{className:`space-y-1 xl:sticky xl:top-4 xl:self-start`,children:[(0,S.jsxs)(`button`,{type:`button`,className:s(`w-full rounded-md border px-3 py-2 text-left text-sm transition-colors`,G===C?`border-primary/50 bg-primary/10 text-foreground`:`border-transparent hover:border-border hover:bg-accent`),onClick:()=>P(C),children:[(0,S.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,S.jsx)(`span`,{className:`font-medium`,children:`All`}),(0,S.jsx)(p,{variant:`outline`,className:`ml-auto h-4 px-1 text-[10px]`,children:e.length})]}),(0,S.jsx)(`span`,{className:`block truncate text-xs text-muted-foreground`,children:`Every externalized prompt template`})]}),W.map(e=>(0,S.jsxs)(`button`,{type:`button`,className:s(`w-full rounded-md border px-3 py-2 text-left text-sm transition-colors`,G===e.key?`border-primary/50 bg-primary/10 text-foreground`:`border-transparent hover:border-border hover:bg-accent`),onClick:()=>P(e.key),children:[(0,S.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,S.jsx)(`span`,{className:`font-medium`,children:e.label}),(0,S.jsx)(p,{variant:`outline`,className:`ml-auto h-4 px-1 text-[10px]`,children:e.count})]}),(0,S.jsx)(`span`,{className:`block truncate text-xs font-mono text-muted-foreground`,children:e.key})]},e.key))]}),(0,S.jsxs)(`div`,{className:`min-w-0 space-y-3`,children:[(0,S.jsx)(`div`,{className:`flex items-center justify-between gap-2 px-1`,children:(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`h2`,{className:`text-sm font-semibold`,children:G===C?`All templates`:`${w(G)} templates`}),(0,S.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[K.length,` template`,K.length===1?``:`s`,` in this view`]})]})}),K.map(e=>{let t=e.slug===q,n=e.template!==e.defaultTemplate;return(0,S.jsx)(`button`,{type:`button`,className:s(`w-full rounded-xl border p-4 text-left transition-colors`,t?`border-primary/50 bg-primary/10 ring-1 ring-primary/20`:`border-border bg-card hover:border-primary/30 hover:bg-accent`),onClick:()=>te(e.slug),children:(0,S.jsx)(`div`,{className:`flex flex-wrap items-start gap-2`,children:(0,S.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,S.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,S.jsx)(`span`,{className:`font-medium text-foreground`,children:e.title}),n&&(0,S.jsx)(p,{className:`bg-amber-500/15 text-amber-300 hover:bg-amber-500/15`,children:`Modified`}),(0,S.jsx)(p,{variant:`outline`,className:`text-[10px]`,children:w(e.category)})]}),(0,S.jsx)(`div`,{className:`mt-1 font-mono text-[11px] text-muted-foreground`,children:e.slug}),e.description&&(0,S.jsx)(`p`,{className:`mt-2 line-clamp-2 text-sm text-muted-foreground`,children:e.description}),(0,S.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-3 text-[11px] text-muted-foreground`,children:[(0,S.jsxs)(`span`,{children:[e.variables.length,` variable`,e.variables.length===1?``:`s`]}),(0,S.jsxs)(`span`,{children:[`Updated `,f(V,e.updatedAt)]})]})]})})},e.slug)})]}),(0,S.jsx)(`div`,{className:`min-w-0`,children:J?(0,S.jsxs)(b,{children:[(0,S.jsxs)(v,{className:`border-b border-border`,children:[(0,S.jsxs)(ee,{className:`flex flex-wrap items-center gap-2`,children:[(0,S.jsx)(`span`,{children:J.title}),J.template!==J.defaultTemplate&&(0,S.jsx)(p,{className:`bg-amber-500/15 text-amber-300 hover:bg-amber-500/15`,children:`Customized`}),X&&(0,S.jsx)(p,{variant:`outline`,children:`Unsaved`})]}),(0,S.jsxs)(_,{className:`space-y-1`,children:[(0,S.jsx)(`div`,{className:`font-mono text-[11px]`,children:J.slug}),J.description&&(0,S.jsx)(`div`,{children:J.description})]})]}),(0,S.jsxs)(y,{className:`space-y-4 pt-4`,children:[k&&(0,S.jsxs)(`div`,{className:`flex items-start gap-2 rounded-md border border-destructive/40 bg-destructive/10 p-2 text-xs text-destructive`,children:[(0,S.jsx)(l,{className:`mt-0.5 size-3.5`}),(0,S.jsx)(`span`,{children:k})]}),j&&(0,S.jsx)(`div`,{className:`rounded-md border border-emerald-500/30 bg-emerald-500/10 px-3 py-2 text-xs text-emerald-300`,children:j}),(0,S.jsxs)(`div`,{className:`space-y-2`,children:[(0,S.jsxs)(`div`,{className:`flex items-center gap-2 text-xs font-medium text-muted-foreground`,children:[(0,S.jsx)(r,{className:`size-3.5`}),`Available variables`]}),J.variables.length>0?(0,S.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:J.variables.map(e=>(0,S.jsx)(p,{variant:`secondary`,className:`font-mono text-[11px]`,children:`{{${e}}}`},e))}):(0,S.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`This template has no placeholder variables.`})]}),J.template!==J.defaultTemplate&&(0,S.jsx)(`div`,{className:`rounded-lg border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-xs text-amber-200`,children:`This template differs from the built-in default. Reset will restore the original text.`}),(0,S.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,S.jsx)(`label`,{htmlFor:`prompt-template-editor`,className:`text-xs font-medium text-muted-foreground`,children:`Template text`}),(0,S.jsx)(h,{id:`prompt-template-editor`,value:Y,onChange:e=>{let t=e.target.value;R(e=>({...e,[J.slug]:t})),k&&A(``),j&&M(``)},rows:18,spellCheck:!1,className:`min-h-[360px] resize-y font-mono text-xs leading-5`})]})]}),(0,S.jsxs)(g,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,S.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:X?`Editing local changes.`:`Updated ${f(V,J.updatedAt)}.`}),(0,S.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[J.template!==J.defaultTemplate&&(0,S.jsxs)(m,{variant:`outline`,size:`sm`,onClick:()=>void re(),disabled:Q,children:[(0,S.jsx)(i,{className:`size-4`}),`Reset to default`]}),(0,S.jsx)(m,{variant:`outline`,size:`sm`,onClick:ie,disabled:!X||Q,children:`Cancel`}),(0,S.jsxs)(m,{size:`sm`,onClick:()=>void ne(),disabled:!X||Q,children:[(0,S.jsx)(t,{className:`size-4`}),`Save`]})]})]})]}):(0,S.jsx)(b,{size:`sm`,children:(0,S.jsx)(y,{className:`text-sm text-muted-foreground`,children:`Select a prompt template to edit it.`})})})]})]})}export{E as PromptSettingsView};
2
- //# sourceMappingURL=prompt-settings-YhAOlYc6.js.map
@@ -1,2 +0,0 @@
1
- import{r as e}from"./chunk-CilyBKbf.js";import{B as t,H as n,I as r,Qn as i,Qt as a,Y as o,Zn as s,_n as c,mn as l,on as u,ur as d}from"./lucide-react-C4eXYCwx.js";import{a as f,c as p,l as m}from"./types-BiJFuTiL.js";import{t as h}from"./badge-D8fABzMs.js";import{t as g}from"./button-KASZcscA.js";import{t as _}from"./input-CtHfLn1i.js";import{n as v,z as y}from"./index-DlBSuzd2.js";import{o as b,r as x,s as S,t as C}from"./card-Cds0MWME.js";var w=e(d(),1),T=s(),E=[{value:`all`,label:`All`},{value:`skill`,label:`Skills`},{value:`plugin`,label:`Plugins`},{value:`mcp`,label:`MCP`}],D=[`any`,...p()];function O(e){return e===`skill`?`bg-blue-500/10 text-blue-400 border-blue-500/30`:e===`plugin`?`bg-violet-500/10 text-violet-400 border-violet-500/30`:`bg-emerald-500/10 text-emerald-400 border-emerald-500/30`}function k(e){return e===`any`?`bg-zinc-500/10 text-zinc-400 border-zinc-500/30`:m(e)}function A(e){return e===`approved`?`bg-emerald-500/10 text-emerald-400 border-emerald-500/30`:e===`rejected`?`bg-red-500/10 text-red-400 border-red-500/30`:`bg-yellow-500/10 text-yellow-400 border-yellow-500/30`}function j({status:e}){return e===`valid`?(0,T.jsx)(l,{className:`h-3.5 w-3.5 text-emerald-400`}):e===`invalid`?(0,T.jsx)(c,{className:`h-3.5 w-3.5 text-red-400`}):(0,T.jsx)(u,{className:`h-3.5 w-3.5 text-zinc-400`})}var M={kind:`skill`,slug:``,title:``},N={githubUrl:``,ref:`main`,subpath:``,provider:`any`,versionConstraint:``},P={command:``,args:``,url:``,approvalStatus:`pending`,versionConstraint:``};function F({variant:e,onToggle:t,onUpdate:r,onValidate:i,busy:o}){let s=o===e.id;return(0,T.jsxs)(`div`,{className:`rounded-md border border-border bg-card/60 p-3 space-y-2`,children:[(0,T.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,T.jsx)(h,{variant:`outline`,className:`text-[10px] ${k(e.provider)}`,children:e.provider}),(0,T.jsx)(`span`,{className:`text-xs font-medium font-mono`,children:e.name}),e.approvalStatus&&(0,T.jsx)(h,{variant:`outline`,className:`text-[10px] ${A(e.approvalStatus)}`,children:e.approvalStatus}),(0,T.jsxs)(`span`,{className:`text-[10px] text-muted-foreground flex items-center gap-1 ml-auto`,children:[(0,T.jsx)(j,{status:e.validationStatus}),e.validationStatus??`unvalidated`]}),(0,T.jsx)(y,{size:`sm`,checked:e.enabled,disabled:s,onCheckedChange:n=>t(e.id,n)})]}),(e.sourceUrl||e.sourceRef)&&(0,T.jsxs)(`div`,{className:`text-[10px] text-muted-foreground font-mono truncate`,title:e.sourceUrl,children:[e.sourceUrl,e.sourceRef?`@${e.resolvedRef??e.sourceRef}`:``,e.sourceSubpath?` · ${e.sourceSubpath}`:``]}),(0,T.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,T.jsxs)(g,{variant:`outline`,size:`sm`,className:`h-6 text-xs`,disabled:s||!e.sourceRef,onClick:()=>r(e.id),title:`Pull latest from source ref`,children:[(0,T.jsx)(a,{className:`h-3 w-3 mr-1`}),`Update ref`]}),(0,T.jsxs)(g,{variant:`outline`,size:`sm`,className:`h-6 text-xs`,disabled:s,onClick:()=>i(e.id),children:[(0,T.jsx)(n,{className:`h-3 w-3 mr-1`}),`Validate`]})]})]})}function I({form:e,onChange:t,onSubmit:n,onCancel:r,busy:i,error:a}){return(0,T.jsxs)(`div`,{className:`rounded-md border border-border bg-card/60 p-3 space-y-3`,children:[(0,T.jsx)(`div`,{className:`text-sm font-medium`,children:`New Capability`}),a&&(0,T.jsx)(`div`,{className:`text-xs text-destructive`,children:a}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(v,{className:`text-xs`,children:`Kind`}),(0,T.jsxs)(`select`,{className:`mt-1 w-full rounded-md border border-input bg-background px-2 py-1.5 text-sm`,value:e.kind,onChange:e=>t({kind:e.target.value}),children:[(0,T.jsx)(`option`,{value:`skill`,children:`Skill`}),(0,T.jsx)(`option`,{value:`plugin`,children:`Plugin`}),(0,T.jsx)(`option`,{value:`mcp`,children:`MCP Server`})]})]}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(v,{className:`text-xs`,children:`Slug`}),(0,T.jsx)(_,{value:e.slug,onChange:e=>t({slug:e.target.value}),placeholder:`my-capability`,className:`mt-1 text-sm font-mono`})]}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(v,{className:`text-xs`,children:`Title (optional)`}),(0,T.jsx)(_,{value:e.title,onChange:e=>t({title:e.target.value}),placeholder:`My Capability`,className:`mt-1 text-sm`})]}),(0,T.jsxs)(`div`,{className:`flex gap-2`,children:[(0,T.jsx)(g,{size:`sm`,onClick:n,disabled:i||!e.slug.trim(),children:i?`Creating…`:`Create`}),(0,T.jsx)(g,{size:`sm`,variant:`outline`,onClick:r,children:`Cancel`})]})]})}function L({form:e,onChange:t,onSubmit:n,onCancel:r,busy:i,error:a}){return(0,T.jsxs)(`div`,{className:`rounded-md border border-border bg-card/60 p-3 space-y-3`,children:[(0,T.jsx)(`div`,{className:`text-sm font-medium`,children:`Import from GitHub`}),a&&(0,T.jsx)(`div`,{className:`text-xs text-destructive`,children:a}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(v,{className:`text-xs`,children:`GitHub URL`}),(0,T.jsx)(_,{value:e.githubUrl,onChange:e=>t({githubUrl:e.target.value}),placeholder:`https://github.com/owner/repo`,className:`mt-1 text-sm font-mono`})]}),(0,T.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,T.jsxs)(`div`,{children:[(0,T.jsx)(v,{className:`text-xs`,children:`Ref`}),(0,T.jsx)(_,{value:e.ref,onChange:e=>t({ref:e.target.value}),placeholder:`main`,className:`mt-1 text-sm font-mono`})]}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(v,{className:`text-xs`,children:`Subpath (optional)`}),(0,T.jsx)(_,{value:e.subpath,onChange:e=>t({subpath:e.target.value}),placeholder:`skills/my-skill`,className:`mt-1 text-sm font-mono`})]})]}),(0,T.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,T.jsxs)(`div`,{children:[(0,T.jsx)(v,{className:`text-xs`,children:`Provider`}),(0,T.jsx)(`select`,{className:`mt-1 w-full rounded-md border border-input bg-background px-2 py-1.5 text-sm`,value:e.provider,onChange:e=>t({provider:e.target.value}),children:D.map(e=>(0,T.jsx)(`option`,{value:e,children:e},e))})]}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(v,{className:`text-xs`,children:`Version constraint (optional)`}),(0,T.jsx)(_,{value:e.versionConstraint,onChange:e=>t({versionConstraint:e.target.value}),placeholder:`>=1.0.0`,className:`mt-1 text-sm font-mono`})]})]}),(0,T.jsxs)(`div`,{className:`flex gap-2`,children:[(0,T.jsx)(g,{size:`sm`,onClick:n,disabled:i||!e.githubUrl.trim()||!e.ref.trim(),children:i?`Importing…`:`Import`}),(0,T.jsx)(g,{size:`sm`,variant:`outline`,onClick:r,children:`Cancel`})]})]})}function R({form:e,onChange:t,onSubmit:n,onCancel:r,busy:i,error:a}){return(0,T.jsxs)(`div`,{className:`rounded-md border border-border bg-card/60 p-3 space-y-3`,children:[(0,T.jsx)(`div`,{className:`text-sm font-medium`,children:`Add MCP Server Variant`}),a&&(0,T.jsx)(`div`,{className:`text-xs text-destructive`,children:a}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(v,{className:`text-xs`,children:`Command (for stdio type)`}),(0,T.jsx)(_,{value:e.command,onChange:e=>t({command:e.target.value}),placeholder:`npx -y @modelcontextprotocol/server-foo`,className:`mt-1 text-sm font-mono`})]}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(v,{className:`text-xs`,children:`Args (space-separated, overrides command split)`}),(0,T.jsx)(_,{value:e.args,onChange:e=>t({args:e.target.value}),placeholder:`--port 3000`,className:`mt-1 text-sm font-mono`})]}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(v,{className:`text-xs`,children:`URL (for http/sse type)`}),(0,T.jsx)(_,{value:e.url,onChange:e=>t({url:e.target.value}),placeholder:`http://localhost:3000/mcp`,className:`mt-1 text-sm font-mono`})]}),(0,T.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,T.jsxs)(`div`,{children:[(0,T.jsx)(v,{className:`text-xs`,children:`Approval status`}),(0,T.jsxs)(`select`,{className:`mt-1 w-full rounded-md border border-input bg-background px-2 py-1.5 text-sm`,value:e.approvalStatus,onChange:e=>t({approvalStatus:e.target.value}),children:[(0,T.jsx)(`option`,{value:`pending`,children:`Pending`}),(0,T.jsx)(`option`,{value:`approved`,children:`Approved`})]})]}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(v,{className:`text-xs`,children:`Version constraint (optional)`}),(0,T.jsx)(_,{value:e.versionConstraint,onChange:e=>t({versionConstraint:e.target.value}),placeholder:`>=1.0.0`,className:`mt-1 text-sm font-mono`})]})]}),(0,T.jsxs)(`div`,{className:`flex gap-2`,children:[(0,T.jsx)(g,{size:`sm`,onClick:n,disabled:i||!e.command.trim()&&!e.url.trim(),children:i?`Adding…`:`Add MCP Variant`}),(0,T.jsx)(g,{size:`sm`,variant:`outline`,onClick:r,children:`Cancel`})]})]})}function z(){let[e,n]=(0,w.useState)([]),[a,s]=(0,w.useState)(`all`),[c,l]=(0,w.useState)(``),[u,d]=(0,w.useState)(!0),[p,m]=(0,w.useState)(null),[_,v]=(0,w.useState)(`none`),[y,D]=(0,w.useState)(!1),[k,A]=(0,w.useState)(null),[j,z]=(0,w.useState)(null),[B,V]=(0,w.useState)(M),[H,U]=(0,w.useState)(N),[W,G]=(0,w.useState)(P);async function K(){m(null);try{let e=await i(`GET`,`/provisioning/capabilities${a===`all`?``:`?kind=${a}`}`);n(e.capabilities),!c&&e.capabilities.length>0&&l(e.capabilities[0].capability.id)}catch(e){m(f(e))}finally{d(!1)}}(0,w.useEffect)(()=>{d(!0),K()},[a]);let q=e.find(e=>e.capability.id===c)??null;function J(e){v(e),A(null),D(!1),V(M),U(N),G(P)}async function Y(){D(!0),A(null);try{await i(`POST`,`/provisioning/capabilities`,{kind:B.kind,slug:B.slug.trim(),title:B.title.trim()||void 0}),v(`none`),await K()}catch(e){A(f(e))}finally{D(!1)}}async function X(){if(q){D(!0),A(null);try{await i(`POST`,`/provisioning/capabilities/${encodeURIComponent(q.capability.id)}/variants/import`,{githubUrl:H.githubUrl.trim(),ref:H.ref.trim(),subpath:H.subpath.trim()||void 0,provider:H.provider,versionConstraint:H.versionConstraint.trim()||void 0}),v(`none`),await K()}catch(e){A(f(e))}finally{D(!1)}}}async function Z(){if(q){D(!0),A(null);try{let e={};if(W.url.trim())e.type=`http`,e.url=W.url.trim();else{e.type=`stdio`;let t=W.command.trim().split(/\s+/);e.command=t[0];let n=W.args.trim()?W.args.trim().split(/\s+/):t.slice(1);n.length>0&&(e.args=n)}await i(`POST`,`/provisioning/capabilities/${encodeURIComponent(q.capability.id)}/variants/mcp`,{server:e,approvalStatus:W.approvalStatus,versionConstraint:W.versionConstraint.trim()||void 0}),v(`none`),await K()}catch(e){A(f(e))}finally{D(!1)}}}async function Q(e,t){z(e);try{await i(`PATCH`,`/provisioning/variants/${encodeURIComponent(e)}`,{enabled:t}),n(n=>n.map(n=>({...n,variants:n.variants.map(n=>n.id===e?{...n,enabled:t}:n)})))}catch(e){m(f(e))}finally{z(null)}}async function ee(e){let t=q?.variants.find(t=>t.id===e);if(t?.sourceRef){z(e);try{await i(`POST`,`/provisioning/variants/${encodeURIComponent(e)}/update`,{ref:t.sourceRef,subpath:t.sourceSubpath}),await K()}catch(e){m(f(e))}finally{z(null)}}}async function te(e){z(e);try{await i(`POST`,`/provisioning/variants/${encodeURIComponent(e)}/validate`,{}),await K()}catch(e){m(f(e))}finally{z(null)}}let $=q?.capability;return(0,T.jsxs)(`div`,{className:`space-y-4 p-4`,children:[(0,T.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,T.jsx)(o,{className:`size-5 text-primary`}),(0,T.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Registry`}),(0,T.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`provisioning capability registry · #561`}),(0,T.jsxs)(`div`,{className:`ml-auto flex items-center gap-2`,children:[E.map(e=>(0,T.jsx)(`button`,{type:`button`,onClick:()=>s(e.value),className:`rounded-md border px-2.5 py-1 text-xs transition-colors ${a===e.value?`border-primary/40 bg-primary/10 text-primary`:`border-border text-muted-foreground hover:bg-accent`}`,children:e.label},e.value)),(0,T.jsx)(g,{variant:`outline`,size:`sm`,onClick:()=>void K(),children:(0,T.jsx)(r,{className:`size-4`})})]})]}),p&&(0,T.jsx)(`div`,{className:`rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-sm text-destructive`,children:p}),(0,T.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 xl:grid-cols-[300px_1fr]`,children:[(0,T.jsxs)(`div`,{className:`space-y-2`,children:[(0,T.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,T.jsxs)(`span`,{className:`text-xs text-muted-foreground font-medium`,children:[e.length,` capabilities`]}),(0,T.jsxs)(g,{size:`sm`,variant:`outline`,className:`h-7 text-xs gap-1`,onClick:()=>J(`new-capability`),children:[(0,T.jsx)(t,{className:`h-3 w-3`}),`New`]})]}),_===`new-capability`&&(0,T.jsx)(I,{form:B,onChange:e=>V(t=>({...t,...e})),onSubmit:()=>void Y(),onCancel:()=>v(`none`),busy:y,error:k}),u&&e.length===0&&(0,T.jsx)(`div`,{className:`py-8 text-center text-sm text-muted-foreground`,children:`Loading…`}),!u&&e.length===0&&(0,T.jsx)(C,{children:(0,T.jsx)(x,{className:`py-10 text-center text-sm text-muted-foreground`,children:`No capabilities yet. Click New to create one.`})}),e.map(({capability:e,variants:t})=>(0,T.jsxs)(`button`,{type:`button`,onClick:()=>{l(e.id),v(`none`)},className:`w-full rounded-md border p-3 text-left transition-colors ${c===e.id?`border-primary/50 bg-primary/5`:`border-border bg-card/60 hover:bg-accent`}`,children:[(0,T.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,T.jsx)(h,{variant:`outline`,className:`text-[10px] ${O(e.kind)}`,children:e.kind}),(0,T.jsx)(`span`,{className:`text-xs font-medium font-mono truncate flex-1`,children:e.slug}),(0,T.jsxs)(`span`,{className:`text-[10px] text-muted-foreground shrink-0`,children:[t.length,`v`]})]}),e.title&&(0,T.jsx)(`div`,{className:`mt-1 text-xs text-muted-foreground truncate`,children:e.title}),(0,T.jsxs)(`div`,{className:`mt-1 flex items-center gap-1.5`,children:[(0,T.jsx)(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full ${e.status===`active`?`bg-emerald-500`:`bg-zinc-500`}`}),(0,T.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:e.status})]})]},e.id))]}),$?(0,T.jsxs)(`div`,{className:`space-y-3`,children:[(0,T.jsxs)(C,{children:[(0,T.jsx)(b,{children:(0,T.jsxs)(S,{className:`flex flex-wrap items-center gap-2`,children:[(0,T.jsx)(h,{variant:`outline`,className:O($.kind),children:$.kind}),(0,T.jsx)(`span`,{className:`font-mono text-base`,children:$.slug}),$.title&&(0,T.jsxs)(`span`,{className:`text-sm font-normal text-muted-foreground`,children:[`· `,$.title]}),(0,T.jsx)(h,{variant:$.status===`active`?`secondary`:`outline`,className:`ml-auto text-[10px]`,children:$.status})]})}),$.description&&(0,T.jsx)(x,{className:`pt-0 text-sm text-muted-foreground`,children:$.description})]}),(0,T.jsxs)(C,{children:[(0,T.jsx)(b,{children:(0,T.jsxs)(S,{className:`flex items-center gap-2 text-base`,children:[`Variants`,(0,T.jsxs)(`span`,{className:`text-xs font-normal text-muted-foreground`,children:[`(`,q?.variants.length??0,`)`]}),(0,T.jsxs)(`div`,{className:`ml-auto flex items-center gap-2`,children:[(0,T.jsxs)(g,{size:`sm`,variant:`outline`,className:`h-7 text-xs gap-1`,onClick:()=>J(_===`import-github`?`none`:`import-github`),children:[(0,T.jsx)(t,{className:`h-3 w-3`}),`GitHub`]}),$.kind===`mcp`&&(0,T.jsxs)(g,{size:`sm`,variant:`outline`,className:`h-7 text-xs gap-1`,onClick:()=>J(_===`import-mcp`?`none`:`import-mcp`),children:[(0,T.jsx)(t,{className:`h-3 w-3`}),`MCP Server`]})]})]})}),(0,T.jsxs)(x,{className:`space-y-3`,children:[_===`import-github`&&(0,T.jsx)(L,{form:H,onChange:e=>U(t=>({...t,...e})),onSubmit:()=>void X(),onCancel:()=>v(`none`),busy:y,error:k}),_===`import-mcp`&&(0,T.jsx)(R,{form:W,onChange:e=>G(t=>({...t,...e})),onSubmit:()=>void Z(),onCancel:()=>v(`none`),busy:y,error:k}),q&&q.variants.length===0&&_===`none`&&(0,T.jsxs)(`div`,{className:`py-6 text-center text-sm text-muted-foreground`,children:[`No variants yet. Add one via GitHub import`,$.kind===`mcp`?` or MCP Server`:``,`.`]}),q?.variants.map(e=>(0,T.jsx)(F,{variant:e,onToggle:(e,t)=>void Q(e,t),onUpdate:e=>void ee(e),onValidate:e=>void te(e),busy:j},e.id))]})]})]}):!u&&(0,T.jsx)(C,{children:(0,T.jsx)(x,{className:`py-16 text-center text-sm text-muted-foreground`,children:`Select a capability to view details and variants.`})})]})]})}export{z as RegistryView};
2
- //# sourceMappingURL=registry-DZoAfrzx.js.map
@@ -1,6 +0,0 @@
1
- import{r as e}from"./chunk-CilyBKbf.js";import{A as t,An as n,B as r,Bn as i,D as a,En as o,Gn as s,I as c,Kt as l,Qn as u,S as d,W as f,Yn as p,Z as m,Zn as h,Zt as g,_n as _,c as v,ft as y,h as b,hn as x,j as S,jt as C,nr as w,p as T,qt as E,ur as D,xn as ee,yn as te}from"./lucide-react-C4eXYCwx.js";import{g as O,m as k,t as A,u as ne}from"./store-Bnag1kY-.js";import{c as re,o as ie,r as ae,u as j}from"./types-BiJFuTiL.js";import{t as oe}from"./themes-DjSwmAZN.js";import{a as M,i as N,n as P,r as F,t as I}from"./select-ZOpLw2Fd.js";import{t as L}from"./badge-D8fABzMs.js";import{t as R}from"./button-KASZcscA.js";import{t as z}from"./input-CtHfLn1i.js";import{r as se,z as B}from"./index-DlBSuzd2.js";import{i as V,n as ce,o as H,r as U,s as W,t as G}from"./card-Cds0MWME.js";import{t as le}from"./user-avatar-BYGrUx1U.js";var K=e(D(),1);function q(e){return`${e.namespace}/${e.key}`}function ue(e){return`/settings/${encodeURIComponent(e.namespace)}/${encodeURIComponent(e.key)}`}function de(e){return e.trim().toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``)||`settings`}function fe(e){let t=new Map;for(let n of e.filter(e=>e.readable)){let e=n.display?.group?.trim()||n.namespace;t.set(e,[...t.get(e)??[],n])}return[...t.entries()].map(([e,t])=>({group:e,slug:de(e),settings:t.sort(pe)})).sort((e,t)=>me(e.settings)-me(t.settings)||e.group.localeCompare(t.group))}function pe(e,t){return(e.display?.order??2**53-1)-(t.display?.order??2**53-1)||e.display?.label?.localeCompare(t.display?.label??``)||q(e).localeCompare(q(t))}function me(e){return Math.min(...e.map(e=>e.display?.order??2**53-1))}function he(e){return Array.isArray(e.type)?e.type.find(e=>e!==`null`):e.type}function ge(e,t,n){if(!t.length)return n;let[r,...i]=t;if(r===void 0)return n;if(typeof r==`number`){let t=Array.isArray(e)?[...e]:[];return t[r]=ge(t[r],i,n),t}let a=ie(e)?{...e}:{},o=ge(a[r],i,n);return o===void 0?delete a[r]:a[r]=o,a}function _e(e){if(e.default!==void 0)return e.default;if(e.const!==void 0)return e.const;if(e.enum?.length)return e.enum[0];switch(he(e)){case`boolean`:return!1;case`integer`:case`number`:return 0;case`array`:return[];case`object`:return{};case`string`:return``;default:return}}function ve(e){return e.split(/\r?\n|,/).map(e=>e.trim()).filter(Boolean)}function ye(e){return Array.isArray(e)?e.map(e=>String(e)).join(`
2
- `):``}function be(e){return ie(e)?Object.entries(e).map(([e,t])=>`${e}=${String(t??``)}`).join(`
3
- `):``}function xe(e){return Object.fromEntries(e.split(/\r?\n/).map(e=>e.trim()).filter(Boolean).map(e=>{let t=e.indexOf(`=`);return t>=0?[e.slice(0,t).trim(),e.slice(t+1)]:[e,``]}))}var J=h(),Se=`__unset__`;function Ce(e){return e===`server-runtime`?`Server runtime`:e===`bootstrap`?`Bootstrap`:`Browser`}function we(e){return e===`server-runtime`?`Stored by Relay and mutable while the server is running.`:e===`bootstrap`?`Read from startup configuration; restart or host config changes are required.`:`Stored only in this browser profile.`}function Te(e){return e===`browser`?(0,J.jsx)(m,{className:`size-3.5`}):(0,J.jsx)(a,{className:`size-3.5`})}function Ee(e){return e.details??[]}function De({group:e,settings:t,onSaved:n}){let r=[...new Set(t.map(e=>e.tier))];return(0,J.jsxs)(`section`,{className:`space-y-3`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,J.jsx)(`h2`,{className:`text-base font-semibold`,children:e}),(0,J.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:r.map(e=>(0,J.jsxs)(L,{variant:`outline`,className:`gap-1`,title:we(e),children:[Te(e),Ce(e)]},e))})]}),t.length===0?(0,J.jsx)(G,{size:`sm`,children:(0,J.jsx)(U,{className:`text-sm text-muted-foreground`,children:`No settings in this group.`})}):(0,J.jsx)(`div`,{className:`space-y-3`,children:t.map(e=>(0,J.jsx)(Oe,{setting:e,onSaved:n},q(e)))})]})}function Oe({setting:e,onSaved:n}){let[r,i]=(0,K.useState)(()=>e.value??e.defaults??_e(e.schema)),[a,o]=(0,K.useState)(!1),[s,c]=(0,K.useState)(``),[l,d]=(0,K.useState)([]),f=e.writable&&e.tier===`server-runtime`;function p(e,t){i(n=>ge(n,e,t)),d([]),c(``)}async function m(){if(f){o(!0),d([]),c(``);try{let t=await u(`PUT`,ue(e),{value:r,updatedBy:`dashboard`});i(t.value),n(t),c(`Saved`)}catch(e){let t=Ee(e);d(t.length?t:[e.message])}finally{o(!1)}}}return(0,J.jsxs)(G,{size:`sm`,children:[(0,J.jsxs)(H,{children:[(0,J.jsxs)(W,{className:`flex flex-wrap items-center gap-2 text-sm`,children:[e.display.label,(0,J.jsxs)(L,{variant:`outline`,className:`gap-1`,title:we(e.tier),children:[Te(e.tier),Ce(e.tier)]}),!e.writable&&(0,J.jsx)(L,{variant:`secondary`,children:`Read only`})]}),e.display.description&&(0,J.jsx)(V,{children:e.display.description}),(0,J.jsx)(ce,{children:(0,J.jsxs)(R,{size:`sm`,onClick:m,disabled:!f||a,children:[(0,J.jsx)(t,{className:`size-4`}),a?`Saving`:`Save`]})})]}),(0,J.jsxs)(U,{className:`space-y-3`,children:[(0,J.jsx)(ke,{schema:e.schema,value:r,path:[],label:e.display.label,required:!0,disabled:!f||a,onChange:p}),(0,J.jsxs)(`p`,{className:`flex flex-wrap items-center gap-x-2 text-[11px] text-muted-foreground`,children:[(0,J.jsxs)(`code`,{className:`rounded bg-muted px-1.5 py-0.5 font-mono`,children:[e.namespace,`/`,e.key]}),(0,J.jsxs)(`span`,{children:[`read `,(0,J.jsx)(`span`,{className:`text-foreground/70`,children:e.scope.read})]}),(0,J.jsx)(`span`,{"aria-hidden":!0,children:`·`}),(0,J.jsxs)(`span`,{children:[`write `,(0,J.jsx)(`span`,{className:`text-foreground/70`,children:e.scope.write})]})]}),l.length>0&&(0,J.jsxs)(`div`,{className:`rounded-md border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive`,children:[(0,J.jsxs)(`div`,{className:`mb-1 flex items-center gap-2 font-medium`,children:[(0,J.jsx)(_,{className:`size-4`}),`Save failed`]}),(0,J.jsx)(`ul`,{className:`list-disc space-y-1 pl-5`,children:l.map(e=>(0,J.jsx)(`li`,{children:e},e))})]}),s&&(0,J.jsxs)(`p`,{className:`flex items-center gap-1 text-sm text-emerald-500`,children:[(0,J.jsx)(x,{className:`size-4`}),s]})]})]})}function ke(e){let{schema:t,value:n,path:r,label:i,required:a,disabled:o,onChange:s}=e,c=he(t);if(t.enum?.length){let e=n==null||n===``?Se:String(n);return(0,J.jsx)(Y,{label:i,description:t.description,children:(0,J.jsxs)(I,{value:e,onValueChange:e=>s(r,e===`__unset__`?void 0:e),disabled:o,children:[(0,J.jsx)(N,{children:(0,J.jsx)(M,{})}),(0,J.jsxs)(P,{children:[!a&&(0,J.jsx)(F,{value:`__unset__`,children:`Not set`}),t.enum.map(e=>(0,J.jsx)(F,{value:String(e),children:String(e)},String(e)))]})]})})}if(c===`boolean`)return(0,J.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-md border bg-muted/20 p-3`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`div`,{className:`text-sm font-medium`,children:i}),t.description&&(0,J.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:t.description})]}),(0,J.jsx)(B,{checked:!!n,onCheckedChange:e=>s(r,e),disabled:o})]});if(c===`integer`||c===`number`)return(0,J.jsx)(Y,{label:i,description:t.description,children:(0,J.jsx)(z,{type:`number`,min:typeof t.minimum==`number`?t.minimum:void 0,max:typeof t.maximum==`number`?t.maximum:void 0,step:c===`integer`?1:`any`,value:typeof n==`number`?n:``,disabled:o,onChange:e=>s(r,e.target.value===``&&!a?void 0:Number(e.target.value))})});if(c===`array`)return(0,J.jsx)(Y,{label:i,description:t.description??`One item per line.`,children:(0,J.jsx)(se,{rows:Math.min(8,Math.max(3,Array.isArray(n)?n.length+1:3)),value:ye(n),disabled:o,onChange:e=>s(r,ve(e.target.value))})});if(c===`object`){let e=t.properties??{},a=new Set(t.required??[]);return Object.keys(e).length===0&&t.additionalProperties?(0,J.jsx)(Y,{label:i,description:t.description??`KEY=value, one entry per line.`,children:(0,J.jsx)(se,{rows:5,value:be(n),disabled:o,onChange:e=>s(r,xe(e.target.value))})}):(0,J.jsxs)(`div`,{className:`space-y-3`,children:[r.length>0&&(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`div`,{className:`text-sm font-medium`,children:i}),t.description&&(0,J.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:t.description})]}),(0,J.jsx)(`div`,{className:`grid gap-3 md:grid-cols-2`,children:Object.entries(e).map(([e,t])=>{let i=ie(n)?n[e]:void 0;return(0,J.jsx)(ke,{schema:t,value:i===void 0&&a.has(e)?_e(t):i,path:[...r,e],label:t.title||Ae(e),required:a.has(e),disabled:o,onChange:s},e)})})]})}return(0,J.jsx)(Y,{label:i,description:t.description,children:(0,J.jsx)(z,{value:typeof n==`string`?n:n==null?``:String(n),disabled:o,onChange:e=>s(r,e.target.value===``&&!a?void 0:e.target.value)})})}function Y({label:e,description:t,children:n}){return(0,J.jsxs)(`label`,{className:`block space-y-1.5 text-sm`,children:[(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:e}),n,t&&(0,J.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:t})]})}function Ae(e){return e.replace(/([a-z0-9])([A-Z])/g,`$1 $2`).replace(/[-_]+/g,` `).replace(/^\w/,e=>e.toUpperCase())}function je(){let e=A(e=>e.theme),t=A(e=>e.showReasoning),r=A(e=>e.set);return(0,J.jsxs)(`section`,{className:`space-y-4`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`h2`,{className:`text-base font-semibold`,children:`Browser preferences`}),(0,J.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`These are stored in local dashboard state, not in Relay server config.`})]}),(0,J.jsxs)(G,{size:`sm`,children:[(0,J.jsxs)(H,{children:[(0,J.jsx)(W,{className:`text-sm`,children:`Dashboard display`}),(0,J.jsx)(V,{className:`text-xs`,children:`Browser tier · persisted in this browser profile.`}),(0,J.jsx)(ce,{children:(0,J.jsxs)(L,{variant:`outline`,className:`gap-1`,children:[(0,J.jsx)(m,{className:`size-3.5`}),`Browser`]})})]}),(0,J.jsxs)(U,{className:`grid gap-3 md:grid-cols-2`,children:[(0,J.jsx)(Y,{label:`Theme`,children:(0,J.jsxs)(I,{value:e,onValueChange:e=>r({theme:e}),children:[(0,J.jsx)(N,{children:(0,J.jsx)(M,{})}),(0,J.jsx)(P,{children:oe.map(e=>(0,J.jsx)(F,{value:e.id,children:e.label},e.id))})]})}),(0,J.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-md border bg-muted/20 p-3`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(n,{className:`size-4`}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`div`,{className:`text-sm font-medium`,children:`Show reasoning details`}),(0,J.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`Display captured reasoning/tool steps in chat. Server capture is controlled separately by provider reasoningCapture.`})]})]}),(0,J.jsx)(B,{checked:t,onCheckedChange:e=>r({showReasoning:e})})]})]})]}),(0,J.jsx)(Me,{})]})}function Me(){let e=A(e=>e.voiceTtsEnabled),t=A(e=>e.setVoiceTtsEnabled),n=A(e=>e.voiceTtsMode),r=A(e=>e.setVoiceTtsMode),i=A(e=>e.voiceTtsKokoroVoice),a=A(e=>e.setVoiceTtsKokoroVoice),o=A(e=>e.voiceTtsBrowserVoice),s=A(e=>e.setVoiceTtsBrowserVoice),c=A(e=>e.voiceInputMode),l=A(e=>e.setVoiceInputMode),[u,d]=(0,K.useState)(()=>O());(0,K.useEffect)(()=>{if(typeof window>`u`||!(`speechSynthesis`in window))return;let e=()=>d(O());return e(),window.speechSynthesis.addEventListener?.(`voiceschanged`,e),()=>window.speechSynthesis.removeEventListener?.(`voiceschanged`,e)},[]);let f=k.some(e=>e.id===i)?k:[...k,{id:i,label:i}];return(0,J.jsxs)(G,{size:`sm`,children:[(0,J.jsxs)(H,{children:[(0,J.jsxs)(W,{className:`flex items-center gap-2 text-sm`,children:[(0,J.jsx)(v,{className:`size-4`}),`Voice`]}),(0,J.jsx)(V,{className:`text-xs`,children:`Browser tier TTS and push-to-talk behavior.`}),(0,J.jsx)(ce,{children:(0,J.jsx)(B,{checked:e,onCheckedChange:t})})]}),(0,J.jsxs)(U,{className:`grid gap-3 md:grid-cols-2`,children:[(0,J.jsx)(Y,{label:`Speech engine`,children:(0,J.jsxs)(I,{value:n,onValueChange:e=>r(e),children:[(0,J.jsx)(N,{children:(0,J.jsx)(M,{})}),(0,J.jsxs)(P,{children:[(0,J.jsx)(F,{value:`kokoro`,children:`Kokoro (server, fallback to browser)`}),(0,J.jsx)(F,{value:`browser`,children:`Browser Web Speech API`})]})]})}),(0,J.jsx)(Y,{label:`Kokoro voice`,children:(0,J.jsxs)(I,{value:i,onValueChange:a,children:[(0,J.jsx)(N,{children:(0,J.jsx)(M,{})}),(0,J.jsx)(P,{children:f.map(e=>(0,J.jsx)(F,{value:e.id,children:e.label},e.id))})]})}),(0,J.jsx)(Y,{label:`Browser voice`,children:(0,J.jsxs)(I,{value:o||`__unset__`,onValueChange:e=>s(e===`__unset__`?``:e),children:[(0,J.jsx)(N,{children:(0,J.jsx)(M,{})}),(0,J.jsxs)(P,{children:[(0,J.jsx)(F,{value:Se,children:`System default`}),u.map(e=>(0,J.jsx)(F,{value:e.uri,children:e.label},e.uri))]})]})}),(0,J.jsx)(Y,{label:`Push-to-talk input`,children:(0,J.jsxs)(I,{value:c,onValueChange:e=>l(e),children:[(0,J.jsx)(N,{children:(0,J.jsx)(M,{})}),(0,J.jsxs)(P,{children:[(0,J.jsx)(F,{value:`compose`,children:`Fill message box`}),(0,J.jsx)(F,{value:`autosend`,children:`Send immediately`})]})]})})]})]})}function Ne({catalog:e,error:t,canWrite:n,onCatalog:i}){let o=e[0]?.provider??``,[s,c]=(0,K.useState)(o),[p,m]=(0,K.useState)(()=>Pe(o)),[h,g]=(0,K.useState)(``),[_,v]=(0,K.useState)([]),y=e.some(e=>e.provider===s)?s:o,S=e.find(e=>e.provider===y)??e[0],C=e.map(e=>e.provider);function w(e){m(t=>({...t,...e})),v([]),g(``)}function T(e){c(e),m(Pe(e)),v([]),g(``)}async function D(){i((await u(`GET`,`/providers`)).catalog)}async function ee(){if(n){v([]),g(``);try{await u(`PUT`,`/providers/${encodeURIComponent(p.provider)}/models/${encodeURIComponent(p.alias)}`,{label:p.label,providerModel:p.providerModel,efforts:ve(p.efforts),defaultEffort:p.defaultEffort.trim()||void 0,limits:p.limits,capabilities:p.capabilities,contextThreshold:Fe(p),disabled:p.disabled,updatedBy:`dashboard`}),await D(),g(`${p.alias} saved`),m(Pe(p.provider))}catch(e){let t=Ee(e);v(t.length?t:[e.message])}}}async function te(e,t){if(n){v([]),g(``);try{await u(`PATCH`,`/providers/${encodeURIComponent(y)}/models/${encodeURIComponent(e.alias)}`,{disabled:t,updatedBy:`dashboard`}),await D(),g(`${e.alias} ${t?`disabled`:`enabled`}`)}catch(e){let t=Ee(e);v(t.length?t:[e.message])}}}async function O(e){if(n){v([]),g(``);try{await u(`DELETE`,`/providers/${encodeURIComponent(y)}/models/${encodeURIComponent(e.alias)}`),await D(),g(`${e.alias} removed`)}catch(e){let t=Ee(e);v(t.length?t:[e.message])}}}function k(e){m({provider:y,alias:e.alias,label:e.label,providerModel:e.providerModel,efforts:e.efforts.join(`, `),defaultEffort:e.defaultEffort??``,selfCompactUtilization:e.contextThreshold?.selfCompactUtilization?.toString()??``,warnUtilization:e.contextThreshold?.warnUtilization?.toString()??``,hardBackstopUtilization:e.contextThreshold?.hardBackstopUtilization?.toString()??``,disabled:!!e.disabled,limits:e.limits,capabilities:e.capabilities}),v([]),g(``)}return t?(0,J.jsx)(G,{size:`sm`,children:(0,J.jsxs)(U,{className:`text-sm text-muted-foreground`,children:[(0,J.jsxs)(`div`,{className:`mb-1 flex items-center gap-2 font-medium text-foreground`,children:[(0,J.jsx)(d,{className:`size-4`}),`Model catalog`]}),t]})}):(0,J.jsxs)(`section`,{className:`space-y-4`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`h2`,{className:`text-base font-semibold`,children:`Model catalog`}),(0,J.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Add override models, disable unavailable models, or remove custom entries from the provider catalog.`})]}),!n&&(0,J.jsx)(L,{variant:`secondary`,children:`Read only: needs settings:write:provider`})]}),(0,J.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:C.map(e=>(0,J.jsx)(R,{variant:e===y?`default`:`outline`,size:`sm`,onClick:()=>T(e),children:e},e))}),(0,J.jsxs)(G,{size:`sm`,children:[(0,J.jsxs)(H,{children:[(0,J.jsx)(W,{className:`text-sm`,children:`Add or edit model`}),(0,J.jsx)(ce,{children:(0,J.jsxs)(L,{variant:`outline`,className:`gap-1`,children:[(0,J.jsx)(a,{className:`size-3.5`}),`Server runtime`]})})]}),(0,J.jsxs)(U,{className:`space-y-3`,children:[(0,J.jsxs)(`div`,{className:`grid gap-3 md:grid-cols-2`,children:[(0,J.jsx)(Y,{label:`Alias`,children:(0,J.jsx)(z,{value:p.alias,disabled:!n,placeholder:`nightly`,onChange:e=>w({alias:e.target.value.trim()})})}),(0,J.jsx)(Y,{label:`Label`,children:(0,J.jsx)(z,{value:p.label,disabled:!n,placeholder:`Nightly Codex`,onChange:e=>w({label:e.target.value})})}),(0,J.jsx)(Y,{label:`Provider model`,children:(0,J.jsx)(z,{value:p.providerModel,disabled:!n,placeholder:`codex-nightly`,onChange:e=>w({providerModel:e.target.value})})}),(0,J.jsx)(Y,{label:`Efforts`,children:(0,J.jsx)(z,{value:p.efforts,disabled:!n,placeholder:`low, medium, high`,onChange:e=>w({efforts:e.target.value})})}),(0,J.jsx)(Y,{label:`Default effort`,children:(0,J.jsx)(z,{value:p.defaultEffort,disabled:!n,placeholder:`medium`,onChange:e=>w({defaultEffort:e.target.value})})}),(0,J.jsx)(Y,{label:`Self compact utilization`,children:(0,J.jsx)(z,{value:p.selfCompactUtilization,disabled:!n,placeholder:`0.80`,inputMode:`decimal`,onChange:e=>w({selfCompactUtilization:e.target.value})})}),(0,J.jsx)(Y,{label:`Warn utilization`,children:(0,J.jsx)(z,{value:p.warnUtilization,disabled:!n,placeholder:`default: self - 0.10`,inputMode:`decimal`,onChange:e=>w({warnUtilization:e.target.value})})}),(0,J.jsx)(Y,{label:`Hard backstop utilization`,children:(0,J.jsx)(z,{value:p.hardBackstopUtilization,disabled:!n,placeholder:`0.90`,inputMode:`decimal`,onChange:e=>w({hardBackstopUtilization:e.target.value})})}),(0,J.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-md border bg-muted/20 p-3`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`div`,{className:`text-sm font-medium`,children:`Disabled`}),(0,J.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`Keep visible but unavailable for new launches.`})]}),(0,J.jsx)(B,{checked:p.disabled,disabled:!n,onCheckedChange:e=>w({disabled:e})})]})]}),(0,J.jsxs)(R,{onClick:ee,disabled:!n||!p.alias||!p.label||!p.providerModel,children:[(0,J.jsx)(r,{className:`size-4`}),`Save model`]})]})]}),(0,J.jsxs)(`div`,{className:`space-y-2`,children:[S&&S.models.length===0&&(0,J.jsx)(G,{size:`sm`,children:(0,J.jsx)(U,{className:`text-sm text-muted-foreground`,children:`No models in this provider catalog yet.`})}),S?.models.map(e=>(0,J.jsx)(G,{size:`sm`,children:(0,J.jsxs)(U,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,J.jsxs)(`div`,{className:`min-w-0`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,J.jsx)(`span`,{className:`font-medium`,children:e.label}),(0,J.jsx)(`code`,{className:`rounded bg-muted px-1.5 py-0.5 font-mono text-xs`,children:e.alias}),e.disabled&&(0,J.jsx)(L,{variant:`secondary`,children:`Disabled`})]}),(0,J.jsxs)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:[e.providerModel,e.efforts.length>0?` · efforts ${e.efforts.join(`, `)}`:` · no effort levels`,e.defaultEffort?` · default ${e.defaultEffort}`:``,` · context ${Le(e)}`]})]}),(0,J.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,J.jsxs)(R,{variant:`outline`,size:`sm`,onClick:()=>k(e),children:[(0,J.jsx)(f,{className:`size-4`}),`Edit`]}),(0,J.jsxs)(R,{variant:`outline`,size:`sm`,disabled:!n,onClick:()=>void te(e,!e.disabled),children:[e.disabled?(0,J.jsx)(l,{className:`size-4`}):(0,J.jsx)(E,{className:`size-4`}),e.disabled?`Enable`:`Disable`]}),(0,J.jsxs)(R,{variant:`outline`,size:`sm`,disabled:!n,onClick:()=>void O(e),children:[(0,J.jsx)(b,{className:`size-4`}),`Remove`]})]})]})},e.alias))]}),_.length>0&&(0,J.jsx)(`div`,{className:`rounded-md border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive`,children:(0,J.jsx)(`ul`,{className:`list-disc space-y-1 pl-5`,children:_.map(e=>(0,J.jsx)(`li`,{children:e},e))})}),h&&(0,J.jsxs)(`p`,{className:`flex items-center gap-1 text-sm text-emerald-500`,children:[(0,J.jsx)(x,{className:`size-4`}),h]})]})}function Pe(e){return{provider:e,alias:``,label:``,providerModel:``,efforts:``,defaultEffort:``,selfCompactUtilization:``,warnUtilization:``,hardBackstopUtilization:``,disabled:!1}}function Fe(e){let t=Ie(e.selfCompactUtilization,`Self compact utilization`),n=Ie(e.warnUtilization,`Warn utilization`),r=Ie(e.hardBackstopUtilization,`Hard backstop utilization`);if(!(t===void 0&&n===void 0&&r===void 0)){if(t===void 0)throw Error(`Self compact utilization is required when setting context thresholds`);return{selfCompactUtilization:t,...n===void 0?{}:{warnUtilization:n},...r===void 0?{}:{hardBackstopUtilization:r}}}}function Ie(e,t){let n=e.trim();if(!n)return;let r=Number(n);if(!Number.isFinite(r))throw Error(`${t} must be a number`);return r}function Le(e){if(e.contextThreshold)return`self ${Re(e.contextThreshold.selfCompactUtilization)}, warn ${Re(e.contextThreshold.warnUtilization??Math.max(0,e.contextThreshold.selfCompactUtilization-.1))}`;let t=ne(e.limits?.contextWindowTokens?.value);return`derived self ${Re(t.selfCompactUtilization)}, warn ${Re(t.warnUtilization)}`}function Re(e){return`${Math.round(e*100)}%`}var ze=5,Be=15,Ve={claude:`Claude`,codex:`Codex`};function He(e){return Math.round(e/6e4)}function Ue(e){return`${He(e)} min`}function We({canWrite:e}){let[t,n]=(0,K.useState)(null),[r,i]=(0,K.useState)(``),[a,o]=(0,K.useState)(``),[s,c]=(0,K.useState)(null);(0,K.useEffect)(()=>{let e=!1;return(async()=>{try{let t=await u(`GET`,`/providers/quota-config`);e||n(t)}catch(t){e||i(t.message)}})(),()=>{e=!0}},[]);async function l(e,t){n(n=>({...n??{},[e]:t})),o(``),c(e);try{let r=await u(`PUT`,`/providers/${e}/quota-config`,t);n(t=>({...t??{},[e]:r}))}catch(t){o(`${Ve[e]??e}: ${t.message}`)}finally{c(null)}}let d=t?Object.keys(t).sort():[];return(0,J.jsxs)(`section`,{className:`space-y-4`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`h2`,{className:`text-base font-semibold`,children:`Quota`}),(0,J.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Per-provider quota collection and display. `,(0,J.jsx)(`strong`,{children:`Enabled`}),` governs collection (disabled stops polling — no API calls);`,(0,J.jsx)(`strong`,{children:` Show in widget`}),` governs display only.`]})]}),r&&(0,J.jsxs)(`div`,{className:`flex items-start gap-2 rounded-lg border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive`,children:[(0,J.jsx)(_,{className:`mt-0.5 size-4`}),(0,J.jsx)(`span`,{children:r})]}),a&&(0,J.jsxs)(`div`,{className:`flex items-start gap-2 rounded-lg border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive`,children:[(0,J.jsx)(_,{className:`mt-0.5 size-4`}),(0,J.jsx)(`span`,{children:a})]}),!t&&!r&&(0,J.jsx)(G,{size:`sm`,children:(0,J.jsxs)(U,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,J.jsx)(y,{className:`size-4 animate-spin`}),`Loading quota config…`]})}),d.map(r=>{let i=t[r],a=!e||s===r;return(0,J.jsxs)(G,{size:`sm`,children:[(0,J.jsxs)(H,{children:[(0,J.jsxs)(W,{className:`flex items-center gap-2 text-sm`,children:[(0,J.jsx)(C,{className:`size-4`}),Ve[r]??r,s===r&&(0,J.jsx)(y,{className:`size-3 animate-spin text-muted-foreground`})]}),(0,J.jsxs)(V,{className:`text-xs`,children:[i.enabled?`Polled every ${Ue(i.pollIntervalMs)}`:`Collection disabled`,i.enabled&&!i.showInWidget?` · hidden from widget`:``]})]}),(0,J.jsxs)(U,{className:`space-y-4`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-md border bg-muted/20 p-3`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`div`,{className:`text-sm font-medium`,children:`Enabled`}),(0,J.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`Collect quota for this provider. Off stops all polling (no API calls, no token spend).`})]}),(0,J.jsx)(B,{checked:i.enabled,disabled:a,onCheckedChange:e=>void l(r,{...i,enabled:e})})]}),(0,J.jsxs)(`div`,{className:`rounded-md border bg-muted/20 p-3 space-y-2`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,J.jsx)(`div`,{className:`text-sm font-medium`,children:`Polling interval`}),(0,J.jsx)(L,{variant:`outline`,className:`tabular-nums`,children:Ue(i.pollIntervalMs)})]}),(0,J.jsx)(`input`,{type:`range`,min:ze,max:Be,step:1,value:He(i.pollIntervalMs),disabled:a||!i.enabled,onChange:e=>{let t=Number(e.target.value)*6e4;n(e=>({...e??{},[r]:{...i,pollIntervalMs:t}}))},onPointerUp:e=>void l(r,{...i,pollIntervalMs:Number(e.target.value)*6e4}),onKeyUp:e=>void l(r,{...i,pollIntervalMs:Number(e.target.value)*6e4}),className:`w-full accent-primary disabled:opacity-50`}),(0,J.jsxs)(`div`,{className:`flex justify-between text-[10px] text-muted-foreground`,children:[(0,J.jsxs)(`span`,{children:[ze,` min`]}),(0,J.jsxs)(`span`,{children:[Be,` min`]})]})]}),(0,J.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-md border bg-muted/20 p-3`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`div`,{className:`text-sm font-medium`,children:`Show in quota widget`}),(0,J.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`Display only. Off hides this provider from the dashboard widget; collection continues if enabled.`})]}),(0,J.jsx)(B,{checked:i.showInWidget,disabled:a,onCheckedChange:e=>void l(r,{...i,showInWidget:e})})]}),(0,J.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-md border bg-muted/20 p-3`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`div`,{className:`text-sm font-medium`,children:`Burn-rate sparkline`}),(0,J.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`Show a mini utilization chart per window in the expanded widget.`})]}),(0,J.jsx)(B,{checked:i.sparklineEnabled??!0,disabled:a,onCheckedChange:e=>void l(r,{...i,sparklineEnabled:e})})]}),(0,J.jsxs)(`div`,{className:`rounded-md border bg-muted/20 p-3 space-y-2`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,J.jsx)(`div`,{className:`text-sm font-medium`,children:`Sparkline range`}),(0,J.jsxs)(L,{variant:`outline`,className:`tabular-nums`,children:[i.sparklineRangeHours??8,`h`]})]}),(0,J.jsx)(`input`,{type:`range`,min:1,max:8,step:1,value:i.sparklineRangeHours??8,disabled:a||!(i.sparklineEnabled??!0),onChange:e=>{let t=Number(e.target.value);n(e=>({...e??{},[r]:{...i,sparklineRangeHours:t}}))},onPointerUp:e=>void l(r,{...i,sparklineRangeHours:Number(e.target.value)}),onKeyUp:e=>void l(r,{...i,sparklineRangeHours:Number(e.target.value)}),className:`w-full accent-primary disabled:opacity-50`}),(0,J.jsxs)(`div`,{className:`flex justify-between text-[10px] text-muted-foreground`,children:[(0,J.jsx)(`span`,{children:`1h`}),(0,J.jsx)(`span`,{children:`8h`})]})]})]})]},r)})]})}function Ge({message:e}){return(0,J.jsxs)(`div`,{className:`flex items-start gap-2 rounded-lg border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive`,children:[(0,J.jsx)(_,{className:`mt-0.5 size-4 shrink-0`}),(0,J.jsx)(`span`,{children:e})]})}var Ke=re(),X={cautionAt:.15,avoidLargeAt:.5,hardAvoidAt:1},qe=.99,Je=.5;function Z(e,t){return((e??t)*100).toFixed(0)}function Q(e){let t=Number(e);return!Number.isFinite(t)||t<0||t>100?null:t/100}function Ye({policy:e,canWrite:n,onPolicy:r}){let i=e.quotaBands,a=e.providerQuota??{},[o,s]=(0,K.useState)(Z(i?.cautionAt,X.cautionAt)),[c,l]=(0,K.useState)(Z(i?.avoidLargeAt,X.avoidLargeAt)),[d,f]=(0,K.useState)(Z(i?.hardAvoidAt,X.hardAvoidAt)),[p,m]=(0,K.useState)(()=>{let e={};for(let t of Ke){let n=a[t]??{};e[t]={backstop:Z(n.hardBackstopUtilization,qe),floor:Z(n.burnPenaltyUtilizationFloor,Je)}}return e}),[h,g]=(0,K.useState)(!1),[_,v]=(0,K.useState)(``),[b,x]=(0,K.useState)(!1),[S,C]=(0,K.useState)(``);async function w(){let t=Q(o),n=Q(c),i=Q(d);if(t===null){C(`Caution threshold must be 0–100%.`);return}if(n===null){C(`Avoid-large threshold must be 0–100%.`);return}if(i===null){C(`Hard-avoid threshold must be 0–100%.`);return}if(t>=n){C(`Caution must be less than avoid-large.`);return}if(n>=i){C(`Avoid-large must be less than hard-avoid.`);return}let a={};for(let e of Ke){let t=p[e],n=Q(t.backstop),r=Q(t.floor);if(n===null){C(`${j(e)}: hard-backstop must be 0–100%.`);return}if(r===null){C(`${j(e)}: burn-penalty floor must be 0–100%.`);return}a[e]={hardBackstopUtilization:n,burnPenaltyUtilizationFloor:r}}C(``),g(!0),v(``),x(!1);try{r(await u(`PUT`,`/routing-policy`,{...e,quotaBands:{cautionAt:t,avoidLargeAt:n,hardAvoidAt:i},providerQuota:a})),x(!0),setTimeout(()=>x(!1),2e3)}catch(e){v(e.message)}finally{g(!1)}}function T(e,t){m(n=>({...n,[e]:{...n[e],...t}})),C(``),x(!1)}function E(){C(``),x(!1)}return(0,J.jsxs)(G,{size:`sm`,children:[(0,J.jsxs)(H,{children:[(0,J.jsx)(W,{className:`text-sm`,children:`Quota thresholds`}),(0,J.jsx)(V,{className:`text-xs`,children:`Band cutoffs govern when the orchestrator starts penalising or blocking high-quota providers. Values are utilization percentages (0–100).`})]}),(0,J.jsxs)(U,{className:`space-y-4`,children:[(_||S)&&(0,J.jsx)(Ge,{message:_||S}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`div`,{className:`mb-2 text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:`Band cutoffs`}),(0,J.jsx)(Xe,{caution:Number(o),avoidLarge:Number(c),hardAvoid:Number(d)}),(0,J.jsxs)(`div`,{className:`mt-3 grid gap-3 sm:grid-cols-3`,children:[(0,J.jsx)($,{label:`Caution at`,hint:`Default: ${(X.cautionAt*100).toFixed(0)}%`,value:o,disabled:!n||h,onChange:e=>{s(e),E()}}),(0,J.jsx)($,{label:`Avoid-large at`,hint:`Default: ${(X.avoidLargeAt*100).toFixed(0)}%`,value:c,disabled:!n||h,onChange:e=>{l(e),E()}}),(0,J.jsx)($,{label:`Hard-avoid at`,hint:`Default: ${(X.hardAvoidAt*100).toFixed(0)}%`,value:d,disabled:!n||h,onChange:e=>{f(e),E()}})]})]}),Ke.map(e=>{let t=p[e];return(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`div`,{className:`mb-2 text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:[j(e),` overrides`]}),(0,J.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,J.jsx)($,{label:`Hard-backstop utilization`,hint:`Provider blocked above this. Default: ${(qe*100).toFixed(0)}%`,value:t.backstop,disabled:!n||h,onChange:t=>T(e,{backstop:t})}),(0,J.jsx)($,{label:`Burn-penalty floor`,hint:`Penalties suppressed below this. Default: ${(Je*100).toFixed(0)}%`,value:t.floor,disabled:!n||h,onChange:t=>T(e,{floor:t})})]})]},e)}),n&&(0,J.jsxs)(R,{size:`sm`,onClick:()=>void w(),disabled:h,children:[h?(0,J.jsx)(y,{className:`size-4 animate-spin`}):(0,J.jsx)(t,{className:`size-4`}),b?`Saved`:`Save thresholds`]})]})]})}function Xe({caution:e,avoidLarge:t,hardAvoid:n}){let r=e=>Math.max(0,Math.min(100,Number.isFinite(e)?e:0)),i=r(e),a=Math.max(i,r(t)),o=Math.max(a,r(n)),s=e=>`${e.toFixed(0)}%`,c=[{key:`normal`,label:`normal`,color:`bg-emerald-500`,from:0,to:i,range:`0–${s(i)}`},{key:`caution`,label:`caution`,color:`bg-amber-500`,from:i,to:a,range:`${s(i)}–${s(a)}`},{key:`avoid-large`,label:`avoid large`,color:`bg-orange-500`,from:a,to:o,range:`${s(a)}–${s(o)}`},{key:`hard-avoid`,label:`hard avoid`,color:`bg-red-500`,from:o,to:100,range:`≥ ${s(o)}`}];return(0,J.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,J.jsx)(`div`,{className:`flex h-2.5 overflow-hidden rounded-full bg-muted`,role:`img`,"aria-label":`Quota penalty bands from 0 to 100 percent`,children:c.map(e=>(0,J.jsx)(`div`,{className:p(e.color,`transition-[width] duration-300`),style:{width:`${e.to-e.from}%`},title:`${e.label} · ${e.range}`},e.key))}),(0,J.jsx)(`div`,{className:`flex flex-wrap gap-x-3 gap-y-1 text-[10px] text-muted-foreground`,children:c.map(e=>(0,J.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,J.jsx)(`span`,{className:p(`size-2 shrink-0 rounded-full`,e.color)}),e.label,` `,(0,J.jsx)(`span`,{className:`tabular-nums text-foreground/70`,children:e.range})]},e.key))})]})}function $({label:e,hint:t,value:n,disabled:r,onChange:i}){return(0,J.jsxs)(`label`,{className:`space-y-1`,children:[(0,J.jsx)(`span`,{className:`text-[10px] font-medium text-muted-foreground`,children:e}),(0,J.jsxs)(`div`,{className:`relative`,children:[(0,J.jsx)(z,{value:n,onChange:e=>i(e.target.value),disabled:r,className:`h-8 pr-6 text-xs tabular-nums`}),(0,J.jsx)(`span`,{className:`pointer-events-none absolute inset-y-0 right-2.5 flex items-center text-xs text-muted-foreground`,children:`%`})]}),(0,J.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:t})]})}function Ze(){let[e,t]=(0,K.useState)(null),[n,r]=(0,K.useState)(!1),[i,a]=(0,K.useState)(``),[o,s]=(0,K.useState)(!1),[d,f]=(0,K.useState)(!1);async function m(){if(!d){r(!0),a(``);try{let[e,n]=await Promise.all([u(`GET`,`/routing-policy`),u(`GET`,`/agent-profiles/coordinator`).catch(()=>null)]);t({policy:e,profile:n}),f(!0)}catch(e){a(e.message)}finally{r(!1)}}}async function h(){f(!1),r(!0),a(``);try{let[e,n]=await Promise.all([u(`GET`,`/routing-policy`),u(`GET`,`/agent-profiles/coordinator`).catch(()=>null)]);t({policy:e,profile:n}),f(!0)}catch(e){a(e.message)}finally{r(!1)}}function g(){let e=!o;s(e),e&&!d&&m()}return(0,J.jsx)(G,{size:`sm`,children:(0,J.jsxs)(U,{className:`space-y-3`,children:[(0,J.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-2 text-left`,onClick:g,children:[(0,J.jsx)(l,{className:`size-4 text-muted-foreground`}),(0,J.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,J.jsx)(`div`,{className:`text-sm font-semibold`,children:`What your coordinator knows`}),(0,J.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`Active routing policy + coordinator profile instructions (read-only)`})]}),o?(0,J.jsx)(ee,{className:`size-4 shrink-0 text-muted-foreground`}):(0,J.jsx)(te,{className:`size-4 shrink-0 text-muted-foreground`})]}),o&&(0,J.jsxs)(`div`,{className:`space-y-4 pt-1`,children:[(0,J.jsx)(`div`,{className:`flex justify-end`,children:(0,J.jsxs)(R,{variant:`outline`,size:`sm`,onClick:()=>void h(),disabled:n,children:[(0,J.jsx)(c,{className:p(`size-3.5`,n&&`animate-spin`)}),`Refresh`]})}),i&&(0,J.jsx)(Ge,{message:i}),n&&!e&&(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-muted-foreground py-2`,children:[(0,J.jsx)(y,{className:`size-3.5 animate-spin`}),`Loading…`]}),e&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(Qe,{policy:e.policy}),e.profile?(0,J.jsx)(et,{profile:e.profile}):(0,J.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:`Coordinator profile not found.`})]})]})]})})}function Qe({policy:e}){let t=e.quotaBands,n=e.providerQuota??{};return(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsx)(`div`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wide`,children:`Active routing policy`}),e.rules.length===0?(0,J.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:`No rules — coordinators use their own heuristics.`}):(0,J.jsxs)(`div`,{className:`overflow-hidden rounded-md border border-border text-xs`,children:[(0,J.jsxs)(`div`,{className:`grid grid-cols-[1.5rem_minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)] gap-px bg-border text-[10px] font-medium text-muted-foreground uppercase tracking-wide`,children:[(0,J.jsx)(`div`,{className:`bg-muted/40 px-2 py-1.5`,children:`#`}),(0,J.jsx)(`div`,{className:`bg-muted/40 px-2 py-1.5`,children:`Match`}),(0,J.jsx)(`div`,{className:`bg-muted/40 px-2 py-1.5`,children:`Target`}),(0,J.jsx)(`div`,{className:`bg-muted/40 px-2 py-1.5`,children:`Status`})]}),e.rules.map((e,t)=>(0,J.jsxs)(`div`,{className:p(`grid grid-cols-[1.5rem_minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)] gap-px bg-border`,e.enabled===!1&&`opacity-50`),children:[(0,J.jsx)(`div`,{className:`bg-card px-2 py-1.5 text-muted-foreground tabular-nums`,children:t+1}),(0,J.jsxs)(`div`,{className:`bg-card px-2 py-1.5`,children:[e.label&&(0,J.jsx)(`div`,{className:`font-medium`,children:e.label}),e.match.taskType&&(0,J.jsxs)(`div`,{className:`font-mono`,children:[`task: `,e.match.taskType]}),e.match.capability&&(0,J.jsxs)(`div`,{className:`font-mono`,children:[`cap: `,e.match.capability]})]}),(0,J.jsxs)(`div`,{className:`bg-card px-2 py-1.5`,children:[(0,J.jsx)(`span`,{className:`font-medium`,children:e.target.provider}),e.target.model&&(0,J.jsxs)(`span`,{className:`text-muted-foreground`,children:[` / `,e.target.model]}),e.target.effort&&(0,J.jsxs)(`span`,{className:`text-muted-foreground`,children:[` (`,e.target.effort,`)`]})]}),(0,J.jsx)(`div`,{className:`bg-card px-2 py-1.5`,children:e.enabled===!1?(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:`disabled`}):(0,J.jsx)(`span`,{className:`text-emerald-500`,children:`active`})})]},t))]}),(t||Object.keys(n).length>0)&&(0,J.jsxs)(`div`,{className:`rounded-md border border-border bg-muted/10 px-3 py-2 text-xs space-y-1`,children:[t&&(0,J.jsxs)(`div`,{className:`flex flex-wrap gap-x-4 gap-y-0.5`,children:[t.cautionAt!==void 0&&(0,J.jsxs)(`span`,{children:[`caution ≥ `,(t.cautionAt*100).toFixed(0),`%`]}),t.avoidLargeAt!==void 0&&(0,J.jsxs)(`span`,{children:[`avoid-large ≥ `,(t.avoidLargeAt*100).toFixed(0),`%`]}),t.hardAvoidAt!==void 0&&(0,J.jsxs)(`span`,{children:[`hard-avoid ≥ `,(t.hardAvoidAt*100).toFixed(0),`%`]})]}),Object.entries(n).map(([e,t])=>(0,J.jsxs)(`div`,{className:`flex flex-wrap gap-x-4 gap-y-0.5 text-muted-foreground`,children:[(0,J.jsx)(`span`,{className:`font-medium text-foreground`,children:j(e)}),t?.hardBackstopUtilization!==void 0&&(0,J.jsxs)(`span`,{children:[`backstop: `,(t.hardBackstopUtilization*100).toFixed(0),`%`]}),t?.burnPenaltyUtilizationFloor!==void 0&&(0,J.jsxs)(`span`,{children:[`floor: `,(t.burnPenaltyUtilizationFloor*100).toFixed(0),`%`]})]},e))]})]})}function $e({text:e,index:t}){return(0,J.jsxs)(`div`,{className:`relative max-h-72 overflow-y-auto rounded-md border border-border bg-muted/20`,children:[t!==void 0&&(0,J.jsxs)(`span`,{className:`sticky top-0 float-right m-1.5 rounded bg-muted px-1.5 py-0.5 text-[9px] font-medium tabular-nums text-muted-foreground`,children:[`#`,t]}),(0,J.jsx)(`pre`,{className:`whitespace-pre-wrap break-words px-3 py-2.5 font-sans text-[11px] leading-relaxed text-foreground/90`,children:e})]})}function et({profile:e}){return(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsxs)(`div`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wide`,children:[`Coordinator profile instructions`,(0,J.jsx)(L,{variant:`secondary`,className:`ml-2 text-[10px]`,children:e.name}),e.builtIn&&(0,J.jsx)(L,{variant:`outline`,className:`ml-1 text-[10px]`,children:`built-in`})]}),e.description&&(0,J.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.description}),(0,J.jsxs)(`div`,{className:`flex flex-wrap gap-2 text-[10px]`,children:[(0,J.jsxs)(L,{variant:`outline`,children:[`base: `,e.base]}),(0,J.jsxs)(L,{variant:`outline`,children:[`repo: `,e.instructions.repoInstructions]}),(0,J.jsxs)(L,{variant:`outline`,children:[`global: `,e.instructions.globalInstructions]}),e.provider&&(0,J.jsxs)(L,{variant:`outline`,children:[`provider: `,e.provider]})]}),e.instructions.system&&(0,J.jsxs)(`div`,{className:`space-y-1`,children:[(0,J.jsx)(`div`,{className:`text-[10px] font-medium text-muted-foreground uppercase tracking-wide`,children:`System prompt`}),(0,J.jsx)($e,{text:e.instructions.system})]}),e.instructions.append.length>0&&(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsxs)(`div`,{className:`text-[10px] font-medium text-muted-foreground uppercase tracking-wide`,children:[`Appended instructions (`,e.instructions.append.length,`)`]}),e.instructions.append.map((e,t)=>(0,J.jsx)($e,{text:e,index:t+1},t))]}),e.instructions.append.length===0&&!e.instructions.system&&(0,J.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:`No instruction blocks defined.`})]})}var tt=re();function nt(){return{label:``,matchTaskType:``,matchCapability:``,targetProvider:tt[0]??``,targetModel:``,targetEffort:``,enabled:!0}}function rt(e){return{label:e.label??``,matchTaskType:e.match.taskType??``,matchCapability:e.match.capability??``,targetProvider:e.target.provider,targetModel:e.target.model??``,targetEffort:e.target.effort??``,enabled:e.enabled!==!1}}function it(e){return{...e.label.trim()?{label:e.label.trim()}:{},match:{...e.matchTaskType.trim()?{taskType:e.matchTaskType.trim()}:{},...e.matchCapability.trim()?{capability:e.matchCapability.trim()}:{}},target:{provider:e.targetProvider,...e.targetModel.trim()?{model:e.targetModel.trim()}:{},...e.targetEffort.trim()?{effort:e.targetEffort.trim()}:{}},enabled:e.enabled}}function at(e){return!e.matchTaskType.trim()&&!e.matchCapability.trim()?`At least one match criterion (task type or capability) is required.`:null}function ot({message:e}){return(0,J.jsxs)(`div`,{className:`flex items-start gap-2 rounded-lg border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive`,children:[(0,J.jsx)(_,{className:`mt-0.5 size-4 shrink-0`}),(0,J.jsx)(`span`,{children:e})]})}function st({canWrite:e}){let[t,n]=(0,K.useState)(null),[r,i]=(0,K.useState)(!1),[a,o]=(0,K.useState)(``),[s,l]=(0,K.useState)(!1);!s&&!r&&!a&&(i(!0),(async()=>{try{n(await u(`GET`,`/routing-policy`)),l(!0)}catch(e){o(e.message)}finally{i(!1)}})());async function d(){i(!0),o(``);try{n(await u(`GET`,`/routing-policy`)),l(!0)}catch(e){o(e.message)}finally{i(!1)}}return(0,J.jsxs)(`div`,{className:`space-y-6`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`h2`,{className:`text-base font-semibold`,children:`Routing`}),(0,J.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Declarative rules mapping task types and capabilities to providers. Rules are advisory — coordinators apply them; explicit per-spawn arguments always take precedence.`})]}),(0,J.jsxs)(R,{variant:`outline`,size:`sm`,onClick:()=>void d(),disabled:r,children:[(0,J.jsx)(c,{className:p(`size-4`,r&&`animate-spin`)}),`Refresh`]})]}),a&&(0,J.jsx)(ot,{message:a}),r&&!t&&(0,J.jsx)(G,{size:`sm`,children:(0,J.jsxs)(U,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,J.jsx)(y,{className:`size-4 animate-spin`}),`Loading routing policy…`]})}),t&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(ct,{policy:t,canWrite:e,onPolicy:n}),(0,J.jsx)(Ye,{policy:t,canWrite:e,onPolicy:n})]}),(0,J.jsx)(Ze,{})]})}function ct({policy:e,canWrite:t,onPolicy:n}){let[i,a]=(0,K.useState)(!1),[o,s]=(0,K.useState)(``),[c,l]=(0,K.useState)(!1),[d,f]=(0,K.useState)(nt),[p,m]=(0,K.useState)(``),[h,g]=(0,K.useState)(null),[_,v]=(0,K.useState)(nt),[b,x]=(0,K.useState)(``);async function C(e){a(!0),s(``);try{n(await u(`PUT`,`/routing-policy`,e))}catch(e){s(e.message)}finally{a(!1)}}function w(t,n){let r=[...e.rules],i=t+n;i<0||i>=r.length||([r[t],r[i]]=[r[i],r[t]],C({...e,rules:r}))}function T(t){let n=e.rules.map((e,n)=>n===t?{...e,enabled:e.enabled===!1}:e);C({...e,rules:n})}function E(t){C({...e,rules:e.rules.filter((e,n)=>n!==t)})}function D(){f(nt()),m(``),l(!0)}function ee(){l(!1),m(``)}function te(){let t=at(d);if(t){m(t);return}l(!1),C({...e,rules:[...e.rules,it(d)]})}function O(t){g(t),v(rt(e.rules[t])),x(``)}function k(){g(null),x(``)}function A(){if(h===null)return;let t=at(_);if(t){x(t);return}let n=e.rules.map((e,t)=>t===h?it(_):e);g(null),C({...e,rules:n})}return(0,J.jsxs)(G,{size:`sm`,children:[(0,J.jsxs)(H,{children:[(0,J.jsxs)(W,{className:`flex items-center gap-2 text-sm`,children:[(0,J.jsx)(S,{className:`size-4`}),`Rules`,(0,J.jsxs)(L,{variant:`outline`,className:`ml-auto text-[10px]`,children:[e.rules.length,` rule`,e.rules.length===1?``:`s`]}),i&&(0,J.jsx)(y,{className:`size-3 animate-spin text-muted-foreground`})]}),(0,J.jsx)(V,{className:`text-xs`,children:`Evaluated in order — first matching enabled rule wins. Rules are advisory; explicit spawn arguments override them.`})]}),(0,J.jsxs)(U,{className:`space-y-2`,children:[o&&(0,J.jsx)(ot,{message:o}),e.rules.length===0&&!c&&(0,J.jsx)(`div`,{className:`rounded-md border border-dashed border-border py-6 text-center text-xs text-muted-foreground`,children:`No rules — coordinators fall back to their own heuristics.`}),e.rules.map((n,r)=>h===r?(0,J.jsx)(ut,{form:_,error:b,onChange:v,onSave:A,onCancel:k},r):(0,J.jsx)(lt,{rule:n,idx:r,total:e.rules.length,canWrite:t,saving:i,onMoveUp:()=>w(r,-1),onMoveDown:()=>w(r,1),onToggle:()=>T(r),onEdit:()=>O(r),onRemove:()=>E(r)},r)),c&&(0,J.jsx)(ut,{form:d,error:p,onChange:f,onSave:te,onCancel:ee,isNew:!0}),t&&!c&&h===null&&(0,J.jsxs)(R,{variant:`outline`,size:`sm`,className:`w-full gap-1`,onClick:D,disabled:i,children:[(0,J.jsx)(r,{className:`size-4`}),`Add rule`]})]})]})}function lt({rule:e,idx:t,total:n,canWrite:r,saving:a,onMoveUp:o,onMoveDown:c,onToggle:l,onEdit:u,onRemove:d}){return(0,J.jsxs)(`div`,{className:p(`group flex items-start gap-3 rounded-md border bg-muted/20 p-3`,e.enabled===!1&&`opacity-60`),children:[(0,J.jsxs)(`div`,{className:`flex flex-col items-center gap-0.5 pt-0.5`,children:[(0,J.jsx)(`button`,{type:`button`,title:`Move up`,onClick:o,disabled:!r||a||t===0,className:`rounded p-0.5 text-muted-foreground hover:bg-accent hover:text-foreground disabled:pointer-events-none disabled:opacity-30`,children:(0,J.jsx)(i,{className:`size-3.5`})}),(0,J.jsx)(`button`,{type:`button`,title:`Move down`,onClick:c,disabled:!r||a||t===n-1,className:`rounded p-0.5 text-muted-foreground hover:bg-accent hover:text-foreground disabled:pointer-events-none disabled:opacity-30`,children:(0,J.jsx)(s,{className:`size-3.5`})})]}),(0,J.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-1`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsxs)(`span`,{className:`text-[10px] tabular-nums text-muted-foreground`,children:[`#`,t+1]}),e.label&&(0,J.jsx)(`span`,{className:`text-xs font-medium`,children:e.label}),(0,J.jsx)(L,{variant:`outline`,className:`text-[10px]`,children:e.target.provider}),e.target.model&&(0,J.jsx)(L,{variant:`outline`,className:`text-[10px] font-mono`,children:e.target.model}),e.target.effort&&(0,J.jsx)(L,{variant:`outline`,className:`text-[10px]`,children:e.target.effort})]}),(0,J.jsxs)(`div`,{className:`flex flex-wrap gap-x-3 gap-y-0.5 text-[10px] text-muted-foreground`,children:[e.match.taskType&&(0,J.jsxs)(`span`,{children:[`task-type: `,(0,J.jsx)(`span`,{className:`font-mono text-foreground`,children:e.match.taskType})]}),e.match.capability&&(0,J.jsxs)(`span`,{children:[`capability: `,(0,J.jsx)(`span`,{className:`font-mono text-foreground`,children:e.match.capability})]})]})]}),(0,J.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1 opacity-70 transition-opacity group-hover:opacity-100 group-focus-within:opacity-100`,children:[(0,J.jsx)(B,{checked:e.enabled!==!1,disabled:!r||a,onCheckedChange:l,title:e.enabled===!1?`Enable rule`:`Disable rule`}),r&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`button`,{type:`button`,title:`Edit`,onClick:u,disabled:a,className:`rounded p-1 text-muted-foreground hover:bg-accent hover:text-foreground disabled:pointer-events-none`,children:(0,J.jsxs)(`svg`,{className:`size-3.5`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,children:[(0,J.jsx)(`path`,{d:`M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7`}),(0,J.jsx)(`path`,{d:`M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z`})]})}),(0,J.jsx)(`button`,{type:`button`,title:`Remove`,onClick:d,disabled:a,className:`rounded p-1 text-destructive hover:bg-destructive/10 disabled:pointer-events-none`,children:(0,J.jsx)(b,{className:`size-3.5`})})]})]})]})}function ut({form:e,error:n,onChange:r,onSave:i,onCancel:a,isNew:o}){function s(t){r({...e,...t})}return(0,J.jsxs)(`div`,{className:`rounded-md border border-primary/30 bg-primary/5 p-3 space-y-3`,children:[(0,J.jsx)(`div`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wide`,children:o?`New rule`:`Edit rule`}),(0,J.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,J.jsxs)(`label`,{className:`space-y-1`,children:[(0,J.jsx)(`span`,{className:`text-[10px] font-medium text-muted-foreground`,children:`Label (optional)`}),(0,J.jsx)(z,{value:e.label,onChange:e=>s({label:e.target.value}),placeholder:`e.g. Route GUI tasks to Claude`,className:`h-8 text-xs`})]}),(0,J.jsxs)(`label`,{className:`space-y-1`,children:[(0,J.jsx)(`span`,{className:`text-[10px] font-medium text-muted-foreground`,children:`Target provider`}),(0,J.jsxs)(I,{value:e.targetProvider,onValueChange:e=>s({targetProvider:e}),children:[(0,J.jsx)(N,{className:`h-8 text-xs`,children:(0,J.jsx)(M,{})}),(0,J.jsx)(P,{children:tt.map(e=>(0,J.jsx)(F,{value:e,className:`text-xs`,children:j(e)},e))})]})]})]}),(0,J.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,J.jsxs)(`label`,{className:`space-y-1`,children:[(0,J.jsx)(`span`,{className:`text-[10px] font-medium text-muted-foreground`,children:`Match task-type (prefix)`}),(0,J.jsx)(z,{value:e.matchTaskType,onChange:e=>s({matchTaskType:e.target.value}),placeholder:`e.g. gui, backend, mechanical`,className:`h-8 font-mono text-xs`}),(0,J.jsxs)(`span`,{className:`block text-[10px] leading-snug text-muted-foreground`,children:[`Prefix match — `,(0,J.jsx)(`span`,{className:`font-mono text-foreground`,children:`gui`}),` matches `,(0,J.jsx)(`span`,{className:`font-mono text-foreground`,children:`gui/ux`}),`, `,(0,J.jsx)(`span`,{className:`font-mono text-foreground`,children:`gui/layout`}),`.`]})]}),(0,J.jsxs)(`label`,{className:`space-y-1`,children:[(0,J.jsx)(`span`,{className:`text-[10px] font-medium text-muted-foreground`,children:`Match capability (exact)`}),(0,J.jsx)(z,{value:e.matchCapability,onChange:e=>s({matchCapability:e.target.value}),placeholder:`e.g. code, research, bounded`,className:`h-8 font-mono text-xs`}),(0,J.jsx)(`span`,{className:`block text-[10px] leading-snug text-muted-foreground`,children:`Exact match against the agent's capability tag. Both fields are AND-ed.`})]})]}),(0,J.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,J.jsxs)(`label`,{className:`space-y-1`,children:[(0,J.jsx)(`span`,{className:`text-[10px] font-medium text-muted-foreground`,children:`Model alias (optional)`}),(0,J.jsx)(z,{value:e.targetModel,onChange:e=>s({targetModel:e.target.value}),placeholder:`e.g. opus, gpt-5.4`,className:`h-8 font-mono text-xs`})]}),(0,J.jsxs)(`label`,{className:`space-y-1`,children:[(0,J.jsx)(`span`,{className:`text-[10px] font-medium text-muted-foreground`,children:`Effort (optional)`}),(0,J.jsx)(z,{value:e.targetEffort,onChange:e=>s({targetEffort:e.target.value}),placeholder:`e.g. high, low`,className:`h-8 text-xs`})]})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(B,{checked:e.enabled,onCheckedChange:e=>s({enabled:e})}),(0,J.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Enabled`})]}),n&&(0,J.jsx)(ot,{message:n}),(0,J.jsxs)(`div`,{className:`flex gap-2`,children:[(0,J.jsxs)(R,{size:`sm`,onClick:i,children:[(0,J.jsx)(t,{className:`size-4`}),o?`Add`:`Save`]}),(0,J.jsx)(R,{size:`sm`,variant:`outline`,onClick:a,children:`Cancel`})]})]})}var dt=`browser`,ft=`models`,pt=`profile`,mt=`routing`,ht=[`branch.landed`,`landed-failure`,`agent.ready`,`agent.exited`,`agent.spawn_failed`,`agent.context_threshold`,`agent.quota_threshold`,`workspace.steward_task`,`workspace.conflict`,`workspace.review_request`];function gt(){if(typeof window>`u`)return``;let e=window.location.hash.replace(/^#/,``);return e.startsWith(`settings/`)?decodeURIComponent(e.slice(9)):``}function _t(e){if(typeof window>`u`)return;let t=new URL(window.location.href);t.hash=`settings/${encodeURIComponent(e)}`,window.history.pushState({},``,t)}function vt(){let[e,t]=(0,K.useState)([]),[n,r]=(0,K.useState)(null),[i,a]=(0,K.useState)([]),[o,s]=(0,K.useState)(()=>gt()),[l,d]=(0,K.useState)(!0),[f,m]=(0,K.useState)(``),[h,v]=(0,K.useState)(``);async function y(){d(!0),m(``),v(``);try{let[e,n,i]=await Promise.all([u(`GET`,`/settings`),u(`GET`,`/tokens/me`),u(`GET`,`/providers`).catch(e=>(v(e.message),{catalog:[]}))]);t(e.settings),r(n),a(i.catalog)}catch(e){m(e.message)}finally{d(!1)}}(0,K.useEffect)(()=>{y()},[]),(0,K.useEffect)(()=>{let e=()=>s(gt());return window.addEventListener(`hashchange`,e),window.addEventListener(`popstate`,e),()=>{window.removeEventListener(`hashchange`,e),window.removeEventListener(`popstate`,e)}},[]);let b=(0,K.useMemo)(()=>fe(e),[e]),x=(0,K.useMemo)(()=>[...b.map(e=>({slug:e.slug,label:e.group,description:`${e.settings.length} schema setting${e.settings.length===1?``:`s`}`,kind:`descriptors`,settings:e.settings})),{slug:mt,label:`Routing`,description:`Rules, quota thresholds, coordinator view`,kind:`routing`,settings:[]},{slug:pt,label:`Profile`,description:`Display name and avatar`,kind:`profile`,settings:[]},{slug:dt,label:`Browser`,description:`Local dashboard preferences`,kind:`browser`,settings:[]},{slug:ft,label:`Models`,description:`Provider model catalog`,kind:`models`,settings:[]}],[b]),S=x.find(e=>e.slug===o)??x[0];function C(e){s(e),_t(e)}function w(e){t(t=>t.map(t=>q(t)===q(e)?e:t))}return(0,J.jsxs)(`div`,{className:`space-y-4`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Settings`}),(0,J.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Schema-driven Relay settings, browser preferences, and model catalog controls.`})]}),(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[n&&(0,J.jsxs)(L,{variant:`outline`,className:`gap-1`,children:[(0,J.jsx)(g,{className:`size-3`}),n.kind,`:`,n.actor]}),(0,J.jsxs)(R,{variant:`outline`,size:`sm`,onClick:()=>void y(),disabled:l,children:[(0,J.jsx)(c,{className:p(`size-4`,l&&`animate-spin`)}),`Refresh`]})]})]}),f&&(0,J.jsxs)(`div`,{className:`flex items-start gap-2 rounded-lg border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive`,children:[(0,J.jsx)(_,{className:`mt-0.5 size-4`}),(0,J.jsx)(`span`,{children:f})]}),(0,J.jsxs)(`div`,{className:`grid gap-4 lg:grid-cols-[230px_minmax(0,1fr)]`,children:[(0,J.jsx)(`nav`,{className:`space-y-1 lg:sticky lg:top-4 lg:self-start`,children:x.map(e=>(0,J.jsxs)(`button`,{type:`button`,className:p(`w-full rounded-md border px-3 py-2 text-left text-sm transition-colors`,S?.slug===e.slug?`border-primary/50 bg-primary/10 text-foreground`:`border-transparent hover:border-border hover:bg-accent`),onClick:()=>C(e.slug),children:[(0,J.jsx)(`span`,{className:`block font-medium`,children:e.label}),(0,J.jsx)(`span`,{className:`block truncate text-xs text-muted-foreground`,children:e.description})]},e.slug))}),(0,J.jsx)(`div`,{className:`min-w-0 space-y-4`,children:l&&!e.length?(0,J.jsx)(G,{size:`sm`,children:(0,J.jsx)(U,{className:`text-sm text-muted-foreground`,children:`Loading settings…`})}):S?.kind===`routing`?(0,J.jsx)(st,{canWrite:ae(n?.scopes,`settings:write:routing`)}):S?.kind===`descriptors`?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(De,{group:S.label,settings:S.settings,onSaved:w}),S.label===`Providers`&&(0,J.jsx)(We,{canWrite:ae(n?.scopes,`settings:write:provider`)}),S.label===`Notifications`&&(0,J.jsx)(yt,{})]}):S?.kind===`profile`?(0,J.jsx)(bt,{}):S?.kind===`browser`?(0,J.jsx)(je,{}):(0,J.jsx)(Ne,{catalog:i,error:h,canWrite:ae(n?.scopes,`settings:write:provider`),onCatalog:a})})]})]})}function yt(){let[e,t]=(0,K.useState)(`branch.landed`),[n,r]=(0,K.useState)(`{
4
- "repoRoot": "/repo"
5
- }`),[i,a]=(0,K.useState)(null),[o,s]=(0,K.useState)(!1),[c,l]=(0,K.useState)(``);async function d(){s(!0),l(``);try{let t=JSON.parse(n);if(!t||typeof t!=`object`||Array.isArray(t))throw Error(`Scope must be a JSON object`);a((await u(`POST`,`/notifications/preview`,{type:e,scope:t})).preview)}catch(e){a(null),l(e.message)}finally{s(!1)}}return(0,J.jsx)(G,{size:`sm`,children:(0,J.jsxs)(U,{className:`space-y-3`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Who gets what`}),(0,J.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Dry-run notification routing without sending.`})]}),(0,J.jsxs)(R,{size:`sm`,onClick:()=>void d(),disabled:o,children:[(0,J.jsx)(S,{className:`size-4`}),`Preview`]})]}),(0,J.jsxs)(`div`,{className:`grid gap-3 md:grid-cols-[240px_minmax(0,1fr)]`,children:[(0,J.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,J.jsx)(`label`,{className:`text-xs font-medium text-muted-foreground`,children:`Type`}),(0,J.jsxs)(I,{value:e,onValueChange:t,children:[(0,J.jsx)(N,{className:`w-full`,children:(0,J.jsx)(M,{})}),(0,J.jsx)(P,{children:ht.map(e=>(0,J.jsx)(F,{value:e,children:e},e))})]})]}),(0,J.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,J.jsx)(`label`,{className:`text-xs font-medium text-muted-foreground`,children:`Scope`}),(0,J.jsx)(se,{value:n,onChange:e=>r(e.target.value),rows:4,className:`font-mono text-xs`})]})]}),c&&(0,J.jsxs)(`div`,{className:`flex items-start gap-2 rounded-md border border-destructive/40 bg-destructive/10 p-2 text-xs text-destructive`,children:[(0,J.jsx)(_,{className:`mt-0.5 size-3.5`}),(0,J.jsx)(`span`,{children:c})]}),i&&(0,J.jsx)(`div`,{className:`overflow-hidden rounded-md border border-border`,children:i.recipients.length===0?(0,J.jsx)(`div`,{className:`px-3 py-4 text-center text-xs text-muted-foreground`,children:`No recipients`}):i.recipients.map(e=>(0,J.jsxs)(`div`,{className:`grid gap-1 border-b border-border px-3 py-2 text-xs last:border-b-0 md:grid-cols-[minmax(0,180px)_minmax(0,160px)_minmax(0,1fr)]`,children:[(0,J.jsx)(`span`,{className:`truncate font-medium`,children:e.recipient}),(0,J.jsx)(`span`,{className:`truncate font-mono text-muted-foreground`,children:e.matchedRule}),(0,J.jsx)(`span`,{className:`truncate text-muted-foreground`,children:e.reason})]},`${e.recipient}-${e.matchedRule}`))})]})})}function bt(){let e=A(e=>e.fetchUsers),n=(0,K.useRef)(null),[r,i]=(0,K.useState)(null),[a,s]=(0,K.useState)(``),[c,l]=(0,K.useState)(!0),[d,f]=(0,K.useState)(!1),[p,m]=(0,K.useState)(``);async function h(){l(!0),m(``);try{let e=await u(`GET`,`/users/me`);i(e),s(e.displayName||e.handle)}catch(e){m(e.message)}finally{l(!1)}}(0,K.useEffect)(()=>{h()},[]);async function g(){f(!0),m(``);try{let t=await u(`PATCH`,`/users/me`,{displayName:a});i(t),s(t.displayName||t.handle),await e()}catch(e){m(e.message)}finally{f(!1)}}async function v(t){if(t){f(!0),m(``);try{let n=await w(`/users/me/avatar`,t);i(n.user),s(n.user.displayName||n.user.handle),await e()}catch(e){m(e.message)}finally{f(!1),n.current&&(n.current.value=``)}}}async function y(){f(!0),m(``);try{i(await u(`DELETE`,`/users/me/avatar`)),await e()}catch(e){m(e.message)}finally{f(!1)}}return(0,J.jsx)(G,{size:`sm`,children:(0,J.jsxs)(U,{className:`space-y-4`,children:[p&&(0,J.jsxs)(`div`,{className:`flex items-start gap-2 rounded-md border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive`,children:[(0,J.jsx)(_,{className:`mt-0.5 size-4`}),(0,J.jsx)(`span`,{children:p})]}),(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4`,children:[(0,J.jsx)(le,{user:r??void 0,distinct:!0,className:`size-16 text-lg`}),(0,J.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-2`,children:[(0,J.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground`,htmlFor:`profile-display-name`,children:`Display name`}),(0,J.jsx)(`input`,{id:`profile-display-name`,className:`h-9 w-full rounded-md border border-input bg-background px-3 text-sm`,value:a,onChange:e=>s(e.target.value),disabled:c||d,maxLength:120})]})]}),(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,J.jsxs)(R,{size:`sm`,onClick:()=>void g(),disabled:c||d||!a.trim(),children:[(0,J.jsx)(t,{className:`size-4`}),`Save`]}),(0,J.jsxs)(R,{size:`sm`,variant:`outline`,onClick:()=>n.current?.click(),disabled:c||d,children:[(0,J.jsx)(T,{className:`size-4`}),`Upload`]}),(0,J.jsxs)(R,{size:`sm`,variant:`outline`,onClick:()=>void y(),disabled:c||d||!r?.avatarArtifactId,children:[(0,J.jsx)(b,{className:`size-4`}),`Remove`]}),d&&(0,J.jsx)(o,{className:`size-4 animate-pulse text-muted-foreground`}),(0,J.jsx)(`input`,{ref:n,type:`file`,accept:`image/png,image/jpeg,image/gif,image/webp`,className:`hidden`,onChange:e=>void v(e.target.files?.[0])})]})]})})}export{vt as SettingsView};
6
- //# sourceMappingURL=settings-DGgwr9WH.js.map
@@ -1,9 +0,0 @@
1
- import{r as e}from"./chunk-CilyBKbf.js";import{Qn as t,er as n,ir as r,lr as i,or as a,sr as o,tr as s,ur as c}from"./lucide-react-C4eXYCwx.js";import{a as l,c as u,f as d,o as f,s as p}from"./types-BiJFuTiL.js";import{$ as m,A as h,E as ee,N as g,R as _,S as v,T as y,U as b,at as x,d as te,et as S,it as C,k as ne,nt as w,p as T,q as re,rt as E,tt as D,y as O}from"./display-1J__Ti1K.js";var k=e(c(),1),ie=e=>{let t,n=new Set,r=(e,r)=>{let i=typeof e==`function`?e(t):e;if(!Object.is(i,t)){let e=t;t=r??(typeof i!=`object`||!i)?i:Object.assign({},t,i),n.forEach(n=>n(t,e))}},i=()=>t,a={setState:r,getState:i,getInitialState:()=>o,subscribe:e=>(n.add(e),()=>n.delete(e))},o=t=e(r,i,a);return a},ae=(e=>e?ie(e):ie),oe=e=>e;function se(e,t=oe){let n=k.useSyncExternalStore(e.subscribe,k.useCallback(()=>t(e.getState()),[e,t]),k.useCallback(()=>t(e.getInitialState()),[e,t]));return k.useDebugValue(n),n}var ce=e=>{let t=ae(e),n=e=>se(t,e);return Object.assign(n,t),n},le=(e=>e?ce(e):ce);function ue(e,t){let n;try{n=e()}catch{return}return{getItem:e=>{let r=e=>e===null?null:JSON.parse(e,t?.reviver),i=n.getItem(e)??null;return i instanceof Promise?i.then(r):r(i)},setItem:(e,r)=>n.setItem(e,JSON.stringify(r,t?.replacer)),removeItem:e=>n.removeItem(e)}}var de=e=>t=>{try{let n=e(t);return n instanceof Promise?n:{then(e){return de(e)(n)},catch(e){return this}}}catch(e){return{then(e){return this},catch(t){return de(t)(e)}}}},fe=(e,t)=>(n,r,i)=>{let a={storage:ue(()=>window.localStorage),partialize:e=>e,version:0,merge:(e,t)=>({...t,...e}),...t},o=!1,s=0,c=new Set,l=new Set,u=a.storage;if(!u)return e((...e)=>{console.warn(`[zustand persist middleware] Unable to update item '${a.name}', the given storage is currently unavailable.`),n(...e)},r,i);let d=()=>{let e=a.partialize({...r()});return u.setItem(a.name,{state:e,version:a.version})},f=i.setState;i.setState=(e,t)=>(f(e,t),d());let p=e((...e)=>(n(...e),d()),r,i);i.getInitialState=()=>p;let m,h=()=>{if(!u)return;let e=++s;o=!1,c.forEach(e=>e(r()??p));let t=a.onRehydrateStorage?.call(a,r()??p)||void 0;return de(u.getItem.bind(u))(a.name).then(e=>{if(e)if(typeof e.version==`number`&&e.version!==a.version){if(a.migrate){let t=a.migrate(e.state,e.version);return t instanceof Promise?t.then(e=>[!0,e]):[!0,t]}console.error(`State loaded from storage couldn't be migrated since no migrate function was provided`)}else return[!1,e.state];return[!1,void 0]}).then(t=>{if(e!==s)return;let[i,o]=t;if(m=a.merge(o,r()??p),n(m,!0),i)return d()}).then(()=>{e===s&&(t?.(r(),void 0),m=r(),o=!0,l.forEach(e=>e(m)))}).catch(n=>{e===s&&t?.(void 0,n)})};return i.persist={setOptions:e=>{a={...a,...e},e.storage&&(u=e.storage)},clearStorage:()=>{u?.removeItem(a.name)},getOptions:()=>a,rehydrate:()=>h(),hasHydrated:()=>o,onHydrate:e=>(c.add(e),()=>{c.delete(e)}),onFinishHydration:e=>(l.add(e),()=>{l.delete(e)})},a.skipHydration||h(),m||p};function pe(e){if(!e)return``;let t=e.replace(/\r\n/g,`
2
- `);return t=t.replace(/```[^\n]*\n([\s\S]*?)```/g,(e,t)=>{let n=t.replace(/\n+$/,``).split(`
3
- `).length;return` code block, ${n} ${n===1?`line`:`lines`}. `}),t=t.replace(/```[^\n]*/g,` code block. `),t=_e(t),t=t.replace(/^#{1,6}\s+/gm,``),t=t.replace(/^\s*[-*+]\s+/gm,`. `),t=t.replace(/^\s*\d+\.\s+/gm,`. `),t=t.replace(/`([^`]+)`/g,`$1`),t=t.replace(/\[([^\]]+)\]\([^)]+\)/g,`$1`),t=t.replace(/(\*\*|__|\*|_)(.*?)\1/g,`$2`),t=t.replace(/[ \t]+/g,` `),t=t.replace(/\n{2,}/g,`. `),t=t.replace(/\s*\.\s*\.\s*(\.\s*)+/g,`. `),t.trim()}function me(e){return/\|/.test(e)&&e.trim().length>0}function he(e){return/^\s*\|?\s*:?-{2,}:?\s*(\|\s*:?-{2,}:?\s*)+\|?\s*$/.test(e)}function ge(e){return e.trim().replace(/^\||\|$/g,``).split(`|`).map(e=>e.trim()).filter(e=>e.length>0)}function _e(e){let t=e.split(`
4
- `),n=[],r=0;for(;r<t.length;){if(me(t[r])&&r+1<t.length&&he(t[r+1])){let e=ge(t[r]),i=r+2,a=0;for(;i<t.length&&me(t[i])&&!he(t[i]);)a++,i++;let o=e.length?`with columns ${e.join(`, `)}`:``,s=`${a} ${a===1?`row`:`rows`}`;n.push(`table ${o?`${o}, `:``}${s}.`.replace(/\s+/g,` `).trim()),r=i;continue}n.push(t[r]),r++}return n.join(`
5
- `)}var A={ms:`milliseconds`,s:`seconds`,kb:`kilobytes`,mb:`megabytes`,gb:`gigabytes`,tb:`terabytes`};function ve(e){return e.split(``).join(` `)}function ye(e){return e.split(``).map(e=>/[0-9]/.test(e)?e:e.toUpperCase()).join(` `)}var be=[{name:`url`,pattern:/\bhttps?:\/\/\S+/gi,replace:` link `},{name:`path`,pattern:/(?:\/[A-Za-z0-9._-]+){2,}\/?/g,replace:e=>` `+e.replace(/[/._-]+/g,` `).trim()+` `},{name:`slash`,pattern:/(?<=[A-Za-z0-9])\/(?=[A-Za-z0-9])/g,replace:` `},{name:`func-call`,pattern:/\b([A-Za-z_$][\w$]*)\(\)/g,replace:`$1`},{name:`approx`,pattern:/~(?=\s*[\d.])/g,replace:`approximately `},{name:`range`,pattern:/(\d)\s*[-–—]\s*(?=\d)/g,replace:`$1 to `},{name:`version`,pattern:/\b(v?)(\d+(?:\.\d+){2,})\b/gi,replace:(e,t,n)=>`${t?`version `:``}${n.replace(/\./g,` dot `)}`},{name:`decimal`,pattern:/\b(\d+)\.(\d+)\b/g,replace:(e,t,n)=>`${t} point ${ve(n)}`},{name:`hash`,pattern:/\b(?=[0-9a-f]{7,40}\b)(?=[0-9a-f]*[a-f])(?=[0-9a-f]*\d)[0-9a-f]{7,40}\b/gi,replace:e=>ye(e)},{name:`id-camel`,pattern:/([a-z])(Id|ID)(s)?\b/g,replace:(e,t,n,r)=>`${t} I D${r?`s`:``}`},{name:`id-word`,pattern:/\b(?:id|Id|ID)(s)?\b/g,replace:(e,t)=>`I D${t?`s`:``}`},{name:`byte-unit`,pattern:/\b(\d+)\s?(kb|mb|gb|tb)\b/gi,replace:(e,t,n)=>`${t} ${A[n.toLowerCase()]}`},{name:`ms-unit`,pattern:/\b(\d{1,5})\s?ms\b/g,replace:(e,t)=>`${t} ${A.ms}`},{name:`s-unit`,pattern:/\b(\d{1,3})\s?s\b/g,replace:(e,t)=>`${t} ${A.s}`},{name:`live-adjective`,pattern:/\b(is|are|was|were|be|been|being|now|and|stays?|staying|went|go|goes|going|deployed|it's|that's|here's|there's|we're|you're|they're)\s+live\b/gi,replace:(e,t)=>`${t} lyve`},{name:`interior-dot`,pattern:/\.(?=[A-Za-z0-9])/g,replace:` dot `}];function xe(e){if(!e)return``;let t=e;for(let e of be)t=t.replace(e.pattern,e.replace);return t.replace(/[ \t]{2,}/g,` `).trim()}function Se(e){return xe(pe(e))}var Ce=[{id:`am_michael`,label:`Michael (US ♂)`},{id:`am_adam`,label:`Adam (US ♂)`},{id:`af_heart`,label:`Heart (US ♀)`},{id:`af_bella`,label:`Bella (US ♀)`},{id:`af_nicole`,label:`Nicole (US ♀)`},{id:`af_sarah`,label:`Sarah (US ♀)`},{id:`bm_george`,label:`George (UK ♂)`},{id:`bf_emma`,label:`Emma (UK ♀)`}],j=220;function we(e){let t=e.match(/[^.!?]+[.!?]*\s*/g)?.map(e=>e.trim()).filter(Boolean)??[e],n=[];for(let e of t){if(e.length<=j){n.push(e);continue}let t=e;for(;t.length>j;){let e=t.lastIndexOf(` `,j);e<=0&&(e=j),n.push(t.slice(0,e).trim()),t=t.slice(e).trim()}t&&n.push(t)}return n}var M=typeof window<`u`&&`speechSynthesis`in window,N=new class{enabled=!1;lang=`en-US`;mode=`kokoro`;kokoroVoice=`am_michael`;browserVoice=``;active=null;queue=[];currentChat=null;speaking=!1;gen=0;audioEl=null;audioUrl=null;playingKey=null;manual=!1;listeners=new Set;get available(){return M||typeof Audio<`u`}isEnabled(){return this.enabled}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}getPlayingKey(){return this.playingKey}setPlayingKey(e){if(e!==this.playingKey){this.playingKey=e;for(let e of this.listeners)e()}}setEnabled(e){e!==this.enabled&&(this.enabled=e,e||this.reset())}setLang(e){this.lang=e}setMode(e){e!==this.mode&&(this.mode=e,this.reset())}setKokoroVoice(e){this.kokoroVoice=e}setBrowserVoice(e){this.browserVoice=e}setActiveChat(e){e!==this.active&&(this.active=e,this.queue=this.queue.filter(t=>t.chatId===e))}onResponse(e,t){if(!this.enabled||!this.available||!e||e!==this.active)return;let n=Se(t);n&&(this.speaking&&(this.manual||this.currentChat&&this.currentChat!==e)&&(this.queue=[],this.cancel()),this.queue.push({chatId:e,text:n}),this.pump())}speak(e,t){if(!this.available)return;let n=Se(e);if(!n)return;this.reset(),this.manual=!0,this.speaking=!0,this.currentChat=null,this.setPlayingKey(t??null);let r=++this.gen,i=we(n),a=()=>{r===this.gen&&(this.speaking=!1,this.manual=!1,this.setPlayingKey(null))};this.mode===`kokoro`?this.speakKokoro(i,0,r,a):this.speakBrowser(i,0,r,a)}bargeIn(){this.reset()}reset(){this.queue=[],this.cancel()}cancel(){this.gen++,this.currentChat=null,this.speaking=!1,this.manual=!1,this.setPlayingKey(null);try{window.speechSynthesis.cancel()}catch{}this.stopAudio()}stopAudio(){if(this.audioEl)try{this.audioEl.pause(),this.audioEl.src=``}catch{}if(this.audioUrl){try{URL.revokeObjectURL(this.audioUrl)}catch{}this.audioUrl=null}}pump(){if(this.speaking)return;let e=this.queue.shift();if(!e)return;this.speaking=!0,this.manual=!1,this.currentChat=e.chatId;let t=++this.gen,n=we(e.text),r=()=>{t===this.gen&&(this.speaking=!1,this.currentChat=null,this.pump())};this.mode===`kokoro`?this.speakKokoro(n,0,t,r):this.speakBrowser(n,0,t,r)}speakBrowser(e,t,n,r){if(n!==this.gen)return;if(!M||t>=e.length)return r();let i=new SpeechSynthesisUtterance(e[t]),a=this.browserVoice?window.speechSynthesis.getVoices().find(e=>e.voiceURI===this.browserVoice):void 0;a?(i.voice=a,i.lang=a.lang):i.lang=this.lang||navigator.language||`en-US`,i.onend=()=>this.speakBrowser(e,t+1,n,r),i.onerror=()=>this.speakBrowser(e,t+1,n,r),window.speechSynthesis.speak(i)}speakKokoro(e,t,n,r,i){if(n!==this.gen)return;let a=e[t];if(a===void 0)return r();let o=i??this.fetchSpeech(a),s=e[t+1],c=s===void 0?void 0:this.fetchSpeech(s);o.then(i=>{n===this.gen&&this.playBlob(i,n,()=>this.speakKokoro(e,t+1,n,r,c),()=>{this.speakBrowser(e,t,n,r)})}).catch(()=>{n===this.gen&&this.speakBrowser(e,t,n,r)})}fetchSpeech(e){return s(`/connectors/voice/call/speak`,{text:e,voice:this.kokoroVoice})}playBlob(e,t,n,r){if(t!==this.gen)return;if(typeof Audio>`u`)return r();this.stopAudio(),this.audioEl||=new Audio;let i=URL.createObjectURL(e);this.audioUrl=i;let a=this.audioEl;a.src=i,a.onended=()=>{t===this.gen&&n()},a.onerror=()=>{t===this.gen&&r()},a.play().catch(()=>{t===this.gen&&r()})}};function Te(){if(!M)return[];try{return window.speechSynthesis.getVoices().map(e=>({uri:e.voiceURI,label:`${e.name} (${e.lang})`,lang:e.lang})).sort((e,t)=>e.lang.localeCompare(t.lang)||e.label.localeCompare(t.label))}catch{return[]}}var Ee=typeof navigator<`u`&&!!navigator.mediaDevices?.getUserMedia&&typeof window<`u`&&`MediaRecorder`in window;function De(){for(let e of[`audio/webm;codecs=opus`,`audio/webm`,`audio/ogg;codecs=opus`,`audio/mp4`])if(typeof MediaRecorder<`u`&&MediaRecorder.isTypeSupported?.(e))return e}var Oe=class{rec=null;chunks=[];stream=null;async start(){this.stream=await navigator.mediaDevices.getUserMedia({audio:!0}),this.chunks=[];let e=De();this.rec=new MediaRecorder(this.stream,e?{mimeType:e}:void 0),this.rec.ondataavailable=e=>{e.data.size&&this.chunks.push(e.data)},this.rec.start()}async stop(){let e=this.rec;if(!e)return this.teardown(),null;let t=new Promise(t=>{e.onstop=()=>t()});try{e.stop()}catch{}await t;let n=e.mimeType||`audio/webm`,r=new Blob(this.chunks,{type:n});return this.teardown(),r.size?r:null}cancel(){try{this.rec?.stop()}catch{}this.teardown()}teardown(){this.stream?.getTracks().forEach(e=>e.stop()),this.rec=null,this.stream=null,this.chunks=[]}};async function ke(e){return((await n(`/connectors/voice/call/transcribe`,e))?.text??``).trim()}var P=le((e,t)=>({now:Date.now(),_timer:null,start(){t()._timer||e({_timer:setInterval(()=>e({now:Date.now()}),1e3)})},stop(){let n=t()._timer;n&&(clearInterval(n),e({_timer:null}))}}));function Ae(){return P(e=>e.now)}function je(e=3e4){return P(t=>Math.floor(t.now/e))}var Me=.1,Ne=.9,F=.8,Pe=.4,I=256e3,Fe=1e6;function Ie(e){return{provider:e.id,label:e.label,defaultModel:e.catalog.defaultModel,models:e.catalog.models}}var Le=Object.fromEntries(d().map(e=>[e.id,Ie(e)]));function Re(e){let t=ze(e);return{selfCompactUtilization:t,warnUtilization:Be(t),hardBackstopUtilization:Math.max(Ne,t)}}function ze(e){return!Number.isFinite(e)||!e||e<=I?F:e>=Fe?Pe:Ve(F-(e-I)/(Fe-I)*(F-Pe))}function Be(e){return Ve(Math.max(0,e-Me))}function Ve(e){return Math.round(e*1e3)/1e3}function L(e,t){let n=t?.find(t=>t.provider===e)??Le[e];if(!n)throw Error(`unknown provider catalog: ${e}`);return n}function R(e){return e?.providers[0]??u()[0]??``}function z(e,t){return L(e,t).models.filter(e=>!e.disabled)}function B(e,t){let n=L(e,t),r=n.models.filter(e=>!e.disabled);return n.defaultModel&&r.some(e=>e.alias===n.defaultModel)?n.defaultModel:r[0]?.alias??``}function He(e,t){return e.filter(e=>e.status===`online`&&_(t,e.baseDir)).sort((e,t)=>g(t.baseDir).length-g(e.baseDir).length)[0]}function Ue(e,t){let n=e.find(e=>e.managedAgents.some(e=>e.agentId===t.id));if(n)return n;let r=typeof t.meta?.cwd==`string`?t.meta.cwd:``;return r?He(e,r):void 0}var We=`/settings/chat/scroll`,Ge=150,Ke=1e3,V=new Map,H=null,qe=null;function Je(e){if(!e||typeof e!=`object`)return null;let t=e;return typeof t.stick!=`boolean`||t.topKey!==null&&typeof t.topKey!=`string`||typeof t.offset!=`number`||!Number.isFinite(t.offset)?null:{stick:t.stick,topKey:t.topKey,offset:Math.max(0,t.offset)}}function Ye(e){return V.get(e)}function Xe(e,t){V.delete(e),V.set(e,t),Ze(),$e()}function Ze(){for(;V.size>Ge;){let e=V.keys().next().value;if(e===void 0)break;V.delete(e)}}function Qe(){let e={};for(let[t,n]of V)e[t]=n;return e}function $e(){H!==null&&clearTimeout(H),H=setTimeout(()=>{et()},Ke)}async function et(){H!==null&&(clearTimeout(H),H=null);try{await t(`PUT`,We,{value:Qe()})}catch{}}function tt(){return qe||(qe=(async()=>{try{let e=(await t(`GET`,We)).value;if(!e||typeof e!=`object`)return;for(let[t,n]of Object.entries(e)){if(V.has(t))continue;let e=Je(n);e&&V.set(t,e)}Ze()}catch{}})(),qe)}function nt(e,t){return t.issueRepo||!e?.issueRepo?t:{...t,issueRepo:e.issueRepo}}function rt(e){let t={};for(let n of e)t[n.id]=n;return t}function U(e,t){let n=e.findIndex(e=>e.id===t.id),r=[...e];return n>=0?r[n]=t:r.push(t),r}var it=3e3;function W(e,t,n,r=Date.now(),i){if(!t||!n)return e;let a=[...e[t]||[]],o=i||`s-${n}-${r}`;return a.some(e=>e.id===o)||a.some(e=>e.status===n&&Math.abs(e.timestamp-r)<=it)?e:(a.push({id:o,status:n,timestamp:r}),a.length>200&&a.splice(0,a.length-200),{...e,[t]:a})}function at(e,t){if(!(!e||e.status===t.status)){if((e.status===`offline`||e.status===`stale`)&&(t.status===`online`||t.status===`idle`||t.status===`busy`))return`online`;if(t.status===`offline`)return`offline`}}var ot=new Set([`compacting`,`compacted`,`clearing-context`,`context-cleared`]);function st(e){let t=e.meta?.timelineEvent;if(!t||typeof t!=`object`||Array.isArray(t))return;let n=t.status;if(typeof n!=`string`||!n)return;let r=t.id,i=t.timestamp;return{status:n,...typeof r==`string`?{id:r}:{},...typeof i==`number`&&Number.isFinite(i)?{timestamp:i}:{}}}function ct(e){let t=e.params?.agentId;return typeof t==`string`&&t?t:typeof e.target==`string`&&e.target?e.target:void 0}function lt(e,t){if(t===`command.dispatched`)return e.type===`agent.compact`?`compaction-requested`:e.type===`agent.clearContext`?`clear-requested`:e.type===`agent.shutdown`?`shutting-down`:void 0;if(t===`command.succeeded`){if(e.type===`agent.shutdown`)return`shutdown`;if(e.type===`agent.restart`)return`restarted`}}function ut(e){return JSON.stringify(e)}function dt(e,t){let n=new Map(e.map(e=>[e.id,e])),r=!(e.length===t.length&&e.every((e,n)=>e.id===t[n]?.id)),i=t.map(e=>{let t=n.get(e.id);return t&&ut(t)===ut(e)?t:(r=!0,e)});return r?i:e}function G(e,t){let n=[...new Map(t.map(e=>[e.id,e])).values()],r=new Map(e.map(e=>[e.id,e])),i=!(e.length===n.length&&e.every((e,t)=>e.id===n[t]?.id)),a=n.map(e=>{let t=r.get(e.id);return t&&JSON.stringify(t)===JSON.stringify(e)?t:(i=!0,e)});return i?a:e}function ft(){return typeof document>`u`?!0:document.hidden}function pt(e,t){return!!(e&&t.view===`chat`&&t.selectedInboxThread===e&&!ft())}function mt(e){return e.threadPeer||e.agentId||``}function ht(e,t){return pt(mt(e),t)}function gt(e){return e.filter(e=>e.to===`user`&&e.from!==`user`&&v(e)).reduce((e,t)=>Math.max(e,t.id),0)}function _t(e){if(e.from===`user`||e.to===`user`)return!0;let t=typeof e.payload?.direction==`string`?e.payload.direction:void 0;return e.kind===`channel.event`&&t===`inbound`}var vt={enabled:!0,browserEnabled:!1,messages:!0,replies:!0,errors:!0};function yt(e,t){return t.enabled?e.kind===`message`?t.messages:e.kind===`reply`?t.replies:t.errors:!1}function bt(){return typeof window<`u`&&`Notification`in window}function K(){return bt()?window.Notification.permission:`unsupported`}function xt(e,t){return!yt(e,t.notificationSettings)||!t.notificationSettings.browserEnabled||K()!==`granted`||ht(e,t)?!1:ft()||t.view!==`chat`}function St(e,t){if(K()===`granted`)try{let n=new window.Notification(e.title,{body:e.body,tag:e.id,icon:`icons/agent-relay-192.png`,data:{view:e.view,threadPeer:e.threadPeer,agentId:e.agentId,messageId:e.messageId}});n.onclick=()=>{window.focus(),t(),n.close()}}catch{}}var Ct=(e,t)=>({notification:null,toastNotification:null,notifications:[],notificationUnread:0,notificationSettings:{...vt},notificationPermission:K(),confirmModal:{show:!1,title:``,message:``,action:null},errorModal:{show:!1,title:``,message:``},openConfirm(t,n,r){e({confirmModal:{show:!0,title:t,message:n,action:r}})},showError(t,n){e({errorModal:{show:!0,title:t,message:n}})},showNotification(t){e({notification:t,toastNotification:null}),setTimeout(()=>e({notification:null}),3e3)},handleRelayNotification(n){let r=t();if(!yt(n,r.notificationSettings)||r.notifications.some(e=>e.id===n.id))return;if(n.messageId&&(n.kind===`message`||n.kind===`reply`)){let e=r.messages.find(e=>e.id===n.messageId);if(e&&!_t(e))return}let i=ht(n,r),a=`${n.title}: ${n.body}`;e({notifications:[n,...r.notifications].slice(0,100),notificationUnread:i?r.notificationUnread:Math.min(99,r.notificationUnread+1),notification:i?r.notification:a,toastNotification:i?r.toastNotification:n}),i||setTimeout(()=>{t().toastNotification?.id===n.id&&e({notification:null,toastNotification:null})},4500),xt(n,r)&&St(n,()=>t().openNotification(n)),i&&n.threadPeer&&n.messageId&&t().markInboxThreadReadTo(n.threadPeer,n.messageId)},async openNotification(n){if(e({notificationUnread:0}),n.threadPeer&&(t().openInboxThread(n.threadPeer),n.messageId&&t().markInboxThreadReadTo(n.threadPeer,n.messageId)),n.view&&await t().switchView(n.view),n.agentId&&n.view===`agents`){let e=t().agentsById[n.agentId];e&&t().openAgentDetail(e)}},dismissToast(){e({notification:null,toastNotification:null})},markNotificationsRead(){e({notificationUnread:0})},clearNotifications(){e({notifications:[],notificationUnread:0})},async requestBrowserNotifications(){if(!bt()){e({notificationPermission:`unsupported`,notificationSettings:{...t().notificationSettings,browserEnabled:!1}}),t().showNotification(`Browser notifications are not supported here`);return}let n=await window.Notification.requestPermission();e({notificationPermission:n,notificationSettings:{...t().notificationSettings,browserEnabled:n===`granted`}}),t().showNotification(n===`granted`?`Browser notifications enabled`:`Browser notifications not enabled`)}}),wt=e=>({voiceTtsEnabled:!1,voiceTtsLang:`en-US`,voiceTtsMode:`kokoro`,voiceTtsKokoroVoice:`am_michael`,voiceTtsBrowserVoice:``,voiceInputMode:`compose`,setVoiceTtsEnabled(t){N.setEnabled(t),e({voiceTtsEnabled:t})},setVoiceTtsLang(t){N.setLang(t),e({voiceTtsLang:t})},setVoiceTtsMode(t){N.setMode(t),e({voiceTtsMode:t})},setVoiceTtsKokoroVoice(t){N.setKokoroVoice(t),e({voiceTtsKokoroVoice:t})},setVoiceTtsBrowserVoice(t){N.setBrowserVoice(t),e({voiceTtsBrowserVoice:t})},setVoiceInputMode(t){e({voiceInputMode:t})}}),Tt=null;function Et(e){let t=e.voiceTtsEnabled&&e.view===`chat`&&e.selectedInboxThread||null;t!==Tt&&(Tt=t,N.setActiveChat(t))}var Dt=e=>(n,s)=>({theme:`dark`,view:`overview`,autoRefresh:!0,mobileMenuOpen:!1,commandPaletteOpen:!1,commandQuery:``,connected:!1,connectionError:!1,quotaSeq:0,authNeeded:!1,authToken:``,stats:{},fileOrchestratorId:``,filePath:``,fileSelectedPath:``,fileSelectedLine:0,fileOverlayOpen:!1,_es:null,_refreshTimer:null,_refreshInFlight:!1,set:e=>n(e),async init(){await e.waitForHydration();let r=s().authToken;r&&a(r),i(s().view),N.setEnabled(s().voiceTtsEnabled),N.setLang(s().voiceTtsLang),N.setMode(s().voiceTtsMode),N.setKokoroVoice(s().voiceTtsKokoroVoice),N.setBrowserVoice(s().voiceTtsBrowserVoice),Et(s()),o(()=>{s().authNeeded||n({authNeeded:!0,connectionError:!1})}),tt(),n({notificationPermission:K()}),s().startClock();try{n({stats:await t(`GET`,`/stats`)})}catch(e){if(e.status===401){n({authNeeded:!0});return}}await s().refresh(),s().connectSSE(),s().startAutoRefresh()},async switchView(e){i(e),n({view:e,mobileMenuOpen:!1});let t=s();[`chat`,`messages`].includes(e)&&await Promise.all([t.fetchMessages(),t.fetchChatHistoryImports()]),e===`activity`&&await Promise.all([t.fetchMessages(),t.fetchPairs(),t.fetchTasks(),t.fetchActivityEvents()]),e===`work`&&await Promise.all([t.fetchMessages(),t.fetchTasks()]),e===`pairs`&&await t.fetchPairs(),e===`channels`&&await Promise.all([t.fetchChannels(),t.fetchIntegrations()]),e===`connectors`&&await t.fetchConnectors(),e===`integrations`&&await t.fetchIntegrations(),e===`memory`&&await t.refreshMemory(),e===`tasks`&&await t.fetchTasks(),e===`teams`&&await Promise.all([t.fetchTeams(),t.fetchTeamOutcomeAggregates(),t.refreshIssueRefs()]),e===`automation`&&await Promise.all([t.fetchAutomations(),t.fetchAutomationRuns()]),e===`maintenance`&&await t.fetchMaintenanceJobs(),e===`workspaces`&&await Promise.all([t.fetchWorkspaces(),t.fetchOrchestrators(),t.fetchAgents()]),e===`files`&&await t.fetchOrchestrators(),e===`analytics`&&await t.fetchAnalytics()},startClock(){P.getState().start()},stopClock(){P.getState().stop()},startAutoRefresh(){s().stopAutoRefresh(),s().autoRefresh&&n({_refreshTimer:setInterval(()=>s().refreshLiveData(),x)})},stopAutoRefresh(){let e=s();e._refreshTimer&&(clearInterval(e._refreshTimer),n({_refreshTimer:null}))},async apiCall(e,n,r){return t(e,n,r)},async openFilesAt(e){let t=s();n({fileOrchestratorId:e.orchestratorId||He(t.orchestrators,e.selectedPath||e.path)?.id||t.orchestrators.find(e=>e.status===`online`)?.id||``,filePath:e.path,fileSelectedPath:e.selectedPath||``,fileSelectedLine:e.line||0,fileOverlayOpen:e.overlay===!0}),e.overlay||await s().switchView(`files`)},async openFilesForAgent(e,t=!1){let n=typeof e.meta?.cwd==`string`?e.meta.cwd:``;if(!n){s().showNotification(`Agent has no cwd`);return}let r=Ue(s().orchestrators,e);if(!r){s().showNotification(`No online orchestrator covers that cwd`);return}await s().openFilesAt({orchestratorId:r.id,path:n,overlay:t})},closeFileOverlay(){n({fileOverlayOpen:!1})},async refresh(){let e=s();await Promise.all([e.fetchStats(),e.fetchHealth(),e.fetchAgents(),e.fetchUsers(),e.fetchOrchestrators(),e.fetchPairs(),e.fetchMessages(),e.fetchTasks(),e.fetchChannels(),e.fetchConnectors(),e.fetchIntegrations(),e.fetchAutomations(),e.fetchAutomationRuns(),e.fetchManagedPolicies(),e.fetchAgentProfiles(),e.fetchMaintenanceJobs(),e.fetchWorkspaces(),e.fetchInboxState(),e.fetchActivityEvents(),e.fetchChatHistoryImports(),e.fetchProviderCatalog()])},async refreshLiveData(){if(!(s()._refreshInFlight||s().authNeeded)){n({_refreshInFlight:!0});try{try{let e=await t(`GET`,`/stats`);n(s().connectionError?{stats:e,connectionError:!1}:{stats:e})}catch(e){if(e.status===401)return;s().connectionError||n({connectionError:!0});return}let e=s(),r=[e.fetchHealth(),e.fetchAgents(),e.fetchOrchestrators(),e.fetchPairs(),e.fetchMessages(),e.fetchTasks(),e.fetchManagedPolicies(),e.fetchInboxState()],i=e.view;[`chat`,`messages`].includes(i)&&r.push(e.fetchChatHistoryImports()),i===`activity`&&r.push(e.fetchActivityEvents()),i===`memory`&&r.push(e.refreshMemory()),i===`automation`&&r.push(e.fetchAutomations(),e.fetchAutomationRuns()),i===`channels`&&r.push(e.fetchChannels(),e.fetchIntegrations()),i===`connectors`&&r.push(e.fetchConnectors()),i===`integrations`&&r.push(e.fetchIntegrations()),i===`maintenance`&&r.push(e.fetchMaintenanceJobs()),i===`profiles`&&r.push(e.fetchAgentProfiles()),i===`workspaces`&&r.push(e.fetchWorkspaces()),i===`analytics`&&r.push(e.fetchAnalytics()),i===`teams`&&r.push(e.fetchTeams(),e.fetchTeamOutcomeAggregates(),e.refreshIssueRefs()),e.agentDetailOpen&&e.agentDetailId&&r.push(e.fetchAgentIssueActivity(e.agentDetailId)),await Promise.all(r)}finally{n({_refreshInFlight:!1})}}},async fetchStats(){try{n({stats:await t(`GET`,`/stats`)})}catch{}},connectSSE(){s().disconnectSSE(),n({_es:r(s().authToken,{connected:()=>{n(s().connectionError?{connected:!0,connectionError:!1}:{connected:!0}),s().refreshLiveData();let e=Object.entries(s().agentChatByAgent).filter(([,e])=>e.loadedInitial).map(([e])=>e);Promise.all(e.map(e=>s().gapFillAgentChat(e))),s().refreshPlans(),s().refreshIssueRefs()},disconnected:()=>n({connected:!1}),message:(e,t)=>{if(e!==`connected`){if(e===`message.new`){let e=JSON.parse(t);if(e.kind===`session`&&e.from!==`user`){let t=e.payload?.session;t?.type===`response`&&t?.origin===`provider`&&N.onResponse(O(e),e.body)}let r=s();if(!r.messages.some(t=>t.id===e.id)){let t=[...r.messages,e];t.length>500&&t.splice(0,t.length-500),n({messages:t})}let i=O(e);for(let t of Object.keys(s().agentChatByAgent))s().appendChatTail(t,[e]);y(e)&&v(e)&&pt(i,r)&&s().markInboxThreadReadTo(i,e.id);return}if(e===`message.queued`||e===`message.expired`||e===`message.delivery_updated`||e===`message.reaction_updated`){let e=JSON.parse(t);n({messages:U(s().messages,e)}),s().applyChatMessageUpdate(e);return}if(e===`notification.created`){s().handleRelayNotification(JSON.parse(t));return}if(e===`plan.created`||e===`plan.changed`){let e=JSON.parse(t),n=e.plan??e.data?.plan;n&&s().upsertPlan(n);return}if(e===`plan.deleted`){let e=JSON.parse(t),n=e.plan??e.data?.plan,r=n?.id??e.planId??e.id??e.data?.planId??e.data?.id;(n||r)&&s().removePlan(n??r);return}if(e===`team.dissolved`){let e=JSON.parse(t);e.teamId&&s().markTeamDissolved({teamId:e.teamId,outcomeStatus:e.outcomeStatus,reason:e.reason}),Promise.all([s().fetchTeams(),s().fetchTeamOutcomeAggregates()]);return}if(e===`activity.created`){let e=JSON.parse(t);n({activityEvents:U(s().activityEvents,e)}),e.issueRefId&&s().fetchIssueRef(e.issueRefId),e.agentId&&s().agentDetailOpen&&s().agentDetailId===e.agentId&&s().fetchAgentIssueActivity(e.agentId);return}if(e===`agent.status`){let e=JSON.parse(t),r=s(),i=r.agentsById[e.id],a=nt(i,e);if(n({agents:U(r.agents,a),agentsById:{...r.agentsById,[a.id]:a}}),r.livenessMismatches[a.id]&&a.status!==`offline`){let e={...r.livenessMismatches};delete e[a.id],n({livenessMismatches:e})}let o=r.commandStalls[a.id];if(o){let e=st(a);if(e?.status&&ot.has(e.status)&&(e.timestamp??0)>o.ts){let e={...r.commandStalls};delete e[a.id],n({commandStalls:e})}}let c=st(a),l=c?.status??at(i,a);if(l){let e=c?.timestamp??Date.now(),t=c?.id||`agent-status:${a.id}:${l}:${e}`;n({chatStatusEvents:W(r.chatStatusEvents,a.id,l,e,t)})}return}if(e===`dashboard.presence`){let e=JSON.parse(t);e.agentId&&s().applyPresence(e.agentId,e.viewers??[]);return}if(e===`liveness.mismatch`){let e=JSON.parse(t);e.agentId&&n({livenessMismatches:{...s().livenessMismatches,[e.agentId]:{agentId:e.agentId,detail:e.detail??`Process reported running but relay marked it offline`,ts:Date.now(),policyName:e.policyName,spawnRequestId:e.spawnRequestId}}});return}if(e===`command.stalled`){let e=JSON.parse(t);if(e.agentId){let t=Date.now(),r=e.kind??`compact`,i=r===`clear`?`clear-stalled`:`compaction-stalled`;n({commandStalls:{...s().commandStalls,[e.agentId]:{agentId:e.agentId,kind:r,detail:e.detail??`A context command was requested but never started — the session may need manual intervention.`,ts:t,commandId:e.commandId}},chatStatusEvents:W(s().chatStatusEvents,e.agentId,i,t,`command-stalled:${e.agentId}:${e.commandId??t}`)})}return}if(e===`agent.removed`){let e=JSON.parse(t),r=s(),i={...r.agentsById};delete i[e.id];let a={...r.livenessMismatches};delete a[e.id];let o={...r.commandStalls};delete o[e.id],n({livenessMismatches:a,commandStalls:o}),n({agents:r.agents.filter(t=>t.id!==e.id),agentsById:i});return}if(e===`provider-quota.updated`){n({quotaSeq:s().quotaSeq+1});return}if(e===`message.claimed`){let e=JSON.parse(t);n({messages:s().messages.map(t=>t.id===e.messageId?{...t,claimedBy:e.claimedBy,claimExpiresAt:e.claimExpiresAt}:t)});return}if(e===`message.claim_released`){let e=JSON.parse(t);n({messages:s().messages.map(t=>t.id===e.messageId?{...t,claimedBy:void 0,claimedAt:void 0,claimExpiresAt:void 0}:t)});return}if(e===`message.deleted`){let e=JSON.parse(t);n({messages:s().messages.filter(t=>t.id!==e.messageId)});return}if(e===`orchestrator.status`){let e=JSON.parse(t);n({orchestrators:U(s().orchestrators,e)});return}if(e===`orchestrator.removed`){let e=JSON.parse(t);n({orchestrators:s().orchestrators.filter(t=>t.id!==e.id)});return}if(e===`policy.state.changed`||e===`config.changed`){s().fetchManagedPolicies();return}if(e===`command.dispatched`||e===`command.succeeded`){let r=JSON.parse(t).command;if(r){let t=lt(r,e);if(t){let e=typeof r.updatedAt==`number`?r.updatedAt:typeof r.createdAt==`number`?r.createdAt:Date.now();n({chatStatusEvents:W(s().chatStatusEvents,ct(r),t,e,r.id?`command:${r.id}:${t}`:void 0)})}}return}if([`task.created`,`task.updated`,`task.claimed`,`task.status`].includes(e)){let e=JSON.parse(t);n({tasks:U(s().tasks,e)})}}}})})},disconnectSSE(){let e=s()._es;e&&(e.close(),n({_es:null}))},openCommandPalette(){n({commandQuery:``,commandPaletteOpen:!0})},closeCommandPalette(){n({commandPaletteOpen:!1,commandQuery:``})},async runCommand(e){let{action:t,payload:r}=e;if(s().closeCommandPalette(),t===`openView`)await s().switchView(r.view);else if(t===`agentPreset`)n({showOffline:!0,agentPresetFilter:r.preset||``}),await s().switchView(`agents`);else if(t===`copy`)try{await navigator.clipboard?.writeText(r.value||``)}catch{}else if(t===`messageAgent`){let e=s().agentsById[r.agentId];e&&s().openComposeToAgent(e)}else t===`pairAgent`?s().openPairInvite(r.agentId):t===`filterTag`?(n({agentTagFilter:r.tag||``,tagFilter:r.tag||``}),await s().switchView(`agents`)):t===`exportActivity`&&s().exportActivity(r.format||`markdown`)},async saveTokenAndRefresh(){let e=s().authToken;a(e);try{await t(`GET`,`/stats`)}catch(e){if(e.status===401){n({authNeeded:!0});return}}n({authNeeded:!1,connectionError:!1}),s().connectSSE(),await s().refresh(),s().startAutoRefresh()},destroy(){o(null),s().disconnectSSE(),s().stopAutoRefresh(),s().stopClock()}}),Ot=(e,n)=>({users:[],usersById:{},presenceByAgent:{},async fetchUsers(){try{let r=await t(`GET`,`/users`),i=G(n().users,r);if(i===n().users)return;let a={};for(let e of i)a[e.id]=e;e({users:i,usersById:a})}catch{}},applyPresence(t,r){e({presenceByAgent:{...n().presenceByAgent,[t]:r}})},async announcePresence(e,r,i){try{let a=await t(`POST`,`/agents/`+encodeURIComponent(e)+`/presence`,{typing:r,...i?{leaving:!0}:{}});n().applyPresence(e,a.viewers??[])}catch{}}}),kt=(e,n)=>({agents:[],agentsById:{},showOffline:!1,showBuiltIns:!1,agentSort:`status`,agentSortDir:`asc`,agentPresetFilter:``,agentStatusFilter:``,agentTagFilter:``,agentHostFilter:``,selectedAgent:``,agentDetailOpen:!1,agentDetailId:``,livenessMismatches:{},commandStalls:{},channelDetailOpen:!1,channelDetailId:``,renameModal:{show:!1,agentId:``,label:``},tagFilter:``,async fetchAgents(){try{let r=await t(`GET`,`/agents`),i=G(n().agents,r);if(i===n().agents)return;e({agents:i,agentsById:rt(i)})}catch{}},openAgentDetail(t){e({agentDetailId:t.id,agentDetailOpen:!0})},closeAgentDetail(){e({agentDetailOpen:!1})},openChannelDetail(t){e({channelDetailId:t.id,channelDetailOpen:!0})},closeChannelDetail(){e({channelDetailOpen:!1})},openRename(t){e({renameModal:{show:!0,agentId:t.id,label:t.label||``}})},async doRename(){let r=n(),i=r.renameModal.label.trim()||null;try{await t(`PATCH`,`/agents/`+r.renameModal.agentId+`/label`,{label:i}),e({renameModal:{...r.renameModal,show:!1}})}catch(e){n().showError(`Rename Failed`,e.message)}},async doDeleteAgent(r){try{await t(`DELETE`,`/agents/`+r);let i=n(),a={...i.agentsById};delete a[r],e({agents:i.agents.filter(e=>e.id!==r),agentsById:a,selectedAgent:i.selectedAgent===r?``:i.selectedAgent})}catch(e){n().showError(`Delete Failed`,e.message)}},async doAgentAction(e,r,i){try{await t(`POST`,`/agents/`+encodeURIComponent(e.id)+`/actions`,{action:r,...i?{surface:{component:i}}:{}});let a=r===`restart`?`Restart`:r===`resume`?`Resume`:r===`shutdown`?`Shutdown`:r===`compact`?`Compact`:r===`clearContext`?`Clear context`:r;n().showNotification(`${a} command sent to ${te(e)}`),await Promise.all([n().fetchMessages(),n().fetchActivityEvents()])}catch(e){n().showError(`Action Failed`,e.message)}}}),q=300,J={messages:[],oldestLoadedId:null,hasMore:!0,loading:!1,loadedInitial:!1};function At(e,t){let n=new URLSearchParams;for(let[e,r]of Object.entries(t))n.set(e,String(r));return`/agents/${encodeURIComponent(e)}/chat?${n.toString()}`}function jt(e,t){return t.filter(t=>h(e,t)&&!ee(t)).sort((e,t)=>e.id-t.id)}function Mt(e,t){return G(e,[...e,...t].sort((e,t)=>e.id-t.id))}function Nt(e){return e[0]?.id??null}var Pt=12,Y=[];function Ft(e){let t=Y.indexOf(e);t!==-1&&Y.splice(t,1),Y.unshift(e)}function It(e,t){let n=new Set(t.filter(Boolean)),r=0;for(let t of Y){if(r>=Pt)break;e[t]?.loadedInitial&&(n.add(t),r++)}let i={};for(let[t,r]of Object.entries(e))(!r.loadedInitial||n.has(t))&&(i[t]=r);return i}var Lt=(e,n)=>({messages:[],agentChatByAgent:{},threadHistory:{},threadMessages:[],threadOpen:!1,chatHistoryImports:[],selectedInboxThread:``,replyTo:null,composeOpen:!1,showReasoning:!1,chatAgentSearch:``,chatAgentProviderFilter:``,chatAgentStatusFilter:``,chatAgentTagFilter:``,chatAgentCapFilter:``,chatAgentHostFilter:``,chatAgentSort:`status`,chatAgentSortDir:`asc`,chatAgentGroupBy:``,chatAgentFiltersCollapsed:!0,chatCollapsedChildren:[],feedObserveAll:!1,coordinatorFollows:[],coordinatorMutes:[],chatStatusEvents:{},chatStickToBottom:!0,chatHasNewItems:!1,inboxReadCursors:{},inboxArchivedThreads:{},inboxDrafts:{},chatSending:!1,inboxSearch:``,inboxSort:`attention`,inboxSortDir:`desc`,inboxShowArchived:!1,channelFilter:``,compose:{...m},inboxCompose:{...S},async fetchMessages(){try{let r=n(),i=`/messages?limit=100`;r.view===`messages`&&r.selectedAgent&&(i+=`&for=`+encodeURIComponent(r.selectedAgent)),r.view===`messages`&&r.channelFilter&&(i+=`&channel=`+encodeURIComponent(r.channelFilter));let a=await t(`GET`,i),o=dt(n().messages,a);e({messages:o});let s=n(),c=s.selectedInboxThread;if(pt(c,s)){let e=0;for(let t of o)t.id>e&&O(t)===c&&y(t)&&v(t)&&(e=t.id);e&&n().markInboxThreadReadTo(c,e)}}catch{}},async loadAgentChat(r){if(!r)return;Ft(r);let i=n().agentChatByAgent[r];if(!i?.loading){i?.loadedInitial&&i.messages.length>0||e(e=>({agentChatByAgent:{...e.agentChatByAgent,[r]:{...e.agentChatByAgent[r]??J,loading:!0}}}));try{let i=await t(`GET`,At(r,{limit:q})),a=jt(r,i),o=n().agentChatByAgent[r]??J,s=o.loadedInitial?Mt(o.messages,a):G([],a),c=o.loadedInitial?o.hasMore:i.length===q;e(e=>({agentChatByAgent:It({...e.agentChatByAgent,[r]:{messages:s,oldestLoadedId:Nt(s),hasMore:c,loading:!1,loadedInitial:!0}},[r,n().selectedAgent,n().selectedInboxThread])}))}catch(t){e(e=>({agentChatByAgent:{...e.agentChatByAgent,[r]:{...e.agentChatByAgent[r]??J,loading:!1}}})),n().showError(`Chat Load Failed`,t.message)}}},async loadOlder(r){if(!r)return;let i=n().agentChatByAgent[r];if(!i?.loadedInitial){await n().loadAgentChat(r);return}if(!(i.loading||!i.hasMore||i.oldestLoadedId===null)){e(e=>({agentChatByAgent:{...e.agentChatByAgent,[r]:{...i,loading:!0}}}));try{let a=await t(`GET`,At(r,{before:i.oldestLoadedId,limit:q})),o=jt(r,a),s=n().agentChatByAgent[r]??i,c=G(s.messages,[...o,...s.messages].sort((e,t)=>e.id-t.id));e(e=>({agentChatByAgent:{...e.agentChatByAgent,[r]:{messages:c,oldestLoadedId:Nt(c),hasMore:a.length===q,loading:!1,loadedInitial:!0}}}))}catch(t){e(e=>({agentChatByAgent:{...e.agentChatByAgent,[r]:{...e.agentChatByAgent[r]??i,loading:!1}}})),n().showError(`Chat Load Failed`,t.message)}}},async gapFillAgentChat(e){if(!e)return;let r=n().agentChatByAgent[e];if(!r?.loadedInitial||r.messages.length===0)return;let i=r.messages[r.messages.length-1].id;try{for(;;){let a=i,o=await t(`GET`,At(e,{since:i,limit:q}));if(o.length===0||(n().appendChatTail(e,o.filter(e=>e.id>a)),i=o[o.length-1].id,i<=a)||o.length<q)return;r=n().agentChatByAgent[e];let s=r?.messages[r.messages.length-1]?.id;s&&s>i&&(i=s)}}catch(t){console.warn(`[chat] gap-fill skipped for ${e}: ${t.message}`)}},appendChatTail(t,r){if(!t||r.length===0)return;let i=jt(t,r);if(i.length===0)return;let a=n().agentChatByAgent[t]??J,o=Mt(a.messages,i);e({agentChatByAgent:{...n().agentChatByAgent,[t]:{...a,messages:o,oldestLoadedId:Nt(o)}}})},async fetchThreadHistory(r){if(r)try{let i=await t(`GET`,`/messages?for=`+encodeURIComponent(r)+`&limit=500`);e({threadHistory:{...n().threadHistory,[r]:i}})}catch{}},async fetchChatHistoryImports(){try{e({chatHistoryImports:await t(`GET`,`/chat/history-imports?limit=500`)})}catch{}},async fetchInboxState(){try{let r=await t(`GET`,`/inbox/state?operatorId=user`),i={},a={},o={};for(let e of r?.threads||[])e.readCursorMessageId&&(i[e.peerId]=e.readCursorMessageId),e.archivedAtMessageId&&(a[e.peerId]=e.archivedAtMessageId);for(let e of r?.drafts||[])e.body&&(o[e.peerId]=e.body);let s=n().inboxDrafts;e({inboxReadCursors:i,inboxArchivedThreads:a,...Object.keys(s).length>0?{}:{inboxDrafts:o}})}catch{}},openCompose(){e({composeOpen:!0,compose:{...m,from:E}})},openComposeToAgent(t){e({replyTo:null,compose:{...m,from:E,to:t.id},composeOpen:!0})},async doSend(){let r=n();if(!r.compose.from||!r.compose.to||!r.compose.body){n().showError(`Validation`,`From, To, and Message are required.`);return}try{let i={from:r.compose.from,to:r.compose.to,body:r.compose.body};r.compose.channel&&(i.channel=r.compose.channel),r.compose.subject&&(i.subject=r.compose.subject),r.replyTo&&(i.replyTo=r.replyTo.id),r.compose.claimable&&(i.claimable=!0,i.kind=`task`,i.payload={title:r.compose.subject||`Claimable task`}),await t(`POST`,`/messages`,i),e({composeOpen:!1,replyTo:null,compose:{...m,from:E}}),await n().fetchMessages()}catch(e){n().showError(`Send Failed`,e.message)}},async doClaim(e){let r=n(),i=r.compose.from||r.selectedAgent;if(!i){n().showError(`Validation`,`Select an agent first.`);return}try{let r=await t(`POST`,`/messages/`+e+`/claim`,{agentId:i});r.ok||n().showError(`Claim Failed`,r.error||`unknown`),r.ok&&await Promise.all([n().fetchMessages(),n().fetchTasks()])}catch(e){n().showError(`Claim Failed`,e.message)}},async doDeliveryAction(e,r,i){try{await t(`POST`,`/messages/`+e+`/delivery/actions`,{action:r,reason:i,agentId:n().compose.from||n().selectedAgent||`user`}),await n().fetchMessages()}catch(e){n().showError(`Delivery Update Failed`,e.message)}},async doDeleteMessage(r){try{await t(`DELETE`,`/messages/`+r),e({messages:n().messages.filter(e=>e.id!==r)})}catch(e){n().showError(`Delete Failed`,e.message)}},applyChatMessageUpdate(t){let r=n().agentChatByAgent,i={};for(let[e,n]of Object.entries(r))n.messages.some(e=>e.id===t.id)&&(i[e]={...n,messages:n.messages.map(e=>e.id===t.id?t:e)});Object.keys(i).length!==0&&e({agentChatByAgent:{...r,...i}})},async reactToMessage(r,i){try{let a=(r.reactions||[]).some(e=>e.actorId===`user`&&e.emoji===i),o=await t(`POST`,`/messages/`+r.id+`/reactions`,{actorId:E,emoji:i,action:a?`remove`:`add`});e({messages:U(n().messages,o)}),n().applyChatMessageUpdate(o)}catch(e){n().showError(`Reaction Failed`,e.message)}},startReply(t){let n=t.from===`user`?t.to:t.from;e({replyTo:{id:t.id,from:t.from},compose:{...m,from:E,to:n,channel:t.channel||``},composeOpen:!0})},cancelReply(){e({replyTo:null})},async openThread(r){e({threadMessages:[],threadOpen:!0});try{e({threadMessages:await t(`GET`,`/messages/`+r+`/thread`)})}catch(e){n().showError(`Thread Load Failed`,e.message)}},openInboxThread(t,r=[]){e({selectedInboxThread:t}),r.length&&n().markInboxThreadRead(t,r),n().loadAgentChat(t)},async sendChatMessage(r,i,a=[]){if(!(!r.trim()&&a.length===0||n().chatSending)){e({chatSending:!0});try{if(n().agentsById[i.peer]?.providerCapabilities?.liveSession?.inject)await t(`POST`,`/agents/`+encodeURIComponent(i.peer)+`/prompt`,{body:r.trim()||`Attachment`,...a.length?{attachments:a}:{}});else{let e={from:E,to:i.peer,body:r.trim()||`Attachment`};i.lastMessage?.channel&&(e.channel=i.lastMessage.channel),i.lastMessage?.id&&(e.replyTo=i.lastMessage.id),a.length&&(e.payload={attachments:a}),await t(`POST`,`/messages`,e)}let o={...n().inboxDrafts};delete o[i.peer],e({inboxDrafts:o}),t(`DELETE`,`/inbox/drafts?operatorId=`+encodeURIComponent(C)+`&peerId=`+encodeURIComponent(i.peer)).catch(()=>{}),await Promise.all([n().fetchMessages(),n().loadAgentChat(i.peer)])}catch(e){n().showError(`Send Failed`,e.message)}e({chatSending:!1})}},async sendPermissionDecision(e,r,i,a){try{await t(`POST`,`/agents/`+encodeURIComponent(e)+`/permission-decision`,{approvalId:r,decision:i,...a?{answers:a}:{}});let o=i===`approve`?`Approved`:i===`approve-session`?`Approved for session`:i===`abort`?`Aborted`:i===`answer`?`Answer sent for`:`Denied`;n().showNotification(`${o} ${i===`answer`?`Claude's question`:`permission request`}`),await n().fetchAgents()}catch(e){n().showError(`Permission Failed`,e.message)}},markInboxThreadReadTo(r,i){!r||i<=(n().inboxReadCursors[r]||0)||(e({inboxReadCursors:{...n().inboxReadCursors,[r]:i}}),t(`PATCH`,`/inbox/threads`,{operatorId:C,peerId:r,readCursorMessageId:i}).catch(()=>{}))},markInboxThreadRead(e,t){!e||!t.length||n().markInboxThreadReadTo(e,gt(t))},markInboxThreadUnread(r){let i={...n().inboxReadCursors};delete i[r],e({inboxReadCursors:i}),t(`PATCH`,`/inbox/threads`,{operatorId:C,peerId:r,readCursorMessageId:null}).catch(()=>{})},archiveInboxThread(r,i){e({inboxArchivedThreads:{...n().inboxArchivedThreads,[r]:i}}),n().selectedInboxThread===r&&e({selectedInboxThread:``}),t(`PATCH`,`/inbox/threads`,{operatorId:C,peerId:r,archivedAtMessageId:i}).catch(()=>{})},unarchiveInboxThread(r){let i={...n().inboxArchivedThreads};delete i[r],e({inboxArchivedThreads:i}),t(`PATCH`,`/inbox/threads`,{operatorId:C,peerId:r,archivedAtMessageId:null}).catch(()=>{})},setReplyDraft(r,i){let a={...n().inboxDrafts};i?a[r]=i:delete a[r],e({inboxDrafts:a}),i?t(`PUT`,`/inbox/drafts`,{operatorId:C,peerId:r,body:i}).catch(()=>{}):t(`DELETE`,`/inbox/drafts?operatorId=`+encodeURIComponent(C)+`&peerId=`+encodeURIComponent(r)).catch(()=>{})},async sendInboxReply(r,i){let a=(n().inboxDrafts[r]||``).trim();if(!a||n().chatSending){a||n().showError(`Validation`,`Reply body is required.`);return}e({chatSending:!0});try{let o={from:E,to:r,body:a};i?.channel&&(o.channel=i.channel),i?.id&&(o.replyTo=i.id),await t(`POST`,`/messages`,o);let s={...n().inboxDrafts};delete s[r],e({inboxDrafts:s}),t(`DELETE`,`/inbox/drafts?operatorId=`+encodeURIComponent(C)+`&peerId=`+encodeURIComponent(r)).catch(()=>{}),await n().fetchMessages()}catch(e){n().showError(`Reply Failed`,e.message)}e({chatSending:!1})},toggleChatChildrenCollapsed(t){let r=n().chatCollapsedChildren;e({chatCollapsedChildren:r.includes(t)?r.filter(e=>e!==t):[...r,t]})},setFeedObserveAll(t){e({feedObserveAll:t})},toggleCoordinatorFollow(t){let r=n().coordinatorFollows,i=n().coordinatorMutes;r.includes(t)?e({coordinatorFollows:r.filter(e=>e!==t)}):e({coordinatorFollows:[...r,t],coordinatorMutes:i.filter(e=>e!==t)})},toggleCoordinatorMute(t){let r=n().coordinatorMutes,i=n().coordinatorFollows;r.includes(t)?e({coordinatorMutes:r.filter(e=>e!==t)}):e({coordinatorMutes:[...r,t],coordinatorFollows:i.filter(e=>e!==t)})},async doSendInboxCompose(){let r=n().inboxCompose,i=r.to;if(i){if(r.toMode===`tag`?i=`tag:`+i:r.toMode===`cap`&&(i=`cap:`+i),!r.body){n().showError(`Validation`,`Message is required.`);return}try{let a={from:E,to:i,body:r.body};r.channel&&(a.channel=r.channel),r.subject&&(a.subject=r.subject),r.claimable&&(a.claimable=!0,a.kind=`task`,a.payload={title:r.subject||`Claimable task`}),await t(`POST`,`/messages`,a),e({inboxCompose:{...S,toMode:r.toMode,to:r.to}}),await n().fetchMessages()}catch(e){n().showError(`Send Failed`,e.message)}}}});function X(e,t){return JSON.stringify([String(e),t||``])}function Z(e,t){return JSON.stringify([`team`,e,t||``])}function Rt(e){return{threadId:String(e.threadId),...e.channel?{channel:e.channel}:{}}}function zt(e){return e.teamId?{teamId:e.teamId,...e.channel?{channel:e.channel}:{}}:null}function Bt(e){return`teamId`in e?Z(e.teamId,e.channel):X(e.threadId,e.channel)}function Vt(e){let t=new URLSearchParams(`teamId`in e?{teamId:e.teamId}:{threadId:String(e.threadId)});return e.channel&&t.set(`channel`,e.channel),`/plans?${t.toString()}`}var Ht=(e,n)=>({plansById:{},plansByThread:{},plansByTeam:{},planLookups:{},planLoading:{},planCollapsed:null,setPlanCollapsed(t){e({planCollapsed:t})},async fetchPlan(r){let i=`teamId`in r?{teamId:r.teamId,...r.channel?{channel:r.channel}:{}}:{threadId:String(r.threadId),...r.channel?{channel:r.channel}:{}},a=Bt(i);e({planLookups:{...n().planLookups,[a]:i},planLoading:{...n().planLoading,[a]:!0}});try{let r=await t(`GET`,Vt(i)),o=Rt(r),s=X(o.threadId,o.channel),c=zt(r),l=c?Z(c.teamId,c.channel):``,u=!(`teamId`in i),d=`teamId`in i;e({plansById:{...n().plansById,[r.id]:r},plansByThread:{...n().plansByThread,...u?{[a]:r}:{},[s]:r},plansByTeam:c?{...n().plansByTeam,...d?{[a]:r}:{},[l]:r}:n().plansByTeam,planLookups:{...n().planLookups,[a]:i,[s]:o,...c?{[l]:c}:{}},planLoading:{...n().planLoading,[a]:!1,[s]:!1,...c?{[l]:!1}:{}}}),n().hydrateIssueRefsForPlan(r)}catch(t){let r=typeof t.status==`number`?t.status:0;e({plansByThread:r===404&&!(`teamId`in i)?{...n().plansByThread,[a]:null}:n().plansByThread,plansByTeam:r===404&&`teamId`in i?{...n().plansByTeam,[a]:null}:n().plansByTeam,planLoading:{...n().planLoading,[a]:!1}}),r&&r!==404&&n().showError(`Plan Load Failed`,t.message)}},async refreshPlans(){let e=Object.values(n().planLookups);await Promise.all(e.map(e=>n().fetchPlan(e)))},upsertPlan(t){let r=Rt(t),i=X(r.threadId,r.channel),a=zt(t),o=a?Z(a.teamId,a.channel):``;e({plansById:{...n().plansById,[t.id]:t},plansByThread:{...n().plansByThread,[i]:t},plansByTeam:a?{...n().plansByTeam,[o]:t}:n().plansByTeam,planLookups:{...n().planLookups,[i]:r,...a?{[o]:a}:{}},planLoading:{...n().planLoading,[i]:!1,...a?{[o]:!1}:{}}}),n().hydrateIssueRefsForPlan(t)},removePlan(t){let r=typeof t==`string`?t:t.id,i={...n().plansById};delete i[r],e({plansById:i,plansByThread:Object.fromEntries(Object.entries(n().plansByThread).filter(([,e])=>e?.id!==r)),plansByTeam:Object.fromEntries(Object.entries(n().plansByTeam).filter(([,e])=>e?.id!==r)),planLookups:Object.fromEntries(Object.entries(n().planLookups).filter(([e])=>n().plansByThread[e]?.id!==r&&n().plansByTeam[e]?.id!==r))})}}),Ut=(e,n)=>({teams:[],teamsLoading:!1,teamsError:null,teamOutcomeAggregates:null,teamOutcomeAggregatesLoading:!1,teamOutcomeAggregatesError:null,async fetchTeams(){e({teamsLoading:!0,teamsError:null});try{let r=await t(`GET`,`/teams`),i=G(n().teams,r.teams);return e({teams:i,teamsLoading:!1,teamsError:null}),i}catch(t){return e({teamsLoading:!1,teamsError:l(t)}),n().teams}},async fetchTeamOutcomeAggregates(){e({teamOutcomeAggregatesLoading:!0,teamOutcomeAggregatesError:null});try{let n=await t(`GET`,`/teams/outcomes`);return e({teamOutcomeAggregates:n,teamOutcomeAggregatesLoading:!1,teamOutcomeAggregatesError:null}),n}catch(t){return e({teamOutcomeAggregatesLoading:!1,teamOutcomeAggregatesError:l(t)}),n().teamOutcomeAggregates}},upsertTeam(t){let r=U(n().teams,t);r!==n().teams&&e({teams:r})},markTeamDissolved(t){let r=Date.now();e({teams:n().teams.map(e=>e.id===t.teamId?{...e,status:`dissolved`,updatedAt:r,dissolvedAt:e.dissolvedAt??r,zeroMembersSince:void 0,...t.outcomeStatus?{outcomeStatus:t.outcomeStatus}:{},...t.reason?{outcomeSummary:t.reason}:{}}:e)})},async dissolveTeam(e){try{let r=await t(`POST`,`/teams/${encodeURIComponent(e)}/dissolve`,{});n().upsertTeam(r),n().showNotification(`Team dissolved`),await Promise.all([n().fetchTeams(),n().fetchTeamOutcomeAggregates(),n().fetchActivityEvents()])}catch(e){n().showError(`Dissolve Failed`,l(e))}}});function Wt(e,t){return JSON.stringify([e,t])}function Gt(e){return[...new Set(e.nodes.map(e=>e.refs?.issueId).filter(e=>!!e))]}function Q(e,t){let n=!1,r={...e};for(let i of t){let t=e[i.id];(!t||JSON.stringify(t)!==JSON.stringify(i))&&(r[i.id]=i,n=!0)}return n?r:e}var Kt=(e,n)=>({issueRefsById:{},issuesByEntity:{},issueActivityByAgent:{},issueLoading:{},issueErrors:{},async fetchIssueRef(r){let i=`ref:${r}`;e({issueLoading:{...n().issueLoading,[i]:!0},issueErrors:{...n().issueErrors,[i]:null}});try{let a=await t(`GET`,`/issue-refs/${encodeURIComponent(r)}`);return e({issueRefsById:Q(n().issueRefsById,[a.issueRef]),issueLoading:{...n().issueLoading,[i]:!1}}),a.issueRef}catch(t){return e({issueLoading:{...n().issueLoading,[i]:!1},issueErrors:{...n().issueErrors,[i]:l(t)}}),n().issueRefsById[r]??null}},async fetchIssuesForEntity(r,i){let a=Wt(r,i);e({issueLoading:{...n().issueLoading,[a]:!0},issueErrors:{...n().issueErrors,[a]:null}});try{let o=await t(`GET`,`/issue-associations/entities/${encodeURIComponent(r)}/${encodeURIComponent(i)}/issues`);return e({issuesByEntity:{...n().issuesByEntity,[a]:o.issues},issueRefsById:Q(n().issueRefsById,o.issues.map(e=>e.issueRef)),issueLoading:{...n().issueLoading,[a]:!1}}),o.issues}catch(t){return e({issueLoading:{...n().issueLoading,[a]:!1},issueErrors:{...n().issueErrors,[a]:l(t)}}),n().issuesByEntity[a]??[]}},async fetchAgentIssueActivity(r){let i=`agent:${r}`;e({issueLoading:{...n().issueLoading,[i]:!0},issueErrors:{...n().issueErrors,[i]:null}});try{let a=await t(`GET`,`/issue-activity/agents/${encodeURIComponent(r)}`);return e({issueActivityByAgent:{...n().issueActivityByAgent,[r]:a.issues},issueRefsById:Q(n().issueRefsById,a.issues.map(e=>e.issueRef)),issueLoading:{...n().issueLoading,[i]:!1}}),a.issues}catch(t){return e({issueLoading:{...n().issueLoading,[i]:!1},issueErrors:{...n().issueErrors,[i]:l(t)}}),n().issueActivityByAgent[r]??[]}},async hydrateIssueRefsForPlan(e){let t=Gt(e).filter(e=>!n().issueRefsById[e]);await Promise.all(t.map(e=>n().fetchIssueRef(e)))},async refreshIssueRefs(){let e=Object.keys(n().issueRefsById).map(e=>n().fetchIssueRef(e)),t=Object.keys(n().issuesByEntity).map(e=>{try{let[t,r]=JSON.parse(e);return n().fetchIssuesForEntity(t,r)}catch{return Promise.resolve([])}});await Promise.all([...e,...t])},upsertIssueRef(t){let r=Q(n().issueRefsById,[t]);r!==n().issueRefsById&&e({issueRefsById:r})}}),qt=(e,n)=>({pairs:[],tasks:[],taskEvents:[],taskEventCache:{},taskEventsOpen:!1,pairInviteOpen:!1,pairMessageOpen:!1,pairInvite:{...D},pairMessage:{...w},pairStatusFilter:`open`,taskStatusFilter:``,taskSourceFilter:``,async fetchPairs(){try{let r=n(),i;if(r.view===`activity`)i=await t(`GET`,`/pairs`);else if(r.pairStatusFilter===`open`){let[e,n]=await Promise.all([t(`GET`,`/pairs?status=active`),t(`GET`,`/pairs?status=pending`)]);i=[...e,...n]}else i=r.pairStatusFilter?await t(`GET`,`/pairs?status=`+encodeURIComponent(r.pairStatusFilter)):await t(`GET`,`/pairs`);let a=i.sort((e,t)=>new Date(t.updatedAt).getTime()-new Date(e.updatedAt).getTime()),o=G(n().pairs,a);o!==n().pairs&&e({pairs:o})}catch{}},async fetchTasks(){try{let r=n(),i=new URLSearchParams({limit:`100`});r.taskStatusFilter&&i.set(`status`,r.taskStatusFilter),r.taskSourceFilter&&i.set(`source`,r.taskSourceFilter);let a=G(n().tasks,await t(`GET`,`/tasks?`+i.toString()));a!==n().tasks&&e({tasks:a})}catch{}},async doClaimTask(e){let r=n(),i=r.compose.from||r.selectedAgent;if(!i){n().showError(`Validation`,`Select an agent first.`);return}try{let r=await t(`POST`,`/tasks/`+e+`/claim`,{agentId:i});r.ok?await Promise.all([n().fetchTasks(),n().fetchMessages()]):n().showError(`Claim Failed`,r.error||`unknown`)}catch(e){n().showError(`Claim Failed`,e.message)}},async doUpdateTaskStatus(r,i){if(!(!r||!i||i===r.status))try{let a={status:i},o=r.claimedBy||n().compose.from||n().selectedAgent;o&&(a.agentId=o);let s=await t(`PATCH`,`/tasks/`+r.id+`/status`,a),c=s.task||s;if(e({tasks:n().tasks.map(e=>e.id===r.id?c:e)}),s.memoryEvent){let t=n().taskEventCache[r.id]||[];e({taskEventCache:{...n().taskEventCache,[r.id]:[...t,s.memoryEvent]},...n().taskEventsOpen?{taskEvents:[...n().taskEvents,s.memoryEvent]}:{}})}s.memory&&n().showNotification(`Memory captured: ${s.memory.title}`)}catch(e){n().showError(`Status Update Failed`,e.message),await n().fetchTasks()}},async openTaskEvents(r){e({taskEvents:[],taskEventsOpen:!0});try{let i=await t(`GET`,`/tasks/`+r.id+`/events`);e({taskEvents:i,taskEventCache:{...n().taskEventCache,[r.id]:i}})}catch(e){n().showError(`Task Events Failed`,e.message)}},openPairInvite(t){e({pairInvite:{...D,requesterId:t||n().selectedAgent||``},pairInviteOpen:!0})},closePairInvite(){e({pairInviteOpen:!1,pairInvite:{...D}})},async doCreatePair(){let r=n();if(!r.pairInvite.requesterId||!r.pairInvite.targetId){n().showError(`Validation`,`Requester and Target are required.`);return}if(r.pairInvite.requesterId===r.pairInvite.targetId){n().showError(`Validation`,`Requester and Target must be different.`);return}try{let i={from:r.pairInvite.requesterId,target:r.pairInvite.targetId};r.pairInvite.objective&&(i.objective=r.pairInvite.objective),await t(`POST`,`/pairs`,i),e({pairInviteOpen:!1,pairInvite:{...D}}),await Promise.all([n().fetchPairs(),n().fetchMessages()])}catch(e){n().showError(`Pair Invite Failed`,e.message)}},openPairMessage(t,n){e({pairMessage:{...w,pairId:t.id,from:n||t.requesterId},pairMessageOpen:!0})},closePairMessage(){e({pairMessageOpen:!1,pairMessage:{...w}})},async doSendPairMessage(){let r=n();if(!r.pairMessage.pairId||!r.pairMessage.from||!r.pairMessage.body){n().showError(`Validation`,`Pair, From, and Message are required.`);return}try{let i={from:r.pairMessage.from,body:r.pairMessage.body};r.pairMessage.subject&&(i.subject=r.pairMessage.subject),await t(`POST`,`/pairs/`+encodeURIComponent(r.pairMessage.pairId)+`/messages`,i),e({pairMessageOpen:!1,pairMessage:{...w}}),await Promise.all([n().fetchPairs(),n().fetchMessages()])}catch(e){n().showError(`Pair Message Failed`,e.message)}},async doAcceptPair(e){try{await t(`POST`,`/pairs/`+encodeURIComponent(e.id)+`/accept`,{agentId:e.targetId}),await Promise.all([n().fetchPairs(),n().fetchMessages()])}catch(e){n().showError(`Accept Failed`,e.message)}},async doRejectPair(e){try{await t(`POST`,`/pairs/`+encodeURIComponent(e.id)+`/reject`,{agentId:e.targetId}),await Promise.all([n().fetchPairs(),n().fetchMessages()])}catch(e){n().showError(`Reject Failed`,e.message)}},async doHangupPair(e,r){try{await t(`POST`,`/pairs/`+encodeURIComponent(e.id)+`/hangup`,{agentId:r||e.requesterId}),await Promise.all([n().fetchPairs(),n().fetchMessages()])}catch(e){n().showError(`Hang Up Failed`,e.message)}}}),Jt=(e,n)=>({orchestrators:[],providerCatalog:[],orchestratorSpawnOpen:!1,orchestratorInstallOpen:!1,spawnOrchId:``,spawnProvider:R(void 0),spawnModel:B(R(void 0)),spawnEffort:``,spawnProfile:`default-relay`,spawnCwd:``,spawnLabel:``,spawnApproval:`guarded`,spawnWorkspaceMode:`inherit`,spawnPrompt:``,spawnSystemPromptAppend:``,spawnCount:1,spawnCwdHistory:[],isSpawning:!1,spawnDirBrowser:{open:!1,loading:!1,path:``,parent:``,baseDir:``,entries:[],error:``},pendingForkImport:null,async fetchOrchestrators(){try{let r=G(n().orchestrators,await t(`GET`,`/orchestrators`));r!==n().orchestrators&&e({orchestrators:r})}catch{}},async fetchProviderCatalog(){try{e({providerCatalog:(await t(`GET`,`/providers`)).catalog})}catch{}},async refreshOrchestratorProviders(e){try{await t(`GET`,`/orchestrators/`+encodeURIComponent(e)+`/providers?refresh=1`),await n().fetchOrchestrators(),n().showNotification(`Provider status refreshed`)}catch(e){n().showError(`Provider Refresh Failed`,e.message)}},openAgentSpawn(){n().openOrchestratorSpawn()},closeAgentSpawn(){e({orchestratorSpawnOpen:!1})},async doSpawnAgent(){await n().submitOrchestratorSpawn()},openOrchestratorSpawn(){n().openOrchestratorSpawnAt()},openOrchestratorSpawnAt(t={}){let r=n().orchestrators.filter(e=>e.status===`online`);if(!r.length){n().showError(`No Orchestrators`,`No orchestrators are currently online.`);return}n().fetchProviderCatalog();let i=n(),a=t.orchestratorId?r.find(e=>e.id===t.orchestratorId):void 0;if(t.orchestratorId&&!a){n().showError(`Orchestrator Offline`,`The selected orchestrator is not online.`);return}let o=t.cwd?.trim()||i.spawnCwd,s=o?r.find(e=>_(o,e.baseDir)):void 0,c=i.spawnOrchId?r.find(e=>e.id===i.spawnOrchId):void 0,l=a?.id||s?.id||c?.id||r[0].id,u=r.find(e=>e.id===l),d=i.spawnProvider&&u.providers.includes(i.spawnProvider)?i.spawnProvider:R(u),f=i.spawnProvider===d&&i.spawnModel&&z(d,i.providerCatalog).some(e=>e.alias===i.spawnModel)?i.spawnModel:B(d,i.providerCatalog),p=o&&_(o,u.baseDir)?o:u.baseDir||``;e({spawnOrchId:l,spawnProvider:d,spawnModel:f,spawnEffort:i.spawnProvider===d&&i.spawnModel===f?i.spawnEffort:``,spawnProfile:i.spawnProfile||`default-relay`,spawnCwd:p,spawnLabel:``,spawnWorkspaceMode:`inherit`,spawnPrompt:``,spawnSystemPromptAppend:``,spawnCount:1,pendingForkImport:null,orchestratorSpawnOpen:!0})},forkFromAgent(t,r){let i=n(),a=i.agentsById[t];if(!a){n().showError(`Fork`,`Agent not found.`);return}let o=i.orchestrators.filter(e=>e.status===`online`);if(!o.length){n().showError(`No Orchestrators`,`No orchestrators are currently online.`);return}n().fetchProviderCatalog();let s=a.providerCapabilities,c=s?.model?.provider||(typeof a.meta?.provider==`string`?a.meta.provider:``),l=s?.model?.alias||s?.model?.id||``,u=(c?L(c,i.providerCatalog):void 0)?.models.find(e=>e.alias===l||e.providerModel===l)?.alias||``,d=s?.model?.effort||``,m=a.meta?.workspace,h=f(m)?m:{},ee=p(h.repoRoot)||p(h.sourceCwd)||(typeof a.meta?.cwd==`string`?a.meta.cwd:``),g=p(h.mode),v=g===`isolated`?`isolated`:g===`shared`?`shared`:`inherit`,y=s?.session?.approvalMode||(typeof a.meta?.approvalMode==`string`?a.meta.approvalMode:`guarded`),b=a.label?`${a.label} (fork)`:``,x=o.find(e=>e.hostname===a.machine)||o.find(e=>_(ee,e.baseDir))||o[0],S=te(a),C=[];for(let e of r){let t=ne(e).trim();if(!t)continue;let n=e.from===`user`?`user`:`agent`;C.push(`[${n}]: ${t}`)}let w=C.join(`
6
- `),T=14e3,re=`You are continuing work from a previous agent session (${S}). Below is the conversation history. Treat it as context for your work, not as your own actions.\n\n${w.length>T?`...
7
- `+w.slice(w.length-T):w}`,E=r.filter(e=>typeof e.id==`number`&&e.id>0).map(e=>e.id);e({spawnOrchId:x.id,spawnProvider:c||R(x),spawnModel:u||B(c||R(x)),spawnEffort:d,spawnProfile:i.spawnProfile||`default-relay`,spawnCwd:ee||x.baseDir||``,spawnLabel:b,spawnApproval:y,spawnWorkspaceMode:v,spawnPrompt:`Continue from this previous session.`,spawnSystemPromptAppend:re,spawnCount:1,pendingForkImport:{sourcePeerId:a.id,sourceAgentId:a.id,sourceThreadId:a.id,sourceAgentLabel:S,messageIds:E},orchestratorSpawnOpen:!0})},openOrchestratorInstall(){e({orchestratorInstallOpen:!0})},openOrchestratorSpawnFor(t){let r=n(),i=r.orchestrators.find(e=>e.id===t),a=R(i),o=B(a,r.providerCatalog),s=r.spawnProvider===a&&r.spawnModel===o?r.spawnEffort:``,c=r.spawnCwd&&_(r.spawnCwd,i?.baseDir)?r.spawnCwd:i?.baseDir||``;e({spawnOrchId:t,spawnProvider:a,spawnModel:o,spawnEffort:s,spawnProfile:r.spawnProfile||`default-relay`,spawnCwd:c,spawnLabel:``,spawnWorkspaceMode:`inherit`,spawnPrompt:``,spawnSystemPromptAppend:``,spawnCount:1,pendingForkImport:null,orchestratorSpawnOpen:!0})},selectSpawnHistory(t,r){let i=n(),a=i.orchestrators.find(e=>e.id===t&&e.status===`online`);if(!a){n().showError(`Unavailable`,`That orchestrator is no longer online.`);return}if(t===i.spawnOrchId){e({spawnCwd:r});return}let o=i.spawnProvider&&a.providers.includes(i.spawnProvider)?i.spawnProvider:R(a),s=i.spawnProvider===o&&i.spawnModel&&z(o,i.providerCatalog).some(e=>e.alias===i.spawnModel)?i.spawnModel:B(o,i.providerCatalog);e({spawnOrchId:t,spawnProvider:o,spawnModel:s,spawnEffort:i.spawnProvider===o&&i.spawnModel===s?i.spawnEffort:``,spawnCwd:r})},async submitOrchestratorSpawn(){let r=n();if(r.isSpawning)return;if(!r.spawnOrchId){n().showError(`Validation`,`Select an orchestrator.`);return}let i=r.orchestrators.find(e=>e.id===r.spawnOrchId);if(!i){n().showError(`Validation`,`Selected orchestrator is not available.`);return}let a=r.spawnCwd.trim();if(!a){n().showError(`Validation`,`Select a working directory.`);return}if(!_(a,i.baseDir)){n().showError(`Validation`,`Working directory must be under ${i.baseDir}.`);return}let o=r.pendingForkImport,s=o?1:Math.max(1,Math.min(10,Math.round(r.spawnCount)||1));e({isSpawning:!0});try{for(let e=0;e<s;e++){let n={provider:r.spawnProvider,orchestratorId:r.spawnOrchId,approvalMode:r.spawnApproval,workspaceMode:r.spawnWorkspaceMode||`inherit`};r.spawnModel&&(n.model=r.spawnModel),r.spawnEffort&&(n.effort=r.spawnEffort),r.spawnProfile&&(n.profile=r.spawnProfile),n.cwd=a,r.spawnLabel&&(n.label=s>1?`${r.spawnLabel} ${e+1}`:r.spawnLabel),r.spawnPrompt&&(n.prompt=r.spawnPrompt),r.spawnSystemPromptAppend&&(n.systemPromptAppend=r.spawnSystemPromptAppend);let i=(await t(`POST`,`/agents/spawn`,n)).command?.params?.spawnRequestId;o&&i&&o.messageIds.length>0&&await t(`POST`,`/chat/history-imports`,{targetSpawnRequestId:i,sourcePeerId:o.sourcePeerId,sourceAgentId:o.sourceAgentId,sourceThreadId:o.sourceThreadId,sourceAgentLabel:o.sourceAgentLabel,importedBy:C,messageIds:o.messageIds})}e({orchestratorSpawnOpen:!1,pendingForkImport:null,isSpawning:!1,spawnCwdHistory:[{orchId:r.spawnOrchId,cwd:a},...r.spawnCwdHistory.filter(e=>!(e.orchId===r.spawnOrchId&&e.cwd===a))].slice(0,5)}),await Promise.all([n().fetchAgents(),n().fetchOrchestrators(),n().fetchActivityEvents(),n().fetchChatHistoryImports()])}catch(t){e({isSpawning:!1}),n().showError(`Spawn Failed`,t.message)}},orchestratorAction(e,r,i,a){let o=r===`restart`?`Restart`:`Shutdown`,s=i?`agent "${i}"`:`all agents`;n().openConfirm(`${o} Agent`,`${o} ${s} on orchestrator "${e}"?`,async()=>{try{await t(`POST`,`/orchestrators/`+encodeURIComponent(e)+`/actions`,{action:r,agentId:i,...a?{surface:{component:a}}:{}}),await Promise.all([n().fetchOrchestrators(),n().fetchActivityEvents()])}catch(e){n().showError(`${o} Failed`,e.message)}})},upgradeOrchestrator(e,r){let i=r?` to v${r}`:` to match the relay`;n().openConfirm(`Upgrade Orchestrator`,`Upgrade "${e}"${i}? It will install the new version and restart itself.`,async()=>{try{await t(`POST`,`/orchestrators/`+encodeURIComponent(e)+`/actions`,{action:`upgrade`,...r?{targetVersion:r}:{}}),await Promise.all([n().fetchOrchestrators(),n().fetchActivityEvents()])}catch(e){n().showError(`Upgrade Failed`,e.message)}})},deleteOrchestrator(e){n().openConfirm(`Remove Orchestrator`,`Remove orchestrator "${e}"?`,async()=>{try{await t(`DELETE`,`/orchestrators/`+encodeURIComponent(e)),await Promise.all([n().fetchOrchestrators(),n().fetchActivityEvents()])}catch(e){n().showError(`Delete Failed`,e.message)}})},async browseSpawnDirectory(r){let i=n().spawnOrchId;if(!i)return;let a=n().spawnDirBrowser;e({spawnDirBrowser:{...a,loading:!0,error:``}});try{let a=r?`?path=`+encodeURIComponent(r):``,o=await t(`GET`,`/orchestrators/`+encodeURIComponent(i)+`/directories`+a);e({spawnDirBrowser:{open:!0,loading:!1,path:o.path||``,parent:o.parent||``,baseDir:o.baseDir||``,entries:o.entries||[],error:``},spawnCwd:o.path||n().spawnCwd})}catch(t){e({spawnDirBrowser:{...n().spawnDirBrowser,loading:!1,error:t.message}})}},selectSpawnDirectory(t){e({spawnCwd:t||n().spawnDirBrowser.path,spawnDirBrowser:{...n().spawnDirBrowser,open:!1}})}}),Yt=(e,n)=>({managedPolicies:[],policyModal:{open:!1,editing:``,name:``,description:``,orchestratorId:``,cwd:``,enabled:void 0,provider:R(void 0),rig:``,model:B(R(void 0)),effort:``,profile:`default-relay`,providerArgs:``,prompt:``,tags:``,capabilities:``,label:``,mode:`always-on`,permissionMode:`guarded`,restartOnUpdate:!0,scheduledDailyRestart:!1,keepaliveSeconds:`300`,backoffSchedule:`5,15,60,300`,backoffResetAfterSeconds:`600`,channelId:``},policyDirBrowser:{open:!1,loading:!1,path:``,parent:``,baseDir:``,entries:[],error:``},agentProfiles:[],profileModal:{open:!1,mode:`create`,profile:{name:``,description:``,provider:`any`,base:`host`,instructions:{system:``,append:[],repoInstructions:`allow`,globalInstructions:`allow`},relay:{context:!0,skills:!0,plugins:!0,statusLine:!0,mcp:!0},skills:[],plugins:[],mcp:{mode:`host`},hooks:{mode:`host`},permissions:{filesystem:`host`},env:{},providerOptions:{}}},async fetchManagedPolicies(){try{e({managedPolicies:await t(`GET`,`/spawn-policies/health`)})}catch{}},async fetchAgentProfiles(){try{e({agentProfiles:(await t(`GET`,`/agent-profiles`)).map(e=>e.value)})}catch{}},openPolicyCreate(){let t=n().orchestrators.filter(e=>e.status===`online`);if(!t.length){n().showError(`No Orchestrators`,`No orchestrators are currently online.`);return}n().fetchProviderCatalog(),e({policyModal:{open:!0,editing:``,name:``,description:``,orchestratorId:t[0].id,cwd:``,enabled:void 0,provider:R(t[0]),rig:``,model:B(R(t[0]),n().providerCatalog),effort:``,profile:`default-relay`,providerArgs:``,prompt:``,tags:``,capabilities:``,label:``,mode:`always-on`,permissionMode:`guarded`,restartOnUpdate:!0,scheduledDailyRestart:!1,keepaliveSeconds:`300`,backoffSchedule:`5,15,60,300`,backoffResetAfterSeconds:`600`,channelId:``},policyDirBrowser:{open:!1,loading:!1,path:``,parent:``,baseDir:``,entries:[],error:``}})},openPolicyEdit(t){n().fetchProviderCatalog(),e({policyModal:{open:!0,editing:t.name,name:t.name,enabled:t.enabled,description:t.description||``,orchestratorId:t.orchestratorId,cwd:t.cwd,provider:t.provider,rig:t.rig||``,model:t.model||B(t.provider,n().providerCatalog),effort:t.effort||``,profile:t.profile||`default-relay`,providerArgs:(t.providerArgs||[]).join(` `),prompt:t.prompt||``,tags:(t.tags||[]).join(`, `),capabilities:(t.capabilities||[]).join(`, `),label:t.label||``,mode:t.mode,permissionMode:t.permissionMode,restartOnUpdate:t.restartOnUpdate,scheduledDailyRestart:t.scheduledDailyRestart,keepaliveSeconds:String(t.onDemand?.keepaliveSeconds??300),backoffSchedule:(t.backoff?.schedule||[5,15,60,300]).join(`, `),backoffResetAfterSeconds:String(t.backoff?.resetAfterSeconds??600),channelId:t.binding?.channelId||``},policyDirBrowser:{open:!1,loading:!1,path:``,parent:``,baseDir:``,entries:[],error:``}})},async submitPolicy(){let r=n().policyModal;if(!r.name.trim()){n().showError(`Validation`,`Policy name is required.`);return}if(!r.orchestratorId){n().showError(`Validation`,`Select an orchestrator.`);return}if(!r.cwd.trim()){n().showError(`Validation`,`Working directory is required.`);return}let i=e=>e.split(/[,\s]+/).map(e=>e.trim()).filter(Boolean),a={name:r.name.trim(),...r.description.trim()?{description:r.description.trim()}:{},...r.enabled===void 0?{}:{enabled:r.enabled},orchestratorId:r.orchestratorId,cwd:r.cwd.trim(),provider:r.provider,...r.rig.trim()?{rig:r.rig.trim()}:{},...r.model?{model:r.model}:{},...r.effort?{effort:r.effort}:{},...r.profile?{profile:r.profile}:{},providerArgs:r.providerArgs.trim()?r.providerArgs.trim().split(/\s+/):[],...r.prompt.trim()?{prompt:r.prompt.trim()}:{},tags:i(r.tags),capabilities:i(r.capabilities),...r.label.trim()?{label:r.label.trim()}:{},mode:r.mode,permissionMode:r.permissionMode,restartOnUpdate:r.restartOnUpdate,scheduledDailyRestart:r.scheduledDailyRestart,...r.mode===`on-demand`?{onDemand:{keepaliveSeconds:Number(r.keepaliveSeconds)||300,idleDefinition:`no-activity`}}:{},backoff:{schedule:i(r.backoffSchedule).map(Number).filter(e=>e>0),resetAfterSeconds:Number(r.backoffResetAfterSeconds)||600},...r.channelId.trim()?{binding:{type:`channel`,channelId:r.channelId.trim()}}:{}};a.backoff.schedule.length||(a.backoff.schedule=[5,15,60,300]);try{await t(`PUT`,`/spawn-policy/`+encodeURIComponent(a.name),a),e({policyModal:{...r,open:!1}}),await n().fetchManagedPolicies()}catch(e){n().showError(`Save Failed`,e.message)}},deletePolicy(e){n().openConfirm(`Delete Policy`,`Delete managed agent policy "${e}"? This will stop any running agent.`,async()=>{try{await t(`DELETE`,`/spawn-policy/`+encodeURIComponent(e)),await n().fetchManagedPolicies()}catch(e){n().showError(`Delete Failed`,e.message)}})},async browsePolicyDirectory(r){let i=n().policyModal.orchestratorId;if(!i)return;let a=n().policyDirBrowser;e({policyDirBrowser:{...a,loading:!0,error:``}});try{let a=r?`?path=`+encodeURIComponent(r):``,o=await t(`GET`,`/orchestrators/`+encodeURIComponent(i)+`/directories`+a);e({policyDirBrowser:{open:!0,loading:!1,path:o.path||``,parent:o.parent||``,baseDir:o.baseDir||``,entries:o.entries||[],error:``},policyModal:{...n().policyModal,cwd:o.path||n().policyModal.cwd}})}catch(t){e({policyDirBrowser:{...n().policyDirBrowser,loading:!1,error:t.message}})}},selectPolicyDirectory(t){e({policyModal:{...n().policyModal,cwd:t||n().policyDirBrowser.path},policyDirBrowser:{...n().policyDirBrowser,open:!1}})},openProfileModal(t,n){let r={name:``,description:``,provider:`any`,base:`host`,instructions:{system:``,append:[],repoInstructions:`allow`,globalInstructions:`allow`},relay:{context:!0,skills:!0,plugins:!0,statusLine:!0,mcp:!0},skills:[],plugins:[],mcp:{mode:`host`},hooks:{mode:`host`},permissions:{filesystem:`host`},env:{},providerOptions:{}},i;n&&t===`duplicate`?(i=JSON.parse(JSON.stringify(n)),i.name=n.name+`-copy`,delete i.builtIn):i=n&&(t===`edit`||t===`view`)?JSON.parse(JSON.stringify(n)):r,e({profileModal:{open:!0,mode:t,profile:i}})},closeProfileModal(){e({profileModal:{...n().profileModal,open:!1}})},updateProfileModal(t){let r=n().profileModal.profile;e({profileModal:{...n().profileModal,profile:{...r,...t}}})},async saveProfile(){let{mode:r,profile:i}=n().profileModal;if(!i.name.trim()){n().showError(`Validation`,`Profile name is required.`);return}if(r!==`view`)try{await t(`PUT`,`/agent-profiles/`+encodeURIComponent(i.name.trim()),i),e({profileModal:{...n().profileModal,open:!1}}),await n().fetchAgentProfiles(),n().showNotification(`Profile "${i.name}" saved`)}catch(e){n().showError(`Save Failed`,e.message)}},deleteProfile(e){let r=typeof e==`string`?n().agentProfiles.find(t=>t.name===e):e,i=typeof e==`string`?e:e.name,a=r?.builtIn===!0;n().openConfirm(a?`Reset Profile`:`Delete Profile`,a?`Reset built-in profile "${i}" to its default?`:`Delete agent profile "${i}"?`,async()=>{try{await t(`DELETE`,`/agent-profiles/`+encodeURIComponent(i)),await n().fetchAgentProfiles(),n().showNotification(a?`Profile "${i}" reset to default`:`Profile "${i}" deleted`)}catch(e){n().showError(`Delete Failed`,e.message)}})}}),Xt=(e,n)=>({operatorActivity:[],recordOperatorActivity(r){let i={id:Date.now(),kind:`operator`,title:r.title||`Activity`,body:r.body,meta:r.meta,icon:r.icon,view:r.view,peer:r.peer,messageId:r.messageId,pairId:r.pairId,taskId:r.taskId,agentId:r.agentId,ts:Date.now(),clientId:`op-`+Date.now(),createdAt:Date.now()};e({operatorActivity:[i,...n().operatorActivity.slice(0,79)]}),t(`POST`,`/activity`,{operatorId:C,clientId:i.clientId,kind:i.kind,title:i.title,body:i.body,meta:i.meta,icon:i.icon,view:i.view,peer:i.peer,messageId:i.messageId,pairId:i.pairId,taskId:i.taskId,agentId:i.agentId}).catch(()=>{})},async openActivityItem(e){if(e.view&&await n().switchView(e.view===`inbox`?`chat`:e.view),e.peer&&n().openInboxThread(e.peer),e.agentId){let t=n().agentsById[e.agentId];t&&n().openAgentDetail(t)}if(e.taskId){let t=n().tasks.find(t=>t.id===e.taskId);t&&await n().openTaskEvents(t)}}});function Zt(e){return re(e.createdAt??e.ts)}function Qt(e,t){let n=[`# Agent Relay Timeline`,``,`Exported: ${t}`,`Events: ${e.length}`,``];for(let t of e){let e=new Date(Zt(t)).toISOString();n.push(`## ${t.title||t.kind||`Event`}`),n.push(`- When: ${e}`),t.kind&&n.push(`- Kind: ${t.kind}`),t.agentId&&n.push(`- Agent: ${t.agentId}`),t.peer&&n.push(`- Peer: ${t.peer}`),t.body&&n.push(``,t.body),n.push(``)}return n.join(`
8
- `)}var $t=(e,n)=>({activityEvents:[],activityFilter:``,async fetchActivityEvents(){try{e({activityEvents:await t(`GET`,`/activity?limit=200`)})}catch{}},exportActivity(e){let t=n(),r=[...t.operatorActivity,...t.activityEvents].sort((e,t)=>Zt(t)-Zt(e)),i=new Date().toISOString(),a=`agent-relay-timeline-${i.slice(0,10)}.${e===`json`?`json`:`md`}`;e===`json`?T(a,JSON.stringify({title:`Agent Relay Timeline`,exportedAt:i,events:r},null,2),`application/json`):T(a,Qt(r,i),`text/markdown`)},exportThread(e,t){let n=`agent-relay-thread-${b(e.peer)}.${t===`json`?`json`:`md`}`,r={title:`Thread: `+e.peer,importedHistory:e.importedHistory||[],messages:e.messages,exportedAt:new Date().toISOString()};T(n,JSON.stringify(r,null,2),t===`json`?`application/json`:`text/markdown`)},exportPair(e,t){let n=`agent-relay-pair-${b(e.id)}.${t===`json`?`json`:`md`}`,r={title:`Pair: `+e.id,pair:e,exportedAt:new Date().toISOString()};T(n,JSON.stringify(r,null,2),t===`json`?`application/json`:`text/markdown`)},async exportTask(r,i){let a=n().taskEventCache[r.id]||[];if(!a.length)try{a=await t(`GET`,`/tasks/`+r.id+`/events`),e({taskEventCache:{...n().taskEventCache,[r.id]:a}})}catch{}let o=`agent-relay-task-${r.id}.${i===`json`?`json`:`md`}`,s={title:`Task: `+(r.title||`#`+r.id),task:r,events:a,exportedAt:new Date().toISOString()};T(o,JSON.stringify(s,null,2),i===`json`?`application/json`:`text/markdown`)}}),en=(e,n)=>({channels:[],connectors:[],integrations:[],automations:[],automationRuns:[],health:null,maintenanceJobs:[],analyticsPeriod:`24h`,analyticsData:null,async fetchChannels(){try{e({channels:await t(`GET`,`/channels`)})}catch{}},async fetchConnectors(){try{e({connectors:await t(`GET`,`/connectors`)})}catch{}},async fetchIntegrations(){try{e({integrations:await t(`GET`,`/integrations`)})}catch{}},async fetchAutomations(){try{e({automations:await t(`GET`,`/automations`)})}catch{}},async fetchAutomationRuns(n){try{let r=new URLSearchParams({limit:`100`});n&&r.set(`automationId`,n),e({automationRuns:await t(`GET`,`/automation-runs?`+r.toString())})}catch{}},async fetchHealth(){try{e({health:await t(`GET`,`/health`)})}catch{}},async fetchMaintenanceJobs(){try{e({maintenanceJobs:await t(`GET`,`/maintenance/jobs`)})}catch{}},async runMaintenanceJob(r){try{let i=await t(`POST`,`/maintenance/jobs/`+encodeURIComponent(r)+`/run`,{});return e({maintenanceJobs:i.jobs}),n().showNotification(i.run.status===`succeeded`?`Maintenance job completed`:`Maintenance job skipped`),i.run}catch(e){return n().showError(`Maintenance Job Failed`,e.message),await n().fetchMaintenanceJobs(),null}},async runHealthAction(r){if(r.preset&&e({agentPresetFilter:r.preset,showOffline:!0}),r.api&&r.path&&(await t(r.api,r.path),await n().refreshLiveData()),r.view&&await n().switchView(r.view),r.copy)try{await navigator.clipboard?.writeText(r.copy)}catch{}},async runConnectorAction(e,r){try{let i=await t(`POST`,`/connectors/`+encodeURIComponent(e)+`/actions`,{action:r});if(await n().fetchConnectors(),!i.ok)throw Error(i.stderr||`${r} failed`);return i}catch(e){throw n().showError(`Connector Action Failed`,e.message),e}},async fetchAnalytics(){try{e({analyticsData:await t(`GET`,`/stats/analytics?period=`+n().analyticsPeriod)})}catch{}},setAnalyticsPeriod(t){e({analyticsPeriod:t}),n().fetchAnalytics()}}),tn=(e,n)=>({workspaces:[],workspaceFocusId:null,workspaceGitState:{},workspaceMergePreview:{},workspaceDiff:{},workspaceOrphans:[],async openWorkspaceFocus(t){e({workspaceFocusId:t}),await n().switchView(`workspaces`)},async fetchWorkspaces(){try{e({workspaces:await t(`GET`,`/workspaces`)})}catch{}},async fetchWorkspaceGitState(n){try{let r=await t(`GET`,`/workspaces/`+encodeURIComponent(n)+`/git-state`);e(e=>({workspaceGitState:{...e.workspaceGitState,[n]:r}}))}catch(t){e(e=>({workspaceGitState:{...e.workspaceGitState,[n]:{available:!1,reason:t.message}}}))}},async fetchWorkspaceMergePreview(n){try{let r=await t(`GET`,`/workspaces/`+encodeURIComponent(n)+`/merge-preview`);e(e=>({workspaceMergePreview:{...e.workspaceMergePreview,[n]:r}}))}catch(t){e(e=>({workspaceMergePreview:{...e.workspaceMergePreview,[n]:{available:!1,reason:t.message}}}))}},async fetchWorkspaceDiff(n){try{let r=await t(`GET`,`/workspaces/`+encodeURIComponent(n)+`/diff`);e(e=>({workspaceDiff:{...e.workspaceDiff,[n]:r}}))}catch(t){e(e=>({workspaceDiff:{...e.workspaceDiff,[n]:{available:!1,reason:t.message}}}))}},async fetchWorkspaceOrphans(){try{e({workspaceOrphans:(await t(`GET`,`/workspaces/orphans`)).orphans??[]})}catch{}},async reclaimWorkspaceOrphan(e){n().openConfirm(`Reclaim Orphan Worktree`,`Remove the orphaned worktree "${e.branch||e.worktreePath}" from disk? It has no live agent.`,async()=>{try{await t(`POST`,`/workspaces/orphans/reclaim`,{worktreePath:e.worktreePath,repoRoot:e.repoRoot,branch:e.branch}),n().showNotification(`Orphan reclaim dispatched`),await Promise.all([n().fetchWorkspaceOrphans(),n().fetchActivityEvents()])}catch(e){n().showError(`Reclaim Failed`,e.message)}})},async workspaceAction(e,r){let i=r===`ready`?`Mark ready`:r===`request-review`?`Request review`:r===`merge-plan`?`Mark merge planned`:r===`merge`?`Merge`:r===`abandon`?`Abandon`:`Cleanup`,a=async()=>{try{await t(`POST`,`/workspaces/`+encodeURIComponent(e)+`/actions`,{action:r}),n().showNotification(r===`cleanup`?`Workspace cleanup requested`:r===`merge`?`Workspace merge dispatched`:`Workspace updated: ${i}`),await Promise.all([n().fetchWorkspaces(),n().fetchOrchestrators(),n().fetchActivityEvents()])}catch(e){n().showError(`Workspace Action Failed`,e.message)}};if(r===`cleanup`||r===`abandon`||r===`merge`){let t=n().workspaces.find(t=>t.id===e),i=t?.branch||t?.worktreePath||e;if(r===`merge`){let t=n().workspaceMergePreview[e],r=t&&t.available!==!1?` — ${t.strategy===`pr`?`opens a PR`:`rebases & fast-forwards into ${t.baseRef||`base`}, then deletes the branch`}.`:` — lands the work and deletes the branch.`;n().openConfirm(`Merge Workspace`,`Merge workspace "${i}"?${r}`,a);return}if(r===`cleanup`){await n().fetchWorkspaceGitState(e);let t=n().workspaceGitState[e],r=``;if(t&&t.available!==!1&&!t.missing){let e=t.ahead??0,n=t.dirtyCount??0;(e>0||n>0)&&(r=` ⚠ This destroys ${[e>0?`${e} unmerged commit(s)`:``,n>0?`${n} uncommitted change(s)`:``].filter(Boolean).join(` and `)}.`)}n().openConfirm(`Cleanup Workspace`,`Remove the worktree for "${i}" on the host?${r}`,a);return}n().openConfirm(`Abandon Workspace`,`Abandon workspace "${i}"?`,a);return}await a()},async purgeWorkspace(e){let r=n().workspaces.find(t=>t.id===e),i=r?.branch||r?.worktreePath||e;n().openConfirm(`Purge Workspace Record`,`Permanently remove the record for "${i}"? This only clears the dashboard row — it does not touch disk.`,async()=>{try{await t(`DELETE`,`/workspaces/`+encodeURIComponent(e)),n().showNotification(`Workspace record purged`),await Promise.all([n().fetchWorkspaces(),n().fetchActivityEvents()])}catch(e){n().showError(`Purge Failed`,e.message)}})}}),nn=(e,n)=>({memories:[],memoryTotal:0,memoryBrokerInfo:null,memoryStats:null,memoryFilters:{search:``,type:``,scope:``,tags:``,visibility:``,minRelevance:`0`},selectedMemoryId:``,memoryLoading:!1,async refreshMemory(){await Promise.all([n().fetchMemoryBroker(),n().fetchMemoryStats(),n().fetchMemories()])},async fetchMemoryBroker(){try{e({memoryBrokerInfo:await t(`GET`,`/memories/broker`)})}catch(e){n().showError(`Memory Broker Failed`,e.message)}},async fetchMemoryStats(){try{e({memoryStats:await t(`GET`,`/memories/stats`)})}catch{}},async fetchMemories(){let r=n().memoryFilters,i={limit:100};if(r.type&&(i.type=r.type),r.scope.trim()&&(i.scope=r.scope.trim()),r.visibility&&(i.visibility=r.visibility),r.tags.trim()&&(i.tags=r.tags.split(`,`).map(e=>e.trim()).filter(Boolean)),r.minRelevance.trim()!==``){let e=Number(r.minRelevance);Number.isFinite(e)&&(i.minRelevance=Math.max(0,Math.min(1,e)))}e({memoryLoading:!0});try{let r=await t(`POST`,`/memories/search`,i),a=r.memories.some(e=>e.id===n().selectedMemoryId)?n().selectedMemoryId:r.memories[0]?.id||``;e({memories:r.memories,memoryTotal:r.total,selectedMemoryId:a})}catch(e){n().showError(`Memory Search Failed`,e.message)}finally{e({memoryLoading:!1})}},async saveMemory(r,i){try{e({selectedMemoryId:(i?await t(`PATCH`,`/memories/`+encodeURIComponent(i),r):await t(`POST`,`/memories`,r)).id}),await Promise.all([n().fetchMemories(),n().fetchMemoryStats()]),n().showNotification(i?`Memory updated`:`Memory created`)}catch(e){n().showError(`Memory Save Failed`,e.message)}},deleteMemory(r){n().openConfirm(`Delete Memory`,`Delete memory "${r}"?`,async()=>{try{await t(`DELETE`,`/memories/`+encodeURIComponent(r)),e({selectedMemoryId:``}),await Promise.all([n().fetchMemories(),n().fetchMemoryStats()]),n().showNotification(`Memory deleted`)}catch(e){n().showError(`Delete Failed`,e.message)}})},async injectMemory(e){try{let r=await t(`POST`,`/memories/inject`,e);return n().showNotification(`Memory inject command sent to ${e.agentId}`),r}catch(e){return n().showError(`Memory Inject Failed`,e.message),null}}}),rn=(e,n)=>({projectFocusId:null,projectByCwd:{},async openProjectFocus(t){e({projectFocusId:t}),await n().switchView(`projects`)},consumeProjectFocus(){n().projectFocusId!==null&&e({projectFocusId:null})},async fetchProjectForCwd(r){if(!(!r||r in n().projectByCwd))try{let n=await t(`GET`,`/projects/resolve?cwd=`+encodeURIComponent(r));e(e=>({projectByCwd:{...e.projectByCwd,[r]:n.project??null}}))}catch{}}});function an(){return $.persist.hasHydrated()?Promise.resolve():new Promise(e=>{let t=$.persist.onFinishHydration(()=>{t(),e()})})}var $=le()(fe((...e)=>({...Dt({waitForHydration:an})(...e),...Ot(...e),...kt(...e),...Lt(...e),...Ht(...e),...Ut(...e),...Kt(...e),...qt(...e),...Jt(...e),...Yt(...e),...Ct(...e),...Xt(...e),...$t(...e),...wt(...e),...en(...e),...tn(...e),...nn(...e),...rn(...e)}),{name:`agent-relay-dashboard`,partialize:e=>({theme:e.theme,view:e.view,showOffline:e.showOffline,showBuiltIns:e.showBuiltIns,showReasoning:e.showReasoning,autoRefresh:e.autoRefresh,voiceTtsEnabled:e.voiceTtsEnabled,voiceTtsLang:e.voiceTtsLang,voiceTtsMode:e.voiceTtsMode,voiceTtsKokoroVoice:e.voiceTtsKokoroVoice,voiceTtsBrowserVoice:e.voiceTtsBrowserVoice,voiceInputMode:e.voiceInputMode,agentSort:e.agentSort,agentSortDir:e.agentSortDir,agentPresetFilter:e.agentPresetFilter,agentStatusFilter:e.agentStatusFilter,agentTagFilter:e.agentTagFilter,agentHostFilter:e.agentHostFilter,pairStatusFilter:e.pairStatusFilter,inboxSort:e.inboxSort,inboxSortDir:e.inboxSortDir,inboxShowArchived:e.inboxShowArchived,chatAgentProviderFilter:e.chatAgentProviderFilter,chatAgentStatusFilter:e.chatAgentStatusFilter,chatAgentTagFilter:e.chatAgentTagFilter,chatAgentCapFilter:e.chatAgentCapFilter,chatAgentHostFilter:e.chatAgentHostFilter,chatAgentSort:e.chatAgentSort,chatAgentSortDir:e.chatAgentSortDir,chatAgentGroupBy:e.chatAgentGroupBy,chatAgentFiltersCollapsed:e.chatAgentFiltersCollapsed,chatCollapsedChildren:e.chatCollapsedChildren,feedObserveAll:e.feedObserveAll,coordinatorFollows:e.coordinatorFollows,coordinatorMutes:e.coordinatorMutes,planCollapsed:e.planCollapsed,activityFilter:e.activityFilter,analyticsPeriod:e.analyticsPeriod,memoryFilters:e.memoryFilters,authToken:e.authToken,inboxReadCursors:e.inboxReadCursors,inboxArchivedThreads:e.inboxArchivedThreads,inboxDrafts:e.inboxDrafts,chatStatusEvents:e.chatStatusEvents,operatorActivity:e.operatorActivity,notifications:e.notifications,notificationUnread:e.notificationUnread,notificationSettings:e.notificationSettings,spawnOrchId:e.spawnOrchId,spawnProvider:e.spawnProvider,spawnModel:e.spawnModel,spawnEffort:e.spawnEffort,spawnProfile:e.spawnProfile,spawnCwd:e.spawnCwd,spawnApproval:e.spawnApproval,spawnWorkspaceMode:e.spawnWorkspaceMode,spawnCwdHistory:e.spawnCwdHistory})}));$.subscribe(Et);export{Ee as _,Ye as a,B as c,P as d,Ae as f,Te as g,Oe as h,Z as i,R as l,Ce as m,Wt as n,Xe as o,je as p,X as r,z as s,$ as t,Re as u,ke as v,N as y};
9
- //# sourceMappingURL=store-Bnag1kY-.js.map