@polderlabs/bizar 4.5.2 → 4.7.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/main-DGGq-iZI.js +361 -0
- package/bizar-dash/dist/assets/main-DGGq-iZI.js.map +1 -0
- package/bizar-dash/dist/assets/{mobile-lbH6szyX.js → mobile-CWqPoGaT.js} +18 -18
- package/bizar-dash/dist/assets/mobile-CWqPoGaT.js.map +1 -0
- package/bizar-dash/dist/assets/{mobile-BRhoDOUz.js → mobile-i4Uv9eW8.js} +1 -1
- package/bizar-dash/dist/assets/{mobile-BRhoDOUz.js.map → mobile-i4Uv9eW8.js.map} +1 -1
- package/bizar-dash/dist/index.html +2 -2
- package/bizar-dash/dist/mobile.html +2 -2
- package/bizar-dash/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +1 -0
- package/bizar-dash/src/server/logger.mjs +71 -0
- package/bizar-dash/src/server/memory-lightrag.mjs +45 -6
- package/bizar-dash/src/server/metrics.mjs +193 -0
- package/bizar-dash/src/server/routes/chat.mjs +6 -3
- package/bizar-dash/src/server/routes/lightrag.mjs +3 -2
- package/bizar-dash/src/server/routes/memory.mjs +5 -4
- package/bizar-dash/src/server/routes/misc.mjs +2 -1
- package/bizar-dash/src/server/routes/overview.mjs +2 -1
- package/bizar-dash/src/server/server.mjs +62 -0
- package/bizar-dash/src/web/components/SearchModal.tsx +3 -2
- package/bizar-dash/src/web/components/VirtualList.tsx +53 -0
- package/bizar-dash/src/web/components/chat/ChatThread.tsx +17 -11
- package/bizar-dash/src/web/hooks/useI18n.ts +13 -0
- package/bizar-dash/src/web/lib/i18n.ts +25 -0
- package/bizar-dash/src/web/locales/en.json +52 -0
- package/bizar-dash/src/web/main.tsx +5 -0
- package/bizar-dash/src/web/views/Activity.tsx +24 -17
- package/bizar-dash/src/web/views/History.tsx +90 -75
- package/bizar-dash/src/web/views/Overview.tsx +11 -8
- package/bizar-dash/src/web/views/Settings.tsx +7 -1
- package/bizar-dash/tests/cli-bugfixes.test.mjs +4 -4
- package/bizar-dash/tests/cli-refactor.test.mjs +184 -0
- package/bizar-dash/tests/components/Button.test.tsx +41 -0
- package/bizar-dash/tests/components/Card.test.tsx +42 -0
- package/bizar-dash/tests/components/Modal.test.tsx +104 -0
- package/bizar-dash/tests/components/Spinner.test.tsx +32 -0
- package/bizar-dash/tests/components/StatusBadge.test.tsx +35 -0
- package/bizar-dash/tests/components/Toast.test.tsx +108 -0
- package/bizar-dash/tests/hooks/useModal.test.tsx +84 -0
- package/bizar-dash/tests/hooks/useToast.test.tsx +50 -0
- package/bizar-dash/tests/lib/i18n.test.ts +46 -0
- package/bizar-dash/tests/lib/utils.test.ts +194 -0
- package/bizar-dash/tests/logger.test.mjs +207 -0
- package/bizar-dash/tests/metrics.test.mjs +183 -0
- package/bizar-dash/tests/server-bugfixes.test.mjs +2 -2
- package/bizar-dash/tests/setup.ts +7 -0
- package/bizar-dash/vitest.config.ts +13 -0
- package/cli/artifact-cli.mjs +605 -0
- package/cli/artifact-render.mjs +621 -0
- package/cli/artifact-server.mjs +847 -0
- package/cli/artifact.mjs +38 -2096
- package/cli/bg.mjs +5 -13
- package/cli/bin.mjs +149 -1361
- package/cli/commands/artifact.mjs +20 -0
- package/cli/commands/dash.mjs +160 -0
- package/cli/commands/headroom.mjs +204 -0
- package/cli/commands/install.mjs +169 -0
- package/cli/commands/memory.mjs +25 -0
- package/cli/commands/minimax.mjs +265 -0
- package/cli/commands/mod.mjs +185 -0
- package/cli/commands/service.mjs +65 -0
- package/cli/commands/usage.mjs +109 -0
- package/cli/commands/util.mjs +306 -0
- package/cli/doctor.mjs +1 -13
- package/cli/provision.mjs +2 -13
- package/cli/service-controller.mjs +1 -11
- package/cli/service.mjs +1 -11
- package/cli/utils.mjs +41 -1
- package/package.json +6 -1
- package/bizar-dash/dist/assets/main-B4OfGAwz.js +0 -361
- package/bizar-dash/dist/assets/main-B4OfGAwz.js.map +0 -1
- package/bizar-dash/dist/assets/mobile-lbH6szyX.js.map +0 -1
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
var pa=Object.defineProperty;var ga=(s,t,a)=>t in s?pa(s,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):s[t]=a;var cs=(s,t,a)=>ga(s,typeof t!="symbol"?t+"":t,a);import{c as X,r,a as S,j as e,R as oe,C as ct,F as Ee,b as Oe,d as He,M as qs,B as qe,S as gs,A as Te,e as Fe,f as Ps,H as js,g as dt,h as ye,i as Z,u as De,P as Me,k as T,l as ce,X as $e,m as ja,T as ke,n as _e,I as _s,o as Ne,E as ls,p as Se,q as os,s as We,t as he,v as Qe,V as mt,w as Re,x as ht,y as fa,z as va,D as ya,G as xs,J as fs,K as ks,L as ba,N as ka,O as Na,Q as wa,U as vs,W as Ut,Y as Ns,Z as ut,_ as Sa,$ as qt,a0 as _t,a1 as Ca,a2 as za,a3 as Ta,a4 as Ma,a5 as Ht,a6 as as,a7 as St,a8 as $a,a9 as Ra,aa as Aa,ab as Hs,ac as ps,ad as xt,ae as Ia,af as La,ag as Ea,ah as Wt,ai as Da,aj as Pa,ak as Oa,al as Fa,am as Ba,an as Ua}from"./mobile-CWqPoGaT.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 Vt=X("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 Kt=X("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 Gt=X("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 pt=X("ArrowUp",[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]]);/**
|
|
22
|
+
* @license lucide-react v0.460.0 - ISC
|
|
23
|
+
*
|
|
24
|
+
* This source code is licensed under the ISC license.
|
|
25
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
26
|
+
*/const Le=X("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 qa=X("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 Yt=X("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 tt=X("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 _a=X("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=X("CircleCheckBig",[["path",{d:"M21.801 10A10 10 0 1 1 17 3.335",key:"yps3ct"}],["path",{d:"m9 11 3 3L22 4",key:"1pflzl"}]]);/**
|
|
52
|
+
* @license lucide-react v0.460.0 - ISC
|
|
53
|
+
*
|
|
54
|
+
* This source code is licensed under the ISC license.
|
|
55
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
56
|
+
*/const Ha=X("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 Wa=X("CirclePlay",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["polygon",{points:"10 8 16 12 10 16 10 8",key:"1cimsy"}]]);/**
|
|
62
|
+
* @license lucide-react v0.460.0 - ISC
|
|
63
|
+
*
|
|
64
|
+
* This source code is licensed under the ISC license.
|
|
65
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
66
|
+
*/const Ye=X("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 Va=X("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 gt=X("Coins",[["circle",{cx:"8",cy:"8",r:"6",key:"3yglwk"}],["path",{d:"M18.09 10.37A6 6 0 1 1 10.34 18",key:"t5s6rm"}],["path",{d:"M7 6h1v4",key:"1obek4"}],["path",{d:"m16.71 13.88.7.71-2.82 2.82",key:"1rbuyh"}]]);/**
|
|
77
|
+
* @license lucide-react v0.460.0 - ISC
|
|
78
|
+
*
|
|
79
|
+
* This source code is licensed under the ISC license.
|
|
80
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
81
|
+
*/const Vs=X("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 Qt=X("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 Ka=X("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 Xe=X("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 Ga=X("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 at=X("EyeOff",[["path",{d:"M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49",key:"ct8e1f"}],["path",{d:"M14.084 14.158a3 3 0 0 1-4.242-4.242",key:"151rxh"}],["path",{d:"M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143",key:"13bj9a"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]]);/**
|
|
107
|
+
* @license lucide-react v0.460.0 - ISC
|
|
108
|
+
*
|
|
109
|
+
* This source code is licensed under the ISC license.
|
|
110
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
111
|
+
*/const is=X("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 Ya=X("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 Qa=X("FileCode",[["path",{d:"M10 12.5 8 15l2 2.5",key:"1tg20x"}],["path",{d:"m14 12.5 2 2.5-2 2.5",key:"yinavb"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7z",key:"1mlx9k"}]]);/**
|
|
122
|
+
* @license lucide-react v0.460.0 - ISC
|
|
123
|
+
*
|
|
124
|
+
* This source code is licensed under the ISC license.
|
|
125
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
126
|
+
*/const Xa=X("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 Za=X("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 Ja=X("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 en=X("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 sn=X("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 tn=X("FolderSearch",[["path",{d:"M10.7 20H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H20a2 2 0 0 1 2 2v4.1",key:"1bw5m7"}],["path",{d:"m21 21-1.9-1.9",key:"1g2n9r"}],["circle",{cx:"17",cy:"17",r:"3",key:"18b49y"}]]);/**
|
|
152
|
+
* @license lucide-react v0.460.0 - ISC
|
|
153
|
+
*
|
|
154
|
+
* This source code is licensed under the ISC license.
|
|
155
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
156
|
+
*/const rs=X("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 an=X("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 nn=X("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 rn=X("GitPullRequest",[["circle",{cx:"18",cy:"18",r:"3",key:"1xkwt0"}],["circle",{cx:"6",cy:"6",r:"3",key:"1lh9wr"}],["path",{d:"M13 6h3a2 2 0 0 1 2 2v7",key:"1yeb86"}],["line",{x1:"6",x2:"6",y1:"9",y2:"21",key:"rroup"}]]);/**
|
|
172
|
+
* @license lucide-react v0.460.0 - ISC
|
|
173
|
+
*
|
|
174
|
+
* This source code is licensed under the ISC license.
|
|
175
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
176
|
+
*/const ys=X("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 ln=X("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=X("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 jt=X("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 on=X("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 Xt=X("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 nt=X("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 fe=X("LoaderCircle",[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]]);/**
|
|
212
|
+
* @license lucide-react v0.460.0 - ISC
|
|
213
|
+
*
|
|
214
|
+
* This source code is licensed under the ISC license.
|
|
215
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
216
|
+
*/const Ct=X("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 Fs=X("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 cn=X("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 dn=X("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 mn=X("OctagonAlert",[["path",{d:"M12 16h.01",key:"1drbdi"}],["path",{d:"M12 8v4",key:"1got3b"}],["path",{d:"M15.312 2a2 2 0 0 1 1.414.586l4.688 4.688A2 2 0 0 1 22 8.688v6.624a2 2 0 0 1-.586 1.414l-4.688 4.688a2 2 0 0 1-1.414.586H8.688a2 2 0 0 1-1.414-.586l-4.688-4.688A2 2 0 0 1 2 15.312V8.688a2 2 0 0 1 .586-1.414l4.688-4.688A2 2 0 0 1 8.688 2z",key:"1fd625"}]]);/**
|
|
237
|
+
* @license lucide-react v0.460.0 - ISC
|
|
238
|
+
*
|
|
239
|
+
* This source code is licensed under the ISC license.
|
|
240
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
241
|
+
*/const ft=X("Package",[["path",{d:"M11 21.73a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73z",key:"1a0edw"}],["path",{d:"M12 22V12",key:"d0xqtd"}],["path",{d:"m3.3 7 7.703 4.734a2 2 0 0 0 1.994 0L20.7 7",key:"yx3hmr"}],["path",{d:"m7.5 4.27 9 5.15",key:"1c824w"}]]);/**
|
|
242
|
+
* @license lucide-react v0.460.0 - ISC
|
|
243
|
+
*
|
|
244
|
+
* This source code is licensed under the ISC license.
|
|
245
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
246
|
+
*/const hn=X("Palette",[["circle",{cx:"13.5",cy:"6.5",r:".5",fill:"currentColor",key:"1okk4w"}],["circle",{cx:"17.5",cy:"10.5",r:".5",fill:"currentColor",key:"f64h9f"}],["circle",{cx:"8.5",cy:"7.5",r:".5",fill:"currentColor",key:"fotxhn"}],["circle",{cx:"6.5",cy:"12.5",r:".5",fill:"currentColor",key:"qy21gx"}],["path",{d:"M12 2C6.5 2 2 6.5 2 12s4.5 10 10 10c.926 0 1.648-.746 1.648-1.688 0-.437-.18-.835-.437-1.125-.29-.289-.438-.652-.438-1.125a1.64 1.64 0 0 1 1.668-1.668h1.996c3.051 0 5.555-2.503 5.555-5.554C21.965 6.012 17.461 2 12 2z",key:"12rzf8"}]]);/**
|
|
247
|
+
* @license lucide-react v0.460.0 - ISC
|
|
248
|
+
*
|
|
249
|
+
* This source code is licensed under the ISC license.
|
|
250
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
251
|
+
*/const un=X("PanelLeftClose",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}],["path",{d:"m16 15-3-3 3-3",key:"14y99z"}]]);/**
|
|
252
|
+
* @license lucide-react v0.460.0 - ISC
|
|
253
|
+
*
|
|
254
|
+
* This source code is licensed under the ISC license.
|
|
255
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
256
|
+
*/const xn=X("PanelLeftOpen",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}],["path",{d:"m14 9 3 3-3 3",key:"8010ee"}]]);/**
|
|
257
|
+
* @license lucide-react v0.460.0 - ISC
|
|
258
|
+
*
|
|
259
|
+
* This source code is licensed under the ISC license.
|
|
260
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
261
|
+
*/const pn=X("PanelsTopLeft",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M3 9h18",key:"1pudct"}],["path",{d:"M9 21V9",key:"1oto5p"}]]);/**
|
|
262
|
+
* @license lucide-react v0.460.0 - ISC
|
|
263
|
+
*
|
|
264
|
+
* This source code is licensed under the ISC license.
|
|
265
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
266
|
+
*/const gn=X("Pen",[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}]]);/**
|
|
267
|
+
* @license lucide-react v0.460.0 - ISC
|
|
268
|
+
*
|
|
269
|
+
* This source code is licensed under the ISC license.
|
|
270
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
271
|
+
*/const it=X("Plug",[["path",{d:"M12 22v-5",key:"1ega77"}],["path",{d:"M9 8V2",key:"14iosj"}],["path",{d:"M15 8V2",key:"18g5xt"}],["path",{d:"M18 8v5a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V8Z",key:"osxo6l"}]]);/**
|
|
272
|
+
* @license lucide-react v0.460.0 - ISC
|
|
273
|
+
*
|
|
274
|
+
* This source code is licensed under the ISC license.
|
|
275
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
276
|
+
*/const jn=X("PowerOff",[["path",{d:"M18.36 6.64A9 9 0 0 1 20.77 15",key:"dxknvb"}],["path",{d:"M6.16 6.16a9 9 0 1 0 12.68 12.68",key:"1x7qb5"}],["path",{d:"M12 2v4",key:"3427ic"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]]);/**
|
|
277
|
+
* @license lucide-react v0.460.0 - ISC
|
|
278
|
+
*
|
|
279
|
+
* This source code is licensed under the ISC license.
|
|
280
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
281
|
+
*/const Bs=X("Puzzle",[["path",{d:"M15.39 4.39a1 1 0 0 0 1.68-.474 2.5 2.5 0 1 1 3.014 3.015 1 1 0 0 0-.474 1.68l1.683 1.682a2.414 2.414 0 0 1 0 3.414L19.61 15.39a1 1 0 0 1-1.68-.474 2.5 2.5 0 1 0-3.014 3.015 1 1 0 0 1 .474 1.68l-1.683 1.682a2.414 2.414 0 0 1-3.414 0L8.61 19.61a1 1 0 0 0-1.68.474 2.5 2.5 0 1 1-3.014-3.015 1 1 0 0 0 .474-1.68l-1.683-1.682a2.414 2.414 0 0 1 0-3.414L4.39 8.61a1 1 0 0 1 1.68.474 2.5 2.5 0 1 0 3.014-3.015 1 1 0 0 1-.474-1.68l1.683-1.682a2.414 2.414 0 0 1 3.414 0z",key:"w46dr5"}]]);/**
|
|
282
|
+
* @license lucide-react v0.460.0 - ISC
|
|
283
|
+
*
|
|
284
|
+
* This source code is licensed under the ISC license.
|
|
285
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
286
|
+
*/const fn=X("Radio",[["path",{d:"M4.9 19.1C1 15.2 1 8.8 4.9 4.9",key:"1vaf9d"}],["path",{d:"M7.8 16.2c-2.3-2.3-2.3-6.1 0-8.5",key:"u1ii0m"}],["circle",{cx:"12",cy:"12",r:"2",key:"1c9p78"}],["path",{d:"M16.2 7.8c2.3 2.3 2.3 6.1 0 8.5",key:"1j5fej"}],["path",{d:"M19.1 4.9C23 8.8 23 15.1 19.1 19",key:"10b0cb"}]]);/**
|
|
287
|
+
* @license lucide-react v0.460.0 - ISC
|
|
288
|
+
*
|
|
289
|
+
* This source code is licensed under the ISC license.
|
|
290
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
291
|
+
*/const vn=X("Redo2",[["path",{d:"m15 14 5-5-5-5",key:"12vg1m"}],["path",{d:"M20 9H9.5A5.5 5.5 0 0 0 4 14.5A5.5 5.5 0 0 0 9.5 20H13",key:"6uklza"}]]);/**
|
|
292
|
+
* @license lucide-react v0.460.0 - ISC
|
|
293
|
+
*
|
|
294
|
+
* This source code is licensed under the ISC license.
|
|
295
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
296
|
+
*/const yn=X("Share2",[["circle",{cx:"18",cy:"5",r:"3",key:"gq8acd"}],["circle",{cx:"6",cy:"12",r:"3",key:"w7nqdw"}],["circle",{cx:"18",cy:"19",r:"3",key:"1xt0gg"}],["line",{x1:"8.59",x2:"15.42",y1:"13.51",y2:"17.49",key:"47mynk"}],["line",{x1:"15.41",x2:"8.59",y1:"6.51",y2:"10.49",key:"1n3mei"}]]);/**
|
|
297
|
+
* @license lucide-react v0.460.0 - ISC
|
|
298
|
+
*
|
|
299
|
+
* This source code is licensed under the ISC license.
|
|
300
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
301
|
+
*/const bs=X("ShieldCheck",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);/**
|
|
302
|
+
* @license lucide-react v0.460.0 - ISC
|
|
303
|
+
*
|
|
304
|
+
* This source code is licensed under the ISC license.
|
|
305
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
306
|
+
*/const bn=X("Shield",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}]]);/**
|
|
307
|
+
* @license lucide-react v0.460.0 - ISC
|
|
308
|
+
*
|
|
309
|
+
* This source code is licensed under the ISC license.
|
|
310
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
311
|
+
*/const kn=X("SquarePen",[["path",{d:"M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7",key:"1m0v6g"}],["path",{d:"M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z",key:"ohrbg2"}]]);/**
|
|
312
|
+
* @license lucide-react v0.460.0 - ISC
|
|
313
|
+
*
|
|
314
|
+
* This source code is licensed under the ISC license.
|
|
315
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
316
|
+
*/const Nn=X("Square",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]]);/**
|
|
317
|
+
* @license lucide-react v0.460.0 - ISC
|
|
318
|
+
*
|
|
319
|
+
* This source code is licensed under the ISC license.
|
|
320
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
321
|
+
*/const Zt=X("Tag",[["path",{d:"M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z",key:"vktsd0"}],["circle",{cx:"7.5",cy:"7.5",r:".5",fill:"currentColor",key:"kqv944"}]]);/**
|
|
322
|
+
* @license lucide-react v0.460.0 - ISC
|
|
323
|
+
*
|
|
324
|
+
* This source code is licensed under the ISC license.
|
|
325
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
326
|
+
*/const wn=X("Target",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["circle",{cx:"12",cy:"12",r:"6",key:"1vlfrh"}],["circle",{cx:"12",cy:"12",r:"2",key:"1c9p78"}]]);/**
|
|
327
|
+
* @license lucide-react v0.460.0 - ISC
|
|
328
|
+
*
|
|
329
|
+
* This source code is licensed under the ISC license.
|
|
330
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
331
|
+
*/const Sn=X("Undo2",[["path",{d:"M9 14 4 9l5-5",key:"102s5s"}],["path",{d:"M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11",key:"f3b9sd"}]]);/**
|
|
332
|
+
* @license lucide-react v0.460.0 - ISC
|
|
333
|
+
*
|
|
334
|
+
* This source code is licensed under the ISC license.
|
|
335
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
336
|
+
*/const Cn=X("User",[["path",{d:"M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2",key:"975kel"}],["circle",{cx:"12",cy:"7",r:"4",key:"17ys0d"}]]);/**
|
|
337
|
+
* @license lucide-react v0.460.0 - ISC
|
|
338
|
+
*
|
|
339
|
+
* This source code is licensed under the ISC license.
|
|
340
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
341
|
+
*/const Jt=X("Users",[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["path",{d:"M22 21v-2a4 4 0 0 0-3-3.87",key:"kshegd"}],["path",{d:"M16 3.13a4 4 0 0 1 0 7.75",key:"1da9ce"}]]);/**
|
|
342
|
+
* @license lucide-react v0.460.0 - ISC
|
|
343
|
+
*
|
|
344
|
+
* This source code is licensed under the ISC license.
|
|
345
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
346
|
+
*/const vt=X("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"}]]),zn=200,Tn=5*60*1e3,Ge=new Map;function Mn(s){const t=Ge.get(s);return t?Date.now()-t.ts>Tn?(Ge.delete(s),null):t.data:null}function Ks(s,t){Ge.size>=zn&&[...Ge.entries()].sort((i,n)=>i[1].ts-n[1].ts).slice(0,50).map(([i])=>i).forEach(i=>Ge.delete(i)),Ge.set(s,{data:t,ts:Date.now()})}function $n(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 Rn(s){return[...s].sort((t,a)=>t.isDir!==a.isDir?t.isDir?-1:1:t.name.localeCompare(a.name,void 0,{sensitivity:"base"}))}function An(s){const t=s.trim();return t?t!==s?{ok:!1,reason:"Name cannot have leading or trailing whitespace."}:t==="."?{ok:!1,reason:"Name cannot be '.'."}:t===".."?{ok:!1,reason:"Name cannot be '..'."}:t.startsWith("-")?{ok:!1,reason:"Name cannot start with '-'."}:t.length>255?{ok:!1,reason:"Name cannot be longer than 255 characters."}:/[/\0:*?"<>|]/.test(t)?{ok:!1,reason:'Name cannot contain / \\ : * ? " < > |'}:{ok:!0}:{ok:!1,reason:"Name cannot be empty."}}function ea({value:s,onChange:t,initialPath:a,projectsDirectory:i,rootLabel:n="Home",height:l=360}){const[o,c]=r.useState(a??i??""),[g,m]=r.useState(new Set),[x,h]=r.useState(-1),[d,u]=r.useState(null),[j,f]=r.useState({}),[y,$]=r.useState(!1),[b,k]=r.useState(null),[P,N]=r.useState(!1),[I,F]=r.useState(""),[w,E]=r.useState(null),[A,z]=r.useState(!1),R=r.useRef(null),B=r.useCallback(async D=>{try{const le=Mn(D);if(le)return le;const ae=await S.get("/fs?path="+encodeURIComponent(D));return Ks(D,ae),ae}catch{return null}},[]),v=r.useCallback(async D=>{var le;$(!0),k(null);try{const ae=await S.get("/fs?path="+encodeURIComponent(D));Ks(D,ae),u(ae),h(-1)}catch(ae){const ue=((le=ae.data)==null?void 0:le.message)??ae.message??"Failed to load directory";k(ue)}finally{$(!1)}},[]);r.useEffect(()=>{o?v(o):S.get("/fs").then(D=>{Ks("",D),u(D),c(D.path),D.path!==s&&t(D.path)}).catch(()=>{k("Could not determine home directory."),$(!1)})},[o]),r.useEffect(()=>{s&&s!==o&&c(s)},[s]);const O=d?Rn(d.entries):[],K=O.filter(D=>D.isDir),M=O,W=D=>{D.isDir&&(c(D.path),t(D.path))},te=()=>{d!=null&&d.parent&&(c(d.parent),t(d.parent))},ee=D=>{D!==o&&(c(D),t(D))},_=async()=>{const D=await B("");D&&(c(D.path),t(D.path))},Y=async()=>{if(!i)return;const D=await B(i);D&&(c(D.path),t(D.path))},se=()=>{N(!0),F(""),E(null),setTimeout(()=>{var D;return(D=R.current)==null?void 0:D.focus()},0)},Q=()=>{N(!1),F(""),E(null)},ie=async()=>{var le;const D=An(I);if(!D.ok){E(D.reason);return}z(!0),E(null);try{const ae=await S.post("/fs/mkdir",{parent:o,name:I.trim()});Ge.delete(o),await v(o),t(ae.path),N(!1),F("")}catch(ae){const ue=ae;ue.status===409?E(`A folder named "${I.trim()}" already exists.`):E(((le=ue.data)==null?void 0:le.message)??ae.message??"Failed to create folder.")}finally{z(!1)}},xe=D=>{D.key==="Enter"?(D.preventDefault(),ie()):D.key==="Escape"&&(D.preventDefault(),Q())},V=D=>{m(le=>{const ae=new Set(le);return ae.has(D)?ae.delete(D):ae.add(D),ae}),j[D]||B(D).then(le=>{le&&f(ae=>({...ae,[D]:le.entries.filter(ue=>ue.isDir)}))})},L=D=>{if(!d)return;const le=M.filter(de=>de.isDir),ae=M.filter(de=>!de.isDir),ue=[...le,...ae];if(D.key==="ArrowDown")D.preventDefault(),h(de=>Math.min(de+1,ue.length-1));else if(D.key==="ArrowUp")D.preventDefault(),h(de=>Math.max(de-1,0));else if(D.key==="Enter"||D.key===" "){D.preventDefault();const de=ue[x];de&&(D.key==="Enter"&&de.isDir?W(de):de.isDir&&t(de.path))}else D.key==="Backspace"&&(D.preventDefault(),te())},U=$n((d==null?void 0:d.path)??o??"/"),p=d==null?void 0:d.parent,q=p!=null,H=o.split("/").filter(Boolean).at(-1)??"/";return e.jsxs("div",{className:"file-browser",onKeyDown:L,tabIndex:-1,children:[e.jsx("div",{className:"file-browser-breadcrumb",role:"navigation","aria-label":"Path breadcrumb",children:U.map((D,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:()=>ee(D.path),title:D.path,children:le===0?D.path==="/"?"/":n:D.label})]},D.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:te,disabled:!q,title:"Go up (Backspace)","aria-label":"Go up one level",children:e.jsx(Gt,{size:13})}),e.jsx("button",{type:"button",className:"file-browser-tool-btn",onClick:()=>v(o),disabled:y,title:"Refresh","aria-label":"Refresh",children:e.jsx(oe,{size:13,className:y?"spin":""})}),e.jsx("button",{type:"button",className:"file-browser-tool-btn",onClick:se,title:"New folder","aria-label":"Create new folder",children:e.jsx(sn,{size:13})}),e.jsxs("div",{className:"file-browser-chips",children:[e.jsxs("button",{type:"button",className:"file-browser-chip",onClick:_,children:[e.jsx(ln,{size:11})," ",n]}),i&&e.jsxs("button",{type:"button",className:"file-browser-chip",onClick:Y,title:i,children:[e.jsx(en,{size:11})," ",i.split("/").filter(Boolean).at(-1)??"Projects"]})]})]}),P?e.jsxs("div",{className:"file-browser-mkdir",children:[e.jsx("input",{ref:R,type:"text",className:"file-browser-mkdir-input",placeholder:"Folder name",value:I,onChange:D=>{F(D.target.value),E(null)},onKeyDown:xe,"aria-label":"New folder name","aria-invalid":w?"true":void 0,"aria-describedby":w?"mkdir-error":void 0,disabled:A,maxLength:255}),w?e.jsx("span",{id:"mkdir-error",className:"file-browser-mkdir-error",role:"alert",children:w}):e.jsx("span",{className:"file-browser-mkdir-hint",children:"Enter to create, Esc to cancel"})]}):e.jsx("span",{className:"file-browser-count-hint",children:y?"…":`${O.length} in ${H}`})]}),b&&e.jsxs("div",{className:"file-browser-error",children:[e.jsx(ct,{size:13}),e.jsx("span",{children:b}),e.jsx("button",{type:"button",className:"file-browser-retry",onClick:()=>v(o),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:y&&!d?e.jsx(In,{}):e.jsx(sa,{path:o,entries:K,expanded:g,childrenMap:j,onToggle:V,onNavigate:W,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"})]}),y&&!d?e.jsx(Ln,{}):e.jsxs(e.Fragment,{children:[(d==null?void 0:d.truncated)&&e.jsxs("div",{className:"file-browser-truncated-banner",role:"status",children:["Showing first 500 of ",d.totalEntries," entries. Navigate into a subfolder to see more."]}),M.length===0?e.jsx("div",{className:"file-browser-empty",children:"This folder is empty"}):e.jsx("div",{className:"file-browser-flat-list",children:M.map((D,le)=>{const ae=D.isDir,ue=le===x,de=D.path===s;return e.jsxs("div",{role:"option","aria-selected":de,className:["file-browser-row",ae?"file-browser-row--dir":"file-browser-row--file",ue&&"file-browser-row--selected",de&&ae&&"file-browser-row--active",!ae&&"file-browser-row--disabled"].filter(Boolean).join(" "),onClick:()=>{ae&&(h(le),t(D.path))},onDoubleClick:()=>{ae&&W(D)},title:D.path,children:[e.jsx("span",{className:"file-browser-row-icon",children:ae?e.jsx(Ee,{size:13}):e.jsx(Za,{size:13})}),e.jsx("span",{className:"file-browser-row-name",children:D.name}),e.jsx("span",{className:"file-browser-row-type",children:ae?"Folder":""})]},D.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 sa({path:s,entries:t,expanded:a,childrenMap:i,onToggle:n,onNavigate:l,level:o}){return e.jsx("ul",{className:"file-browser-tree-list",role:"group",children:t.map(c=>{const g=a.has(c.path),m=i[c.path]??[];return e.jsxs("li",{className:"file-browser-tree-node",children:[e.jsxs("div",{className:["file-browser-tree-row",g&&"file-browser-tree-row--expanded"].filter(Boolean).join(" "),style:{paddingLeft:`${o*16+8}px`},children:[e.jsx("button",{type:"button",className:"file-browser-tree-toggle",onClick:x=>{x.stopPropagation(),n(c.path)},"aria-label":g?"Collapse":"Expand",children:(m.length>0,g?e.jsx(Oe,{size:11}):e.jsx(He,{size:11}))}),e.jsxs("button",{type:"button",className:"file-browser-tree-name",onClick:()=>l(c),title:c.path,children:[e.jsx(Ee,{size:12}),e.jsx("span",{children:c.name})]})]}),g&&m.length>0&&e.jsx(sa,{path:c.path,entries:m,expanded:a,childrenMap:i,onToggle:n,onNavigate:l,level:o+1})]},c.path)})})}function In(){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 Ln(){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 rt=[{id:"overview",label:"Overview",icon:Xt},{id:"chat",label:"Chat",icon:qs},{id:"agents",label:"Agents",icon:qe},{id:"artifacts",label:"Glyphs",icon:Fs},{id:"tasks",label:"Tasks",icon:gs},{id:"activity",label:"Activity",icon:Te},{id:"background",label:"Active",icon:fn},{id:"skills",label:"Skills",icon:Fe},{id:"memory",label:"Memory",icon:Le},{id:"mods",label:"Mods",icon:Bs},{id:"schedules",label:"Schedules",icon:Ps},{id:"history",label:"History",icon:js},{id:"minimax",label:"Usage",icon:gt},{id:"settings",label:"Settings",icon:dt}];function En({activeTab:s,onTabChange:t,wsStatus:a,version:i,activeProject:n,projects:l,onProjectChange:o,onProjectsRefresh:c,onOpenSearch:g,settings:m,rightSlot:x,notificationsSlot:h,showTabs:d=!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(Dn,{activeProject:n,projects:l,onChange:o,onRefresh:c,settings:m??null}),e.jsxs("button",{type:"button",className:"topbar-search",onClick:g,title:"Search (Ctrl/Cmd+K)","aria-label":"Open search",children:[e.jsx(ye,{size:14}),e.jsx("span",{className:"muted",children:"Search…"}),e.jsx("kbd",{children:"⌘K"})]}),e.jsx("div",{className:"topbar-spacer"}),e.jsxs("div",{className:"topbar-right",children:[h,x,e.jsxs("div",{className:Z("ws-status",`ws-${a}`),title:`WebSocket: ${a}`,children:[e.jsx("span",{className:"ws-dot"}),e.jsx("span",{className:"ws-label",children:a})]})]})]}),d&&e.jsxs("nav",{className:"tabs-row",role:"tablist","aria-label":"Primary tabs",children:[rt.map(j=>{const f=j.icon,y=j.id===s;return e.jsxs("button",{type:"button",role:"tab","aria-selected":y,className:Z("tab",y&&"tab-active"),onClick:()=>t(j.id),title:j.label,children:[e.jsx(f,{size:14,className:"tab-icon"}),e.jsx("span",{className:"tab-label",children:j.label})]},j.id)}),u&&u.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"tab-separator","aria-hidden":"true"}),u.map(j=>{const f=j.icon,y=j.id===s;return e.jsxs("button",{type:"button",role:"tab","aria-selected":y,className:Z("tab","tab-mod",y&&"tab-active"),onClick:()=>t(j.id),title:`${j.label} (mod)`,children:[e.jsx(f,{size:14,className:"tab-icon"}),e.jsx("span",{className:"tab-label",children:j.label}),e.jsx("span",{className:"tab-badge",children:"mod"})]},j.id)})]})]})]})}function Dn({activeProject:s,projects:t,onChange:a,onRefresh:i,settings:n}){const[l,o]=r.useState(!1),c=De();r.useEffect(()=>{if(!l)return;const m=()=>o(!1);return document.addEventListener("click",m),()=>document.removeEventListener("click",m)},[l]);const g=()=>{c.open({title:"Add project",children:e.jsx(Pn,{settings:n,onAdd:async(m,x)=>{try{await S.post("/projects",{path:m,name:x}),i(),o(!1),c.close()}catch(h){alert(`Add failed: ${h.message}`)}}}),footer:e.jsx("div",{className:"modal-footer-actions",children:e.jsx(T,{variant:"ghost",onClick:()=>c.close(),children:"Cancel"})})})};return e.jsxs("div",{className:"project-selector",onClick:m=>m.stopPropagation(),children:[e.jsxs("button",{type:"button",className:"project-selector-btn",onClick:()=>o(m=>!m),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(Oe,{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(oe,{size:12})}),e.jsx("button",{type:"button",className:"icon-btn",onClick:g,title:"Add project","aria-label":"Add project",children:e.jsx(Me,{size:12})})]})]}),e.jsxs("ul",{className:"project-selector-list",children:[t.length===0&&e.jsx("li",{className:"muted project-selector-empty",children:"No projects. Add one to start."}),t.map(m=>e.jsx("li",{children:e.jsxs("button",{type:"button",className:Z("project-selector-item",(s==null?void 0:s.id)===m.id&&"active"),onClick:()=>{a(m.id),o(!1)},children:[e.jsx("span",{className:"project-selector-item-name",children:m.name}),e.jsx("span",{className:"project-selector-item-status",children:m.status})]})},m.id))]})]})]})}function Pn({settings:s,onAdd:t}){var h,d;const[a,i]=r.useState(((h=s==null?void 0:s.dashboard)==null?void 0:h.projectsDirectory)??""),[n,l]=r.useState(""),[o,c]=r.useState(!1),[g,m]=r.useState(null),x=async()=>{var u;if(a){c(!0),m(null);try{await S.get("/fs?path="+encodeURIComponent(a)),t(a,n||null)}catch(j){const f=j;f.status===404?m("That folder no longer exists. Pick another."):m(((u=f.data)==null?void 0:u.message)??j.message??"Validation failed.")}finally{c(!1)}}};return e.jsxs("div",{children:[e.jsx("label",{className:"field-label",children:"Folder"}),e.jsx(ea,{value:a,onChange:u=>{i(u),m(null)},projectsDirectory:(d=s==null?void 0:s.dashboard)==null?void 0:d.projectsDirectory,height:320}),g&&e.jsx("p",{className:"field-help",style:{color:"var(--error)",marginTop:4},children:g}),e.jsxs("div",{style:{marginTop:"var(--space-3)"},children:[e.jsx("label",{className:"field-label",htmlFor:"topbar-add-project-name",children:"Name (optional)"}),e.jsx("input",{id:"topbar-add-project-name",className:"input",type:"text",placeholder:"My App",value:n,onChange:u=>l(u.target.value)})]}),e.jsx("div",{style:{marginTop:"var(--space-3)",display:"flex",justifyContent:"flex-end"},children:e.jsxs(T,{variant:"primary",onClick:x,disabled:!a||o,children:[o?e.jsx("span",{className:"btn-spinner"}):null,o?"Checking…":"Add"]})})]})}function On({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 o=l.icon,c=l.id===t;return e.jsxs("button",{type:"button",role:"tab","aria-selected":c,className:Z("sidebar-tab",c&&"sidebar-tab-active"),onClick:()=>a(l.id),title:l.label,children:[e.jsx(o,{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 o=l.icon,c=l.id===t;return e.jsxs("button",{type:"button",role:"tab","aria-selected":c,className:Z("sidebar-tab","sidebar-tab-mod",c&&"sidebar-tab-active"),onClick:()=>a(l.id),title:`${l.label} (mod)`,children:[e.jsx(o,{size:18,"aria-hidden":!0}),e.jsx("span",{className:"sidebar-tab-label",children:l.label})]},l.id)})]})]})})}const Gs=[{id:"all",label:"All"},{id:"projects",label:"Projects"},{id:"agents",label:"Agents"},{id:"tasks",label:"Tasks"},{id:"mods",label:"Mods"},{id:"schedules",label:"Schedules"},{id:"commands",label:"Commands"},{id:"settings",label:"Settings"}],zt={all:null,projects:"project",agents:"agent",tasks:"task",mods:"mod",schedules:"schedule",commands:"command",settings:"setting"};function Fn({open:s,onClose:t,onSelect:a}){const i=ce(),[n,l]=r.useState(""),[o,c]=r.useState("all"),[g,m]=r.useState([]),[x,h]=r.useState(!1),[d,u]=r.useState(0),j=r.useRef(null),f=r.useRef(null);if(r.useEffect(()=>{let k;return s&&(f.current=document.activeElement instanceof HTMLElement?document.activeElement:null,l(""),m([]),u(0),k=window.setTimeout(()=>{var P;return(P=j.current)==null?void 0:P.focus()},30)),()=>{if(k&&window.clearTimeout(k),!s)return;const P=f.current;P&&P.isConnected&&P.focus()}},[s]),r.useEffect(()=>{if(!s)return;if(!n.trim()){m([]),u(0);return}let k=!1;h(!0);const P=setTimeout(()=>{S.get(`/search?q=${encodeURIComponent(n)}&scope=${o}`).then(N=>{k||(m(N.results||[]),u(0))}).catch(N=>{k||i.error(`Search failed: ${N.message}`)}).finally(()=>!k&&h(!1))},150);return()=>{k=!0,clearTimeout(P)}},[n,o,s,i]),!s)return null;const y={};for(const k of g){const P=k.type.toLowerCase();y[P]=y[P]||[],y[P].push(k)}const $=[];for(const k of Gs.map(P=>P.id)){const P=zt[k];P&&y[P]&&$.push(...y[P])}const b=k=>{if(k.key==="Escape")t();else if(k.key==="ArrowDown"){if(k.preventDefault(),$.length===0)return;u(P=>Math.min(P+1,$.length-1))}else if(k.key==="ArrowUp"){if(k.preventDefault(),$.length===0)return;u(P=>Math.max(P-1,0))}else k.key==="Enter"&&$[d]&&(k.preventDefault(),a($[d]),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:k=>k.stopPropagation(),children:[e.jsxs("div",{className:"search-modal-head",role:"search",children:[e.jsx(ye,{size:14,"aria-hidden":!0}),e.jsx("span",{id:"search-modal-title",className:"sr-only",children:"Search"}),e.jsx("input",{ref:j,className:"search-modal-input",placeholder:"Search tasks, agents, settings, projects…",value:n,onChange:k=>l(k.target.value),onKeyDown:b,"aria-label":"Search"}),e.jsx("button",{type:"button",className:"icon-btn","aria-label":"Close",onClick:t,children:e.jsx($e,{size:14})})]}),e.jsx("div",{className:"search-modal-scopes",children:Gs.map(k=>e.jsx("button",{type:"button",className:Z("search-scope",o===k.id&&"search-scope-active"),onClick:()=>c(k.id),children:k.label},k.id))}),e.jsxs("div",{className:"search-modal-body",children:[x&&e.jsx("div",{className:"muted",children:"Searching…"}),!x&&n&&$.length===0&&e.jsx("div",{className:"muted",children:"No results."}),!x&&!n&&e.jsx("div",{className:"muted",children:"Type to search…"}),Gs.map(k=>{const P=zt[k.id];if(!P)return null;const N=y[P];return!N||N.length===0?null:e.jsxs("div",{className:"search-group",children:[e.jsx("div",{className:"search-group-head",children:k.label}),N.map(I=>{const F=$.indexOf(I);return e.jsxs("button",{type:"button",className:Z("search-result",F===d&&"search-result-active"),onMouseEnter:()=>u(F),onClick:()=>{a(I),t()},children:[e.jsx("span",{className:"search-result-type",children:I.type}),e.jsx("span",{className:"search-result-label",children:Bn(I)})]},`${I.type}-${F}`)})]},k.id)})]}),e.jsx("div",{className:"search-modal-foot",children:e.jsx("span",{className:"muted",children:"↑↓ navigate · ↵ open · esc close"})})]})})}function Bn(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 Un={info:_s,success:_e,warning:ke,error:ct};function qn({onCountChange:s,wsSubscribe:t}){const a=ce(),[i,n]=r.useState(!1),[l,o]=r.useState([]),[c,g]=r.useState(null),[m,x]=r.useState(!1),h=r.useRef(null),d=r.useRef(0),u=async()=>{var b;try{x(!0);const k=await S.get("/notifications?limit=200");o(k.notifications||[]),g(k.stats||null),d.current=((b=k.stats)==null?void 0:b.unread)||0,s==null||s(d.current)}catch(k){console.warn("[notifications] reload failed:",k.message)}finally{x(!1)}};r.useEffect(()=>{u()},[]),r.useEffect(()=>t?t(k=>{if(k.type==="notification:new"){const P=k.notification;o(N=>[P,...N.filter(I=>I.id!==P.id)]),P.read||(d.current+=1,g(N=>N?{...N,unread:(N.unread||0)+1}:{total:1,unread:1,lastTs:P.ts,counts:{[P.severity||"info"]:1}}),s==null||s(d.current))}else k.type==="notifications:change"&&u()}):void 0,[t]),r.useEffect(()=>{if(!i)return;const b=P=>{h.current&&(h.current.contains(P.target)||n(!1))},k=P=>{P.key==="Escape"&&n(!1)};return document.addEventListener("mousedown",b),document.addEventListener("keydown",k),()=>{document.removeEventListener("mousedown",b),document.removeEventListener("keydown",k)}},[i]);const j=async()=>{try{await S.post("/notifications/read-all",{}),o(b=>b.map(k=>({...k,read:!0}))),g(b=>b&&{...b,unread:0}),d.current=0,s==null||s(0),a.success("All notifications marked as read.",1500)}catch(b){a.error(`Failed: ${b.message}`)}},f=async b=>{try{await S.post(`/notifications/${encodeURIComponent(b)}/read`,{}),o(k=>k.map(P=>P.id===b?{...P,read:!0}:P)),g(k=>k&&{...k,unread:Math.max(0,(k.unread||1)-1)}),d.current=Math.max(0,d.current-1),s==null||s(d.current)}catch(k){a.error(`Failed: ${k.message}`)}},y=async b=>{try{await S.del(`/notifications/${encodeURIComponent(b)}`),o(k=>{const P=k.find(N=>N.id===b);return P&&!P.read&&(d.current=Math.max(0,d.current-1),g(N=>N&&{...N,unread:Math.max(0,N.unread-1)}),s==null||s(d.current)),k.filter(N=>N.id!==b)})}catch(k){a.error(`Failed: ${k.message}`)}},$=(c==null?void 0:c.unread)||0;return e.jsxs("div",{className:"notifications-root",ref:h,children:[e.jsxs("button",{type:"button",className:Z("topbar-icon-btn notifications-bell",i&&"is-open"),onClick:()=>n(b=>!b),title:"Notifications","aria-label":"Notifications","aria-haspopup":"true","aria-expanded":i,children:[e.jsx(ja,{size:16}),$>0&&e.jsx("span",{className:"notifications-badge",children:$>99?"99+":$})]}),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"}),$>0&&e.jsxs("span",{className:"muted text-sm",children:[" · ",$," unread"]})]}),e.jsxs("div",{className:"notifications-panel-head-actions",children:[e.jsxs(T,{size:"sm",variant:"ghost",onClick:j,disabled:$===0,children:[e.jsx(tt,{size:12})," Mark all read"]}),e.jsx("button",{type:"button",className:"icon-btn",onClick:()=>n(!1),"aria-label":"Close",title:"Close",children:e.jsx($e,{size:14})})]})]}),e.jsx("div",{className:"notifications-list",children:m&&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(b=>{const k=Un[b.severity]||_s;return e.jsxs("div",{className:Z("notification-item",!b.read&&"is-unread",`severity-${b.severity}`),children:[e.jsx(k,{size:14,className:`notification-icon severity-${b.severity}`}),e.jsxs("div",{className:"notification-body",children:[b.title&&e.jsx("div",{className:"notification-title",children:b.title}),e.jsx("div",{className:"notification-msg",children:b.message}),e.jsxs("div",{className:"notification-meta muted",children:[e.jsx("span",{className:"mono",children:b.source}),e.jsx("span",{children:"·"}),e.jsx("span",{children:Ne(b.ts)})]})]}),e.jsxs("div",{className:"notification-actions",children:[!b.read&&e.jsx("button",{type:"button",className:"icon-btn",onClick:()=>f(b.id),title:"Mark as read","aria-label":"Mark as read",children:e.jsx(tt,{size:12})}),e.jsx("button",{type:"button",className:"icon-btn icon-btn-danger",onClick:()=>y(b.id),title:"Remove","aria-label":"Remove",children:e.jsx($e,{size:12})})]})]},b.id)})}),e.jsx("footer",{className:"notifications-panel-foot",children:e.jsx("span",{className:"muted text-sm",children:c?`${c.total} total · last ${Ne(c.lastTs||new Date().toISOString())}`:""})})]})]})}function _n({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,o=i==="toggle";return e.jsxs("div",{children:[o?e.jsxs("p",{style:{marginBottom:16,lineHeight:1.6},children:["Visual plan mode has been ",e.jsx("strong",{children:a?"enabled":"disabled"}),".",a?" The agent will create a plan and wait for your feedback on complex tasks.":" The agent will work without a visual plan canvas."]}):e.jsxs("div",{style:{marginBottom:16},children:[e.jsxs("p",{style:{marginBottom:8,fontWeight:600},children:["Visual Plan: ",e.jsx("span",{style:{color:a?"var(--color-success)":"var(--color-muted)"},children:a?"ON":"OFF"})]}),e.jsx("p",{style:{lineHeight:1.6,color:"var(--color-muted)",fontSize:13},children:"When enabled, the agent creates a visual plan and waits for your feedback before proceeding with complex tasks."}),n&&e.jsxs("p",{style:{marginTop:8,fontSize:13,color:"var(--color-muted)"},children:["Default template: ",e.jsx("code",{children:n})]}),l&&e.jsxs("p",{style:{fontSize:13,color:"var(--color-muted)"},children:["Last used plan: ",e.jsx("code",{children:l})]}),e.jsxs("p",{style:{marginTop:12,fontSize:13,color:"var(--color-muted)"},children:["Use ",e.jsx("code",{children:"/visual-plan on"})," or ",e.jsx("code",{children:"/visual-plan off"})," to toggle."]})]}),e.jsx("div",{style:{display:"flex",gap:8,justifyContent:"flex-end"},children:e.jsx(T,{variant:"ghost",onClick:t,children:"Close"})})]})}const Hn=["blank","feature-design","bug-investigation","decision-record","horizontal","vertical"];function Wn({data:s,onClose:t}){const a=(s==null?void 0:s.templates)??Hn,i=(s==null?void 0:s.defaultTemplate)??"blank",[n,l]=r.useState(""),[o,c]=r.useState(i),[g,m]=r.useState(!1),[x,h]=r.useState(null),d=async()=>{if(!n.trim()){h("Slug is required.");return}if(!/^[a-z0-9][a-z0-9-]{0,63}$/.test(n)){h("Invalid slug. Use lowercase letters, numbers, and hyphens. Must start with an alphanumeric character.");return}m(!0),h(null);try{await S.post("/artifacts",{slug:n,template:o}),t()}catch(u){h(u.message),m(!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),h(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:o,onChange:u=>c(u.target.value),children:a.map(u=>e.jsx("option",{value:u,children:u},u))})]}),x&&e.jsx("p",{style:{marginBottom:12,color:"var(--color-danger)",fontSize:13},children:x}),e.jsxs("div",{style:{display:"flex",gap:8,justifyContent:"flex-end"},children:[e.jsx(T,{variant:"ghost",onClick:t,disabled:g,children:"Cancel"}),e.jsx(T,{variant:"primary",onClick:d,disabled:g||!n.trim(),children:g?"Creating…":"Create"})]})]})}function Vn({data:s,onClose:t}){const a=(s==null?void 0:s.plans)??[],i=(s==null?void 0:s.count)??a.length,n=l=>{window.open(`/artifacts/${l}/`,"_blank")};return e.jsxs("div",{children:[a.length===0?e.jsxs("p",{style:{marginBottom:16,color:"var(--color-muted)"},children:["No plans found in this worktree. Use ",e.jsx("code",{children:"/artifact new <slug>"})," to create one."]}):e.jsxs("div",{style:{marginBottom:16},children:[e.jsxs("p",{style:{marginBottom:12,fontSize:13,color:"var(--color-muted)"},children:[i," plan",i!==1?"s":""," in this worktree:"]}),e.jsx("ul",{style:{listStyle:"none",padding:0,margin:0},children:a.map(l=>e.jsxs("li",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 0",borderBottom:"1px solid var(--color-border)"},children:[e.jsx("code",{style:{fontSize:13},children:l}),e.jsx(T,{variant:"ghost",size:"sm",onClick:()=>n(l),children:"Open"})]},l))})]}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsx(T,{variant:"ghost",onClick:t,children:"Close"})})]})}function Kn({data:s,onClose:t}){const a=(s==null?void 0:s.commands)??[],i=(s==null?void 0:s.templates)??[],n=(s==null?void 0:s.statuses)??[];return e.jsxs("div",{children:[a.length>0?e.jsx("table",{style:{width:"100%",borderCollapse:"collapse",marginBottom:16,fontSize:13},children:e.jsx("tbody",{children:a.map(l=>e.jsxs("tr",{style:{borderBottom:"1px solid var(--color-border)"},children:[e.jsx("td",{style:{padding:"5px 8px 5px 0",whiteSpace:"nowrap"},children:e.jsx("code",{style:{fontSize:12},children:l.cmd})}),e.jsx("td",{style:{padding:"5px 0",color:"var(--color-muted)"},children:l.desc})]},l.cmd))})}):e.jsx("p",{style:{marginBottom:16,color:"var(--color-muted)"},children:"No commands available."}),i.length>0&&e.jsxs("div",{style:{marginBottom:12},children:[e.jsx("p",{style:{fontSize:12,color:"var(--color-muted)",marginBottom:4},children:"Available templates:"}),e.jsx("p",{style:{fontSize:13},children:i.join(", ")})]}),n.length>0&&e.jsxs("div",{style:{marginBottom:12},children:[e.jsx("p",{style:{fontSize:12,color:"var(--color-muted)",marginBottom:4},children:"Available statuses:"}),e.jsx("p",{style:{fontSize:13},children:n.join(", ")})]}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsx(T,{variant:"ghost",onClick:t,children:"Close"})})]})}function Gn({data:s,onClose:t}){const[a,i]=r.useState(!1),[n,l]=r.useState(null),o=async()=>{i(!0),l(null);try{const c=await S.post("/chat/audit",{});l(c)}catch(c){l({ok:!1,findings:[],error:c.message})}finally{i(!1)}};return e.jsx("div",{children:n===null?e.jsxs(e.Fragment,{children:[e.jsx("p",{style:{marginBottom:16,lineHeight:1.6},children:"Run a security audit of your Bizar agent configuration. The audit checks for common misconfigurations, exposed secrets, and insecure defaults."}),e.jsxs("div",{style:{display:"flex",gap:8,justifyContent:"flex-end"},children:[e.jsx(T,{variant:"ghost",onClick:t,children:"Cancel"}),e.jsx(T,{variant:"primary",onClick:o,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((c,g)=>e.jsx("li",{style:{marginBottom:4,fontSize:13},children:c},g))})]}):e.jsxs("p",{style:{marginBottom:16,color:"var(--color-danger)"},children:["Audit failed: ",n.error??"unknown error"]}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsx(T,{variant:"ghost",onClick:t,children:"Close"})})]})})}function Yn({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 Qn({dialog:s,onClose:t}){switch(s.component){case"visual-artifact":return e.jsx(_n,{data:s.data,onClose:t});case"artifact-create":return e.jsx(Wn,{data:s.data,onClose:t});case"artifact-list":return e.jsx(Vn,{data:s.data,onClose:t});case"help":return e.jsx(Kn,{data:s.data,onClose:t});case"audit":return e.jsx(Gn,{data:s.data,onClose:t});default:return e.jsx(Yn,{dialog:s,onClose:t})}}function J({variant:s="elevated",interactive:t=!1,className:a,children:i,...n}){return e.jsx("div",{className:Z("card",`card-${s}`,t&&"card-interactive",a),...n,children:i})}function ne({children:s,className:t}){return e.jsx("h3",{className:Z("card-title",t),children:s})}function re({children:s,className:t}){return e.jsx("div",{className:Z("card-meta",t),children:s})}function Xn({setActiveTab:s,refreshKey:t=0}){var m;const[a,i]=r.useState(null),[n,l]=r.useState(!0),o=async()=>{l(!0);try{const[x,h,d]=await Promise.all([S.get("/memory/status").catch(()=>null),S.get("/memory/health").catch(()=>null),S.get("/memory/lightrag/stats").catch(()=>null)]);i({initialized:!!(x!=null&&x.initialized),mode:x==null?void 0:x.mode,projectId:x==null?void 0:x.projectId,vaultRoot:x==null?void 0:x.vaultRoot,branch:x==null?void 0:x.branch,gitClean:x==null?void 0:x.gitClean,noteCount:(x==null?void 0:x.noteCount)||0,healthScore:h==null?void 0:h.score,healthStatus:h==null?void 0:h.status,lightrag:d?{running:d.running,indexedApprox:d.indexedApprox}:void 0})}catch{i({initialized:!1})}finally{l(!1)}};r.useEffect(()=>{o()},[t]);const c=()=>s("memory"),g=(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(J,{className:"memory-overview-card",children:[e.jsxs(ne,{children:[e.jsx(Le,{size:14})," Memory",e.jsxs(T,{variant:"ghost",size:"sm",style:{marginLeft:"auto"},onClick:c,children:["Open Memory ",e.jsx(ls,{size:12})]}),e.jsx(T,{variant:"ghost",size:"sm",onClick:o,"aria-label":"Refresh",title:"Refresh",children:e.jsx(oe,{size:12})})]}),e.jsx(re,{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:g},children:a.healthScore!==void 0?`${a.healthScore}/100`:"—"}),e.jsx("div",{className:"memory-status-card-sub muted",children:a.healthStatus||"—"})]}),e.jsxs("div",{className:"memory-status-card-cell",children:[e.jsxs("div",{className:"memory-status-card-label",children:[e.jsx(Le,{size:11})," LightRAG"]}),e.jsx("div",{className:"memory-status-card-value",children:(m=a.lightrag)!=null&&m.running?"running":"stopped"}),e.jsx("div",{className:"memory-status-card-sub muted",children:a.lightrag?`${a.lightrag.indexedApprox} chunks`:"—"})]}),e.jsxs("div",{className:"memory-status-card-cell",children:[e.jsxs("div",{className:"memory-status-card-label",children:[e.jsx(Se,{size:11})," Vault"]}),e.jsxs("div",{className:"memory-status-card-value",children:[a.noteCount," notes"]}),e.jsx("div",{className:"memory-status-card-sub muted ellipsis",title:a.vaultRoot||"",children:a.vaultRoot?a.vaultRoot.split("/").slice(-2).join("/"):"—"})]}),e.jsxs("div",{className:"memory-status-card-cell",children:[e.jsxs("div",{className:"memory-status-card-label",children:[e.jsx(rs,{size:11})," Git"]}),e.jsx("div",{className:"memory-status-card-value",children:a.gitClean===null?a.mode==="local-only"?"local-only":"—":a.gitClean?"clean":"dirty"}),e.jsx("div",{className:"memory-status-card-sub muted",children:a.branch?`branch ${a.branch}`:os(a.branch||"")||"—"})]})]}):e.jsxs("div",{className:"muted",children:["Memory not initialised. Click ",e.jsx("strong",{children:"Open Memory"})," to set it up."]}),n&&!a&&e.jsx("div",{className:"muted text-sm",children:"Loading…"})]})}function we({icon:s,title:t,message:a,action:i,className:n}){return e.jsxs("div",{className:Z("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 Zn({snapshot:s,settings:t,setActiveTab:a,refreshSnapshot:i}){var W,te,ee;const n=ce(),l=De(),o=r.useRef(null),[c,g]=r.useState(s.overview??null),[m,x]=r.useState(!s.overview),[h,d]=r.useState(s.projects||[]),[u,j]=r.useState(((W=s.activeProject)==null?void 0:W.id)||null),[f,y]=r.useState(s.mods||[]),[$,b]=r.useState(!1),[k,P]=r.useState(((te=s.overview)==null?void 0:te.recentActivity)??[]),[N,I]=r.useState(!1),[F,w]=r.useState(new Set);r.useEffect(()=>{let _=!1;return(async()=>{try{const Y=await S.get("/activity/hidden");_||w(new Set(Y.hidden||[]))}catch{}})(),()=>{_=!0}},[]);const E=(_,Y)=>{const se=`${_.kind||""}|${_.ts||""}|${_.slug||_.title||""}|${Y}`;let Q=0;for(let ie=0;ie<se.length;ie++)Q=(Q<<5)-Q+se.charCodeAt(ie)|0;return Math.abs(Q).toString(16).padStart(8,"0").slice(0,16)},A=async _=>{const Y=new Set(F);Y.add(_),w(Y);try{await S.post("/activity/hide",{keys:[_]})}catch(se){const Q=new Set(F);w(Q),n.error(`Hide failed: ${se.message}`)}},z=async()=>{if(!confirm("Hide every recent activity item from the overview? The full log stays in Settings → Activity Log."))return;const _=k.map((se,Q)=>E(se,Q)),Y=new Set(F);_.forEach(se=>Y.add(se)),w(Y);try{await S.post("/activity/hide",{keys:_}),n.success(`Hidden ${_.length} item(s). Restore them in Settings → Activity Log.`)}catch(se){n.error(`Clear failed: ${se.message}`)}},R=async()=>{w(new Set);try{await S.del("/activity/hide"),n.success("All hidden activity restored to the overview.")}catch(_){n.error(`Restore failed: ${_.message}`)}};r.useEffect(()=>{var _;s.overview&&(g(s.overview),P(s.overview.recentActivity??[]),x(!1)),d(s.projects||[]),j(((_=s.activeProject)==null?void 0:_.id)||null),y(s.mods||[])},[s.overview,s.projects,s.activeProject,s.mods]),r.useEffect(()=>{let _;try{const Y=S.getToken(),se=Y?`/api/activity/stream?token=${encodeURIComponent(Y)}`:"/api/activity/stream";_=new EventSource(se),_.addEventListener("snapshot",Q=>{try{const ie=JSON.parse(Q.data);P(Array.isArray(ie.events)?ie.events.slice(0,50):[])}catch{}}),_.addEventListener("activity",Q=>{try{const ie=JSON.parse(Q.data);P(xe=>[ie,...xe].slice(0,50))}catch{}})}catch{}return()=>{try{_==null||_.close()}catch{}}},[]);const B=async()=>{n.info("Refreshing…",1500),await i();try{const _=await S.get("/projects");d(_.projects||[]),j(_.active||null)}catch{}},v=()=>{l.open({title:"Add project",children:e.jsx(Jn,{settings:t,onAdd:async(_,Y)=>{try{const se=await S.post("/projects",{path:_,name:Y});d(Q=>[...Q.filter(ie=>ie.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(T,{variant:"ghost",onClick:()=>l.close(),children:"Cancel"})})})},O=async()=>{var _;try{const Y=await S.post("/projects/auto-detect");d(Y.projects||[]),j(Y.active||null);const se=(_=Y.projects)==null?void 0:_.find(Q=>Q.id===Y.active);n.success(se?`Active: ${se.name}`:"Projects refreshed."),await i()}catch(Y){n.error(`Auto-detect failed: ${Y.message}`)}},K=async _=>{try{await S.post(`/projects/${encodeURIComponent(_)}/activate`),j(_),n.success("Project activated."),await i()}catch(Y){n.error(`Activate failed: ${Y.message}`)}},M=async _=>{if(confirm(`Remove project "${_}" from the registry?`))try{await S.del(`/projects/${encodeURIComponent(_)}`),d(Y=>Y.filter(se=>se.id!==_)),u===_&&j(null),n.success("Project removed.")}catch(Y){n.error(`Remove failed: ${Y.message}`)}};return m||!c?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 _=>{var se,Q;_.preventDefault();const Y=(((se=o.current)==null?void 0:se.value)||"").trim();if(Y){b(!0);try{const ie=await S.post("/tasks/submit",{title:Y});n.success(`Odin split it into ${((Q=ie.subtasks)==null?void 0:Q.length)||1} task(s)`),o.current&&(o.current.value=""),await i()}catch(ie){n.error(`Failed: ${ie.message}`)}finally{b(!1)}}},children:[e.jsx("textarea",{ref:o,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:$}),e.jsxs("div",{style:{display:"flex",gap:"var(--space-2)",alignItems:"center",flexWrap:"wrap"},children:[e.jsxs(T,{type:"submit",variant:"primary",size:"lg",disabled:$,children:[$?e.jsx(he,{size:"sm"}):e.jsx(Qe,{size:16}),"Submit to Odin"]}),e.jsxs("span",{className:"muted",style:{fontSize:12},children:[e.jsx(Fe,{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(_=>e.jsx("button",{type:"button",className:"overview-quick-chip",onClick:()=>{o.current&&(o.current.value=_,o.current.focus())},children:_},_))})]}),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:[F.size>0&&e.jsxs(T,{variant:"ghost",size:"sm",onClick:R,title:"Restore hidden items to this overview",children:[e.jsx(is,{size:12})," Show ",F.size," hidden"]}),k.length>8&&e.jsx(T,{variant:"ghost",size:"sm",onClick:()=>I(_=>!_),children:N?"Show less":"Show all"}),k.length>0&&e.jsxs(T,{variant:"ghost",size:"sm",onClick:z,title:"Hide every item from the overview (full log kept)",children:[e.jsx(at,{size:12})," Hide all"]})]})]}),F.size>0&&e.jsxs("div",{className:"activity-hidden-banner",role:"status",children:[e.jsxs("span",{children:[e.jsx(at,{size:12,style:{verticalAlign:-2,marginRight:6}}),F.size," item",F.size===1?"":"s"," hidden from the overview."]}),e.jsxs(T,{variant:"ghost",size:"sm",onClick:R,children:[e.jsx(is,{size:12})," Show them again"]})]}),k.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:Z("activity-feed-list-wrap",!N&&"activity-feed-list-wrap-collapsed"),children:[e.jsx(mt,{items:k.slice(0,30).filter((_,Y)=>!F.has(E(_,Y))),itemHeight:60,height:Math.min(k.filter((_,Y)=>!F.has(E(_,Y))).length*60,480),className:"activity-feed-list",renderItem:(_,Y)=>{const se=k.slice(0,30).findIndex(Q=>Q===_);return e.jsx(oi,{item:_,activityKey:E(_,se),onNavigate:a,onHide:A})}}),!N&&k.length>8&&e.jsx("div",{className:"activity-feed-fade","aria-hidden":"true"})]})]}),e.jsxs(J,{className:"project-picker",children:[e.jsxs(ne,{children:[e.jsx(Ee,{size:14})," Projects",e.jsxs(T,{variant:"ghost",size:"sm",style:{marginLeft:"auto"},onClick:v,children:[e.jsx(Me,{size:12})," Add"]}),e.jsxs(T,{variant:"ghost",size:"sm",onClick:O,title:"Use the server's working directory",children:[e.jsx(Me,{size:12})," Auto-detect"]}),((ee=t==null?void 0:t.dashboard)==null?void 0:ee.projectsDirectory)&&e.jsxs(T,{variant:"ghost",size:"sm",title:`Scan ${t.dashboard.projectsDirectory} for projects`,onClick:async()=>{try{const _=await S.post("/projects/scan");_.error?n.error(_.error):n.success(`Added ${_.added.length}, skipped ${_.skipped}.`),await i();const Y=await S.get("/projects");d(Y.projects||[]),j(Y.active||null)}catch(_){n.error(`Scan failed: ${_.message}`)}},children:[e.jsx(tn,{size:12})," Scan"]}),e.jsx(T,{variant:"ghost",size:"sm",onClick:B,title:"Refresh",children:e.jsx(oe,{size:12})})]}),e.jsxs(re,{children:[h.length," project",h.length===1?"":"s"," ·"," ",c.counts.agents," agents ·"," ",c.counts.sessions," session",c.counts.sessions===1?"":"s"]}),h.length===0?e.jsx(we,{icon:e.jsx(Ee,{size:32}),title:"No projects yet",message:"Add a project to start tracking its tasks, plans, and schedules.",action:e.jsxs("div",{className:"empty-state-actions",children:[e.jsxs(T,{variant:"primary",onClick:O,children:[e.jsx(Me,{size:14})," Use current directory"]}),e.jsx(T,{variant:"secondary",onClick:v,children:"Add by path…"})]})}):e.jsx("div",{className:"project-grid",children:h.map(_=>e.jsx(ei,{project:_,active:u===_.id,onOpen:()=>K(_.id),onRemove:()=>M(_.id)},_.id))})]}),e.jsx(Xn,{setActiveTab:a}),e.jsxs("div",{className:"overview-cols",children:[e.jsxs(J,{children:[e.jsx(ne,{children:"Mods"}),e.jsxs(re,{children:["Extensions installed under ",e.jsx("code",{children:"~/.config/bizar/mods/"})]}),f.length===0?e.jsx("div",{className:"muted",children:"No mods installed."}):e.jsx("ul",{className:"mod-mini-list",children:f.map(_=>e.jsxs("li",{className:"mod-mini",children:[e.jsx("span",{className:"mod-mini-name",children:_.name}),e.jsxs("span",{className:"mod-mini-meta",children:["v",_.version," · ",_.type]}),e.jsx("span",{className:`mod-mini-pill ${_.enabled?"mod-mini-pill-on":"mod-mini-pill-off"}`,children:_.enabled?"on":"off"})]},_.id))})]}),e.jsxs(J,{children:[e.jsx(ne,{children:"Environment"}),e.jsx(re,{children:"Runtime + paths"}),e.jsxs("dl",{className:"env-table",children:[e.jsx("dt",{children:"Node"}),e.jsx("dd",{className:"mono",children:c.versions.node}),e.jsx("dt",{children:"Platform"}),e.jsx("dd",{className:"mono",children:c.versions.platform}),e.jsx("dt",{children:"Project root"}),e.jsx("dd",{className:"mono ellipsis",title:c.versions.projectRoot,children:c.versions.projectRoot}),e.jsx("dt",{children:"Bizar root"}),e.jsx("dd",{className:"mono ellipsis",title:c.versions.bizarRoot,children:c.versions.bizarRoot}),e.jsx("dt",{children:"Generated"}),e.jsx("dd",{className:"mono tabular-nums",children:os(c.generatedAt)})]})]})]})]})}function Jn({settings:s,onAdd:t}){var h,d;const[a,i]=r.useState(((h=s==null?void 0:s.dashboard)==null?void 0:h.projectsDirectory)??""),[n,l]=r.useState(""),[o,c]=r.useState(!1),[g,m]=r.useState(null),x=async()=>{var u;if(a){c(!0),m(null);try{await S.get("/fs?path="+encodeURIComponent(a)),t(a,n||null)}catch(j){const f=j;f.status===404?m("That folder no longer exists. Pick another."):m(((u=f.data)==null?void 0:u.message)??j.message??"Validation failed.")}finally{c(!1)}}};return e.jsxs("div",{children:[e.jsx("label",{className:"field-label",children:"Folder"}),e.jsx(ea,{value:a,onChange:u=>{i(u),m(null)},projectsDirectory:(d=s==null?void 0:s.dashboard)==null?void 0:d.projectsDirectory,height:320}),g&&e.jsx("p",{className:"field-help",style:{color:"var(--error)",marginTop:4},children:g}),e.jsxs("div",{style:{marginTop:"var(--space-3)"},children:[e.jsx("label",{className:"field-label",htmlFor:"add-project-name",children:"Name (optional)"}),e.jsx("input",{id:"add-project-name",className:"input",type:"text",placeholder:"My App",value:n,onChange:u=>l(u.target.value)}),e.jsx("p",{className:"field-help",style:{marginTop:4},children:"Display name for this project. Defaults to the folder name."})]}),e.jsx("div",{style:{marginTop:"var(--space-3)",display:"flex",justifyContent:"flex-end"},children:e.jsxs(T,{variant:"primary",onClick:x,disabled:!a||o,children:[o?e.jsx("span",{className:"btn-spinner"}):null,o?"Checking…":"Add"]})})]})}function ei({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(Re,{size:12})})]}),e.jsx("div",{className:"project-card-path mono ellipsis",title:s.path,children:s.path}),e.jsx("div",{className:"project-card-meta",children:s.lastAccessed&&e.jsxs("span",{className:"muted",children:["Last opened ",Ne(s.lastAccessed)]})}),e.jsx("div",{className:"project-card-actions",children:e.jsx(T,{variant:t?"ghost":"primary",size:"sm",onClick:a,children:t?e.jsxs(e.Fragment,{children:[e.jsx(ht,{size:12})," Active"]}):e.jsx(e.Fragment,{children:"Open"})})})]})}function si(s){return s&&s.charAt(0).toUpperCase()+s.slice(1)}function ti(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"},o=n[a]||si(a.replace(/-/g," ")),c=l[i]||i.replace(/-/g," ");return`${o} ${c}`.trim()}function Ms(s,t){for(const a of t){const i=s[a];if(typeof i=="string"&&i.trim())return i.trim()}return""}function ai(s){const t=Ms(s,["message","text","prompt","title","name"]);if(t)return t;const a=[],i=Ms(s,["slug"]),n=Ms(s,["agent","author"]),l=Ms(s,["status"]);return i&&a.push(`Plan ${i}`),n&&a.push(n),l&&a.push(l),a.length?a.join(" · "):"No additional details."}function ni(s){return Ne(s)}function ii(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 ri(s){const t=s.toLowerCase();return t==="task"?gs:t==="agent"?qe:t==="plan"?Fs:t.includes("bg")||t.includes("background")||t.includes("job")?vt:t==="mod"?Bs:t==="skill"?Fe:t.includes("error")||t.includes("failure")?mn:t.includes("warn")?ke:Te}function li(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 oi({item:s,activityKey:t,onNavigate:a,onHide:i}){const n=ii(s),l=ri(s.kind||""),o=ti(s.kind||"activity"),c=ai(s),g=li(s.kind||""),m=n==="error"?"var(--error)":n==="warning"?"var(--warning)":n==="success"?"var(--success)":"var(--accent)";return e.jsxs("div",{className:Z("activity-feed-row",`activity-feed-row-${n}`),children:[e.jsxs("button",{type:"button",className:"activity-feed-row-main",onClick:()=>{g&&a(g)},title:g?`Open ${g}`:o,children:[e.jsx("div",{className:"activity-feed-icon",style:{color:m},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:o}),e.jsx("div",{className:"activity-feed-time text-xs muted tabular-nums",children:ni(s.ts)})]}),e.jsx("div",{className:"activity-feed-summary text-sm",children:c})]})]}),e.jsx("button",{type:"button",className:"activity-feed-hide-btn",onClick:()=>i(t),title:"Hide this from the overview (kept in Settings → Activity Log)","aria-label":"Hide from overview",children:e.jsx($e,{size:12})})]})}const ci=We.memo(Zn);function di({session:s,mode:t,anchor:a,renameDraft:i,setRenameDraft:n,onEdit:l,onDeleteRequest:o,onConfirmDelete:c,onConfirmRename:g,onClose:m}){const x=r.useRef(null),h=Math.round(a.rect.bottom+2),d=Math.max(8,Math.round(window.innerWidth-a.rect.right));r.useEffect(()=>{const j=$=>{const b=$.target;!x.current||!b||x.current.contains(b)||m()},f=$=>{$.key==="Escape"&&m()},y=window.setTimeout(()=>{document.addEventListener("mousedown",j),document.addEventListener("keydown",f)},0);return()=>{window.clearTimeout(y),document.removeEventListener("mousedown",j),document.removeEventListener("keydown",f)}},[m]),r.useEffect(()=>{if(t!=="rename")return;const j=window.setTimeout(()=>{var y;const f=(y=x.current)==null?void 0:y.querySelector("input.session-row-menu-input");f==null||f.focus(),f==null||f.select()},0);return()=>window.clearTimeout(j)},[t]);const u=e.jsxs("div",{ref:x,className:"session-row-menu",role:"menu","aria-label":`Options for ${s.title}`,style:{position:"fixed",top:h,right:d},onClick:j=>j.stopPropagation(),children:[t==="main"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",className:"session-row-menu-item",role:"menuitem",onClick:j=>{j.stopPropagation(),l()},children:[e.jsx(kn,{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:j=>{j.stopPropagation(),o()},children:[e.jsx(Re,{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:j=>n(j.target.value),onKeyDown:j=>{j.key==="Enter"?(j.preventDefault(),g()):j.key==="Escape"&&(j.preventDefault(),m())},onClick:j=>j.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:j=>{j.stopPropagation(),m()},children:"Cancel"}),e.jsx("button",{type:"button",className:"btn btn-primary",onClick:j=>{j.stopPropagation(),g()},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:j=>{j.stopPropagation(),m()},children:"Cancel"}),e.jsx("button",{type:"button",className:"btn btn-danger",onClick:j=>{j.stopPropagation(),c()},children:"Delete"})]})]})]});return fa.createPortal(u,document.body)}function lt({node:s,depth:t=0,collapsible:a=!1,isLast:i=!0,open:n,onToggle:l}){var u;const[o,c]=r.useState(a),g=n!==void 0,m=g?n:o,x=j=>{g||c(j),l==null||l(j)},h=(((u=s.children)==null?void 0:u.length)??0)>0,d=e.jsxs(e.Fragment,{children:[a&&e.jsx("span",{className:`agent-node-chevron ${m?"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}`,m?"open":"closed",i?"last":""].filter(Boolean).join(" "),children:[a?e.jsx("button",{type:"button",className:`agent-node-head status-${s.status} collapsible`,onClick:j=>{j.stopPropagation(),x(!m)},"aria-expanded":m,children:d}):e.jsx("div",{className:`agent-node-head status-${s.status}`,children:d}),m&&e.jsxs(e.Fragment,{children:[s.summary&&e.jsx("div",{className:"agent-node-summary",children:s.summary}),h&&e.jsx("div",{className:"agent-node-children",children:s.children.map((j,f)=>e.jsx(lt,{node:j,depth:t+1,collapsible:!1,isLast:f===s.children.length-1},j.id))})]})]})}function mi(s){return s.tree!==void 0}function hi(s){const t=s.open??!0;if(mi(s))return e.jsx("div",{className:`agent-tree variant-${s.variant??"full"}`,children:e.jsx(lt,{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(lt,{node:i,depth:0,collapsible:!1,open:t,isLast:n===a.length-1})},i.id))})})}function ui({children:s,variant:t="rail",open:a=!0}){return a?e.jsx(hi,{variant:t,open:a,children:s}):null}const xi=["Today","Yesterday","This week","Earlier"];function Tt(s,t){return s.getFullYear()===t.getFullYear()&&s.getMonth()===t.getMonth()&&s.getDate()===t.getDate()}function pi(s,t){const a=s.getTime()-t.getTime();return Math.floor(a/(1e3*60*60*24))}function gi(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 o=new Date(Number(l.mtime)||Date.now());Tt(o,t)?n.Today.push(l):Tt(o,a)?n.Yesterday.push(l):pi(t,o)<7?n["This week"].push(l):n.Earlier.push(l)}return n}function ji(s){return new Date(Number(s)||Date.now()).toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit",hour12:!1})}function fi({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 vi({sessions:s,opencodeSessions:t=[],activeSessionId:a,activeOpencodeSessionId:i,activeProject:n,creating:l,onCreateSession:o,onSelectSession:c,onSelectOpencodeSession:g,onRenameSession:m,onDeleteSession:x,groupBy:h}){var M;const d=r.useMemo(()=>[...s,...t],[s,t]),u=r.useMemo(()=>[...d].sort((W,te)=>Number(te.mtime??0)-Number(W.mtime??0)),[d]),j=r.useMemo(()=>h?h(u):gi(u),[h,u]),[f,y]=r.useState({}),$=W=>f[W]===!0,[b,k]=r.useState(null),[P,N]=r.useState("main"),[I,F]=r.useState(""),[w,E]=r.useState(null),A=r.useRef({}),z=(W,te="main")=>{const ee=A.current[W];if(!ee)return;const _=te==="main"?ee:ee.querySelector(".chat-rail-item-menu-trigger")??ee;if(E({id:W,rect:_.getBoundingClientRect()}),k(W),N(te),te==="rename"){const Y=[...s,...t].find(se=>se.id===W);F((Y==null?void 0:Y.title)??(Y==null?void 0:Y.id)??"")}},R=()=>{k(null),N("main"),F(""),E(null)},B=W=>{if(W.source==="opencode"){g(W);return}c(W.id)},v=()=>{if(!w)return;const W=w.id,te=I.trim();if(!te){R();return}m==null||m(W,te),R()},O=()=>{w&&(x==null||x(w.id),R())},K=h?Object.entries(j):xi.filter(W=>{var te;return(te=j[W])==null?void 0:te.length}).map(W=>[W,j[W]]);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:o,disabled:l||!n,title:n?"Create new session":"Pick a project first","aria-label":"Create new session",children:[e.jsx(Me,{size:14,"aria-hidden":!0}),e.jsx("span",{children:l?"Creating…":"New session"})]})}),u.length===0?e.jsx("div",{className:"chat-sessions-empty",children:e.jsx(va,{icon:e.jsx(Me,{size:20,"aria-hidden":!0}),title:n?"No sessions yet":"No project",message:n?"Create your first session to start chatting.":"Pick a project in Overview to scope chat sessions."})}):e.jsx("div",{className:"chat-rail-list",children:K.map(([W,te])=>e.jsxs("div",{className:"chat-rail-group",children:[e.jsx("div",{className:"chat-rail-group-label",children:W}),te.map(ee=>{var xe,V;const _=ee.source==="opencode",Y=_?i===ee.id:a===ee.id,se=ee.tree,Q=!!((xe=se==null?void 0:se.root)!=null&&xe.children&&se.root.children.length>0),ie=$(ee.id);return e.jsxs(r.Fragment,{children:[e.jsxs("div",{ref:L=>{A.current[ee.id]=L},role:"button",tabIndex:0,className:`chat-rail-item state-${ee.state??"idle"}${Y?" active":""}`,onClick:()=>B(ee),onKeyDown:L=>{(L.key==="Enter"||L.key===" ")&&(L.preventDefault(),B(ee))},"aria-current":Y?"true":void 0,children:[e.jsx(fi,{state:ee.state??"idle",agent:ee.agent}),e.jsxs("div",{className:"chat-rail-item-title",children:[ee.pinned&&e.jsx("span",{className:"chat-rail-pin","aria-hidden":!0,children:"★"}),_&&e.jsx(ls,{size:11,style:{color:"var(--text-muted)",flexShrink:0},"aria-hidden":!0}),e.jsx("span",{className:"chat-ellipsis",children:ee.title||ee.id})]}),e.jsxs("div",{className:"chat-rail-item-meta",children:[e.jsx("span",{className:"chat-rail-item-meta-time",children:ee.time??ji(ee.mtime)}),(ee.unread??0)>0&&e.jsx("span",{className:"chat-rail-badge",children:ee.unread})]}),e.jsx("button",{type:"button",className:`chat-rail-item-menu-trigger${b===ee.id?" open":""}`,"aria-label":`Session options for ${ee.title||ee.id}`,"aria-haspopup":"menu","aria-expanded":b===ee.id,onClick:L=>{L.stopPropagation(),b===ee.id?R():z(ee.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"})]})}),Y&&Q&&e.jsx("button",{type:"button",className:`chat-rail-tree-chevron${ie?" open":""}`,"aria-label":ie?"Collapse sub-agents":"Expand sub-agents","aria-expanded":ie,onClick:L=>{L.stopPropagation(),y(U=>({...U,[ee.id]:!U[ee.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"})})})]}),Y&&Q&&ie&&((V=se==null?void 0:se.root)==null?void 0:V.children)&&e.jsx(ui,{children:se.root.children,variant:"rail",open:!0})]},_?`oc-${ee.id}`:ee.id)})]},W))}),b&&w&&e.jsx(di,{session:{id:w.id,title:((M=[...s,...t].find(W=>W.id===w.id))==null?void 0:M.title)??w.id},mode:P,anchor:w,renameDraft:I,setRenameDraft:F,onEdit:()=>z(b,"rename"),onDeleteRequest:()=>z(b,"confirm-delete"),onConfirmDelete:O,onConfirmRename:v,onClose:R})]})}function yi(s){const{text:t,sending:a,onSend:i,activeSource:n}=s,[l,o]=r.useState(!1),c=()=>{!t.trim()||a||(o(!0),i(),window.setTimeout(()=>o(!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(ya,{...s,onSend:c})}),e.jsxs("div",{className:"chat-composer-hint chat-muted",children:[e.jsxs("span",{children:[e.jsx("kbd",{children:"⏎"})," send"]}),e.jsxs("span",{children:[e.jsx("kbd",{children:"⇧⏎"})," newline"]}),e.jsxs("span",{children:[e.jsx("kbd",{children:"/"})," commands"]}),n==="opencode"&&e.jsx("span",{className:"chat-composer-source-hint",children:"→ opencode"}),n==="bizar"&&e.jsx("span",{className:"chat-composer-source-hint",children:"→ bizar chat"}),a&&e.jsx("span",{className:"chat-composer-source-hint",children:"sending…"})]})]})}function Ys(s){return s.toLocaleString()}function bi(s){return!s||!s.includes("/")?"":s.split("/")[0]}function ki(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 Ni({sessionId:s,messages:t,pinned:a,agent:i,model:n,agents:l,mcps:o,allCommands:c,activeSource:g="bizar",onRename:m,onDelete:x,onExport:h,busy:d}){const[u,j]=r.useState(null);r.useEffect(()=>{let E=!1;return(async()=>{try{const A=await fetch("/api/usage?range=24h",{headers:{Accept:"application/json"}});if(!A.ok)return;const z=await A.json();E||j(z)}catch{}})(),()=>{E=!0}},[s]);const f=(t==null?void 0:t.length)??0,y=(a==null?void 0:a.size)??0,$=t.reduce((E,A)=>E+(A.content||A.message||"").length,0),b=Math.round($/4),k=ki(n),P=b/1e6*k,N=(u==null?void 0:u.totalTokens)??b,I=(u==null?void 0:u.costUsd)??P,F=128e3,w=bi(n);return e.jsxs("aside",{className:"chat-info",children:[e.jsxs("div",{className:"chat-info-section",children:[e.jsxs("div",{className:"chat-info-section-head",children:[e.jsxs("h4",{children:[e.jsx(qs,{size:11,style:{marginRight:4,verticalAlign:-1},"aria-hidden":!0})," ","Session"]}),e.jsx("span",{className:`chat-source-badge chat-source-${g??"none"}`,style:{marginLeft:"auto"},children:g==="opencode"?"opencode":"bizar chat"})]}),e.jsx("div",{className:"chat-info-mono chat-ellipsis",title:s,children:s||"Live"}),e.jsxs("div",{className:"chat-info-mono",children:[Ys(f)," message",f===1?"":"s",y>0&&` · ${y} pinned`]})]}),e.jsxs("div",{className:"chat-info-section",children:[e.jsxs("h4",{children:[e.jsx(qe,{size:11,style:{marginRight:4,verticalAlign:-1},"aria-hidden":!0})," ","Agent"]}),e.jsx("div",{className:"chat-info-value",children:i||"—"})]}),e.jsxs("div",{className:"chat-info-section",children:[e.jsxs("h4",{children:[e.jsx(xs,{size:11,style:{marginRight:4,verticalAlign:-1},"aria-hidden":!0})," ","Model"]}),e.jsx("div",{className:"chat-mono chat-ellipsis",title:n,children:n||"—"}),w&&e.jsxs("div",{className:"chat-info-mono",children:["provider · ",w]})]}),e.jsxs("div",{className:"chat-info-section",children:[e.jsx("h4",{children:"Tokens"}),e.jsxs("div",{className:"chat-mono",children:[Ys(N)," / ",Ys(F)]}),e.jsx("div",{className:"chat-info-bar","aria-hidden":!0,children:e.jsx("div",{className:"chat-info-bar-fill",style:{width:`${Math.min(100,N/Math.max(1,F)*100)}%`}})})]}),e.jsxs("div",{className:"chat-info-section",children:[e.jsxs("h4",{children:[e.jsx(Ha,{size:11,style:{marginRight:4,verticalAlign:-1},"aria-hidden":!0})," ","Cost"]}),e.jsxs("div",{className:"chat-mono",children:["$",I.toFixed(4)]}),!u&&e.jsx("div",{className:"chat-info-mono",children:"approx · live from MiniMax"})]}),e.jsxs("div",{className:"chat-info-section",children:[e.jsxs("h4",{children:[e.jsx(qe,{size:11,style:{marginRight:4,verticalAlign:-1},"aria-hidden":!0})," ","Attached agents"]}),l!=null&&l.length?e.jsx("div",{className:"chat-info-agents",children:l.map(E=>e.jsx("span",{className:"chat-info-agent",children:E.name},E.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(xs,{size:11,style:{marginRight:4,verticalAlign:-1},"aria-hidden":!0})," ","MCPs"]}),o!=null&&o.length?e.jsx("div",{className:"chat-info-agents",children:o.map(E=>e.jsx("span",{className:"chat-info-agent",children:E.id},E.id))}):e.jsx("div",{className:"chat-info-mono",children:"No MCPs configured"})]}),e.jsxs("div",{className:"chat-info-section",children:[e.jsxs("h4",{children:[e.jsx(fs,{size:11,style:{marginRight:4,verticalAlign:-1},"aria-hidden":!0})," ","Slash commands"]}),e.jsxs("div",{className:"chat-info-mono",children:[(c==null?void 0:c.length)??0," available"]})]}),(m||x||h)&&e.jsxs("div",{className:"chat-info-section",children:[e.jsx("h4",{children:"Actions"}),e.jsxs("div",{className:"chat-info-actions",children:[m&&e.jsxs("button",{type:"button",className:"btn btn-ghost btn-sm",onClick:m,disabled:d==null?void 0:d.rename,title:"Rename session",children:[e.jsx(ks,{size:12,"aria-hidden":!0})," Rename"]}),h&&e.jsxs("button",{type:"button",className:"btn btn-ghost btn-sm",onClick:h,title:"Export transcript",children:[e.jsx(Xe,{size:12,"aria-hidden":!0})," Export"]}),x&&e.jsxs("button",{type:"button",className:"btn btn-ghost btn-sm btn-danger",onClick:x,disabled:d==null?void 0:d.delete,title:"Delete session",children:[e.jsx(Re,{size:12,"aria-hidden":!0})," Delete"]})]})]})]})}function wi({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(Kt,{size:14,"aria-hidden":!0}),e.jsx("span",{children:"Jump to latest"}),t>0&&e.jsxs("span",{className:"jump-badge",children:[t," new"]})]})})}function Si({snapshot:s,settings:t,setActiveTab:a,initialTaskId:i,onClearTaskId:n}){const l=ce(),o=De(),c=ba(s,t,i??"");r.useEffect(()=>{c.setToast({error:M=>l.error(M),success:M=>l.success(M),info:M=>l.info(M),warning:M=>l.warning(M)})},[c,l]);const[g,m]=r.useState(""),[x,h]=r.useState(t.defaultAgent||"odin"),[d,u]=r.useState(t.defaultModel||""),[j,f]=r.useState([]),y=r.useRef(null),{allCommands:$,suggestions:b,setQuery:k}=ka(s);r.useEffect(()=>{k(g)},[g,k]);const P=()=>{var M;return(M=y.current)==null?void 0:M.click()},N=M=>{const W=M.target.files;if(!W)return;const te=[];for(let ee=0;ee<W.length;ee++)te.push(W[ee].name);f(ee=>{const _=te.filter(Y=>!ee.includes(Y));return[...ee,..._]}),y.current&&(y.current.value="")},I=async()=>{const M=g.trim();if(!M)return;m(""),k(""),(await c.onSend(M,x,d,j)).ok&&c.jumpToLatest()},F=async()=>{c.busy.create||await c.onCreateSession()},w=M=>{o.open({title:"Delete message?",children:e.jsx("p",{style:{margin:0},children:"This action cannot be undone."}),footer:e.jsxs("div",{style:{display:"flex",gap:8,justifyContent:"flex-end"},children:[e.jsx(T,{variant:"secondary",size:"sm",onClick:()=>o.close(),children:"Cancel"}),e.jsx(T,{variant:"danger",size:"sm",onClick:()=>{o.close(),c.deleteMessage(M)},children:"Delete"})]})})},E=(M,W)=>{let te="";o.open({title:"Rename session",children:e.jsx("input",{autoFocus:!0,defaultValue:W,onChange:ee=>{te=ee.target.value},onKeyDown:ee=>{ee.key==="Enter"&&(ee.preventDefault(),o.close(),c.renameSession(M,te).then(_=>{_&&l.success("Renamed.")}))},style:{width:"100%",padding:"8px 10px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:"var(--radius-sm)",color:"var(--text)",font:"13px/1.4 var(--font-sans)",marginTop:6}}),footer:e.jsxs("div",{style:{display:"flex",gap:8,justifyContent:"flex-end"},children:[e.jsx(T,{variant:"secondary",size:"sm",onClick:()=>o.close(),children:"Cancel"}),e.jsx(T,{variant:"primary",size:"sm",onClick:()=>{o.close(),c.renameSession(M,te)},children:"Save"})]})})},A=(M,W)=>{o.open({title:"Delete session?",children:e.jsxs("p",{style:{margin:0},children:["Delete ",e.jsx("strong",{children:W}),"? Messages on the opencode serve will be removed. This cannot be undone."]}),footer:e.jsxs("div",{style:{display:"flex",gap:8,justifyContent:"flex-end"},children:[e.jsx(T,{variant:"secondary",size:"sm",onClick:()=>o.close(),children:"Cancel"}),e.jsx(T,{variant:"danger",size:"sm",onClick:async()=>{o.close(),await c.deleteSession(M)},children:"Delete"})]})})},z=()=>{const M=c.activeSource==="opencode"?c.activeOpencodeSessionId:c.sessionId;if(!M)return;const te=(c.activeSource==="opencode"?c.opencodeMessages:c.bizarMessages).map(se=>{const Q=se.ts??"",ie=(se.role||"unknown").toUpperCase(),xe=se.content||se.message||"";return`[${Q}] ${ie}: ${xe}`}).join(`
|
|
347
|
+
|
|
348
|
+
`),ee=new Blob([te],{type:"text/plain;charset=utf-8"}),_=URL.createObjectURL(ee),Y=document.createElement("a");Y.href=_,Y.download=`${M}.txt`,document.body.appendChild(Y),Y.click(),document.body.removeChild(Y),URL.revokeObjectURL(_)},R=r.useMemo(()=>c.sessions.map(M=>c.getSessionDisplay(M)),[c.sessions,c.getSessionDisplay]),B=r.useMemo(()=>c.opencodeSessions.map(M=>c.getSessionDisplay(M)),[c.opencodeSessions,c.getSessionDisplay]),v=r.useMemo(()=>{const M=c.activeSource==="opencode"?c.activeOpencodeSessionId??"":c.sessionId;return M?R.find(W=>W.id===M)??B.find(W=>W.id===M)??null:null},[c.activeSource,c.activeOpencodeSessionId,c.sessionId,R,B]),O=(()=>{var te;const M=`${x||"Odin"} · ${((te=s.activeProject)==null?void 0:te.name)??"no project"}`,W=(v==null?void 0:v.state)??"idle";return W==="streaming"?`Replying · ${M}`:W==="awaiting"?`Your turn · ${M}`:`${M} · idle`})(),K=c.activeSource==="opencode"?"opencode":"bizar chat";return e.jsxs("div",{className:"chat-shell",children:[e.jsx(Na,{activeProject:s.activeProject,sessionCount:c.sessions.length,sessionsOpen:!0,infoOpen:!0,onToggleSessions:()=>{},onToggleInfo:()=>{},onOpenOverview:()=>a==null?void 0:a("overview")}),e.jsxs("div",{className:"chat-page",children:[e.jsx(vi,{sessions:R,opencodeSessions:B,activeSessionId:c.sessionId,activeOpencodeSessionId:c.activeOpencodeSessionId,activeProject:s.activeProject,creating:c.busy.create,onCreateSession:F,onSelectSession:c.selectBizarSession,onSelectOpencodeSession:M=>c.loadOpencodeSession(M.id),onRenameSession:E,onDeleteSession:M=>{const W=c.sessions.find(te=>te.id===M)??c.opencodeSessions.find(te=>te.id===M);A(M,(W==null?void 0:W.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)??c.sessionId??"New chat"}),e.jsx("span",{className:`chat-source-badge chat-source-${c.activeSource??"none"}`,title:c.activeSource==="opencode"?"Messages go to the opencode serve child":"Messages go to the local chat store",children:K})]}),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"}),O]}),c.opencodeError&&e.jsx("div",{className:"chat-thread-error",role:"alert",children:c.opencodeError})]}),e.jsxs("div",{className:"chat-thread-actions",children:[v&&e.jsxs("button",{className:"btn btn-ghost",title:"Rename session",type:"button",disabled:c.busy.rename,onClick:()=>E(v.id,v.title??""),children:[e.jsx(ks,{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:c.busy.delete,onClick:()=>A(v.id,v.title??v.id),children:[e.jsx(Re,{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:z,children:e.jsx("span",{className:"mono",children:"export"})})]})]}),e.jsx("div",{className:"chat-thread-scroll",ref:c.listRef,onScroll:c.handleScroll,children:e.jsx(wa,{messages:c.activeSource==="opencode"?c.opencodeMessages:c.bizarMessages,loading:c.loading,activeProject:s.activeProject,sessionId:c.activeSource==="opencode"?c.activeOpencodeSessionId??c.sessionId:c.sessionId,pinned:c.pinned,activeSource:c.activeSource,onPickSuggestion:M=>m(M),onCopy:M=>c.copyMessage(M),onDelete:w,onTogglePin:c.togglePin,onRegenerate:c.onRegenerate})}),!c.stickToBottom&&e.jsx(wi,{streaming:(v==null?void 0:v.state)==="streaming",newMessageCount:c.newMessageCount,onClick:c.jumpToLatest}),e.jsx(yi,{agent:x,setAgent:h,model:d,setModel:u,text:g,setText:m,sending:c.sending,activeSource:c.activeSource,onSend:I,attachments:j,setAttachments:f,suggestions:b,onPickSuggestion:M=>m(`${M.split(" ")[0]} `),agents:s.agents||[],onAttach:P}),e.jsx("input",{ref:y,type:"file",multiple:!0,style:{display:"none"},onChange:N})]}),e.jsx(Ni,{sessionId:c.activeSource==="opencode"?c.activeOpencodeSessionId??c.sessionId:c.sessionId,messages:c.activeSource==="opencode"?c.opencodeMessages:c.bizarMessages,pinned:c.pinned,agent:x,model:d,agents:s.agents||[],mcps:s.mcps||[],allCommands:$,activeSource:c.activeSource,onRename:()=>{v&&E(v.id,v.title??"")},onDelete:()=>{v&&A(v.id,v.title??v.id)},onExport:z,busy:c.busy})]})]})}function ns({kind:s="neutral",children:t,className:a,dot:i=!1}){return e.jsxs("span",{className:Z("badge",`badge-${s}`,a),children:[i&&e.jsx("span",{className:"badge-dot"}),t]})}const Mt=["bash","read","edit","write","webfetch","websearch","task","glob","grep"],$t=["anthropic/claude-3-5-sonnet","anthropic/claude-3-5-haiku","openai/gpt-4o","openai/gpt-4o-mini","openrouter/minimax/minimax-m3","openrouter/minimax/minimax-m2.7"],Ls=[{id:"reasoning",label:"Reasoning",color:"var(--accent)"},{id:"code",label:"Code",color:"var(--info)"},{id:"design",label:"Design",color:"var(--success)"},{id:"planning",label:"Planning",color:"var(--warning)"},{id:"gitops",label:"GitOps",color:"var(--error)"},{id:"analysis",label:"Analysis",color:"var(--text-dim)"}];function Ci(s){var t;return((t=Ls.find(a=>a.id===s))==null?void 0:t.color)||"var(--text-dim)"}function zi({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 Ti({agent:s}){if(s.isStuck)return e.jsx(ns,{kind:"error",dot:!0,children:"stuck"});const t=s.status||"idle";return t==="working"?e.jsx(ns,{kind:"info",dot:!0,children:"working"}):t==="error"?e.jsx(ns,{kind:"error",dot:!0,children:"error"}):e.jsx(ns,{kind:"neutral",dot:!0,children:"idle"})}function Mi({snapshot:s,refreshSnapshot:t}){const a=ce(),i=De(),[n,l]=r.useState(s.agents||[]),[o,c]=r.useState(!s.agents),[g,m]=r.useState(""),[x,h]=r.useState("");r.useEffect(()=>{l(s.agents||[]),c(!s.agents)},[s.agents]);const d=async()=>{try{const N=await S.get("/agents");l(N.agents||[])}catch(N){a.error(`Agents load failed: ${N.message}`)}finally{c(!1)}},u=r.useMemo(()=>{let N=[...n];if(g&&(N=N.filter(I=>g==="__none__"?!I.category:(I.category||"")===g)),x){const I=x.toLowerCase();N=N.filter(F=>F.name.toLowerCase().includes(I)||(F.description||"").toLowerCase().includes(I)||(F.tags||[]).some(w=>w.toLowerCase().includes(I)))}return N.sort((I,F)=>I.name.localeCompare(F.name))},[n,g,x]),j=r.useMemo(()=>{const N=new Set;for(const I of n)for(const F of I.tags||[])N.add(F);return Array.from(N).sort()},[n]),f=()=>{let N=null,I=null,F=null,w=null,E=null,A=null,z=null,R=null,B=null;i.open({title:"New agent",width:640,children:e.jsxs("div",{className:"agent-form",children:[e.jsx("label",{className:"field-label",children:"Name (a-z, 0-9, dashes)"}),e.jsx("input",{ref:v=>N=v,className:"input",type:"text",placeholder:"my-agent",autoFocus:!0}),e.jsx("label",{className:"field-label",children:"Description"}),e.jsx("input",{ref:v=>{I=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",children:"Model"}),e.jsxs("select",{ref:v=>F=v,className:"select",defaultValue:"",children:[e.jsx("option",{value:"",children:"(provider default)"}),$t.map(v=>e.jsx("option",{value:v,children:v},v))]})]}),e.jsxs("div",{className:"task-form-field",children:[e.jsx("label",{className:"field-label",children:"Mode"}),e.jsxs("select",{ref:v=>w=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",children:"Color"}),e.jsx("input",{ref:v=>E=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",children:"Category"}),e.jsxs("select",{ref:v=>B=v,className:"select",defaultValue:"",children:[e.jsx("option",{value:"",children:"(none)"}),Ls.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",children:"Tags (comma-separated)"}),e.jsx("input",{ref:v=>R=v,className:"input",type:"text",placeholder:"reasoning, code, planning"})]})]}),e.jsx("label",{className:"field-label",children:"Tools"}),e.jsx("div",{ref:v=>z=v,className:"agent-tools",children:Mt.map(v=>e.jsxs("label",{className:"checkbox-row",children:[e.jsx("input",{type:"checkbox",value:v}),e.jsx("span",{children:v})]},v))}),e.jsx("label",{className:"field-label",children:"System prompt"}),e.jsx("textarea",{ref:v=>A=v,className:"textarea",rows:6,placeholder:"You are a..."})]}),footer:e.jsxs("div",{className:"modal-footer-actions",children:[e.jsx(T,{variant:"ghost",onClick:()=>i.close(),children:"Cancel"}),e.jsxs(T,{variant:"primary",onClick:async()=>{const v=((N==null?void 0:N.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 O=[];z&&z.querySelectorAll('input[type="checkbox"]:checked').forEach(M=>{O.push(M.value)});const K=((R==null?void 0:R.value)||"").split(",").map(M=>M.trim()).filter(Boolean);try{const M=await S.post("/agents",{name:v,description:((I==null?void 0:I.value)||"").trim(),model:(F==null?void 0:F.value)||"",mode:(w==null?void 0:w.value)||"subagent",color:(E==null?void 0:E.value)||"",tools:O,tags:K,category:(B==null?void 0:B.value)||"",prompt:(A==null?void 0:A.value)||""});l(W=>[...W,M]),a.success("Agent created."),i.close(),await t()}catch(M){a.error(`Create failed: ${M.message}`)}},children:[e.jsx(vs,{size:12})," Create"]})]})})},y=async N=>{let I=null,F=null,w=null,E=null,A=null,z=null,R=null,B=null;try{const v=await S.get(`/agents/${encodeURIComponent(N.name)}`);i.open({title:`Edit ${N.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",children:"Description"}),e.jsx("input",{ref:O=>{I=O},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",children:"Model"}),e.jsxs("select",{ref:O=>F=O,className:"select",defaultValue:v.model,children:[e.jsx("option",{value:"",children:"(provider default)"}),$t.map(O=>e.jsx("option",{value:O,children:O},O))]})]}),e.jsxs("div",{className:"task-form-field",children:[e.jsx("label",{className:"field-label",children:"Mode"}),e.jsxs("select",{ref:O=>w=O,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",children:"Color"}),e.jsx("input",{ref:O=>E=O,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",children:"Category"}),e.jsxs("select",{ref:O=>B=O,className:"select",defaultValue:v.category||"",children:[e.jsx("option",{value:"",children:"(none)"}),Ls.map(O=>e.jsx("option",{value:O.id,children:O.label},O.id))]})]}),e.jsxs("div",{className:"task-form-field",style:{flex:2},children:[e.jsx("label",{className:"field-label",children:"Tags (comma-separated)"}),e.jsx("input",{ref:O=>R=O,className:"input",type:"text",defaultValue:(v.tags||[]).join(", ")})]})]}),e.jsx("label",{className:"field-label",children:"Tools"}),e.jsx("div",{ref:O=>z=O,className:"agent-tools",children:Mt.map(O=>{var K;return e.jsxs("label",{className:"checkbox-row",children:[e.jsx("input",{type:"checkbox",value:O,defaultChecked:(K=v.tools)==null?void 0:K.includes(O)}),e.jsx("span",{children:O})]},O)})}),e.jsx("label",{className:"field-label",children:"System prompt"}),e.jsx("textarea",{ref:O=>A=O,className:"textarea",rows:8,defaultValue:v.prompt||""})]}),footer:e.jsxs("div",{className:"modal-footer-actions",children:[e.jsx(T,{variant:"ghost",onClick:()=>i.close(),children:"Cancel"}),e.jsxs(T,{variant:"primary",onClick:async()=>{const O=[];z&&z.querySelectorAll('input[type="checkbox"]:checked').forEach(M=>{O.push(M.value)});const K=((R==null?void 0:R.value)||"").split(",").map(M=>M.trim()).filter(Boolean);try{const M=await S.put(`/agents/${encodeURIComponent(N.name)}`,{description:((I==null?void 0:I.value)||"").trim(),model:(F==null?void 0:F.value)||"",mode:(w==null?void 0:w.value)||"subagent",color:(E==null?void 0:E.value)||"",tools:O,tags:K,category:(B==null?void 0:B.value)||"",prompt:(A==null?void 0:A.value)||""});l(W=>W.map(te=>te.name===N.name?M:te)),a.success("Agent saved."),i.close(),await t()}catch(M){a.error(`Save failed: ${M.message}`)}},children:[e.jsx(vs,{size:12})," Save"]})]})})}catch(v){a.error(`Load failed: ${v.message}`)}},$=async N=>{if(confirm(`Delete agent "${N.name}"? This removes ${N.path}.`))try{await S.del(`/agents/${encodeURIComponent(N.name)}`),l(I=>I.filter(F=>F.name!==N.name)),a.success("Agent deleted.")}catch(I){a.error(`Delete failed: ${I.message}`)}},b=async N=>{let I=null;i.open({title:`Invoke ${N.name}`,children:e.jsxs("div",{className:"invoke-form",children:[e.jsxs("p",{className:"muted invoke-form-meta mono",children:[N.model||"—"," · ",N.path]}),e.jsx("p",{className:"invoke-form-desc",children:N.description}),e.jsx("label",{className:"field-label",htmlFor:"invoke-prompt",children:"Prompt"}),e.jsx("textarea",{ref:F=>I=F,id:"invoke-prompt",className:"textarea",rows:5,placeholder:"What should this agent do?",autoFocus:!0})]}),footer:e.jsxs("div",{className:"modal-footer-actions",children:[e.jsx(T,{variant:"ghost",onClick:()=>i.close(),children:"Cancel"}),e.jsxs(T,{variant:"primary",onClick:async()=>{const F=((I==null?void 0:I.value)||"").trim();if(!F){a.warning("Prompt is required.");return}try{await S.post(`/agents/${encodeURIComponent(N.name)}/invoke`,{prompt:F}),a.success(`Invoked ${N.name}.`),i.close()}catch(w){a.error(`Invoke failed: ${w.message}`)}},children:[e.jsx(Ns,{size:14})," Invoke"]})]})})},k=async N=>{try{const I=await S.post(`/agents/${encodeURIComponent(N.name)}/restart`);l(F=>F.map(w=>w.name===N.name?I:w)),a.success(`${N.name} restarted.`)}catch(I){a.error(`Restart failed: ${I.message}`)}},P=async(N,I)=>{try{const F=await S.post(`/agents/${encodeURIComponent(N.name)}/status`,{status:I});l(w=>w.map(E=>E.name===N.name?F:E))}catch(F){a.error(`Status update failed: ${F.message}`)}};return e.jsxs("div",{className:"view view-agents",children:[e.jsxs("header",{className:"view-header",children:[e.jsxs("div",{className:"view-header-text",children:[e.jsxs("h2",{className:"view-title",children:[e.jsx(qe,{size:18})," Agents (",u.length,")"]}),e.jsxs("p",{className:"view-subtitle",children:["The Norse pantheon — click ",e.jsx("kbd",{children:"Edit"})," to modify or ",e.jsx("kbd",{children:"Invoke"})," to dispatch."]})]}),e.jsxs("div",{className:"view-actions",children:[e.jsx("div",{className:"search-input",children:e.jsx("input",{className:"input",type:"text",placeholder:"Search…",value:x,onChange:N=>h(N.target.value)})}),e.jsxs("select",{className:"select select-sm",value:g,onChange:N=>m(N.target.value),children:[e.jsx("option",{value:"",children:"All categories"}),Ls.map(N=>e.jsx("option",{value:N.id,children:N.label},N.id)),e.jsx("option",{value:"__none__",children:"(no category)"})]}),e.jsxs(T,{variant:"secondary",size:"sm",onClick:d,children:[e.jsx(oe,{size:14})," Refresh"]}),e.jsxs(T,{variant:"primary",size:"sm",onClick:f,children:[e.jsx(Me,{size:14})," New agent"]})]})]}),j.length>0&&e.jsxs("div",{className:"agent-tags-row",children:[e.jsx(Zt,{size:12}),j.map(N=>e.jsx("span",{className:"tag",children:N},N))]}),o?e.jsx("div",{className:"view-loading",children:e.jsx(he,{size:"lg"})}):u.length===0?e.jsx(we,{icon:e.jsx(qe,{size:32}),title:"No agents found",message:"Run bizar in the terminal to install Bizar."}):e.jsx("div",{className:"agent-grid",children:u.map(N=>e.jsx($i,{agent:N,onInvoke:()=>b(N),onEdit:()=>y(N),onDelete:()=>$(N),onRestart:()=>k(N),onSetStatus:I=>P(N,I)},N.name))})]})}function $i({agent:s,onInvoke:t,onEdit:a,onDelete:i,onRestart:n,onSetStatus:l}){const[o,c]=r.useState(!1),g=Ci(s.category),m=(s.status==="working"||!!s.currentTaskId)&&!s.isStuck;return e.jsxs(J,{variant:"elevated",interactive:!0,className:Z("agent-card",m&&"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(zi,{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, ${g} 18%, transparent)`,color:g},children:s.category}),e.jsx(Ti,{agent:s})]})]}),e.jsx("p",{className:"agent-card-desc",children:Ut(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(x=>e.jsx("span",{className:"agent-card-tag",children:x},x))}),(m||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(Va,{size:12}),e.jsx("span",{className:"muted",children:"Success rate"}),e.jsxs("span",{className:"tabular-nums",children:[Math.round((s.successRate||0)*100),"%"]}),e.jsxs("span",{className:"muted tabular-nums",children:["(",s.tasksSucceeded,"/",s.tasksTotal,")"]})]})]}),s.lastError&&e.jsxs("div",{className:"agent-card-error",children:[e.jsx(ke,{size:12}),e.jsxs("span",{className:"muted",children:["Last error: ",s.lastError.message]})]}),e.jsxs("div",{className:"agent-card-actions",children:[e.jsxs(T,{variant:"primary",size:"sm",onClick:t,children:[e.jsx(Ns,{size:12})," Invoke"]}),e.jsxs(T,{variant:"secondary",size:"sm",onClick:a,children:[e.jsx(ks,{size:12})," Edit"]}),(s.isStuck||s.status==="working"||s.status==="error")&&e.jsxs(T,{variant:"ghost",size:"sm",onClick:n,title:"Reset agent status",children:[e.jsx(ut,{size:12})," Restart"]}),e.jsx(T,{variant:"ghost",size:"sm",onClick:i,children:e.jsx(Re,{size:12})}),e.jsx("button",{type:"button",className:"icon-btn","aria-label":o?"Collapse":"Expand",onClick:()=>c(x=>!x),style:{marginLeft:"auto"},children:o?e.jsx(Oe,{size:12}):e.jsx(He,{size:12})})]}),o&&e.jsxs("div",{className:"agent-card-expanded",children:[e.jsxs("div",{className:"agent-card-status-actions",children:[e.jsx("span",{className:"muted text-sm",children:"Set status:"}),e.jsx(T,{variant:s.status==="idle"?"primary":"ghost",size:"sm",onClick:()=>l("idle"),children:"Idle"}),e.jsx(T,{variant:s.status==="working"?"primary":"ghost",size:"sm",onClick:()=>l("working"),children:"Working"}),e.jsx(T,{variant:s.status==="error"?"primary":"ghost",size:"sm",onClick:()=>l("error"),children:"Error"})]}),e.jsxs("div",{className:"agent-card-meta",children:[e.jsx(Ee,{size:11}),e.jsx("code",{className:"mono agent-card-path",children:s.path})]})]})]})}function Ri({id:s,children:t}){return e.jsx("div",{id:s,"data-block-id":s,className:Z("glyph-richtext"),style:ta,children:e.jsx(qt,{remarkPlugins:[_t],children:t})})}const Ai={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:Ye,label:"Danger"}};function Ii({id:s,tone:t="info",children:a}){const i=Ai[t],n=i.icon;return e.jsxs("div",{id:s,"data-block-id":s,className:Z("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:{...ta,fontSize:14},children:e.jsx(qt,{remarkPlugins:[_t],children:a})})]})]})}function Li({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(tt,{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 Ei({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,o)=>e.jsx("td",{style:{padding:"8px 12px",color:"var(--text)",verticalAlign:"top",wordBreak:"break-word"},children:l},o))},n))})]})})}function Di({id:s,tabs:t}){var l;const[a,i]=r.useState(((l=t[0])==null?void 0:l.id)??""),n=r.useMemo(()=>t.find(o=>o.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(o=>{const c=o.id===(n==null?void 0:n.id);return e.jsxs("button",{type:"button",role:"tab","aria-selected":c,onClick:()=>i(o.id),style:{padding:"6px 12px",fontSize:12,fontFamily:"var(--font-mono)",borderRadius:6,border:"none",cursor:"pointer",background:c?"var(--bg-elev)":"transparent",color:c?"var(--text-strong)":"var(--text-dim)",boxShadow:c?"0 0 0 1px var(--border)":"none",whiteSpace:"nowrap"},children:[e.jsx("span",{children:o.label}),o.language&&e.jsx("span",{style:{marginLeft:6,color:"var(--text-dim)",fontSize:11},children:o.language})]},o.id)})}),n&&e.jsxs(e.Fragment,{children:[e.jsx("pre",{style:{margin:0,padding:14,overflowX:"auto",fontFamily:"var(--font-mono)",fontSize:12.5,lineHeight:1.55,color:"var(--text)",background:"var(--bg-elev)"},children:e.jsx("code",{children:n.code})}),n.caption&&e.jsx("div",{style:{padding:"8px 14px",borderTop:"1px solid var(--border)",fontSize:12,color:"var(--text-dim)",background:"var(--bg)"},children:n.caption})]})]})}function Pi({id:s,title:t,question:a,options:i}){return e.jsxs("div",{id:s,"data-block-id":s,className:"glyph-decision",style:{margin:"16px 0",padding:16,border:"1px solid var(--border)",borderRadius:10,background:"var(--bg-elev)"},children:[t&&e.jsx("h3",{style:{margin:0,marginBottom:4,fontSize:15,fontWeight:600,color:"var(--text-strong)"},children:t}),a&&e.jsx("p",{style:{margin:0,marginBottom:12,fontSize:13,color:"var(--text-dim)"},children:a}),e.jsx("div",{style:{display:"grid",gap:10,gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))"},children:i.map(n=>{const l=!!n.recommended;return e.jsxs("div",{style:{position:"relative",padding:12,borderRadius:8,border:l?"2px solid var(--success)":"1px solid var(--border)",background:l?"var(--success-soft)":"var(--bg)"},children:[l&&e.jsx("span",{style:{position:"absolute",top:-10,right:10,padding:"2px 8px",fontSize:11,fontWeight:600,color:"var(--bg)",background:"var(--success)",borderRadius:999},children:"Recommended"}),e.jsx("div",{style:{fontWeight:600,fontSize:14,color:"var(--text-strong)",marginBottom:4},children:n.label}),e.jsx("div",{style:{fontSize:13,color:"var(--text)"},children:n.detail})]},n.id)})})]})}function Oi({id:s,questions:t}){const[a,i]=r.useState({});function n(l,o){i(c=>({...c,[l]:o}))}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:o=>n(l.id,o.target.value),style:Rt,children:[e.jsx("option",{value:"",children:"— select —"}),(l.options??[]).map(o=>e.jsx("option",{value:o,children:o},o))]}),l.kind==="text"&&e.jsx("input",{id:`oq-${l.id}`,type:"text",value:a[l.id]??"",onChange:o=>n(l.id,o.target.value),style:Rt}),l.kind==="multi"&&e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4},children:(l.options??[]).map(o=>{const c=a[l.id]??[],g=c.includes(o);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:g,onChange:()=>{const m=g?c.filter(x=>x!==o):[...c,o];n(l.id,m)}}),e.jsx("span",{children:o})]},o)})})]},l.id))]})}const Rt={padding:"6px 10px",fontSize:13,borderRadius:6,border:"1px solid var(--border-strong)",background:"var(--bg)",color:"var(--text)",fontFamily:"inherit"},Fi={added:{bg:"var(--success-soft)",fg:"var(--success)",label:"A"},modified:{bg:"var(--info-soft, rgba(96, 165, 250, 0.12))",fg:"var(--info)",label:"M"},removed:{bg:"var(--error-soft)",fg:"var(--error)",label:"D"},renamed:{bg:"rgba(139, 92, 246, 0.15)",fg:"var(--accent)",label:"R"}};function Bi({id:s,title:t,entries:a}){return e.jsxs("div",{id:s,"data-block-id":s,className:"glyph-filetree",style:{margin:"12px 0",padding:t?14:8,border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-elev)"},children:[t&&e.jsx("div",{style:{fontSize:12,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:.4,marginBottom:8},children:t}),e.jsx("ul",{style:{listStyle:"none",padding:0,margin:0,display:"flex",flexDirection:"column",gap:2},children:a.map(i=>{const n=Fi[i.change];return e.jsxs("li",{style:{display:"flex",alignItems:"center",gap:10,padding:"5px 8px",borderRadius:5,fontSize:13},children:[e.jsx("span",{"aria-label":i.change,title:i.change,style:{flexShrink:0,width:22,height:18,borderRadius:4,background:n.bg,color:n.fg,display:"inline-flex",alignItems:"center",justifyContent:"center",fontSize:10,fontWeight:700,fontFamily:"var(--font-mono)"},children:n.label}),e.jsx("span",{style:{fontFamily:"var(--font-mono)",color:"var(--text)",wordBreak:"break-all",flex:1},children:i.path}),i.note&&e.jsx("span",{style:{fontSize:12,color:"var(--text-dim)"},children:i.note})]},i.path)})})]})}function Ui({id:s,filename:t,language:a,mode:i="unified",before:n,after:l}){const o=n.split(`
|
|
349
|
+
`),c=l.split(`
|
|
350
|
+
`),g=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(Ya,{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})]}),m={margin:0,padding:0,fontFamily:"var(--font-mono)",fontSize:12.5,lineHeight:1.55,color:"var(--text)",background:"var(--bg-elev)"},x=(h,d,u)=>{const j={del:"var(--error-soft)",add:"var(--success-soft)",ctx:"transparent"},f={del:"var(--error)",add:"var(--success)",ctx:"var(--text-dim)"};return e.jsxs("div",{style:{display:"flex",padding:"0 12px",background:j[u]},children:[e.jsx("span",{style:{width:18,color:f[u],userSelect:"none",flexShrink:0},children:h}),e.jsx("span",{style:{whiteSpace:"pre",flex:1,overflowX:"auto"},children:d||" "})]})};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:[g,i==="unified"?e.jsxs("pre",{style:m,children:[o.map((h,d)=>e.jsx("div",{children:x("-",h,"del")},`b${d}`)),c.map((h,d)=>e.jsx("div",{children:x("+",h,"add")},`a${d}`))]}):e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr"},children:[e.jsx("pre",{style:{...m,borderRight:"1px solid var(--border)"},children:o.map((h,d)=>e.jsx("div",{children:x("-",h,"del")},d))}),e.jsx("pre",{style:m,children:c.map((h,d)=>e.jsx("div",{children:x("+",h,"add")},d))})]})]})}const qi={up:{fg:"var(--success)",Icon:Oe,label:"trending up"},down:{fg:"var(--error)",Icon:Oe,label:"trending down"},flat:{fg:"var(--text-dim)",Icon:dn,label:"flat"}};function _i({id:s,label:t,value:a,trend:i,hint:n}){const l=i?qi[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===Oe&&i==="up"?"rotate(180deg)":void 0},children:e.jsx(l.Icon,{size:14})})]}),n&&e.jsx("div",{style:{fontSize:12,color:"var(--text-dim)"},children:n})]})}const Hi={task:{stroke:"var(--info)",fill:"var(--bg-elev)",fg:"var(--text)"},decision:{stroke:"var(--warning)",fill:"var(--bg-elev)",fg:"var(--text)"},note:{stroke:"var(--border-strong)",fill:"var(--bg)",fg:"var(--text-dim)"}},Ce=160,Ie=56,Je=60,es=80;function Wi({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(Vi,{id:s})});const i=new Map(t.map(x=>[x.id,x])),n=Ki(t),l=Math.max(...n.map(x=>x.col))+1,o=Math.max(...n.map(x=>x.row))+1,c=l*(Ce+Je)+Je,g=o*(Ie+es)+es;function m(x){if(!i.get(x))return null;const d=n.find(u=>u.id===x);return d?{x:Je+d.col*(Ce+Je)+Ce/2,y:es+d.row*(Ie+es)+Ie/2}:null}return e.jsx("div",{id:s,"data-block-id":s,className:"glyph-workflow",style:{margin:"12px 0",padding:12,border:"1px solid var(--border)",borderRadius:10,background:"var(--bg-elev)",overflow:"auto"},children:e.jsxs("svg",{role:"img","aria-label":"Workflow diagram",width:c,height:g,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((x,h)=>{const d=m(x.from),u=m(x.to);if(!d||!u)return null;const j=u.x-d.x,f=u.y-d.y,y=j>=0?d.x+Ce/2:d.x-Ce/2,$=j>=0?u.x-Ce/2:u.x+Ce/2,b=f>=0?d.y+Ie/2:d.y-Ie/2,k=f>=0?u.y-Ie/2:u.y+Ie/2,P=(y+$)/2,N=(b+k)/2;return e.jsxs("g",{children:[e.jsx("line",{x1:y,y1:b,x2:$,y2:k,stroke:"var(--text-dim)",strokeWidth:1.5,markerEnd:`url(#arrow-${s})`}),x.label&&e.jsx("text",{x:P,y:N-4,fontSize:10,fill:"var(--text-dim)",textAnchor:"middle",fontFamily:"var(--font-mono)",children:x.label})]},h)}),t.map(x=>{const h=n.find(y=>y.id===x.id);if(!h)return null;const d=Je+h.col*(Ce+Je),u=es+h.row*(Ie+es),j=Hi[x.type];if(x.type==="decision"){const y=d+Ce/2,$=u+Ie/2,b=[[y,u],[d+Ce,$],[y,u+Ie],[d,$]].map(k=>k.join(",")).join(" ");return e.jsxs("g",{children:[e.jsx("polygon",{points:b,fill:j.fill,stroke:j.stroke,strokeWidth:2}),e.jsx("foreignObject",{x:d+8,y:$-14,width:Ce-16,height:28,children:e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",gap:4,fontSize:12,color:j.fg,textAlign:"center",lineHeight:1.2,fontStyle:"italic",height:"100%"},children:[e.jsx(Ka,{size:11}),x.label]})})]},x.id)}const f=x.type==="note";return e.jsxs("g",{children:[e.jsx("rect",{x:d,y:u,width:Ce,height:Ie,rx:8,fill:j.fill,stroke:j.stroke,strokeWidth:f?1:2,strokeDasharray:f?"4 3":void 0}),e.jsx("foreignObject",{x:d+6,y:u+6,width:Ce-12,height:Ie-12,children:e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",gap:6,fontSize:12,color:j.fg,textAlign:"center",lineHeight:1.25,fontStyle:f?"italic":"normal",height:"100%"},children:[f&&e.jsx(Sa,{size:11}),x.label]})})]},x.id)})]})})}function Vi({id:s}){return e.jsx("div",{id:s,style:{padding:20,textAlign:"center",color:"var(--text-dim)",fontSize:13},children:"No workflow steps."})}function Ki(s){return s.length===0?[]:s.map((t,a)=>({id:t.id,col:a,row:0}))}const ta={fontSize:14,lineHeight:1.6,color:"var(--text)"};function Gi({id:s,title:t,x:a,y:i,w:n,h:l,html:o}){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:o}})]})]})}class Yi extends We.Component{constructor(){super(...arguments);cs(this,"state",{err:null})}static getDerivedStateFromError(a){return{err:a}}componentDidCatch(a,i){try{this.props.onError(this.props.blockId,this.props.blockType,a,i)}catch{}}render(){return this.state.err?e.jsxs("div",{className:"glyph-block-error",role:"alert",style:{border:"1px solid var(--error, #f85149)",background:"rgba(248, 81, 73, 0.06)",borderRadius:8,padding:"12px 14px",margin:"12px 0",color:"var(--text)",fontFamily:"var(--font-mono, ui-monospace, monospace)",fontSize:12,lineHeight:1.55},children:[e.jsxs("strong",{style:{color:"var(--error, #f85149)",fontFamily:"var(--font-sans, system-ui, sans-serif)",display:"block",marginBottom:4},children:[this.props.blockType," block crashed"]}),e.jsxs("div",{style:{color:"var(--text-muted)",marginBottom:6},children:["block id: ",e.jsx("code",{children:this.props.blockId})]}),e.jsx("pre",{style:{margin:0,whiteSpace:"pre-wrap",wordBreak:"break-word",color:"var(--text)"},children:this.state.err.message})]}):this.props.children}}function Qi(s){const t=s.data??{};switch(s.type){case"RichText":return{ok:!0};case"Callout":return{ok:!0};case"Checklist":return Array.isArray(t.items)?{ok:!0}:{ok:!1,error:"Checklist requires data.items to be an array"};case"Table":return Array.isArray(t.columns)?Array.isArray(t.rows)?t.rows.length>0&&!Array.isArray(t.rows[0])?{ok:!1,error:"Table.data.rows[0] must be an array (cell array)"}:{ok:!0}:{ok:!1,error:"Table requires data.rows to be an array"}:{ok:!1,error:"Table requires data.columns to be an array"};case"CodeTabs":return Array.isArray(t.tabs)?{ok:!0}:{ok:!1,error:"CodeTabs requires data.tabs to be an array"};case"Decision":return Array.isArray(t.options)?{ok:!0}:{ok:!1,error:"Decision requires data.options to be an array"};case"OpenQuestions":return Array.isArray(t.questions)?{ok:!0}:{ok:!1,error:"OpenQuestions requires data.questions to be an array"};case"FileTree":if(!Array.isArray(t.entries))return{ok:!1,error:"FileTree requires data.entries to be an array"};for(const a of t.entries)if(a===null||typeof a!="object"||Array.isArray(a))return{ok:!1,error:`FileTree contains a malformed entry: ${JSON.stringify(a)}`};return{ok:!0};case"Diff":return typeof t.before!="string"?{ok:!1,error:"Diff requires data.before to be a string"}:typeof t.after!="string"?{ok:!1,error:"Diff requires data.after to be a string"}:{ok:!0};case"Stat":return t.label===void 0||t.label===null?{ok:!1,error:"Stat requires data.label"}:t.value===void 0||t.value===null?{ok:!1,error:"Stat requires data.value"}:{ok:!0};case"Workflow":return Array.isArray(t.steps)?{ok:!0}:{ok:!1,error:"Workflow requires data.steps to be an array"};case"Mockup":return typeof t.html!="string"?{ok:!1,error:"Mockup requires data.html to be a string"}:{ok:!0};case"Diagram":return typeof t.dataHtml!="string"?{ok:!1,error:"Diagram requires data.dataHtml to be a string"}:{ok:!0};default:return{ok:!1,error:`Unknown block type: ${s.type}`}}}const Xi={overview:"Overview",implementation:"Implementation plan","implementation-plan":"Implementation plan",questions:"Open questions","open-questions":"Open questions","open-questions-for-you":"Open questions",comments:"Comments",handoff:"Handoff"};function Zi(s){const t=[];let a={heading:null,blocks:[]};for(const i of s){const n=Xi[i.id]??null;n?((a.blocks.length>0||a.heading!==null)&&t.push(a),a={heading:n,blocks:[i]}):a.blocks.push(i)}return(a.blocks.length>0||a.heading!==null)&&t.push(a),t}function Ji({slug:s,onClose:t,onCommentAdded:a}){var Q,ie,xe,V;const i=ce(),[n,l]=r.useState(null),[o,c]=r.useState([]),[g,m]=r.useState(!0),[x,h]=r.useState(null),[d,u]=r.useState(null),[j,f]=r.useState(!1),[y,$]=r.useState(!1),[b,k]=r.useState(null),[P,N]=r.useState(null),[I,F]=r.useState(""),[w,E]=r.useState(null),[A,z]=r.useState([]),R=We.useCallback((L,U,p)=>{z(q=>q.some(H=>H.blockId===L)?q:[...q,{blockId:L,blockType:U,message:p.message||String(p)}])},[]),B=r.useRef(null),v=r.useMemo(()=>n?Zi(n.blocks):[],[n]);r.useEffect(()=>{let L=!1;const U=5e3;return(async()=>{m(!0),h(null);try{const p=new Promise((le,ae)=>setTimeout(()=>ae(new Error("Request timed out after 5s")),U)),[q,H]=await Promise.race([Promise.all([S.get(`/artifacts/${encodeURIComponent(s)}/render`),S.get(`/artifacts/${encodeURIComponent(s)}`)]),p]);if(L)return;l(q);const D=(H==null?void 0:H.comments)??[];c(Array.isArray(D)?D:[])}catch(p){if(!L){const q=p.message;h(q),u(q)}}finally{L||m(!1)}})(),()=>{L=!0}},[s]);function O(L){if(!B.current)return;L.preventDefault();const U=B.current.getBoundingClientRect();k({x:L.clientX,y:L.clientY,worldX:L.clientX-U.left,worldY:L.clientY-U.top})}async function K(){if(!(!P||!I.trim()))try{const L=await S.post(`/artifacts/${encodeURIComponent(s)}/comments`,{x:P.worldX,y:P.worldY,text:I.trim(),author:"drb0rk"});c(U=>[...U,{id:L.id??`cmt_${Date.now()}`,x:P.worldX,y:P.worldY,text:I.trim(),author:"drb0rk",created:new Date().toISOString()}]),N(null),F(""),k(null),a==null||a(),i.success("Comment added")}catch(L){i.error(`Failed to add comment: ${L.message}`)}}async function M(){if(!j){f(!0);try{const L=await S.post(`/artifacts/${encodeURIComponent(s)}/submit`,{answers:[],submitter:"drb0rk"});L!=null&&L.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(L){i.error(`Submit failed: ${L.message}`)}finally{f(!1)}}}function W(){$(L=>!L)}const te=L=>{const U=L.id,p=L.data??{},q=Qi(L);return q.ok?e.jsx(Yi,{blockId:U,blockType:L.type,onError:R,children:ee(L,U,p)},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:[L.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:q.error})]},U)},ee=(L,U,p)=>{switch(L.type){case"RichText":return e.jsx(Ri,{id:U,children:L.childrenMarkdown??""},U);case"Callout":return e.jsx(Ii,{id:U,tone:p.tone??"info",children:L.childrenMarkdown??""},U);case"Checklist":return e.jsx(Li,{id:U,items:p.items??[]},U);case"Table":return e.jsx(Ei,{id:U,columns:p.columns??[],rows:p.rows??[]},U);case"CodeTabs":return e.jsx(Di,{id:U,tabs:p.tabs??[]},U);case"Decision":return e.jsx(Pi,{id:U,title:p.title,question:p.question,options:p.options??[]},U);case"OpenQuestions":return e.jsx(Oi,{id:U,questions:p.questions??[]},U);case"FileTree":return e.jsx(Bi,{id:U,title:p.title,entries:p.entries??[]},U);case"Diff":return e.jsx(Ui,{id:U,filename:p.filename,language:p.language,mode:p.mode??"unified",before:p.before??"",after:p.after??""},U);case"Stat":return e.jsx(_i,{id:U,label:p.label??"",value:p.value,trend:p.trend,hint:p.hint},U);case"Workflow":return e.jsx(Wi,{id:U,steps:p.steps??[],connections:p.connections},U);case"Mockup":return e.jsx(Gi,{id:U,title:p.title,x:p.x,y:p.y,w:p.w,h:p.h,html:p.html??""},U);case"Diagram":return e.jsx("div",{id:U,className:"glyph-block-placeholder",children:e.jsxs("em",{children:["[Diagram] ",U]})},U)}};if(g)return e.jsx("div",{className:"glyph-renderer glyph-renderer--loading",children:d?e.jsxs(e.Fragment,{children:[e.jsx("strong",{children:"Failed to load glyph."}),e.jsx("pre",{children:d})]}):e.jsxs(e.Fragment,{children:[e.jsx(er,{})," Loading glyph…"]})});if(x||!n)return e.jsxs("div",{className:"glyph-renderer glyph-renderer--error",children:[e.jsx("strong",{children:"Failed to load glyph."}),e.jsx("pre",{children:x??"unknown error"})]});const _=((Q=n.frontmatter)==null?void 0:Q.title)??s,Y=((ie=n.frontmatter)==null?void 0:ie.status)??"draft",se=o.length;return e.jsxs("div",{className:`glyph-canvas ${y?"glyph-canvas--fullscreen":""}`,ref:B,onContextMenu:O,children:[e.jsxs("div",{className:"glyph-toolbar-floating",children:[e.jsxs("button",{className:"glyph-btn glyph-btn--primary glyph-btn--send",onClick:M,disabled:j,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(yn,{size:15})}),e.jsx("button",{className:"glyph-icon-btn",title:"Undo",disabled:!0,children:e.jsx(Sn,{size:15})}),e.jsx("button",{className:"glyph-icon-btn",title:"Redo",disabled:!0,children:e.jsx(vn,{size:15})}),e.jsx("button",{className:"glyph-icon-btn",title:y?"Exit fullscreen":"Fullscreen",onClick:W,children:e.jsx(cn,{size:15})}),e.jsx("button",{className:"glyph-icon-btn",title:"More",children:e.jsx(Ga,{size:15})}),e.jsx("span",{className:"glyph-toolbar-divider"}),e.jsxs("button",{className:"glyph-icon-btn",title:"Comment count","aria-label":"Comment count",children:[e.jsx(qs,{size:15}),e.jsx("span",{className:"glyph-icon-btn-count",children:se})]}),t&&e.jsx("button",{className:"glyph-icon-btn glyph-icon-btn--close",title:"Close",onClick:t,"aria-label":"Close",children:e.jsx($e,{size:15})})]}),e.jsxs("div",{className:"glyph-canvas-content",children:[e.jsxs("header",{className:"glyph-canvas-title",children:[e.jsx("h1",{className:"glyph-title",children:_}),e.jsxs("div",{className:"glyph-meta",children:[e.jsx("span",{className:`glyph-status glyph-status--${Y}`,children:Y}),e.jsx("span",{className:"glyph-slug",children:s})]})]}),(A.length>0||((xe=n.errors)==null?void 0:xe.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:A.length>0?`${A.length} block${A.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:[A.map((L,U)=>e.jsxs("li",{children:[e.jsx("strong",{children:L.blockType})," (",e.jsx("code",{children:L.blockId}),"): ",L.message]},`be-${U}`)),(V=n.errors)==null?void 0:V.map((L,U)=>e.jsxs("li",{children:[L.line?`line ${L.line}: `:"",L.message]},`ce-${U}`))]})]}),e.jsx("div",{className:"glyph-sections",children:v.map((L,U)=>e.jsxs("section",{className:`glyph-section ${L.heading?"glyph-section--headed":"glyph-section--plain"}`,children:[L.heading&&e.jsx("h2",{className:"glyph-section-heading",children:L.heading}),e.jsx("div",{className:"glyph-section-blocks",children:L.blocks.map(te)})]},`sec-${U}-${L.heading??"ungrouped"}`))})]}),o.map(L=>e.jsxs("button",{className:`glyph-pin ${w===L.id?"glyph-pin--active":""}`,style:{left:L.x,top:L.y},onClick:U=>{U.stopPropagation(),E(w===L.id?null:L.id)},title:L.text,children:[e.jsx(Ct,{size:14}),w===L.id&&e.jsxs("div",{className:"glyph-pin-thread",children:[e.jsx("div",{className:"glyph-pin-text",children:L.text}),e.jsxs("div",{className:"glyph-pin-meta",children:[L.author??"anonymous"," · ",L.created?new Date(L.created).toLocaleString():""]})]})]},L.id)),b&&e.jsx("div",{className:"glyph-ctx-menu",style:{left:b.x,top:b.y},onClick:L=>L.stopPropagation(),children:e.jsxs("button",{className:"glyph-ctx-item",onClick:()=>{N({worldX:b.worldX,worldY:b.worldY}),k(null)},children:[e.jsx(Ct,{size:14})," Add comment here"]})}),P&&e.jsx("div",{className:"glyph-modal-overlay",onClick:()=>N(null),children:e.jsxs("div",{className:"glyph-modal",onClick:L=>L.stopPropagation(),children:[e.jsxs("h3",{children:["Add comment at (",Math.round(P.worldX),", ",Math.round(P.worldY),")"]}),e.jsx("textarea",{autoFocus:!0,value:I,onChange:L=>F(L.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:()=>N(null),children:"Cancel"}),e.jsx("button",{className:"glyph-btn glyph-btn--primary",onClick:K,disabled:!I.trim(),children:"Add comment"})]})]})})]})}function er(){return e.jsx("span",{className:"glyph-spinner","aria-label":"loading",children:"…"})}function sr(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 tr({snapshot:s,refreshSnapshot:t}){const a=ce(),[i,n]=r.useState(s.artifacts||[]),[l,o]=r.useState(!s.artifacts),[c,g]=r.useState(null),[m,x]=r.useState(""),[h,d]=r.useState(!1);r.useEffect(()=>{s.artifacts&&(n(s.artifacts),o(!1))},[s.artifacts]);const u=async()=>{try{const $=await S.get("/artifacts");n($.artifacts||[]),o(!1)}catch($){a.error(`Artifacts load failed: ${$.message}`),o(!1)}},j=r.useMemo(()=>{let $=i;if(m){const b=m.toLowerCase();$=$.filter(k=>(k.slug||"").toLowerCase().includes(b)||(k.title||"").toLowerCase().includes(b))}return h||($=$.filter(b=>b.status!=="archived")),$},[i,m,h]),f=async($,b)=>{try{const k=await S.post("/artifacts",{slug:$,title:b});a.success(`Artifact "${k.slug}" created.`),g(k.slug),await u()}catch(k){a.error(`Create failed: ${k.message}`)}},y=async $=>{if(confirm(`Delete artifact "${$}"? This removes the directory permanently.`))try{await S.del(`/artifacts/${encodeURIComponent($)}`),a.success("Artifact deleted."),c===$&&g(null),await u()}catch(b){a.error(`Delete failed: ${b.message}`)}};return c?e.jsxs("div",{className:"artifact-glyph-overlay",children:[e.jsx("div",{className:"artifact-glyph-toolbar",children:e.jsxs(T,{variant:"ghost",onClick:()=>{g(null),u()},children:[e.jsx(Gt,{size:14})," Back to artifacts"]})}),e.jsx(Ji,{slug:c,onClose:()=>{g(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(Fs,{size:18})," Glyphs (",i.length,")"]}),e.jsx("p",{className:"view-subtitle",children:"Visual artifacts with elements, connections, and threaded comments."})]}),e.jsxs("div",{className:"view-actions",children:[e.jsxs("div",{className:"search-input",children:[e.jsx(ye,{size:14}),e.jsx("input",{className:"input",type:"text",placeholder:"Search…",value:m,onChange:$=>x($.target.value)})]}),e.jsxs(T,{variant:"ghost",size:"sm",onClick:()=>d($=>!$),title:h?"Hide archived":"Show archived",children:[h?e.jsx(Vt,{size:14}):e.jsx(Ca,{size:14}),h?"Hide archived":"Show archived"]}),e.jsxs(T,{variant:"secondary",size:"sm",onClick:u,children:[e.jsx(oe,{size:14})," Refresh"]})]})]}),e.jsx(ar,{onCreate:f}),l?e.jsx("div",{className:"view-loading",children:e.jsx(he,{size:"lg"})}):j.length===0?e.jsx(we,{icon:e.jsx(Fs,{size:32}),title:h?"No artifacts":"No artifacts yet",message:h?"No artifacts match your filter (try Show archived off).":"Create one above to get started."}):e.jsx("div",{className:"artifacts-grid",children:j.map($=>e.jsx(nr,{artifact:$,onOpen:()=>g($.slug),onDelete:()=>y($.slug)},$.slug))})]})}function ar({onCreate:s}){const[t,a]=r.useState(""),[i,n]=r.useState("");return e.jsxs(J,{className:"new-artifact",children:[e.jsxs(ne,{children:[e.jsx(Me,{size:14})," New artifact"]}),e.jsx(re,{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("input",{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)}),e.jsx("input",{className:"input",type:"text",placeholder:"Title (optional)",value:i,onChange:l=>n(l.target.value)}),e.jsx(T,{variant:"primary",type:"submit",children:"Create"})]})]})}function nr({artifact:s,onOpen:t,onDelete:a}){const i=sr(s.status||"draft");return e.jsxs(J,{variant:"elevated",interactive:!0,className:"artifact-card",onClick:t,children:[e.jsxs("div",{className:"artifact-card-head",children:[e.jsx("div",{className:"artifact-card-title",children:s.title||s.slug}),e.jsx(ns,{kind:i,children:s.status||"draft"})]}),e.jsxs("div",{className:"artifact-card-slug mono",children:[s.slug," · ",s.source]}),e.jsxs("div",{className:"artifact-card-meta",children:[s.elementCount!=null&&e.jsxs("span",{children:[s.elementCount," elements"]}),s.commentCount!=null&&e.jsxs("span",{children:[" · ",s.commentCount," comments"]}),e.jsxs("span",{children:[" · edited ",Ne(s.mtime)]})]}),e.jsxs("div",{className:"artifact-card-actions",children:[e.jsxs(T,{variant:"primary",size:"sm",onClick:n=>{n.stopPropagation(),t()},children:["Open",e.jsx(He,{size:12})]}),e.jsxs(T,{variant:"ghost",size:"sm",onClick:n=>{n.stopPropagation(),a()},children:[e.jsx(Re,{size:12})," Delete"]})]})]})}function ir({children:s,className:t,onRemove:a}){return e.jsxs("span",{className:Z("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 rr({task:s,agents:t,onPromote:a,onDelete:i,onEdit:n,onRefresh:l}){var x;const o=ce(),c=async()=>{try{await S.post(`/tasks/${encodeURIComponent(s.id)}/promote`),o.success("Promoted to queued.",1500),a(s.id)}catch(h){o.error(`Promote failed: ${h.message}`)}},g=async()=>{if(confirm("Delete this task?"))try{await S.del(`/tasks/${encodeURIComponent(s.id)}`),o.success("Deleted.",1500),i(s.id)}catch(h){o.error(`Delete failed: ${h.message}`)}},m={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:m[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]}),((x=s.tags)==null?void 0:x.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:c,children:e.jsx(pt,{size:13})}),e.jsx("button",{type:"button",className:"icon-btn",title:"Edit",onClick:()=>n(s),children:e.jsx(Fe,{size:13})}),e.jsx("button",{type:"button",className:"icon-btn icon-btn-danger",title:"Delete",onClick:g,children:e.jsx(Re,{size:13})})]})]})]})}function lr({agents:s,onRefresh:t}){const a=ce(),[i,n]=r.useState([]),[l,o]=r.useState(!1),c=async()=>{try{o(!0);const d=await S.get("/tasks/backlog");n(Array.isArray(d.tasks)?d.tasks:[])}catch(d){a.error(`Backlog load failed: ${d.message}`)}finally{o(!1)}};r.useEffect(()=>{c()},[]);const g=async d=>{n(u=>u.filter(j=>j.id!==d)),await t()},m=async d=>{n(u=>u.filter(j=>j.id!==d)),await t()},x=d=>{},h=async()=>{var d;if(i.length!==0)try{const j=((d=(await S.post("/tasks/promote-batch",{ids:i.map(f=>f.id)})).affected)==null?void 0:d.filter(f=>f.ok).length)??0;a.success(`Promoted ${j} 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(T,{variant:"ghost",size:"sm",onClick:h,title:"Promote all to queued",children:[e.jsx(pt,{size:12})," Promote all"]}),e.jsx(T,{variant:"ghost",size:"sm",onClick:c,title:"Refresh backlog","aria-label":"Refresh backlog",children:e.jsx(oe,{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(d=>e.jsx(rr,{task:d,agents:s,onPromote:g,onDelete:m,onEdit:x,onRefresh:t},d.id))})]})}const Es=[{id:"queued",label:"Todo",kind:"info"},{id:"doing",label:"In progress",kind:"accent"},{id:"done",label:"Done",kind:"success"},{id:"blocked",label:"Failed",kind:"error"}],yt=["low","normal","high"];function or({snapshot:s,refreshSnapshot:t,setActiveTab:a}){const i=ce(),n=De(),[l,o]=r.useState(s.tasks||[]),[c,g]=r.useState(!s.tasks),[m,x]=r.useState(""),[h,d]=r.useState(""),[u,j]=r.useState(!1),[f,y]=r.useState(0),$=async()=>{try{const E=await S.get("/tasks");o(Array.isArray(E)?E:[])}catch(E){i.error(`Tasks load failed: ${E.message}`)}finally{g(!1)}};r.useEffect(()=>{s.tasks&&(o(s.tasks),g(!1))},[s.tasks]),r.useEffect(()=>{const E=setInterval(()=>y(A=>A+1),3e4);return()=>clearInterval(E)},[]);const b=r.useMemo(()=>{let E=l.filter(A=>A.status!=="backlog");if(h&&(E=E.filter(A=>(A.priority||"normal")===h)),m.trim()){const A=m.toLowerCase();E=E.filter(z=>(z.title||"").toLowerCase().includes(A)||(z.description||"").toLowerCase().includes(A))}return E},[l,m,h]),k=r.useMemo(()=>{const E={high:0,normal:1,low:2};return[...b].sort((A,z)=>{const R=E[A.priority]??1,B=E[z.priority]??1;return R!==B?R-B:new Date(z.createdAt).getTime()-new Date(A.createdAt).getTime()})},[b]),P=l.filter(E=>E.status==="backlog").length,N=async(E,A)=>{const z=l.find(B=>B.id===E);if(!z)return;const R=z.status;o(B=>B.map(v=>v.id===E?{...v,status:A}:v));try{await S.patch(`/tasks/${encodeURIComponent(E)}/status`,{status:A}),i.success(`Moved to ${A}.`,1200)}catch(B){o(v=>v.map(O=>O.id===E?{...O,status:R}:O)),i.error(`Move failed: ${B.message}`)}},I=async E=>{if(confirm("Delete this task?"))try{await S.del(`/tasks/${encodeURIComponent(E)}`),o(A=>A.filter(z=>z.id!==E)),i.success("Task deleted.",1200)}catch(A){i.error(`Delete failed: ${A.message}`)}},F=async E=>{try{const A=await S.post(`/tasks/${encodeURIComponent(E)}/start`);A&&A.task&&o(z=>z.map(R=>R.id===E?A.task:R)),i.success("Retry dispatched.",1200)}catch(A){i.error(`Retry failed: ${A.message}`)}},w=async E=>{const A=l.find(z=>z.id===E);if(A)try{const z=await S.post("/tasks/submit",{title:A.title,description:A.description,priority:A.priority,tags:A.tags}),R=(z.subtasks||[]).length;i.success(R>1?`Odin split it into ${R} subtasks.`:"Sent to Odin.",1500),z.subtasks&&z.subtasks.length>0&&o(B=>[z.main,...z.subtasks,...B.filter(v=>v.id!==A.id)]),await t()}catch(z){i.error(`Submit failed: ${z.message}`)}};return e.jsxs("div",{className:"view view-tasks",children:[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 (",k.length,")"]}),e.jsx("p",{className:"view-subtitle",children:"Add a task — title and description is all you need. Odin picks the agent and priority."})]})}),e.jsxs("div",{className:"tasks-toolbar",children:[e.jsx("div",{className:"tasks-toolbar-group",children:e.jsxs("div",{className:"search-input",style:{width:200},children:[e.jsx(ye,{size:12}),e.jsx("input",{className:"input",type:"text",placeholder:"Search…",value:m,onChange:E=>x(E.target.value)}),m&&e.jsx("button",{type:"button",className:"icon-btn","aria-label":"Clear search",onClick:()=>x(""),children:e.jsx($e,{size:12})})]})}),e.jsx("div",{className:"tasks-toolbar-divider"}),e.jsxs("div",{className:"tasks-toolbar-group",children:[e.jsx("span",{className:"tasks-toolbar-label",children:"Priority"}),e.jsxs("select",{className:"select select-sm",value:h,onChange:E=>d(E.target.value),title:"Filter by priority",children:[e.jsx("option",{value:"",children:"All"}),yt.map(E=>e.jsx("option",{value:E,children:E},E))]})]}),e.jsx("div",{className:"tasks-toolbar-spacer"}),e.jsxs("div",{className:"tasks-toolbar-group",children:[e.jsx(T,{variant:"ghost",size:"sm",onClick:$,title:"Refresh","aria-label":"Refresh tasks",children:e.jsx(oe,{size:14})}),P>0&&e.jsxs(T,{variant:u?"accent":"ghost",size:"sm",onClick:()=>j(E=>!E),title:u?"Hide backlog":"Show backlog",children:[e.jsx(Os,{size:14}),"Backlog",e.jsx("span",{className:"badge",children:P})]}),e.jsxs(T,{variant:"primary",size:"sm",onClick:()=>mr(n,i,o,$,t),children:[e.jsx(Me,{size:14})," New task"]})]})]}),u&&P>0&&e.jsx(lr,{agents:s.agents||[],onRefresh:t}),c?e.jsx("div",{className:"view-loading",children:e.jsx(he,{size:"lg"})}):e.jsx("div",{className:"kanban",children:Es.map(E=>e.jsx(cr,{column:E,tasks:k.filter(A=>A.status===E.id),onMove:N,onDelete:I,onRetry:F,onEdit:A=>hr(n,i,A,o,$,t),onSubmitToOdin:w,tick:f},E.id))})]})}function cr({column:s,tasks:t,onMove:a,onDelete:i,onRetry:n,onEdit:l,onSubmitToOdin:o,tick:c}){const[g,m]=r.useState(!1);return e.jsxs("div",{className:Z("kanban-column",g&&"kanban-column-drop"),"data-column":s.id,onDragOver:x=>{x.preventDefault(),m(!0)},onDragLeave:()=>m(!1),onDrop:x=>{x.preventDefault(),m(!1);const h=x.dataTransfer.getData("text/task-id");h&&a(h,s.id)},children:[e.jsxs("div",{className:"kanban-col-header",children:[e.jsxs(ne,{children:[e.jsx("span",{className:Z("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(x=>e.jsx(dr,{task:x,onMove:h=>{const u=Es.findIndex(j=>j.id===x.status)+h;u>=0&&u<Es.length&&a(x.id,Es[u].id)},onEdit:()=>l(x),onDelete:()=>i(x.id),onRetry:()=>n(x.id),onSubmitToOdin:()=>o(x.id),tick:c},x.id))})]})}function dr({task:s,onMove:t,onEdit:a,onDelete:i,onRetry:n,onSubmitToOdin:l,tick:o}){const c=s.workedBy||s.assignee||null;return e.jsxs("div",{className:Z("task-card",`priority-${s.priority}`),"data-task-id":s.id,draggable:!0,onDragStart:g=>{g.dataTransfer.setData("text/task-id",s.id),g.dataTransfer.effectAllowed="move"},"data-tick":o,children:[e.jsxs("div",{className:"task-card-head",children:[e.jsx("span",{className:"priority-dot",style:{background:Ta[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:[c&&e.jsxs("span",{className:"task-card-badge",title:`Auto-assigned to @${c}`,children:[e.jsx(qe,{size:10})," @",c]}),s.timeSpent?e.jsxs("span",{className:"task-card-badge",children:[e.jsx(Ps,{size:10})," ",Math.round((s.timeSpent||0)/60),"m"]}):null,s.tags&&s.tags.length>0&&s.tags.slice(0,3).map(g=>e.jsx(ir,{children:g},g))]}),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:g=>g.stopPropagation(),children:[e.jsx("button",{type:"button",className:"icon-btn","aria-label":"Move left",title:"Move left",onClick:()=>t(-1),children:e.jsx(_a,{size:14})}),e.jsx("button",{type:"button",className:"icon-btn","aria-label":"Edit",title:"Edit",onClick:a,children:e.jsx(gn,{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(ut,{size:14})}),e.jsx("button",{type:"button",className:"icon-btn icon-btn-danger","aria-label":"Delete",title:"Delete",onClick:i,children:e.jsx(Re,{size:14})}),e.jsx("button",{type:"button",className:"icon-btn","aria-label":"Move right",title:"Move right",onClick:()=>t(1),children:e.jsx(He,{size:14})})]})]})]})}function mr(s,t,a,i,n){let l=null,o=null,c=null,g=null;const m=async h=>{h&&typeof h.preventDefault=="function"&&h.preventDefault();const d=((l==null?void 0:l.value)||"").trim(),u=((o==null?void 0:o.value)||"").trim();if(!d){t.warning("Title is required."),l==null||l.focus();return}const j=(g==null?void 0:g.value)||"normal",f=((c==null?void 0:c.value)||"").split(",").map(y=>y.trim()).filter(Boolean);try{const y=await S.post("/tasks",{title:d,description:u,priority:j,tags:f});s.close(),typeof window<"u"&&window.dispatchEvent(new MouseEvent("mousedown")),a($=>[y,...$]),t.success("Task created.",1200),await n()}catch(y){t.error(`Create failed: ${y.message}`)}},x=h=>{h.key==="Enter"&&!h.shiftKey&&(h.preventDefault(),m(h))};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:h=>{l=h},id:"task-title",className:"input",type:"text",maxLength:200,placeholder:"What needs to be done?",autoFocus:!0,onKeyDown:x}),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:h=>{o=h},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 d;if(!((d=o==null?void 0:o.value)!=null&&d.trim()))return;const h=await za(o.value);h!==o.value&&(o.value=h)},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:h=>{g=h},id:"task-priority",className:"select",defaultValue:"normal",children:yt.map(h=>e.jsx("option",{value:h,children:h},h))})]}),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:h=>{c=h},id:"task-tags",className:"input",type:"text",placeholder:"bug, frontend, urgent"})]})]}),e.jsx("p",{className:"muted text-sm",style:{marginTop:8},children:"The agent and final priority are decided by Odin after you submit."})]}),footer:e.jsxs("div",{className:"modal-footer-actions",children:[e.jsx(T,{variant:"ghost",onClick:()=>s.close(),children:"Cancel"}),e.jsxs(T,{variant:"primary",type:"button",onClick:h=>m(h),children:[e.jsx(Me,{size:14})," Create task"]})]})})}function hr(s,t,a,i,n,l){let o=null,c=null,g=null,m=null;const x=async()=>{const h=((o==null?void 0:o.value)||"").trim(),d=((c==null?void 0:c.value)||"").trim();if(!h){t.warning("Title is required."),o==null||o.focus();return}const u=(m==null?void 0:m.value)||"normal",j=((g==null?void 0:g.value)||"").split(",").map(f=>f.trim()).filter(Boolean);try{const f=await S.put(`/tasks/${encodeURIComponent(a.id)}`,{title:h,description:d,priority:u,tags:j});s.close(),typeof window<"u"&&window.dispatchEvent(new MouseEvent("mousedown")),i(y=>y.map($=>$.id===a.id?f:$)),t.success("Task updated.",1200),await l()}catch(f){t.error(`Save failed: ${f.message}`)}};s.open({title:"Edit task",width:520,children:e.jsxs("div",{className:"task-form",children:[e.jsx("label",{className:"field-label",htmlFor:"edit-task-title",children:"Title *"}),e.jsx("input",{ref:h=>{o=h},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:h=>{c=h},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:h=>{m=h},id:"edit-task-priority",className:"select",defaultValue:a.priority||"normal",children:yt.map(h=>e.jsx("option",{value:h,children:h},h))})]}),e.jsxs("label",{htmlFor:"edit-task-tags",className:"task-form-field",style:{flex:2},children:["Tags",e.jsx("input",{ref:h=>{g=h},id:"edit-task-tags",className:"input",type:"text",defaultValue:(a.tags||[]).join(", "),placeholder:"comma-separated"})]})]}),e.jsxs(J,{children:[e.jsxs(ne,{children:[e.jsx(Zt,{size:12})," Status"]}),e.jsxs(re,{children:["Current: ",e.jsx("strong",{children:a.status}),a.workedBy&&e.jsxs(e.Fragment,{children:[" · Worked by @",a.workedBy]}),a.assignee&&!a.workedBy&&e.jsxs(e.Fragment,{children:[" · Assigned @",a.assignee]})]})]})]}),footer:e.jsxs("div",{className:"modal-footer-actions",children:[e.jsx(T,{variant:"ghost",onClick:()=>s.close(),children:"Cancel"}),e.jsxs(T,{variant:"primary",onClick:x,children:[e.jsx(Vt,{size:14})," Save"]})]})})}const ur=We.memo(or);function xr(s){return S.urlWithToken(`/artifacts/${encodeURIComponent(s)}/content`)}function pr(s,t){const a=xr(t);window.open(a,"_blank","noopener,noreferrer")}const At={"1m":60*1e3,"5m":5*60*1e3,"30m":30*60*1e3,"1h":60*60*1e3},ze=56,Be=32,ss=22,gr=4,jr=.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 Xs(s){return s&&Qs[s]||Qs.idle}function $s(s,t=24){return s?s.length<=t?s:s.slice(0,t-1)+"…":""}function Us(s){if(s==null)return 0;if(typeof s=="number")return s;const t=new Date(s).getTime();return Number.isNaN(t)?0:t}function Zs(s){const t=s._timerStart;return typeof t=="number"&&t>0?t:Us(s.createdAt)||Date.now()}function fr(s,t){return(s.status==="done"||s.status==="archived"||s.status==="failed"||s.status==="killed")&&(Us(s.completedAt)||Us(s.updatedAt))||t}function vr(s){return typeof s.startedAt=="number"&&s.startedAt>0?s.startedAt:Date.now()}function yr(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 br(s){return s<=6e4?1e4:s<=3e5?3e4:s<=18e5?3e5:6e5}function kr(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 Nr({snapshot:s,refreshSnapshot:t}){const a=ce(),i=r.useRef(null),[n,l]=r.useState("live"),[o,c]=r.useState("5m"),[g,m]=r.useState(()=>typeof window>"u"?!0:window.innerWidth>900),[x,h]=r.useState([]),[d,u]=r.useState([]),[j,f]=r.useState(!0),[y,$]=r.useState(0),[b,k]=r.useState(Date.now()),[P,N]=r.useState(()=>Date.now()-At["5m"]*.1),[I,F]=r.useState({width:800,height:400}),[w,E]=r.useState(null),[A,z]=r.useState(""),[R,B]=r.useState([]),[v,O]=r.useState(""),[K,M]=r.useState("normal"),[W,te]=r.useState(""),[ee,_]=r.useState(""),[Y,se]=r.useState(!1),[Q,ie]=r.useState(!1),[xe,V]=r.useState([]),L=De(),U=s.agents||[],p=s.tasks||[],q=At[o],H=P,D=P+q,le=r.useCallback(async()=>{try{const[C,G]=await Promise.all([S.get("/background").catch(()=>({instances:[]})),S.get("/activity?limit=200").catch(()=>({events:[]}))]);h(C.instances||[]),u(G.events||[])}catch(C){console.warn("activity reload failed:",C)}finally{f(!1)}},[]);r.useEffect(()=>{le();const C=setInterval(le,3e3);return()=>clearInterval(C)},[le]),r.useEffect(()=>{$(C=>C+1)},[p.length,U.length]),r.useEffect(()=>{if(n==="pause")return;k(Date.now());const C=setInterval(()=>k(Date.now()),1e3);return()=>clearInterval(C)},[n,y]),r.useEffect(()=>{if(n==="pause")return;(b-P)/q>jr&&N(b-q*.1)},[b,P,q,n]),r.useEffect(()=>{N(Date.now()-q*.1)},[o]),r.useEffect(()=>{n==="live"&&N(Date.now()-q*.1)},[n]),r.useLayoutEffect(()=>{const C=i.current;if(!C)return;const G=new ResizeObserver(pe=>{for(const ge of pe){const{width:me,height:je}=ge.contentRect;F({width:Math.max(200,Math.floor(me)),height:Math.max(120,Math.floor(je))})}});return G.observe(C),()=>G.disconnect()},[]);const ae=r.useMemo(()=>{const C=[];let G=0;for(const me of x){const je=vr(me),Ae=yr(me,b);Ae<H||je>D||C.push({kind:"bg",id:`bg:${me.instanceId}`,index:G++,label:`BG ${$s(me.promptPreview,20)||me.instanceId.slice(0,10)}`,sub:me.status||"pending",start:je,end:Ae,data:me})}const pe=[...p].sort((me,je)=>Zs(me)-Zs(je)),ge=[];for(const me of pe){const je=Zs(me),Ae=fr(me,b);if(Ae<H||je>D)continue;let Ze=-1;for(let Ve=0;Ve<ge.length;Ve++)if(ge[Ve]<=je){ge[Ve]=Ae,Ze=Ve;break}Ze===-1&&(ge.push(Ae),Ze=ge.length-1),C.push({kind:"task",id:`task:${me.id}`,index:G+Ze,label:$s(me.title,32),sub:me.status,start:je,end:Ae,data:me})}return C},[x,p,b,H,D]),ue=r.useMemo(()=>{const C=new Map;for(const G of ae)C.set(G.id,G);return C},[ae]),de=r.useCallback(C=>q<=0?0:(C-H)/q*I.width,[H,q,I.width]),ws=r.useMemo(()=>{const C=br(q),G=[],pe=Math.floor(H/C)*C;for(let ge=pe;ge<=D+C;ge+=C){if(ge<H-C)continue;if(ge>D)break;const me=de(ge);me<-40||me>I.width+40||G.push({t:ge,x:me,label:kr(ge,q)})}return G},[H,D,q,I.width,de]),Ss=r.useMemo(()=>{const C=[];for(const G of ae){if(G.kind==="events")continue;const pe=Math.max(G.start,H),ge=Math.min(G.end,D);if(ge<H||pe>D)continue;const me=de(pe),je=de(ge),Ae=Math.max(gr,je-me),Ze=Be+ss+G.index*ze+8,Ve=ze-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 xa=(w==null?void 0:w.id)===G.id;C.push({id:G.id,laneIndex:G.index,x:me,y:Ze,w:Ae,h:Ve,label:G.label,statusClass:Pe,selected:xa,data:G.data,kind:G.kind,start:G.start,end:G.end})}return C},[ae,de,w,H,D]),Cs=r.useMemo(()=>{const C=[];for(const G of d){const pe=Us(G.ts);if(pe<H-5e3||pe>D+5e3)continue;const ge=de(pe);let me=Be+12;if(G.taskId){const je=ue.get(`task:${G.taskId}`);je&&(me=Be+ss+je.index*ze+ze/2)}else if(G.nodeId){const je=String(G.nodeId),Ae=ue.get(je.startsWith("task:")||je.startsWith("bg:")?je:`task:${je}`);Ae&&(me=Be+ss+Ae.index*ze+ze/2)}C.push({id:`${G.ts}-${G.kind}-${G.author??""}-${G.taskId??""}`,x:ge,y:me,kind:G.kind||"event",ts:pe,text:String(G.text||G.kind||""),author:G.author})}return C},[d,H,D,de,ue]),zs=r.useMemo(()=>ae.map(C=>({id:C.id,y:Be+ss+C.index*ze,h:ze})),[ae]),Ts=r.useMemo(()=>{const C=de(b);return Math.max(0,Math.min(I.width,C))},[de,b,I.width]),ca=r.useCallback(C=>{const pe={id:C.id,kind:C.kind,label:C.label,status:C.statusClass,data:C.data};E(pe)},[]);r.useEffect(()=>{if(!w){B([]),_(""),V([]);return}z(""),O(""),te(""),V([]),(async()=>{try{const C=await S.get(`/activity?nodeId=${encodeURIComponent(w.id)}&limit=50`);B(C.events||[])}catch{B([])}if(w.kind==="bg"){const C=w.data;try{const G=await S.get(`/background/${encodeURIComponent(C.instanceId)}/output?lines=80`);_(G.output||"")}catch{_("")}if(C.taskId)try{const G=await S.get(`/tasks/${encodeURIComponent(C.taskId)}/artifacts`);V((G.artifacts||[]).map(pe=>pe.id))}catch{V([])}}})()},[w]);const Nt=async()=>{if(!(!w||!A.trim())){ie(!0);try{await S.post("/comments",{nodeId:w.id,text:A,author:"user"}),z("");const C=await S.get(`/activity?nodeId=${encodeURIComponent(w.id)}&limit=50`);B(C.events||[]),a.success("Comment added.")}catch(C){a.error(`Comment failed: ${C.message}`)}finally{ie(!1)}}},da=async()=>{if(!(!w||!v.trim())){se(!0);try{await S.post(`/nodes/${encodeURIComponent(w.id)}/tasks`,{title:v,description:`Created from timeline selection ${w.id}.`,priority:K}),O(""),a.success("Task created."),await t()}catch(C){a.error(`Task create failed: ${C.message}`)}finally{se(!1)}}},wt=async()=>{if(!w||w.kind!=="bg"||!W.trim())return;const C=w.data;try{const G=await S.post(`/background/${encodeURIComponent(C.instanceId)}/message`,{message:W});G.ok?(a.success("Message sent."),te("")):a.warning(G.error||"Send failed")}catch(G){a.error(`Send failed: ${G.message}`)}},ma=async()=>{if(!w||w.kind!=="bg"||!confirm("Kill this bg instance session?"))return;const C=w.data;try{const G=await S.del(`/background/${encodeURIComponent(C.instanceId)}`);G.ok?a.success("Session killed."):a.warning(G.error||"Kill failed"),await le()}catch(G){a.error(`Kill failed: ${G.message}`)}},ha=async()=>{if(!w||w.kind!=="bg")return;const C=w.data;try{const G=await S.get(`/background/${encodeURIComponent(C.instanceId)}/output?lines=80`);_(G.output||"")}catch{}};r.useEffect(()=>{const C=G=>{G.key==="Escape"&&E(null)};return window.addEventListener("keydown",C),()=>window.removeEventListener("keydown",C)},[]);const ua=()=>{$(C=>C+1),le()},Ws=Be+ss+ae.length*ze;return e.jsxs("div",{className:"view view-activity",children:[e.jsxs("header",{className:"view-header",children:[e.jsxs("div",{className:"view-header-text",children:[e.jsxs("h2",{className:"view-title",children:[e.jsx(Te,{size:18})," Activity"]}),e.jsx("p",{className:"view-subtitle",children:"Live timeline of agents, tasks, and background sessions. Active tasks pulse; the red line marks “now”."})]}),e.jsx("div",{className:"view-actions",children:e.jsxs("div",{className:"tl-mode-toggle",children:[e.jsxs(T,{variant:n==="live"?"primary":"secondary",size:"sm",onClick:()=>l(n==="live"?"pause":"live"),title:n==="live"?"Pause timeline":"Resume timeline",children:[n==="live"?e.jsx(Ma,{size:14}):e.jsx(Ns,{size:14}),n==="live"?"Live":"Paused"]}),e.jsx("div",{className:"tl-zoom-group",children:["1m","5m","30m","1h"].map(C=>e.jsx("button",{type:"button",className:Z("tl-zoom-btn",o===C&&"tl-zoom-btn-active"),onClick:()=>c(C),title:`Zoom to ${C}`,children:C},C))}),e.jsxs(T,{variant:"secondary",size:"sm",onClick:ua,title:"Refresh",children:[e.jsx(oe,{size:14})," Refresh"]})]})})]}),j&&e.jsx("div",{className:"view-loading",children:e.jsx(he,{size:"lg"})}),!j&&U.length===0&&p.length===0&&x.length===0&&d.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:Z("tl-view",w&&"tl-view-detail-open"),children:e.jsxs("div",{className:Z("tl-body",!g&&"tl-body-stream-collapsed"),children:[e.jsxs("aside",{className:Z("tl-stream",!g&&"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:()=>m(!1),title:"Hide event stream","aria-label":"Hide event stream",children:e.jsx(un,{size:14})})]}),e.jsx("div",{className:"tl-stream-list",children:d.length===0?e.jsx("div",{className:"tl-stream-empty",children:e.jsx("p",{children:"No events yet."})}):e.jsx(mt,{items:[...d].reverse(),itemHeight:40,height:400,className:"tl-stream-virtual",renderItem:C=>{const G=C.author?qe:C.kind==="task"?gs:C.kind==="bg"?Vs:Te;return e.jsxs("div",{className:"tl-stream-event",children:[e.jsx("span",{className:"tl-stream-event-time",children:new Date(C.ts).toLocaleTimeString("en-GB",{hour12:!1})}),e.jsx("span",{className:"tl-stream-event-icon",style:{color:Xs(C.kind)},children:e.jsx(G,{size:12})}),e.jsx("span",{className:"tl-stream-event-text",children:C.author||C.text||C.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:[!g&&e.jsxs(T,{variant:"ghost",size:"sm",onClick:()=>m(!0),title:"Show event stream",children:[e.jsx(xn,{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(H).toLocaleTimeString("en-GB",{hour12:!1})," →"," ",new Date(D).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(on,{size:11})," agent"]}),e.jsxs("span",{className:"tl-legend-item",children:[e.jsx(wn,{size:11})," task"]}),e.jsxs("span",{className:"tl-legend-item",children:[e.jsx(Vs,{size:11})," bg"]})]})]}),e.jsx("div",{className:"tl-canvas-scroll",children:e.jsxs("svg",{className:"tl-canvas",width:I.width,height:Math.max(I.height,Ws),role:"application","aria-label":"Activity timeline",children:[e.jsx("defs",{children:e.jsx("pattern",{id:"tl-canvas-grid",width:I.width,height:ze,patternUnits:"userSpaceOnUse",children:e.jsx("path",{d:`M 0 0 L 0 ${ze}`,fill:"none",stroke:"var(--border)",strokeWidth:.5,opacity:.35})})}),e.jsx("rect",{width:"100%",height:"100%",fill:"url(#tl-canvas-grid)"}),zs.map(C=>e.jsx("rect",{className:"tl-lane-bg",x:0,y:C.y,width:I.width,height:C.h,fill:C.id.charCodeAt(C.id.length-1)%2===0?"var(--bg-elev-2)":"var(--bg-elev)",opacity:.4},`bg-${C.id}`)),e.jsx("g",{className:"tl-time-axis",children:ws.map(C=>e.jsxs("g",{children:[e.jsx("line",{x1:C.x,y1:0,x2:C.x,y2:Ws,stroke:"var(--border)",strokeWidth:.5,strokeDasharray:"2,4",opacity:.5}),e.jsx("text",{x:C.x+4,y:Be-8,fontSize:10,fontFamily:"var(--font-mono)",fill:"var(--text-dim)",children:C.label})]},`tick-${C.t}`))}),ae.map(C=>{const G=Be+ss+C.index*ze+ze/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:$s(C.label,28)}),e.jsx("text",{x:6,y:G+10,className:"tl-lane-label-sub",textAnchor:"start",children:C.sub})]},`label-${C.id}`)}),Ss.map(C=>{const G=Xs(C.statusClass),pe=C.id===(w==null?void 0:w.id);return e.jsxs("g",{className:Z("tl-task-bar",`tl-task-bar-${C.statusClass}`,pe&&"tl-task-bar-selected"),onClick:()=>ca(C),children:[e.jsx("rect",{x:C.x,y:C.y,width:C.w,height:C.h,rx:6,fill:G,fillOpacity:C.statusClass==="done"?.35:C.statusClass==="queued"?.18:.85,stroke:G,strokeWidth:pe?2.5:1.5,strokeOpacity:C.statusClass==="done"?.5:1,strokeDasharray:C.statusClass==="queued"?"4 4":void 0,style:{cursor:"pointer"}}),C.w>36&&e.jsx("text",{x:C.x+8,y:C.y+C.h/2+4,fontSize:11,fontFamily:"var(--font-sans)",fontWeight:500,fill:"var(--text-strong)",style:{pointerEvents:"none"},opacity:C.statusClass==="done"?.7:1,children:$s(C.label,Math.max(4,Math.floor(C.w/7)))})]},`bar-${C.id}`)}),Cs.map(C=>{const G=Xs(C.kind);return e.jsxs("g",{className:"tl-event-marker-group",children:[e.jsx("line",{x1:C.x,y1:C.y-6,x2:C.x,y2:C.y+6,stroke:G,strokeWidth:1.2,opacity:.7}),e.jsx("circle",{cx:C.x,cy:C.y,r:4,fill:G,opacity:.9,children:e.jsx("title",{children:`${C.kind}${C.author?` · ${C.author}`:""} · ${new Date(C.ts).toLocaleTimeString("en-GB",{hour12:!1})}`})})]},`ev-${C.id}`)}),e.jsx("line",{className:"tl-now-line",x1:Ts,y1:0,x2:Ts,y2:Ws,stroke:"var(--error)",strokeWidth:1.5,opacity:.9}),e.jsxs("g",{className:"tl-now-marker",children:[e.jsx("circle",{cx:Ts,cy:Be-4,r:4,fill:"var(--error)"}),e.jsx("text",{x:Ts+6,y:Be-4,fontSize:10,fontWeight:700,fill:"var(--error)",fontFamily:"var(--font-mono)",children:"now"})]})]})})]}),w&&e.jsx("aside",{className:"tl-detail tl-detail-enter",children:e.jsxs(J,{children:[e.jsxs(ne,{children:[w.kind==="agent"&&e.jsx(qe,{size:14}),w.kind==="task"&&e.jsx(gs,{size:14}),w.kind==="bg"&&e.jsx(Vs,{size:14}),w.label,e.jsx("button",{type:"button",className:"icon-btn",onClick:()=>E(null),title:"Close","aria-label":"Close activity detail",style:{marginLeft:"auto"},children:e.jsx($e,{size:14})})]}),e.jsxs("div",{className:"tl-detail-meta",children:[e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"type"})," ",w.kind]}),e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"status"})," ",e.jsx("code",{children:w.status})]}),w.kind==="agent"&&(()=>{const C=w.data;return e.jsxs(e.Fragment,{children:[C.role&&e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"role"})," ",C.role]}),C.model&&e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"model"})," ",C.model]})]})})(),w.kind==="task"&&(()=>{const C=w.data;return e.jsxs(e.Fragment,{children:[C.assignee&&e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"assignee"})," @",C.assignee]}),C.priority&&e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"priority"})," ",C.priority]}),C.createdAt&&e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"created"})," ",new Date(C.createdAt).toLocaleString()]})]})})(),w.kind==="bg"&&(()=>{const C=w.data;return e.jsxs(e.Fragment,{children:[C.startedAt&&e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"started"})," ",new Date(C.startedAt).toLocaleString()]}),C.tmuxSession&&e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"tmux"})," ",e.jsx("code",{children:C.tmuxSession})," ",C.tmuxActive?e.jsx("span",{className:"tag tag-success",children:"active"}):e.jsx("span",{className:"tag",children:"inactive"})]})]})})()]}),w.kind==="task"&&w.data.description&&e.jsx("div",{className:"tl-detail-desc",children:w.data.description}),w.kind==="bg"&&w.data.promptPreview&&e.jsx("div",{className:"tl-detail-desc",children:w.data.promptPreview}),w.kind==="bg"&&e.jsxs("div",{className:"tl-detail-bg",children:[e.jsx("pre",{className:"tl-bg-output",children:ee||"(no output — start the session via tmux attach)"}),e.jsxs("div",{className:"tl-bg-output-actions",children:[e.jsxs(T,{variant:"ghost",size:"sm",onClick:ha,children:[e.jsx(oe,{size:12})," Refresh output"]}),xe.length>0&&e.jsxs(T,{variant:"secondary",size:"sm",onClick:()=>pr(L,xe[0]),children:[e.jsx(Se,{size:12})," Open artifact"]}),e.jsxs(T,{variant:"danger",size:"sm",onClick:ma,children:[e.jsx(Re,{size:12})," Kill session"]})]}),e.jsxs("div",{className:"tl-form-row",children:[e.jsx("input",{className:"input",placeholder:"Send a message to this bg session…",value:W,onChange:C=>te(C.target.value),onKeyDown:C=>{C.key==="Enter"&&wt()}}),e.jsxs(T,{variant:"primary",size:"sm",disabled:!W.trim(),onClick:wt,children:[e.jsx(Qe,{size:12})," Send"]})]})]}),w.kind!=="bg"&&e.jsxs("div",{className:"tl-detail-create",children:[e.jsx("div",{className:"field-label",children:"Create follow-up task"}),e.jsx("input",{className:"input",placeholder:"Task title",value:v,onChange:C=>O(C.target.value)}),e.jsxs("div",{className:"tl-form-row",children:[e.jsxs("select",{className:"select",value:K,onChange:C=>M(C.target.value),children:[e.jsx("option",{value:"low",children:"Low"}),e.jsx("option",{value:"normal",children:"Normal"}),e.jsx("option",{value:"high",children:"High"})]}),e.jsxs(T,{variant:"primary",size:"sm",disabled:!v.trim()||Y,onClick:da,children:[e.jsx(Me,{size:12})," Add task"]})]})]}),e.jsxs("div",{className:"tl-detail-comments",children:[e.jsxs("div",{className:"field-label",children:[e.jsx(qs,{size:12})," Comments & activity"]}),e.jsxs("ul",{className:"comment-list",children:[R.length===0&&e.jsx("li",{className:"muted",children:"No comments yet."}),R.map((C,G)=>e.jsxs("li",{className:"comment-item",children:[e.jsxs("div",{className:"comment-head",children:[e.jsx("strong",{children:C.author||"system"}),e.jsxs("span",{className:"muted",children:[C.kind," · ",new Date(C.ts).toLocaleString()]})]}),C.text&&e.jsx("div",{className:"comment-text",children:C.text}),C.taskId&&e.jsxs("div",{className:"muted",children:["→ task ",e.jsx("code",{children:String(C.taskId)})]})]},`c-${G}`))]}),e.jsxs("div",{className:"comment-input-row",children:[e.jsx("input",{className:"input",placeholder:"Add a comment…",value:A,onChange:C=>z(C.target.value),onKeyDown:C=>{C.key==="Enter"&&!C.shiftKey&&Nt()}}),e.jsxs(T,{variant:"secondary",size:"sm",disabled:!A.trim()||Q,onClick:Nt,children:[e.jsx(Qe,{size:12})," Post"]})]})]})]})},w.id)]})})]})}const wr=[{value:"anthropic",label:"Anthropic"},{value:"anyllm",label:"AnyLLM"},{value:"litellm-anthropic",label:"LiteLLM (Anthropic)"},{value:"litellm-openai",label:"LiteLLM (OpenAI)"}];function Sr({settings:s,onPatch:t}){const a=ce(),[i,n]=r.useState(null),[l,o]=r.useState(null),[c,g]=r.useState(!1),[m,x]=r.useState(!1),[h,d]=r.useState(!1),[u,j]=r.useState(!1),[f,y]=r.useState(!1),[$,b]=r.useState(!1),k=r.useCallback(async()=>{g(!0);try{const[M,W]=await Promise.all([S.get("/headroom/status"),S.get("/headroom/stats?hours=24").catch(()=>({error:"no stats"}))]);n(M),W.error||o(W)}catch(M){a.error(`Failed to load Headroom status: ${M.message}`)}finally{g(!1)}},[a]);r.useEffect(()=>{k()},[k]);const P=async()=>{x(!0);try{const M=await S.post("/headroom/install",{force:!0});M.installed?(a.success(`Headroom installed via ${M.method}.`),await k()):a.error('Headroom install failed. Try: pip install "headroom-ai[all]"')}catch(M){a.error(`Install failed: ${M.message}`)}finally{x(!1)}},N=async()=>{d(!0);try{(await S.post("/headroom/wrap",{port:s.port})).ok?(a.success("opencode wrapped with Headroom."),await k()):a.error("Wrap failed.")}catch(M){a.error(`Wrap failed: ${M.message}`)}finally{d(!1)}},I=async()=>{j(!0);try{(await S.post("/headroom/unwrap")).ok?(a.success("opencode unwrapped from Headroom."),await k()):a.error("Unwrap failed.")}catch(M){a.error(`Unwrap failed: ${M.message}`)}finally{j(!1)}},F=async()=>{y(!0);try{(await S.post("/headroom/proxy/start",{port:s.port,host:s.host})).ok?(a.success(`Headroom proxy started on ${s.host}:${s.port}.`),await k()):a.error("Proxy start failed.")}catch(M){a.error(`Proxy start failed: ${M.message}`)}finally{y(!1)}},w=async()=>{b(!0);try{(await S.post("/headroom/proxy/stop")).ok?(a.success("Headroom proxy stopped."),await k()):a.error("Proxy stop failed.")}catch(M){a.error(`Proxy stop failed: ${M.message}`)}finally{b(!1)}},E=async()=>{try{const{spawn:M}=await Ht(async()=>{const{spawn:W}=await import("./__vite-browser-external-BIHI7g3E.js");return{spawn:W}},[]);M("headroom",["dashboard"],{detached:!0,stdio:"ignore"})}catch{a.error("Could not open Headroom dashboard. Run `headroom dashboard` manually.")}},{installed:A,version:z,proxyRunning:R,proxyPort:B,wrapped:v}=i||{},O=(l==null?void 0:l.compressionRatio)??0,K=(l==null?void 0:l.tokensSaved)??0;return e.jsx("div",{id:"settings-headroom","data-section":"headroom",children:e.jsxs(J,{children:[e.jsxs(ne,{children:[e.jsx(Te,{size:14,style:{color:R?"var(--success)":"var(--text-dim)"}}),"Headroom",A&&z&&e.jsxs("span",{style:{fontSize:11,color:"var(--text-dim)",marginLeft:6},children:["v",z," ",R?"✓":"✗"]}),!A&&e.jsx("span",{style:{fontSize:11,color:"var(--error)",marginLeft:6},children:"not installed"})]}),e.jsx(re,{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:[A?e.jsx(Is,{size:12,style:{color:"var(--success)"}}):e.jsx(Ye,{size:12,style:{color:"var(--error)"}}),e.jsx("span",{children:A?"Installed":"Not installed"})]}),e.jsxs("div",{className:"headroom-status-item",children:[R?e.jsx(Is,{size:12,style:{color:"var(--success)"}}):e.jsx(Ye,{size:12,style:{color:"var(--text-dim)"}}),e.jsxs("span",{children:["Proxy ",R?`${B} ✓`:"stopped"]})]}),e.jsxs("div",{className:"headroom-status-item",children:[v?e.jsx(Is,{size:12,style:{color:"var(--success)"}}):e.jsx(Ye,{size:12,style:{color:"var(--text-dim)"}}),e.jsxs("span",{children:["opencode ",v?"wrapped":"not wrapped"]})]})]}),(K>0||O>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:O>0?`${Math.round(O*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:K>0?K.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:[A?e.jsxs(e.Fragment,{children:[e.jsxs(T,{variant:"secondary",size:"sm",onClick:N,disabled:h||v,title:v?"opencode is already wrapped":"Wrap opencode to route through Headroom proxy",children:[h?e.jsx("span",{className:"btn-spinner"}):e.jsx(vt,{size:13}),h?"Wrapping…":v?"Wrapped ✓":"Wrap opencode"]}),v&&e.jsxs(T,{variant:"ghost",size:"sm",onClick:I,disabled:u,children:[u?e.jsx("span",{className:"btn-spinner"}):e.jsx(oe,{size:13}),u?"Unwrapping…":"Unwrap"]})]}):e.jsxs(T,{variant:"primary",size:"sm",onClick:P,disabled:m,children:[m?e.jsx("span",{className:"btn-spinner"}):e.jsx(Xe,{size:13}),m?"Installing…":"Install Headroom"]}),A&&e.jsxs(e.Fragment,{children:[R?e.jsxs(T,{variant:"secondary",size:"sm",onClick:w,disabled:$,children:[$?e.jsx("span",{className:"btn-spinner"}):e.jsx(Nn,{size:13}),$?"Stopping…":"Stop proxy"]}):e.jsxs(T,{variant:"secondary",size:"sm",onClick:F,disabled:f,children:[f?e.jsx("span",{className:"btn-spinner"}):e.jsx(Ns,{size:13}),f?"Starting…":"Start proxy"]}),e.jsxs(T,{variant:"ghost",size:"sm",onClick:E,children:[e.jsx(ls,{size:13}),"Dashboard"]})]}),e.jsx(T,{variant:"ghost",size:"sm",onClick:k,disabled:c,children:e.jsx(oe,{size:13,className:c?"spin":""})})]}),e.jsxs("div",{style:{marginTop:16},children:[e.jsxs("label",{className:"checkbox-row",children:[e.jsx("input",{type:"checkbox",checked:s.enabled,onChange:M=>t({enabled:M.target.checked})}),e.jsx("span",{children:"Enable Headroom"})]}),e.jsxs("label",{className:"checkbox-row",children:[e.jsx("input",{type:"checkbox",checked:s.autoInstall,onChange:M=>t({autoInstall:M.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:M=>t({autoStart:M.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:M=>t({autoWrap:M.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:M=>t({routeAllProviders:M.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:M=>t({port:Math.max(1,Math.min(65535,parseInt(M.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:M=>t({host:M.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:M=>t({backend:M.target.value}),children:wr.map(M=>e.jsx("option",{value:M.value,children:M.label},M.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:M=>t({budget:Math.max(0,parseFloat(M.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:M=>t({outputShaper:M.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:M=>t({telemetry:M.target.checked})}),e.jsx("span",{children:"Enable telemetry"})]})]})]})})}const Cr=[{id:"dark",label:"Dark",Icon:$a},{id:"light",label:"Light",Icon:Ra},{id:"system",label:"System",Icon:Aa}],zr=[{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"}],It={enabled:!0,autoInstall:!0,port:8787,host:"127.0.0.1",outputShaper:!1,telemetry:!1,budget:0,backend:"anthropic",autoStart:!0,autoWrap:!0,routeAllProviders:!0},Tr=["Inter","system-ui","Segoe UI","Roboto","JetBrains Mono","SF Mono","Cascadia Code"];function Mr(s){if(s<=0)return"expired";const t=Math.floor(s/1e3),a=Math.floor(t/60),i=t%60;return`${a}:${String(i).padStart(2,"0")}`}function $r(){const s=ce(),[t,a]=r.useState(null),[i,n]=r.useState(!1),[l,o]=r.useState(null),[c,g]=r.useState(Date.now()),m=r.useCallback(async()=>{n(!0),o(null);try{const d=await S.post("/pair/start");a(d)}catch(d){o((d==null?void 0:d.message)||"Failed to start pairing"),s.error("Pairing failed.")}finally{n(!1)}},[s]);r.useEffect(()=>{if(!t)return;const d=setInterval(()=>g(Date.now()),1e3);return()=>clearInterval(d)},[t]);const x=t?t.expiresAt-c:0,h=t!=null&&x<=0;return e.jsxs(J,{id:"settings-updates","data-section":"updates",children:[e.jsxs(ne,{children:[e.jsx(Ia,{size:14})," Companion App"]}),e.jsxs(re,{children:["Scan the QR with ",e.jsx("a",{href:"https://github.com/DrB0rk/BizarHarness",target:"_blank",rel:"noopener noreferrer",children:"Bizar Companion"})," to pair. Tokens expire after 5 minutes."]}),e.jsxs("div",{style:{display:"flex",gap:16,alignItems:"flex-start",flexWrap:"wrap"},children:[e.jsx("div",{style:{flex:"0 0 auto"},children:t&&!h?e.jsx("div",{style:{background:"#fff",padding:12,borderRadius:12},children:e.jsx(La,{value:t.qrPayload,size:192,level:"M",includeMargin:!1})}):e.jsx("div",{style:{width:216,height:216,borderRadius:12,background:"var(--surface-2, #161b22)",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted, #8b949e)",fontSize:12,textAlign:"center",padding:16,border:"1px dashed var(--border, #30363d)"},children:t&&h?"QR expired":"No QR generated yet"})}),e.jsxs("div",{style:{flex:"1 1 240px",minWidth:220},children:[!t&&e.jsxs(T,{variant:"primary",onClick:m,disabled:i,children:[e.jsx(Ea,{size:14})," ",i?"Generating…":"Generate QR Code"]}),t&&!h&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{marginBottom:10},children:[e.jsx("strong",{children:"Expires in"})," ",e.jsx("span",{className:"mono",children:Mr(x)})]}),e.jsxs("div",{style:{marginBottom:6},children:[e.jsx("strong",{children:"URL:"})," ",e.jsx("span",{className:"mono",style:{wordBreak:"break-all"},children:t.publicUrl})]}),e.jsxs("div",{style:{marginBottom:12},children:[e.jsx("strong",{children:"Token:"})," ",e.jsxs("span",{className:"mono",style:{wordBreak:"break-all",fontSize:12},children:[t.token.slice(0,16),"…",t.token.slice(-6)]})]}),e.jsxs(T,{variant:"secondary",onClick:m,disabled:i,children:[e.jsx(oe,{size:14})," Regenerate"]})]}),t&&h&&e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{marginBottom:12,color:"var(--error, #f85149)"},children:"Token expired — generate a fresh QR to pair again."}),e.jsxs(T,{variant:"primary",onClick:()=>{a(null),m()},children:[e.jsx(oe,{size:14})," Generate new QR"]})]}),l&&e.jsx("div",{style:{marginTop:10,color:"var(--error, #f85149)",fontSize:12},children:l})]})]})]})}const Rr=[{id:"topnav",label:"Top nav"},{id:"sidebar",label:"Sidebar"},{id:"both",label:"Both"}];function Ar(){const s=ce(),[t,a]=r.useState({current:{},latest:null,checking:!1,updating:!1,hasUpdates:!1,requiresRestart:!1,perPackage:{}});r.useEffect(()=>{const g=new xt;return g.on(m=>{(m.type==="update:progress"||m.type==="update:log"||m.type==="update:complete")&&a(x=>{if(m.type==="update:complete")return{...x,updating:!1,requiresRestart:!!m.requiresRestart};if(m.type==="update:log"){const d=m,u=x.perPackage[d.pkg]||{logs:[]};return{...x,perPackage:{...x.perPackage,[d.pkg]:{...u,logs:[...(u.logs||[]).slice(-50),d.line]}}}}const h=m;return{...x,perPackage:{...x.perPackage,[h.pkg]:{...x.perPackage[h.pkg],status:h.status,error:h.error,newVersion:h.newVersion}}}})}),()=>g.close()},[]),r.useEffect(()=>{S.get("/updates/status").then(g=>a(m=>({...m,current:g.current}))).catch(g=>a(m=>({...m,error:g.message})))},[]);const i=async()=>{a(g=>({...g,checking:!0,error:void 0}));try{const g=await S.get("/updates/check");a(m=>({...m,checking:!1,current:g.current,latest:g.latest,hasUpdates:g.hasUpdates}))}catch(g){a(m=>({...m,checking:!1,error:g.message}))}},n=async()=>{if(confirm("Update Bizar packages? The dashboard will restart automatically.")){a(g=>({...g,updating:!0,requiresRestart:!1,perPackage:{},error:void 0}));try{await S.post("/updates/apply",{packages:["bizar","bizar-dash","bizar-plugin"]})}catch(g){a(m=>({...m,updating:!1,error:g.message}))}}},l=async()=>{if(confirm("Restart the dashboard? You will be disconnected briefly."))try{await S.post("/restart"),s.info("Restarting…",3e3),setTimeout(()=>window.location.reload(),3e3)}catch{s.error("Restart failed")}},o=[{id:"bizar",name:"Bizar CLI"},{id:"bizar-dash",name:"Dashboard"},{id:"bizar-plugin",name:"Opencode Plugin"}],c=t.checking||t.updating;return e.jsxs(J,{id:"settings-updates","data-section":"updates",children:[e.jsxs(ne,{children:[e.jsx(Xe,{size:14})," Updates"]}),e.jsx(re,{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:o.map(g=>e.jsxs("li",{children:[e.jsx("span",{children:g.name}),e.jsx("code",{className:"mono",children:t.current[g.id]||"—"})]},g.id))})]}),t.latest&&e.jsxs("div",{className:"updates-latest",children:[e.jsx("h4",{children:"Latest available"}),e.jsx("ul",{children:o.map(g=>{var d;const m=t.current[g.id],x=(d=t.latest)==null?void 0:d[g.id],h=m&&x&&m!==x;return e.jsxs("li",{className:h?"updates-outdated":"updates-current-version",children:[e.jsx("span",{children:g.name}),e.jsxs("code",{className:"mono",children:[x||"—",h&&e.jsx("span",{className:"updates-badge",children:"update available"})]})]},g.id)})})]}),t.updating&&e.jsx("div",{className:"updates-progress-rows",children:o.map(g=>{const m=t.perPackage[g.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:g.name}),e.jsxs("div",{className:"updates-pkg-status",children:[m.status==="starting"&&e.jsx("span",{className:"btn-spinner"}),m.status==="installing"&&e.jsx("span",{className:"btn-spinner"}),m.status==="done"&&e.jsx(Is,{size:14,className:"icon-success"}),m.status==="error"&&e.jsx(ct,{size:14,className:"icon-error"}),e.jsx("span",{children:m.status}),m.newVersion&&e.jsxs("code",{className:"mono",style:{fontSize:11},children:["→ ",m.newVersion]})]})]}),m.logs.length>0&&e.jsxs("details",{className:"updates-pkg-logs",children:[e.jsxs("summary",{children:["npm output (",m.logs.length," lines)"]}),e.jsx("pre",{children:m.logs.join(`
|
|
351
|
+
`)})]}),m.status==="error"&&m.error&&e.jsxs("div",{className:"updates-pkg-error",children:[e.jsx(ke,{size:12})," ",m.error]})]},g.id)})}),e.jsxs("div",{className:"updates-actions",children:[e.jsxs(T,{onClick:i,disabled:c,children:[t.checking?e.jsx("span",{className:"btn-spinner"}):e.jsx(oe,{size:14}),"Check for updates"]}),e.jsxs(T,{variant:"primary",onClick:n,disabled:!t.hasUpdates||t.updating,children:[t.updating?e.jsx("span",{className:"btn-spinner"}):e.jsx(Xe,{size:14}),t.updating?"Updating…":t.hasUpdates?"Update now":"Up to date"]}),t.requiresRestart&&e.jsxs(T,{variant:"danger",onClick:l,children:[e.jsx(oe,{size:14})," Restart Dashboard"]})]}),t.error&&e.jsxs("div",{className:"updates-error",children:[e.jsx(ke,{size:14}),e.jsx("span",{children:t.error})]})]})}function Ir({settings:s,refreshSnapshot:t}){var se,Q,ie,xe,V,L,U;const a=ce(),[i,n]=r.useState(s),[l,o]=r.useState(!1),[c,g]=r.useState(!1),[m,x]=r.useState(null),[h,d]=r.useState({port:4321,https:!0,hostname:""}),[u,j]=r.useState({});r.useEffect(()=>{n(s),o(!1),s.theme&&as(s.theme)},[s]),r.useEffect(()=>{m&&d({port:m.settings.port,https:m.settings.https!==!1,hostname:m.settings.hostname||""})},[m]),r.useEffect(()=>{S.get("/tailscale/status").then(x).catch(()=>{})},[]),r.useEffect(()=>{S.get("/settings/plugin-options").then(j).catch(()=>{})},[]);const f=p=>{n(q=>{const H={...q,theme:{...q.theme,...p}};return as(H.theme),H}),o(!0)},y=p=>{n(q=>({...q,ui:{...q.ui,...p}})),o(!0)},$=(p,q)=>{n(H=>({...H,[p]:q})),o(!0)},b=p=>{n(q=>({...q,notifications:{...q.notifications,...p}})),o(!0)},k=p=>{n(q=>({...q,agents:{...q.agents,...p}})),o(!0)},P=[{id:"theme",label:"Theme"},{id:"layout",label:"Layout"},{id:"general",label:"General"},{id:"service",label:"Service"},{id:"tailscale",label:"Tailscale"},{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:"updates",label:"Updates"},{id:"activity-log",label:"Activity"},{id:"about",label:"About"}],[N,I]=r.useState(()=>{if(typeof window>"u")return null;const p=window.location.hash.replace(/^#settings-/,"");return P.some(q=>q.id===p)?p:null}),F=p=>{I(p);try{const q=p?`#settings-${p}`:window.location.pathname;if(history.replaceState(null,"",q),p){const H=document.getElementById(`settings-${p}`);H&&H.scrollIntoView({behavior:"smooth",block:"start"})}else window.scrollTo({top:0,behavior:"smooth"})}catch{}},w=p=>{n(q=>({...q,dashboard:{...q.dashboard,...p}})),o(!0)},E=async()=>{g(!0);try{const p=await S.put("/settings",i);n(p.data),o(!1),ps(p.data.theme),as(p.data.theme),a.success("Settings saved."),await t()}catch(p){a.error(`Save failed: ${p.message}`)}finally{g(!1)}},A=async()=>{try{const p=await S.get("/settings");n(p.data),o(!1),ps(p.data.theme),as(p.data.theme),a.info("Settings reloaded.",1500)}catch(p){a.error(`Reload failed: ${p.message}`)}},z=async()=>{if(confirm("Reset all settings to defaults?"))try{const p=await S.post("/settings/reset");n(p.data),o(!1),ps(p.data.theme),as(p.data.theme),a.success("Settings reset."),await t()}catch(p){a.error(`Reset failed: ${p.message}`)}},R=async()=>{try{m!=null&&m.settings.enabled?(await S.post("/tailscale/disable"),a.success("Tailscale serve disabled.")):(await S.post("/tailscale/enable",{port:h.port||4321,https:h.https,hostname:h.hostname||""}),a.success("Tailscale serve enabled."));const p=await S.get("/tailscale/status");x(p)}catch(p){a.error(`Tailscale failed: ${p.message}`)}},B=i.about||{version:"3.0.4",homepage:"https://github.com/DrB0rk/BizarHarness",license:"MIT"},[v,O]=r.useState(S.getToken()),[K,M]=r.useState(null),[W,te]=r.useState("");r.useEffect(()=>{let p=!1;return(async()=>{try{const q=await S.probeAuthStatus();p||M(q)}catch{p||M({required:!0,loopback:!1,peer:""})}})(),()=>{p=!0}},[]);const ee=async()=>{try{const p=await S.get("/auth/reveal");te(p.token),O(p.token),S.setToken(p.token);try{await navigator.clipboard.writeText(p.token),a.success("Token copied to clipboard.")}catch{a.success("Token revealed — copy from the field below.")}}catch(p){a.error(`Reveal failed: ${p.message}`)}},_=async()=>{if(confirm("Regenerate the auth token? Anything still using the old token will start getting 401 errors immediately."))try{const p=await S.post("/auth/regenerate");te(p.token),O(p.token),S.setToken(p.token);try{await navigator.clipboard.writeText(p.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(p){a.error(`Regenerate failed: ${p.message}`)}},Y=()=>{S.setToken(v.trim()),a.success("Token saved. The dashboard will use it on the next request.")};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(dt,{size:18})," Settings"]}),e.jsxs("p",{className:"view-subtitle",children:["Personal preferences. Changes are saved to"," ",e.jsx("code",{children:"~/.config/bizar/settings.json"}),"."]})]}),e.jsxs("div",{className:"view-actions",children:[e.jsxs(T,{variant:"ghost",size:"sm",onClick:z,children:[e.jsx(St,{size:14})," Reset"]}),e.jsxs(T,{variant:"secondary",size:"sm",onClick:A,children:[e.jsx(oe,{size:14})," Reload"]}),e.jsxs(T,{variant:"primary",size:"sm",disabled:!l||c,onClick:E,children:[c?e.jsx("span",{className:"btn-spinner"}):e.jsx(vs,{size:14}),c?"Saving…":"Save"]})]})]}),e.jsxs("nav",{className:"settings-subnav","aria-label":"Settings sections",children:[e.jsx("button",{type:"button",className:Z("settings-subnav-button","settings-subnav-button-all",N===null&&"settings-subnav-button-active"),onClick:()=>F(null),title:"Show all settings sections",children:"All"}),P.map(p=>e.jsx("button",{type:"button",className:Z("settings-subnav-button",N===p.id&&"settings-subnav-button-active"),onClick:()=>F(p.id),children:p.label},p.id))]}),e.jsxs("div",{className:Z("settings-grid",N&&"settings-grid-filtered"),"data-active-section":N||void 0,children:[N&&e.jsxs("div",{className:"settings-filter-banner",children:[e.jsxs("span",{children:["Showing only ",e.jsx("strong",{children:(se=P.find(p=>p.id===N))==null?void 0:se.label}),"."]}),e.jsx("button",{type:"button",className:"settings-filter-clear",onClick:()=>F(null),children:"Show all sections"})]}),e.jsx("div",{"data-section":"theme",style:{display:N===null||N==="theme"?"block":"none"},children:e.jsxs(J,{id:"settings-theme","data-section":"theme",children:[e.jsxs(ne,{children:[e.jsx(hn,{size:14})," Theme"]}),e.jsx(re,{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:zr.map(p=>e.jsxs("button",{type:"button",className:Z("theme-preset",i.theme.accent===p.accent&&"theme-preset-active"),onClick:()=>f({accent:p.accent}),title:p.name,children:[e.jsx("span",{className:"theme-preset-swatch",style:{background:p.accent}}),e.jsx("span",{className:"theme-preset-name",children:p.name})]},p.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:Cr.map(({id:p,label:q,Icon:H})=>{const D=i.theme.mode===p;return e.jsxs("button",{type:"button",className:Z("theme-card",D&&"theme-card-active"),onClick:()=>f({mode:p}),children:[e.jsx(H,{size:16}),e.jsx("span",{className:"theme-card-label",children:q}),e.jsx("span",{className:Z("theme-card-swatch",`theme-card-swatch-${p}`)})]},p)})})]}),e.jsxs("div",{className:"theme-colors",children:[e.jsxs("div",{className:"field","data-setting-id":"theme.accent",children:[e.jsx("label",{className:"field-label",children:"Accent"}),e.jsxs("div",{className:"color-row",children:[e.jsx("input",{type:"color",className:"input color-input",value:i.theme.accent,onChange:p=>f({accent:p.target.value}),"aria-label":"Accent color"}),e.jsx("input",{type:"text",className:"input",value:i.theme.accent,onChange:p=>f({accent:p.target.value}),"aria-label":"Accent color hex"})]})]}),e.jsxs("div",{className:"field","data-setting-id":"theme.success",children:[e.jsx("label",{className:"field-label",children:"Success"}),e.jsxs("div",{className:"color-row",children:[e.jsx("input",{type:"color",className:"input color-input",value:i.theme.success,onChange:p=>f({success:p.target.value}),"aria-label":"Success color"}),e.jsx("input",{type:"text",className:"input",value:i.theme.success,onChange:p=>f({success:p.target.value}),"aria-label":"Success color hex"})]})]}),e.jsxs("div",{className:"field","data-setting-id":"theme.warning",children:[e.jsx("label",{className:"field-label",children:"Warning"}),e.jsxs("div",{className:"color-row",children:[e.jsx("input",{type:"color",className:"input color-input",value:i.theme.warning,onChange:p=>f({warning:p.target.value}),"aria-label":"Warning color"}),e.jsx("input",{type:"text",className:"input",value:i.theme.warning,onChange:p=>f({warning:p.target.value}),"aria-label":"Warning color hex"})]})]}),e.jsxs("div",{className:"field","data-setting-id":"theme.error",children:[e.jsx("label",{className:"field-label",children:"Error"}),e.jsxs("div",{className:"color-row",children:[e.jsx("input",{type:"color",className:"input color-input",value:i.theme.error,onChange:p=>f({error:p.target.value}),"aria-label":"Error color"}),e.jsx("input",{type:"text",className:"input",value:i.theme.error,onChange:p=>f({error:p.target.value}),"aria-label":"Error color hex"})]})]}),e.jsxs("div",{className:"field","data-setting-id":"theme.info",children:[e.jsx("label",{className:"field-label",children:"Info"}),e.jsxs("div",{className:"color-row",children:[e.jsx("input",{type:"color",className:"input color-input",value:i.theme.info,onChange:p=>f({info:p.target.value}),"aria-label":"Info color"}),e.jsx("input",{type:"text",className:"input",value:i.theme.info,onChange:p=>f({info:p.target.value}),"aria-label":"Info color hex"})]})]})]}),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:i.theme.fontFamily,onChange:p=>f({fontFamily:p.target.value}),children:Tr.map(p=>e.jsx("option",{value:p,children:p},p))})]}),e.jsxs("div",{className:"field","data-setting-id":"theme.fontSize",children:[e.jsxs("label",{className:"field-label",children:["Font size: ",i.theme.fontSize,"px"]}),e.jsx("input",{type:"range",min:12,max:20,value:i.theme.fontSize,onChange:p=>f({fontSize:Number(p.target.value)})})]}),e.jsxs("label",{className:"checkbox-row","data-setting-id":"theme.compactMode",children:[e.jsx("input",{type:"checkbox",checked:i.theme.compactMode,onChange:p=>f({compactMode:p.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:i.theme.animations,onChange:p=>f({animations:p.target.checked})}),e.jsx("span",{children:"Enable animations"})]})]})}),e.jsx("div",{"data-section":"updates",style:{display:N===null||N==="updates"?"block":"none"},children:e.jsx(Ar,{})}),e.jsx("div",{"data-section":"layout",style:{display:N===null||N==="layout"?"block":"none"},children:e.jsxs(J,{id:"settings-layout","data-section":"layout",children:[e.jsxs(ne,{children:[e.jsx(pn,{size:14})," UI layout"]}),e.jsx(re,{children:"Choose how the dashboard's navigation is presented."}),e.jsx("div",{className:"layout-row","data-setting-id":"ui.layout",children:Rr.map(p=>e.jsx("button",{type:"button",className:Z("layout-card",i.ui.layout===p.id&&"layout-card-active"),onClick:()=>y({layout:p.id}),children:e.jsx("span",{className:"layout-card-label",children:p.label})},p.id))}),e.jsxs("label",{className:"checkbox-row","data-setting-id":"ui.showHeader",children:[e.jsx("input",{type:"checkbox",checked:i.ui.showHeader,onChange:p=>y({showHeader:p.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:i.ui.showStatusBar,onChange:p=>y({showStatusBar:p.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:i.ui.defaultTab,onChange:p=>y({defaultTab:p.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.jsx("div",{"data-section":"general",style:{display:N===null||N==="general"?"block":"none"},children:e.jsxs(J,{id:"settings-general","data-section":"general",children:[e.jsx(ne,{children:"General"}),e.jsx(re,{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:i.defaultAgent||"",onChange:p=>$("defaultAgent",p.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:i.defaultModel||"",onChange:p=>$("defaultModel",p.target.value)})]})]})}),e.jsx("div",{"data-section":"service",style:{display:N===null||N==="service"?"block":"none"},children:e.jsxs(J,{id:"settings-service","data-section":"service",children:[e.jsxs(ne,{children:[e.jsx(xs,{size:14})," Service"]}),e.jsx(re,{children:"Background daemon that runs schedules."}),e.jsx("div",{"data-setting-id":"service.enabled",children:m?e.jsxs("div",{className:"service-card",children:[e.jsxs("p",{children:["Status: ",e.jsx("strong",{children:m!=null&&m.settings.enabled?"enabled":"disabled"})," ","· Tailscale installed: ",e.jsx("strong",{children:m.installed?"yes":"no"})," ","· authenticated: ",e.jsx("strong",{children:m.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.jsx("div",{"data-section":"tailscale",style:{display:N===null||N==="tailscale"?"block":"none"},children:e.jsxs(J,{id:"settings-tailscale","data-section":"tailscale",children:[e.jsxs(ne,{children:[e.jsx(it,{size:14})," Tailscale serve"]}),e.jsx(re,{children:"Expose the dashboard over your Tailscale network."}),m?e.jsxs(e.Fragment,{children:[e.jsxs("p",{children:["Installed: ",e.jsx("strong",{children:m.installed?"yes":"no"})," ",m.version&&e.jsxs("span",{className:"muted",children:["(",m.version,")"]})]}),e.jsxs("p",{children:["Authenticated: ",e.jsx("strong",{children:m.authenticated?"yes":"no"})]}),e.jsxs("p",{children:["Serve enabled: ",e.jsx("strong",{children:m.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:h.port,onChange:p=>d(q=>({...q,port:Number(p.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:h.https,onChange:p=>d(q=>({...q,https:p.target.checked}))})]})]}),e.jsx(T,{variant:"primary",onClick:R,children:m.settings.enabled?"Disable serve":"Enable serve"})]}):e.jsx("p",{className:"muted",children:"Loading Tailscale status…"})]})}),e.jsx("div",{"data-section":"notifications",style:{display:N===null||N==="notifications"?"block":"none"},children:e.jsxs(J,{id:"settings-notifications","data-section":"notifications",children:[e.jsx(ne,{children:"Notifications"}),e.jsx(re,{children:"Toast triggers inside the dashboard."}),e.jsxs("label",{className:"checkbox-row","data-setting-id":"notifications.onAgentComplete",children:[e.jsx("input",{type:"checkbox",checked:!!i.notifications.onAgentComplete,onChange:p=>b({onAgentComplete:p.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:!!i.notifications.onPlanApproval,onChange:p=>b({onPlanApproval:p.target.checked})}),e.jsx("span",{children:"Notify when a plan needs approval"})]})]})}),e.jsx("div",{"data-section":"auth",style:{display:N===null||N==="auth"?"block":"none"},children:e.jsxs(J,{id:"settings-auth","data-section":"auth",children:[e.jsxs(ne,{children:[e.jsx(bn,{size:14})," Authentication"]}),e.jsx(re,{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:K?K.required?"yes":"no":"probing…"})]}),e.jsxs("p",{style:{margin:"4px 0"},children:["Connection:"," ",e.jsx("strong",{children:K?K.loopback?"loopback (auto-trusted)":"remote":"probing…"})]}),e.jsxs("p",{style:{margin:"4px 0"},children:["Peer address:"," ",K!=null&&K.peer?e.jsx("code",{children:K.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:v,onChange:p=>O(p.target.value),placeholder:"Paste token from server stderr or another browser",spellCheck:!1,autoComplete:"off"}),e.jsxs("div",{className:"task-form-row",style:{marginTop:8},children:[e.jsxs(T,{variant:"secondary",size:"sm",onClick:Y,children:[e.jsx(jt,{size:14})," Save token"]}),e.jsxs(T,{variant:"ghost",size:"sm",onClick:ee,children:[e.jsx(Hs,{size:14})," Reveal & copy server token"]}),e.jsxs(T,{variant:"ghost",size:"sm",onClick:_,children:[e.jsx(St,{size:14})," Regenerate"]})]}),W?e.jsxs("p",{className:"muted",style:{fontSize:12,marginTop:8},children:["Last revealed token (one-time): ",e.jsx("code",{className:"mono",children:W})]}):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."})]})]})}),e.jsx("div",{"data-section":"agents",style:{display:N===null||N==="agents"?"block":"none"},children:e.jsxs(J,{id:"settings-agents","data-section":"agents",children:[e.jsxs(ne,{children:[e.jsx(xs,{size:14})," Agent Behavior"]}),e.jsx(re,{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:((Q=i.agents)==null?void 0:Q.maxParallel)??6,onChange:p=>k({maxParallel:Math.max(1,Math.min(20,parseInt(p.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:((ie=i.agents)==null?void 0:ie.stuckThresholdMs)??6e5,onChange:p=>k({stuckThresholdMs:Math.max(6e4,Math.min(36e5,parseInt(p.target.value,10)||6e5))})})]}),e.jsxs("label",{className:"checkbox-row","data-setting-id":"agents.autoRestart",children:[e.jsx("input",{type:"checkbox",checked:!!((xe=i.agents)!=null&&xe.autoRestart),onChange:p=>k({autoRestart:p.target.checked})}),e.jsx("span",{children:"Auto-restart stuck agents"})]})]})}),e.jsx("div",{"data-section":"dashboard",style:{display:N===null||N==="dashboard"?"block":"none"},children:e.jsxs(J,{id:"settings-dashboard","data-section":"dashboard",children:[e.jsxs(ne,{children:[e.jsx(ys,{size:14})," Dashboard"]}),e.jsxs(re,{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:i.dashboard.autoLaunchWeb!==!1,onChange:p=>w({autoLaunchWeb:p.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:i.dashboard.projectsDirectory??"",onChange:p=>w({projectsDirectory:p.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."}),i.dashboard.projectsDirectory&&e.jsxs(e.Fragment,{children:[!/^\/|^[A-Za-z]:/.test(i.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)."}),i.dashboard.projectsDirectory.includes("..")&&e.jsx("p",{style:{color:"var(--error)",fontSize:11,marginTop:4},children:"Path traversal not allowed — this will be rejected server-side."})]})]}),e.jsxs("div",{className:"field","data-setting-id":"dashboard.allowedRoots",style:{marginTop:"var(--space-4)"},children:[e.jsxs("label",{className:"field-label",htmlFor:"set-allowed-roots",children:["Additional allowed roots ",e.jsx("span",{className:"muted",children:"(advanced)"})]}),e.jsx("textarea",{id:"set-allowed-roots",className:"textarea",rows:4,placeholder:`/workspace
|
|
352
|
+
/srv/projects`,value:(i.dashboard.allowedRoots??[]).join(`
|
|
353
|
+
`),onChange:p=>{const q=p.target.value.split(`
|
|
354
|
+
`).map(H=>H.trim()).filter(Boolean);w({allowedRoots:q})}}),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 p=(i.dashboard.allowedRoots??[]).join(`
|
|
355
|
+
`).split(`
|
|
356
|
+
`),q=[];return p.forEach((H,D)=>{H.trim()&&(/^\/|^[A-Za-z]:/.test(H)||q.push({key:`noabs-${D}`,msg:e.jsxs("p",{style:{color:"var(--warning)",fontSize:11,marginTop:2},children:["Line ",D+1,': "',H,'" — should be absolute (start with / or a drive letter).']})}),H.includes("..")&&q.push({key:`dots-${D}`,msg:e.jsxs("p",{style:{color:"var(--error)",fontSize:11,marginTop:2},children:["Line ",D+1,': "',H,`" — contains '..' (server will reject this).`]})}))}),q.map(H=>H.msg)})()]})]})}),e.jsx("div",{"data-section":"background",style:{display:N===null||N==="background"?"block":"none"},children:e.jsxs(J,{id:"settings-background","data-section":"background",children:[e.jsxs(ne,{children:[e.jsx(xs,{size:14})," Background Agents"]}),e.jsx(re,{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:u.maxConcurrentInstances??8,onChange:p=>j(q=>({...q,maxConcurrentInstances:Math.max(1,Math.min(32,parseInt(p.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:u.backgroundToolCallCap??500,onChange:p=>j(q=>({...q,backgroundToolCallCap:Math.max(1,Math.min(5e3,parseInt(p.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:u.backgroundStallTimeoutMs??18e4,onChange:p=>j(q=>({...q,backgroundStallTimeoutMs:Math.max(1e4,Math.min(6e5,parseInt(p.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:u.backgroundThinkingLoopTimeoutMs??3e5,onChange:p=>j(q=>({...q,backgroundThinkingLoopTimeoutMs:Math.max(3e4,Math.min(9e5,parseInt(p.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:u.backgroundMaxInterventions??1,onChange:p=>j(q=>({...q,backgroundMaxInterventions:Math.max(1,Math.min(3,parseInt(p.target.value,10)||1))}))}),e.jsxs("small",{className:"muted",children:["Plugin option: ",e.jsx("code",{children:"backgroundMaxInterventions"})]})]}),e.jsxs("div",{className:"form-row",children:[e.jsxs(T,{variant:"secondary",size:"sm",onClick:async()=>{try{await S.put("/settings/plugin-options",u),a.success("Saved — restart opencode for changes to take effect.")}catch(p){a.error(`Save failed: ${p.message}`)}},children:[e.jsx(vs,{size:14})," Save plugin options"]}),e.jsx(T,{variant:"secondary",size:"sm",onClick:async()=>{try{const q=await(await fetch("/api/background/cleanup",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({maxAgeDays:7})})).json();a.success(`Cleaned up ${q.deleted} old instances.`)}catch(p){a.error(`Cleanup failed: ${p.message}`)}},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."]})})]})})]}),e.jsx("div",{"data-section":"system-llm",style:{display:N===null||N==="system-llm"?"block":"none"},children:e.jsxs(J,{id:"settings-system-llm","data-section":"system-llm",children:[e.jsxs(ne,{children:[e.jsx(Fe,{size:14})," System LLM API"]}),e.jsx(re,{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:!!((V=i.systemLlm)!=null&&V.enabled),onChange:p=>{const q=i.systemLlm||{enabled:!0,provider:"opencode",model:"opencode/deepseek-v4-flash-free"};$("systemLlm",{...q,enabled:p.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:((L=i.systemLlm)==null?void 0:L.provider)||"opencode",onChange:p=>{const q=i.systemLlm||{enabled:!0,provider:"opencode",model:"opencode/deepseek-v4-flash-free"};$("systemLlm",{...q,provider:p.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:((U=i.systemLlm)==null?void 0:U.model)||"opencode/deepseek-v4-flash-free",onChange:p=>{const q=i.systemLlm||{enabled:!0,provider:"opencode",model:"opencode/deepseek-v4-flash-free"};$("systemLlm",{...q,model:p.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"})]})]})]})}),e.jsx("div",{"data-section":"headroom",style:{display:N===null||N==="headroom"?"block":"none"},children:e.jsx(Sr,{settings:i.headroom||It,onPatch:p=>{n(q=>({...q,headroom:{...q.headroom||It,...p}})),o(!0)}})}),e.jsx($r,{}),e.jsx("div",{style:{display:N===null||N==="activity-log"?"block":"none"},children:e.jsx("div",{"data-section":"activity-log",style:{display:N===null||N==="activity-log"?"block":"none"},children:e.jsx("section",{id:"settings-activity-log","data-section":"activity-log",className:"settings-section-wrap",children:e.jsx(Lr,{})})})}),e.jsx("div",{style:{display:N===null||N==="about"?"block":"none"},children:e.jsx("div",{"data-section":"about",style:{display:N===null||N==="about"?"block":"none"},children:e.jsxs(J,{id:"settings-about","data-section":"about",children:[e.jsxs(ne,{children:[e.jsx(_s,{size:14})," About"]}),e.jsx(re,{children:"Build metadata."}),e.jsxs("dl",{className:"about-table",children:[e.jsx("dt",{children:"Version"}),e.jsx("dd",{className:"mono",children:B.version}),e.jsx("dt",{children:"Homepage"}),e.jsx("dd",{children:e.jsx("a",{href:B.homepage,target:"_blank",rel:"noopener noreferrer",children:B.homepage})}),e.jsx("dt",{children:"License"}),e.jsx("dd",{children:B.license})]})]})})})]})}function Lr(){const s=ce(),[t,a]=r.useState([]),[i,n]=r.useState(new Set),[l,o]=r.useState(!0),[c,g]=r.useState(""),[m,x]=r.useState(!0),h=r.useCallback(async()=>{o(!0);try{const[y,$]=await Promise.all([S.get("/activity"),S.get("/activity/hidden")]);a(Array.isArray(y.items)?y.items:[]),n(new Set($.hidden||[]))}catch(y){s.error(`Load failed: ${y.message}`)}finally{o(!1)}},[s]);r.useEffect(()=>{h()},[h]);const d=(y,$)=>{const b=`${y.kind||""}|${y.ts||""}|${y.slug||""}|${$}`;let k=0;for(let P=0;P<b.length;P++)k=(k<<5)-k+b.charCodeAt(P)|0;return Math.abs(k).toString(16).padStart(8,"0").slice(0,16)},u=async()=>{try{await S.del("/activity/hide"),n(new Set),s.success("All hidden activity restored.")}catch(y){s.error(`Restore failed: ${y.message}`)}},j=async y=>{try{await S.del(`/activity/hide/${encodeURIComponent(y)}`);const $=new Set(i);$.delete(y),n($)}catch($){s.error(`Restore failed: ${$.message}`)}},f=t.filter((y,$)=>{const b=d(y,$);if(!m&&i.has(b))return!1;if(!c)return!0;const k=c.toLowerCase();return[y.kind,y.slug,y.message].some(P=>typeof P=="string"&&P.toLowerCase().includes(k))});return e.jsxs(J,{id:"settings-diagnostics","data-section":"diagnostics",children:[e.jsxs(ne,{children:[e.jsx(Te,{size:14})," Activity log",e.jsxs("span",{className:"muted",style:{fontWeight:400,marginLeft:8,fontSize:12},children:[t.length," total · ",i.size," hidden"]}),e.jsx(T,{variant:"ghost",size:"sm",style:{marginLeft:"auto"},onClick:h,title:"Reload",children:e.jsx(oe,{size:12})})]}),e.jsxs(re,{children:["Full history from ",e.jsx("code",{children:"~/.bizar/activity.log"}),". Hiding an item in the Overview only hides it there — the entry stays here."]}),e.jsxs("div",{className:"activity-log-toolbar",children:[e.jsxs("div",{className:"activity-log-search",children:[e.jsx(ye,{size:12}),e.jsx("input",{type:"text",className:"input",placeholder:"Filter by kind, slug, or message…",value:c,onChange:y=>g(y.target.value)})]}),e.jsxs("label",{className:"activity-log-toggle",children:[e.jsx("input",{type:"checkbox",checked:m,onChange:y=>x(y.target.checked)}),"Show hidden"]}),e.jsxs(T,{variant:"ghost",size:"sm",disabled:i.size===0,onClick:u,title:"Restore all hidden items to the Overview",children:[e.jsx(is,{size:12})," Restore all"]})]}),l?e.jsx("div",{className:"muted",style:{padding:"12px 0",fontSize:12},children:"Loading…"}):f.length===0?e.jsx("div",{className:"muted",style:{padding:"12px 0",fontSize:12},children:t.length===0?"No activity yet.":"No items match the current filter."}):e.jsxs("div",{className:"activity-log-table-wrap",children:[e.jsxs("table",{className:"activity-log-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Kind"}),e.jsx("th",{children:"Detail"}),e.jsx("th",{children:"Time"}),e.jsx("th",{})]})}),e.jsx("tbody",{children:f.slice(0,200).map((y,$)=>{const b=d(y,$),k=i.has(b);return e.jsxs("tr",{className:Z(k&&"activity-log-row-hidden"),children:[e.jsx("td",{className:"activity-log-kind",children:y.kind||"activity"}),e.jsx("td",{className:"activity-log-detail",children:y.message||y.slug||"—"}),e.jsx("td",{className:"activity-log-time mono",children:y.ts?new Date(y.ts).toLocaleString():"—"}),e.jsx("td",{children:k?e.jsx(T,{variant:"ghost",size:"sm",onClick:()=>j(b),title:"Restore to Overview",children:e.jsx(is,{size:12})}):e.jsx("span",{className:"activity-log-state-tag",children:"shown"})})]},`${y.ts}-${$}`)})})]}),f.length>200&&e.jsxs("div",{className:"muted",style:{fontSize:11,padding:"8px 0"},children:["Showing first 200 of ",f.length,"."]})]})]})}const Lt=We.memo(Ir);function Er({snapshot:s,refreshSnapshot:t}){const a=ce(),i=De(),[n,l]=r.useState(Array.isArray(s.mods)?s.mods:[]),[o,c]=r.useState(!0),[g,m]=r.useState(null),[x,h]=r.useState([]),[d,u]=r.useState(null),[j,f]=r.useState(!1),[y,$]=r.useState(null),[b,k]=r.useState(!1),[P,N]=r.useState({}),I=async()=>{var v,O,K;k(!0);try{const M=await S.get("/mods/registry");$({source:((v=M.registry)==null?void 0:v.source)||"",version:(O=M.registry)==null?void 0:O.version,updatedAt:(K=M.registry)==null?void 0:K.updatedAt,mods:M.mods||[]})}catch(M){$({source:"",mods:[],error:M.message})}finally{k(!1)}},F=async v=>{N(O=>({...O,[v]:!0}));try{const O=await S.post("/mods",{id:v});l(K=>[...K.filter(M=>M.id!==O.id),O]),a.success(`Mod "${O.id}" installed from registry.`),await t()}catch(O){a.error(`Install failed: ${O.message}`)}finally{N(O=>({...O,[v]:!1}))}},w=async(v,O=!1)=>{N(K=>({...K,[v]:!0}));try{const K=await S.post(`/mods/${encodeURIComponent(v)}/upgrade`,{backup:O});l(W=>[...W.filter(te=>te.id!==K.mod.id),K.mod]);const M=K.backupPath?` (backup at ${K.backupPath})`:"";a.success(`Mod "${v}" upgraded v${K.from} → v${K.to}${M}.`),await t()}catch(K){a.error(`Upgrade failed: ${K.message}`)}finally{N(K=>({...K,[v]:!1}))}},E=async()=>{try{const v=await S.get("/mods");l(v.mods||[]);try{const O=await S.get("/mods/views");h(O.views||[])}catch{h([])}}catch(v){a.error(`Mods load failed: ${v.message}`)}finally{c(!1)}};r.useEffect(()=>{E()},[]),r.useEffect(()=>{Array.isArray(s.mods)&&s.mods!==n&&l(s.mods)},[s.mods]);const A=()=>{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",children:"Path"}),e.jsx("input",{ref:O=>v=O,className:"input",type:"text",placeholder:"/path/to/my-mod",autoFocus:!0})]}),footer:e.jsxs("div",{className:"modal-footer-actions",children:[e.jsx(T,{variant:"ghost",onClick:()=>i.close(),children:"Cancel"}),e.jsx(T,{variant:"primary",onClick:async()=>{const O=((v==null?void 0:v.value)||"").trim();if(!O){a.warning("Path is required.");return}try{const K=await S.post("/mods",{path:O});l(M=>[...M,K]),a.success(`Mod "${K.id}" installed.`),i.close(),await t()}catch(K){a.error(`Install failed: ${K.message}`)}},children:"Install"})]})})},z=async v=>{if(confirm(`Uninstall mod "${v}"? This removes the folder from ~/.config/bizar/mods/.`))try{await S.del(`/mods/${encodeURIComponent(v)}`),l(O=>O.filter(K=>K.id!==v)),g===v&&m(null),a.success("Mod uninstalled.")}catch(O){a.error(`Uninstall failed: ${O.message}`)}},R=async v=>{try{const O=await S.put(`/mods/${encodeURIComponent(v.id)}`,{enabled:!v.enabled});l(K=>K.map(M=>M.id===v.id?O:M)),a.success(`Mod ${O.enabled?"enabled":"disabled"}.`)}catch(O){a.error(`Toggle failed: ${O.message}`)}},B=n.find(v=>v.id===g)||null;return o?e.jsx("div",{className:"view-loading",children:e.jsx(he,{size:"lg"})}):e.jsxs("div",{className:"view view-mods",children:[e.jsxs("header",{className:"view-header",children:[e.jsxs("div",{className:"view-header-text",children:[e.jsxs("h2",{className:"view-title",children:[e.jsx(Bs,{size:18})," Mods (",n.length,")"]}),e.jsxs("p",{className:"view-subtitle",children:["Extensions installed in ",e.jsx("code",{children:"~/.config/bizar/mods/"}),". Mods can add agents, commands, routes, and views."]})]}),e.jsxs("div",{className:"view-actions",children:[e.jsxs(T,{variant:"secondary",size:"sm",onClick:E,children:[e.jsx(oe,{size:14})," Refresh"]}),e.jsxs(T,{variant:"primary",size:"sm",onClick:A,children:[e.jsx(Me,{size:14})," Install mod"]})]})]}),n.length===0?e.jsx(we,{icon:e.jsx(Bs,{size:32}),title:"No mods installed",message:"Mods are folders with a mod.json. Install one to extend Bizar with custom agents, commands, and views."}):e.jsxs("div",{className:"mods-layout",children:[e.jsx("div",{className:"mods-list",children:n.map(v=>e.jsxs("div",{className:Z("mod-list-item",g===v.id&&"mod-list-item-active"),onClick:()=>m(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:O=>O.stopPropagation(),children:[e.jsx("button",{type:"button",className:"icon-btn","aria-label":"Toggle enabled",title:v.enabled?"Disable":"Enable",onClick:()=>R(v),children:e.jsx(ht,{size:12})}),e.jsx("button",{type:"button",className:"icon-btn icon-btn-danger","aria-label":"Uninstall",title:"Uninstall",onClick:()=>z(v.id),children:e.jsx(Re,{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))}),B&&e.jsx(Dr,{mod:B})]}),e.jsxs(J,{className:"mods-registry-card",children:[e.jsxs("div",{className:"mods-registry-head",onClick:()=>{!y&&!b&&I(),f(v=>!v)},children:[e.jsx(ys,{size:14}),e.jsx("span",{className:"mods-registry-title",children:"Mod registry"}),e.jsx("span",{className:"muted",style:{fontSize:11},children:y!=null&&y.mods?`${y.mods.length} available`:"click to browse"}),e.jsx("span",{className:"mods-registry-spacer"}),j?e.jsx(Oe,{size:14}):e.jsx(He,{size:14})]}),j&&e.jsx("div",{className:"mods-registry-body",children:b?e.jsx("div",{className:"muted",style:{padding:12,fontSize:12},children:"Loading registry…"}):y!=null&&y.error?e.jsxs("div",{className:"mods-registry-error",children:[e.jsx(bs,{size:12})," Could not load registry: ",y.error]}):!y||y.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:[y.source&&e.jsxs("div",{className:"muted",style:{fontSize:11,marginBottom:8},children:["Source: ",e.jsx("code",{children:y.source})]}),e.jsx("div",{className:"mods-registry-grid",children:y.mods.map(v=>{const O=n.some(M=>M.id===v.id),K=!!P[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:Z("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(bs,{size:10}),(v.permissions||[]).slice(0,4).map(M=>e.jsx("span",{className:"mod-registry-perm",children:M},M)),(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:[!O&&e.jsx(T,{variant:"primary",size:"sm",disabled:K,onClick:()=>F(v.id),title:"Install from registry",children:K?e.jsx(he,{size:"sm"}):e.jsxs(e.Fragment,{children:[e.jsx(Xe,{size:12})," Install"]})}),O&&v.upgradeAvailable&&e.jsx(T,{variant:"primary",size:"sm",disabled:K,onClick:()=>w(v.id),title:`Upgrade from v${v.installedVersion||"?"} to v${v.upgradeAvailable}`,children:K?e.jsx(he,{size:"sm"}):e.jsxs(e.Fragment,{children:[e.jsx(Xe,{size:12})," Upgrade to v",v.upgradeAvailable]})}),O&&!v.upgradeAvailable&&e.jsxs(T,{variant:"ghost",size:"sm",disabled:!0,title:`Installed v${v.installedVersion||"?"}`,children:["Installed v",v.installedVersion||"?"]})]})]},v.id)})})]})})]}),x.length>0&&e.jsxs(J,{className:"mod-views-hint",children:[e.jsxs(ne,{children:[e.jsx(ys,{size:14})," Mod views"]}),e.jsxs(re,{children:[x.length," mod-supplied view",x.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."]})]}),d&&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:d,target:"_blank",rel:"noreferrer",children:d})]}),e.jsx("button",{type:"button",className:"icon-btn","aria-label":"Close iframe",onClick:()=>u(null),children:e.jsx($e,{size:14})})]}),e.jsx("iframe",{src:d,className:"mod-iframe",title:"Mod view",sandbox:"allow-scripts allow-same-origin allow-forms allow-popups"})]})]})}function Dr({mod:s}){const t=ce(),[a,i]=r.useState(null),[n,l]=r.useState(!1),[o,c]=r.useState(!1),[g,m]=r.useState(null),x=async()=>{l(!0);try{const d=await S.get(`/mods/${s.id}/instructions`);i(d),c(!0)}catch(d){t.error(`Failed to load instructions: ${d.message}`)}finally{l(!1)}},h=async()=>{try{const d=await S.post(`/mods/${s.id}/instructions/reinstall`,{});t.success(`Reinstalled: ${d.counts.agents} agents, ${d.counts.commands} commands, ${d.counts.skills} skills, ${d.counts.instructions} instructions.`),await x()}catch(d){t.error(`Reinstall failed: ${d.message}`)}};return e.jsxs(J,{className:"mod-details",children:[e.jsxs(ne,{children:[e.jsx(Se,{size:14})," Mod details — ",s.name]}),e.jsx(re,{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(d=>e.jsx("span",{className:"tag",children:d},d)),(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(d=>e.jsxs("li",{children:[e.jsx("span",{className:"mod-file-cat",children:d.category}),e.jsx("span",{className:"mono",children:d.path})]},d.path))})]}),e.jsxs("div",{className:"mod-instructions",children:[e.jsxs("div",{className:"mod-instructions-head",onClick:()=>{!a&&!n&&x(),c(d=>!d)},children:[e.jsx(Qa,{size:14}),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"}),o?e.jsx(Oe,{size:14}):e.jsx(He,{size:14})]}),o&&a&&e.jsxs("div",{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(Cn,{size:11})," Agents (",a.agents.length,")"]}),a.agents.map(d=>e.jsxs("div",{className:"mod-instructions-file",children:[e.jsxs("div",{className:"mod-instructions-file-head",onClick:()=>m(u=>u===d.filename?null:d.filename),children:[e.jsx("span",{className:"mono",children:d.filename}),e.jsxs("span",{className:"muted",style:{fontSize:10},children:["installed at ",d.fullPath]})]}),g===d.filename&&e.jsx("pre",{className:"mod-instructions-content",children:d.content||e.jsx("em",{className:"muted",children:"(file missing on disk)"})})]},d.filename))]}),a.commands.length>0&&e.jsxs("div",{className:"mod-instructions-section",children:[e.jsxs("div",{className:"mod-instructions-section-title",children:[e.jsx(fs,{size:11})," Commands (",a.commands.length,")"]}),a.commands.map(d=>e.jsxs("div",{className:"mod-instructions-file",children:[e.jsxs("div",{className:"mod-instructions-file-head",onClick:()=>m(u=>u===d.filename?null:d.filename),children:[e.jsx("span",{className:"mono",children:d.filename}),e.jsxs("span",{className:"muted",style:{fontSize:10},children:["installed at ",d.fullPath]})]}),g===d.filename&&e.jsx("pre",{className:"mod-instructions-content",children:d.content||e.jsx("em",{className:"muted",children:"(file missing on disk)"})})]},d.filename))]}),a.skills.length>0&&e.jsxs("div",{className:"mod-instructions-section",children:[e.jsxs("div",{className:"mod-instructions-section-title",children:[e.jsx(Wt,{size:11})," Skills (",a.skills.length,")"]}),a.skills.map(d=>e.jsxs("div",{className:"mod-instructions-file",children:[e.jsxs("div",{className:"mod-instructions-file-head",onClick:()=>m(u=>u===d.name?null:d.name),children:[e.jsx("span",{className:"mono",children:d.name}),e.jsxs("span",{className:"muted",style:{fontSize:10},children:["installed at ",d.fullPath]})]}),g===d.name&&e.jsx("pre",{className:"mod-instructions-content",children:d.content||e.jsx("em",{className:"muted",children:"(file missing on disk)"})})]},d.name))]}),a.total===0&&e.jsxs("div",{className:"muted",style:{padding:8,fontSize:12},children:["This mod did not install any instruction files. Mods install instructions by shipping a top-level ",e.jsx("code",{children:"INSTRUCTIONS.md"}),", an ",e.jsx("code",{children:"agents/"})," directory, a ",e.jsx("code",{children:"commands/"})," directory, or a ",e.jsx("code",{children:"skills/"})," directory."]}),e.jsx("div",{className:"mod-instructions-actions",children:e.jsxs(T,{variant:"ghost",size:"sm",onClick:h,children:[e.jsx(oe,{size:11})," Reinstall from mod folder"]})})]})]})]})}function Pr({viewId:s,reloadKey:t,setActiveTab:a}){const i=ce(),[n,l]=r.useState(null),[o,c]=r.useState(!0),[g,m]=r.useState(0);if(r.useEffect(()=>{let x=!1;return(async()=>{try{const h=await S.get("/mods/views");if(x)return;const d=(h.views||[]).find(u=>u.id===s);l(d||null)}catch(h){i.error(`Failed to load mod view: ${h.message}`)}finally{x||c(!1)}})(),()=>{x=!0}},[s,i]),o)return e.jsx(we,{title:"Loading mod view…"});if(!n)return e.jsx(we,{title:"Mod view not found",message:`No view with id "${s}" is currently installed.`,action:e.jsx(T,{onClick:()=>a("mods"),variant:"primary",size:"sm",children:"Open Mods"})});if(n.kind==="iframe"){const x=`/api/mods/${n.modId}/web/index.html?t=${g+(t||0)}`;return e.jsxs("div",{className:"mod-view-iframe-pane",children:[e.jsxs("div",{className:"mod-view-iframe-header",children:[e.jsxs("span",{className:"mod-view-iframe-label",children:[e.jsx(ys,{size:14}),n.label,e.jsxs("span",{className:"muted",style:{fontSize:11,fontWeight:400},children:["by ",n.modId]})]}),e.jsxs("div",{className:"mod-view-iframe-actions",children:[e.jsxs(T,{variant:"ghost",size:"sm",onClick:()=>m(h=>h+1),title:"Reload this view",children:[e.jsx(oe,{size:11})," Reload"]}),e.jsx("a",{href:x,target:"_blank",rel:"noopener noreferrer",className:"icon-btn",title:"Open in new tab",children:e.jsx(ls,{size:12})})]})]}),e.jsx("iframe",{src:x,className:"mod-view-iframe",title:n.label},g+(t||0))]})}if(n.component){const x=n.component,h=n.modId,d=r.lazy(()=>Ht(()=>import(`/api/mods/${encodeURIComponent(h)}/views/${encodeURIComponent(x)}`),[]).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(nt,{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(Or,{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(d,{})})})})]})}return e.jsxs(J,{children:[e.jsxs(ne,{children:[e.jsx(nt,{size:14})," ",n.label]}),e.jsxs(re,{children:["by ",n.modId]}),n.description&&e.jsx("p",{className:"muted",style:{marginTop:8},children:n.description}),e.jsxs("p",{className:"muted",style:{fontSize:12,marginTop:12},children:["This mod declared a tab view but did not provide a component path in views/registry.json. Add a ",e.jsx("code",{children:"component"})," field (e.g. ",e.jsx("code",{children:'"MyView.js"'}),") and ship the file under ",e.jsx("code",{children:"views/"}),"."]}),e.jsx("div",{style:{marginTop:12},children:e.jsx(T,{variant:"secondary",size:"sm",onClick:()=>a("mods"),children:"Open Mods page"})})]})}class Or extends r.Component{constructor(){super(...arguments);cs(this,"state",{error:null})}static getDerivedStateFromError(a){return{error:a}}componentDidCatch(){}render(){return this.state.error?e.jsxs("div",{className:"mod-view-error",children:[e.jsx(ke,{size:16}),e.jsx("strong",{children:"Failed to render mod view"}),e.jsxs("div",{className:"muted",style:{fontSize:12,marginTop:6},children:[this.props.modId," → ",this.props.component,": ",this.state.error.message]})]}):this.props.children}}const Fr=["interval","cron","once"],Br=["command","agent","webhook"],ot=[{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)"}],Ur=Array.from({length:12},(s,t)=>t*5),bt=Array.from({length:24},(s,t)=>({value:t,label:t===0?"12 AM":t<12?`${t} AM`:t===12?"12 PM":`${t-12} PM`})),kt=[{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"}],aa=[{value:"s",label:"seconds"},{value:"m",label:"minutes"},{value:"h",label:"hours"},{value:"d",label:"days"}];function na(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),o=parseInt(i,10);if(!Number.isFinite(l)||!Number.isFinite(o)||a!==String(l)||i!==String(o))return null;const c=n==="*"?"*":parseInt(n,10);return c===null||n!=="*"&&!Number.isFinite(c)?null:{minute:l,hour:o,dow:n==="*"?"*":String(c)}}function qr(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 _r(s){var l,o;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"?na(s.schedule):null,a=s.type==="interval"?qr(s.schedule):null,i=s.timezone||"UTC",n=ot.some(c=>c.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"?Hr(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((o=s.budgetCheck)==null?void 0:o.maxConcurrent)?s.budgetCheck.maxConcurrent:6,enabled:s.enabled!==!1,humanLabel:""}}function Hr(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 Wr(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}`,o=((a=kt.find(x=>x.value===s.cronDow))==null?void 0:a.label)||"",c=((i=bt.find(x=>x.value===s.cronHour))==null?void 0:i.label)||`${s.cronHour}`,g=String(s.cronMinute).padStart(2,"0"),m=o==="Every day"?`Every day at ${c.replace(" ","")} (min ${g})`:`Every ${o} at ${c.replace(" ","")} (min ${g})`;return{schedule:l,humanLabel:s.humanLabel||m}}if(s.type==="interval"){const l=((n=aa.find(c=>c.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 Vr({snapshot:s,refreshSnapshot:t}){var d;const a=ce(),i=De(),[n,l]=r.useState(s.schedules||[]),[o,c]=r.useState(!s.schedules),g=async()=>{try{const u=await S.get("/projects/active/schedules");l(u.schedules||[])}catch(u){a.error(`Schedules load failed: ${u.message}`)}finally{c(!1)}};r.useEffect(()=>{var u;if((u=s.schedules)!=null&&u.length||s.schedules){l(s.schedules||[]),c(!1);return}g()},[s.schedules]);const m=u=>{i.open({title:u?`Edit schedule: ${u.name}`:"New schedule",width:640,children:e.jsx(Kr,{initial:u,onClose:i.close,onSubmitted:async j=>{l(f=>{const y=f.findIndex(b=>b.id===j.id);if(y===-1)return[...f,j];const $=f.slice();return $[y]=j,$}),a.success(u?"Schedule updated.":"Schedule created."),i.close(),await t()},onError:j=>a.error(j)})})},x=async u=>{var j;try{const f=await S.post(`/schedules/${encodeURIComponent(u.id)}/run`);a.success(f.ok?"Schedule ran.":`Run failed: ${((j=f.runResult)==null?void 0:j.error)||"unknown"}`),await g()}catch(f){a.error(`Run failed: ${f.message}`)}},h=async u=>{if(confirm(`Delete schedule "${u.name}"?`))try{await S.del(`/schedules/${encodeURIComponent(u.id)}`),l(j=>j.filter(f=>f.id!==u.id)),a.success("Schedule deleted.")}catch(j){a.error(`Delete failed: ${j.message}`)}};return o?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(Ps,{size:18})," Schedules (",n.length,")"]}),e.jsxs("p",{className:"view-subtitle",children:["Recurring tasks for the active project: ",e.jsx("strong",{children:((d=s.activeProject)==null?void 0:d.name)||"(none)"}),". Service daemon runs them at the right time."]})]}),e.jsxs("div",{className:"view-actions",children:[e.jsxs(T,{variant:"secondary",size:"sm",onClick:g,children:[e.jsx(oe,{size:14})," Refresh"]}),e.jsxs(T,{variant:"primary",size:"sm",onClick:()=>m(),children:[e.jsx(Me,{size:14})," New schedule"]})]})]}),n.length===0?e.jsx(we,{icon:e.jsx(Ps,{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 j;return e.jsxs(J,{className:"schedule-card",children:[e.jsxs("div",{className:"schedule-card-head",children:[e.jsxs("div",{children:[e.jsx(ne,{children:u.name}),e.jsxs(re,{children:[e.jsx("code",{children:u.type})," ·"," ",e.jsx("span",{title:u.schedule,children:Gr(u)||u.schedule}),u.timezone&&u.timezone!=="UTC"?e.jsxs(e.Fragment,{children:[" · ",e.jsx("code",{children:u.timezone})]}):null," · ",e.jsx("span",{className:u.enabled?"status-on":"status-neutral",children:u.enabled?"enabled":"disabled"})]})]}),e.jsxs("div",{className:"schedule-card-actions",children:[e.jsxs(T,{variant:"secondary",size:"sm",onClick:()=>m(u),children:[e.jsx(ks,{size:12})," Edit"]}),e.jsxs(T,{variant:"secondary",size:"sm",onClick:()=>x(u),children:[e.jsx(Wa,{size:12})," Run now"]}),e.jsx("button",{type:"button",className:"icon-btn icon-btn-danger","aria-label":"Delete",title:"Delete",onClick:()=>h(u),children:e.jsx(Re,{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]})]}),((j=u.budgetCheck)==null?void 0:j.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 ${Et(u.lastResult)}`,children:u.lastResult}),u.lastError&&e.jsxs("span",{className:"muted schedule-card-error",title:u.lastError,children:[" ","— ",Dt(u.lastError,80)]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"next"})," ",u.nextRun?e.jsx("span",{title:new Date(u.nextRun).toISOString(),children:Yr(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((f,y)=>e.jsxs("li",{children:[e.jsx("span",{className:"tabular-nums muted",children:Ne(f.ts)})," ",e.jsx("span",{className:`tag ${Et(f.result)}`,children:f.result}),f.error&&e.jsxs("span",{className:"muted",children:[" — ",Dt(f.error,80)]})]},y))})]})]},u.id)})})]})}function Kr({initial:s,onClose:t,onSubmitted:a,onError:i}){const[n,l]=r.useState(()=>_r(s)),[o,c]=r.useState(!1),g=r.useMemo(()=>ot.some(h=>h.value===n.timezone)?n.timezone:"Other…",[n.timezone]),m=(h,d)=>{l(u=>({...u,[h]:d}))},x=async h=>{h.preventDefault();const d=n.name.trim();if(!d){i("Name is required.");return}const u=Wr(n);if(!u.schedule){i("Schedule value is required.");return}if(!n.actionTarget.trim()){i("Action target is required.");return}const j=n.timezone==="Other…"?n.customTimezone.trim():n.timezone,f={type:n.actionType,target:n.actionTarget.trim()};n.actionType==="agent"&&n.actionPrompt.trim()&&(f.prompt=n.actionPrompt.trim());const y={name:d,type:n.type,schedule:u.schedule,timezone:j||"UTC",action:f,budgetCheck:{maxConcurrent:n.maxConcurrent,skipIfBudgetLow:n.skipIfBudgetLow},enabled:n.enabled};c(!0);try{const $=s?await S.put(`/schedules/${encodeURIComponent(s.id)}`,y):await S.post("/schedules",y);await a($)}catch($){i(`${s?"Update":"Create"} failed: ${$.message}`)}finally{c(!1)}};return e.jsxs("form",{className:"schedule-form",onSubmit:x,children:[e.jsx("label",{className:"field-label",children:"Name"}),e.jsx("input",{className:"input",type:"text",placeholder:"Weekly code review",value:n.name,onChange:h=>m("name",h.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",children:"Type"}),e.jsx("select",{className:"select",value:n.type,onChange:h=>m("type",h.target.value),children:Fr.map(h=>e.jsx("option",{value:h,children:h},h))})]})}),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",children:"Day of week"}),e.jsx("select",{className:"select",value:n.cronDow,onChange:h=>m("cronDow",h.target.value),children:kt.map(h=>e.jsx("option",{value:h.value,children:h.label},h.value))})]}),e.jsxs("div",{className:"task-form-field",children:[e.jsx("label",{className:"field-label",children:"Hour"}),e.jsx("select",{className:"select",value:String(n.cronHour),onChange:h=>m("cronHour",parseInt(h.target.value,10)),children:bt.map(h=>e.jsx("option",{value:String(h.value),children:h.label},h.value))})]}),e.jsxs("div",{className:"task-form-field",children:[e.jsx("label",{className:"field-label",children:"Minute"}),e.jsx("select",{className:"select",value:String(n.cronMinute),onChange:h=>m("cronMinute",parseInt(h.target.value,10)),children:Ur.map(h=>e.jsx("option",{value:String(h),children:String(h).padStart(2,"0")},h))})]})]})}),n.showAdvanced&&e.jsxs("div",{className:"task-form-field",children:[e.jsx("label",{className:"field-label",children:"Cron expression"}),e.jsx("input",{className:"input",type:"text",value:n.rawCron,onChange:h=>m("rawCron",h.target.value),placeholder:"0 13 * * 0"})]}),e.jsxs("button",{type:"button",className:"link-btn",onClick:()=>m("showAdvanced",!n.showAdvanced),children:[e.jsx(Oe,{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",children:"Every"}),e.jsx("input",{className:"input",type:"number",min:1,value:n.intervalN,onChange:h=>m("intervalN",parseInt(h.target.value,10)||1)})]}),e.jsxs("div",{className:"task-form-field",style:{flex:1},children:[e.jsx("label",{className:"field-label",children:"Unit"}),e.jsx("select",{className:"select",value:n.intervalUnit,onChange:h=>m("intervalUnit",h.target.value),children:aa.map(h=>e.jsx("option",{value:h.value,children:h.label},h.value))})]})]}),n.type==="once"&&e.jsxs("div",{className:"task-form-field",children:[e.jsx("label",{className:"field-label",children:"Run at"}),e.jsx("input",{className:"input",type:"datetime-local",value:n.onceAt,onChange:h=>m("onceAt",h.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",children:"Timezone"}),e.jsxs("select",{className:"select",value:g,onChange:h=>m("timezone",h.target.value),children:[ot.map(h=>e.jsx("option",{value:h.value,children:h.label},h.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",children:"IANA name"}),e.jsx("input",{className:"input",type:"text",placeholder:"Europe/Paris",value:n.customTimezone,onChange:h=>m("customTimezone",h.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:"Action"}),e.jsx("select",{className:"select",value:n.actionType,onChange:h=>m("actionType",h.target.value),children:Br.map(h=>e.jsx("option",{value:h,children:h},h))})]}),e.jsxs("div",{className:"task-form-field",style:{flex:2},children:[e.jsx("label",{className:"field-label",children:"Target"}),e.jsx("input",{className:"input",type:"text",placeholder:n.actionType==="webhook"?"https://...":n.actionType==="agent"?"agent name or task ref":"echo hi",value:n.actionTarget,onChange:h=>m("actionTarget",h.target.value)})]})]}),n.actionType==="agent"&&e.jsxs("div",{className:"task-form-field",children:[e.jsx("label",{className:"field-label",children:"Prompt (what to send the agent)"}),e.jsx("textarea",{className:"input",rows:3,placeholder:"Review open PRs for stale code review comments and nudge reviewers.",value:n.actionPrompt,onChange:h=>m("actionPrompt",h.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",{type:"checkbox",checked:n.skipIfBudgetLow,onChange:h=>m("skipIfBudgetLow",h.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",children:"Max concurrent bg tasks"}),e.jsx("input",{className:"input",type:"number",min:1,max:64,value:n.maxConcurrent,onChange:h=>m("maxConcurrent",parseInt(h.target.value,10)||6),disabled:!n.skipIfBudgetLow})]})]}),e.jsxs("label",{className:"checkbox-row",children:[e.jsx("input",{type:"checkbox",checked:n.enabled,onChange:h=>m("enabled",h.target.checked)}),e.jsx("span",{children:"Enabled"})]}),e.jsxs("div",{className:"modal-footer-actions",children:[e.jsx(T,{variant:"ghost",type:"button",onClick:t,disabled:o,children:"Cancel"}),e.jsx(T,{variant:"primary",type:"submit",disabled:o,children:s?"Save":"Create"})]})]})}function Gr(s){var l,o;if(s.type!=="cron")return s.schedule;const t=na(s.schedule);if(!t)return s.schedule;const a=((l=kt.find(c=>c.value===t.dow))==null?void 0:l.label)||"",i=((o=bt.find(c=>c.value===t.hour))==null?void 0:o.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 Yr(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 Et(s){return s==="success"?"tag-success":s==="skipped"?"tag-warning":"tag-error"}function Dt(s,t){return s.length<=t?s:s.slice(0,t-1)+"…"}const Qr=[{id:"all",label:"All",icon:Fe},{id:"shipped",label:"Shipped",icon:ft},{id:"user",label:"User",icon:Jt},{id:"project",label:"Project",icon:Ee}],Ds={shipped:"Shipped",user:"User",project:"Project"},Xr={shipped:ft,user:Jt,project:Ee};function Zr({snapshot:s,refreshSnapshot:t}){const a=ce(),i=De(),[n,l]=r.useState([]),[o,c]=r.useState({shipped:0,user:0,project:0,all:0}),[g,m]=r.useState(!0),[x,h]=r.useState("all"),[d,u]=r.useState(""),[j,f]=r.useState(null),[y,$]=r.useState(!1),b=async()=>{var I,F,w;m(!0);try{const E=await S.get("/skills");l(E.skills||[]),c({shipped:((I=E.counts)==null?void 0:I.shipped)??0,user:((F=E.counts)==null?void 0:F.user)??0,project:((w=E.counts)==null?void 0:w.project)??0,all:(E.skills||[]).length})}catch(E){a.error(`Skills load failed: ${E.message}`)}finally{m(!1)}};r.useEffect(()=>{b()},[]),r.useEffect(()=>{if(!d.trim()){f(null);return}$(!0);const I=setTimeout(async()=>{try{const F=await S.get(`/skills/search?q=${encodeURIComponent(d.trim())}`);f(F.results||[])}catch(F){a.error(`Search failed: ${F.message}`)}finally{$(!1)}},280);return()=>clearTimeout(I)},[d]);const k=r.useMemo(()=>j!==null?j:x==="all"?n:n.filter(I=>I.source===x),[n,x,j]),P=async()=>{try{await S.post("/skills/refresh",{}),a.success("Skills refreshed."),await b()}catch(I){a.error(`Refresh failed: ${I.message}`)}},N=async I=>{try{const F=await S.get(`/skills/${encodeURIComponent(I.source)}/${encodeURIComponent(I.name)}`);i.open({title:F.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":F.source,children:Ds[F.source]||F.source}),e.jsx("code",{className:"mono text-sm muted",children:F.path})]}),F.description&&e.jsx("p",{className:"skill-detail-desc",children:F.description}),F.body&&e.jsx("div",{className:"skill-detail-body",children:e.jsx("pre",{className:"skill-body-pre",children:F.body})})]}),footer:e.jsx(T,{variant:"ghost",onClick:()=>i.close(),children:"Close"})})}catch{i.open({title:I.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":I.source,children:Ds[I.source]||I.source}),e.jsx("code",{className:"mono text-sm muted",children:I.path})]}),I.description&&e.jsx("p",{className:"skill-detail-desc",children:I.description})]}),footer:e.jsx(T,{variant:"ghost",onClick:()=>i.close(),children:"Close"})})}};return e.jsxs("div",{className:"view view-skills",children:[e.jsxs("header",{className:"view-header",children:[e.jsxs("div",{className:"view-header-text",children:[e.jsxs("h2",{className:"view-title",children:[e.jsx(Fe,{size:18})," Skills"]}),e.jsx("p",{className:"view-subtitle",children:"Browse all available skills — shipped, user, and project-local."})]}),e.jsxs("div",{className:"view-actions",children:[e.jsxs("div",{className:"search-input",children:[e.jsx(ye,{size:14}),e.jsx("input",{className:"input",type:"text",placeholder:"Search skills…",value:d,onChange:I=>u(I.target.value)}),d&&e.jsx("button",{type:"button",className:"icon-btn","aria-label":"Clear search",onClick:()=>u(""),children:e.jsx(Ye,{size:12})})]}),e.jsxs(T,{variant:"secondary",size:"sm",onClick:P,children:[e.jsx(oe,{size:14})," Refresh"]})]})]}),!d.trim()&&e.jsx("div",{className:"skills-tabs",children:Qr.map(I=>{const F=I.icon,w=I.id==="all"?o.all:o[I.id]??0;return e.jsxs("button",{type:"button",className:Z("skills-tab",x===I.id&&"skills-tab-active"),onClick:()=>h(I.id),children:[e.jsx(F,{size:14}),e.jsx("span",{children:I.label}),e.jsx("span",{className:"skills-tab-count",children:w})]},I.id)})}),d.trim()&&e.jsxs("section",{className:"skills-section",children:[e.jsxs("h3",{className:"skills-section-title",children:[e.jsx(ye,{size:14})," Search results",y&&e.jsx(he,{size:"sm"})]}),y?e.jsx("div",{className:"skills-grid",children:[0,1,2].map(I=>e.jsx("div",{className:"skill-card skill-card-skeleton"},I))}):j&&j.length===0?e.jsx(we,{icon:e.jsx(ye,{size:28}),title:"No matches",message:`No skills match "${d}".`}):e.jsx("div",{className:"skills-grid",children:(j||[]).map((I,F)=>e.jsx(Pt,{skill:I,onShow:()=>N(I),searchQ:d},`search-${F}`))})]}),!d.trim()&&e.jsx("section",{className:"skills-section",children:g?e.jsx("div",{className:"view-loading",children:e.jsx(he,{size:"lg"})}):k.length===0?e.jsx(we,{icon:e.jsx(Wt,{size:28}),title:"No skills here",message:x==="all"?"No skills found. Install skills with the skills CLI or add SKILL.md files to a skills directory.":`No skills in the ${Ds[x]} tab.`}):e.jsx("div",{className:"skills-grid",children:k.map((I,F)=>e.jsx(Pt,{skill:I,onShow:()=>N(I)},`${I.source}-${I.name}-${F}`))})}),!d.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 Pt({skill:s,onShow:t,searchQ:a=""}){const i=Xr[s.source]||ft,n=s.description?s.description.length>200?s.description.slice(0,200)+"…":s.description:"No description.";return e.jsxs(J,{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:Jr(s.name,a)}),e.jsx("span",{className:"skill-source-badge","data-source":s.source,children:Ds[s.source]||s.source})]})]}),e.jsx("p",{className:"skill-card-desc",children:n}),e.jsx("div",{className:"skill-card-actions",children:e.jsxs(T,{variant:"ghost",size:"sm",onClick:t,children:[e.jsx(ls,{size:12})," View"]})})]})}function Jr(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 el=We.memo(Zr);function sl({refreshKey:s,onRefresh:t,setActiveSubPanel:a}){const i=ce(),[n,l]=r.useState(null),[o,c]=r.useState(!0),g=async j=>{c(!0);try{const[f,y,$,b]=await Promise.all([S.get("/memory/health",j).catch(()=>null),S.get("/memory/status",j).catch(()=>null),S.get("/memory/lightrag/stats",j).catch(()=>null),S.get("/memory/storage",j).catch(()=>null)]);l({health:f||{score:0,status:"unconfigured",checks:[],message:"memory not initialised"},vault:{exists:!!(y!=null&&y.initialized),vaultRoot:(y==null?void 0:y.vaultRoot)||"",mode:(y==null?void 0:y.mode)||"local-only",noteCount:(y==null?void 0:y.noteCount)||0,totalSize:(b==null?void 0:b.total)||0,folderCount:0,folders:[],lastModified:null,gitClean:(y==null?void 0:y.gitClean)??null,gitBranch:(y==null?void 0:y.branch)||null},lightrag:$||{running:!1,pid:null,host:"127.0.0.1",port:9621,indexedApprox:0,queryCountLast24h:0,lastReindexAt:null},storage:b||{total:0,breakdown:[]}})}catch(f){i.error(`Memory overview failed: ${f.message}`)}finally{c(!1)}};if(r.useEffect(()=>{const j=new AbortController;return g(j.signal),()=>j.abort()},[s]),o&&!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:m,vault:x,lightrag:h,storage:d}=n,u=m.score>=80?"var(--success)":m.score>=50?"var(--warning)":"var(--error)";return e.jsxs("div",{className:"memory-overview",children:[e.jsxs(J,{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:m.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:m.status})]}),e.jsx("p",{className:"memory-health-message",children:m.message}),e.jsxs(T,{variant:"ghost",size:"sm",onClick:t,children:[e.jsx(oe,{size:12})," Refresh"]})]})]}),e.jsxs("div",{className:"memory-source-pills",children:[e.jsxs("button",{type:"button",className:"memory-source-pill",onClick:()=>a("lightrag"),children:[e.jsx(Le,{size:14}),e.jsx("span",{children:"LightRAG"}),e.jsx("span",{className:Z("memory-source-pill-status",h.running?"on":"off"),children:h.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:Z("memory-source-pill-status",x.exists?"on":"off"),children:[x.noteCount," notes"]})]}),e.jsxs("button",{type:"button",className:"memory-source-pill",onClick:()=>a("git"),children:[e.jsx(rs,{size:14}),e.jsx("span",{children:"Git Sync"}),e.jsx("span",{className:Z("memory-source-pill-status",x.gitClean===null?"na":x.gitClean?"on":"warn"),children:x.gitClean===null?"—":x.gitClean?"clean":"dirty"})]}),e.jsxs("button",{type:"button",className:"memory-source-pill",onClick:()=>a("semantic"),children:[e.jsx(ye,{size:14}),e.jsx("span",{children:"Semantic Search"}),e.jsx("span",{className:"memory-source-pill-status na",children:"cross-source"})]})]}),e.jsxs("div",{className:"memory-stat-grid",children:[e.jsx(ts,{icon:e.jsx(Le,{size:16}),label:"LightRAG",value:h.running?`running · ${h.queryCountLast24h} q/24h`:"stopped",sub:h.running?`${h.indexedApprox} indexed chunks`:"start from the LightRAG panel",onClick:()=>a("lightrag")}),e.jsx(ts,{icon:e.jsx(Se,{size:16}),label:"Obsidian",value:`${x.noteCount} notes`,sub:x.folderCount>0?`${x.folderCount} folders`:"no folders yet",onClick:()=>a("obsidian")}),e.jsx(ts,{icon:e.jsx(rs,{size:16}),label:"Git",value:x.gitBranch?`branch ${x.gitBranch}`:"local-only",sub:x.gitClean===null?"not configured":x.gitClean?"clean working tree":"dirty — commit or pull",onClick:()=>a("git")}),e.jsx(ts,{icon:e.jsx(Qt,{size:16}),label:"Storage",value:tl(d.total),sub:d.breakdown.length>0?`${d.breakdown.length} dirs tracked`:"no memory data on disk"}),e.jsx(ts,{icon:e.jsx(Fe,{size:16}),label:"Last reindex",value:h.lastReindexAt?os(h.lastReindexAt):"never",sub:"lightrag ingest",onClick:()=>a("lightrag")}),e.jsx(ts,{icon:e.jsx(bs,{size:16}),label:"Health",value:`${m.score}/100`,sub:m.status,onClick:()=>a("config")})]}),m.checks.length>0&&e.jsxs(J,{children:[e.jsx(ne,{children:"Health checks"}),e.jsx(re,{children:"Composite score across all memory subsystems"}),e.jsx("ul",{className:"memory-check-list",children:m.checks.map(j=>e.jsxs("li",{className:"memory-check-row",children:[e.jsx("span",{className:"memory-check-icon",children:j.pass?e.jsx(_e,{size:14,style:{color:"var(--success)"}}):j.name.includes("secrets")||j.name.includes("schema")?e.jsx(ke,{size:14,style:{color:"var(--warning)"}}):e.jsx(Ye,{size:14,style:{color:"var(--error)"}})}),e.jsx("span",{className:"memory-check-name",children:j.name}),e.jsx("span",{className:"memory-check-detail muted",children:j.detail})]},j.name))})]})]})}function ts({icon:s,label:t,value:a,sub:i,onClick:n}){const l=n?"button":"div";return e.jsxs(l,{type:n?"button":void 0,onClick:n,className:Z("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 tl(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 al({refreshKey:s}){const t=ce(),[a,i]=r.useState(null),[n,l]=r.useState(null),[o,c]=r.useState([]),[g,m]=r.useState(!0),[x,h]=r.useState(null),[d,u]=r.useState(""),[j,f]=r.useState(null),y=async()=>{m(!0);try{const[w,E,A]=await Promise.all([S.get("/memory/lightrag/stats").catch(()=>null),S.get("/memory/config").then(z=>(z==null?void 0:z.lightrag)||null).catch(()=>null),S.get("/memory/lightrag/log").catch(()=>({lines:[]}))]);i(w),l(E),c((A==null?void 0:A.lines)||[])}catch(w){t.error(`LightRAG status failed: ${w.message}`)}finally{m(!1)}};r.useEffect(()=>{y()},[s]);const $=async(w,E,A)=>{h(w);try{await E(),t.success(A),await y()}catch(z){t.error(`${w} failed: ${z.message}`)}finally{h(null)}},b=()=>$("start",()=>S.post("/memory/lightrag/start",{}),"LightRAG starting…"),k=()=>$("stop",()=>S.post("/memory/lightrag/stop",{}),"LightRAG stopping…"),P=async()=>{h("restart");try{await S.post("/memory/lightrag/stop",{}).catch(()=>{}),await new Promise(w=>setTimeout(w,600)),await S.post("/memory/lightrag/start",{}),t.success("LightRAG restarted."),await y()}catch(w){t.error(`Restart failed: ${w.message}`)}finally{h(null)}},N=()=>$("reindex",()=>S.post("/memory/lightrag/reindex",{}),"Reindex complete."),I=()=>$("rebuild",()=>S.post("/memory/lightrag/rebuild-graph",{}),"Graph rebuilt."),F=async()=>{var w,E,A;if(d.trim()){h("query");try{const z=await S.get(`/memory/query?q=${encodeURIComponent(d)}&topK=8`),R=(w=z==null?void 0:z.semantic)!=null&&w.response?typeof z.semantic.response=="string"?z.semantic.response:JSON.stringify(z.semantic.response):((E=z==null?void 0:z.semantic)==null?void 0:E.error)||"No response";f({ok:!!((A=z==null?void 0:z.semantic)!=null&&A.ok),text:R})}catch(z){f({ok:!1,text:z.message})}finally{h(null)}}};return g&&!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(J,{variant:"elevated",children:[e.jsxs(ne,{children:[e.jsx(Le,{size:14}),"LightRAG",e.jsx("span",{className:Z("memory-source-pill-status",a.running?"on":"off"),children:a.running?"running":"stopped"})]}),e.jsx(re,{children:a.running?e.jsxs(e.Fragment,{children:["PID ",e.jsx("code",{children:a.pid})," · ",a.host,":",a.port]}):e.jsx(e.Fragment,{children:"Server is not running. Start it from the controls below."})}),e.jsxs("div",{className:"memory-action-row",children:[e.jsxs(T,{variant:"primary",size:"sm",onClick:b,disabled:!!x||a.running,children:[x==="start"?e.jsx(fe,{size:12,className:"memory-spin"}):e.jsx(Ns,{size:12}),"Start"]}),e.jsxs(T,{variant:"secondary",size:"sm",onClick:k,disabled:!!x||!a.running,children:[x==="stop"?e.jsx(fe,{size:12,className:"memory-spin"}):e.jsx(jn,{size:12}),"Stop"]}),e.jsxs(T,{variant:"secondary",size:"sm",onClick:P,disabled:!!x,children:[x==="restart"?e.jsx(fe,{size:12,className:"memory-spin"}):e.jsx(ht,{size:12}),"Restart"]}),e.jsxs(T,{variant:"ghost",size:"sm",onClick:N,disabled:!!x,children:[x==="reindex"?e.jsx(fe,{size:12,className:"memory-spin"}):e.jsx(oe,{size:12}),"Reindex all"]}),e.jsxs(T,{variant:"ghost",size:"sm",onClick:I,disabled:!!x,title:"Wipe working dir + reindex from scratch",children:[x==="rebuild"?e.jsx(fe,{size:12,className:"memory-spin"}):e.jsx(ut,{size:12}),"Rebuild graph"]})]})]}),e.jsxs("div",{className:"memory-stat-grid",children:[e.jsx(ds,{icon:e.jsx(Qt,{size:14}),label:"Indexed chunks (approx)",value:String(a.indexedApprox)}),e.jsx(ds,{icon:e.jsx(nl,{n:a.noteCount}),label:"Notes in vault",value:String(a.noteCount)}),e.jsx(ds,{icon:e.jsx(vt,{size:14}),label:"Queries last 24h",value:String(a.queryCountLast24h)}),e.jsx(ds,{icon:e.jsx(Fe,{size:14}),label:"Avg response",value:a.avgResponseMs!==null?`${a.avgResponseMs} ms`:"—"}),e.jsx(ds,{icon:a.lastReindexOk?e.jsx(_e,{size:14}):a.lastReindexOk===!1?e.jsx(Ye,{size:14}):e.jsx(oe,{size:14}),label:"Last reindex",value:a.lastReindexAt?os(a.lastReindexAt):"never",sub:a.lastReindexInserted!==null?`${a.lastReindexInserted} inserted${a.lastReindexFailed?`, ${a.lastReindexFailed} failed`:""}`:void 0})]}),e.jsxs(J,{children:[e.jsxs(ne,{children:[e.jsx(ye,{size:14})," Quick search"]}),e.jsx(re,{children:"Send a natural-language query to the LightRAG index."}),e.jsxs("div",{className:"memory-search-row",children:[e.jsx("input",{type:"text",className:"input",placeholder:"e.g. how does the memory service write notes?",value:d,onChange:w=>u(w.target.value),onKeyDown:w=>{w.key==="Enter"&&F()},disabled:x==="query"}),e.jsxs(T,{variant:"primary",onClick:F,disabled:x==="query"||!d.trim(),children:[x==="query"?e.jsx(fe,{size:12,className:"memory-spin"}):e.jsx(ye,{size:12}),"Query"]})]}),j&&e.jsx("div",{className:Z("memory-query-result",j.ok?"ok":"err"),children:e.jsx("pre",{className:"mono text-sm",children:j.text})})]}),n&&e.jsxs(J,{children:[e.jsx(ne,{children:"Configuration"}),e.jsxs(re,{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})]})]}),o.length>0&&e.jsxs(J,{children:[e.jsxs(ne,{children:[e.jsx(oe,{size:14})," Server log (tail)"]}),e.jsxs(re,{children:["Last ",o.length," lines from ",e.jsx("code",{children:"lightrag.log"})]}),e.jsx("pre",{className:"memory-log-tail mono text-xs",children:o.join(`
|
|
357
|
+
`)})]})]}):e.jsx("div",{className:"muted",children:"No LightRAG data available."})}function ds({icon:s,label:t,value:a,sub:i}){return e.jsxs("div",{className:"memory-stat-card",children:[e.jsx("div",{className:"memory-stat-icon",children:s}),e.jsxs("div",{className:"memory-stat-body",children:[e.jsx("div",{className:"memory-stat-label",children:t}),e.jsx("div",{className:"memory-stat-value",children:a}),i&&e.jsx("div",{className:"memory-stat-sub muted",children:i})]})]})}function nl({n:s}){return e.jsxs("span",{style:{position:"relative",display:"inline-block"},children:[e.jsx(ye,{size:14}),e.jsx("span",{className:"memory-mini-badge",children:s})]})}function il({refreshKey:s}){const t=ce(),a=De(),[i,n]=r.useState([]),[l,o]=r.useState(null),[c,g]=r.useState(!0),[m,x]=r.useState(""),[h,d]=r.useState(null),[u,j]=r.useState(!1),[f,y]=r.useState(null),[$,b]=r.useState([]),k=async()=>{var A;g(!0);try{const[z,R]=await Promise.all([S.get("/memory/notes").catch(()=>({notes:[]})),S.get("/memory/obsidian/tree").catch(()=>({tree:null}))]);n(z.notes||[]),o(R.tree),f&&!((A=z.notes)!=null&&A.find(B=>B.relPath===f))&&(y(null),b([]))}catch(z){t.error(`Vault load failed: ${z.message}`)}finally{g(!1)}};r.useEffect(()=>{k()},[s]),r.useEffect(()=>{if(!m.trim()){d(null);return}j(!0);const A=setTimeout(async()=>{try{const z=await S.get(`/memory/search?q=${encodeURIComponent(m)}&limit=50`),R=new Set((z.results||[]).map(B=>B.relPath));d(i.filter(B=>R.has(B.relPath)))}catch(z){t.error(`Search failed: ${z.message}`)}finally{j(!1)}},240);return()=>clearTimeout(A)},[m,i,t]);const P=async A=>{y(A);try{const z=await S.get(`/memory/obsidian/backlinks?note=${encodeURIComponent(A)}`);b(z.backlinks||[])}catch{b([])}},N=()=>{a.open({title:"New note",width:720,children:e.jsx(Ot,{mode:"create",onSave:async(A,z,R)=>{try{await S.post("/memory/notes",{path:A,frontmatter:z,body:R}),t.success(`Created ${A}.`),a.close(),await k(),P(A)}catch(B){t.error(`Create failed: ${B.message}`)}},onCancel:()=>a.close()})})},I=async A=>{try{const z=await S.get(`/memory/notes/${A.split("/").map(encodeURIComponent).join("/")}`);a.open({title:`Edit ${A}`,width:720,children:e.jsx(Ot,{mode:"edit",initial:{relPath:z.relPath,frontmatter:z.frontmatter,body:z.body},onSave:async(R,B,v)=>{try{await S.put(`/memory/notes/${R.split("/").map(encodeURIComponent).join("/")}`,{frontmatter:B,body:v}),t.success(`Saved ${R}.`),a.close(),await k(),P(R)}catch(O){t.error(`Save failed: ${O.message}`)}},onCancel:()=>a.close()})})}catch(z){t.error(`Load failed: ${z.message}`)}},F=async A=>{if(confirm(`Delete ${A}? This cannot be undone.`))try{await S.del(`/memory/notes/${A.split("/").map(encodeURIComponent).join("/")}`),t.success(`Deleted ${A}.`),f===A&&y(null),await k()}catch(z){t.error(`Delete failed: ${z.message}`)}},w=r.useMemo(()=>[...i].sort((A,z)=>z.mtime-A.mtime),[i]),E=h??w;return c&&!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(J,{variant:"outlined",className:"memory-tree-card",children:[e.jsxs(ne,{children:[e.jsx(Ee,{size:14})," Folders"]}),e.jsx(re,{children:l?`${la(l)} folder(s)`:"no vault"}),e.jsx("div",{className:"memory-tree-body",children:l?e.jsx(ra,{node:l,depth:0,onSelect:P,selected:f}):null})]}),e.jsxs("div",{className:"memory-obsidian-list-col",children:[e.jsxs("div",{className:"memory-list-toolbar",children:[e.jsxs("div",{className:"search-input",children:[e.jsx(ye,{size:14}),e.jsx("input",{type:"text",className:"input",placeholder:"Search notes…",value:m,onChange:A=>x(A.target.value)}),m&&e.jsx("button",{type:"button",className:"icon-btn",onClick:()=>x(""),"aria-label":"Clear search",children:e.jsx($e,{size:12})})]}),e.jsxs(T,{variant:"primary",size:"sm",onClick:N,children:[e.jsx(Xa,{size:12})," New note"]}),e.jsx(T,{variant:"ghost",size:"sm",onClick:k,title:"Refresh",children:e.jsx(oe,{size:12})})]}),u&&e.jsx("div",{className:"muted text-sm",children:"Searching…"}),E.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 "${m}".`}):e.jsx("ul",{className:"memory-note-list",children:E.map(A=>e.jsxs("li",{className:Z("memory-note-card",f===A.relPath&&"memory-note-card-active"),children:[e.jsxs("button",{type:"button",className:"memory-note-card-main",onClick:()=>P(A.relPath),children:[e.jsxs("div",{className:"memory-note-card-title",children:[e.jsx(Se,{size:12}),e.jsx("span",{children:ia(A)})]}),e.jsxs("div",{className:"memory-note-card-meta",children:[e.jsx("code",{className:"muted",children:A.relPath}),e.jsxs("span",{className:"muted",children:["· ",Ne(A.mtime)]}),!A.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:()=>I(A.relPath),"aria-label":`Edit ${A.relPath}`,title:"Edit",children:e.jsx(ks,{size:12})}),e.jsx("button",{type:"button",className:"icon-btn",onClick:()=>F(A.relPath),"aria-label":`Delete ${A.relPath}`,title:"Delete",children:e.jsx(Re,{size:12})})]})]},A.relPath))})]}),e.jsx("div",{className:"memory-obsidian-detail-col",children:f?e.jsx(rl,{relPath:f,onClose:()=>y(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 ia(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 ra({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:Z("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(o=>!o),children:[n?e.jsx(Oe,{size:11}):e.jsx(He,{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((o,c)=>e.jsx(ra,{node:o,depth:t+1,onSelect:a,selected:i},`${o.path}-${c}`))})]})}function la(s){return s.type==="note"?0:1+(s.children||[]).reduce((t,a)=>t+la(a),0)}function rl({relPath:s,onClose:t}){var x,h;const[a,i]=r.useState(null),[n,l]=r.useState([]),[o,c]=r.useState(!0);if(r.useEffect(()=>{let d=!1;return c(!0),(async()=>{try{const[u,j]=await Promise.all([S.get(`/memory/notes/${s.split("/").map(encodeURIComponent).join("/")}`),S.get(`/memory/obsidian/backlinks?note=${encodeURIComponent(s)}`)]);if(d)return;i(u),l(j.backlinks||[])}catch{d||i(null)}finally{d||c(!1)}})(),()=>{d=!0}},[s]),o)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 g=Array.isArray((x=a.frontmatter)==null?void 0:x.tags)?a.frontmatter.tags:[],m=Array.isArray((h=a.frontmatter)==null?void 0:h.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:ia(a)}),e.jsx("button",{type:"button",className:"icon-btn",onClick:t,"aria-label":"Close",children:e.jsx($e,{size:12})})]}),e.jsxs("div",{className:"memory-note-detail-meta",children:[e.jsx("code",{children:s}),e.jsxs("span",{className:"muted",children:["· modified ",os(a.mtime)]})]}),g.length>0&&e.jsx("div",{className:"memory-tag-row",children:g.map((d,u)=>e.jsx("span",{className:"memory-tag",children:String(d)},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(d=>e.jsxs("li",{children:[e.jsx("code",{children:d.fromRelPath}),e.jsx("p",{className:"muted text-sm",children:d.snippet})]},d.fromRelPath))})]}),m.length>0&&e.jsxs("div",{className:"memory-backlinks",children:[e.jsx("h4",{children:"Forward links"}),e.jsx("ul",{children:m.map((d,u)=>e.jsx("li",{children:e.jsx("code",{children:String(d)})},u))})]})]})}function Ot({mode:s,initial:t,onSave:a,onCancel:i}){const[n,l]=r.useState((t==null?void 0:t.relPath)||"untitled.md"),[o,c]=r.useState(t!=null&&t.frontmatter?ll(t.frontmatter):`title: ""
|
|
358
|
+
tags: []
|
|
359
|
+
`),[g,m]=r.useState((t==null?void 0:t.body)||""),[x,h]=r.useState(!1),d=ce(),u=async()=>{if(!n.endsWith(".md")){d.error("Path must end in .md");return}let j;try{j=ol(o)||{}}catch(f){d.error(`Frontmatter parse failed: ${f.message}`);return}h(!0);try{await a(n,j,g)}finally{h(!1)}};return e.jsxs("div",{className:"memory-editor-modal",children:[e.jsx("label",{className:"field-label",children:"Path"}),e.jsx("input",{type:"text",className:"input mono",value:n,onChange:j=>l(j.target.value),disabled:s==="edit",placeholder:"notes/example.md"}),e.jsx("label",{className:"field-label",style:{marginTop:12},children:"Frontmatter (YAML)"}),e.jsx("textarea",{className:"memory-editor-textarea mono text-sm",rows:6,value:o,onChange:j=>c(j.target.value)}),e.jsx("label",{className:"field-label",style:{marginTop:12},children:"Body (Markdown)"}),e.jsx("textarea",{className:"memory-editor-textarea mono text-sm",rows:14,value:g,onChange:j=>m(j.target.value)}),e.jsxs("div",{className:"modal-footer-actions",style:{marginTop:12},children:[e.jsx(T,{variant:"ghost",onClick:i,disabled:x,children:"Cancel"}),e.jsxs(T,{variant:"primary",onClick:u,disabled:x,children:[x&&e.jsx(fe,{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(` - ${Js(n)}`)}else if(typeof i=="object"){t.push(`${a}:`);for(const[n,l]of Object.entries(i))t.push(` ${n}: ${Js(l)}`)}else t.push(`${a}: ${Js(i)}`);return t.join(`
|
|
360
|
+
`)}function Js(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 ol(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[,o,c]=l;if(c===""){const g={},m=[];let x=!1,h=!1;for(;i+1<a.length;){const d=a[i+1];if(!d.startsWith(" "))break;if(d.startsWith(" - "))x=!0,m.push(et(d.slice(4))),i++;else{h=!0;const u=d.match(/^ ([A-Za-z_][\w-]*):\s*(.*)$/);u&&(g[u[1]]=et(u[2])),i++}}t[o]=x&&!h?m:h?g:{}}else t[o]=et(c);i++}return t}function et(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 cl({refreshKey:s}){var k,P,N,I;const t=ce(),[a,i]=r.useState(null),[n,l]=r.useState(null),[o,c]=r.useState(!0),[g,m]=r.useState(null),[x,h]=r.useState(null),d=async()=>{var F;c(!0);try{const[w,E,A]=await Promise.all([S.get("/memory/git/status").catch(()=>null),S.get("/memory/git/diff").catch(()=>null),S.get("/memory/config/global").catch(()=>null)]);i(w),l(E),h(((F=A==null?void 0:A.config)==null?void 0:F.git)||null)}catch(w){t.error(`Git status failed: ${w.message}`)}finally{c(!1)}};r.useEffect(()=>{d()},[s]);const u=async(F,w,E)=>{m(F);try{await w(),t.success(E),await d()}catch(A){t.error(`${F} failed: ${A.message}`)}finally{m(null)}},j=()=>u("pull",()=>S.post("/memory/git/pull",{}),"Pull complete."),f=()=>u("push",()=>S.post("/memory/git/push",{}),"Push complete."),y=()=>{const F=prompt("Commit message:",`[memory-sync] ${new Date().toISOString().slice(0,10)} vault sync`);F&&u("commit",()=>S.post("/memory/git/commit",{message:F}),"Committed.")},$=()=>u("fetch",()=>S.post("/memory/git/sync",{push:!1}),"Fetch complete.");if(o&&!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 b=a.mode==="local-only";return e.jsxs("div",{className:"memory-panel-content",children:[e.jsxs(J,{variant:"elevated",children:[e.jsxs(ne,{children:[e.jsx(rs,{size:14})," Git sync",b?e.jsx("span",{className:"memory-source-pill-status na",children:"local-only"}):e.jsx("span",{className:Z("memory-source-pill-status",a.clean?"on":"warn"),children:a.clean?"clean":"dirty"})]}),e.jsx(re,{children:b?"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]})}),!b&&e.jsxs("div",{className:"memory-git-status-row",children:[e.jsx(ms,{ok:a.clean??!1,label:"Working tree"}),e.jsx(ms,{ok:(a.ahead??0)===0,label:`Ahead: ${a.ahead??0}`}),e.jsx(ms,{ok:(a.behind??0)===0,label:`Behind: ${a.behind??0}`}),e.jsx(ms,{ok:(((k=a.modified)==null?void 0:k.length)??0)===0,label:`Modified: ${((P=a.modified)==null?void 0:P.length)??0}`}),e.jsx(ms,{ok:(((N=a.untracked)==null?void 0:N.length)??0)===0,label:`Untracked: ${((I=a.untracked)==null?void 0:I.length)??0}`})]}),e.jsxs("div",{className:"memory-action-row",children:[e.jsxs(T,{variant:"secondary",size:"sm",onClick:j,disabled:!!g||b,children:[g==="pull"?e.jsx(fe,{size:12,className:"memory-spin"}):e.jsx(Kt,{size:12}),"Pull"]}),e.jsxs(T,{variant:"secondary",size:"sm",onClick:f,disabled:!!g||b,children:[g==="push"?e.jsx(fe,{size:12,className:"memory-spin"}):e.jsx(pt,{size:12}),"Push"]}),e.jsxs(T,{variant:"secondary",size:"sm",onClick:y,disabled:!!g||b,children:[g==="commit"?e.jsx(fe,{size:12,className:"memory-spin"}):e.jsx(an,{size:12}),"Commit"]}),e.jsxs(T,{variant:"ghost",size:"sm",onClick:$,disabled:!!g||b,children:[g==="fetch"?e.jsx(fe,{size:12,className:"memory-spin"}):e.jsx(rn,{size:12}),"Fetch + sync"]}),e.jsxs(T,{variant:"ghost",size:"sm",onClick:d,disabled:!!g,children:[e.jsx(oe,{size:12})," Refresh"]})]})]}),x&&e.jsxs(J,{children:[e.jsxs(ne,{children:[e.jsx(Da,{size:14})," Repository"]}),e.jsxs(re,{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:x.repoPath,children:x.repoPath||"—"}),e.jsx("dt",{children:"Remote"}),e.jsx("dd",{className:"mono ellipsis",title:x.remoteUrl,children:x.remoteUrl||"—"}),e.jsx("dt",{children:"Branch"}),e.jsx("dd",{children:e.jsx("code",{children:x.branch||"main"})}),e.jsx("dt",{children:"Auto-sync"}),e.jsx("dd",{children:x.autoSync?"enabled":"disabled"})]})]}),e.jsxs(J,{children:[e.jsxs(ne,{children:[e.jsx(nn,{size:14})," Working-tree diff"]}),e.jsx(re,{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(F=>e.jsx("li",{children:e.jsx("code",{children:F})},F))}),n&&n.lines.length>1&&e.jsx("pre",{className:"memory-log-tail mono text-xs",children:n.lines.slice(0,400).join(`
|
|
361
|
+
`)})]})]})}function ms({ok:s,label:t}){return e.jsxs("span",{className:Z("memory-git-status-pill",s?"ok":"warn"),children:[s?e.jsx(_e,{size:11}):e.jsx(fe,{size:11,className:"memory-spin"}),t]})}function dl({refreshKey:s}){const t=ce(),[a,i]=r.useState(""),[n,l]=r.useState({lightrag:!0,obsidian:!0}),[o,c]=r.useState(null),[g,m]=r.useState(!1),[x,h]=r.useState(""),d=async j=>{if(j.trim()){m(!0),h(j);try{const f=[...n.lightrag?["lightrag"]:[],...n.obsidian?["obsidian"]:[]],y=await S.post("/memory/semantic-search",{query:j,limit:20,sources:f});c(y.results||[])}catch(f){t.error(`Search failed: ${f.message}`),c([])}finally{m(!1)}}};r.useEffect(()=>{x&&d(x)},[n]),r.useEffect(()=>{x&&d(x)},[s]);const u=r.useMemo(()=>{const j=(o||[]).filter(y=>y.source==="obsidian"),f=(o||[]).filter(y=>y.source==="lightrag");return{obs:j,lr:f}},[o]);return e.jsxs("div",{className:"memory-panel-content",children:[e.jsxs(J,{variant:"elevated",children:[e.jsxs(ne,{children:[e.jsx(ye,{size:14})," Semantic search"]}),e.jsx(re,{children:"Query both LightRAG (graph-based) and the Obsidian vault in one shot."}),e.jsxs("div",{className:"memory-search-row",children:[e.jsx("input",{type:"text",className:"input",placeholder:"e.g. how are notes indexed?",value:a,onChange:j=>i(j.target.value),onKeyDown:j=>{j.key==="Enter"&&d(a)},disabled:g}),e.jsxs(T,{variant:"primary",onClick:()=>d(a),disabled:g||!a.trim(),children:[g?e.jsx(fe,{size:12,className:"memory-spin"}):e.jsx(ye,{size:12}),"Search"]})]}),e.jsxs("div",{className:"memory-source-toggle-row",children:[e.jsx(Ft,{active:n.obsidian,onToggle:()=>l(j=>({...j,obsidian:!j.obsidian})),label:"Obsidian",icon:e.jsx(Se,{size:11})}),e.jsx(Ft,{active:n.lightrag,onToggle:()=>l(j=>({...j,lightrag:!j.lightrag})),label:"LightRAG",icon:e.jsx(Le,{size:11})}),a&&e.jsx("button",{type:"button",className:"icon-btn",onClick:()=>{i(""),c(null),h("")},"aria-label":"Clear",children:e.jsx($e,{size:12})})]})]}),g&&e.jsx("div",{className:"view-loading",children:e.jsx(he,{size:"md"})}),!g&&o&&o.length===0&&e.jsx(we,{icon:e.jsx(ye,{size:28}),title:"No matches",message:`Nothing in scope matched "${x}".`}),u.obs.length>0&&e.jsxs(J,{children:[e.jsxs(ne,{children:[e.jsx(Se,{size:14})," Obsidian (",u.obs.length,")"]}),e.jsx("ul",{className:"memory-search-result-list",children:u.obs.map((j,f)=>e.jsxs("li",{className:"memory-search-result",children:[e.jsxs("div",{className:"memory-search-result-head",children:[e.jsx("code",{children:j.relPath}),e.jsxs("span",{className:"muted text-xs",children:["score ",j.score.toFixed(1)]})]}),e.jsx("p",{className:"muted text-sm",children:j.snippet})]},`obs-${f}`))})]}),u.lr.length>0&&e.jsxs(J,{children:[e.jsxs(ne,{children:[e.jsx(Le,{size:14})," LightRAG (",u.lr.length,")"]}),e.jsx("div",{className:"memory-search-result-list",children:u.lr.map((j,f)=>e.jsxs("div",{className:"memory-search-result",children:[e.jsxs("div",{className:"memory-search-result-head",children:[e.jsxs("span",{className:"memory-source-pill",children:[e.jsx(Le,{size:11})," LightRAG"]}),j.error&&e.jsxs("span",{className:"muted text-xs",children:["error: ",j.error]})]}),e.jsx("p",{className:"text-sm",children:j.snippet})]},`lr-${f}`))})]})]})}function Ft({active:s,onToggle:t,label:a,icon:i}){return e.jsxs("button",{type:"button",className:Z("memory-toggle-chip",s&&"memory-toggle-chip-active"),onClick:t,"aria-pressed":s,children:[i,e.jsx("span",{children:a})]})}function ml({refreshKey:s}){var y,$,b,k,P,N,I,F,w,E,A,z;const t=ce(),[a,i]=r.useState(null),[n,l]=r.useState(!0),[o,c]=r.useState(!1),[g,m]=r.useState(null),[x,h]=r.useState(!1),d=async()=>{l(!0);try{const R=await S.get("/memory/config/global");i(R.config)}catch(R){t.error(`Config load failed: ${R.message}`)}finally{l(!1)}};r.useEffect(()=>{d()},[s]);const u=(R,B,v)=>{i(O=>O&&{...O,[R]:{...O[R]||{},[B]:v}})},j=async()=>{if(a){c(!0);try{await S.put("/memory/config/global",a),t.success("Config saved.")}catch(R){t.error(`Save failed: ${R.message}`)}finally{c(!1)}}},f=async()=>{h(!0);try{const R=await S.post("/memory/test-git",{});m(R.checks)}catch(R){t.error(`Test failed: ${R.message}`)}finally{h(!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(J,{children:[e.jsxs(ne,{children:[e.jsx(Le,{size:14})," LightRAG"]}),e.jsxs(re,{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:!!((y=a.lightrag)!=null&&y.enabled),onChange:R=>u("lightrag","enabled",R.target.checked)}),e.jsx("span",{children:($=a.lightrag)!=null&&$.enabled?"on":"off"})]})}),e.jsx(Ue,{label:"URL",children:e.jsx("input",{type:"text",className:"input mono",value:((b=a.lightrag)==null?void 0:b.url)||"",onChange:R=>u("lightrag","url",R.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:((k=a.lightrag)==null?void 0:k.llm)||"",onChange:R=>u("lightrag","llm",R.target.value),placeholder:"opencode/gpt-5-nano"})}),e.jsx(Ue,{label:"Embedding",children:e.jsx("input",{type:"text",className:"input mono",value:((P=a.lightrag)==null?void 0:P.embedding)||"",onChange:R=>u("lightrag","embedding",R.target.value),placeholder:"opencode/text-embedding-3-small"})})]})]}),e.jsxs(J,{children:[e.jsxs(ne,{children:[e.jsx(Se,{size:14})," Obsidian vault"]}),e.jsx(re,{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:((N=a.obsidian)==null?void 0:N.vaultPath)||"",onChange:R=>u("obsidian","vaultPath",R.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:((I=a.obsidian)==null?void 0:I.syncInterval)??300,onChange:R=>u("obsidian","syncInterval",Number(R.target.value))})})]})]}),e.jsxs(J,{children:[e.jsxs(ne,{children:[e.jsx(rs,{size:14})," Git sync"]}),e.jsx(re,{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:((F=a.git)==null?void 0:F.repoPath)||"",onChange:R=>u("git","repoPath",R.target.value),placeholder:"/path/to/repo"})}),e.jsx(Ue,{label:"Remote URL",children:e.jsx("input",{type:"text",className:"input mono",value:((w=a.git)==null?void 0:w.remoteUrl)||"",onChange:R=>u("git","remoteUrl",R.target.value),placeholder:"git@github.com:org/repo.git"})}),e.jsx(Ue,{label:"Branch",children:e.jsx("input",{type:"text",className:"input mono",value:((E=a.git)==null?void 0:E.branch)||"main",onChange:R=>u("git","branch",R.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:!!((A=a.git)!=null&&A.autoSync),onChange:R=>u("git","autoSync",R.target.checked)}),e.jsx("span",{children:(z=a.git)!=null&&z.autoSync?"on":"off"})]})})]})]}),e.jsxs(J,{children:[e.jsxs(ne,{children:[e.jsx(Fe,{size:14})," CCR (Compress-Cache-Retrieve)"]}),e.jsx(re,{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(J,{children:[e.jsxs(ne,{children:[e.jsx(it,{size:14})," Connection tests"]}),e.jsx(re,{children:"Verify the configured git repo, remote, and path."}),e.jsxs("div",{className:"memory-action-row",children:[e.jsxs(T,{variant:"secondary",onClick:f,disabled:x,children:[x?e.jsx(fe,{size:12,className:"memory-spin"}):e.jsx(it,{size:12}),"Test git connection"]}),e.jsxs(T,{variant:"primary",onClick:j,disabled:o,children:[o?e.jsx(fe,{size:12,className:"memory-spin"}):e.jsx(vs,{size:12}),"Save config"]})]}),g&&g.length>0&&e.jsx("ul",{className:"memory-check-list",style:{marginTop:12},children:g.map((R,B)=>e.jsxs("li",{className:"memory-check-row",children:[e.jsx("span",{className:"memory-check-icon",children:e.jsx("span",{className:Z("memory-pill",R.pass?"memory-pill-ok":"memory-pill-warn"),children:R.pass?"OK":"FAIL"})}),e.jsx("span",{className:"memory-check-name",children:R.name}),e.jsx("span",{className:"memory-check-detail muted",children:R.detail})]},B))})]})]}):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",children:s}),e.jsx("div",{className:"memory-config-row-control",children:t})]}):e.jsxs("label",{className:"memory-config-row-stack",children:[e.jsx("span",{children:s}),t]})}const hl=[{id:"overview",label:"Overview",icon:Xt},{id:"lightrag",label:"LightRAG",icon:Le},{id:"obsidian",label:"Obsidian Vault",icon:Se},{id:"git",label:"Git Sync",icon:rs},{id:"semantic",label:"Semantic Search",icon:ye},{id:"config",label:"Config",icon:dt}];function ul(s){const t=ce(),[a,i]=r.useState("overview"),[n,l]=r.useState(0),o=r.useCallback(()=>{l(m=>m+1)},[]),c=r.useCallback(async()=>{o(),t.info("Refreshing memory…",1200)},[o,t]),g=()=>{switch(a){case"overview":return e.jsx(sl,{refreshKey:n,onRefresh:o,setActiveSubPanel:i});case"lightrag":return e.jsx(al,{refreshKey:n});case"obsidian":return e.jsx(il,{refreshKey:n});case"git":return e.jsx(cl,{refreshKey:n});case"semantic":return e.jsx(dl,{refreshKey:n});case"config":return e.jsx(ml,{refreshKey:n});default:return e.jsxs(J,{children:["Unknown panel: ",a]})}};return e.jsxs("div",{className:"view view-memory memory-tab",children:[e.jsxs("header",{className:"view-header",children:[e.jsxs("div",{className:"view-header-text",children:[e.jsxs("h2",{className:"view-title",children:[e.jsx(Le,{size:18})," Memory"]}),e.jsx("p",{className:"view-subtitle",children:"LightRAG, Obsidian vault, git sync, and semantic search — all in one place."})]}),e.jsx("div",{className:"view-actions",children:e.jsx("button",{type:"button",className:"icon-btn",onClick:c,"aria-label":"Refresh memory",title:"Refresh",children:e.jsx(oe,{size:14})})})]}),e.jsxs("div",{className:"memory-tab-body",children:[e.jsx("nav",{className:"memory-source-rail","aria-label":"Memory sources",children:hl.map(m=>{const x=m.icon,h=a===m.id;return e.jsxs("button",{type:"button",role:"tab","aria-selected":h,className:Z("memory-source-button",h&&"memory-source-button-active"),onClick:()=>i(m.id),children:[e.jsx(x,{size:16,"aria-hidden":!0}),e.jsx("span",{children:m.label})]},m.id)})}),e.jsx("div",{className:"memory-main",children:g()},a)]})]})}const xl=We.memo(ul),hs=[{id:"1h",label:"Last hour",ms:60*60*1e3},{id:"1d",label:"Last day",ms:24*60*60*1e3},{id:"7d",label:"Last 7 days",ms:7*24*60*60*1e3},{id:"30d",label:"Last 30 days",ms:30*24*60*60*1e3},{id:"all",label:"All time",ms:0}];function pl(s,t,a,i){const n=a.has(s.id);return e.jsxs(J,{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(Oe,{size:14}):e.jsx(He,{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,o)=>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??"")]})]},o))})]},s.id)}function gl({snapshot:s}){var y,$;const t=ce(),[a,i]=r.useState(null),[n,l]=r.useState(!0),[o,c]=r.useState("1d"),[g,m]=r.useState(new Set),[x,h]=r.useState(0),d=async b=>{try{const k=b?`?since=${encodeURIComponent(b)}&limit=1000`:"?limit=1000",P=await S.get(`/history${k}`);i(P),m(new Set(P.projects.filter(N=>P.events.some(I=>I.projectId===N.id)).map(N=>N.id)))}catch(k){t.error(`History load failed: ${k.message}`)}finally{l(!1)}};r.useEffect(()=>{l(!0);const b=hs.find(k=>k.id===o)||hs[1];if(b.ms>0){const k=new Date(Date.now()-b.ms).toISOString();d(k)}else d()},[o]),r.useEffect(()=>{const b=setInterval(()=>h(k=>k+1),3e4);return()=>clearInterval(b)},[]);const u=new Map;for(const b of(a==null?void 0:a.events)||[]){const k=b.projectId||"global";u.has(k)||u.set(k,[]),u.get(k).push(b)}const j=b=>{m(k=>{const P=new Set(k);return P.has(b)?P.delete(b):P.add(b),P})},f=()=>{if(!a)return;const b=new Blob([JSON.stringify(a,null,2)],{type:"application/json"}),k=URL.createObjectURL(b),P=document.createElement("a");P.href=k,P.download=`bizar-history-${new Date().toISOString().replace(/[:.]/g,"-")}.json`,P.click(),URL.revokeObjectURL(k),t.success("History exported.")};return e.jsxs("div",{className:"view view-history","data-tick":x,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.",((y=a==null?void 0:a.stats)==null?void 0:y.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(Ja,{size:14,style:{color:"var(--text-dim)"}}),e.jsx("select",{className:"select select-sm",value:o,onChange:b=>c(b.target.value),title:"Time range",children:hs.map(b=>e.jsx("option",{value:b.id,children:b.label},b.id))})]}),e.jsxs(T,{variant:"ghost",size:"sm",onClick:()=>{l(!0);const b=hs.find(k=>k.id===o)||hs[1];b.ms>0?d(new Date(Date.now()-b.ms).toISOString()):d()},children:[e.jsx(oe,{size:14})," Refresh"]}),e.jsxs(T,{variant:"secondary",size:"sm",onClick:f,children:[e.jsx(Xe,{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(J,{children:[e.jsxs(ne,{children:[e.jsx(Ee,{size:14})," No projects"]}),e.jsx(re,{children:"Register a project in Overview to start tracking history."})]}),a.projects.length>0&&e.jsx(mt,{items:a.projects,itemHeight:70,height:Math.min(a.projects.length*70,500),className:"history-virtual-list",renderItem:b=>pl(b,u.get(b.id)||[],g,j)}),u.has("global")&&e.jsxs(J,{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((b,k)=>e.jsxs("div",{className:"history-timeline-row",children:[e.jsx("span",{className:"history-timeline-ts",children:new Date(b.ts).toLocaleTimeString()}),e.jsx("span",{className:"history-timeline-kind",children:b.kind||"event"}),e.jsxs("span",{className:"history-timeline-msg",title:String(b.text||b.title||""),children:[b.author?`@${b.author} `:"",String(b.text??b.title??b.name??"")]})]},k))})]}),(($=a.stats)==null?void 0:$.counts)&&Object.keys(a.stats.counts).length>0&&e.jsxs(J,{children:[e.jsx(ne,{children:"Event counts by kind"}),e.jsxs(re,{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((b,k)=>k[1]-b[1]).slice(0,30).map(([b,k])=>e.jsxs("span",{className:Z("tag","tag-neutral"),style:{fontFamily:"var(--font-mono)"},children:[b,": ",k]},b))})]})]})]})}const ve={top:16,right:20,bottom:40,left:52};function jl({series:s,height:t=280,onHover:a,className:i}){const n=r.useRef(null),[l,o]=r.useState(null),{labels:c,requests:g,tokens:m}=s,x=c.length;if(x===0)return e.jsx("div",{className:Z("usage-chart-empty",i),style:{height:t},children:e.jsx("span",{children:"No data for this range"})});const h=600-ve.left-ve.right,d=t-ve.top-ve.bottom,u=Math.max(...g,1),j=Math.max(...m,1),f=Math.max(4,Math.min(24,Math.floor(h/x)-4)),y=(h-f*x)/(x+1);function $(R){return ve.left+y+R*(f+y)}function b(R){return R/u*d*.75}function k(R){return ve.top+d-R/j*d*.75}const P=m.map((R,B)=>`${$(B)+f/2},${k(R)}`).join(" "),N=[0,.25,.5,.75,1].map(R=>({y:ve.top+d-R*d*.75,label:R===0?"0":`${Math.round(u*R).toLocaleString()}`})),I=[0,.25,.5,.75,1].map(R=>({y:ve.top+d-R*d*.75,label:R===0?"0":`${Math.round(j*R/1e3)}k`})),F=Math.max(1,Math.floor(x/7)),w=c.map((R,B)=>({i:B,l:R,x:$(B)+f/2})).filter((R,B)=>B%F===0),E=r.useCallback(R=>{if(!n.current)return;const B=n.current.getBoundingClientRect(),v=(R.clientX-B.left)*(600/B.width),O=(R.clientY-B.top)*(t/B.height),K=v-ve.left,M=Math.round((K-y/2)/(f+y)),W=Math.max(0,Math.min(x-1,M));o({index:W,x:R.clientX-B.left,y:R.clientY-B.top}),a==null||a(W,v,O)},[x,f,y,a,t]),A=r.useCallback(()=>{o(null),a==null||a(null,0,0)},[a]),z=l;return e.jsxs("div",{ref:n,className:Z("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:E,onMouseLeave:A,children:[N.map((R,B)=>e.jsx("line",{x1:ve.left,y1:R.y,x2:600-ve.right,y2:R.y,stroke:"var(--border)",strokeWidth:1,strokeDasharray:"4,3",opacity:.5},`grid-${B}`)),N.map((R,B)=>e.jsx("text",{x:ve.left-6,y:R.y+4,textAnchor:"end",fontSize:10,fill:"var(--text-muted)",fontFamily:"var(--font-mono, ui-monospace, monospace)",children:R.label},`ly-${B}`)),I.map((R,B)=>e.jsx("text",{x:600-ve.right+6,y:R.y+4,textAnchor:"start",fontSize:10,fill:"var(--text-muted)",fontFamily:"var(--font-mono, ui-monospace, monospace)",children:R.label},`ry-${B}`)),g.map((R,B)=>{const v=b(R),O=$(B),K=ve.top+d-v;return e.jsx("rect",{x:O,y:K,width:f,height:v,rx:2,fill:((z==null?void 0:z.index)===B,"var(--accent)"),opacity:(z==null?void 0:z.index)===B?1:.75,style:{transition:"opacity 120ms ease"}},`bar-${B}`)}),e.jsx("polyline",{points:P,fill:"none",stroke:"var(--warning, #d29922)",strokeWidth:2,strokeLinejoin:"round",strokeLinecap:"round",opacity:.9}),m.map((R,B)=>e.jsx("circle",{cx:$(B)+f/2,cy:k(R),r:(z==null?void 0:z.index)===B?5:3,fill:"var(--warning, #d29922)",opacity:(z==null?void 0:z.index)===B?1:.7,style:{transition:"r 120ms ease"}},`dot-${B}`)),w.map(({i:R,l:B,x:v})=>e.jsx("text",{x:v,y:ve.top+d+18,textAnchor:"middle",fontSize:10,fill:"var(--text-muted)",fontFamily:"var(--font-mono, ui-monospace, monospace)",children:B},`xl-${R}`)),e.jsx("line",{x1:ve.left,y1:ve.top+d,x2:600-ve.right,y2:ve.top+d,stroke:"var(--border)",strokeWidth:1})]}),z!==null&&e.jsxs("div",{className:"usage-chart-tooltip",style:{left:Math.min(z.x+12,460),top:z.y-60},children:[e.jsx("div",{className:"usage-tooltip-date",children:c[z.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:g[z.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:m[z.index].toLocaleString()})]})]})]})}function Ke({label:s,col:t,sortKey:a,sortDir:i,onSort:n}){const l=a===t;return e.jsxs("th",{className:Z("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 fl({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:Z("mono",n.errors>0&&"is-err"),children:n.errors>0?n.errors:"—"})]},`${n.providerId}::${n.modelId}`))})]})})}function vl({activeTab:s,setActiveTab:t}){const[a,i]=r.useState("quota"),n=ce();return e.jsxs("div",{className:"view-container view-minimax-usage",children:[e.jsxs("div",{className:"minimax-sub-tabs",children:[e.jsxs("button",{className:Z("minimax-sub-tab",a==="quota"&&"is-active"),onClick:()=>i("quota"),children:[e.jsx(gt,{size:13})," Token Plan"]}),e.jsxs("button",{className:Z("minimax-sub-tab",a==="analytics"&&"is-active"),onClick:()=>i("analytics"),children:[e.jsx(Yt,{size:13})," Usage Analytics"]})]}),a==="quota"?e.jsx(yl,{activeTab:s,setActiveTab:t}):e.jsx(bl,{toast:n})]})}function yl({activeTab:s,setActiveTab:t}){var se;const a=ce(),[i,n]=r.useState(null),[l,o]=r.useState(null),[c,g]=r.useState(null),[m,x]=r.useState(!0),[h,d]=r.useState(!1),[u,j]=r.useState(null),[f,y]=r.useState(null),[$,b]=r.useState(!1),[k,P]=r.useState(0),[N,I]=r.useState(!1),[F,w]=r.useState(null),[E,A]=r.useState(""),[z,R]=r.useState(!1),[B,v]=r.useState(!1),O=r.useCallback(async()=>{x(!0),j(null);try{const[Q,ie,xe]=await Promise.all([S.get("/minimax/status"),S.get("/minimax/remains"),S.get("/minimax/onboarding")]);n(Q),o(ie),g(xe),Q.configured&&P(4)}catch(Q){j(Q.message||"Failed to load MiniMax data")}finally{x(!1)}},[]);r.useEffect(()=>{O()},[O]);const K=r.useCallback(async()=>{try{await S.post("/minimax/onboarding",{dismissedAt:Date.now()}),g(Q=>Q&&{...Q,dismissedAt:Date.now()})}catch{}},[]),M=r.useCallback(async()=>{if(!E.trim()){a.error("Paste a Subscription Key first.");return}I(!0),w(null);try{const Q=await S.post("/minimax/test",{prompt:"Reply with a single word: pong",model:"MiniMax-M3",maxTokens:16});if(w(Q),Q.ok){P(3),a.success("Key works. Saving…");try{await S.post("/minimax/onboarding/save-key",{key:E.trim(),groupId:"default"}),te(),a.success("Subscription Key saved.")}catch(ie){a.error(`Save failed: ${ie.message}`)}O()}else a.error(`Verification failed: ${Q.message??Q.error??"unknown"}`)}catch(Q){a.error(`Test request failed: ${Q.message}`)}finally{I(!1)}},[E,a,O]),W=r.useCallback(async()=>{if(!E.trim()){a.error("Paste a Subscription Key first.");return}v(!0);try{const Q=await S.post("/minimax/onboarding/save-key",{key:E.trim(),groupId:"default"});if(!Q.ok){a.error(`Save failed: ${Q.message??Q.error??"unknown"}`);return}A(""),te(),a.success("Subscription Key saved. Loading quota…"),O()}catch(Q){a.error(`Save failed: ${Q.message}`)}finally{v(!1)}},[E,a,O]),te=r.useCallback(async()=>{try{await S.del("/minimax/cache")}catch{}},[]),ee=r.useCallback(async()=>{d(!0),j(null);try{await S.post("/minimax/remains/refresh"),await O(),a.success("Refreshed")}catch(Q){a.error(`Refresh failed: ${Q.message}`)}finally{d(!1)}},[O,a]),_=r.useCallback(async()=>{var Q;b(!0),y(null);try{const ie=await S.post("/minimax/test",{prompt:"Reply with a single word: pong",model:"MiniMax-M3",maxTokens:16});y(ie),ie.ok?a.success(`Test ok — used ${((Q=ie.usage)==null?void 0:Q.total_tokens)??"?"} tokens`):a.error(`Test failed: ${ie.message??ie.error??"unknown"}`)}catch(ie){a.error(`Test request failed: ${ie.message}`)}finally{b(!1)}},[a]);return m&&!i?e.jsxs("div",{className:"view-container",children:[e.jsx(he,{})," Loading MiniMax data…"]}):i?!i.configured&&(c==null?void 0:c.dismissedAt)==null&&k<4?e.jsx(wl,{step:k,setStep:P,keyDraft:E,setKeyDraft:A,showKey:z,setShowKey:R,verifying:N,verifyResult:F,onVerify:M,onSkip:async()=>{await K(),a.success("Skipped.")},onManualKeySave:W,savingKey:B,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(gt,{size:20,style:{verticalAlign:"text-bottom",marginRight:6}}),"MiniMax Token Plan"]}),e.jsxs("p",{className:"view-subtitle",children:["Remaining 5-hour + weekly quota per model. Fetches live from"," ",e.jsx("code",{children:"www.minimax.io/v1/token_plan/remains"}),"."]})]}),e.jsxs("div",{className:"view-header-actions",children:[e.jsxs(T,{variant:"secondary",size:"sm",onClick:()=>t("settings"),title:"Configure your Subscription Key",children:[e.jsx(jt,{size:14})," ",i.configured?`Key ${i.apiKeyHint}`:"Add key"]}),e.jsxs(T,{variant:"secondary",size:"sm",onClick:ee,disabled:h,children:[h?e.jsx(fe,{size:14,className:"spin"}):e.jsx(oe,{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?Nl(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(Q=>e.jsx(kl,{model:Q},Q.model_name))})]}),i.configured&&e.jsxs(J,{id:"minimax-test",children:[e.jsxs(ne,{children:[e.jsx(Qe,{size:14})," Test the API key"]}),e.jsxs(re,{children:["One-shot chat completion to ",e.jsxs("code",{children:[i.chatBaseUrl,"/chat/completions"]}),"."]}),e.jsxs("div",{className:"minimax-test-actions",children:[e.jsxs(T,{onClick:_,disabled:$,variant:"primary",size:"sm",children:[$?e.jsx(fe,{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"'})]}),f&&e.jsxs("div",{className:Z("minimax-test-result",f.ok?"ok":"err"),children:[f.ok?e.jsx(_e,{size:14}):e.jsx(ke,{size:14}),e.jsx("div",{className:"minimax-test-body",children:f.ok?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"minimax-test-line",children:[e.jsx("strong",{children:"model:"})," ",e.jsx("code",{children:f.model})," ·"," ",e.jsx("strong",{children:"finish:"})," ",f.finishReason??"—"]}),f.content&&e.jsx("div",{className:"minimax-test-content",children:e.jsx("code",{children:f.content})}),f.usage&&e.jsxs("div",{className:"minimax-test-usage",children:[e.jsx("strong",{children:"usage:"})," total ",e.jsx("code",{children:f.usage.total_tokens??"?"})," · prompt"," ",e.jsx("code",{children:f.usage.prompt_tokens??"?"})," · completion"," ",e.jsx("code",{children:f.usage.completion_tokens??"?"}),((se=f.usage.prompt_tokens_details)==null?void 0:se.cached_tokens)!=null&&e.jsxs(e.Fragment,{children:[" · cached ",e.jsx("code",{children:f.usage.prompt_tokens_details.cached_tokens})]})]})]}):e.jsx("pre",{children:f.message??f.error??"unknown error"})})]})]})]}):e.jsx("div",{className:"view-container",children:e.jsxs("div",{className:"error-card",children:[e.jsx(ke,{size:20}),e.jsxs("div",{children:[e.jsx("strong",{children:"Couldn't load MiniMax status"}),e.jsx("pre",{children:u??"unknown error"})]})]})})}function bl({toast:s}){const[t,a]=r.useState("24h"),[i,n]=r.useState(""),[l,o]=r.useState(""),[c,g]=r.useState(!0),[m,x]=r.useState(null),[h,d]=r.useState([]),[u,j]=r.useState("requests"),[f,y]=r.useState("desc"),[$,b]=r.useState(!1),k=r.useCallback(async(z,R,B)=>{g(!0);try{const v=new URLSearchParams({range:z});z==="custom"&&R&&B&&(v.set("from",String(R)),v.set("to",String(B)));const[O,K]=await Promise.all([S.get(`/usage?${v.toString()}`),S.get("/usage/recent?limit=20")]);x(O),d(K.records)}catch(v){s.error(`Failed to load usage data: ${v.message}`)}finally{g(!1)}},[s]);r.useEffect(()=>{if(t==="custom"){const z=i?new Date(i).getTime():Date.now()-6048e5,R=l?new Date(l).getTime():Date.now();k("custom",z,R)}else k(t)},[t,k]);const P=r.useCallback(z=>{u===z?y(R=>R==="asc"?"desc":"asc"):(j(z),y("desc"))},[u]),N=r.useMemo(()=>m!=null&&m.perModel?[...m.perModel].sort((z,R)=>{const B=z[u]??0,v=R[u]??0,O=typeof B=="number"&&typeof v=="number"?B-v:String(B).localeCompare(String(v));return f==="asc"?O:-O}):[],[m==null?void 0:m.perModel,u,f]),I=r.useMemo(()=>m!=null&&m.daily?{labels:m.daily.map(z=>z.date.slice(5)),requests:m.daily.map(z=>z.requests),tokens:m.daily.map(z=>z.totalTokens)}:{labels:[],requests:[],tokens:[]},[m==null?void 0:m.daily]),F=r.useCallback(async()=>{b(!0),await k(t==="custom"?"custom":t,t==="custom"&&i?new Date(i).getTime():void 0,t==="custom"&&l?new Date(l).getTime():void 0),b(!1)},[k,t,i,l]);if(c&&!m)return e.jsxs("div",{className:"view-container",children:[e.jsx(he,{})," Loading usage data…"]});const w=m==null?void 0:m.totals,E=(m==null?void 0:m.errors)??[],A=(m==null?void 0:m.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(Yt,{size:20,style:{verticalAlign:"text-bottom",marginRight:6}}),"Usage Analytics"]}),e.jsxs("p",{className:"view-subtitle",children:["Aggregated from ",e.jsx("code",{children:"~/.local/share/bizar/usage.jsonl"})," — every chatCompletion and fetchRemains call."]})]}),e.jsx("div",{className:"view-header-actions",children:e.jsxs(T,{variant:"secondary",size:"sm",onClick:F,disabled:$,children:[$?e.jsx(fe,{size:14,className:"spin"}):e.jsx(oe,{size:14})," Refresh"]})})]}),e.jsxs("div",{className:"usage-time-range",children:[["24h","7d","30d","custom"].map(z=>e.jsx("button",{className:Z("usage-range-chip",t===z&&"is-active"),onClick:()=>a(z),children:z==="custom"?"Custom":z.toUpperCase()},z)),t==="custom"&&e.jsxs("div",{className:"usage-custom-dates",children:[e.jsx("input",{type:"date",className:"usage-date-input",value:i,onChange:z=>n(z.target.value)}),e.jsx("span",{style:{color:"var(--text-muted)",fontSize:12},children:"to"}),e.jsx("input",{type:"date",className:"usage-date-input",value:l,onChange:z=>o(z.target.value)})]})]}),e.jsxs("div",{className:"usage-kpi-row",children:[e.jsx(us,{label:"Total Requests",value:(w==null?void 0:w.requests.toLocaleString())??"—",sub:w?`${w.errors} errors`:void 0,tone:w&&w.errors>w.requests*.1?"warn":void 0}),e.jsx(us,{label:"Total Tokens",value:w?w.totalTokens>=1e3?`${Math.round(w.totalTokens/1e3)}k`:String(w.totalTokens):"—",sub:w?`${w.promptTokens.toLocaleString()} prompt · ${w.completionTokens.toLocaleString()} completion`:void 0}),e.jsx(us,{label:"Errors",value:String((w==null?void 0:w.errors)??"—"),sub:E.length>0?`${E[0].code}: ${E[0].count}`:void 0,tone:w&&w.errors>0?"err":void 0}),e.jsx(us,{label:"Avg Latency",value:(w==null?void 0:w.avgLatencyMs)!=null?`${w.avgLatencyMs}ms`:"—",sub:(w==null?void 0:w.p95LatencyMs)!=null?`p95 ${w.p95LatencyMs}ms`:void 0}),e.jsx(us,{label:"Est. Cost",value:(w==null?void 0:w.costEstimate)!=null&&w.costEstimate>0?`$${w.costEstimate.toFixed(4)}`:"—",sub:"approximate USD",tone:void 0})]}),e.jsxs(J,{className:"usage-chart-card",children:[e.jsx("div",{className:"usage-chart-wrap",children:e.jsx(jl,{series:I,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(J,{children:[e.jsx(ne,{children:"Per-model breakdown"}),e.jsx(fl,{rows:N,sortKey:u,sortDir:f,onSort:P})]}),A.length>0&&e.jsxs(J,{children:[e.jsx(ne,{children:"API Keys"}),e.jsx("div",{className:"usage-key-row",children:A.map(z=>e.jsxs("span",{className:Z("usage-key-badge",z.isBackup?"is-backup":"is-active"),children:[e.jsx("span",{className:"usage-key-dot"}),z.keyEnvVar,z.isBackup?" (backup)":" (active)"," · ",z.requests," req"]},z.keyEnvVar))})]}),h.length>0&&e.jsxs(J,{children:[e.jsx(ne,{children:"Recent activity"}),e.jsx("div",{className:"usage-recent-list",children:h.map((z,R)=>e.jsxs("div",{className:Z("usage-recent-item",z.error&&"is-err"),children:[e.jsx("span",{className:"usage-recent-time",children:new Date(z.ts).toLocaleTimeString()}),e.jsx("span",{className:"usage-recent-model",children:e.jsx("code",{children:z.modelId})}),e.jsxs("span",{className:"usage-recent-tokens",children:[z.totalTokens.toLocaleString()," tok"]}),e.jsxs("span",{className:"usage-recent-latency",children:[z.latencyMs,"ms"]}),e.jsx("span",{className:"usage-recent-endpoint",children:z.endpoint})]},`${z.requestId}-${R}`))})]})]})}function us({label:s,value:t,sub:a,tone:i}){return e.jsxs("div",{className:"usage-kpi-card",children:[e.jsx("div",{className:"usage-kpi-label",children:s}),e.jsx("div",{className:Z("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 kl({model:s}){const t=As(s.current_interval_remaining_percent??0,0,100),a=As(s.current_weekly_remaining_percent??0,0,100),i=As(100-t,0,100),n=As(100-a,0,100);return e.jsxs(J,{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:Z("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(Bt,{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(Bt,{icon:e.jsx(qa,{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 Bt({icon:s,label:t,remainingPct:a,consumedPct:i,used:n,total:l,resetIn:o,resetISO:c}){const g=a>=75?"good":a>=25?"warn":"low";return e.jsxs("div",{className:`minimax-quota-row is-${g}`,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:c,children:o?`resets in ${o}`:"—"})]})]})}function As(s,t,a){return Math.max(t,Math.min(a,s))}function Nl(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 wl({step:s,setStep:t,keyDraft:a,setKeyDraft:i,showKey:n,setShowKey:l,verifying:o,verifyResult:c,onVerify:g,onSkip:m,onManualKeySave:x,savingKey:h,status:d}){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(Fe,{size:20,style:{verticalAlign:"text-bottom",marginRight:6}}),"Set up MiniMax Token Plan tracking"]}),e.jsx("p",{className:"view-subtitle",children:"We'll read your Subscription Key and show your remaining quota."})]}),e.jsx("div",{className:"view-header-actions",children:e.jsxs(T,{variant:"ghost",size:"sm",onClick:m,children:[e.jsx($e,{size:14})," Skip for now"]})})]}),e.jsx("div",{className:"minimax-wizard-stepper",children:["Welcome","Get a key","Paste & test","Done"].map((u,j)=>e.jsxs("div",{className:Z("minimax-wizard-step",j===s&&"is-current",j<s&&"is-done",j>s&&"is-todo"),children:[e.jsx("div",{className:"minimax-wizard-step-bullet",children:j<s?e.jsx(_e,{size:14}):j+1}),e.jsx("div",{className:"minimax-wizard-step-label",children:u})]},u))}),e.jsxs(J,{id:"minimax-wizard-card",children:[s===0&&e.jsxs("div",{className:"minimax-wizard-body",children:[e.jsx("h3",{className:"minimax-wizard-title",children:"Welcome"}),e.jsxs("p",{className:"minimax-wizard-prose",children:["BizarHarness shows you how much of your MiniMax Token Plan quota you have left — both the ",e.jsx("strong",{children:"5-hour rolling"})," and ",e.jsx("strong",{children:"weekly"})," windows."]}),e.jsxs("ul",{className:"minimax-wizard-list",children:[e.jsxs("li",{children:["Stored in ",e.jsx("code",{children:"~/.local/share/opencode/auth.json"}),"."]}),e.jsx("li",{children:"Read fresh on every dashboard load."}),e.jsx("li",{children:"Never logged in full."})]}),e.jsx("div",{className:"minimax-wizard-actions",children:e.jsxs(T,{onClick:()=>t(1),variant:"primary",size:"md",children:["Get started ",e.jsx("span",{style:{marginLeft:6},children:"→"})]})})]}),s===1&&e.jsxs("div",{className:"minimax-wizard-body",children:[e.jsx("h3",{className:"minimax-wizard-title",children:"Get your Subscription Key"}),e.jsx("p",{className:"minimax-wizard-prose",children:"Go to the MiniMax console and copy your Subscription Key."}),e.jsxs("ol",{className:"minimax-wizard-list",children:[e.jsxs("li",{children:["Open ",e.jsxs("a",{href:"https://platform.minimax.io/user-center/payment/token-plan",target:"_blank",rel:"noreferrer",className:"minimax-wizard-link",children:[e.jsx(ls,{size:12})," platform.minimax.io"]})]}),e.jsxs("li",{children:["Click ",e.jsx("strong",{children:"Copy Subscription Key"}),"."]}),e.jsx("li",{children:"Come back here and paste it."})]}),e.jsxs("div",{className:"minimax-wizard-actions",children:[e.jsx(T,{variant:"secondary",size:"md",onClick:()=>t(0),children:"← Back"}),e.jsxs(T,{variant:"primary",size:"md",onClick:()=>t(2),children:["I have my key ",e.jsx("span",{style:{marginLeft:6},children:"→"})]})]})]}),s===2&&e.jsxs("div",{className:"minimax-wizard-body",children:[e.jsx("h3",{className:"minimax-wizard-title",children:"Paste & test"}),e.jsx("p",{className:"minimax-wizard-prose",children:"Paste your key below. We'll test it against the real API before saving."}),e.jsx("div",{className:"minimax-key-row",children:e.jsxs("div",{className:"minimax-key-input-wrap",children:[e.jsx(jt,{size:12,className:"minimax-key-icon"}),e.jsx("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}),e.jsx("button",{type:"button",onClick:()=>l(u=>!u),className:"minimax-key-toggle","aria-label":n?"Hide key":"Show key",children:n?e.jsx(at,{size:13}):e.jsx(is,{size:13})})]})}),c&&!c.ok&&e.jsxs("div",{className:"minimax-wizard-error",children:[e.jsx(ke,{size:14}),e.jsxs("span",{children:[e.jsx("strong",{children:"Verification failed:"})," ",c.message??c.error]})]}),e.jsxs("div",{className:"minimax-wizard-actions",children:[e.jsx(T,{variant:"secondary",size:"md",onClick:()=>t(1),children:"← Back"}),e.jsxs(T,{variant:"primary",size:"md",onClick:g,disabled:o||!a.trim(),children:[o?e.jsx(fe,{size:14,className:"spin"}):e.jsx(bs,{size:14}),o?"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(),x()},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(T,{variant:"primary",size:"md",onClick:()=>window.location.reload(),children:"View your quota →"})})]}),e.jsxs("div",{className:"minimax-wizard-footer",children:[e.jsx(bs,{size:11}),e.jsxs("span",{children:["Key written to ",e.jsx("code",{children:"~/.local/share/opencode/auth.json"})," with mode 0600."]})]})]})]})}const Sl=We.memo(vl),Cl={pending:"info",running:"accent",done:"success",failed:"error",killed:"neutral",timed_out:"warning"},zl={pending:"Pending",running:"Running",done:"Done",failed:"Failed",killed:"Killed",timed_out:"Timed out"};function Tl({status:s,dot:t}){const a=Cl[s]||"neutral",i=zl[s]||s;return e.jsx(ns,{kind:a,dot:t,children:i})}function Ml({instanceId:s,instanceName:t,onConfirm:a,onClose:i}){return e.jsxs("div",{children:[e.jsxs("p",{style:{marginBottom:16,lineHeight:1.6},children:["Instance ",e.jsx("code",{children:s}),t?e.jsxs(e.Fragment,{children:[" (",t,")"]}):null," will be terminated. This cannot be undone."]}),e.jsxs("div",{style:{display:"flex",gap:8,justifyContent:"flex-end"},children:[e.jsx(T,{variant:"ghost",onClick:i,children:"Cancel"}),e.jsx(T,{variant:"danger",onClick:async()=>{await a(),i()},children:"Kill"})]})]})}function $l(s,t,a,i,n){s.open({title:"Kill instance?",width:400,children:e.jsx(Ml,{instanceId:a,instanceName:i,onConfirm:async()=>{try{const o=await(await fetch(`/api/background/${encodeURIComponent(a)}`,{method:"DELETE"})).json();o.ok?(t.success(`Instance ${a} killed.`),n==null||n()):t.error(`Kill failed: ${o.error||"unknown error"}`)}catch(l){t.error(`Kill failed: ${l.message}`)}},onClose:()=>s.close()})})}function Rl({instance:s}){const t=ce(),[a,i]=r.useState(!1),n=s.tmuxSession,l=n?`tmux attach -t ${n}`:null,o=async()=>{if(l)try{await navigator.clipboard.writeText(l),t.success("Attach command copied")}catch{t.error("Could not copy to clipboard")}},c=async()=>{if(!(!s.instanceId||!n)){i(!0);try{const g=await S.post(`/background/${encodeURIComponent(s.instanceId)}/open-terminal`,{emulator:"system"});if(g.ok)t.success("Opening terminal…");else if(t.error(g.error||"Failed to open terminal"),l)try{await navigator.clipboard.writeText(l),t.success("Command copied to clipboard")}catch{}}catch(g){if(t.error(`Failed: ${g.message}`),l)try{await navigator.clipboard.writeText(l),t.success("Command copied to clipboard")}catch{}}finally{i(!1)}}};return n?e.jsxs(J,{variant:"outlined",className:"bg-tmux-card",children:[e.jsxs("div",{className:"bg-tmux-card-header",children:[e.jsx(fs,{size:14}),e.jsx("span",{children:"tmux session"}),s.tmuxActive!==!1?e.jsx("span",{className:"badge badge-success",children:"live"}):e.jsx("span",{className:"badge badge-warning",children:"inactive"})]}),e.jsx("code",{className:"mono bg-tmux-session-name",children:n}),e.jsx("p",{className:"muted bg-tmux-hint",children:"Attach to the agent's tmux session from a terminal on the host running the dashboard."}),e.jsxs("div",{className:"bg-tmux-card-actions",children:[e.jsxs(T,{variant:"ghost",size:"sm",onClick:o,title:"Copy attach command",children:[e.jsx(Hs,{size:14})," Copy"]}),e.jsxs(T,{variant:"primary",size:"sm",onClick:c,loading:a,title:"Open in system terminal",children:[e.jsx(fs,{size:14})," Open terminal"]})]})]}):e.jsxs(J,{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 Al=5e3,Il=2e3,Ll=120;function El(s){return s.status==="pending"||s.status==="running"}function Dl(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 Pl(s){const t=ce(),a=De(),[i,n]=r.useState([]),[l,o]=r.useState(!0),[c,g]=r.useState(null),[,m]=r.useState(0),x=r.useCallback(async()=>{try{const f=await S.get("/background");n(Array.isArray(f==null?void 0:f.instances)?f.instances:[]),g(null)}catch(f){g((f==null?void 0:f.message)||"Failed to load background agents.")}finally{o(!1)}},[]);r.useEffect(()=>{x();const f=setInterval(x,Al);return()=>clearInterval(f)},[x]),r.useEffect(()=>{const f=setInterval(()=>m(y=>(y+1)%1e6),1e3);return()=>clearInterval(f)},[]),r.useEffect(()=>{const f=new xt,y=f.on($=>{const b=$.type;(b==="background:change"||b==="background:cleanup")&&x()});return()=>{y(),f.close()}},[x]);const h=i.filter(El),d=f=>{Fl(a,f)},u=async f=>{try{const y=await S.get(`/background/${encodeURIComponent(f.instanceId)}/tmux`);Ul(a,y)}catch(y){t.error(`Tmux info failed: ${y.message}`)}},j=f=>{$l(a,t,f.instanceId,f.agent||f.prompt,()=>{n(y=>y.filter($=>$.instanceId!==f.instanceId))})};return l?e.jsx("div",{className:"bg-active-view",children:e.jsxs("div",{className:"bg-active-loading",children:[e.jsx(he,{size:"md"}),e.jsx("span",{children:"Loading background agents…"})]})}):c?e.jsx("div",{className:"bg-active-view",children:e.jsx(we,{icon:e.jsx(Te,{size:32}),title:"Couldn't load background agents",message:c,action:e.jsxs(T,{variant:"primary",onClick:x,children:[e.jsx(oe,{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:[h.length," active · ",i.length," total in store"]})]}),e.jsxs(T,{variant:"ghost",size:"sm",onClick:x,title:"Refresh now",children:[e.jsx(oe,{size:14})," Refresh"]})]}),h.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:h.map(f=>e.jsx(Ol,{inst:f,onViewOutput:()=>d(f),onOpenTmux:()=>u(f),onKill:()=>j(f)},f.instanceId))})]})}function Ol({inst:s,onViewOutput:t,onOpenTmux:a,onKill:i}){const n=typeof s.startedAt=="number"?s.startedAt:0,l=n?os(n):"—",o=n?Date.now()-n:0,c=Ut(s.prompt,Ll);return e.jsxs(J,{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(Tl,{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"})]})]}),c&&e.jsx("div",{className:"bg-active-prompt",children:c}),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:"})," ",Dl(o)]}),e.jsxs("span",{children:[e.jsx("strong",{children:"Tool calls:"})," ",s.toolCallCount??0]}),s.tmuxSession&&e.jsxs("span",{className:Z(s.tmuxActive&&"bg-active-meta-tmux-live"),children:[e.jsx("strong",{children:"tmux:"})," ",e.jsx("code",{className:"mono",children:s.tmuxSession}),s.tmuxActive?" · live":""]})]}),e.jsxs("div",{className:"bg-active-actions",children:[e.jsxs(T,{variant:"secondary",size:"sm",onClick:t,children:[e.jsx(is,{size:14})," View output"]}),e.jsxs(T,{variant:"ghost",size:"sm",onClick:a,children:[e.jsx(fs,{size:14})," Open in tmux"]}),e.jsxs(T,{variant:"danger",size:"sm",onClick:i,children:[e.jsx(Re,{size:14})," Kill"]})]}),e.jsx(Rl,{instance:s})]})}function Fl(s,t){s.open({title:`Output — ${t.agent||t.instanceId}`,width:720,children:e.jsx(Bl,{instanceId:t.instanceId})})}function Bl({instanceId:s}){const t=ce(),[a,i]=r.useState(""),[n,l]=r.useState(!0),[o,c]=r.useState(null),[g,m]=r.useState(!0),x=r.useRef(null),h=r.useRef(!0),d=r.useCallback(async()=>{try{const f=await S.get(`/background/${encodeURIComponent(s)}/output?lines=200`);i((f==null?void 0:f.output)??""),m((f==null?void 0:f.available)!==!1),c(null)}catch(f){c((f==null?void 0:f.message)||"Failed to load output.")}finally{l(!1)}},[s]);r.useEffect(()=>{d();const f=setInterval(d,Il);return()=>clearInterval(f)},[d]),r.useEffect(()=>{var f;h.current&&((f=x.current)==null||f.scrollIntoView({behavior:"auto",block:"end"}))},[a]);const u=f=>{const y=f.currentTarget,$=y.scrollHeight-y.scrollTop-y.clientHeight<24;h.current=$},j=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:g?`${a.length} chars · auto-refresh 2s`:"Output unavailable"}),e.jsxs("div",{className:"bg-output-toolbar-actions",children:[e.jsxs(T,{variant:"ghost",size:"sm",onClick:d,title:"Refresh now",children:[e.jsx(oe,{size:14})," Refresh"]}),e.jsxs(T,{variant:"ghost",size:"sm",onClick:j,disabled:!a,children:[e.jsx(Hs,{size:14})," Copy"]})]})]}),n&&!a?e.jsxs("div",{className:"bg-output-loading",children:[e.jsx(fe,{size:16,className:"spin"})," Loading…"]}):o?e.jsx("div",{className:"bg-output-error",children:o}):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:x})]}):e.jsx("div",{className:"bg-output-empty muted",children:"No output captured yet."})]})}function Ul(s,t){const a=t.attachCommand||t.session||"";s.open({title:"Attach to tmux",width:520,children:e.jsx(ql,{info:t,cmd:a})})}function ql({info:s,cmd:t}){const[a,i]=r.useState(!1),n=async()=>{try{await navigator.clipboard.writeText(t),i(!0),window.setTimeout(()=>i(!1),1500)}catch{}};return e.jsx("div",{className:"bg-tmux-modal",children:t?e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"bg-tmux-meta",children:[s.exists?e.jsx("span",{className:"badge badge-success",children:"session live"}):e.jsxs("span",{className:"badge badge-warning",children:["session not running",s.reason?` — ${s.reason}`:""]}),s.session&&e.jsxs("span",{className:"bg-tmux-session muted",children:["· session ",e.jsx("code",{className:"mono",children:s.session})]})]}),e.jsx("label",{className:"field-label",children:"Attach command"}),e.jsxs("div",{className:"bg-tmux-command-row",children:[e.jsx("code",{className:"bg-tmux-command mono",children:t}),e.jsxs(T,{variant:"secondary",size:"sm",onClick:n,children:[e.jsx(Hs,{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 st={overview:ci,chat:Si,agents:Mi,artifacts:tr,memory:xl,tasks:ur,activity:Nr,background:Pl,config:Lt,settings:Lt,mods:Er,schedules:Vr,skills:el,history:gl,minimax:Sl},_l="v4.5.0";function Hl(s,t,a,i){if(st[s]){const o=st[s];return e.jsx(o,{...t})}const n=a.find(o=>o.id===s);if(n)return e.jsx(Pr,{viewId:n.id,reloadKey:i,activeTab:t.activeTab,setActiveTab:t.setActiveTab});const l=st.overview;return e.jsx(l,{...t})}function Wl({onSaved:s}){const[t,a]=r.useState(""),i=r.useRef(null);r.useEffect(()=>{var o;(o=i.current)==null||o.focus()},[]);const n=()=>{const o=t.trim();o&&(S.setToken(o),s())},l=o=>{o.key==="Escape"&&(o.preventDefault(),s()),o.key==="Enter"&&(o.preventDefault(),n())};return e.jsxs("form",{className:"token-entry-form",onSubmit:o=>{o.preventDefault(),n()},children:[e.jsxs("div",{className:"token-entry-row",children:[e.jsx("input",{ref:i,type:"password",className:"input mono",value:t,onChange:o=>a(o.target.value),placeholder:"Paste auth token",spellCheck:!1,autoComplete:"off",onKeyDown:l}),e.jsx(T,{type:"submit",variant:"primary",size:"sm",disabled:!t.trim(),children:"Save & retry"})]}),e.jsxs("p",{className:"token-entry-hint",children:["Where do I find this token? Check the file"," ",e.jsx("code",{children:"~/.config/bizar/dashboard-secret"})," on the machine running the dashboard, or look for it in the server output."]})]})}function Vl(){return e.jsx(Pa,{children:e.jsx(Oa,{children:e.jsx(Kl,{})})})}function Kl(){var Q,ie,xe;const s=ce(),t=De(),{isModalOpen:a}=t,i=r.useRef(!1),[n,l]=r.useState("overview"),[o,c]=r.useState(null),[g,m]=r.useState(null),[x,h]=r.useState("connecting"),[d,u]=r.useState(null),[j,f]=r.useState(!1),[y,$]=r.useState(!1),[b,k]=r.useState([]),[P,N]=r.useState(!1),[I,F]=r.useState([]),[w,E]=r.useState(0),A=r.useRef(null),[z,R]=r.useState(null);r.useEffect(()=>{let V=!1;return(async()=>{try{const L=await S.get("/mods/views");if(V)return;F(L.views||[])}catch{V||F([])}})(),()=>{V=!0}},[w,o==null?void 0:o.mods]),r.useEffect(()=>{if(!z)return;const V=z.on(L=>{((L==null?void 0:L.type)==="mod:change"||(L==null?void 0:L.type)==="mod:enabled"||(L==null?void 0:L.type)==="mod:installed")&&E(U=>U+1)});return()=>V()},[z]),r.useEffect(()=>{g!=null&&g.theme&&(ps(g.theme),as(g.theme))},[g==null?void 0:g.theme]),r.useEffect(()=>{i.current=a},[a]),r.useEffect(()=>{var U;if(((U=g==null?void 0:g.theme)==null?void 0:U.mode)!=="system")return;const V=window.matchMedia("(prefers-color-scheme: light)"),L=()=>ps(g.theme.mode);return V.addEventListener("change",L),()=>V.removeEventListener("change",L)},[(Q=g==null?void 0:g.theme)==null?void 0:Q.mode]);const B=r.useCallback(async()=>{let V=!1;const L=()=>Promise.all([S.get("/snapshot").catch(()=>null),S.get("/settings").catch(()=>null),S.get("/agents/stuck").catch(()=>null)]),U=(p,q,H)=>{p&&c(p),q!=null&&q.data&&m(q.data),H!=null&&H.stuck&&k(H.stuck)};try{const p=await S.probeAuthStatus(),[q,H,D]=await L();if(U(q,H,D),q||H){u(null);return}if(!p.loopback){u("Dashboard server unreachable.");return}await new Promise(de=>setTimeout(de,1e3));const[le,ae,ue]=await L();U(le,ae,ue),!le&&!ae&&u("Dashboard server unreachable.")}catch(p){const q=(p==null?void 0:p.message)??"unknown error";if(p instanceof Fa&&p.status===401){u(q),f(!0),s.error(`Auth required: ${q}`);return}u(q),s.error(`Failed to load: ${q}`)}},[s]);r.useEffect(()=>{let V=!1;const L=setTimeout(()=>{V||B()},0);return()=>{V=!0,clearTimeout(L)}},[B]),r.useEffect(()=>{let V=!1;return S.get("/settings").then(L=>{var p,q;if(V)return;const U=(q=(p=L==null?void 0:L.data)==null?void 0:p.ui)==null?void 0:q.defaultTab;U&&l(U)}).catch(()=>{}),()=>{V=!0}},[]),r.useEffect(()=>{let V=!1;const L=async()=>{try{const p=await S.get("/agents/stuck");V||k(q=>{const H=p.stuck||[];return q.length===0&&H.length>0&&s.warning(`${H.length} agent${H.length===1?"":"s"} stuck`,5e3),H})}catch{}},U=setInterval(L,3e4);return L(),()=>{V=!0,clearInterval(U)}},[]),r.useEffect(()=>{const V=new xt;A.current=V,R(V);const L=V.onStatus(p=>h(p)),U=V.on(p=>{var q;if(p.type==="snapshot"&&"data"in p&&p.data)c(H=>({...H??{},...p.data}));else if(p.type==="change"){const H=p,D=((q=H.path)==null?void 0:q.split("/").pop())||H.path||"";s.info(`File changed: ${D}`,2500)}else if(p.type==="tasks:change"){const H=p;c(D=>{if(!D)return D;const le=(D.tasks||[]).map(ue=>ue.id===H.task.id?H.task:ue),ae=le.some(ue=>ue.id===H.task.id);return{...D,tasks:ae?le:[H.task,...le]}})}else if(p.type==="tasks:delete"){const H=p;c(D=>D&&{...D,tasks:(D.tasks||[]).filter(le=>le.id!==H.id)})}else if(p.type==="settings:change"){const H=p;H.settings&&m(H.settings)}else if(p.type==="project:change")S.get("/snapshot").then(H=>c(D=>({...D??{},...H}))).catch(()=>{});else if(p.type==="agents:change"||p.type==="schedules:change")S.get("/snapshot").then(H=>c(D=>({...D??{},...H}))).catch(()=>{});else if(p.type==="agent:status"||p.type==="agent:restarted"){const H=p;c(D=>{if(!D)return D;const le=(D.agents||[]).map(ae=>ae.name===H.agent.name?H.agent:ae);return{...D,agents:le}})}else if(p.type==="artifact:change")S.get("/artifacts").then(H=>{c(D=>D&&{...D,artifacts:H.artifacts||[]})}).catch(()=>{});else if(p.type==="agent:stuck")k(p.agents||[]);else if(p.type==="dialog:show"){const H=p;H.dialog&&t.open({title:H.dialog.title,width:520,children:e.jsx(Qn,{dialog:H.dialog,onClose:()=>t.close()})})}});return()=>{L(),U(),V.close(),R(null)}},[s]);const v=r.useCallback(V=>z?z.on(V):()=>{},[z]),O=r.useRef(0);r.useEffect(()=>{const V=()=>{O.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={};rt.forEach((U,p)=>{V[String(p+1)]=U.id});const L=U=>{var de,ws,Ss,Cs;if((U.metaKey||U.ctrlKey)&&U.key.toLowerCase()==="k"){U.preventDefault(),$(!0);return}if(U.key==="/"&&!U.metaKey&&!U.ctrlKey){const zs=(ws=(de=U.target)==null?void 0:de.tagName)==null?void 0:ws.toLowerCase();if(zs!=="input"&&zs!=="textarea"&&!((Ss=U.target)!=null&&Ss.isContentEditable)){U.preventDefault(),$(!0);return}}const p=document.activeElement;if(!p||p===document.body||p===document.documentElement)return;const H=U.target,D=(Cs=H==null?void 0:H.tagName)==null?void 0:Cs.toLowerCase(),le=D==="input"||D==="textarea"||D==="select"||D==="button"||D==="option"||D==="label"||!!(H!=null&&H.isContentEditable);let ae=!1;if(H&&typeof H.closest=="function"&&(ae=!!H.closest('form, [role="dialog"], [contenteditable], [data-no-key]')),U.repeat||i.current||le||ae||U.metaKey||U.ctrlKey||U.altKey||U.shiftKey||Date.now()<O.current)return;const ue=V[U.key];ue&&(U.preventDefault(),l(ue))};return document.addEventListener("keydown",L),()=>document.removeEventListener("keydown",L)},[]);const K=r.useMemo(()=>async()=>{try{const V=await S.get("/snapshot");c(L=>({...L??{},...V}))}catch(V){s.error(`Refresh failed: ${V.message}`)}},[s]),M=r.useMemo(()=>{const V=I.map(L=>({id:L.id,label:L.label,icon:L.kind==="iframe"?ys:nt,isMod:!0,modId:L.modId}));return[...rt,...V]},[I]),W=r.useMemo(()=>o&&g?Hl(n,{snapshot:o,settings:g,activeTab:n,setActiveTab:l,refreshSnapshot:K},I,w):null,[n,o,g,I,w,K]),te=async()=>{try{const V=await S.get("/projects");c(L=>{var U;return L&&{...L,projects:V.projects||[],activeProject:((U=V.projects)==null?void 0:U.find(p=>p.id===V.active))||null}})}catch(V){s.error(`Projects refresh failed: ${V.message}`)}},ee=async V=>{try{await S.post(`/projects/${encodeURIComponent(V)}/activate`),c(L=>L&&{...L,activeProject:L.projects.find(U=>U.id===V)||null})}catch(L){s.error(`Activate failed: ${L.message}`)}},_=V=>{const L=V.type;if(L==="agent")l("agents");else if(L==="task")l("tasks");else if(L==="mod")l("mods");else if(L==="schedule")l("schedules");else if(L==="project"){const U=V.item.id;ee(U)}else if(L==="command")s.info(`/${V.item.name} — run from the TUI`,2500);else if(L==="setting"){const U=V.item.id||V.item.path||"";l("settings");const p=q=>{if(q<=0)return;const H=U?document.querySelector(`[data-setting-id="${CSS.escape(U)}"]`):null;H?(H.scrollIntoView({behavior:"smooth",block:"center"}),H.classList.remove("setting-flash"),H.offsetWidth,H.classList.add("setting-flash"),window.setTimeout(()=>H.classList.remove("setting-flash"),1500)):window.setTimeout(()=>p(q-1),80)};window.setTimeout(()=>p(15),60)}},Y=((ie=g==null?void 0:g.ui)==null?void 0:ie.layout)||"topnav",se=((xe=g==null?void 0:g.ui)==null?void 0:xe.showHeader)!==!1;return e.jsxs("div",{className:"app","data-layout":Y,"data-active-tab":n,children:[se&&e.jsx(En,{activeTab:n,onTabChange:l,wsStatus:x,version:_l,activeProject:(o==null?void 0:o.activeProject)||null,projects:(o==null?void 0:o.projects)||[],onProjectChange:ee,onProjectsRefresh:te,onOpenSearch:()=>$(!0),settings:g,notificationsSlot:e.jsx(qn,{wsSubscribe:v}),showTabs:Y==="topnav",extraTabs:M}),b.length>0&&!P&&e.jsxs("div",{className:"stuck-banner",role:"alert",children:[e.jsx(ke,{size:16}),e.jsxs("span",{children:[e.jsx("strong",{children:b.length})," agent",b.length===1?"":"s"," stuck:"," ",e.jsx("span",{className:"mono",children:b.map(V=>V.name).join(", ")})]}),e.jsx(T,{variant:"secondary",size:"sm",onClick:()=>{l("agents"),N(!0)},children:"Review"}),e.jsx("button",{type:"button",className:"icon-btn","aria-label":"Dismiss",onClick:()=>N(!0),children:e.jsx($e,{size:14})})]}),e.jsxs("div",{className:"layout-body",children:[Y!=="topnav"&&e.jsx(On,{tabs:M,activeTab:n,onTabChange:l}),e.jsxs("main",{className:"content",children:[d&&e.jsxs("div",{className:"boot-error",children:[e.jsx("h2",{children:"Dashboard unavailable"}),e.jsx("p",{children:d}),j&&e.jsx(Wl,{onSaved:()=>{f(!1),B()}}),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."]})]}),!d&&(!o||!g)&&e.jsxs("div",{className:"loading",children:[e.jsx(he,{size:"lg"}),e.jsx("p",{children:"Loading Bizar…"})]}),W&&e.jsx(r.Suspense,{fallback:e.jsxs("div",{className:"loading",children:[e.jsx(he,{size:"lg"}),e.jsx("p",{children:"Loading…"})]}),children:e.jsx(Gl,{children:W})})]})]}),e.jsx(Fn,{open:y,onClose:()=>$(!1),onSelect:_})]})}class Gl extends r.Component{constructor(){super(...arguments);cs(this,"state",{err:null});cs(this,"reset",()=>this.setState({err:null}))}static getDerivedStateFromError(a){return{err:a}}componentDidCatch(a,i){console.error("[ViewErrorBoundary] caught render error:",a,i==null?void 0:i.componentStack)}render(){return this.state.err?e.jsxs("div",{className:"view-error-fallback",role:"alert",children:[e.jsx(ke,{size:20}),e.jsxs("div",{className:"view-error-body",children:[e.jsx("strong",{children:"This view crashed."}),e.jsx("pre",{children:this.state.err.message}),e.jsx(T,{variant:"secondary",size:"sm",onClick:this.reset,children:"Retry"})]})]}):this.props.children}}function Yl(){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(Ua,{}):e.jsx(Vl,{})}const oa=document.getElementById("root");if(!oa)throw new Error("Root element #root not found");Ba(oa).render(e.jsx(r.StrictMode,{children:e.jsx(Yl,{})}));
|