@polderlabs/bizar 4.8.0 → 4.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bizar-dash/dist/assets/index-DU61awG3.js +9 -0
- package/bizar-dash/dist/assets/index-DU61awG3.js.map +1 -0
- package/bizar-dash/dist/assets/main-DaC1Lc6q.js +366 -0
- package/bizar-dash/dist/assets/main-DaC1Lc6q.js.map +1 -0
- package/bizar-dash/dist/assets/{main-DX_Jh8Wc.css → main-DfmIfOUS.css} +1 -1
- package/bizar-dash/dist/assets/{mobile-Chvf9u_B.js → mobile-CL5uUQEC.js} +1 -1
- package/bizar-dash/dist/assets/{mobile-Chvf9u_B.js.map → mobile-CL5uUQEC.js.map} +1 -1
- package/bizar-dash/dist/assets/mobile-D5WTWvuh.js +338 -0
- package/bizar-dash/dist/assets/mobile-D5WTWvuh.js.map +1 -0
- package/bizar-dash/dist/index.html +3 -3
- package/bizar-dash/dist/mobile.html +2 -2
- package/bizar-dash/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +1 -1
- package/bizar-dash/src/server/memory-lightrag.mjs +109 -0
- package/bizar-dash/src/server/memory-store.mjs +121 -0
- package/bizar-dash/src/server/otel.mjs +133 -0
- package/bizar-dash/src/server/routes/chat.mjs +246 -170
- package/bizar-dash/src/server/routes/memory.mjs +46 -0
- package/bizar-dash/src/server/routes/opencode-sessions.mjs +82 -48
- package/bizar-dash/src/server/server.mjs +40 -0
- package/bizar-dash/src/web/components/SettingsSearch.tsx +204 -89
- package/bizar-dash/src/web/lib/search.ts +115 -0
- package/bizar-dash/src/web/mobile/views/MobileSettings.tsx +10 -35
- package/bizar-dash/src/web/mobile/views/QrCodePanel.tsx +69 -0
- package/bizar-dash/src/web/styles/memory.css +84 -1
- package/bizar-dash/src/web/styles/settings.css +80 -0
- package/bizar-dash/src/web/views/Memory.tsx +6 -1
- package/bizar-dash/src/web/views/Settings.tsx +96 -0
- package/bizar-dash/src/web/views/memory/MemoryGraphLegend.tsx +29 -0
- package/bizar-dash/src/web/views/memory/MemoryGraphPanel.tsx +192 -0
- package/bizar-dash/src/web/views/memory/MemoryGraphView.tsx +336 -0
- package/bizar-dash/tests/bundle-analysis.test.mjs +70 -0
- package/bizar-dash/tests/components/settings-search.test.tsx +180 -0
- package/bizar-dash/tests/docker-build.test.mjs +96 -0
- package/bizar-dash/tests/lib/search-fuzzy.test.ts +149 -0
- package/bizar-dash/tests/memory-graph-view.test.tsx +69 -0
- package/bizar-dash/tests/memory-graph.test.mjs +95 -0
- package/bizar-dash/tests/otel.test.mjs +188 -0
- package/cli/commands/dash.mjs +6 -0
- package/package.json +7 -1
- package/bizar-dash/dist/assets/main-DHZmbnxQ.js +0 -361
- package/bizar-dash/dist/assets/main-DHZmbnxQ.js.map +0 -1
- package/bizar-dash/dist/assets/mobile-BK8-ythT.js +0 -351
- package/bizar-dash/dist/assets/mobile-BK8-ythT.js.map +0 -1
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
var wa=Object.defineProperty;var Sa=(s,t,a)=>t in s?wa(s,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):s[t]=a;var ds=(s,t,a)=>Sa(s,typeof t!="symbol"?t+"":t,a);import{c as Q,r,a as C,j as e,R as ce,C as ut,F as Ee,b as Fe,d as We,M as Hs,B as He,S as gs,A as Te,e as Oe,f as Fs,H as js,g as xt,h as ve,i as K,u as De,P as $e,k as R,l as oe,X as Ce,m as Ca,T as ke,n as _e,I as _s,o as Ne,E as os,p as Se,q as cs,s as Ve,t as he,v as Qe,V as pt,w as Ae,x as gt,y as za,z as Ma,D as Ta,G as fs,J as ys,K as Ns,L as $a,N as Aa,O as Ra,Q as La,U as vs,W as Gt,Y as ws,Z as jt,_ as Ia,$ as Kt,a0 as Yt,a1 as Ea,a2 as Da,a3 as Pa,a4 as Fa,a5 as Oa,a6 as Ba,a7 as Ua,a8 as ft,a9 as Ws,aa as Xt,ab as Qt,ac as ns,ad as ps,ae as Zt,af as qa,ag as Ha,ah as _a,ai as Wa,aj as Va,ak as Ga}from"./mobile-D5WTWvuh.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 Jt=Q("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 ea=Q("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 sa=Q("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 yt=Q("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 Ie=Q("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 Ka=Q("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 ta=Q("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 rt=Q("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 Ya=Q("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=Q("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 Xa=Q("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 Qa=Q("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 Xe=Q("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 Za=Q("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 vt=Q("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 Gs=Q("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 aa=Q("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 Ja=Q("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 Ze=Q("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 en=Q("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 lt=Q("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 rs=Q("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 sn=Q("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 tn=Q("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 an=Q("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 nn=Q("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 rn=Q("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 ln=Q("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 on=Q("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 cn=Q("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 ls=Q("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 dn=Q("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 mn=Q("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 hn=Q("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 bs=Q("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 un=Q("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 Os=Q("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 bt=Q("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 xn=Q("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 na=Q("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 ot=Q("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=Q("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 $t=Q("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 Bs=Q("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 pn=Q("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 gn=Q("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 ia=Q("Network",[["rect",{x:"16",y:"16",width:"6",height:"6",rx:"1",key:"4q2zg0"}],["rect",{x:"2",y:"16",width:"6",height:"6",rx:"1",key:"8cvhb9"}],["rect",{x:"9",y:"2",width:"6",height:"6",rx:"1",key:"1egb70"}],["path",{d:"M5 16v-3a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v3",key:"1jsf9p"}],["path",{d:"M12 12V8",key:"2874zd"}]]);/**
|
|
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 jn=Q("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"}]]);/**
|
|
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 kt=Q("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"}]]);/**
|
|
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 fn=Q("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"}]]);/**
|
|
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 yn=Q("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"}]]);/**
|
|
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 vn=Q("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"}]]);/**
|
|
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 bn=Q("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"}]]);/**
|
|
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 kn=Q("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"}]]);/**
|
|
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 ct=Q("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"}]]);/**
|
|
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 Nn=Q("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"}]]);/**
|
|
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 Us=Q("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"}]]);/**
|
|
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 wn=Q("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"}]]);/**
|
|
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 Sn=Q("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"}]]);/**
|
|
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 Cn=Q("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"}]]);/**
|
|
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 ks=Q("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"}]]);/**
|
|
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 zn=Q("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"}]]);/**
|
|
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 Mn=Q("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"}]]);/**
|
|
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 Tn=Q("Square",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]]);/**
|
|
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 ra=Q("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"}]]);/**
|
|
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 $n=Q("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"}]]);/**
|
|
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 An=Q("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"}]]);/**
|
|
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 Rn=Q("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"}]]);/**
|
|
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 la=Q("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"}]]);/**
|
|
347
|
+
* @license lucide-react v0.460.0 - ISC
|
|
348
|
+
*
|
|
349
|
+
* This source code is licensed under the ISC license.
|
|
350
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
351
|
+
*/const Nt=Q("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"}]]),Ln=200,In=5*60*1e3,Ye=new Map;function En(s){const t=Ye.get(s);return t?Date.now()-t.ts>In?(Ye.delete(s),null):t.data:null}function Ks(s,t){Ye.size>=Ln&&[...Ye.entries()].sort((i,n)=>i[1].ts-n[1].ts).slice(0,50).map(([i])=>i).forEach(i=>Ye.delete(i)),Ye.set(s,{data:t,ts:Date.now()})}function Dn(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 Pn(s){return[...s].sort((t,a)=>t.isDir!==a.isDir?t.isDir?-1:1:t.name.localeCompare(a.name,void 0,{sensitivity:"base"}))}function Fn(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 oa({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,j]=r.useState({}),[b,A]=r.useState(!1),[N,w]=r.useState(null),[E,M]=r.useState(!1),[$,D]=r.useState(""),[f,F]=r.useState(null),[S,y]=r.useState(!1),k=r.useRef(null),P=r.useCallback(async O=>{try{const le=En(O);if(le)return le;const te=await C.get("/fs?path="+encodeURIComponent(O));return Ks(O,te),te}catch{return null}},[]),v=r.useCallback(async O=>{var le;A(!0),w(null);try{const te=await C.get("/fs?path="+encodeURIComponent(O));Ks(O,te),u(te),d(-1)}catch(te){const ue=((le=te.data)==null?void 0:le.message)??te.message??"Failed to load directory";w(ue)}finally{A(!1)}},[]);r.useEffect(()=>{c?v(c):C.get("/fs").then(O=>{Ks("",O),u(O),o(O.path),O.path!==s&&t(O.path)}).catch(()=>{w("Could not determine home directory."),A(!1)})},[c]),r.useEffect(()=>{s&&s!==c&&o(s)},[s]);const L=m?Pn(m.entries):[],B=L.filter(O=>O.isDir),z=L,_=O=>{O.isDir&&(o(O.path),t(O.path))},ae=()=>{m!=null&&m.parent&&(o(m.parent),t(m.parent))},J=O=>{O!==c&&(o(O),t(O))},q=async()=>{const O=await P("");O&&(o(O.path),t(O.path))},X=async()=>{if(!i)return;const O=await P(i);O&&(o(O.path),t(O.path))},se=()=>{M(!0),D(""),F(null),setTimeout(()=>{var O;return(O=k.current)==null?void 0:O.focus()},0)},Z=()=>{M(!1),D(""),F(null)},re=async()=>{var le;const O=Fn($);if(!O.ok){F(O.reason);return}y(!0),F(null);try{const te=await C.post("/fs/mkdir",{parent:c,name:$.trim()});Ye.delete(c),await v(c),t(te.path),M(!1),D("")}catch(te){const ue=te;ue.status===409?F(`A folder named "${$.trim()}" already exists.`):F(((le=ue.data)==null?void 0:le.message)??te.message??"Failed to create folder.")}finally{y(!1)}},fe=O=>{O.key==="Enter"?(O.preventDefault(),re()):O.key==="Escape"&&(O.preventDefault(),Z())},V=O=>{x(le=>{const te=new Set(le);return te.has(O)?te.delete(O):te.add(O),te}),g[O]||P(O).then(le=>{le&&j(te=>({...te,[O]:le.entries.filter(ue=>ue.isDir)}))})},I=O=>{if(!m)return;const le=z.filter(de=>de.isDir),te=z.filter(de=>!de.isDir),ue=[...le,...te];if(O.key==="ArrowDown")O.preventDefault(),d(de=>Math.min(de+1,ue.length-1));else if(O.key==="ArrowUp")O.preventDefault(),d(de=>Math.max(de-1,0));else if(O.key==="Enter"||O.key===" "){O.preventDefault();const de=ue[h];de&&(O.key==="Enter"&&de.isDir?_(de):de.isDir&&t(de.path))}else O.key==="Backspace"&&(O.preventDefault(),ae())},U=Dn((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:U.map((O,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(O.path),title:O.path,children:le===0?O.path==="/"?"/":n:O.label})]},O.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(sa,{size:13})}),e.jsx("button",{type:"button",className:"file-browser-tool-btn",onClick:()=>v(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:se,title:"New folder","aria-label":"Create new folder",children:e.jsx(on,{size:13})}),e.jsxs("div",{className:"file-browser-chips",children:[e.jsxs("button",{type:"button",className:"file-browser-chip",onClick:q,children:[e.jsx(un,{size:11})," ",n]}),i&&e.jsxs("button",{type:"button",className:"file-browser-chip",onClick:X,title:i,children:[e.jsx(ln,{size:11})," ",i.split("/").filter(Boolean).at(-1)??"Projects"]})]})]}),E?e.jsxs("div",{className:"file-browser-mkdir",children:[e.jsx("input",{ref:k,type:"text",className:"file-browser-mkdir-input",placeholder:"Folder name",value:$,onChange:O=>{D(O.target.value),F(null)},onKeyDown:fe,"aria-label":"New folder name","aria-invalid":f?"true":void 0,"aria-describedby":f?"mkdir-error":void 0,disabled:S,maxLength:255}),f?e.jsx("span",{id:"mkdir-error",className:"file-browser-mkdir-error",role:"alert",children:f}):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?"…":`${L.length} in ${W}`})]}),N&&e.jsxs("div",{className:"file-browser-error",children:[e.jsx(ut,{size:13}),e.jsx("span",{children:N}),e.jsx("button",{type:"button",className:"file-browser-retry",onClick:()=>v(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(On,{}):e.jsx(ca,{path:c,entries:B,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(Bn,{}):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."]}),z.length===0?e.jsx("div",{className:"file-browser-empty",children:"This folder is empty"}):e.jsx("div",{className:"file-browser-flat-list",children:z.map((O,le)=>{const te=O.isDir,ue=le===h,de=O.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(O.path))},onDoubleClick:()=>{te&&_(O)},title:O.path,children:[e.jsx("span",{className:"file-browser-row-icon",children:te?e.jsx(Ee,{size:13}):e.jsx(nn,{size:13})}),e.jsx("span",{className:"file-browser-row-name",children:O.name}),e.jsx("span",{className:"file-browser-row-type",children:te?"Folder":""})]},O.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 ca({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(We,{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(ca,{path:o.path,entries:x,expanded:a,childrenMap:i,onToggle:n,onNavigate:l,level:c+1})]},o.path)})})}function On(){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 Bn(){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 dt=[{id:"overview",label:"Overview",icon:na},{id:"chat",label:"Chat",icon:Hs},{id:"agents",label:"Agents",icon:He},{id:"artifacts",label:"Glyphs",icon:Bs},{id:"tasks",label:"Tasks",icon:gs},{id:"activity",label:"Activity",icon:Te},{id:"background",label:"Active",icon:wn},{id:"skills",label:"Skills",icon:Oe},{id:"memory",label:"Memory",icon:Ie},{id:"mods",label:"Mods",icon:Us},{id:"schedules",label:"Schedules",icon:Fs},{id:"history",label:"History",icon:js},{id:"minimax",label:"Usage",icon:vt},{id:"settings",label:"Settings",icon:xt}];function Un({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(qn,{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(ve,{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:K("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:[dt.map(g=>{const j=g.icon,b=g.id===s;return e.jsxs("button",{type:"button",role:"tab","aria-selected":b,className:K("tab",b&&"tab-active"),onClick:()=>t(g.id),title:g.label,children:[e.jsx(j,{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 j=g.icon,b=g.id===s;return e.jsxs("button",{type:"button",role:"tab","aria-selected":b,className:K("tab","tab-mod",b&&"tab-active"),onClick:()=>t(g.id),title:`${g.label} (mod)`,children:[e.jsx(j,{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 qn({activeProject:s,projects:t,onChange:a,onRefresh:i,settings:n}){const[l,c]=r.useState(!1),o=De();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(Hn,{settings:n,onAdd:async(x,h)=>{try{await C.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(R,{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($e,{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:K("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 Hn({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 C.get("/fs?path="+encodeURIComponent(a)),t(a,n||null)}catch(g){const j=g;j.status===404?x("That folder no longer exists. Pick another."):x(((u=j.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(oa,{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(R,{variant:"primary",onClick:h,disabled:!a||c,children:[c?e.jsx("span",{className:"btn-spinner"}):null,c?"Checking…":"Add"]})})]})}function _n({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:K("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:K("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 Ys=[{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"}],At={all:null,projects:"project",agents:"agent",tasks:"task",mods:"mod",schedules:"schedule",commands:"command",settings:"setting"};function Wn({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),j=r.useRef(null);if(r.useEffect(()=>{let w;return s&&(j.current=document.activeElement instanceof HTMLElement?document.activeElement:null,l(""),x([]),u(0),w=window.setTimeout(()=>{var E;return(E=g.current)==null?void 0:E.focus()},30)),()=>{if(w&&window.clearTimeout(w),!s)return;const E=j.current;E&&E.isConnected&&E.focus()}},[s]),r.useEffect(()=>{if(!s)return;if(!n.trim()){x([]),u(0);return}let w=!1;d(!0);const E=setTimeout(()=>{C.get(`/search?q=${encodeURIComponent(n)}&scope=${c}`).then(M=>{w||(x(M.results||[]),u(0))}).catch(M=>{w||i.error(`Search failed: ${M.message}`)}).finally(()=>!w&&d(!1))},150);return()=>{w=!0,clearTimeout(E)}},[n,c,s,i]),!s)return null;const b={};for(const w of p){const E=w.type.toLowerCase();b[E]=b[E]||[],b[E].push(w)}const A=[];for(const w of Ys.map(E=>E.id)){const E=At[w];E&&b[E]&&A.push(...b[E])}const N=w=>{if(w.key==="Escape")t();else if(w.key==="ArrowDown"){if(w.preventDefault(),A.length===0)return;u(E=>Math.min(E+1,A.length-1))}else if(w.key==="ArrowUp"){if(w.preventDefault(),A.length===0)return;u(E=>Math.max(E-1,0))}else w.key==="Enter"&&A[m]&&(w.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:w=>w.stopPropagation(),children:[e.jsxs("div",{className:"search-modal-head",role:"search",children:[e.jsx(ve,{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:w=>l(w.target.value),onKeyDown:N,"aria-label":"Search"}),e.jsx("button",{type:"button",className:"icon-btn","aria-label":"Close",onClick:t,children:e.jsx(Ce,{size:14})})]}),e.jsx("div",{className:"search-modal-scopes",role:"tablist","aria-label":"Search scope",children:Ys.map(w=>e.jsx("button",{type:"button",role:"tab","aria-selected":c===w.id,className:K("search-scope",c===w.id&&"search-scope-active"),onClick:()=>o(w.id),children:w.label},w.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…"}),Ys.map(w=>{const E=At[w.id];if(!E)return null;const M=b[E];return!M||M.length===0?null:e.jsxs("div",{className:"search-group",children:[e.jsx("div",{className:"search-group-head",children:w.label}),M.map($=>{const D=A.indexOf($);return e.jsxs("button",{type:"button",className:K("search-result",D===m&&"search-result-active"),onMouseEnter:()=>u(D),onClick:()=>{a($),t()},children:[e.jsx("span",{className:"search-result-type",children:$.type}),e.jsx("span",{className:"search-result-label",children:Vn($)})]},`${$.type}-${D}`)})]},w.id)})]}),e.jsx("div",{className:"search-modal-foot",children:e.jsx("span",{className:"muted",children:"↑↓ navigate · ↵ open · esc close"})})]})})}function Vn(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 Gn={info:_s,success:_e,warning:ke,error:ut};function Kn({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 N;try{h(!0);const w=await C.get("/notifications?limit=200");c(w.notifications||[]),p(w.stats||null),m.current=((N=w.stats)==null?void 0:N.unread)||0,s==null||s(m.current)}catch(w){console.warn("[notifications] reload failed:",w.message)}finally{h(!1)}};r.useEffect(()=>{u()},[]),r.useEffect(()=>t?t(w=>{if(w.type==="notification:new"){const E=w.notification;c(M=>[E,...M.filter($=>$.id!==E.id)]),E.read||(m.current+=1,p(M=>M?{...M,unread:(M.unread||0)+1}:{total:1,unread:1,lastTs:E.ts,counts:{[E.severity||"info"]:1}}),s==null||s(m.current))}else w.type==="notifications:change"&&u()}):void 0,[t]),r.useEffect(()=>{if(!i)return;const N=E=>{d.current&&(d.current.contains(E.target)||n(!1))},w=E=>{E.key==="Escape"&&n(!1)};return document.addEventListener("mousedown",N),document.addEventListener("keydown",w),()=>{document.removeEventListener("mousedown",N),document.removeEventListener("keydown",w)}},[i]);const g=async()=>{try{await C.post("/notifications/read-all",{}),c(N=>N.map(w=>({...w,read:!0}))),p(N=>N&&{...N,unread:0}),m.current=0,s==null||s(0),a.success("All notifications marked as read.",1500)}catch(N){a.error(`Failed: ${N.message}`)}},j=async N=>{try{await C.post(`/notifications/${encodeURIComponent(N)}/read`,{}),c(w=>w.map(E=>E.id===N?{...E,read:!0}:E)),p(w=>w&&{...w,unread:Math.max(0,(w.unread||1)-1)}),m.current=Math.max(0,m.current-1),s==null||s(m.current)}catch(w){a.error(`Failed: ${w.message}`)}},b=async N=>{try{await C.del(`/notifications/${encodeURIComponent(N)}`),c(w=>{const E=w.find(M=>M.id===N);return E&&!E.read&&(m.current=Math.max(0,m.current-1),p(M=>M&&{...M,unread:Math.max(0,M.unread-1)}),s==null||s(m.current)),w.filter(M=>M.id!==N)})}catch(w){a.error(`Failed: ${w.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:K("topbar-icon-btn notifications-bell",i&&"is-open"),onClick:()=>n(N=>!N),title:"Notifications","aria-label":"Notifications","aria-haspopup":"true","aria-expanded":i,children:[e.jsx(Ca,{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(R,{size:"sm",variant:"ghost",onClick:g,disabled:A===0,children:[e.jsx(rt,{size:12})," Mark all read"]}),e.jsx("button",{type:"button",className:"icon-btn",onClick:()=>n(!1),"aria-label":"Close",title:"Close",children:e.jsx(Ce,{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(N=>{const w=Gn[N.severity]||_s;return e.jsxs("div",{className:K("notification-item",!N.read&&"is-unread",`severity-${N.severity}`),children:[e.jsx(w,{size:14,className:`notification-icon severity-${N.severity}`}),e.jsxs("div",{className:"notification-body",children:[N.title&&e.jsx("div",{className:"notification-title",children:N.title}),e.jsx("div",{className:"notification-msg",children:N.message}),e.jsxs("div",{className:"notification-meta muted",children:[e.jsx("span",{className:"mono",children:N.source}),e.jsx("span",{children:"·"}),e.jsx("span",{children:Ne(N.ts)})]})]}),e.jsxs("div",{className:"notification-actions",children:[!N.read&&e.jsx("button",{type:"button",className:"icon-btn",onClick:()=>j(N.id),title:"Mark as read","aria-label":"Mark as read",children:e.jsx(rt,{size:12})}),e.jsx("button",{type:"button",className:"icon-btn icon-btn-danger",onClick:()=>b(N.id),title:"Remove","aria-label":"Remove",children:e.jsx(Ce,{size:12})})]})]},N.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 Yn({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(R,{variant:"ghost",onClick:t,children:"Close"})})]})}const Xn=["blank","feature-design","bug-investigation","decision-record","horizontal","vertical"];function Qn({data:s,onClose:t}){const a=(s==null?void 0:s.templates)??Xn,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 C.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(R,{variant:"ghost",onClick:t,disabled:p,children:"Cancel"}),e.jsx(R,{variant:"primary",onClick:m,disabled:p||!n.trim(),children:p?"Creating…":"Create"})]})]})}function Zn({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(R,{variant:"ghost",size:"sm",onClick:()=>n(l),children:"Open"})]},l))})]}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsx(R,{variant:"ghost",onClick:t,children:"Close"})})]})}function Jn({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(R,{variant:"ghost",onClick:t,children:"Close"})})]})}function ei({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 C.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(R,{variant:"ghost",onClick:t,children:"Cancel"}),e.jsx(R,{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(R,{variant:"ghost",onClick:t,children:"Close"})})]})})}function si({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 ti({dialog:s,onClose:t}){switch(s.component){case"visual-artifact":return e.jsx(Yn,{data:s.data,onClose:t});case"artifact-create":return e.jsx(Qn,{data:s.data,onClose:t});case"artifact-list":return e.jsx(Zn,{data:s.data,onClose:t});case"help":return e.jsx(Jn,{data:s.data,onClose:t});case"audit":return e.jsx(ei,{data:s.data,onClose:t});default:return e.jsx(si,{dialog:s,onClose:t})}}function Y({variant:s="elevated",interactive:t=!1,className:a,children:i,...n}){return e.jsx("div",{className:K("card",`card-${s}`,t&&"card-interactive",a),...n,children:i})}function ee({children:s,className:t}){return e.jsx("h3",{className:K("card-title",t),children:s})}function ie({children:s,className:t}){return e.jsx("div",{className:K("card-meta",t),children:s})}function ai({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([C.get("/memory/status").catch(()=>null),C.get("/memory/health").catch(()=>null),C.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(Y,{className:"memory-overview-card",children:[e.jsxs(ee,{children:[e.jsx(Ie,{size:14})," Memory",e.jsxs(R,{variant:"ghost",size:"sm",style:{marginLeft:"auto"},onClick:o,children:["Open Memory ",e.jsx(os,{size:12})]}),e.jsx(R,{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(Ie,{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(ls,{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}`:cs(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:K("empty-state",n),children:[e.jsx("div",{className:"empty-icon",children:s??e.jsx(Os,{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 ni({snapshot:s,settings:t,setActiveTab:a,refreshSnapshot:i}){var _,ae,J;const n=oe(),l=De(),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),[j,b]=r.useState(s.mods||[]),[A,N]=r.useState(!1),[w,E]=r.useState(((ae=s.overview)==null?void 0:ae.recentActivity)??[]),[M,$]=r.useState(!1),[D,f]=r.useState(new Set);r.useEffect(()=>{let q=!1;return(async()=>{try{const X=await C.get("/activity/hidden");q||f(new Set(X.hidden||[]))}catch{}})(),()=>{q=!0}},[]);const F=(q,X)=>{const se=`${q.kind||""}|${q.ts||""}|${q.slug||q.title||""}|${X}`;let Z=0;for(let re=0;re<se.length;re++)Z=(Z<<5)-Z+se.charCodeAt(re)|0;return Math.abs(Z).toString(16).padStart(8,"0").slice(0,16)},S=async q=>{const X=new Set(D);X.add(q),f(X);try{await C.post("/activity/hide",{keys:[q]})}catch(se){const Z=new Set(D);f(Z),n.error(`Hide failed: ${se.message}`)}},y=async()=>{if(!confirm("Hide every recent activity item from the overview? The full log stays in Settings → Activity Log."))return;const q=w.map((se,Z)=>F(se,Z)),X=new Set(D);q.forEach(se=>X.add(se)),f(X);try{await C.post("/activity/hide",{keys:q}),n.success(`Hidden ${q.length} item(s). Restore them in Settings → Activity Log.`)}catch(se){n.error(`Clear failed: ${se.message}`)}},k=async()=>{f(new Set);try{await C.del("/activity/hide"),n.success("All hidden activity restored to the overview.")}catch(q){n.error(`Restore failed: ${q.message}`)}};r.useEffect(()=>{var q;s.overview&&(p(s.overview),E(s.overview.recentActivity??[]),h(!1)),m(s.projects||[]),g(((q=s.activeProject)==null?void 0:q.id)||null),b(s.mods||[])},[s.overview,s.projects,s.activeProject,s.mods]),r.useEffect(()=>{let q;try{const X=C.getToken(),se=X?`/api/activity/stream?token=${encodeURIComponent(X)}`:"/api/activity/stream";q=new EventSource(se),q.addEventListener("snapshot",Z=>{try{const re=JSON.parse(Z.data);E(Array.isArray(re.events)?re.events.slice(0,50):[])}catch{}}),q.addEventListener("activity",Z=>{try{const re=JSON.parse(Z.data);E(fe=>[re,...fe].slice(0,50))}catch{}})}catch{}return()=>{try{q==null||q.close()}catch{}}},[]);const P=async()=>{n.info("Refreshing…",1500),await i();try{const q=await C.get("/projects");m(q.projects||[]),g(q.active||null)}catch{}},v=()=>{l.open({title:"Add project",children:e.jsx(ii,{settings:t,onAdd:async(q,X)=>{try{const se=await C.post("/projects",{path:q,name:X});m(Z=>[...Z.filter(re=>re.id!==se.id),se]),n.success("Project added."),l.close()}catch(se){n.error(`Add failed: ${se.message}`)}}}),footer:e.jsx("div",{className:"modal-footer-actions",children:e.jsx(R,{variant:"ghost",onClick:()=>l.close(),children:"Cancel"})})})},L=async()=>{var q;try{const X=await C.post("/projects/auto-detect");m(X.projects||[]),g(X.active||null);const se=(q=X.projects)==null?void 0:q.find(Z=>Z.id===X.active);n.success(se?`Active: ${se.name}`:"Projects refreshed."),await i()}catch(X){n.error(`Auto-detect failed: ${X.message}`)}},B=async q=>{try{await C.post(`/projects/${encodeURIComponent(q)}/activate`),g(q),n.success("Project activated."),await i()}catch(X){n.error(`Activate failed: ${X.message}`)}},z=async q=>{if(confirm(`Remove project "${q}" from the registry?`))try{await C.del(`/projects/${encodeURIComponent(q)}`),m(X=>X.filter(se=>se.id!==q)),u===q&&g(null),n.success("Project removed.")}catch(X){n.error(`Remove failed: ${X.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 q=>{var se,Z;q.preventDefault();const X=(((se=c.current)==null?void 0:se.value)||"").trim();if(X){N(!0);try{const re=await C.post("/tasks/submit",{title:X});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{N(!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(R,{type:"submit",variant:"primary",size:"lg",disabled:A,children:[A?e.jsx(he,{size:"sm"}):e.jsx(Qe,{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(q=>e.jsx("button",{type:"button",className:"overview-quick-chip",onClick:()=>{c.current&&(c.current.value=q,c.current.focus())},children:q},q))})]}),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:[D.size>0&&e.jsxs(R,{variant:"ghost",size:"sm",onClick:k,title:"Restore hidden items to this overview",children:[e.jsx(rs,{size:12})," Show ",D.size," hidden"]}),w.length>8&&e.jsx(R,{variant:"ghost",size:"sm",onClick:()=>$(q=>!q),children:M?"Show less":"Show all"}),w.length>0&&e.jsxs(R,{variant:"ghost",size:"sm",onClick:y,title:"Hide every item from the overview (full log kept)",children:[e.jsx(lt,{size:12})," Hide all"]})]})]}),D.size>0&&e.jsxs("div",{className:"activity-hidden-banner",role:"status",children:[e.jsxs("span",{children:[e.jsx(lt,{size:12,style:{verticalAlign:-2,marginRight:6}}),D.size," item",D.size===1?"":"s"," hidden from the overview."]}),e.jsxs(R,{variant:"ghost",size:"sm",onClick:k,children:[e.jsx(rs,{size:12})," Show them again"]})]}),w.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:K("activity-feed-list-wrap",!M&&"activity-feed-list-wrap-collapsed"),"aria-live":"polite","aria-relevant":"additions",children:[e.jsx(pt,{items:w.slice(0,30).filter((q,X)=>!D.has(F(q,X))),itemHeight:60,height:Math.min(w.filter((q,X)=>!D.has(F(q,X))).length*60,480),className:"activity-feed-list",renderItem:(q,X)=>{const se=w.slice(0,30).findIndex(Z=>Z===q);return e.jsx(xi,{item:q,activityKey:F(q,se),onNavigate:a,onHide:S})}}),!M&&w.length>8&&e.jsx("div",{className:"activity-feed-fade","aria-hidden":"true"})]})]}),e.jsxs(Y,{className:"project-picker",children:[e.jsxs(ee,{children:[e.jsx(Ee,{size:14})," Projects",e.jsxs(R,{variant:"ghost",size:"sm",style:{marginLeft:"auto"},onClick:v,children:[e.jsx($e,{size:12})," Add"]}),e.jsxs(R,{variant:"ghost",size:"sm",onClick:L,title:"Use the server's working directory",children:[e.jsx($e,{size:12})," Auto-detect"]}),((J=t==null?void 0:t.dashboard)==null?void 0:J.projectsDirectory)&&e.jsxs(R,{variant:"ghost",size:"sm",title:`Scan ${t.dashboard.projectsDirectory} for projects`,onClick:async()=>{try{const q=await C.post("/projects/scan");q.error?n.error(q.error):n.success(`Added ${q.added.length}, skipped ${q.skipped}.`),await i();const X=await C.get("/projects");m(X.projects||[]),g(X.active||null)}catch(q){n.error(`Scan failed: ${q.message}`)}},children:[e.jsx(cn,{size:12})," Scan"]}),e.jsx(R,{variant:"ghost",size:"sm",onClick:P,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(R,{variant:"primary",onClick:L,children:[e.jsx($e,{size:14})," Use current directory"]}),e.jsx(R,{variant:"secondary",onClick:v,children:"Add by path…"})]})}):e.jsx("div",{className:"project-grid",children:d.map(q=>e.jsx(ri,{project:q,active:u===q.id,onOpen:()=>B(q.id),onRemove:()=>z(q.id)},q.id))})]}),e.jsx(ai,{setActiveTab:a}),e.jsxs("div",{className:"overview-cols",children:[e.jsxs(Y,{children:[e.jsx(ee,{children:"Mods"}),e.jsxs(ie,{children:["Extensions installed under ",e.jsx("code",{children:"~/.config/bizar/mods/"})]}),j.length===0?e.jsx("div",{className:"muted",children:"No mods installed."}):e.jsx("ul",{className:"mod-mini-list",children:j.map(q=>e.jsxs("li",{className:"mod-mini",children:[e.jsx("span",{className:"mod-mini-name",children:q.name}),e.jsxs("span",{className:"mod-mini-meta",children:["v",q.version," · ",q.type]}),e.jsx("span",{className:`mod-mini-pill ${q.enabled?"mod-mini-pill-on":"mod-mini-pill-off"}`,children:q.enabled?"on":"off"})]},q.id))})]}),e.jsxs(Y,{children:[e.jsx(ee,{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:cs(o.generatedAt)})]})]})]})]})}function ii({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 C.get("/fs?path="+encodeURIComponent(a)),t(a,n||null)}catch(g){const j=g;j.status===404?x("That folder no longer exists. Pick another."):x(((u=j.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(oa,{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(R,{variant:"primary",onClick:h,disabled:!a||c,children:[c?e.jsx("span",{className:"btn-spinner"}):null,c?"Checking…":"Add"]})})]})}function ri({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(R,{variant:t?"ghost":"primary",size:"sm",onClick:a,children:t?e.jsxs(e.Fragment,{children:[e.jsx(gt,{size:12})," Active"]}):e.jsx(e.Fragment,{children:"Open"})})})]})}function li(s){return s&&s.charAt(0).toUpperCase()+s.slice(1)}function oi(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]||li(a.replace(/-/g," ")),o=l[i]||i.replace(/-/g," ");return`${c} ${o}`.trim()}function $s(s,t){for(const a of t){const i=s[a];if(typeof i=="string"&&i.trim())return i.trim()}return""}function ci(s){const t=$s(s,["message","text","prompt","title","name"]);if(t)return t;const a=[],i=$s(s,["slug"]),n=$s(s,["agent","author"]),l=$s(s,["status"]);return i&&a.push(`Plan ${i}`),n&&a.push(n),l&&a.push(l),a.length?a.join(" · "):"No additional details."}function di(s){return Ne(s)}function mi(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 hi(s){const t=s.toLowerCase();return t==="task"?gs:t==="agent"?He:t==="plan"?Bs:t.includes("bg")||t.includes("background")||t.includes("job")?Nt:t==="mod"?Us:t==="skill"?Oe:t.includes("error")||t.includes("failure")?jn:t.includes("warn")?ke:Te}function ui(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 xi({item:s,activityKey:t,onNavigate:a,onHide:i}){const n=mi(s),l=hi(s.kind||""),c=oi(s.kind||"activity"),o=ci(s),p=ui(s.kind||""),x=n==="error"?"var(--error)":n==="warning"?"var(--warning)":n==="success"?"var(--success)":"var(--accent)";return e.jsxs("div",{className:K("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:di(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(Ce,{size:12})})]})}const pi=Ve.memo(ni);function gi({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 N=A.target;!h.current||!N||h.current.contains(N)||x()},j=A=>{A.key==="Escape"&&x()},b=window.setTimeout(()=>{document.addEventListener("mousedown",g),document.addEventListener("keydown",j)},0);return()=>{window.clearTimeout(b),document.removeEventListener("mousedown",g),document.removeEventListener("keydown",j)}},[x]),r.useEffect(()=>{if(t!=="rename")return;const g=window.setTimeout(()=>{var b;const j=(b=h.current)==null?void 0:b.querySelector("input.session-row-menu-input");j==null||j.focus(),j==null||j.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(Mn,{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 za.createPortal(u,document.body)}function mt({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,j)=>e.jsx(mt,{node:g,depth:t+1,collapsible:!1,isLast:j===s.children.length-1},g.id))})]})]})}function ji(s){return s.tree!==void 0}function fi(s){const t=s.open??!0;if(ji(s))return e.jsx("div",{className:`agent-tree variant-${s.variant??"full"}`,children:e.jsx(mt,{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(mt,{node:i,depth:0,collapsible:!1,open:t,isLast:n===a.length-1})},i.id))})})}function yi({children:s,variant:t="rail",open:a=!0}){return a?e.jsx(fi,{variant:t,open:a,children:s}):null}const vi=["Today","Yesterday","This week","Earlier"];function Rt(s,t){return s.getFullYear()===t.getFullYear()&&s.getMonth()===t.getMonth()&&s.getDate()===t.getDate()}function bi(s,t){const a=s.getTime()-t.getTime();return Math.floor(a/(1e3*60*60*24))}function ki(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());Rt(c,t)?n.Today.push(l):Rt(c,a)?n.Yesterday.push(l):bi(t,c)<7?n["This week"].push(l):n.Earlier.push(l)}return n}function Ni(s){return new Date(Number(s)||Date.now()).toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit",hour12:!1})}function wi({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 Si({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 z;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):ki(u),[d,u]),[j,b]=r.useState({}),A=_=>j[_]===!0,[N,w]=r.useState(null),[E,M]=r.useState("main"),[$,D]=r.useState(""),[f,F]=r.useState(null),S=r.useRef({}),y=(_,ae="main")=>{const J=S.current[_];if(!J)return;const q=ae==="main"?J:J.querySelector(".chat-rail-item-menu-trigger")??J;if(F({id:_,rect:q.getBoundingClientRect()}),w(_),M(ae),ae==="rename"){const X=[...s,...t].find(se=>se.id===_);D((X==null?void 0:X.title)??(X==null?void 0:X.id)??"")}},k=()=>{w(null),M("main"),D(""),F(null)},P=_=>{if(_.source==="opencode"){p(_);return}o(_.id)},v=()=>{if(!f)return;const _=f.id,ae=$.trim();if(!ae){k();return}x==null||x(_,ae),k()},L=()=>{f&&(h==null||h(f.id),k())},B=d?Object.entries(g):vi.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($e,{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(Ma,{icon:e.jsx($e,{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:B.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 q=J.source==="opencode",X=q?i===J.id:a===J.id,se=J.tree,Z=!!((fe=se==null?void 0:se.root)!=null&&fe.children&&se.root.children.length>0),re=A(J.id);return e.jsxs(r.Fragment,{children:[e.jsxs("div",{ref:I=>{S.current[J.id]=I},role:"button",tabIndex:0,className:`chat-rail-item state-${J.state??"idle"}${X?" active":""}`,onClick:()=>P(J),onKeyDown:I=>{(I.key==="Enter"||I.key===" ")&&(I.preventDefault(),P(J))},"aria-current":X?"true":void 0,children:[e.jsx(wi,{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:"★"}),q&&e.jsx(os,{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??Ni(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${N===J.id?" open":""}`,"aria-label":`Session options for ${J.title||J.id}`,"aria-haspopup":"menu","aria-expanded":N===J.id,onClick:I=>{I.stopPropagation(),N===J.id?k():y(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"})]})}),X&&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(U=>({...U,[J.id]:!U[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"})})})]}),X&&Z&&re&&((V=se==null?void 0:se.root)==null?void 0:V.children)&&e.jsx(yi,{children:se.root.children,variant:"rail",open:!0})]},q?`oc-${J.id}`:J.id)})]},_))}),N&&f&&e.jsx(gi,{session:{id:f.id,title:((z=[...s,...t].find(_=>_.id===f.id))==null?void 0:z.title)??f.id},mode:E,anchor:f,renameDraft:$,setRenameDraft:D,onEdit:()=>y(N,"rename"),onDeleteRequest:()=>y(N,"confirm-delete"),onConfirmDelete:L,onConfirmRename:v,onClose:k})]})}function Ci(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(Ta,{...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 Xs(s){return s.toLocaleString()}function zi(s){return!s||!s.includes("/")?"":s.split("/")[0]}function Mi(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 Ti({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 F=!1;return(async()=>{try{const S=await fetch("/api/usage?range=24h",{headers:{Accept:"application/json"}});if(!S.ok)return;const y=await S.json();F||g(y)}catch{}})(),()=>{F=!0}},[s]);const j=(t==null?void 0:t.length)??0,b=(a==null?void 0:a.size)??0,A=t.reduce((F,S)=>F+(S.content||S.message||"").length,0),N=Math.round(A/4),w=Mi(n),E=N/1e6*w,M=(u==null?void 0:u.totalTokens)??N,$=(u==null?void 0:u.costUsd)??E,D=128e3,f=zi(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(Hs,{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:[Xs(j)," message",j===1?"":"s",b>0&&` · ${b} pinned`]})]}),e.jsxs("div",{className:"chat-info-section",children:[e.jsxs("h4",{children:[e.jsx(He,{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(fs,{size:11,style:{marginRight:4,verticalAlign:-1},"aria-hidden":!0})," ","Model"]}),e.jsx("div",{className:"chat-mono chat-ellipsis",title:n,children:n||"—"}),f&&e.jsxs("div",{className:"chat-info-mono",children:["provider · ",f]})]}),e.jsxs("div",{className:"chat-info-section",children:[e.jsx("h4",{children:"Tokens"}),e.jsxs("div",{className:"chat-mono",children:[Xs(M)," / ",Xs(D)]}),e.jsx("div",{className:"chat-info-bar","aria-hidden":!0,children:e.jsx("div",{className:"chat-info-bar-fill",style:{width:`${Math.min(100,M/Math.max(1,D)*100)}%`}})})]}),e.jsxs("div",{className:"chat-info-section",children:[e.jsxs("h4",{children:[e.jsx(Xa,{size:11,style:{marginRight:4,verticalAlign:-1},"aria-hidden":!0})," ","Cost"]}),e.jsxs("div",{className:"chat-mono",children:["$",$.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(He,{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(F=>e.jsx("span",{className:"chat-info-agent",children:F.name},F.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(fs,{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(F=>e.jsx("span",{className:"chat-info-agent",children:F.id},F.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(ys,{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(Ns,{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(Ze,{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 $i({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(ea,{size:14,"aria-hidden":!0}),e.jsx("span",{children:"Jump to latest"}),t>0&&e.jsxs("span",{className:"jump-badge",children:[t," new"]})]})})}function Ai({snapshot:s,settings:t,setActiveTab:a,initialTaskId:i,onClearTaskId:n}){const l=oe(),c=De(),o=$a(s,t,i??"");r.useEffect(()=>{o.setToast({error:z=>l.error(z),success:z=>l.success(z),info:z=>l.info(z),warning:z=>l.warning(z)})},[o,l]);const[p,x]=r.useState(""),[h,d]=r.useState(t.defaultAgent||"odin"),[m,u]=r.useState(t.defaultModel||""),[g,j]=r.useState([]),b=r.useRef(null),{allCommands:A,suggestions:N,setQuery:w}=Aa(s);r.useEffect(()=>{w(p)},[p,w]);const E=()=>{var z;return(z=b.current)==null?void 0:z.click()},M=z=>{const _=z.target.files;if(!_)return;const ae=[];for(let J=0;J<_.length;J++)ae.push(_[J].name);j(J=>{const q=ae.filter(X=>!J.includes(X));return[...J,...q]}),b.current&&(b.current.value="")},$=async()=>{const z=p.trim();if(!z)return;x(""),w(""),(await o.onSend(z,h,m,g)).ok&&o.jumpToLatest()},D=async()=>{o.busy.create||await o.onCreateSession()},f=z=>{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(R,{variant:"secondary",size:"sm",onClick:()=>c.close(),children:"Cancel"}),e.jsx(R,{variant:"danger",size:"sm",onClick:()=>{c.close(),o.deleteMessage(z)},children:"Delete"})]})})},F=(z,_)=>{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(z,ae).then(q=>{q&&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(R,{variant:"secondary",size:"sm",onClick:()=>c.close(),children:"Cancel"}),e.jsx(R,{variant:"primary",size:"sm",onClick:()=>{c.close(),o.renameSession(z,ae)},children:"Save"})]})})},S=(z,_)=>{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(R,{variant:"secondary",size:"sm",onClick:()=>c.close(),children:"Cancel"}),e.jsx(R,{variant:"danger",size:"sm",onClick:async()=>{c.close(),await o.deleteSession(z)},children:"Delete"})]})})},y=()=>{const z=o.activeSource==="opencode"?o.activeOpencodeSessionId:o.sessionId;if(!z)return;const ae=(o.activeSource==="opencode"?o.opencodeMessages:o.bizarMessages).map(se=>{const Z=se.ts??"",re=(se.role||"unknown").toUpperCase(),fe=se.content||se.message||"";return`[${Z}] ${re}: ${fe}`}).join(`
|
|
352
|
+
|
|
353
|
+
`),J=new Blob([ae],{type:"text/plain;charset=utf-8"}),q=URL.createObjectURL(J),X=document.createElement("a");X.href=q,X.download=`${z}.txt`,document.body.appendChild(X),X.click(),document.body.removeChild(X),URL.revokeObjectURL(q)},k=r.useMemo(()=>o.sessions.map(z=>o.getSessionDisplay(z)),[o.sessions,o.getSessionDisplay]),P=r.useMemo(()=>o.opencodeSessions.map(z=>o.getSessionDisplay(z)),[o.opencodeSessions,o.getSessionDisplay]),v=r.useMemo(()=>{const z=o.activeSource==="opencode"?o.activeOpencodeSessionId??"":o.sessionId;return z?k.find(_=>_.id===z)??P.find(_=>_.id===z)??null:null},[o.activeSource,o.activeOpencodeSessionId,o.sessionId,k,P]),L=(()=>{var ae;const z=`${h||"Odin"} · ${((ae=s.activeProject)==null?void 0:ae.name)??"no project"}`,_=(v==null?void 0:v.state)??"idle";return _==="streaming"?`Replying · ${z}`:_==="awaiting"?`Your turn · ${z}`:`${z} · idle`})(),B=o.activeSource==="opencode"?"opencode":"bizar chat";return e.jsxs("div",{className:"chat-shell",children:[e.jsx(Ra,{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(Si,{sessions:k,opencodeSessions:P,activeSessionId:o.sessionId,activeOpencodeSessionId:o.activeOpencodeSessionId,activeProject:s.activeProject,creating:o.busy.create,onCreateSession:D,onSelectSession:o.selectBizarSession,onSelectOpencodeSession:z=>o.loadOpencodeSession(z.id),onRenameSession:F,onDeleteSession:z=>{const _=o.sessions.find(ae=>ae.id===z)??o.opencodeSessions.find(ae=>ae.id===z);S(z,(_==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:(v==null?void 0:v.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:B})]}),e.jsxs("div",{className:`chat-thread-sub chat-muted state-${(v==null?void 0:v.state)??"idle"}`,children:[e.jsx("span",{className:"chat-thread-dot"}),L]}),o.opencodeError&&e.jsx("div",{className:"chat-thread-error",role:"alert",children:o.opencodeError})]}),e.jsxs("div",{className:"chat-thread-actions",children:[v&&e.jsxs("button",{className:"btn btn-ghost",title:"Rename session",type:"button",disabled:o.busy.rename,onClick:()=>F(v.id,v.title??""),children:[e.jsx(Ns,{size:12,"aria-hidden":!0})," ",e.jsx("span",{className:"mono",children:"rename"})]}),v&&e.jsxs("button",{className:"btn btn-ghost btn-danger",title:"Delete session",type:"button",disabled:o.busy.delete,onClick:()=>S(v.id,v.title??v.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:y,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(La,{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:z=>x(z),onCopy:z=>o.copyMessage(z),onDelete:f,onTogglePin:o.togglePin,onRegenerate:o.onRegenerate})}),!o.stickToBottom&&e.jsx($i,{streaming:(v==null?void 0:v.state)==="streaming",newMessageCount:o.newMessageCount,onClick:o.jumpToLatest}),e.jsx(Ci,{agent:h,setAgent:d,model:m,setModel:u,text:p,setText:x,sending:o.sending,activeSource:o.activeSource,onSend:$,attachments:g,setAttachments:j,suggestions:N,onPickSuggestion:z=>x(`${z.split(" ")[0]} `),agents:s.agents||[],onAttach:E}),e.jsx("input",{ref:b,type:"file",multiple:!0,style:{display:"none"},onChange:M,"aria-label":"Attach files to message",tabIndex:-1})]}),e.jsx(Ti,{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:()=>{v&&F(v.id,v.title??"")},onDelete:()=>{v&&S(v.id,v.title??v.id)},onExport:y,busy:o.busy})]})]})}function is({kind:s="neutral",children:t,className:a,dot:i=!1}){return e.jsxs("span",{className:K("badge",`badge-${s}`,a),children:[i&&e.jsx("span",{className:"badge-dot"}),t]})}const Lt=["bash","read","edit","write","webfetch","websearch","task","glob","grep"],It=["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"],Es=[{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 Ri(s){var t;return((t=Es.find(a=>a.id===s))==null?void 0:t.color)||"var(--text-dim)"}function Li({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 Ii({agent:s}){if(s.isStuck)return e.jsx(is,{kind:"error",dot:!0,children:"stuck"});const t=s.status||"idle";return t==="working"?e.jsx(is,{kind:"info",dot:!0,children:"working"}):t==="error"?e.jsx(is,{kind:"error",dot:!0,children:"error"}):e.jsx(is,{kind:"neutral",dot:!0,children:"idle"})}function Ei({snapshot:s,refreshSnapshot:t}){const a=oe(),i=De(),[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 M=await C.get("/agents");l(M.agents||[])}catch(M){a.error(`Agents load failed: ${M.message}`)}finally{o(!1)}},u=r.useMemo(()=>{let M=[...n];if(p&&(M=M.filter($=>p==="__none__"?!$.category:($.category||"")===p)),h){const $=h.toLowerCase();M=M.filter(D=>D.name.toLowerCase().includes($)||(D.description||"").toLowerCase().includes($)||(D.tags||[]).some(f=>f.toLowerCase().includes($)))}return M.sort(($,D)=>$.name.localeCompare(D.name))},[n,p,h]),g=r.useMemo(()=>{const M=new Set;for(const $ of n)for(const D of $.tags||[])M.add(D);return Array.from(M).sort()},[n]),j=()=>{let M=null,$=null,D=null,f=null,F=null,S=null,y=null,k=null,P=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:v=>M=v,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:v=>{$=v},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:v=>D=v,className:"select",defaultValue:"",children:[e.jsx("option",{value:"",children:"(provider default)"}),It.map(v=>e.jsx("option",{value:v,children:v},v))]})]}),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:v=>f=v,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:v=>F=v,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:v=>P=v,className:"select",defaultValue:"",children:[e.jsx("option",{value:"",children:"(none)"}),Es.map(v=>e.jsx("option",{value:v.id,children:v.label},v.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:v=>k=v,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:v=>y=v,className:"agent-tools",children:Lt.map(v=>e.jsxs("label",{className:"checkbox-row",children:[e.jsx("input",{type:"checkbox",value:v,"aria-label":v}),e.jsx("span",{children:v})]},v))})]}),e.jsx("label",{className:"field-label",htmlFor:"agent-new-prompt",children:"System prompt"}),e.jsx("textarea",{id:"agent-new-prompt",ref:v=>S=v,className:"textarea",rows:6,placeholder:"You are a..."})]}),footer:e.jsxs("div",{className:"modal-footer-actions",children:[e.jsx(R,{variant:"ghost",onClick:()=>i.close(),children:"Cancel"}),e.jsxs(R,{variant:"primary",onClick:async()=>{const v=((M==null?void 0:M.value)||"").trim();if(!/^[a-z0-9][a-z0-9-]{0,63}$/i.test(v)){a.warning("Invalid name (a-z, 0-9, dashes).");return}const L=[];y&&y.querySelectorAll('input[type="checkbox"]:checked').forEach(z=>{L.push(z.value)});const B=((k==null?void 0:k.value)||"").split(",").map(z=>z.trim()).filter(Boolean);try{const z=await C.post("/agents",{name:v,description:(($==null?void 0:$.value)||"").trim(),model:(D==null?void 0:D.value)||"",mode:(f==null?void 0:f.value)||"subagent",color:(F==null?void 0:F.value)||"",tools:L,tags:B,category:(P==null?void 0:P.value)||"",prompt:(S==null?void 0:S.value)||""});l(_=>[..._,z]),a.success("Agent created."),i.close(),await t()}catch(z){a.error(`Create failed: ${z.message}`)}},children:[e.jsx(vs,{size:12})," Create"]})]})})},b=async M=>{let $=null,D=null,f=null,F=null,S=null,y=null,k=null,P=null;try{const v=await C.get(`/agents/${encodeURIComponent(M.name)}`);i.open({title:`Edit ${M.name}`,width:640,children:e.jsxs("div",{className:"agent-form",children:[e.jsxs("div",{className:"muted",children:["File: ",e.jsx("code",{children:v.path})]}),e.jsx("label",{className:"field-label",htmlFor:"agent-edit-desc",children:"Description"}),e.jsx("input",{id:"agent-edit-desc",ref:L=>{$=L},className:"input",type:"text",defaultValue:v.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:L=>D=L,className:"select",defaultValue:v.model,children:[e.jsx("option",{value:"",children:"(provider default)"}),It.map(L=>e.jsx("option",{value:L,children:L},L))]})]}),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:L=>f=L,className:"select",defaultValue:v.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:L=>F=L,className:"input",type:"color",defaultValue:v.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:L=>P=L,className:"select",defaultValue:v.category||"",children:[e.jsx("option",{value:"",children:"(none)"}),Es.map(L=>e.jsx("option",{value:L.id,children:L.label},L.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:L=>k=L,className:"input",type:"text",defaultValue:(v.tags||[]).join(", ")})]})]}),e.jsxs("fieldset",{children:[e.jsx("legend",{className:"field-label",style:{padding:0},children:"Tools"}),e.jsx("div",{ref:L=>y=L,className:"agent-tools",children:Lt.map(L=>{var B;return e.jsxs("label",{className:"checkbox-row",children:[e.jsx("input",{type:"checkbox",value:L,"aria-label":L,defaultChecked:(B=v.tools)==null?void 0:B.includes(L)}),e.jsx("span",{children:L})]},L)})})]}),e.jsx("label",{className:"field-label",htmlFor:"agent-edit-prompt",children:"System prompt"}),e.jsx("textarea",{id:"agent-edit-prompt",ref:L=>S=L,className:"textarea",rows:8,defaultValue:v.prompt||""})]}),footer:e.jsxs("div",{className:"modal-footer-actions",children:[e.jsx(R,{variant:"ghost",onClick:()=>i.close(),children:"Cancel"}),e.jsxs(R,{variant:"primary",onClick:async()=>{const L=[];y&&y.querySelectorAll('input[type="checkbox"]:checked').forEach(z=>{L.push(z.value)});const B=((k==null?void 0:k.value)||"").split(",").map(z=>z.trim()).filter(Boolean);try{const z=await C.put(`/agents/${encodeURIComponent(M.name)}`,{description:(($==null?void 0:$.value)||"").trim(),model:(D==null?void 0:D.value)||"",mode:(f==null?void 0:f.value)||"subagent",color:(F==null?void 0:F.value)||"",tools:L,tags:B,category:(P==null?void 0:P.value)||"",prompt:(S==null?void 0:S.value)||""});l(_=>_.map(ae=>ae.name===M.name?z:ae)),a.success("Agent saved."),i.close(),await t()}catch(z){a.error(`Save failed: ${z.message}`)}},children:[e.jsx(vs,{size:12})," Save"]})]})})}catch(v){a.error(`Load failed: ${v.message}`)}},A=async M=>{if(confirm(`Delete agent "${M.name}"? This removes ${M.path}.`))try{await C.del(`/agents/${encodeURIComponent(M.name)}`),l($=>$.filter(D=>D.name!==M.name)),a.success("Agent deleted.")}catch($){a.error(`Delete failed: ${$.message}`)}},N=async M=>{let $=null;i.open({title:`Invoke ${M.name}`,children:e.jsxs("div",{className:"invoke-form",children:[e.jsxs("p",{className:"muted invoke-form-meta mono",children:[M.model||"—"," · ",M.path]}),e.jsx("p",{className:"invoke-form-desc",children:M.description}),e.jsx("label",{className:"field-label",htmlFor:"invoke-prompt",children:"Prompt"}),e.jsx("textarea",{ref:D=>$=D,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(R,{variant:"ghost",onClick:()=>i.close(),children:"Cancel"}),e.jsxs(R,{variant:"primary",onClick:async()=>{const D=(($==null?void 0:$.value)||"").trim();if(!D){a.warning("Prompt is required.");return}try{await C.post(`/agents/${encodeURIComponent(M.name)}/invoke`,{prompt:D}),a.success(`Invoked ${M.name}.`),i.close()}catch(f){a.error(`Invoke failed: ${f.message}`)}},children:[e.jsx(ws,{size:14})," Invoke"]})]})})},w=async M=>{try{const $=await C.post(`/agents/${encodeURIComponent(M.name)}/restart`);l(D=>D.map(f=>f.name===M.name?$:f)),a.success(`${M.name} restarted.`)}catch($){a.error(`Restart failed: ${$.message}`)}},E=async(M,$)=>{try{const D=await C.post(`/agents/${encodeURIComponent(M.name)}/status`,{status:$});l(f=>f.map(F=>F.name===M.name?D:F))}catch(D){a.error(`Status update failed: ${D.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(He,{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:M=>d(M.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:M=>x(M.target.value),children:[e.jsx("option",{value:"",children:"All categories"}),Es.map(M=>e.jsx("option",{value:M.id,children:M.label},M.id)),e.jsx("option",{value:"__none__",children:"(no category)"})]}),e.jsxs(R,{variant:"secondary",size:"sm",onClick:m,children:[e.jsx(ce,{size:14})," Refresh"]}),e.jsxs(R,{variant:"primary",size:"sm",onClick:j,children:[e.jsx($e,{size:14})," New agent"]})]})]}),g.length>0&&e.jsxs("div",{className:"agent-tags-row",children:[e.jsx(ra,{size:12}),g.map(M=>e.jsx("span",{className:"tag",children:M},M))]}),c?e.jsx("div",{className:"view-loading",children:e.jsx(he,{size:"lg"})}):u.length===0?e.jsx(we,{icon:e.jsx(He,{size:32}),title:"No agents found",message:"Run bizar in the terminal to install Bizar."}):e.jsx("div",{className:"agent-grid",children:u.map(M=>e.jsx(Di,{agent:M,onInvoke:()=>N(M),onEdit:()=>b(M),onDelete:()=>A(M),onRestart:()=>w(M),onSetStatus:$=>E(M,$)},M.name))})]})}function Di({agent:s,onInvoke:t,onEdit:a,onDelete:i,onRestart:n,onSetStatus:l}){const[c,o]=r.useState(!1),p=Ri(s.category),x=(s.status==="working"||!!s.currentTaskId)&&!s.isStuck;return e.jsxs(Y,{variant:"elevated",interactive:!0,className:K("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(Li,{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(Ii,{agent:s})]})]}),e.jsx("p",{className:"agent-card-desc",children:Gt(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(_e,{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(Za,{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(R,{variant:"primary",size:"sm",onClick:t,children:[e.jsx(ws,{size:12})," Invoke"]}),e.jsxs(R,{variant:"secondary",size:"sm",onClick:a,children:[e.jsx(Ns,{size:12})," Edit"]}),(s.isStuck||s.status==="working"||s.status==="error")&&e.jsxs(R,{variant:"ghost",size:"sm",onClick:n,title:"Reset agent status",children:[e.jsx(jt,{size:12})," Restart"]}),e.jsx(R,{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(We,{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(R,{variant:s.status==="idle"?"primary":"ghost",size:"sm",onClick:()=>l("idle"),children:"Idle"}),e.jsx(R,{variant:s.status==="working"?"primary":"ghost",size:"sm",onClick:()=>l("working"),children:"Working"}),e.jsx(R,{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 Pi({id:s,children:t}){return e.jsx("div",{id:s,"data-block-id":s,className:K("glyph-richtext"),style:da,children:e.jsx(Kt,{remarkPlugins:[Yt],children:t})})}const Fi={info:{bg:"var(--info-soft, rgba(96, 165, 250, 0.12))",border:"var(--info)",fg:"var(--info)",icon:_s,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:_e,label:"Success"},danger:{bg:"var(--error-soft, rgba(248, 113, 113, 0.12))",border:"var(--error)",fg:"var(--error)",icon:Xe,label:"Danger"}};function Oi({id:s,tone:t="info",children:a}){const i=Fi[t],n=i.icon;return e.jsxs("div",{id:s,"data-block-id":s,className:K("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:{...da,fontSize:14},children:e.jsx(Kt,{remarkPlugins:[Yt],children:a})})]})]})}function Bi({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(rt,{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 Ui({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 qi({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 Hi({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 _i({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:Et,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:Et}),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 Et={padding:"6px 10px",fontSize:13,borderRadius:6,border:"1px solid var(--border-strong)",background:"var(--bg)",color:"var(--text)",fontFamily:"inherit"},Wi={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 Vi({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=Wi[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 Gi({id:s,filename:t,language:a,mode:i="unified",before:n,after:l}){const c=n.split(`
|
|
354
|
+
`),o=l.split(`
|
|
355
|
+
`),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(sn,{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"},j={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:j[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 Ki={up:{fg:"var(--success)",Icon:Fe,label:"trending up"},down:{fg:"var(--error)",Icon:Fe,label:"trending down"},flat:{fg:"var(--text-dim)",Icon:gn,label:"flat"}};function Yi({id:s,label:t,value:a,trend:i,hint:n}){const l=i?Ki[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 Xi={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)"}},ze=160,Le=56,es=60,ss=80;function Qi({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(Zi,{id:s})});const i=new Map(t.map(h=>[h.id,h])),n=Ji(t),l=Math.max(...n.map(h=>h.col))+1,c=Math.max(...n.map(h=>h.row))+1,o=l*(ze+es)+es,p=c*(Le+ss)+ss;function x(h){if(!i.get(h))return null;const m=n.find(u=>u.id===h);return m?{x:es+m.col*(ze+es)+ze/2,y:ss+m.row*(Le+ss)+Le/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,j=u.y-m.y,b=g>=0?m.x+ze/2:m.x-ze/2,A=g>=0?u.x-ze/2:u.x+ze/2,N=j>=0?m.y+Le/2:m.y-Le/2,w=j>=0?u.y-Le/2:u.y+Le/2,E=(b+A)/2,M=(N+w)/2;return e.jsxs("g",{children:[e.jsx("line",{x1:b,y1:N,x2:A,y2:w,stroke:"var(--text-dim)",strokeWidth:1.5,markerEnd:`url(#arrow-${s})`}),h.label&&e.jsx("text",{x:E,y:M-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=es+d.col*(ze+es),u=ss+d.row*(Le+ss),g=Xi[h.type];if(h.type==="decision"){const b=m+ze/2,A=u+Le/2,N=[[b,u],[m+ze,A],[b,u+Le],[m,A]].map(w=>w.join(",")).join(" ");return e.jsxs("g",{children:[e.jsx("polygon",{points:N,fill:g.fill,stroke:g.stroke,strokeWidth:2}),e.jsx("foreignObject",{x:m+8,y:A-14,width:ze-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(Ja,{size:11}),h.label]})})]},h.id)}const j=h.type==="note";return e.jsxs("g",{children:[e.jsx("rect",{x:m,y:u,width:ze,height:Le,rx:8,fill:g.fill,stroke:g.stroke,strokeWidth:j?1:2,strokeDasharray:j?"4 3":void 0}),e.jsx("foreignObject",{x:m+6,y:u+6,width:ze-12,height:Le-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:j?"italic":"normal",height:"100%"},children:[j&&e.jsx(Ia,{size:11}),h.label]})})]},h.id)})]})})}function Zi({id:s}){return e.jsx("div",{id:s,style:{padding:20,textAlign:"center",color:"var(--text-dim)",fontSize:13},children:"No workflow steps."})}function Ji(s){return s.length===0?[]:s.map((t,a)=>({id:t.id,col:a,row:0}))}const da={fontSize:14,lineHeight:1.6,color:"var(--text)"};function er({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 sr extends Ve.Component{constructor(){super(...arguments);ds(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 tr(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 ar={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 nr(s){const t=[];let a={heading:null,blocks:[]};for(const i of s){const n=ar[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 ir({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,j]=r.useState(!1),[b,A]=r.useState(!1),[N,w]=r.useState(null),[E,M]=r.useState(null),[$,D]=r.useState(""),[f,F]=r.useState(null),[S,y]=r.useState([]),k=Ve.useCallback((I,U,H)=>{y(ne=>ne.some(W=>W.blockId===I)?ne:[...ne,{blockId:I,blockType:U,message:H.message||String(H)}])},[]),P=r.useRef(null),v=r.useMemo(()=>n?nr(n.blocks):[],[n]);r.useEffect(()=>{let I=!1;const U=5e3;return(async()=>{x(!0),d(null);try{const H=new Promise((le,te)=>setTimeout(()=>te(new Error("Request timed out after 5s")),U)),[ne,W]=await Promise.race([Promise.all([C.get(`/artifacts/${encodeURIComponent(s)}/render`),C.get(`/artifacts/${encodeURIComponent(s)}`)]),H]);if(I)return;l(ne);const O=(W==null?void 0:W.comments)??[];o(Array.isArray(O)?O:[])}catch(H){if(!I){const ne=H.message;d(ne),u(ne)}}finally{I||x(!1)}})(),()=>{I=!0}},[s]);function L(I){if(!P.current)return;I.preventDefault();const U=P.current.getBoundingClientRect();w({x:I.clientX,y:I.clientY,worldX:I.clientX-U.left,worldY:I.clientY-U.top})}async function B(){if(!(!E||!$.trim()))try{const I=await C.post(`/artifacts/${encodeURIComponent(s)}/comments`,{x:E.worldX,y:E.worldY,text:$.trim(),author:"drb0rk"});o(U=>[...U,{id:I.id??`cmt_${Date.now()}`,x:E.worldX,y:E.worldY,text:$.trim(),author:"drb0rk",created:new Date().toISOString()}]),M(null),D(""),w(null),a==null||a(),i.success("Comment added")}catch(I){i.error(`Failed to add comment: ${I.message}`)}}async function z(){if(!g){j(!0);try{const I=await C.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{j(!1)}}}function _(){A(I=>!I)}const ae=I=>{const U=I.id,H=I.data??{},ne=tr(I);return ne.ok?e.jsx(sr,{blockId:U,blockType:I.type,onError:k,children:J(I,U,H)},U):e.jsxs("div",{id:U,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:U})]}),e.jsx("pre",{style:{margin:0,whiteSpace:"pre-wrap",wordBreak:"break-word"},children:ne.error})]},U)},J=(I,U,H)=>{switch(I.type){case"RichText":return e.jsx(Pi,{id:U,children:I.childrenMarkdown??""},U);case"Callout":return e.jsx(Oi,{id:U,tone:H.tone??"info",children:I.childrenMarkdown??""},U);case"Checklist":return e.jsx(Bi,{id:U,items:H.items??[]},U);case"Table":return e.jsx(Ui,{id:U,columns:H.columns??[],rows:H.rows??[]},U);case"CodeTabs":return e.jsx(qi,{id:U,tabs:H.tabs??[]},U);case"Decision":return e.jsx(Hi,{id:U,title:H.title,question:H.question,options:H.options??[]},U);case"OpenQuestions":return e.jsx(_i,{id:U,questions:H.questions??[]},U);case"FileTree":return e.jsx(Vi,{id:U,title:H.title,entries:H.entries??[]},U);case"Diff":return e.jsx(Gi,{id:U,filename:H.filename,language:H.language,mode:H.mode??"unified",before:H.before??"",after:H.after??""},U);case"Stat":return e.jsx(Yi,{id:U,label:H.label??"",value:H.value,trend:H.trend,hint:H.hint},U);case"Workflow":return e.jsx(Qi,{id:U,steps:H.steps??[],connections:H.connections},U);case"Mockup":return e.jsx(er,{id:U,title:H.title,x:H.x,y:H.y,w:H.w,h:H.h,html:H.html??""},U);case"Diagram":return e.jsx("div",{id:U,className:"glyph-block-placeholder",children:e.jsxs("em",{children:["[Diagram] ",U]})},U)}};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(rr,{})," 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 q=((Z=n.frontmatter)==null?void 0:Z.title)??s,X=((re=n.frontmatter)==null?void 0:re.status)??"draft",se=c.length;return e.jsxs("div",{className:`glyph-canvas ${b?"glyph-canvas--fullscreen":""}`,ref:P,onContextMenu:L,children:[e.jsxs("div",{className:"glyph-toolbar-floating",children:[e.jsxs("button",{className:"glyph-btn glyph-btn--primary glyph-btn--send",onClick:z,disabled:g,title:"Send comments + question answers to the agent — writes feedback.md, status=review",children:[e.jsx(Qe,{size:14}),e.jsx("span",{children:"Send to agent"}),e.jsx("span",{className:"glyph-btn-badge",children:se})]}),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(Cn,{size:15})}),e.jsx("button",{className:"glyph-icon-btn",title:"Undo",disabled:!0,children:e.jsx(An,{size:15})}),e.jsx("button",{className:"glyph-icon-btn",title:"Redo",disabled:!0,children:e.jsx(Sn,{size:15})}),e.jsx("button",{className:"glyph-icon-btn",title:b?"Exit fullscreen":"Fullscreen",onClick:_,children:e.jsx(pn,{size:15})}),e.jsx("button",{className:"glyph-icon-btn",title:"More",children:e.jsx(en,{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(Hs,{size:15}),e.jsx("span",{className:"glyph-icon-btn-count",children:se})]}),t&&e.jsx("button",{className:"glyph-icon-btn glyph-icon-btn--close",title:"Close",onClick:t,"aria-label":"Close",children:e.jsx(Ce,{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:q}),e.jsxs("div",{className:"glyph-meta",children:[e.jsx("span",{className:`glyph-status glyph-status--${X}`,children:X}),e.jsx("span",{className:"glyph-slug",children:s})]})]}),(S.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:S.length>0?`${S.length} block${S.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:[S.map((I,U)=>e.jsxs("li",{children:[e.jsx("strong",{children:I.blockType})," (",e.jsx("code",{children:I.blockId}),"): ",I.message]},`be-${U}`)),(V=n.errors)==null?void 0:V.map((I,U)=>e.jsxs("li",{children:[I.line?`line ${I.line}: `:"",I.message]},`ce-${U}`))]})]}),e.jsx("div",{className:"glyph-sections",children:v.map((I,U)=>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-${U}-${I.heading??"ungrouped"}`))})]}),c.map(I=>e.jsxs("button",{className:`glyph-pin ${f===I.id?"glyph-pin--active":""}`,style:{left:I.x,top:I.y},onClick:U=>{U.stopPropagation(),F(f===I.id?null:I.id)},title:I.text,children:[e.jsx($t,{size:14}),f===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)),N&&e.jsx("div",{className:"glyph-ctx-menu",style:{left:N.x,top:N.y},onClick:I=>I.stopPropagation(),children:e.jsxs("button",{className:"glyph-ctx-item",onClick:()=>{M({worldX:N.worldX,worldY:N.worldY}),w(null)},children:[e.jsx($t,{size:14})," Add comment here"]})}),E&&e.jsx("div",{className:"glyph-modal-overlay",onClick:()=>M(null),children:e.jsxs("div",{className:"glyph-modal",onClick:I=>I.stopPropagation(),children:[e.jsxs("h3",{children:["Add comment at (",Math.round(E.worldX),", ",Math.round(E.worldY),")"]}),e.jsx("textarea",{autoFocus:!0,value:$,onChange:I=>D(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:()=>M(null),children:"Cancel"}),e.jsx("button",{className:"glyph-btn glyph-btn--primary",onClick:B,disabled:!$.trim(),children:"Add comment"})]})]})})]})}function rr(){return e.jsx("span",{className:"glyph-spinner","aria-label":"loading",children:"…"})}function lr(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 or({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 C.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 N=x.toLowerCase();A=A.filter(w=>(w.slug||"").toLowerCase().includes(N)||(w.title||"").toLowerCase().includes(N))}return d||(A=A.filter(N=>N.status!=="archived")),A},[i,x,d]),j=async(A,N)=>{try{const w=await C.post("/artifacts",{slug:A,title:N});a.success(`Artifact "${w.slug}" created.`),p(w.slug),await u()}catch(w){a.error(`Create failed: ${w.message}`)}},b=async A=>{if(confirm(`Delete artifact "${A}"? This removes the directory permanently.`))try{await C.del(`/artifacts/${encodeURIComponent(A)}`),a.success("Artifact deleted."),o===A&&p(null),await u()}catch(N){a.error(`Delete failed: ${N.message}`)}};return o?e.jsxs("div",{className:"artifact-glyph-overlay",children:[e.jsx("div",{className:"artifact-glyph-toolbar",children:e.jsxs(R,{variant:"ghost",onClick:()=>{p(null),u()},children:[e.jsx(sa,{size:14})," Back to artifacts"]})}),e.jsx(ir,{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(Bs,{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(ve,{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(R,{variant:"ghost",size:"sm",onClick:()=>m(A=>!A),title:d?"Hide archived":"Show archived",children:[d?e.jsx(Jt,{size:14}):e.jsx(Ea,{size:14}),d?"Hide archived":"Show archived"]}),e.jsxs(R,{variant:"secondary",size:"sm",onClick:u,children:[e.jsx(ce,{size:14})," Refresh"]})]})]}),e.jsx(cr,{onCreate:j}),l?e.jsx("div",{className:"view-loading",children:e.jsx(he,{size:"lg"})}):g.length===0?e.jsx(we,{icon:e.jsx(Bs,{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(dr,{artifact:A,onOpen:()=>p(A.slug),onDelete:()=>b(A.slug)},A.slug))})]})}function cr({onCreate:s}){const[t,a]=r.useState(""),[i,n]=r.useState("");return e.jsxs(Y,{className:"new-artifact",children:[e.jsxs(ee,{children:[e.jsx($e,{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(R,{variant:"primary",type:"submit",children:"Create"})]})]})}function dr({artifact:s,onOpen:t,onDelete:a}){const i=lr(s.status||"draft");return e.jsxs(Y,{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(is,{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(R,{variant:"primary",size:"sm",onClick:n=>{n.stopPropagation(),t()},children:["Open",e.jsx(We,{size:12})]}),e.jsxs(R,{variant:"ghost",size:"sm",onClick:n=>{n.stopPropagation(),a()},children:[e.jsx(Ae,{size:12})," Delete"]})]})]})}function mr({children:s,className:t,onRemove:a}){return e.jsxs("span",{className:K("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 hr({task:s,agents:t,onPromote:a,onDelete:i,onEdit:n,onRefresh:l}){var h;const c=oe(),o=async()=>{try{await C.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 C.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(yt,{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 ur({agents:s,onRefresh:t}){const a=oe(),[i,n]=r.useState([]),[l,c]=r.useState(!1),o=async()=>{try{c(!0);const m=await C.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 C.post("/tasks/promote-batch",{ids:i.map(j=>j.id)})).affected)==null?void 0:m.filter(j=>j.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(Os,{size:15}),"Backlog (",i.length,")"]}),e.jsxs("div",{className:"backlog-panel-header-actions",children:[i.length>0&&e.jsxs(R,{variant:"ghost",size:"sm",onClick:d,title:"Promote all to queued",children:[e.jsx(yt,{size:12})," Promote all"]}),e.jsx(R,{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(Os,{size:28}),e.jsx("span",{children:"Backlog is empty."})]}):e.jsx("div",{className:"backlog-list",children:i.map(m=>e.jsx(hr,{task:m,agents:s,onPromote:p,onDelete:x,onEdit:h,onRefresh:t},m.id))})]})}const Ds=[{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"}],wt=["low","normal","high"];function xr({snapshot:s,refreshSnapshot:t,setActiveTab:a}){const i=oe(),n=De(),[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),[j,b]=r.useState(0),[A,N]=r.useState(""),w=async()=>{try{const y=await C.get("/tasks");c(Array.isArray(y)?y:[])}catch(y){i.error(`Tasks load failed: ${y.message}`)}finally{p(!1)}};r.useEffect(()=>{s.tasks&&(c(s.tasks),p(!1))},[s.tasks]),r.useEffect(()=>{const y=setInterval(()=>b(k=>k+1),3e4);return()=>clearInterval(y)},[]);const E=r.useMemo(()=>{let y=l.filter(k=>k.status!=="backlog");if(d&&(y=y.filter(k=>(k.priority||"normal")===d)),x.trim()){const k=x.toLowerCase();y=y.filter(P=>(P.title||"").toLowerCase().includes(k)||(P.description||"").toLowerCase().includes(k))}return y},[l,x,d]),M=r.useMemo(()=>{const y={high:0,normal:1,low:2};return[...E].sort((k,P)=>{const v=y[k.priority]??1,L=y[P.priority]??1;return v!==L?v-L:new Date(P.createdAt).getTime()-new Date(k.createdAt).getTime()})},[E]),$=l.filter(y=>y.status==="backlog").length,D=async(y,k)=>{const P=l.find(L=>L.id===y);if(!P)return;const v=P.status;c(L=>L.map(B=>B.id===y?{...B,status:k}:B)),N(`Task ${P.title} moved to ${k}.`);try{await C.patch(`/tasks/${encodeURIComponent(y)}/status`,{status:k}),i.success(`Moved to ${k}.`,1200)}catch(L){c(B=>B.map(z=>z.id===y?{...z,status:v}:z)),N(`Failed to move task ${P.title}: ${L.message}`),i.error(`Move failed: ${L.message}`)}},f=async y=>{if(confirm("Delete this task?"))try{await C.del(`/tasks/${encodeURIComponent(y)}`),c(k=>k.filter(P=>P.id!==y)),i.success("Task deleted.",1200)}catch(k){i.error(`Delete failed: ${k.message}`)}},F=async y=>{try{const k=await C.post(`/tasks/${encodeURIComponent(y)}/start`);k&&k.task&&c(P=>P.map(v=>v.id===y?k.task:v)),i.success("Retry dispatched.",1200)}catch(k){i.error(`Retry failed: ${k.message}`)}},S=async y=>{const k=l.find(P=>P.id===y);if(k)try{const P=await C.post("/tasks/submit",{title:k.title,description:k.description,priority:k.priority,tags:k.tags}),v=(P.subtasks||[]).length;i.success(v>1?`Odin split it into ${v} subtasks.`:"Sent to Odin.",1500),P.subtasks&&P.subtasks.length>0&&c(L=>[P.main,...P.subtasks,...L.filter(B=>B.id!==k.id)]),await t()}catch(P){i.error(`Submit failed: ${P.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(gs,{size:18})," Tasks (",M.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(ve,{size:12,"aria-hidden":!0}),e.jsx("input",{className:"input",type:"text",placeholder:"Search…",value:x,onChange:y=>h(y.target.value),"aria-label":"Search tasks"}),x&&e.jsx("button",{type:"button",className:"icon-btn","aria-label":"Clear search",onClick:()=>h(""),children:e.jsx(Ce,{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:y=>m(y.target.value),title:"Filter by priority",children:[e.jsx("option",{value:"",children:"All"}),wt.map(y=>e.jsx("option",{value:y,children:y},y))]})]}),e.jsx("div",{className:"tasks-toolbar-spacer"}),e.jsxs("div",{className:"tasks-toolbar-group",children:[e.jsx(R,{variant:"ghost",size:"sm",onClick:w,title:"Refresh","aria-label":"Refresh tasks",children:e.jsx(ce,{size:14})}),$>0&&e.jsxs(R,{variant:u?"accent":"ghost",size:"sm",onClick:()=>g(y=>!y),title:u?"Hide backlog":"Show backlog",children:[e.jsx(Os,{size:14}),"Backlog",e.jsx("span",{className:"badge",children:$})]}),e.jsxs(R,{variant:"primary",size:"sm",onClick:()=>jr(n,i,c,w,t),children:[e.jsx($e,{size:14})," New task"]})]})]}),u&&$>0&&e.jsx(ur,{agents:s.agents||[],onRefresh:t}),o?e.jsx("div",{className:"view-loading",children:e.jsx(he,{size:"lg"})}):e.jsx("div",{className:"kanban",children:Ds.map(y=>e.jsx(pr,{column:y,tasks:M.filter(k=>k.status===y.id),onMove:D,onDelete:f,onRetry:F,onEdit:k=>fr(n,i,k,c,w,t),onSubmitToOdin:S,tick:j},y.id))})]})}function pr({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:K("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(ee,{children:[e.jsx("span",{className:K("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(gr,{task:h,onMove:d=>{const u=Ds.findIndex(g=>g.id===h.status)+d;u>=0&&u<Ds.length&&a(h.id,Ds[u].id)},onEdit:()=>l(h),onDelete:()=>i(h.id),onRetry:()=>n(h.id),onSubmitToOdin:()=>c(h.id),tick:o},h.id))})]})}function gr({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:K("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:Pa[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(He,{size:10})," @",o]}),s.timeSpent?e.jsxs("span",{className:"task-card-badge",children:[e.jsx(Fs,{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(mr,{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(Ya,{size:14})}),e.jsx("button",{type:"button",className:"icon-btn","aria-label":"Edit",title:"Edit",onClick:a,children:e.jsx(kn,{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(Qe,{size:14})}),e.jsx("button",{type:"button",className:"icon-btn","aria-label":"Retry",title:"Retry",onClick:n,children:e.jsx(jt,{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(We,{size:14})})]})]})]})}function jr(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",j=((o==null?void 0:o.value)||"").split(",").map(b=>b.trim()).filter(Boolean);try{const b=await C.post("/tasks",{title:m,description:u,priority:g,tags:j});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 Da(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:wt.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(R,{variant:"ghost",onClick:()=>s.close(),children:"Cancel"}),e.jsxs(R,{variant:"primary",type:"button",onClick:d=>x(d),children:[e.jsx($e,{size:14})," Create task"]})]})})}function fr(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(j=>j.trim()).filter(Boolean);try{const j=await C.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?j:A)),t.success("Task updated.",1200),await l()}catch(j){t.error(`Save failed: ${j.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:wt.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(Y,{children:[e.jsxs(ee,{children:[e.jsx(ra,{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(R,{variant:"ghost",onClick:()=>s.close(),children:"Cancel"}),e.jsxs(R,{variant:"primary",onClick:h,children:[e.jsx(Jt,{size:14})," Save"]})]})})}const yr=Ve.memo(xr);function vr(s){return C.urlWithToken(`/artifacts/${encodeURIComponent(s)}/content`)}function br(s,t){const a=vr(t);window.open(a,"_blank","noopener,noreferrer")}const Dt={"1m":60*1e3,"5m":5*60*1e3,"30m":30*60*1e3,"1h":60*60*1e3},Me=56,Be=32,ts=22,kr=4,Nr=.9,Qs={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 Zs(s){return s&&Qs[s]||Qs.idle}function As(s,t=24){return s?s.length<=t?s:s.slice(0,t-1)+"…":""}function qs(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 Js(s){const t=s._timerStart;return typeof t=="number"&&t>0?t:qs(s.createdAt)||Date.now()}function wr(s,t){return(s.status==="done"||s.status==="archived"||s.status==="failed"||s.status==="killed")&&(qs(s.completedAt)||qs(s.updatedAt))||t}function Sr(s){return typeof s.startedAt=="number"&&s.startedAt>0?s.startedAt:Date.now()}function Cr(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 zr(s){return s<=6e4?1e4:s<=3e5?3e4:s<=18e5?3e5:6e5}function Mr(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 Tr({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,j]=r.useState(!0),[b,A]=r.useState(0),[N,w]=r.useState(Date.now()),[E,M]=r.useState(()=>Date.now()-Dt["5m"]*.1),[$,D]=r.useState({width:800,height:400}),[f,F]=r.useState(null),[S,y]=r.useState(""),[k,P]=r.useState([]),[v,L]=r.useState(""),[B,z]=r.useState("normal"),[_,ae]=r.useState(""),[J,q]=r.useState(""),[X,se]=r.useState(!1),[Z,re]=r.useState(!1),[fe,V]=r.useState([]),I=De(),U=s.agents||[],H=s.tasks||[],ne=Dt[c],W=E,O=E+ne,le=r.useCallback(async()=>{try{const[T,G]=await Promise.all([C.get("/background").catch(()=>({instances:[]})),C.get("/activity?limit=200").catch(()=>({events:[]}))]);d(T.instances||[]),u(G.events||[])}catch(T){console.warn("activity reload failed:",T)}finally{j(!1)}},[]);r.useEffect(()=>{le();const T=setInterval(le,3e3);return()=>clearInterval(T)},[le]),r.useEffect(()=>{A(T=>T+1)},[H.length,U.length]),r.useEffect(()=>{if(n==="pause")return;w(Date.now());const T=setInterval(()=>w(Date.now()),1e3);return()=>clearInterval(T)},[n,b]),r.useEffect(()=>{if(n==="pause")return;(N-E)/ne>Nr&&M(N-ne*.1)},[N,E,ne,n]),r.useEffect(()=>{M(Date.now()-ne*.1)},[c]),r.useEffect(()=>{n==="live"&&M(Date.now()-ne*.1)},[n]),r.useLayoutEffect(()=>{const T=i.current;if(!T)return;const G=new ResizeObserver(xe=>{for(const pe of xe){const{width:me,height:ge}=pe.contentRect;D({width:Math.max(200,Math.floor(me)),height:Math.max(120,Math.floor(ge))})}});return G.observe(T),()=>G.disconnect()},[]);const te=r.useMemo(()=>{const T=[];let G=0;for(const me of h){const ge=Sr(me),Re=Cr(me,N);Re<W||ge>O||T.push({kind:"bg",id:`bg:${me.instanceId}`,index:G++,label:`BG ${As(me.promptPreview,20)||me.instanceId.slice(0,10)}`,sub:me.status||"pending",start:ge,end:Re,data:me})}const xe=[...H].sort((me,ge)=>Js(me)-Js(ge)),pe=[];for(const me of xe){const ge=Js(me),Re=wr(me,N);if(Re<W||ge>O)continue;let Je=-1;for(let Ge=0;Ge<pe.length;Ge++)if(pe[Ge]<=ge){pe[Ge]=Re,Je=Ge;break}Je===-1&&(pe.push(Re),Je=pe.length-1),T.push({kind:"task",id:`task:${me.id}`,index:G+Je,label:As(me.title,32),sub:me.status,start:ge,end:Re,data:me})}return T},[h,H,N,W,O]),ue=r.useMemo(()=>{const T=new Map;for(const G of te)T.set(G.id,G);return T},[te]),de=r.useCallback(T=>ne<=0?0:(T-W)/ne*$.width,[W,ne,$.width]),Ss=r.useMemo(()=>{const T=zr(ne),G=[],xe=Math.floor(W/T)*T;for(let pe=xe;pe<=O+T;pe+=T){if(pe<W-T)continue;if(pe>O)break;const me=de(pe);me<-40||me>$.width+40||G.push({t:pe,x:me,label:Mr(pe,ne)})}return G},[W,O,ne,$.width,de]),Cs=r.useMemo(()=>{const T=[];for(const G of te){if(G.kind==="events")continue;const xe=Math.max(G.start,W),pe=Math.min(G.end,O);if(pe<W||xe>O)continue;const me=de(xe),ge=de(pe),Re=Math.max(kr,ge-me),Je=Be+ts+G.index*Me+8,Ge=Me-16;let Pe="doing";if(G.kind==="bg"){const be=G.data.status||"pending";be==="done"||be==="success"?Pe="done":be==="failed"||be==="killed"||be==="error"?Pe="failed":be==="queued"||be==="pending"?Pe="queued":be==="blocked"||be==="stuck"?Pe="blocked":Pe="doing"}else{const be=G.data.status;be==="done"||be==="archived"?Pe="done":be==="failed"||be==="killed"?Pe="failed":be==="queued"?Pe="queued":be==="blocked"?Pe="blocked":Pe="doing"}const Na=(f==null?void 0:f.id)===G.id;T.push({id:G.id,laneIndex:G.index,x:me,y:Je,w:Re,h:Ge,label:G.label,statusClass:Pe,selected:Na,data:G.data,kind:G.kind,start:G.start,end:G.end})}return T},[te,de,f,W,O]),zs=r.useMemo(()=>{const T=[];for(const G of m){const xe=qs(G.ts);if(xe<W-5e3||xe>O+5e3)continue;const pe=de(xe);let me=Be+12;if(G.taskId){const ge=ue.get(`task:${G.taskId}`);ge&&(me=Be+ts+ge.index*Me+Me/2)}else if(G.nodeId){const ge=String(G.nodeId),Re=ue.get(ge.startsWith("task:")||ge.startsWith("bg:")?ge:`task:${ge}`);Re&&(me=Be+ts+Re.index*Me+Me/2)}T.push({id:`${G.ts}-${G.kind}-${G.author??""}-${G.taskId??""}`,x:pe,y:me,kind:G.kind||"event",ts:xe,text:String(G.text||G.kind||""),author:G.author})}return T},[m,W,O,de,ue]),Ms=r.useMemo(()=>te.map(T=>({id:T.id,y:Be+ts+T.index*Me,h:Me})),[te]),Ts=r.useMemo(()=>{const T=de(N);return Math.max(0,Math.min($.width,T))},[de,N,$.width]),fa=r.useCallback(T=>{const xe={id:T.id,kind:T.kind,label:T.label,status:T.statusClass,data:T.data};F(xe)},[]);r.useEffect(()=>{if(!f){P([]),q(""),V([]);return}y(""),L(""),ae(""),V([]),(async()=>{try{const T=await C.get(`/activity?nodeId=${encodeURIComponent(f.id)}&limit=50`);P(T.events||[])}catch{P([])}if(f.kind==="bg"){const T=f.data;try{const G=await C.get(`/background/${encodeURIComponent(T.instanceId)}/output?lines=80`);q(G.output||"")}catch{q("")}if(T.taskId)try{const G=await C.get(`/tasks/${encodeURIComponent(T.taskId)}/artifacts`);V((G.artifacts||[]).map(xe=>xe.id))}catch{V([])}}})()},[f]);const Mt=async()=>{if(!(!f||!S.trim())){re(!0);try{await C.post("/comments",{nodeId:f.id,text:S,author:"user"}),y("");const T=await C.get(`/activity?nodeId=${encodeURIComponent(f.id)}&limit=50`);P(T.events||[]),a.success("Comment added.")}catch(T){a.error(`Comment failed: ${T.message}`)}finally{re(!1)}}},ya=async()=>{if(!(!f||!v.trim())){se(!0);try{await C.post(`/nodes/${encodeURIComponent(f.id)}/tasks`,{title:v,description:`Created from timeline selection ${f.id}.`,priority:B}),L(""),a.success("Task created."),await t()}catch(T){a.error(`Task create failed: ${T.message}`)}finally{se(!1)}}},Tt=async()=>{if(!f||f.kind!=="bg"||!_.trim())return;const T=f.data;try{const G=await C.post(`/background/${encodeURIComponent(T.instanceId)}/message`,{message:_});G.ok?(a.success("Message sent."),ae("")):a.warning(G.error||"Send failed")}catch(G){a.error(`Send failed: ${G.message}`)}},va=async()=>{if(!f||f.kind!=="bg"||!confirm("Kill this bg instance session?"))return;const T=f.data;try{const G=await C.del(`/background/${encodeURIComponent(T.instanceId)}`);G.ok?a.success("Session killed."):a.warning(G.error||"Kill failed"),await le()}catch(G){a.error(`Kill failed: ${G.message}`)}},ba=async()=>{if(!f||f.kind!=="bg")return;const T=f.data;try{const G=await C.get(`/background/${encodeURIComponent(T.instanceId)}/output?lines=80`);q(G.output||"")}catch{}};r.useEffect(()=>{const T=G=>{G.key==="Escape"&&F(null)};return window.addEventListener("keydown",T),()=>window.removeEventListener("keydown",T)},[]);const ka=()=>{A(T=>T+1),le()},Vs=Be+ts+te.length*Me;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(R,{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(Fa,{size:14}):e.jsx(ws,{size:14}),n==="live"?"Live":"Paused"]}),e.jsx("div",{className:"tl-zoom-group",children:["1m","5m","30m","1h"].map(T=>e.jsx("button",{type:"button",className:K("tl-zoom-btn",c===T&&"tl-zoom-btn-active"),onClick:()=>o(T),title:`Zoom to ${T}`,children:T},T))}),e.jsxs(R,{variant:"secondary",size:"sm",onClick:ka,title:"Refresh",children:[e.jsx(ce,{size:14})," Refresh"]})]})})]}),g&&e.jsx("div",{className:"view-loading",children:e.jsx(he,{size:"lg"})}),!g&&U.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:K("tl-view",f&&"tl-view-detail-open"),children:e.jsxs("div",{className:K("tl-body",!p&&"tl-body-stream-collapsed"),children:[e.jsxs("aside",{className:K("tl-stream",!p&&"tl-stream-collapsed"),children:[e.jsxs("div",{className:"tl-stream-head",children:[e.jsxs("h3",{children:[e.jsx(js,{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(yn,{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(pt,{items:[...m].reverse(),itemHeight:40,height:400,className:"tl-stream-virtual",renderItem:T=>{const G=T.author?He:T.kind==="task"?gs:T.kind==="bg"?Gs:Te;return e.jsxs("div",{className:"tl-stream-event",children:[e.jsx("span",{className:"tl-stream-event-time",children:new Date(T.ts).toLocaleTimeString("en-GB",{hour12:!1})}),e.jsx("span",{className:"tl-stream-event-icon",style:{color:Zs(T.kind)},children:e.jsx(G,{size:12})}),e.jsx("span",{className:"tl-stream-event-text",children:T.author||T.text||T.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(R,{variant:"ghost",size:"sm",onClick:()=>x(!0),title:"Show event stream",children:[e.jsx(vn,{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(O).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(xn,{size:11})," agent"]}),e.jsxs("span",{className:"tl-legend-item",children:[e.jsx($n,{size:11})," task"]}),e.jsxs("span",{className:"tl-legend-item",children:[e.jsx(Gs,{size:11})," bg"]})]})]}),e.jsx("div",{className:"tl-canvas-scroll",children:e.jsxs("svg",{className:"tl-canvas",width:$.width,height:Math.max($.height,Vs),role:"application","aria-label":"Activity timeline",children:[e.jsx("defs",{children:e.jsx("pattern",{id:"tl-canvas-grid",width:$.width,height:Me,patternUnits:"userSpaceOnUse",children:e.jsx("path",{d:`M 0 0 L 0 ${Me}`,fill:"none",stroke:"var(--border)",strokeWidth:.5,opacity:.35})})}),e.jsx("rect",{width:"100%",height:"100%",fill:"url(#tl-canvas-grid)"}),Ms.map(T=>e.jsx("rect",{className:"tl-lane-bg",x:0,y:T.y,width:$.width,height:T.h,fill:T.id.charCodeAt(T.id.length-1)%2===0?"var(--bg-elev-2)":"var(--bg-elev)",opacity:.4},`bg-${T.id}`)),e.jsx("g",{className:"tl-time-axis",children:Ss.map(T=>e.jsxs("g",{children:[e.jsx("line",{x1:T.x,y1:0,x2:T.x,y2:Vs,stroke:"var(--border)",strokeWidth:.5,strokeDasharray:"2,4",opacity:.5}),e.jsx("text",{x:T.x+4,y:Be-8,fontSize:10,fontFamily:"var(--font-mono)",fill:"var(--text-dim)",children:T.label})]},`tick-${T.t}`))}),te.map(T=>{const G=Be+ts+T.index*Me+Me/2;return e.jsxs("g",{className:"tl-lane-label-group",children:[e.jsx("text",{x:6,y:G-2,className:"tl-lane-label",textAnchor:"start",children:As(T.label,28)}),e.jsx("text",{x:6,y:G+10,className:"tl-lane-label-sub",textAnchor:"start",children:T.sub})]},`label-${T.id}`)}),Cs.map(T=>{const G=Zs(T.statusClass),xe=T.id===(f==null?void 0:f.id);return e.jsxs("g",{className:K("tl-task-bar",`tl-task-bar-${T.statusClass}`,xe&&"tl-task-bar-selected"),onClick:()=>fa(T),children:[e.jsx("rect",{x:T.x,y:T.y,width:T.w,height:T.h,rx:6,fill:G,fillOpacity:T.statusClass==="done"?.35:T.statusClass==="queued"?.18:.85,stroke:G,strokeWidth:xe?2.5:1.5,strokeOpacity:T.statusClass==="done"?.5:1,strokeDasharray:T.statusClass==="queued"?"4 4":void 0,style:{cursor:"pointer"}}),T.w>36&&e.jsx("text",{x:T.x+8,y:T.y+T.h/2+4,fontSize:11,fontFamily:"var(--font-sans)",fontWeight:500,fill:"var(--text-strong)",style:{pointerEvents:"none"},opacity:T.statusClass==="done"?.7:1,children:As(T.label,Math.max(4,Math.floor(T.w/7)))})]},`bar-${T.id}`)}),zs.map(T=>{const G=Zs(T.kind);return e.jsxs("g",{className:"tl-event-marker-group",children:[e.jsx("line",{x1:T.x,y1:T.y-6,x2:T.x,y2:T.y+6,stroke:G,strokeWidth:1.2,opacity:.7}),e.jsx("circle",{cx:T.x,cy:T.y,r:4,fill:G,opacity:.9,children:e.jsx("title",{children:`${T.kind}${T.author?` · ${T.author}`:""} · ${new Date(T.ts).toLocaleTimeString("en-GB",{hour12:!1})}`})})]},`ev-${T.id}`)}),e.jsx("line",{className:"tl-now-line",x1:Ts,y1:0,x2:Ts,y2:Vs,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"})]})]})})]}),f&&e.jsx("aside",{className:"tl-detail tl-detail-enter",children:e.jsxs(Y,{children:[e.jsxs(ee,{children:[f.kind==="agent"&&e.jsx(He,{size:14}),f.kind==="task"&&e.jsx(gs,{size:14}),f.kind==="bg"&&e.jsx(Gs,{size:14}),f.label,e.jsx("button",{type:"button",className:"icon-btn",onClick:()=>F(null),title:"Close","aria-label":"Close activity detail",style:{marginLeft:"auto"},children:e.jsx(Ce,{size:14})})]}),e.jsxs("div",{className:"tl-detail-meta",children:[e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"type"})," ",f.kind]}),e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"status"})," ",e.jsx("code",{children:f.status})]}),f.kind==="agent"&&(()=>{const T=f.data;return e.jsxs(e.Fragment,{children:[T.role&&e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"role"})," ",T.role]}),T.model&&e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"model"})," ",T.model]})]})})(),f.kind==="task"&&(()=>{const T=f.data;return e.jsxs(e.Fragment,{children:[T.assignee&&e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"assignee"})," @",T.assignee]}),T.priority&&e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"priority"})," ",T.priority]}),T.createdAt&&e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"created"})," ",new Date(T.createdAt).toLocaleString()]})]})})(),f.kind==="bg"&&(()=>{const T=f.data;return e.jsxs(e.Fragment,{children:[T.startedAt&&e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"started"})," ",new Date(T.startedAt).toLocaleString()]}),T.tmuxSession&&e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"tmux"})," ",e.jsx("code",{children:T.tmuxSession})," ",T.tmuxActive?e.jsx("span",{className:"tag tag-success",children:"active"}):e.jsx("span",{className:"tag",children:"inactive"})]})]})})()]}),f.kind==="task"&&f.data.description&&e.jsx("div",{className:"tl-detail-desc",children:f.data.description}),f.kind==="bg"&&f.data.promptPreview&&e.jsx("div",{className:"tl-detail-desc",children:f.data.promptPreview}),f.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(R,{variant:"ghost",size:"sm",onClick:ba,children:[e.jsx(ce,{size:12})," Refresh output"]}),fe.length>0&&e.jsxs(R,{variant:"secondary",size:"sm",onClick:()=>br(I,fe[0]),children:[e.jsx(Se,{size:12})," Open artifact"]}),e.jsxs(R,{variant:"danger",size:"sm",onClick:va,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:T=>ae(T.target.value),onKeyDown:T=>{T.key==="Enter"&&Tt()},"aria-label":"Send a message to this bg session"}),e.jsxs(R,{variant:"primary",size:"sm",disabled:!_.trim(),onClick:Tt,children:[e.jsx(Qe,{size:12})," Send"]})]})]}),f.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:v,onChange:T=>L(T.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:B,onChange:T=>z(T.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(R,{variant:"primary",size:"sm",disabled:!v.trim()||X,onClick:ya,children:[e.jsx($e,{size:12})," Add task"]})]})]}),e.jsxs("div",{className:"tl-detail-comments",children:[e.jsxs("div",{className:"field-label",children:[e.jsx(Hs,{size:12})," Comments & activity"]}),e.jsxs("ul",{className:"comment-list",children:[k.length===0&&e.jsx("li",{className:"muted",children:"No comments yet."}),k.map((T,G)=>e.jsxs("li",{className:"comment-item",children:[e.jsxs("div",{className:"comment-head",children:[e.jsx("strong",{children:T.author||"system"}),e.jsxs("span",{className:"muted",children:[T.kind," · ",new Date(T.ts).toLocaleString()]})]}),T.text&&e.jsx("div",{className:"comment-text",children:T.text}),T.taskId&&e.jsxs("div",{className:"muted",children:["→ task ",e.jsx("code",{children:String(T.taskId)})]})]},`c-${G}`))]}),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:S,onChange:T=>y(T.target.value),onKeyDown:T=>{T.key==="Enter"&&!T.shiftKey&&Mt()},"aria-label":"Add a comment"}),e.jsxs(R,{variant:"secondary",size:"sm",disabled:!S.trim()||Z,onClick:Mt,children:[e.jsx(Qe,{size:12})," Post"]})]})]})]})},f.id)]})})]})}function $r(s,t){const a=s.length,i=t.length,n=Array.from({length:i+1},()=>Array(a+1).fill(0));for(let l=0;l<=a;l++)n[0][l]=l;for(let l=0;l<=i;l++)n[l][0]=l;for(let l=1;l<=i;l++)for(let c=1;c<=a;c++){const o=s[c-1]===t[l-1]?0:1;n[l][c]=Math.min(n[l][c-1]+1,n[l-1][c]+1,n[l-1][c-1]+o)}return n[i][a]}function et(s,t){if(t===s)return 100;if(t.startsWith(s))return 90;const a=t.split(/\s+/);for(const l of a)if(l.startsWith(s))return 80;const i=Math.min(s.length,t.length);return $r(s,t.substring(0,i))<=2?40:t.includes(s)?30:0}function Ar(s,t){const a=s.toLowerCase().trim();return a?t.map(i=>{const n=et(a,i.label.toLowerCase()),l=i.value?et(a,String(i.value).toLowerCase()):0,c=i.description?et(a,i.description.toLowerCase()):0,o=Math.max(n,l,c);if(o===0)return null;const p=n>=l&&n>=c?"label":l>=n&&l>=c?"value":"description",x=p==="label"?i.label:p==="value"?String(i.value):i.description;return{...i,score:o,matchedField:p,matchedTerm:x}}).filter(i=>i!==null).sort((i,n)=>n.score-i.score):[]}const St="bizar_settings_recent";function ma(){try{const s=localStorage.getItem(St);return s?JSON.parse(s):[]}catch{return[]}}function Rr(s){if(s)try{const t=ma().filter(a=>a!==s);t.unshift(s),localStorage.setItem(St,JSON.stringify(t.slice(0,5)))}catch{}}function Lr(s,t){if(!t)return s;const a=t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),i=new RegExp(`(${a})`,"gi");return s.split(i).map((l,c)=>i.test(l)?e.jsx("mark",{children:l},c):e.jsx("span",{children:l},c))}function Ir(s){const t=[];for(const a of s){t.push({key:a.id,label:a.label,section:a.id,description:`${a.fields.length} field${a.fields.length===1?"":"s"}`});for(const i of a.fields)t.push({key:i.key,label:i.label,section:a.id,value:i.value})}return t}function Er({sections:s,onJump:t}){const[a,i]=r.useState(""),[n,l]=r.useState([]),[c,o]=r.useState(0),[p,x]=r.useState(null),[h,d]=r.useState(!1),m=r.useRef(null),u=r.useRef(null),g=r.useRef(null),j=r.useRef([]);r.useEffect(()=>{j.current=Ir(s)},[s]);const b=r.useCallback((S,y=!1)=>{if(u.current&&clearTimeout(u.current),!S.trim()){l([]),o(0);return}const k=()=>{const P=Ar(S,j.current);l(P),o(0)};y?k():u.current=setTimeout(k,150)},[]);r.useEffect(()=>{b(a)},[a,b]),r.useEffect(()=>()=>{u.current&&clearTimeout(u.current),g.current&&clearTimeout(g.current)},[]);const A=(S,y)=>{const k=document.querySelector(`[data-section="${S}"] [data-setting-id="${y}"]`);k&&(k.scrollIntoView({behavior:"smooth",block:"center"}),k.classList.add("setting-flash"),setTimeout(()=>k.classList.remove("setting-flash"),2e3));const P=document.querySelector(`[data-section="${S}"]`);P&&P.scrollIntoView({behavior:"smooth",block:k?"nearest":"start"})},N=S=>{x(S),g.current&&clearTimeout(g.current),g.current=setTimeout(()=>x(null),1500);const y=document.querySelector(`[data-section="${S}"]`);y&&y.scrollIntoView({behavior:"smooth",block:"start"})},w=S=>{var y;Rr(a),S.key===S.section?(N(S.section),t(S.section)):(N(S.section),t(S.section,S.key),A(S.section,S.key)),i(""),(y=m.current)==null||y.blur()},E=S=>{var y;S.key==="Escape"?(i(""),(y=m.current)==null||y.blur()):S.key==="ArrowDown"?(S.preventDefault(),o(k=>Math.min(k+1,n.length-1))):S.key==="ArrowUp"?(S.preventDefault(),o(k=>Math.max(k-1,0))):S.key==="Enter"&&(S.preventDefault(),n.length===0&&a.trim()&&b(a,!0),n[c]&&w(n[c]))},M=S=>{w(S)},$=ma(),D=S=>{var y;i(S),(y=m.current)==null||y.focus()},f=()=>{try{localStorage.removeItem(St)}catch{}d(S=>S)},F=h&&!a.trim()&&$.length>0;return e.jsxs("div",{className:"settings-search",children:[e.jsxs("div",{className:"settings-search-input-wrap",children:[e.jsx(ve,{size:13,className:"settings-search-icon"}),e.jsx("input",{ref:m,className:"settings-search-input",placeholder:"Search settings…",value:a,onChange:S=>i(S.target.value),onKeyDown:E,onFocus:()=>d(!0),onBlur:()=>setTimeout(()=>d(!1),150),"aria-label":"Search settings"}),a&&e.jsx("button",{type:"button",className:"icon-btn settings-search-clear",onClick:()=>i(""),"aria-label":"Clear search",children:e.jsx(Ce,{size:12})})]}),F&&e.jsxs("div",{className:"settings-search-recent",children:[e.jsxs("div",{className:"settings-search-recent-header",children:[e.jsx("span",{className:"settings-search-recent-label",children:"Recent"}),e.jsx("button",{type:"button",className:"settings-search-recent-clear",onClick:f,tabIndex:-1,children:"Clear"})]}),$.map(S=>e.jsxs("button",{type:"button",className:"settings-search-recent-item",onMouseDown:y=>{y.preventDefault(),D(S)},children:[e.jsx(ve,{size:11}),e.jsx("span",{children:S})]},S))]}),a&&n.length>0&&e.jsx("div",{className:"settings-search-results",children:n.map((S,y)=>e.jsxs("button",{type:"button",className:K("settings-search-result",y===c&&"settings-search-result-active"),onClick:()=>M(S),onMouseEnter:()=>o(y),children:[e.jsx("span",{className:K("settings-search-result-type",S.key===S.section&&"settings-search-result-type-section"),children:S.key===S.section?"section":"field"}),e.jsx("span",{className:"settings-search-result-label",children:Lr(S.label,a)}),S.key!==S.section&&e.jsx("span",{className:"settings-search-result-key mono muted",children:S.key})]},`${S.section}::${S.key}`))}),a&&n.length===0&&e.jsx("div",{className:"settings-search-empty muted",children:"No matching settings."})]})}const Dr=[{id:"dark",label:"Dark",Icon:Oa},{id:"light",label:"Light",Icon:Ba},{id:"system",label:"System",Icon:Ua}],Pr=[{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"}],Fr=["Inter","system-ui","Segoe UI","Roboto","JetBrains Mono","SF Mono","Cascadia Code"];function Or({settings:s,patchTheme:t,patchUi:a}){return e.jsxs(Y,{id:"settings-theme","data-section":"theme",children:[e.jsxs(ee,{children:[e.jsx(fn,{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:Pr.map(i=>e.jsxs("button",{type:"button",className:K("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:Dr.map(({id:i,label:n,Icon:l})=>{const c=s.theme.mode===i;return e.jsxs("button",{type:"button",className:K("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:K("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:Fr.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 st=[{id:"bizar",name:"Bizar CLI"},{id:"bizar-dash",name:"Dashboard"},{id:"bizar-plugin",name:"Opencode Plugin"}];function Br(){const s=oe(),[t,a]=r.useState({current:{},latest:null,checking:!1,updating:!1,hasUpdates:!1,requiresRestart:!1,perPackage:{}});r.useEffect(()=>{const o=new ft;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(()=>{C.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 C.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 C.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 C.post("/restart"),s.info("Restarting…",3e3),setTimeout(()=>window.location.reload(),3e3)}catch{s.error("Restart failed")}},c=t.checking||t.updating;return e.jsxs(Y,{id:"settings-updates","data-section":"updates",children:[e.jsxs(ee,{children:[e.jsx(Ze,{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:st.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:st.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:st.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(ut,{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(`
|
|
356
|
+
`)})]}),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(R,{onClick:i,disabled:c,children:[t.checking?e.jsx("span",{className:"btn-spinner"}):e.jsx(ce,{size:14}),"Check for updates"]}),e.jsxs(R,{variant:"primary",onClick:n,disabled:!t.hasUpdates||t.updating,children:[t.updating?e.jsx("span",{className:"btn-spinner"}):e.jsx(Ze,{size:14}),t.updating?"Updating…":t.hasUpdates?"Update now":"Up to date"]}),t.requiresRestart&&e.jsxs(R,{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 Ur=[{id:"topnav",label:"Top nav"},{id:"sidebar",label:"Sidebar"},{id:"both",label:"Both"}];function qr({settings:s,patchUi:t,patchTop:a}){return e.jsxs(e.Fragment,{children:[e.jsxs(Y,{id:"settings-layout","data-section":"layout",children:[e.jsxs(ee,{children:[e.jsx(bn,{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:Ur.map(i=>e.jsx("button",{type:"button",className:K("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(Y,{id:"settings-general","data-section":"general",children:[e.jsx(ee,{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 Hr({tailscale:s,tailscaleDraft:t,setTailscaleDraft:a,onTailscaleToggle:i}){return e.jsxs(e.Fragment,{children:[e.jsxs(Y,{id:"settings-service","data-section":"service",children:[e.jsxs(ee,{children:[e.jsx(fs,{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(Y,{id:"settings-tailscale","data-section":"tailscale",children:[e.jsxs(ee,{children:[e.jsx(ct,{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(R,{variant:"primary",onClick:i,children:s.settings.enabled?"Disable serve":"Enable serve"})]}):e.jsx("p",{className:"muted",children:"Loading Tailscale status…"})]})]})}function _r({settings:s,patchNotifications:t}){return e.jsxs(Y,{id:"settings-notifications","data-section":"notifications",children:[e.jsx(ee,{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 Wr({authStatus:s,setAuthStatus:t}){const a=oe(),[i,n]=r.useState(C.getToken()),[l,c]=r.useState("");r.useEffect(()=>{let h=!1;return(async()=>{try{const d=await C.probeAuthStatus();h||t(d)}catch{h||t({required:!0,loopback:!1,peer:""})}})(),()=>{h=!0}},[]);const o=async()=>{try{const h=await C.get("/auth/reveal");c(h.token),n(h.token),C.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 C.post("/auth/regenerate");c(h.token),n(h.token),C.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=()=>{C.setToken(i.trim()),a.success("Token saved. The dashboard will use it on the next request.")};return e.jsxs(Y,{id:"settings-auth","data-section":"auth",children:[e.jsxs(ee,{children:[e.jsx(zn,{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(R,{variant:"secondary",size:"sm",onClick:x,children:[e.jsx(bt,{size:14})," Save token"]}),e.jsxs(R,{variant:"ghost",size:"sm",onClick:o,children:[e.jsx(Ws,{size:14})," Reveal & copy server token"]}),e.jsxs(R,{variant:"ghost",size:"sm",onClick:p,children:[e.jsx(Xt,{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 Vr({settings:s,patchAgents:t,patchDashboard:a}){var p,x,h;const i=oe(),[n,l]=r.useState({});r.useEffect(()=>{C.get("/settings/plugin-options").then(l).catch(()=>{})},[]);const c=async()=>{try{await C.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(Y,{id:"settings-agents","data-section":"agents",children:[e.jsxs(ee,{children:[e.jsx(fs,{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(Y,{id:"settings-dashboard","data-section":"dashboard",children:[e.jsxs(ee,{children:[e.jsx(bs,{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
|
|
357
|
+
/srv/projects`,value:(s.dashboard.allowedRoots??[]).join(`
|
|
358
|
+
`),onChange:d=>{const m=d.target.value.split(`
|
|
359
|
+
`).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(`
|
|
360
|
+
`).split(`
|
|
361
|
+
`),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(Y,{id:"settings-background","data-section":"background",children:[e.jsxs(ee,{children:[e.jsx(fs,{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(R,{variant:"secondary",size:"sm",onClick:c,children:[e.jsx(vs,{size:14})," Save plugin options"]}),e.jsx(R,{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 Gr({settings:s,patchTop:t}){var a,i,n;return e.jsxs(Y,{id:"settings-system-llm","data-section":"system-llm",children:[e.jsxs(ee,{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 Kr=[{value:"anthropic",label:"Anthropic"},{value:"anyllm",label:"AnyLLM"},{value:"litellm-anthropic",label:"LiteLLM (Anthropic)"},{value:"litellm-openai",label:"LiteLLM (OpenAI)"}];function Yr({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),[j,b]=r.useState(!1),[A,N]=r.useState(!1),w=r.useCallback(async()=>{p(!0);try{const[z,_]=await Promise.all([C.get("/headroom/status"),C.get("/headroom/stats?hours=24").catch(()=>({error:"no stats"}))]);n(z),_.error||c(_)}catch(z){a.error(`Failed to load Headroom status: ${z.message}`)}finally{p(!1)}},[a]);r.useEffect(()=>{w()},[w]);const E=async()=>{h(!0);try{const z=await C.post("/headroom/install",{force:!0});z.installed?(a.success(`Headroom installed via ${z.method}.`),await w()):a.error('Headroom install failed. Try: pip install "headroom-ai[all]"')}catch(z){a.error(`Install failed: ${z.message}`)}finally{h(!1)}},M=async()=>{m(!0);try{(await C.post("/headroom/wrap",{port:s.port})).ok?(a.success("opencode wrapped with Headroom."),await w()):a.error("Wrap failed.")}catch(z){a.error(`Wrap failed: ${z.message}`)}finally{m(!1)}},$=async()=>{g(!0);try{(await C.post("/headroom/unwrap")).ok?(a.success("opencode unwrapped from Headroom."),await w()):a.error("Unwrap failed.")}catch(z){a.error(`Unwrap failed: ${z.message}`)}finally{g(!1)}},D=async()=>{b(!0);try{(await C.post("/headroom/proxy/start",{port:s.port,host:s.host})).ok?(a.success(`Headroom proxy started on ${s.host}:${s.port}.`),await w()):a.error("Proxy start failed.")}catch(z){a.error(`Proxy start failed: ${z.message}`)}finally{b(!1)}},f=async()=>{N(!0);try{(await C.post("/headroom/proxy/stop")).ok?(a.success("Headroom proxy stopped."),await w()):a.error("Proxy stop failed.")}catch(z){a.error(`Proxy stop failed: ${z.message}`)}finally{N(!1)}},F=async()=>{try{const{spawn:z}=await Qt(async()=>{const{spawn:_}=await import("./__vite-browser-external-BIHI7g3E.js");return{spawn:_}},[]);z("headroom",["dashboard"],{detached:!0,stdio:"ignore"})}catch{a.error("Could not open Headroom dashboard. Run `headroom dashboard` manually.")}},{installed:S,version:y,proxyRunning:k,proxyPort:P,wrapped:v}=i||{},L=(l==null?void 0:l.compressionRatio)??0,B=(l==null?void 0:l.tokensSaved)??0;return e.jsx("div",{id:"settings-headroom","data-section":"headroom",children:e.jsxs(Y,{children:[e.jsxs(ee,{children:[e.jsx(Te,{size:14,style:{color:k?"var(--success)":"var(--text-dim)"}}),"Headroom",S&&y&&e.jsxs("span",{style:{fontSize:11,color:"var(--text-dim)",marginLeft:6},children:["v",y," ",k?"✓":"✗"]}),!S&&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:[S?e.jsx(Is,{size:12,style:{color:"var(--success)"}}):e.jsx(Xe,{size:12,style:{color:"var(--error)"}}),e.jsx("span",{children:S?"Installed":"Not installed"})]}),e.jsxs("div",{className:"headroom-status-item",children:[k?e.jsx(Is,{size:12,style:{color:"var(--success)"}}):e.jsx(Xe,{size:12,style:{color:"var(--text-dim)"}}),e.jsxs("span",{children:["Proxy ",k?`${P} ✓`:"stopped"]})]}),e.jsxs("div",{className:"headroom-status-item",children:[v?e.jsx(Is,{size:12,style:{color:"var(--success)"}}):e.jsx(Xe,{size:12,style:{color:"var(--text-dim)"}}),e.jsxs("span",{children:["opencode ",v?"wrapped":"not wrapped"]})]})]}),(B>0||L>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:L>0?`${Math.round(L*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:B>0?B.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:[S?e.jsxs(e.Fragment,{children:[e.jsxs(R,{variant:"secondary",size:"sm",onClick:M,disabled:d||v,title:v?"opencode is already wrapped":"Wrap opencode to route through Headroom proxy",children:[d?e.jsx("span",{className:"btn-spinner"}):e.jsx(Nt,{size:13}),d?"Wrapping…":v?"Wrapped ✓":"Wrap opencode"]}),v&&e.jsxs(R,{variant:"ghost",size:"sm",onClick:$,disabled:u,children:[u?e.jsx("span",{className:"btn-spinner"}):e.jsx(ce,{size:13}),u?"Unwrapping…":"Unwrap"]})]}):e.jsxs(R,{variant:"primary",size:"sm",onClick:E,disabled:x,children:[x?e.jsx("span",{className:"btn-spinner"}):e.jsx(Ze,{size:13}),x?"Installing…":"Install Headroom"]}),S&&e.jsxs(e.Fragment,{children:[k?e.jsxs(R,{variant:"secondary",size:"sm",onClick:f,disabled:A,children:[A?e.jsx("span",{className:"btn-spinner"}):e.jsx(Tn,{size:13}),A?"Stopping…":"Stop proxy"]}):e.jsxs(R,{variant:"secondary",size:"sm",onClick:D,disabled:j,children:[j?e.jsx("span",{className:"btn-spinner"}):e.jsx(ws,{size:13}),j?"Starting…":"Start proxy"]}),e.jsxs(R,{variant:"ghost",size:"sm",onClick:F,children:[e.jsx(os,{size:13}),"Dashboard"]})]}),e.jsx(R,{variant:"ghost",size:"sm",onClick:w,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:z=>t({enabled:z.target.checked})}),e.jsx("span",{children:"Enable Headroom"})]}),e.jsxs("label",{className:"checkbox-row",children:[e.jsx("input",{type:"checkbox",checked:s.autoInstall,onChange:z=>t({autoInstall:z.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:z=>t({autoStart:z.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:z=>t({autoWrap:z.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:z=>t({routeAllProviders:z.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:z=>t({port:Math.max(1,Math.min(65535,parseInt(z.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:z=>t({host:z.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:z=>t({backend:z.target.value}),children:Kr.map(z=>e.jsx("option",{value:z.value,children:z.label},z.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:z=>t({budget:Math.max(0,parseFloat(z.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:z=>t({outputShaper:z.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:z=>t({telemetry:z.target.checked})}),e.jsx("span",{children:"Enable telemetry"})]})]})]})})}const Pt={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 Xr({settings:s,setSettings:t,setDirty:a}){return e.jsx(Yr,{settings:s.headroom||Pt,onPatch:i=>{t(n=>({...n,headroom:{...n.headroom||Pt,...i}})),a(!0)}})}function Qr(){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([C.get("/activity"),C.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 N=`${b.kind||""}|${b.ts||""}|${b.slug||""}|${A}`;let w=0;for(let E=0;E<N.length;E++)w=(w<<5)-w+N.charCodeAt(E)|0;return Math.abs(w).toString(16).padStart(8,"0").slice(0,16)},u=async()=>{try{await C.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 C.del(`/activity/hide/${encodeURIComponent(b)}`);const A=new Set(i);A.delete(b),n(A)}catch(A){s.error(`Restore failed: ${A.message}`)}},j=t.filter((b,A)=>{const N=m(b,A);if(!x&&i.has(N))return!1;if(!o)return!0;const w=o.toLowerCase();return[b.kind,b.slug,b.message].some(E=>typeof E=="string"&&E.toLowerCase().includes(w))});return e.jsxs(Y,{id:"settings-activity-log","data-section":"activity-log",children:[e.jsxs(ee,{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(R,{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(ve,{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(R,{variant:"ghost",size:"sm",disabled:i.size===0,onClick:u,title:"Restore all hidden items to the Overview",children:[e.jsx(rs,{size:12})," Restore all"]})]}),l?e.jsx("div",{className:"muted",style:{padding:"12px 0",fontSize:12},children:"Loading…"}):j.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:j.slice(0,200).map((b,A)=>{const N=m(b,A),w=i.has(N);return e.jsxs("tr",{className:K(w&&"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:w?e.jsx(R,{variant:"ghost",size:"sm",onClick:()=>g(N),title:"Restore to Overview",children:e.jsx(rs,{size:12})}):e.jsx("span",{className:"activity-log-state-tag",children:"shown"})})]},`${b.ts}-${A}`)})})]}),j.length>200&&e.jsxs("div",{className:"muted",style:{fontSize:11,padding:"8px 0"},children:["Showing first 200 of ",j.length,"."]})]})]})}function Zr({about:s}){return e.jsxs(Y,{id:"settings-about","data-section":"about",children:[e.jsxs(ee,{children:[e.jsx(_s,{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 Jr({about:s}){return e.jsxs(e.Fragment,{children:[e.jsx(Qr,{}),e.jsx(Zr,{about:s})]})}function el(){return e.jsxs(Y,{id:"settings-env-vars","data-section":"env-vars",children:[e.jsx(ee,{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 sl(){return e.jsxs(Y,{id:"settings-providers","data-section":"providers",children:[e.jsx(ee,{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 tl(){return e.jsxs(Y,{id:"settings-memory","data-section":"memory",children:[e.jsx(ee,{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 al(){return e.jsxs(Y,{id:"settings-skills","data-section":"skills",children:[e.jsx(ee,{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 nl(){return e.jsxs(Y,{id:"settings-backup","data-section":"backup",children:[e.jsx(ee,{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 Ft=[{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"}],il=[{id:"theme",label:"Theme",fields:[{key:"theme.presets",label:"Accent presets",section:"theme"},{key:"theme.accent",label:"Accent color",section:"theme"},{key:"theme.success",label:"Success color",section:"theme"},{key:"theme.warning",label:"Warning color",section:"theme"},{key:"theme.error",label:"Error color",section:"theme"},{key:"theme.info",label:"Info color",section:"theme"},{key:"theme.fontFamily",label:"Font family",section:"theme"},{key:"theme.fontSize",label:"Font size",section:"theme"},{key:"theme.compactMode",label:"Compact mode",section:"theme"},{key:"theme.animations",label:"Animations",section:"theme"}]},{id:"updates",label:"Updates",fields:[{key:"updates.channel",label:"Update channel",section:"updates"}]},{id:"layout",label:"Layout",fields:[{key:"ui.layout",label:"UI layout",section:"layout"},{key:"ui.showHeader",label:"Show header",section:"layout"},{key:"ui.showStatusBar",label:"Show status bar",section:"layout"},{key:"ui.defaultTab",label:"Default tab",section:"layout"}]},{id:"general",label:"General",fields:[{key:"defaultAgent",label:"Default agent",section:"general"},{key:"defaultModel",label:"Model override",section:"general"}]},{id:"network",label:"Network",fields:[{key:"tailscale.enabled",label:"Tailscale Serve",section:"network"},{key:"tailscale.port",label:"Tailscale port",section:"network"},{key:"tailscale.https",label:"Tailscale HTTPS",section:"network"},{key:"tailscale.hostname",label:"Tailscale hostname",section:"network"}]},{id:"notifications",label:"Notifications",fields:[{key:"notifications.onAgentComplete",label:"Notify on agent complete",section:"notifications"},{key:"notifications.onPlanApproval",label:"Notify on plan approval",section:"notifications"}]},{id:"auth",label:"Auth",fields:[{key:"auth.enabled",label:"Auth enabled",section:"auth"},{key:"auth.loopback",label:"Loopback mode",section:"auth"},{key:"auth.token",label:"Auth token",section:"auth"}]},{id:"agents",label:"Agents",fields:[{key:"agents.maxParallel",label:"Max parallel agents",section:"agents"},{key:"agents.stuckThresholdMs",label:"Stuck threshold",section:"agents"},{key:"agents.autoRestart",label:"Auto restart",section:"agents"},{key:"workflow.artifactsEnabled",label:"Artifacts enabled",section:"agents"},{key:"workflow.agentsDecideAutonomously",label:"Autonomous decisions",section:"agents"}]},{id:"dashboard",label:"Dashboard",fields:[{key:"dashboard.autoLaunchWeb",label:"Auto-launch web",section:"dashboard"},{key:"dashboard.projectsDirectory",label:"Projects directory",section:"dashboard"},{key:"dashboard.allowedRoots",label:"Allowed roots",section:"dashboard"}]},{id:"background",label:"Background",fields:[{key:"service.enabled",label:"Background service",section:"background"},{key:"service.autostart",label:"Auto-start service",section:"background"}]},{id:"system-llm",label:"System LLM",fields:[{key:"systemLlm.enabled",label:"System LLM enabled",section:"system-llm"}]},{id:"headroom",label:"Headroom",fields:[{key:"headroom.enabled",label:"Headroom enabled",section:"headroom"},{key:"headroom.port",label:"Headroom port",section:"headroom"},{key:"headroom.budget",label:"Headroom budget",section:"headroom"},{key:"headroom.backend",label:"Headroom backend",section:"headroom"}]},{id:"activity-log",label:"Activity",fields:[{key:"activity.log",label:"Activity log",section:"activity-log"}]},{id:"about",label:"About",fields:[{key:"about.version",label:"Version",section:"about"},{key:"about.homepage",label:"Homepage",section:"about"},{key:"about.license",label:"License",section:"about"}]},{id:"env-vars",label:"Env Vars",fields:[{key:"env.add",label:"Add variable",section:"env-vars"}]},{id:"providers",label:"Providers",fields:[{key:"providers.list",label:"Provider list",section:"providers"}]},{id:"memory",label:"Memory",fields:[{key:"memory.config",label:"Memory config",section:"memory"}]},{id:"skills",label:"Skills",fields:[{key:"skills.paths",label:"Skill paths",section:"skills"}]},{id:"backup",label:"Backup",fields:[{key:"backup.create",label:"Create backup",section:"backup"},{key:"backup.restore",label:"Restore backup",section:"backup"}]}];function rl({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&&ns(s.theme)},[s]),r.useEffect(()=>{x&&m({port:x.settings.port,https:x.settings.https!==!1,hostname:x.settings.hostname||""})},[x]),r.useEffect(()=>{C.get("/tailscale/status").then(h).catch(()=>{})},[]);const j=B=>{n(z=>{const _={...z,theme:{...z.theme,...B}};return ns(_.theme),_}),c(!0)},b=B=>{n(z=>({...z,ui:{...z.ui,...B}})),c(!0)},A=(B,z)=>{n(_=>({..._,[B]:z})),c(!0)},N=B=>{n(z=>({...z,notifications:{...z.notifications,...B}})),c(!0)},w=B=>{n(z=>({...z,agents:{...z.agents,...B}})),c(!0)},E=B=>{n(z=>({...z,dashboard:{...z.dashboard,...B}})),c(!0)},[M,$]=r.useState(()=>{if(typeof window>"u")return null;const B=window.location.hash.replace(/^#settings-/,"");return Ft.some(z=>z.id===B)?B:null}),D=B=>{$(B);try{if(history.replaceState(null,"",B?`#settings-${B}`:window.location.pathname),B){const z=document.getElementById(`settings-${B}`);z&&z.scrollIntoView({behavior:"smooth",block:"start"})}else window.scrollTo({top:0,behavior:"smooth"})}catch{}},f=async()=>{try{x!=null&&x.settings.enabled?(await C.post("/tailscale/disable"),a.success("Tailscale serve disabled.")):(await C.post("/tailscale/enable",{port:d.port||4321,https:d.https,hostname:d.hostname||""}),a.success("Tailscale serve enabled.")),h(await C.get("/tailscale/status"))}catch(B){a.error(`Tailscale failed: ${B.message}`)}},F=async()=>{p(!0);try{const B=await C.put("/settings",i);n(B.data),c(!1),ps(B.data.theme),ns(B.data.theme),a.success("Settings saved."),await t()}catch(B){a.error(`Save failed: ${B.message}`)}finally{p(!1)}},S=async()=>{try{const B=await C.get("/settings");n(B.data),c(!1),ps(B.data.theme),ns(B.data.theme),a.info("Settings reloaded.",1500)}catch(B){a.error(`Reload failed: ${B.message}`)}},y=async()=>{if(confirm("Reset all settings to defaults?"))try{const B=await C.post("/settings/reset");n(B.data),c(!1),ps(B.data.theme),ns(B.data.theme),a.success("Settings reset."),await t()}catch(B){a.error(`Reset failed: ${B.message}`)}},k={settings:i,patchTheme:j,patchUi:b,patchTop:A,patchNotifications:N,patchAgents:w,patchDashboard:E},P=i.about||{version:"3.0.4",homepage:"https://github.com/DrB0rk/BizarHarness",license:"MIT"},v=M===null,L=B=>M===B;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(xt,{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(R,{variant:"ghost",size:"sm",onClick:y,children:[e.jsx(Xt,{size:14})," Reset"]}),e.jsxs(R,{variant:"secondary",size:"sm",onClick:S,children:[e.jsx(ce,{size:14})," Reload"]}),e.jsxs(R,{variant:"primary",size:"sm",disabled:!l||o,onClick:F,children:[o?e.jsx("span",{className:"btn-spinner"}):e.jsx(vs,{size:14}),o?"Saving…":"Save"]})]})]}),e.jsx(Er,{sections:il,onJump:D}),e.jsxs("nav",{className:"settings-subnav","aria-label":"Settings sections",children:[e.jsx("button",{type:"button",className:K("settings-subnav-button","settings-subnav-button-all",v&&"settings-subnav-button-active"),onClick:()=>D(null),title:"Show all settings sections",children:"All"}),Ft.map(B=>e.jsx("button",{type:"button",className:K("settings-subnav-button",M===B.id&&"settings-subnav-button-active"),onClick:()=>D(B.id),children:B.label},B.id))]}),e.jsxs("div",{className:K("settings-grid",M&&"settings-grid-filtered"),"data-active-section":M||void 0,children:[(v||L("theme"))&&e.jsx(Or,{...k}),(v||L("updates"))&&e.jsx(Br,{}),(v||L("layout")||L("general"))&&e.jsx(qr,{...k}),(v||L("network")||L("service")||L("tailscale"))&&e.jsx(Hr,{tailscale:x,tailscaleDraft:d,setTailscaleDraft:m,onTailscaleToggle:f}),(v||L("notifications"))&&e.jsx(_r,{...k}),(v||L("auth"))&&e.jsx(Wr,{settings:i,authStatus:u,setAuthStatus:g}),(v||L("agents")||L("dashboard")||L("background"))&&e.jsx(Vr,{...k}),(v||L("system-llm"))&&e.jsx(Gr,{...k}),(v||L("headroom"))&&e.jsx(Xr,{settings:i,setSettings:n,setDirty:c}),(v||L("activity-log")||L("about"))&&e.jsx(Jr,{about:P}),(v||L("env-vars"))&&e.jsx(el,{}),(v||L("providers"))&&e.jsx(sl,{}),(v||L("memory"))&&e.jsx(tl,{}),(v||L("skills"))&&e.jsx(al,{}),(v||L("backup"))&&e.jsx(nl,{})]})]})}const Ot=Ve.memo(rl);function ll({snapshot:s,refreshSnapshot:t}){const a=oe(),i=De(),[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,j]=r.useState(!1),[b,A]=r.useState(null),[N,w]=r.useState(!1),[E,M]=r.useState({}),$=async()=>{var v,L,B;w(!0);try{const z=await C.get("/mods/registry");A({source:((v=z.registry)==null?void 0:v.source)||"",version:(L=z.registry)==null?void 0:L.version,updatedAt:(B=z.registry)==null?void 0:B.updatedAt,mods:z.mods||[]})}catch(z){A({source:"",mods:[],error:z.message})}finally{w(!1)}},D=async v=>{M(L=>({...L,[v]:!0}));try{const L=await C.post("/mods",{id:v});l(B=>[...B.filter(z=>z.id!==L.id),L]),a.success(`Mod "${L.id}" installed from registry.`),await t()}catch(L){a.error(`Install failed: ${L.message}`)}finally{M(L=>({...L,[v]:!1}))}},f=async(v,L=!1)=>{M(B=>({...B,[v]:!0}));try{const B=await C.post(`/mods/${encodeURIComponent(v)}/upgrade`,{backup:L});l(_=>[..._.filter(ae=>ae.id!==B.mod.id),B.mod]);const z=B.backupPath?` (backup at ${B.backupPath})`:"";a.success(`Mod "${v}" upgraded v${B.from} → v${B.to}${z}.`),await t()}catch(B){a.error(`Upgrade failed: ${B.message}`)}finally{M(B=>({...B,[v]:!1}))}},F=async()=>{try{const v=await C.get("/mods");l(v.mods||[]);try{const L=await C.get("/mods/views");d(L.views||[])}catch{d([])}}catch(v){a.error(`Mods load failed: ${v.message}`)}finally{o(!1)}};r.useEffect(()=>{F()},[]),r.useEffect(()=>{Array.isArray(s.mods)&&s.mods!==n&&l(s.mods)},[s.mods]);const S=()=>{let v=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:L=>v=L,className:"input",type:"text",placeholder:"/path/to/my-mod",autoFocus:!0})]}),footer:e.jsxs("div",{className:"modal-footer-actions",children:[e.jsx(R,{variant:"ghost",onClick:()=>i.close(),children:"Cancel"}),e.jsx(R,{variant:"primary",onClick:async()=>{const L=((v==null?void 0:v.value)||"").trim();if(!L){a.warning("Path is required.");return}try{const B=await C.post("/mods",{path:L});l(z=>[...z,B]),a.success(`Mod "${B.id}" installed.`),i.close(),await t()}catch(B){a.error(`Install failed: ${B.message}`)}},children:"Install"})]})})},y=async v=>{if(confirm(`Uninstall mod "${v}"? This removes the folder from ~/.config/bizar/mods/.`))try{await C.del(`/mods/${encodeURIComponent(v)}`),l(L=>L.filter(B=>B.id!==v)),p===v&&x(null),a.success("Mod uninstalled.")}catch(L){a.error(`Uninstall failed: ${L.message}`)}},k=async v=>{try{const L=await C.put(`/mods/${encodeURIComponent(v.id)}`,{enabled:!v.enabled});l(B=>B.map(z=>z.id===v.id?L:z)),a.success(`Mod ${L.enabled?"enabled":"disabled"}.`)}catch(L){a.error(`Toggle failed: ${L.message}`)}},P=n.find(v=>v.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(Us,{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(R,{variant:"secondary",size:"sm",onClick:F,children:[e.jsx(ce,{size:14})," Refresh"]}),e.jsxs(R,{variant:"primary",size:"sm",onClick:S,children:[e.jsx($e,{size:14})," Install mod"]})]})]}),n.length===0?e.jsx(we,{icon:e.jsx(Us,{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(v=>e.jsxs("div",{className:K("mod-list-item",p===v.id&&"mod-list-item-active"),onClick:()=>x(v.id),children:[e.jsxs("div",{className:"mod-list-item-head",children:[e.jsxs("div",{children:[e.jsx("div",{className:"mod-list-item-name",children:v.name}),e.jsxs("div",{className:"mod-list-item-meta",children:["v",v.version," · ",v.type," · ",v.author]})]}),e.jsxs("div",{className:"mod-list-item-actions",onClick:L=>L.stopPropagation(),children:[e.jsx("button",{type:"button",className:"icon-btn","aria-label":"Toggle enabled",title:v.enabled?"Disable":"Enable",onClick:()=>k(v),children:e.jsx(gt,{size:12})}),e.jsx("button",{type:"button",className:"icon-btn icon-btn-danger","aria-label":"Uninstall",title:"Uninstall",onClick:()=>y(v.id),children:e.jsx(Ae,{size:12})})]})]}),e.jsx("div",{className:"mod-list-item-desc ellipsis-2",title:v.description,children:v.description}),e.jsx("div",{className:"mod-list-item-status",children:e.jsx("span",{className:`mod-mini-pill ${v.enabled?"mod-mini-pill-on":"mod-mini-pill-off"}`,children:v.enabled?"enabled":"disabled"})})]},v.id))}),P&&e.jsx(ol,{mod:P})]}),e.jsxs(Y,{className:"mods-registry-card",children:[e.jsxs("button",{type:"button",className:"mods-registry-head","aria-expanded":g,"aria-controls":"mods-registry-body",onClick:()=>{!b&&!N&&$(),j(v=>!v)},children:[e.jsx(bs,{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(We,{size:14,"aria-hidden":!0})]}),g&&e.jsx("div",{id:"mods-registry-body",className:"mods-registry-body",children:N?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(ks,{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(v=>{const L=n.some(z=>z.id===v.id),B=!!E[v.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:v.name}),v.latest&&e.jsxs("span",{className:K("mod-registry-version",v.upgradeAvailable&&"mod-registry-version-upgrade"),children:["v",v.latest,v.upgradeAvailable?" ↑":""]})]}),v.description&&e.jsx("div",{className:"mod-registry-card-desc",children:v.description}),e.jsxs("div",{className:"mod-registry-card-meta",children:[v.author&&e.jsxs("span",{className:"muted",children:["by ",v.author]}),v.homepage&&e.jsx("a",{href:v.homepage,target:"_blank",rel:"noopener noreferrer",className:"mod-registry-link",children:"homepage"})]}),(v.permissions||[]).length>0&&e.jsxs("div",{className:"mod-registry-perms",children:[e.jsx(ks,{size:10}),(v.permissions||[]).slice(0,4).map(z=>e.jsx("span",{className:"mod-registry-perm",children:z},z)),(v.permissions||[]).length>4&&e.jsxs("span",{className:"mod-registry-perm-more",children:["+",v.permissions.length-4]})]}),e.jsxs("div",{className:"mod-registry-card-actions",children:[!L&&e.jsx(R,{variant:"primary",size:"sm",disabled:B,onClick:()=>D(v.id),title:"Install from registry",children:B?e.jsx(he,{size:"sm"}):e.jsxs(e.Fragment,{children:[e.jsx(Ze,{size:12})," Install"]})}),L&&v.upgradeAvailable&&e.jsx(R,{variant:"primary",size:"sm",disabled:B,onClick:()=>f(v.id),title:`Upgrade from v${v.installedVersion||"?"} to v${v.upgradeAvailable}`,children:B?e.jsx(he,{size:"sm"}):e.jsxs(e.Fragment,{children:[e.jsx(Ze,{size:12})," Upgrade to v",v.upgradeAvailable]})}),L&&!v.upgradeAvailable&&e.jsxs(R,{variant:"ghost",size:"sm",disabled:!0,title:`Installed v${v.installedVersion||"?"}`,children:["Installed v",v.installedVersion||"?"]})]})]},v.id)})})]})})]}),h.length>0&&e.jsxs(Y,{className:"mod-views-hint",children:[e.jsxs(ee,{children:[e.jsx(bs,{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(Ce,{size:14})})]}),e.jsx("iframe",{src:m,className:"mod-iframe",title:"Mod view",sandbox:"allow-scripts allow-same-origin allow-forms allow-popups"})]})]})}function ol({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 C.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 C.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(Y,{className:"mod-details",children:[e.jsxs(ee,{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(tn,{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(We,{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(Rn,{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(ys,{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(Zt,{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(R,{variant:"ghost",size:"sm",onClick:d,children:[e.jsx(ce,{size:11})," Reinstall from mod folder"]})})]})]})]})}function cl({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 C.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(R,{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(bs,{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(R,{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(os,{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(()=>Qt(()=>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(ot,{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(dl,{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(Y,{children:[e.jsxs(ee,{children:[e.jsx(ot,{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(R,{variant:"secondary",size:"sm",onClick:()=>a("mods"),children:"Open Mods page"})})]})}class dl extends r.Component{constructor(){super(...arguments);ds(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 ml=["interval","cron","once"],hl=["command","agent","webhook"],ht=[{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)"}],ul=Array.from({length:12},(s,t)=>t*5),Ct=Array.from({length:24},(s,t)=>({value:t,label:t===0?"12 AM":t<12?`${t} AM`:t===12?"12 PM":`${t-12} PM`})),zt=[{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"}],ha=[{value:"s",label:"seconds"},{value:"m",label:"minutes"},{value:"h",label:"hours"},{value:"d",label:"days"}];function ua(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 xl(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 pl(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"?ua(s.schedule):null,a=s.type==="interval"?xl(s.schedule):null,i=s.timezone||"UTC",n=ht.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"?gl(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 gl(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 jl(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=zt.find(h=>h.value===s.cronDow))==null?void 0:a.label)||"",o=((i=Ct.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=ha.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 fl({snapshot:s,refreshSnapshot:t}){var m;const a=oe(),i=De(),[n,l]=r.useState(s.schedules||[]),[c,o]=r.useState(!s.schedules),p=async()=>{try{const u=await C.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(yl,{initial:u,onClose:i.close,onSubmitted:async g=>{l(j=>{const b=j.findIndex(N=>N.id===g.id);if(b===-1)return[...j,g];const A=j.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 j=await C.post(`/schedules/${encodeURIComponent(u.id)}/run`);a.success(j.ok?"Schedule ran.":`Run failed: ${((g=j.runResult)==null?void 0:g.error)||"unknown"}`),await p()}catch(j){a.error(`Run failed: ${j.message}`)}},d=async u=>{if(confirm(`Delete schedule "${u.name}"?`))try{await C.del(`/schedules/${encodeURIComponent(u.id)}`),l(g=>g.filter(j=>j.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(Fs,{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(R,{variant:"secondary",size:"sm",onClick:p,children:[e.jsx(ce,{size:14})," Refresh"]}),e.jsxs(R,{variant:"primary",size:"sm",onClick:()=>x(),children:[e.jsx($e,{size:14})," New schedule"]})]})]}),n.length===0?e.jsx(we,{icon:e.jsx(Fs,{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(Y,{className:"schedule-card",children:[e.jsxs("div",{className:"schedule-card-head",children:[e.jsxs("div",{children:[e.jsx(ee,{children:u.name}),e.jsxs(ie,{children:[e.jsx("code",{children:u.type})," ·"," ",e.jsx("span",{title:u.schedule,children:vl(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(R,{variant:"secondary",size:"sm",onClick:()=>x(u),children:[e.jsx(Ns,{size:12})," Edit"]}),e.jsxs(R,{variant:"secondary",size:"sm",onClick:()=>h(u),children:[e.jsx(Qa,{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 ${Bt(u.lastResult)}`,children:u.lastResult}),u.lastError&&e.jsxs("span",{className:"muted schedule-card-error",title:u.lastError,children:[" ","— ",Ut(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:bl(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(js,{size:12})," ",u.history.length," run",u.history.length===1?"":"s"]}),e.jsx("ul",{children:u.history.slice(-10).reverse().map((j,b)=>e.jsxs("li",{children:[e.jsx("span",{className:"tabular-nums muted",children:Ne(j.ts)})," ",e.jsx("span",{className:`tag ${Bt(j.result)}`,children:j.result}),j.error&&e.jsxs("span",{className:"muted",children:[" — ",Ut(j.error,80)]})]},b))})]})]},u.id)})})]})}function yl({initial:s,onClose:t,onSubmitted:a,onError:i}){const[n,l]=r.useState(()=>pl(s)),[c,o]=r.useState(!1),p=r.useMemo(()=>ht.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=jl(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,j={type:n.actionType,target:n.actionTarget.trim()};n.actionType==="agent"&&n.actionPrompt.trim()&&(j.prompt=n.actionPrompt.trim());const b={name:m,type:n.type,schedule:u.schedule,timezone:g||"UTC",action:j,budgetCheck:{maxConcurrent:n.maxConcurrent,skipIfBudgetLow:n.skipIfBudgetLow},enabled:n.enabled};o(!0);try{const A=s?await C.put(`/schedules/${encodeURIComponent(s.id)}`,b):await C.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:ml.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:zt.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:Ct.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:ul.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:ha.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:[ht.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:hl.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(R,{variant:"ghost",type:"button",onClick:t,disabled:c,children:"Cancel"}),e.jsx(R,{variant:"primary",type:"submit",disabled:c,children:s?"Save":"Create"})]})]})}function vl(s){var l,c;if(s.type!=="cron")return s.schedule;const t=ua(s.schedule);if(!t)return s.schedule;const a=((l=zt.find(o=>o.value===t.dow))==null?void 0:l.label)||"",i=((c=Ct.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 bl(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 Bt(s){return s==="success"?"tag-success":s==="skipped"?"tag-warning":"tag-error"}function Ut(s,t){return s.length<=t?s:s.slice(0,t-1)+"…"}const kl=[{id:"all",label:"All",icon:Oe},{id:"shipped",label:"Shipped",icon:kt},{id:"user",label:"User",icon:la},{id:"project",label:"Project",icon:Ee}],Ps={shipped:"Shipped",user:"User",project:"Project"},Nl={shipped:kt,user:la,project:Ee};function wl({snapshot:s,refreshSnapshot:t}){const a=oe(),i=De(),[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,j]=r.useState(null),[b,A]=r.useState(!1),N=async()=>{var $,D,f;x(!0);try{const F=await C.get("/skills");l(F.skills||[]),o({shipped:(($=F.counts)==null?void 0:$.shipped)??0,user:((D=F.counts)==null?void 0:D.user)??0,project:((f=F.counts)==null?void 0:f.project)??0,all:(F.skills||[]).length})}catch(F){a.error(`Skills load failed: ${F.message}`)}finally{x(!1)}};r.useEffect(()=>{N()},[]),r.useEffect(()=>{if(!m.trim()){j(null);return}A(!0);const $=setTimeout(async()=>{try{const D=await C.get(`/skills/search?q=${encodeURIComponent(m.trim())}`);j(D.results||[])}catch(D){a.error(`Search failed: ${D.message}`)}finally{A(!1)}},280);return()=>clearTimeout($)},[m]);const w=r.useMemo(()=>g!==null?g:h==="all"?n:n.filter($=>$.source===h),[n,h,g]),E=async()=>{try{await C.post("/skills/refresh",{}),a.success("Skills refreshed."),await N()}catch($){a.error(`Refresh failed: ${$.message}`)}},M=async $=>{try{const D=await C.get(`/skills/${encodeURIComponent($.source)}/${encodeURIComponent($.name)}`);i.open({title:D.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":D.source,children:Ps[D.source]||D.source}),e.jsx("code",{className:"mono text-sm muted",children:D.path})]}),D.description&&e.jsx("p",{className:"skill-detail-desc",children:D.description}),D.body&&e.jsx("div",{className:"skill-detail-body",children:e.jsx("pre",{className:"skill-body-pre",children:D.body})})]}),footer:e.jsx(R,{variant:"ghost",onClick:()=>i.close(),children:"Close"})})}catch{i.open({title:$.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":$.source,children:Ps[$.source]||$.source}),e.jsx("code",{className:"mono text-sm muted",children:$.path})]}),$.description&&e.jsx("p",{className:"skill-detail-desc",children:$.description})]}),footer:e.jsx(R,{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(ve,{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:$=>u($.target.value),"aria-label":"Search skills"}),m&&e.jsx("button",{type:"button",className:"icon-btn","aria-label":"Clear search",onClick:()=>u(""),children:e.jsx(Xe,{size:12})})]}),e.jsxs(R,{variant:"secondary",size:"sm",onClick:E,children:[e.jsx(ce,{size:14})," Refresh"]})]})]}),!m.trim()&&e.jsx("div",{className:"skills-tabs",children:kl.map($=>{const D=$.icon,f=$.id==="all"?c.all:c[$.id]??0;return e.jsxs("button",{type:"button",className:K("skills-tab",h===$.id&&"skills-tab-active"),onClick:()=>d($.id),children:[e.jsx(D,{size:14}),e.jsx("span",{children:$.label}),e.jsx("span",{className:"skills-tab-count",children:f})]},$.id)})}),m.trim()&&e.jsxs("section",{className:"skills-section",children:[e.jsxs("h3",{className:"skills-section-title",children:[e.jsx(ve,{size:14})," Search results",b&&e.jsx(he,{size:"sm"})]}),b?e.jsx("div",{className:"skills-grid",children:[0,1,2].map($=>e.jsx("div",{className:"skill-card skill-card-skeleton"},$))}):g&&g.length===0?e.jsx(we,{icon:e.jsx(ve,{size:28}),title:"No matches",message:`No skills match "${m}".`}):e.jsx("div",{className:"skills-grid",children:(g||[]).map(($,D)=>e.jsx(qt,{skill:$,onShow:()=>M($),searchQ:m},`search-${D}`))})]}),!m.trim()&&e.jsx("section",{className:"skills-section",children:p?e.jsx("div",{className:"view-loading",children:e.jsx(he,{size:"lg"})}):w.length===0?e.jsx(we,{icon:e.jsx(Zt,{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:w.map(($,D)=>e.jsx(qt,{skill:$,onShow:()=>M($)},`${$.source}-${$.name}-${D}`))})}),!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 qt({skill:s,onShow:t,searchQ:a=""}){const i=Nl[s.source]||kt,n=s.description?s.description.length>200?s.description.slice(0,200)+"…":s.description:"No description.";return e.jsxs(Y,{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:Sl(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(R,{variant:"ghost",size:"sm",onClick:t,children:[e.jsx(os,{size:12})," View"]})})]})}function Sl(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 Cl=Ve.memo(wl);function zl({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[j,b,A,N]=await Promise.all([C.get("/memory/health",g).catch(()=>null),C.get("/memory/status",g).catch(()=>null),C.get("/memory/lightrag/stats",g).catch(()=>null),C.get("/memory/storage",g).catch(()=>null)]);l({health:j||{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:(N==null?void 0:N.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:N||{total:0,breakdown:[]}})}catch(j){i.error(`Memory overview failed: ${j.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(Y,{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(R,{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(Ie,{size:14}),e.jsx("span",{children:"LightRAG"}),e.jsx("span",{className:K("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:K("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(ls,{size:14}),e.jsx("span",{children:"Git Sync"}),e.jsx("span",{className:K("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(ve,{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(as,{icon:e.jsx(Ie,{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(as,{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(as,{icon:e.jsx(ls,{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(as,{icon:e.jsx(aa,{size:16}),label:"Storage",value:Ml(m.total),sub:m.breakdown.length>0?`${m.breakdown.length} dirs tracked`:"no memory data on disk"}),e.jsx(as,{icon:e.jsx(Oe,{size:16}),label:"Last reindex",value:d.lastReindexAt?cs(d.lastReindexAt):"never",sub:"lightrag ingest",onClick:()=>a("lightrag")}),e.jsx(as,{icon:e.jsx(ks,{size:16}),label:"Health",value:`${x.score}/100`,sub:x.status,onClick:()=>a("config")})]}),x.checks.length>0&&e.jsxs(Y,{children:[e.jsx(ee,{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(_e,{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(Xe,{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 as({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:K("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 Ml(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 Tl({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,j]=r.useState(null),b=async()=>{x(!0);try{const[f,F,S]=await Promise.all([C.get("/memory/lightrag/stats").catch(()=>null),C.get("/memory/config").then(y=>(y==null?void 0:y.lightrag)||null).catch(()=>null),C.get("/memory/lightrag/log").catch(()=>({lines:[]}))]);i(f),l(F),o((S==null?void 0:S.lines)||[])}catch(f){t.error(`LightRAG status failed: ${f.message}`)}finally{x(!1)}};r.useEffect(()=>{b()},[s]);const A=async(f,F,S)=>{d(f);try{await F(),t.success(S),await b()}catch(y){t.error(`${f} failed: ${y.message}`)}finally{d(null)}},N=()=>A("start",()=>C.post("/memory/lightrag/start",{}),"LightRAG starting…"),w=()=>A("stop",()=>C.post("/memory/lightrag/stop",{}),"LightRAG stopping…"),E=async()=>{d("restart");try{await C.post("/memory/lightrag/stop",{}).catch(()=>{}),await new Promise(f=>setTimeout(f,600)),await C.post("/memory/lightrag/start",{}),t.success("LightRAG restarted."),await b()}catch(f){t.error(`Restart failed: ${f.message}`)}finally{d(null)}},M=()=>A("reindex",()=>C.post("/memory/lightrag/reindex",{}),"Reindex complete."),$=()=>A("rebuild",()=>C.post("/memory/lightrag/rebuild-graph",{}),"Graph rebuilt."),D=async()=>{var f,F,S;if(m.trim()){d("query");try{const y=await C.get(`/memory/query?q=${encodeURIComponent(m)}&topK=8`),k=(f=y==null?void 0:y.semantic)!=null&&f.response?typeof y.semantic.response=="string"?y.semantic.response:JSON.stringify(y.semantic.response):((F=y==null?void 0:y.semantic)==null?void 0:F.error)||"No response";j({ok:!!((S=y==null?void 0:y.semantic)!=null&&S.ok),text:k})}catch(y){j({ok:!1,text:y.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(Y,{variant:"elevated",children:[e.jsxs(ee,{children:[e.jsx(Ie,{size:14}),"LightRAG",e.jsx("span",{className:K("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(R,{variant:"primary",size:"sm",onClick:N,disabled:!!h||a.running,children:[h==="start"?e.jsx(je,{size:12,className:"memory-spin"}):e.jsx(ws,{size:12}),"Start"]}),e.jsxs(R,{variant:"secondary",size:"sm",onClick:w,disabled:!!h||!a.running,children:[h==="stop"?e.jsx(je,{size:12,className:"memory-spin"}):e.jsx(Nn,{size:12}),"Stop"]}),e.jsxs(R,{variant:"secondary",size:"sm",onClick:E,disabled:!!h,children:[h==="restart"?e.jsx(je,{size:12,className:"memory-spin"}):e.jsx(gt,{size:12}),"Restart"]}),e.jsxs(R,{variant:"ghost",size:"sm",onClick:M,disabled:!!h,children:[h==="reindex"?e.jsx(je,{size:12,className:"memory-spin"}):e.jsx(ce,{size:12}),"Reindex all"]}),e.jsxs(R,{variant:"ghost",size:"sm",onClick:$,disabled:!!h,title:"Wipe working dir + reindex from scratch",children:[h==="rebuild"?e.jsx(je,{size:12,className:"memory-spin"}):e.jsx(jt,{size:12}),"Rebuild graph"]})]})]}),e.jsxs("div",{className:"memory-stat-grid",children:[e.jsx(ms,{icon:e.jsx(aa,{size:14}),label:"Indexed chunks (approx)",value:String(a.indexedApprox)}),e.jsx(ms,{icon:e.jsx($l,{n:a.noteCount}),label:"Notes in vault",value:String(a.noteCount)}),e.jsx(ms,{icon:e.jsx(Nt,{size:14}),label:"Queries last 24h",value:String(a.queryCountLast24h)}),e.jsx(ms,{icon:e.jsx(Oe,{size:14}),label:"Avg response",value:a.avgResponseMs!==null?`${a.avgResponseMs} ms`:"—"}),e.jsx(ms,{icon:a.lastReindexOk?e.jsx(_e,{size:14}):a.lastReindexOk===!1?e.jsx(Xe,{size:14}):e.jsx(ce,{size:14}),label:"Last reindex",value:a.lastReindexAt?cs(a.lastReindexAt):"never",sub:a.lastReindexInserted!==null?`${a.lastReindexInserted} inserted${a.lastReindexFailed?`, ${a.lastReindexFailed} failed`:""}`:void 0})]}),e.jsxs(Y,{children:[e.jsxs(ee,{children:[e.jsx(ve,{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:f=>u(f.target.value),onKeyDown:f=>{f.key==="Enter"&&D()},disabled:h==="query","aria-label":"Search LightRAG"}),e.jsxs(R,{variant:"primary",onClick:D,disabled:h==="query"||!m.trim(),children:[h==="query"?e.jsx(je,{size:12,className:"memory-spin"}):e.jsx(ve,{size:12}),"Query"]})]}),g&&e.jsx("div",{className:K("memory-query-result",g.ok?"ok":"err"),children:e.jsx("pre",{className:"mono text-sm",children:g.text})})]}),n&&e.jsxs(Y,{children:[e.jsx(ee,{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(Y,{children:[e.jsxs(ee,{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(`
|
|
362
|
+
`)})]})]}):e.jsx("div",{className:"muted",children:"No LightRAG data available."})}function ms({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 $l({n:s}){return e.jsxs("span",{style:{position:"relative",display:"inline-block"},children:[e.jsx(ve,{size:14}),e.jsx("span",{className:"memory-mini-badge",children:s})]})}function Al({refreshKey:s}){const t=oe(),a=De(),[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),[j,b]=r.useState(null),[A,N]=r.useState([]),w=async()=>{var S;p(!0);try{const[y,k]=await Promise.all([C.get("/memory/notes").catch(()=>({notes:[]})),C.get("/memory/obsidian/tree").catch(()=>({tree:null}))]);n(y.notes||[]),c(k.tree),j&&!((S=y.notes)!=null&&S.find(P=>P.relPath===j))&&(b(null),N([]))}catch(y){t.error(`Vault load failed: ${y.message}`)}finally{p(!1)}};r.useEffect(()=>{w()},[s]),r.useEffect(()=>{if(!x.trim()){m(null);return}g(!0);const S=setTimeout(async()=>{try{const y=await C.get(`/memory/search?q=${encodeURIComponent(x)}&limit=50`),k=new Set((y.results||[]).map(P=>P.relPath));m(i.filter(P=>k.has(P.relPath)))}catch(y){t.error(`Search failed: ${y.message}`)}finally{g(!1)}},240);return()=>clearTimeout(S)},[x,i,t]);const E=async S=>{b(S);try{const y=await C.get(`/memory/obsidian/backlinks?note=${encodeURIComponent(S)}`);N(y.backlinks||[])}catch{N([])}},M=()=>{a.open({title:"New note",width:720,children:e.jsx(Ht,{mode:"create",onSave:async(S,y,k)=>{try{await C.post("/memory/notes",{path:S,frontmatter:y,body:k}),t.success(`Created ${S}.`),a.close(),await w(),E(S)}catch(P){t.error(`Create failed: ${P.message}`)}},onCancel:()=>a.close()})})},$=async S=>{try{const y=await C.get(`/memory/notes/${S.split("/").map(encodeURIComponent).join("/")}`);a.open({title:`Edit ${S}`,width:720,children:e.jsx(Ht,{mode:"edit",initial:{relPath:y.relPath,frontmatter:y.frontmatter,body:y.body},onSave:async(k,P,v)=>{try{await C.put(`/memory/notes/${k.split("/").map(encodeURIComponent).join("/")}`,{frontmatter:P,body:v}),t.success(`Saved ${k}.`),a.close(),await w(),E(k)}catch(L){t.error(`Save failed: ${L.message}`)}},onCancel:()=>a.close()})})}catch(y){t.error(`Load failed: ${y.message}`)}},D=async S=>{if(confirm(`Delete ${S}? This cannot be undone.`))try{await C.del(`/memory/notes/${S.split("/").map(encodeURIComponent).join("/")}`),t.success(`Deleted ${S}.`),j===S&&b(null),await w()}catch(y){t.error(`Delete failed: ${y.message}`)}},f=r.useMemo(()=>[...i].sort((S,y)=>y.mtime-S.mtime),[i]),F=d??f;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(Y,{variant:"outlined",className:"memory-tree-card",children:[e.jsxs(ee,{children:[e.jsx(Ee,{size:14})," Folders"]}),e.jsx(ie,{children:l?`${ga(l)} folder(s)`:"no vault"}),e.jsx("div",{className:"memory-tree-body",children:l?e.jsx(pa,{node:l,depth:0,onSelect:E,selected:j}):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(ve,{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:S=>h(S.target.value),"aria-label":"Search notes"}),x&&e.jsx("button",{type:"button",className:"icon-btn",onClick:()=>h(""),"aria-label":"Clear search",children:e.jsx(Ce,{size:12})})]}),e.jsxs(R,{variant:"primary",size:"sm",onClick:M,children:[e.jsx(an,{size:12})," New note"]}),e.jsx(R,{variant:"ghost",size:"sm",onClick:w,title:"Refresh",children:e.jsx(ce,{size:12})})]}),u&&e.jsx("div",{className:"muted text-sm",children:"Searching…"}),F.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:F.map(S=>e.jsxs("li",{className:K("memory-note-card",j===S.relPath&&"memory-note-card-active"),children:[e.jsxs("button",{type:"button",className:"memory-note-card-main",onClick:()=>E(S.relPath),children:[e.jsxs("div",{className:"memory-note-card-title",children:[e.jsx(Se,{size:12}),e.jsx("span",{children:xa(S)})]}),e.jsxs("div",{className:"memory-note-card-meta",children:[e.jsx("code",{className:"muted",children:S.relPath}),e.jsxs("span",{className:"muted",children:["· ",Ne(S.mtime)]}),!S.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:()=>$(S.relPath),"aria-label":`Edit ${S.relPath}`,title:"Edit",children:e.jsx(Ns,{size:12})}),e.jsx("button",{type:"button",className:"icon-btn",onClick:()=>D(S.relPath),"aria-label":`Delete ${S.relPath}`,title:"Delete",children:e.jsx(Ae,{size:12})})]})]},S.relPath))})]}),e.jsx("div",{className:"memory-obsidian-detail-col",children:j?e.jsx(Rl,{relPath:j,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 xa(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 pa({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:K("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(We,{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(pa,{node:c,depth:t+1,onSelect:a,selected:i},`${c.path}-${o}`))})]})}function ga(s){return s.type==="note"?0:1+(s.children||[]).reduce((t,a)=>t+ga(a),0)}function Rl({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([C.get(`/memory/notes/${s.split("/").map(encodeURIComponent).join("/")}`),C.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:xa(a)}),e.jsx("button",{type:"button",className:"icon-btn",onClick:t,"aria-label":"Close",children:e.jsx(Ce,{size:12})})]}),e.jsxs("div",{className:"memory-note-detail-meta",children:[e.jsx("code",{children:s}),e.jsxs("span",{className:"muted",children:["· modified ",cs(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 Ht({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?Ll(t.frontmatter):`title: ""
|
|
363
|
+
tags: []
|
|
364
|
+
`),[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=Il(c)||{}}catch(j){m.error(`Frontmatter parse failed: ${j.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(R,{variant:"ghost",onClick:i,disabled:h,children:"Cancel"}),e.jsxs(R,{variant:"primary",onClick:u,disabled:h,children:[h&&e.jsx(je,{size:12,className:"memory-spin"}),s==="create"?"Create":"Save"]})]})]})}function Ll(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(` - ${tt(n)}`)}else if(typeof i=="object"){t.push(`${a}:`);for(const[n,l]of Object.entries(i))t.push(` ${n}: ${tt(l)}`)}else t.push(`${a}: ${tt(i)}`);return t.join(`
|
|
365
|
+
`)}function tt(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 Il(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(at(m.slice(4))),i++;else{d=!0;const u=m.match(/^ ([A-Za-z_][\w-]*):\s*(.*)$/);u&&(p[u[1]]=at(u[2])),i++}}t[c]=h&&!d?x:d?p:{}}else t[c]=at(o);i++}return t}function at(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 El({refreshKey:s}){var w,E,M,$;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 D;o(!0);try{const[f,F,S]=await Promise.all([C.get("/memory/git/status").catch(()=>null),C.get("/memory/git/diff").catch(()=>null),C.get("/memory/config/global").catch(()=>null)]);i(f),l(F),d(((D=S==null?void 0:S.config)==null?void 0:D.git)||null)}catch(f){t.error(`Git status failed: ${f.message}`)}finally{o(!1)}};r.useEffect(()=>{m()},[s]);const u=async(D,f,F)=>{x(D);try{await f(),t.success(F),await m()}catch(S){t.error(`${D} failed: ${S.message}`)}finally{x(null)}},g=()=>u("pull",()=>C.post("/memory/git/pull",{}),"Pull complete."),j=()=>u("push",()=>C.post("/memory/git/push",{}),"Push complete."),b=()=>{const D=prompt("Commit message:",`[memory-sync] ${new Date().toISOString().slice(0,10)} vault sync`);D&&u("commit",()=>C.post("/memory/git/commit",{message:D}),"Committed.")},A=()=>u("fetch",()=>C.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 N=a.mode==="local-only";return e.jsxs("div",{className:"memory-panel-content",children:[e.jsxs(Y,{variant:"elevated",children:[e.jsxs(ee,{children:[e.jsx(ls,{size:14})," Git sync",N?e.jsx("span",{className:"memory-source-pill-status na",children:"local-only"}):e.jsx("span",{className:K("memory-source-pill-status",a.clean?"on":"warn"),children:a.clean?"clean":"dirty"})]}),e.jsx(ie,{children:N?"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]})}),!N&&e.jsxs("div",{className:"memory-git-status-row",children:[e.jsx(hs,{ok:a.clean??!1,label:"Working tree"}),e.jsx(hs,{ok:(a.ahead??0)===0,label:`Ahead: ${a.ahead??0}`}),e.jsx(hs,{ok:(a.behind??0)===0,label:`Behind: ${a.behind??0}`}),e.jsx(hs,{ok:(((w=a.modified)==null?void 0:w.length)??0)===0,label:`Modified: ${((E=a.modified)==null?void 0:E.length)??0}`}),e.jsx(hs,{ok:(((M=a.untracked)==null?void 0:M.length)??0)===0,label:`Untracked: ${(($=a.untracked)==null?void 0:$.length)??0}`})]}),e.jsxs("div",{className:"memory-action-row",children:[e.jsxs(R,{variant:"secondary",size:"sm",onClick:g,disabled:!!p||N,children:[p==="pull"?e.jsx(je,{size:12,className:"memory-spin"}):e.jsx(ea,{size:12}),"Pull"]}),e.jsxs(R,{variant:"secondary",size:"sm",onClick:j,disabled:!!p||N,children:[p==="push"?e.jsx(je,{size:12,className:"memory-spin"}):e.jsx(yt,{size:12}),"Push"]}),e.jsxs(R,{variant:"secondary",size:"sm",onClick:b,disabled:!!p||N,children:[p==="commit"?e.jsx(je,{size:12,className:"memory-spin"}):e.jsx(dn,{size:12}),"Commit"]}),e.jsxs(R,{variant:"ghost",size:"sm",onClick:A,disabled:!!p||N,children:[p==="fetch"?e.jsx(je,{size:12,className:"memory-spin"}):e.jsx(hn,{size:12}),"Fetch + sync"]}),e.jsxs(R,{variant:"ghost",size:"sm",onClick:m,disabled:!!p,children:[e.jsx(ce,{size:12})," Refresh"]})]})]}),h&&e.jsxs(Y,{children:[e.jsxs(ee,{children:[e.jsx(qa,{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(Y,{children:[e.jsxs(ee,{children:[e.jsx(mn,{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(D=>e.jsx("li",{children:e.jsx("code",{children:D})},D))}),n&&n.lines.length>1&&e.jsx("pre",{className:"memory-log-tail mono text-xs",children:n.lines.slice(0,400).join(`
|
|
366
|
+
`)})]})]})}function hs({ok:s,label:t}){return e.jsxs("span",{className:K("memory-git-status-pill",s?"ok":"warn"),children:[s?e.jsx(_e,{size:11}):e.jsx(je,{size:11,className:"memory-spin"}),t]})}function Dl({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 j=[...n.lightrag?["lightrag"]:[],...n.obsidian?["obsidian"]:[]],b=await C.post("/memory/semantic-search",{query:g,limit:20,sources:j});o(b.results||[])}catch(j){t.error(`Search failed: ${j.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"),j=(c||[]).filter(b=>b.source==="lightrag");return{obs:g,lr:j}},[c]);return e.jsxs("div",{className:"memory-panel-content",children:[e.jsxs(Y,{variant:"elevated",children:[e.jsxs(ee,{children:[e.jsx(ve,{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(R,{variant:"primary",onClick:()=>m(a),disabled:p||!a.trim(),children:[p?e.jsx(je,{size:12,className:"memory-spin"}):e.jsx(ve,{size:12}),"Search"]})]}),e.jsxs("div",{className:"memory-source-toggle-row",children:[e.jsx(_t,{active:n.obsidian,onToggle:()=>l(g=>({...g,obsidian:!g.obsidian})),label:"Obsidian",icon:e.jsx(Se,{size:11})}),e.jsx(_t,{active:n.lightrag,onToggle:()=>l(g=>({...g,lightrag:!g.lightrag})),label:"LightRAG",icon:e.jsx(Ie,{size:11})}),a&&e.jsx("button",{type:"button",className:"icon-btn",onClick:()=>{i(""),o(null),d("")},"aria-label":"Clear",children:e.jsx(Ce,{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(ve,{size:28}),title:"No matches",message:`Nothing in scope matched "${h}".`}),u.obs.length>0&&e.jsxs(Y,{children:[e.jsxs(ee,{children:[e.jsx(Se,{size:14})," Obsidian (",u.obs.length,")"]}),e.jsx("ul",{className:"memory-search-result-list",children:u.obs.map((g,j)=>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-${j}`))})]}),u.lr.length>0&&e.jsxs(Y,{children:[e.jsxs(ee,{children:[e.jsx(Ie,{size:14})," LightRAG (",u.lr.length,")"]}),e.jsx("div",{className:"memory-search-result-list",children:u.lr.map((g,j)=>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(Ie,{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-${j}`))})]})]})}function _t({active:s,onToggle:t,label:a,icon:i}){return e.jsxs("button",{type:"button",className:K("memory-toggle-chip",s&&"memory-toggle-chip-active"),onClick:t,"aria-pressed":s,children:[i,e.jsx("span",{children:a})]})}function Pl({refreshKey:s}){var b,A,N,w,E,M,$,D,f,F,S,y;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 k=await C.get("/memory/config/global");i(k.config)}catch(k){t.error(`Config load failed: ${k.message}`)}finally{l(!1)}};r.useEffect(()=>{m()},[s]);const u=(k,P,v)=>{i(L=>L&&{...L,[k]:{...L[k]||{},[P]:v}})},g=async()=>{if(a){o(!0);try{await C.put("/memory/config/global",a),t.success("Config saved.")}catch(k){t.error(`Save failed: ${k.message}`)}finally{o(!1)}}},j=async()=>{d(!0);try{const k=await C.post("/memory/test-git",{});x(k.checks)}catch(k){t.error(`Test failed: ${k.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(Y,{children:[e.jsxs(ee,{children:[e.jsx(Ie,{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:k=>u("lightrag","enabled",k.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:((N=a.lightrag)==null?void 0:N.url)||"",onChange:k=>u("lightrag","url",k.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:((w=a.lightrag)==null?void 0:w.llm)||"",onChange:k=>u("lightrag","llm",k.target.value),placeholder:"opencode/gpt-5-nano"})}),e.jsx(Ue,{label:"Embedding",children:e.jsx("input",{type:"text",className:"input mono",value:((E=a.lightrag)==null?void 0:E.embedding)||"",onChange:k=>u("lightrag","embedding",k.target.value),placeholder:"opencode/text-embedding-3-small"})})]})]}),e.jsxs(Y,{children:[e.jsxs(ee,{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:((M=a.obsidian)==null?void 0:M.vaultPath)||"",onChange:k=>u("obsidian","vaultPath",k.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:(($=a.obsidian)==null?void 0:$.syncInterval)??300,onChange:k=>u("obsidian","syncInterval",Number(k.target.value))})})]})]}),e.jsxs(Y,{children:[e.jsxs(ee,{children:[e.jsx(ls,{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:((D=a.git)==null?void 0:D.repoPath)||"",onChange:k=>u("git","repoPath",k.target.value),placeholder:"/path/to/repo"})}),e.jsx(Ue,{label:"Remote URL",children:e.jsx("input",{type:"text",className:"input mono",value:((f=a.git)==null?void 0:f.remoteUrl)||"",onChange:k=>u("git","remoteUrl",k.target.value),placeholder:"git@github.com:org/repo.git"})}),e.jsx(Ue,{label:"Branch",children:e.jsx("input",{type:"text",className:"input mono",value:((F=a.git)==null?void 0:F.branch)||"main",onChange:k=>u("git","branch",k.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:!!((S=a.git)!=null&&S.autoSync),onChange:k=>u("git","autoSync",k.target.checked)}),e.jsx("span",{children:(y=a.git)!=null&&y.autoSync?"on":"off"})]})})]})]}),e.jsxs(Y,{children:[e.jsxs(ee,{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(Y,{children:[e.jsxs(ee,{children:[e.jsx(ct,{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(R,{variant:"secondary",onClick:j,disabled:h,children:[h?e.jsx(je,{size:12,className:"memory-spin"}):e.jsx(ct,{size:12}),"Test git connection"]}),e.jsxs(R,{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((k,P)=>e.jsxs("li",{className:"memory-check-row",children:[e.jsx("span",{className:"memory-check-icon",children:e.jsx("span",{className:K("memory-pill",k.pass?"memory-pill-ok":"memory-pill-warn"),children:k.pass?"OK":"FAIL"})}),e.jsx("span",{className:"memory-check-name",children:k.name}),e.jsx("span",{className:"memory-check-detail muted",children:k.detail})]},P))})]})]}):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 qe=800,Wt=60,nt={default:"#8b5cf6",note:"#8b5cf6",entity:"#34d399",concept:"#fbbf24",root:"#f87171"};function Fl(s,t){return nt[s]||nt[t]||nt.default}function Ol(s){return 6+Math.min(s.size*2,10)}function Bl(s,t){var l,c;if(s.length===0)return[];const a=new Map;for(const o of s)a.set(o.id,new Set);for(const o of t)(l=a.get(o.source))==null||l.add(o.target),(c=a.get(o.target))==null||c.add(o.source);const i=s.map((o,p)=>{const x=p/s.length*Math.PI*2,h=qe*.28;return{...o,x:qe/2+h*Math.cos(x)+(Math.random()-.5)*40,y:qe/2+h*Math.sin(x)+(Math.random()-.5)*40,vx:0,vy:0}}),n=new Map;for(const o of i)n.set(o.id,o);for(let o=0;o<Wt;o++){const p=1-o/Wt;for(let d=0;d<i.length;d++)for(let m=d+1;m<i.length;m++){const u=i[d],g=i[m],j=g.x-u.x,b=g.y-u.y,A=Math.sqrt(j*j+b*b)||1,N=400*p/(A*A),w=j/A*N,E=b/A*N;u.vx-=w,u.vy-=E,g.vx+=w,g.vy+=E}for(const d of t){const m=n.get(d.source),u=n.get(d.target);if(!m||!u)continue;const g=u.x-m.x,j=u.y-m.y,b=Math.sqrt(g*g+j*j)||1,N=(b-80)*.08*p,w=g/b*N,E=j/b*N;m.vx+=w,m.vy+=E,u.vx-=w,u.vy-=E}const x=qe/2,h=qe/2;for(const d of i)d.vx+=(x-d.x)*.01*p,d.vy+=(h-d.y)*.01*p;for(const d of i)d.vx*=.85,d.vy*=.85,d.x+=d.vx,d.y+=d.vy,d.x=Math.max(20,Math.min(qe-20,d.x)),d.y=Math.max(20,Math.min(qe-20,d.y))}return i}function Ul({data:s,onNodeClick:t,className:a}){const i=r.useRef(null),[n,l]=r.useState({x:0,y:0,scale:1}),c=r.useRef(!1),o=r.useRef({x:0,y:0,tx:0,ty:0}),p=r.useRef(null),[x,h]=r.useState(null),[d,m]=r.useState(null),u=r.useMemo(()=>Bl(s.nodes,s.edges),[s.nodes,s.edges]),g=r.useMemo(()=>{const f=new Map;for(const F of u)f.set(F.id,F);return f},[u]),j=r.useCallback(f=>{f.target.closest(".memory-graph-node")||(c.current=!0,o.current={x:f.clientX,y:f.clientY,tx:n.x,ty:n.y})},[n]),b=r.useCallback(f=>{if(!c.current)return;const F=f.clientX-o.current.x,S=f.clientY-o.current.y;l(y=>({...y,x:o.current.tx+F,y:o.current.ty+S}))},[]),A=r.useCallback(()=>{c.current=!1},[]),N=r.useCallback(f=>{f.preventDefault();const F=f.deltaY<0?1.1:.9,S=i.current;if(!S)return;const y=S.getBoundingClientRect(),k=f.clientX-y.left,P=f.clientY-y.top;l(v=>{const L=Math.max(.2,Math.min(4,v.scale*F)),B=L/v.scale;return{x:k-(k-v.x)*B,y:P-(P-v.y)*B,scale:L}})},[]),w=r.useCallback(f=>{const F=Array.from(f.touches);if(F.length===2){const[S,y]=F;p.current=Math.hypot(y.clientX-S.clientX,y.clientY-S.clientY)}else F.length===1&&(c.current=!0,o.current={x:F[0].clientX,y:F[0].clientY,tx:n.x,ty:n.y})},[n]),E=r.useCallback(f=>{const F=Array.from(f.touches);if(F.length===2&&p.current!==null){const[S,y]=F,k=Math.hypot(y.clientX-S.clientX,y.clientY-S.clientY),P=k/p.current;p.current=k,l(v=>({...v,scale:Math.max(.2,Math.min(4,v.scale*P))}))}else if(F.length===1&&c.current){const S=F[0].clientX-o.current.x,y=F[0].clientY-o.current.y;l(k=>({...k,x:o.current.tx+S,y:o.current.ty+y}))}},[]),M=r.useCallback(()=>{c.current=!1,p.current=null},[]),$=r.useCallback(f=>{h(f.id===x?null:f.id),t==null||t(f)},[x,t]),D=Math.max(.5,1/Math.log2(n.scale+1));return e.jsx("svg",{ref:i,className:K("memory-graph-canvas",a),viewBox:`0 0 ${qe} ${qe}`,style:{width:"100%",height:"100%",minHeight:400,cursor:c.current?"grabbing":"grab"},onMouseDown:j,onMouseMove:b,onMouseUp:A,onMouseLeave:A,onWheel:N,onTouchStart:w,onTouchMove:E,onTouchEnd:M,children:e.jsxs("g",{transform:`translate(${n.x},${n.y}) scale(${n.scale})`,children:[s.edges.map((f,F)=>{const S=g.get(f.source),y=g.get(f.target);if(!S||!y)return null;const k=d===f.source||d===f.target||x===f.source||x===f.target;return e.jsx("line",{x1:S.x,y1:S.y,x2:y.x,y2:y.y,stroke:k?"#8b5cf6":"#2d3648",strokeWidth:k?D*2:D,strokeOpacity:k?.9:.5},`e-${F}`)}),u.map(f=>{const F=Ol(f),S=Fl(f.group,f.type),y=x===f.id,k=d===f.id;return e.jsxs("g",{className:"memory-graph-node",transform:`translate(${f.x},${f.y})`,onClick:()=>$(f),onMouseEnter:()=>m(f.id),onMouseLeave:()=>m(null),style:{cursor:"pointer"},children:[e.jsx("circle",{r:F+6,fill:"transparent"}),(y||k)&&e.jsx("circle",{r:F+4,fill:S,fillOpacity:.2}),e.jsx("circle",{r:F,fill:S,fillOpacity:y?1:.75,stroke:y?"#fff":S,strokeWidth:y?2:1}),n.scale>.5&&e.jsx("text",{y:F+12,textAnchor:"middle",fontSize:Math.max(8,Math.min(11,10/Math.sqrt(n.scale))),fill:"var(--text-dim, #b4bcd0)",style:{pointerEvents:"none",userSelect:"none"},children:f.label.length>20?f.label.slice(0,18)+"…":f.label})]},f.id)})]})})}const ql=[{color:"#8b5cf6",label:"Note / Default"},{color:"#34d399",label:"Entity (LightRAG)"},{color:"#fbbf24",label:"Concept (LightRAG)"},{color:"#f87171",label:"Root / Ungrouped"}];function Hl({className:s}){return e.jsx("div",{className:K("memory-graph-legend",s),children:ql.map(t=>e.jsxs("span",{className:"memory-graph-legend-item",children:[e.jsx("span",{className:"memory-graph-legend-dot",style:{background:t.color}}),t.label]},t.label))})}function _l({refreshKey:s}){const t=oe(),[a,i]=r.useState({nodes:[],edges:[]}),[n,l]=r.useState(!0),[c,o]=r.useState(null),[p,x]=r.useState(""),[h,d]=r.useState(2),[m,u]=r.useState(""),[g,j]=r.useState(null),[b,A]=r.useState(null),N=r.useCallback(async()=>{var M,$;l(!0),o(null);try{const D=new URLSearchParams({limit:"200"});m&&D.set("root",m),D.set("depth",String(h));const f=await C.get(`/memory/graph?${D}`);i({nodes:f.nodes||[],edges:f.edges||[]}),j({totalNodes:f.totalNodes??((M=f.nodes)==null?void 0:M.length)??0,totalEdges:f.totalEdges??(($=f.edges)==null?void 0:$.length)??0})}catch(D){o(D.message),t.error(`Graph load failed: ${D.message}`)}finally{l(!1)}},[m,h,t]);r.useEffect(()=>{N()},[N,s]);const w=r.useCallback(M=>{A($=>($==null?void 0:$.id)===M.id?null:M)},[]),E=p.trim()?{nodes:a.nodes.filter(M=>M.label.toLowerCase().includes(p.toLowerCase())),edges:a.edges.filter(M=>a.nodes.some($=>$.id===M.source&&$.label.toLowerCase().includes(p.toLowerCase()))||a.nodes.some($=>$.id===M.target&&$.label.toLowerCase().includes(p.toLowerCase())))}:a;return e.jsxs("div",{className:"memory-panel-content",children:[e.jsxs(Y,{children:[e.jsxs(ee,{children:[e.jsx(ia,{size:14})," Memory Graph"]}),e.jsx(ie,{children:"Interactive knowledge graph — LightRAG entities + Obsidian wikilinks. Drag to pan, scroll to zoom."}),e.jsxs("div",{className:"memory-graph-controls",children:[e.jsxs("div",{className:"memory-graph-search-row",children:[e.jsx("label",{htmlFor:"graph-filter",className:"sr-only",children:"Filter nodes"}),e.jsx("input",{id:"graph-filter",type:"text",className:"input",placeholder:"Filter nodes…",value:p,onChange:M=>x(M.target.value),style:{maxWidth:240}}),e.jsx("input",{type:"text",className:"input",placeholder:"Root note id (optional)",value:m,onChange:M=>u(M.target.value),style:{maxWidth:240},title:"Start from a specific note"}),e.jsx("label",{htmlFor:"graph-depth",className:"sr-only",children:"Depth"}),e.jsxs("span",{className:"muted text-sm",style:{whiteSpace:"nowrap"},children:["Depth",e.jsx("input",{id:"graph-depth",type:"range",min:1,max:3,value:h,onChange:M=>d(parseInt(M.target.value,10)),style:{marginLeft:8,verticalAlign:"middle"}}),h]}),e.jsx("button",{type:"button",className:"icon-btn",onClick:N,title:"Refresh graph",disabled:n,children:e.jsx(ce,{size:14,className:n?"memory-spin":""})})]}),e.jsx(Hl,{})]})]}),e.jsx(Y,{children:n&&!a.nodes.length?e.jsxs("div",{className:"view-loading",children:[e.jsx(he,{size:"lg"}),e.jsx("p",{children:"Loading graph…"})]}):c&&!a.nodes.length?e.jsxs("div",{className:"muted text-sm",children:["Failed to load graph: ",c]}):a.nodes.length===0?e.jsx("div",{className:"muted text-sm",children:"No graph data available. Index some notes first with LightRAG or add wikilinks to your vault."}):e.jsxs("div",{style:{position:"relative"},children:[e.jsx(Ul,{data:E,onNodeClick:w,className:"memory-graph-canvas-svg"}),p&&e.jsxs("div",{className:"text-xs muted",style:{marginTop:4},children:["Showing ",E.nodes.length," of ",a.nodes.length," nodes"]})]})}),b&&e.jsxs(Y,{children:[e.jsx(ee,{children:b.label}),e.jsx(ie,{children:e.jsx("code",{children:b.id})}),e.jsxs("dl",{className:"memory-config-row",children:[e.jsx("dt",{children:"Type"}),e.jsx("dd",{children:e.jsx("code",{children:b.type})}),e.jsx("dt",{children:"Group"}),e.jsx("dd",{children:e.jsx("code",{children:b.group})}),e.jsx("dt",{children:"Size"}),e.jsx("dd",{children:b.size})]})]}),g&&e.jsx(Y,{children:e.jsxs("div",{className:"memory-graph-stats",children:[e.jsxs("span",{children:[g.totalNodes," node",g.totalNodes!==1?"s":""]}),e.jsx("span",{className:"muted",children:"·"}),e.jsxs("span",{children:[g.totalEdges," edge",g.totalEdges!==1?"s":""]}),p&&e.jsxs("span",{className:"muted",children:["· ",E.nodes.length," shown"]})]})})]})}const Wl=[{id:"overview",label:"Overview",icon:na},{id:"lightrag",label:"LightRAG",icon:Ie},{id:"obsidian",label:"Obsidian Vault",icon:Se},{id:"git",label:"Git Sync",icon:ls},{id:"semantic",label:"Semantic Search",icon:ve},{id:"config",label:"Config",icon:xt},{id:"graph",label:"Memory Graph",icon:ia}];function Vl(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(zl,{refreshKey:n,onRefresh:c,setActiveSubPanel:i});case"lightrag":return e.jsx(Tl,{refreshKey:n});case"obsidian":return e.jsx(Al,{refreshKey:n});case"git":return e.jsx(El,{refreshKey:n});case"semantic":return e.jsx(Dl,{refreshKey:n});case"config":return e.jsx(Pl,{refreshKey:n});case"graph":return e.jsx(_l,{refreshKey:n});default:return e.jsxs(Y,{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(Ie,{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:K("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 Gl=Ve.memo(Vl),us=[{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 Kl(s,t,a,i){const n=a.has(s.id);return e.jsxs(Y,{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(We,{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 Yl({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 N=>{try{const w=N?`?since=${encodeURIComponent(N)}&limit=1000`:"?limit=1000",E=await C.get(`/history${w}`);i(E),x(new Set(E.projects.filter(M=>E.events.some($=>$.projectId===M.id)).map(M=>M.id)))}catch(w){t.error(`History load failed: ${w.message}`)}finally{l(!1)}};r.useEffect(()=>{l(!0);const N=us.find(w=>w.id===c)||us[1];if(N.ms>0){const w=new Date(Date.now()-N.ms).toISOString();m(w)}else m()},[c]),r.useEffect(()=>{const N=setInterval(()=>d(w=>w+1),3e4);return()=>clearInterval(N)},[]);const u=new Map;for(const N of(a==null?void 0:a.events)||[]){const w=N.projectId||"global";u.has(w)||u.set(w,[]),u.get(w).push(N)}const g=N=>{x(w=>{const E=new Set(w);return E.has(N)?E.delete(N):E.add(N),E})},j=()=>{if(!a)return;const N=new Blob([JSON.stringify(a,null,2)],{type:"application/json"}),w=URL.createObjectURL(N),E=document.createElement("a");E.href=w,E.download=`bizar-history-${new Date().toISOString().replace(/[:.]/g,"-")}.json`,E.click(),URL.revokeObjectURL(w),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(js,{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(rn,{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:N=>o(N.target.value),title:"Time range","aria-label":"Time range",children:us.map(N=>e.jsx("option",{value:N.id,children:N.label},N.id))})]}),e.jsxs(R,{variant:"ghost",size:"sm",onClick:()=>{l(!0);const N=us.find(w=>w.id===c)||us[1];N.ms>0?m(new Date(Date.now()-N.ms).toISOString()):m()},children:[e.jsx(ce,{size:14})," Refresh"]}),e.jsxs(R,{variant:"secondary",size:"sm",onClick:j,children:[e.jsx(Ze,{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(Y,{children:[e.jsxs(ee,{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(pt,{items:a.projects,itemHeight:70,height:Math.min(a.projects.length*70,500),className:"history-virtual-list",renderItem:N=>Kl(N,u.get(N.id)||[],p,g)}),u.has("global")&&e.jsxs(Y,{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(js,{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((N,w)=>e.jsxs("div",{className:"history-timeline-row",children:[e.jsx("span",{className:"history-timeline-ts",children:new Date(N.ts).toLocaleTimeString()}),e.jsx("span",{className:"history-timeline-kind",children:N.kind||"event"}),e.jsxs("span",{className:"history-timeline-msg",title:String(N.text||N.title||""),children:[N.author?`@${N.author} `:"",String(N.text??N.title??N.name??"")]})]},w))})]}),((A=a.stats)==null?void 0:A.counts)&&Object.keys(a.stats.counts).length>0&&e.jsxs(Y,{children:[e.jsx(ee,{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((N,w)=>w[1]-N[1]).slice(0,30).map(([N,w])=>e.jsxs("span",{className:K("tag","tag-neutral"),style:{fontFamily:"var(--font-mono)"},children:[N,": ",w]},N))})]})]})]})}const ye={top:16,right:20,bottom:40,left:52};function Xl({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:K("usage-chart-empty",i),style:{height:t},children:e.jsx("span",{children:"No data for this range"})});const d=600-ye.left-ye.right,m=t-ye.top-ye.bottom,u=Math.max(...p,1),g=Math.max(...x,1),j=Math.max(4,Math.min(24,Math.floor(d/h)-4)),b=(d-j*h)/(h+1);function A(k){return ye.left+b+k*(j+b)}function N(k){return k/u*m*.75}function w(k){return ye.top+m-k/g*m*.75}const E=x.map((k,P)=>`${A(P)+j/2},${w(k)}`).join(" "),M=[0,.25,.5,.75,1].map(k=>({y:ye.top+m-k*m*.75,label:k===0?"0":`${Math.round(u*k).toLocaleString()}`})),$=[0,.25,.5,.75,1].map(k=>({y:ye.top+m-k*m*.75,label:k===0?"0":`${Math.round(g*k/1e3)}k`})),D=Math.max(1,Math.floor(h/7)),f=o.map((k,P)=>({i:P,l:k,x:A(P)+j/2})).filter((k,P)=>P%D===0),F=r.useCallback(k=>{if(!n.current)return;const P=n.current.getBoundingClientRect(),v=(k.clientX-P.left)*(600/P.width),L=(k.clientY-P.top)*(t/P.height),B=v-ye.left,z=Math.round((B-b/2)/(j+b)),_=Math.max(0,Math.min(h-1,z));c({index:_,x:k.clientX-P.left,y:k.clientY-P.top}),a==null||a(_,v,L)},[h,j,b,a,t]),S=r.useCallback(()=>{c(null),a==null||a(null,0,0)},[a]),y=l;return e.jsxs("div",{ref:n,className:K("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:F,onMouseLeave:S,children:[M.map((k,P)=>e.jsx("line",{x1:ye.left,y1:k.y,x2:600-ye.right,y2:k.y,stroke:"var(--border)",strokeWidth:1,strokeDasharray:"4,3",opacity:.5},`grid-${P}`)),M.map((k,P)=>e.jsx("text",{x:ye.left-6,y:k.y+4,textAnchor:"end",fontSize:10,fill:"var(--text-muted)",fontFamily:"var(--font-mono, ui-monospace, monospace)",children:k.label},`ly-${P}`)),$.map((k,P)=>e.jsx("text",{x:600-ye.right+6,y:k.y+4,textAnchor:"start",fontSize:10,fill:"var(--text-muted)",fontFamily:"var(--font-mono, ui-monospace, monospace)",children:k.label},`ry-${P}`)),p.map((k,P)=>{const v=N(k),L=A(P),B=ye.top+m-v;return e.jsx("rect",{x:L,y:B,width:j,height:v,rx:2,fill:((y==null?void 0:y.index)===P,"var(--accent)"),opacity:(y==null?void 0:y.index)===P?1:.75,style:{transition:"opacity 120ms ease"}},`bar-${P}`)}),e.jsx("polyline",{points:E,fill:"none",stroke:"var(--warning, #d29922)",strokeWidth:2,strokeLinejoin:"round",strokeLinecap:"round",opacity:.9}),x.map((k,P)=>e.jsx("circle",{cx:A(P)+j/2,cy:w(k),r:(y==null?void 0:y.index)===P?5:3,fill:"var(--warning, #d29922)",opacity:(y==null?void 0:y.index)===P?1:.7,style:{transition:"r 120ms ease"}},`dot-${P}`)),f.map(({i:k,l:P,x:v})=>e.jsx("text",{x:v,y:ye.top+m+18,textAnchor:"middle",fontSize:10,fill:"var(--text-muted)",fontFamily:"var(--font-mono, ui-monospace, monospace)",children:P},`xl-${k}`)),e.jsx("line",{x1:ye.left,y1:ye.top+m,x2:600-ye.right,y2:ye.top+m,stroke:"var(--border)",strokeWidth:1})]}),y!==null&&e.jsxs("div",{className:"usage-chart-tooltip",style:{left:Math.min(y.x+12,460),top:y.y-60},children:[e.jsx("div",{className:"usage-tooltip-date",children:o[y.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[y.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[y.index].toLocaleString()})]})]})]})}function Ke({label:s,col:t,sortKey:a,sortDir:i,onSort:n}){const l=a===t;return e.jsxs("th",{className:K("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 Ql({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:K("mono",n.errors>0&&"is-err"),children:n.errors>0?n.errors:"—"})]},`${n.providerId}::${n.modelId}`))})]})})}function Zl({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:K("minimax-sub-tab",a==="quota"&&"is-active"),onClick:()=>i("quota"),children:[e.jsx(vt,{size:13})," Token Plan"]}),e.jsxs("button",{className:K("minimax-sub-tab",a==="analytics"&&"is-active"),onClick:()=>i("analytics"),children:[e.jsx(ta,{size:13})," Usage Analytics"]})]}),a==="quota"?e.jsx(Jl,{activeTab:s,setActiveTab:t}):e.jsx(eo,{toast:n})]})}function Jl({activeTab:s,setActiveTab:t}){var se;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),[j,b]=r.useState(null),[A,N]=r.useState(!1),[w,E]=r.useState(0),[M,$]=r.useState(!1),[D,f]=r.useState(null),[F,S]=r.useState(""),[y,k]=r.useState(!1),[P,v]=r.useState(!1),L=r.useCallback(async()=>{h(!0),g(null);try{const[Z,re,fe]=await Promise.all([C.get("/minimax/status"),C.get("/minimax/remains"),C.get("/minimax/onboarding")]);n(Z),c(re),p(fe),Z.configured&&E(4)}catch(Z){g(Z.message||"Failed to load MiniMax data")}finally{h(!1)}},[]);r.useEffect(()=>{L()},[L]);const B=r.useCallback(async()=>{try{await C.post("/minimax/onboarding",{dismissedAt:Date.now()}),p(Z=>Z&&{...Z,dismissedAt:Date.now()})}catch{}},[]),z=r.useCallback(async()=>{if(!F.trim()){a.error("Paste a Subscription Key first.");return}$(!0),f(null);try{const Z=await C.post("/minimax/test",{prompt:"Reply with a single word: pong",model:"MiniMax-M3",maxTokens:16});if(f(Z),Z.ok){E(3),a.success("Key works. Saving…");try{await C.post("/minimax/onboarding/save-key",{key:F.trim(),groupId:"default"}),ae(),a.success("Subscription Key saved.")}catch(re){a.error(`Save failed: ${re.message}`)}L()}else a.error(`Verification failed: ${Z.message??Z.error??"unknown"}`)}catch(Z){a.error(`Test request failed: ${Z.message}`)}finally{$(!1)}},[F,a,L]),_=r.useCallback(async()=>{if(!F.trim()){a.error("Paste a Subscription Key first.");return}v(!0);try{const Z=await C.post("/minimax/onboarding/save-key",{key:F.trim(),groupId:"default"});if(!Z.ok){a.error(`Save failed: ${Z.message??Z.error??"unknown"}`);return}S(""),ae(),a.success("Subscription Key saved. Loading quota…"),L()}catch(Z){a.error(`Save failed: ${Z.message}`)}finally{v(!1)}},[F,a,L]),ae=r.useCallback(async()=>{try{await C.del("/minimax/cache")}catch{}},[]),J=r.useCallback(async()=>{m(!0),g(null);try{await C.post("/minimax/remains/refresh"),await L(),a.success("Refreshed")}catch(Z){a.error(`Refresh failed: ${Z.message}`)}finally{m(!1)}},[L,a]),q=r.useCallback(async()=>{var Z;N(!0),b(null);try{const re=await C.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{N(!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&&w<4?e.jsx(ao,{step:w,setStep:E,keyDraft:F,setKeyDraft:S,showKey:y,setShowKey:k,verifying:M,verifyResult:D,onVerify:z,onSkip:async()=>{await B(),a.success("Skipped.")},onManualKeySave:_,savingKey:P,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(vt,{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(R,{variant:"secondary",size:"sm",onClick:()=>t("settings"),title:"Configure your Subscription Key",children:[e.jsx(bt,{size:14})," ",i.configured?`Key ${i.apiKeyHint}`:"Add key"]}),e.jsxs(R,{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(Rs,{label:"Models tracked",value:String(l.models.length),hint:"Distinct model quotas returned by the API"}),e.jsx(Rs,{label:"Last fetched",value:l.fetchedAt?to(l.fetchedAt):"—",hint:"Refreshed on demand + every 60s"}),e.jsx(Rs,{label:"Group",value:l.groupId??"—",hint:"Usually 'default' for an individual team"}),e.jsx(Rs,{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(so,{model:Z},Z.model_name))})]}),i.configured&&e.jsxs(Y,{id:"minimax-test",children:[e.jsxs(ee,{children:[e.jsx(Qe,{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(R,{onClick:q,disabled:A,variant:"primary",size:"sm",children:[A?e.jsx(je,{size:14,className:"spin"}):e.jsx(Qe,{size:14})," Send test prompt"]}),e.jsx("code",{className:"minimax-test-prompt",children:'"Reply with a single word: pong"'})]}),j&&e.jsxs("div",{className:K("minimax-test-result",j.ok?"ok":"err"),children:[j.ok?e.jsx(_e,{size:14}):e.jsx(ke,{size:14}),e.jsx("div",{className:"minimax-test-body",children:j.ok?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"minimax-test-line",children:[e.jsx("strong",{children:"model:"})," ",e.jsx("code",{children:j.model})," ·"," ",e.jsx("strong",{children:"finish:"})," ",j.finishReason??"—"]}),j.content&&e.jsx("div",{className:"minimax-test-content",children:e.jsx("code",{children:j.content})}),j.usage&&e.jsxs("div",{className:"minimax-test-usage",children:[e.jsx("strong",{children:"usage:"})," total ",e.jsx("code",{children:j.usage.total_tokens??"?"})," · prompt"," ",e.jsx("code",{children:j.usage.prompt_tokens??"?"})," · completion"," ",e.jsx("code",{children:j.usage.completion_tokens??"?"}),((se=j.usage.prompt_tokens_details)==null?void 0:se.cached_tokens)!=null&&e.jsxs(e.Fragment,{children:[" · cached ",e.jsx("code",{children:j.usage.prompt_tokens_details.cached_tokens})]})]})]}):e.jsx("pre",{children:j.message??j.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 eo({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"),[j,b]=r.useState("desc"),[A,N]=r.useState(!1),w=r.useCallback(async(y,k,P)=>{p(!0);try{const v=new URLSearchParams({range:y});y==="custom"&&k&&P&&(v.set("from",String(k)),v.set("to",String(P)));const[L,B]=await Promise.all([C.get(`/usage?${v.toString()}`),C.get("/usage/recent?limit=20")]);h(L),m(B.records)}catch(v){s.error(`Failed to load usage data: ${v.message}`)}finally{p(!1)}},[s]);r.useEffect(()=>{if(t==="custom"){const y=i?new Date(i).getTime():Date.now()-6048e5,k=l?new Date(l).getTime():Date.now();w("custom",y,k)}else w(t)},[t,w]);const E=r.useCallback(y=>{u===y?b(k=>k==="asc"?"desc":"asc"):(g(y),b("desc"))},[u]),M=r.useMemo(()=>x!=null&&x.perModel?[...x.perModel].sort((y,k)=>{const P=y[u]??0,v=k[u]??0,L=typeof P=="number"&&typeof v=="number"?P-v:String(P).localeCompare(String(v));return j==="asc"?L:-L}):[],[x==null?void 0:x.perModel,u,j]),$=r.useMemo(()=>x!=null&&x.daily?{labels:x.daily.map(y=>y.date.slice(5)),requests:x.daily.map(y=>y.requests),tokens:x.daily.map(y=>y.totalTokens)}:{labels:[],requests:[],tokens:[]},[x==null?void 0:x.daily]),D=r.useCallback(async()=>{N(!0),await w(t==="custom"?"custom":t,t==="custom"&&i?new Date(i).getTime():void 0,t==="custom"&&l?new Date(l).getTime():void 0),N(!1)},[w,t,i,l]);if(o&&!x)return e.jsxs("div",{className:"view-container",children:[e.jsx(he,{})," Loading usage data…"]});const f=x==null?void 0:x.totals,F=(x==null?void 0:x.errors)??[],S=(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(ta,{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(R,{variant:"secondary",size:"sm",onClick:D,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(y=>e.jsx("button",{className:K("usage-range-chip",t===y&&"is-active"),onClick:()=>a(y),children:y==="custom"?"Custom":y.toUpperCase()},y)),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:y=>n(y.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:y=>c(y.target.value),"aria-label":"To date"})]})]}),e.jsxs("div",{className:"usage-kpi-row",children:[e.jsx(xs,{label:"Total Requests",value:(f==null?void 0:f.requests.toLocaleString())??"—",sub:f?`${f.errors} errors`:void 0,tone:f&&f.errors>f.requests*.1?"warn":void 0}),e.jsx(xs,{label:"Total Tokens",value:f?f.totalTokens>=1e3?`${Math.round(f.totalTokens/1e3)}k`:String(f.totalTokens):"—",sub:f?`${f.promptTokens.toLocaleString()} prompt · ${f.completionTokens.toLocaleString()} completion`:void 0}),e.jsx(xs,{label:"Errors",value:String((f==null?void 0:f.errors)??"—"),sub:F.length>0?`${F[0].code}: ${F[0].count}`:void 0,tone:f&&f.errors>0?"err":void 0}),e.jsx(xs,{label:"Avg Latency",value:(f==null?void 0:f.avgLatencyMs)!=null?`${f.avgLatencyMs}ms`:"—",sub:(f==null?void 0:f.p95LatencyMs)!=null?`p95 ${f.p95LatencyMs}ms`:void 0}),e.jsx(xs,{label:"Est. Cost",value:(f==null?void 0:f.costEstimate)!=null&&f.costEstimate>0?`$${f.costEstimate.toFixed(4)}`:"—",sub:"approximate USD",tone:void 0})]}),e.jsxs(Y,{className:"usage-chart-card",children:[e.jsx("div",{className:"usage-chart-wrap",children:e.jsx(Xl,{series:$,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(Y,{children:[e.jsx(ee,{children:"Per-model breakdown"}),e.jsx(Ql,{rows:M,sortKey:u,sortDir:j,onSort:E})]}),S.length>0&&e.jsxs(Y,{children:[e.jsx(ee,{children:"API Keys"}),e.jsx("div",{className:"usage-key-row",children:S.map(y=>e.jsxs("span",{className:K("usage-key-badge",y.isBackup?"is-backup":"is-active"),children:[e.jsx("span",{className:"usage-key-dot"}),y.keyEnvVar,y.isBackup?" (backup)":" (active)"," · ",y.requests," req"]},y.keyEnvVar))})]}),d.length>0&&e.jsxs(Y,{children:[e.jsx(ee,{children:"Recent activity"}),e.jsx("div",{className:"usage-recent-list",children:d.map((y,k)=>e.jsxs("div",{className:K("usage-recent-item",y.error&&"is-err"),children:[e.jsx("span",{className:"usage-recent-time",children:new Date(y.ts).toLocaleTimeString()}),e.jsx("span",{className:"usage-recent-model",children:e.jsx("code",{children:y.modelId})}),e.jsxs("span",{className:"usage-recent-tokens",children:[y.totalTokens.toLocaleString()," tok"]}),e.jsxs("span",{className:"usage-recent-latency",children:[y.latencyMs,"ms"]}),e.jsx("span",{className:"usage-recent-endpoint",children:y.endpoint})]},`${y.requestId}-${k}`))})]})]})}function xs({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:K("usage-kpi-value",i&&`is-${i}`),children:t}),a&&e.jsx("div",{className:"usage-kpi-sub",children:a})]})}function Rs({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 so({model:s}){const t=Ls(s.current_interval_remaining_percent??0,0,100),a=Ls(s.current_weekly_remaining_percent??0,0,100),i=Ls(100-t,0,100),n=Ls(100-a,0,100);return e.jsxs(Y,{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:K("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(Vt,{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(Vt,{icon:e.jsx(Ka,{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 Vt({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 Ls(s,t,a){return Math.max(t,Math.min(a,s))}function to(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 ao({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(R,{variant:"ghost",size:"sm",onClick:x,children:[e.jsx(Ce,{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:K("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(_e,{size:14}):g+1}),e.jsx("div",{className:"minimax-wizard-step-label",children:u})]},u))}),e.jsxs(Y,{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(R,{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(os,{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(R,{variant:"secondary",size:"md",onClick:()=>t(0),children:"← Back"}),e.jsxs(R,{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(bt,{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(lt,{size:13}):e.jsx(rs,{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(R,{variant:"secondary",size:"md",onClick:()=>t(1),children:"← Back"}),e.jsxs(R,{variant:"primary",size:"md",onClick:p,disabled:c||!a.trim(),children:[c?e.jsx(je,{size:14,className:"spin"}):e.jsx(ks,{size:14}),c?"Testing…":"Test & 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(_e,{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(R,{variant:"primary",size:"md",onClick:()=>window.location.reload(),children:"View your quota →"})})]}),e.jsxs("div",{className:"minimax-wizard-footer",children:[e.jsx(ks,{size:11}),e.jsxs("span",{children:["Key written to ",e.jsx("code",{children:"~/.local/share/opencode/auth.json"})," with mode 0600."]})]})]})]})}const no=Ve.memo(Zl),io={pending:"info",running:"accent",done:"success",failed:"error",killed:"neutral",timed_out:"warning"},ro={pending:"Pending",running:"Running",done:"Done",failed:"Failed",killed:"Killed",timed_out:"Timed out"};function lo({status:s,dot:t}){const a=io[s]||"neutral",i=ro[s]||s;return e.jsx(is,{kind:a,dot:t,children:i})}function oo({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(R,{variant:"ghost",onClick:i,children:"Cancel"}),e.jsx(R,{variant:"danger",onClick:async()=>{await a(),i()},children:"Kill"})]})]})}function co(s,t,a,i,n){s.open({title:"Kill instance?",width:400,children:e.jsx(oo,{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 mo({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 C.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(Y,{variant:"outlined",className:"bg-tmux-card",children:[e.jsxs("div",{className:"bg-tmux-card-header",children:[e.jsx(ys,{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(R,{variant:"ghost",size:"sm",onClick:c,title:"Copy attach command",children:[e.jsx(Ws,{size:14})," Copy"]}),e.jsxs(R,{variant:"primary",size:"sm",onClick:o,loading:a,title:"Open in system terminal",children:[e.jsx(ys,{size:14})," Open terminal"]})]})]}):e.jsxs(Y,{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 ho=5e3,uo=2e3,xo=120;function po(s){return s.status==="pending"||s.status==="running"}function go(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 jo(s){const t=oe(),a=De(),[i,n]=r.useState([]),[l,c]=r.useState(!0),[o,p]=r.useState(null),[,x]=r.useState(0),h=r.useCallback(async()=>{try{const j=await C.get("/background");n(Array.isArray(j==null?void 0:j.instances)?j.instances:[]),p(null)}catch(j){p((j==null?void 0:j.message)||"Failed to load background agents.")}finally{c(!1)}},[]);r.useEffect(()=>{h();const j=setInterval(h,ho);return()=>clearInterval(j)},[h]),r.useEffect(()=>{const j=setInterval(()=>x(b=>(b+1)%1e6),1e3);return()=>clearInterval(j)},[]),r.useEffect(()=>{const j=new ft,b=j.on(A=>{const N=A.type;(N==="background:change"||N==="background:cleanup")&&h()});return()=>{b(),j.close()}},[h]);const d=i.filter(po),m=j=>{yo(a,j)},u=async j=>{try{const b=await C.get(`/background/${encodeURIComponent(j.instanceId)}/tmux`);bo(a,b)}catch(b){t.error(`Tmux info failed: ${b.message}`)}},g=j=>{co(a,t,j.instanceId,j.agent||j.prompt,()=>{n(b=>b.filter(A=>A.instanceId!==j.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(R,{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(R,{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(j=>e.jsx(fo,{inst:j,onViewOutput:()=>m(j),onOpenTmux:()=>u(j),onKill:()=>g(j)},j.instanceId))})]})}function fo({inst:s,onViewOutput:t,onOpenTmux:a,onKill:i}){const n=typeof s.startedAt=="number"?s.startedAt:0,l=n?cs(n):"—",c=n?Date.now()-n:0,o=Gt(s.prompt,xo);return e.jsxs(Y,{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(lo,{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:"})," ",go(c)]}),e.jsxs("span",{children:[e.jsx("strong",{children:"Tool calls:"})," ",s.toolCallCount??0]}),s.tmuxSession&&e.jsxs("span",{className:K(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(R,{variant:"secondary",size:"sm",onClick:t,children:[e.jsx(rs,{size:14})," View output"]}),e.jsxs(R,{variant:"ghost",size:"sm",onClick:a,children:[e.jsx(ys,{size:14})," Open in tmux"]}),e.jsxs(R,{variant:"danger",size:"sm",onClick:i,children:[e.jsx(Ae,{size:14})," Kill"]})]}),e.jsx(mo,{instance:s})]})}function yo(s,t){s.open({title:`Output — ${t.agent||t.instanceId}`,width:720,children:e.jsx(vo,{instanceId:t.instanceId})})}function vo({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 j=await C.get(`/background/${encodeURIComponent(s)}/output?lines=200`);i((j==null?void 0:j.output)??""),x((j==null?void 0:j.available)!==!1),o(null)}catch(j){o((j==null?void 0:j.message)||"Failed to load output.")}finally{l(!1)}},[s]);r.useEffect(()=>{m();const j=setInterval(m,uo);return()=>clearInterval(j)},[m]),r.useEffect(()=>{var j;d.current&&((j=h.current)==null||j.scrollIntoView({behavior:"auto",block:"end"}))},[a]);const u=j=>{const b=j.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(R,{variant:"ghost",size:"sm",onClick:m,title:"Refresh now",children:[e.jsx(ce,{size:14})," Refresh"]}),e.jsxs(R,{variant:"ghost",size:"sm",onClick:g,disabled:!a,children:[e.jsx(Ws,{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 bo(s,t){const a=t.attachCommand||t.session||"";s.open({title:"Attach to tmux",width:520,children:e.jsx(ko,{info:t,cmd:a})})}function ko({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(R,{variant:"secondary",size:"sm",onClick:n,children:[e.jsx(Ws,{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 it={overview:pi,chat:Ai,agents:Ei,artifacts:or,memory:Gl,tasks:yr,activity:Tr,background:jo,config:Ot,settings:Ot,mods:ll,schedules:fl,skills:Cl,history:Yl,minimax:no},No="v4.5.0";function wo(s,t,a,i){if(it[s]){const c=it[s];return e.jsx(c,{...t})}const n=a.find(c=>c.id===s);if(n)return e.jsx(cl,{viewId:n.id,reloadKey:i,activeTab:t.activeTab,setActiveTab:t.setActiveTab});const l=it.overview;return e.jsx(l,{...t})}function So({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&&(C.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(R,{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 Co(){return e.jsx(Ha,{children:e.jsx(_a,{children:e.jsx(zo,{})})})}function zo(){var Z,re,fe;const s=oe(),t=De(),{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,j]=r.useState(!1),[b,A]=r.useState(!1),[N,w]=r.useState([]),[E,M]=r.useState(!1),[$,D]=r.useState([]),[f,F]=r.useState(0),S=r.useRef(null),[y,k]=r.useState(null);r.useEffect(()=>{let V=!1;return(async()=>{try{const I=await C.get("/mods/views");if(V)return;D(I.views||[])}catch{V||D([])}})(),()=>{V=!0}},[f,c==null?void 0:c.mods]),r.useEffect(()=>{if(!y)return;const V=y.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")&&F(U=>U+1)});return()=>V()},[y]),r.useEffect(()=>{p!=null&&p.theme&&(ps(p.theme),ns(p.theme))},[p==null?void 0:p.theme]),r.useEffect(()=>{i.current=a},[a]),r.useEffect(()=>{var U;if(((U=p==null?void 0:p.theme)==null?void 0:U.mode)!=="system")return;const V=window.matchMedia("(prefers-color-scheme: light)"),I=()=>ps(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 P=r.useCallback(async()=>{let V=!1;const I=()=>Promise.all([C.get("/snapshot").catch(()=>null),C.get("/settings").catch(()=>null),C.get("/agents/stuck").catch(()=>null)]),U=(H,ne,W)=>{H&&o(H),ne!=null&&ne.data&&x(ne.data),W!=null&&W.stuck&&w(W.stuck)};try{const H=await C.probeAuthStatus(),[ne,W,O]=await I();if(U(ne,W,O),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();U(le,te,ue),!le&&!te&&u("Dashboard server unreachable.")}catch(H){const ne=(H==null?void 0:H.message)??"unknown error";if(H instanceof Wa&&H.status===401){u(ne),j(!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||P()},0);return()=>{V=!0,clearTimeout(I)}},[P]),r.useEffect(()=>{let V=!1;return C.get("/settings").then(I=>{var H,ne;if(V)return;const U=(ne=(H=I==null?void 0:I.data)==null?void 0:H.ui)==null?void 0:ne.defaultTab;U&&l(U)}).catch(()=>{}),()=>{V=!0}},[]),r.useEffect(()=>{let V=!1;const I=async()=>{try{const H=await C.get("/agents/stuck");V||w(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{}},U=setInterval(I,3e4);return I(),()=>{V=!0,clearInterval(U)}},[]),r.useEffect(()=>{const V=new ft;S.current=V,k(V);const I=V.onStatus(H=>d(H)),U=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,O=((ne=W.path)==null?void 0:ne.split("/").pop())||W.path||"";s.info(`File changed: ${O}`,2500)}else if(H.type==="tasks:change"){const W=H;o(O=>{if(!O)return O;const le=(O.tasks||[]).map(ue=>ue.id===W.task.id?W.task:ue),te=le.some(ue=>ue.id===W.task.id);return{...O,tasks:te?le:[W.task,...le]}})}else if(H.type==="tasks:delete"){const W=H;o(O=>O&&{...O,tasks:(O.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")C.get("/snapshot").then(W=>o(O=>({...O??{},...W}))).catch(()=>{});else if(H.type==="agents:change"||H.type==="schedules:change")C.get("/snapshot").then(W=>o(O=>({...O??{},...W}))).catch(()=>{});else if(H.type==="agent:status"||H.type==="agent:restarted"){const W=H;o(O=>{if(!O)return O;const le=(O.agents||[]).map(te=>te.name===W.agent.name?W.agent:te);return{...O,agents:le}})}else if(H.type==="artifact:change")C.get("/artifacts").then(W=>{o(O=>O&&{...O,artifacts:W.artifacts||[]})}).catch(()=>{});else if(H.type==="agent:stuck")w(H.agents||[]);else if(H.type==="dialog:show"){const W=H;W.dialog&&t.open({title:W.dialog.title,width:520,children:e.jsx(ti,{dialog:W.dialog,onClose:()=>t.close()})})}});return()=>{I(),U(),V.close(),k(null)}},[s]);const v=r.useCallback(V=>y?y.on(V):()=>{},[y]),L=r.useRef(0);r.useEffect(()=>{const V=()=>{L.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={};dt.forEach((U,H)=>{V[String(H+1)]=U.id});const I=U=>{var de,Ss,Cs,zs;if((U.metaKey||U.ctrlKey)&&U.key.toLowerCase()==="k"){U.preventDefault(),A(!0);return}if(U.key==="/"&&!U.metaKey&&!U.ctrlKey){const Ms=(Ss=(de=U.target)==null?void 0:de.tagName)==null?void 0:Ss.toLowerCase();if(Ms!=="input"&&Ms!=="textarea"&&!((Cs=U.target)!=null&&Cs.isContentEditable)){U.preventDefault(),A(!0);return}}const H=document.activeElement;if(!H||H===document.body||H===document.documentElement)return;const W=U.target,O=(zs=W==null?void 0:W.tagName)==null?void 0:zs.toLowerCase(),le=O==="input"||O==="textarea"||O==="select"||O==="button"||O==="option"||O==="label"||!!(W!=null&&W.isContentEditable);let te=!1;if(W&&typeof W.closest=="function"&&(te=!!W.closest('form, [role="dialog"], [contenteditable], [data-no-key]')),U.repeat||i.current||le||te||U.metaKey||U.ctrlKey||U.altKey||U.shiftKey||Date.now()<L.current)return;const ue=V[U.key];ue&&(U.preventDefault(),l(ue))};return document.addEventListener("keydown",I),()=>document.removeEventListener("keydown",I)},[]);const B=r.useMemo(()=>async()=>{try{const V=await C.get("/snapshot");o(I=>({...I??{},...V}))}catch(V){s.error(`Refresh failed: ${V.message}`)}},[s]),z=r.useMemo(()=>{const V=$.map(I=>({id:I.id,label:I.label,icon:I.kind==="iframe"?bs:ot,isMod:!0,modId:I.modId}));return[...dt,...V]},[$]),_=r.useMemo(()=>c&&p?wo(n,{snapshot:c,settings:p,activeTab:n,setActiveTab:l,refreshSnapshot:B},$,f):null,[n,c,p,$,f,B]),ae=async()=>{try{const V=await C.get("/projects");o(I=>{var U;return I&&{...I,projects:V.projects||[],activeProject:((U=V.projects)==null?void 0:U.find(H=>H.id===V.active))||null}})}catch(V){s.error(`Projects refresh failed: ${V.message}`)}},J=async V=>{try{await C.post(`/projects/${encodeURIComponent(V)}/activate`),o(I=>I&&{...I,activeProject:I.projects.find(U=>U.id===V)||null})}catch(I){s.error(`Activate failed: ${I.message}`)}},q=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 U=V.item.id;J(U)}else if(I==="command")s.info(`/${V.item.name} — run from the TUI`,2500);else if(I==="setting"){const U=V.item.id||V.item.path||"";l("settings");const H=ne=>{if(ne<=0)return;const W=U?document.querySelector(`[data-setting-id="${CSS.escape(U)}"]`):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)}},X=((re=p==null?void 0:p.ui)==null?void 0:re.layout)||"topnav",se=((fe=p==null?void 0:p.ui)==null?void 0:fe.showHeader)!==!1;return e.jsxs("div",{className:"app","data-layout":X,"data-active-tab":n,children:[e.jsx("a",{className:"skip-to-main",href:"#main-content",children:"Skip to main content"}),se&&e.jsx(Un,{activeTab:n,onTabChange:l,wsStatus:h,version:No,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(Kn,{wsSubscribe:v}),showTabs:X==="topnav",extraTabs:z}),N.length>0&&!E&&e.jsxs("div",{className:"stuck-banner",role:"alert",children:[e.jsx(ke,{size:16}),e.jsxs("span",{children:[e.jsx("strong",{children:N.length})," agent",N.length===1?"":"s"," stuck:"," ",e.jsx("span",{className:"mono",children:N.map(V=>V.name).join(", ")})]}),e.jsx(R,{variant:"secondary",size:"sm",onClick:()=>{l("agents"),M(!0)},children:"Review"}),e.jsx("button",{type:"button",className:"icon-btn","aria-label":"Dismiss",onClick:()=>M(!0),children:e.jsx(Ce,{size:14})})]}),e.jsxs("div",{className:"layout-body",children:[X!=="topnav"&&e.jsx(_n,{tabs:z,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(So,{onSaved:()=>{j(!1),P()}}),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(Mo,{children:_})})]})]}),e.jsx(Wn,{open:b,onClose:()=>A(!1),onSelect:q})]})}class Mo extends r.Component{constructor(){super(...arguments);ds(this,"state",{err:null});ds(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(R,{variant:"secondary",size:"sm",onClick:this.reset,children:"Retry"})]})]}):this.props.children}}function To(){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(Ga,{}):e.jsx(Co,{})}const ja=document.getElementById("root");if(!ja)throw new Error("Root element #root not found");Va(ja).render(e.jsx(r.StrictMode,{children:e.jsx(To,{})}));
|