@polderlabs/bizar 4.5.2 → 4.7.1

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 (123) hide show
  1. package/bizar-dash/dist/assets/main-DHZmbnxQ.js +361 -0
  2. package/bizar-dash/dist/assets/main-DHZmbnxQ.js.map +1 -0
  3. package/bizar-dash/dist/assets/main-DX_Jh8Wc.css +1 -0
  4. package/bizar-dash/dist/assets/{mobile-lbH6szyX.js → mobile-BK8-ythT.js} +18 -18
  5. package/bizar-dash/dist/assets/mobile-BK8-ythT.js.map +1 -0
  6. package/bizar-dash/dist/assets/{mobile-BRhoDOUz.js → mobile-Chvf9u_B.js} +1 -1
  7. package/bizar-dash/dist/assets/{mobile-BRhoDOUz.js.map → mobile-Chvf9u_B.js.map} +1 -1
  8. package/bizar-dash/dist/index.html +3 -3
  9. package/bizar-dash/dist/mobile.html +2 -2
  10. package/bizar-dash/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +1 -0
  11. package/bizar-dash/skills/publishing/SKILL.md +146 -0
  12. package/bizar-dash/src/server/api.mjs +8 -0
  13. package/bizar-dash/src/server/backup-store.mjs +525 -0
  14. package/bizar-dash/src/server/digest-store.mjs +558 -0
  15. package/bizar-dash/src/server/lib/rate-limit.mjs +122 -0
  16. package/bizar-dash/src/server/logger.mjs +71 -0
  17. package/bizar-dash/src/server/memory-lightrag.mjs +45 -6
  18. package/bizar-dash/src/server/metrics.mjs +193 -0
  19. package/bizar-dash/src/server/routes/backup.mjs +112 -0
  20. package/bizar-dash/src/server/routes/chat.mjs +20 -3
  21. package/bizar-dash/src/server/routes/digests.mjs +82 -0
  22. package/bizar-dash/src/server/routes/lightrag.mjs +3 -2
  23. package/bizar-dash/src/server/routes/memory.mjs +5 -4
  24. package/bizar-dash/src/server/routes/misc.mjs +2 -1
  25. package/bizar-dash/src/server/routes/overview.mjs +2 -1
  26. package/bizar-dash/src/server/routes-v2/events.mjs +14 -0
  27. package/bizar-dash/src/server/schedules-runner.mjs +126 -0
  28. package/bizar-dash/src/server/server.mjs +79 -0
  29. package/bizar-dash/src/web/App.tsx +8 -1
  30. package/bizar-dash/src/web/components/BackupRestore.tsx +330 -0
  31. package/bizar-dash/src/web/components/SearchModal.tsx +6 -3
  32. package/bizar-dash/src/web/components/VirtualList.tsx +53 -0
  33. package/bizar-dash/src/web/components/chat/ChatThread.tsx +17 -11
  34. package/bizar-dash/src/web/components/chat/Composer.tsx +2 -0
  35. package/bizar-dash/src/web/hooks/useI18n.ts +13 -0
  36. package/bizar-dash/src/web/lib/i18n.ts +25 -0
  37. package/bizar-dash/src/web/locales/en.json +52 -0
  38. package/bizar-dash/src/web/main.tsx +5 -0
  39. package/bizar-dash/src/web/styles/main.css +70 -8
  40. package/bizar-dash/src/web/views/Activity.tsx +35 -18
  41. package/bizar-dash/src/web/views/Agents.tsx +57 -42
  42. package/bizar-dash/src/web/views/Artifacts.tsx +38 -25
  43. package/bizar-dash/src/web/views/Chat.tsx +8 -0
  44. package/bizar-dash/src/web/views/History.tsx +94 -76
  45. package/bizar-dash/src/web/views/MiniMaxUsage.tsx +21 -4
  46. package/bizar-dash/src/web/views/Mods.tsx +30 -17
  47. package/bizar-dash/src/web/views/Overview.tsx +19 -9
  48. package/bizar-dash/src/web/views/Providers.tsx +16 -16
  49. package/bizar-dash/src/web/views/Schedules.tsx +33 -15
  50. package/bizar-dash/src/web/views/Settings.tsx +97 -1745
  51. package/bizar-dash/src/web/views/Skills.tsx +4 -1
  52. package/bizar-dash/src/web/views/Tasks.tsx +11 -2
  53. package/bizar-dash/src/web/views/memory/ConfigPanel.tsx +8 -2
  54. package/bizar-dash/src/web/views/memory/LightragPanel.tsx +3 -0
  55. package/bizar-dash/src/web/views/memory/ObsidianPanel.tsx +12 -4
  56. package/bizar-dash/src/web/views/memory/SemanticSearchPanel.tsx +3 -0
  57. package/bizar-dash/src/web/views/settings/ActivitySection.tsx +205 -0
  58. package/bizar-dash/src/web/views/settings/AgentSection.tsx +294 -0
  59. package/bizar-dash/src/web/views/settings/AuthSection.tsx +159 -0
  60. package/bizar-dash/src/web/views/settings/BackupSection.tsx +16 -0
  61. package/bizar-dash/src/web/views/settings/EnvVarsSection.tsx +16 -0
  62. package/bizar-dash/src/web/views/settings/GeneralSection.tsx +105 -0
  63. package/bizar-dash/src/web/views/settings/HeadroomSection.tsx +39 -0
  64. package/bizar-dash/src/web/views/settings/MemorySection.tsx +16 -0
  65. package/bizar-dash/src/web/views/settings/NetworkSection.tsx +87 -0
  66. package/bizar-dash/src/web/views/settings/NotificationsSection.tsx +34 -0
  67. package/bizar-dash/src/web/views/settings/ProvidersSection.tsx +16 -0
  68. package/bizar-dash/src/web/views/settings/SkillsSection.tsx +16 -0
  69. package/bizar-dash/src/web/views/settings/SystemLlmSection.tsx +81 -0
  70. package/bizar-dash/src/web/views/settings/ThemeSection.tsx +168 -0
  71. package/bizar-dash/src/web/views/settings/UpdatesSection.tsx +256 -0
  72. package/bizar-dash/tests/a11y.test.tsx +206 -0
  73. package/bizar-dash/tests/backup-restore.test.mjs +217 -0
  74. package/bizar-dash/tests/backup-restore.test.tsx +123 -0
  75. package/bizar-dash/tests/backup-store.test.mjs +300 -0
  76. package/bizar-dash/tests/cli-bugfixes.test.mjs +4 -4
  77. package/bizar-dash/tests/cli-error-visibility.test.mjs +153 -0
  78. package/bizar-dash/tests/cli-refactor.test.mjs +184 -0
  79. package/bizar-dash/tests/components/Button.test.tsx +41 -0
  80. package/bizar-dash/tests/components/Card.test.tsx +42 -0
  81. package/bizar-dash/tests/components/Modal.test.tsx +104 -0
  82. package/bizar-dash/tests/components/Spinner.test.tsx +32 -0
  83. package/bizar-dash/tests/components/StatusBadge.test.tsx +35 -0
  84. package/bizar-dash/tests/components/Toast.test.tsx +108 -0
  85. package/bizar-dash/tests/digest-generation.test.mjs +191 -0
  86. package/bizar-dash/tests/digest-store.test.mjs +264 -0
  87. package/bizar-dash/tests/hooks/useModal.test.tsx +84 -0
  88. package/bizar-dash/tests/hooks/useToast.test.tsx +50 -0
  89. package/bizar-dash/tests/lib/i18n.test.ts +46 -0
  90. package/bizar-dash/tests/lib/utils.test.ts +194 -0
  91. package/bizar-dash/tests/logger.test.mjs +207 -0
  92. package/bizar-dash/tests/metrics.test.mjs +183 -0
  93. package/bizar-dash/tests/rate-limit.test.mjs +298 -0
  94. package/bizar-dash/tests/server-bugfixes.test.mjs +2 -2
  95. package/bizar-dash/tests/setup.ts +7 -0
  96. package/bizar-dash/vitest.config.ts +13 -0
  97. package/cli/artifact-cli.mjs +605 -0
  98. package/cli/artifact-render.mjs +621 -0
  99. package/cli/artifact-server.mjs +847 -0
  100. package/cli/artifact.mjs +38 -2096
  101. package/cli/bg.mjs +5 -13
  102. package/cli/bin.mjs +221 -1350
  103. package/cli/commands/artifact.mjs +20 -0
  104. package/cli/commands/dash.mjs +160 -0
  105. package/cli/commands/headroom.mjs +204 -0
  106. package/cli/commands/install.mjs +169 -0
  107. package/cli/commands/memory.mjs +25 -0
  108. package/cli/commands/minimax.mjs +285 -0
  109. package/cli/commands/mod.mjs +185 -0
  110. package/cli/commands/service.mjs +65 -0
  111. package/cli/commands/usage.mjs +109 -0
  112. package/cli/commands/util.mjs +459 -0
  113. package/cli/digest.mjs +149 -0
  114. package/cli/doctor.mjs +1 -13
  115. package/cli/provision.mjs +2 -13
  116. package/cli/service-controller.mjs +1 -11
  117. package/cli/service.mjs +1 -11
  118. package/cli/utils.mjs +41 -1
  119. package/package.json +6 -1
  120. package/bizar-dash/dist/assets/main-B4OfGAwz.js +0 -361
  121. package/bizar-dash/dist/assets/main-B4OfGAwz.js.map +0 -1
  122. package/bizar-dash/dist/assets/main-DAlLdW8I.css +0 -1
  123. package/bizar-dash/dist/assets/mobile-lbH6szyX.js.map +0 -1
@@ -0,0 +1,361 @@
1
+ var ja=Object.defineProperty;var fa=(s,t,a)=>t in s?ja(s,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):s[t]=a;var cs=(s,t,a)=>fa(s,typeof t!="symbol"?t+"":t,a);import{c as Y,r,a as w,j as e,R as ce,C as dt,F as Ee,b as Fe,d as _e,M as qs,B as qe,S as ps,A as Te,e as Oe,f as Ds,H as gs,g as mt,h as ye,i as X,u as Pe,P as Me,k as T,l as oe,X as $e,m as va,T as ke,n as He,I as Hs,o as Ne,E as ls,p as Se,q as os,s as We,t as he,v as Xe,V as ht,w as Ae,x as ut,y as ya,z as ba,D as ka,G as js,J as fs,K as ks,L as Na,N as wa,O as Sa,Q as Ca,U as vs,W as qt,Y as Ns,Z as xt,_ as za,$ as Ht,a0 as _t,a1 as Ta,a2 as Ma,a3 as $a,a4 as Aa,a5 as Ra,a6 as Ia,a7 as La,a8 as pt,a9 as _s,aa as Wt,ab as Vt,ac as as,ad as xs,ae as Kt,af as Ea,ag as Pa,ah as Da,ai as Fa,aj as Oa,ak as Ba}from"./mobile-BK8-ythT.js";/**
2
+ * @license lucide-react v0.460.0 - ISC
3
+ *
4
+ * This source code is licensed under the ISC license.
5
+ * See the LICENSE file in the root directory of this source tree.
6
+ */const Gt=Y("ArchiveRestore",[["rect",{width:"20",height:"5",x:"2",y:"3",rx:"1",key:"1wp1u1"}],["path",{d:"M4 8v11a2 2 0 0 0 2 2h2",key:"tvwodi"}],["path",{d:"M20 8v11a2 2 0 0 1-2 2h-2",key:"1gkqxj"}],["path",{d:"m9 15 3-3 3 3",key:"1pd0qc"}],["path",{d:"M12 12v9",key:"192myk"}]]);/**
7
+ * @license lucide-react v0.460.0 - ISC
8
+ *
9
+ * This source code is licensed under the ISC license.
10
+ * See the LICENSE file in the root directory of this source tree.
11
+ */const Yt=Y("ArrowDown",[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]]);/**
12
+ * @license lucide-react v0.460.0 - ISC
13
+ *
14
+ * This source code is licensed under the ISC license.
15
+ * See the LICENSE file in the root directory of this source tree.
16
+ */const Xt=Y("ArrowLeft",[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]]);/**
17
+ * @license lucide-react v0.460.0 - ISC
18
+ *
19
+ * This source code is licensed under the ISC license.
20
+ * See the LICENSE file in the root directory of this source tree.
21
+ */const gt=Y("ArrowUp",[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]]);/**
22
+ * @license lucide-react v0.460.0 - ISC
23
+ *
24
+ * This source code is licensed under the ISC license.
25
+ * See the LICENSE file in the root directory of this source tree.
26
+ */const Le=Y("Brain",[["path",{d:"M12 5a3 3 0 1 0-5.997.125 4 4 0 0 0-2.526 5.77 4 4 0 0 0 .556 6.588A4 4 0 1 0 12 18Z",key:"l5xja"}],["path",{d:"M12 5a3 3 0 1 1 5.997.125 4 4 0 0 1 2.526 5.77 4 4 0 0 1-.556 6.588A4 4 0 1 1 12 18Z",key:"ep3f8r"}],["path",{d:"M15 13a4.5 4.5 0 0 1-3-4 4.5 4.5 0 0 1-3 4",key:"1p4c4q"}],["path",{d:"M17.599 6.5a3 3 0 0 0 .399-1.375",key:"tmeiqw"}],["path",{d:"M6.003 5.125A3 3 0 0 0 6.401 6.5",key:"105sqy"}],["path",{d:"M3.477 10.896a4 4 0 0 1 .585-.396",key:"ql3yin"}],["path",{d:"M19.938 10.5a4 4 0 0 1 .585.396",key:"1qfode"}],["path",{d:"M6 18a4 4 0 0 1-1.967-.516",key:"2e4loj"}],["path",{d:"M19.967 17.484A4 4 0 0 1 18 18",key:"159ez6"}]]);/**
27
+ * @license lucide-react v0.460.0 - ISC
28
+ *
29
+ * This source code is licensed under the ISC license.
30
+ * See the LICENSE file in the root directory of this source tree.
31
+ */const Ua=Y("Calendar",[["path",{d:"M8 2v4",key:"1cmpym"}],["path",{d:"M16 2v4",key:"4m81vk"}],["rect",{width:"18",height:"18",x:"3",y:"4",rx:"2",key:"1hopcy"}],["path",{d:"M3 10h18",key:"8toen8"}]]);/**
32
+ * @license lucide-react v0.460.0 - ISC
33
+ *
34
+ * This source code is licensed under the ISC license.
35
+ * See the LICENSE file in the root directory of this source tree.
36
+ */const Qt=Y("ChartNoAxesColumn",[["line",{x1:"18",x2:"18",y1:"20",y2:"10",key:"1xfpm4"}],["line",{x1:"12",x2:"12",y1:"20",y2:"4",key:"be30l9"}],["line",{x1:"6",x2:"6",y1:"20",y2:"14",key:"1r4le6"}]]);/**
37
+ * @license lucide-react v0.460.0 - ISC
38
+ *
39
+ * This source code is licensed under the ISC license.
40
+ * See the LICENSE file in the root directory of this source tree.
41
+ */const at=Y("Check",[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]]);/**
42
+ * @license lucide-react v0.460.0 - ISC
43
+ *
44
+ * This source code is licensed under the ISC license.
45
+ * See the LICENSE file in the root directory of this source tree.
46
+ */const qa=Y("ChevronLeft",[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]]);/**
47
+ * @license lucide-react v0.460.0 - ISC
48
+ *
49
+ * This source code is licensed under the ISC license.
50
+ * See the LICENSE file in the root directory of this source tree.
51
+ */const Is=Y("CircleCheckBig",[["path",{d:"M21.801 10A10 10 0 1 1 17 3.335",key:"yps3ct"}],["path",{d:"m9 11 3 3L22 4",key:"1pflzl"}]]);/**
52
+ * @license lucide-react v0.460.0 - ISC
53
+ *
54
+ * This source code is licensed under the ISC license.
55
+ * See the LICENSE file in the root directory of this source tree.
56
+ */const Ha=Y("CircleDollarSign",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M16 8h-6a2 2 0 1 0 0 4h4a2 2 0 1 1 0 4H8",key:"1h4pet"}],["path",{d:"M12 18V6",key:"zqpxq5"}]]);/**
57
+ * @license lucide-react v0.460.0 - ISC
58
+ *
59
+ * This source code is licensed under the ISC license.
60
+ * See the LICENSE file in the root directory of this source tree.
61
+ */const _a=Y("CirclePlay",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["polygon",{points:"10 8 16 12 10 16 10 8",key:"1cimsy"}]]);/**
62
+ * @license lucide-react v0.460.0 - ISC
63
+ *
64
+ * This source code is licensed under the ISC license.
65
+ * See the LICENSE file in the root directory of this source tree.
66
+ */const Ye=Y("CircleX",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m15 9-6 6",key:"1uzhvr"}],["path",{d:"m9 9 6 6",key:"z0biqf"}]]);/**
67
+ * @license lucide-react v0.460.0 - ISC
68
+ *
69
+ * This source code is licensed under the ISC license.
70
+ * See the LICENSE file in the root directory of this source tree.
71
+ */const Wa=Y("Circle",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]]);/**
72
+ * @license lucide-react v0.460.0 - ISC
73
+ *
74
+ * This source code is licensed under the ISC license.
75
+ * See the LICENSE file in the root directory of this source tree.
76
+ */const jt=Y("Coins",[["circle",{cx:"8",cy:"8",r:"6",key:"3yglwk"}],["path",{d:"M18.09 10.37A6 6 0 1 1 10.34 18",key:"t5s6rm"}],["path",{d:"M7 6h1v4",key:"1obek4"}],["path",{d:"m16.71 13.88.7.71-2.82 2.82",key:"1rbuyh"}]]);/**
77
+ * @license lucide-react v0.460.0 - ISC
78
+ *
79
+ * This source code is licensed under the ISC license.
80
+ * See the LICENSE file in the root directory of this source tree.
81
+ */const Vs=Y("Cpu",[["rect",{width:"16",height:"16",x:"4",y:"4",rx:"2",key:"14l7u7"}],["rect",{width:"6",height:"6",x:"9",y:"9",rx:"1",key:"5aljv4"}],["path",{d:"M15 2v2",key:"13l42r"}],["path",{d:"M15 20v2",key:"15mkzm"}],["path",{d:"M2 15h2",key:"1gxd5l"}],["path",{d:"M2 9h2",key:"1bbxkp"}],["path",{d:"M20 15h2",key:"19e6y8"}],["path",{d:"M20 9h2",key:"19tzq7"}],["path",{d:"M9 2v2",key:"165o2o"}],["path",{d:"M9 20v2",key:"i2bqo8"}]]);/**
82
+ * @license lucide-react v0.460.0 - ISC
83
+ *
84
+ * This source code is licensed under the ISC license.
85
+ * See the LICENSE file in the root directory of this source tree.
86
+ */const Zt=Y("Database",[["ellipse",{cx:"12",cy:"5",rx:"9",ry:"3",key:"msslwz"}],["path",{d:"M3 5V19A9 3 0 0 0 21 19V5",key:"1wlel7"}],["path",{d:"M3 12A9 3 0 0 0 21 12",key:"mv7ke4"}]]);/**
87
+ * @license lucide-react v0.460.0 - ISC
88
+ *
89
+ * This source code is licensed under the ISC license.
90
+ * See the LICENSE file in the root directory of this source tree.
91
+ */const Va=Y("Diamond",[["path",{d:"M2.7 10.3a2.41 2.41 0 0 0 0 3.41l7.59 7.59a2.41 2.41 0 0 0 3.41 0l7.59-7.59a2.41 2.41 0 0 0 0-3.41l-7.59-7.59a2.41 2.41 0 0 0-3.41 0Z",key:"1f1r0c"}]]);/**
92
+ * @license lucide-react v0.460.0 - ISC
93
+ *
94
+ * This source code is licensed under the ISC license.
95
+ * See the LICENSE file in the root directory of this source tree.
96
+ */const Qe=Y("Download",[["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}],["polyline",{points:"7 10 12 15 17 10",key:"2ggqvy"}],["line",{x1:"12",x2:"12",y1:"15",y2:"3",key:"1vk2je"}]]);/**
97
+ * @license lucide-react v0.460.0 - ISC
98
+ *
99
+ * This source code is licensed under the ISC license.
100
+ * See the LICENSE file in the root directory of this source tree.
101
+ */const Ka=Y("Ellipsis",[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"19",cy:"12",r:"1",key:"1wjl8i"}],["circle",{cx:"5",cy:"12",r:"1",key:"1pcz8c"}]]);/**
102
+ * @license lucide-react v0.460.0 - ISC
103
+ *
104
+ * This source code is licensed under the ISC license.
105
+ * See the LICENSE file in the root directory of this source tree.
106
+ */const nt=Y("EyeOff",[["path",{d:"M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49",key:"ct8e1f"}],["path",{d:"M14.084 14.158a3 3 0 0 1-4.242-4.242",key:"151rxh"}],["path",{d:"M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143",key:"13bj9a"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]]);/**
107
+ * @license lucide-react v0.460.0 - ISC
108
+ *
109
+ * This source code is licensed under the ISC license.
110
+ * See the LICENSE file in the root directory of this source tree.
111
+ */const is=Y("Eye",[["path",{d:"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0",key:"1nclc0"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]);/**
112
+ * @license lucide-react v0.460.0 - ISC
113
+ *
114
+ * This source code is licensed under the ISC license.
115
+ * See the LICENSE file in the root directory of this source tree.
116
+ */const Ga=Y("FileCode2",[["path",{d:"M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4",key:"1pf5j1"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"m5 12-3 3 3 3",key:"oke12k"}],["path",{d:"m9 18 3-3-3-3",key:"112psh"}]]);/**
117
+ * @license lucide-react v0.460.0 - ISC
118
+ *
119
+ * This source code is licensed under the ISC license.
120
+ * See the LICENSE file in the root directory of this source tree.
121
+ */const Ya=Y("FileCode",[["path",{d:"M10 12.5 8 15l2 2.5",key:"1tg20x"}],["path",{d:"m14 12.5 2 2.5-2 2.5",key:"yinavb"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7z",key:"1mlx9k"}]]);/**
122
+ * @license lucide-react v0.460.0 - ISC
123
+ *
124
+ * This source code is licensed under the ISC license.
125
+ * See the LICENSE file in the root directory of this source tree.
126
+ */const Xa=Y("FilePlus",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M9 15h6",key:"cctwl0"}],["path",{d:"M12 18v-6",key:"17g6i2"}]]);/**
127
+ * @license lucide-react v0.460.0 - ISC
128
+ *
129
+ * This source code is licensed under the ISC license.
130
+ * See the LICENSE file in the root directory of this source tree.
131
+ */const Qa=Y("File",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}]]);/**
132
+ * @license lucide-react v0.460.0 - ISC
133
+ *
134
+ * This source code is licensed under the ISC license.
135
+ * See the LICENSE file in the root directory of this source tree.
136
+ */const Za=Y("Filter",[["polygon",{points:"22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3",key:"1yg77f"}]]);/**
137
+ * @license lucide-react v0.460.0 - ISC
138
+ *
139
+ * This source code is licensed under the ISC license.
140
+ * See the LICENSE file in the root directory of this source tree.
141
+ */const Ja=Y("FolderOpen",[["path",{d:"m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2",key:"usdka0"}]]);/**
142
+ * @license lucide-react v0.460.0 - ISC
143
+ *
144
+ * This source code is licensed under the ISC license.
145
+ * See the LICENSE file in the root directory of this source tree.
146
+ */const en=Y("FolderPlus",[["path",{d:"M12 10v6",key:"1bos4e"}],["path",{d:"M9 13h6",key:"1uhe8q"}],["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]]);/**
147
+ * @license lucide-react v0.460.0 - ISC
148
+ *
149
+ * This source code is licensed under the ISC license.
150
+ * See the LICENSE file in the root directory of this source tree.
151
+ */const sn=Y("FolderSearch",[["path",{d:"M10.7 20H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H20a2 2 0 0 1 2 2v4.1",key:"1bw5m7"}],["path",{d:"m21 21-1.9-1.9",key:"1g2n9r"}],["circle",{cx:"17",cy:"17",r:"3",key:"18b49y"}]]);/**
152
+ * @license lucide-react v0.460.0 - ISC
153
+ *
154
+ * This source code is licensed under the ISC license.
155
+ * See the LICENSE file in the root directory of this source tree.
156
+ */const rs=Y("GitBranch",[["line",{x1:"6",x2:"6",y1:"3",y2:"15",key:"17qcm7"}],["circle",{cx:"18",cy:"6",r:"3",key:"1h7g24"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}],["path",{d:"M18 9a9 9 0 0 1-9 9",key:"n2h4wq"}]]);/**
157
+ * @license lucide-react v0.460.0 - ISC
158
+ *
159
+ * This source code is licensed under the ISC license.
160
+ * See the LICENSE file in the root directory of this source tree.
161
+ */const tn=Y("GitCommitHorizontal",[["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}],["line",{x1:"3",x2:"9",y1:"12",y2:"12",key:"1dyftd"}],["line",{x1:"15",x2:"21",y1:"12",y2:"12",key:"oup4p8"}]]);/**
162
+ * @license lucide-react v0.460.0 - ISC
163
+ *
164
+ * This source code is licensed under the ISC license.
165
+ * See the LICENSE file in the root directory of this source tree.
166
+ */const an=Y("GitMerge",[["circle",{cx:"18",cy:"18",r:"3",key:"1xkwt0"}],["circle",{cx:"6",cy:"6",r:"3",key:"1lh9wr"}],["path",{d:"M6 21V9a9 9 0 0 0 9 9",key:"7kw0sc"}]]);/**
167
+ * @license lucide-react v0.460.0 - ISC
168
+ *
169
+ * This source code is licensed under the ISC license.
170
+ * See the LICENSE file in the root directory of this source tree.
171
+ */const nn=Y("GitPullRequest",[["circle",{cx:"18",cy:"18",r:"3",key:"1xkwt0"}],["circle",{cx:"6",cy:"6",r:"3",key:"1lh9wr"}],["path",{d:"M13 6h3a2 2 0 0 1 2 2v7",key:"1yeb86"}],["line",{x1:"6",x2:"6",y1:"9",y2:"21",key:"rroup"}]]);/**
172
+ * @license lucide-react v0.460.0 - ISC
173
+ *
174
+ * This source code is licensed under the ISC license.
175
+ * See the LICENSE file in the root directory of this source tree.
176
+ */const ys=Y("Globe",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20",key:"13o1zl"}],["path",{d:"M2 12h20",key:"9i4pu4"}]]);/**
177
+ * @license lucide-react v0.460.0 - ISC
178
+ *
179
+ * This source code is licensed under the ISC license.
180
+ * See the LICENSE file in the root directory of this source tree.
181
+ */const rn=Y("House",[["path",{d:"M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8",key:"5wwlr5"}],["path",{d:"M3 10a2 2 0 0 1 .709-1.528l7-5.999a2 2 0 0 1 2.582 0l7 5.999A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z",key:"1d0kgt"}]]);/**
182
+ * @license lucide-react v0.460.0 - ISC
183
+ *
184
+ * This source code is licensed under the ISC license.
185
+ * See the LICENSE file in the root directory of this source tree.
186
+ */const Fs=Y("Inbox",[["polyline",{points:"22 12 16 12 14 15 10 15 8 12 2 12",key:"o97t9d"}],["path",{d:"M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z",key:"oot6mr"}]]);/**
187
+ * @license lucide-react v0.460.0 - ISC
188
+ *
189
+ * This source code is licensed under the ISC license.
190
+ * See the LICENSE file in the root directory of this source tree.
191
+ */const ft=Y("KeyRound",[["path",{d:"M2.586 17.414A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814a6.5 6.5 0 1 0-4-4z",key:"1s6t7t"}],["circle",{cx:"16.5",cy:"7.5",r:".5",fill:"currentColor",key:"w0ekpg"}]]);/**
192
+ * @license lucide-react v0.460.0 - ISC
193
+ *
194
+ * This source code is licensed under the ISC license.
195
+ * See the LICENSE file in the root directory of this source tree.
196
+ */const ln=Y("Layers",[["path",{d:"m12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83Z",key:"8b97xw"}],["path",{d:"m22 17.65-9.17 4.16a2 2 0 0 1-1.66 0L2 17.65",key:"dd6zsq"}],["path",{d:"m22 12.65-9.17 4.16a2 2 0 0 1-1.66 0L2 12.65",key:"ep9fru"}]]);/**
197
+ * @license lucide-react v0.460.0 - ISC
198
+ *
199
+ * This source code is licensed under the ISC license.
200
+ * See the LICENSE file in the root directory of this source tree.
201
+ */const Jt=Y("LayoutDashboard",[["rect",{width:"7",height:"9",x:"3",y:"3",rx:"1",key:"10lvy0"}],["rect",{width:"7",height:"5",x:"14",y:"3",rx:"1",key:"16une8"}],["rect",{width:"7",height:"9",x:"14",y:"12",rx:"1",key:"1hutg5"}],["rect",{width:"7",height:"5",x:"3",y:"16",rx:"1",key:"ldoo1y"}]]);/**
202
+ * @license lucide-react v0.460.0 - ISC
203
+ *
204
+ * This source code is licensed under the ISC license.
205
+ * See the LICENSE file in the root directory of this source tree.
206
+ */const it=Y("LayoutTemplate",[["rect",{width:"18",height:"7",x:"3",y:"3",rx:"1",key:"f1a2em"}],["rect",{width:"9",height:"7",x:"3",y:"14",rx:"1",key:"jqznyg"}],["rect",{width:"5",height:"7",x:"16",y:"14",rx:"1",key:"q5h2i8"}]]);/**
207
+ * @license lucide-react v0.460.0 - ISC
208
+ *
209
+ * This source code is licensed under the ISC license.
210
+ * See the LICENSE file in the root directory of this source tree.
211
+ */const je=Y("LoaderCircle",[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]]);/**
212
+ * @license lucide-react v0.460.0 - ISC
213
+ *
214
+ * This source code is licensed under the ISC license.
215
+ * See the LICENSE file in the root directory of this source tree.
216
+ */const Ct=Y("MapPin",[["path",{d:"M20 10c0 4.993-5.539 10.193-7.399 11.799a1 1 0 0 1-1.202 0C9.539 20.193 4 14.993 4 10a8 8 0 0 1 16 0",key:"1r0f0z"}],["circle",{cx:"12",cy:"10",r:"3",key:"ilqhr7"}]]);/**
217
+ * @license lucide-react v0.460.0 - ISC
218
+ *
219
+ * This source code is licensed under the ISC license.
220
+ * See the LICENSE file in the root directory of this source tree.
221
+ */const Os=Y("Map",[["path",{d:"M14.106 5.553a2 2 0 0 0 1.788 0l3.659-1.83A1 1 0 0 1 21 4.619v12.764a1 1 0 0 1-.553.894l-4.553 2.277a2 2 0 0 1-1.788 0l-4.212-2.106a2 2 0 0 0-1.788 0l-3.659 1.83A1 1 0 0 1 3 19.381V6.618a1 1 0 0 1 .553-.894l4.553-2.277a2 2 0 0 1 1.788 0z",key:"169xi5"}],["path",{d:"M15 5.764v15",key:"1pn4in"}],["path",{d:"M9 3.236v15",key:"1uimfh"}]]);/**
222
+ * @license lucide-react v0.460.0 - ISC
223
+ *
224
+ * This source code is licensed under the ISC license.
225
+ * See the LICENSE file in the root directory of this source tree.
226
+ */const on=Y("Maximize2",[["polyline",{points:"15 3 21 3 21 9",key:"mznyad"}],["polyline",{points:"9 21 3 21 3 15",key:"1avn1i"}],["line",{x1:"21",x2:"14",y1:"3",y2:"10",key:"ota7mn"}],["line",{x1:"3",x2:"10",y1:"21",y2:"14",key:"1atl0r"}]]);/**
227
+ * @license lucide-react v0.460.0 - ISC
228
+ *
229
+ * This source code is licensed under the ISC license.
230
+ * See the LICENSE file in the root directory of this source tree.
231
+ */const cn=Y("Minus",[["path",{d:"M5 12h14",key:"1ays0h"}]]);/**
232
+ * @license lucide-react v0.460.0 - ISC
233
+ *
234
+ * This source code is licensed under the ISC license.
235
+ * See the LICENSE file in the root directory of this source tree.
236
+ */const dn=Y("OctagonAlert",[["path",{d:"M12 16h.01",key:"1drbdi"}],["path",{d:"M12 8v4",key:"1got3b"}],["path",{d:"M15.312 2a2 2 0 0 1 1.414.586l4.688 4.688A2 2 0 0 1 22 8.688v6.624a2 2 0 0 1-.586 1.414l-4.688 4.688a2 2 0 0 1-1.414.586H8.688a2 2 0 0 1-1.414-.586l-4.688-4.688A2 2 0 0 1 2 15.312V8.688a2 2 0 0 1 .586-1.414l4.688-4.688A2 2 0 0 1 8.688 2z",key:"1fd625"}]]);/**
237
+ * @license lucide-react v0.460.0 - ISC
238
+ *
239
+ * This source code is licensed under the ISC license.
240
+ * See the LICENSE file in the root directory of this source tree.
241
+ */const vt=Y("Package",[["path",{d:"M11 21.73a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73z",key:"1a0edw"}],["path",{d:"M12 22V12",key:"d0xqtd"}],["path",{d:"m3.3 7 7.703 4.734a2 2 0 0 0 1.994 0L20.7 7",key:"yx3hmr"}],["path",{d:"m7.5 4.27 9 5.15",key:"1c824w"}]]);/**
242
+ * @license lucide-react v0.460.0 - ISC
243
+ *
244
+ * This source code is licensed under the ISC license.
245
+ * See the LICENSE file in the root directory of this source tree.
246
+ */const mn=Y("Palette",[["circle",{cx:"13.5",cy:"6.5",r:".5",fill:"currentColor",key:"1okk4w"}],["circle",{cx:"17.5",cy:"10.5",r:".5",fill:"currentColor",key:"f64h9f"}],["circle",{cx:"8.5",cy:"7.5",r:".5",fill:"currentColor",key:"fotxhn"}],["circle",{cx:"6.5",cy:"12.5",r:".5",fill:"currentColor",key:"qy21gx"}],["path",{d:"M12 2C6.5 2 2 6.5 2 12s4.5 10 10 10c.926 0 1.648-.746 1.648-1.688 0-.437-.18-.835-.437-1.125-.29-.289-.438-.652-.438-1.125a1.64 1.64 0 0 1 1.668-1.668h1.996c3.051 0 5.555-2.503 5.555-5.554C21.965 6.012 17.461 2 12 2z",key:"12rzf8"}]]);/**
247
+ * @license lucide-react v0.460.0 - ISC
248
+ *
249
+ * This source code is licensed under the ISC license.
250
+ * See the LICENSE file in the root directory of this source tree.
251
+ */const hn=Y("PanelLeftClose",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}],["path",{d:"m16 15-3-3 3-3",key:"14y99z"}]]);/**
252
+ * @license lucide-react v0.460.0 - ISC
253
+ *
254
+ * This source code is licensed under the ISC license.
255
+ * See the LICENSE file in the root directory of this source tree.
256
+ */const un=Y("PanelLeftOpen",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}],["path",{d:"m14 9 3 3-3 3",key:"8010ee"}]]);/**
257
+ * @license lucide-react v0.460.0 - ISC
258
+ *
259
+ * This source code is licensed under the ISC license.
260
+ * See the LICENSE file in the root directory of this source tree.
261
+ */const xn=Y("PanelsTopLeft",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M3 9h18",key:"1pudct"}],["path",{d:"M9 21V9",key:"1oto5p"}]]);/**
262
+ * @license lucide-react v0.460.0 - ISC
263
+ *
264
+ * This source code is licensed under the ISC license.
265
+ * See the LICENSE file in the root directory of this source tree.
266
+ */const pn=Y("Pen",[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}]]);/**
267
+ * @license lucide-react v0.460.0 - ISC
268
+ *
269
+ * This source code is licensed under the ISC license.
270
+ * See the LICENSE file in the root directory of this source tree.
271
+ */const rt=Y("Plug",[["path",{d:"M12 22v-5",key:"1ega77"}],["path",{d:"M9 8V2",key:"14iosj"}],["path",{d:"M15 8V2",key:"18g5xt"}],["path",{d:"M18 8v5a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V8Z",key:"osxo6l"}]]);/**
272
+ * @license lucide-react v0.460.0 - ISC
273
+ *
274
+ * This source code is licensed under the ISC license.
275
+ * See the LICENSE file in the root directory of this source tree.
276
+ */const gn=Y("PowerOff",[["path",{d:"M18.36 6.64A9 9 0 0 1 20.77 15",key:"dxknvb"}],["path",{d:"M6.16 6.16a9 9 0 1 0 12.68 12.68",key:"1x7qb5"}],["path",{d:"M12 2v4",key:"3427ic"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]]);/**
277
+ * @license lucide-react v0.460.0 - ISC
278
+ *
279
+ * This source code is licensed under the ISC license.
280
+ * See the LICENSE file in the root directory of this source tree.
281
+ */const Bs=Y("Puzzle",[["path",{d:"M15.39 4.39a1 1 0 0 0 1.68-.474 2.5 2.5 0 1 1 3.014 3.015 1 1 0 0 0-.474 1.68l1.683 1.682a2.414 2.414 0 0 1 0 3.414L19.61 15.39a1 1 0 0 1-1.68-.474 2.5 2.5 0 1 0-3.014 3.015 1 1 0 0 1 .474 1.68l-1.683 1.682a2.414 2.414 0 0 1-3.414 0L8.61 19.61a1 1 0 0 0-1.68.474 2.5 2.5 0 1 1-3.014-3.015 1 1 0 0 0 .474-1.68l-1.683-1.682a2.414 2.414 0 0 1 0-3.414L4.39 8.61a1 1 0 0 1 1.68.474 2.5 2.5 0 1 0 3.014-3.015 1 1 0 0 1-.474-1.68l1.683-1.682a2.414 2.414 0 0 1 3.414 0z",key:"w46dr5"}]]);/**
282
+ * @license lucide-react v0.460.0 - ISC
283
+ *
284
+ * This source code is licensed under the ISC license.
285
+ * See the LICENSE file in the root directory of this source tree.
286
+ */const jn=Y("Radio",[["path",{d:"M4.9 19.1C1 15.2 1 8.8 4.9 4.9",key:"1vaf9d"}],["path",{d:"M7.8 16.2c-2.3-2.3-2.3-6.1 0-8.5",key:"u1ii0m"}],["circle",{cx:"12",cy:"12",r:"2",key:"1c9p78"}],["path",{d:"M16.2 7.8c2.3 2.3 2.3 6.1 0 8.5",key:"1j5fej"}],["path",{d:"M19.1 4.9C23 8.8 23 15.1 19.1 19",key:"10b0cb"}]]);/**
287
+ * @license lucide-react v0.460.0 - ISC
288
+ *
289
+ * This source code is licensed under the ISC license.
290
+ * See the LICENSE file in the root directory of this source tree.
291
+ */const fn=Y("Redo2",[["path",{d:"m15 14 5-5-5-5",key:"12vg1m"}],["path",{d:"M20 9H9.5A5.5 5.5 0 0 0 4 14.5A5.5 5.5 0 0 0 9.5 20H13",key:"6uklza"}]]);/**
292
+ * @license lucide-react v0.460.0 - ISC
293
+ *
294
+ * This source code is licensed under the ISC license.
295
+ * See the LICENSE file in the root directory of this source tree.
296
+ */const vn=Y("Share2",[["circle",{cx:"18",cy:"5",r:"3",key:"gq8acd"}],["circle",{cx:"6",cy:"12",r:"3",key:"w7nqdw"}],["circle",{cx:"18",cy:"19",r:"3",key:"1xt0gg"}],["line",{x1:"8.59",x2:"15.42",y1:"13.51",y2:"17.49",key:"47mynk"}],["line",{x1:"15.41",x2:"8.59",y1:"6.51",y2:"10.49",key:"1n3mei"}]]);/**
297
+ * @license lucide-react v0.460.0 - ISC
298
+ *
299
+ * This source code is licensed under the ISC license.
300
+ * See the LICENSE file in the root directory of this source tree.
301
+ */const bs=Y("ShieldCheck",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);/**
302
+ * @license lucide-react v0.460.0 - ISC
303
+ *
304
+ * This source code is licensed under the ISC license.
305
+ * See the LICENSE file in the root directory of this source tree.
306
+ */const yn=Y("Shield",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}]]);/**
307
+ * @license lucide-react v0.460.0 - ISC
308
+ *
309
+ * This source code is licensed under the ISC license.
310
+ * See the LICENSE file in the root directory of this source tree.
311
+ */const bn=Y("SquarePen",[["path",{d:"M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7",key:"1m0v6g"}],["path",{d:"M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z",key:"ohrbg2"}]]);/**
312
+ * @license lucide-react v0.460.0 - ISC
313
+ *
314
+ * This source code is licensed under the ISC license.
315
+ * See the LICENSE file in the root directory of this source tree.
316
+ */const kn=Y("Square",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]]);/**
317
+ * @license lucide-react v0.460.0 - ISC
318
+ *
319
+ * This source code is licensed under the ISC license.
320
+ * See the LICENSE file in the root directory of this source tree.
321
+ */const ea=Y("Tag",[["path",{d:"M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z",key:"vktsd0"}],["circle",{cx:"7.5",cy:"7.5",r:".5",fill:"currentColor",key:"kqv944"}]]);/**
322
+ * @license lucide-react v0.460.0 - ISC
323
+ *
324
+ * This source code is licensed under the ISC license.
325
+ * See the LICENSE file in the root directory of this source tree.
326
+ */const Nn=Y("Target",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["circle",{cx:"12",cy:"12",r:"6",key:"1vlfrh"}],["circle",{cx:"12",cy:"12",r:"2",key:"1c9p78"}]]);/**
327
+ * @license lucide-react v0.460.0 - ISC
328
+ *
329
+ * This source code is licensed under the ISC license.
330
+ * See the LICENSE file in the root directory of this source tree.
331
+ */const wn=Y("Undo2",[["path",{d:"M9 14 4 9l5-5",key:"102s5s"}],["path",{d:"M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11",key:"f3b9sd"}]]);/**
332
+ * @license lucide-react v0.460.0 - ISC
333
+ *
334
+ * This source code is licensed under the ISC license.
335
+ * See the LICENSE file in the root directory of this source tree.
336
+ */const Sn=Y("User",[["path",{d:"M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2",key:"975kel"}],["circle",{cx:"12",cy:"7",r:"4",key:"17ys0d"}]]);/**
337
+ * @license lucide-react v0.460.0 - ISC
338
+ *
339
+ * This source code is licensed under the ISC license.
340
+ * See the LICENSE file in the root directory of this source tree.
341
+ */const sa=Y("Users",[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["path",{d:"M22 21v-2a4 4 0 0 0-3-3.87",key:"kshegd"}],["path",{d:"M16 3.13a4 4 0 0 1 0 7.75",key:"1da9ce"}]]);/**
342
+ * @license lucide-react v0.460.0 - ISC
343
+ *
344
+ * This source code is licensed under the ISC license.
345
+ * See the LICENSE file in the root directory of this source tree.
346
+ */const yt=Y("Zap",[["path",{d:"M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z",key:"1xq2db"}]]),Cn=200,zn=5*60*1e3,Ge=new Map;function Tn(s){const t=Ge.get(s);return t?Date.now()-t.ts>zn?(Ge.delete(s),null):t.data:null}function Ks(s,t){Ge.size>=Cn&&[...Ge.entries()].sort((i,n)=>i[1].ts-n[1].ts).slice(0,50).map(([i])=>i).forEach(i=>Ge.delete(i)),Ge.set(s,{data:t,ts:Date.now()})}function Mn(s){if(!s||s==="/")return[{label:"/",path:"/"}];const t=s.split("/").filter(Boolean),a=[];let i="";for(let n=0;n<t.length;n++)i+="/"+t[n],a.push({label:t[n],path:i});return a}function $n(s){return[...s].sort((t,a)=>t.isDir!==a.isDir?t.isDir?-1:1:t.name.localeCompare(a.name,void 0,{sensitivity:"base"}))}function An(s){const t=s.trim();return t?t!==s?{ok:!1,reason:"Name cannot have leading or trailing whitespace."}:t==="."?{ok:!1,reason:"Name cannot be '.'."}:t===".."?{ok:!1,reason:"Name cannot be '..'."}:t.startsWith("-")?{ok:!1,reason:"Name cannot start with '-'."}:t.length>255?{ok:!1,reason:"Name cannot be longer than 255 characters."}:/[/\0:*?"<>|]/.test(t)?{ok:!1,reason:'Name cannot contain / \\ : * ? " < > |'}:{ok:!0}:{ok:!1,reason:"Name cannot be empty."}}function ta({value:s,onChange:t,initialPath:a,projectsDirectory:i,rootLabel:n="Home",height:l=360}){const[c,o]=r.useState(a??i??""),[p,x]=r.useState(new Set),[h,d]=r.useState(-1),[m,u]=r.useState(null),[g,f]=r.useState({}),[b,A]=r.useState(!1),[y,v]=r.useState(null),[L,$]=r.useState(!1),[R,P]=r.useState(""),[S,q]=r.useState(null),[O,k]=r.useState(!1),N=r.useRef(null),D=r.useCallback(async E=>{try{const le=Tn(E);if(le)return le;const te=await w.get("/fs?path="+encodeURIComponent(E));return Ks(E,te),te}catch{return null}},[]),j=r.useCallback(async E=>{var le;A(!0),v(null);try{const te=await w.get("/fs?path="+encodeURIComponent(E));Ks(E,te),u(te),d(-1)}catch(te){const ue=((le=te.data)==null?void 0:le.message)??te.message??"Failed to load directory";v(ue)}finally{A(!1)}},[]);r.useEffect(()=>{c?j(c):w.get("/fs").then(E=>{Ks("",E),u(E),o(E.path),E.path!==s&&t(E.path)}).catch(()=>{v("Could not determine home directory."),A(!1)})},[c]),r.useEffect(()=>{s&&s!==c&&o(s)},[s]);const M=m?$n(m.entries):[],F=M.filter(E=>E.isDir),C=M,_=E=>{E.isDir&&(o(E.path),t(E.path))},ae=()=>{m!=null&&m.parent&&(o(m.parent),t(m.parent))},J=E=>{E!==c&&(o(E),t(E))},U=async()=>{const E=await D("");E&&(o(E.path),t(E.path))},G=async()=>{if(!i)return;const E=await D(i);E&&(o(E.path),t(E.path))},ee=()=>{$(!0),P(""),q(null),setTimeout(()=>{var E;return(E=N.current)==null?void 0:E.focus()},0)},Z=()=>{$(!1),P(""),q(null)},re=async()=>{var le;const E=An(R);if(!E.ok){q(E.reason);return}k(!0),q(null);try{const te=await w.post("/fs/mkdir",{parent:c,name:R.trim()});Ge.delete(c),await j(c),t(te.path),$(!1),P("")}catch(te){const ue=te;ue.status===409?q(`A folder named "${R.trim()}" already exists.`):q(((le=ue.data)==null?void 0:le.message)??te.message??"Failed to create folder.")}finally{k(!1)}},fe=E=>{E.key==="Enter"?(E.preventDefault(),re()):E.key==="Escape"&&(E.preventDefault(),Z())},V=E=>{x(le=>{const te=new Set(le);return te.has(E)?te.delete(E):te.add(E),te}),g[E]||D(E).then(le=>{le&&f(te=>({...te,[E]:le.entries.filter(ue=>ue.isDir)}))})},I=E=>{if(!m)return;const le=C.filter(de=>de.isDir),te=C.filter(de=>!de.isDir),ue=[...le,...te];if(E.key==="ArrowDown")E.preventDefault(),d(de=>Math.min(de+1,ue.length-1));else if(E.key==="ArrowUp")E.preventDefault(),d(de=>Math.max(de-1,0));else if(E.key==="Enter"||E.key===" "){E.preventDefault();const de=ue[h];de&&(E.key==="Enter"&&de.isDir?_(de):de.isDir&&t(de.path))}else E.key==="Backspace"&&(E.preventDefault(),ae())},B=Mn((m==null?void 0:m.path)??c??"/"),H=m==null?void 0:m.parent,ne=H!=null,W=c.split("/").filter(Boolean).at(-1)??"/";return e.jsxs("div",{className:"file-browser",onKeyDown:I,tabIndex:-1,children:[e.jsx("div",{className:"file-browser-breadcrumb",role:"navigation","aria-label":"Path breadcrumb",children:B.map((E,le)=>e.jsxs("span",{className:"file-browser-breadcrumb-item",children:[le>0&&e.jsx("span",{className:"file-browser-breadcrumb-sep","aria-hidden":!0,children:"/"}),e.jsx("button",{type:"button",className:"file-browser-breadcrumb-btn",onClick:()=>J(E.path),title:E.path,children:le===0?E.path==="/"?"/":n:E.label})]},E.path))}),e.jsxs("div",{className:"file-browser-toolbar",children:[e.jsxs("div",{className:"file-browser-toolbar-left",children:[e.jsx("button",{type:"button",className:"file-browser-tool-btn",onClick:ae,disabled:!ne,title:"Go up (Backspace)","aria-label":"Go up one level",children:e.jsx(Xt,{size:13})}),e.jsx("button",{type:"button",className:"file-browser-tool-btn",onClick:()=>j(c),disabled:b,title:"Refresh","aria-label":"Refresh",children:e.jsx(ce,{size:13,className:b?"spin":""})}),e.jsx("button",{type:"button",className:"file-browser-tool-btn",onClick:ee,title:"New folder","aria-label":"Create new folder",children:e.jsx(en,{size:13})}),e.jsxs("div",{className:"file-browser-chips",children:[e.jsxs("button",{type:"button",className:"file-browser-chip",onClick:U,children:[e.jsx(rn,{size:11})," ",n]}),i&&e.jsxs("button",{type:"button",className:"file-browser-chip",onClick:G,title:i,children:[e.jsx(Ja,{size:11})," ",i.split("/").filter(Boolean).at(-1)??"Projects"]})]})]}),L?e.jsxs("div",{className:"file-browser-mkdir",children:[e.jsx("input",{ref:N,type:"text",className:"file-browser-mkdir-input",placeholder:"Folder name",value:R,onChange:E=>{P(E.target.value),q(null)},onKeyDown:fe,"aria-label":"New folder name","aria-invalid":S?"true":void 0,"aria-describedby":S?"mkdir-error":void 0,disabled:O,maxLength:255}),S?e.jsx("span",{id:"mkdir-error",className:"file-browser-mkdir-error",role:"alert",children:S}):e.jsx("span",{className:"file-browser-mkdir-hint",children:"Enter to create, Esc to cancel"})]}):e.jsx("span",{className:"file-browser-count-hint",children:b?"…":`${M.length} in ${W}`})]}),y&&e.jsxs("div",{className:"file-browser-error",children:[e.jsx(dt,{size:13}),e.jsx("span",{children:y}),e.jsx("button",{type:"button",className:"file-browser-retry",onClick:()=>j(c),children:"Retry"})]}),e.jsxs("div",{className:"file-browser-body",style:{height:l},children:[e.jsx("div",{className:"file-browser-pane file-browser-tree","aria-label":"Folder tree",children:b&&!m?e.jsx(Rn,{}):e.jsx(aa,{path:c,entries:F,expanded:p,childrenMap:g,onToggle:V,onNavigate:_,level:0})}),e.jsxs("div",{className:"file-browser-pane file-browser-flat","aria-label":"Directory contents",children:[e.jsxs("div",{className:"file-browser-flat-header",children:[e.jsx("span",{children:"Name"}),e.jsx("span",{children:"Type"})]}),b&&!m?e.jsx(In,{}):e.jsxs(e.Fragment,{children:[(m==null?void 0:m.truncated)&&e.jsxs("div",{className:"file-browser-truncated-banner",role:"status",children:["Showing first 500 of ",m.totalEntries," entries. Navigate into a subfolder to see more."]}),C.length===0?e.jsx("div",{className:"file-browser-empty",children:"This folder is empty"}):e.jsx("div",{className:"file-browser-flat-list",children:C.map((E,le)=>{const te=E.isDir,ue=le===h,de=E.path===s;return e.jsxs("div",{role:"option","aria-selected":de,className:["file-browser-row",te?"file-browser-row--dir":"file-browser-row--file",ue&&"file-browser-row--selected",de&&te&&"file-browser-row--active",!te&&"file-browser-row--disabled"].filter(Boolean).join(" "),onClick:()=>{te&&(d(le),t(E.path))},onDoubleClick:()=>{te&&_(E)},title:E.path,children:[e.jsx("span",{className:"file-browser-row-icon",children:te?e.jsx(Ee,{size:13}):e.jsx(Qa,{size:13})}),e.jsx("span",{className:"file-browser-row-name",children:E.name}),e.jsx("span",{className:"file-browser-row-type",children:te?"Folder":""})]},E.path)})})]})]})]}),e.jsxs("div",{className:"file-browser-footer-hint",children:["Select a folder, then click Add. Use ",e.jsx("kbd",{children:"↑"})," ",e.jsx("kbd",{children:"↓"})," to navigate, ",e.jsx("kbd",{children:"Enter"})," to confirm."]})]})}function aa({path:s,entries:t,expanded:a,childrenMap:i,onToggle:n,onNavigate:l,level:c}){return e.jsx("ul",{className:"file-browser-tree-list",role:"group",children:t.map(o=>{const p=a.has(o.path),x=i[o.path]??[];return e.jsxs("li",{className:"file-browser-tree-node",children:[e.jsxs("div",{className:["file-browser-tree-row",p&&"file-browser-tree-row--expanded"].filter(Boolean).join(" "),style:{paddingLeft:`${c*16+8}px`},children:[e.jsx("button",{type:"button",className:"file-browser-tree-toggle",onClick:h=>{h.stopPropagation(),n(o.path)},"aria-label":p?"Collapse":"Expand",children:(x.length>0,p?e.jsx(Fe,{size:11}):e.jsx(_e,{size:11}))}),e.jsxs("button",{type:"button",className:"file-browser-tree-name",onClick:()=>l(o),title:o.path,children:[e.jsx(Ee,{size:12}),e.jsx("span",{children:o.name})]})]}),p&&x.length>0&&e.jsx(aa,{path:o.path,entries:x,expanded:a,childrenMap:i,onToggle:n,onNavigate:l,level:c+1})]},o.path)})})}function Rn(){return e.jsx("div",{className:"file-browser-skeleton-wrap",children:[80,60,90,55,70].map((s,t)=>e.jsx("div",{className:"file-browser-skeleton-row",style:{width:s}},t))})}function In(){return e.jsx("div",{className:"file-browser-skeleton-wrap",children:[60,90,70,50,80,65].map((s,t)=>e.jsx("div",{className:"file-browser-skeleton-row",style:{width:s}},t))})}const lt=[{id:"overview",label:"Overview",icon:Jt},{id:"chat",label:"Chat",icon:qs},{id:"agents",label:"Agents",icon:qe},{id:"artifacts",label:"Glyphs",icon:Os},{id:"tasks",label:"Tasks",icon:ps},{id:"activity",label:"Activity",icon:Te},{id:"background",label:"Active",icon:jn},{id:"skills",label:"Skills",icon:Oe},{id:"memory",label:"Memory",icon:Le},{id:"mods",label:"Mods",icon:Bs},{id:"schedules",label:"Schedules",icon:Ds},{id:"history",label:"History",icon:gs},{id:"minimax",label:"Usage",icon:jt},{id:"settings",label:"Settings",icon:mt}];function Ln({activeTab:s,onTabChange:t,wsStatus:a,version:i,activeProject:n,projects:l,onProjectChange:c,onProjectsRefresh:o,onOpenSearch:p,settings:x,rightSlot:h,notificationsSlot:d,showTabs:m=!0,extraTabs:u}){return e.jsxs("header",{className:"topbar",children:[e.jsxs("div",{className:"topbar-row",children:[e.jsxs("div",{className:"brand",children:[e.jsx("span",{className:"brand-logo","aria-hidden":"true",children:"ᛒ"}),e.jsx("span",{className:"brand-title",children:"Bizar"}),e.jsx("span",{className:"brand-version",children:i})]}),e.jsx(En,{activeProject:n,projects:l,onChange:c,onRefresh:o,settings:x??null}),e.jsxs("button",{type:"button",className:"topbar-search",onClick:p,title:"Search (Ctrl/Cmd+K)","aria-label":"Open search",children:[e.jsx(ye,{size:14}),e.jsx("span",{className:"muted",children:"Search…"}),e.jsx("kbd",{children:"⌘K"})]}),e.jsx("div",{className:"topbar-spacer"}),e.jsxs("div",{className:"topbar-right",children:[d,h,e.jsxs("div",{className:X("ws-status",`ws-${a}`),title:`WebSocket: ${a}`,children:[e.jsx("span",{className:"ws-dot"}),e.jsx("span",{className:"ws-label",children:a})]})]})]}),m&&e.jsxs("nav",{className:"tabs-row",role:"tablist","aria-label":"Primary tabs",children:[lt.map(g=>{const f=g.icon,b=g.id===s;return e.jsxs("button",{type:"button",role:"tab","aria-selected":b,className:X("tab",b&&"tab-active"),onClick:()=>t(g.id),title:g.label,children:[e.jsx(f,{size:14,className:"tab-icon"}),e.jsx("span",{className:"tab-label",children:g.label})]},g.id)}),u&&u.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"tab-separator","aria-hidden":"true"}),u.map(g=>{const f=g.icon,b=g.id===s;return e.jsxs("button",{type:"button",role:"tab","aria-selected":b,className:X("tab","tab-mod",b&&"tab-active"),onClick:()=>t(g.id),title:`${g.label} (mod)`,children:[e.jsx(f,{size:14,className:"tab-icon"}),e.jsx("span",{className:"tab-label",children:g.label}),e.jsx("span",{className:"tab-badge",children:"mod"})]},g.id)})]})]})]})}function En({activeProject:s,projects:t,onChange:a,onRefresh:i,settings:n}){const[l,c]=r.useState(!1),o=Pe();r.useEffect(()=>{if(!l)return;const x=()=>c(!1);return document.addEventListener("click",x),()=>document.removeEventListener("click",x)},[l]);const p=()=>{o.open({title:"Add project",children:e.jsx(Pn,{settings:n,onAdd:async(x,h)=>{try{await w.post("/projects",{path:x,name:h}),i(),c(!1),o.close()}catch(d){alert(`Add failed: ${d.message}`)}}}),footer:e.jsx("div",{className:"modal-footer-actions",children:e.jsx(T,{variant:"ghost",onClick:()=>o.close(),children:"Cancel"})})})};return e.jsxs("div",{className:"project-selector",onClick:x=>x.stopPropagation(),children:[e.jsxs("button",{type:"button",className:"project-selector-btn",onClick:()=>c(x=>!x),title:"Switch active project","aria-haspopup":"menu","aria-expanded":l,children:[e.jsx(Ee,{size:14}),e.jsx("span",{className:"project-selector-name",children:(s==null?void 0:s.name)||"(no project)"}),e.jsx(Fe,{size:12})]}),l&&e.jsxs("div",{className:"project-selector-menu",children:[e.jsxs("div",{className:"project-selector-menu-head",children:[e.jsxs("span",{className:"muted",children:[t.length," project",t.length===1?"":"s"]}),e.jsxs("div",{className:"project-selector-menu-actions",children:[e.jsx("button",{type:"button",className:"icon-btn",onClick:i,title:"Refresh","aria-label":"Refresh projects",children:e.jsx(ce,{size:12})}),e.jsx("button",{type:"button",className:"icon-btn",onClick:p,title:"Add project","aria-label":"Add project",children:e.jsx(Me,{size:12})})]})]}),e.jsxs("ul",{className:"project-selector-list",children:[t.length===0&&e.jsx("li",{className:"muted project-selector-empty",children:"No projects. Add one to start."}),t.map(x=>e.jsx("li",{children:e.jsxs("button",{type:"button",className:X("project-selector-item",(s==null?void 0:s.id)===x.id&&"active"),onClick:()=>{a(x.id),c(!1)},children:[e.jsx("span",{className:"project-selector-item-name",children:x.name}),e.jsx("span",{className:"project-selector-item-status",children:x.status})]})},x.id))]})]})]})}function Pn({settings:s,onAdd:t}){var d,m;const[a,i]=r.useState(((d=s==null?void 0:s.dashboard)==null?void 0:d.projectsDirectory)??""),[n,l]=r.useState(""),[c,o]=r.useState(!1),[p,x]=r.useState(null),h=async()=>{var u;if(a){o(!0),x(null);try{await w.get("/fs?path="+encodeURIComponent(a)),t(a,n||null)}catch(g){const f=g;f.status===404?x("That folder no longer exists. Pick another."):x(((u=f.data)==null?void 0:u.message)??g.message??"Validation failed.")}finally{o(!1)}}};return e.jsxs("div",{children:[e.jsx("label",{className:"field-label",children:"Folder"}),e.jsx(ta,{value:a,onChange:u=>{i(u),x(null)},projectsDirectory:(m=s==null?void 0:s.dashboard)==null?void 0:m.projectsDirectory,height:320}),p&&e.jsx("p",{className:"field-help",style:{color:"var(--error)",marginTop:4},children:p}),e.jsxs("div",{style:{marginTop:"var(--space-3)"},children:[e.jsx("label",{className:"field-label",htmlFor:"topbar-add-project-name",children:"Name (optional)"}),e.jsx("input",{id:"topbar-add-project-name",className:"input",type:"text",placeholder:"My App",value:n,onChange:u=>l(u.target.value)})]}),e.jsx("div",{style:{marginTop:"var(--space-3)",display:"flex",justifyContent:"flex-end"},children:e.jsxs(T,{variant:"primary",onClick:h,disabled:!a||c,children:[c?e.jsx("span",{className:"btn-spinner"}):null,c?"Checking…":"Add"]})})]})}function Dn({tabs:s,activeTab:t,onTabChange:a}){const i=s.filter(l=>!l.isMod),n=s.filter(l=>l.isMod);return e.jsx("aside",{className:"sidebar","aria-label":"Primary navigation",children:e.jsxs("nav",{className:"sidebar-nav",role:"tablist",children:[i.map(l=>{const c=l.icon,o=l.id===t;return e.jsxs("button",{type:"button",role:"tab","aria-selected":o,className:X("sidebar-tab",o&&"sidebar-tab-active"),onClick:()=>a(l.id),title:l.label,children:[e.jsx(c,{size:18,"aria-hidden":!0}),e.jsx("span",{className:"sidebar-tab-label",children:l.label})]},l.id)}),n.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"sidebar-section-divider","aria-hidden":"true"}),e.jsx("div",{className:"sidebar-section-label",children:"Mods"}),n.map(l=>{const c=l.icon,o=l.id===t;return e.jsxs("button",{type:"button",role:"tab","aria-selected":o,className:X("sidebar-tab","sidebar-tab-mod",o&&"sidebar-tab-active"),onClick:()=>a(l.id),title:`${l.label} (mod)`,children:[e.jsx(c,{size:18,"aria-hidden":!0}),e.jsx("span",{className:"sidebar-tab-label",children:l.label})]},l.id)})]})]})})}const Gs=[{id:"all",label:"All"},{id:"projects",label:"Projects"},{id:"agents",label:"Agents"},{id:"tasks",label:"Tasks"},{id:"mods",label:"Mods"},{id:"schedules",label:"Schedules"},{id:"commands",label:"Commands"},{id:"settings",label:"Settings"}],zt={all:null,projects:"project",agents:"agent",tasks:"task",mods:"mod",schedules:"schedule",commands:"command",settings:"setting"};function Fn({open:s,onClose:t,onSelect:a}){const i=oe(),[n,l]=r.useState(""),[c,o]=r.useState("all"),[p,x]=r.useState([]),[h,d]=r.useState(!1),[m,u]=r.useState(0),g=r.useRef(null),f=r.useRef(null);if(r.useEffect(()=>{let v;return s&&(f.current=document.activeElement instanceof HTMLElement?document.activeElement:null,l(""),x([]),u(0),v=window.setTimeout(()=>{var L;return(L=g.current)==null?void 0:L.focus()},30)),()=>{if(v&&window.clearTimeout(v),!s)return;const L=f.current;L&&L.isConnected&&L.focus()}},[s]),r.useEffect(()=>{if(!s)return;if(!n.trim()){x([]),u(0);return}let v=!1;d(!0);const L=setTimeout(()=>{w.get(`/search?q=${encodeURIComponent(n)}&scope=${c}`).then($=>{v||(x($.results||[]),u(0))}).catch($=>{v||i.error(`Search failed: ${$.message}`)}).finally(()=>!v&&d(!1))},150);return()=>{v=!0,clearTimeout(L)}},[n,c,s,i]),!s)return null;const b={};for(const v of p){const L=v.type.toLowerCase();b[L]=b[L]||[],b[L].push(v)}const A=[];for(const v of Gs.map(L=>L.id)){const L=zt[v];L&&b[L]&&A.push(...b[L])}const y=v=>{if(v.key==="Escape")t();else if(v.key==="ArrowDown"){if(v.preventDefault(),A.length===0)return;u(L=>Math.min(L+1,A.length-1))}else if(v.key==="ArrowUp"){if(v.preventDefault(),A.length===0)return;u(L=>Math.max(L-1,0))}else v.key==="Enter"&&A[m]&&(v.preventDefault(),a(A[m]),t())};return e.jsx("div",{className:"search-modal-backdrop",onClick:t,children:e.jsxs("div",{className:"search-modal",role:"dialog","aria-modal":"true","aria-labelledby":"search-modal-title",onClick:v=>v.stopPropagation(),children:[e.jsxs("div",{className:"search-modal-head",role:"search",children:[e.jsx(ye,{size:14,"aria-hidden":!0}),e.jsx("span",{id:"search-modal-title",className:"sr-only",children:"Search"}),e.jsx("input",{ref:g,className:"search-modal-input",placeholder:"Search tasks, agents, settings, projects…",value:n,onChange:v=>l(v.target.value),onKeyDown:y,"aria-label":"Search"}),e.jsx("button",{type:"button",className:"icon-btn","aria-label":"Close",onClick:t,children:e.jsx($e,{size:14})})]}),e.jsx("div",{className:"search-modal-scopes",role:"tablist","aria-label":"Search scope",children:Gs.map(v=>e.jsx("button",{type:"button",role:"tab","aria-selected":c===v.id,className:X("search-scope",c===v.id&&"search-scope-active"),onClick:()=>o(v.id),children:v.label},v.id))}),e.jsxs("div",{className:"search-modal-body",children:[h&&e.jsx("div",{className:"muted",children:"Searching…"}),!h&&n&&A.length===0&&e.jsx("div",{className:"muted",children:"No results."}),!h&&!n&&e.jsx("div",{className:"muted",children:"Type to search…"}),Gs.map(v=>{const L=zt[v.id];if(!L)return null;const $=b[L];return!$||$.length===0?null:e.jsxs("div",{className:"search-group",children:[e.jsx("div",{className:"search-group-head",children:v.label}),$.map(R=>{const P=A.indexOf(R);return e.jsxs("button",{type:"button",className:X("search-result",P===m&&"search-result-active"),onMouseEnter:()=>u(P),onClick:()=>{a(R),t()},children:[e.jsx("span",{className:"search-result-type",children:R.type}),e.jsx("span",{className:"search-result-label",children:On(R)})]},`${R.type}-${P}`)})]},v.id)})]}),e.jsx("div",{className:"search-modal-foot",children:e.jsx("span",{className:"muted",children:"↑↓ navigate · ↵ open · esc close"})})]})})}function On(s){const t=s.item||{};if(s.type==="project")return`${t.name} — ${t.path}`;if(s.type==="agent")return`${t.name} — ${t.description||t.model||""}`;if(s.type==="task")return`${t.title} — ${t.status||""}`;if(s.type==="mod")return`${t.name} v${t.version} — ${t.description||""}`;if(s.type==="schedule")return`${t.name} (${t.type}: ${t.schedule})`;if(s.type==="command")return`${t.name} — ${t.description||""}`;if(s.type==="setting"){const a=t.value===null||t.value===void 0?"":typeof t.value=="string"?` = ${t.value}`:` = ${JSON.stringify(t.value)}`;return`${t.label}${a} — ${t.desc||""}`.trim()}return JSON.stringify(t).slice(0,80)}const Bn={info:Hs,success:He,warning:ke,error:dt};function Un({onCountChange:s,wsSubscribe:t}){const a=oe(),[i,n]=r.useState(!1),[l,c]=r.useState([]),[o,p]=r.useState(null),[x,h]=r.useState(!1),d=r.useRef(null),m=r.useRef(0),u=async()=>{var y;try{h(!0);const v=await w.get("/notifications?limit=200");c(v.notifications||[]),p(v.stats||null),m.current=((y=v.stats)==null?void 0:y.unread)||0,s==null||s(m.current)}catch(v){console.warn("[notifications] reload failed:",v.message)}finally{h(!1)}};r.useEffect(()=>{u()},[]),r.useEffect(()=>t?t(v=>{if(v.type==="notification:new"){const L=v.notification;c($=>[L,...$.filter(R=>R.id!==L.id)]),L.read||(m.current+=1,p($=>$?{...$,unread:($.unread||0)+1}:{total:1,unread:1,lastTs:L.ts,counts:{[L.severity||"info"]:1}}),s==null||s(m.current))}else v.type==="notifications:change"&&u()}):void 0,[t]),r.useEffect(()=>{if(!i)return;const y=L=>{d.current&&(d.current.contains(L.target)||n(!1))},v=L=>{L.key==="Escape"&&n(!1)};return document.addEventListener("mousedown",y),document.addEventListener("keydown",v),()=>{document.removeEventListener("mousedown",y),document.removeEventListener("keydown",v)}},[i]);const g=async()=>{try{await w.post("/notifications/read-all",{}),c(y=>y.map(v=>({...v,read:!0}))),p(y=>y&&{...y,unread:0}),m.current=0,s==null||s(0),a.success("All notifications marked as read.",1500)}catch(y){a.error(`Failed: ${y.message}`)}},f=async y=>{try{await w.post(`/notifications/${encodeURIComponent(y)}/read`,{}),c(v=>v.map(L=>L.id===y?{...L,read:!0}:L)),p(v=>v&&{...v,unread:Math.max(0,(v.unread||1)-1)}),m.current=Math.max(0,m.current-1),s==null||s(m.current)}catch(v){a.error(`Failed: ${v.message}`)}},b=async y=>{try{await w.del(`/notifications/${encodeURIComponent(y)}`),c(v=>{const L=v.find($=>$.id===y);return L&&!L.read&&(m.current=Math.max(0,m.current-1),p($=>$&&{...$,unread:Math.max(0,$.unread-1)}),s==null||s(m.current)),v.filter($=>$.id!==y)})}catch(v){a.error(`Failed: ${v.message}`)}},A=(o==null?void 0:o.unread)||0;return e.jsxs("div",{className:"notifications-root",ref:d,children:[e.jsxs("button",{type:"button",className:X("topbar-icon-btn notifications-bell",i&&"is-open"),onClick:()=>n(y=>!y),title:"Notifications","aria-label":"Notifications","aria-haspopup":"true","aria-expanded":i,children:[e.jsx(va,{size:16}),A>0&&e.jsx("span",{className:"notifications-badge",children:A>99?"99+":A})]}),i&&e.jsxs("div",{className:"notifications-panel",role:"dialog","aria-label":"Notifications",children:[e.jsxs("header",{className:"notifications-panel-head",children:[e.jsxs("div",{children:[e.jsx("strong",{children:"Notifications"}),A>0&&e.jsxs("span",{className:"muted text-sm",children:[" · ",A," unread"]})]}),e.jsxs("div",{className:"notifications-panel-head-actions",children:[e.jsxs(T,{size:"sm",variant:"ghost",onClick:g,disabled:A===0,children:[e.jsx(at,{size:12})," Mark all read"]}),e.jsx("button",{type:"button",className:"icon-btn",onClick:()=>n(!1),"aria-label":"Close",title:"Close",children:e.jsx($e,{size:14})})]})]}),e.jsx("div",{className:"notifications-list",children:x&&l.length===0?e.jsx("div",{className:"notifications-empty muted",children:"Loading…"}):l.length===0?e.jsx("div",{className:"notifications-empty muted",children:"No notifications yet."}):l.map(y=>{const v=Bn[y.severity]||Hs;return e.jsxs("div",{className:X("notification-item",!y.read&&"is-unread",`severity-${y.severity}`),children:[e.jsx(v,{size:14,className:`notification-icon severity-${y.severity}`}),e.jsxs("div",{className:"notification-body",children:[y.title&&e.jsx("div",{className:"notification-title",children:y.title}),e.jsx("div",{className:"notification-msg",children:y.message}),e.jsxs("div",{className:"notification-meta muted",children:[e.jsx("span",{className:"mono",children:y.source}),e.jsx("span",{children:"·"}),e.jsx("span",{children:Ne(y.ts)})]})]}),e.jsxs("div",{className:"notification-actions",children:[!y.read&&e.jsx("button",{type:"button",className:"icon-btn",onClick:()=>f(y.id),title:"Mark as read","aria-label":"Mark as read",children:e.jsx(at,{size:12})}),e.jsx("button",{type:"button",className:"icon-btn icon-btn-danger",onClick:()=>b(y.id),title:"Remove","aria-label":"Remove",children:e.jsx($e,{size:12})})]})]},y.id)})}),e.jsx("footer",{className:"notifications-panel-foot",children:e.jsx("span",{className:"muted text-sm",children:o?`${o.total} total · last ${Ne(o.lastTs||new Date().toISOString())}`:""})})]})]})}function qn({data:s,onClose:t}){const a=s==null?void 0:s.enabled;s==null||s.previousEnabled;const i=s==null?void 0:s.mode,n=s==null?void 0:s.defaultTemplate,l=s==null?void 0:s.lastUsedSlug,c=i==="toggle";return e.jsxs("div",{children:[c?e.jsxs("p",{style:{marginBottom:16,lineHeight:1.6},children:["Visual plan mode has been ",e.jsx("strong",{children:a?"enabled":"disabled"}),".",a?" The agent will create a plan and wait for your feedback on complex tasks.":" The agent will work without a visual plan canvas."]}):e.jsxs("div",{style:{marginBottom:16},children:[e.jsxs("p",{style:{marginBottom:8,fontWeight:600},children:["Visual Plan: ",e.jsx("span",{style:{color:a?"var(--color-success)":"var(--color-muted)"},children:a?"ON":"OFF"})]}),e.jsx("p",{style:{lineHeight:1.6,color:"var(--color-muted)",fontSize:13},children:"When enabled, the agent creates a visual plan and waits for your feedback before proceeding with complex tasks."}),n&&e.jsxs("p",{style:{marginTop:8,fontSize:13,color:"var(--color-muted)"},children:["Default template: ",e.jsx("code",{children:n})]}),l&&e.jsxs("p",{style:{fontSize:13,color:"var(--color-muted)"},children:["Last used plan: ",e.jsx("code",{children:l})]}),e.jsxs("p",{style:{marginTop:12,fontSize:13,color:"var(--color-muted)"},children:["Use ",e.jsx("code",{children:"/visual-plan on"})," or ",e.jsx("code",{children:"/visual-plan off"})," to toggle."]})]}),e.jsx("div",{style:{display:"flex",gap:8,justifyContent:"flex-end"},children:e.jsx(T,{variant:"ghost",onClick:t,children:"Close"})})]})}const Hn=["blank","feature-design","bug-investigation","decision-record","horizontal","vertical"];function _n({data:s,onClose:t}){const a=(s==null?void 0:s.templates)??Hn,i=(s==null?void 0:s.defaultTemplate)??"blank",[n,l]=r.useState(""),[c,o]=r.useState(i),[p,x]=r.useState(!1),[h,d]=r.useState(null),m=async()=>{if(!n.trim()){d("Slug is required.");return}if(!/^[a-z0-9][a-z0-9-]{0,63}$/.test(n)){d("Invalid slug. Use lowercase letters, numbers, and hyphens. Must start with an alphanumeric character.");return}x(!0),d(null);try{await w.post("/artifacts",{slug:n,template:c}),t()}catch(u){d(u.message),x(!1)}};return e.jsxs("div",{children:[e.jsxs("p",{style:{marginBottom:16,color:"var(--color-muted)",fontSize:13},children:["Create a new visual plan. Plans are stored in ",e.jsx("code",{children:"artifacts/"})," in your worktree."]}),e.jsxs("div",{style:{marginBottom:12},children:[e.jsx("label",{className:"field-label",htmlFor:"plan-slug",children:"Plan slug"}),e.jsx("input",{id:"plan-slug",className:"input",type:"text",placeholder:"e.g. my-feature",value:n,onChange:u=>{l(u.target.value),d(null)},autoFocus:!0})]}),e.jsxs("div",{style:{marginBottom:16},children:[e.jsx("label",{className:"field-label",htmlFor:"plan-template",children:"Template"}),e.jsx("select",{id:"plan-template",className:"select",value:c,onChange:u=>o(u.target.value),children:a.map(u=>e.jsx("option",{value:u,children:u},u))})]}),h&&e.jsx("p",{style:{marginBottom:12,color:"var(--color-danger)",fontSize:13},children:h}),e.jsxs("div",{style:{display:"flex",gap:8,justifyContent:"flex-end"},children:[e.jsx(T,{variant:"ghost",onClick:t,disabled:p,children:"Cancel"}),e.jsx(T,{variant:"primary",onClick:m,disabled:p||!n.trim(),children:p?"Creating…":"Create"})]})]})}function Wn({data:s,onClose:t}){const a=(s==null?void 0:s.plans)??[],i=(s==null?void 0:s.count)??a.length,n=l=>{window.open(`/artifacts/${l}/`,"_blank")};return e.jsxs("div",{children:[a.length===0?e.jsxs("p",{style:{marginBottom:16,color:"var(--color-muted)"},children:["No plans found in this worktree. Use ",e.jsx("code",{children:"/artifact new <slug>"})," to create one."]}):e.jsxs("div",{style:{marginBottom:16},children:[e.jsxs("p",{style:{marginBottom:12,fontSize:13,color:"var(--color-muted)"},children:[i," plan",i!==1?"s":""," in this worktree:"]}),e.jsx("ul",{style:{listStyle:"none",padding:0,margin:0},children:a.map(l=>e.jsxs("li",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 0",borderBottom:"1px solid var(--color-border)"},children:[e.jsx("code",{style:{fontSize:13},children:l}),e.jsx(T,{variant:"ghost",size:"sm",onClick:()=>n(l),children:"Open"})]},l))})]}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsx(T,{variant:"ghost",onClick:t,children:"Close"})})]})}function Vn({data:s,onClose:t}){const a=(s==null?void 0:s.commands)??[],i=(s==null?void 0:s.templates)??[],n=(s==null?void 0:s.statuses)??[];return e.jsxs("div",{children:[a.length>0?e.jsx("table",{style:{width:"100%",borderCollapse:"collapse",marginBottom:16,fontSize:13},children:e.jsx("tbody",{children:a.map(l=>e.jsxs("tr",{style:{borderBottom:"1px solid var(--color-border)"},children:[e.jsx("td",{style:{padding:"5px 8px 5px 0",whiteSpace:"nowrap"},children:e.jsx("code",{style:{fontSize:12},children:l.cmd})}),e.jsx("td",{style:{padding:"5px 0",color:"var(--color-muted)"},children:l.desc})]},l.cmd))})}):e.jsx("p",{style:{marginBottom:16,color:"var(--color-muted)"},children:"No commands available."}),i.length>0&&e.jsxs("div",{style:{marginBottom:12},children:[e.jsx("p",{style:{fontSize:12,color:"var(--color-muted)",marginBottom:4},children:"Available templates:"}),e.jsx("p",{style:{fontSize:13},children:i.join(", ")})]}),n.length>0&&e.jsxs("div",{style:{marginBottom:12},children:[e.jsx("p",{style:{fontSize:12,color:"var(--color-muted)",marginBottom:4},children:"Available statuses:"}),e.jsx("p",{style:{fontSize:13},children:n.join(", ")})]}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsx(T,{variant:"ghost",onClick:t,children:"Close"})})]})}function Kn({data:s,onClose:t}){const[a,i]=r.useState(!1),[n,l]=r.useState(null),c=async()=>{i(!0),l(null);try{const o=await w.post("/chat/audit",{});l(o)}catch(o){l({ok:!1,findings:[],error:o.message})}finally{i(!1)}};return e.jsx("div",{children:n===null?e.jsxs(e.Fragment,{children:[e.jsx("p",{style:{marginBottom:16,lineHeight:1.6},children:"Run a security audit of your Bizar agent configuration. The audit checks for common misconfigurations, exposed secrets, and insecure defaults."}),e.jsxs("div",{style:{display:"flex",gap:8,justifyContent:"flex-end"},children:[e.jsx(T,{variant:"ghost",onClick:t,children:"Cancel"}),e.jsx(T,{variant:"primary",onClick:c,disabled:a,children:a?"Running…":"Run Audit"})]})]}):e.jsxs(e.Fragment,{children:[n.ok?e.jsxs("div",{children:[e.jsx("p",{style:{marginBottom:12,fontWeight:600,color:"var(--color-success)"},children:"Audit passed — no issues found."}),n.findings.length>0&&e.jsx("ul",{style:{marginBottom:16,paddingLeft:20},children:n.findings.map((o,p)=>e.jsx("li",{style:{marginBottom:4,fontSize:13},children:o},p))})]}):e.jsxs("p",{style:{marginBottom:16,color:"var(--color-danger)"},children:["Audit failed: ",n.error??"unknown error"]}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsx(T,{variant:"ghost",onClick:t,children:"Close"})})]})})}function Gn({dialog:s,onClose:t}){if(!s.data)return e.jsxs("div",{children:[e.jsx("p",{style:{marginBottom:16,lineHeight:1.6},children:`Command: ${s.command}`}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsx("button",{type:"button",className:"btn",onClick:t,children:"Close"})})]});const{message:a,detail:i,url:n}=s.data;return e.jsxs("div",{children:[e.jsx("p",{style:{marginBottom:16,lineHeight:1.6},children:a??`Command: ${s.command}`}),i&&e.jsx("p",{style:{marginBottom:16,color:"var(--color-muted)",fontSize:13},children:i}),n&&e.jsx("p",{style:{marginBottom:16},children:e.jsx("a",{href:n,target:"_blank",rel:"noopener noreferrer",children:n})}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsx("button",{type:"button",className:"btn",onClick:t,children:"Close"})})]})}function Yn({dialog:s,onClose:t}){switch(s.component){case"visual-artifact":return e.jsx(qn,{data:s.data,onClose:t});case"artifact-create":return e.jsx(_n,{data:s.data,onClose:t});case"artifact-list":return e.jsx(Wn,{data:s.data,onClose:t});case"help":return e.jsx(Vn,{data:s.data,onClose:t});case"audit":return e.jsx(Kn,{data:s.data,onClose:t});default:return e.jsx(Gn,{dialog:s,onClose:t})}}function Q({variant:s="elevated",interactive:t=!1,className:a,children:i,...n}){return e.jsx("div",{className:X("card",`card-${s}`,t&&"card-interactive",a),...n,children:i})}function se({children:s,className:t}){return e.jsx("h3",{className:X("card-title",t),children:s})}function ie({children:s,className:t}){return e.jsx("div",{className:X("card-meta",t),children:s})}function Xn({setActiveTab:s,refreshKey:t=0}){var x;const[a,i]=r.useState(null),[n,l]=r.useState(!0),c=async()=>{l(!0);try{const[h,d,m]=await Promise.all([w.get("/memory/status").catch(()=>null),w.get("/memory/health").catch(()=>null),w.get("/memory/lightrag/stats").catch(()=>null)]);i({initialized:!!(h!=null&&h.initialized),mode:h==null?void 0:h.mode,projectId:h==null?void 0:h.projectId,vaultRoot:h==null?void 0:h.vaultRoot,branch:h==null?void 0:h.branch,gitClean:h==null?void 0:h.gitClean,noteCount:(h==null?void 0:h.noteCount)||0,healthScore:d==null?void 0:d.score,healthStatus:d==null?void 0:d.status,lightrag:m?{running:m.running,indexedApprox:m.indexedApprox}:void 0})}catch{i({initialized:!1})}finally{l(!1)}};r.useEffect(()=>{c()},[t]);const o=()=>s("memory"),p=(a==null?void 0:a.healthStatus)==="healthy"?"var(--success)":(a==null?void 0:a.healthStatus)==="degraded"?"var(--warning)":(a==null?void 0:a.healthStatus)==="unhealthy"?"var(--error)":"var(--text-dim)";return e.jsxs(Q,{className:"memory-overview-card",children:[e.jsxs(se,{children:[e.jsx(Le,{size:14})," Memory",e.jsxs(T,{variant:"ghost",size:"sm",style:{marginLeft:"auto"},onClick:o,children:["Open Memory ",e.jsx(ls,{size:12})]}),e.jsx(T,{variant:"ghost",size:"sm",onClick:c,"aria-label":"Refresh",title:"Refresh",children:e.jsx(ce,{size:12})})]}),e.jsx(ie,{children:"LightRAG + Obsidian vault + git sync — opens the dedicated Memory tab."}),a!=null&&a.initialized?e.jsxs("div",{className:"memory-status-card-grid",children:[e.jsxs("div",{className:"memory-status-card-cell",children:[e.jsxs("div",{className:"memory-status-card-label",children:[e.jsx(Te,{size:11})," Health"]}),e.jsx("div",{className:"memory-status-card-value",style:{color:p},children:a.healthScore!==void 0?`${a.healthScore}/100`:"—"}),e.jsx("div",{className:"memory-status-card-sub muted",children:a.healthStatus||"—"})]}),e.jsxs("div",{className:"memory-status-card-cell",children:[e.jsxs("div",{className:"memory-status-card-label",children:[e.jsx(Le,{size:11})," LightRAG"]}),e.jsx("div",{className:"memory-status-card-value",children:(x=a.lightrag)!=null&&x.running?"running":"stopped"}),e.jsx("div",{className:"memory-status-card-sub muted",children:a.lightrag?`${a.lightrag.indexedApprox} chunks`:"—"})]}),e.jsxs("div",{className:"memory-status-card-cell",children:[e.jsxs("div",{className:"memory-status-card-label",children:[e.jsx(Se,{size:11})," Vault"]}),e.jsxs("div",{className:"memory-status-card-value",children:[a.noteCount," notes"]}),e.jsx("div",{className:"memory-status-card-sub muted ellipsis",title:a.vaultRoot||"",children:a.vaultRoot?a.vaultRoot.split("/").slice(-2).join("/"):"—"})]}),e.jsxs("div",{className:"memory-status-card-cell",children:[e.jsxs("div",{className:"memory-status-card-label",children:[e.jsx(rs,{size:11})," Git"]}),e.jsx("div",{className:"memory-status-card-value",children:a.gitClean===null?a.mode==="local-only"?"local-only":"—":a.gitClean?"clean":"dirty"}),e.jsx("div",{className:"memory-status-card-sub muted",children:a.branch?`branch ${a.branch}`:os(a.branch||"")||"—"})]})]}):e.jsxs("div",{className:"muted",children:["Memory not initialised. Click ",e.jsx("strong",{children:"Open Memory"})," to set it up."]}),n&&!a&&e.jsx("div",{className:"muted text-sm",children:"Loading…"})]})}function we({icon:s,title:t,message:a,action:i,className:n}){return e.jsxs("div",{className:X("empty-state",n),children:[e.jsx("div",{className:"empty-icon",children:s??e.jsx(Fs,{size:32})}),e.jsx("div",{className:"empty-title",children:t}),a&&e.jsx("div",{className:"empty-message",children:a}),i&&e.jsx("div",{className:"empty-action",children:i})]})}function Qn({snapshot:s,settings:t,setActiveTab:a,refreshSnapshot:i}){var _,ae,J;const n=oe(),l=Pe(),c=r.useRef(null),[o,p]=r.useState(s.overview??null),[x,h]=r.useState(!s.overview),[d,m]=r.useState(s.projects||[]),[u,g]=r.useState(((_=s.activeProject)==null?void 0:_.id)||null),[f,b]=r.useState(s.mods||[]),[A,y]=r.useState(!1),[v,L]=r.useState(((ae=s.overview)==null?void 0:ae.recentActivity)??[]),[$,R]=r.useState(!1),[P,S]=r.useState(new Set);r.useEffect(()=>{let U=!1;return(async()=>{try{const G=await w.get("/activity/hidden");U||S(new Set(G.hidden||[]))}catch{}})(),()=>{U=!0}},[]);const q=(U,G)=>{const ee=`${U.kind||""}|${U.ts||""}|${U.slug||U.title||""}|${G}`;let Z=0;for(let re=0;re<ee.length;re++)Z=(Z<<5)-Z+ee.charCodeAt(re)|0;return Math.abs(Z).toString(16).padStart(8,"0").slice(0,16)},O=async U=>{const G=new Set(P);G.add(U),S(G);try{await w.post("/activity/hide",{keys:[U]})}catch(ee){const Z=new Set(P);S(Z),n.error(`Hide failed: ${ee.message}`)}},k=async()=>{if(!confirm("Hide every recent activity item from the overview? The full log stays in Settings → Activity Log."))return;const U=v.map((ee,Z)=>q(ee,Z)),G=new Set(P);U.forEach(ee=>G.add(ee)),S(G);try{await w.post("/activity/hide",{keys:U}),n.success(`Hidden ${U.length} item(s). Restore them in Settings → Activity Log.`)}catch(ee){n.error(`Clear failed: ${ee.message}`)}},N=async()=>{S(new Set);try{await w.del("/activity/hide"),n.success("All hidden activity restored to the overview.")}catch(U){n.error(`Restore failed: ${U.message}`)}};r.useEffect(()=>{var U;s.overview&&(p(s.overview),L(s.overview.recentActivity??[]),h(!1)),m(s.projects||[]),g(((U=s.activeProject)==null?void 0:U.id)||null),b(s.mods||[])},[s.overview,s.projects,s.activeProject,s.mods]),r.useEffect(()=>{let U;try{const G=w.getToken(),ee=G?`/api/activity/stream?token=${encodeURIComponent(G)}`:"/api/activity/stream";U=new EventSource(ee),U.addEventListener("snapshot",Z=>{try{const re=JSON.parse(Z.data);L(Array.isArray(re.events)?re.events.slice(0,50):[])}catch{}}),U.addEventListener("activity",Z=>{try{const re=JSON.parse(Z.data);L(fe=>[re,...fe].slice(0,50))}catch{}})}catch{}return()=>{try{U==null||U.close()}catch{}}},[]);const D=async()=>{n.info("Refreshing…",1500),await i();try{const U=await w.get("/projects");m(U.projects||[]),g(U.active||null)}catch{}},j=()=>{l.open({title:"Add project",children:e.jsx(Zn,{settings:t,onAdd:async(U,G)=>{try{const ee=await w.post("/projects",{path:U,name:G});m(Z=>[...Z.filter(re=>re.id!==ee.id),ee]),n.success("Project added."),l.close()}catch(ee){n.error(`Add failed: ${ee.message}`)}}}),footer:e.jsx("div",{className:"modal-footer-actions",children:e.jsx(T,{variant:"ghost",onClick:()=>l.close(),children:"Cancel"})})})},M=async()=>{var U;try{const G=await w.post("/projects/auto-detect");m(G.projects||[]),g(G.active||null);const ee=(U=G.projects)==null?void 0:U.find(Z=>Z.id===G.active);n.success(ee?`Active: ${ee.name}`:"Projects refreshed."),await i()}catch(G){n.error(`Auto-detect failed: ${G.message}`)}},F=async U=>{try{await w.post(`/projects/${encodeURIComponent(U)}/activate`),g(U),n.success("Project activated."),await i()}catch(G){n.error(`Activate failed: ${G.message}`)}},C=async U=>{if(confirm(`Remove project "${U}" from the registry?`))try{await w.del(`/projects/${encodeURIComponent(U)}`),m(G=>G.filter(ee=>ee.id!==U)),u===U&&g(null),n.success("Project removed.")}catch(G){n.error(`Remove failed: ${G.message}`)}};return x||!o?e.jsxs("div",{className:"view-loading",children:[e.jsx(he,{size:"lg"}),e.jsx("p",{children:"Loading overview…"})]}):e.jsxs("div",{className:"view view-overview",children:[e.jsxs("div",{className:"overview-hero-noframe",children:[e.jsx("h1",{children:"What do you want to do?"}),e.jsx("p",{className:"overview-hero-subtitle",children:"Describe what you want — Odin will split it into tasks, create a plan, delegate to background agents, and track progress in real time."}),e.jsxs("form",{className:"overview-hero-form-noframe",onSubmit:async U=>{var ee,Z;U.preventDefault();const G=(((ee=c.current)==null?void 0:ee.value)||"").trim();if(G){y(!0);try{const re=await w.post("/tasks/submit",{title:G});n.success(`Odin split it into ${((Z=re.subtasks)==null?void 0:Z.length)||1} task(s)`),c.current&&(c.current.value=""),await i()}catch(re){n.error(`Failed: ${re.message}`)}finally{y(!1)}}},children:[e.jsx("label",{htmlFor:"overview-hero-input",className:"sr-only",children:"Describe what you want Odin to do"}),e.jsx("textarea",{id:"overview-hero-input",ref:c,className:"overview-input-hero",placeholder:"e.g. Implement user authentication with email + password, including registration, login, password reset, and integration tests. Use Bcrypt, JWT tokens, and the existing API style.",disabled:A,"aria-label":"Describe what you want Odin to do"}),e.jsxs("div",{style:{display:"flex",gap:"var(--space-2)",alignItems:"center",flexWrap:"wrap"},children:[e.jsxs(T,{type:"submit",variant:"primary",size:"lg",disabled:A,children:[A?e.jsx(he,{size:"sm"}):e.jsx(Xe,{size:16}),"Submit to Odin"]}),e.jsxs("span",{className:"muted",style:{fontSize:12},children:[e.jsx(Oe,{size:12,style:{display:"inline",verticalAlign:-2,color:"var(--accent)"}})," ","Odin + 12 specialist agents available"]})]})]}),e.jsx("div",{className:"overview-quick-actions-row",children:["Implement feature","Fix bug","Refactor","Investigate","Add tests","Document","Optimize","Deploy"].map(U=>e.jsx("button",{type:"button",className:"overview-quick-chip",onClick:()=>{c.current&&(c.current.value=U,c.current.focus())},children:U},U))})]}),e.jsxs("div",{className:"overview-feed",children:[e.jsxs("div",{className:"overview-feed-head",children:[e.jsx("h2",{children:"Recent activity"}),e.jsxs("div",{className:"overview-feed-head-actions",children:[P.size>0&&e.jsxs(T,{variant:"ghost",size:"sm",onClick:N,title:"Restore hidden items to this overview",children:[e.jsx(is,{size:12})," Show ",P.size," hidden"]}),v.length>8&&e.jsx(T,{variant:"ghost",size:"sm",onClick:()=>R(U=>!U),children:$?"Show less":"Show all"}),v.length>0&&e.jsxs(T,{variant:"ghost",size:"sm",onClick:k,title:"Hide every item from the overview (full log kept)",children:[e.jsx(nt,{size:12})," Hide all"]})]})]}),P.size>0&&e.jsxs("div",{className:"activity-hidden-banner",role:"status",children:[e.jsxs("span",{children:[e.jsx(nt,{size:12,style:{verticalAlign:-2,marginRight:6}}),P.size," item",P.size===1?"":"s"," hidden from the overview."]}),e.jsxs(T,{variant:"ghost",size:"sm",onClick:N,children:[e.jsx(is,{size:12})," Show them again"]})]}),v.length===0?e.jsx("div",{className:"muted",style:{padding:"24px 0",fontSize:13},children:"No activity yet. Use the chat above or invoke a Bizar command to start a feed."}):e.jsxs("div",{className:X("activity-feed-list-wrap",!$&&"activity-feed-list-wrap-collapsed"),"aria-live":"polite","aria-relevant":"additions",children:[e.jsx(ht,{items:v.slice(0,30).filter((U,G)=>!P.has(q(U,G))),itemHeight:60,height:Math.min(v.filter((U,G)=>!P.has(q(U,G))).length*60,480),className:"activity-feed-list",renderItem:(U,G)=>{const ee=v.slice(0,30).findIndex(Z=>Z===U);return e.jsx(li,{item:U,activityKey:q(U,ee),onNavigate:a,onHide:O})}}),!$&&v.length>8&&e.jsx("div",{className:"activity-feed-fade","aria-hidden":"true"})]})]}),e.jsxs(Q,{className:"project-picker",children:[e.jsxs(se,{children:[e.jsx(Ee,{size:14})," Projects",e.jsxs(T,{variant:"ghost",size:"sm",style:{marginLeft:"auto"},onClick:j,children:[e.jsx(Me,{size:12})," Add"]}),e.jsxs(T,{variant:"ghost",size:"sm",onClick:M,title:"Use the server's working directory",children:[e.jsx(Me,{size:12})," Auto-detect"]}),((J=t==null?void 0:t.dashboard)==null?void 0:J.projectsDirectory)&&e.jsxs(T,{variant:"ghost",size:"sm",title:`Scan ${t.dashboard.projectsDirectory} for projects`,onClick:async()=>{try{const U=await w.post("/projects/scan");U.error?n.error(U.error):n.success(`Added ${U.added.length}, skipped ${U.skipped}.`),await i();const G=await w.get("/projects");m(G.projects||[]),g(G.active||null)}catch(U){n.error(`Scan failed: ${U.message}`)}},children:[e.jsx(sn,{size:12})," Scan"]}),e.jsx(T,{variant:"ghost",size:"sm",onClick:D,title:"Refresh",children:e.jsx(ce,{size:12})})]}),e.jsxs(ie,{children:[d.length," project",d.length===1?"":"s"," ·"," ",o.counts.agents," agents ·"," ",o.counts.sessions," session",o.counts.sessions===1?"":"s"]}),d.length===0?e.jsx(we,{icon:e.jsx(Ee,{size:32}),title:"No projects yet",message:"Add a project to start tracking its tasks, plans, and schedules.",action:e.jsxs("div",{className:"empty-state-actions",children:[e.jsxs(T,{variant:"primary",onClick:M,children:[e.jsx(Me,{size:14})," Use current directory"]}),e.jsx(T,{variant:"secondary",onClick:j,children:"Add by path…"})]})}):e.jsx("div",{className:"project-grid",children:d.map(U=>e.jsx(Jn,{project:U,active:u===U.id,onOpen:()=>F(U.id),onRemove:()=>C(U.id)},U.id))})]}),e.jsx(Xn,{setActiveTab:a}),e.jsxs("div",{className:"overview-cols",children:[e.jsxs(Q,{children:[e.jsx(se,{children:"Mods"}),e.jsxs(ie,{children:["Extensions installed under ",e.jsx("code",{children:"~/.config/bizar/mods/"})]}),f.length===0?e.jsx("div",{className:"muted",children:"No mods installed."}):e.jsx("ul",{className:"mod-mini-list",children:f.map(U=>e.jsxs("li",{className:"mod-mini",children:[e.jsx("span",{className:"mod-mini-name",children:U.name}),e.jsxs("span",{className:"mod-mini-meta",children:["v",U.version," · ",U.type]}),e.jsx("span",{className:`mod-mini-pill ${U.enabled?"mod-mini-pill-on":"mod-mini-pill-off"}`,children:U.enabled?"on":"off"})]},U.id))})]}),e.jsxs(Q,{children:[e.jsx(se,{children:"Environment"}),e.jsx(ie,{children:"Runtime + paths"}),e.jsxs("dl",{className:"env-table",children:[e.jsx("dt",{children:"Node"}),e.jsx("dd",{className:"mono",children:o.versions.node}),e.jsx("dt",{children:"Platform"}),e.jsx("dd",{className:"mono",children:o.versions.platform}),e.jsx("dt",{children:"Project root"}),e.jsx("dd",{className:"mono ellipsis",title:o.versions.projectRoot,children:o.versions.projectRoot}),e.jsx("dt",{children:"Bizar root"}),e.jsx("dd",{className:"mono ellipsis",title:o.versions.bizarRoot,children:o.versions.bizarRoot}),e.jsx("dt",{children:"Generated"}),e.jsx("dd",{className:"mono tabular-nums",children:os(o.generatedAt)})]})]})]})]})}function Zn({settings:s,onAdd:t}){var d,m;const[a,i]=r.useState(((d=s==null?void 0:s.dashboard)==null?void 0:d.projectsDirectory)??""),[n,l]=r.useState(""),[c,o]=r.useState(!1),[p,x]=r.useState(null),h=async()=>{var u;if(a){o(!0),x(null);try{await w.get("/fs?path="+encodeURIComponent(a)),t(a,n||null)}catch(g){const f=g;f.status===404?x("That folder no longer exists. Pick another."):x(((u=f.data)==null?void 0:u.message)??g.message??"Validation failed.")}finally{o(!1)}}};return e.jsxs("div",{children:[e.jsx("label",{className:"field-label",children:"Folder"}),e.jsx(ta,{value:a,onChange:u=>{i(u),x(null)},projectsDirectory:(m=s==null?void 0:s.dashboard)==null?void 0:m.projectsDirectory,height:320}),p&&e.jsx("p",{className:"field-help",style:{color:"var(--error)",marginTop:4},children:p}),e.jsxs("div",{style:{marginTop:"var(--space-3)"},children:[e.jsx("label",{className:"field-label",htmlFor:"add-project-name",children:"Name (optional)"}),e.jsx("input",{id:"add-project-name",className:"input",type:"text",placeholder:"My App",value:n,onChange:u=>l(u.target.value)}),e.jsx("p",{className:"field-help",style:{marginTop:4},children:"Display name for this project. Defaults to the folder name."})]}),e.jsx("div",{style:{marginTop:"var(--space-3)",display:"flex",justifyContent:"flex-end"},children:e.jsxs(T,{variant:"primary",onClick:h,disabled:!a||c,children:[c?e.jsx("span",{className:"btn-spinner"}):null,c?"Checking…":"Add"]})})]})}function Jn({project:s,active:t,onOpen:a,onRemove:i}){const n={active:"status-on",inactive:"status-neutral",error:"status-error"}[s.status]||"status-neutral";return e.jsxs("div",{className:`project-card ${t?"project-card-active":""}`,children:[e.jsxs("div",{className:"project-card-head",children:[e.jsx("span",{className:`project-card-status ${n}`,children:s.status}),e.jsx("div",{className:"project-card-name",children:s.name}),e.jsx("button",{type:"button",className:"icon-btn","aria-label":"Remove project",title:"Remove",onClick:l=>{l.stopPropagation(),i()},children:e.jsx(Ae,{size:12})})]}),e.jsx("div",{className:"project-card-path mono ellipsis",title:s.path,children:s.path}),e.jsx("div",{className:"project-card-meta",children:s.lastAccessed&&e.jsxs("span",{className:"muted",children:["Last opened ",Ne(s.lastAccessed)]})}),e.jsx("div",{className:"project-card-actions",children:e.jsx(T,{variant:t?"ghost":"primary",size:"sm",onClick:a,children:t?e.jsxs(e.Fragment,{children:[e.jsx(ut,{size:12})," Active"]}):e.jsx(e.Fragment,{children:"Open"})})})]})}function ei(s){return s&&s.charAt(0).toUpperCase()+s.slice(1)}function si(s){const t=s.trim().toLowerCase().replace(/[:_]/g,"."),[a,i="updated"]=t.split("."),n={settings:"Settings",task:"Task",tasks:"Task",agent:"Agent",agents:"Agent",plan:"Plan",plans:"Plan",bg:"Background job",background:"Background job",session:"Session",mod:"Mod",mods:"Mod",provider:"Provider",providers:"Provider"},l={create:"created",created:"created",add:"added",added:"added",update:"updated",updated:"updated",delegate:"delegated",delegated:"delegated",invoke:"invoked",invoked:"invoked",restart:"restarted",restarted:"restarted",delete:"deleted",deleted:"deleted",remove:"removed",removed:"removed",archive:"archived",archived:"archived",restore:"restored",restored:"restored",complete:"completed",completed:"completed",fail:"failed",failed:"failed",error:"errored",stuck:"marked stuck"},c=n[a]||ei(a.replace(/-/g," ")),o=l[i]||i.replace(/-/g," ");return`${c} ${o}`.trim()}function Ms(s,t){for(const a of t){const i=s[a];if(typeof i=="string"&&i.trim())return i.trim()}return""}function ti(s){const t=Ms(s,["message","text","prompt","title","name"]);if(t)return t;const a=[],i=Ms(s,["slug"]),n=Ms(s,["agent","author"]),l=Ms(s,["status"]);return i&&a.push(`Plan ${i}`),n&&a.push(n),l&&a.push(l),a.length?a.join(" · "):"No additional details."}function ai(s){return Ne(s)}function ni(s){const t=(s.kind||"").toLowerCase(),a=(s.status||"").toLowerCase();return t.includes("error")||a==="error"||a==="failure"?"error":t.includes("warn")||a==="blocked"?"warning":t.includes("done")||t.includes("success")||a==="done"?"success":"info"}function ii(s){const t=s.toLowerCase();return t==="task"?ps:t==="agent"?qe:t==="plan"?Os:t.includes("bg")||t.includes("background")||t.includes("job")?yt:t==="mod"?Bs:t==="skill"?Oe:t.includes("error")||t.includes("failure")?dn:t.includes("warn")?ke:Te}function ri(s){const t=s.toLowerCase();return t==="task"?"tasks":t==="agent"?"agents":t==="plan"?"artifacts":t.includes("bg")||t.includes("background")?"activity":t==="mod"?"mods":t==="skill"?"skills":null}function li({item:s,activityKey:t,onNavigate:a,onHide:i}){const n=ni(s),l=ii(s.kind||""),c=si(s.kind||"activity"),o=ti(s),p=ri(s.kind||""),x=n==="error"?"var(--error)":n==="warning"?"var(--warning)":n==="success"?"var(--success)":"var(--accent)";return e.jsxs("div",{className:X("activity-feed-row",`activity-feed-row-${n}`),children:[e.jsxs("button",{type:"button",className:"activity-feed-row-main",onClick:()=>{p&&a(p)},title:p?`Open ${p}`:c,children:[e.jsx("div",{className:"activity-feed-icon",style:{color:x},children:e.jsx(l,{size:14})}),e.jsxs("div",{className:"activity-feed-body",children:[e.jsxs("div",{className:"activity-feed-title-row",children:[e.jsx("div",{className:"activity-feed-title",children:c}),e.jsx("div",{className:"activity-feed-time text-xs muted tabular-nums",children:ai(s.ts)})]}),e.jsx("div",{className:"activity-feed-summary text-sm",children:o})]})]}),e.jsx("button",{type:"button",className:"activity-feed-hide-btn",onClick:()=>i(t),title:"Hide this from the overview (kept in Settings → Activity Log)","aria-label":"Hide from overview",children:e.jsx($e,{size:12})})]})}const oi=We.memo(Qn);function ci({session:s,mode:t,anchor:a,renameDraft:i,setRenameDraft:n,onEdit:l,onDeleteRequest:c,onConfirmDelete:o,onConfirmRename:p,onClose:x}){const h=r.useRef(null),d=Math.round(a.rect.bottom+2),m=Math.max(8,Math.round(window.innerWidth-a.rect.right));r.useEffect(()=>{const g=A=>{const y=A.target;!h.current||!y||h.current.contains(y)||x()},f=A=>{A.key==="Escape"&&x()},b=window.setTimeout(()=>{document.addEventListener("mousedown",g),document.addEventListener("keydown",f)},0);return()=>{window.clearTimeout(b),document.removeEventListener("mousedown",g),document.removeEventListener("keydown",f)}},[x]),r.useEffect(()=>{if(t!=="rename")return;const g=window.setTimeout(()=>{var b;const f=(b=h.current)==null?void 0:b.querySelector("input.session-row-menu-input");f==null||f.focus(),f==null||f.select()},0);return()=>window.clearTimeout(g)},[t]);const u=e.jsxs("div",{ref:h,className:"session-row-menu",role:"menu","aria-label":`Options for ${s.title}`,style:{position:"fixed",top:d,right:m},onClick:g=>g.stopPropagation(),children:[t==="main"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",className:"session-row-menu-item",role:"menuitem",onClick:g=>{g.stopPropagation(),l()},children:[e.jsx(bn,{size:13,"aria-hidden":!0}),e.jsx("span",{children:"Rename"}),e.jsx("kbd",{children:"R"})]}),e.jsxs("button",{type:"button",className:"session-row-menu-item session-row-menu-item-danger",role:"menuitem",onClick:g=>{g.stopPropagation(),c()},children:[e.jsx(Ae,{size:13,"aria-hidden":!0}),e.jsx("span",{children:"Delete"}),e.jsx("kbd",{children:"⌫"})]})]}),t==="rename"&&e.jsxs("div",{className:"session-row-menu-inline",children:[e.jsx("div",{className:"session-row-menu-inline-label chat-mono",children:"Rename session"}),e.jsx("input",{type:"text",className:"session-row-menu-input",value:i,onChange:g=>n(g.target.value),onKeyDown:g=>{g.key==="Enter"?(g.preventDefault(),p()):g.key==="Escape"&&(g.preventDefault(),x())},onClick:g=>g.stopPropagation(),"aria-label":"New session name"}),e.jsxs("div",{className:"session-row-menu-inline-actions",children:[e.jsx("button",{type:"button",className:"btn btn-ghost",onClick:g=>{g.stopPropagation(),x()},children:"Cancel"}),e.jsx("button",{type:"button",className:"btn btn-primary",onClick:g=>{g.stopPropagation(),p()},children:"Save"})]})]}),t==="confirm-delete"&&e.jsxs("div",{className:"session-row-menu-inline",children:[e.jsx("div",{className:"session-row-menu-inline-label chat-mono",children:"Delete this session?"}),e.jsxs("div",{className:"session-row-menu-inline-message",children:['"',s.title,'" and its sub-agents will be removed.']}),e.jsxs("div",{className:"session-row-menu-inline-actions",children:[e.jsx("button",{type:"button",className:"btn btn-ghost",onClick:g=>{g.stopPropagation(),x()},children:"Cancel"}),e.jsx("button",{type:"button",className:"btn btn-danger",onClick:g=>{g.stopPropagation(),o()},children:"Delete"})]})]})]});return ya.createPortal(u,document.body)}function ot({node:s,depth:t=0,collapsible:a=!1,isLast:i=!0,open:n,onToggle:l}){var u;const[c,o]=r.useState(a),p=n!==void 0,x=p?n:c,h=g=>{p||o(g),l==null||l(g)},d=(((u=s.children)==null?void 0:u.length)??0)>0,m=e.jsxs(e.Fragment,{children:[a&&e.jsx("span",{className:`agent-node-chevron ${x?"open":""}`,"aria-hidden":!0,children:"›"}),e.jsx("span",{className:`agent-node-dot status-${s.status}`,"aria-hidden":!0}),e.jsx("span",{className:"agent-node-name",children:s.name}),s.role&&e.jsx("span",{className:"agent-node-role chat-mono",children:s.role}),e.jsx("span",{className:`agent-node-pill status-${s.status}`,children:s.status})]});return e.jsxs("div",{className:["agent-node",`depth-${t}`,`status-${s.status}`,x?"open":"closed",i?"last":""].filter(Boolean).join(" "),children:[a?e.jsx("button",{type:"button",className:`agent-node-head status-${s.status} collapsible`,onClick:g=>{g.stopPropagation(),h(!x)},"aria-expanded":x,children:m}):e.jsx("div",{className:`agent-node-head status-${s.status}`,children:m}),x&&e.jsxs(e.Fragment,{children:[s.summary&&e.jsx("div",{className:"agent-node-summary",children:s.summary}),d&&e.jsx("div",{className:"agent-node-children",children:s.children.map((g,f)=>e.jsx(ot,{node:g,depth:t+1,collapsible:!1,isLast:f===s.children.length-1},g.id))})]})]})}function di(s){return s.tree!==void 0}function mi(s){const t=s.open??!0;if(di(s))return e.jsx("div",{className:`agent-tree variant-${s.variant??"full"}`,children:e.jsx(ot,{node:s.tree.root,depth:0,open:t})});const a=s.children??[];return e.jsx("div",{className:`agent-tree variant-${s.variant} agent-tree-children-only`,children:e.jsx("div",{className:"agent-tree-children-body",children:a.map((i,n)=>e.jsx(r.Fragment,{children:e.jsx(ot,{node:i,depth:0,collapsible:!1,open:t,isLast:n===a.length-1})},i.id))})})}function hi({children:s,variant:t="rail",open:a=!0}){return a?e.jsx(mi,{variant:t,open:a,children:s}):null}const ui=["Today","Yesterday","This week","Earlier"];function Tt(s,t){return s.getFullYear()===t.getFullYear()&&s.getMonth()===t.getMonth()&&s.getDate()===t.getDate()}function xi(s,t){const a=s.getTime()-t.getTime();return Math.floor(a/(1e3*60*60*24))}function pi(s){const t=new Date,a=new Date(t);a.setDate(a.getDate()-1);const i=new Date(t);i.setDate(i.getDate()-7);const n={Today:[],Yesterday:[],"This week":[],Earlier:[]};for(const l of s){const c=new Date(Number(l.mtime)||Date.now());Tt(c,t)?n.Today.push(l):Tt(c,a)?n.Yesterday.push(l):xi(t,c)<7?n["This week"].push(l):n.Earlier.push(l)}return n}function gi(s){return new Date(Number(s)||Date.now()).toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit",hour12:!1})}function ji({state:s,agent:t}){return s==="streaming"?e.jsx("span",{className:"session-state session-state-streaming",title:`${t||"Odin"} is typing…`}):s==="awaiting"?e.jsx("span",{className:"session-state session-state-awaiting",title:"Awaiting your reply","aria-hidden":!0}):s==="idle"?e.jsx("span",{className:"session-state session-state-idle","aria-hidden":!0}):null}function fi({sessions:s,opencodeSessions:t=[],activeSessionId:a,activeOpencodeSessionId:i,activeProject:n,creating:l,onCreateSession:c,onSelectSession:o,onSelectOpencodeSession:p,onRenameSession:x,onDeleteSession:h,groupBy:d}){var C;const m=r.useMemo(()=>[...s,...t],[s,t]),u=r.useMemo(()=>[...m].sort((_,ae)=>Number(ae.mtime??0)-Number(_.mtime??0)),[m]),g=r.useMemo(()=>d?d(u):pi(u),[d,u]),[f,b]=r.useState({}),A=_=>f[_]===!0,[y,v]=r.useState(null),[L,$]=r.useState("main"),[R,P]=r.useState(""),[S,q]=r.useState(null),O=r.useRef({}),k=(_,ae="main")=>{const J=O.current[_];if(!J)return;const U=ae==="main"?J:J.querySelector(".chat-rail-item-menu-trigger")??J;if(q({id:_,rect:U.getBoundingClientRect()}),v(_),$(ae),ae==="rename"){const G=[...s,...t].find(ee=>ee.id===_);P((G==null?void 0:G.title)??(G==null?void 0:G.id)??"")}},N=()=>{v(null),$("main"),P(""),q(null)},D=_=>{if(_.source==="opencode"){p(_);return}o(_.id)},j=()=>{if(!S)return;const _=S.id,ae=R.trim();if(!ae){N();return}x==null||x(_,ae),N()},M=()=>{S&&(h==null||h(S.id),N())},F=d?Object.entries(g):ui.filter(_=>{var ae;return(ae=g[_])==null?void 0:ae.length}).map(_=>[_,g[_]]);return e.jsxs("aside",{className:"chat-rail",children:[e.jsx("div",{className:"chat-rail-head",children:e.jsxs("button",{type:"button",className:"chat-new-btn",onClick:c,disabled:l||!n,title:n?"Create new session":"Pick a project first","aria-label":"Create new session",children:[e.jsx(Me,{size:14,"aria-hidden":!0}),e.jsx("span",{children:l?"Creating…":"New session"})]})}),u.length===0?e.jsx("div",{className:"chat-sessions-empty",children:e.jsx(ba,{icon:e.jsx(Me,{size:20,"aria-hidden":!0}),title:n?"No sessions yet":"No project",message:n?"Create your first session to start chatting.":"Pick a project in Overview to scope chat sessions."})}):e.jsx("div",{className:"chat-rail-list",children:F.map(([_,ae])=>e.jsxs("div",{className:"chat-rail-group",children:[e.jsx("div",{className:"chat-rail-group-label",children:_}),ae.map(J=>{var fe,V;const U=J.source==="opencode",G=U?i===J.id:a===J.id,ee=J.tree,Z=!!((fe=ee==null?void 0:ee.root)!=null&&fe.children&&ee.root.children.length>0),re=A(J.id);return e.jsxs(r.Fragment,{children:[e.jsxs("div",{ref:I=>{O.current[J.id]=I},role:"button",tabIndex:0,className:`chat-rail-item state-${J.state??"idle"}${G?" active":""}`,onClick:()=>D(J),onKeyDown:I=>{(I.key==="Enter"||I.key===" ")&&(I.preventDefault(),D(J))},"aria-current":G?"true":void 0,children:[e.jsx(ji,{state:J.state??"idle",agent:J.agent}),e.jsxs("div",{className:"chat-rail-item-title",children:[J.pinned&&e.jsx("span",{className:"chat-rail-pin","aria-hidden":!0,children:"★"}),U&&e.jsx(ls,{size:11,style:{color:"var(--text-muted)",flexShrink:0},"aria-hidden":!0}),e.jsx("span",{className:"chat-ellipsis",children:J.title||J.id})]}),e.jsxs("div",{className:"chat-rail-item-meta",children:[e.jsx("span",{className:"chat-rail-item-meta-time",children:J.time??gi(J.mtime)}),(J.unread??0)>0&&e.jsx("span",{className:"chat-rail-badge",children:J.unread})]}),e.jsx("button",{type:"button",className:`chat-rail-item-menu-trigger${y===J.id?" open":""}`,"aria-label":`Session options for ${J.title||J.id}`,"aria-haspopup":"menu","aria-expanded":y===J.id,onClick:I=>{I.stopPropagation(),y===J.id?N():k(J.id,"main")},children:e.jsxs("svg",{viewBox:"0 0 14 14","aria-hidden":!0,children:[e.jsx("circle",{cx:"3",cy:"7",r:"1.2",fill:"currentColor"}),e.jsx("circle",{cx:"7",cy:"7",r:"1.2",fill:"currentColor"}),e.jsx("circle",{cx:"11",cy:"7",r:"1.2",fill:"currentColor"})]})}),G&&Z&&e.jsx("button",{type:"button",className:`chat-rail-tree-chevron${re?" open":""}`,"aria-label":re?"Collapse sub-agents":"Expand sub-agents","aria-expanded":re,onClick:I=>{I.stopPropagation(),b(B=>({...B,[J.id]:!B[J.id]}))},children:e.jsx("svg",{viewBox:"0 0 10 10","aria-hidden":!0,children:e.jsx("polyline",{points:"3,1.5 7,5 3,8.5"})})})]}),G&&Z&&re&&((V=ee==null?void 0:ee.root)==null?void 0:V.children)&&e.jsx(hi,{children:ee.root.children,variant:"rail",open:!0})]},U?`oc-${J.id}`:J.id)})]},_))}),y&&S&&e.jsx(ci,{session:{id:S.id,title:((C=[...s,...t].find(_=>_.id===S.id))==null?void 0:C.title)??S.id},mode:L,anchor:S,renameDraft:R,setRenameDraft:P,onEdit:()=>k(y,"rename"),onDeleteRequest:()=>k(y,"confirm-delete"),onConfirmDelete:M,onConfirmRename:j,onClose:N})]})}function vi(s){const{text:t,sending:a,onSend:i,activeSource:n}=s,[l,c]=r.useState(!1),o=()=>{!t.trim()||a||(c(!0),i(),window.setTimeout(()=>c(!1),320))};return e.jsxs("div",{className:`chat-composer-wrap chat-composer-source-${n??"none"}`,children:[e.jsx("div",{className:`chat-composer-pill${l?" takeoff":""}`,children:e.jsx(ka,{...s,onSend:o})}),e.jsxs("div",{className:"chat-composer-hint chat-muted",children:[e.jsxs("span",{children:[e.jsx("kbd",{children:"⏎"})," send"]}),e.jsxs("span",{children:[e.jsx("kbd",{children:"⇧⏎"})," newline"]}),e.jsxs("span",{children:[e.jsx("kbd",{children:"/"})," commands"]}),n==="opencode"&&e.jsx("span",{className:"chat-composer-source-hint",children:"→ opencode"}),n==="bizar"&&e.jsx("span",{className:"chat-composer-source-hint",children:"→ bizar chat"}),a&&e.jsx("span",{className:"chat-composer-source-hint",children:"sending…"})]})]})}function Ys(s){return s.toLocaleString()}function yi(s){return!s||!s.includes("/")?"":s.split("/")[0]}function bi(s){if(!s)return 0;const t=s.toLowerCase();return t.includes("opus")?15:t.includes("sonnet")?3:t.includes("haiku")?.8:t.includes("gpt-4o")?5:t.includes("gpt-4")?10:t.includes("deepseek")?.27:t.includes("minimax")?.3:t.includes("llama-3.3-70b")?.59:1}function ki({sessionId:s,messages:t,pinned:a,agent:i,model:n,agents:l,mcps:c,allCommands:o,activeSource:p="bizar",onRename:x,onDelete:h,onExport:d,busy:m}){const[u,g]=r.useState(null);r.useEffect(()=>{let q=!1;return(async()=>{try{const O=await fetch("/api/usage?range=24h",{headers:{Accept:"application/json"}});if(!O.ok)return;const k=await O.json();q||g(k)}catch{}})(),()=>{q=!0}},[s]);const f=(t==null?void 0:t.length)??0,b=(a==null?void 0:a.size)??0,A=t.reduce((q,O)=>q+(O.content||O.message||"").length,0),y=Math.round(A/4),v=bi(n),L=y/1e6*v,$=(u==null?void 0:u.totalTokens)??y,R=(u==null?void 0:u.costUsd)??L,P=128e3,S=yi(n);return e.jsxs("aside",{className:"chat-info",children:[e.jsxs("div",{className:"chat-info-section",children:[e.jsxs("div",{className:"chat-info-section-head",children:[e.jsxs("h4",{children:[e.jsx(qs,{size:11,style:{marginRight:4,verticalAlign:-1},"aria-hidden":!0})," ","Session"]}),e.jsx("span",{className:`chat-source-badge chat-source-${p??"none"}`,style:{marginLeft:"auto"},children:p==="opencode"?"opencode":"bizar chat"})]}),e.jsx("div",{className:"chat-info-mono chat-ellipsis",title:s,children:s||"Live"}),e.jsxs("div",{className:"chat-info-mono",children:[Ys(f)," message",f===1?"":"s",b>0&&` · ${b} pinned`]})]}),e.jsxs("div",{className:"chat-info-section",children:[e.jsxs("h4",{children:[e.jsx(qe,{size:11,style:{marginRight:4,verticalAlign:-1},"aria-hidden":!0})," ","Agent"]}),e.jsx("div",{className:"chat-info-value",children:i||"—"})]}),e.jsxs("div",{className:"chat-info-section",children:[e.jsxs("h4",{children:[e.jsx(js,{size:11,style:{marginRight:4,verticalAlign:-1},"aria-hidden":!0})," ","Model"]}),e.jsx("div",{className:"chat-mono chat-ellipsis",title:n,children:n||"—"}),S&&e.jsxs("div",{className:"chat-info-mono",children:["provider · ",S]})]}),e.jsxs("div",{className:"chat-info-section",children:[e.jsx("h4",{children:"Tokens"}),e.jsxs("div",{className:"chat-mono",children:[Ys($)," / ",Ys(P)]}),e.jsx("div",{className:"chat-info-bar","aria-hidden":!0,children:e.jsx("div",{className:"chat-info-bar-fill",style:{width:`${Math.min(100,$/Math.max(1,P)*100)}%`}})})]}),e.jsxs("div",{className:"chat-info-section",children:[e.jsxs("h4",{children:[e.jsx(Ha,{size:11,style:{marginRight:4,verticalAlign:-1},"aria-hidden":!0})," ","Cost"]}),e.jsxs("div",{className:"chat-mono",children:["$",R.toFixed(4)]}),!u&&e.jsx("div",{className:"chat-info-mono",children:"approx · live from MiniMax"})]}),e.jsxs("div",{className:"chat-info-section",children:[e.jsxs("h4",{children:[e.jsx(qe,{size:11,style:{marginRight:4,verticalAlign:-1},"aria-hidden":!0})," ","Attached agents"]}),l!=null&&l.length?e.jsx("div",{className:"chat-info-agents",children:l.map(q=>e.jsx("span",{className:"chat-info-agent",children:q.name},q.name))}):e.jsx("div",{className:"chat-info-mono",children:"None attached"})]}),e.jsxs("div",{className:"chat-info-section",children:[e.jsxs("h4",{children:[e.jsx(js,{size:11,style:{marginRight:4,verticalAlign:-1},"aria-hidden":!0})," ","MCPs"]}),c!=null&&c.length?e.jsx("div",{className:"chat-info-agents",children:c.map(q=>e.jsx("span",{className:"chat-info-agent",children:q.id},q.id))}):e.jsx("div",{className:"chat-info-mono",children:"No MCPs configured"})]}),e.jsxs("div",{className:"chat-info-section",children:[e.jsxs("h4",{children:[e.jsx(fs,{size:11,style:{marginRight:4,verticalAlign:-1},"aria-hidden":!0})," ","Slash commands"]}),e.jsxs("div",{className:"chat-info-mono",children:[(o==null?void 0:o.length)??0," available"]})]}),(x||h||d)&&e.jsxs("div",{className:"chat-info-section",children:[e.jsx("h4",{children:"Actions"}),e.jsxs("div",{className:"chat-info-actions",children:[x&&e.jsxs("button",{type:"button",className:"btn btn-ghost btn-sm",onClick:x,disabled:m==null?void 0:m.rename,title:"Rename session",children:[e.jsx(ks,{size:12,"aria-hidden":!0})," Rename"]}),d&&e.jsxs("button",{type:"button",className:"btn btn-ghost btn-sm",onClick:d,title:"Export transcript",children:[e.jsx(Qe,{size:12,"aria-hidden":!0})," Export"]}),h&&e.jsxs("button",{type:"button",className:"btn btn-ghost btn-sm btn-danger",onClick:h,disabled:m==null?void 0:m.delete,title:"Delete session",children:[e.jsx(Ae,{size:12,"aria-hidden":!0})," Delete"]})]})]})]})}function Ni({streaming:s,newMessageCount:t,onClick:a,streamingLabel:i="Odin is replying"}){return e.jsx("button",{type:"button",className:`jump-to-latest${s?" is-streaming":""}`,onClick:a,"aria-label":"Jump to latest message",title:"Jump to latest (⌘/Ctrl+End)",children:s?e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"jump-dots","aria-hidden":!0,children:[e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{})]}),e.jsx("span",{children:i}),t>0&&e.jsx("span",{className:"jump-badge jump-badge-live",children:"live"})]}):e.jsxs(e.Fragment,{children:[e.jsx(Yt,{size:14,"aria-hidden":!0}),e.jsx("span",{children:"Jump to latest"}),t>0&&e.jsxs("span",{className:"jump-badge",children:[t," new"]})]})})}function wi({snapshot:s,settings:t,setActiveTab:a,initialTaskId:i,onClearTaskId:n}){const l=oe(),c=Pe(),o=Na(s,t,i??"");r.useEffect(()=>{o.setToast({error:C=>l.error(C),success:C=>l.success(C),info:C=>l.info(C),warning:C=>l.warning(C)})},[o,l]);const[p,x]=r.useState(""),[h,d]=r.useState(t.defaultAgent||"odin"),[m,u]=r.useState(t.defaultModel||""),[g,f]=r.useState([]),b=r.useRef(null),{allCommands:A,suggestions:y,setQuery:v}=wa(s);r.useEffect(()=>{v(p)},[p,v]);const L=()=>{var C;return(C=b.current)==null?void 0:C.click()},$=C=>{const _=C.target.files;if(!_)return;const ae=[];for(let J=0;J<_.length;J++)ae.push(_[J].name);f(J=>{const U=ae.filter(G=>!J.includes(G));return[...J,...U]}),b.current&&(b.current.value="")},R=async()=>{const C=p.trim();if(!C)return;x(""),v(""),(await o.onSend(C,h,m,g)).ok&&o.jumpToLatest()},P=async()=>{o.busy.create||await o.onCreateSession()},S=C=>{c.open({title:"Delete message?",children:e.jsx("p",{style:{margin:0},children:"This action cannot be undone."}),footer:e.jsxs("div",{style:{display:"flex",gap:8,justifyContent:"flex-end"},children:[e.jsx(T,{variant:"secondary",size:"sm",onClick:()=>c.close(),children:"Cancel"}),e.jsx(T,{variant:"danger",size:"sm",onClick:()=>{c.close(),o.deleteMessage(C)},children:"Delete"})]})})},q=(C,_)=>{let ae="";c.open({title:"Rename session",children:e.jsx("input",{id:"rename-session-input",autoFocus:!0,defaultValue:_,"aria-label":"Session title",onChange:J=>{ae=J.target.value},onKeyDown:J=>{J.key==="Enter"&&(J.preventDefault(),c.close(),o.renameSession(C,ae).then(U=>{U&&l.success("Renamed.")}))},style:{width:"100%",padding:"8px 10px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:"var(--radius-sm)",color:"var(--text)",font:"13px/1.4 var(--font-sans)",marginTop:6}}),footer:e.jsxs("div",{style:{display:"flex",gap:8,justifyContent:"flex-end"},children:[e.jsx(T,{variant:"secondary",size:"sm",onClick:()=>c.close(),children:"Cancel"}),e.jsx(T,{variant:"primary",size:"sm",onClick:()=>{c.close(),o.renameSession(C,ae)},children:"Save"})]})})},O=(C,_)=>{c.open({title:"Delete session?",children:e.jsxs("p",{style:{margin:0},children:["Delete ",e.jsx("strong",{children:_}),"? Messages on the opencode serve will be removed. This cannot be undone."]}),footer:e.jsxs("div",{style:{display:"flex",gap:8,justifyContent:"flex-end"},children:[e.jsx(T,{variant:"secondary",size:"sm",onClick:()=>c.close(),children:"Cancel"}),e.jsx(T,{variant:"danger",size:"sm",onClick:async()=>{c.close(),await o.deleteSession(C)},children:"Delete"})]})})},k=()=>{const C=o.activeSource==="opencode"?o.activeOpencodeSessionId:o.sessionId;if(!C)return;const ae=(o.activeSource==="opencode"?o.opencodeMessages:o.bizarMessages).map(ee=>{const Z=ee.ts??"",re=(ee.role||"unknown").toUpperCase(),fe=ee.content||ee.message||"";return`[${Z}] ${re}: ${fe}`}).join(`
347
+
348
+ `),J=new Blob([ae],{type:"text/plain;charset=utf-8"}),U=URL.createObjectURL(J),G=document.createElement("a");G.href=U,G.download=`${C}.txt`,document.body.appendChild(G),G.click(),document.body.removeChild(G),URL.revokeObjectURL(U)},N=r.useMemo(()=>o.sessions.map(C=>o.getSessionDisplay(C)),[o.sessions,o.getSessionDisplay]),D=r.useMemo(()=>o.opencodeSessions.map(C=>o.getSessionDisplay(C)),[o.opencodeSessions,o.getSessionDisplay]),j=r.useMemo(()=>{const C=o.activeSource==="opencode"?o.activeOpencodeSessionId??"":o.sessionId;return C?N.find(_=>_.id===C)??D.find(_=>_.id===C)??null:null},[o.activeSource,o.activeOpencodeSessionId,o.sessionId,N,D]),M=(()=>{var ae;const C=`${h||"Odin"} · ${((ae=s.activeProject)==null?void 0:ae.name)??"no project"}`,_=(j==null?void 0:j.state)??"idle";return _==="streaming"?`Replying · ${C}`:_==="awaiting"?`Your turn · ${C}`:`${C} · idle`})(),F=o.activeSource==="opencode"?"opencode":"bizar chat";return e.jsxs("div",{className:"chat-shell",children:[e.jsx(Sa,{activeProject:s.activeProject,sessionCount:o.sessions.length,sessionsOpen:!0,infoOpen:!0,onToggleSessions:()=>{},onToggleInfo:()=>{},onOpenOverview:()=>a==null?void 0:a("overview")}),e.jsxs("div",{className:"chat-page",children:[e.jsx(fi,{sessions:N,opencodeSessions:D,activeSessionId:o.sessionId,activeOpencodeSessionId:o.activeOpencodeSessionId,activeProject:s.activeProject,creating:o.busy.create,onCreateSession:P,onSelectSession:o.selectBizarSession,onSelectOpencodeSession:C=>o.loadOpencodeSession(C.id),onRenameSession:q,onDeleteSession:C=>{const _=o.sessions.find(ae=>ae.id===C)??o.opencodeSessions.find(ae=>ae.id===C);O(C,(_==null?void 0:_.title)??"")}}),e.jsxs("section",{className:"chat-thread-section",children:[e.jsxs("div",{className:"chat-thread-head",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"chat-thread-title-row",children:[e.jsx("div",{className:"chat-thread-title",children:(j==null?void 0:j.title)??o.sessionId??"New chat"}),e.jsx("span",{className:`chat-source-badge chat-source-${o.activeSource??"none"}`,title:o.activeSource==="opencode"?"Messages go to the opencode serve child":"Messages go to the local chat store",children:F})]}),e.jsxs("div",{className:`chat-thread-sub chat-muted state-${(j==null?void 0:j.state)??"idle"}`,children:[e.jsx("span",{className:"chat-thread-dot"}),M]}),o.opencodeError&&e.jsx("div",{className:"chat-thread-error",role:"alert",children:o.opencodeError})]}),e.jsxs("div",{className:"chat-thread-actions",children:[j&&e.jsxs("button",{className:"btn btn-ghost",title:"Rename session",type:"button",disabled:o.busy.rename,onClick:()=>q(j.id,j.title??""),children:[e.jsx(ks,{size:12,"aria-hidden":!0})," ",e.jsx("span",{className:"mono",children:"rename"})]}),j&&e.jsxs("button",{className:"btn btn-ghost btn-danger",title:"Delete session",type:"button",disabled:o.busy.delete,onClick:()=>O(j.id,j.title??j.id),children:[e.jsx(Ae,{size:12,"aria-hidden":!0})," ",e.jsx("span",{className:"mono",children:"delete"})]}),e.jsx("button",{className:"btn btn-ghost",title:"Export transcript",type:"button",onClick:k,children:e.jsx("span",{className:"mono",children:"export"})})]})]}),e.jsx("div",{className:"chat-thread-scroll",ref:o.listRef,onScroll:o.handleScroll,role:"log","aria-live":"polite","aria-relevant":"additions","aria-label":"Chat message thread",children:e.jsx(Ca,{messages:o.activeSource==="opencode"?o.opencodeMessages:o.bizarMessages,loading:o.loading,activeProject:s.activeProject,sessionId:o.activeSource==="opencode"?o.activeOpencodeSessionId??o.sessionId:o.sessionId,pinned:o.pinned,activeSource:o.activeSource,onPickSuggestion:C=>x(C),onCopy:C=>o.copyMessage(C),onDelete:S,onTogglePin:o.togglePin,onRegenerate:o.onRegenerate})}),!o.stickToBottom&&e.jsx(Ni,{streaming:(j==null?void 0:j.state)==="streaming",newMessageCount:o.newMessageCount,onClick:o.jumpToLatest}),e.jsx(vi,{agent:h,setAgent:d,model:m,setModel:u,text:p,setText:x,sending:o.sending,activeSource:o.activeSource,onSend:R,attachments:g,setAttachments:f,suggestions:y,onPickSuggestion:C=>x(`${C.split(" ")[0]} `),agents:s.agents||[],onAttach:L}),e.jsx("input",{ref:b,type:"file",multiple:!0,style:{display:"none"},onChange:$,"aria-label":"Attach files to message",tabIndex:-1})]}),e.jsx(ki,{sessionId:o.activeSource==="opencode"?o.activeOpencodeSessionId??o.sessionId:o.sessionId,messages:o.activeSource==="opencode"?o.opencodeMessages:o.bizarMessages,pinned:o.pinned,agent:h,model:m,agents:s.agents||[],mcps:s.mcps||[],allCommands:A,activeSource:o.activeSource,onRename:()=>{j&&q(j.id,j.title??"")},onDelete:()=>{j&&O(j.id,j.title??j.id)},onExport:k,busy:o.busy})]})]})}function ns({kind:s="neutral",children:t,className:a,dot:i=!1}){return e.jsxs("span",{className:X("badge",`badge-${s}`,a),children:[i&&e.jsx("span",{className:"badge-dot"}),t]})}const Mt=["bash","read","edit","write","webfetch","websearch","task","glob","grep"],$t=["anthropic/claude-3-5-sonnet","anthropic/claude-3-5-haiku","openai/gpt-4o","openai/gpt-4o-mini","openrouter/minimax/minimax-m3","openrouter/minimax/minimax-m2.7"],Ls=[{id:"reasoning",label:"Reasoning",color:"var(--accent)"},{id:"code",label:"Code",color:"var(--info)"},{id:"design",label:"Design",color:"var(--success)"},{id:"planning",label:"Planning",color:"var(--warning)"},{id:"gitops",label:"GitOps",color:"var(--error)"},{id:"analysis",label:"Analysis",color:"var(--text-dim)"}];function Si(s){var t;return((t=Ls.find(a=>a.id===s))==null?void 0:t.color)||"var(--text-dim)"}function Ci({status:s,isStuck:t}){const a=t?"var(--error)":s==="working"?"var(--info)":s==="error"?"var(--error)":"var(--text-dim)";return e.jsx("span",{className:"agent-status-dot",style:{background:a}})}function zi({agent:s}){if(s.isStuck)return e.jsx(ns,{kind:"error",dot:!0,children:"stuck"});const t=s.status||"idle";return t==="working"?e.jsx(ns,{kind:"info",dot:!0,children:"working"}):t==="error"?e.jsx(ns,{kind:"error",dot:!0,children:"error"}):e.jsx(ns,{kind:"neutral",dot:!0,children:"idle"})}function Ti({snapshot:s,refreshSnapshot:t}){const a=oe(),i=Pe(),[n,l]=r.useState(s.agents||[]),[c,o]=r.useState(!s.agents),[p,x]=r.useState(""),[h,d]=r.useState("");r.useEffect(()=>{l(s.agents||[]),o(!s.agents)},[s.agents]);const m=async()=>{try{const $=await w.get("/agents");l($.agents||[])}catch($){a.error(`Agents load failed: ${$.message}`)}finally{o(!1)}},u=r.useMemo(()=>{let $=[...n];if(p&&($=$.filter(R=>p==="__none__"?!R.category:(R.category||"")===p)),h){const R=h.toLowerCase();$=$.filter(P=>P.name.toLowerCase().includes(R)||(P.description||"").toLowerCase().includes(R)||(P.tags||[]).some(S=>S.toLowerCase().includes(R)))}return $.sort((R,P)=>R.name.localeCompare(P.name))},[n,p,h]),g=r.useMemo(()=>{const $=new Set;for(const R of n)for(const P of R.tags||[])$.add(P);return Array.from($).sort()},[n]),f=()=>{let $=null,R=null,P=null,S=null,q=null,O=null,k=null,N=null,D=null;i.open({title:"New agent",width:640,children:e.jsxs("div",{className:"agent-form",children:[e.jsx("label",{className:"field-label",htmlFor:"agent-new-name",children:"Name (a-z, 0-9, dashes)"}),e.jsx("input",{id:"agent-new-name",ref:j=>$=j,className:"input",type:"text",placeholder:"my-agent",autoFocus:!0}),e.jsx("label",{className:"field-label",htmlFor:"agent-new-desc",children:"Description"}),e.jsx("input",{id:"agent-new-desc",ref:j=>{R=j},className:"input",type:"text",placeholder:"What does this agent do?"}),e.jsxs("div",{className:"task-form-row",children:[e.jsxs("div",{className:"task-form-field",children:[e.jsx("label",{className:"field-label",htmlFor:"agent-new-model",children:"Model"}),e.jsxs("select",{id:"agent-new-model",ref:j=>P=j,className:"select",defaultValue:"",children:[e.jsx("option",{value:"",children:"(provider default)"}),$t.map(j=>e.jsx("option",{value:j,children:j},j))]})]}),e.jsxs("div",{className:"task-form-field",children:[e.jsx("label",{className:"field-label",htmlFor:"agent-new-mode",children:"Mode"}),e.jsxs("select",{id:"agent-new-mode",ref:j=>S=j,className:"select",defaultValue:"subagent",children:[e.jsx("option",{value:"primary",children:"primary"}),e.jsx("option",{value:"subagent",children:"subagent"}),e.jsx("option",{value:"all",children:"all"})]})]}),e.jsxs("div",{className:"task-form-field",style:{flex:"0 0 80px"},children:[e.jsx("label",{className:"field-label",htmlFor:"agent-new-color",children:"Color"}),e.jsx("input",{id:"agent-new-color",ref:j=>q=j,className:"input",type:"color",defaultValue:"#8b5cf6"})]})]}),e.jsxs("div",{className:"task-form-row",children:[e.jsxs("div",{className:"task-form-field",style:{flex:1},children:[e.jsx("label",{className:"field-label",htmlFor:"agent-new-category",children:"Category"}),e.jsxs("select",{id:"agent-new-category",ref:j=>D=j,className:"select",defaultValue:"",children:[e.jsx("option",{value:"",children:"(none)"}),Ls.map(j=>e.jsx("option",{value:j.id,children:j.label},j.id))]})]}),e.jsxs("div",{className:"task-form-field",style:{flex:2},children:[e.jsx("label",{className:"field-label",htmlFor:"agent-new-tags",children:"Tags (comma-separated)"}),e.jsx("input",{id:"agent-new-tags",ref:j=>N=j,className:"input",type:"text",placeholder:"reasoning, code, planning"})]})]}),e.jsxs("fieldset",{children:[e.jsx("legend",{className:"field-label",style:{padding:0},children:"Tools"}),e.jsx("div",{ref:j=>k=j,className:"agent-tools",children:Mt.map(j=>e.jsxs("label",{className:"checkbox-row",children:[e.jsx("input",{type:"checkbox",value:j,"aria-label":j}),e.jsx("span",{children:j})]},j))})]}),e.jsx("label",{className:"field-label",htmlFor:"agent-new-prompt",children:"System prompt"}),e.jsx("textarea",{id:"agent-new-prompt",ref:j=>O=j,className:"textarea",rows:6,placeholder:"You are a..."})]}),footer:e.jsxs("div",{className:"modal-footer-actions",children:[e.jsx(T,{variant:"ghost",onClick:()=>i.close(),children:"Cancel"}),e.jsxs(T,{variant:"primary",onClick:async()=>{const j=(($==null?void 0:$.value)||"").trim();if(!/^[a-z0-9][a-z0-9-]{0,63}$/i.test(j)){a.warning("Invalid name (a-z, 0-9, dashes).");return}const M=[];k&&k.querySelectorAll('input[type="checkbox"]:checked').forEach(C=>{M.push(C.value)});const F=((N==null?void 0:N.value)||"").split(",").map(C=>C.trim()).filter(Boolean);try{const C=await w.post("/agents",{name:j,description:((R==null?void 0:R.value)||"").trim(),model:(P==null?void 0:P.value)||"",mode:(S==null?void 0:S.value)||"subagent",color:(q==null?void 0:q.value)||"",tools:M,tags:F,category:(D==null?void 0:D.value)||"",prompt:(O==null?void 0:O.value)||""});l(_=>[..._,C]),a.success("Agent created."),i.close(),await t()}catch(C){a.error(`Create failed: ${C.message}`)}},children:[e.jsx(vs,{size:12})," Create"]})]})})},b=async $=>{let R=null,P=null,S=null,q=null,O=null,k=null,N=null,D=null;try{const j=await w.get(`/agents/${encodeURIComponent($.name)}`);i.open({title:`Edit ${$.name}`,width:640,children:e.jsxs("div",{className:"agent-form",children:[e.jsxs("div",{className:"muted",children:["File: ",e.jsx("code",{children:j.path})]}),e.jsx("label",{className:"field-label",htmlFor:"agent-edit-desc",children:"Description"}),e.jsx("input",{id:"agent-edit-desc",ref:M=>{R=M},className:"input",type:"text",defaultValue:j.description}),e.jsxs("div",{className:"task-form-row",children:[e.jsxs("div",{className:"task-form-field",children:[e.jsx("label",{className:"field-label",htmlFor:"agent-edit-model",children:"Model"}),e.jsxs("select",{id:"agent-edit-model",ref:M=>P=M,className:"select",defaultValue:j.model,children:[e.jsx("option",{value:"",children:"(provider default)"}),$t.map(M=>e.jsx("option",{value:M,children:M},M))]})]}),e.jsxs("div",{className:"task-form-field",children:[e.jsx("label",{className:"field-label",htmlFor:"agent-edit-mode",children:"Mode"}),e.jsxs("select",{id:"agent-edit-mode",ref:M=>S=M,className:"select",defaultValue:j.mode||"subagent",children:[e.jsx("option",{value:"primary",children:"primary"}),e.jsx("option",{value:"subagent",children:"subagent"}),e.jsx("option",{value:"all",children:"all"})]})]}),e.jsxs("div",{className:"task-form-field",style:{flex:"0 0 80px"},children:[e.jsx("label",{className:"field-label",htmlFor:"agent-edit-color",children:"Color"}),e.jsx("input",{id:"agent-edit-color",ref:M=>q=M,className:"input",type:"color",defaultValue:j.color||"#8b5cf6"})]})]}),e.jsxs("div",{className:"task-form-row",children:[e.jsxs("div",{className:"task-form-field",style:{flex:1},children:[e.jsx("label",{className:"field-label",htmlFor:"agent-edit-category",children:"Category"}),e.jsxs("select",{id:"agent-edit-category",ref:M=>D=M,className:"select",defaultValue:j.category||"",children:[e.jsx("option",{value:"",children:"(none)"}),Ls.map(M=>e.jsx("option",{value:M.id,children:M.label},M.id))]})]}),e.jsxs("div",{className:"task-form-field",style:{flex:2},children:[e.jsx("label",{className:"field-label",htmlFor:"agent-edit-tags",children:"Tags (comma-separated)"}),e.jsx("input",{id:"agent-edit-tags",ref:M=>N=M,className:"input",type:"text",defaultValue:(j.tags||[]).join(", ")})]})]}),e.jsxs("fieldset",{children:[e.jsx("legend",{className:"field-label",style:{padding:0},children:"Tools"}),e.jsx("div",{ref:M=>k=M,className:"agent-tools",children:Mt.map(M=>{var F;return e.jsxs("label",{className:"checkbox-row",children:[e.jsx("input",{type:"checkbox",value:M,"aria-label":M,defaultChecked:(F=j.tools)==null?void 0:F.includes(M)}),e.jsx("span",{children:M})]},M)})})]}),e.jsx("label",{className:"field-label",htmlFor:"agent-edit-prompt",children:"System prompt"}),e.jsx("textarea",{id:"agent-edit-prompt",ref:M=>O=M,className:"textarea",rows:8,defaultValue:j.prompt||""})]}),footer:e.jsxs("div",{className:"modal-footer-actions",children:[e.jsx(T,{variant:"ghost",onClick:()=>i.close(),children:"Cancel"}),e.jsxs(T,{variant:"primary",onClick:async()=>{const M=[];k&&k.querySelectorAll('input[type="checkbox"]:checked').forEach(C=>{M.push(C.value)});const F=((N==null?void 0:N.value)||"").split(",").map(C=>C.trim()).filter(Boolean);try{const C=await w.put(`/agents/${encodeURIComponent($.name)}`,{description:((R==null?void 0:R.value)||"").trim(),model:(P==null?void 0:P.value)||"",mode:(S==null?void 0:S.value)||"subagent",color:(q==null?void 0:q.value)||"",tools:M,tags:F,category:(D==null?void 0:D.value)||"",prompt:(O==null?void 0:O.value)||""});l(_=>_.map(ae=>ae.name===$.name?C:ae)),a.success("Agent saved."),i.close(),await t()}catch(C){a.error(`Save failed: ${C.message}`)}},children:[e.jsx(vs,{size:12})," Save"]})]})})}catch(j){a.error(`Load failed: ${j.message}`)}},A=async $=>{if(confirm(`Delete agent "${$.name}"? This removes ${$.path}.`))try{await w.del(`/agents/${encodeURIComponent($.name)}`),l(R=>R.filter(P=>P.name!==$.name)),a.success("Agent deleted.")}catch(R){a.error(`Delete failed: ${R.message}`)}},y=async $=>{let R=null;i.open({title:`Invoke ${$.name}`,children:e.jsxs("div",{className:"invoke-form",children:[e.jsxs("p",{className:"muted invoke-form-meta mono",children:[$.model||"—"," · ",$.path]}),e.jsx("p",{className:"invoke-form-desc",children:$.description}),e.jsx("label",{className:"field-label",htmlFor:"invoke-prompt",children:"Prompt"}),e.jsx("textarea",{ref:P=>R=P,id:"invoke-prompt",className:"textarea",rows:5,placeholder:"What should this agent do?",autoFocus:!0})]}),footer:e.jsxs("div",{className:"modal-footer-actions",children:[e.jsx(T,{variant:"ghost",onClick:()=>i.close(),children:"Cancel"}),e.jsxs(T,{variant:"primary",onClick:async()=>{const P=((R==null?void 0:R.value)||"").trim();if(!P){a.warning("Prompt is required.");return}try{await w.post(`/agents/${encodeURIComponent($.name)}/invoke`,{prompt:P}),a.success(`Invoked ${$.name}.`),i.close()}catch(S){a.error(`Invoke failed: ${S.message}`)}},children:[e.jsx(Ns,{size:14})," Invoke"]})]})})},v=async $=>{try{const R=await w.post(`/agents/${encodeURIComponent($.name)}/restart`);l(P=>P.map(S=>S.name===$.name?R:S)),a.success(`${$.name} restarted.`)}catch(R){a.error(`Restart failed: ${R.message}`)}},L=async($,R)=>{try{const P=await w.post(`/agents/${encodeURIComponent($.name)}/status`,{status:R});l(S=>S.map(q=>q.name===$.name?P:q))}catch(P){a.error(`Status update failed: ${P.message}`)}};return e.jsxs("div",{className:"view view-agents",children:[e.jsxs("header",{className:"view-header",children:[e.jsxs("div",{className:"view-header-text",children:[e.jsxs("h2",{className:"view-title",children:[e.jsx(qe,{size:18})," Agents (",u.length,")"]}),e.jsxs("p",{className:"view-subtitle",children:["The Norse pantheon — click ",e.jsx("kbd",{children:"Edit"})," to modify or ",e.jsx("kbd",{children:"Invoke"})," to dispatch."]})]}),e.jsxs("div",{className:"view-actions",children:[e.jsxs("div",{className:"search-input",children:[e.jsx("label",{htmlFor:"agents-search",className:"sr-only",children:"Search agents"}),e.jsx("input",{id:"agents-search",className:"input",type:"text",placeholder:"Search…",value:h,onChange:$=>d($.target.value),"aria-label":"Search agents"})]}),e.jsx("label",{htmlFor:"agents-category-filter",className:"sr-only",children:"Filter by category"}),e.jsxs("select",{id:"agents-category-filter",className:"select select-sm",value:p,onChange:$=>x($.target.value),children:[e.jsx("option",{value:"",children:"All categories"}),Ls.map($=>e.jsx("option",{value:$.id,children:$.label},$.id)),e.jsx("option",{value:"__none__",children:"(no category)"})]}),e.jsxs(T,{variant:"secondary",size:"sm",onClick:m,children:[e.jsx(ce,{size:14})," Refresh"]}),e.jsxs(T,{variant:"primary",size:"sm",onClick:f,children:[e.jsx(Me,{size:14})," New agent"]})]})]}),g.length>0&&e.jsxs("div",{className:"agent-tags-row",children:[e.jsx(ea,{size:12}),g.map($=>e.jsx("span",{className:"tag",children:$},$))]}),c?e.jsx("div",{className:"view-loading",children:e.jsx(he,{size:"lg"})}):u.length===0?e.jsx(we,{icon:e.jsx(qe,{size:32}),title:"No agents found",message:"Run bizar in the terminal to install Bizar."}):e.jsx("div",{className:"agent-grid",children:u.map($=>e.jsx(Mi,{agent:$,onInvoke:()=>y($),onEdit:()=>b($),onDelete:()=>A($),onRestart:()=>v($),onSetStatus:R=>L($,R)},$.name))})]})}function Mi({agent:s,onInvoke:t,onEdit:a,onDelete:i,onRestart:n,onSetStatus:l}){const[c,o]=r.useState(!1),p=Si(s.category),x=(s.status==="working"||!!s.currentTaskId)&&!s.isStuck;return e.jsxs(Q,{variant:"elevated",interactive:!0,className:X("agent-card",x&&"is-working",s.isStuck&&"is-stuck"),children:[e.jsxs("div",{className:"agent-card-head",children:[e.jsxs("div",{className:"agent-card-name",children:[e.jsx(Ci,{status:s.status,isStuck:s.isStuck}),s.name]}),e.jsxs("div",{className:"agent-card-badges",children:[s.category&&e.jsx("span",{className:"agent-card-category",style:{background:`color-mix(in srgb, ${p} 18%, transparent)`,color:p},children:s.category}),e.jsx(zi,{agent:s})]})]}),e.jsx("p",{className:"agent-card-desc",children:qt(s.description,200)}),e.jsxs("div",{className:"agent-card-meta",children:[e.jsx("span",{className:"mono",title:s.model||"",children:s.model||"—"}),e.jsx("span",{className:"tabular-nums muted",children:Ne(s.mtime)})]}),s.tags&&s.tags.length>0&&e.jsx("div",{className:"agent-card-tags",children:s.tags.map(h=>e.jsx("span",{className:"agent-card-tag",children:h},h))}),(x||s.lastTask)&&e.jsxs("div",{className:"agent-card-activity",children:[s.currentTaskId&&e.jsxs("div",{className:"agent-card-row",children:[e.jsx(Te,{size:12}),e.jsx("span",{className:"muted",children:"Working on"}),e.jsx("code",{className:"mono",children:s.currentTaskId})]}),s.lastTask&&!s.currentTaskId&&e.jsxs("div",{className:"agent-card-row",children:[e.jsx(He,{size:12}),e.jsx("span",{className:"muted",children:"Last"}),e.jsx("code",{className:"mono",children:s.lastTask.id}),e.jsx("span",{className:"muted tabular-nums",children:Ne(s.lastTask.finishedAt)})]}),s.tasksTotal!=null&&s.tasksTotal>0&&e.jsxs("div",{className:"agent-card-row",children:[e.jsx(Wa,{size:12}),e.jsx("span",{className:"muted",children:"Success rate"}),e.jsxs("span",{className:"tabular-nums",children:[Math.round((s.successRate||0)*100),"%"]}),e.jsxs("span",{className:"muted tabular-nums",children:["(",s.tasksSucceeded,"/",s.tasksTotal,")"]})]})]}),s.lastError&&e.jsxs("div",{className:"agent-card-error",children:[e.jsx(ke,{size:12}),e.jsxs("span",{className:"muted",children:["Last error: ",s.lastError.message]})]}),e.jsxs("div",{className:"agent-card-actions",children:[e.jsxs(T,{variant:"primary",size:"sm",onClick:t,children:[e.jsx(Ns,{size:12})," Invoke"]}),e.jsxs(T,{variant:"secondary",size:"sm",onClick:a,children:[e.jsx(ks,{size:12})," Edit"]}),(s.isStuck||s.status==="working"||s.status==="error")&&e.jsxs(T,{variant:"ghost",size:"sm",onClick:n,title:"Reset agent status",children:[e.jsx(xt,{size:12})," Restart"]}),e.jsx(T,{variant:"ghost",size:"sm",onClick:i,children:e.jsx(Ae,{size:12})}),e.jsx("button",{type:"button",className:"icon-btn","aria-label":c?"Collapse":"Expand",onClick:()=>o(h=>!h),style:{marginLeft:"auto"},children:c?e.jsx(Fe,{size:12}):e.jsx(_e,{size:12})})]}),c&&e.jsxs("div",{className:"agent-card-expanded",children:[e.jsxs("div",{className:"agent-card-status-actions",children:[e.jsx("span",{className:"muted text-sm",children:"Set status:"}),e.jsx(T,{variant:s.status==="idle"?"primary":"ghost",size:"sm",onClick:()=>l("idle"),children:"Idle"}),e.jsx(T,{variant:s.status==="working"?"primary":"ghost",size:"sm",onClick:()=>l("working"),children:"Working"}),e.jsx(T,{variant:s.status==="error"?"primary":"ghost",size:"sm",onClick:()=>l("error"),children:"Error"})]}),e.jsxs("div",{className:"agent-card-meta",children:[e.jsx(Ee,{size:11}),e.jsx("code",{className:"mono agent-card-path",children:s.path})]})]})]})}function $i({id:s,children:t}){return e.jsx("div",{id:s,"data-block-id":s,className:X("glyph-richtext"),style:na,children:e.jsx(Ht,{remarkPlugins:[_t],children:t})})}const Ai={info:{bg:"var(--info-soft, rgba(96, 165, 250, 0.12))",border:"var(--info)",fg:"var(--info)",icon:Hs,label:"Note"},warn:{bg:"var(--warning-soft, rgba(251, 191, 36, 0.15))",border:"var(--warning)",fg:"var(--warning)",icon:ke,label:"Warning"},success:{bg:"var(--success-soft, rgba(52, 211, 153, 0.15))",border:"var(--success)",fg:"var(--success)",icon:He,label:"Success"},danger:{bg:"var(--error-soft, rgba(248, 113, 113, 0.12))",border:"var(--error)",fg:"var(--error)",icon:Ye,label:"Danger"}};function Ri({id:s,tone:t="info",children:a}){const i=Ai[t],n=i.icon;return e.jsxs("div",{id:s,"data-block-id":s,className:X("glyph-callout",`glyph-callout-${t}`),style:{display:"flex",gap:12,padding:"12px 16px",margin:"12px 0",borderLeft:`3px solid ${i.border}`,background:i.bg,borderRadius:8,color:"var(--text)"},role:t==="danger"||t==="warn"?"alert":void 0,children:[e.jsx("div",{style:{flexShrink:0,color:i.fg,paddingTop:2},children:e.jsx(n,{size:18})}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontWeight:600,fontSize:13,color:i.fg,marginBottom:4},children:i.label}),e.jsx("div",{className:"glyph-richtext",style:{...na,fontSize:14},children:e.jsx(Ht,{remarkPlugins:[_t],children:a})})]})]})}function Ii({id:s,items:t}){return e.jsx("ul",{id:s,"data-block-id":s,className:"glyph-checklist",style:{listStyle:"none",padding:0,margin:"12px 0",display:"flex",flexDirection:"column",gap:6},children:t.map(a=>e.jsxs("li",{style:{display:"flex",alignItems:"flex-start",gap:10,padding:"6px 10px",borderRadius:6,background:"var(--bg-elev)",border:"1px solid var(--border)",fontSize:14},children:[e.jsx("span",{"aria-hidden":!0,style:{flexShrink:0,marginTop:1,width:16,height:16,borderRadius:4,border:`1.5px solid ${a.checked?"var(--success)":"var(--border-strong)"}`,background:a.checked?"var(--success)":"transparent",color:"var(--bg)",display:"inline-flex",alignItems:"center",justifyContent:"center"},children:a.checked?e.jsx(at,{size:12,strokeWidth:3}):null}),e.jsx("span",{style:{color:a.checked?"var(--text-dim)":"var(--text)",textDecoration:a.checked?"line-through":"none",wordBreak:"break-word"},children:a.label})]},a.id))})}function Li({id:s,columns:t,rows:a}){return e.jsx("div",{id:s,"data-block-id":s,className:"glyph-table-wrap",style:{margin:"12px 0",border:"1px solid var(--border)",borderRadius:8,overflow:"auto",background:"var(--bg-elev)"},children:e.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:13},children:[e.jsx("thead",{children:e.jsx("tr",{children:t.map((i,n)=>e.jsx("th",{style:{textAlign:"left",padding:"8px 12px",borderBottom:"1px solid var(--border-strong)",background:"var(--bg)",color:"var(--text-dim)",fontWeight:600,fontSize:12,textTransform:"uppercase",letterSpacing:.3,whiteSpace:"nowrap"},children:i},n))})}),e.jsx("tbody",{children:a.map((i,n)=>e.jsx("tr",{style:{borderTop:n===0?"none":"1px solid var(--border)"},children:i.map((l,c)=>e.jsx("td",{style:{padding:"8px 12px",color:"var(--text)",verticalAlign:"top",wordBreak:"break-word"},children:l},c))},n))})]})})}function Ei({id:s,tabs:t}){var l;const[a,i]=r.useState(((l=t[0])==null?void 0:l.id)??""),n=r.useMemo(()=>t.find(c=>c.id===a)??t[0],[t,a]);return e.jsxs("div",{id:s,"data-block-id":s,className:"glyph-codetabs",style:{margin:"12px 0",border:"1px solid var(--border)",borderRadius:8,overflow:"hidden",background:"var(--bg-elev)"},children:[e.jsx("div",{role:"tablist",style:{display:"flex",gap:2,padding:4,background:"var(--bg)",borderBottom:"1px solid var(--border)",overflowX:"auto"},children:t.map(c=>{const o=c.id===(n==null?void 0:n.id);return e.jsxs("button",{type:"button",role:"tab","aria-selected":o,onClick:()=>i(c.id),style:{padding:"6px 12px",fontSize:12,fontFamily:"var(--font-mono)",borderRadius:6,border:"none",cursor:"pointer",background:o?"var(--bg-elev)":"transparent",color:o?"var(--text-strong)":"var(--text-dim)",boxShadow:o?"0 0 0 1px var(--border)":"none",whiteSpace:"nowrap"},children:[e.jsx("span",{children:c.label}),c.language&&e.jsx("span",{style:{marginLeft:6,color:"var(--text-dim)",fontSize:11},children:c.language})]},c.id)})}),n&&e.jsxs(e.Fragment,{children:[e.jsx("pre",{style:{margin:0,padding:14,overflowX:"auto",fontFamily:"var(--font-mono)",fontSize:12.5,lineHeight:1.55,color:"var(--text)",background:"var(--bg-elev)"},children:e.jsx("code",{children:n.code})}),n.caption&&e.jsx("div",{style:{padding:"8px 14px",borderTop:"1px solid var(--border)",fontSize:12,color:"var(--text-dim)",background:"var(--bg)"},children:n.caption})]})]})}function Pi({id:s,title:t,question:a,options:i}){return e.jsxs("div",{id:s,"data-block-id":s,className:"glyph-decision",style:{margin:"16px 0",padding:16,border:"1px solid var(--border)",borderRadius:10,background:"var(--bg-elev)"},children:[t&&e.jsx("h3",{style:{margin:0,marginBottom:4,fontSize:15,fontWeight:600,color:"var(--text-strong)"},children:t}),a&&e.jsx("p",{style:{margin:0,marginBottom:12,fontSize:13,color:"var(--text-dim)"},children:a}),e.jsx("div",{style:{display:"grid",gap:10,gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))"},children:i.map(n=>{const l=!!n.recommended;return e.jsxs("div",{style:{position:"relative",padding:12,borderRadius:8,border:l?"2px solid var(--success)":"1px solid var(--border)",background:l?"var(--success-soft)":"var(--bg)"},children:[l&&e.jsx("span",{style:{position:"absolute",top:-10,right:10,padding:"2px 8px",fontSize:11,fontWeight:600,color:"var(--bg)",background:"var(--success)",borderRadius:999},children:"Recommended"}),e.jsx("div",{style:{fontWeight:600,fontSize:14,color:"var(--text-strong)",marginBottom:4},children:n.label}),e.jsx("div",{style:{fontSize:13,color:"var(--text)"},children:n.detail})]},n.id)})})]})}function Di({id:s,questions:t}){const[a,i]=r.useState({});function n(l,c){i(o=>({...o,[l]:c}))}return e.jsxs("div",{id:s,"data-block-id":s,className:"glyph-openquestions",style:{margin:"16px 0",padding:16,border:"1px solid var(--border)",borderRadius:10,background:"var(--bg-elev)",display:"flex",flexDirection:"column",gap:14},children:[e.jsx("div",{style:{fontSize:13,fontWeight:600,color:"var(--text-strong)"},children:"Open questions"}),t.map(l=>e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[e.jsx("label",{htmlFor:`oq-${l.id}`,style:{fontSize:13,color:"var(--text)",fontWeight:500},children:l.label}),l.kind==="choice"&&e.jsxs("select",{id:`oq-${l.id}`,value:a[l.id]??"",onChange:c=>n(l.id,c.target.value),style:At,children:[e.jsx("option",{value:"",children:"— select —"}),(l.options??[]).map(c=>e.jsx("option",{value:c,children:c},c))]}),l.kind==="text"&&e.jsx("input",{id:`oq-${l.id}`,type:"text",value:a[l.id]??"",onChange:c=>n(l.id,c.target.value),style:At}),l.kind==="multi"&&e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4},children:(l.options??[]).map(c=>{const o=a[l.id]??[],p=o.includes(c);return e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,fontSize:13,color:"var(--text)",cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:p,onChange:()=>{const x=p?o.filter(h=>h!==c):[...o,c];n(l.id,x)}}),e.jsx("span",{children:c})]},c)})})]},l.id))]})}const At={padding:"6px 10px",fontSize:13,borderRadius:6,border:"1px solid var(--border-strong)",background:"var(--bg)",color:"var(--text)",fontFamily:"inherit"},Fi={added:{bg:"var(--success-soft)",fg:"var(--success)",label:"A"},modified:{bg:"var(--info-soft, rgba(96, 165, 250, 0.12))",fg:"var(--info)",label:"M"},removed:{bg:"var(--error-soft)",fg:"var(--error)",label:"D"},renamed:{bg:"rgba(139, 92, 246, 0.15)",fg:"var(--accent)",label:"R"}};function Oi({id:s,title:t,entries:a}){return e.jsxs("div",{id:s,"data-block-id":s,className:"glyph-filetree",style:{margin:"12px 0",padding:t?14:8,border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-elev)"},children:[t&&e.jsx("div",{style:{fontSize:12,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:.4,marginBottom:8},children:t}),e.jsx("ul",{style:{listStyle:"none",padding:0,margin:0,display:"flex",flexDirection:"column",gap:2},children:a.map(i=>{const n=Fi[i.change];return e.jsxs("li",{style:{display:"flex",alignItems:"center",gap:10,padding:"5px 8px",borderRadius:5,fontSize:13},children:[e.jsx("span",{"aria-label":i.change,title:i.change,style:{flexShrink:0,width:22,height:18,borderRadius:4,background:n.bg,color:n.fg,display:"inline-flex",alignItems:"center",justifyContent:"center",fontSize:10,fontWeight:700,fontFamily:"var(--font-mono)"},children:n.label}),e.jsx("span",{style:{fontFamily:"var(--font-mono)",color:"var(--text)",wordBreak:"break-all",flex:1},children:i.path}),i.note&&e.jsx("span",{style:{fontSize:12,color:"var(--text-dim)"},children:i.note})]},i.path)})})]})}function Bi({id:s,filename:t,language:a,mode:i="unified",before:n,after:l}){const c=n.split(`
349
+ `),o=l.split(`
350
+ `),p=e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"6px 12px",background:"var(--bg)",borderBottom:"1px solid var(--border)",fontSize:12,color:"var(--text-dim)",fontFamily:"var(--font-mono)"},children:[e.jsx(Ga,{size:14}),e.jsx("span",{style:{color:"var(--text)"},children:t??"diff"}),a&&e.jsxs("span",{children:["· ",a]}),e.jsx("span",{style:{marginLeft:"auto",textTransform:"uppercase",letterSpacing:.3},children:i})]}),x={margin:0,padding:0,fontFamily:"var(--font-mono)",fontSize:12.5,lineHeight:1.55,color:"var(--text)",background:"var(--bg-elev)"},h=(d,m,u)=>{const g={del:"var(--error-soft)",add:"var(--success-soft)",ctx:"transparent"},f={del:"var(--error)",add:"var(--success)",ctx:"var(--text-dim)"};return e.jsxs("div",{style:{display:"flex",padding:"0 12px",background:g[u]},children:[e.jsx("span",{style:{width:18,color:f[u],userSelect:"none",flexShrink:0},children:d}),e.jsx("span",{style:{whiteSpace:"pre",flex:1,overflowX:"auto"},children:m||" "})]})};return e.jsxs("div",{id:s,"data-block-id":s,className:"glyph-diff",style:{margin:"12px 0",border:"1px solid var(--border)",borderRadius:8,overflow:"hidden",background:"var(--bg-elev)"},children:[p,i==="unified"?e.jsxs("pre",{style:x,children:[c.map((d,m)=>e.jsx("div",{children:h("-",d,"del")},`b${m}`)),o.map((d,m)=>e.jsx("div",{children:h("+",d,"add")},`a${m}`))]}):e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr"},children:[e.jsx("pre",{style:{...x,borderRight:"1px solid var(--border)"},children:c.map((d,m)=>e.jsx("div",{children:h("-",d,"del")},m))}),e.jsx("pre",{style:x,children:o.map((d,m)=>e.jsx("div",{children:h("+",d,"add")},m))})]})]})}const Ui={up:{fg:"var(--success)",Icon:Fe,label:"trending up"},down:{fg:"var(--error)",Icon:Fe,label:"trending down"},flat:{fg:"var(--text-dim)",Icon:cn,label:"flat"}};function qi({id:s,label:t,value:a,trend:i,hint:n}){const l=i?Ui[i]:null;return e.jsxs("div",{id:s,"data-block-id":s,className:"glyph-stat",style:{padding:14,border:"1px solid var(--border)",borderRadius:10,background:"var(--bg-elev)",display:"flex",flexDirection:"column",gap:4,minWidth:140},children:[e.jsx("div",{style:{fontSize:12,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:.4},children:t}),e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:8},children:[e.jsx("span",{style:{fontSize:24,fontWeight:700,color:"var(--text-strong)"},children:a}),l&&e.jsx("span",{"aria-label":l.label,style:{display:"inline-flex",alignItems:"center",color:l.fg,transform:l.Icon===Fe&&i==="up"?"rotate(180deg)":void 0},children:e.jsx(l.Icon,{size:14})})]}),n&&e.jsx("div",{style:{fontSize:12,color:"var(--text-dim)"},children:n})]})}const Hi={task:{stroke:"var(--info)",fill:"var(--bg-elev)",fg:"var(--text)"},decision:{stroke:"var(--warning)",fill:"var(--bg-elev)",fg:"var(--text)"},note:{stroke:"var(--border-strong)",fill:"var(--bg)",fg:"var(--text-dim)"}},Ce=160,Ie=56,Je=60,es=80;function _i({id:s,steps:t,connections:a=[]}){if(t.length===0)return e.jsx("div",{id:s,"data-block-id":s,className:"glyph-workflow",children:e.jsx(Wi,{id:s})});const i=new Map(t.map(h=>[h.id,h])),n=Vi(t),l=Math.max(...n.map(h=>h.col))+1,c=Math.max(...n.map(h=>h.row))+1,o=l*(Ce+Je)+Je,p=c*(Ie+es)+es;function x(h){if(!i.get(h))return null;const m=n.find(u=>u.id===h);return m?{x:Je+m.col*(Ce+Je)+Ce/2,y:es+m.row*(Ie+es)+Ie/2}:null}return e.jsx("div",{id:s,"data-block-id":s,className:"glyph-workflow",style:{margin:"12px 0",padding:12,border:"1px solid var(--border)",borderRadius:10,background:"var(--bg-elev)",overflow:"auto"},children:e.jsxs("svg",{role:"img","aria-label":"Workflow diagram",width:o,height:p,style:{display:"block",maxWidth:"100%"},children:[e.jsx("defs",{children:e.jsx("marker",{id:`arrow-${s}`,viewBox:"0 0 10 10",refX:"9",refY:"5",markerWidth:"6",markerHeight:"6",orient:"auto-start-reverse",children:e.jsx("path",{d:"M 0 0 L 10 5 L 0 10 z",fill:"var(--text-dim)"})})}),a.map((h,d)=>{const m=x(h.from),u=x(h.to);if(!m||!u)return null;const g=u.x-m.x,f=u.y-m.y,b=g>=0?m.x+Ce/2:m.x-Ce/2,A=g>=0?u.x-Ce/2:u.x+Ce/2,y=f>=0?m.y+Ie/2:m.y-Ie/2,v=f>=0?u.y-Ie/2:u.y+Ie/2,L=(b+A)/2,$=(y+v)/2;return e.jsxs("g",{children:[e.jsx("line",{x1:b,y1:y,x2:A,y2:v,stroke:"var(--text-dim)",strokeWidth:1.5,markerEnd:`url(#arrow-${s})`}),h.label&&e.jsx("text",{x:L,y:$-4,fontSize:10,fill:"var(--text-dim)",textAnchor:"middle",fontFamily:"var(--font-mono)",children:h.label})]},d)}),t.map(h=>{const d=n.find(b=>b.id===h.id);if(!d)return null;const m=Je+d.col*(Ce+Je),u=es+d.row*(Ie+es),g=Hi[h.type];if(h.type==="decision"){const b=m+Ce/2,A=u+Ie/2,y=[[b,u],[m+Ce,A],[b,u+Ie],[m,A]].map(v=>v.join(",")).join(" ");return e.jsxs("g",{children:[e.jsx("polygon",{points:y,fill:g.fill,stroke:g.stroke,strokeWidth:2}),e.jsx("foreignObject",{x:m+8,y:A-14,width:Ce-16,height:28,children:e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",gap:4,fontSize:12,color:g.fg,textAlign:"center",lineHeight:1.2,fontStyle:"italic",height:"100%"},children:[e.jsx(Va,{size:11}),h.label]})})]},h.id)}const f=h.type==="note";return e.jsxs("g",{children:[e.jsx("rect",{x:m,y:u,width:Ce,height:Ie,rx:8,fill:g.fill,stroke:g.stroke,strokeWidth:f?1:2,strokeDasharray:f?"4 3":void 0}),e.jsx("foreignObject",{x:m+6,y:u+6,width:Ce-12,height:Ie-12,children:e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",gap:6,fontSize:12,color:g.fg,textAlign:"center",lineHeight:1.25,fontStyle:f?"italic":"normal",height:"100%"},children:[f&&e.jsx(za,{size:11}),h.label]})})]},h.id)})]})})}function Wi({id:s}){return e.jsx("div",{id:s,style:{padding:20,textAlign:"center",color:"var(--text-dim)",fontSize:13},children:"No workflow steps."})}function Vi(s){return s.length===0?[]:s.map((t,a)=>({id:t.id,col:a,row:0}))}const na={fontSize:14,lineHeight:1.6,color:"var(--text)"};function Ki({id:s,title:t,x:a,y:i,w:n,h:l,html:c}){return e.jsxs("figure",{id:s,"data-block-id":s,className:"glyph-mockup",style:{width:n,minHeight:l},children:[t&&e.jsx("figcaption",{className:"glyph-mockup-title",children:t}),e.jsxs("div",{className:"glyph-mockup-frame",children:[e.jsxs("div",{className:"glyph-mockup-chrome",children:[e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{})]}),e.jsx("div",{className:"glyph-mockup-body",dangerouslySetInnerHTML:{__html:c}})]})]})}class Gi extends We.Component{constructor(){super(...arguments);cs(this,"state",{err:null})}static getDerivedStateFromError(a){return{err:a}}componentDidCatch(a,i){try{this.props.onError(this.props.blockId,this.props.blockType,a,i)}catch{}}render(){return this.state.err?e.jsxs("div",{className:"glyph-block-error",role:"alert",style:{border:"1px solid var(--error, #f85149)",background:"rgba(248, 81, 73, 0.06)",borderRadius:8,padding:"12px 14px",margin:"12px 0",color:"var(--text)",fontFamily:"var(--font-mono, ui-monospace, monospace)",fontSize:12,lineHeight:1.55},children:[e.jsxs("strong",{style:{color:"var(--error, #f85149)",fontFamily:"var(--font-sans, system-ui, sans-serif)",display:"block",marginBottom:4},children:[this.props.blockType," block crashed"]}),e.jsxs("div",{style:{color:"var(--text-muted)",marginBottom:6},children:["block id: ",e.jsx("code",{children:this.props.blockId})]}),e.jsx("pre",{style:{margin:0,whiteSpace:"pre-wrap",wordBreak:"break-word",color:"var(--text)"},children:this.state.err.message})]}):this.props.children}}function Yi(s){const t=s.data??{};switch(s.type){case"RichText":return{ok:!0};case"Callout":return{ok:!0};case"Checklist":return Array.isArray(t.items)?{ok:!0}:{ok:!1,error:"Checklist requires data.items to be an array"};case"Table":return Array.isArray(t.columns)?Array.isArray(t.rows)?t.rows.length>0&&!Array.isArray(t.rows[0])?{ok:!1,error:"Table.data.rows[0] must be an array (cell array)"}:{ok:!0}:{ok:!1,error:"Table requires data.rows to be an array"}:{ok:!1,error:"Table requires data.columns to be an array"};case"CodeTabs":return Array.isArray(t.tabs)?{ok:!0}:{ok:!1,error:"CodeTabs requires data.tabs to be an array"};case"Decision":return Array.isArray(t.options)?{ok:!0}:{ok:!1,error:"Decision requires data.options to be an array"};case"OpenQuestions":return Array.isArray(t.questions)?{ok:!0}:{ok:!1,error:"OpenQuestions requires data.questions to be an array"};case"FileTree":if(!Array.isArray(t.entries))return{ok:!1,error:"FileTree requires data.entries to be an array"};for(const a of t.entries)if(a===null||typeof a!="object"||Array.isArray(a))return{ok:!1,error:`FileTree contains a malformed entry: ${JSON.stringify(a)}`};return{ok:!0};case"Diff":return typeof t.before!="string"?{ok:!1,error:"Diff requires data.before to be a string"}:typeof t.after!="string"?{ok:!1,error:"Diff requires data.after to be a string"}:{ok:!0};case"Stat":return t.label===void 0||t.label===null?{ok:!1,error:"Stat requires data.label"}:t.value===void 0||t.value===null?{ok:!1,error:"Stat requires data.value"}:{ok:!0};case"Workflow":return Array.isArray(t.steps)?{ok:!0}:{ok:!1,error:"Workflow requires data.steps to be an array"};case"Mockup":return typeof t.html!="string"?{ok:!1,error:"Mockup requires data.html to be a string"}:{ok:!0};case"Diagram":return typeof t.dataHtml!="string"?{ok:!1,error:"Diagram requires data.dataHtml to be a string"}:{ok:!0};default:return{ok:!1,error:`Unknown block type: ${s.type}`}}}const Xi={overview:"Overview",implementation:"Implementation plan","implementation-plan":"Implementation plan",questions:"Open questions","open-questions":"Open questions","open-questions-for-you":"Open questions",comments:"Comments",handoff:"Handoff"};function Qi(s){const t=[];let a={heading:null,blocks:[]};for(const i of s){const n=Xi[i.id]??null;n?((a.blocks.length>0||a.heading!==null)&&t.push(a),a={heading:n,blocks:[i]}):a.blocks.push(i)}return(a.blocks.length>0||a.heading!==null)&&t.push(a),t}function Zi({slug:s,onClose:t,onCommentAdded:a}){var Z,re,fe,V;const i=oe(),[n,l]=r.useState(null),[c,o]=r.useState([]),[p,x]=r.useState(!0),[h,d]=r.useState(null),[m,u]=r.useState(null),[g,f]=r.useState(!1),[b,A]=r.useState(!1),[y,v]=r.useState(null),[L,$]=r.useState(null),[R,P]=r.useState(""),[S,q]=r.useState(null),[O,k]=r.useState([]),N=We.useCallback((I,B,H)=>{k(ne=>ne.some(W=>W.blockId===I)?ne:[...ne,{blockId:I,blockType:B,message:H.message||String(H)}])},[]),D=r.useRef(null),j=r.useMemo(()=>n?Qi(n.blocks):[],[n]);r.useEffect(()=>{let I=!1;const B=5e3;return(async()=>{x(!0),d(null);try{const H=new Promise((le,te)=>setTimeout(()=>te(new Error("Request timed out after 5s")),B)),[ne,W]=await Promise.race([Promise.all([w.get(`/artifacts/${encodeURIComponent(s)}/render`),w.get(`/artifacts/${encodeURIComponent(s)}`)]),H]);if(I)return;l(ne);const E=(W==null?void 0:W.comments)??[];o(Array.isArray(E)?E:[])}catch(H){if(!I){const ne=H.message;d(ne),u(ne)}}finally{I||x(!1)}})(),()=>{I=!0}},[s]);function M(I){if(!D.current)return;I.preventDefault();const B=D.current.getBoundingClientRect();v({x:I.clientX,y:I.clientY,worldX:I.clientX-B.left,worldY:I.clientY-B.top})}async function F(){if(!(!L||!R.trim()))try{const I=await w.post(`/artifacts/${encodeURIComponent(s)}/comments`,{x:L.worldX,y:L.worldY,text:R.trim(),author:"drb0rk"});o(B=>[...B,{id:I.id??`cmt_${Date.now()}`,x:L.worldX,y:L.worldY,text:R.trim(),author:"drb0rk",created:new Date().toISOString()}]),$(null),P(""),v(null),a==null||a(),i.success("Comment added")}catch(I){i.error(`Failed to add comment: ${I.message}`)}}async function C(){if(!g){f(!0);try{const I=await w.post(`/artifacts/${encodeURIComponent(s)}/submit`,{answers:[],submitter:"drb0rk"});I!=null&&I.ok?(i.success("Sent to agent — feedback.md written, status=review"),a==null||a()):i.error("Submit failed: server did not return ok=true")}catch(I){i.error(`Submit failed: ${I.message}`)}finally{f(!1)}}}function _(){A(I=>!I)}const ae=I=>{const B=I.id,H=I.data??{},ne=Yi(I);return ne.ok?e.jsx(Gi,{blockId:B,blockType:I.type,onError:N,children:J(I,B,H)},B):e.jsxs("div",{id:B,className:"glyph-block-error",role:"alert",style:{border:"1px solid var(--error, #f85149)",background:"rgba(248, 81, 73, 0.06)",borderRadius:8,padding:"12px 14px",margin:"12px 0",color:"var(--text)",fontFamily:"var(--font-mono, ui-monospace, monospace)",fontSize:12,lineHeight:1.55},children:[e.jsxs("strong",{style:{color:"var(--error, #f85149)",fontFamily:"var(--font-sans, system-ui, sans-serif)",display:"block",marginBottom:4},children:[I.type," block invalid"]}),e.jsxs("div",{style:{color:"var(--text-muted)",marginBottom:6},children:["block id: ",e.jsx("code",{children:B})]}),e.jsx("pre",{style:{margin:0,whiteSpace:"pre-wrap",wordBreak:"break-word"},children:ne.error})]},B)},J=(I,B,H)=>{switch(I.type){case"RichText":return e.jsx($i,{id:B,children:I.childrenMarkdown??""},B);case"Callout":return e.jsx(Ri,{id:B,tone:H.tone??"info",children:I.childrenMarkdown??""},B);case"Checklist":return e.jsx(Ii,{id:B,items:H.items??[]},B);case"Table":return e.jsx(Li,{id:B,columns:H.columns??[],rows:H.rows??[]},B);case"CodeTabs":return e.jsx(Ei,{id:B,tabs:H.tabs??[]},B);case"Decision":return e.jsx(Pi,{id:B,title:H.title,question:H.question,options:H.options??[]},B);case"OpenQuestions":return e.jsx(Di,{id:B,questions:H.questions??[]},B);case"FileTree":return e.jsx(Oi,{id:B,title:H.title,entries:H.entries??[]},B);case"Diff":return e.jsx(Bi,{id:B,filename:H.filename,language:H.language,mode:H.mode??"unified",before:H.before??"",after:H.after??""},B);case"Stat":return e.jsx(qi,{id:B,label:H.label??"",value:H.value,trend:H.trend,hint:H.hint},B);case"Workflow":return e.jsx(_i,{id:B,steps:H.steps??[],connections:H.connections},B);case"Mockup":return e.jsx(Ki,{id:B,title:H.title,x:H.x,y:H.y,w:H.w,h:H.h,html:H.html??""},B);case"Diagram":return e.jsx("div",{id:B,className:"glyph-block-placeholder",children:e.jsxs("em",{children:["[Diagram] ",B]})},B)}};if(p)return e.jsx("div",{className:"glyph-renderer glyph-renderer--loading",children:m?e.jsxs(e.Fragment,{children:[e.jsx("strong",{children:"Failed to load glyph."}),e.jsx("pre",{children:m})]}):e.jsxs(e.Fragment,{children:[e.jsx(Ji,{})," Loading glyph…"]})});if(h||!n)return e.jsxs("div",{className:"glyph-renderer glyph-renderer--error",children:[e.jsx("strong",{children:"Failed to load glyph."}),e.jsx("pre",{children:h??"unknown error"})]});const U=((Z=n.frontmatter)==null?void 0:Z.title)??s,G=((re=n.frontmatter)==null?void 0:re.status)??"draft",ee=c.length;return e.jsxs("div",{className:`glyph-canvas ${b?"glyph-canvas--fullscreen":""}`,ref:D,onContextMenu:M,children:[e.jsxs("div",{className:"glyph-toolbar-floating",children:[e.jsxs("button",{className:"glyph-btn glyph-btn--primary glyph-btn--send",onClick:C,disabled:g,title:"Send comments + question answers to the agent — writes feedback.md, status=review",children:[e.jsx(Xe,{size:14}),e.jsx("span",{children:"Send to agent"}),e.jsx("span",{className:"glyph-btn-badge",children:ee})]}),e.jsx("span",{className:"glyph-toolbar-divider"}),e.jsx("button",{className:"glyph-icon-btn",title:"Share",onClick:()=>{typeof window<"u"&&navigator.clipboard&&(navigator.clipboard.writeText(window.location.href).catch(()=>{}),i.success("Link copied"))},children:e.jsx(vn,{size:15})}),e.jsx("button",{className:"glyph-icon-btn",title:"Undo",disabled:!0,children:e.jsx(wn,{size:15})}),e.jsx("button",{className:"glyph-icon-btn",title:"Redo",disabled:!0,children:e.jsx(fn,{size:15})}),e.jsx("button",{className:"glyph-icon-btn",title:b?"Exit fullscreen":"Fullscreen",onClick:_,children:e.jsx(on,{size:15})}),e.jsx("button",{className:"glyph-icon-btn",title:"More",children:e.jsx(Ka,{size:15})}),e.jsx("span",{className:"glyph-toolbar-divider"}),e.jsxs("button",{className:"glyph-icon-btn",title:"Comment count","aria-label":"Comment count",children:[e.jsx(qs,{size:15}),e.jsx("span",{className:"glyph-icon-btn-count",children:ee})]}),t&&e.jsx("button",{className:"glyph-icon-btn glyph-icon-btn--close",title:"Close",onClick:t,"aria-label":"Close",children:e.jsx($e,{size:15})})]}),e.jsxs("div",{className:"glyph-canvas-content",children:[e.jsxs("header",{className:"glyph-canvas-title",children:[e.jsx("h1",{className:"glyph-title",children:U}),e.jsxs("div",{className:"glyph-meta",children:[e.jsx("span",{className:`glyph-status glyph-status--${G}`,children:G}),e.jsx("span",{className:"glyph-slug",children:s})]})]}),(O.length>0||((fe=n.errors)==null?void 0:fe.length)>0)&&e.jsxs("div",{className:"glyph-render-errors",role:"alert",style:{border:"1px solid var(--error, #f85149)",background:"rgba(248, 81, 73, 0.08)",borderRadius:8,padding:"12px 16px",margin:"0 0 16px 0",color:"var(--text)"},children:[e.jsx("strong",{style:{color:"var(--error, #f85149)",display:"block",marginBottom:8},children:O.length>0?`${O.length} block${O.length===1?"":"s"} failed to render`:"Compiler warnings"}),e.jsxs("ul",{style:{margin:0,paddingLeft:20,fontFamily:"var(--font-mono, ui-monospace, monospace)",fontSize:12,lineHeight:1.6},children:[O.map((I,B)=>e.jsxs("li",{children:[e.jsx("strong",{children:I.blockType})," (",e.jsx("code",{children:I.blockId}),"): ",I.message]},`be-${B}`)),(V=n.errors)==null?void 0:V.map((I,B)=>e.jsxs("li",{children:[I.line?`line ${I.line}: `:"",I.message]},`ce-${B}`))]})]}),e.jsx("div",{className:"glyph-sections",children:j.map((I,B)=>e.jsxs("section",{className:`glyph-section ${I.heading?"glyph-section--headed":"glyph-section--plain"}`,children:[I.heading&&e.jsx("h2",{className:"glyph-section-heading",children:I.heading}),e.jsx("div",{className:"glyph-section-blocks",children:I.blocks.map(ae)})]},`sec-${B}-${I.heading??"ungrouped"}`))})]}),c.map(I=>e.jsxs("button",{className:`glyph-pin ${S===I.id?"glyph-pin--active":""}`,style:{left:I.x,top:I.y},onClick:B=>{B.stopPropagation(),q(S===I.id?null:I.id)},title:I.text,children:[e.jsx(Ct,{size:14}),S===I.id&&e.jsxs("div",{className:"glyph-pin-thread",children:[e.jsx("div",{className:"glyph-pin-text",children:I.text}),e.jsxs("div",{className:"glyph-pin-meta",children:[I.author??"anonymous"," · ",I.created?new Date(I.created).toLocaleString():""]})]})]},I.id)),y&&e.jsx("div",{className:"glyph-ctx-menu",style:{left:y.x,top:y.y},onClick:I=>I.stopPropagation(),children:e.jsxs("button",{className:"glyph-ctx-item",onClick:()=>{$({worldX:y.worldX,worldY:y.worldY}),v(null)},children:[e.jsx(Ct,{size:14})," Add comment here"]})}),L&&e.jsx("div",{className:"glyph-modal-overlay",onClick:()=>$(null),children:e.jsxs("div",{className:"glyph-modal",onClick:I=>I.stopPropagation(),children:[e.jsxs("h3",{children:["Add comment at (",Math.round(L.worldX),", ",Math.round(L.worldY),")"]}),e.jsx("textarea",{autoFocus:!0,value:R,onChange:I=>P(I.target.value),placeholder:"What should the agent know about this area?",rows:4,className:"glyph-modal-textarea"}),e.jsxs("div",{className:"glyph-modal-actions",children:[e.jsx("button",{className:"glyph-btn glyph-btn--ghost",onClick:()=>$(null),children:"Cancel"}),e.jsx("button",{className:"glyph-btn glyph-btn--primary",onClick:F,disabled:!R.trim(),children:"Add comment"})]})]})})]})}function Ji(){return e.jsx("span",{className:"glyph-spinner","aria-label":"loading",children:"…"})}function er(s){switch(s){case"approved":case"done":return"success";case"in-progress":case"doing":return"info";case"rejected":return"error";case"archived":return"warning";case"draft":default:return"neutral"}}function sr({snapshot:s,refreshSnapshot:t}){const a=oe(),[i,n]=r.useState(s.artifacts||[]),[l,c]=r.useState(!s.artifacts),[o,p]=r.useState(null),[x,h]=r.useState(""),[d,m]=r.useState(!1);r.useEffect(()=>{s.artifacts&&(n(s.artifacts),c(!1))},[s.artifacts]);const u=async()=>{try{const A=await w.get("/artifacts");n(A.artifacts||[]),c(!1)}catch(A){a.error(`Artifacts load failed: ${A.message}`),c(!1)}},g=r.useMemo(()=>{let A=i;if(x){const y=x.toLowerCase();A=A.filter(v=>(v.slug||"").toLowerCase().includes(y)||(v.title||"").toLowerCase().includes(y))}return d||(A=A.filter(y=>y.status!=="archived")),A},[i,x,d]),f=async(A,y)=>{try{const v=await w.post("/artifacts",{slug:A,title:y});a.success(`Artifact "${v.slug}" created.`),p(v.slug),await u()}catch(v){a.error(`Create failed: ${v.message}`)}},b=async A=>{if(confirm(`Delete artifact "${A}"? This removes the directory permanently.`))try{await w.del(`/artifacts/${encodeURIComponent(A)}`),a.success("Artifact deleted."),o===A&&p(null),await u()}catch(y){a.error(`Delete failed: ${y.message}`)}};return o?e.jsxs("div",{className:"artifact-glyph-overlay",children:[e.jsx("div",{className:"artifact-glyph-toolbar",children:e.jsxs(T,{variant:"ghost",onClick:()=>{p(null),u()},children:[e.jsx(Xt,{size:14})," Back to artifacts"]})}),e.jsx(Zi,{slug:o,onClose:()=>{p(null),u()},onCommentAdded:()=>u()})]}):e.jsxs("div",{className:"view view-artifacts",children:[e.jsxs("header",{className:"view-header",children:[e.jsxs("div",{className:"view-header-text",children:[e.jsxs("h2",{className:"view-title",children:[e.jsx(Os,{size:18})," Glyphs (",i.length,")"]}),e.jsx("p",{className:"view-subtitle",children:"Visual artifacts with elements, connections, and threaded comments."})]}),e.jsxs("div",{className:"view-actions",children:[e.jsxs("div",{className:"search-input",children:[e.jsx(ye,{size:14,"aria-hidden":!0}),e.jsx("label",{htmlFor:"artifacts-search",className:"sr-only",children:"Search artifacts"}),e.jsx("input",{id:"artifacts-search",className:"input",type:"text",placeholder:"Search…",value:x,onChange:A=>h(A.target.value),"aria-label":"Search artifacts"})]}),e.jsxs(T,{variant:"ghost",size:"sm",onClick:()=>m(A=>!A),title:d?"Hide archived":"Show archived",children:[d?e.jsx(Gt,{size:14}):e.jsx(Ta,{size:14}),d?"Hide archived":"Show archived"]}),e.jsxs(T,{variant:"secondary",size:"sm",onClick:u,children:[e.jsx(ce,{size:14})," Refresh"]})]})]}),e.jsx(tr,{onCreate:f}),l?e.jsx("div",{className:"view-loading",children:e.jsx(he,{size:"lg"})}):g.length===0?e.jsx(we,{icon:e.jsx(Os,{size:32}),title:d?"No artifacts":"No artifacts yet",message:d?"No artifacts match your filter (try Show archived off).":"Create one above to get started."}):e.jsx("div",{className:"artifacts-grid",children:g.map(A=>e.jsx(ar,{artifact:A,onOpen:()=>p(A.slug),onDelete:()=>b(A.slug)},A.slug))})]})}function tr({onCreate:s}){const[t,a]=r.useState(""),[i,n]=r.useState("");return e.jsxs(Q,{className:"new-artifact",children:[e.jsxs(se,{children:[e.jsx(Me,{size:14})," New artifact"]}),e.jsx(ie,{children:"Slug must be lowercase, may contain hyphens, 1–64 chars."}),e.jsxs("form",{className:"new-artifact-form",onSubmit:l=>{l.preventDefault(),t.trim()&&(s(t.trim(),i.trim()||void 0),a(""),n(""))},children:[e.jsx("label",{htmlFor:"new-artifact-slug",className:"sr-only",children:"Artifact slug"}),e.jsx("input",{id:"new-artifact-slug",className:"input",type:"text",placeholder:"slug (e.g. dashboard-v3.1)",pattern:"[a-z0-9][a-z0-9-]{0,63}",required:!0,value:t,onChange:l=>a(l.target.value),"aria-label":"Artifact slug"}),e.jsx("label",{htmlFor:"new-artifact-title",className:"sr-only",children:"Artifact title"}),e.jsx("input",{id:"new-artifact-title",className:"input",type:"text",placeholder:"Title (optional)",value:i,onChange:l=>n(l.target.value)}),e.jsx(T,{variant:"primary",type:"submit",children:"Create"})]})]})}function ar({artifact:s,onOpen:t,onDelete:a}){const i=er(s.status||"draft");return e.jsxs(Q,{variant:"elevated",interactive:!0,className:"artifact-card",onClick:t,children:[e.jsxs("div",{className:"artifact-card-head",children:[e.jsx("div",{className:"artifact-card-title",children:s.title||s.slug}),e.jsx(ns,{kind:i,children:s.status||"draft"})]}),e.jsxs("div",{className:"artifact-card-slug mono",children:[s.slug," · ",s.source]}),e.jsxs("div",{className:"artifact-card-meta",children:[s.elementCount!=null&&e.jsxs("span",{children:[s.elementCount," elements"]}),s.commentCount!=null&&e.jsxs("span",{children:[" · ",s.commentCount," comments"]}),e.jsxs("span",{children:[" · edited ",Ne(s.mtime)]})]}),e.jsxs("div",{className:"artifact-card-actions",children:[e.jsxs(T,{variant:"primary",size:"sm",onClick:n=>{n.stopPropagation(),t()},children:["Open",e.jsx(_e,{size:12})]}),e.jsxs(T,{variant:"ghost",size:"sm",onClick:n=>{n.stopPropagation(),a()},children:[e.jsx(Ae,{size:12})," Delete"]})]})]})}function nr({children:s,className:t,onRemove:a}){return e.jsxs("span",{className:X("tag",t),children:[s,a&&e.jsx("button",{type:"button",className:"tag-remove","aria-label":`Remove ${typeof s=="string"?s:"tag"}`,onClick:a,children:"×"})]})}function ir({task:s,agents:t,onPromote:a,onDelete:i,onEdit:n,onRefresh:l}){var h;const c=oe(),o=async()=>{try{await w.post(`/tasks/${encodeURIComponent(s.id)}/promote`),c.success("Promoted to queued.",1500),a(s.id)}catch(d){c.error(`Promote failed: ${d.message}`)}},p=async()=>{if(confirm("Delete this task?"))try{await w.del(`/tasks/${encodeURIComponent(s.id)}`),c.success("Deleted.",1500),i(s.id)}catch(d){c.error(`Delete failed: ${d.message}`)}},x={high:"var(--warning)",normal:"var(--info)",low:"var(--muted)"};return e.jsxs("div",{className:"backlog-item","data-task-id":s.id,children:[e.jsxs("div",{className:"backlog-item-head",children:[e.jsx("span",{className:"priority-dot",style:{background:x[s.priority]||"var(--info)"}}),e.jsx("span",{className:"backlog-item-title",children:s.title}),s.assignee&&e.jsxs("span",{className:"backlog-item-badge",children:["@",s.assignee]}),((h=s.tags)==null?void 0:h.length)>0&&e.jsx("span",{className:"backlog-item-badge",children:s.tags.join(", ")})]}),s.description&&e.jsx("div",{className:"backlog-item-desc",children:s.description.slice(0,120)}),e.jsxs("div",{className:"backlog-item-footer",children:[e.jsx("span",{className:"muted text-sm tabular-nums",children:Ne(s.createdAt)}),e.jsxs("div",{className:"backlog-item-actions",children:[e.jsx("button",{type:"button",className:"icon-btn",title:"Promote to queued",onClick:o,children:e.jsx(gt,{size:13})}),e.jsx("button",{type:"button",className:"icon-btn",title:"Edit",onClick:()=>n(s),children:e.jsx(Oe,{size:13})}),e.jsx("button",{type:"button",className:"icon-btn icon-btn-danger",title:"Delete",onClick:p,children:e.jsx(Ae,{size:13})})]})]})]})}function rr({agents:s,onRefresh:t}){const a=oe(),[i,n]=r.useState([]),[l,c]=r.useState(!1),o=async()=>{try{c(!0);const m=await w.get("/tasks/backlog");n(Array.isArray(m.tasks)?m.tasks:[])}catch(m){a.error(`Backlog load failed: ${m.message}`)}finally{c(!1)}};r.useEffect(()=>{o()},[]);const p=async m=>{n(u=>u.filter(g=>g.id!==m)),await t()},x=async m=>{n(u=>u.filter(g=>g.id!==m)),await t()},h=m=>{},d=async()=>{var m;if(i.length!==0)try{const g=((m=(await w.post("/tasks/promote-batch",{ids:i.map(f=>f.id)})).affected)==null?void 0:m.filter(f=>f.ok).length)??0;a.success(`Promoted ${g} task(s).`,2e3),n([]),await t()}catch(u){a.error(`Promote all failed: ${u.message}`)}};return e.jsxs("div",{className:"backlog-panel",children:[e.jsxs("div",{className:"backlog-panel-header",children:[e.jsxs("span",{className:"backlog-panel-title",children:[e.jsx(Fs,{size:15}),"Backlog (",i.length,")"]}),e.jsxs("div",{className:"backlog-panel-header-actions",children:[i.length>0&&e.jsxs(T,{variant:"ghost",size:"sm",onClick:d,title:"Promote all to queued",children:[e.jsx(gt,{size:12})," Promote all"]}),e.jsx(T,{variant:"ghost",size:"sm",onClick:o,title:"Refresh backlog","aria-label":"Refresh backlog",children:e.jsx(ce,{size:12,className:l?"animate-spin":""})})]})]}),l?e.jsx("div",{className:"backlog-empty",children:"Loading…"}):i.length===0?e.jsxs("div",{className:"backlog-empty",children:[e.jsx(Fs,{size:28}),e.jsx("span",{children:"Backlog is empty."})]}):e.jsx("div",{className:"backlog-list",children:i.map(m=>e.jsx(ir,{task:m,agents:s,onPromote:p,onDelete:x,onEdit:h,onRefresh:t},m.id))})]})}const Es=[{id:"queued",label:"Todo",kind:"info"},{id:"doing",label:"In progress",kind:"accent"},{id:"done",label:"Done",kind:"success"},{id:"blocked",label:"Failed",kind:"error"}],bt=["low","normal","high"];function lr({snapshot:s,refreshSnapshot:t,setActiveTab:a}){const i=oe(),n=Pe(),[l,c]=r.useState(s.tasks||[]),[o,p]=r.useState(!s.tasks),[x,h]=r.useState(""),[d,m]=r.useState(""),[u,g]=r.useState(!1),[f,b]=r.useState(0),[A,y]=r.useState(""),v=async()=>{try{const k=await w.get("/tasks");c(Array.isArray(k)?k:[])}catch(k){i.error(`Tasks load failed: ${k.message}`)}finally{p(!1)}};r.useEffect(()=>{s.tasks&&(c(s.tasks),p(!1))},[s.tasks]),r.useEffect(()=>{const k=setInterval(()=>b(N=>N+1),3e4);return()=>clearInterval(k)},[]);const L=r.useMemo(()=>{let k=l.filter(N=>N.status!=="backlog");if(d&&(k=k.filter(N=>(N.priority||"normal")===d)),x.trim()){const N=x.toLowerCase();k=k.filter(D=>(D.title||"").toLowerCase().includes(N)||(D.description||"").toLowerCase().includes(N))}return k},[l,x,d]),$=r.useMemo(()=>{const k={high:0,normal:1,low:2};return[...L].sort((N,D)=>{const j=k[N.priority]??1,M=k[D.priority]??1;return j!==M?j-M:new Date(D.createdAt).getTime()-new Date(N.createdAt).getTime()})},[L]),R=l.filter(k=>k.status==="backlog").length,P=async(k,N)=>{const D=l.find(M=>M.id===k);if(!D)return;const j=D.status;c(M=>M.map(F=>F.id===k?{...F,status:N}:F)),y(`Task ${D.title} moved to ${N}.`);try{await w.patch(`/tasks/${encodeURIComponent(k)}/status`,{status:N}),i.success(`Moved to ${N}.`,1200)}catch(M){c(F=>F.map(C=>C.id===k?{...C,status:j}:C)),y(`Failed to move task ${D.title}: ${M.message}`),i.error(`Move failed: ${M.message}`)}},S=async k=>{if(confirm("Delete this task?"))try{await w.del(`/tasks/${encodeURIComponent(k)}`),c(N=>N.filter(D=>D.id!==k)),i.success("Task deleted.",1200)}catch(N){i.error(`Delete failed: ${N.message}`)}},q=async k=>{try{const N=await w.post(`/tasks/${encodeURIComponent(k)}/start`);N&&N.task&&c(D=>D.map(j=>j.id===k?N.task:j)),i.success("Retry dispatched.",1200)}catch(N){i.error(`Retry failed: ${N.message}`)}},O=async k=>{const N=l.find(D=>D.id===k);if(N)try{const D=await w.post("/tasks/submit",{title:N.title,description:N.description,priority:N.priority,tags:N.tags}),j=(D.subtasks||[]).length;i.success(j>1?`Odin split it into ${j} subtasks.`:"Sent to Odin.",1500),D.subtasks&&D.subtasks.length>0&&c(M=>[D.main,...D.subtasks,...M.filter(F=>F.id!==N.id)]),await t()}catch(D){i.error(`Submit failed: ${D.message}`)}};return e.jsxs("div",{className:"view view-tasks",children:[e.jsx("div",{className:"sr-only",role:"status","aria-live":"polite",children:A}),e.jsx("header",{className:"view-header",children:e.jsxs("div",{className:"view-header-text",children:[e.jsxs("h2",{className:"view-title",children:[e.jsx(ps,{size:18})," Tasks (",$.length,")"]}),e.jsx("p",{className:"view-subtitle",children:"Add a task — title and description is all you need. Odin picks the agent and priority."})]})}),e.jsxs("div",{className:"tasks-toolbar",children:[e.jsx("div",{className:"tasks-toolbar-group",children:e.jsxs("div",{className:"search-input",style:{width:200},children:[e.jsx(ye,{size:12,"aria-hidden":!0}),e.jsx("input",{className:"input",type:"text",placeholder:"Search…",value:x,onChange:k=>h(k.target.value),"aria-label":"Search tasks"}),x&&e.jsx("button",{type:"button",className:"icon-btn","aria-label":"Clear search",onClick:()=>h(""),children:e.jsx($e,{size:12})})]})}),e.jsx("div",{className:"tasks-toolbar-divider"}),e.jsxs("div",{className:"tasks-toolbar-group",children:[e.jsx("label",{className:"tasks-toolbar-label",htmlFor:"tasks-priority-filter",children:"Priority"}),e.jsxs("select",{id:"tasks-priority-filter",className:"select select-sm",value:d,onChange:k=>m(k.target.value),title:"Filter by priority",children:[e.jsx("option",{value:"",children:"All"}),bt.map(k=>e.jsx("option",{value:k,children:k},k))]})]}),e.jsx("div",{className:"tasks-toolbar-spacer"}),e.jsxs("div",{className:"tasks-toolbar-group",children:[e.jsx(T,{variant:"ghost",size:"sm",onClick:v,title:"Refresh","aria-label":"Refresh tasks",children:e.jsx(ce,{size:14})}),R>0&&e.jsxs(T,{variant:u?"accent":"ghost",size:"sm",onClick:()=>g(k=>!k),title:u?"Hide backlog":"Show backlog",children:[e.jsx(Fs,{size:14}),"Backlog",e.jsx("span",{className:"badge",children:R})]}),e.jsxs(T,{variant:"primary",size:"sm",onClick:()=>dr(n,i,c,v,t),children:[e.jsx(Me,{size:14})," New task"]})]})]}),u&&R>0&&e.jsx(rr,{agents:s.agents||[],onRefresh:t}),o?e.jsx("div",{className:"view-loading",children:e.jsx(he,{size:"lg"})}):e.jsx("div",{className:"kanban",children:Es.map(k=>e.jsx(or,{column:k,tasks:$.filter(N=>N.status===k.id),onMove:P,onDelete:S,onRetry:q,onEdit:N=>mr(n,i,N,c,v,t),onSubmitToOdin:O,tick:f},k.id))})]})}function or({column:s,tasks:t,onMove:a,onDelete:i,onRetry:n,onEdit:l,onSubmitToOdin:c,tick:o}){const[p,x]=r.useState(!1);return e.jsxs("div",{className:X("kanban-column",p&&"kanban-column-drop"),"data-column":s.id,onDragOver:h=>{h.preventDefault(),x(!0)},onDragLeave:()=>x(!1),onDrop:h=>{h.preventDefault(),x(!1);const d=h.dataTransfer.getData("text/task-id");d&&a(d,s.id)},children:[e.jsxs("div",{className:"kanban-col-header",children:[e.jsxs(se,{children:[e.jsx("span",{className:X("status-dot",`status-${s.kind}`)}),s.label]}),e.jsx("span",{className:"kanban-col-count tabular-nums",children:t.length})]}),e.jsx("div",{className:"kanban-col-body",children:t.length===0?e.jsx("div",{className:"kanban-empty",children:"No tasks"}):t.map(h=>e.jsx(cr,{task:h,onMove:d=>{const u=Es.findIndex(g=>g.id===h.status)+d;u>=0&&u<Es.length&&a(h.id,Es[u].id)},onEdit:()=>l(h),onDelete:()=>i(h.id),onRetry:()=>n(h.id),onSubmitToOdin:()=>c(h.id),tick:o},h.id))})]})}function cr({task:s,onMove:t,onEdit:a,onDelete:i,onRetry:n,onSubmitToOdin:l,tick:c}){const o=s.workedBy||s.assignee||null;return e.jsxs("div",{className:X("task-card",`priority-${s.priority}`),"data-task-id":s.id,draggable:!0,onDragStart:p=>{p.dataTransfer.setData("text/task-id",s.id),p.dataTransfer.effectAllowed="move"},"data-tick":c,children:[e.jsxs("div",{className:"task-card-head",children:[e.jsx("span",{className:"priority-dot",style:{background:$a[s.priority]||"var(--info)"}}),e.jsx("div",{className:"task-card-title",children:s.title})]}),s.description&&e.jsx("div",{className:"task-card-desc",children:s.description.slice(0,160)}),e.jsxs("div",{className:"task-card-badges",children:[o&&e.jsxs("span",{className:"task-card-badge",title:`Auto-assigned to @${o}`,children:[e.jsx(qe,{size:10})," @",o]}),s.timeSpent?e.jsxs("span",{className:"task-card-badge",children:[e.jsx(Ds,{size:10})," ",Math.round((s.timeSpent||0)/60),"m"]}):null,s.tags&&s.tags.length>0&&s.tags.slice(0,3).map(p=>e.jsx(nr,{children:p},p))]}),e.jsxs("div",{className:"task-card-footer",children:[e.jsx("span",{className:"task-card-time tabular-nums muted",children:Ne(s.createdAt)}),e.jsxs("div",{className:"task-card-actions",onClick:p=>p.stopPropagation(),children:[e.jsx("button",{type:"button",className:"icon-btn","aria-label":"Move left",title:"Move left",onClick:()=>t(-1),children:e.jsx(qa,{size:14})}),e.jsx("button",{type:"button",className:"icon-btn","aria-label":"Edit",title:"Edit",onClick:a,children:e.jsx(pn,{size:14})}),e.jsx("button",{type:"button",className:"icon-btn","aria-label":"Submit to Odin",title:"Re-delegate to Odin",onClick:l,children:e.jsx(Xe,{size:14})}),e.jsx("button",{type:"button",className:"icon-btn","aria-label":"Retry",title:"Retry",onClick:n,children:e.jsx(xt,{size:14})}),e.jsx("button",{type:"button",className:"icon-btn icon-btn-danger","aria-label":"Delete",title:"Delete",onClick:i,children:e.jsx(Ae,{size:14})}),e.jsx("button",{type:"button",className:"icon-btn","aria-label":"Move right",title:"Move right",onClick:()=>t(1),children:e.jsx(_e,{size:14})})]})]})]})}function dr(s,t,a,i,n){let l=null,c=null,o=null,p=null;const x=async d=>{d&&typeof d.preventDefault=="function"&&d.preventDefault();const m=((l==null?void 0:l.value)||"").trim(),u=((c==null?void 0:c.value)||"").trim();if(!m){t.warning("Title is required."),l==null||l.focus();return}const g=(p==null?void 0:p.value)||"normal",f=((o==null?void 0:o.value)||"").split(",").map(b=>b.trim()).filter(Boolean);try{const b=await w.post("/tasks",{title:m,description:u,priority:g,tags:f});s.close(),typeof window<"u"&&window.dispatchEvent(new MouseEvent("mousedown")),a(A=>[b,...A]),t.success("Task created.",1200),await n()}catch(b){t.error(`Create failed: ${b.message}`)}},h=d=>{d.key==="Enter"&&!d.shiftKey&&(d.preventDefault(),x(d))};s.open({title:"New task",width:520,children:e.jsxs("div",{className:"task-form",children:[e.jsx("label",{className:"field-label",htmlFor:"task-title",children:"Title *"}),e.jsx("input",{ref:d=>{l=d},id:"task-title",className:"input",type:"text",maxLength:200,placeholder:"What needs to be done?",autoFocus:!0,onKeyDown:h}),e.jsx("label",{className:"field-label",htmlFor:"task-desc",children:"Description"}),e.jsxs("div",{style:{display:"flex",gap:6,alignItems:"flex-start"},children:[e.jsx("textarea",{ref:d=>{c=d},id:"task-desc",className:"textarea",rows:4,placeholder:"Add any context Odin might need (markdown ok)…",style:{flex:1}}),e.jsx("button",{type:"button",className:"btn btn-ghost btn-icon",title:"Enhance with AI",onClick:async()=>{var m;if(!((m=c==null?void 0:c.value)!=null&&m.trim()))return;const d=await Ma(c.value);d!==c.value&&(c.value=d)},children:"✨"})]}),e.jsxs("div",{className:"task-form-row",children:[e.jsxs("label",{htmlFor:"task-priority",className:"task-form-field",children:["Priority hint",e.jsx("select",{ref:d=>{p=d},id:"task-priority",className:"select",defaultValue:"normal",children:bt.map(d=>e.jsx("option",{value:d,children:d},d))})]}),e.jsxs("label",{htmlFor:"task-tags",className:"task-form-field",style:{flex:2},children:["Tags ",e.jsx("span",{className:"field-hint",children:"(comma-separated)"}),e.jsx("input",{ref:d=>{o=d},id:"task-tags",className:"input",type:"text",placeholder:"bug, frontend, urgent"})]})]}),e.jsx("p",{className:"muted text-sm",style:{marginTop:8},children:"The agent and final priority are decided by Odin after you submit."})]}),footer:e.jsxs("div",{className:"modal-footer-actions",children:[e.jsx(T,{variant:"ghost",onClick:()=>s.close(),children:"Cancel"}),e.jsxs(T,{variant:"primary",type:"button",onClick:d=>x(d),children:[e.jsx(Me,{size:14})," Create task"]})]})})}function mr(s,t,a,i,n,l){let c=null,o=null,p=null,x=null;const h=async()=>{const d=((c==null?void 0:c.value)||"").trim(),m=((o==null?void 0:o.value)||"").trim();if(!d){t.warning("Title is required."),c==null||c.focus();return}const u=(x==null?void 0:x.value)||"normal",g=((p==null?void 0:p.value)||"").split(",").map(f=>f.trim()).filter(Boolean);try{const f=await w.put(`/tasks/${encodeURIComponent(a.id)}`,{title:d,description:m,priority:u,tags:g});s.close(),typeof window<"u"&&window.dispatchEvent(new MouseEvent("mousedown")),i(b=>b.map(A=>A.id===a.id?f:A)),t.success("Task updated.",1200),await l()}catch(f){t.error(`Save failed: ${f.message}`)}};s.open({title:"Edit task",width:520,children:e.jsxs("div",{className:"task-form",children:[e.jsx("label",{className:"field-label",htmlFor:"edit-task-title",children:"Title *"}),e.jsx("input",{ref:d=>{c=d},id:"edit-task-title",className:"input",type:"text",maxLength:200,defaultValue:a.title,autoFocus:!0}),e.jsx("label",{className:"field-label",htmlFor:"edit-task-desc",children:"Description"}),e.jsx("textarea",{ref:d=>{o=d},id:"edit-task-desc",className:"textarea",rows:4,defaultValue:a.description||""}),e.jsxs("div",{className:"task-form-row",children:[e.jsxs("label",{htmlFor:"edit-task-priority",className:"task-form-field",children:["Priority hint",e.jsx("select",{ref:d=>{x=d},id:"edit-task-priority",className:"select",defaultValue:a.priority||"normal",children:bt.map(d=>e.jsx("option",{value:d,children:d},d))})]}),e.jsxs("label",{htmlFor:"edit-task-tags",className:"task-form-field",style:{flex:2},children:["Tags",e.jsx("input",{ref:d=>{p=d},id:"edit-task-tags",className:"input",type:"text",defaultValue:(a.tags||[]).join(", "),placeholder:"comma-separated"})]})]}),e.jsxs(Q,{children:[e.jsxs(se,{children:[e.jsx(ea,{size:12})," Status"]}),e.jsxs(ie,{children:["Current: ",e.jsx("strong",{children:a.status}),a.workedBy&&e.jsxs(e.Fragment,{children:[" · Worked by @",a.workedBy]}),a.assignee&&!a.workedBy&&e.jsxs(e.Fragment,{children:[" · Assigned @",a.assignee]})]})]})]}),footer:e.jsxs("div",{className:"modal-footer-actions",children:[e.jsx(T,{variant:"ghost",onClick:()=>s.close(),children:"Cancel"}),e.jsxs(T,{variant:"primary",onClick:h,children:[e.jsx(Gt,{size:14})," Save"]})]})})}const hr=We.memo(lr);function ur(s){return w.urlWithToken(`/artifacts/${encodeURIComponent(s)}/content`)}function xr(s,t){const a=ur(t);window.open(a,"_blank","noopener,noreferrer")}const Rt={"1m":60*1e3,"5m":5*60*1e3,"30m":30*60*1e3,"1h":60*60*1e3},ze=56,Be=32,ss=22,pr=4,gr=.9,Xs={working:"var(--success)",running:"var(--success)",doing:"var(--info)",queued:"var(--info)",done:"var(--success)",success:"var(--success)",blocked:"var(--warning)",error:"var(--error)",failed:"var(--error)",stuck:"var(--warning)",killed:"var(--error)",idle:"var(--text-dim)",pending:"var(--info)",timed_out:"var(--warning)"};function Qs(s){return s&&Xs[s]||Xs.idle}function $s(s,t=24){return s?s.length<=t?s:s.slice(0,t-1)+"…":""}function Us(s){if(s==null)return 0;if(typeof s=="number")return s;const t=new Date(s).getTime();return Number.isNaN(t)?0:t}function Zs(s){const t=s._timerStart;return typeof t=="number"&&t>0?t:Us(s.createdAt)||Date.now()}function jr(s,t){return(s.status==="done"||s.status==="archived"||s.status==="failed"||s.status==="killed")&&(Us(s.completedAt)||Us(s.updatedAt))||t}function fr(s){return typeof s.startedAt=="number"&&s.startedAt>0?s.startedAt:Date.now()}function vr(s,t){return(s.status==="done"||s.status==="success"||s.status==="killed"||s.status==="failed"||s.status==="error"||s.status==="timed_out")&&(s.completedAt||s.lastEventAt)||t}function yr(s){return s<=6e4?1e4:s<=3e5?3e4:s<=18e5?3e5:6e5}function br(s,t){const a=new Date(s);return t<=3e5?a.toLocaleTimeString("en-GB",{hour12:!1}):a.toLocaleTimeString("en-GB",{hour12:!1,hour:"2-digit",minute:"2-digit"})}function kr({snapshot:s,refreshSnapshot:t}){const a=oe(),i=r.useRef(null),[n,l]=r.useState("live"),[c,o]=r.useState("5m"),[p,x]=r.useState(()=>typeof window>"u"?!0:window.innerWidth>900),[h,d]=r.useState([]),[m,u]=r.useState([]),[g,f]=r.useState(!0),[b,A]=r.useState(0),[y,v]=r.useState(Date.now()),[L,$]=r.useState(()=>Date.now()-Rt["5m"]*.1),[R,P]=r.useState({width:800,height:400}),[S,q]=r.useState(null),[O,k]=r.useState(""),[N,D]=r.useState([]),[j,M]=r.useState(""),[F,C]=r.useState("normal"),[_,ae]=r.useState(""),[J,U]=r.useState(""),[G,ee]=r.useState(!1),[Z,re]=r.useState(!1),[fe,V]=r.useState([]),I=Pe(),B=s.agents||[],H=s.tasks||[],ne=Rt[c],W=L,E=L+ne,le=r.useCallback(async()=>{try{const[z,K]=await Promise.all([w.get("/background").catch(()=>({instances:[]})),w.get("/activity?limit=200").catch(()=>({events:[]}))]);d(z.instances||[]),u(K.events||[])}catch(z){console.warn("activity reload failed:",z)}finally{f(!1)}},[]);r.useEffect(()=>{le();const z=setInterval(le,3e3);return()=>clearInterval(z)},[le]),r.useEffect(()=>{A(z=>z+1)},[H.length,B.length]),r.useEffect(()=>{if(n==="pause")return;v(Date.now());const z=setInterval(()=>v(Date.now()),1e3);return()=>clearInterval(z)},[n,b]),r.useEffect(()=>{if(n==="pause")return;(y-L)/ne>gr&&$(y-ne*.1)},[y,L,ne,n]),r.useEffect(()=>{$(Date.now()-ne*.1)},[c]),r.useEffect(()=>{n==="live"&&$(Date.now()-ne*.1)},[n]),r.useLayoutEffect(()=>{const z=i.current;if(!z)return;const K=new ResizeObserver(xe=>{for(const pe of xe){const{width:me,height:ge}=pe.contentRect;P({width:Math.max(200,Math.floor(me)),height:Math.max(120,Math.floor(ge))})}});return K.observe(z),()=>K.disconnect()},[]);const te=r.useMemo(()=>{const z=[];let K=0;for(const me of h){const ge=fr(me),Re=vr(me,y);Re<W||ge>E||z.push({kind:"bg",id:`bg:${me.instanceId}`,index:K++,label:`BG ${$s(me.promptPreview,20)||me.instanceId.slice(0,10)}`,sub:me.status||"pending",start:ge,end:Re,data:me})}const xe=[...H].sort((me,ge)=>Zs(me)-Zs(ge)),pe=[];for(const me of xe){const ge=Zs(me),Re=jr(me,y);if(Re<W||ge>E)continue;let Ze=-1;for(let Ve=0;Ve<pe.length;Ve++)if(pe[Ve]<=ge){pe[Ve]=Re,Ze=Ve;break}Ze===-1&&(pe.push(Re),Ze=pe.length-1),z.push({kind:"task",id:`task:${me.id}`,index:K+Ze,label:$s(me.title,32),sub:me.status,start:ge,end:Re,data:me})}return z},[h,H,y,W,E]),ue=r.useMemo(()=>{const z=new Map;for(const K of te)z.set(K.id,K);return z},[te]),de=r.useCallback(z=>ne<=0?0:(z-W)/ne*R.width,[W,ne,R.width]),ws=r.useMemo(()=>{const z=yr(ne),K=[],xe=Math.floor(W/z)*z;for(let pe=xe;pe<=E+z;pe+=z){if(pe<W-z)continue;if(pe>E)break;const me=de(pe);me<-40||me>R.width+40||K.push({t:pe,x:me,label:br(pe,ne)})}return K},[W,E,ne,R.width,de]),Ss=r.useMemo(()=>{const z=[];for(const K of te){if(K.kind==="events")continue;const xe=Math.max(K.start,W),pe=Math.min(K.end,E);if(pe<W||xe>E)continue;const me=de(xe),ge=de(pe),Re=Math.max(pr,ge-me),Ze=Be+ss+K.index*ze+8,Ve=ze-16;let De="doing";if(K.kind==="bg"){const be=K.data.status||"pending";be==="done"||be==="success"?De="done":be==="failed"||be==="killed"||be==="error"?De="failed":be==="queued"||be==="pending"?De="queued":be==="blocked"||be==="stuck"?De="blocked":De="doing"}else{const be=K.data.status;be==="done"||be==="archived"?De="done":be==="failed"||be==="killed"?De="failed":be==="queued"?De="queued":be==="blocked"?De="blocked":De="doing"}const ga=(S==null?void 0:S.id)===K.id;z.push({id:K.id,laneIndex:K.index,x:me,y:Ze,w:Re,h:Ve,label:K.label,statusClass:De,selected:ga,data:K.data,kind:K.kind,start:K.start,end:K.end})}return z},[te,de,S,W,E]),Cs=r.useMemo(()=>{const z=[];for(const K of m){const xe=Us(K.ts);if(xe<W-5e3||xe>E+5e3)continue;const pe=de(xe);let me=Be+12;if(K.taskId){const ge=ue.get(`task:${K.taskId}`);ge&&(me=Be+ss+ge.index*ze+ze/2)}else if(K.nodeId){const ge=String(K.nodeId),Re=ue.get(ge.startsWith("task:")||ge.startsWith("bg:")?ge:`task:${ge}`);Re&&(me=Be+ss+Re.index*ze+ze/2)}z.push({id:`${K.ts}-${K.kind}-${K.author??""}-${K.taskId??""}`,x:pe,y:me,kind:K.kind||"event",ts:xe,text:String(K.text||K.kind||""),author:K.author})}return z},[m,W,E,de,ue]),zs=r.useMemo(()=>te.map(z=>({id:z.id,y:Be+ss+z.index*ze,h:ze})),[te]),Ts=r.useMemo(()=>{const z=de(y);return Math.max(0,Math.min(R.width,z))},[de,y,R.width]),ma=r.useCallback(z=>{const xe={id:z.id,kind:z.kind,label:z.label,status:z.statusClass,data:z.data};q(xe)},[]);r.useEffect(()=>{if(!S){D([]),U(""),V([]);return}k(""),M(""),ae(""),V([]),(async()=>{try{const z=await w.get(`/activity?nodeId=${encodeURIComponent(S.id)}&limit=50`);D(z.events||[])}catch{D([])}if(S.kind==="bg"){const z=S.data;try{const K=await w.get(`/background/${encodeURIComponent(z.instanceId)}/output?lines=80`);U(K.output||"")}catch{U("")}if(z.taskId)try{const K=await w.get(`/tasks/${encodeURIComponent(z.taskId)}/artifacts`);V((K.artifacts||[]).map(xe=>xe.id))}catch{V([])}}})()},[S]);const wt=async()=>{if(!(!S||!O.trim())){re(!0);try{await w.post("/comments",{nodeId:S.id,text:O,author:"user"}),k("");const z=await w.get(`/activity?nodeId=${encodeURIComponent(S.id)}&limit=50`);D(z.events||[]),a.success("Comment added.")}catch(z){a.error(`Comment failed: ${z.message}`)}finally{re(!1)}}},ha=async()=>{if(!(!S||!j.trim())){ee(!0);try{await w.post(`/nodes/${encodeURIComponent(S.id)}/tasks`,{title:j,description:`Created from timeline selection ${S.id}.`,priority:F}),M(""),a.success("Task created."),await t()}catch(z){a.error(`Task create failed: ${z.message}`)}finally{ee(!1)}}},St=async()=>{if(!S||S.kind!=="bg"||!_.trim())return;const z=S.data;try{const K=await w.post(`/background/${encodeURIComponent(z.instanceId)}/message`,{message:_});K.ok?(a.success("Message sent."),ae("")):a.warning(K.error||"Send failed")}catch(K){a.error(`Send failed: ${K.message}`)}},ua=async()=>{if(!S||S.kind!=="bg"||!confirm("Kill this bg instance session?"))return;const z=S.data;try{const K=await w.del(`/background/${encodeURIComponent(z.instanceId)}`);K.ok?a.success("Session killed."):a.warning(K.error||"Kill failed"),await le()}catch(K){a.error(`Kill failed: ${K.message}`)}},xa=async()=>{if(!S||S.kind!=="bg")return;const z=S.data;try{const K=await w.get(`/background/${encodeURIComponent(z.instanceId)}/output?lines=80`);U(K.output||"")}catch{}};r.useEffect(()=>{const z=K=>{K.key==="Escape"&&q(null)};return window.addEventListener("keydown",z),()=>window.removeEventListener("keydown",z)},[]);const pa=()=>{A(z=>z+1),le()},Ws=Be+ss+te.length*ze;return e.jsxs("div",{className:"view view-activity",children:[e.jsxs("header",{className:"view-header",children:[e.jsxs("div",{className:"view-header-text",children:[e.jsxs("h2",{className:"view-title",children:[e.jsx(Te,{size:18})," Activity"]}),e.jsx("p",{className:"view-subtitle",children:"Live timeline of agents, tasks, and background sessions. Active tasks pulse; the red line marks “now”."})]}),e.jsx("div",{className:"view-actions",children:e.jsxs("div",{className:"tl-mode-toggle",children:[e.jsxs(T,{variant:n==="live"?"primary":"secondary",size:"sm",onClick:()=>l(n==="live"?"pause":"live"),title:n==="live"?"Pause timeline":"Resume timeline",children:[n==="live"?e.jsx(Aa,{size:14}):e.jsx(Ns,{size:14}),n==="live"?"Live":"Paused"]}),e.jsx("div",{className:"tl-zoom-group",children:["1m","5m","30m","1h"].map(z=>e.jsx("button",{type:"button",className:X("tl-zoom-btn",c===z&&"tl-zoom-btn-active"),onClick:()=>o(z),title:`Zoom to ${z}`,children:z},z))}),e.jsxs(T,{variant:"secondary",size:"sm",onClick:pa,title:"Refresh",children:[e.jsx(ce,{size:14})," Refresh"]})]})})]}),g&&e.jsx("div",{className:"view-loading",children:e.jsx(he,{size:"lg"})}),!g&&B.length===0&&H.length===0&&h.length===0&&m.length===0?e.jsx(we,{icon:e.jsx(Te,{size:32}),title:"No activity yet",message:"Once agents, tasks, or background instances exist, they'll show up here on the timeline."}):e.jsx("div",{className:X("tl-view",S&&"tl-view-detail-open"),children:e.jsxs("div",{className:X("tl-body",!p&&"tl-body-stream-collapsed"),children:[e.jsxs("aside",{className:X("tl-stream",!p&&"tl-stream-collapsed"),children:[e.jsxs("div",{className:"tl-stream-head",children:[e.jsxs("h3",{children:[e.jsx(gs,{size:13})," Live events"]}),e.jsx("button",{type:"button",className:"icon-btn",onClick:()=>x(!1),title:"Hide event stream","aria-label":"Hide event stream",children:e.jsx(hn,{size:14})})]}),e.jsx("div",{className:"tl-stream-list",children:m.length===0?e.jsx("div",{className:"tl-stream-empty",children:e.jsx("p",{children:"No events yet."})}):e.jsx(ht,{items:[...m].reverse(),itemHeight:40,height:400,className:"tl-stream-virtual",renderItem:z=>{const K=z.author?qe:z.kind==="task"?ps:z.kind==="bg"?Vs:Te;return e.jsxs("div",{className:"tl-stream-event",children:[e.jsx("span",{className:"tl-stream-event-time",children:new Date(z.ts).toLocaleTimeString("en-GB",{hour12:!1})}),e.jsx("span",{className:"tl-stream-event-icon",style:{color:Qs(z.kind)},children:e.jsx(K,{size:12})}),e.jsx("span",{className:"tl-stream-event-text",children:z.author||z.text||z.kind})]})}})})]}),e.jsxs("div",{className:"tl-canvas-wrap",ref:i,children:[e.jsxs("div",{className:"tl-canvas-toolbar",children:[e.jsxs("div",{className:"tl-canvas-toolbar-left",children:[!p&&e.jsxs(T,{variant:"ghost",size:"sm",onClick:()=>x(!0),title:"Show event stream",children:[e.jsx(un,{size:14})," Events"]}),e.jsx("span",{className:"tl-canvas-mode",children:n==="live"?"● Live":"⏸ Paused"}),e.jsxs("span",{className:"tl-canvas-range",children:[new Date(W).toLocaleTimeString("en-GB",{hour12:!1})," →"," ",new Date(E).toLocaleTimeString("en-GB",{hour12:!1})]})]}),e.jsxs("div",{className:"tl-canvas-legend",children:[e.jsxs("span",{className:"tl-legend-item",children:[e.jsx("span",{className:"tl-legend-dot",style:{background:"var(--success)"}})," active"]}),e.jsxs("span",{className:"tl-legend-item",children:[e.jsx("span",{className:"tl-legend-dot tl-legend-dot-dashed",style:{borderColor:"var(--info)"}})," queued"]}),e.jsxs("span",{className:"tl-legend-item",children:[e.jsx("span",{className:"tl-legend-dot",style:{background:"var(--warning)"}})," blocked"]}),e.jsxs("span",{className:"tl-legend-item",children:[e.jsx("span",{className:"tl-legend-dot",style:{background:"var(--error)"}})," error"]}),e.jsx("span",{className:"tl-legend-sep"}),e.jsxs("span",{className:"tl-legend-item",children:[e.jsx(ln,{size:11})," agent"]}),e.jsxs("span",{className:"tl-legend-item",children:[e.jsx(Nn,{size:11})," task"]}),e.jsxs("span",{className:"tl-legend-item",children:[e.jsx(Vs,{size:11})," bg"]})]})]}),e.jsx("div",{className:"tl-canvas-scroll",children:e.jsxs("svg",{className:"tl-canvas",width:R.width,height:Math.max(R.height,Ws),role:"application","aria-label":"Activity timeline",children:[e.jsx("defs",{children:e.jsx("pattern",{id:"tl-canvas-grid",width:R.width,height:ze,patternUnits:"userSpaceOnUse",children:e.jsx("path",{d:`M 0 0 L 0 ${ze}`,fill:"none",stroke:"var(--border)",strokeWidth:.5,opacity:.35})})}),e.jsx("rect",{width:"100%",height:"100%",fill:"url(#tl-canvas-grid)"}),zs.map(z=>e.jsx("rect",{className:"tl-lane-bg",x:0,y:z.y,width:R.width,height:z.h,fill:z.id.charCodeAt(z.id.length-1)%2===0?"var(--bg-elev-2)":"var(--bg-elev)",opacity:.4},`bg-${z.id}`)),e.jsx("g",{className:"tl-time-axis",children:ws.map(z=>e.jsxs("g",{children:[e.jsx("line",{x1:z.x,y1:0,x2:z.x,y2:Ws,stroke:"var(--border)",strokeWidth:.5,strokeDasharray:"2,4",opacity:.5}),e.jsx("text",{x:z.x+4,y:Be-8,fontSize:10,fontFamily:"var(--font-mono)",fill:"var(--text-dim)",children:z.label})]},`tick-${z.t}`))}),te.map(z=>{const K=Be+ss+z.index*ze+ze/2;return e.jsxs("g",{className:"tl-lane-label-group",children:[e.jsx("text",{x:6,y:K-2,className:"tl-lane-label",textAnchor:"start",children:$s(z.label,28)}),e.jsx("text",{x:6,y:K+10,className:"tl-lane-label-sub",textAnchor:"start",children:z.sub})]},`label-${z.id}`)}),Ss.map(z=>{const K=Qs(z.statusClass),xe=z.id===(S==null?void 0:S.id);return e.jsxs("g",{className:X("tl-task-bar",`tl-task-bar-${z.statusClass}`,xe&&"tl-task-bar-selected"),onClick:()=>ma(z),children:[e.jsx("rect",{x:z.x,y:z.y,width:z.w,height:z.h,rx:6,fill:K,fillOpacity:z.statusClass==="done"?.35:z.statusClass==="queued"?.18:.85,stroke:K,strokeWidth:xe?2.5:1.5,strokeOpacity:z.statusClass==="done"?.5:1,strokeDasharray:z.statusClass==="queued"?"4 4":void 0,style:{cursor:"pointer"}}),z.w>36&&e.jsx("text",{x:z.x+8,y:z.y+z.h/2+4,fontSize:11,fontFamily:"var(--font-sans)",fontWeight:500,fill:"var(--text-strong)",style:{pointerEvents:"none"},opacity:z.statusClass==="done"?.7:1,children:$s(z.label,Math.max(4,Math.floor(z.w/7)))})]},`bar-${z.id}`)}),Cs.map(z=>{const K=Qs(z.kind);return e.jsxs("g",{className:"tl-event-marker-group",children:[e.jsx("line",{x1:z.x,y1:z.y-6,x2:z.x,y2:z.y+6,stroke:K,strokeWidth:1.2,opacity:.7}),e.jsx("circle",{cx:z.x,cy:z.y,r:4,fill:K,opacity:.9,children:e.jsx("title",{children:`${z.kind}${z.author?` · ${z.author}`:""} · ${new Date(z.ts).toLocaleTimeString("en-GB",{hour12:!1})}`})})]},`ev-${z.id}`)}),e.jsx("line",{className:"tl-now-line",x1:Ts,y1:0,x2:Ts,y2:Ws,stroke:"var(--error)",strokeWidth:1.5,opacity:.9}),e.jsxs("g",{className:"tl-now-marker",children:[e.jsx("circle",{cx:Ts,cy:Be-4,r:4,fill:"var(--error)"}),e.jsx("text",{x:Ts+6,y:Be-4,fontSize:10,fontWeight:700,fill:"var(--error)",fontFamily:"var(--font-mono)",children:"now"})]})]})})]}),S&&e.jsx("aside",{className:"tl-detail tl-detail-enter",children:e.jsxs(Q,{children:[e.jsxs(se,{children:[S.kind==="agent"&&e.jsx(qe,{size:14}),S.kind==="task"&&e.jsx(ps,{size:14}),S.kind==="bg"&&e.jsx(Vs,{size:14}),S.label,e.jsx("button",{type:"button",className:"icon-btn",onClick:()=>q(null),title:"Close","aria-label":"Close activity detail",style:{marginLeft:"auto"},children:e.jsx($e,{size:14})})]}),e.jsxs("div",{className:"tl-detail-meta",children:[e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"type"})," ",S.kind]}),e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"status"})," ",e.jsx("code",{children:S.status})]}),S.kind==="agent"&&(()=>{const z=S.data;return e.jsxs(e.Fragment,{children:[z.role&&e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"role"})," ",z.role]}),z.model&&e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"model"})," ",z.model]})]})})(),S.kind==="task"&&(()=>{const z=S.data;return e.jsxs(e.Fragment,{children:[z.assignee&&e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"assignee"})," @",z.assignee]}),z.priority&&e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"priority"})," ",z.priority]}),z.createdAt&&e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"created"})," ",new Date(z.createdAt).toLocaleString()]})]})})(),S.kind==="bg"&&(()=>{const z=S.data;return e.jsxs(e.Fragment,{children:[z.startedAt&&e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"started"})," ",new Date(z.startedAt).toLocaleString()]}),z.tmuxSession&&e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"tmux"})," ",e.jsx("code",{children:z.tmuxSession})," ",z.tmuxActive?e.jsx("span",{className:"tag tag-success",children:"active"}):e.jsx("span",{className:"tag",children:"inactive"})]})]})})()]}),S.kind==="task"&&S.data.description&&e.jsx("div",{className:"tl-detail-desc",children:S.data.description}),S.kind==="bg"&&S.data.promptPreview&&e.jsx("div",{className:"tl-detail-desc",children:S.data.promptPreview}),S.kind==="bg"&&e.jsxs("div",{className:"tl-detail-bg",children:[e.jsx("pre",{className:"tl-bg-output",children:J||"(no output — start the session via tmux attach)"}),e.jsxs("div",{className:"tl-bg-output-actions",children:[e.jsxs(T,{variant:"ghost",size:"sm",onClick:xa,children:[e.jsx(ce,{size:12})," Refresh output"]}),fe.length>0&&e.jsxs(T,{variant:"secondary",size:"sm",onClick:()=>xr(I,fe[0]),children:[e.jsx(Se,{size:12})," Open artifact"]}),e.jsxs(T,{variant:"danger",size:"sm",onClick:ua,children:[e.jsx(Ae,{size:12})," Kill session"]})]}),e.jsxs("div",{className:"tl-form-row",children:[e.jsx("label",{htmlFor:"bg-message-input",className:"sr-only",children:"Send a message to this bg session"}),e.jsx("input",{id:"bg-message-input",className:"input",placeholder:"Send a message to this bg session…",value:_,onChange:z=>ae(z.target.value),onKeyDown:z=>{z.key==="Enter"&&St()},"aria-label":"Send a message to this bg session"}),e.jsxs(T,{variant:"primary",size:"sm",disabled:!_.trim(),onClick:St,children:[e.jsx(Xe,{size:12})," Send"]})]})]}),S.kind!=="bg"&&e.jsxs("div",{className:"tl-detail-create",children:[e.jsx("label",{className:"field-label",htmlFor:"followup-task-title",children:"Create follow-up task"}),e.jsx("input",{id:"followup-task-title",className:"input",placeholder:"Task title",value:j,onChange:z=>M(z.target.value)}),e.jsxs("div",{className:"tl-form-row",children:[e.jsx("label",{htmlFor:"followup-task-priority",className:"sr-only",children:"Task priority"}),e.jsxs("select",{id:"followup-task-priority",className:"select",value:F,onChange:z=>C(z.target.value),"aria-label":"Task priority",children:[e.jsx("option",{value:"low",children:"Low"}),e.jsx("option",{value:"normal",children:"Normal"}),e.jsx("option",{value:"high",children:"High"})]}),e.jsxs(T,{variant:"primary",size:"sm",disabled:!j.trim()||G,onClick:ha,children:[e.jsx(Me,{size:12})," Add task"]})]})]}),e.jsxs("div",{className:"tl-detail-comments",children:[e.jsxs("div",{className:"field-label",children:[e.jsx(qs,{size:12})," Comments & activity"]}),e.jsxs("ul",{className:"comment-list",children:[N.length===0&&e.jsx("li",{className:"muted",children:"No comments yet."}),N.map((z,K)=>e.jsxs("li",{className:"comment-item",children:[e.jsxs("div",{className:"comment-head",children:[e.jsx("strong",{children:z.author||"system"}),e.jsxs("span",{className:"muted",children:[z.kind," · ",new Date(z.ts).toLocaleString()]})]}),z.text&&e.jsx("div",{className:"comment-text",children:z.text}),z.taskId&&e.jsxs("div",{className:"muted",children:["→ task ",e.jsx("code",{children:String(z.taskId)})]})]},`c-${K}`))]}),e.jsxs("div",{className:"comment-input-row",children:[e.jsx("label",{htmlFor:"comment-input",className:"sr-only",children:"Add a comment"}),e.jsx("input",{id:"comment-input",className:"input",placeholder:"Add a comment…",value:O,onChange:z=>k(z.target.value),onKeyDown:z=>{z.key==="Enter"&&!z.shiftKey&&wt()},"aria-label":"Add a comment"}),e.jsxs(T,{variant:"secondary",size:"sm",disabled:!O.trim()||Z,onClick:wt,children:[e.jsx(Xe,{size:12})," Post"]})]})]})]})},S.id)]})})]})}const Nr=[{id:"dark",label:"Dark",Icon:Ra},{id:"light",label:"Light",Icon:Ia},{id:"system",label:"System",Icon:La}],wr=[{name:"Purple",accent:"#8b5cf6"},{name:"Blue",accent:"#3b82f6"},{name:"Green",accent:"#10b981"},{name:"Orange",accent:"#f97316"},{name:"Red",accent:"#ef4444"},{name:"Pink",accent:"#ec4899"},{name:"Cyan",accent:"#06b6d4"},{name:"Mono",accent:"#6b7280"}],Sr=["Inter","system-ui","Segoe UI","Roboto","JetBrains Mono","SF Mono","Cascadia Code"];function Cr({settings:s,patchTheme:t,patchUi:a}){return e.jsxs(Q,{id:"settings-theme","data-section":"theme",children:[e.jsxs(se,{children:[e.jsx(mn,{size:14})," Theme"]}),e.jsx(ie,{children:"Mode, accent, and colors. Live preview as you tweak."}),e.jsxs("div",{className:"field","data-setting-id":"theme.presets",children:[e.jsx("label",{className:"field-label",children:"Accent presets"}),e.jsx("div",{className:"theme-presets",children:wr.map(i=>e.jsxs("button",{type:"button",className:X("theme-preset",s.theme.accent===i.accent&&"theme-preset-active"),onClick:()=>t({accent:i.accent}),title:i.name,children:[e.jsx("span",{className:"theme-preset-swatch",style:{background:i.accent}}),e.jsx("span",{className:"theme-preset-name",children:i.name})]},i.name))})]}),e.jsxs("div",{className:"field","data-setting-id":"theme.mode",children:[e.jsx("label",{className:"field-label",children:"Mode"}),e.jsx("div",{className:"theme-row",children:Nr.map(({id:i,label:n,Icon:l})=>{const c=s.theme.mode===i;return e.jsxs("button",{type:"button",className:X("theme-card",c&&"theme-card-active"),onClick:()=>t({mode:i}),children:[e.jsx(l,{size:16}),e.jsx("span",{className:"theme-card-label",children:n}),e.jsx("span",{className:X("theme-card-swatch",`theme-card-swatch-${i}`)})]},i)})})]}),e.jsx("div",{className:"theme-colors",children:["accent","success","warning","error","info"].map(i=>e.jsxs("div",{className:"field","data-setting-id":`theme.${i}`,children:[e.jsx("label",{className:"field-label",children:i.charAt(0).toUpperCase()+i.slice(1)}),e.jsxs("div",{className:"color-row",children:[e.jsx("input",{type:"color",className:"input color-input",value:s.theme[i],onChange:n=>t({[i]:n.target.value}),"aria-label":`${i} color`}),e.jsx("input",{type:"text",className:"input",value:s.theme[i],onChange:n=>t({[i]:n.target.value}),"aria-label":`${i} color hex`})]})]},i))}),e.jsxs("div",{className:"field","data-setting-id":"theme.fontFamily",children:[e.jsx("label",{className:"field-label",children:"Font family"}),e.jsx("select",{className:"select",value:s.theme.fontFamily,onChange:i=>t({fontFamily:i.target.value}),children:Sr.map(i=>e.jsx("option",{value:i,children:i},i))})]}),e.jsxs("div",{className:"field","data-setting-id":"theme.fontSize",children:[e.jsxs("label",{className:"field-label",children:["Font size: ",s.theme.fontSize,"px"]}),e.jsx("input",{type:"range",min:12,max:20,value:s.theme.fontSize,onChange:i=>t({fontSize:Number(i.target.value)})})]}),e.jsxs("label",{className:"checkbox-row","data-setting-id":"theme.compactMode",children:[e.jsx("input",{type:"checkbox",checked:s.theme.compactMode,onChange:i=>t({compactMode:i.target.checked})}),e.jsx("span",{children:"Compact mode (denser UI)"})]}),e.jsxs("label",{className:"checkbox-row","data-setting-id":"theme.animations",children:[e.jsx("input",{type:"checkbox",checked:s.theme.animations,onChange:i=>t({animations:i.target.checked})}),e.jsx("span",{children:"Enable animations"})]})]})}const Js=[{id:"bizar",name:"Bizar CLI"},{id:"bizar-dash",name:"Dashboard"},{id:"bizar-plugin",name:"Opencode Plugin"}];function zr(){const s=oe(),[t,a]=r.useState({current:{},latest:null,checking:!1,updating:!1,hasUpdates:!1,requiresRestart:!1,perPackage:{}});r.useEffect(()=>{const o=new pt;return o.on(p=>{(p.type==="update:progress"||p.type==="update:log"||p.type==="update:complete")&&a(x=>{if(p.type==="update:complete")return{...x,updating:!1,requiresRestart:!!p.requiresRestart};if(p.type==="update:log"){const d=p,m=x.perPackage[d.pkg]||{logs:[]};return{...x,perPackage:{...x.perPackage,[d.pkg]:{...m,logs:[...(m.logs||[]).slice(-50),d.line]}}}}const h=p;return{...x,perPackage:{...x.perPackage,[h.pkg]:{...x.perPackage[h.pkg],status:h.status,error:h.error,newVersion:h.newVersion}}}})}),()=>o.close()},[]),r.useEffect(()=>{w.get("/updates/status").then(o=>a(p=>({...p,current:o.current}))).catch(o=>a(p=>({...p,error:o.message})))},[]);const i=async()=>{a(o=>({...o,checking:!0,error:void 0}));try{const o=await w.get("/updates/check");a(p=>({...p,checking:!1,current:o.current,latest:o.latest,hasUpdates:o.hasUpdates}))}catch(o){a(p=>({...p,checking:!1,error:o.message}))}},n=async()=>{if(confirm("Update Bizar packages? The dashboard will restart automatically.")){a(o=>({...o,updating:!0,requiresRestart:!1,perPackage:{},error:void 0}));try{await w.post("/updates/apply",{packages:["bizar","bizar-dash","bizar-plugin"]})}catch(o){a(p=>({...p,updating:!1,error:o.message}))}}},l=async()=>{if(confirm("Restart the dashboard? You will be disconnected briefly."))try{await w.post("/restart"),s.info("Restarting…",3e3),setTimeout(()=>window.location.reload(),3e3)}catch{s.error("Restart failed")}},c=t.checking||t.updating;return e.jsxs(Q,{id:"settings-updates","data-section":"updates",children:[e.jsxs(se,{children:[e.jsx(Qe,{size:14})," Updates"]}),e.jsx(ie,{children:"Check installed Bizar packages and apply dashboard updates."}),e.jsxs("div",{className:"updates-current",children:[e.jsx("h4",{children:"Installed versions"}),e.jsx("ul",{children:Js.map(o=>e.jsxs("li",{children:[e.jsx("span",{children:o.name}),e.jsx("code",{className:"mono",children:t.current[o.id]||"—"})]},o.id))})]}),t.latest&&e.jsxs("div",{className:"updates-latest",children:[e.jsx("h4",{children:"Latest available"}),e.jsx("ul",{children:Js.map(o=>{var d;const p=t.current[o.id],x=(d=t.latest)==null?void 0:d[o.id],h=p&&x&&p!==x;return e.jsxs("li",{className:h?"updates-outdated":"updates-current-version",children:[e.jsx("span",{children:o.name}),e.jsxs("code",{className:"mono",children:[x||"—",h&&e.jsx("span",{className:"updates-badge",children:"update available"})]})]},o.id)})})]}),t.updating&&e.jsx("div",{className:"updates-progress-rows",children:Js.map(o=>{const p=t.perPackage[o.id]||{status:"idle",logs:[]};return e.jsxs("div",{className:"updates-pkg-row",children:[e.jsxs("div",{className:"updates-pkg-row-header",children:[e.jsx("span",{className:"updates-pkg-name",children:o.name}),e.jsxs("div",{className:"updates-pkg-status",children:[p.status==="starting"&&e.jsx("span",{className:"btn-spinner"}),p.status==="installing"&&e.jsx("span",{className:"btn-spinner"}),p.status==="done"&&e.jsx(Is,{size:14,className:"icon-success"}),p.status==="error"&&e.jsx(dt,{size:14,className:"icon-error"}),e.jsx("span",{children:p.status}),p.newVersion&&e.jsxs("code",{className:"mono",style:{fontSize:11},children:["→ ",p.newVersion]})]})]}),p.logs.length>0&&e.jsxs("details",{className:"updates-pkg-logs",children:[e.jsxs("summary",{children:["npm output (",p.logs.length," lines)"]}),e.jsx("pre",{children:p.logs.join(`
351
+ `)})]}),p.status==="error"&&p.error&&e.jsxs("div",{className:"updates-pkg-error",children:[e.jsx(ke,{size:12})," ",p.error]})]},o.id)})}),e.jsxs("div",{className:"updates-actions",children:[e.jsxs(T,{onClick:i,disabled:c,children:[t.checking?e.jsx("span",{className:"btn-spinner"}):e.jsx(ce,{size:14}),"Check for updates"]}),e.jsxs(T,{variant:"primary",onClick:n,disabled:!t.hasUpdates||t.updating,children:[t.updating?e.jsx("span",{className:"btn-spinner"}):e.jsx(Qe,{size:14}),t.updating?"Updating…":t.hasUpdates?"Update now":"Up to date"]}),t.requiresRestart&&e.jsxs(T,{variant:"danger",onClick:l,children:[e.jsx(ce,{size:14})," Restart Dashboard"]})]}),t.error&&e.jsxs("div",{className:"updates-error",children:[e.jsx(ke,{size:14}),e.jsx("span",{children:t.error})]})]})}const Tr=[{id:"topnav",label:"Top nav"},{id:"sidebar",label:"Sidebar"},{id:"both",label:"Both"}];function Mr({settings:s,patchUi:t,patchTop:a}){return e.jsxs(e.Fragment,{children:[e.jsxs(Q,{id:"settings-layout","data-section":"layout",children:[e.jsxs(se,{children:[e.jsx(xn,{size:14})," UI layout"]}),e.jsx(ie,{children:"Choose how the dashboard's navigation is presented."}),e.jsx("div",{className:"layout-row","data-setting-id":"ui.layout",children:Tr.map(i=>e.jsx("button",{type:"button",className:X("layout-card",s.ui.layout===i.id&&"layout-card-active"),onClick:()=>t({layout:i.id}),children:e.jsx("span",{className:"layout-card-label",children:i.label})},i.id))}),e.jsxs("label",{className:"checkbox-row","data-setting-id":"ui.showHeader",children:[e.jsx("input",{type:"checkbox",checked:s.ui.showHeader,onChange:i=>t({showHeader:i.target.checked})}),e.jsx("span",{children:"Show header"})]}),e.jsxs("label",{className:"checkbox-row","data-setting-id":"ui.showStatusBar",children:[e.jsx("input",{type:"checkbox",checked:s.ui.showStatusBar,onChange:i=>t({showStatusBar:i.target.checked})}),e.jsx("span",{children:"Show status bar"})]}),e.jsxs("div",{className:"field","data-setting-id":"ui.defaultTab",children:[e.jsx("label",{className:"field-label",children:"Default tab"}),e.jsxs("select",{className:"select",value:s.ui.defaultTab,onChange:i=>t({defaultTab:i.target.value}),children:[e.jsx("option",{value:"overview",children:"Overview"}),e.jsx("option",{value:"chat",children:"Chat"}),e.jsx("option",{value:"agents",children:"Agents"}),e.jsx("option",{value:"artifacts",children:"Plans"}),e.jsx("option",{value:"projects",children:"Projects"}),e.jsx("option",{value:"tasks",children:"Tasks"}),e.jsx("option",{value:"config",children:"Config"}),e.jsx("option",{value:"settings",children:"Settings"}),e.jsx("option",{value:"mods",children:"Mods"}),e.jsx("option",{value:"schedules",children:"Schedules"})]})]})]}),e.jsxs(Q,{id:"settings-general","data-section":"general",children:[e.jsx(se,{children:"General"}),e.jsx(ie,{children:"Default agent + model override."}),e.jsxs("div",{className:"field","data-setting-id":"defaultAgent",children:[e.jsx("label",{className:"field-label",htmlFor:"set-default-agent",children:"Default agent"}),e.jsx("input",{id:"set-default-agent",className:"input",type:"text",placeholder:"e.g. odin",value:s.defaultAgent||"",onChange:i=>a("defaultAgent",i.target.value)})]}),e.jsxs("div",{className:"field","data-setting-id":"defaultModel",children:[e.jsx("label",{className:"field-label",htmlFor:"set-default-model",children:"Model override"}),e.jsx("input",{id:"set-default-model",className:"input",type:"text",placeholder:"(leave empty for provider default)",value:s.defaultModel||"",onChange:i=>a("defaultModel",i.target.value)})]})]})]})}function $r({tailscale:s,tailscaleDraft:t,setTailscaleDraft:a,onTailscaleToggle:i}){return e.jsxs(e.Fragment,{children:[e.jsxs(Q,{id:"settings-service","data-section":"service",children:[e.jsxs(se,{children:[e.jsx(js,{size:14})," Service"]}),e.jsx(ie,{children:"Background daemon that runs schedules."}),e.jsx("div",{"data-setting-id":"service.enabled",children:s?e.jsxs("div",{className:"service-card",children:[e.jsxs("p",{children:["Status: ",e.jsx("strong",{children:s.settings.enabled?"enabled":"disabled"})," ","· Tailscale installed: ",e.jsx("strong",{children:s.installed?"yes":"no"})," ","· authenticated: ",e.jsx("strong",{children:s.authenticated?"yes":"no"})]}),e.jsxs("p",{className:"muted",children:["Use ",e.jsx("code",{children:"bizar service start"})," / ",e.jsx("code",{children:"bizar service stop"})," in your terminal to control the daemon."]})]}):e.jsx("p",{className:"muted",children:"Loading service status…"})})]}),e.jsxs(Q,{id:"settings-tailscale","data-section":"tailscale",children:[e.jsxs(se,{children:[e.jsx(rt,{size:14})," Tailscale serve"]}),e.jsx(ie,{children:"Expose the dashboard over your Tailscale network."}),s?e.jsxs(e.Fragment,{children:[e.jsxs("p",{children:["Installed: ",e.jsx("strong",{children:s.installed?"yes":"no"})," ",s.version&&e.jsxs("span",{className:"muted",children:["(",s.version,")"]})]}),e.jsxs("p",{children:["Authenticated: ",e.jsx("strong",{children:s.authenticated?"yes":"no"})]}),e.jsxs("p",{children:["Serve enabled: ",e.jsx("strong",{children:s.settings.enabled?"yes":"no"})]}),e.jsxs("div",{className:"task-form-row",children:[e.jsxs("div",{className:"task-form-field",children:[e.jsx("label",{className:"field-label",children:"Port"}),e.jsx("input",{type:"number",className:"input",value:t.port,onChange:n=>a(l=>({...l,port:Number(n.target.value)||4321}))})]}),e.jsxs("div",{className:"task-form-field",children:[e.jsx("label",{className:"field-label",htmlFor:"tailscale-https",children:"Use HTTPS"}),e.jsx("input",{id:"tailscale-https",type:"checkbox",checked:t.https,onChange:n=>a(l=>({...l,https:n.target.checked}))})]})]}),e.jsx(T,{variant:"primary",onClick:i,children:s.settings.enabled?"Disable serve":"Enable serve"})]}):e.jsx("p",{className:"muted",children:"Loading Tailscale status…"})]})]})}function Ar({settings:s,patchNotifications:t}){return e.jsxs(Q,{id:"settings-notifications","data-section":"notifications",children:[e.jsx(se,{children:"Notifications"}),e.jsx(ie,{children:"Toast triggers inside the dashboard."}),e.jsxs("label",{className:"checkbox-row","data-setting-id":"notifications.onAgentComplete",children:[e.jsx("input",{type:"checkbox",checked:!!s.notifications.onAgentComplete,onChange:a=>t({onAgentComplete:a.target.checked})}),e.jsx("span",{children:"Notify when an agent invocation completes"})]}),e.jsxs("label",{className:"checkbox-row","data-setting-id":"notifications.onPlanApproval",children:[e.jsx("input",{type:"checkbox",checked:!!s.notifications.onPlanApproval,onChange:a=>t({onPlanApproval:a.target.checked})}),e.jsx("span",{children:"Notify when a plan needs approval"})]})]})}function Rr({authStatus:s,setAuthStatus:t}){const a=oe(),[i,n]=r.useState(w.getToken()),[l,c]=r.useState("");r.useEffect(()=>{let h=!1;return(async()=>{try{const d=await w.probeAuthStatus();h||t(d)}catch{h||t({required:!0,loopback:!1,peer:""})}})(),()=>{h=!0}},[]);const o=async()=>{try{const h=await w.get("/auth/reveal");c(h.token),n(h.token),w.setToken(h.token);try{await navigator.clipboard.writeText(h.token),a.success("Token copied to clipboard.")}catch{a.success("Token revealed — copy from the field below.")}}catch(h){a.error(`Reveal failed: ${h.message}`)}},p=async()=>{if(confirm("Regenerate the auth token? Anything still using the old token will start getting 401 errors immediately."))try{const h=await w.post("/auth/regenerate");c(h.token),n(h.token),w.setToken(h.token);try{await navigator.clipboard.writeText(h.token),a.success("New token generated and copied to clipboard.")}catch{a.success("New token generated — copy from the field below. Old token is now invalid.")}}catch(h){a.error(`Regenerate failed: ${h.message}`)}},x=()=>{w.setToken(i.trim()),a.success("Token saved. The dashboard will use it on the next request.")};return e.jsxs(Q,{id:"settings-auth","data-section":"auth",children:[e.jsxs(se,{children:[e.jsx(yn,{size:14})," Authentication"]}),e.jsx(ie,{children:"Localhost and Tailscale browser access are auto-trusted via loopback. A bearer token is still available for non-loopback clients and forced-auth mode."}),e.jsxs("div",{className:"field","data-setting-id":"auth.status",children:[e.jsx("label",{className:"field-label",children:"Server status"}),e.jsxs("p",{style:{margin:"4px 0"},children:["Auth required:"," ",e.jsx("strong",{children:s?s.required?"yes":"no":"probing…"})]}),e.jsxs("p",{style:{margin:"4px 0"},children:["Connection:"," ",e.jsx("strong",{children:s?s.loopback?"loopback (auto-trusted)":"remote":"probing…"})]}),e.jsxs("p",{style:{margin:"4px 0"},children:["Peer address:"," ",s!=null&&s.peer?e.jsx("code",{children:s.peer}):e.jsx("span",{className:"muted",children:"probing…"})]}),e.jsxs("p",{className:"muted",style:{fontSize:12,margin:"4px 0"},children:["Localhost and Tailscale browser access are auto-trusted because the dashboard sees a loopback peer. Paste a token only for non-loopback API clients/scripts, or if you force auth for every connection with"," ",e.jsx("code",{children:"BIZAR_DASHBOARD_REQUIRE_AUTH=1"}),"."]}),e.jsxs("p",{className:"muted",style:{fontSize:12,margin:"4px 0"},children:["Dashboard tokens are generated on first boot and saved to"," ",e.jsx("code",{children:"~/.config/bizar/dashboard-secret"})," (mode 0600)."]}),e.jsx("p",{className:"muted",style:{fontSize:12,margin:"4px 0"},children:"For Tailscale Serve or any reverse-proxy access, paste this token once via the boot screen — it is saved per-origin and works for all subsequent visits."})]}),e.jsxs("div",{className:"field","data-setting-id":"auth.token",children:[e.jsx("label",{className:"field-label",children:"Token (this browser)"}),e.jsx("input",{type:"password",className:"input mono",value:i,onChange:h=>n(h.target.value),placeholder:"Paste token from server stderr or another browser",spellCheck:!1,autoComplete:"off"}),e.jsxs("div",{className:"task-form-row",style:{marginTop:8},children:[e.jsxs(T,{variant:"secondary",size:"sm",onClick:x,children:[e.jsx(ft,{size:14})," Save token"]}),e.jsxs(T,{variant:"ghost",size:"sm",onClick:o,children:[e.jsx(_s,{size:14})," Reveal & copy server token"]}),e.jsxs(T,{variant:"ghost",size:"sm",onClick:p,children:[e.jsx(Wt,{size:14})," Regenerate"]})]}),l?e.jsxs("p",{className:"muted",style:{fontSize:12,marginTop:8},children:["Last revealed token (one-time): ",e.jsx("code",{className:"mono",children:l})]}):null,e.jsx("p",{className:"muted",style:{fontSize:12,marginTop:8},children:"Regenerating invalidates the current token immediately. Anything still using the old token will see 401 until it's updated."})]})]})}function Ir({settings:s,patchAgents:t,patchDashboard:a}){var p,x,h;const i=oe(),[n,l]=r.useState({});r.useEffect(()=>{w.get("/settings/plugin-options").then(l).catch(()=>{})},[]);const c=async()=>{try{await w.put("/settings/plugin-options",n),i.success("Saved — restart opencode for changes to take effect.")}catch(d){i.error(`Save failed: ${d.message}`)}},o=async()=>{try{const m=await(await fetch("/api/background/cleanup",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({maxAgeDays:7})})).json();i.success(`Cleaned up ${m.deleted} old instances.`)}catch(d){i.error(`Cleanup failed: ${d.message}`)}};return e.jsxs(e.Fragment,{children:[e.jsxs(Q,{id:"settings-agents","data-section":"agents",children:[e.jsxs(se,{children:[e.jsx(js,{size:14})," Agent Behavior"]}),e.jsx(ie,{children:"Limits and timeouts for background agent dispatch."}),e.jsxs("div",{className:"form-row",children:[e.jsxs("label",{htmlFor:"agents-maxParallel",children:["Max parallel agents",e.jsx("span",{className:"meta-badge",children:"default: 6"})]}),e.jsx("input",{id:"agents-maxParallel",type:"number",min:1,max:20,value:((p=s.agents)==null?void 0:p.maxParallel)??6,onChange:d=>t({maxParallel:Math.max(1,Math.min(20,parseInt(d.target.value,10)||6))})})]}),e.jsxs("div",{className:"form-row",children:[e.jsxs("label",{htmlFor:"agents-stuckThresholdMs",children:["Stuck threshold (ms)",e.jsx("span",{className:"meta-badge",children:"default: 600000 (10 min)"})]}),e.jsx("input",{id:"agents-stuckThresholdMs",type:"number",min:6e4,max:36e5,step:6e4,value:((x=s.agents)==null?void 0:x.stuckThresholdMs)??6e5,onChange:d=>t({stuckThresholdMs:Math.max(6e4,Math.min(36e5,parseInt(d.target.value,10)||6e5))})})]}),e.jsxs("label",{className:"checkbox-row","data-setting-id":"agents.autoRestart",children:[e.jsx("input",{type:"checkbox",checked:!!((h=s.agents)!=null&&h.autoRestart),onChange:d=>t({autoRestart:d.target.checked})}),e.jsx("span",{children:"Auto-restart stuck agents"})]})]}),e.jsxs(Q,{id:"settings-dashboard","data-section":"dashboard",children:[e.jsxs(se,{children:[e.jsx(ys,{size:14})," Dashboard"]}),e.jsxs(ie,{children:["Controls how ",e.jsx("code",{children:"bizar"})," starts up."]}),e.jsxs("label",{className:"checkbox-row","data-setting-id":"dashboard.autoLaunchWeb",children:[e.jsx("input",{type:"checkbox",checked:s.dashboard.autoLaunchWeb!==!1,onChange:d=>a({autoLaunchWeb:d.target.checked})}),e.jsx("span",{children:"Auto-launch web UI alongside TUI"})]}),e.jsxs("div",{className:"field","data-setting-id":"dashboard.projectsDirectory",style:{marginTop:"var(--space-4)"},children:[e.jsx("label",{className:"field-label",htmlFor:"set-projects-directory",children:"Projects directory"}),e.jsx("input",{id:"set-projects-directory",className:"input",type:"text",placeholder:"/home/user/projects",value:s.dashboard.projectsDirectory??"",onChange:d=>a({projectsDirectory:d.target.value})}),e.jsx("p",{className:"field-help",children:"New projects created via the dashboard will land here, and existing project directories inside this folder are auto-recognized on startup."}),s.dashboard.projectsDirectory&&e.jsxs(e.Fragment,{children:[!/^\/|^[A-Za-z]:/.test(s.dashboard.projectsDirectory)&&e.jsx("p",{style:{color:"var(--warning)",fontSize:11,marginTop:4},children:"Path should be absolute (start with / on Linux/Mac, or a drive letter on Windows)."}),s.dashboard.projectsDirectory.includes("..")&&e.jsx("p",{style:{color:"var(--error)",fontSize:11,marginTop:4},children:"Path traversal not allowed — this will be rejected server-side."})]})]}),e.jsxs("div",{className:"field","data-setting-id":"dashboard.allowedRoots",style:{marginTop:"var(--space-4)"},children:[e.jsxs("label",{className:"field-label",htmlFor:"set-allowed-roots",children:["Additional allowed roots ",e.jsx("span",{className:"muted",children:"(advanced)"})]}),e.jsx("textarea",{id:"set-allowed-roots",className:"textarea",rows:4,placeholder:`/workspace
352
+ /srv/projects`,value:(s.dashboard.allowedRoots??[]).join(`
353
+ `),onChange:d=>{const m=d.target.value.split(`
354
+ `).map(u=>u.trim()).filter(Boolean);a({allowedRoots:m})}}),e.jsx("p",{className:"field-help",children:"Optional. Add filesystem roots beyond your home directory that the file browser and project scanner can access. Each path must be inside your home directory. One per line."}),(()=>{const d=(s.dashboard.allowedRoots??[]).join(`
355
+ `).split(`
356
+ `),m=[];return d.forEach((u,g)=>{u.trim()&&(/^\/|^[A-Za-z]:/.test(u)||m.push({key:`noabs-${g}`,msg:e.jsxs("p",{style:{color:"var(--warning)",fontSize:11,marginTop:2},children:["Line ",g+1,': "',u,'" — should be absolute (start with / or a drive letter).']})}),u.includes("..")&&m.push({key:`dots-${g}`,msg:e.jsxs("p",{style:{color:"var(--error)",fontSize:11,marginTop:2},children:["Line ",g+1,': "',u,`" — contains '..' (server will reject this).`]})}))}),m.map(u=>u.msg)})()]})]}),e.jsxs(Q,{id:"settings-background","data-section":"background",children:[e.jsxs(se,{children:[e.jsx(js,{size:14})," Background Agents"]}),e.jsx(ie,{children:"Tune plugin options. Changes take effect on next plugin restart."}),e.jsxs("div",{className:"form-row",children:[e.jsxs("label",{htmlFor:"bg-maxConcurrent",children:["Max concurrent instances",e.jsx("span",{className:"meta-badge",children:"default: 8"})]}),e.jsx("input",{id:"bg-maxConcurrent",type:"number",min:1,max:32,value:n.maxConcurrentInstances??8,onChange:d=>l(m=>({...m,maxConcurrentInstances:Math.max(1,Math.min(32,parseInt(d.target.value,10)||8))}))}),e.jsxs("small",{className:"muted",children:["Plugin option: ",e.jsx("code",{children:"maxConcurrentInstances"})]})]}),e.jsxs("div",{className:"form-row",children:[e.jsxs("label",{htmlFor:"bg-toolCallCap",children:["Tool-call cap",e.jsx("span",{className:"meta-badge",children:"default: 500"})]}),e.jsx("input",{id:"bg-toolCallCap",type:"number",min:1,max:5e3,value:n.backgroundToolCallCap??500,onChange:d=>l(m=>({...m,backgroundToolCallCap:Math.max(1,Math.min(5e3,parseInt(d.target.value,10)||500))}))}),e.jsxs("small",{className:"muted",children:["Plugin option: ",e.jsx("code",{children:"backgroundToolCallCap"})]})]}),e.jsxs("div",{className:"form-row",children:[e.jsxs("label",{htmlFor:"bg-stallTimeout",children:["Stall timeout (ms)",e.jsx("span",{className:"meta-badge",children:"default: 180000"})]}),e.jsx("input",{id:"bg-stallTimeout",type:"number",min:1e4,max:6e5,step:1e3,value:n.backgroundStallTimeoutMs??18e4,onChange:d=>l(m=>({...m,backgroundStallTimeoutMs:Math.max(1e4,Math.min(6e5,parseInt(d.target.value,10)||18e4))}))}),e.jsxs("small",{className:"muted",children:["Plugin option: ",e.jsx("code",{children:"backgroundStallTimeoutMs"})]})]}),e.jsxs("div",{className:"form-row",children:[e.jsxs("label",{htmlFor:"bg-thinkingLoopTimeout",children:["Thinking-loop timeout (ms)",e.jsx("span",{className:"meta-badge",children:"default: 300000"})]}),e.jsx("input",{id:"bg-thinkingLoopTimeout",type:"number",min:3e4,max:9e5,step:1e3,value:n.backgroundThinkingLoopTimeoutMs??3e5,onChange:d=>l(m=>({...m,backgroundThinkingLoopTimeoutMs:Math.max(3e4,Math.min(9e5,parseInt(d.target.value,10)||3e5))}))}),e.jsxs("small",{className:"muted",children:["Plugin option: ",e.jsx("code",{children:"backgroundThinkingLoopTimeoutMs"})]})]}),e.jsxs("div",{className:"form-row",children:[e.jsxs("label",{htmlFor:"bg-maxInterventions",children:["Max interventions",e.jsx("span",{className:"meta-badge",children:"default: 1"})]}),e.jsx("input",{id:"bg-maxInterventions",type:"number",min:1,max:3,value:n.backgroundMaxInterventions??1,onChange:d=>l(m=>({...m,backgroundMaxInterventions:Math.max(1,Math.min(3,parseInt(d.target.value,10)||1))}))}),e.jsxs("small",{className:"muted",children:["Plugin option: ",e.jsx("code",{children:"backgroundMaxInterventions"})]})]}),e.jsxs("div",{className:"form-row",children:[e.jsxs(T,{variant:"secondary",size:"sm",onClick:c,children:[e.jsx(vs,{size:14})," Save plugin options"]}),e.jsx(T,{variant:"secondary",size:"sm",onClick:o,children:"Cleanup old instances (>7 days)"})]}),e.jsx("div",{className:"form-row",children:e.jsxs("small",{children:["Plugin options are read at startup. Save changes and run ",e.jsx("code",{children:"bizar update"})," to apply."]})})]})]})}function Lr({settings:s,patchTop:t}){var a,i,n;return e.jsxs(Q,{id:"settings-system-llm","data-section":"system-llm",children:[e.jsxs(se,{children:[e.jsx(Oe,{size:14})," System LLM API"]}),e.jsx(ie,{children:"Configures the LLM used for automatic title generation, prompt enhancement, summarization, and other system-level calls."}),e.jsxs("label",{className:"checkbox-row","data-setting-id":"systemLlm.enabled",children:[e.jsx("input",{type:"checkbox",checked:!!((a=s.systemLlm)!=null&&a.enabled),onChange:l=>{const c=s.systemLlm||{enabled:!0,provider:"opencode",model:"opencode/deepseek-v4-flash-free"};t("systemLlm",{...c,enabled:l.target.checked})}}),e.jsx("span",{children:"Enable system LLM calls"})]}),e.jsxs("div",{className:"field","data-setting-id":"systemLlm.provider",style:{marginTop:"var(--space-3)"},children:[e.jsx("label",{className:"field-label",htmlFor:"set-system-llm-provider",children:"Provider"}),e.jsxs("select",{id:"set-system-llm-provider",className:"select",value:((i=s.systemLlm)==null?void 0:i.provider)||"opencode",onChange:l=>{const c=s.systemLlm||{enabled:!0,provider:"opencode",model:"opencode/deepseek-v4-flash-free"};t("systemLlm",{...c,provider:l.target.value})},children:[e.jsx("option",{value:"opencode",children:"Opencode"}),e.jsx("option",{value:"openrouter",children:"OpenRouter"}),e.jsx("option",{value:"minimax",children:"MiniMax"})]})]}),e.jsxs("div",{className:"field","data-setting-id":"systemLlm.model",children:[e.jsx("label",{className:"field-label",htmlFor:"set-system-llm-model",children:"Model"}),e.jsx("input",{id:"set-system-llm-model",className:"input mono",type:"text",placeholder:"opencode/deepseek-v4-flash-free",value:((n=s.systemLlm)==null?void 0:n.model)||"opencode/deepseek-v4-flash-free",onChange:l=>{const c=s.systemLlm||{enabled:!0,provider:"opencode",model:"opencode/deepseek-v4-flash-free"};t("systemLlm",{...c,model:l.target.value})}}),e.jsxs("p",{className:"field-help",children:["The API key is read from ",e.jsx("code",{children:"auth.json"})," for the selected provider. Leave the default model for best results."]})]}),e.jsxs("div",{style:{marginTop:"var(--space-4)"},children:[e.jsx("h4",{style:{margin:"0 0 var(--space-2)"},children:"Features using this API"}),e.jsxs("ul",{className:"settings-feature-list",style:{margin:0,paddingLeft:"var(--space-4)",lineHeight:1.8},children:[e.jsx("li",{children:"Auto-title generation for new chat sessions"}),e.jsx("li",{children:"Auto-title generation for new tasks"}),e.jsx("li",{children:'"Enhance prompt" button in the task input'}),e.jsx("li",{children:'"Enhance prompt" button in the chat composer'}),e.jsx("li",{className:"muted",style:{fontSize:12},children:"Future: summarization, name generation, and more"})]})]})]})}const Er=[{value:"anthropic",label:"Anthropic"},{value:"anyllm",label:"AnyLLM"},{value:"litellm-anthropic",label:"LiteLLM (Anthropic)"},{value:"litellm-openai",label:"LiteLLM (OpenAI)"}];function Pr({settings:s,onPatch:t}){const a=oe(),[i,n]=r.useState(null),[l,c]=r.useState(null),[o,p]=r.useState(!1),[x,h]=r.useState(!1),[d,m]=r.useState(!1),[u,g]=r.useState(!1),[f,b]=r.useState(!1),[A,y]=r.useState(!1),v=r.useCallback(async()=>{p(!0);try{const[C,_]=await Promise.all([w.get("/headroom/status"),w.get("/headroom/stats?hours=24").catch(()=>({error:"no stats"}))]);n(C),_.error||c(_)}catch(C){a.error(`Failed to load Headroom status: ${C.message}`)}finally{p(!1)}},[a]);r.useEffect(()=>{v()},[v]);const L=async()=>{h(!0);try{const C=await w.post("/headroom/install",{force:!0});C.installed?(a.success(`Headroom installed via ${C.method}.`),await v()):a.error('Headroom install failed. Try: pip install "headroom-ai[all]"')}catch(C){a.error(`Install failed: ${C.message}`)}finally{h(!1)}},$=async()=>{m(!0);try{(await w.post("/headroom/wrap",{port:s.port})).ok?(a.success("opencode wrapped with Headroom."),await v()):a.error("Wrap failed.")}catch(C){a.error(`Wrap failed: ${C.message}`)}finally{m(!1)}},R=async()=>{g(!0);try{(await w.post("/headroom/unwrap")).ok?(a.success("opencode unwrapped from Headroom."),await v()):a.error("Unwrap failed.")}catch(C){a.error(`Unwrap failed: ${C.message}`)}finally{g(!1)}},P=async()=>{b(!0);try{(await w.post("/headroom/proxy/start",{port:s.port,host:s.host})).ok?(a.success(`Headroom proxy started on ${s.host}:${s.port}.`),await v()):a.error("Proxy start failed.")}catch(C){a.error(`Proxy start failed: ${C.message}`)}finally{b(!1)}},S=async()=>{y(!0);try{(await w.post("/headroom/proxy/stop")).ok?(a.success("Headroom proxy stopped."),await v()):a.error("Proxy stop failed.")}catch(C){a.error(`Proxy stop failed: ${C.message}`)}finally{y(!1)}},q=async()=>{try{const{spawn:C}=await Vt(async()=>{const{spawn:_}=await import("./__vite-browser-external-BIHI7g3E.js");return{spawn:_}},[]);C("headroom",["dashboard"],{detached:!0,stdio:"ignore"})}catch{a.error("Could not open Headroom dashboard. Run `headroom dashboard` manually.")}},{installed:O,version:k,proxyRunning:N,proxyPort:D,wrapped:j}=i||{},M=(l==null?void 0:l.compressionRatio)??0,F=(l==null?void 0:l.tokensSaved)??0;return e.jsx("div",{id:"settings-headroom","data-section":"headroom",children:e.jsxs(Q,{children:[e.jsxs(se,{children:[e.jsx(Te,{size:14,style:{color:N?"var(--success)":"var(--text-dim)"}}),"Headroom",O&&k&&e.jsxs("span",{style:{fontSize:11,color:"var(--text-dim)",marginLeft:6},children:["v",k," ",N?"✓":"✗"]}),!O&&e.jsx("span",{style:{fontSize:11,color:"var(--error)",marginLeft:6},children:"not installed"})]}),e.jsx(ie,{children:"Context compression for token efficiency. Compresses tool outputs, logs, and conversation history by 60–95% before they reach the model."}),e.jsxs("div",{style:{display:"flex",gap:16,flexWrap:"wrap",marginTop:12,marginBottom:12},children:[e.jsxs("div",{className:"headroom-status-item",children:[O?e.jsx(Is,{size:12,style:{color:"var(--success)"}}):e.jsx(Ye,{size:12,style:{color:"var(--error)"}}),e.jsx("span",{children:O?"Installed":"Not installed"})]}),e.jsxs("div",{className:"headroom-status-item",children:[N?e.jsx(Is,{size:12,style:{color:"var(--success)"}}):e.jsx(Ye,{size:12,style:{color:"var(--text-dim)"}}),e.jsxs("span",{children:["Proxy ",N?`${D} ✓`:"stopped"]})]}),e.jsxs("div",{className:"headroom-status-item",children:[j?e.jsx(Is,{size:12,style:{color:"var(--success)"}}):e.jsx(Ye,{size:12,style:{color:"var(--text-dim)"}}),e.jsxs("span",{children:["opencode ",j?"wrapped":"not wrapped"]})]})]}),(F>0||M>0)&&e.jsxs("div",{style:{display:"flex",gap:24,marginBottom:12},children:[e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:20,fontWeight:700,color:"var(--success)"},children:M>0?`${Math.round(M*100)}%`:"—"}),e.jsx("div",{className:"muted",style:{fontSize:11},children:"Compression ratio"})]}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:20,fontWeight:700,color:"var(--accent)"},children:F>0?F.toLocaleString():"—"}),e.jsx("div",{className:"muted",style:{fontSize:11},children:"Tokens saved (24h)"})]})]}),e.jsxs("div",{style:{display:"flex",gap:8,flexWrap:"wrap",marginBottom:8},children:[O?e.jsxs(e.Fragment,{children:[e.jsxs(T,{variant:"secondary",size:"sm",onClick:$,disabled:d||j,title:j?"opencode is already wrapped":"Wrap opencode to route through Headroom proxy",children:[d?e.jsx("span",{className:"btn-spinner"}):e.jsx(yt,{size:13}),d?"Wrapping…":j?"Wrapped ✓":"Wrap opencode"]}),j&&e.jsxs(T,{variant:"ghost",size:"sm",onClick:R,disabled:u,children:[u?e.jsx("span",{className:"btn-spinner"}):e.jsx(ce,{size:13}),u?"Unwrapping…":"Unwrap"]})]}):e.jsxs(T,{variant:"primary",size:"sm",onClick:L,disabled:x,children:[x?e.jsx("span",{className:"btn-spinner"}):e.jsx(Qe,{size:13}),x?"Installing…":"Install Headroom"]}),O&&e.jsxs(e.Fragment,{children:[N?e.jsxs(T,{variant:"secondary",size:"sm",onClick:S,disabled:A,children:[A?e.jsx("span",{className:"btn-spinner"}):e.jsx(kn,{size:13}),A?"Stopping…":"Stop proxy"]}):e.jsxs(T,{variant:"secondary",size:"sm",onClick:P,disabled:f,children:[f?e.jsx("span",{className:"btn-spinner"}):e.jsx(Ns,{size:13}),f?"Starting…":"Start proxy"]}),e.jsxs(T,{variant:"ghost",size:"sm",onClick:q,children:[e.jsx(ls,{size:13}),"Dashboard"]})]}),e.jsx(T,{variant:"ghost",size:"sm",onClick:v,disabled:o,children:e.jsx(ce,{size:13,className:o?"spin":""})})]}),e.jsxs("div",{style:{marginTop:16},children:[e.jsxs("label",{className:"checkbox-row",children:[e.jsx("input",{type:"checkbox",checked:s.enabled,onChange:C=>t({enabled:C.target.checked})}),e.jsx("span",{children:"Enable Headroom"})]}),e.jsxs("label",{className:"checkbox-row",children:[e.jsx("input",{type:"checkbox",checked:s.autoInstall,onChange:C=>t({autoInstall:C.target.checked})}),e.jsx("span",{children:"Auto-install if missing on dashboard startup"})]}),e.jsxs("label",{className:"checkbox-row",children:[e.jsx("input",{type:"checkbox",checked:s.autoStart,onChange:C=>t({autoStart:C.target.checked})}),e.jsx("span",{children:"Auto-start proxy on dashboard startup"})]}),e.jsxs("label",{className:"checkbox-row",children:[e.jsx("input",{type:"checkbox",checked:s.autoWrap,onChange:C=>t({autoWrap:C.target.checked})}),e.jsx("span",{children:"Auto-wrap opencode on dashboard startup"})]}),e.jsxs("label",{className:"checkbox-row",children:[e.jsx("input",{type:"checkbox",checked:s.routeAllProviders,onChange:C=>t({routeAllProviders:C.target.checked})}),e.jsx("span",{children:"Route all providers through Headroom proxy"})]}),e.jsxs("div",{className:"task-form-row",style:{marginTop:12},children:[e.jsxs("div",{className:"task-form-field",children:[e.jsx("label",{className:"field-label",children:"Proxy port"}),e.jsx("input",{type:"number",className:"input",value:s.port,min:1,max:65535,onChange:C=>t({port:Math.max(1,Math.min(65535,parseInt(C.target.value,10)||8787))})})]}),e.jsxs("div",{className:"task-form-field",children:[e.jsx("label",{className:"field-label",children:"Proxy host"}),e.jsx("input",{type:"text",className:"input",value:s.host,onChange:C=>t({host:C.target.value})})]})]}),e.jsxs("div",{className:"task-form-row",children:[e.jsxs("div",{className:"task-form-field",children:[e.jsx("label",{className:"field-label",children:"Backend"}),e.jsx("select",{className:"select",value:s.backend,onChange:C=>t({backend:C.target.value}),children:Er.map(C=>e.jsx("option",{value:C.value,children:C.label},C.value))})]}),e.jsxs("div",{className:"task-form-field",children:[e.jsx("label",{className:"field-label",children:"Monthly budget (USD)"}),e.jsx("input",{type:"number",className:"input",value:s.budget,min:0,step:1,onChange:C=>t({budget:Math.max(0,parseFloat(C.target.value)||0)})}),e.jsx("span",{className:"field-help",children:"0 = unlimited"})]})]}),e.jsxs("label",{className:"checkbox-row",children:[e.jsx("input",{type:"checkbox",checked:s.outputShaper,onChange:C=>t({outputShaper:C.target.checked})}),e.jsx("span",{children:"Enable output shaper"})]}),e.jsxs("label",{className:"checkbox-row",children:[e.jsx("input",{type:"checkbox",checked:s.telemetry,onChange:C=>t({telemetry:C.target.checked})}),e.jsx("span",{children:"Enable telemetry"})]})]})]})})}const It={enabled:!0,autoInstall:!0,port:8787,host:"127.0.0.1",outputShaper:!1,telemetry:!1,budget:0,backend:"anthropic",autoStart:!0,autoWrap:!0,routeAllProviders:!0};function Dr({settings:s,setSettings:t,setDirty:a}){return e.jsx(Pr,{settings:s.headroom||It,onPatch:i=>{t(n=>({...n,headroom:{...n.headroom||It,...i}})),a(!0)}})}function Fr(){const s=oe(),[t,a]=r.useState([]),[i,n]=r.useState(new Set),[l,c]=r.useState(!0),[o,p]=r.useState(""),[x,h]=r.useState(!0),d=r.useCallback(async()=>{c(!0);try{const[b,A]=await Promise.all([w.get("/activity"),w.get("/activity/hidden")]);a(Array.isArray(b.items)?b.items:[]),n(new Set(A.hidden||[]))}catch(b){s.error(`Load failed: ${b.message}`)}finally{c(!1)}},[s]);r.useEffect(()=>{d()},[d]);const m=(b,A)=>{const y=`${b.kind||""}|${b.ts||""}|${b.slug||""}|${A}`;let v=0;for(let L=0;L<y.length;L++)v=(v<<5)-v+y.charCodeAt(L)|0;return Math.abs(v).toString(16).padStart(8,"0").slice(0,16)},u=async()=>{try{await w.del("/activity/hide"),n(new Set),s.success("All hidden activity restored.")}catch(b){s.error(`Restore failed: ${b.message}`)}},g=async b=>{try{await w.del(`/activity/hide/${encodeURIComponent(b)}`);const A=new Set(i);A.delete(b),n(A)}catch(A){s.error(`Restore failed: ${A.message}`)}},f=t.filter((b,A)=>{const y=m(b,A);if(!x&&i.has(y))return!1;if(!o)return!0;const v=o.toLowerCase();return[b.kind,b.slug,b.message].some(L=>typeof L=="string"&&L.toLowerCase().includes(v))});return e.jsxs(Q,{id:"settings-activity-log","data-section":"activity-log",children:[e.jsxs(se,{children:[e.jsx(Te,{size:14})," Activity log",e.jsxs("span",{className:"muted",style:{fontWeight:400,marginLeft:8,fontSize:12},children:[t.length," total · ",i.size," hidden"]}),e.jsx(T,{variant:"ghost",size:"sm",style:{marginLeft:"auto"},onClick:d,title:"Reload",children:e.jsx(ce,{size:12})})]}),e.jsxs(ie,{children:["Full history from ",e.jsx("code",{children:"~/.bizar/activity.log"}),". Hiding an item in the Overview only hides it there — the entry stays here."]}),e.jsxs("div",{className:"activity-log-toolbar",children:[e.jsxs("div",{className:"activity-log-search",children:[e.jsx(ye,{size:12}),e.jsx("input",{type:"text",className:"input",placeholder:"Filter by kind, slug, or message…",value:o,onChange:b=>p(b.target.value)})]}),e.jsxs("label",{className:"activity-log-toggle",children:[e.jsx("input",{type:"checkbox",checked:x,onChange:b=>h(b.target.checked)}),"Show hidden"]}),e.jsxs(T,{variant:"ghost",size:"sm",disabled:i.size===0,onClick:u,title:"Restore all hidden items to the Overview",children:[e.jsx(is,{size:12})," Restore all"]})]}),l?e.jsx("div",{className:"muted",style:{padding:"12px 0",fontSize:12},children:"Loading…"}):f.length===0?e.jsx("div",{className:"muted",style:{padding:"12px 0",fontSize:12},children:t.length===0?"No activity yet.":"No items match the current filter."}):e.jsxs("div",{className:"activity-log-table-wrap",children:[e.jsxs("table",{className:"activity-log-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Kind"}),e.jsx("th",{children:"Detail"}),e.jsx("th",{children:"Time"}),e.jsx("th",{})]})}),e.jsx("tbody",{children:f.slice(0,200).map((b,A)=>{const y=m(b,A),v=i.has(y);return e.jsxs("tr",{className:X(v&&"activity-log-row-hidden"),children:[e.jsx("td",{className:"activity-log-kind",children:b.kind||"activity"}),e.jsx("td",{className:"activity-log-detail",children:b.message||b.slug||"—"}),e.jsx("td",{className:"activity-log-time mono",children:b.ts?new Date(b.ts).toLocaleString():"—"}),e.jsx("td",{children:v?e.jsx(T,{variant:"ghost",size:"sm",onClick:()=>g(y),title:"Restore to Overview",children:e.jsx(is,{size:12})}):e.jsx("span",{className:"activity-log-state-tag",children:"shown"})})]},`${b.ts}-${A}`)})})]}),f.length>200&&e.jsxs("div",{className:"muted",style:{fontSize:11,padding:"8px 0"},children:["Showing first 200 of ",f.length,"."]})]})]})}function Or({about:s}){return e.jsxs(Q,{id:"settings-about","data-section":"about",children:[e.jsxs(se,{children:[e.jsx(Hs,{size:14})," About"]}),e.jsx(ie,{children:"Build metadata."}),e.jsxs("dl",{className:"about-table",children:[e.jsx("dt",{children:"Version"}),e.jsx("dd",{className:"mono",children:(s==null?void 0:s.version)||"—"}),e.jsx("dt",{children:"Homepage"}),e.jsx("dd",{children:e.jsx("a",{href:(s==null?void 0:s.homepage)||"https://github.com/DrB0rk/BizarHarness",target:"_blank",rel:"noopener noreferrer",children:(s==null?void 0:s.homepage)||"https://github.com/DrB0rk/BizarHarness"})}),e.jsx("dt",{children:"License"}),e.jsx("dd",{children:(s==null?void 0:s.license)||"MIT"})]})]})}function Br({about:s}){return e.jsxs(e.Fragment,{children:[e.jsx(Fr,{}),e.jsx(Or,{about:s})]})}function Ur(){return e.jsxs(Q,{id:"settings-env-vars","data-section":"env-vars",children:[e.jsx(se,{children:"Environment Variables"}),e.jsx(ie,{children:"Configure environment variables for the Bizar runtime."}),e.jsx("p",{className:"muted",style:{fontSize:12},children:"Environment variable management is coming soon."})]})}function qr(){return e.jsxs(Q,{id:"settings-providers","data-section":"providers",children:[e.jsx(se,{children:"AI Providers"}),e.jsx(ie,{children:"Configure API keys and endpoints for AI providers."}),e.jsx("p",{className:"muted",style:{fontSize:12},children:"Provider management is coming soon."})]})}function Hr(){return e.jsxs(Q,{id:"settings-memory","data-section":"memory",children:[e.jsx(se,{children:"Memory"}),e.jsx(ie,{children:"Configure LightRAG, Obsidian vault, and git integration."}),e.jsx("p",{className:"muted",style:{fontSize:12},children:"Memory configuration is coming soon."})]})}function _r(){return e.jsxs(Q,{id:"settings-skills","data-section":"skills",children:[e.jsx(se,{children:"Skills"}),e.jsx(ie,{children:"Manage agent skill paths and refresh available skills."}),e.jsx("p",{className:"muted",style:{fontSize:12},children:"Skills configuration is coming soon."})]})}function Wr(){return e.jsxs(Q,{id:"settings-backup","data-section":"backup",children:[e.jsx(se,{children:"Backup & Restore"}),e.jsx(ie,{children:"Export and restore your Bizar configuration."}),e.jsx("p",{className:"muted",style:{fontSize:12},children:"Backup and restore is coming soon."})]})}const Lt=[{id:"theme",label:"Theme"},{id:"updates",label:"Updates"},{id:"layout",label:"Layout"},{id:"general",label:"General"},{id:"network",label:"Network"},{id:"notifications",label:"Notifications"},{id:"auth",label:"Auth"},{id:"agents",label:"Agents"},{id:"dashboard",label:"Dashboard"},{id:"background",label:"Background"},{id:"system-llm",label:"System LLM"},{id:"headroom",label:"Headroom"},{id:"activity-log",label:"Activity"},{id:"about",label:"About"},{id:"env-vars",label:"Env Vars"},{id:"providers",label:"Providers"},{id:"memory",label:"Memory"},{id:"skills",label:"Skills"},{id:"backup",label:"Backup"}];function Vr({settings:s,refreshSnapshot:t}){const a=oe(),[i,n]=r.useState(s),[l,c]=r.useState(!1),[o,p]=r.useState(!1),[x,h]=r.useState(null),[d,m]=r.useState({port:4321,https:!0,hostname:""}),[u,g]=r.useState(null);r.useEffect(()=>{n(s),c(!1),s.theme&&as(s.theme)},[s]),r.useEffect(()=>{x&&m({port:x.settings.port,https:x.settings.https!==!1,hostname:x.settings.hostname||""})},[x]),r.useEffect(()=>{w.get("/tailscale/status").then(h).catch(()=>{})},[]);const f=F=>{n(C=>{const _={...C,theme:{...C.theme,...F}};return as(_.theme),_}),c(!0)},b=F=>{n(C=>({...C,ui:{...C.ui,...F}})),c(!0)},A=(F,C)=>{n(_=>({..._,[F]:C})),c(!0)},y=F=>{n(C=>({...C,notifications:{...C.notifications,...F}})),c(!0)},v=F=>{n(C=>({...C,agents:{...C.agents,...F}})),c(!0)},L=F=>{n(C=>({...C,dashboard:{...C.dashboard,...F}})),c(!0)},[$,R]=r.useState(()=>{if(typeof window>"u")return null;const F=window.location.hash.replace(/^#settings-/,"");return Lt.some(C=>C.id===F)?F:null}),P=F=>{R(F);try{if(history.replaceState(null,"",F?`#settings-${F}`:window.location.pathname),F){const C=document.getElementById(`settings-${F}`);C&&C.scrollIntoView({behavior:"smooth",block:"start"})}else window.scrollTo({top:0,behavior:"smooth"})}catch{}},S=async()=>{try{x!=null&&x.settings.enabled?(await w.post("/tailscale/disable"),a.success("Tailscale serve disabled.")):(await w.post("/tailscale/enable",{port:d.port||4321,https:d.https,hostname:d.hostname||""}),a.success("Tailscale serve enabled.")),h(await w.get("/tailscale/status"))}catch(F){a.error(`Tailscale failed: ${F.message}`)}},q=async()=>{p(!0);try{const F=await w.put("/settings",i);n(F.data),c(!1),xs(F.data.theme),as(F.data.theme),a.success("Settings saved."),await t()}catch(F){a.error(`Save failed: ${F.message}`)}finally{p(!1)}},O=async()=>{try{const F=await w.get("/settings");n(F.data),c(!1),xs(F.data.theme),as(F.data.theme),a.info("Settings reloaded.",1500)}catch(F){a.error(`Reload failed: ${F.message}`)}},k=async()=>{if(confirm("Reset all settings to defaults?"))try{const F=await w.post("/settings/reset");n(F.data),c(!1),xs(F.data.theme),as(F.data.theme),a.success("Settings reset."),await t()}catch(F){a.error(`Reset failed: ${F.message}`)}},N={settings:i,patchTheme:f,patchUi:b,patchTop:A,patchNotifications:y,patchAgents:v,patchDashboard:L},D=i.about||{version:"3.0.4",homepage:"https://github.com/DrB0rk/BizarHarness",license:"MIT"},j=$===null,M=F=>$===F;return e.jsxs("div",{className:"view view-settings",children:[e.jsxs("header",{className:"view-header",children:[e.jsxs("div",{className:"view-header-text",children:[e.jsxs("h2",{className:"view-title",children:[e.jsx(mt,{size:18})," Settings"]}),e.jsxs("p",{className:"view-subtitle",children:["Personal preferences. Changes are saved to ",e.jsx("code",{children:"~/.config/bizar/settings.json"}),"."]})]}),e.jsxs("div",{className:"view-actions",children:[e.jsxs(T,{variant:"ghost",size:"sm",onClick:k,children:[e.jsx(Wt,{size:14})," Reset"]}),e.jsxs(T,{variant:"secondary",size:"sm",onClick:O,children:[e.jsx(ce,{size:14})," Reload"]}),e.jsxs(T,{variant:"primary",size:"sm",disabled:!l||o,onClick:q,children:[o?e.jsx("span",{className:"btn-spinner"}):e.jsx(vs,{size:14}),o?"Saving…":"Save"]})]})]}),e.jsxs("nav",{className:"settings-subnav","aria-label":"Settings sections",children:[e.jsx("button",{type:"button",className:X("settings-subnav-button","settings-subnav-button-all",j&&"settings-subnav-button-active"),onClick:()=>P(null),title:"Show all settings sections",children:"All"}),Lt.map(F=>e.jsx("button",{type:"button",className:X("settings-subnav-button",$===F.id&&"settings-subnav-button-active"),onClick:()=>P(F.id),children:F.label},F.id))]}),e.jsxs("div",{className:X("settings-grid",$&&"settings-grid-filtered"),"data-active-section":$||void 0,children:[(j||M("theme"))&&e.jsx(Cr,{...N}),(j||M("updates"))&&e.jsx(zr,{}),(j||M("layout")||M("general"))&&e.jsx(Mr,{...N}),(j||M("network")||M("service")||M("tailscale"))&&e.jsx($r,{tailscale:x,tailscaleDraft:d,setTailscaleDraft:m,onTailscaleToggle:S}),(j||M("notifications"))&&e.jsx(Ar,{...N}),(j||M("auth"))&&e.jsx(Rr,{settings:i,authStatus:u,setAuthStatus:g}),(j||M("agents")||M("dashboard")||M("background"))&&e.jsx(Ir,{...N}),(j||M("system-llm"))&&e.jsx(Lr,{...N}),(j||M("headroom"))&&e.jsx(Dr,{settings:i,setSettings:n,setDirty:c}),(j||M("activity-log")||M("about"))&&e.jsx(Br,{about:D}),(j||M("env-vars"))&&e.jsx(Ur,{}),(j||M("providers"))&&e.jsx(qr,{}),(j||M("memory"))&&e.jsx(Hr,{}),(j||M("skills"))&&e.jsx(_r,{}),(j||M("backup"))&&e.jsx(Wr,{})]})]})}const Et=We.memo(Vr);function Kr({snapshot:s,refreshSnapshot:t}){const a=oe(),i=Pe(),[n,l]=r.useState(Array.isArray(s.mods)?s.mods:[]),[c,o]=r.useState(!0),[p,x]=r.useState(null),[h,d]=r.useState([]),[m,u]=r.useState(null),[g,f]=r.useState(!1),[b,A]=r.useState(null),[y,v]=r.useState(!1),[L,$]=r.useState({}),R=async()=>{var j,M,F;v(!0);try{const C=await w.get("/mods/registry");A({source:((j=C.registry)==null?void 0:j.source)||"",version:(M=C.registry)==null?void 0:M.version,updatedAt:(F=C.registry)==null?void 0:F.updatedAt,mods:C.mods||[]})}catch(C){A({source:"",mods:[],error:C.message})}finally{v(!1)}},P=async j=>{$(M=>({...M,[j]:!0}));try{const M=await w.post("/mods",{id:j});l(F=>[...F.filter(C=>C.id!==M.id),M]),a.success(`Mod "${M.id}" installed from registry.`),await t()}catch(M){a.error(`Install failed: ${M.message}`)}finally{$(M=>({...M,[j]:!1}))}},S=async(j,M=!1)=>{$(F=>({...F,[j]:!0}));try{const F=await w.post(`/mods/${encodeURIComponent(j)}/upgrade`,{backup:M});l(_=>[..._.filter(ae=>ae.id!==F.mod.id),F.mod]);const C=F.backupPath?` (backup at ${F.backupPath})`:"";a.success(`Mod "${j}" upgraded v${F.from} → v${F.to}${C}.`),await t()}catch(F){a.error(`Upgrade failed: ${F.message}`)}finally{$(F=>({...F,[j]:!1}))}},q=async()=>{try{const j=await w.get("/mods");l(j.mods||[]);try{const M=await w.get("/mods/views");d(M.views||[])}catch{d([])}}catch(j){a.error(`Mods load failed: ${j.message}`)}finally{o(!1)}};r.useEffect(()=>{q()},[]),r.useEffect(()=>{Array.isArray(s.mods)&&s.mods!==n&&l(s.mods)},[s.mods]);const O=()=>{let j=null;i.open({title:"Install mod",children:e.jsxs("div",{children:[e.jsxs("p",{className:"muted",children:["Provide the absolute path to a mod folder (one that contains a ",e.jsx("code",{children:"mod.json"}),"). The folder will be copied to"," ",e.jsx("code",{children:"~/.config/bizar/mods/<id>/"}),"."]}),e.jsx("label",{className:"field-label",htmlFor:"install-mod-path",children:"Path"}),e.jsx("input",{id:"install-mod-path",ref:M=>j=M,className:"input",type:"text",placeholder:"/path/to/my-mod",autoFocus:!0})]}),footer:e.jsxs("div",{className:"modal-footer-actions",children:[e.jsx(T,{variant:"ghost",onClick:()=>i.close(),children:"Cancel"}),e.jsx(T,{variant:"primary",onClick:async()=>{const M=((j==null?void 0:j.value)||"").trim();if(!M){a.warning("Path is required.");return}try{const F=await w.post("/mods",{path:M});l(C=>[...C,F]),a.success(`Mod "${F.id}" installed.`),i.close(),await t()}catch(F){a.error(`Install failed: ${F.message}`)}},children:"Install"})]})})},k=async j=>{if(confirm(`Uninstall mod "${j}"? This removes the folder from ~/.config/bizar/mods/.`))try{await w.del(`/mods/${encodeURIComponent(j)}`),l(M=>M.filter(F=>F.id!==j)),p===j&&x(null),a.success("Mod uninstalled.")}catch(M){a.error(`Uninstall failed: ${M.message}`)}},N=async j=>{try{const M=await w.put(`/mods/${encodeURIComponent(j.id)}`,{enabled:!j.enabled});l(F=>F.map(C=>C.id===j.id?M:C)),a.success(`Mod ${M.enabled?"enabled":"disabled"}.`)}catch(M){a.error(`Toggle failed: ${M.message}`)}},D=n.find(j=>j.id===p)||null;return c?e.jsx("div",{className:"view-loading",children:e.jsx(he,{size:"lg"})}):e.jsxs("div",{className:"view view-mods",children:[e.jsxs("header",{className:"view-header",children:[e.jsxs("div",{className:"view-header-text",children:[e.jsxs("h2",{className:"view-title",children:[e.jsx(Bs,{size:18})," Mods (",n.length,")"]}),e.jsxs("p",{className:"view-subtitle",children:["Extensions installed in ",e.jsx("code",{children:"~/.config/bizar/mods/"}),". Mods can add agents, commands, routes, and views."]})]}),e.jsxs("div",{className:"view-actions",children:[e.jsxs(T,{variant:"secondary",size:"sm",onClick:q,children:[e.jsx(ce,{size:14})," Refresh"]}),e.jsxs(T,{variant:"primary",size:"sm",onClick:O,children:[e.jsx(Me,{size:14})," Install mod"]})]})]}),n.length===0?e.jsx(we,{icon:e.jsx(Bs,{size:32}),title:"No mods installed",message:"Mods are folders with a mod.json. Install one to extend Bizar with custom agents, commands, and views."}):e.jsxs("div",{className:"mods-layout",children:[e.jsx("div",{className:"mods-list",children:n.map(j=>e.jsxs("div",{className:X("mod-list-item",p===j.id&&"mod-list-item-active"),onClick:()=>x(j.id),children:[e.jsxs("div",{className:"mod-list-item-head",children:[e.jsxs("div",{children:[e.jsx("div",{className:"mod-list-item-name",children:j.name}),e.jsxs("div",{className:"mod-list-item-meta",children:["v",j.version," · ",j.type," · ",j.author]})]}),e.jsxs("div",{className:"mod-list-item-actions",onClick:M=>M.stopPropagation(),children:[e.jsx("button",{type:"button",className:"icon-btn","aria-label":"Toggle enabled",title:j.enabled?"Disable":"Enable",onClick:()=>N(j),children:e.jsx(ut,{size:12})}),e.jsx("button",{type:"button",className:"icon-btn icon-btn-danger","aria-label":"Uninstall",title:"Uninstall",onClick:()=>k(j.id),children:e.jsx(Ae,{size:12})})]})]}),e.jsx("div",{className:"mod-list-item-desc ellipsis-2",title:j.description,children:j.description}),e.jsx("div",{className:"mod-list-item-status",children:e.jsx("span",{className:`mod-mini-pill ${j.enabled?"mod-mini-pill-on":"mod-mini-pill-off"}`,children:j.enabled?"enabled":"disabled"})})]},j.id))}),D&&e.jsx(Gr,{mod:D})]}),e.jsxs(Q,{className:"mods-registry-card",children:[e.jsxs("button",{type:"button",className:"mods-registry-head","aria-expanded":g,"aria-controls":"mods-registry-body",onClick:()=>{!b&&!y&&R(),f(j=>!j)},children:[e.jsx(ys,{size:14,"aria-hidden":!0}),e.jsx("span",{className:"mods-registry-title",children:"Mod registry"}),e.jsx("span",{className:"muted",style:{fontSize:11},children:b!=null&&b.mods?`${b.mods.length} available`:"click to browse"}),e.jsx("span",{className:"mods-registry-spacer"}),g?e.jsx(Fe,{size:14,"aria-hidden":!0}):e.jsx(_e,{size:14,"aria-hidden":!0})]}),g&&e.jsx("div",{id:"mods-registry-body",className:"mods-registry-body",children:y?e.jsx("div",{className:"muted",style:{padding:12,fontSize:12},children:"Loading registry…"}):b!=null&&b.error?e.jsxs("div",{className:"mods-registry-error",children:[e.jsx(bs,{size:12})," Could not load registry: ",b.error]}):!b||b.mods.length===0?e.jsx("div",{className:"muted",style:{padding:12,fontSize:12},children:"No mods listed in the registry yet."}):e.jsxs(e.Fragment,{children:[b.source&&e.jsxs("div",{className:"muted",style:{fontSize:11,marginBottom:8},children:["Source: ",e.jsx("code",{children:b.source})]}),e.jsx("div",{className:"mods-registry-grid",children:b.mods.map(j=>{const M=n.some(C=>C.id===j.id),F=!!L[j.id];return e.jsxs("div",{className:"mod-registry-card",children:[e.jsxs("div",{className:"mod-registry-card-head",children:[e.jsx("div",{className:"mod-registry-card-name",children:j.name}),j.latest&&e.jsxs("span",{className:X("mod-registry-version",j.upgradeAvailable&&"mod-registry-version-upgrade"),children:["v",j.latest,j.upgradeAvailable?" ↑":""]})]}),j.description&&e.jsx("div",{className:"mod-registry-card-desc",children:j.description}),e.jsxs("div",{className:"mod-registry-card-meta",children:[j.author&&e.jsxs("span",{className:"muted",children:["by ",j.author]}),j.homepage&&e.jsx("a",{href:j.homepage,target:"_blank",rel:"noopener noreferrer",className:"mod-registry-link",children:"homepage"})]}),(j.permissions||[]).length>0&&e.jsxs("div",{className:"mod-registry-perms",children:[e.jsx(bs,{size:10}),(j.permissions||[]).slice(0,4).map(C=>e.jsx("span",{className:"mod-registry-perm",children:C},C)),(j.permissions||[]).length>4&&e.jsxs("span",{className:"mod-registry-perm-more",children:["+",j.permissions.length-4]})]}),e.jsxs("div",{className:"mod-registry-card-actions",children:[!M&&e.jsx(T,{variant:"primary",size:"sm",disabled:F,onClick:()=>P(j.id),title:"Install from registry",children:F?e.jsx(he,{size:"sm"}):e.jsxs(e.Fragment,{children:[e.jsx(Qe,{size:12})," Install"]})}),M&&j.upgradeAvailable&&e.jsx(T,{variant:"primary",size:"sm",disabled:F,onClick:()=>S(j.id),title:`Upgrade from v${j.installedVersion||"?"} to v${j.upgradeAvailable}`,children:F?e.jsx(he,{size:"sm"}):e.jsxs(e.Fragment,{children:[e.jsx(Qe,{size:12})," Upgrade to v",j.upgradeAvailable]})}),M&&!j.upgradeAvailable&&e.jsxs(T,{variant:"ghost",size:"sm",disabled:!0,title:`Installed v${j.installedVersion||"?"}`,children:["Installed v",j.installedVersion||"?"]})]})]},j.id)})})]})})]}),h.length>0&&e.jsxs(Q,{className:"mod-views-hint",children:[e.jsxs(se,{children:[e.jsx(ys,{size:14})," Mod views"]}),e.jsxs(ie,{children:[h.length," mod-supplied view",h.length===1?"":"s"," are now available in the sidebar navigation. Look for the ",e.jsx("strong",{children:"Mods"})," section at the bottom of the sidebar."]})]}),m&&e.jsxs("div",{className:"mod-iframe-panel",children:[e.jsxs("div",{className:"mod-iframe-header",children:[e.jsxs("span",{children:["Mod view — ",e.jsx("a",{href:m,target:"_blank",rel:"noreferrer",children:m})]}),e.jsx("button",{type:"button",className:"icon-btn","aria-label":"Close iframe",onClick:()=>u(null),children:e.jsx($e,{size:14})})]}),e.jsx("iframe",{src:m,className:"mod-iframe",title:"Mod view",sandbox:"allow-scripts allow-same-origin allow-forms allow-popups"})]})]})}function Gr({mod:s}){const t=oe(),[a,i]=r.useState(null),[n,l]=r.useState(!1),[c,o]=r.useState(!1),[p,x]=r.useState(null),h=async()=>{l(!0);try{const m=await w.get(`/mods/${s.id}/instructions`);i(m),o(!0)}catch(m){t.error(`Failed to load instructions: ${m.message}`)}finally{l(!1)}},d=async()=>{try{const m=await w.post(`/mods/${s.id}/instructions/reinstall`,{});t.success(`Reinstalled: ${m.counts.agents} agents, ${m.counts.commands} commands, ${m.counts.skills} skills, ${m.counts.instructions} instructions.`),await h()}catch(m){t.error(`Reinstall failed: ${m.message}`)}};return e.jsxs(Q,{className:"mod-details",children:[e.jsxs(se,{children:[e.jsx(Se,{size:14})," Mod details — ",s.name]}),e.jsx(ie,{children:e.jsx("code",{children:s.path})}),e.jsxs("dl",{className:"env-table",children:[e.jsx("dt",{children:"ID"}),e.jsx("dd",{className:"mono",children:s.id}),e.jsx("dt",{children:"Version"}),e.jsx("dd",{className:"mono",children:s.version}),e.jsx("dt",{children:"Type"}),e.jsx("dd",{className:"mono",children:s.type}),e.jsx("dt",{children:"Author"}),e.jsx("dd",{className:"mono",children:s.author||"—"}),e.jsx("dt",{children:"Bizar"}),e.jsx("dd",{className:"mono",children:s.bizar||"*"}),e.jsx("dt",{children:"Enabled"}),e.jsx("dd",{children:s.enabled?"yes":"no"}),e.jsx("dt",{children:"Permissions"}),e.jsxs("dd",{children:[(s.permissions||[]).map(m=>e.jsx("span",{className:"tag",children:m},m)),(s.permissions||[]).length===0&&e.jsx("span",{className:"muted",children:"(none)"})]})]}),e.jsxs("div",{className:"mod-files",children:[e.jsx("div",{className:"muted",children:"Files"}),e.jsx("ul",{children:(s.files||[]).map(m=>e.jsxs("li",{children:[e.jsx("span",{className:"mod-file-cat",children:m.category}),e.jsx("span",{className:"mono",children:m.path})]},m.path))})]}),e.jsxs("div",{className:"mod-instructions",children:[e.jsxs("button",{type:"button",className:"mod-instructions-head","aria-expanded":c,"aria-controls":`mod-instructions-body-${s.id}`,onClick:()=>{!a&&!n&&h(),o(m=>!m)},children:[e.jsx(Ya,{size:14,"aria-hidden":!0}),e.jsx("span",{children:"Installed instructions"}),e.jsx("span",{className:"muted",style:{fontSize:11},children:a?`${a.total} files`:"click to view"}),e.jsx("span",{className:"mod-instructions-spacer"}),c?e.jsx(Fe,{size:14,"aria-hidden":!0}):e.jsx(_e,{size:14,"aria-hidden":!0})]}),c&&a&&e.jsxs("div",{id:`mod-instructions-body-${s.id}`,className:"mod-instructions-body",children:[a.agents.length>0&&e.jsxs("div",{className:"mod-instructions-section",children:[e.jsxs("div",{className:"mod-instructions-section-title",children:[e.jsx(Sn,{size:11})," Agents (",a.agents.length,")"]}),a.agents.map(m=>e.jsxs("div",{className:"mod-instructions-file",children:[e.jsxs("div",{className:"mod-instructions-file-head",onClick:()=>x(u=>u===m.filename?null:m.filename),children:[e.jsx("span",{className:"mono",children:m.filename}),e.jsxs("span",{className:"muted",style:{fontSize:10},children:["installed at ",m.fullPath]})]}),p===m.filename&&e.jsx("pre",{className:"mod-instructions-content",children:m.content||e.jsx("em",{className:"muted",children:"(file missing on disk)"})})]},m.filename))]}),a.commands.length>0&&e.jsxs("div",{className:"mod-instructions-section",children:[e.jsxs("div",{className:"mod-instructions-section-title",children:[e.jsx(fs,{size:11})," Commands (",a.commands.length,")"]}),a.commands.map(m=>e.jsxs("div",{className:"mod-instructions-file",children:[e.jsxs("div",{className:"mod-instructions-file-head",onClick:()=>x(u=>u===m.filename?null:m.filename),children:[e.jsx("span",{className:"mono",children:m.filename}),e.jsxs("span",{className:"muted",style:{fontSize:10},children:["installed at ",m.fullPath]})]}),p===m.filename&&e.jsx("pre",{className:"mod-instructions-content",children:m.content||e.jsx("em",{className:"muted",children:"(file missing on disk)"})})]},m.filename))]}),a.skills.length>0&&e.jsxs("div",{className:"mod-instructions-section",children:[e.jsxs("div",{className:"mod-instructions-section-title",children:[e.jsx(Kt,{size:11})," Skills (",a.skills.length,")"]}),a.skills.map(m=>e.jsxs("div",{className:"mod-instructions-file",children:[e.jsxs("div",{className:"mod-instructions-file-head",onClick:()=>x(u=>u===m.name?null:m.name),children:[e.jsx("span",{className:"mono",children:m.name}),e.jsxs("span",{className:"muted",style:{fontSize:10},children:["installed at ",m.fullPath]})]}),p===m.name&&e.jsx("pre",{className:"mod-instructions-content",children:m.content||e.jsx("em",{className:"muted",children:"(file missing on disk)"})})]},m.name))]}),a.total===0&&e.jsxs("div",{className:"muted",style:{padding:8,fontSize:12},children:["This mod did not install any instruction files. Mods install instructions by shipping a top-level ",e.jsx("code",{children:"INSTRUCTIONS.md"}),", an ",e.jsx("code",{children:"agents/"})," directory, a ",e.jsx("code",{children:"commands/"})," directory, or a ",e.jsx("code",{children:"skills/"})," directory."]}),e.jsx("div",{className:"mod-instructions-actions",children:e.jsxs(T,{variant:"ghost",size:"sm",onClick:d,children:[e.jsx(ce,{size:11})," Reinstall from mod folder"]})})]})]})]})}function Yr({viewId:s,reloadKey:t,setActiveTab:a}){const i=oe(),[n,l]=r.useState(null),[c,o]=r.useState(!0),[p,x]=r.useState(0);if(r.useEffect(()=>{let h=!1;return(async()=>{try{const d=await w.get("/mods/views");if(h)return;const m=(d.views||[]).find(u=>u.id===s);l(m||null)}catch(d){i.error(`Failed to load mod view: ${d.message}`)}finally{h||o(!1)}})(),()=>{h=!0}},[s,i]),c)return e.jsx(we,{title:"Loading mod view…"});if(!n)return e.jsx(we,{title:"Mod view not found",message:`No view with id "${s}" is currently installed.`,action:e.jsx(T,{onClick:()=>a("mods"),variant:"primary",size:"sm",children:"Open Mods"})});if(n.kind==="iframe"){const h=`/api/mods/${n.modId}/web/index.html?t=${p+(t||0)}`;return e.jsxs("div",{className:"mod-view-iframe-pane",children:[e.jsxs("div",{className:"mod-view-iframe-header",children:[e.jsxs("span",{className:"mod-view-iframe-label",children:[e.jsx(ys,{size:14}),n.label,e.jsxs("span",{className:"muted",style:{fontSize:11,fontWeight:400},children:["by ",n.modId]})]}),e.jsxs("div",{className:"mod-view-iframe-actions",children:[e.jsxs(T,{variant:"ghost",size:"sm",onClick:()=>x(d=>d+1),title:"Reload this view",children:[e.jsx(ce,{size:11})," Reload"]}),e.jsx("a",{href:h,target:"_blank",rel:"noopener noreferrer",className:"icon-btn",title:"Open in new tab",children:e.jsx(ls,{size:12})})]})]}),e.jsx("iframe",{src:h,className:"mod-view-iframe",title:n.label},p+(t||0))]})}if(n.component){const h=n.component,d=n.modId,m=r.lazy(()=>Vt(()=>import(`/api/mods/${encodeURIComponent(d)}/views/${encodeURIComponent(h)}`),[]).then(u=>({default:u.default??(()=>null)})));return e.jsxs("div",{className:"mod-view-tab-pane",children:[e.jsx("div",{className:"mod-view-iframe-header",children:e.jsxs("span",{className:"mod-view-iframe-label",children:[e.jsx(it,{size:14}),n.label,e.jsxs("span",{className:"muted",style:{fontSize:11,fontWeight:400},children:["by ",n.modId]})]})}),e.jsx("div",{className:"mod-view-tab-body",children:e.jsx(Xr,{modId:n.modId,component:n.component,children:e.jsx(r.Suspense,{fallback:e.jsxs("div",{style:{padding:24},children:[e.jsx(he,{size:"md"})," ",e.jsx("span",{className:"muted",children:"Loading mod view…"})]}),children:e.jsx(m,{})})})})]})}return e.jsxs(Q,{children:[e.jsxs(se,{children:[e.jsx(it,{size:14})," ",n.label]}),e.jsxs(ie,{children:["by ",n.modId]}),n.description&&e.jsx("p",{className:"muted",style:{marginTop:8},children:n.description}),e.jsxs("p",{className:"muted",style:{fontSize:12,marginTop:12},children:["This mod declared a tab view but did not provide a component path in views/registry.json. Add a ",e.jsx("code",{children:"component"})," field (e.g. ",e.jsx("code",{children:'"MyView.js"'}),") and ship the file under ",e.jsx("code",{children:"views/"}),"."]}),e.jsx("div",{style:{marginTop:12},children:e.jsx(T,{variant:"secondary",size:"sm",onClick:()=>a("mods"),children:"Open Mods page"})})]})}class Xr extends r.Component{constructor(){super(...arguments);cs(this,"state",{error:null})}static getDerivedStateFromError(a){return{error:a}}componentDidCatch(){}render(){return this.state.error?e.jsxs("div",{className:"mod-view-error",children:[e.jsx(ke,{size:16}),e.jsx("strong",{children:"Failed to render mod view"}),e.jsxs("div",{className:"muted",style:{fontSize:12,marginTop:6},children:[this.props.modId," → ",this.props.component,": ",this.state.error.message]})]}):this.props.children}}const Qr=["interval","cron","once"],Zr=["command","agent","webhook"],ct=[{value:"UTC",label:"UTC"},{value:"America/New_York",label:"America/New_York (ET)"},{value:"America/Los_Angeles",label:"America/Los_Angeles (PT)"},{value:"America/Chicago",label:"America/Chicago (CT)"},{value:"Europe/London",label:"Europe/London (UK)"},{value:"Europe/Berlin",label:"Europe/Berlin (CET)"},{value:"Asia/Tokyo",label:"Asia/Tokyo (JST)"}],Jr=Array.from({length:12},(s,t)=>t*5),kt=Array.from({length:24},(s,t)=>({value:t,label:t===0?"12 AM":t<12?`${t} AM`:t===12?"12 PM":`${t-12} PM`})),Nt=[{value:"*",label:"Every day"},{value:"0",label:"Sunday"},{value:"1",label:"Monday"},{value:"2",label:"Tuesday"},{value:"3",label:"Wednesday"},{value:"4",label:"Thursday"},{value:"5",label:"Friday"},{value:"6",label:"Saturday"}],ia=[{value:"s",label:"seconds"},{value:"m",label:"minutes"},{value:"h",label:"hours"},{value:"d",label:"days"}];function ra(s){if(typeof s!="string")return null;const t=s.trim().split(/\s+/);if(t.length!==5)return null;const[a,i,,,n]=t,l=parseInt(a,10),c=parseInt(i,10);if(!Number.isFinite(l)||!Number.isFinite(c)||a!==String(l)||i!==String(c))return null;const o=n==="*"?"*":parseInt(n,10);return o===null||n!=="*"&&!Number.isFinite(o)?null:{minute:l,hour:c,dow:n==="*"?"*":String(o)}}function el(s){if(typeof s!="string")return null;const t=/^(\d+)\s*([smhd])$/i.exec(s.trim());return t?{n:parseInt(t[1],10),unit:t[2].toLowerCase()}:null}function sl(s){var l,c;if(!s)return{name:"",type:"cron",cronMinute:0,cronHour:13,cronDow:"0",showAdvanced:!1,rawCron:"0 13 * * 0",intervalN:30,intervalUnit:"m",onceAt:"",timezone:"UTC",customTimezone:"",actionType:"agent",actionTarget:"",actionPrompt:"",skipIfBudgetLow:!1,maxConcurrent:6,enabled:!0,humanLabel:""};const t=s.type==="cron"?ra(s.schedule):null,a=s.type==="interval"?el(s.schedule):null,i=s.timezone||"UTC",n=ct.some(o=>o.value===i);return{name:s.name||"",type:s.type,cronMinute:(t==null?void 0:t.minute)??0,cronHour:(t==null?void 0:t.hour)??9,cronDow:(t==null?void 0:t.dow)??"*",showAdvanced:!t,rawCron:s.schedule,intervalN:(a==null?void 0:a.n)??30,intervalUnit:(a==null?void 0:a.unit)??"m",onceAt:s.type==="once"?tl(s.schedule):"",timezone:n?i:"Other…",customTimezone:n?"":i,actionType:s.action.type,actionTarget:s.action.target||"",actionPrompt:s.action.prompt||"",skipIfBudgetLow:!!((l=s.budgetCheck)!=null&&l.skipIfBudgetLow),maxConcurrent:Number.isFinite((c=s.budgetCheck)==null?void 0:c.maxConcurrent)?s.budgetCheck.maxConcurrent:6,enabled:s.enabled!==!1,humanLabel:""}}function tl(s){if(!s)return"";try{const t=new Date(s);if(Number.isNaN(t.getTime()))return"";const a=i=>String(i).padStart(2,"0");return`${t.getFullYear()}-${a(t.getMonth()+1)}-${a(t.getDate())}T${a(t.getHours())}:${a(t.getMinutes())}`}catch{return""}}function al(s){var a,i,n;if(s.type==="cron"){if(s.showAdvanced)return{schedule:s.rawCron.trim(),humanLabel:s.humanLabel||s.rawCron.trim()};const l=`${s.cronMinute} ${s.cronHour} * * ${s.cronDow}`,c=((a=Nt.find(h=>h.value===s.cronDow))==null?void 0:a.label)||"",o=((i=kt.find(h=>h.value===s.cronHour))==null?void 0:i.label)||`${s.cronHour}`,p=String(s.cronMinute).padStart(2,"0"),x=c==="Every day"?`Every day at ${o.replace(" ","")} (min ${p})`:`Every ${c} at ${o.replace(" ","")} (min ${p})`;return{schedule:l,humanLabel:s.humanLabel||x}}if(s.type==="interval"){const l=((n=ia.find(o=>o.value===s.intervalUnit))==null?void 0:n.label)||s.intervalUnit;return{schedule:`${s.intervalN}${s.intervalUnit}`,humanLabel:s.humanLabel||`Every ${s.intervalN} ${l}`}}return s.onceAt?{schedule:new Date(s.onceAt).toISOString(),humanLabel:s.humanLabel||new Date(s.onceAt).toLocaleString()}:{schedule:"",humanLabel:s.humanLabel||""}}function nl({snapshot:s,refreshSnapshot:t}){var m;const a=oe(),i=Pe(),[n,l]=r.useState(s.schedules||[]),[c,o]=r.useState(!s.schedules),p=async()=>{try{const u=await w.get("/projects/active/schedules");l(u.schedules||[])}catch(u){a.error(`Schedules load failed: ${u.message}`)}finally{o(!1)}};r.useEffect(()=>{var u;if((u=s.schedules)!=null&&u.length||s.schedules){l(s.schedules||[]),o(!1);return}p()},[s.schedules]);const x=u=>{i.open({title:u?`Edit schedule: ${u.name}`:"New schedule",width:640,children:e.jsx(il,{initial:u,onClose:i.close,onSubmitted:async g=>{l(f=>{const b=f.findIndex(y=>y.id===g.id);if(b===-1)return[...f,g];const A=f.slice();return A[b]=g,A}),a.success(u?"Schedule updated.":"Schedule created."),i.close(),await t()},onError:g=>a.error(g)})})},h=async u=>{var g;try{const f=await w.post(`/schedules/${encodeURIComponent(u.id)}/run`);a.success(f.ok?"Schedule ran.":`Run failed: ${((g=f.runResult)==null?void 0:g.error)||"unknown"}`),await p()}catch(f){a.error(`Run failed: ${f.message}`)}},d=async u=>{if(confirm(`Delete schedule "${u.name}"?`))try{await w.del(`/schedules/${encodeURIComponent(u.id)}`),l(g=>g.filter(f=>f.id!==u.id)),a.success("Schedule deleted.")}catch(g){a.error(`Delete failed: ${g.message}`)}};return c?e.jsx("div",{className:"view-loading",children:e.jsx(he,{size:"lg"})}):e.jsxs("div",{className:"view view-schedules",children:[e.jsxs("header",{className:"view-header",children:[e.jsxs("div",{className:"view-header-text",children:[e.jsxs("h2",{className:"view-title",children:[e.jsx(Ds,{size:18})," Schedules (",n.length,")"]}),e.jsxs("p",{className:"view-subtitle",children:["Recurring tasks for the active project: ",e.jsx("strong",{children:((m=s.activeProject)==null?void 0:m.name)||"(none)"}),". Service daemon runs them at the right time."]})]}),e.jsxs("div",{className:"view-actions",children:[e.jsxs(T,{variant:"secondary",size:"sm",onClick:p,children:[e.jsx(ce,{size:14})," Refresh"]}),e.jsxs(T,{variant:"primary",size:"sm",onClick:()=>x(),children:[e.jsx(Me,{size:14})," New schedule"]})]})]}),n.length===0?e.jsx(we,{icon:e.jsx(Ds,{size:32}),title:"No schedules",message:s.activeProject?"Add a schedule to run commands, webhooks, or agent tasks on a cron / interval / one-shot basis.":"Activate a project first to scope schedules."}):e.jsx("div",{className:"schedule-grid",children:n.map(u=>{var g;return e.jsxs(Q,{className:"schedule-card",children:[e.jsxs("div",{className:"schedule-card-head",children:[e.jsxs("div",{children:[e.jsx(se,{children:u.name}),e.jsxs(ie,{children:[e.jsx("code",{children:u.type})," ·"," ",e.jsx("span",{title:u.schedule,children:rl(u)||u.schedule}),u.timezone&&u.timezone!=="UTC"?e.jsxs(e.Fragment,{children:[" · ",e.jsx("code",{children:u.timezone})]}):null," · ",e.jsx("span",{className:u.enabled?"status-on":"status-neutral",children:u.enabled?"enabled":"disabled"})]})]}),e.jsxs("div",{className:"schedule-card-actions",children:[e.jsxs(T,{variant:"secondary",size:"sm",onClick:()=>x(u),children:[e.jsx(ks,{size:12})," Edit"]}),e.jsxs(T,{variant:"secondary",size:"sm",onClick:()=>h(u),children:[e.jsx(_a,{size:12})," Run now"]}),e.jsx("button",{type:"button",className:"icon-btn icon-btn-danger","aria-label":"Delete",title:"Delete",onClick:()=>d(u),children:e.jsx(Ae,{size:12})})]})]}),e.jsxs("div",{className:"schedule-card-action",children:[e.jsx("span",{className:"muted",children:"action:"})," ",e.jsxs("code",{children:[u.action.type," ",u.action.target]}),u.action.type==="agent"&&u.action.prompt&&e.jsxs("div",{className:"schedule-card-prompt",children:[e.jsx("span",{className:"muted",children:"prompt:"})," ",u.action.prompt]})]}),((g=u.budgetCheck)==null?void 0:g.skipIfBudgetLow)&&e.jsxs("div",{className:"schedule-card-budget",children:[e.jsx("span",{className:"muted",children:"budget gate:"})," ","skip if concurrent ≥ ",u.budgetCheck.maxConcurrent??6]}),e.jsxs("div",{className:"schedule-card-times",children:[e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"last"})," ",u.lastRun?Ne(u.lastRun):"—",u.lastResult&&e.jsx("span",{className:`tag ${Pt(u.lastResult)}`,children:u.lastResult}),u.lastError&&e.jsxs("span",{className:"muted schedule-card-error",title:u.lastError,children:[" ","— ",Dt(u.lastError,80)]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"next"})," ",u.nextRun?e.jsx("span",{title:new Date(u.nextRun).toISOString(),children:ll(u.nextRun,u.timezone)}):"—",u.nextRun&&e.jsxs("span",{className:"muted",children:[" · ",Ne(u.nextRun)]})]})]}),u.history&&u.history.length>0&&e.jsxs("details",{className:"schedule-card-history",children:[e.jsxs("summary",{children:[e.jsx(gs,{size:12})," ",u.history.length," run",u.history.length===1?"":"s"]}),e.jsx("ul",{children:u.history.slice(-10).reverse().map((f,b)=>e.jsxs("li",{children:[e.jsx("span",{className:"tabular-nums muted",children:Ne(f.ts)})," ",e.jsx("span",{className:`tag ${Pt(f.result)}`,children:f.result}),f.error&&e.jsxs("span",{className:"muted",children:[" — ",Dt(f.error,80)]})]},b))})]})]},u.id)})})]})}function il({initial:s,onClose:t,onSubmitted:a,onError:i}){const[n,l]=r.useState(()=>sl(s)),[c,o]=r.useState(!1),p=r.useMemo(()=>ct.some(d=>d.value===n.timezone)?n.timezone:"Other…",[n.timezone]),x=(d,m)=>{l(u=>({...u,[d]:m}))},h=async d=>{d.preventDefault();const m=n.name.trim();if(!m){i("Name is required.");return}const u=al(n);if(!u.schedule){i("Schedule value is required.");return}if(!n.actionTarget.trim()){i("Action target is required.");return}const g=n.timezone==="Other…"?n.customTimezone.trim():n.timezone,f={type:n.actionType,target:n.actionTarget.trim()};n.actionType==="agent"&&n.actionPrompt.trim()&&(f.prompt=n.actionPrompt.trim());const b={name:m,type:n.type,schedule:u.schedule,timezone:g||"UTC",action:f,budgetCheck:{maxConcurrent:n.maxConcurrent,skipIfBudgetLow:n.skipIfBudgetLow},enabled:n.enabled};o(!0);try{const A=s?await w.put(`/schedules/${encodeURIComponent(s.id)}`,b):await w.post("/schedules",b);await a(A)}catch(A){i(`${s?"Update":"Create"} failed: ${A.message}`)}finally{o(!1)}};return e.jsxs("form",{className:"schedule-form",onSubmit:h,children:[e.jsx("label",{className:"field-label",htmlFor:"schedule-name",children:"Name"}),e.jsx("input",{id:"schedule-name",className:"input",type:"text",placeholder:"Weekly code review",value:n.name,onChange:d=>x("name",d.target.value),autoFocus:!0}),e.jsx("div",{className:"task-form-row",children:e.jsxs("div",{className:"task-form-field",children:[e.jsx("label",{className:"field-label",htmlFor:"schedule-type",children:"Type"}),e.jsx("select",{id:"schedule-type",className:"select",value:n.type,onChange:d=>x("type",d.target.value),children:Qr.map(d=>e.jsx("option",{value:d,children:d},d))})]})}),n.type==="cron"&&e.jsxs("div",{className:"schedule-cron-group",children:[!n.showAdvanced&&e.jsx(e.Fragment,{children:e.jsxs("div",{className:"task-form-row",children:[e.jsxs("div",{className:"task-form-field",children:[e.jsx("label",{className:"field-label",htmlFor:"schedule-dow",children:"Day of week"}),e.jsx("select",{id:"schedule-dow",className:"select",value:n.cronDow,onChange:d=>x("cronDow",d.target.value),children:Nt.map(d=>e.jsx("option",{value:d.value,children:d.label},d.value))})]}),e.jsxs("div",{className:"task-form-field",children:[e.jsx("label",{className:"field-label",htmlFor:"schedule-hour",children:"Hour"}),e.jsx("select",{id:"schedule-hour",className:"select",value:String(n.cronHour),onChange:d=>x("cronHour",parseInt(d.target.value,10)),children:kt.map(d=>e.jsx("option",{value:String(d.value),children:d.label},d.value))})]}),e.jsxs("div",{className:"task-form-field",children:[e.jsx("label",{className:"field-label",htmlFor:"schedule-minute",children:"Minute"}),e.jsx("select",{id:"schedule-minute",className:"select",value:String(n.cronMinute),onChange:d=>x("cronMinute",parseInt(d.target.value,10)),children:Jr.map(d=>e.jsx("option",{value:String(d),children:String(d).padStart(2,"0")},d))})]})]})}),n.showAdvanced&&e.jsxs("div",{className:"task-form-field",children:[e.jsx("label",{className:"field-label",htmlFor:"schedule-cron-expr",children:"Cron expression"}),e.jsx("input",{id:"schedule-cron-expr",className:"input",type:"text",value:n.rawCron,onChange:d=>x("rawCron",d.target.value),placeholder:"0 13 * * 0"})]}),e.jsxs("button",{type:"button",className:"link-btn",onClick:()=>x("showAdvanced",!n.showAdvanced),"aria-expanded":n.showAdvanced,children:[e.jsx(Fe,{size:12,style:{transform:n.showAdvanced?"rotate(180deg)":"none",transition:"transform 0.15s"}}),n.showAdvanced?"Hide advanced":"Advanced (raw cron)"]})]}),n.type==="interval"&&e.jsxs("div",{className:"task-form-row",children:[e.jsxs("div",{className:"task-form-field",style:{flex:1},children:[e.jsx("label",{className:"field-label",htmlFor:"schedule-interval-n",children:"Every"}),e.jsx("input",{id:"schedule-interval-n",className:"input",type:"number",min:1,value:n.intervalN,onChange:d=>x("intervalN",parseInt(d.target.value,10)||1)})]}),e.jsxs("div",{className:"task-form-field",style:{flex:1},children:[e.jsx("label",{className:"field-label",htmlFor:"schedule-interval-unit",children:"Unit"}),e.jsx("select",{id:"schedule-interval-unit",className:"select",value:n.intervalUnit,onChange:d=>x("intervalUnit",d.target.value),children:ia.map(d=>e.jsx("option",{value:d.value,children:d.label},d.value))})]})]}),n.type==="once"&&e.jsxs("div",{className:"task-form-field",children:[e.jsx("label",{className:"field-label",htmlFor:"schedule-once-at",children:"Run at"}),e.jsx("input",{id:"schedule-once-at",className:"input",type:"datetime-local",value:n.onceAt,onChange:d=>x("onceAt",d.target.value)})]}),e.jsxs("div",{className:"task-form-row",children:[e.jsxs("div",{className:"task-form-field",style:{flex:1},children:[e.jsx("label",{className:"field-label",htmlFor:"schedule-timezone",children:"Timezone"}),e.jsxs("select",{id:"schedule-timezone",className:"select",value:p,onChange:d=>x("timezone",d.target.value),children:[ct.map(d=>e.jsx("option",{value:d.value,children:d.label},d.value)),e.jsx("option",{value:"Other…",children:"Other…"})]})]}),n.timezone==="Other…"&&e.jsxs("div",{className:"task-form-field",style:{flex:1},children:[e.jsx("label",{className:"field-label",htmlFor:"schedule-custom-tz",children:"IANA name"}),e.jsx("input",{id:"schedule-custom-tz",className:"input",type:"text",placeholder:"Europe/Paris",value:n.customTimezone,onChange:d=>x("customTimezone",d.target.value)})]})]}),e.jsxs("div",{className:"task-form-row",children:[e.jsxs("div",{className:"task-form-field",children:[e.jsx("label",{className:"field-label",htmlFor:"schedule-action-type",children:"Action"}),e.jsx("select",{id:"schedule-action-type",className:"select",value:n.actionType,onChange:d=>x("actionType",d.target.value),children:Zr.map(d=>e.jsx("option",{value:d,children:d},d))})]}),e.jsxs("div",{className:"task-form-field",style:{flex:2},children:[e.jsx("label",{className:"field-label",htmlFor:"schedule-action-target",children:"Target"}),e.jsx("input",{id:"schedule-action-target",className:"input",type:"text",placeholder:n.actionType==="webhook"?"https://...":n.actionType==="agent"?"agent name or task ref":"echo hi",value:n.actionTarget,onChange:d=>x("actionTarget",d.target.value)})]})]}),n.actionType==="agent"&&e.jsxs("div",{className:"task-form-field",children:[e.jsx("label",{className:"field-label",htmlFor:"schedule-action-prompt",children:"Prompt (what to send the agent)"}),e.jsx("textarea",{id:"schedule-action-prompt",className:"input",rows:3,placeholder:"Review open PRs for stale code review comments and nudge reviewers.",value:n.actionPrompt,onChange:d=>x("actionPrompt",d.target.value)})]}),e.jsxs("fieldset",{className:"schedule-budget-card",children:[e.jsx("legend",{children:"Budget pre-flight"}),e.jsxs("label",{className:"checkbox-row",children:[e.jsx("input",{id:"schedule-skip-budget",type:"checkbox",checked:n.skipIfBudgetLow,onChange:d=>x("skipIfBudgetLow",d.target.checked)}),e.jsx("span",{children:"Skip this run when too many background tasks are already running."})]}),e.jsxs("div",{className:"task-form-field",children:[e.jsx("label",{className:"field-label",htmlFor:"schedule-max-concurrent",children:"Max concurrent bg tasks"}),e.jsx("input",{id:"schedule-max-concurrent",className:"input",type:"number",min:1,max:64,value:n.maxConcurrent,onChange:d=>x("maxConcurrent",parseInt(d.target.value,10)||6),disabled:!n.skipIfBudgetLow})]})]}),e.jsxs("label",{className:"checkbox-row",children:[e.jsx("input",{id:"schedule-enabled",type:"checkbox",checked:n.enabled,onChange:d=>x("enabled",d.target.checked)}),e.jsx("span",{children:"Enabled"})]}),e.jsxs("div",{className:"modal-footer-actions",children:[e.jsx(T,{variant:"ghost",type:"button",onClick:t,disabled:c,children:"Cancel"}),e.jsx(T,{variant:"primary",type:"submit",disabled:c,children:s?"Save":"Create"})]})]})}function rl(s){var l,c;if(s.type!=="cron")return s.schedule;const t=ra(s.schedule);if(!t)return s.schedule;const a=((l=Nt.find(o=>o.value===t.dow))==null?void 0:l.label)||"",i=((c=kt.find(o=>o.value===t.hour))==null?void 0:c.label)||`${t.hour}`,n=String(t.minute).padStart(2,"0");return a==="Every day"?`Every day at ${i} :${n}`:`Every ${a} at ${i} :${n}`}function ll(s,t){try{return new Date(s).toLocaleString(void 0,{timeZone:t||void 0,weekday:"long",hour:"numeric",minute:"2-digit",month:"short",day:"numeric"})}catch{return new Date(s).toLocaleString()}}function Pt(s){return s==="success"?"tag-success":s==="skipped"?"tag-warning":"tag-error"}function Dt(s,t){return s.length<=t?s:s.slice(0,t-1)+"…"}const ol=[{id:"all",label:"All",icon:Oe},{id:"shipped",label:"Shipped",icon:vt},{id:"user",label:"User",icon:sa},{id:"project",label:"Project",icon:Ee}],Ps={shipped:"Shipped",user:"User",project:"Project"},cl={shipped:vt,user:sa,project:Ee};function dl({snapshot:s,refreshSnapshot:t}){const a=oe(),i=Pe(),[n,l]=r.useState([]),[c,o]=r.useState({shipped:0,user:0,project:0,all:0}),[p,x]=r.useState(!0),[h,d]=r.useState("all"),[m,u]=r.useState(""),[g,f]=r.useState(null),[b,A]=r.useState(!1),y=async()=>{var R,P,S;x(!0);try{const q=await w.get("/skills");l(q.skills||[]),o({shipped:((R=q.counts)==null?void 0:R.shipped)??0,user:((P=q.counts)==null?void 0:P.user)??0,project:((S=q.counts)==null?void 0:S.project)??0,all:(q.skills||[]).length})}catch(q){a.error(`Skills load failed: ${q.message}`)}finally{x(!1)}};r.useEffect(()=>{y()},[]),r.useEffect(()=>{if(!m.trim()){f(null);return}A(!0);const R=setTimeout(async()=>{try{const P=await w.get(`/skills/search?q=${encodeURIComponent(m.trim())}`);f(P.results||[])}catch(P){a.error(`Search failed: ${P.message}`)}finally{A(!1)}},280);return()=>clearTimeout(R)},[m]);const v=r.useMemo(()=>g!==null?g:h==="all"?n:n.filter(R=>R.source===h),[n,h,g]),L=async()=>{try{await w.post("/skills/refresh",{}),a.success("Skills refreshed."),await y()}catch(R){a.error(`Refresh failed: ${R.message}`)}},$=async R=>{try{const P=await w.get(`/skills/${encodeURIComponent(R.source)}/${encodeURIComponent(R.name)}`);i.open({title:P.name,width:640,children:e.jsxs("div",{className:"skill-detail",children:[e.jsxs("div",{className:"skill-detail-meta",children:[e.jsx("span",{className:"skill-source-badge","data-source":P.source,children:Ps[P.source]||P.source}),e.jsx("code",{className:"mono text-sm muted",children:P.path})]}),P.description&&e.jsx("p",{className:"skill-detail-desc",children:P.description}),P.body&&e.jsx("div",{className:"skill-detail-body",children:e.jsx("pre",{className:"skill-body-pre",children:P.body})})]}),footer:e.jsx(T,{variant:"ghost",onClick:()=>i.close(),children:"Close"})})}catch{i.open({title:R.name,width:560,children:e.jsxs("div",{className:"skill-detail",children:[e.jsxs("div",{className:"skill-detail-meta",children:[e.jsx("span",{className:"skill-source-badge","data-source":R.source,children:Ps[R.source]||R.source}),e.jsx("code",{className:"mono text-sm muted",children:R.path})]}),R.description&&e.jsx("p",{className:"skill-detail-desc",children:R.description})]}),footer:e.jsx(T,{variant:"ghost",onClick:()=>i.close(),children:"Close"})})}};return e.jsxs("div",{className:"view view-skills",children:[e.jsxs("header",{className:"view-header",children:[e.jsxs("div",{className:"view-header-text",children:[e.jsxs("h2",{className:"view-title",children:[e.jsx(Oe,{size:18})," Skills"]}),e.jsx("p",{className:"view-subtitle",children:"Browse all available skills — shipped, user, and project-local."})]}),e.jsxs("div",{className:"view-actions",children:[e.jsxs("div",{className:"search-input",children:[e.jsx(ye,{size:14,"aria-hidden":!0}),e.jsx("label",{htmlFor:"skills-search",className:"sr-only",children:"Search skills"}),e.jsx("input",{id:"skills-search",className:"input",type:"text",placeholder:"Search skills…",value:m,onChange:R=>u(R.target.value),"aria-label":"Search skills"}),m&&e.jsx("button",{type:"button",className:"icon-btn","aria-label":"Clear search",onClick:()=>u(""),children:e.jsx(Ye,{size:12})})]}),e.jsxs(T,{variant:"secondary",size:"sm",onClick:L,children:[e.jsx(ce,{size:14})," Refresh"]})]})]}),!m.trim()&&e.jsx("div",{className:"skills-tabs",children:ol.map(R=>{const P=R.icon,S=R.id==="all"?c.all:c[R.id]??0;return e.jsxs("button",{type:"button",className:X("skills-tab",h===R.id&&"skills-tab-active"),onClick:()=>d(R.id),children:[e.jsx(P,{size:14}),e.jsx("span",{children:R.label}),e.jsx("span",{className:"skills-tab-count",children:S})]},R.id)})}),m.trim()&&e.jsxs("section",{className:"skills-section",children:[e.jsxs("h3",{className:"skills-section-title",children:[e.jsx(ye,{size:14})," Search results",b&&e.jsx(he,{size:"sm"})]}),b?e.jsx("div",{className:"skills-grid",children:[0,1,2].map(R=>e.jsx("div",{className:"skill-card skill-card-skeleton"},R))}):g&&g.length===0?e.jsx(we,{icon:e.jsx(ye,{size:28}),title:"No matches",message:`No skills match "${m}".`}):e.jsx("div",{className:"skills-grid",children:(g||[]).map((R,P)=>e.jsx(Ft,{skill:R,onShow:()=>$(R),searchQ:m},`search-${P}`))})]}),!m.trim()&&e.jsx("section",{className:"skills-section",children:p?e.jsx("div",{className:"view-loading",children:e.jsx(he,{size:"lg"})}):v.length===0?e.jsx(we,{icon:e.jsx(Kt,{size:28}),title:"No skills here",message:h==="all"?"No skills found. Install skills with the skills CLI or add SKILL.md files to a skills directory.":`No skills in the ${Ps[h]} tab.`}):e.jsx("div",{className:"skills-grid",children:v.map((R,P)=>e.jsx(Ft,{skill:R,onShow:()=>$(R)},`${R.source}-${R.name}-${P}`))})}),!m.trim()&&e.jsx("footer",{className:"view-footer",children:e.jsxs("span",{className:"text-sm muted",children:["Skills are discovered from"," ",e.jsx("code",{children:"~/.opencode/skills/"}),","," ",e.jsx("code",{children:"~/.agents/skills/"}),","," ",e.jsx("code",{children:"bizar-dash/skills/"}),", and project-local directories."]})})]})}function Ft({skill:s,onShow:t,searchQ:a=""}){const i=cl[s.source]||vt,n=s.description?s.description.length>200?s.description.slice(0,200)+"…":s.description:"No description.";return e.jsxs(Q,{variant:"elevated",interactive:!0,className:"skill-card",children:[e.jsxs("div",{className:"skill-card-head",children:[e.jsx("div",{className:"skill-card-icon",style:{background:"color-mix(in srgb, var(--accent) 12%, transparent)"},children:e.jsx(i,{size:18})}),e.jsxs("div",{className:"skill-card-title-area",children:[e.jsx("div",{className:"skill-card-title",children:ml(s.name,a)}),e.jsx("span",{className:"skill-source-badge","data-source":s.source,children:Ps[s.source]||s.source})]})]}),e.jsx("p",{className:"skill-card-desc",children:n}),e.jsx("div",{className:"skill-card-actions",children:e.jsxs(T,{variant:"ghost",size:"sm",onClick:t,children:[e.jsx(ls,{size:12})," View"]})})]})}function ml(s,t){if(!t.trim())return s;const a=s.toLowerCase().indexOf(t.toLowerCase());return a<0?s:e.jsxs(e.Fragment,{children:[s.slice(0,a),e.jsx("mark",{className:"skill-highlight",children:s.slice(a,a+t.length)}),s.slice(a+t.length)]})}const hl=We.memo(dl);function ul({refreshKey:s,onRefresh:t,setActiveSubPanel:a}){const i=oe(),[n,l]=r.useState(null),[c,o]=r.useState(!0),p=async g=>{o(!0);try{const[f,b,A,y]=await Promise.all([w.get("/memory/health",g).catch(()=>null),w.get("/memory/status",g).catch(()=>null),w.get("/memory/lightrag/stats",g).catch(()=>null),w.get("/memory/storage",g).catch(()=>null)]);l({health:f||{score:0,status:"unconfigured",checks:[],message:"memory not initialised"},vault:{exists:!!(b!=null&&b.initialized),vaultRoot:(b==null?void 0:b.vaultRoot)||"",mode:(b==null?void 0:b.mode)||"local-only",noteCount:(b==null?void 0:b.noteCount)||0,totalSize:(y==null?void 0:y.total)||0,folderCount:0,folders:[],lastModified:null,gitClean:(b==null?void 0:b.gitClean)??null,gitBranch:(b==null?void 0:b.branch)||null},lightrag:A||{running:!1,pid:null,host:"127.0.0.1",port:9621,indexedApprox:0,queryCountLast24h:0,lastReindexAt:null},storage:y||{total:0,breakdown:[]}})}catch(f){i.error(`Memory overview failed: ${f.message}`)}finally{o(!1)}};if(r.useEffect(()=>{const g=new AbortController;return p(g.signal),()=>g.abort()},[s]),c&&!n)return e.jsxs("div",{className:"view-loading",children:[e.jsx(he,{size:"lg"}),e.jsx("p",{children:"Loading memory overview…"})]});if(!n)return e.jsx("div",{className:"muted",children:"No memory data available."});const{health:x,vault:h,lightrag:d,storage:m}=n,u=x.score>=80?"var(--success)":x.score>=50?"var(--warning)":"var(--error)";return e.jsxs("div",{className:"memory-overview",children:[e.jsxs(Q,{variant:"elevated",className:"memory-health-hero",children:[e.jsxs("div",{className:"memory-health-score",style:{borderColor:u},children:[e.jsx("span",{className:"memory-health-score-value",style:{color:u},children:x.score}),e.jsx("span",{className:"memory-health-score-label",children:"/ 100"})]}),e.jsxs("div",{className:"memory-health-meta",children:[e.jsxs("h3",{className:"memory-health-title",children:[e.jsx(Te,{size:16}),"Memory health ·"," ",e.jsx("span",{style:{color:u},children:x.status})]}),e.jsx("p",{className:"memory-health-message",children:x.message}),e.jsxs(T,{variant:"ghost",size:"sm",onClick:t,children:[e.jsx(ce,{size:12})," Refresh"]})]})]}),e.jsxs("div",{className:"memory-source-pills",children:[e.jsxs("button",{type:"button",className:"memory-source-pill",onClick:()=>a("lightrag"),children:[e.jsx(Le,{size:14}),e.jsx("span",{children:"LightRAG"}),e.jsx("span",{className:X("memory-source-pill-status",d.running?"on":"off"),children:d.running?"running":"stopped"})]}),e.jsxs("button",{type:"button",className:"memory-source-pill",onClick:()=>a("obsidian"),children:[e.jsx(Se,{size:14}),e.jsx("span",{children:"Obsidian Vault"}),e.jsxs("span",{className:X("memory-source-pill-status",h.exists?"on":"off"),children:[h.noteCount," notes"]})]}),e.jsxs("button",{type:"button",className:"memory-source-pill",onClick:()=>a("git"),children:[e.jsx(rs,{size:14}),e.jsx("span",{children:"Git Sync"}),e.jsx("span",{className:X("memory-source-pill-status",h.gitClean===null?"na":h.gitClean?"on":"warn"),children:h.gitClean===null?"—":h.gitClean?"clean":"dirty"})]}),e.jsxs("button",{type:"button",className:"memory-source-pill",onClick:()=>a("semantic"),children:[e.jsx(ye,{size:14}),e.jsx("span",{children:"Semantic Search"}),e.jsx("span",{className:"memory-source-pill-status na",children:"cross-source"})]})]}),e.jsxs("div",{className:"memory-stat-grid",children:[e.jsx(ts,{icon:e.jsx(Le,{size:16}),label:"LightRAG",value:d.running?`running · ${d.queryCountLast24h} q/24h`:"stopped",sub:d.running?`${d.indexedApprox} indexed chunks`:"start from the LightRAG panel",onClick:()=>a("lightrag")}),e.jsx(ts,{icon:e.jsx(Se,{size:16}),label:"Obsidian",value:`${h.noteCount} notes`,sub:h.folderCount>0?`${h.folderCount} folders`:"no folders yet",onClick:()=>a("obsidian")}),e.jsx(ts,{icon:e.jsx(rs,{size:16}),label:"Git",value:h.gitBranch?`branch ${h.gitBranch}`:"local-only",sub:h.gitClean===null?"not configured":h.gitClean?"clean working tree":"dirty — commit or pull",onClick:()=>a("git")}),e.jsx(ts,{icon:e.jsx(Zt,{size:16}),label:"Storage",value:xl(m.total),sub:m.breakdown.length>0?`${m.breakdown.length} dirs tracked`:"no memory data on disk"}),e.jsx(ts,{icon:e.jsx(Oe,{size:16}),label:"Last reindex",value:d.lastReindexAt?os(d.lastReindexAt):"never",sub:"lightrag ingest",onClick:()=>a("lightrag")}),e.jsx(ts,{icon:e.jsx(bs,{size:16}),label:"Health",value:`${x.score}/100`,sub:x.status,onClick:()=>a("config")})]}),x.checks.length>0&&e.jsxs(Q,{children:[e.jsx(se,{children:"Health checks"}),e.jsx(ie,{children:"Composite score across all memory subsystems"}),e.jsx("ul",{className:"memory-check-list",children:x.checks.map(g=>e.jsxs("li",{className:"memory-check-row",children:[e.jsx("span",{className:"memory-check-icon",children:g.pass?e.jsx(He,{size:14,style:{color:"var(--success)"}}):g.name.includes("secrets")||g.name.includes("schema")?e.jsx(ke,{size:14,style:{color:"var(--warning)"}}):e.jsx(Ye,{size:14,style:{color:"var(--error)"}})}),e.jsx("span",{className:"memory-check-name",children:g.name}),e.jsx("span",{className:"memory-check-detail muted",children:g.detail})]},g.name))})]})]})}function ts({icon:s,label:t,value:a,sub:i,onClick:n}){const l=n?"button":"div";return e.jsxs(l,{type:n?"button":void 0,onClick:n,className:X("memory-stat-card",n&&"memory-stat-card-clickable"),children:[e.jsx("div",{className:"memory-stat-icon",children:s}),e.jsxs("div",{className:"memory-stat-body",children:[e.jsx("div",{className:"memory-stat-label",children:t}),e.jsx("div",{className:"memory-stat-value",children:a}),e.jsx("div",{className:"memory-stat-sub muted",children:i})]})]})}function xl(s){return s<1024?`${s} B`:s<1024*1024?`${(s/1024).toFixed(1)} KB`:s<1024*1024*1024?`${(s/(1024*1024)).toFixed(1)} MB`:`${(s/(1024*1024*1024)).toFixed(2)} GB`}function pl({refreshKey:s}){const t=oe(),[a,i]=r.useState(null),[n,l]=r.useState(null),[c,o]=r.useState([]),[p,x]=r.useState(!0),[h,d]=r.useState(null),[m,u]=r.useState(""),[g,f]=r.useState(null),b=async()=>{x(!0);try{const[S,q,O]=await Promise.all([w.get("/memory/lightrag/stats").catch(()=>null),w.get("/memory/config").then(k=>(k==null?void 0:k.lightrag)||null).catch(()=>null),w.get("/memory/lightrag/log").catch(()=>({lines:[]}))]);i(S),l(q),o((O==null?void 0:O.lines)||[])}catch(S){t.error(`LightRAG status failed: ${S.message}`)}finally{x(!1)}};r.useEffect(()=>{b()},[s]);const A=async(S,q,O)=>{d(S);try{await q(),t.success(O),await b()}catch(k){t.error(`${S} failed: ${k.message}`)}finally{d(null)}},y=()=>A("start",()=>w.post("/memory/lightrag/start",{}),"LightRAG starting…"),v=()=>A("stop",()=>w.post("/memory/lightrag/stop",{}),"LightRAG stopping…"),L=async()=>{d("restart");try{await w.post("/memory/lightrag/stop",{}).catch(()=>{}),await new Promise(S=>setTimeout(S,600)),await w.post("/memory/lightrag/start",{}),t.success("LightRAG restarted."),await b()}catch(S){t.error(`Restart failed: ${S.message}`)}finally{d(null)}},$=()=>A("reindex",()=>w.post("/memory/lightrag/reindex",{}),"Reindex complete."),R=()=>A("rebuild",()=>w.post("/memory/lightrag/rebuild-graph",{}),"Graph rebuilt."),P=async()=>{var S,q,O;if(m.trim()){d("query");try{const k=await w.get(`/memory/query?q=${encodeURIComponent(m)}&topK=8`),N=(S=k==null?void 0:k.semantic)!=null&&S.response?typeof k.semantic.response=="string"?k.semantic.response:JSON.stringify(k.semantic.response):((q=k==null?void 0:k.semantic)==null?void 0:q.error)||"No response";f({ok:!!((O=k==null?void 0:k.semantic)!=null&&O.ok),text:N})}catch(k){f({ok:!1,text:k.message})}finally{d(null)}}};return p&&!a?e.jsxs("div",{className:"view-loading",children:[e.jsx(he,{size:"lg"}),e.jsx("p",{children:"Loading LightRAG status…"})]}):a?e.jsxs("div",{className:"memory-panel-content",children:[e.jsxs(Q,{variant:"elevated",children:[e.jsxs(se,{children:[e.jsx(Le,{size:14}),"LightRAG",e.jsx("span",{className:X("memory-source-pill-status",a.running?"on":"off"),children:a.running?"running":"stopped"})]}),e.jsx(ie,{children:a.running?e.jsxs(e.Fragment,{children:["PID ",e.jsx("code",{children:a.pid})," · ",a.host,":",a.port]}):e.jsx(e.Fragment,{children:"Server is not running. Start it from the controls below."})}),e.jsxs("div",{className:"memory-action-row",children:[e.jsxs(T,{variant:"primary",size:"sm",onClick:y,disabled:!!h||a.running,children:[h==="start"?e.jsx(je,{size:12,className:"memory-spin"}):e.jsx(Ns,{size:12}),"Start"]}),e.jsxs(T,{variant:"secondary",size:"sm",onClick:v,disabled:!!h||!a.running,children:[h==="stop"?e.jsx(je,{size:12,className:"memory-spin"}):e.jsx(gn,{size:12}),"Stop"]}),e.jsxs(T,{variant:"secondary",size:"sm",onClick:L,disabled:!!h,children:[h==="restart"?e.jsx(je,{size:12,className:"memory-spin"}):e.jsx(ut,{size:12}),"Restart"]}),e.jsxs(T,{variant:"ghost",size:"sm",onClick:$,disabled:!!h,children:[h==="reindex"?e.jsx(je,{size:12,className:"memory-spin"}):e.jsx(ce,{size:12}),"Reindex all"]}),e.jsxs(T,{variant:"ghost",size:"sm",onClick:R,disabled:!!h,title:"Wipe working dir + reindex from scratch",children:[h==="rebuild"?e.jsx(je,{size:12,className:"memory-spin"}):e.jsx(xt,{size:12}),"Rebuild graph"]})]})]}),e.jsxs("div",{className:"memory-stat-grid",children:[e.jsx(ds,{icon:e.jsx(Zt,{size:14}),label:"Indexed chunks (approx)",value:String(a.indexedApprox)}),e.jsx(ds,{icon:e.jsx(gl,{n:a.noteCount}),label:"Notes in vault",value:String(a.noteCount)}),e.jsx(ds,{icon:e.jsx(yt,{size:14}),label:"Queries last 24h",value:String(a.queryCountLast24h)}),e.jsx(ds,{icon:e.jsx(Oe,{size:14}),label:"Avg response",value:a.avgResponseMs!==null?`${a.avgResponseMs} ms`:"—"}),e.jsx(ds,{icon:a.lastReindexOk?e.jsx(He,{size:14}):a.lastReindexOk===!1?e.jsx(Ye,{size:14}):e.jsx(ce,{size:14}),label:"Last reindex",value:a.lastReindexAt?os(a.lastReindexAt):"never",sub:a.lastReindexInserted!==null?`${a.lastReindexInserted} inserted${a.lastReindexFailed?`, ${a.lastReindexFailed} failed`:""}`:void 0})]}),e.jsxs(Q,{children:[e.jsxs(se,{children:[e.jsx(ye,{size:14})," Quick search"]}),e.jsx(ie,{children:"Send a natural-language query to the LightRAG index."}),e.jsxs("div",{className:"memory-search-row",children:[e.jsx("label",{htmlFor:"lightrag-query",className:"sr-only",children:"Search LightRAG"}),e.jsx("input",{id:"lightrag-query",type:"text",className:"input",placeholder:"e.g. how does the memory service write notes?",value:m,onChange:S=>u(S.target.value),onKeyDown:S=>{S.key==="Enter"&&P()},disabled:h==="query","aria-label":"Search LightRAG"}),e.jsxs(T,{variant:"primary",onClick:P,disabled:h==="query"||!m.trim(),children:[h==="query"?e.jsx(je,{size:12,className:"memory-spin"}):e.jsx(ye,{size:12}),"Query"]})]}),g&&e.jsx("div",{className:X("memory-query-result",g.ok?"ok":"err"),children:e.jsx("pre",{className:"mono text-sm",children:g.text})})]}),n&&e.jsxs(Q,{children:[e.jsx(se,{children:"Configuration"}),e.jsxs(ie,{children:["Effective values from ",e.jsx("code",{children:".bizar/memory.json"})," + env defaults."]}),e.jsxs("dl",{className:"memory-config-row",children:[e.jsx("dt",{children:"LLM binding"}),e.jsxs("dd",{children:[e.jsx("code",{children:n.llmBinding})," · ",e.jsx("code",{children:n.llmModel})]}),e.jsx("dt",{children:"Embedding"}),e.jsxs("dd",{children:[e.jsx("code",{children:n.embeddingBinding})," · ",e.jsx("code",{children:n.embeddingModel})]}),e.jsx("dt",{children:"Host"}),e.jsx("dd",{children:e.jsxs("code",{children:[n.host,":",n.port]})}),e.jsx("dt",{children:"Working dir"}),e.jsx("dd",{className:"mono ellipsis",title:n.workingDir,children:n.workingDir})]})]}),c.length>0&&e.jsxs(Q,{children:[e.jsxs(se,{children:[e.jsx(ce,{size:14})," Server log (tail)"]}),e.jsxs(ie,{children:["Last ",c.length," lines from ",e.jsx("code",{children:"lightrag.log"})]}),e.jsx("pre",{className:"memory-log-tail mono text-xs",children:c.join(`
357
+ `)})]})]}):e.jsx("div",{className:"muted",children:"No LightRAG data available."})}function ds({icon:s,label:t,value:a,sub:i}){return e.jsxs("div",{className:"memory-stat-card",children:[e.jsx("div",{className:"memory-stat-icon",children:s}),e.jsxs("div",{className:"memory-stat-body",children:[e.jsx("div",{className:"memory-stat-label",children:t}),e.jsx("div",{className:"memory-stat-value",children:a}),i&&e.jsx("div",{className:"memory-stat-sub muted",children:i})]})]})}function gl({n:s}){return e.jsxs("span",{style:{position:"relative",display:"inline-block"},children:[e.jsx(ye,{size:14}),e.jsx("span",{className:"memory-mini-badge",children:s})]})}function jl({refreshKey:s}){const t=oe(),a=Pe(),[i,n]=r.useState([]),[l,c]=r.useState(null),[o,p]=r.useState(!0),[x,h]=r.useState(""),[d,m]=r.useState(null),[u,g]=r.useState(!1),[f,b]=r.useState(null),[A,y]=r.useState([]),v=async()=>{var O;p(!0);try{const[k,N]=await Promise.all([w.get("/memory/notes").catch(()=>({notes:[]})),w.get("/memory/obsidian/tree").catch(()=>({tree:null}))]);n(k.notes||[]),c(N.tree),f&&!((O=k.notes)!=null&&O.find(D=>D.relPath===f))&&(b(null),y([]))}catch(k){t.error(`Vault load failed: ${k.message}`)}finally{p(!1)}};r.useEffect(()=>{v()},[s]),r.useEffect(()=>{if(!x.trim()){m(null);return}g(!0);const O=setTimeout(async()=>{try{const k=await w.get(`/memory/search?q=${encodeURIComponent(x)}&limit=50`),N=new Set((k.results||[]).map(D=>D.relPath));m(i.filter(D=>N.has(D.relPath)))}catch(k){t.error(`Search failed: ${k.message}`)}finally{g(!1)}},240);return()=>clearTimeout(O)},[x,i,t]);const L=async O=>{b(O);try{const k=await w.get(`/memory/obsidian/backlinks?note=${encodeURIComponent(O)}`);y(k.backlinks||[])}catch{y([])}},$=()=>{a.open({title:"New note",width:720,children:e.jsx(Ot,{mode:"create",onSave:async(O,k,N)=>{try{await w.post("/memory/notes",{path:O,frontmatter:k,body:N}),t.success(`Created ${O}.`),a.close(),await v(),L(O)}catch(D){t.error(`Create failed: ${D.message}`)}},onCancel:()=>a.close()})})},R=async O=>{try{const k=await w.get(`/memory/notes/${O.split("/").map(encodeURIComponent).join("/")}`);a.open({title:`Edit ${O}`,width:720,children:e.jsx(Ot,{mode:"edit",initial:{relPath:k.relPath,frontmatter:k.frontmatter,body:k.body},onSave:async(N,D,j)=>{try{await w.put(`/memory/notes/${N.split("/").map(encodeURIComponent).join("/")}`,{frontmatter:D,body:j}),t.success(`Saved ${N}.`),a.close(),await v(),L(N)}catch(M){t.error(`Save failed: ${M.message}`)}},onCancel:()=>a.close()})})}catch(k){t.error(`Load failed: ${k.message}`)}},P=async O=>{if(confirm(`Delete ${O}? This cannot be undone.`))try{await w.del(`/memory/notes/${O.split("/").map(encodeURIComponent).join("/")}`),t.success(`Deleted ${O}.`),f===O&&b(null),await v()}catch(k){t.error(`Delete failed: ${k.message}`)}},S=r.useMemo(()=>[...i].sort((O,k)=>k.mtime-O.mtime),[i]),q=d??S;return o&&!i.length?e.jsxs("div",{className:"view-loading",children:[e.jsx(he,{size:"lg"}),e.jsx("p",{children:"Loading vault…"})]}):e.jsxs("div",{className:"memory-panel-content memory-obsidian-grid",children:[e.jsxs(Q,{variant:"outlined",className:"memory-tree-card",children:[e.jsxs(se,{children:[e.jsx(Ee,{size:14})," Folders"]}),e.jsx(ie,{children:l?`${ca(l)} folder(s)`:"no vault"}),e.jsx("div",{className:"memory-tree-body",children:l?e.jsx(oa,{node:l,depth:0,onSelect:L,selected:f}):null})]}),e.jsxs("div",{className:"memory-obsidian-list-col",children:[e.jsxs("div",{className:"memory-list-toolbar",children:[e.jsxs("div",{className:"search-input",children:[e.jsx(ye,{size:14,"aria-hidden":!0}),e.jsx("label",{htmlFor:"obsidian-search",className:"sr-only",children:"Search notes"}),e.jsx("input",{id:"obsidian-search",type:"text",className:"input",placeholder:"Search notes…",value:x,onChange:O=>h(O.target.value),"aria-label":"Search notes"}),x&&e.jsx("button",{type:"button",className:"icon-btn",onClick:()=>h(""),"aria-label":"Clear search",children:e.jsx($e,{size:12})})]}),e.jsxs(T,{variant:"primary",size:"sm",onClick:$,children:[e.jsx(Xa,{size:12})," New note"]}),e.jsx(T,{variant:"ghost",size:"sm",onClick:v,title:"Refresh",children:e.jsx(ce,{size:12})})]}),u&&e.jsx("div",{className:"muted text-sm",children:"Searching…"}),q.length===0?e.jsx(we,{icon:e.jsx(Se,{size:28}),title:"No notes",message:i.length===0?'No notes in this vault yet. Click "New note" to create one.':`No notes match "${x}".`}):e.jsx("ul",{className:"memory-note-list",children:q.map(O=>e.jsxs("li",{className:X("memory-note-card",f===O.relPath&&"memory-note-card-active"),children:[e.jsxs("button",{type:"button",className:"memory-note-card-main",onClick:()=>L(O.relPath),children:[e.jsxs("div",{className:"memory-note-card-title",children:[e.jsx(Se,{size:12}),e.jsx("span",{children:la(O)})]}),e.jsxs("div",{className:"memory-note-card-meta",children:[e.jsx("code",{className:"muted",children:O.relPath}),e.jsxs("span",{className:"muted",children:["· ",Ne(O.mtime)]}),!O.schemaValid&&e.jsx("span",{className:"memory-pill-warn",children:"schema"})]})]}),e.jsxs("div",{className:"memory-note-card-actions",children:[e.jsx("button",{type:"button",className:"icon-btn",onClick:()=>R(O.relPath),"aria-label":`Edit ${O.relPath}`,title:"Edit",children:e.jsx(ks,{size:12})}),e.jsx("button",{type:"button",className:"icon-btn",onClick:()=>P(O.relPath),"aria-label":`Delete ${O.relPath}`,title:"Delete",children:e.jsx(Ae,{size:12})})]})]},O.relPath))})]}),e.jsx("div",{className:"memory-obsidian-detail-col",children:f?e.jsx(fl,{relPath:f,onClose:()=>b(null)}):e.jsx(we,{icon:e.jsx(Se,{size:28}),title:"Pick a note",message:"Select a note from the list to view its content, frontmatter, and backlinks."})})]})}function la(s){var a;const t=(a=s.frontmatter)==null?void 0:a.title;return typeof t=="string"&&t.trim()?t:s.relPath.replace(/\.md$/i,"")}function oa({node:s,depth:t,onSelect:a,selected:i}){const[n,l]=r.useState(t<2);return s.type==="note"?e.jsxs("button",{type:"button",className:X("memory-tree-node memory-tree-node-note",i===s.path&&"memory-tree-node-active"),style:{paddingLeft:6+t*12},onClick:()=>a(s.path),children:[e.jsx(Se,{size:11}),e.jsx("span",{children:s.name})]}):e.jsxs("div",{className:"memory-tree-folder",children:[e.jsxs("button",{type:"button",className:"memory-tree-node memory-tree-node-folder",style:{paddingLeft:6+t*12},onClick:()=>l(c=>!c),children:[n?e.jsx(Fe,{size:11}):e.jsx(_e,{size:11}),e.jsx(Ee,{size:11}),e.jsx("span",{children:s.name||"vault"}),s.children&&s.children.length>0&&e.jsx("span",{className:"muted text-xs",children:s.children.length})]}),n&&s.children&&e.jsx("div",{className:"memory-tree-children",children:s.children.map((c,o)=>e.jsx(oa,{node:c,depth:t+1,onSelect:a,selected:i},`${c.path}-${o}`))})]})}function ca(s){return s.type==="note"?0:1+(s.children||[]).reduce((t,a)=>t+ca(a),0)}function fl({relPath:s,onClose:t}){var h,d;const[a,i]=r.useState(null),[n,l]=r.useState([]),[c,o]=r.useState(!0);if(r.useEffect(()=>{let m=!1;return o(!0),(async()=>{try{const[u,g]=await Promise.all([w.get(`/memory/notes/${s.split("/").map(encodeURIComponent).join("/")}`),w.get(`/memory/obsidian/backlinks?note=${encodeURIComponent(s)}`)]);if(m)return;i(u),l(g.backlinks||[])}catch{m||i(null)}finally{m||o(!1)}})(),()=>{m=!0}},[s]),c)return e.jsx("div",{className:"view-loading",children:e.jsx(he,{size:"sm"})});if(!a)return e.jsx("div",{className:"muted",children:"Note not found."});const p=Array.isArray((h=a.frontmatter)==null?void 0:h.tags)?a.frontmatter.tags:[],x=Array.isArray((d=a.frontmatter)==null?void 0:d.links)?a.frontmatter.links:[];return e.jsxs("div",{className:"memory-note-detail",children:[e.jsxs("div",{className:"memory-note-detail-head",children:[e.jsx("h3",{children:la(a)}),e.jsx("button",{type:"button",className:"icon-btn",onClick:t,"aria-label":"Close",children:e.jsx($e,{size:12})})]}),e.jsxs("div",{className:"memory-note-detail-meta",children:[e.jsx("code",{children:s}),e.jsxs("span",{className:"muted",children:["· modified ",os(a.mtime)]})]}),p.length>0&&e.jsx("div",{className:"memory-tag-row",children:p.map((m,u)=>e.jsx("span",{className:"memory-tag",children:String(m)},u))}),e.jsx("pre",{className:"memory-note-body mono text-sm",children:a.body}),n.length>0&&e.jsxs("div",{className:"memory-backlinks",children:[e.jsx("h4",{children:"Backlinks"}),e.jsx("ul",{children:n.map(m=>e.jsxs("li",{children:[e.jsx("code",{children:m.fromRelPath}),e.jsx("p",{className:"muted text-sm",children:m.snippet})]},m.fromRelPath))})]}),x.length>0&&e.jsxs("div",{className:"memory-backlinks",children:[e.jsx("h4",{children:"Forward links"}),e.jsx("ul",{children:x.map((m,u)=>e.jsx("li",{children:e.jsx("code",{children:String(m)})},u))})]})]})}function Ot({mode:s,initial:t,onSave:a,onCancel:i}){const[n,l]=r.useState((t==null?void 0:t.relPath)||"untitled.md"),[c,o]=r.useState(t!=null&&t.frontmatter?vl(t.frontmatter):`title: ""
358
+ tags: []
359
+ `),[p,x]=r.useState((t==null?void 0:t.body)||""),[h,d]=r.useState(!1),m=oe(),u=async()=>{if(!n.endsWith(".md")){m.error("Path must end in .md");return}let g;try{g=yl(c)||{}}catch(f){m.error(`Frontmatter parse failed: ${f.message}`);return}d(!0);try{await a(n,g,p)}finally{d(!1)}};return e.jsxs("div",{className:"memory-editor-modal",children:[e.jsx("label",{className:"field-label",htmlFor:"obsidian-note-path",children:"Path"}),e.jsx("input",{id:"obsidian-note-path",type:"text",className:"input mono",value:n,onChange:g=>l(g.target.value),disabled:s==="edit",placeholder:"notes/example.md"}),e.jsx("label",{className:"field-label",htmlFor:"obsidian-note-frontmatter",style:{marginTop:12},children:"Frontmatter (YAML)"}),e.jsx("textarea",{id:"obsidian-note-frontmatter",className:"memory-editor-textarea mono text-sm",rows:6,value:c,onChange:g=>o(g.target.value),"aria-label":"Frontmatter YAML"}),e.jsx("label",{className:"field-label",htmlFor:"obsidian-note-body",style:{marginTop:12},children:"Body (Markdown)"}),e.jsx("textarea",{id:"obsidian-note-body",className:"memory-editor-textarea mono text-sm",rows:14,value:p,onChange:g=>x(g.target.value),"aria-label":"Body markdown"}),e.jsxs("div",{className:"modal-footer-actions",style:{marginTop:12},children:[e.jsx(T,{variant:"ghost",onClick:i,disabled:h,children:"Cancel"}),e.jsxs(T,{variant:"primary",onClick:u,disabled:h,children:[h&&e.jsx(je,{size:12,className:"memory-spin"}),s==="create"?"Create":"Save"]})]})]})}function vl(s){const t=[];for(const[a,i]of Object.entries(s))if(i!=null)if(Array.isArray(i)){if(i.length===0){t.push(`${a}: []`);continue}t.push(`${a}:`);for(const n of i)t.push(` - ${et(n)}`)}else if(typeof i=="object"){t.push(`${a}:`);for(const[n,l]of Object.entries(i))t.push(` ${n}: ${et(l)}`)}else t.push(`${a}: ${et(i)}`);return t.join(`
360
+ `)}function et(s){return typeof s=="string"?/[:#\n"']/.test(s)||s===""?JSON.stringify(s):s:typeof s=="number"||typeof s=="boolean"?String(s):JSON.stringify(s)}function yl(s){const t={},a=s.split(/\r?\n/);let i=0;for(;i<a.length;){const n=a[i];if(!n.trim()||n.trim().startsWith("#")){i++;continue}const l=n.match(/^([A-Za-z_][\w-]*):\s*(.*)$/);if(!l){i++;continue}const[,c,o]=l;if(o===""){const p={},x=[];let h=!1,d=!1;for(;i+1<a.length;){const m=a[i+1];if(!m.startsWith(" "))break;if(m.startsWith(" - "))h=!0,x.push(st(m.slice(4))),i++;else{d=!0;const u=m.match(/^ ([A-Za-z_][\w-]*):\s*(.*)$/);u&&(p[u[1]]=st(u[2])),i++}}t[c]=h&&!d?x:d?p:{}}else t[c]=st(o);i++}return t}function st(s){const t=s.trim();return t===""?"":t==="true"?!0:t==="false"?!1:t==="null"||t==="~"?null:/^-?\d+$/.test(t)?parseInt(t,10):/^-?\d+\.\d+$/.test(t)?parseFloat(t):t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'")?t.slice(1,-1):t}function bl({refreshKey:s}){var v,L,$,R;const t=oe(),[a,i]=r.useState(null),[n,l]=r.useState(null),[c,o]=r.useState(!0),[p,x]=r.useState(null),[h,d]=r.useState(null),m=async()=>{var P;o(!0);try{const[S,q,O]=await Promise.all([w.get("/memory/git/status").catch(()=>null),w.get("/memory/git/diff").catch(()=>null),w.get("/memory/config/global").catch(()=>null)]);i(S),l(q),d(((P=O==null?void 0:O.config)==null?void 0:P.git)||null)}catch(S){t.error(`Git status failed: ${S.message}`)}finally{o(!1)}};r.useEffect(()=>{m()},[s]);const u=async(P,S,q)=>{x(P);try{await S(),t.success(q),await m()}catch(O){t.error(`${P} failed: ${O.message}`)}finally{x(null)}},g=()=>u("pull",()=>w.post("/memory/git/pull",{}),"Pull complete."),f=()=>u("push",()=>w.post("/memory/git/push",{}),"Push complete."),b=()=>{const P=prompt("Commit message:",`[memory-sync] ${new Date().toISOString().slice(0,10)} vault sync`);P&&u("commit",()=>w.post("/memory/git/commit",{message:P}),"Committed.")},A=()=>u("fetch",()=>w.post("/memory/git/sync",{push:!1}),"Fetch complete.");if(c&&!a)return e.jsxs("div",{className:"view-loading",children:[e.jsx(he,{size:"lg"}),e.jsx("p",{children:"Loading git status…"})]});if(!a)return e.jsx("div",{className:"muted",children:"No git data available."});const y=a.mode==="local-only";return e.jsxs("div",{className:"memory-panel-content",children:[e.jsxs(Q,{variant:"elevated",children:[e.jsxs(se,{children:[e.jsx(rs,{size:14})," Git sync",y?e.jsx("span",{className:"memory-source-pill-status na",children:"local-only"}):e.jsx("span",{className:X("memory-source-pill-status",a.clean?"on":"warn"),children:a.clean?"clean":"dirty"})]}),e.jsx(ie,{children:y?"Memory is in local-only mode. Configure a shared repo in Settings → Memory to enable git sync.":e.jsxs(e.Fragment,{children:["Branch ",e.jsx("code",{children:a.branch||"—"}),a.ahead?e.jsxs(e.Fragment,{children:[" · ahead ",a.ahead]}):null,a.behind?e.jsxs(e.Fragment,{children:[" · behind ",a.behind]}):null]})}),!y&&e.jsxs("div",{className:"memory-git-status-row",children:[e.jsx(ms,{ok:a.clean??!1,label:"Working tree"}),e.jsx(ms,{ok:(a.ahead??0)===0,label:`Ahead: ${a.ahead??0}`}),e.jsx(ms,{ok:(a.behind??0)===0,label:`Behind: ${a.behind??0}`}),e.jsx(ms,{ok:(((v=a.modified)==null?void 0:v.length)??0)===0,label:`Modified: ${((L=a.modified)==null?void 0:L.length)??0}`}),e.jsx(ms,{ok:((($=a.untracked)==null?void 0:$.length)??0)===0,label:`Untracked: ${((R=a.untracked)==null?void 0:R.length)??0}`})]}),e.jsxs("div",{className:"memory-action-row",children:[e.jsxs(T,{variant:"secondary",size:"sm",onClick:g,disabled:!!p||y,children:[p==="pull"?e.jsx(je,{size:12,className:"memory-spin"}):e.jsx(Yt,{size:12}),"Pull"]}),e.jsxs(T,{variant:"secondary",size:"sm",onClick:f,disabled:!!p||y,children:[p==="push"?e.jsx(je,{size:12,className:"memory-spin"}):e.jsx(gt,{size:12}),"Push"]}),e.jsxs(T,{variant:"secondary",size:"sm",onClick:b,disabled:!!p||y,children:[p==="commit"?e.jsx(je,{size:12,className:"memory-spin"}):e.jsx(tn,{size:12}),"Commit"]}),e.jsxs(T,{variant:"ghost",size:"sm",onClick:A,disabled:!!p||y,children:[p==="fetch"?e.jsx(je,{size:12,className:"memory-spin"}):e.jsx(nn,{size:12}),"Fetch + sync"]}),e.jsxs(T,{variant:"ghost",size:"sm",onClick:m,disabled:!!p,children:[e.jsx(ce,{size:12})," Refresh"]})]})]}),h&&e.jsxs(Q,{children:[e.jsxs(se,{children:[e.jsx(Ea,{size:14})," Repository"]}),e.jsxs(ie,{children:["Snapshot of ",e.jsx("code",{children:"~/.config/bizar/memory-config.json"})," → git block."]}),e.jsxs("dl",{className:"memory-config-row",children:[e.jsx("dt",{children:"Path"}),e.jsx("dd",{className:"mono ellipsis",title:h.repoPath,children:h.repoPath||"—"}),e.jsx("dt",{children:"Remote"}),e.jsx("dd",{className:"mono ellipsis",title:h.remoteUrl,children:h.remoteUrl||"—"}),e.jsx("dt",{children:"Branch"}),e.jsx("dd",{children:e.jsx("code",{children:h.branch||"main"})}),e.jsx("dt",{children:"Auto-sync"}),e.jsx("dd",{children:h.autoSync?"enabled":"disabled"})]})]}),e.jsxs(Q,{children:[e.jsxs(se,{children:[e.jsx(an,{size:14})," Working-tree diff"]}),e.jsx(ie,{children:n!=null&&n.hasDiff?`${n.files.length} file(s) changed`:"no working-tree changes"}),n&&n.files.length>0&&e.jsx("ul",{className:"memory-diff-files",children:n.files.map(P=>e.jsx("li",{children:e.jsx("code",{children:P})},P))}),n&&n.lines.length>1&&e.jsx("pre",{className:"memory-log-tail mono text-xs",children:n.lines.slice(0,400).join(`
361
+ `)})]})]})}function ms({ok:s,label:t}){return e.jsxs("span",{className:X("memory-git-status-pill",s?"ok":"warn"),children:[s?e.jsx(He,{size:11}):e.jsx(je,{size:11,className:"memory-spin"}),t]})}function kl({refreshKey:s}){const t=oe(),[a,i]=r.useState(""),[n,l]=r.useState({lightrag:!0,obsidian:!0}),[c,o]=r.useState(null),[p,x]=r.useState(!1),[h,d]=r.useState(""),m=async g=>{if(g.trim()){x(!0),d(g);try{const f=[...n.lightrag?["lightrag"]:[],...n.obsidian?["obsidian"]:[]],b=await w.post("/memory/semantic-search",{query:g,limit:20,sources:f});o(b.results||[])}catch(f){t.error(`Search failed: ${f.message}`),o([])}finally{x(!1)}}};r.useEffect(()=>{h&&m(h)},[n]),r.useEffect(()=>{h&&m(h)},[s]);const u=r.useMemo(()=>{const g=(c||[]).filter(b=>b.source==="obsidian"),f=(c||[]).filter(b=>b.source==="lightrag");return{obs:g,lr:f}},[c]);return e.jsxs("div",{className:"memory-panel-content",children:[e.jsxs(Q,{variant:"elevated",children:[e.jsxs(se,{children:[e.jsx(ye,{size:14})," Semantic search"]}),e.jsx(ie,{children:"Query both LightRAG (graph-based) and the Obsidian vault in one shot."}),e.jsxs("div",{className:"memory-search-row",children:[e.jsx("label",{htmlFor:"semantic-search-input",className:"sr-only",children:"Semantic search"}),e.jsx("input",{id:"semantic-search-input",type:"text",className:"input",placeholder:"e.g. how are notes indexed?",value:a,onChange:g=>i(g.target.value),onKeyDown:g=>{g.key==="Enter"&&m(a)},disabled:p,"aria-label":"Semantic search query"}),e.jsxs(T,{variant:"primary",onClick:()=>m(a),disabled:p||!a.trim(),children:[p?e.jsx(je,{size:12,className:"memory-spin"}):e.jsx(ye,{size:12}),"Search"]})]}),e.jsxs("div",{className:"memory-source-toggle-row",children:[e.jsx(Bt,{active:n.obsidian,onToggle:()=>l(g=>({...g,obsidian:!g.obsidian})),label:"Obsidian",icon:e.jsx(Se,{size:11})}),e.jsx(Bt,{active:n.lightrag,onToggle:()=>l(g=>({...g,lightrag:!g.lightrag})),label:"LightRAG",icon:e.jsx(Le,{size:11})}),a&&e.jsx("button",{type:"button",className:"icon-btn",onClick:()=>{i(""),o(null),d("")},"aria-label":"Clear",children:e.jsx($e,{size:12})})]})]}),p&&e.jsx("div",{className:"view-loading",children:e.jsx(he,{size:"md"})}),!p&&c&&c.length===0&&e.jsx(we,{icon:e.jsx(ye,{size:28}),title:"No matches",message:`Nothing in scope matched "${h}".`}),u.obs.length>0&&e.jsxs(Q,{children:[e.jsxs(se,{children:[e.jsx(Se,{size:14})," Obsidian (",u.obs.length,")"]}),e.jsx("ul",{className:"memory-search-result-list",children:u.obs.map((g,f)=>e.jsxs("li",{className:"memory-search-result",children:[e.jsxs("div",{className:"memory-search-result-head",children:[e.jsx("code",{children:g.relPath}),e.jsxs("span",{className:"muted text-xs",children:["score ",g.score.toFixed(1)]})]}),e.jsx("p",{className:"muted text-sm",children:g.snippet})]},`obs-${f}`))})]}),u.lr.length>0&&e.jsxs(Q,{children:[e.jsxs(se,{children:[e.jsx(Le,{size:14})," LightRAG (",u.lr.length,")"]}),e.jsx("div",{className:"memory-search-result-list",children:u.lr.map((g,f)=>e.jsxs("div",{className:"memory-search-result",children:[e.jsxs("div",{className:"memory-search-result-head",children:[e.jsxs("span",{className:"memory-source-pill",children:[e.jsx(Le,{size:11})," LightRAG"]}),g.error&&e.jsxs("span",{className:"muted text-xs",children:["error: ",g.error]})]}),e.jsx("p",{className:"text-sm",children:g.snippet})]},`lr-${f}`))})]})]})}function Bt({active:s,onToggle:t,label:a,icon:i}){return e.jsxs("button",{type:"button",className:X("memory-toggle-chip",s&&"memory-toggle-chip-active"),onClick:t,"aria-pressed":s,children:[i,e.jsx("span",{children:a})]})}function Nl({refreshKey:s}){var b,A,y,v,L,$,R,P,S,q,O,k;const t=oe(),[a,i]=r.useState(null),[n,l]=r.useState(!0),[c,o]=r.useState(!1),[p,x]=r.useState(null),[h,d]=r.useState(!1),m=async()=>{l(!0);try{const N=await w.get("/memory/config/global");i(N.config)}catch(N){t.error(`Config load failed: ${N.message}`)}finally{l(!1)}};r.useEffect(()=>{m()},[s]);const u=(N,D,j)=>{i(M=>M&&{...M,[N]:{...M[N]||{},[D]:j}})},g=async()=>{if(a){o(!0);try{await w.put("/memory/config/global",a),t.success("Config saved.")}catch(N){t.error(`Save failed: ${N.message}`)}finally{o(!1)}}},f=async()=>{d(!0);try{const N=await w.post("/memory/test-git",{});x(N.checks)}catch(N){t.error(`Test failed: ${N.message}`)}finally{d(!1)}};return n&&!a?e.jsxs("div",{className:"view-loading",children:[e.jsx(he,{size:"md"}),e.jsx("p",{children:"Loading config…"})]}):a?e.jsxs("div",{className:"memory-panel-content",children:[e.jsxs(Q,{children:[e.jsxs(se,{children:[e.jsx(Le,{size:14})," LightRAG"]}),e.jsxs(ie,{children:["URL + model overrides. Server-side defaults from ",e.jsx("code",{children:"opencode Zen free tier"}),"."]}),e.jsxs("div",{className:"memory-config-form",children:[e.jsx(Ue,{label:"Enabled",inline:!0,children:e.jsxs("label",{className:"memory-switch",children:[e.jsx("input",{type:"checkbox",checked:!!((b=a.lightrag)!=null&&b.enabled),onChange:N=>u("lightrag","enabled",N.target.checked)}),e.jsx("span",{children:(A=a.lightrag)!=null&&A.enabled?"on":"off"})]})}),e.jsx(Ue,{label:"URL",children:e.jsx("input",{type:"text",className:"input mono",value:((y=a.lightrag)==null?void 0:y.url)||"",onChange:N=>u("lightrag","url",N.target.value),placeholder:"http://127.0.0.1:9621"})}),e.jsx(Ue,{label:"LLM model",children:e.jsx("input",{type:"text",className:"input mono",value:((v=a.lightrag)==null?void 0:v.llm)||"",onChange:N=>u("lightrag","llm",N.target.value),placeholder:"opencode/gpt-5-nano"})}),e.jsx(Ue,{label:"Embedding",children:e.jsx("input",{type:"text",className:"input mono",value:((L=a.lightrag)==null?void 0:L.embedding)||"",onChange:N=>u("lightrag","embedding",N.target.value),placeholder:"opencode/text-embedding-3-small"})})]})]}),e.jsxs(Q,{children:[e.jsxs(se,{children:[e.jsx(Se,{size:14})," Obsidian vault"]}),e.jsx(ie,{children:"Path + sync cadence for the markdown vault."}),e.jsxs("div",{className:"memory-config-form",children:[e.jsx(Ue,{label:"Vault path",children:e.jsx("input",{type:"text",className:"input mono",value:(($=a.obsidian)==null?void 0:$.vaultPath)||"",onChange:N=>u("obsidian","vaultPath",N.target.value),placeholder:"/home/me/vault"})}),e.jsx(Ue,{label:"Sync interval (seconds)",children:e.jsx("input",{type:"number",min:0,max:2592e3,className:"input mono",value:((R=a.obsidian)==null?void 0:R.syncInterval)??300,onChange:N=>u("obsidian","syncInterval",Number(N.target.value))})})]})]}),e.jsxs(Q,{children:[e.jsxs(se,{children:[e.jsx(rs,{size:14})," Git sync"]}),e.jsx(ie,{children:"Repo path, remote, branch, and auto-sync toggle."}),e.jsxs("div",{className:"memory-config-form",children:[e.jsx(Ue,{label:"Repo path",children:e.jsx("input",{type:"text",className:"input mono",value:((P=a.git)==null?void 0:P.repoPath)||"",onChange:N=>u("git","repoPath",N.target.value),placeholder:"/path/to/repo"})}),e.jsx(Ue,{label:"Remote URL",children:e.jsx("input",{type:"text",className:"input mono",value:((S=a.git)==null?void 0:S.remoteUrl)||"",onChange:N=>u("git","remoteUrl",N.target.value),placeholder:"git@github.com:org/repo.git"})}),e.jsx(Ue,{label:"Branch",children:e.jsx("input",{type:"text",className:"input mono",value:((q=a.git)==null?void 0:q.branch)||"main",onChange:N=>u("git","branch",N.target.value),placeholder:"main"})}),e.jsx(Ue,{label:"Auto-sync",inline:!0,children:e.jsxs("label",{className:"memory-switch",children:[e.jsx("input",{type:"checkbox",checked:!!((O=a.git)!=null&&O.autoSync),onChange:N=>u("git","autoSync",N.target.checked)}),e.jsx("span",{children:(k=a.git)!=null&&k.autoSync?"on":"off"})]})})]})]}),e.jsxs(Q,{children:[e.jsxs(se,{children:[e.jsx(Oe,{size:14})," CCR (Compress-Cache-Retrieve)"]}),e.jsx(ie,{children:"Reversible compression for very long conversations. Enabled automatically when the Headroom mod is installed."}),e.jsx("div",{className:"muted text-sm",children:"See Settings → Headroom for CCR configuration. This panel will surface retention + compression-ratio controls when the mod is active."})]}),e.jsxs(Q,{children:[e.jsxs(se,{children:[e.jsx(rt,{size:14})," Connection tests"]}),e.jsx(ie,{children:"Verify the configured git repo, remote, and path."}),e.jsxs("div",{className:"memory-action-row",children:[e.jsxs(T,{variant:"secondary",onClick:f,disabled:h,children:[h?e.jsx(je,{size:12,className:"memory-spin"}):e.jsx(rt,{size:12}),"Test git connection"]}),e.jsxs(T,{variant:"primary",onClick:g,disabled:c,children:[c?e.jsx(je,{size:12,className:"memory-spin"}):e.jsx(vs,{size:12}),"Save config"]})]}),p&&p.length>0&&e.jsx("ul",{className:"memory-check-list",style:{marginTop:12},children:p.map((N,D)=>e.jsxs("li",{className:"memory-check-row",children:[e.jsx("span",{className:"memory-check-icon",children:e.jsx("span",{className:X("memory-pill",N.pass?"memory-pill-ok":"memory-pill-warn"),children:N.pass?"OK":"FAIL"})}),e.jsx("span",{className:"memory-check-name",children:N.name}),e.jsx("span",{className:"memory-check-detail muted",children:N.detail})]},D))})]})]}):e.jsx("div",{className:"muted",children:"No config available."})}function Ue({label:s,children:t,inline:a}){return a?e.jsxs("div",{className:"memory-config-row-inline",children:[e.jsx("div",{className:"memory-config-row-label",id:`cfg-${s.replace(/\s+/g,"-").toLowerCase()}`,children:s}),e.jsx("div",{className:"memory-config-row-control",role:"group","aria-labelledby":`cfg-${s.replace(/\s+/g,"-").toLowerCase()}`,children:t})]}):e.jsxs("label",{className:"memory-config-row-stack",children:[e.jsx("span",{children:s}),t]})}const wl=[{id:"overview",label:"Overview",icon:Jt},{id:"lightrag",label:"LightRAG",icon:Le},{id:"obsidian",label:"Obsidian Vault",icon:Se},{id:"git",label:"Git Sync",icon:rs},{id:"semantic",label:"Semantic Search",icon:ye},{id:"config",label:"Config",icon:mt}];function Sl(s){const t=oe(),[a,i]=r.useState("overview"),[n,l]=r.useState(0),c=r.useCallback(()=>{l(x=>x+1)},[]),o=r.useCallback(async()=>{c(),t.info("Refreshing memory…",1200)},[c,t]),p=()=>{switch(a){case"overview":return e.jsx(ul,{refreshKey:n,onRefresh:c,setActiveSubPanel:i});case"lightrag":return e.jsx(pl,{refreshKey:n});case"obsidian":return e.jsx(jl,{refreshKey:n});case"git":return e.jsx(bl,{refreshKey:n});case"semantic":return e.jsx(kl,{refreshKey:n});case"config":return e.jsx(Nl,{refreshKey:n});default:return e.jsxs(Q,{children:["Unknown panel: ",a]})}};return e.jsxs("div",{className:"view view-memory memory-tab",children:[e.jsxs("header",{className:"view-header",children:[e.jsxs("div",{className:"view-header-text",children:[e.jsxs("h2",{className:"view-title",children:[e.jsx(Le,{size:18})," Memory"]}),e.jsx("p",{className:"view-subtitle",children:"LightRAG, Obsidian vault, git sync, and semantic search — all in one place."})]}),e.jsx("div",{className:"view-actions",children:e.jsx("button",{type:"button",className:"icon-btn",onClick:o,"aria-label":"Refresh memory",title:"Refresh",children:e.jsx(ce,{size:14})})})]}),e.jsxs("div",{className:"memory-tab-body",children:[e.jsx("nav",{className:"memory-source-rail","aria-label":"Memory sources",children:wl.map(x=>{const h=x.icon,d=a===x.id;return e.jsxs("button",{type:"button",role:"tab","aria-selected":d,className:X("memory-source-button",d&&"memory-source-button-active"),onClick:()=>i(x.id),children:[e.jsx(h,{size:16,"aria-hidden":!0}),e.jsx("span",{children:x.label})]},x.id)})}),e.jsx("div",{className:"memory-main",children:p()},a)]})]})}const Cl=We.memo(Sl),hs=[{id:"1h",label:"Last hour",ms:60*60*1e3},{id:"1d",label:"Last day",ms:24*60*60*1e3},{id:"7d",label:"Last 7 days",ms:7*24*60*60*1e3},{id:"30d",label:"Last 30 days",ms:30*24*60*60*1e3},{id:"all",label:"All time",ms:0}];function zl(s,t,a,i){const n=a.has(s.id);return e.jsxs(Q,{className:"history-project",style:{marginBottom:4},children:[e.jsxs("div",{className:"history-project-head",children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:4,minWidth:0,flex:1},children:[e.jsxs("div",{className:"history-project-name",children:[e.jsx(Ee,{size:16})," ",s.name]}),e.jsx("div",{className:"history-project-meta",children:s.path})]}),e.jsxs("div",{className:"history-project-stats",children:[e.jsxs("span",{className:"history-project-stat",children:[e.jsx("span",{className:"history-project-stat-num",children:s.tasks.done}),e.jsxs("span",{className:"muted",children:["/ ",s.tasks.total," done"]})]}),s.tasks.doing>0&&e.jsxs("span",{className:"history-project-stat",children:[e.jsx("span",{className:"history-project-stat-num",children:s.tasks.doing}),e.jsx("span",{className:"muted",children:"doing"})]}),s.tasks.blocked>0&&e.jsxs("span",{className:"history-project-stat",children:[e.jsx("span",{className:"history-project-stat-num",children:s.tasks.blocked}),e.jsx("span",{className:"muted",children:"blocked"})]}),e.jsxs("span",{className:"history-project-stat",children:[e.jsx(Se,{size:11})," ",e.jsx("span",{className:"history-project-stat-num",children:s.plans}),e.jsxs("span",{className:"muted",children:[" plan",s.plans===1?"":"s"]})]}),s.lastAccessed&&e.jsx("span",{className:"history-project-stat",children:e.jsxs("span",{className:"muted",children:["last opened ",Ne(s.lastAccessed)]})})]}),e.jsx("button",{type:"button",className:"icon-btn",onClick:()=>i(s.id),"aria-label":n?"Collapse":"Expand",children:n?e.jsx(Fe,{size:14}):e.jsx(_e,{size:14})})]}),n&&e.jsx("div",{className:"history-timeline-mini",children:t.length===0?e.jsx("div",{className:"muted",style:{padding:"12px 8px",fontSize:12},children:"No events in this time range."}):t.slice(-100).reverse().map((l,c)=>e.jsxs("div",{className:"history-timeline-row",children:[e.jsx("span",{className:"history-timeline-ts",children:new Date(l.ts).toLocaleTimeString()}),e.jsx("span",{className:"history-timeline-kind",children:l.kind||"event"}),e.jsxs("span",{className:"history-timeline-msg",title:String(l.text||l.title||""),children:[l.author?`@${l.author} `:"",String(l.text??l.title??l.name??"")]})]},c))})]},s.id)}function Tl({snapshot:s}){var b,A;const t=oe(),[a,i]=r.useState(null),[n,l]=r.useState(!0),[c,o]=r.useState("1d"),[p,x]=r.useState(new Set),[h,d]=r.useState(0),m=async y=>{try{const v=y?`?since=${encodeURIComponent(y)}&limit=1000`:"?limit=1000",L=await w.get(`/history${v}`);i(L),x(new Set(L.projects.filter($=>L.events.some(R=>R.projectId===$.id)).map($=>$.id)))}catch(v){t.error(`History load failed: ${v.message}`)}finally{l(!1)}};r.useEffect(()=>{l(!0);const y=hs.find(v=>v.id===c)||hs[1];if(y.ms>0){const v=new Date(Date.now()-y.ms).toISOString();m(v)}else m()},[c]),r.useEffect(()=>{const y=setInterval(()=>d(v=>v+1),3e4);return()=>clearInterval(y)},[]);const u=new Map;for(const y of(a==null?void 0:a.events)||[]){const v=y.projectId||"global";u.has(v)||u.set(v,[]),u.get(v).push(y)}const g=y=>{x(v=>{const L=new Set(v);return L.has(y)?L.delete(y):L.add(y),L})},f=()=>{if(!a)return;const y=new Blob([JSON.stringify(a,null,2)],{type:"application/json"}),v=URL.createObjectURL(y),L=document.createElement("a");L.href=v,L.download=`bizar-history-${new Date().toISOString().replace(/[:.]/g,"-")}.json`,L.click(),URL.revokeObjectURL(v),t.success("History exported.")};return e.jsxs("div",{className:"view view-history","data-tick":h,children:[e.jsxs("header",{className:"view-header",children:[e.jsxs("div",{className:"view-header-text",children:[e.jsxs("h2",{className:"view-title",children:[e.jsx(gs,{size:18})," History"]}),e.jsxs("p",{className:"view-subtitle",children:["Cross-project history of events, tasks, and plans.",((b=a==null?void 0:a.stats)==null?void 0:b.lastTs)&&e.jsxs(e.Fragment,{children:[" · last event ",Ne(a.stats.lastTs)]})]})]}),e.jsxs("div",{className:"view-actions",children:[e.jsxs("div",{className:"tasks-toolbar-group",children:[e.jsx(Za,{size:14,style:{color:"var(--text-dim)"},"aria-hidden":!0}),e.jsx("label",{htmlFor:"history-range",className:"sr-only",children:"Time range"}),e.jsx("select",{id:"history-range",className:"select select-sm",value:c,onChange:y=>o(y.target.value),title:"Time range","aria-label":"Time range",children:hs.map(y=>e.jsx("option",{value:y.id,children:y.label},y.id))})]}),e.jsxs(T,{variant:"ghost",size:"sm",onClick:()=>{l(!0);const y=hs.find(v=>v.id===c)||hs[1];y.ms>0?m(new Date(Date.now()-y.ms).toISOString()):m()},children:[e.jsx(ce,{size:14})," Refresh"]}),e.jsxs(T,{variant:"secondary",size:"sm",onClick:f,children:[e.jsx(Qe,{size:14})," Export"]})]})]}),n&&e.jsxs("div",{className:"view-loading",children:[e.jsx(he,{size:"lg"}),e.jsx("p",{children:"Loading history…"})]}),!n&&a&&e.jsxs("div",{className:"history-list",children:[a.projects.length===0&&e.jsxs(Q,{children:[e.jsxs(se,{children:[e.jsx(Ee,{size:14})," No projects"]}),e.jsx(ie,{children:"Register a project in Overview to start tracking history."})]}),a.projects.length>0&&e.jsx(ht,{items:a.projects,itemHeight:70,height:Math.min(a.projects.length*70,500),className:"history-virtual-list",renderItem:y=>zl(y,u.get(y.id)||[],p,g)}),u.has("global")&&e.jsxs(Q,{className:"history-project",children:[e.jsx("div",{className:"history-project-head",children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:4,minWidth:0,flex:1},children:[e.jsxs("div",{className:"history-project-name",children:[e.jsx(gs,{size:16})," Global events"]}),e.jsx("div",{className:"history-project-meta",children:"Activity not tied to a specific project"})]})}),e.jsx("div",{className:"history-timeline-mini",children:(u.get("global")||[]).slice(-100).reverse().map((y,v)=>e.jsxs("div",{className:"history-timeline-row",children:[e.jsx("span",{className:"history-timeline-ts",children:new Date(y.ts).toLocaleTimeString()}),e.jsx("span",{className:"history-timeline-kind",children:y.kind||"event"}),e.jsxs("span",{className:"history-timeline-msg",title:String(y.text||y.title||""),children:[y.author?`@${y.author} `:"",String(y.text??y.title??y.name??"")]})]},v))})]}),((A=a.stats)==null?void 0:A.counts)&&Object.keys(a.stats.counts).length>0&&e.jsxs(Q,{children:[e.jsx(se,{children:"Event counts by kind"}),e.jsxs(ie,{children:[a.stats.lines," total lines in log"]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:8,marginTop:8},children:Object.entries(a.stats.counts).sort((y,v)=>v[1]-y[1]).slice(0,30).map(([y,v])=>e.jsxs("span",{className:X("tag","tag-neutral"),style:{fontFamily:"var(--font-mono)"},children:[y,": ",v]},y))})]})]})]})}const ve={top:16,right:20,bottom:40,left:52};function Ml({series:s,height:t=280,onHover:a,className:i}){const n=r.useRef(null),[l,c]=r.useState(null),{labels:o,requests:p,tokens:x}=s,h=o.length;if(h===0)return e.jsx("div",{className:X("usage-chart-empty",i),style:{height:t},children:e.jsx("span",{children:"No data for this range"})});const d=600-ve.left-ve.right,m=t-ve.top-ve.bottom,u=Math.max(...p,1),g=Math.max(...x,1),f=Math.max(4,Math.min(24,Math.floor(d/h)-4)),b=(d-f*h)/(h+1);function A(N){return ve.left+b+N*(f+b)}function y(N){return N/u*m*.75}function v(N){return ve.top+m-N/g*m*.75}const L=x.map((N,D)=>`${A(D)+f/2},${v(N)}`).join(" "),$=[0,.25,.5,.75,1].map(N=>({y:ve.top+m-N*m*.75,label:N===0?"0":`${Math.round(u*N).toLocaleString()}`})),R=[0,.25,.5,.75,1].map(N=>({y:ve.top+m-N*m*.75,label:N===0?"0":`${Math.round(g*N/1e3)}k`})),P=Math.max(1,Math.floor(h/7)),S=o.map((N,D)=>({i:D,l:N,x:A(D)+f/2})).filter((N,D)=>D%P===0),q=r.useCallback(N=>{if(!n.current)return;const D=n.current.getBoundingClientRect(),j=(N.clientX-D.left)*(600/D.width),M=(N.clientY-D.top)*(t/D.height),F=j-ve.left,C=Math.round((F-b/2)/(f+b)),_=Math.max(0,Math.min(h-1,C));c({index:_,x:N.clientX-D.left,y:N.clientY-D.top}),a==null||a(_,j,M)},[h,f,b,a,t]),O=r.useCallback(()=>{c(null),a==null||a(null,0,0)},[a]),k=l;return e.jsxs("div",{ref:n,className:X("usage-chart",i),style:{position:"relative"},children:[e.jsxs("svg",{viewBox:`0 0 600 ${t}`,width:"100%",height:t,style:{display:"block",overflow:"visible"},onMouseMove:q,onMouseLeave:O,children:[$.map((N,D)=>e.jsx("line",{x1:ve.left,y1:N.y,x2:600-ve.right,y2:N.y,stroke:"var(--border)",strokeWidth:1,strokeDasharray:"4,3",opacity:.5},`grid-${D}`)),$.map((N,D)=>e.jsx("text",{x:ve.left-6,y:N.y+4,textAnchor:"end",fontSize:10,fill:"var(--text-muted)",fontFamily:"var(--font-mono, ui-monospace, monospace)",children:N.label},`ly-${D}`)),R.map((N,D)=>e.jsx("text",{x:600-ve.right+6,y:N.y+4,textAnchor:"start",fontSize:10,fill:"var(--text-muted)",fontFamily:"var(--font-mono, ui-monospace, monospace)",children:N.label},`ry-${D}`)),p.map((N,D)=>{const j=y(N),M=A(D),F=ve.top+m-j;return e.jsx("rect",{x:M,y:F,width:f,height:j,rx:2,fill:((k==null?void 0:k.index)===D,"var(--accent)"),opacity:(k==null?void 0:k.index)===D?1:.75,style:{transition:"opacity 120ms ease"}},`bar-${D}`)}),e.jsx("polyline",{points:L,fill:"none",stroke:"var(--warning, #d29922)",strokeWidth:2,strokeLinejoin:"round",strokeLinecap:"round",opacity:.9}),x.map((N,D)=>e.jsx("circle",{cx:A(D)+f/2,cy:v(N),r:(k==null?void 0:k.index)===D?5:3,fill:"var(--warning, #d29922)",opacity:(k==null?void 0:k.index)===D?1:.7,style:{transition:"r 120ms ease"}},`dot-${D}`)),S.map(({i:N,l:D,x:j})=>e.jsx("text",{x:j,y:ve.top+m+18,textAnchor:"middle",fontSize:10,fill:"var(--text-muted)",fontFamily:"var(--font-mono, ui-monospace, monospace)",children:D},`xl-${N}`)),e.jsx("line",{x1:ve.left,y1:ve.top+m,x2:600-ve.right,y2:ve.top+m,stroke:"var(--border)",strokeWidth:1})]}),k!==null&&e.jsxs("div",{className:"usage-chart-tooltip",style:{left:Math.min(k.x+12,460),top:k.y-60},children:[e.jsx("div",{className:"usage-tooltip-date",children:o[k.index]}),e.jsxs("div",{className:"usage-tooltip-row",children:[e.jsx("span",{className:"usage-tooltip-dot",style:{background:"var(--accent)"}}),e.jsx("span",{children:"Requests:"}),e.jsx("strong",{children:p[k.index].toLocaleString()})]}),e.jsxs("div",{className:"usage-tooltip-row",children:[e.jsx("span",{className:"usage-tooltip-dot",style:{background:"var(--warning, #d29922)"}}),e.jsx("span",{children:"Tokens:"}),e.jsx("strong",{children:x[k.index].toLocaleString()})]})]})]})}function Ke({label:s,col:t,sortKey:a,sortDir:i,onSort:n}){const l=a===t;return e.jsxs("th",{className:X("usage-sort-header",l&&"is-active"),onClick:()=>n(t),"aria-sort":l?i==="asc"?"ascending":"descending":"none",children:[e.jsx("span",{children:s}),e.jsx("span",{className:"usage-sort-icon",children:l?i==="asc"?" ↑":" ↓":" ↕"})]})}function $l({rows:s,sortKey:t,sortDir:a,onSort:i}){return e.jsx("div",{className:"usage-table-wrap",children:e.jsxs("table",{className:"usage-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(Ke,{label:"Model",col:"modelId",sortKey:t,sortDir:a,onSort:i}),e.jsx(Ke,{label:"Requests",col:"requests",sortKey:t,sortDir:a,onSort:i}),e.jsx(Ke,{label:"Prompt Tok",col:"promptTokens",sortKey:t,sortDir:a,onSort:i}),e.jsx(Ke,{label:"Compl Tok",col:"completionTokens",sortKey:t,sortDir:a,onSort:i}),e.jsx(Ke,{label:"Total Tok",col:"totalTokens",sortKey:t,sortDir:a,onSort:i}),e.jsx(Ke,{label:"Avg Latency",col:"avgLatencyMs",sortKey:t,sortDir:a,onSort:i}),e.jsx(Ke,{label:"Errors",col:"errors",sortKey:t,sortDir:a,onSort:i})]})}),e.jsx("tbody",{children:s.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:7,className:"usage-table-empty",children:"No data for this range"})}):s.map(n=>e.jsxs("tr",{children:[e.jsx("td",{className:"usage-table-model",children:e.jsx("code",{children:n.modelId})}),e.jsx("td",{className:"mono",children:n.requests.toLocaleString()}),e.jsx("td",{className:"mono",children:n.promptTokens.toLocaleString()}),e.jsx("td",{className:"mono",children:n.completionTokens.toLocaleString()}),e.jsx("td",{className:"mono",children:n.totalTokens.toLocaleString()}),e.jsxs("td",{className:"mono",children:[n.avgLatencyMs,"ms"]}),e.jsx("td",{className:X("mono",n.errors>0&&"is-err"),children:n.errors>0?n.errors:"—"})]},`${n.providerId}::${n.modelId}`))})]})})}function Al({activeTab:s,setActiveTab:t}){const[a,i]=r.useState("quota"),n=oe();return e.jsxs("div",{className:"view-container view-minimax-usage",children:[e.jsxs("div",{className:"minimax-sub-tabs",children:[e.jsxs("button",{className:X("minimax-sub-tab",a==="quota"&&"is-active"),onClick:()=>i("quota"),children:[e.jsx(jt,{size:13})," Token Plan"]}),e.jsxs("button",{className:X("minimax-sub-tab",a==="analytics"&&"is-active"),onClick:()=>i("analytics"),children:[e.jsx(Qt,{size:13})," Usage Analytics"]})]}),a==="quota"?e.jsx(Rl,{activeTab:s,setActiveTab:t}):e.jsx(Il,{toast:n})]})}function Rl({activeTab:s,setActiveTab:t}){var ee;const a=oe(),[i,n]=r.useState(null),[l,c]=r.useState(null),[o,p]=r.useState(null),[x,h]=r.useState(!0),[d,m]=r.useState(!1),[u,g]=r.useState(null),[f,b]=r.useState(null),[A,y]=r.useState(!1),[v,L]=r.useState(0),[$,R]=r.useState(!1),[P,S]=r.useState(null),[q,O]=r.useState(""),[k,N]=r.useState(!1),[D,j]=r.useState(!1),M=r.useCallback(async()=>{h(!0),g(null);try{const[Z,re,fe]=await Promise.all([w.get("/minimax/status"),w.get("/minimax/remains"),w.get("/minimax/onboarding")]);n(Z),c(re),p(fe),Z.configured&&L(4)}catch(Z){g(Z.message||"Failed to load MiniMax data")}finally{h(!1)}},[]);r.useEffect(()=>{M()},[M]);const F=r.useCallback(async()=>{try{await w.post("/minimax/onboarding",{dismissedAt:Date.now()}),p(Z=>Z&&{...Z,dismissedAt:Date.now()})}catch{}},[]),C=r.useCallback(async()=>{if(!q.trim()){a.error("Paste a Subscription Key first.");return}R(!0),S(null);try{const Z=await w.post("/minimax/test",{prompt:"Reply with a single word: pong",model:"MiniMax-M3",maxTokens:16});if(S(Z),Z.ok){L(3),a.success("Key works. Saving…");try{await w.post("/minimax/onboarding/save-key",{key:q.trim(),groupId:"default"}),ae(),a.success("Subscription Key saved.")}catch(re){a.error(`Save failed: ${re.message}`)}M()}else a.error(`Verification failed: ${Z.message??Z.error??"unknown"}`)}catch(Z){a.error(`Test request failed: ${Z.message}`)}finally{R(!1)}},[q,a,M]),_=r.useCallback(async()=>{if(!q.trim()){a.error("Paste a Subscription Key first.");return}j(!0);try{const Z=await w.post("/minimax/onboarding/save-key",{key:q.trim(),groupId:"default"});if(!Z.ok){a.error(`Save failed: ${Z.message??Z.error??"unknown"}`);return}O(""),ae(),a.success("Subscription Key saved. Loading quota…"),M()}catch(Z){a.error(`Save failed: ${Z.message}`)}finally{j(!1)}},[q,a,M]),ae=r.useCallback(async()=>{try{await w.del("/minimax/cache")}catch{}},[]),J=r.useCallback(async()=>{m(!0),g(null);try{await w.post("/minimax/remains/refresh"),await M(),a.success("Refreshed")}catch(Z){a.error(`Refresh failed: ${Z.message}`)}finally{m(!1)}},[M,a]),U=r.useCallback(async()=>{var Z;y(!0),b(null);try{const re=await w.post("/minimax/test",{prompt:"Reply with a single word: pong",model:"MiniMax-M3",maxTokens:16});b(re),re.ok?a.success(`Test ok — used ${((Z=re.usage)==null?void 0:Z.total_tokens)??"?"} tokens`):a.error(`Test failed: ${re.message??re.error??"unknown"}`)}catch(re){a.error(`Test request failed: ${re.message}`)}finally{y(!1)}},[a]);return x&&!i?e.jsxs("div",{className:"view-container",children:[e.jsx(he,{})," Loading MiniMax data…"]}):i?!i.configured&&(o==null?void 0:o.dismissedAt)==null&&v<4?e.jsx(Pl,{step:v,setStep:L,keyDraft:q,setKeyDraft:O,showKey:k,setShowKey:N,verifying:$,verifyResult:P,onVerify:C,onSkip:async()=>{await F(),a.success("Skipped.")},onManualKeySave:_,savingKey:D,status:i}):e.jsxs(e.Fragment,{children:[e.jsxs("header",{className:"view-header",children:[e.jsxs("div",{className:"view-header-titles",children:[e.jsxs("h1",{className:"view-title",children:[e.jsx(jt,{size:20,style:{verticalAlign:"text-bottom",marginRight:6}}),"MiniMax Token Plan"]}),e.jsxs("p",{className:"view-subtitle",children:["Remaining 5-hour + weekly quota per model. Fetches live from"," ",e.jsx("code",{children:"www.minimax.io/v1/token_plan/remains"}),"."]})]}),e.jsxs("div",{className:"view-header-actions",children:[e.jsxs(T,{variant:"secondary",size:"sm",onClick:()=>t("settings"),title:"Configure your Subscription Key",children:[e.jsx(ft,{size:14})," ",i.configured?`Key ${i.apiKeyHint}`:"Add key"]}),e.jsxs(T,{variant:"secondary",size:"sm",onClick:J,disabled:d,children:[d?e.jsx(je,{size:14,className:"spin"}):e.jsx(ce,{size:14})," Refresh"]})]})]}),l&&!l.ok&&e.jsxs("div",{className:"banner banner-err",children:[e.jsx(ke,{size:16}),e.jsxs("span",{children:[e.jsx("strong",{children:"Couldn't load quota"}),": ",l.message??l.error??"unknown error"]})]}),(l==null?void 0:l.ok)&&l.models&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"minimax-stats-row",children:[e.jsx(As,{label:"Models tracked",value:String(l.models.length),hint:"Distinct model quotas returned by the API"}),e.jsx(As,{label:"Last fetched",value:l.fetchedAt?El(l.fetchedAt):"—",hint:"Refreshed on demand + every 60s"}),e.jsx(As,{label:"Group",value:l.groupId??"—",hint:"Usually 'default' for an individual team"}),e.jsx(As,{label:"API key",value:l.apiKeyHint??"—",hint:"Masked; the real key never leaves auth.json"})]}),e.jsx("div",{className:"minimax-models-grid",children:l.models.map(Z=>e.jsx(Ll,{model:Z},Z.model_name))})]}),i.configured&&e.jsxs(Q,{id:"minimax-test",children:[e.jsxs(se,{children:[e.jsx(Xe,{size:14})," Test the API key"]}),e.jsxs(ie,{children:["One-shot chat completion to ",e.jsxs("code",{children:[i.chatBaseUrl,"/chat/completions"]}),"."]}),e.jsxs("div",{className:"minimax-test-actions",children:[e.jsxs(T,{onClick:U,disabled:A,variant:"primary",size:"sm",children:[A?e.jsx(je,{size:14,className:"spin"}):e.jsx(Xe,{size:14})," Send test prompt"]}),e.jsx("code",{className:"minimax-test-prompt",children:'"Reply with a single word: pong"'})]}),f&&e.jsxs("div",{className:X("minimax-test-result",f.ok?"ok":"err"),children:[f.ok?e.jsx(He,{size:14}):e.jsx(ke,{size:14}),e.jsx("div",{className:"minimax-test-body",children:f.ok?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"minimax-test-line",children:[e.jsx("strong",{children:"model:"})," ",e.jsx("code",{children:f.model})," ·"," ",e.jsx("strong",{children:"finish:"})," ",f.finishReason??"—"]}),f.content&&e.jsx("div",{className:"minimax-test-content",children:e.jsx("code",{children:f.content})}),f.usage&&e.jsxs("div",{className:"minimax-test-usage",children:[e.jsx("strong",{children:"usage:"})," total ",e.jsx("code",{children:f.usage.total_tokens??"?"})," · prompt"," ",e.jsx("code",{children:f.usage.prompt_tokens??"?"})," · completion"," ",e.jsx("code",{children:f.usage.completion_tokens??"?"}),((ee=f.usage.prompt_tokens_details)==null?void 0:ee.cached_tokens)!=null&&e.jsxs(e.Fragment,{children:[" · cached ",e.jsx("code",{children:f.usage.prompt_tokens_details.cached_tokens})]})]})]}):e.jsx("pre",{children:f.message??f.error??"unknown error"})})]})]})]}):e.jsx("div",{className:"view-container",children:e.jsxs("div",{className:"error-card",children:[e.jsx(ke,{size:20}),e.jsxs("div",{children:[e.jsx("strong",{children:"Couldn't load MiniMax status"}),e.jsx("pre",{children:u??"unknown error"})]})]})})}function Il({toast:s}){const[t,a]=r.useState("24h"),[i,n]=r.useState(""),[l,c]=r.useState(""),[o,p]=r.useState(!0),[x,h]=r.useState(null),[d,m]=r.useState([]),[u,g]=r.useState("requests"),[f,b]=r.useState("desc"),[A,y]=r.useState(!1),v=r.useCallback(async(k,N,D)=>{p(!0);try{const j=new URLSearchParams({range:k});k==="custom"&&N&&D&&(j.set("from",String(N)),j.set("to",String(D)));const[M,F]=await Promise.all([w.get(`/usage?${j.toString()}`),w.get("/usage/recent?limit=20")]);h(M),m(F.records)}catch(j){s.error(`Failed to load usage data: ${j.message}`)}finally{p(!1)}},[s]);r.useEffect(()=>{if(t==="custom"){const k=i?new Date(i).getTime():Date.now()-6048e5,N=l?new Date(l).getTime():Date.now();v("custom",k,N)}else v(t)},[t,v]);const L=r.useCallback(k=>{u===k?b(N=>N==="asc"?"desc":"asc"):(g(k),b("desc"))},[u]),$=r.useMemo(()=>x!=null&&x.perModel?[...x.perModel].sort((k,N)=>{const D=k[u]??0,j=N[u]??0,M=typeof D=="number"&&typeof j=="number"?D-j:String(D).localeCompare(String(j));return f==="asc"?M:-M}):[],[x==null?void 0:x.perModel,u,f]),R=r.useMemo(()=>x!=null&&x.daily?{labels:x.daily.map(k=>k.date.slice(5)),requests:x.daily.map(k=>k.requests),tokens:x.daily.map(k=>k.totalTokens)}:{labels:[],requests:[],tokens:[]},[x==null?void 0:x.daily]),P=r.useCallback(async()=>{y(!0),await v(t==="custom"?"custom":t,t==="custom"&&i?new Date(i).getTime():void 0,t==="custom"&&l?new Date(l).getTime():void 0),y(!1)},[v,t,i,l]);if(o&&!x)return e.jsxs("div",{className:"view-container",children:[e.jsx(he,{})," Loading usage data…"]});const S=x==null?void 0:x.totals,q=(x==null?void 0:x.errors)??[],O=(x==null?void 0:x.perKey)??[];return e.jsxs(e.Fragment,{children:[e.jsxs("header",{className:"view-header",children:[e.jsxs("div",{className:"view-header-titles",children:[e.jsxs("h1",{className:"view-title",children:[e.jsx(Qt,{size:20,style:{verticalAlign:"text-bottom",marginRight:6}}),"Usage Analytics"]}),e.jsxs("p",{className:"view-subtitle",children:["Aggregated from ",e.jsx("code",{children:"~/.local/share/bizar/usage.jsonl"})," — every chatCompletion and fetchRemains call."]})]}),e.jsx("div",{className:"view-header-actions",children:e.jsxs(T,{variant:"secondary",size:"sm",onClick:P,disabled:A,children:[A?e.jsx(je,{size:14,className:"spin"}):e.jsx(ce,{size:14})," Refresh"]})})]}),e.jsxs("div",{className:"usage-time-range",children:[["24h","7d","30d","custom"].map(k=>e.jsx("button",{className:X("usage-range-chip",t===k&&"is-active"),onClick:()=>a(k),children:k==="custom"?"Custom":k.toUpperCase()},k)),t==="custom"&&e.jsxs("div",{className:"usage-custom-dates",children:[e.jsx("label",{htmlFor:"usage-from-date",className:"sr-only",children:"From date"}),e.jsx("input",{id:"usage-from-date",type:"date",className:"usage-date-input",value:i,onChange:k=>n(k.target.value),"aria-label":"From date"}),e.jsx("span",{style:{color:"var(--text-muted)",fontSize:12},"aria-hidden":!0,children:"to"}),e.jsx("label",{htmlFor:"usage-to-date",className:"sr-only",children:"To date"}),e.jsx("input",{id:"usage-to-date",type:"date",className:"usage-date-input",value:l,onChange:k=>c(k.target.value),"aria-label":"To date"})]})]}),e.jsxs("div",{className:"usage-kpi-row",children:[e.jsx(us,{label:"Total Requests",value:(S==null?void 0:S.requests.toLocaleString())??"—",sub:S?`${S.errors} errors`:void 0,tone:S&&S.errors>S.requests*.1?"warn":void 0}),e.jsx(us,{label:"Total Tokens",value:S?S.totalTokens>=1e3?`${Math.round(S.totalTokens/1e3)}k`:String(S.totalTokens):"—",sub:S?`${S.promptTokens.toLocaleString()} prompt · ${S.completionTokens.toLocaleString()} completion`:void 0}),e.jsx(us,{label:"Errors",value:String((S==null?void 0:S.errors)??"—"),sub:q.length>0?`${q[0].code}: ${q[0].count}`:void 0,tone:S&&S.errors>0?"err":void 0}),e.jsx(us,{label:"Avg Latency",value:(S==null?void 0:S.avgLatencyMs)!=null?`${S.avgLatencyMs}ms`:"—",sub:(S==null?void 0:S.p95LatencyMs)!=null?`p95 ${S.p95LatencyMs}ms`:void 0}),e.jsx(us,{label:"Est. Cost",value:(S==null?void 0:S.costEstimate)!=null&&S.costEstimate>0?`$${S.costEstimate.toFixed(4)}`:"—",sub:"approximate USD",tone:void 0})]}),e.jsxs(Q,{className:"usage-chart-card",children:[e.jsx("div",{className:"usage-chart-wrap",children:e.jsx(Ml,{series:R,height:280})}),e.jsxs("div",{className:"usage-legend",children:[e.jsxs("div",{className:"usage-legend-item",children:[e.jsx("div",{className:"usage-legend-bar",style:{background:"var(--accent)"}}),e.jsx("span",{children:"Requests (bar)"})]}),e.jsxs("div",{className:"usage-legend-item",children:[e.jsx("div",{className:"usage-legend-line",style:{background:"var(--warning, #d29922)"}}),e.jsx("span",{children:"Tokens (line)"})]})]})]}),e.jsxs(Q,{children:[e.jsx(se,{children:"Per-model breakdown"}),e.jsx($l,{rows:$,sortKey:u,sortDir:f,onSort:L})]}),O.length>0&&e.jsxs(Q,{children:[e.jsx(se,{children:"API Keys"}),e.jsx("div",{className:"usage-key-row",children:O.map(k=>e.jsxs("span",{className:X("usage-key-badge",k.isBackup?"is-backup":"is-active"),children:[e.jsx("span",{className:"usage-key-dot"}),k.keyEnvVar,k.isBackup?" (backup)":" (active)"," · ",k.requests," req"]},k.keyEnvVar))})]}),d.length>0&&e.jsxs(Q,{children:[e.jsx(se,{children:"Recent activity"}),e.jsx("div",{className:"usage-recent-list",children:d.map((k,N)=>e.jsxs("div",{className:X("usage-recent-item",k.error&&"is-err"),children:[e.jsx("span",{className:"usage-recent-time",children:new Date(k.ts).toLocaleTimeString()}),e.jsx("span",{className:"usage-recent-model",children:e.jsx("code",{children:k.modelId})}),e.jsxs("span",{className:"usage-recent-tokens",children:[k.totalTokens.toLocaleString()," tok"]}),e.jsxs("span",{className:"usage-recent-latency",children:[k.latencyMs,"ms"]}),e.jsx("span",{className:"usage-recent-endpoint",children:k.endpoint})]},`${k.requestId}-${N}`))})]})]})}function us({label:s,value:t,sub:a,tone:i}){return e.jsxs("div",{className:"usage-kpi-card",children:[e.jsx("div",{className:"usage-kpi-label",children:s}),e.jsx("div",{className:X("usage-kpi-value",i&&`is-${i}`),children:t}),a&&e.jsx("div",{className:"usage-kpi-sub",children:a})]})}function As({label:s,value:t,hint:a}){return e.jsxs("div",{className:"stat",children:[e.jsx("div",{className:"stat-label",children:s}),e.jsx("div",{className:"stat-value",children:t}),a&&e.jsx("div",{className:"stat-hint",children:a})]})}function Ll({model:s}){const t=Rs(s.current_interval_remaining_percent??0,0,100),a=Rs(s.current_weekly_remaining_percent??0,0,100),i=Rs(100-t,0,100),n=Rs(100-a,0,100);return e.jsxs(Q,{id:`minimax-model-${s.model_name}`,className:"minimax-model-card",children:[e.jsxs("div",{className:"minimax-model-head",children:[e.jsx("div",{className:"minimax-model-name",children:s.model_name}),e.jsxs("div",{className:X("minimax-model-status",t<25||a<25?"is-warn":"is-ok"),children:[s.current_interval_status===1?"active":"idle"," ·"," ",s.current_weekly_status===1?"week active":"week idle"]})]}),e.jsxs("div",{className:"minimax-quota-rows",children:[e.jsx(Ut,{icon:e.jsx(Te,{size:12}),label:"5-hour rolling",remainingPct:t,consumedPct:i,used:s.current_interval_usage_count??0,total:s.current_interval_total_count??0,resetIn:s.intervalResetInHuman,resetISO:s.endTimeISO}),e.jsx(Ut,{icon:e.jsx(Ua,{size:12}),label:"Weekly",remainingPct:a,consumedPct:n,used:s.current_weekly_usage_count??0,total:s.current_weekly_total_count??0,resetIn:s.weeklyResetInHuman,resetISO:s.weeklyEndTimeISO})]})]})}function Ut({icon:s,label:t,remainingPct:a,consumedPct:i,used:n,total:l,resetIn:c,resetISO:o}){const p=a>=75?"good":a>=25?"warn":"low";return e.jsxs("div",{className:`minimax-quota-row is-${p}`,children:[e.jsxs("div",{className:"minimax-quota-head",children:[e.jsxs("span",{className:"minimax-quota-label",children:[s," ",t]}),e.jsxs("span",{className:"minimax-quota-remaining",children:[a,"% remaining"]})]}),e.jsx("div",{className:"minimax-bar",children:e.jsx("div",{className:"minimax-bar-fill",style:{width:`${i}%`},"aria-label":`${i}% consumed`})}),e.jsxs("div",{className:"minimax-quota-meta",children:[e.jsxs("span",{children:[e.jsx("strong",{children:n})," / ",l||"—"," requests"]}),e.jsx("span",{title:o,children:c?`resets in ${c}`:"—"})]})]})}function Rs(s,t,a){return Math.max(t,Math.min(a,s))}function El(s){const t=Date.now()-s;return t<5e3?"just now":t<6e4?`${Math.floor(t/1e3)}s ago`:t<36e5?`${Math.floor(t/6e4)}m ago`:`${Math.floor(t/36e5)}h ago`}function Pl({step:s,setStep:t,keyDraft:a,setKeyDraft:i,showKey:n,setShowKey:l,verifying:c,verifyResult:o,onVerify:p,onSkip:x,onManualKeySave:h,savingKey:d,status:m}){return e.jsxs("div",{className:"view-container view-minimax-onboarding",children:[e.jsxs("header",{className:"view-header",children:[e.jsxs("div",{className:"view-header-titles",children:[e.jsxs("h1",{className:"view-title",children:[e.jsx(Oe,{size:20,style:{verticalAlign:"text-bottom",marginRight:6}}),"Set up MiniMax Token Plan tracking"]}),e.jsx("p",{className:"view-subtitle",children:"We'll read your Subscription Key and show your remaining quota."})]}),e.jsx("div",{className:"view-header-actions",children:e.jsxs(T,{variant:"ghost",size:"sm",onClick:x,children:[e.jsx($e,{size:14})," Skip for now"]})})]}),e.jsx("div",{className:"minimax-wizard-stepper",children:["Welcome","Get a key","Paste & test","Done"].map((u,g)=>e.jsxs("div",{className:X("minimax-wizard-step",g===s&&"is-current",g<s&&"is-done",g>s&&"is-todo"),children:[e.jsx("div",{className:"minimax-wizard-step-bullet",children:g<s?e.jsx(He,{size:14}):g+1}),e.jsx("div",{className:"minimax-wizard-step-label",children:u})]},u))}),e.jsxs(Q,{id:"minimax-wizard-card",children:[s===0&&e.jsxs("div",{className:"minimax-wizard-body",children:[e.jsx("h3",{className:"minimax-wizard-title",children:"Welcome"}),e.jsxs("p",{className:"minimax-wizard-prose",children:["BizarHarness shows you how much of your MiniMax Token Plan quota you have left — both the ",e.jsx("strong",{children:"5-hour rolling"})," and ",e.jsx("strong",{children:"weekly"})," windows."]}),e.jsxs("ul",{className:"minimax-wizard-list",children:[e.jsxs("li",{children:["Stored in ",e.jsx("code",{children:"~/.local/share/opencode/auth.json"}),"."]}),e.jsx("li",{children:"Read fresh on every dashboard load."}),e.jsx("li",{children:"Never logged in full."})]}),e.jsx("div",{className:"minimax-wizard-actions",children:e.jsxs(T,{onClick:()=>t(1),variant:"primary",size:"md",children:["Get started ",e.jsx("span",{style:{marginLeft:6},children:"→"})]})})]}),s===1&&e.jsxs("div",{className:"minimax-wizard-body",children:[e.jsx("h3",{className:"minimax-wizard-title",children:"Get your Subscription Key"}),e.jsx("p",{className:"minimax-wizard-prose",children:"Go to the MiniMax console and copy your Subscription Key."}),e.jsxs("ol",{className:"minimax-wizard-list",children:[e.jsxs("li",{children:["Open ",e.jsxs("a",{href:"https://platform.minimax.io/user-center/payment/token-plan",target:"_blank",rel:"noreferrer",className:"minimax-wizard-link",children:[e.jsx(ls,{size:12})," platform.minimax.io"]})]}),e.jsxs("li",{children:["Click ",e.jsx("strong",{children:"Copy Subscription Key"}),"."]}),e.jsx("li",{children:"Come back here and paste it."})]}),e.jsxs("div",{className:"minimax-wizard-actions",children:[e.jsx(T,{variant:"secondary",size:"md",onClick:()=>t(0),children:"← Back"}),e.jsxs(T,{variant:"primary",size:"md",onClick:()=>t(2),children:["I have my key ",e.jsx("span",{style:{marginLeft:6},children:"→"})]})]})]}),s===2&&e.jsxs("div",{className:"minimax-wizard-body",children:[e.jsx("h3",{className:"minimax-wizard-title",children:"Paste & test"}),e.jsx("p",{className:"minimax-wizard-prose",children:"Paste your key below. We'll test it against the real API before saving."}),e.jsx("div",{className:"minimax-key-row",children:e.jsxs("div",{className:"minimax-key-input-wrap",children:[e.jsx(ft,{size:12,className:"minimax-key-icon","aria-hidden":!0}),e.jsx("label",{htmlFor:"minimax-key-input",className:"sr-only",children:"Subscription Key"}),e.jsx("input",{id:"minimax-key-input",type:n?"text":"password",value:a,onChange:u=>i(u.target.value),placeholder:"sk-cp-...",spellCheck:!1,autoComplete:"off",className:"minimax-key-input",autoFocus:!0,"aria-label":"Subscription Key"}),e.jsx("button",{type:"button",onClick:()=>l(u=>!u),className:"minimax-key-toggle","aria-label":n?"Hide key":"Show key",children:n?e.jsx(nt,{size:13}):e.jsx(is,{size:13})})]})}),o&&!o.ok&&e.jsxs("div",{className:"minimax-wizard-error",children:[e.jsx(ke,{size:14}),e.jsxs("span",{children:[e.jsx("strong",{children:"Verification failed:"})," ",o.message??o.error]})]}),e.jsxs("div",{className:"minimax-wizard-actions",children:[e.jsx(T,{variant:"secondary",size:"md",onClick:()=>t(1),children:"← Back"}),e.jsxs(T,{variant:"primary",size:"md",onClick:p,disabled:c||!a.trim(),children:[c?e.jsx(je,{size:14,className:"spin"}):e.jsx(bs,{size:14}),c?"Testing…":"Test &amp; save key"]})]}),e.jsxs("p",{className:"minimax-wizard-prose minimax-wizard-prose--muted",children:["Don't want to test first? ",e.jsx("a",{href:"#",onClick:u=>{u.preventDefault(),h()},className:"minimax-wizard-link",children:"Save without testing"})]})]}),s===3&&e.jsxs("div",{className:"minimax-wizard-body",children:[e.jsxs("h3",{className:"minimax-wizard-title",children:[e.jsx(He,{size:18,style:{verticalAlign:"text-bottom",marginRight:6}}),"All set"]}),e.jsx("p",{className:"minimax-wizard-prose",children:"The key works and is saved. Reloading so you can see your live quota."}),e.jsx("div",{className:"minimax-wizard-actions",children:e.jsx(T,{variant:"primary",size:"md",onClick:()=>window.location.reload(),children:"View your quota →"})})]}),e.jsxs("div",{className:"minimax-wizard-footer",children:[e.jsx(bs,{size:11}),e.jsxs("span",{children:["Key written to ",e.jsx("code",{children:"~/.local/share/opencode/auth.json"})," with mode 0600."]})]})]})]})}const Dl=We.memo(Al),Fl={pending:"info",running:"accent",done:"success",failed:"error",killed:"neutral",timed_out:"warning"},Ol={pending:"Pending",running:"Running",done:"Done",failed:"Failed",killed:"Killed",timed_out:"Timed out"};function Bl({status:s,dot:t}){const a=Fl[s]||"neutral",i=Ol[s]||s;return e.jsx(ns,{kind:a,dot:t,children:i})}function Ul({instanceId:s,instanceName:t,onConfirm:a,onClose:i}){return e.jsxs("div",{children:[e.jsxs("p",{style:{marginBottom:16,lineHeight:1.6},children:["Instance ",e.jsx("code",{children:s}),t?e.jsxs(e.Fragment,{children:[" (",t,")"]}):null," will be terminated. This cannot be undone."]}),e.jsxs("div",{style:{display:"flex",gap:8,justifyContent:"flex-end"},children:[e.jsx(T,{variant:"ghost",onClick:i,children:"Cancel"}),e.jsx(T,{variant:"danger",onClick:async()=>{await a(),i()},children:"Kill"})]})]})}function ql(s,t,a,i,n){s.open({title:"Kill instance?",width:400,children:e.jsx(Ul,{instanceId:a,instanceName:i,onConfirm:async()=>{try{const c=await(await fetch(`/api/background/${encodeURIComponent(a)}`,{method:"DELETE"})).json();c.ok?(t.success(`Instance ${a} killed.`),n==null||n()):t.error(`Kill failed: ${c.error||"unknown error"}`)}catch(l){t.error(`Kill failed: ${l.message}`)}},onClose:()=>s.close()})})}function Hl({instance:s}){const t=oe(),[a,i]=r.useState(!1),n=s.tmuxSession,l=n?`tmux attach -t ${n}`:null,c=async()=>{if(l)try{await navigator.clipboard.writeText(l),t.success("Attach command copied")}catch{t.error("Could not copy to clipboard")}},o=async()=>{if(!(!s.instanceId||!n)){i(!0);try{const p=await w.post(`/background/${encodeURIComponent(s.instanceId)}/open-terminal`,{emulator:"system"});if(p.ok)t.success("Opening terminal…");else if(t.error(p.error||"Failed to open terminal"),l)try{await navigator.clipboard.writeText(l),t.success("Command copied to clipboard")}catch{}}catch(p){if(t.error(`Failed: ${p.message}`),l)try{await navigator.clipboard.writeText(l),t.success("Command copied to clipboard")}catch{}}finally{i(!1)}}};return n?e.jsxs(Q,{variant:"outlined",className:"bg-tmux-card",children:[e.jsxs("div",{className:"bg-tmux-card-header",children:[e.jsx(fs,{size:14}),e.jsx("span",{children:"tmux session"}),s.tmuxActive!==!1?e.jsx("span",{className:"badge badge-success",children:"live"}):e.jsx("span",{className:"badge badge-warning",children:"inactive"})]}),e.jsx("code",{className:"mono bg-tmux-session-name",children:n}),e.jsx("p",{className:"muted bg-tmux-hint",children:"Attach to the agent's tmux session from a terminal on the host running the dashboard."}),e.jsxs("div",{className:"bg-tmux-card-actions",children:[e.jsxs(T,{variant:"ghost",size:"sm",onClick:c,title:"Copy attach command",children:[e.jsx(_s,{size:14})," Copy"]}),e.jsxs(T,{variant:"primary",size:"sm",onClick:o,loading:a,title:"Open in system terminal",children:[e.jsx(fs,{size:14})," Open terminal"]})]})]}):e.jsxs(Q,{variant:"outlined",className:"bg-tmux-card bg-tmux-card-warn",children:[e.jsxs("div",{className:"bg-tmux-card-header",children:[e.jsx(ke,{size:14}),e.jsx("span",{children:"No tmux session"})]}),e.jsx("p",{className:"bg-tmux-hint muted",children:"This instance does not have a tmux session attached. Sessions are created automatically when a background agent starts."})]})}const _l=5e3,Wl=2e3,Vl=120;function Kl(s){return s.status==="pending"||s.status==="running"}function Gl(s){if(!Number.isFinite(s)||s<0)return"—";const t=Math.floor(s/1e3),a=Math.floor(t/3600),i=Math.floor(t%3600/60),n=t%60;return a>0?`${a}h ${i}m ${n}s`:i>0?`${i}m ${n}s`:`${n}s`}function Yl(s){const t=oe(),a=Pe(),[i,n]=r.useState([]),[l,c]=r.useState(!0),[o,p]=r.useState(null),[,x]=r.useState(0),h=r.useCallback(async()=>{try{const f=await w.get("/background");n(Array.isArray(f==null?void 0:f.instances)?f.instances:[]),p(null)}catch(f){p((f==null?void 0:f.message)||"Failed to load background agents.")}finally{c(!1)}},[]);r.useEffect(()=>{h();const f=setInterval(h,_l);return()=>clearInterval(f)},[h]),r.useEffect(()=>{const f=setInterval(()=>x(b=>(b+1)%1e6),1e3);return()=>clearInterval(f)},[]),r.useEffect(()=>{const f=new pt,b=f.on(A=>{const y=A.type;(y==="background:change"||y==="background:cleanup")&&h()});return()=>{b(),f.close()}},[h]);const d=i.filter(Kl),m=f=>{Ql(a,f)},u=async f=>{try{const b=await w.get(`/background/${encodeURIComponent(f.instanceId)}/tmux`);Jl(a,b)}catch(b){t.error(`Tmux info failed: ${b.message}`)}},g=f=>{ql(a,t,f.instanceId,f.agent||f.prompt,()=>{n(b=>b.filter(A=>A.instanceId!==f.instanceId))})};return l?e.jsx("div",{className:"bg-active-view",children:e.jsxs("div",{className:"bg-active-loading",children:[e.jsx(he,{size:"md"}),e.jsx("span",{children:"Loading background agents…"})]})}):o?e.jsx("div",{className:"bg-active-view",children:e.jsx(we,{icon:e.jsx(Te,{size:32}),title:"Couldn't load background agents",message:o,action:e.jsxs(T,{variant:"primary",onClick:h,children:[e.jsx(ce,{size:14})," Retry"]})})}):e.jsxs("div",{className:"bg-active-view",children:[e.jsxs("div",{className:"bg-active-header",children:[e.jsxs("div",{className:"bg-active-header-text",children:[e.jsx("h2",{className:"bg-active-title",children:"Active Background Agents"}),e.jsxs("p",{className:"bg-active-subtitle muted",children:[d.length," active · ",i.length," total in store"]})]}),e.jsxs(T,{variant:"ghost",size:"sm",onClick:h,title:"Refresh now",children:[e.jsx(ce,{size:14})," Refresh"]})]}),d.length===0?e.jsx(we,{icon:e.jsx(Te,{size:32}),title:"No active background agents",message:"Spawn one from the Agents tab or via the bizar_spawn_background tool."}):e.jsx("div",{className:"bg-active-list",children:d.map(f=>e.jsx(Xl,{inst:f,onViewOutput:()=>m(f),onOpenTmux:()=>u(f),onKill:()=>g(f)},f.instanceId))})]})}function Xl({inst:s,onViewOutput:t,onOpenTmux:a,onKill:i}){const n=typeof s.startedAt=="number"?s.startedAt:0,l=n?os(n):"—",c=n?Date.now()-n:0,o=qt(s.prompt,Vl);return e.jsxs(Q,{className:"bg-active-card",variant:"elevated",children:[e.jsxs("div",{className:"bg-active-card-top",children:[e.jsxs("div",{className:"bg-active-card-id",children:[e.jsx("code",{className:"mono",children:s.instanceId}),e.jsx(Bl,{status:s.status||"pending",dot:!0})]}),e.jsxs("div",{className:"bg-active-card-agent",children:[e.jsx("span",{className:"bg-active-card-agent-label",children:"Agent"}),e.jsx("span",{className:"bg-active-card-agent-name",children:s.agent||"unknown"})]})]}),o&&e.jsx("div",{className:"bg-active-prompt",children:o}),s.currentStep&&e.jsxs("div",{className:"bg-active-step",children:[e.jsx("span",{className:"bg-active-step-label",children:"Step:"}),e.jsx("span",{className:"bg-active-step-value",children:s.currentStep})]}),typeof s.progress=="number"&&e.jsxs("div",{className:"progress-bar","aria-label":"Progress",children:[e.jsx("div",{className:"progress-fill",style:{width:`${Math.max(0,Math.min(100,s.progress))}%`}}),e.jsxs("span",{className:"progress-label",children:[Math.round(s.progress),"%"]})]}),e.jsxs("div",{className:"bg-active-meta",children:[e.jsxs("span",{title:l,children:[e.jsx("strong",{children:"Started:"})," ",l]}),e.jsxs("span",{children:[e.jsx("strong",{children:"Duration:"})," ",Gl(c)]}),e.jsxs("span",{children:[e.jsx("strong",{children:"Tool calls:"})," ",s.toolCallCount??0]}),s.tmuxSession&&e.jsxs("span",{className:X(s.tmuxActive&&"bg-active-meta-tmux-live"),children:[e.jsx("strong",{children:"tmux:"})," ",e.jsx("code",{className:"mono",children:s.tmuxSession}),s.tmuxActive?" · live":""]})]}),e.jsxs("div",{className:"bg-active-actions",children:[e.jsxs(T,{variant:"secondary",size:"sm",onClick:t,children:[e.jsx(is,{size:14})," View output"]}),e.jsxs(T,{variant:"ghost",size:"sm",onClick:a,children:[e.jsx(fs,{size:14})," Open in tmux"]}),e.jsxs(T,{variant:"danger",size:"sm",onClick:i,children:[e.jsx(Ae,{size:14})," Kill"]})]}),e.jsx(Hl,{instance:s})]})}function Ql(s,t){s.open({title:`Output — ${t.agent||t.instanceId}`,width:720,children:e.jsx(Zl,{instanceId:t.instanceId})})}function Zl({instanceId:s}){const t=oe(),[a,i]=r.useState(""),[n,l]=r.useState(!0),[c,o]=r.useState(null),[p,x]=r.useState(!0),h=r.useRef(null),d=r.useRef(!0),m=r.useCallback(async()=>{try{const f=await w.get(`/background/${encodeURIComponent(s)}/output?lines=200`);i((f==null?void 0:f.output)??""),x((f==null?void 0:f.available)!==!1),o(null)}catch(f){o((f==null?void 0:f.message)||"Failed to load output.")}finally{l(!1)}},[s]);r.useEffect(()=>{m();const f=setInterval(m,Wl);return()=>clearInterval(f)},[m]),r.useEffect(()=>{var f;d.current&&((f=h.current)==null||f.scrollIntoView({behavior:"auto",block:"end"}))},[a]);const u=f=>{const b=f.currentTarget,A=b.scrollHeight-b.scrollTop-b.clientHeight<24;d.current=A},g=async()=>{try{await navigator.clipboard.writeText(a),t.success("Output copied.")}catch{}};return e.jsxs("div",{className:"bg-output-modal",children:[e.jsxs("div",{className:"bg-output-toolbar",children:[e.jsx("span",{className:"muted",children:p?`${a.length} chars · auto-refresh 2s`:"Output unavailable"}),e.jsxs("div",{className:"bg-output-toolbar-actions",children:[e.jsxs(T,{variant:"ghost",size:"sm",onClick:m,title:"Refresh now",children:[e.jsx(ce,{size:14})," Refresh"]}),e.jsxs(T,{variant:"ghost",size:"sm",onClick:g,disabled:!a,children:[e.jsx(_s,{size:14})," Copy"]})]})]}),n&&!a?e.jsxs("div",{className:"bg-output-loading",children:[e.jsx(je,{size:16,className:"spin"})," Loading…"]}):c?e.jsx("div",{className:"bg-output-error",children:c}):a?e.jsxs("div",{className:"bg-output-scroll",onScroll:u,children:[e.jsx("pre",{className:"bg-output-pre mono",children:e.jsx("code",{children:a})}),e.jsx("div",{ref:h})]}):e.jsx("div",{className:"bg-output-empty muted",children:"No output captured yet."})]})}function Jl(s,t){const a=t.attachCommand||t.session||"";s.open({title:"Attach to tmux",width:520,children:e.jsx(eo,{info:t,cmd:a})})}function eo({info:s,cmd:t}){const[a,i]=r.useState(!1),n=async()=>{try{await navigator.clipboard.writeText(t),i(!0),window.setTimeout(()=>i(!1),1500)}catch{}};return e.jsx("div",{className:"bg-tmux-modal",children:t?e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"bg-tmux-meta",children:[s.exists?e.jsx("span",{className:"badge badge-success",children:"session live"}):e.jsxs("span",{className:"badge badge-warning",children:["session not running",s.reason?` — ${s.reason}`:""]}),s.session&&e.jsxs("span",{className:"bg-tmux-session muted",children:["· session ",e.jsx("code",{className:"mono",children:s.session})]})]}),e.jsx("label",{className:"field-label",children:"Attach command"}),e.jsxs("div",{className:"bg-tmux-command-row",children:[e.jsx("code",{className:"bg-tmux-command mono",children:t}),e.jsxs(T,{variant:"secondary",size:"sm",onClick:n,children:[e.jsx(_s,{size:14})," ",a?"Copied":"Copy"]})]}),e.jsx("p",{className:"muted bg-tmux-hint",children:"Paste this into a terminal on the host running the dashboard. The dashboard itself does not open terminals."})]}):e.jsx("p",{className:"muted",children:"No tmux session attached to this instance."})})}const tt={overview:oi,chat:wi,agents:Ti,artifacts:sr,memory:Cl,tasks:hr,activity:kr,background:Yl,config:Et,settings:Et,mods:Kr,schedules:nl,skills:hl,history:Tl,minimax:Dl},so="v4.5.0";function to(s,t,a,i){if(tt[s]){const c=tt[s];return e.jsx(c,{...t})}const n=a.find(c=>c.id===s);if(n)return e.jsx(Yr,{viewId:n.id,reloadKey:i,activeTab:t.activeTab,setActiveTab:t.setActiveTab});const l=tt.overview;return e.jsx(l,{...t})}function ao({onSaved:s}){const[t,a]=r.useState(""),i=r.useRef(null);r.useEffect(()=>{var c;(c=i.current)==null||c.focus()},[]);const n=()=>{const c=t.trim();c&&(w.setToken(c),s())},l=c=>{c.key==="Escape"&&(c.preventDefault(),s()),c.key==="Enter"&&(c.preventDefault(),n())};return e.jsxs("form",{className:"token-entry-form",onSubmit:c=>{c.preventDefault(),n()},children:[e.jsxs("div",{className:"token-entry-row",children:[e.jsx("input",{ref:i,type:"password",className:"input mono",value:t,onChange:c=>a(c.target.value),placeholder:"Paste auth token",spellCheck:!1,autoComplete:"off",onKeyDown:l}),e.jsx(T,{type:"submit",variant:"primary",size:"sm",disabled:!t.trim(),children:"Save & retry"})]}),e.jsxs("p",{className:"token-entry-hint",children:["Where do I find this token? Check the file"," ",e.jsx("code",{children:"~/.config/bizar/dashboard-secret"})," on the machine running the dashboard, or look for it in the server output."]})]})}function no(){return e.jsx(Pa,{children:e.jsx(Da,{children:e.jsx(io,{})})})}function io(){var Z,re,fe;const s=oe(),t=Pe(),{isModalOpen:a}=t,i=r.useRef(!1),[n,l]=r.useState("overview"),[c,o]=r.useState(null),[p,x]=r.useState(null),[h,d]=r.useState("connecting"),[m,u]=r.useState(null),[g,f]=r.useState(!1),[b,A]=r.useState(!1),[y,v]=r.useState([]),[L,$]=r.useState(!1),[R,P]=r.useState([]),[S,q]=r.useState(0),O=r.useRef(null),[k,N]=r.useState(null);r.useEffect(()=>{let V=!1;return(async()=>{try{const I=await w.get("/mods/views");if(V)return;P(I.views||[])}catch{V||P([])}})(),()=>{V=!0}},[S,c==null?void 0:c.mods]),r.useEffect(()=>{if(!k)return;const V=k.on(I=>{((I==null?void 0:I.type)==="mod:change"||(I==null?void 0:I.type)==="mod:enabled"||(I==null?void 0:I.type)==="mod:installed")&&q(B=>B+1)});return()=>V()},[k]),r.useEffect(()=>{p!=null&&p.theme&&(xs(p.theme),as(p.theme))},[p==null?void 0:p.theme]),r.useEffect(()=>{i.current=a},[a]),r.useEffect(()=>{var B;if(((B=p==null?void 0:p.theme)==null?void 0:B.mode)!=="system")return;const V=window.matchMedia("(prefers-color-scheme: light)"),I=()=>xs(p.theme.mode);return V.addEventListener("change",I),()=>V.removeEventListener("change",I)},[(Z=p==null?void 0:p.theme)==null?void 0:Z.mode]);const D=r.useCallback(async()=>{let V=!1;const I=()=>Promise.all([w.get("/snapshot").catch(()=>null),w.get("/settings").catch(()=>null),w.get("/agents/stuck").catch(()=>null)]),B=(H,ne,W)=>{H&&o(H),ne!=null&&ne.data&&x(ne.data),W!=null&&W.stuck&&v(W.stuck)};try{const H=await w.probeAuthStatus(),[ne,W,E]=await I();if(B(ne,W,E),ne||W){u(null);return}if(!H.loopback){u("Dashboard server unreachable.");return}await new Promise(de=>setTimeout(de,1e3));const[le,te,ue]=await I();B(le,te,ue),!le&&!te&&u("Dashboard server unreachable.")}catch(H){const ne=(H==null?void 0:H.message)??"unknown error";if(H instanceof Fa&&H.status===401){u(ne),f(!0),s.error(`Auth required: ${ne}`);return}u(ne),s.error(`Failed to load: ${ne}`)}},[s]);r.useEffect(()=>{let V=!1;const I=setTimeout(()=>{V||D()},0);return()=>{V=!0,clearTimeout(I)}},[D]),r.useEffect(()=>{let V=!1;return w.get("/settings").then(I=>{var H,ne;if(V)return;const B=(ne=(H=I==null?void 0:I.data)==null?void 0:H.ui)==null?void 0:ne.defaultTab;B&&l(B)}).catch(()=>{}),()=>{V=!0}},[]),r.useEffect(()=>{let V=!1;const I=async()=>{try{const H=await w.get("/agents/stuck");V||v(ne=>{const W=H.stuck||[];return ne.length===0&&W.length>0&&s.warning(`${W.length} agent${W.length===1?"":"s"} stuck`,5e3),W})}catch{}},B=setInterval(I,3e4);return I(),()=>{V=!0,clearInterval(B)}},[]),r.useEffect(()=>{const V=new pt;O.current=V,N(V);const I=V.onStatus(H=>d(H)),B=V.on(H=>{var ne;if(H.type==="snapshot"&&"data"in H&&H.data)o(W=>({...W??{},...H.data}));else if(H.type==="change"){const W=H,E=((ne=W.path)==null?void 0:ne.split("/").pop())||W.path||"";s.info(`File changed: ${E}`,2500)}else if(H.type==="tasks:change"){const W=H;o(E=>{if(!E)return E;const le=(E.tasks||[]).map(ue=>ue.id===W.task.id?W.task:ue),te=le.some(ue=>ue.id===W.task.id);return{...E,tasks:te?le:[W.task,...le]}})}else if(H.type==="tasks:delete"){const W=H;o(E=>E&&{...E,tasks:(E.tasks||[]).filter(le=>le.id!==W.id)})}else if(H.type==="settings:change"){const W=H;W.settings&&x(W.settings)}else if(H.type==="project:change")w.get("/snapshot").then(W=>o(E=>({...E??{},...W}))).catch(()=>{});else if(H.type==="agents:change"||H.type==="schedules:change")w.get("/snapshot").then(W=>o(E=>({...E??{},...W}))).catch(()=>{});else if(H.type==="agent:status"||H.type==="agent:restarted"){const W=H;o(E=>{if(!E)return E;const le=(E.agents||[]).map(te=>te.name===W.agent.name?W.agent:te);return{...E,agents:le}})}else if(H.type==="artifact:change")w.get("/artifacts").then(W=>{o(E=>E&&{...E,artifacts:W.artifacts||[]})}).catch(()=>{});else if(H.type==="agent:stuck")v(H.agents||[]);else if(H.type==="dialog:show"){const W=H;W.dialog&&t.open({title:W.dialog.title,width:520,children:e.jsx(Yn,{dialog:W.dialog,onClose:()=>t.close()})})}});return()=>{I(),B(),V.close(),N(null)}},[s]);const j=r.useCallback(V=>k?k.on(V):()=>{},[k]),M=r.useRef(0);r.useEffect(()=>{const V=()=>{M.current=Date.now()+1500};return document.addEventListener("mousedown",V,!0),document.addEventListener("click",V,!0),document.addEventListener("focusin",V,!0),document.addEventListener("keydown",V,!0),()=>{document.removeEventListener("mousedown",V,!0),document.removeEventListener("click",V,!0),document.removeEventListener("focusin",V,!0),document.removeEventListener("keydown",V,!0)}},[]),r.useEffect(()=>{const V={};lt.forEach((B,H)=>{V[String(H+1)]=B.id});const I=B=>{var de,ws,Ss,Cs;if((B.metaKey||B.ctrlKey)&&B.key.toLowerCase()==="k"){B.preventDefault(),A(!0);return}if(B.key==="/"&&!B.metaKey&&!B.ctrlKey){const zs=(ws=(de=B.target)==null?void 0:de.tagName)==null?void 0:ws.toLowerCase();if(zs!=="input"&&zs!=="textarea"&&!((Ss=B.target)!=null&&Ss.isContentEditable)){B.preventDefault(),A(!0);return}}const H=document.activeElement;if(!H||H===document.body||H===document.documentElement)return;const W=B.target,E=(Cs=W==null?void 0:W.tagName)==null?void 0:Cs.toLowerCase(),le=E==="input"||E==="textarea"||E==="select"||E==="button"||E==="option"||E==="label"||!!(W!=null&&W.isContentEditable);let te=!1;if(W&&typeof W.closest=="function"&&(te=!!W.closest('form, [role="dialog"], [contenteditable], [data-no-key]')),B.repeat||i.current||le||te||B.metaKey||B.ctrlKey||B.altKey||B.shiftKey||Date.now()<M.current)return;const ue=V[B.key];ue&&(B.preventDefault(),l(ue))};return document.addEventListener("keydown",I),()=>document.removeEventListener("keydown",I)},[]);const F=r.useMemo(()=>async()=>{try{const V=await w.get("/snapshot");o(I=>({...I??{},...V}))}catch(V){s.error(`Refresh failed: ${V.message}`)}},[s]),C=r.useMemo(()=>{const V=R.map(I=>({id:I.id,label:I.label,icon:I.kind==="iframe"?ys:it,isMod:!0,modId:I.modId}));return[...lt,...V]},[R]),_=r.useMemo(()=>c&&p?to(n,{snapshot:c,settings:p,activeTab:n,setActiveTab:l,refreshSnapshot:F},R,S):null,[n,c,p,R,S,F]),ae=async()=>{try{const V=await w.get("/projects");o(I=>{var B;return I&&{...I,projects:V.projects||[],activeProject:((B=V.projects)==null?void 0:B.find(H=>H.id===V.active))||null}})}catch(V){s.error(`Projects refresh failed: ${V.message}`)}},J=async V=>{try{await w.post(`/projects/${encodeURIComponent(V)}/activate`),o(I=>I&&{...I,activeProject:I.projects.find(B=>B.id===V)||null})}catch(I){s.error(`Activate failed: ${I.message}`)}},U=V=>{const I=V.type;if(I==="agent")l("agents");else if(I==="task")l("tasks");else if(I==="mod")l("mods");else if(I==="schedule")l("schedules");else if(I==="project"){const B=V.item.id;J(B)}else if(I==="command")s.info(`/${V.item.name} — run from the TUI`,2500);else if(I==="setting"){const B=V.item.id||V.item.path||"";l("settings");const H=ne=>{if(ne<=0)return;const W=B?document.querySelector(`[data-setting-id="${CSS.escape(B)}"]`):null;W?(W.scrollIntoView({behavior:"smooth",block:"center"}),W.classList.remove("setting-flash"),W.offsetWidth,W.classList.add("setting-flash"),window.setTimeout(()=>W.classList.remove("setting-flash"),1500)):window.setTimeout(()=>H(ne-1),80)};window.setTimeout(()=>H(15),60)}},G=((re=p==null?void 0:p.ui)==null?void 0:re.layout)||"topnav",ee=((fe=p==null?void 0:p.ui)==null?void 0:fe.showHeader)!==!1;return e.jsxs("div",{className:"app","data-layout":G,"data-active-tab":n,children:[e.jsx("a",{className:"skip-to-main",href:"#main-content",children:"Skip to main content"}),ee&&e.jsx(Ln,{activeTab:n,onTabChange:l,wsStatus:h,version:so,activeProject:(c==null?void 0:c.activeProject)||null,projects:(c==null?void 0:c.projects)||[],onProjectChange:J,onProjectsRefresh:ae,onOpenSearch:()=>A(!0),settings:p,notificationsSlot:e.jsx(Un,{wsSubscribe:j}),showTabs:G==="topnav",extraTabs:C}),y.length>0&&!L&&e.jsxs("div",{className:"stuck-banner",role:"alert",children:[e.jsx(ke,{size:16}),e.jsxs("span",{children:[e.jsx("strong",{children:y.length})," agent",y.length===1?"":"s"," stuck:"," ",e.jsx("span",{className:"mono",children:y.map(V=>V.name).join(", ")})]}),e.jsx(T,{variant:"secondary",size:"sm",onClick:()=>{l("agents"),$(!0)},children:"Review"}),e.jsx("button",{type:"button",className:"icon-btn","aria-label":"Dismiss",onClick:()=>$(!0),children:e.jsx($e,{size:14})})]}),e.jsxs("div",{className:"layout-body",children:[G!=="topnav"&&e.jsx(Dn,{tabs:C,activeTab:n,onTabChange:l}),e.jsxs("main",{className:"content",id:"main-content",tabIndex:-1,children:[m&&e.jsxs("div",{className:"boot-error",children:[e.jsx("h2",{children:"Dashboard unavailable"}),e.jsx("p",{children:m}),g&&e.jsx(ao,{onSaved:()=>{f(!1),D()}}),e.jsxs("p",{className:"boot-error-hint",children:["Make sure the Bizar dashboard server is running. Try"," ",e.jsx("code",{children:"bizar-dash start"})," in your terminal."]})]}),!m&&(!c||!p)&&e.jsxs("div",{className:"loading",children:[e.jsx(he,{size:"lg"}),e.jsx("p",{children:"Loading Bizar…"})]}),_&&e.jsx(r.Suspense,{fallback:e.jsxs("div",{className:"loading",children:[e.jsx(he,{size:"lg"}),e.jsx("p",{children:"Loading…"})]}),children:e.jsx(ro,{children:_})})]})]}),e.jsx(Fn,{open:b,onClose:()=>A(!1),onSelect:U})]})}class ro extends r.Component{constructor(){super(...arguments);cs(this,"state",{err:null});cs(this,"reset",()=>this.setState({err:null}))}static getDerivedStateFromError(a){return{err:a}}componentDidCatch(a,i){console.error("[ViewErrorBoundary] caught render error:",a,i==null?void 0:i.componentStack)}render(){return this.state.err?e.jsxs("div",{className:"view-error-fallback",role:"alert",children:[e.jsx(ke,{size:20}),e.jsxs("div",{className:"view-error-body",children:[e.jsx("strong",{children:"This view crashed."}),e.jsx("pre",{children:this.state.err.message}),e.jsx(T,{variant:"secondary",size:"sm",onClick:this.reset,children:"Retry"})]})]}):this.props.children}}function lo(){const[s,t]=r.useState(()=>typeof window>"u"?!1:window.matchMedia("(max-width: 767px)").matches);return r.useEffect(()=>{const a=window.matchMedia("(max-width: 767px)"),i=n=>t(n.matches);return a.addEventListener("change",i),()=>a.removeEventListener("change",i)},[]),s?e.jsx(Ba,{}):e.jsx(no,{})}const da=document.getElementById("root");if(!da)throw new Error("Root element #root not found");Oa(da).render(e.jsx(r.StrictMode,{children:e.jsx(lo,{})}));