@polderlabs/bizar 4.4.13 → 4.5.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/CHANGELOG.md +37 -276
- package/bizar-dash/dist/assets/main-CDFKHzBg.css +1 -0
- package/bizar-dash/dist/assets/main-NYFpS2wY.js +312 -0
- package/bizar-dash/dist/assets/main-NYFpS2wY.js.map +1 -0
- package/bizar-dash/dist/assets/{mobile-DSb-t42Y.js → mobile--0FBIKX3.js} +2 -2
- package/bizar-dash/dist/assets/{mobile-DSb-t42Y.js.map → mobile--0FBIKX3.js.map} +1 -1
- package/bizar-dash/dist/assets/mobile-OgRp8VIb.js +352 -0
- package/bizar-dash/dist/assets/mobile-OgRp8VIb.js.map +1 -0
- package/bizar-dash/dist/index.html +3 -3
- package/bizar-dash/dist/mobile.html +2 -2
- package/bizar-dash/skills/agent-baseline/SKILL.md +80 -0
- package/bizar-dash/skills/bizar/SKILL.md +96 -0
- package/bizar-dash/skills/chat/SKILL.md +74 -0
- package/bizar-dash/skills/lightrag/SKILL.md +75 -0
- package/bizar-dash/skills/minimax/SKILL.md +80 -0
- package/bizar-dash/skills/obsidian/SKILL.md +55 -0
- package/bizar-dash/skills/providers/SKILL.md +75 -0
- package/bizar-dash/skills/sdk/SKILL.md +138 -0
- package/bizar-dash/skills/self-improvement/SKILL.md +53 -0
- package/bizar-dash/skills/skills-cli/SKILL.md +94 -0
- package/bizar-dash/skills/usage/SKILL.md +62 -0
- package/bizar-dash/src/server/api.mjs +12 -0
- package/bizar-dash/src/server/memory-lightrag.mjs +5 -2
- package/bizar-dash/src/server/memory-store.mjs +38 -0
- package/bizar-dash/src/server/minimax-usage-store.mjs +372 -0
- package/bizar-dash/src/server/minimax.mjs +196 -5
- package/bizar-dash/src/server/providers-store.mjs +956 -0
- package/bizar-dash/src/server/routes/config.mjs +52 -1
- package/bizar-dash/src/server/routes/env-vars.mjs +165 -0
- package/bizar-dash/src/server/routes/lightrag.mjs +154 -0
- package/bizar-dash/src/server/routes/memory.mjs +241 -1
- package/bizar-dash/src/server/routes/opencode-session-detail.mjs +14 -29
- package/bizar-dash/src/server/routes/opencode-sessions.mjs +205 -3
- package/bizar-dash/src/server/routes/providers.mjs +266 -5
- package/bizar-dash/src/server/routes/skills.mjs +32 -43
- package/bizar-dash/src/server/routes/update.mjs +340 -0
- package/bizar-dash/src/server/routes/usage.mjs +136 -0
- package/bizar-dash/src/server/serve-info.mjs +135 -4
- package/bizar-dash/src/server/server.mjs +4 -0
- package/bizar-dash/src/server/skills-store.mjs +152 -262
- package/bizar-dash/src/web/App.tsx +118 -29
- package/bizar-dash/src/web/components/EnvVarManager.tsx +247 -0
- package/bizar-dash/src/web/components/SettingsSearch.tsx +213 -0
- package/bizar-dash/src/web/components/Topbar.tsx +0 -1
- package/bizar-dash/src/web/components/UsageChart.tsx +250 -0
- package/bizar-dash/src/web/components/UsageTable.tsx +90 -0
- package/bizar-dash/src/web/components/chat/ChatComposer.tsx +21 -25
- package/bizar-dash/src/web/components/chat/ChatInfoPanel.tsx +199 -37
- package/bizar-dash/src/web/components/chat/ChatThread.tsx +29 -17
- package/bizar-dash/src/web/components/chat/FloatingComposer.tsx +7 -1
- package/bizar-dash/src/web/components/chat/InfoPanel.tsx +71 -6
- package/bizar-dash/src/web/components/chat/useChat.ts +751 -257
- package/bizar-dash/src/web/lib/api.ts +43 -0
- package/bizar-dash/src/web/main.tsx +1 -0
- package/bizar-dash/src/web/mobile/views/MobileChat.tsx +110 -35
- package/bizar-dash/src/web/styles/chat.css +135 -1
- package/bizar-dash/src/web/styles/main.css +46 -0
- package/bizar-dash/src/web/styles/minimax-usage.css +335 -0
- package/bizar-dash/src/web/styles/settings.css +418 -0
- package/bizar-dash/src/web/styles/skills.css +302 -0
- package/bizar-dash/src/web/styles/tasks.css +288 -0
- package/bizar-dash/src/web/views/Chat.tsx +276 -48
- package/bizar-dash/src/web/views/Config.tsx +3 -2065
- package/bizar-dash/src/web/views/MiniMaxUsage.tsx +476 -461
- package/bizar-dash/src/web/views/Settings.tsx +6 -0
- package/bizar-dash/src/web/views/Skills.tsx +208 -260
- package/bizar-dash/src/web/views/Tasks.tsx +348 -1119
- package/bizar-dash/tests/chat-session-create.test.mjs +391 -0
- package/bizar-dash/tests/chat-session-stream.test.mjs +308 -0
- package/bizar-dash/tests/env-vars-store.test.mjs +216 -0
- package/bizar-dash/tests/lightrag-defaults.node.test.mjs +118 -0
- package/bizar-dash/tests/minimax-chat-usage.test.mjs +178 -0
- package/bizar-dash/tests/minimax-usage-store.node.test.mjs +293 -0
- package/bizar-dash/tests/opencode-sessions-detail.test.mjs +12 -9
- package/bizar-dash/tests/providers-store-backup-keys.node.test.mjs +479 -3
- package/bizar-dash/tests/providers-store-search.node.test.mjs +166 -0
- package/bizar-dash/tests/skills-list.test.mjs +232 -0
- package/bizar-dash/tests/skills-search.test.mjs +222 -0
- package/bizar-dash/tests/tasks-create.test.mjs +187 -0
- package/bizar-dash/tests/update-check.test.mjs +127 -0
- package/bizar-dash/tests/update-run.test.mjs +266 -0
- package/cli/bin.mjs +82 -1
- package/cli/provision.mjs +118 -4
- package/config/agents/_shared/SKILLS.md +109 -0
- package/package.json +1 -1
- package/bizar-dash/dist/assets/main-BB5mJurD.js +0 -352
- package/bizar-dash/dist/assets/main-BB5mJurD.js.map +0 -1
- package/bizar-dash/dist/assets/main-BsnQLXdh.css +0 -1
- package/bizar-dash/dist/assets/mobile-Dl1q7Cyq.js +0 -354
- package/bizar-dash/dist/assets/mobile-Dl1q7Cyq.js.map +0 -1
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
var Kt=Object.defineProperty;var Gt=(s,t,a)=>t in s?Kt(s,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):s[t]=a;var Is=(s,t,a)=>Gt(s,typeof t!="symbol"?t+"":t,a);import{c as Z,r,a as z,j as e,R as he,C as Gs,F as Ie,b as Le,d as _e,M as zs,B as De,S as as,A as Re,e as Oe,f as ys,H as ns,g as vt,h as Pe,i as ee,u as $e,P as Ne,k as $,l as de,X as Ee,m as Yt,T as we,n as Xe,I as Ts,o as ye,p as fe,q as qe,s as yt,t as Te,v as bt,w as Xt,E as Qt,x as Ms,y as Jt,z as ss,D as is,G as $s,J as Zt,K as ea,L as sa,N as ta,O as bs,Q as kt,U as Ys,V as Nt,W as aa,Y as wt,Z as St,_ as Ct,$ as na,a0 as ia,a1 as ra,a2 as la,a3 as Xs,a4 as Ge,a5 as rt,a6 as oa,a7 as ca,a8 as da,a9 as As,aa as ts,ab as Qs,ac as ha,ad as ma,ae as ua,af as zt,ag as xa,ah as pa,ai as ga,aj as ja,ak as fa,al as va}from"./mobile-OgRp8VIb.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 Tt=Z("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 ya=Z("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 Mt=Z("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 $t=Z("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 ba=Z("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"}]]);/**
|
|
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 At=Z("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"}]]);/**
|
|
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 qs=Z("Check",[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]]);/**
|
|
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 ka=Z("ChevronLeft",[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]]);/**
|
|
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 Na=Z("CircleCheckBig",[["path",{d:"M21.801 10A10 10 0 1 1 17 3.335",key:"yps3ct"}],["path",{d:"m9 11 3 3L22 4",key:"1pflzl"}]]);/**
|
|
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 wa=Z("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"}]]);/**
|
|
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 Sa=Z("CirclePlay",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["polygon",{points:"10 8 16 12 10 16 10 8",key:"1cimsy"}]]);/**
|
|
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 Rt=Z("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"}]]);/**
|
|
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 Ca=Z("Circle",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]]);/**
|
|
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 Js=Z("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"}]]);/**
|
|
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 Ls=Z("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"}]]);/**
|
|
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 za=Z("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"}]]);/**
|
|
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 Qe=Z("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"}]]);/**
|
|
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 Ta=Z("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"}]]);/**
|
|
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 _s=Z("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"}]]);/**
|
|
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 Je=Z("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"}]]);/**
|
|
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 Ma=Z("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"}]]);/**
|
|
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 $a=Z("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"}]]);/**
|
|
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 Aa=Z("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"}]]);/**
|
|
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 Ra=Z("Filter",[["polygon",{points:"22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3",key:"1yg77f"}]]);/**
|
|
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 Ia=Z("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"}]]);/**
|
|
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 La=Z("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"}]]);/**
|
|
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 Ea=Z("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"}]]);/**
|
|
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 rs=Z("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"}]]);/**
|
|
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 Da=Z("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"}]]);/**
|
|
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 ks=Z("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"}]]);/**
|
|
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 Zs=Z("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"}]]);/**
|
|
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 Pa=Z("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"}]]);/**
|
|
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 Oa=Z("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"}]]);/**
|
|
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 Hs=Z("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"}]]);/**
|
|
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 ls=Z("LoaderCircle",[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]]);/**
|
|
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 lt=Z("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"}]]);/**
|
|
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 Ns=Z("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"}]]);/**
|
|
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 Fa=Z("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"}]]);/**
|
|
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 Ba=Z("Minus",[["path",{d:"M5 12h14",key:"1ays0h"}]]);/**
|
|
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 Ua=Z("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"}]]);/**
|
|
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 et=Z("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"}]]);/**
|
|
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 qa=Z("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"}]]);/**
|
|
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 _a=Z("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"}]]);/**
|
|
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 Ha=Z("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"}]]);/**
|
|
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 Wa=Z("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"}]]);/**
|
|
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 Va=Z("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"}]]);/**
|
|
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 Ka=Z("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"}]]);/**
|
|
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 ws=Z("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"}]]);/**
|
|
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 Ga=Z("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"}]]);/**
|
|
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 Ya=Z("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"}]]);/**
|
|
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 Xa=Z("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"}]]);/**
|
|
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 Ss=Z("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"}]]);/**
|
|
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 Qa=Z("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"}]]);/**
|
|
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 Ja=Z("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"}]]);/**
|
|
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 It=Z("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"}]]);/**
|
|
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 Za=Z("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"}]]);/**
|
|
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 en=Z("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"}]]);/**
|
|
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 sn=Z("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"}]]);/**
|
|
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 Lt=Z("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"}]]);/**
|
|
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 tn=Z("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"}]]),an=200,nn=5*60*1e3,Ue=new Map;function rn(s){const t=Ue.get(s);return t?Date.now()-t.ts>nn?(Ue.delete(s),null):t.data:null}function Es(s,t){Ue.size>=an&&[...Ue.entries()].sort((i,n)=>i[1].ts-n[1].ts).slice(0,50).map(([i])=>i).forEach(i=>Ue.delete(i)),Ue.set(s,{data:t,ts:Date.now()})}function ln(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 on(s){return[...s].sort((t,a)=>t.isDir!==a.isDir?t.isDir?-1:1:t.name.localeCompare(a.name,void 0,{sensitivity:"base"}))}function cn(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 Et({value:s,onChange:t,initialPath:a,projectsDirectory:i,rootLabel:n="Home",height:l=360}){const[o,c]=r.useState(a??i??""),[p,u]=r.useState(new Set),[j,m]=r.useState(-1),[d,x]=r.useState(null),[b,g]=r.useState({}),[w,T]=r.useState(!1),[v,k]=r.useState(null),[L,y]=r.useState(!1),[M,F]=r.useState(""),[S,I]=r.useState(null),[H,R]=r.useState(!1),q=r.useRef(null),_=r.useCallback(async A=>{try{const ne=rn(A);if(ne)return ne;const te=await z.get("/fs?path="+encodeURIComponent(A));return Es(A,te),te}catch{return null}},[]),f=r.useCallback(async A=>{var ne;T(!0),k(null);try{const te=await z.get("/fs?path="+encodeURIComponent(A));Es(A,te),x(te),m(-1)}catch(te){const me=((ne=te.data)==null?void 0:ne.message)??te.message??"Failed to load directory";k(me)}finally{T(!1)}},[]);r.useEffect(()=>{o?f(o):z.get("/fs").then(A=>{Es("",A),x(A),c(A.path),A.path!==s&&t(A.path)}).catch(()=>{k("Could not determine home directory."),T(!1)})},[o]),r.useEffect(()=>{s&&s!==o&&c(s)},[s]);const E=d?on(d.entries):[],G=E.filter(A=>A.isDir),D=E,V=A=>{A.isDir&&(c(A.path),t(A.path))},se=()=>{d!=null&&d.parent&&(c(d.parent),t(d.parent))},Q=A=>{A!==o&&(c(A),t(A))},B=async()=>{const A=await _("");A&&(c(A.path),t(A.path))},Y=async()=>{if(!i)return;const A=await _(i);A&&(c(A.path),t(A.path))},J=()=>{y(!0),F(""),I(null),setTimeout(()=>{var A;return(A=q.current)==null?void 0:A.focus()},0)},X=()=>{y(!1),F(""),I(null)},ae=async()=>{var ne;const A=cn(M);if(!A.ok){I(A.reason);return}R(!0),I(null);try{const te=await z.post("/fs/mkdir",{parent:o,name:M.trim()});Ue.delete(o),await f(o),t(te.path),y(!1),F("")}catch(te){const me=te;me.status===409?I(`A folder named "${M.trim()}" already exists.`):I(((ne=me.data)==null?void 0:ne.message)??te.message??"Failed to create folder.")}finally{R(!1)}},ue=A=>{A.key==="Enter"?(A.preventDefault(),ae()):A.key==="Escape"&&(A.preventDefault(),X())},W=A=>{u(ne=>{const te=new Set(ne);return te.has(A)?te.delete(A):te.add(A),te}),b[A]||_(A).then(ne=>{ne&&g(te=>({...te,[A]:ne.entries.filter(me=>me.isDir)}))})},C=A=>{if(!d)return;const ne=D.filter(le=>le.isDir),te=D.filter(le=>!le.isDir),me=[...ne,...te];if(A.key==="ArrowDown")A.preventDefault(),m(le=>Math.min(le+1,me.length-1));else if(A.key==="ArrowUp")A.preventDefault(),m(le=>Math.max(le-1,0));else if(A.key==="Enter"||A.key===" "){A.preventDefault();const le=me[j];le&&(A.key==="Enter"&&le.isDir?V(le):le.isDir&&t(le.path))}else A.key==="Backspace"&&(A.preventDefault(),se())},P=ln((d==null?void 0:d.path)??o??"/"),h=d==null?void 0:d.parent,O=h!=null,U=o.split("/").filter(Boolean).at(-1)??"/";return e.jsxs("div",{className:"file-browser",onKeyDown:C,tabIndex:-1,children:[e.jsx("div",{className:"file-browser-breadcrumb",role:"navigation","aria-label":"Path breadcrumb",children:P.map((A,ne)=>e.jsxs("span",{className:"file-browser-breadcrumb-item",children:[ne>0&&e.jsx("span",{className:"file-browser-breadcrumb-sep","aria-hidden":!0,children:"/"}),e.jsx("button",{type:"button",className:"file-browser-breadcrumb-btn",onClick:()=>Q(A.path),title:A.path,children:ne===0?A.path==="/"?"/":n:A.label})]},A.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:se,disabled:!O,title:"Go up (Backspace)","aria-label":"Go up one level",children:e.jsx(Mt,{size:13})}),e.jsx("button",{type:"button",className:"file-browser-tool-btn",onClick:()=>f(o),disabled:w,title:"Refresh","aria-label":"Refresh",children:e.jsx(he,{size:13,className:w?"spin":""})}),e.jsx("button",{type:"button",className:"file-browser-tool-btn",onClick:J,title:"New folder","aria-label":"Create new folder",children:e.jsx(La,{size:13})}),e.jsxs("div",{className:"file-browser-chips",children:[e.jsxs("button",{type:"button",className:"file-browser-chip",onClick:B,children:[e.jsx(Da,{size:11})," ",n]}),i&&e.jsxs("button",{type:"button",className:"file-browser-chip",onClick:Y,title:i,children:[e.jsx(Ia,{size:11})," ",i.split("/").filter(Boolean).at(-1)??"Projects"]})]})]}),L?e.jsxs("div",{className:"file-browser-mkdir",children:[e.jsx("input",{ref:q,type:"text",className:"file-browser-mkdir-input",placeholder:"Folder name",value:M,onChange:A=>{F(A.target.value),I(null)},onKeyDown:ue,"aria-label":"New folder name","aria-invalid":S?"true":void 0,"aria-describedby":S?"mkdir-error":void 0,disabled:H,maxLength:255}),S?e.jsx("span",{id:"mkdir-error",className:"file-browser-mkdir-error",role:"alert",children:S}):e.jsx("span",{className:"file-browser-mkdir-hint",children:"Enter to create, Esc to cancel"})]}):e.jsx("span",{className:"file-browser-count-hint",children:w?"…":`${E.length} in ${U}`})]}),v&&e.jsxs("div",{className:"file-browser-error",children:[e.jsx(Gs,{size:13}),e.jsx("span",{children:v}),e.jsx("button",{type:"button",className:"file-browser-retry",onClick:()=>f(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:w&&!d?e.jsx(dn,{}):e.jsx(Dt,{path:o,entries:G,expanded:p,childrenMap:b,onToggle:W,onNavigate:V,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"})]}),w&&!d?e.jsx(hn,{}):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."]}),D.length===0?e.jsx("div",{className:"file-browser-empty",children:"This folder is empty"}):e.jsx("div",{className:"file-browser-flat-list",children:D.map((A,ne)=>{const te=A.isDir,me=ne===j,le=A.path===s;return e.jsxs("div",{role:"option","aria-selected":le,className:["file-browser-row",te?"file-browser-row--dir":"file-browser-row--file",me&&"file-browser-row--selected",le&&te&&"file-browser-row--active",!te&&"file-browser-row--disabled"].filter(Boolean).join(" "),onClick:()=>{te&&(m(ne),t(A.path))},onDoubleClick:()=>{te&&V(A)},title:A.path,children:[e.jsx("span",{className:"file-browser-row-icon",children:te?e.jsx(Ie,{size:13}):e.jsx(Aa,{size:13})}),e.jsx("span",{className:"file-browser-row-name",children:A.name}),e.jsx("span",{className:"file-browser-row-type",children:te?"Folder":""})]},A.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 Dt({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 p=a.has(c.path),u=i[c.path]??[];return e.jsxs("li",{className:"file-browser-tree-node",children:[e.jsxs("div",{className:["file-browser-tree-row",p&&"file-browser-tree-row--expanded"].filter(Boolean).join(" "),style:{paddingLeft:`${o*16+8}px`},children:[e.jsx("button",{type:"button",className:"file-browser-tree-toggle",onClick:j=>{j.stopPropagation(),n(c.path)},"aria-label":p?"Collapse":"Expand",children:(u.length>0,p?e.jsx(Le,{size:11}):e.jsx(_e,{size:11}))}),e.jsxs("button",{type:"button",className:"file-browser-tree-name",onClick:()=>l(c),title:c.path,children:[e.jsx(Ie,{size:12}),e.jsx("span",{children:c.name})]})]}),p&&u.length>0&&e.jsx(Dt,{path:c.path,entries:u,expanded:a,childrenMap:i,onToggle:n,onNavigate:l,level:o+1})]},c.path)})})}function dn(){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 hn(){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 Ws=[{id:"overview",label:"Overview",icon:Oa},{id:"chat",label:"Chat",icon:zs},{id:"agents",label:"Agents",icon:De},{id:"artifacts",label:"Glyphs",icon:Ns},{id:"tasks",label:"Tasks",icon:as},{id:"activity",label:"Activity",icon:Re},{id:"background",label:"Active",icon:Ga},{id:"skills",label:"Skills",icon:Oe},{id:"mods",label:"Mods",icon:ws},{id:"schedules",label:"Schedules",icon:ys},{id:"history",label:"History",icon:ns},{id:"minimax",label:"Usage",icon:Js},{id:"settings",label:"Settings",icon:vt}];function mn({activeTab:s,onTabChange:t,wsStatus:a,version:i,activeProject:n,projects:l,onProjectChange:o,onProjectsRefresh:c,onOpenSearch:p,settings:u,rightSlot:j,notificationsSlot:m,showTabs:d=!0,extraTabs:x}){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(un,{activeProject:n,projects:l,onChange:o,onRefresh:c,settings:u??null}),e.jsxs("button",{type:"button",className:"topbar-search",onClick:p,title:"Search (Ctrl/Cmd+K)","aria-label":"Open search",children:[e.jsx(Pe,{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:[m,j,e.jsxs("div",{className:ee("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",children:[Ws.map(b=>{const g=b.icon,w=b.id===s;return e.jsxs("button",{type:"button",role:"tab","aria-selected":w,className:ee("tab",w&&"tab-active"),onClick:()=>t(b.id),title:b.label,children:[e.jsx(g,{size:14,className:"tab-icon"}),e.jsx("span",{className:"tab-label",children:b.label})]},b.id)}),x&&x.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"tab-separator","aria-hidden":"true"}),x.map(b=>{const g=b.icon,w=b.id===s;return e.jsxs("button",{type:"button",role:"tab","aria-selected":w,className:ee("tab","tab-mod",w&&"tab-active"),onClick:()=>t(b.id),title:`${b.label} (mod)`,children:[e.jsx(g,{size:14,className:"tab-icon"}),e.jsx("span",{className:"tab-label",children:b.label}),e.jsx("span",{className:"tab-badge",children:"mod"})]},b.id)})]})]})]})}function un({activeProject:s,projects:t,onChange:a,onRefresh:i,settings:n}){const[l,o]=r.useState(!1),c=$e();r.useEffect(()=>{if(!l)return;const u=()=>o(!1);return document.addEventListener("click",u),()=>document.removeEventListener("click",u)},[l]);const p=()=>{c.open({title:"Add project",children:e.jsx(xn,{settings:n,onAdd:async(u,j)=>{try{await z.post("/projects",{path:u,name:j}),i(),o(!1),c.close()}catch(m){alert(`Add failed: ${m.message}`)}}}),footer:e.jsx("div",{className:"modal-footer-actions",children:e.jsx($,{variant:"ghost",onClick:()=>c.close(),children:"Cancel"})})})};return e.jsxs("div",{className:"project-selector",onClick:u=>u.stopPropagation(),children:[e.jsxs("button",{type:"button",className:"project-selector-btn",onClick:()=>o(u=>!u),title:"Switch active project","aria-haspopup":"menu","aria-expanded":l,children:[e.jsx(Ie,{size:14}),e.jsx("span",{className:"project-selector-name",children:(s==null?void 0:s.name)||"(no project)"}),e.jsx(Le,{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(he,{size:12})}),e.jsx("button",{type:"button",className:"icon-btn",onClick:p,title:"Add project","aria-label":"Add project",children:e.jsx(Ne,{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(u=>e.jsx("li",{children:e.jsxs("button",{type:"button",className:ee("project-selector-item",(s==null?void 0:s.id)===u.id&&"active"),onClick:()=>{a(u.id),o(!1)},children:[e.jsx("span",{className:"project-selector-item-name",children:u.name}),e.jsx("span",{className:"project-selector-item-status",children:u.status})]})},u.id))]})]})]})}function xn({settings:s,onAdd:t}){var m,d;const[a,i]=r.useState(((m=s==null?void 0:s.dashboard)==null?void 0:m.projectsDirectory)??""),[n,l]=r.useState(""),[o,c]=r.useState(!1),[p,u]=r.useState(null),j=async()=>{var x;if(a){c(!0),u(null);try{await z.get("/fs?path="+encodeURIComponent(a)),t(a,n||null)}catch(b){const g=b;g.status===404?u("That folder no longer exists. Pick another."):u(((x=g.data)==null?void 0:x.message)??b.message??"Validation failed.")}finally{c(!1)}}};return e.jsxs("div",{children:[e.jsx("label",{className:"field-label",children:"Folder"}),e.jsx(Et,{value:a,onChange:x=>{i(x),u(null)},projectsDirectory:(d=s==null?void 0:s.dashboard)==null?void 0:d.projectsDirectory,height:320}),p&&e.jsx("p",{className:"field-help",style:{color:"var(--error)",marginTop:4},children:p}),e.jsxs("div",{style:{marginTop:"var(--space-3)"},children:[e.jsx("label",{className:"field-label",htmlFor:"topbar-add-project-name",children:"Name (optional)"}),e.jsx("input",{id:"topbar-add-project-name",className:"input",type:"text",placeholder:"My App",value:n,onChange:x=>l(x.target.value)})]}),e.jsx("div",{style:{marginTop:"var(--space-3)",display:"flex",justifyContent:"flex-end"},children:e.jsxs($,{variant:"primary",onClick:j,disabled:!a||o,children:[o?e.jsx("span",{className:"btn-spinner"}):null,o?"Checking…":"Add"]})})]})}function pn({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:ee("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:ee("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 Ds=[{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"}],ot={all:null,projects:"project",agents:"agent",tasks:"task",mods:"mod",schedules:"schedule",commands:"command",settings:"setting"};function gn({open:s,onClose:t,onSelect:a}){const i=de(),[n,l]=r.useState(""),[o,c]=r.useState("all"),[p,u]=r.useState([]),[j,m]=r.useState(!1),[d,x]=r.useState(0),b=r.useRef(null),g=r.useRef(null);if(r.useEffect(()=>{let k;return s&&(g.current=document.activeElement instanceof HTMLElement?document.activeElement:null,l(""),u([]),x(0),k=window.setTimeout(()=>{var L;return(L=b.current)==null?void 0:L.focus()},30)),()=>{if(k&&window.clearTimeout(k),!s)return;const L=g.current;L&&L.isConnected&&L.focus()}},[s]),r.useEffect(()=>{if(!s)return;if(!n.trim()){u([]),x(0);return}let k=!1;m(!0);const L=setTimeout(()=>{z.get(`/search?q=${encodeURIComponent(n)}&scope=${o}`).then(y=>{k||(u(y.results||[]),x(0))}).catch(y=>{k||i.error(`Search failed: ${y.message}`)}).finally(()=>!k&&m(!1))},150);return()=>{k=!0,clearTimeout(L)}},[n,o,s,i]),!s)return null;const w={};for(const k of p){const L=k.type.toLowerCase();w[L]=w[L]||[],w[L].push(k)}const T=[];for(const k of Ds.map(L=>L.id)){const L=ot[k];L&&w[L]&&T.push(...w[L])}const v=k=>{if(k.key==="Escape")t();else if(k.key==="ArrowDown"){if(k.preventDefault(),T.length===0)return;x(L=>Math.min(L+1,T.length-1))}else if(k.key==="ArrowUp"){if(k.preventDefault(),T.length===0)return;x(L=>Math.max(L-1,0))}else k.key==="Enter"&&T[d]&&(k.preventDefault(),a(T[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",children:[e.jsx(Pe,{size:14}),e.jsx("span",{id:"search-modal-title",className:"sr-only",children:"Search"}),e.jsx("input",{ref:b,className:"search-modal-input",placeholder:"Search tasks, agents, settings, projects…",value:n,onChange:k=>l(k.target.value),onKeyDown:v}),e.jsx("button",{type:"button",className:"icon-btn","aria-label":"Close",onClick:t,children:e.jsx(Ee,{size:14})})]}),e.jsx("div",{className:"search-modal-scopes",children:Ds.map(k=>e.jsx("button",{type:"button",className:ee("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:[j&&e.jsx("div",{className:"muted",children:"Searching…"}),!j&&n&&T.length===0&&e.jsx("div",{className:"muted",children:"No results."}),!j&&!n&&e.jsx("div",{className:"muted",children:"Type to search…"}),Ds.map(k=>{const L=ot[k.id];if(!L)return null;const y=w[L];return!y||y.length===0?null:e.jsxs("div",{className:"search-group",children:[e.jsx("div",{className:"search-group-head",children:k.label}),y.map(M=>{const F=T.indexOf(M);return e.jsxs("button",{type:"button",className:ee("search-result",F===d&&"search-result-active"),onMouseEnter:()=>x(F),onClick:()=>{a(M),t()},children:[e.jsx("span",{className:"search-result-type",children:M.type}),e.jsx("span",{className:"search-result-label",children:jn(M)})]},`${M.type}-${F}`)})]},k.id)})]}),e.jsx("div",{className:"search-modal-foot",children:e.jsx("span",{className:"muted",children:"↑↓ navigate · ↵ open · esc close"})})]})})}function jn(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 fn={info:Ts,success:Xe,warning:we,error:Gs};function vn({onCountChange:s,wsSubscribe:t}){const a=de(),[i,n]=r.useState(!1),[l,o]=r.useState([]),[c,p]=r.useState(null),[u,j]=r.useState(!1),m=r.useRef(null),d=r.useRef(0),x=async()=>{var v;try{j(!0);const k=await z.get("/notifications?limit=200");o(k.notifications||[]),p(k.stats||null),d.current=((v=k.stats)==null?void 0:v.unread)||0,s==null||s(d.current)}catch(k){console.warn("[notifications] reload failed:",k.message)}finally{j(!1)}};r.useEffect(()=>{x()},[]),r.useEffect(()=>t?t(k=>{if(k.type==="notification:new"){const L=k.notification;o(y=>[L,...y.filter(M=>M.id!==L.id)]),L.read||(d.current+=1,p(y=>y?{...y,unread:(y.unread||0)+1}:{total:1,unread:1,lastTs:L.ts,counts:{[L.severity||"info"]:1}}),s==null||s(d.current))}else k.type==="notifications:change"&&x()}):void 0,[t]),r.useEffect(()=>{if(!i)return;const v=L=>{m.current&&(m.current.contains(L.target)||n(!1))},k=L=>{L.key==="Escape"&&n(!1)};return document.addEventListener("mousedown",v),document.addEventListener("keydown",k),()=>{document.removeEventListener("mousedown",v),document.removeEventListener("keydown",k)}},[i]);const b=async()=>{try{await z.post("/notifications/read-all",{}),o(v=>v.map(k=>({...k,read:!0}))),p(v=>v&&{...v,unread:0}),d.current=0,s==null||s(0),a.success("All notifications marked as read.",1500)}catch(v){a.error(`Failed: ${v.message}`)}},g=async v=>{try{await z.post(`/notifications/${encodeURIComponent(v)}/read`,{}),o(k=>k.map(L=>L.id===v?{...L,read:!0}:L)),p(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}`)}},w=async v=>{try{await z.del(`/notifications/${encodeURIComponent(v)}`),o(k=>{const L=k.find(y=>y.id===v);return L&&!L.read&&(d.current=Math.max(0,d.current-1),p(y=>y&&{...y,unread:Math.max(0,y.unread-1)}),s==null||s(d.current)),k.filter(y=>y.id!==v)})}catch(k){a.error(`Failed: ${k.message}`)}},T=(c==null?void 0:c.unread)||0;return e.jsxs("div",{className:"notifications-root",ref:m,children:[e.jsxs("button",{type:"button",className:ee("topbar-icon-btn notifications-bell",i&&"is-open"),onClick:()=>n(v=>!v),title:"Notifications","aria-label":"Notifications","aria-haspopup":"true","aria-expanded":i,children:[e.jsx(Yt,{size:16}),T>0&&e.jsx("span",{className:"notifications-badge",children:T>99?"99+":T})]}),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"}),T>0&&e.jsxs("span",{className:"muted text-sm",children:[" · ",T," unread"]})]}),e.jsxs("div",{className:"notifications-panel-head-actions",children:[e.jsxs($,{size:"sm",variant:"ghost",onClick:b,disabled:T===0,children:[e.jsx(qs,{size:12})," Mark all read"]}),e.jsx("button",{type:"button",className:"icon-btn",onClick:()=>n(!1),"aria-label":"Close",title:"Close",children:e.jsx(Ee,{size:14})})]})]}),e.jsx("div",{className:"notifications-list",children:u&&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(v=>{const k=fn[v.severity]||Ts;return e.jsxs("div",{className:ee("notification-item",!v.read&&"is-unread",`severity-${v.severity}`),children:[e.jsx(k,{size:14,className:`notification-icon severity-${v.severity}`}),e.jsxs("div",{className:"notification-body",children:[v.title&&e.jsx("div",{className:"notification-title",children:v.title}),e.jsx("div",{className:"notification-msg",children:v.message}),e.jsxs("div",{className:"notification-meta muted",children:[e.jsx("span",{className:"mono",children:v.source}),e.jsx("span",{children:"·"}),e.jsx("span",{children:ye(v.ts)})]})]}),e.jsxs("div",{className:"notification-actions",children:[!v.read&&e.jsx("button",{type:"button",className:"icon-btn",onClick:()=>g(v.id),title:"Mark as read","aria-label":"Mark as read",children:e.jsx(qs,{size:12})}),e.jsx("button",{type:"button",className:"icon-btn icon-btn-danger",onClick:()=>w(v.id),title:"Remove","aria-label":"Remove",children:e.jsx(Ee,{size:12})})]})]},v.id)})}),e.jsx("footer",{className:"notifications-panel-foot",children:e.jsx("span",{className:"muted text-sm",children:c?`${c.total} total · last ${ye(c.lastTs||new Date().toISOString())}`:""})})]})]})}function yn({data:s,onClose:t}){const a=s==null?void 0:s.enabled;s==null||s.previousEnabled;const i=s==null?void 0:s.mode,n=s==null?void 0:s.defaultTemplate,l=s==null?void 0:s.lastUsedSlug,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($,{variant:"ghost",onClick:t,children:"Close"})})]})}const bn=["blank","feature-design","bug-investigation","decision-record","horizontal","vertical"];function kn({data:s,onClose:t}){const a=(s==null?void 0:s.templates)??bn,i=(s==null?void 0:s.defaultTemplate)??"blank",[n,l]=r.useState(""),[o,c]=r.useState(i),[p,u]=r.useState(!1),[j,m]=r.useState(null),d=async()=>{if(!n.trim()){m("Slug is required.");return}if(!/^[a-z0-9][a-z0-9-]{0,63}$/.test(n)){m("Invalid slug. Use lowercase letters, numbers, and hyphens. Must start with an alphanumeric character.");return}u(!0),m(null);try{await z.post("/artifacts",{slug:n,template:o}),t()}catch(x){m(x.message),u(!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:x=>{l(x.target.value),m(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:x=>c(x.target.value),children:a.map(x=>e.jsx("option",{value:x,children:x},x))})]}),j&&e.jsx("p",{style:{marginBottom:12,color:"var(--color-danger)",fontSize:13},children:j}),e.jsxs("div",{style:{display:"flex",gap:8,justifyContent:"flex-end"},children:[e.jsx($,{variant:"ghost",onClick:t,disabled:p,children:"Cancel"}),e.jsx($,{variant:"primary",onClick:d,disabled:p||!n.trim(),children:p?"Creating…":"Create"})]})]})}function Nn({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($,{variant:"ghost",size:"sm",onClick:()=>n(l),children:"Open"})]},l))})]}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsx($,{variant:"ghost",onClick:t,children:"Close"})})]})}function wn({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($,{variant:"ghost",onClick:t,children:"Close"})})]})}function Sn({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 z.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($,{variant:"ghost",onClick:t,children:"Cancel"}),e.jsx($,{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,p)=>e.jsx("li",{style:{marginBottom:4,fontSize:13},children:c},p))})]}):e.jsxs("p",{style:{marginBottom:16,color:"var(--color-danger)"},children:["Audit failed: ",n.error??"unknown error"]}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsx($,{variant:"ghost",onClick:t,children:"Close"})})]})})}function Cn({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 zn({dialog:s,onClose:t}){switch(s.component){case"visual-artifact":return e.jsx(yn,{data:s.data,onClose:t});case"artifact-create":return e.jsx(kn,{data:s.data,onClose:t});case"artifact-list":return e.jsx(Nn,{data:s.data,onClose:t});case"help":return e.jsx(wn,{data:s.data,onClose:t});case"audit":return e.jsx(Sn,{data:s.data,onClose:t});default:return e.jsx(Cn,{dialog:s,onClose:t})}}function ie({variant:s="elevated",interactive:t=!1,className:a,children:i,...n}){return e.jsx("div",{className:ee("card",`card-${s}`,t&&"card-interactive",a),...n,children:i})}function re({children:s,className:t}){return e.jsx("h3",{className:ee("card-title",t),children:s})}function ce({children:s,className:t}){return e.jsx("div",{className:ee("card-meta",t),children:s})}function ze({icon:s,title:t,message:a,action:i,className:n}){return e.jsxs("div",{className:ee("empty-state",n),children:[e.jsx("div",{className:"empty-icon",children:s??e.jsx(ks,{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 Tn({snapshot:s,settings:t,setActiveTab:a,refreshSnapshot:i}){var V,se,Q;const n=de(),l=$e(),o=r.useRef(null),[c,p]=r.useState(s.overview??null),[u,j]=r.useState(!s.overview),[m,d]=r.useState(s.projects||[]),[x,b]=r.useState(((V=s.activeProject)==null?void 0:V.id)||null),[g,w]=r.useState(s.mods||[]),[T,v]=r.useState(!1),[k,L]=r.useState(((se=s.overview)==null?void 0:se.recentActivity)??[]),[y,M]=r.useState(!1),[F,S]=r.useState(new Set);r.useEffect(()=>{let B=!1;return(async()=>{try{const Y=await z.get("/activity/hidden");B||S(new Set(Y.hidden||[]))}catch{}})(),()=>{B=!0}},[]);const I=(B,Y)=>{const J=`${B.kind||""}|${B.ts||""}|${B.slug||B.title||""}|${Y}`;let X=0;for(let ae=0;ae<J.length;ae++)X=(X<<5)-X+J.charCodeAt(ae)|0;return Math.abs(X).toString(16).padStart(8,"0").slice(0,16)},H=async B=>{const Y=new Set(F);Y.add(B),S(Y);try{await z.post("/activity/hide",{keys:[B]})}catch(J){const X=new Set(F);S(X),n.error(`Hide failed: ${J.message}`)}},R=async()=>{if(!confirm("Hide every recent activity item from the overview? The full log stays in Settings → Activity Log."))return;const B=k.map((J,X)=>I(J,X)),Y=new Set(F);B.forEach(J=>Y.add(J)),S(Y);try{await z.post("/activity/hide",{keys:B}),n.success(`Hidden ${B.length} item(s). Restore them in Settings → Activity Log.`)}catch(J){n.error(`Clear failed: ${J.message}`)}},q=async()=>{S(new Set);try{await z.del("/activity/hide"),n.success("All hidden activity restored to the overview.")}catch(B){n.error(`Restore failed: ${B.message}`)}};r.useEffect(()=>{var B;s.overview&&(p(s.overview),L(s.overview.recentActivity??[]),j(!1)),d(s.projects||[]),b(((B=s.activeProject)==null?void 0:B.id)||null),w(s.mods||[])},[s.overview,s.projects,s.activeProject,s.mods]),r.useEffect(()=>{let B;try{const Y=z.getToken(),J=Y?`/api/activity/stream?token=${encodeURIComponent(Y)}`:"/api/activity/stream";B=new EventSource(J),B.addEventListener("snapshot",X=>{try{const ae=JSON.parse(X.data);L(Array.isArray(ae.events)?ae.events.slice(0,50):[])}catch{}}),B.addEventListener("activity",X=>{try{const ae=JSON.parse(X.data);L(ue=>[ae,...ue].slice(0,50))}catch{}})}catch{}return()=>{try{B==null||B.close()}catch{}}},[]);const _=async()=>{n.info("Refreshing…",1500),await i();try{const B=await z.get("/projects");d(B.projects||[]),b(B.active||null)}catch{}},f=()=>{l.open({title:"Add project",children:e.jsx(Mn,{settings:t,onAdd:async(B,Y)=>{try{const J=await z.post("/projects",{path:B,name:Y});d(X=>[...X.filter(ae=>ae.id!==J.id),J]),n.success("Project added."),l.close()}catch(J){n.error(`Add failed: ${J.message}`)}}}),footer:e.jsx("div",{className:"modal-footer-actions",children:e.jsx($,{variant:"ghost",onClick:()=>l.close(),children:"Cancel"})})})},E=async()=>{var B;try{const Y=await z.post("/projects/auto-detect");d(Y.projects||[]),b(Y.active||null);const J=(B=Y.projects)==null?void 0:B.find(X=>X.id===Y.active);n.success(J?`Active: ${J.name}`:"Projects refreshed."),await i()}catch(Y){n.error(`Auto-detect failed: ${Y.message}`)}},G=async B=>{try{await z.post(`/projects/${encodeURIComponent(B)}/activate`),b(B),n.success("Project activated."),await i()}catch(Y){n.error(`Activate failed: ${Y.message}`)}},D=async B=>{if(confirm(`Remove project "${B}" from the registry?`))try{await z.del(`/projects/${encodeURIComponent(B)}`),d(Y=>Y.filter(J=>J.id!==B)),x===B&&b(null),n.success("Project removed.")}catch(Y){n.error(`Remove failed: ${Y.message}`)}};return u||!c?e.jsxs("div",{className:"view-loading",children:[e.jsx(fe,{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 B=>{var J,X;B.preventDefault();const Y=(((J=o.current)==null?void 0:J.value)||"").trim();if(Y){v(!0);try{const ae=await z.post("/tasks/submit",{title:Y});n.success(`Odin split it into ${((X=ae.subtasks)==null?void 0:X.length)||1} task(s)`),o.current&&(o.current.value=""),await i()}catch(ae){n.error(`Failed: ${ae.message}`)}finally{v(!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:T}),e.jsxs("div",{style:{display:"flex",gap:"var(--space-2)",alignItems:"center",flexWrap:"wrap"},children:[e.jsxs($,{type:"submit",variant:"primary",size:"lg",disabled:T,children:[T?e.jsx(fe,{size:"sm"}):e.jsx(qe,{size:16}),"Submit to Odin"]}),e.jsxs("span",{className:"muted",style:{fontSize:12},children:[e.jsx(Oe,{size:12,style:{display:"inline",verticalAlign:-2,color:"var(--accent)"}})," ","Odin + 12 specialist agents available"]})]})]}),e.jsx("div",{className:"overview-quick-actions-row",children:["Implement feature","Fix bug","Refactor","Investigate","Add tests","Document","Optimize","Deploy"].map(B=>e.jsx("button",{type:"button",className:"overview-quick-chip",onClick:()=>{o.current&&(o.current.value=B,o.current.focus())},children:B},B))})]}),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($,{variant:"ghost",size:"sm",onClick:q,title:"Restore hidden items to this overview",children:[e.jsx(Je,{size:12})," Show ",F.size," hidden"]}),k.length>8&&e.jsx($,{variant:"ghost",size:"sm",onClick:()=>M(B=>!B),children:y?"Show less":"Show all"}),k.length>0&&e.jsxs($,{variant:"ghost",size:"sm",onClick:R,title:"Hide every item from the overview (full log kept)",children:[e.jsx(_s,{size:12})," Hide all"]})]})]}),F.size>0&&e.jsxs("div",{className:"activity-hidden-banner",role:"status",children:[e.jsxs("span",{children:[e.jsx(_s,{size:12,style:{verticalAlign:-2,marginRight:6}}),F.size," item",F.size===1?"":"s"," hidden from the overview."]}),e.jsxs($,{variant:"ghost",size:"sm",onClick:q,children:[e.jsx(Je,{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:ee("activity-feed-list-wrap",!y&&"activity-feed-list-wrap-collapsed"),children:[e.jsx("div",{className:"activity-feed-list",children:k.slice(0,30).map((B,Y)=>{const J=I(B,Y);return F.has(J)?null:e.jsx(On,{item:B,activityKey:J,onNavigate:a,onHide:H},`${B.ts}-${Y}`)})}),!y&&k.length>8&&e.jsx("div",{className:"activity-feed-fade","aria-hidden":"true"})]})]}),e.jsxs(ie,{className:"project-picker",children:[e.jsxs(re,{children:[e.jsx(Ie,{size:14})," Projects",e.jsxs($,{variant:"ghost",size:"sm",style:{marginLeft:"auto"},onClick:f,children:[e.jsx(Ne,{size:12})," Add"]}),e.jsxs($,{variant:"ghost",size:"sm",onClick:E,title:"Use the server's working directory",children:[e.jsx(Ne,{size:12})," Auto-detect"]}),((Q=t==null?void 0:t.dashboard)==null?void 0:Q.projectsDirectory)&&e.jsxs($,{variant:"ghost",size:"sm",title:`Scan ${t.dashboard.projectsDirectory} for projects`,onClick:async()=>{try{const B=await z.post("/projects/scan");B.error?n.error(B.error):n.success(`Added ${B.added.length}, skipped ${B.skipped}.`),await i();const Y=await z.get("/projects");d(Y.projects||[]),b(Y.active||null)}catch(B){n.error(`Scan failed: ${B.message}`)}},children:[e.jsx(Ea,{size:12})," Scan"]}),e.jsx($,{variant:"ghost",size:"sm",onClick:_,title:"Refresh",children:e.jsx(he,{size:12})})]}),e.jsxs(ce,{children:[m.length," project",m.length===1?"":"s"," ·"," ",c.counts.agents," agents ·"," ",c.counts.sessions," session",c.counts.sessions===1?"":"s"]}),m.length===0?e.jsx(ze,{icon:e.jsx(Ie,{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($,{variant:"primary",onClick:E,children:[e.jsx(Ne,{size:14})," Use current directory"]}),e.jsx($,{variant:"secondary",onClick:f,children:"Add by path…"})]})}):e.jsx("div",{className:"project-grid",children:m.map(B=>e.jsx($n,{project:B,active:x===B.id,onOpen:()=>G(B.id),onRemove:()=>D(B.id)},B.id))})]}),e.jsxs("div",{className:"overview-cols",children:[e.jsxs(ie,{children:[e.jsx(re,{children:"Mods"}),e.jsxs(ce,{children:["Extensions installed under ",e.jsx("code",{children:"~/.config/bizar/mods/"})]}),g.length===0?e.jsx("div",{className:"muted",children:"No mods installed."}):e.jsx("ul",{className:"mod-mini-list",children:g.map(B=>e.jsxs("li",{className:"mod-mini",children:[e.jsx("span",{className:"mod-mini-name",children:B.name}),e.jsxs("span",{className:"mod-mini-meta",children:["v",B.version," · ",B.type]}),e.jsx("span",{className:`mod-mini-pill ${B.enabled?"mod-mini-pill-on":"mod-mini-pill-off"}`,children:B.enabled?"on":"off"})]},B.id))})]}),e.jsxs(ie,{children:[e.jsx(re,{children:"Environment"}),e.jsx(ce,{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:yt(c.generatedAt)})]})]})]})]})}function Mn({settings:s,onAdd:t}){var m,d;const[a,i]=r.useState(((m=s==null?void 0:s.dashboard)==null?void 0:m.projectsDirectory)??""),[n,l]=r.useState(""),[o,c]=r.useState(!1),[p,u]=r.useState(null),j=async()=>{var x;if(a){c(!0),u(null);try{await z.get("/fs?path="+encodeURIComponent(a)),t(a,n||null)}catch(b){const g=b;g.status===404?u("That folder no longer exists. Pick another."):u(((x=g.data)==null?void 0:x.message)??b.message??"Validation failed.")}finally{c(!1)}}};return e.jsxs("div",{children:[e.jsx("label",{className:"field-label",children:"Folder"}),e.jsx(Et,{value:a,onChange:x=>{i(x),u(null)},projectsDirectory:(d=s==null?void 0:s.dashboard)==null?void 0:d.projectsDirectory,height:320}),p&&e.jsx("p",{className:"field-help",style:{color:"var(--error)",marginTop:4},children:p}),e.jsxs("div",{style:{marginTop:"var(--space-3)"},children:[e.jsx("label",{className:"field-label",htmlFor:"add-project-name",children:"Name (optional)"}),e.jsx("input",{id:"add-project-name",className:"input",type:"text",placeholder:"My App",value:n,onChange:x=>l(x.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($,{variant:"primary",onClick:j,disabled:!a||o,children:[o?e.jsx("span",{className:"btn-spinner"}):null,o?"Checking…":"Add"]})})]})}function $n({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(Te,{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 ",ye(s.lastAccessed)]})}),e.jsx("div",{className:"project-card-actions",children:e.jsx($,{variant:t?"ghost":"primary",size:"sm",onClick:a,children:t?e.jsxs(e.Fragment,{children:[e.jsx(bt,{size:12})," Active"]}):e.jsx(e.Fragment,{children:"Open"})})})]})}function An(s){return s&&s.charAt(0).toUpperCase()+s.slice(1)}function Rn(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]||An(a.replace(/-/g," ")),c=l[i]||i.replace(/-/g," ");return`${o} ${c}`.trim()}function us(s,t){for(const a of t){const i=s[a];if(typeof i=="string"&&i.trim())return i.trim()}return""}function In(s){const t=us(s,["message","text","prompt","title","name"]);if(t)return t;const a=[],i=us(s,["slug"]),n=us(s,["agent","author"]),l=us(s,["status"]);return i&&a.push(`Plan ${i}`),n&&a.push(n),l&&a.push(l),a.length?a.join(" · "):"No additional details."}function Ln(s){return ye(s)}function En(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 Dn(s){const t=s.toLowerCase();return t==="task"?as:t==="agent"?De:t==="plan"?Ns:t.includes("bg")||t.includes("background")||t.includes("job")?tn:t==="mod"?ws:t==="skill"?Oe:t.includes("error")||t.includes("failure")?Ua:t.includes("warn")?we:Re}function Pn(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 On({item:s,activityKey:t,onNavigate:a,onHide:i}){const n=En(s),l=Dn(s.kind||""),o=Rn(s.kind||"activity"),c=In(s),p=Pn(s.kind||""),u=n==="error"?"var(--error)":n==="warning"?"var(--warning)":n==="success"?"var(--success)":"var(--accent)";return e.jsxs("div",{className:ee("activity-feed-row",`activity-feed-row-${n}`),children:[e.jsxs("button",{type:"button",className:"activity-feed-row-main",onClick:()=>{p&&a(p)},title:p?`Open ${p}`:o,children:[e.jsx("div",{className:"activity-feed-icon",style:{color:u},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:Ln(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(Ee,{size:12})})]})}function Fn({session:s,mode:t,anchor:a,renameDraft:i,setRenameDraft:n,onEdit:l,onDeleteRequest:o,onConfirmDelete:c,onConfirmRename:p,onClose:u}){const j=r.useRef(null),m=Math.round(a.rect.bottom+2),d=Math.max(8,Math.round(window.innerWidth-a.rect.right));r.useEffect(()=>{const b=T=>{const v=T.target;!j.current||!v||j.current.contains(v)||u()},g=T=>{T.key==="Escape"&&u()},w=window.setTimeout(()=>{document.addEventListener("mousedown",b),document.addEventListener("keydown",g)},0);return()=>{window.clearTimeout(w),document.removeEventListener("mousedown",b),document.removeEventListener("keydown",g)}},[u]),r.useEffect(()=>{if(t!=="rename")return;const b=window.setTimeout(()=>{var w;const g=(w=j.current)==null?void 0:w.querySelector("input.session-row-menu-input");g==null||g.focus(),g==null||g.select()},0);return()=>window.clearTimeout(b)},[t]);const x=e.jsxs("div",{ref:j,className:"session-row-menu",role:"menu","aria-label":`Options for ${s.title}`,style:{position:"fixed",top:m,right:d},onClick:b=>b.stopPropagation(),children:[t==="main"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",className:"session-row-menu-item",role:"menuitem",onClick:b=>{b.stopPropagation(),l()},children:[e.jsx(Ja,{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:b=>{b.stopPropagation(),o()},children:[e.jsx(Te,{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:b=>n(b.target.value),onKeyDown:b=>{b.key==="Enter"?(b.preventDefault(),p()):b.key==="Escape"&&(b.preventDefault(),u())},onClick:b=>b.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:b=>{b.stopPropagation(),u()},children:"Cancel"}),e.jsx("button",{type:"button",className:"btn btn-primary",onClick:b=>{b.stopPropagation(),p()},children:"Save"})]})]}),t==="confirm-delete"&&e.jsxs("div",{className:"session-row-menu-inline",children:[e.jsx("div",{className:"session-row-menu-inline-label chat-mono",children:"Delete this session?"}),e.jsxs("div",{className:"session-row-menu-inline-message",children:['"',s.title,'" and its sub-agents will be removed.']}),e.jsxs("div",{className:"session-row-menu-inline-actions",children:[e.jsx("button",{type:"button",className:"btn btn-ghost",onClick:b=>{b.stopPropagation(),u()},children:"Cancel"}),e.jsx("button",{type:"button",className:"btn btn-danger",onClick:b=>{b.stopPropagation(),c()},children:"Delete"})]})]})]});return Xt.createPortal(x,document.body)}function Vs({node:s,depth:t=0,collapsible:a=!1,isLast:i=!0,open:n,onToggle:l}){var x;const[o,c]=r.useState(a),p=n!==void 0,u=p?n:o,j=b=>{p||c(b),l==null||l(b)},m=(((x=s.children)==null?void 0:x.length)??0)>0,d=e.jsxs(e.Fragment,{children:[a&&e.jsx("span",{className:`agent-node-chevron ${u?"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}`,u?"open":"closed",i?"last":""].filter(Boolean).join(" "),children:[a?e.jsx("button",{type:"button",className:`agent-node-head status-${s.status} collapsible`,onClick:b=>{b.stopPropagation(),j(!u)},"aria-expanded":u,children:d}):e.jsx("div",{className:`agent-node-head status-${s.status}`,children:d}),u&&e.jsxs(e.Fragment,{children:[s.summary&&e.jsx("div",{className:"agent-node-summary",children:s.summary}),m&&e.jsx("div",{className:"agent-node-children",children:s.children.map((b,g)=>e.jsx(Vs,{node:b,depth:t+1,collapsible:!1,isLast:g===s.children.length-1},b.id))})]})]})}function Bn(s){return s.tree!==void 0}function Un(s){const t=s.open??!0;if(Bn(s))return e.jsx("div",{className:`agent-tree variant-${s.variant??"full"}`,children:e.jsx(Vs,{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(Vs,{node:i,depth:0,collapsible:!1,open:t,isLast:n===a.length-1})},i.id))})})}function qn({children:s,variant:t="rail",open:a=!0}){return a?e.jsx(Un,{variant:t,open:a,children:s}):null}const _n=["Today","Yesterday","This week","Earlier"];function ct(s,t){return s.getFullYear()===t.getFullYear()&&s.getMonth()===t.getMonth()&&s.getDate()===t.getDate()}function Hn(s,t){const a=s.getTime()-t.getTime();return Math.floor(a/(1e3*60*60*24))}function Wn(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());ct(o,t)?n.Today.push(l):ct(o,a)?n.Yesterday.push(l):Hn(t,o)<7?n["This week"].push(l):n.Earlier.push(l)}return n}function Vn(s){return new Date(Number(s)||Date.now()).toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit",hour12:!1})}function Kn({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 Gn({sessions:s,opencodeSessions:t=[],activeSessionId:a,activeOpencodeSessionId:i,activeProject:n,creating:l,onCreateSession:o,onSelectSession:c,onSelectOpencodeSession:p,onRenameSession:u,onDeleteSession:j,groupBy:m}){var D;const d=r.useMemo(()=>[...s,...t],[s,t]),x=r.useMemo(()=>[...d].sort((V,se)=>Number(se.mtime??0)-Number(V.mtime??0)),[d]),b=r.useMemo(()=>m?m(x):Wn(x),[m,x]),[g,w]=r.useState({}),T=V=>g[V]===!0,[v,k]=r.useState(null),[L,y]=r.useState("main"),[M,F]=r.useState(""),[S,I]=r.useState(null),H=r.useRef({}),R=(V,se="main")=>{const Q=H.current[V];if(!Q)return;const B=se==="main"?Q:Q.querySelector(".chat-rail-item-menu-trigger")??Q;if(I({id:V,rect:B.getBoundingClientRect()}),k(V),y(se),se==="rename"){const Y=[...s,...t].find(J=>J.id===V);F((Y==null?void 0:Y.title)??(Y==null?void 0:Y.id)??"")}},q=()=>{k(null),y("main"),F(""),I(null)},_=V=>{if(V.source==="opencode"){p(V);return}c(V.id)},f=()=>{if(!S)return;const V=S.id,se=M.trim();if(!se){q();return}u==null||u(V,se),q()},E=()=>{S&&(j==null||j(S.id),q())},G=m?Object.entries(b):_n.filter(V=>{var se;return(se=b[V])==null?void 0:se.length}).map(V=>[V,b[V]]);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(Ne,{size:14,"aria-hidden":!0}),e.jsx("span",{children:l?"Creating…":"New session"})]})}),x.length===0?e.jsx("div",{className:"chat-sessions-empty",children:e.jsx(Qt,{icon:e.jsx(Ne,{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:G.map(([V,se])=>e.jsxs("div",{className:"chat-rail-group",children:[e.jsx("div",{className:"chat-rail-group-label",children:V}),se.map(Q=>{var ue,W;const B=Q.source==="opencode",Y=B?i===Q.id:a===Q.id,J=Q.tree,X=!!((ue=J==null?void 0:J.root)!=null&&ue.children&&J.root.children.length>0),ae=T(Q.id);return e.jsxs(r.Fragment,{children:[e.jsxs("div",{ref:C=>{H.current[Q.id]=C},role:"button",tabIndex:0,className:`chat-rail-item state-${Q.state??"idle"}${Y?" active":""}`,onClick:()=>_(Q),onKeyDown:C=>{(C.key==="Enter"||C.key===" ")&&(C.preventDefault(),_(Q))},"aria-current":Y?"true":void 0,children:[e.jsx(Kn,{state:Q.state??"idle",agent:Q.agent}),e.jsxs("div",{className:"chat-rail-item-title",children:[Q.pinned&&e.jsx("span",{className:"chat-rail-pin","aria-hidden":!0,children:"★"}),B&&e.jsx(Ms,{size:11,style:{color:"var(--text-muted)",flexShrink:0},"aria-hidden":!0}),e.jsx("span",{className:"chat-ellipsis",children:Q.title||Q.id})]}),e.jsxs("div",{className:"chat-rail-item-meta",children:[e.jsx("span",{className:"chat-rail-item-meta-time",children:Q.time??Vn(Q.mtime)}),(Q.unread??0)>0&&e.jsx("span",{className:"chat-rail-badge",children:Q.unread})]}),e.jsx("button",{type:"button",className:`chat-rail-item-menu-trigger${v===Q.id?" open":""}`,"aria-label":`Session options for ${Q.title||Q.id}`,"aria-haspopup":"menu","aria-expanded":v===Q.id,onClick:C=>{C.stopPropagation(),v===Q.id?q():R(Q.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&&X&&e.jsx("button",{type:"button",className:`chat-rail-tree-chevron${ae?" open":""}`,"aria-label":ae?"Collapse sub-agents":"Expand sub-agents","aria-expanded":ae,onClick:C=>{C.stopPropagation(),w(P=>({...P,[Q.id]:!P[Q.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&&X&&ae&&((W=J==null?void 0:J.root)==null?void 0:W.children)&&e.jsx(qn,{children:J.root.children,variant:"rail",open:!0})]},B?`oc-${Q.id}`:Q.id)})]},V))}),v&&S&&e.jsx(Fn,{session:{id:S.id,title:((D=[...s,...t].find(V=>V.id===S.id))==null?void 0:D.title)??S.id},mode:L,anchor:S,renameDraft:M,setRenameDraft:F,onEdit:()=>R(v,"rename"),onDeleteRequest:()=>R(v,"confirm-delete"),onConfirmDelete:E,onConfirmRename:f,onClose:q})]})}function Yn(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(Jt,{...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 Ps(s){return s.toLocaleString()}function Xn(s){return!s||!s.includes("/")?"":s.split("/")[0]}function Qn(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 Jn({sessionId:s,messages:t,pinned:a,agent:i,model:n,agents:l,mcps:o,allCommands:c,activeSource:p="bizar",onRename:u,onDelete:j,onExport:m,busy:d}){const[x,b]=r.useState(null);r.useEffect(()=>{let I=!1;return(async()=>{try{const H=await fetch("/api/usage?range=24h",{headers:{Accept:"application/json"}});if(!H.ok)return;const R=await H.json();I||b(R)}catch{}})(),()=>{I=!0}},[s]);const g=(t==null?void 0:t.length)??0,w=(a==null?void 0:a.size)??0,T=t.reduce((I,H)=>I+(H.content||H.message||"").length,0),v=Math.round(T/4),k=Qn(n),L=v/1e6*k,y=(x==null?void 0:x.totalTokens)??v,M=(x==null?void 0:x.costUsd)??L,F=128e3,S=Xn(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(zs,{size:11,style:{marginRight:4,verticalAlign:-1},"aria-hidden":!0})," ","Session"]}),e.jsx("span",{className:`chat-source-badge chat-source-${p??"none"}`,style:{marginLeft:"auto"},children:p==="opencode"?"opencode":"bizar chat"})]}),e.jsx("div",{className:"chat-info-mono chat-ellipsis",title:s,children:s||"Live"}),e.jsxs("div",{className:"chat-info-mono",children:[Ps(g)," message",g===1?"":"s",w>0&&` · ${w} pinned`]})]}),e.jsxs("div",{className:"chat-info-section",children:[e.jsxs("h4",{children:[e.jsx(De,{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(ss,{size:11,style:{marginRight:4,verticalAlign:-1},"aria-hidden":!0})," ","Model"]}),e.jsx("div",{className:"chat-mono chat-ellipsis",title:n,children:n||"—"}),S&&e.jsxs("div",{className:"chat-info-mono",children:["provider · ",S]})]}),e.jsxs("div",{className:"chat-info-section",children:[e.jsx("h4",{children:"Tokens"}),e.jsxs("div",{className:"chat-mono",children:[Ps(y)," / ",Ps(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,y/Math.max(1,F)*100)}%`}})})]}),e.jsxs("div",{className:"chat-info-section",children:[e.jsxs("h4",{children:[e.jsx(wa,{size:11,style:{marginRight:4,verticalAlign:-1},"aria-hidden":!0})," ","Cost"]}),e.jsxs("div",{className:"chat-mono",children:["$",M.toFixed(4)]}),!x&&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(De,{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(I=>e.jsx("span",{className:"chat-info-agent",children:I.name},I.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(ss,{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(I=>e.jsx("span",{className:"chat-info-agent",children:I.id},I.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(is,{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"]})]}),(u||j||m)&&e.jsxs("div",{className:"chat-info-section",children:[e.jsx("h4",{children:"Actions"}),e.jsxs("div",{className:"chat-info-actions",children:[u&&e.jsxs("button",{type:"button",className:"btn btn-ghost btn-sm",onClick:u,disabled:d==null?void 0:d.rename,title:"Rename session",children:[e.jsx($s,{size:12,"aria-hidden":!0})," Rename"]}),m&&e.jsxs("button",{type:"button",className:"btn btn-ghost btn-sm",onClick:m,title:"Export transcript",children:[e.jsx(Qe,{size:12,"aria-hidden":!0})," Export"]}),j&&e.jsxs("button",{type:"button",className:"btn btn-ghost btn-sm btn-danger",onClick:j,disabled:d==null?void 0:d.delete,title:"Delete session",children:[e.jsx(Te,{size:12,"aria-hidden":!0})," Delete"]})]})]})]})}function Zn({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(ya,{size:14,"aria-hidden":!0}),e.jsx("span",{children:"Jump to latest"}),t>0&&e.jsxs("span",{className:"jump-badge",children:[t," new"]})]})})}function ei({snapshot:s,settings:t,setActiveTab:a,initialTaskId:i,onClearTaskId:n}){const l=de(),o=$e(),c=Zt(s,t,i??"");r.useEffect(()=>{c.setToast({error:D=>l.error(D),success:D=>l.success(D),info:D=>l.info(D),warning:D=>l.warning(D)})},[c,l]);const[p,u]=r.useState(""),[j,m]=r.useState(t.defaultAgent||"odin"),[d,x]=r.useState(t.defaultModel||""),[b,g]=r.useState([]),w=r.useRef(null),{allCommands:T,suggestions:v,setQuery:k}=ea(s);r.useEffect(()=>{k(p)},[p,k]);const L=()=>{var D;return(D=w.current)==null?void 0:D.click()},y=D=>{const V=D.target.files;if(!V)return;const se=[];for(let Q=0;Q<V.length;Q++)se.push(V[Q].name);g(Q=>{const B=se.filter(Y=>!Q.includes(Y));return[...Q,...B]}),w.current&&(w.current.value="")},M=async()=>{const D=p.trim();if(!D)return;u(""),k(""),(await c.onSend(D,j,d,b)).ok&&c.jumpToLatest()},F=async()=>{c.busy.create||await c.onCreateSession()},S=D=>{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($,{variant:"secondary",size:"sm",onClick:()=>o.close(),children:"Cancel"}),e.jsx($,{variant:"danger",size:"sm",onClick:()=>{o.close(),c.deleteMessage(D)},children:"Delete"})]})})},I=(D,V)=>{let se="";o.open({title:"Rename session",children:e.jsx("input",{autoFocus:!0,defaultValue:V,onChange:Q=>{se=Q.target.value},onKeyDown:Q=>{Q.key==="Enter"&&(Q.preventDefault(),o.close(),c.renameSession(D,se).then(B=>{B&&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($,{variant:"secondary",size:"sm",onClick:()=>o.close(),children:"Cancel"}),e.jsx($,{variant:"primary",size:"sm",onClick:()=>{o.close(),c.renameSession(D,se)},children:"Save"})]})})},H=(D,V)=>{o.open({title:"Delete session?",children:e.jsxs("p",{style:{margin:0},children:["Delete ",e.jsx("strong",{children:V}),"? 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($,{variant:"secondary",size:"sm",onClick:()=>o.close(),children:"Cancel"}),e.jsx($,{variant:"danger",size:"sm",onClick:async()=>{o.close(),await c.deleteSession(D)},children:"Delete"})]})})},R=()=>{const D=c.activeSource==="opencode"?c.activeOpencodeSessionId:c.sessionId;if(!D)return;const se=(c.activeSource==="opencode"?c.opencodeMessages:c.bizarMessages).map(J=>{const X=J.ts??"",ae=(J.role||"unknown").toUpperCase(),ue=J.content||J.message||"";return`[${X}] ${ae}: ${ue}`}).join(`
|
|
302
|
+
|
|
303
|
+
`),Q=new Blob([se],{type:"text/plain;charset=utf-8"}),B=URL.createObjectURL(Q),Y=document.createElement("a");Y.href=B,Y.download=`${D}.txt`,document.body.appendChild(Y),Y.click(),document.body.removeChild(Y),URL.revokeObjectURL(B)},q=r.useMemo(()=>c.sessions.map(D=>c.getSessionDisplay(D)),[c.sessions,c.getSessionDisplay]),_=r.useMemo(()=>c.opencodeSessions.map(D=>c.getSessionDisplay(D)),[c.opencodeSessions,c.getSessionDisplay]),f=r.useMemo(()=>{const D=c.activeSource==="opencode"?c.activeOpencodeSessionId??"":c.sessionId;return D?q.find(V=>V.id===D)??_.find(V=>V.id===D)??null:null},[c.activeSource,c.activeOpencodeSessionId,c.sessionId,q,_]),E=(()=>{var se;const D=`${j||"Odin"} · ${((se=s.activeProject)==null?void 0:se.name)??"no project"}`,V=(f==null?void 0:f.state)??"idle";return V==="streaming"?`Replying · ${D}`:V==="awaiting"?`Your turn · ${D}`:`${D} · idle`})(),G=c.activeSource==="opencode"?"opencode":"bizar chat";return e.jsxs("div",{className:"chat-shell",children:[e.jsx(sa,{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(Gn,{sessions:q,opencodeSessions:_,activeSessionId:c.sessionId,activeOpencodeSessionId:c.activeOpencodeSessionId,activeProject:s.activeProject,creating:c.busy.create,onCreateSession:F,onSelectSession:c.selectBizarSession,onSelectOpencodeSession:D=>c.loadOpencodeSession(D.id),onRenameSession:I,onDeleteSession:D=>{const V=c.sessions.find(se=>se.id===D)??c.opencodeSessions.find(se=>se.id===D);H(D,(V==null?void 0:V.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:(f==null?void 0:f.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:G})]}),e.jsxs("div",{className:`chat-thread-sub chat-muted state-${(f==null?void 0:f.state)??"idle"}`,children:[e.jsx("span",{className:"chat-thread-dot"}),E]}),c.opencodeError&&e.jsx("div",{className:"chat-thread-error",role:"alert",children:c.opencodeError})]}),e.jsxs("div",{className:"chat-thread-actions",children:[f&&e.jsxs("button",{className:"btn btn-ghost",title:"Rename session",type:"button",disabled:c.busy.rename,onClick:()=>I(f.id,f.title??""),children:[e.jsx($s,{size:12,"aria-hidden":!0})," ",e.jsx("span",{className:"mono",children:"rename"})]}),f&&e.jsxs("button",{className:"btn btn-ghost btn-danger",title:"Delete session",type:"button",disabled:c.busy.delete,onClick:()=>H(f.id,f.title??f.id),children:[e.jsx(Te,{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:R,children:e.jsx("span",{className:"mono",children:"export"})})]})]}),e.jsx("div",{className:"chat-thread-scroll",ref:c.listRef,onScroll:c.handleScroll,children:e.jsx(ta,{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:D=>u(D),onCopy:D=>c.copyMessage(D),onDelete:S,onTogglePin:c.togglePin,onRegenerate:c.onRegenerate})}),!c.stickToBottom&&e.jsx(Zn,{streaming:(f==null?void 0:f.state)==="streaming",newMessageCount:c.newMessageCount,onClick:c.jumpToLatest}),e.jsx(Yn,{agent:j,setAgent:m,model:d,setModel:x,text:p,setText:u,sending:c.sending,activeSource:c.activeSource,onSend:M,attachments:b,setAttachments:g,suggestions:v,onPickSuggestion:D=>u(`${D.split(" ")[0]} `),agents:s.agents||[],onAttach:L}),e.jsx("input",{ref:w,type:"file",multiple:!0,style:{display:"none"},onChange:y})]}),e.jsx(Jn,{sessionId:c.activeSource==="opencode"?c.activeOpencodeSessionId??c.sessionId:c.sessionId,messages:c.activeSource==="opencode"?c.opencodeMessages:c.bizarMessages,pinned:c.pinned,agent:j,model:d,agents:s.agents||[],mcps:s.mcps||[],allCommands:T,activeSource:c.activeSource,onRename:()=>{f&&I(f.id,f.title??"")},onDelete:()=>{f&&H(f.id,f.title??f.id)},onExport:R,busy:c.busy})]})]})}function Ye({kind:s="neutral",children:t,className:a,dot:i=!1}){return e.jsxs("span",{className:ee("badge",`badge-${s}`,a),children:[i&&e.jsx("span",{className:"badge-dot"}),t]})}const dt=["bash","read","edit","write","webfetch","websearch","task","glob","grep"],ht=["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"],js=[{id:"reasoning",label:"Reasoning",color:"var(--accent)"},{id:"code",label:"Code",color:"var(--info)"},{id:"design",label:"Design",color:"var(--success)"},{id:"planning",label:"Planning",color:"var(--warning)"},{id:"gitops",label:"GitOps",color:"var(--error)"},{id:"analysis",label:"Analysis",color:"var(--text-dim)"}];function si(s){var t;return((t=js.find(a=>a.id===s))==null?void 0:t.color)||"var(--text-dim)"}function ti({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 ai({agent:s}){if(s.isStuck)return e.jsx(Ye,{kind:"error",dot:!0,children:"stuck"});const t=s.status||"idle";return t==="working"?e.jsx(Ye,{kind:"info",dot:!0,children:"working"}):t==="error"?e.jsx(Ye,{kind:"error",dot:!0,children:"error"}):e.jsx(Ye,{kind:"neutral",dot:!0,children:"idle"})}function ni({snapshot:s,refreshSnapshot:t}){const a=de(),i=$e(),[n,l]=r.useState(s.agents||[]),[o,c]=r.useState(!s.agents),[p,u]=r.useState(""),[j,m]=r.useState("");r.useEffect(()=>{l(s.agents||[]),c(!s.agents)},[s.agents]);const d=async()=>{try{const y=await z.get("/agents");l(y.agents||[])}catch(y){a.error(`Agents load failed: ${y.message}`)}finally{c(!1)}},x=r.useMemo(()=>{let y=[...n];if(p&&(y=y.filter(M=>p==="__none__"?!M.category:(M.category||"")===p)),j){const M=j.toLowerCase();y=y.filter(F=>F.name.toLowerCase().includes(M)||(F.description||"").toLowerCase().includes(M)||(F.tags||[]).some(S=>S.toLowerCase().includes(M)))}return y.sort((M,F)=>M.name.localeCompare(F.name))},[n,p,j]),b=r.useMemo(()=>{const y=new Set;for(const M of n)for(const F of M.tags||[])y.add(F);return Array.from(y).sort()},[n]),g=()=>{let y=null,M=null,F=null,S=null,I=null,H=null,R=null,q=null,_=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:f=>y=f,className:"input",type:"text",placeholder:"my-agent",autoFocus:!0}),e.jsx("label",{className:"field-label",children:"Description"}),e.jsx("input",{ref:f=>{M=f},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:f=>F=f,className:"select",defaultValue:"",children:[e.jsx("option",{value:"",children:"(provider default)"}),ht.map(f=>e.jsx("option",{value:f,children:f},f))]})]}),e.jsxs("div",{className:"task-form-field",children:[e.jsx("label",{className:"field-label",children:"Mode"}),e.jsxs("select",{ref:f=>S=f,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:f=>I=f,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:f=>_=f,className:"select",defaultValue:"",children:[e.jsx("option",{value:"",children:"(none)"}),js.map(f=>e.jsx("option",{value:f.id,children:f.label},f.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:f=>q=f,className:"input",type:"text",placeholder:"reasoning, code, planning"})]})]}),e.jsx("label",{className:"field-label",children:"Tools"}),e.jsx("div",{ref:f=>R=f,className:"agent-tools",children:dt.map(f=>e.jsxs("label",{className:"checkbox-row",children:[e.jsx("input",{type:"checkbox",value:f}),e.jsx("span",{children:f})]},f))}),e.jsx("label",{className:"field-label",children:"System prompt"}),e.jsx("textarea",{ref:f=>H=f,className:"textarea",rows:6,placeholder:"You are a..."})]}),footer:e.jsxs("div",{className:"modal-footer-actions",children:[e.jsx($,{variant:"ghost",onClick:()=>i.close(),children:"Cancel"}),e.jsxs($,{variant:"primary",onClick:async()=>{const f=((y==null?void 0:y.value)||"").trim();if(!/^[a-z0-9][a-z0-9-]{0,63}$/i.test(f)){a.warning("Invalid name (a-z, 0-9, dashes).");return}const E=[];R&&R.querySelectorAll('input[type="checkbox"]:checked').forEach(D=>{E.push(D.value)});const G=((q==null?void 0:q.value)||"").split(",").map(D=>D.trim()).filter(Boolean);try{const D=await z.post("/agents",{name:f,description:((M==null?void 0:M.value)||"").trim(),model:(F==null?void 0:F.value)||"",mode:(S==null?void 0:S.value)||"subagent",color:(I==null?void 0:I.value)||"",tools:E,tags:G,category:(_==null?void 0:_.value)||"",prompt:(H==null?void 0:H.value)||""});l(V=>[...V,D]),a.success("Agent created."),i.close(),await t()}catch(D){a.error(`Create failed: ${D.message}`)}},children:[e.jsx(bs,{size:12})," Create"]})]})})},w=async y=>{let M=null,F=null,S=null,I=null,H=null,R=null,q=null,_=null;try{const f=await z.get(`/agents/${encodeURIComponent(y.name)}`);i.open({title:`Edit ${y.name}`,width:640,children:e.jsxs("div",{className:"agent-form",children:[e.jsxs("div",{className:"muted",children:["File: ",e.jsx("code",{children:f.path})]}),e.jsx("label",{className:"field-label",children:"Description"}),e.jsx("input",{ref:E=>{M=E},className:"input",type:"text",defaultValue:f.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:E=>F=E,className:"select",defaultValue:f.model,children:[e.jsx("option",{value:"",children:"(provider default)"}),ht.map(E=>e.jsx("option",{value:E,children:E},E))]})]}),e.jsxs("div",{className:"task-form-field",children:[e.jsx("label",{className:"field-label",children:"Mode"}),e.jsxs("select",{ref:E=>S=E,className:"select",defaultValue:f.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:E=>I=E,className:"input",type:"color",defaultValue:f.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:E=>_=E,className:"select",defaultValue:f.category||"",children:[e.jsx("option",{value:"",children:"(none)"}),js.map(E=>e.jsx("option",{value:E.id,children:E.label},E.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:E=>q=E,className:"input",type:"text",defaultValue:(f.tags||[]).join(", ")})]})]}),e.jsx("label",{className:"field-label",children:"Tools"}),e.jsx("div",{ref:E=>R=E,className:"agent-tools",children:dt.map(E=>{var G;return e.jsxs("label",{className:"checkbox-row",children:[e.jsx("input",{type:"checkbox",value:E,defaultChecked:(G=f.tools)==null?void 0:G.includes(E)}),e.jsx("span",{children:E})]},E)})}),e.jsx("label",{className:"field-label",children:"System prompt"}),e.jsx("textarea",{ref:E=>H=E,className:"textarea",rows:8,defaultValue:f.prompt||""})]}),footer:e.jsxs("div",{className:"modal-footer-actions",children:[e.jsx($,{variant:"ghost",onClick:()=>i.close(),children:"Cancel"}),e.jsxs($,{variant:"primary",onClick:async()=>{const E=[];R&&R.querySelectorAll('input[type="checkbox"]:checked').forEach(D=>{E.push(D.value)});const G=((q==null?void 0:q.value)||"").split(",").map(D=>D.trim()).filter(Boolean);try{const D=await z.put(`/agents/${encodeURIComponent(y.name)}`,{description:((M==null?void 0:M.value)||"").trim(),model:(F==null?void 0:F.value)||"",mode:(S==null?void 0:S.value)||"subagent",color:(I==null?void 0:I.value)||"",tools:E,tags:G,category:(_==null?void 0:_.value)||"",prompt:(H==null?void 0:H.value)||""});l(V=>V.map(se=>se.name===y.name?D:se)),a.success("Agent saved."),i.close(),await t()}catch(D){a.error(`Save failed: ${D.message}`)}},children:[e.jsx(bs,{size:12})," Save"]})]})})}catch(f){a.error(`Load failed: ${f.message}`)}},T=async y=>{if(confirm(`Delete agent "${y.name}"? This removes ${y.path}.`))try{await z.del(`/agents/${encodeURIComponent(y.name)}`),l(M=>M.filter(F=>F.name!==y.name)),a.success("Agent deleted.")}catch(M){a.error(`Delete failed: ${M.message}`)}},v=async y=>{let M=null;i.open({title:`Invoke ${y.name}`,children:e.jsxs("div",{className:"invoke-form",children:[e.jsxs("p",{className:"muted invoke-form-meta mono",children:[y.model||"—"," · ",y.path]}),e.jsx("p",{className:"invoke-form-desc",children:y.description}),e.jsx("label",{className:"field-label",htmlFor:"invoke-prompt",children:"Prompt"}),e.jsx("textarea",{ref:F=>M=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($,{variant:"ghost",onClick:()=>i.close(),children:"Cancel"}),e.jsxs($,{variant:"primary",onClick:async()=>{const F=((M==null?void 0:M.value)||"").trim();if(!F){a.warning("Prompt is required.");return}try{await z.post(`/agents/${encodeURIComponent(y.name)}/invoke`,{prompt:F}),a.success(`Invoked ${y.name}.`),i.close()}catch(S){a.error(`Invoke failed: ${S.message}`)}},children:[e.jsx(Ys,{size:14})," Invoke"]})]})})},k=async y=>{try{const M=await z.post(`/agents/${encodeURIComponent(y.name)}/restart`);l(F=>F.map(S=>S.name===y.name?M:S)),a.success(`${y.name} restarted.`)}catch(M){a.error(`Restart failed: ${M.message}`)}},L=async(y,M)=>{try{const F=await z.post(`/agents/${encodeURIComponent(y.name)}/status`,{status:M});l(S=>S.map(I=>I.name===y.name?F:I))}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(De,{size:18})," Agents (",x.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:j,onChange:y=>m(y.target.value)})}),e.jsxs("select",{className:"select select-sm",value:p,onChange:y=>u(y.target.value),children:[e.jsx("option",{value:"",children:"All categories"}),js.map(y=>e.jsx("option",{value:y.id,children:y.label},y.id)),e.jsx("option",{value:"__none__",children:"(no category)"})]}),e.jsxs($,{variant:"secondary",size:"sm",onClick:d,children:[e.jsx(he,{size:14})," Refresh"]}),e.jsxs($,{variant:"primary",size:"sm",onClick:g,children:[e.jsx(Ne,{size:14})," New agent"]})]})]}),b.length>0&&e.jsxs("div",{className:"agent-tags-row",children:[e.jsx(It,{size:12}),b.map(y=>e.jsx("span",{className:"tag",children:y},y))]}),o?e.jsx("div",{className:"view-loading",children:e.jsx(fe,{size:"lg"})}):x.length===0?e.jsx(ze,{icon:e.jsx(De,{size:32}),title:"No agents found",message:"Run bizar in the terminal to install Bizar."}):e.jsx("div",{className:"agent-grid",children:x.map(y=>e.jsx(ii,{agent:y,onInvoke:()=>v(y),onEdit:()=>w(y),onDelete:()=>T(y),onRestart:()=>k(y),onSetStatus:M=>L(y,M)},y.name))})]})}function ii({agent:s,onInvoke:t,onEdit:a,onDelete:i,onRestart:n,onSetStatus:l}){const[o,c]=r.useState(!1),p=si(s.category),u=(s.status==="working"||!!s.currentTaskId)&&!s.isStuck;return e.jsxs(ie,{variant:"elevated",interactive:!0,className:ee("agent-card",u&&"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(ti,{status:s.status,isStuck:s.isStuck}),s.name]}),e.jsxs("div",{className:"agent-card-badges",children:[s.category&&e.jsx("span",{className:"agent-card-category",style:{background:`color-mix(in srgb, ${p} 18%, transparent)`,color:p},children:s.category}),e.jsx(ai,{agent:s})]})]}),e.jsx("p",{className:"agent-card-desc",children:kt(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:ye(s.mtime)})]}),s.tags&&s.tags.length>0&&e.jsx("div",{className:"agent-card-tags",children:s.tags.map(j=>e.jsx("span",{className:"agent-card-tag",children:j},j))}),(u||s.lastTask)&&e.jsxs("div",{className:"agent-card-activity",children:[s.currentTaskId&&e.jsxs("div",{className:"agent-card-row",children:[e.jsx(Re,{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(Xe,{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:ye(s.lastTask.finishedAt)})]}),s.tasksTotal!=null&&s.tasksTotal>0&&e.jsxs("div",{className:"agent-card-row",children:[e.jsx(Ca,{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(we,{size:12}),e.jsxs("span",{className:"muted",children:["Last error: ",s.lastError.message]})]}),e.jsxs("div",{className:"agent-card-actions",children:[e.jsxs($,{variant:"primary",size:"sm",onClick:t,children:[e.jsx(Ys,{size:12})," Invoke"]}),e.jsxs($,{variant:"secondary",size:"sm",onClick:a,children:[e.jsx($s,{size:12})," Edit"]}),(s.isStuck||s.status==="working"||s.status==="error")&&e.jsxs($,{variant:"ghost",size:"sm",onClick:n,title:"Reset agent status",children:[e.jsx(Nt,{size:12})," Restart"]}),e.jsx($,{variant:"ghost",size:"sm",onClick:i,children:e.jsx(Te,{size:12})}),e.jsx("button",{type:"button",className:"icon-btn","aria-label":o?"Collapse":"Expand",onClick:()=>c(j=>!j),style:{marginLeft:"auto"},children:o?e.jsx(Le,{size:12}):e.jsx(_e,{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($,{variant:s.status==="idle"?"primary":"ghost",size:"sm",onClick:()=>l("idle"),children:"Idle"}),e.jsx($,{variant:s.status==="working"?"primary":"ghost",size:"sm",onClick:()=>l("working"),children:"Working"}),e.jsx($,{variant:s.status==="error"?"primary":"ghost",size:"sm",onClick:()=>l("error"),children:"Error"})]}),e.jsxs("div",{className:"agent-card-meta",children:[e.jsx(Ie,{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:ee("glyph-richtext"),style:Pt,children:e.jsx(wt,{remarkPlugins:[St],children:t})})}const li={info:{bg:"var(--info-soft, rgba(96, 165, 250, 0.12))",border:"var(--info)",fg:"var(--info)",icon:Ts,label:"Note"},warn:{bg:"var(--warning-soft, rgba(251, 191, 36, 0.15))",border:"var(--warning)",fg:"var(--warning)",icon:we,label:"Warning"},success:{bg:"var(--success-soft, rgba(52, 211, 153, 0.15))",border:"var(--success)",fg:"var(--success)",icon:Xe,label:"Success"},danger:{bg:"var(--error-soft, rgba(248, 113, 113, 0.12))",border:"var(--error)",fg:"var(--error)",icon:Rt,label:"Danger"}};function oi({id:s,tone:t="info",children:a}){const i=li[t],n=i.icon;return e.jsxs("div",{id:s,"data-block-id":s,className:ee("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:{...Pt,fontSize:14},children:e.jsx(wt,{remarkPlugins:[St],children:a})})]})]})}function ci({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(qs,{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 di({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 hi({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 mi({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 ui({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:mt,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:mt}),l.kind==="multi"&&e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4},children:(l.options??[]).map(o=>{const c=a[l.id]??[],p=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:p,onChange:()=>{const u=p?c.filter(j=>j!==o):[...c,o];n(l.id,u)}}),e.jsx("span",{children:o})]},o)})})]},l.id))]})}const mt={padding:"6px 10px",fontSize:13,borderRadius:6,border:"1px solid var(--border-strong)",background:"var(--bg)",color:"var(--text)",fontFamily:"inherit"},xi={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 pi({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=xi[i.change];return e.jsxs("li",{style:{display:"flex",alignItems:"center",gap:10,padding:"5px 8px",borderRadius:5,fontSize:13},children:[e.jsx("span",{"aria-label":i.change,title:i.change,style:{flexShrink:0,width:22,height:18,borderRadius:4,background:n.bg,color:n.fg,display:"inline-flex",alignItems:"center",justifyContent:"center",fontSize:10,fontWeight:700,fontFamily:"var(--font-mono)"},children:n.label}),e.jsx("span",{style:{fontFamily:"var(--font-mono)",color:"var(--text)",wordBreak:"break-all",flex:1},children:i.path}),i.note&&e.jsx("span",{style:{fontSize:12,color:"var(--text-dim)"},children:i.note})]},i.path)})})]})}function gi({id:s,filename:t,language:a,mode:i="unified",before:n,after:l}){const o=n.split(`
|
|
304
|
+
`),c=l.split(`
|
|
305
|
+
`),p=e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"6px 12px",background:"var(--bg)",borderBottom:"1px solid var(--border)",fontSize:12,color:"var(--text-dim)",fontFamily:"var(--font-mono)"},children:[e.jsx(Ma,{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})]}),u={margin:0,padding:0,fontFamily:"var(--font-mono)",fontSize:12.5,lineHeight:1.55,color:"var(--text)",background:"var(--bg-elev)"},j=(m,d,x)=>{const b={del:"var(--error-soft)",add:"var(--success-soft)",ctx:"transparent"},g={del:"var(--error)",add:"var(--success)",ctx:"var(--text-dim)"};return e.jsxs("div",{style:{display:"flex",padding:"0 12px",background:b[x]},children:[e.jsx("span",{style:{width:18,color:g[x],userSelect:"none",flexShrink:0},children:m}),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:[p,i==="unified"?e.jsxs("pre",{style:u,children:[o.map((m,d)=>e.jsx("div",{children:j("-",m,"del")},`b${d}`)),c.map((m,d)=>e.jsx("div",{children:j("+",m,"add")},`a${d}`))]}):e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr"},children:[e.jsx("pre",{style:{...u,borderRight:"1px solid var(--border)"},children:o.map((m,d)=>e.jsx("div",{children:j("-",m,"del")},d))}),e.jsx("pre",{style:u,children:c.map((m,d)=>e.jsx("div",{children:j("+",m,"add")},d))})]})]})}const ji={up:{fg:"var(--success)",Icon:Le,label:"trending up"},down:{fg:"var(--error)",Icon:Le,label:"trending down"},flat:{fg:"var(--text-dim)",Icon:Ba,label:"flat"}};function fi({id:s,label:t,value:a,trend:i,hint:n}){const l=i?ji[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===Le&&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 vi={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)"}},be=160,Ce=56,We=60,Ve=80;function yi({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(bi,{id:s})});const i=new Map(t.map(j=>[j.id,j])),n=ki(t),l=Math.max(...n.map(j=>j.col))+1,o=Math.max(...n.map(j=>j.row))+1,c=l*(be+We)+We,p=o*(Ce+Ve)+Ve;function u(j){if(!i.get(j))return null;const d=n.find(x=>x.id===j);return d?{x:We+d.col*(be+We)+be/2,y:Ve+d.row*(Ce+Ve)+Ce/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:p,style:{display:"block",maxWidth:"100%"},children:[e.jsx("defs",{children:e.jsx("marker",{id:`arrow-${s}`,viewBox:"0 0 10 10",refX:"9",refY:"5",markerWidth:"6",markerHeight:"6",orient:"auto-start-reverse",children:e.jsx("path",{d:"M 0 0 L 10 5 L 0 10 z",fill:"var(--text-dim)"})})}),a.map((j,m)=>{const d=u(j.from),x=u(j.to);if(!d||!x)return null;const b=x.x-d.x,g=x.y-d.y,w=b>=0?d.x+be/2:d.x-be/2,T=b>=0?x.x-be/2:x.x+be/2,v=g>=0?d.y+Ce/2:d.y-Ce/2,k=g>=0?x.y-Ce/2:x.y+Ce/2,L=(w+T)/2,y=(v+k)/2;return e.jsxs("g",{children:[e.jsx("line",{x1:w,y1:v,x2:T,y2:k,stroke:"var(--text-dim)",strokeWidth:1.5,markerEnd:`url(#arrow-${s})`}),j.label&&e.jsx("text",{x:L,y:y-4,fontSize:10,fill:"var(--text-dim)",textAnchor:"middle",fontFamily:"var(--font-mono)",children:j.label})]},m)}),t.map(j=>{const m=n.find(w=>w.id===j.id);if(!m)return null;const d=We+m.col*(be+We),x=Ve+m.row*(Ce+Ve),b=vi[j.type];if(j.type==="decision"){const w=d+be/2,T=x+Ce/2,v=[[w,x],[d+be,T],[w,x+Ce],[d,T]].map(k=>k.join(",")).join(" ");return e.jsxs("g",{children:[e.jsx("polygon",{points:v,fill:b.fill,stroke:b.stroke,strokeWidth:2}),e.jsx("foreignObject",{x:d+8,y:T-14,width:be-16,height:28,children:e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",gap:4,fontSize:12,color:b.fg,textAlign:"center",lineHeight:1.2,fontStyle:"italic",height:"100%"},children:[e.jsx(za,{size:11}),j.label]})})]},j.id)}const g=j.type==="note";return e.jsxs("g",{children:[e.jsx("rect",{x:d,y:x,width:be,height:Ce,rx:8,fill:b.fill,stroke:b.stroke,strokeWidth:g?1:2,strokeDasharray:g?"4 3":void 0}),e.jsx("foreignObject",{x:d+6,y:x+6,width:be-12,height:Ce-12,children:e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",gap:6,fontSize:12,color:b.fg,textAlign:"center",lineHeight:1.25,fontStyle:g?"italic":"normal",height:"100%"},children:[g&&e.jsx(aa,{size:11}),j.label]})})]},j.id)})]})})}function bi({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 Pt={fontSize:14,lineHeight:1.6,color:"var(--text)"};function Ni({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 wi extends Ct.Component{constructor(){super(...arguments);Is(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 Si(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 Ci={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=Ci[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 Ti({slug:s,onClose:t,onCommentAdded:a}){var X,ae,ue,W;const i=de(),[n,l]=r.useState(null),[o,c]=r.useState([]),[p,u]=r.useState(!0),[j,m]=r.useState(null),[d,x]=r.useState(null),[b,g]=r.useState(!1),[w,T]=r.useState(!1),[v,k]=r.useState(null),[L,y]=r.useState(null),[M,F]=r.useState(""),[S,I]=r.useState(null),[H,R]=r.useState([]),q=Ct.useCallback((C,P,h)=>{R(O=>O.some(U=>U.blockId===C)?O:[...O,{blockId:C,blockType:P,message:h.message||String(h)}])},[]),_=r.useRef(null),f=r.useMemo(()=>n?zi(n.blocks):[],[n]);r.useEffect(()=>{let C=!1;const P=5e3;return(async()=>{u(!0),m(null);try{const h=new Promise((ne,te)=>setTimeout(()=>te(new Error("Request timed out after 5s")),P)),[O,U]=await Promise.race([Promise.all([z.get(`/artifacts/${encodeURIComponent(s)}/render`),z.get(`/artifacts/${encodeURIComponent(s)}`)]),h]);if(C)return;l(O);const A=(U==null?void 0:U.comments)??[];c(Array.isArray(A)?A:[])}catch(h){if(!C){const O=h.message;m(O),x(O)}}finally{C||u(!1)}})(),()=>{C=!0}},[s]);function E(C){if(!_.current)return;C.preventDefault();const P=_.current.getBoundingClientRect();k({x:C.clientX,y:C.clientY,worldX:C.clientX-P.left,worldY:C.clientY-P.top})}async function G(){if(!(!L||!M.trim()))try{const C=await z.post(`/artifacts/${encodeURIComponent(s)}/comments`,{x:L.worldX,y:L.worldY,text:M.trim(),author:"drb0rk"});c(P=>[...P,{id:C.id??`cmt_${Date.now()}`,x:L.worldX,y:L.worldY,text:M.trim(),author:"drb0rk",created:new Date().toISOString()}]),y(null),F(""),k(null),a==null||a(),i.success("Comment added")}catch(C){i.error(`Failed to add comment: ${C.message}`)}}async function D(){if(!b){g(!0);try{const C=await z.post(`/artifacts/${encodeURIComponent(s)}/submit`,{answers:[],submitter:"drb0rk"});C!=null&&C.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(C){i.error(`Submit failed: ${C.message}`)}finally{g(!1)}}}function V(){T(C=>!C)}const se=C=>{const P=C.id,h=C.data??{},O=Si(C);return O.ok?e.jsx(wi,{blockId:P,blockType:C.type,onError:q,children:Q(C,P,h)},P):e.jsxs("div",{id:P,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:[C.type," block invalid"]}),e.jsxs("div",{style:{color:"var(--text-muted)",marginBottom:6},children:["block id: ",e.jsx("code",{children:P})]}),e.jsx("pre",{style:{margin:0,whiteSpace:"pre-wrap",wordBreak:"break-word"},children:O.error})]},P)},Q=(C,P,h)=>{switch(C.type){case"RichText":return e.jsx(ri,{id:P,children:C.childrenMarkdown??""},P);case"Callout":return e.jsx(oi,{id:P,tone:h.tone??"info",children:C.childrenMarkdown??""},P);case"Checklist":return e.jsx(ci,{id:P,items:h.items??[]},P);case"Table":return e.jsx(di,{id:P,columns:h.columns??[],rows:h.rows??[]},P);case"CodeTabs":return e.jsx(hi,{id:P,tabs:h.tabs??[]},P);case"Decision":return e.jsx(mi,{id:P,title:h.title,question:h.question,options:h.options??[]},P);case"OpenQuestions":return e.jsx(ui,{id:P,questions:h.questions??[]},P);case"FileTree":return e.jsx(pi,{id:P,title:h.title,entries:h.entries??[]},P);case"Diff":return e.jsx(gi,{id:P,filename:h.filename,language:h.language,mode:h.mode??"unified",before:h.before??"",after:h.after??""},P);case"Stat":return e.jsx(fi,{id:P,label:h.label??"",value:h.value,trend:h.trend,hint:h.hint},P);case"Workflow":return e.jsx(yi,{id:P,steps:h.steps??[],connections:h.connections},P);case"Mockup":return e.jsx(Ni,{id:P,title:h.title,x:h.x,y:h.y,w:h.w,h:h.h,html:h.html??""},P);case"Diagram":return e.jsx("div",{id:P,className:"glyph-block-placeholder",children:e.jsxs("em",{children:["[Diagram] ",P]})},P)}};if(p)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(Mi,{})," Loading glyph…"]})});if(j||!n)return e.jsxs("div",{className:"glyph-renderer glyph-renderer--error",children:[e.jsx("strong",{children:"Failed to load glyph."}),e.jsx("pre",{children:j??"unknown error"})]});const B=((X=n.frontmatter)==null?void 0:X.title)??s,Y=((ae=n.frontmatter)==null?void 0:ae.status)??"draft",J=o.length;return e.jsxs("div",{className:`glyph-canvas ${w?"glyph-canvas--fullscreen":""}`,ref:_,onContextMenu:E,children:[e.jsxs("div",{className:"glyph-toolbar-floating",children:[e.jsxs("button",{className:"glyph-btn glyph-btn--primary glyph-btn--send",onClick:D,disabled:b,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:J})]}),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(Xa,{size:15})}),e.jsx("button",{className:"glyph-icon-btn",title:"Undo",disabled:!0,children:e.jsx(en,{size:15})}),e.jsx("button",{className:"glyph-icon-btn",title:"Redo",disabled:!0,children:e.jsx(Ya,{size:15})}),e.jsx("button",{className:"glyph-icon-btn",title:w?"Exit fullscreen":"Fullscreen",onClick:V,children:e.jsx(Fa,{size:15})}),e.jsx("button",{className:"glyph-icon-btn",title:"More",children:e.jsx(Ta,{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(zs,{size:15}),e.jsx("span",{className:"glyph-icon-btn-count",children:J})]}),t&&e.jsx("button",{className:"glyph-icon-btn glyph-icon-btn--close",title:"Close",onClick:t,"aria-label":"Close",children:e.jsx(Ee,{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:B}),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})]})]}),(H.length>0||((ue=n.errors)==null?void 0:ue.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:H.length>0?`${H.length} block${H.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:[H.map((C,P)=>e.jsxs("li",{children:[e.jsx("strong",{children:C.blockType})," (",e.jsx("code",{children:C.blockId}),"): ",C.message]},`be-${P}`)),(W=n.errors)==null?void 0:W.map((C,P)=>e.jsxs("li",{children:[C.line?`line ${C.line}: `:"",C.message]},`ce-${P}`))]})]}),e.jsx("div",{className:"glyph-sections",children:f.map((C,P)=>e.jsxs("section",{className:`glyph-section ${C.heading?"glyph-section--headed":"glyph-section--plain"}`,children:[C.heading&&e.jsx("h2",{className:"glyph-section-heading",children:C.heading}),e.jsx("div",{className:"glyph-section-blocks",children:C.blocks.map(se)})]},`sec-${P}-${C.heading??"ungrouped"}`))})]}),o.map(C=>e.jsxs("button",{className:`glyph-pin ${S===C.id?"glyph-pin--active":""}`,style:{left:C.x,top:C.y},onClick:P=>{P.stopPropagation(),I(S===C.id?null:C.id)},title:C.text,children:[e.jsx(lt,{size:14}),S===C.id&&e.jsxs("div",{className:"glyph-pin-thread",children:[e.jsx("div",{className:"glyph-pin-text",children:C.text}),e.jsxs("div",{className:"glyph-pin-meta",children:[C.author??"anonymous"," · ",C.created?new Date(C.created).toLocaleString():""]})]})]},C.id)),v&&e.jsx("div",{className:"glyph-ctx-menu",style:{left:v.x,top:v.y},onClick:C=>C.stopPropagation(),children:e.jsxs("button",{className:"glyph-ctx-item",onClick:()=>{y({worldX:v.worldX,worldY:v.worldY}),k(null)},children:[e.jsx(lt,{size:14})," Add comment here"]})}),L&&e.jsx("div",{className:"glyph-modal-overlay",onClick:()=>y(null),children:e.jsxs("div",{className:"glyph-modal",onClick:C=>C.stopPropagation(),children:[e.jsxs("h3",{children:["Add comment at (",Math.round(L.worldX),", ",Math.round(L.worldY),")"]}),e.jsx("textarea",{autoFocus:!0,value:M,onChange:C=>F(C.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:()=>y(null),children:"Cancel"}),e.jsx("button",{className:"glyph-btn glyph-btn--primary",onClick:G,disabled:!M.trim(),children:"Add comment"})]})]})})]})}function Mi(){return e.jsx("span",{className:"glyph-spinner","aria-label":"loading",children:"…"})}function $i(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 Ai({snapshot:s,refreshSnapshot:t}){const a=de(),[i,n]=r.useState(s.artifacts||[]),[l,o]=r.useState(!s.artifacts),[c,p]=r.useState(null),[u,j]=r.useState(""),[m,d]=r.useState(!1);r.useEffect(()=>{s.artifacts&&(n(s.artifacts),o(!1))},[s.artifacts]);const x=async()=>{try{const T=await z.get("/artifacts");n(T.artifacts||[]),o(!1)}catch(T){a.error(`Artifacts load failed: ${T.message}`),o(!1)}},b=r.useMemo(()=>{let T=i;if(u){const v=u.toLowerCase();T=T.filter(k=>(k.slug||"").toLowerCase().includes(v)||(k.title||"").toLowerCase().includes(v))}return m||(T=T.filter(v=>v.status!=="archived")),T},[i,u,m]),g=async(T,v)=>{try{const k=await z.post("/artifacts",{slug:T,title:v});a.success(`Artifact "${k.slug}" created.`),p(k.slug),await x()}catch(k){a.error(`Create failed: ${k.message}`)}},w=async T=>{if(confirm(`Delete artifact "${T}"? This removes the directory permanently.`))try{await z.del(`/artifacts/${encodeURIComponent(T)}`),a.success("Artifact deleted."),c===T&&p(null),await x()}catch(v){a.error(`Delete failed: ${v.message}`)}};return c?e.jsxs("div",{className:"artifact-glyph-overlay",children:[e.jsx("div",{className:"artifact-glyph-toolbar",children:e.jsxs($,{variant:"ghost",onClick:()=>{p(null),x()},children:[e.jsx(Mt,{size:14})," Back to artifacts"]})}),e.jsx(Ti,{slug:c,onClose:()=>{p(null),x()},onCommentAdded:()=>x()})]}):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(Ns,{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(Pe,{size:14}),e.jsx("input",{className:"input",type:"text",placeholder:"Search…",value:u,onChange:T=>j(T.target.value)})]}),e.jsxs($,{variant:"ghost",size:"sm",onClick:()=>d(T=>!T),title:m?"Hide archived":"Show archived",children:[m?e.jsx(Tt,{size:14}):e.jsx(na,{size:14}),m?"Hide archived":"Show archived"]}),e.jsxs($,{variant:"secondary",size:"sm",onClick:x,children:[e.jsx(he,{size:14})," Refresh"]})]})]}),e.jsx(Ri,{onCreate:g}),l?e.jsx("div",{className:"view-loading",children:e.jsx(fe,{size:"lg"})}):b.length===0?e.jsx(ze,{icon:e.jsx(Ns,{size:32}),title:m?"No artifacts":"No artifacts yet",message:m?"No artifacts match your filter (try Show archived off).":"Create one above to get started."}):e.jsx("div",{className:"artifacts-grid",children:b.map(T=>e.jsx(Ii,{artifact:T,onOpen:()=>p(T.slug),onDelete:()=>w(T.slug)},T.slug))})]})}function Ri({onCreate:s}){const[t,a]=r.useState(""),[i,n]=r.useState("");return e.jsxs(ie,{className:"new-artifact",children:[e.jsxs(re,{children:[e.jsx(Ne,{size:14})," New artifact"]}),e.jsx(ce,{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($,{variant:"primary",type:"submit",children:"Create"})]})]})}function Ii({artifact:s,onOpen:t,onDelete:a}){const i=$i(s.status||"draft");return e.jsxs(ie,{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(Ye,{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 ",ye(s.mtime)]})]}),e.jsxs("div",{className:"artifact-card-actions",children:[e.jsxs($,{variant:"primary",size:"sm",onClick:n=>{n.stopPropagation(),t()},children:["Open",e.jsx(_e,{size:12})]}),e.jsxs($,{variant:"ghost",size:"sm",onClick:n=>{n.stopPropagation(),a()},children:[e.jsx(Te,{size:12})," Delete"]})]})]})}function Li({children:s,className:t,onRemove:a}){return e.jsxs("span",{className:ee("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 Ei({task:s,agents:t,onPromote:a,onDelete:i,onEdit:n,onRefresh:l}){var j;const o=de(),c=async()=>{try{await z.post(`/tasks/${encodeURIComponent(s.id)}/promote`),o.success("Promoted to queued.",1500),a(s.id)}catch(m){o.error(`Promote failed: ${m.message}`)}},p=async()=>{if(confirm("Delete this task?"))try{await z.del(`/tasks/${encodeURIComponent(s.id)}`),o.success("Deleted.",1500),i(s.id)}catch(m){o.error(`Delete failed: ${m.message}`)}},u={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:u[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]}),((j=s.tags)==null?void 0:j.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:ye(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($t,{size:13})}),e.jsx("button",{type:"button",className:"icon-btn",title:"Edit",onClick:()=>n(s),children:e.jsx(Oe,{size:13})}),e.jsx("button",{type:"button",className:"icon-btn icon-btn-danger",title:"Delete",onClick:p,children:e.jsx(Te,{size:13})})]})]})]})}function Di({agents:s,onRefresh:t}){const a=de(),[i,n]=r.useState([]),[l,o]=r.useState(!1),c=async()=>{try{o(!0);const d=await z.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 p=async d=>{n(x=>x.filter(b=>b.id!==d)),await t()},u=async d=>{n(x=>x.filter(b=>b.id!==d)),await t()},j=d=>{},m=async()=>{var d;if(i.length!==0)try{const b=((d=(await z.post("/tasks/promote-batch",{ids:i.map(g=>g.id)})).affected)==null?void 0:d.filter(g=>g.ok).length)??0;a.success(`Promoted ${b} task(s).`,2e3),n([]),await t()}catch(x){a.error(`Promote all failed: ${x.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(ks,{size:15}),"Backlog (",i.length,")"]}),e.jsxs("div",{className:"backlog-panel-header-actions",children:[i.length>0&&e.jsxs($,{variant:"ghost",size:"sm",onClick:m,title:"Promote all to queued",children:[e.jsx($t,{size:12})," Promote all"]}),e.jsx($,{variant:"ghost",size:"sm",onClick:c,title:"Refresh backlog","aria-label":"Refresh backlog",children:e.jsx(he,{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(ks,{size:28}),e.jsx("span",{children:"Backlog is empty."})]}):e.jsx("div",{className:"backlog-list",children:i.map(d=>e.jsx(Ei,{task:d,agents:s,onPromote:p,onDelete:u,onEdit:j,onRefresh:t},d.id))})]})}const fs=[{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"}],st=["low","normal","high"];function Pi({snapshot:s,refreshSnapshot:t,setActiveTab:a}){const i=de(),n=$e(),[l,o]=r.useState(s.tasks||[]),[c,p]=r.useState(!s.tasks),[u,j]=r.useState(""),[m,d]=r.useState(""),[x,b]=r.useState(!1),[g,w]=r.useState(0),T=async()=>{try{const I=await z.get("/tasks");o(Array.isArray(I)?I:[])}catch(I){i.error(`Tasks load failed: ${I.message}`)}finally{p(!1)}};r.useEffect(()=>{s.tasks&&(o(s.tasks),p(!1))},[s.tasks]),r.useEffect(()=>{const I=setInterval(()=>w(H=>H+1),3e4);return()=>clearInterval(I)},[]);const v=r.useMemo(()=>{let I=l.filter(H=>H.status!=="backlog");if(m&&(I=I.filter(H=>(H.priority||"normal")===m)),u.trim()){const H=u.toLowerCase();I=I.filter(R=>(R.title||"").toLowerCase().includes(H)||(R.description||"").toLowerCase().includes(H))}return I},[l,u,m]),k=r.useMemo(()=>{const I={high:0,normal:1,low:2};return[...v].sort((H,R)=>{const q=I[H.priority]??1,_=I[R.priority]??1;return q!==_?q-_:new Date(R.createdAt).getTime()-new Date(H.createdAt).getTime()})},[v]),L=l.filter(I=>I.status==="backlog").length,y=async(I,H)=>{const R=l.find(_=>_.id===I);if(!R)return;const q=R.status;o(_=>_.map(f=>f.id===I?{...f,status:H}:f));try{await z.patch(`/tasks/${encodeURIComponent(I)}/status`,{status:H}),i.success(`Moved to ${H}.`,1200)}catch(_){o(f=>f.map(E=>E.id===I?{...E,status:q}:E)),i.error(`Move failed: ${_.message}`)}},M=async I=>{if(confirm("Delete this task?"))try{await z.del(`/tasks/${encodeURIComponent(I)}`),o(H=>H.filter(R=>R.id!==I)),i.success("Task deleted.",1200)}catch(H){i.error(`Delete failed: ${H.message}`)}},F=async I=>{try{const H=await z.post(`/tasks/${encodeURIComponent(I)}/start`);H&&H.task&&o(R=>R.map(q=>q.id===I?H.task:q)),i.success("Retry dispatched.",1200)}catch(H){i.error(`Retry failed: ${H.message}`)}},S=async I=>{const H=l.find(R=>R.id===I);if(H)try{const R=await z.post("/tasks/submit",{title:H.title,description:H.description,priority:H.priority,tags:H.tags}),q=(R.subtasks||[]).length;i.success(q>1?`Odin split it into ${q} subtasks.`:"Sent to Odin.",1500),R.subtasks&&R.subtasks.length>0&&o(_=>[R.main,...R.subtasks,..._.filter(f=>f.id!==H.id)]),await t()}catch(R){i.error(`Submit failed: ${R.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(as,{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(Pe,{size:12}),e.jsx("input",{className:"input",type:"text",placeholder:"Search…",value:u,onChange:I=>j(I.target.value)}),u&&e.jsx("button",{type:"button",className:"icon-btn","aria-label":"Clear search",onClick:()=>j(""),children:e.jsx(Ee,{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:m,onChange:I=>d(I.target.value),title:"Filter by priority",children:[e.jsx("option",{value:"",children:"All"}),st.map(I=>e.jsx("option",{value:I,children:I},I))]})]}),e.jsx("div",{className:"tasks-toolbar-spacer"}),e.jsxs("div",{className:"tasks-toolbar-group",children:[e.jsx($,{variant:"ghost",size:"sm",onClick:T,title:"Refresh","aria-label":"Refresh tasks",children:e.jsx(he,{size:14})}),L>0&&e.jsxs($,{variant:x?"accent":"ghost",size:"sm",onClick:()=>b(I=>!I),title:x?"Hide backlog":"Show backlog",children:[e.jsx(ks,{size:14}),"Backlog",e.jsx("span",{className:"badge",children:L})]}),e.jsxs($,{variant:"primary",size:"sm",onClick:()=>Bi(n,i,o,T,t),children:[e.jsx(Ne,{size:14})," New task"]})]})]}),x&&L>0&&e.jsx(Di,{agents:s.agents||[],onRefresh:t}),c?e.jsx("div",{className:"view-loading",children:e.jsx(fe,{size:"lg"})}):e.jsx("div",{className:"kanban",children:fs.map(I=>e.jsx(Oi,{column:I,tasks:k.filter(H=>H.status===I.id),onMove:y,onDelete:M,onRetry:F,onEdit:H=>Ui(n,i,H,o,T,t),onSubmitToOdin:S,tick:g},I.id))})]})}function Oi({column:s,tasks:t,onMove:a,onDelete:i,onRetry:n,onEdit:l,onSubmitToOdin:o,tick:c}){const[p,u]=r.useState(!1);return e.jsxs("div",{className:ee("kanban-column",p&&"kanban-column-drop"),"data-column":s.id,onDragOver:j=>{j.preventDefault(),u(!0)},onDragLeave:()=>u(!1),onDrop:j=>{j.preventDefault(),u(!1);const m=j.dataTransfer.getData("text/task-id");m&&a(m,s.id)},children:[e.jsxs("div",{className:"kanban-col-header",children:[e.jsxs(re,{children:[e.jsx("span",{className:ee("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(j=>e.jsx(Fi,{task:j,onMove:m=>{const x=fs.findIndex(b=>b.id===j.status)+m;x>=0&&x<fs.length&&a(j.id,fs[x].id)},onEdit:()=>l(j),onDelete:()=>i(j.id),onRetry:()=>n(j.id),onSubmitToOdin:()=>o(j.id),tick:c},j.id))})]})}function Fi({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:ee("task-card",`priority-${s.priority}`),"data-task-id":s.id,draggable:!0,onDragStart:p=>{p.dataTransfer.setData("text/task-id",s.id),p.dataTransfer.effectAllowed="move"},"data-tick":o,children:[e.jsxs("div",{className:"task-card-head",children:[e.jsx("span",{className:"priority-dot",style:{background:ra[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(De,{size:10})," @",c]}),s.timeSpent?e.jsxs("span",{className:"task-card-badge",children:[e.jsx(ys,{size:10})," ",Math.round((s.timeSpent||0)/60),"m"]}):null,s.tags&&s.tags.length>0&&s.tags.slice(0,3).map(p=>e.jsx(Li,{children:p},p))]}),e.jsxs("div",{className:"task-card-footer",children:[e.jsx("span",{className:"task-card-time tabular-nums muted",children:ye(s.createdAt)}),e.jsxs("div",{className:"task-card-actions",onClick:p=>p.stopPropagation(),children:[e.jsx("button",{type:"button",className:"icon-btn","aria-label":"Move left",title:"Move left",onClick:()=>t(-1),children:e.jsx(ka,{size:14})}),e.jsx("button",{type:"button",className:"icon-btn","aria-label":"Edit",title:"Edit",onClick:a,children:e.jsx(Va,{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(Nt,{size:14})}),e.jsx("button",{type:"button",className:"icon-btn icon-btn-danger","aria-label":"Delete",title:"Delete",onClick:i,children:e.jsx(Te,{size:14})}),e.jsx("button",{type:"button",className:"icon-btn","aria-label":"Move right",title:"Move right",onClick:()=>t(1),children:e.jsx(_e,{size:14})})]})]})]})}function Bi(s,t,a,i,n){let l=null,o=null,c=null,p=null;const u=async m=>{m&&typeof m.preventDefault=="function"&&m.preventDefault();const d=((l==null?void 0:l.value)||"").trim(),x=((o==null?void 0:o.value)||"").trim();if(!d){t.warning("Title is required."),l==null||l.focus();return}const b=(p==null?void 0:p.value)||"normal",g=((c==null?void 0:c.value)||"").split(",").map(w=>w.trim()).filter(Boolean);try{const w=await z.post("/tasks",{title:d,description:x,priority:b,tags:g});s.close(),typeof window<"u"&&window.dispatchEvent(new MouseEvent("mousedown")),a(T=>[w,...T]),t.success("Task created.",1200),await n()}catch(w){t.error(`Create failed: ${w.message}`)}},j=m=>{m.key==="Enter"&&!m.shiftKey&&(m.preventDefault(),u(m))};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:m=>{l=m},id:"task-title",className:"input",type:"text",maxLength:200,placeholder:"What needs to be done?",autoFocus:!0,onKeyDown:j}),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:m=>{o=m},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 m=await ia(o.value);m!==o.value&&(o.value=m)},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:m=>{p=m},id:"task-priority",className:"select",defaultValue:"normal",children:st.map(m=>e.jsx("option",{value:m,children:m},m))})]}),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:m=>{c=m},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($,{variant:"ghost",onClick:()=>s.close(),children:"Cancel"}),e.jsxs($,{variant:"primary",type:"button",onClick:m=>u(m),children:[e.jsx(Ne,{size:14})," Create task"]})]})})}function Ui(s,t,a,i,n,l){let o=null,c=null,p=null,u=null;const j=async()=>{const m=((o==null?void 0:o.value)||"").trim(),d=((c==null?void 0:c.value)||"").trim();if(!m){t.warning("Title is required."),o==null||o.focus();return}const x=(u==null?void 0:u.value)||"normal",b=((p==null?void 0:p.value)||"").split(",").map(g=>g.trim()).filter(Boolean);try{const g=await z.put(`/tasks/${encodeURIComponent(a.id)}`,{title:m,description:d,priority:x,tags:b});s.close(),typeof window<"u"&&window.dispatchEvent(new MouseEvent("mousedown")),i(w=>w.map(T=>T.id===a.id?g:T)),t.success("Task updated.",1200),await l()}catch(g){t.error(`Save failed: ${g.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:m=>{o=m},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:m=>{c=m},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:m=>{u=m},id:"edit-task-priority",className:"select",defaultValue:a.priority||"normal",children:st.map(m=>e.jsx("option",{value:m,children:m},m))})]}),e.jsxs("label",{htmlFor:"edit-task-tags",className:"task-form-field",style:{flex:2},children:["Tags",e.jsx("input",{ref:m=>{p=m},id:"edit-task-tags",className:"input",type:"text",defaultValue:(a.tags||[]).join(", "),placeholder:"comma-separated"})]})]}),e.jsxs(ie,{children:[e.jsxs(re,{children:[e.jsx(It,{size:12})," Status"]}),e.jsxs(ce,{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($,{variant:"ghost",onClick:()=>s.close(),children:"Cancel"}),e.jsxs($,{variant:"primary",onClick:j,children:[e.jsx(Tt,{size:14})," Save"]})]})})}function qi(s){return z.urlWithToken(`/artifacts/${encodeURIComponent(s)}/content`)}function _i(s,t){const a=qi(t);window.open(a,"_blank","noopener,noreferrer")}const ut={"1m":60*1e3,"5m":5*60*1e3,"30m":30*60*1e3,"1h":60*60*1e3},ke=56,Ae=32,Ke=22,Hi=4,Wi=.9,Os={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 Fs(s){return s&&Os[s]||Os.idle}function xs(s,t=24){return s?s.length<=t?s:s.slice(0,t-1)+"…":""}function Cs(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 Bs(s){const t=s._timerStart;return typeof t=="number"&&t>0?t:Cs(s.createdAt)||Date.now()}function Vi(s,t){return(s.status==="done"||s.status==="archived"||s.status==="failed"||s.status==="killed")&&(Cs(s.completedAt)||Cs(s.updatedAt))||t}function Ki(s){return typeof s.startedAt=="number"&&s.startedAt>0?s.startedAt:Date.now()}function Gi(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 Yi(s){return s<=6e4?1e4:s<=3e5?3e4:s<=18e5?3e5:6e5}function Xi(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 Qi({snapshot:s,refreshSnapshot:t}){const a=de(),i=r.useRef(null),[n,l]=r.useState("live"),[o,c]=r.useState("5m"),[p,u]=r.useState(()=>typeof window>"u"?!0:window.innerWidth>900),[j,m]=r.useState([]),[d,x]=r.useState([]),[b,g]=r.useState(!0),[w,T]=r.useState(0),[v,k]=r.useState(Date.now()),[L,y]=r.useState(()=>Date.now()-ut["5m"]*.1),[M,F]=r.useState({width:800,height:400}),[S,I]=r.useState(null),[H,R]=r.useState(""),[q,_]=r.useState([]),[f,E]=r.useState(""),[G,D]=r.useState("normal"),[V,se]=r.useState(""),[Q,B]=r.useState(""),[Y,J]=r.useState(!1),[X,ae]=r.useState(!1),[ue,W]=r.useState([]),C=$e(),P=s.agents||[],h=s.tasks||[],O=ut[o],U=L,A=L+O,ne=r.useCallback(async()=>{try{const[N,K]=await Promise.all([z.get("/background").catch(()=>({instances:[]})),z.get("/activity?limit=200").catch(()=>({events:[]}))]);m(N.instances||[]),x(K.events||[])}catch(N){console.warn("activity reload failed:",N)}finally{g(!1)}},[]);r.useEffect(()=>{ne();const N=setInterval(ne,3e3);return()=>clearInterval(N)},[ne]),r.useEffect(()=>{T(N=>N+1)},[h.length,P.length]),r.useEffect(()=>{if(n==="pause")return;k(Date.now());const N=setInterval(()=>k(Date.now()),1e3);return()=>clearInterval(N)},[n,w]),r.useEffect(()=>{if(n==="pause")return;(v-L)/O>Wi&&y(v-O*.1)},[v,L,O,n]),r.useEffect(()=>{y(Date.now()-O*.1)},[o]),r.useEffect(()=>{n==="live"&&y(Date.now()-O*.1)},[n]),r.useLayoutEffect(()=>{const N=i.current;if(!N)return;const K=new ResizeObserver(xe=>{for(const pe of xe){const{width:oe,height:ge}=pe.contentRect;F({width:Math.max(200,Math.floor(oe)),height:Math.max(120,Math.floor(ge))})}});return K.observe(N),()=>K.disconnect()},[]);const te=r.useMemo(()=>{const N=[];let K=0;for(const oe of j){const ge=Ki(oe),Se=Gi(oe,v);Se<U||ge>A||N.push({kind:"bg",id:`bg:${oe.instanceId}`,index:K++,label:`BG ${xs(oe.promptPreview,20)||oe.instanceId.slice(0,10)}`,sub:oe.status||"pending",start:ge,end:Se,data:oe})}const xe=[...h].sort((oe,ge)=>Bs(oe)-Bs(ge)),pe=[];for(const oe of xe){const ge=Bs(oe),Se=Vi(oe,v);if(Se<U||ge>A)continue;let He=-1;for(let Fe=0;Fe<pe.length;Fe++)if(pe[Fe]<=ge){pe[Fe]=Se,He=Fe;break}He===-1&&(pe.push(Se),He=pe.length-1),N.push({kind:"task",id:`task:${oe.id}`,index:K+He,label:xs(oe.title,32),sub:oe.status,start:ge,end:Se,data:oe})}return N},[j,h,v,U,A]),me=r.useMemo(()=>{const N=new Map;for(const K of te)N.set(K.id,K);return N},[te]),le=r.useCallback(N=>O<=0?0:(N-U)/O*M.width,[U,O,M.width]),os=r.useMemo(()=>{const N=Yi(O),K=[],xe=Math.floor(U/N)*N;for(let pe=xe;pe<=A+N;pe+=N){if(pe<U-N)continue;if(pe>A)break;const oe=le(pe);oe<-40||oe>M.width+40||K.push({t:pe,x:oe,label:Xi(pe,O)})}return K},[U,A,O,M.width,le]),cs=r.useMemo(()=>{const N=[];for(const K of te){if(K.kind==="events")continue;const xe=Math.max(K.start,U),pe=Math.min(K.end,A);if(pe<U||xe>A)continue;const oe=le(xe),ge=le(pe),Se=Math.max(Hi,ge-oe),He=Ae+Ke+K.index*ke+8,Fe=ke-16;let Me="doing";if(K.kind==="bg"){const ve=K.data.status||"pending";ve==="done"||ve==="success"?Me="done":ve==="failed"||ve==="killed"||ve==="error"?Me="failed":ve==="queued"||ve==="pending"?Me="queued":ve==="blocked"||ve==="stuck"?Me="blocked":Me="doing"}else{const ve=K.data.status;ve==="done"||ve==="archived"?Me="done":ve==="failed"||ve==="killed"?Me="failed":ve==="queued"?Me="queued":ve==="blocked"?Me="blocked":Me="doing"}const Vt=(S==null?void 0:S.id)===K.id;N.push({id:K.id,laneIndex:K.index,x:oe,y:He,w:Se,h:Fe,label:K.label,statusClass:Me,selected:Vt,data:K.data,kind:K.kind,start:K.start,end:K.end})}return N},[te,le,S,U,A]),ds=r.useMemo(()=>{const N=[];for(const K of d){const xe=Cs(K.ts);if(xe<U-5e3||xe>A+5e3)continue;const pe=le(xe);let oe=Ae+12;if(K.taskId){const ge=me.get(`task:${K.taskId}`);ge&&(oe=Ae+Ke+ge.index*ke+ke/2)}else if(K.nodeId){const ge=String(K.nodeId),Se=me.get(ge.startsWith("task:")||ge.startsWith("bg:")?ge:`task:${ge}`);Se&&(oe=Ae+Ke+Se.index*ke+ke/2)}N.push({id:`${K.ts}-${K.kind}-${K.author??""}-${K.taskId??""}`,x:pe,y:oe,kind:K.kind||"event",ts:xe,text:String(K.text||K.kind||""),author:K.author})}return N},[d,U,A,le,me]),hs=r.useMemo(()=>te.map(N=>({id:N.id,y:Ae+Ke+N.index*ke,h:ke})),[te]),ms=r.useMemo(()=>{const N=le(v);return Math.max(0,Math.min(M.width,N))},[le,v,M.width]),Ut=r.useCallback(N=>{const xe={id:N.id,kind:N.kind,label:N.label,status:N.statusClass,data:N.data};I(xe)},[]);r.useEffect(()=>{if(!S){_([]),B(""),W([]);return}R(""),E(""),se(""),W([]),(async()=>{try{const N=await z.get(`/activity?nodeId=${encodeURIComponent(S.id)}&limit=50`);_(N.events||[])}catch{_([])}if(S.kind==="bg"){const N=S.data;try{const K=await z.get(`/background/${encodeURIComponent(N.instanceId)}/output?lines=80`);B(K.output||"")}catch{B("")}if(N.taskId)try{const K=await z.get(`/tasks/${encodeURIComponent(N.taskId)}/artifacts`);W((K.artifacts||[]).map(xe=>xe.id))}catch{W([])}}})()},[S]);const nt=async()=>{if(!(!S||!H.trim())){ae(!0);try{await z.post("/comments",{nodeId:S.id,text:H,author:"user"}),R("");const N=await z.get(`/activity?nodeId=${encodeURIComponent(S.id)}&limit=50`);_(N.events||[]),a.success("Comment added.")}catch(N){a.error(`Comment failed: ${N.message}`)}finally{ae(!1)}}},qt=async()=>{if(!(!S||!f.trim())){J(!0);try{await z.post(`/nodes/${encodeURIComponent(S.id)}/tasks`,{title:f,description:`Created from timeline selection ${S.id}.`,priority:G}),E(""),a.success("Task created."),await t()}catch(N){a.error(`Task create failed: ${N.message}`)}finally{J(!1)}}},it=async()=>{if(!S||S.kind!=="bg"||!V.trim())return;const N=S.data;try{const K=await z.post(`/background/${encodeURIComponent(N.instanceId)}/message`,{message:V});K.ok?(a.success("Message sent."),se("")):a.warning(K.error||"Send failed")}catch(K){a.error(`Send failed: ${K.message}`)}},_t=async()=>{if(!S||S.kind!=="bg"||!confirm("Kill this bg instance session?"))return;const N=S.data;try{const K=await z.del(`/background/${encodeURIComponent(N.instanceId)}`);K.ok?a.success("Session killed."):a.warning(K.error||"Kill failed"),await ne()}catch(K){a.error(`Kill failed: ${K.message}`)}},Ht=async()=>{if(!S||S.kind!=="bg")return;const N=S.data;try{const K=await z.get(`/background/${encodeURIComponent(N.instanceId)}/output?lines=80`);B(K.output||"")}catch{}};r.useEffect(()=>{const N=K=>{K.key==="Escape"&&I(null)};return window.addEventListener("keydown",N),()=>window.removeEventListener("keydown",N)},[]);const Wt=()=>{T(N=>N+1),ne()},Rs=Ae+Ke+te.length*ke;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(Re,{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($,{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(la,{size:14}):e.jsx(Ys,{size:14}),n==="live"?"Live":"Paused"]}),e.jsx("div",{className:"tl-zoom-group",children:["1m","5m","30m","1h"].map(N=>e.jsx("button",{type:"button",className:ee("tl-zoom-btn",o===N&&"tl-zoom-btn-active"),onClick:()=>c(N),title:`Zoom to ${N}`,children:N},N))}),e.jsxs($,{variant:"secondary",size:"sm",onClick:Wt,title:"Refresh",children:[e.jsx(he,{size:14})," Refresh"]})]})})]}),b&&e.jsx("div",{className:"view-loading",children:e.jsx(fe,{size:"lg"})}),!b&&P.length===0&&h.length===0&&j.length===0&&d.length===0?e.jsx(ze,{icon:e.jsx(Re,{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:ee("tl-view",S&&"tl-view-detail-open"),children:e.jsxs("div",{className:ee("tl-body",!p&&"tl-body-stream-collapsed"),children:[e.jsxs("aside",{className:ee("tl-stream",!p&&"tl-stream-collapsed"),children:[e.jsxs("div",{className:"tl-stream-head",children:[e.jsxs("h3",{children:[e.jsx(ns,{size:13})," Live events"]}),e.jsx("button",{type:"button",className:"icon-btn",onClick:()=>u(!1),title:"Hide event stream","aria-label":"Hide event stream",children:e.jsx(_a,{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."})}):[...d].reverse().map((N,K)=>{const xe=N.author?De:N.kind==="task"?as:N.kind==="bg"?Ls:Re;return e.jsxs("div",{className:"tl-stream-event",children:[e.jsx("span",{className:"tl-stream-event-time",children:new Date(N.ts).toLocaleTimeString("en-GB",{hour12:!1})}),e.jsx("span",{className:"tl-stream-event-icon",style:{color:Fs(N.kind)},children:e.jsx(xe,{size:12})}),e.jsx("span",{className:"tl-stream-event-text",children:N.author||N.text||N.kind})]},`${N.ts}-${K}`)})})]}),e.jsxs("div",{className:"tl-canvas-wrap",ref:i,children:[e.jsxs("div",{className:"tl-canvas-toolbar",children:[e.jsxs("div",{className:"tl-canvas-toolbar-left",children:[!p&&e.jsxs($,{variant:"ghost",size:"sm",onClick:()=>u(!0),title:"Show event stream",children:[e.jsx(Ha,{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(U).toLocaleTimeString("en-GB",{hour12:!1})," →"," ",new Date(A).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(Pa,{size:11})," agent"]}),e.jsxs("span",{className:"tl-legend-item",children:[e.jsx(Za,{size:11})," task"]}),e.jsxs("span",{className:"tl-legend-item",children:[e.jsx(Ls,{size:11})," bg"]})]})]}),e.jsx("div",{className:"tl-canvas-scroll",children:e.jsxs("svg",{className:"tl-canvas",width:M.width,height:Math.max(M.height,Rs),role:"application","aria-label":"Activity timeline",children:[e.jsx("defs",{children:e.jsx("pattern",{id:"tl-canvas-grid",width:M.width,height:ke,patternUnits:"userSpaceOnUse",children:e.jsx("path",{d:`M 0 0 L 0 ${ke}`,fill:"none",stroke:"var(--border)",strokeWidth:.5,opacity:.35})})}),e.jsx("rect",{width:"100%",height:"100%",fill:"url(#tl-canvas-grid)"}),hs.map(N=>e.jsx("rect",{className:"tl-lane-bg",x:0,y:N.y,width:M.width,height:N.h,fill:N.id.charCodeAt(N.id.length-1)%2===0?"var(--bg-elev-2)":"var(--bg-elev)",opacity:.4},`bg-${N.id}`)),e.jsx("g",{className:"tl-time-axis",children:os.map(N=>e.jsxs("g",{children:[e.jsx("line",{x1:N.x,y1:0,x2:N.x,y2:Rs,stroke:"var(--border)",strokeWidth:.5,strokeDasharray:"2,4",opacity:.5}),e.jsx("text",{x:N.x+4,y:Ae-8,fontSize:10,fontFamily:"var(--font-mono)",fill:"var(--text-dim)",children:N.label})]},`tick-${N.t}`))}),te.map(N=>{const K=Ae+Ke+N.index*ke+ke/2;return e.jsxs("g",{className:"tl-lane-label-group",children:[e.jsx("text",{x:6,y:K-2,className:"tl-lane-label",textAnchor:"start",children:xs(N.label,28)}),e.jsx("text",{x:6,y:K+10,className:"tl-lane-label-sub",textAnchor:"start",children:N.sub})]},`label-${N.id}`)}),cs.map(N=>{const K=Fs(N.statusClass),xe=N.id===(S==null?void 0:S.id);return e.jsxs("g",{className:ee("tl-task-bar",`tl-task-bar-${N.statusClass}`,xe&&"tl-task-bar-selected"),onClick:()=>Ut(N),children:[e.jsx("rect",{x:N.x,y:N.y,width:N.w,height:N.h,rx:6,fill:K,fillOpacity:N.statusClass==="done"?.35:N.statusClass==="queued"?.18:.85,stroke:K,strokeWidth:xe?2.5:1.5,strokeOpacity:N.statusClass==="done"?.5:1,strokeDasharray:N.statusClass==="queued"?"4 4":void 0,style:{cursor:"pointer"}}),N.w>36&&e.jsx("text",{x:N.x+8,y:N.y+N.h/2+4,fontSize:11,fontFamily:"var(--font-sans)",fontWeight:500,fill:"var(--text-strong)",style:{pointerEvents:"none"},opacity:N.statusClass==="done"?.7:1,children:xs(N.label,Math.max(4,Math.floor(N.w/7)))})]},`bar-${N.id}`)}),ds.map(N=>{const K=Fs(N.kind);return e.jsxs("g",{className:"tl-event-marker-group",children:[e.jsx("line",{x1:N.x,y1:N.y-6,x2:N.x,y2:N.y+6,stroke:K,strokeWidth:1.2,opacity:.7}),e.jsx("circle",{cx:N.x,cy:N.y,r:4,fill:K,opacity:.9,children:e.jsx("title",{children:`${N.kind}${N.author?` · ${N.author}`:""} · ${new Date(N.ts).toLocaleTimeString("en-GB",{hour12:!1})}`})})]},`ev-${N.id}`)}),e.jsx("line",{className:"tl-now-line",x1:ms,y1:0,x2:ms,y2:Rs,stroke:"var(--error)",strokeWidth:1.5,opacity:.9}),e.jsxs("g",{className:"tl-now-marker",children:[e.jsx("circle",{cx:ms,cy:Ae-4,r:4,fill:"var(--error)"}),e.jsx("text",{x:ms+6,y:Ae-4,fontSize:10,fontWeight:700,fill:"var(--error)",fontFamily:"var(--font-mono)",children:"now"})]})]})})]}),S&&e.jsx("aside",{className:"tl-detail tl-detail-enter",children:e.jsxs(ie,{children:[e.jsxs(re,{children:[S.kind==="agent"&&e.jsx(De,{size:14}),S.kind==="task"&&e.jsx(as,{size:14}),S.kind==="bg"&&e.jsx(Ls,{size:14}),S.label,e.jsx("button",{type:"button",className:"icon-btn",onClick:()=>I(null),title:"Close","aria-label":"Close activity detail",style:{marginLeft:"auto"},children:e.jsx(Ee,{size:14})})]}),e.jsxs("div",{className:"tl-detail-meta",children:[e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"type"})," ",S.kind]}),e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"status"})," ",e.jsx("code",{children:S.status})]}),S.kind==="agent"&&(()=>{const N=S.data;return e.jsxs(e.Fragment,{children:[N.role&&e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"role"})," ",N.role]}),N.model&&e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"model"})," ",N.model]})]})})(),S.kind==="task"&&(()=>{const N=S.data;return e.jsxs(e.Fragment,{children:[N.assignee&&e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"assignee"})," @",N.assignee]}),N.priority&&e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"priority"})," ",N.priority]}),N.createdAt&&e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"created"})," ",new Date(N.createdAt).toLocaleString()]})]})})(),S.kind==="bg"&&(()=>{const N=S.data;return e.jsxs(e.Fragment,{children:[N.startedAt&&e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"started"})," ",new Date(N.startedAt).toLocaleString()]}),N.tmuxSession&&e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"tmux"})," ",e.jsx("code",{children:N.tmuxSession})," ",N.tmuxActive?e.jsx("span",{className:"tag tag-success",children:"active"}):e.jsx("span",{className:"tag",children:"inactive"})]})]})})()]}),S.kind==="task"&&S.data.description&&e.jsx("div",{className:"tl-detail-desc",children:S.data.description}),S.kind==="bg"&&S.data.promptPreview&&e.jsx("div",{className:"tl-detail-desc",children:S.data.promptPreview}),S.kind==="bg"&&e.jsxs("div",{className:"tl-detail-bg",children:[e.jsx("pre",{className:"tl-bg-output",children:Q||"(no output — start the session via tmux attach)"}),e.jsxs("div",{className:"tl-bg-output-actions",children:[e.jsxs($,{variant:"ghost",size:"sm",onClick:Ht,children:[e.jsx(he,{size:12})," Refresh output"]}),ue.length>0&&e.jsxs($,{variant:"secondary",size:"sm",onClick:()=>_i(C,ue[0]),children:[e.jsx(Xs,{size:12})," Open artifact"]}),e.jsxs($,{variant:"danger",size:"sm",onClick:_t,children:[e.jsx(Te,{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:V,onChange:N=>se(N.target.value),onKeyDown:N=>{N.key==="Enter"&&it()}}),e.jsxs($,{variant:"primary",size:"sm",disabled:!V.trim(),onClick:it,children:[e.jsx(qe,{size:12})," Send"]})]})]}),S.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:f,onChange:N=>E(N.target.value)}),e.jsxs("div",{className:"tl-form-row",children:[e.jsxs("select",{className:"select",value:G,onChange:N=>D(N.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($,{variant:"primary",size:"sm",disabled:!f.trim()||Y,onClick:qt,children:[e.jsx(Ne,{size:12})," Add task"]})]})]}),e.jsxs("div",{className:"tl-detail-comments",children:[e.jsxs("div",{className:"field-label",children:[e.jsx(zs,{size:12})," Comments & activity"]}),e.jsxs("ul",{className:"comment-list",children:[q.length===0&&e.jsx("li",{className:"muted",children:"No comments yet."}),q.map((N,K)=>e.jsxs("li",{className:"comment-item",children:[e.jsxs("div",{className:"comment-head",children:[e.jsx("strong",{children:N.author||"system"}),e.jsxs("span",{className:"muted",children:[N.kind," · ",new Date(N.ts).toLocaleString()]})]}),N.text&&e.jsx("div",{className:"comment-text",children:N.text}),N.taskId&&e.jsxs("div",{className:"muted",children:["→ task ",e.jsx("code",{children:String(N.taskId)})]})]},`c-${K}`))]}),e.jsxs("div",{className:"comment-input-row",children:[e.jsx("input",{className:"input",placeholder:"Add a comment…",value:H,onChange:N=>R(N.target.value),onKeyDown:N=>{N.key==="Enter"&&!N.shiftKey&&nt()}}),e.jsxs($,{variant:"secondary",size:"sm",disabled:!H.trim()||X,onClick:nt,children:[e.jsx(qe,{size:12})," Post"]})]})]})]})},S.id)]})})]})}const Ji=[{id:"dark",label:"Dark",Icon:oa},{id:"light",label:"Light",Icon:ca},{id:"system",label:"System",Icon:da}],Zi=[{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"}],er=["Inter","system-ui","Segoe UI","Roboto","JetBrains Mono","SF Mono","Cascadia Code"];function sr(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 tr(){const s=de(),[t,a]=r.useState(null),[i,n]=r.useState(!1),[l,o]=r.useState(null),[c,p]=r.useState(Date.now()),u=r.useCallback(async()=>{n(!0),o(null);try{const d=await z.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(()=>p(Date.now()),1e3);return()=>clearInterval(d)},[t]);const j=t?t.expiresAt-c:0,m=t!=null&&j<=0;return e.jsxs(ie,{id:"settings-updates","data-section":"updates",children:[e.jsxs(re,{children:[e.jsx(ha,{size:14})," Companion App"]}),e.jsxs(ce,{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&&!m?e.jsx("div",{style:{background:"#fff",padding:12,borderRadius:12},children:e.jsx(ma,{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&&m?"QR expired":"No QR generated yet"})}),e.jsxs("div",{style:{flex:"1 1 240px",minWidth:220},children:[!t&&e.jsxs($,{variant:"primary",onClick:u,disabled:i,children:[e.jsx(ua,{size:14})," ",i?"Generating…":"Generate QR Code"]}),t&&!m&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{marginBottom:10},children:[e.jsx("strong",{children:"Expires in"})," ",e.jsx("span",{className:"mono",children:sr(j)})]}),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($,{variant:"secondary",onClick:u,disabled:i,children:[e.jsx(he,{size:14})," Regenerate"]})]}),t&&m&&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($,{variant:"primary",onClick:()=>{a(null),u()},children:[e.jsx(he,{size:14})," Generate new QR"]})]}),l&&e.jsx("div",{style:{marginTop:10,color:"var(--error, #f85149)",fontSize:12},children:l})]})]})]})}const ar=[{id:"topnav",label:"Top nav"},{id:"sidebar",label:"Sidebar"},{id:"both",label:"Both"}];function nr(){const s=de(),[t,a]=r.useState({current:{},latest:null,checking:!1,updating:!1,hasUpdates:!1,requiresRestart:!1,perPackage:{}});r.useEffect(()=>{const p=new Qs;return p.on(u=>{(u.type==="update:progress"||u.type==="update:log"||u.type==="update:complete")&&a(j=>{if(u.type==="update:complete")return{...j,updating:!1,requiresRestart:!!u.requiresRestart};if(u.type==="update:log"){const d=u,x=j.perPackage[d.pkg]||{logs:[]};return{...j,perPackage:{...j.perPackage,[d.pkg]:{...x,logs:[...(x.logs||[]).slice(-50),d.line]}}}}const m=u;return{...j,perPackage:{...j.perPackage,[m.pkg]:{...j.perPackage[m.pkg],status:m.status,error:m.error,newVersion:m.newVersion}}}})}),()=>p.close()},[]),r.useEffect(()=>{z.get("/updates/status").then(p=>a(u=>({...u,current:p.current}))).catch(p=>a(u=>({...u,error:p.message})))},[]);const i=async()=>{a(p=>({...p,checking:!0,error:void 0}));try{const p=await z.get("/updates/check");a(u=>({...u,checking:!1,current:p.current,latest:p.latest,hasUpdates:p.hasUpdates}))}catch(p){a(u=>({...u,checking:!1,error:p.message}))}},n=async()=>{if(confirm("Update Bizar packages? The dashboard will restart automatically.")){a(p=>({...p,updating:!0,requiresRestart:!1,perPackage:{},error:void 0}));try{await z.post("/updates/apply",{packages:["bizar","bizar-dash","bizar-plugin"]})}catch(p){a(u=>({...u,updating:!1,error:p.message}))}}},l=async()=>{if(confirm("Restart the dashboard? You will be disconnected briefly."))try{await z.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(ie,{id:"settings-updates","data-section":"updates",children:[e.jsxs(re,{children:[e.jsx(Qe,{size:14})," Updates"]}),e.jsx(ce,{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(p=>e.jsxs("li",{children:[e.jsx("span",{children:p.name}),e.jsx("code",{className:"mono",children:t.current[p.id]||"—"})]},p.id))})]}),t.latest&&e.jsxs("div",{className:"updates-latest",children:[e.jsx("h4",{children:"Latest available"}),e.jsx("ul",{children:o.map(p=>{var d;const u=t.current[p.id],j=(d=t.latest)==null?void 0:d[p.id],m=u&&j&&u!==j;return e.jsxs("li",{className:m?"updates-outdated":"updates-current-version",children:[e.jsx("span",{children:p.name}),e.jsxs("code",{className:"mono",children:[j||"—",m&&e.jsx("span",{className:"updates-badge",children:"update available"})]})]},p.id)})})]}),t.updating&&e.jsx("div",{className:"updates-progress-rows",children:o.map(p=>{const u=t.perPackage[p.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:p.name}),e.jsxs("div",{className:"updates-pkg-status",children:[u.status==="starting"&&e.jsx("span",{className:"btn-spinner"}),u.status==="installing"&&e.jsx("span",{className:"btn-spinner"}),u.status==="done"&&e.jsx(Na,{size:14,className:"icon-success"}),u.status==="error"&&e.jsx(Gs,{size:14,className:"icon-error"}),e.jsx("span",{children:u.status}),u.newVersion&&e.jsxs("code",{className:"mono",style:{fontSize:11},children:["→ ",u.newVersion]})]})]}),u.logs.length>0&&e.jsxs("details",{className:"updates-pkg-logs",children:[e.jsxs("summary",{children:["npm output (",u.logs.length," lines)"]}),e.jsx("pre",{children:u.logs.join(`
|
|
306
|
+
`)})]}),u.status==="error"&&u.error&&e.jsxs("div",{className:"updates-pkg-error",children:[e.jsx(we,{size:12})," ",u.error]})]},p.id)})}),e.jsxs("div",{className:"updates-actions",children:[e.jsxs($,{onClick:i,disabled:c,children:[t.checking?e.jsx("span",{className:"btn-spinner"}):e.jsx(he,{size:14}),"Check for updates"]}),e.jsxs($,{variant:"primary",onClick:n,disabled:!t.hasUpdates||t.updating,children:[t.updating?e.jsx("span",{className:"btn-spinner"}):e.jsx(Qe,{size:14}),t.updating?"Updating…":t.hasUpdates?"Update now":"Up to date"]}),t.requiresRestart&&e.jsxs($,{variant:"danger",onClick:l,children:[e.jsx(he,{size:14})," Restart Dashboard"]})]}),t.error&&e.jsxs("div",{className:"updates-error",children:[e.jsx(we,{size:14}),e.jsx("span",{children:t.error})]})]})}function xt({settings:s,refreshSnapshot:t}){var J,X,ae,ue,W,C,P;const a=de(),[i,n]=r.useState(s),[l,o]=r.useState(!1),[c,p]=r.useState(!1),[u,j]=r.useState(null),[m,d]=r.useState({port:4321,https:!0,hostname:""}),[x,b]=r.useState({});r.useEffect(()=>{n(s),o(!1),s.theme&&Ge(s.theme)},[s]),r.useEffect(()=>{u&&d({port:u.settings.port,https:u.settings.https!==!1,hostname:u.settings.hostname||""})},[u]),r.useEffect(()=>{z.get("/tailscale/status").then(j).catch(()=>{})},[]),r.useEffect(()=>{z.get("/settings/plugin-options").then(b).catch(()=>{})},[]);const g=h=>{n(O=>{const U={...O,theme:{...O.theme,...h}};return Ge(U.theme),U}),o(!0)},w=h=>{n(O=>({...O,ui:{...O.ui,...h}})),o(!0)},T=(h,O)=>{n(U=>({...U,[h]:O})),o(!0)},v=h=>{n(O=>({...O,notifications:{...O.notifications,...h}})),o(!0)},k=h=>{n(O=>({...O,agents:{...O.agents,...h}})),o(!0)},L=[{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:"updates",label:"Updates"},{id:"activity-log",label:"Activity"},{id:"about",label:"About"}],[y,M]=r.useState(()=>{if(typeof window>"u")return null;const h=window.location.hash.replace(/^#settings-/,"");return L.some(O=>O.id===h)?h:null}),F=h=>{M(h);try{const O=h?`#settings-${h}`:window.location.pathname;if(history.replaceState(null,"",O),h){const U=document.getElementById(`settings-${h}`);U&&U.scrollIntoView({behavior:"smooth",block:"start"})}else window.scrollTo({top:0,behavior:"smooth"})}catch{}},S=h=>{n(O=>({...O,dashboard:{...O.dashboard,...h}})),o(!0)},I=async()=>{p(!0);try{const h=await z.put("/settings",i);n(h.data),o(!1),ts(h.data.theme),Ge(h.data.theme),a.success("Settings saved."),await t()}catch(h){a.error(`Save failed: ${h.message}`)}finally{p(!1)}},H=async()=>{try{const h=await z.get("/settings");n(h.data),o(!1),ts(h.data.theme),Ge(h.data.theme),a.info("Settings reloaded.",1500)}catch(h){a.error(`Reload failed: ${h.message}`)}},R=async()=>{if(confirm("Reset all settings to defaults?"))try{const h=await z.post("/settings/reset");n(h.data),o(!1),ts(h.data.theme),Ge(h.data.theme),a.success("Settings reset."),await t()}catch(h){a.error(`Reset failed: ${h.message}`)}},q=async()=>{try{u!=null&&u.settings.enabled?(await z.post("/tailscale/disable"),a.success("Tailscale serve disabled.")):(await z.post("/tailscale/enable",{port:m.port||4321,https:m.https,hostname:m.hostname||""}),a.success("Tailscale serve enabled."));const h=await z.get("/tailscale/status");j(h)}catch(h){a.error(`Tailscale failed: ${h.message}`)}},_=i.about||{version:"3.0.4",homepage:"https://github.com/DrB0rk/BizarHarness",license:"MIT"},[f,E]=r.useState(z.getToken()),[G,D]=r.useState(null),[V,se]=r.useState("");r.useEffect(()=>{let h=!1;return(async()=>{try{const O=await z.probeAuthStatus();h||D(O)}catch{h||D({required:!0,loopback:!1,peer:""})}})(),()=>{h=!0}},[]);const Q=async()=>{try{const h=await z.get("/auth/reveal");se(h.token),E(h.token),z.setToken(h.token);try{await navigator.clipboard.writeText(h.token),a.success("Token copied to clipboard.")}catch{a.success("Token revealed — copy from the field below.")}}catch(h){a.error(`Reveal failed: ${h.message}`)}},B=async()=>{if(confirm("Regenerate the auth token? Anything still using the old token will start getting 401 errors immediately."))try{const h=await z.post("/auth/regenerate");se(h.token),E(h.token),z.setToken(h.token);try{await navigator.clipboard.writeText(h.token),a.success("New token generated and copied to clipboard.")}catch{a.success("New token generated — copy from the field below. Old token is now invalid.")}}catch(h){a.error(`Regenerate failed: ${h.message}`)}},Y=()=>{z.setToken(f.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(vt,{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($,{variant:"ghost",size:"sm",onClick:R,children:[e.jsx(rt,{size:14})," Reset"]}),e.jsxs($,{variant:"secondary",size:"sm",onClick:H,children:[e.jsx(he,{size:14})," Reload"]}),e.jsxs($,{variant:"primary",size:"sm",disabled:!l||c,onClick:I,children:[c?e.jsx("span",{className:"btn-spinner"}):e.jsx(bs,{size:14}),c?"Saving…":"Save"]})]})]}),e.jsxs("nav",{className:"settings-subnav","aria-label":"Settings sections",children:[e.jsx("button",{type:"button",className:ee("settings-subnav-button","settings-subnav-button-all",y===null&&"settings-subnav-button-active"),onClick:()=>F(null),title:"Show all settings sections",children:"All"}),L.map(h=>e.jsx("button",{type:"button",className:ee("settings-subnav-button",y===h.id&&"settings-subnav-button-active"),onClick:()=>F(h.id),children:h.label},h.id))]}),e.jsxs("div",{className:ee("settings-grid",y&&"settings-grid-filtered"),"data-active-section":y||void 0,children:[y&&e.jsxs("div",{className:"settings-filter-banner",children:[e.jsxs("span",{children:["Showing only ",e.jsx("strong",{children:(J=L.find(h=>h.id===y))==null?void 0:J.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:y===null||y==="theme"?"block":"none"},children:e.jsxs(ie,{id:"settings-theme","data-section":"theme",children:[e.jsxs(re,{children:[e.jsx(qa,{size:14})," Theme"]}),e.jsx(ce,{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:Zi.map(h=>e.jsxs("button",{type:"button",className:ee("theme-preset",i.theme.accent===h.accent&&"theme-preset-active"),onClick:()=>g({accent:h.accent}),title:h.name,children:[e.jsx("span",{className:"theme-preset-swatch",style:{background:h.accent}}),e.jsx("span",{className:"theme-preset-name",children:h.name})]},h.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:Ji.map(({id:h,label:O,Icon:U})=>{const A=i.theme.mode===h;return e.jsxs("button",{type:"button",className:ee("theme-card",A&&"theme-card-active"),onClick:()=>g({mode:h}),children:[e.jsx(U,{size:16}),e.jsx("span",{className:"theme-card-label",children:O}),e.jsx("span",{className:ee("theme-card-swatch",`theme-card-swatch-${h}`)})]},h)})})]}),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:h=>g({accent:h.target.value}),"aria-label":"Accent color"}),e.jsx("input",{type:"text",className:"input",value:i.theme.accent,onChange:h=>g({accent:h.target.value})})]})]}),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:h=>g({success:h.target.value}),"aria-label":"Success color"}),e.jsx("input",{type:"text",className:"input",value:i.theme.success,onChange:h=>g({success:h.target.value})})]})]}),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:h=>g({warning:h.target.value}),"aria-label":"Warning color"}),e.jsx("input",{type:"text",className:"input",value:i.theme.warning,onChange:h=>g({warning:h.target.value})})]})]}),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:h=>g({error:h.target.value}),"aria-label":"Error color"}),e.jsx("input",{type:"text",className:"input",value:i.theme.error,onChange:h=>g({error:h.target.value})})]})]}),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:h=>g({info:h.target.value}),"aria-label":"Info color"}),e.jsx("input",{type:"text",className:"input",value:i.theme.info,onChange:h=>g({info:h.target.value})})]})]})]}),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:h=>g({fontFamily:h.target.value}),children:er.map(h=>e.jsx("option",{value:h,children:h},h))})]}),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:h=>g({fontSize:Number(h.target.value)})})]}),e.jsxs("label",{className:"checkbox-row","data-setting-id":"theme.compactMode",children:[e.jsx("input",{type:"checkbox",checked:i.theme.compactMode,onChange:h=>g({compactMode:h.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:h=>g({animations:h.target.checked})}),e.jsx("span",{children:"Enable animations"})]})]})}),e.jsx("div",{"data-section":"updates",style:{display:y===null||y==="updates"?"block":"none"},children:e.jsx(nr,{})}),e.jsx("div",{"data-section":"layout",style:{display:y===null||y==="layout"?"block":"none"},children:e.jsxs(ie,{id:"settings-layout","data-section":"layout",children:[e.jsxs(re,{children:[e.jsx(Wa,{size:14})," UI layout"]}),e.jsx(ce,{children:"Choose how the dashboard's navigation is presented."}),e.jsx("div",{className:"layout-row","data-setting-id":"ui.layout",children:ar.map(h=>e.jsx("button",{type:"button",className:ee("layout-card",i.ui.layout===h.id&&"layout-card-active"),onClick:()=>w({layout:h.id}),children:e.jsx("span",{className:"layout-card-label",children:h.label})},h.id))}),e.jsxs("label",{className:"checkbox-row","data-setting-id":"ui.showHeader",children:[e.jsx("input",{type:"checkbox",checked:i.ui.showHeader,onChange:h=>w({showHeader:h.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:h=>w({showStatusBar:h.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:h=>w({defaultTab:h.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:y===null||y==="general"?"block":"none"},children:e.jsxs(ie,{id:"settings-general","data-section":"general",children:[e.jsx(re,{children:"General"}),e.jsx(ce,{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:h=>T("defaultAgent",h.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:h=>T("defaultModel",h.target.value)})]})]})}),e.jsx("div",{"data-section":"service",style:{display:y===null||y==="service"?"block":"none"},children:e.jsxs(ie,{id:"settings-service","data-section":"service",children:[e.jsxs(re,{children:[e.jsx(ss,{size:14})," Service"]}),e.jsx(ce,{children:"Background daemon that runs schedules."}),e.jsx("div",{"data-setting-id":"service.enabled",children:u?e.jsxs("div",{className:"service-card",children:[e.jsxs("p",{children:["Status: ",e.jsx("strong",{children:u!=null&&u.settings.enabled?"enabled":"disabled"})," ","· Tailscale installed: ",e.jsx("strong",{children:u.installed?"yes":"no"})," ","· authenticated: ",e.jsx("strong",{children:u.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:y===null||y==="tailscale"?"block":"none"},children:e.jsxs(ie,{id:"settings-tailscale","data-section":"tailscale",children:[e.jsxs(re,{children:[e.jsx(Ka,{size:14})," Tailscale serve"]}),e.jsx(ce,{children:"Expose the dashboard over your Tailscale network."}),u?e.jsxs(e.Fragment,{children:[e.jsxs("p",{children:["Installed: ",e.jsx("strong",{children:u.installed?"yes":"no"})," ",u.version&&e.jsxs("span",{className:"muted",children:["(",u.version,")"]})]}),e.jsxs("p",{children:["Authenticated: ",e.jsx("strong",{children:u.authenticated?"yes":"no"})]}),e.jsxs("p",{children:["Serve enabled: ",e.jsx("strong",{children:u.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:m.port,onChange:h=>d(O=>({...O,port:Number(h.target.value)||4321}))})]}),e.jsxs("div",{className:"task-form-field",children:[e.jsx("label",{className:"field-label",children:"Use HTTPS"}),e.jsx("input",{type:"checkbox",checked:m.https,onChange:h=>d(O=>({...O,https:h.target.checked}))})]})]}),e.jsx($,{variant:"primary",onClick:q,children:u.settings.enabled?"Disable serve":"Enable serve"})]}):e.jsx("p",{className:"muted",children:"Loading Tailscale status…"})]})}),e.jsx("div",{"data-section":"notifications",style:{display:y===null||y==="notifications"?"block":"none"},children:e.jsxs(ie,{id:"settings-notifications","data-section":"notifications",children:[e.jsx(re,{children:"Notifications"}),e.jsx(ce,{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:h=>v({onAgentComplete:h.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:h=>v({onPlanApproval:h.target.checked})}),e.jsx("span",{children:"Notify when a plan needs approval"})]})]})}),e.jsx("div",{"data-section":"auth",style:{display:y===null||y==="auth"?"block":"none"},children:e.jsxs(ie,{id:"settings-auth","data-section":"auth",children:[e.jsxs(re,{children:[e.jsx(Qa,{size:14})," Authentication"]}),e.jsx(ce,{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:G?G.required?"yes":"no":"probing…"})]}),e.jsxs("p",{style:{margin:"4px 0"},children:["Connection:"," ",e.jsx("strong",{children:G?G.loopback?"loopback (auto-trusted)":"remote":"probing…"})]}),e.jsxs("p",{style:{margin:"4px 0"},children:["Peer address:"," ",G!=null&&G.peer?e.jsx("code",{children:G.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:f,onChange:h=>E(h.target.value),placeholder:"Paste token from server stderr or another browser",spellCheck:!1,autoComplete:"off"}),e.jsxs("div",{className:"task-form-row",style:{marginTop:8},children:[e.jsxs($,{variant:"secondary",size:"sm",onClick:Y,children:[e.jsx(Zs,{size:14})," Save token"]}),e.jsxs($,{variant:"ghost",size:"sm",onClick:Q,children:[e.jsx(As,{size:14})," Reveal & copy server token"]}),e.jsxs($,{variant:"ghost",size:"sm",onClick:B,children:[e.jsx(rt,{size:14})," Regenerate"]})]}),V?e.jsxs("p",{className:"muted",style:{fontSize:12,marginTop:8},children:["Last revealed token (one-time): ",e.jsx("code",{className:"mono",children:V})]}):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:y===null||y==="agents"?"block":"none"},children:e.jsxs(ie,{id:"settings-agents","data-section":"agents",children:[e.jsxs(re,{children:[e.jsx(ss,{size:14})," Agent Behavior"]}),e.jsx(ce,{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:((X=i.agents)==null?void 0:X.maxParallel)??6,onChange:h=>k({maxParallel:Math.max(1,Math.min(20,parseInt(h.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:((ae=i.agents)==null?void 0:ae.stuckThresholdMs)??6e5,onChange:h=>k({stuckThresholdMs:Math.max(6e4,Math.min(36e5,parseInt(h.target.value,10)||6e5))})})]}),e.jsxs("label",{className:"checkbox-row","data-setting-id":"agents.autoRestart",children:[e.jsx("input",{type:"checkbox",checked:!!((ue=i.agents)!=null&&ue.autoRestart),onChange:h=>k({autoRestart:h.target.checked})}),e.jsx("span",{children:"Auto-restart stuck agents"})]})]})}),e.jsx("div",{"data-section":"dashboard",style:{display:y===null||y==="dashboard"?"block":"none"},children:e.jsxs(ie,{id:"settings-dashboard","data-section":"dashboard",children:[e.jsxs(re,{children:[e.jsx(rs,{size:14})," Dashboard"]}),e.jsxs(ce,{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:h=>S({autoLaunchWeb:h.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:h=>S({projectsDirectory:h.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
|
|
307
|
+
/srv/projects`,value:(i.dashboard.allowedRoots??[]).join(`
|
|
308
|
+
`),onChange:h=>{const O=h.target.value.split(`
|
|
309
|
+
`).map(U=>U.trim()).filter(Boolean);S({allowedRoots:O})}}),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 h=(i.dashboard.allowedRoots??[]).join(`
|
|
310
|
+
`).split(`
|
|
311
|
+
`),O=[];return h.forEach((U,A)=>{U.trim()&&(/^\/|^[A-Za-z]:/.test(U)||O.push({key:`noabs-${A}`,msg:e.jsxs("p",{style:{color:"var(--warning)",fontSize:11,marginTop:2},children:["Line ",A+1,': "',U,'" — should be absolute (start with / or a drive letter).']})}),U.includes("..")&&O.push({key:`dots-${A}`,msg:e.jsxs("p",{style:{color:"var(--error)",fontSize:11,marginTop:2},children:["Line ",A+1,': "',U,`" — contains '..' (server will reject this).`]})}))}),O.map(U=>U.msg)})()]})]})}),e.jsx("div",{"data-section":"background",style:{display:y===null||y==="background"?"block":"none"},children:e.jsxs(ie,{id:"settings-background","data-section":"background",children:[e.jsxs(re,{children:[e.jsx(ss,{size:14})," Background Agents"]}),e.jsx(ce,{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:x.maxConcurrentInstances??8,onChange:h=>b(O=>({...O,maxConcurrentInstances:Math.max(1,Math.min(32,parseInt(h.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:x.backgroundToolCallCap??500,onChange:h=>b(O=>({...O,backgroundToolCallCap:Math.max(1,Math.min(5e3,parseInt(h.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:x.backgroundStallTimeoutMs??18e4,onChange:h=>b(O=>({...O,backgroundStallTimeoutMs:Math.max(1e4,Math.min(6e5,parseInt(h.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:x.backgroundThinkingLoopTimeoutMs??3e5,onChange:h=>b(O=>({...O,backgroundThinkingLoopTimeoutMs:Math.max(3e4,Math.min(9e5,parseInt(h.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:x.backgroundMaxInterventions??1,onChange:h=>b(O=>({...O,backgroundMaxInterventions:Math.max(1,Math.min(3,parseInt(h.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($,{variant:"secondary",size:"sm",onClick:async()=>{try{await z.put("/settings/plugin-options",x),a.success("Saved — restart opencode for changes to take effect.")}catch(h){a.error(`Save failed: ${h.message}`)}},children:[e.jsx(bs,{size:14})," Save plugin options"]}),e.jsx($,{variant:"secondary",size:"sm",onClick:async()=>{try{const O=await(await fetch("/api/background/cleanup",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({maxAgeDays:7})})).json();a.success(`Cleaned up ${O.deleted} old instances.`)}catch(h){a.error(`Cleanup failed: ${h.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:y===null||y==="system-llm"?"block":"none"},children:e.jsxs(ie,{id:"settings-system-llm","data-section":"system-llm",children:[e.jsxs(re,{children:[e.jsx(Oe,{size:14})," System LLM API"]}),e.jsx(ce,{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:!!((W=i.systemLlm)!=null&&W.enabled),onChange:h=>{const O=i.systemLlm||{enabled:!0,provider:"opencode",model:"opencode/deepseek-v4-flash-free"};T("systemLlm",{...O,enabled:h.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:((C=i.systemLlm)==null?void 0:C.provider)||"opencode",onChange:h=>{const O=i.systemLlm||{enabled:!0,provider:"opencode",model:"opencode/deepseek-v4-flash-free"};T("systemLlm",{...O,provider:h.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:((P=i.systemLlm)==null?void 0:P.model)||"opencode/deepseek-v4-flash-free",onChange:h=>{const O=i.systemLlm||{enabled:!0,provider:"opencode",model:"opencode/deepseek-v4-flash-free"};T("systemLlm",{...O,model:h.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(tr,{}),e.jsx("div",{style:{display:y===null||y==="activity-log"?"block":"none"},children:e.jsx("div",{"data-section":"activity-log",style:{display:y===null||y==="activity-log"?"block":"none"},children:e.jsx("section",{id:"settings-activity-log","data-section":"activity-log",className:"settings-section-wrap",children:e.jsx(ir,{})})})}),e.jsx("div",{style:{display:y===null||y==="about"?"block":"none"},children:e.jsx("div",{"data-section":"about",style:{display:y===null||y==="about"?"block":"none"},children:e.jsxs(ie,{id:"settings-about","data-section":"about",children:[e.jsxs(re,{children:[e.jsx(Ts,{size:14})," About"]}),e.jsx(ce,{children:"Build metadata."}),e.jsxs("dl",{className:"about-table",children:[e.jsx("dt",{children:"Version"}),e.jsx("dd",{className:"mono",children:_.version}),e.jsx("dt",{children:"Homepage"}),e.jsx("dd",{children:e.jsx("a",{href:_.homepage,target:"_blank",rel:"noopener noreferrer",children:_.homepage})}),e.jsx("dt",{children:"License"}),e.jsx("dd",{children:_.license})]})]})})})]})}function ir(){const s=de(),[t,a]=r.useState([]),[i,n]=r.useState(new Set),[l,o]=r.useState(!0),[c,p]=r.useState(""),[u,j]=r.useState(!0),m=r.useCallback(async()=>{o(!0);try{const[w,T]=await Promise.all([z.get("/activity"),z.get("/activity/hidden")]);a(Array.isArray(w.items)?w.items:[]),n(new Set(T.hidden||[]))}catch(w){s.error(`Load failed: ${w.message}`)}finally{o(!1)}},[s]);r.useEffect(()=>{m()},[m]);const d=(w,T)=>{const v=`${w.kind||""}|${w.ts||""}|${w.slug||""}|${T}`;let k=0;for(let L=0;L<v.length;L++)k=(k<<5)-k+v.charCodeAt(L)|0;return Math.abs(k).toString(16).padStart(8,"0").slice(0,16)},x=async()=>{try{await z.del("/activity/hide"),n(new Set),s.success("All hidden activity restored.")}catch(w){s.error(`Restore failed: ${w.message}`)}},b=async w=>{try{await z.del(`/activity/hide/${encodeURIComponent(w)}`);const T=new Set(i);T.delete(w),n(T)}catch(T){s.error(`Restore failed: ${T.message}`)}},g=t.filter((w,T)=>{const v=d(w,T);if(!u&&i.has(v))return!1;if(!c)return!0;const k=c.toLowerCase();return[w.kind,w.slug,w.message].some(L=>typeof L=="string"&&L.toLowerCase().includes(k))});return e.jsxs(ie,{id:"settings-diagnostics","data-section":"diagnostics",children:[e.jsxs(re,{children:[e.jsx(Re,{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($,{variant:"ghost",size:"sm",style:{marginLeft:"auto"},onClick:m,title:"Reload",children:e.jsx(he,{size:12})})]}),e.jsxs(ce,{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(Pe,{size:12}),e.jsx("input",{type:"text",className:"input",placeholder:"Filter by kind, slug, or message…",value:c,onChange:w=>p(w.target.value)})]}),e.jsxs("label",{className:"activity-log-toggle",children:[e.jsx("input",{type:"checkbox",checked:u,onChange:w=>j(w.target.checked)}),"Show hidden"]}),e.jsxs($,{variant:"ghost",size:"sm",disabled:i.size===0,onClick:x,title:"Restore all hidden items to the Overview",children:[e.jsx(Je,{size:12})," Restore all"]})]}),l?e.jsx("div",{className:"muted",style:{padding:"12px 0",fontSize:12},children:"Loading…"}):g.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:g.slice(0,200).map((w,T)=>{const v=d(w,T),k=i.has(v);return e.jsxs("tr",{className:ee(k&&"activity-log-row-hidden"),children:[e.jsx("td",{className:"activity-log-kind",children:w.kind||"activity"}),e.jsx("td",{className:"activity-log-detail",children:w.message||w.slug||"—"}),e.jsx("td",{className:"activity-log-time mono",children:w.ts?new Date(w.ts).toLocaleString():"—"}),e.jsx("td",{children:k?e.jsx($,{variant:"ghost",size:"sm",onClick:()=>b(v),title:"Restore to Overview",children:e.jsx(Je,{size:12})}):e.jsx("span",{className:"activity-log-state-tag",children:"shown"})})]},`${w.ts}-${T}`)})})]}),g.length>200&&e.jsxs("div",{className:"muted",style:{fontSize:11,padding:"8px 0"},children:["Showing first 200 of ",g.length,"."]})]})]})}function rr({snapshot:s,refreshSnapshot:t}){const a=de(),i=$e(),[n,l]=r.useState(Array.isArray(s.mods)?s.mods:[]),[o,c]=r.useState(!0),[p,u]=r.useState(null),[j,m]=r.useState([]),[d,x]=r.useState(null),[b,g]=r.useState(!1),[w,T]=r.useState(null),[v,k]=r.useState(!1),[L,y]=r.useState({}),M=async()=>{var f,E,G;k(!0);try{const D=await z.get("/mods/registry");T({source:((f=D.registry)==null?void 0:f.source)||"",version:(E=D.registry)==null?void 0:E.version,updatedAt:(G=D.registry)==null?void 0:G.updatedAt,mods:D.mods||[]})}catch(D){T({source:"",mods:[],error:D.message})}finally{k(!1)}},F=async f=>{y(E=>({...E,[f]:!0}));try{const E=await z.post("/mods",{id:f});l(G=>[...G.filter(D=>D.id!==E.id),E]),a.success(`Mod "${E.id}" installed from registry.`),await t()}catch(E){a.error(`Install failed: ${E.message}`)}finally{y(E=>({...E,[f]:!1}))}},S=async(f,E=!1)=>{y(G=>({...G,[f]:!0}));try{const G=await z.post(`/mods/${encodeURIComponent(f)}/upgrade`,{backup:E});l(V=>[...V.filter(se=>se.id!==G.mod.id),G.mod]);const D=G.backupPath?` (backup at ${G.backupPath})`:"";a.success(`Mod "${f}" upgraded v${G.from} → v${G.to}${D}.`),await t()}catch(G){a.error(`Upgrade failed: ${G.message}`)}finally{y(G=>({...G,[f]:!1}))}},I=async()=>{try{const f=await z.get("/mods");l(f.mods||[]);try{const E=await z.get("/mods/views");m(E.views||[])}catch{m([])}}catch(f){a.error(`Mods load failed: ${f.message}`)}finally{c(!1)}};r.useEffect(()=>{I()},[]),r.useEffect(()=>{Array.isArray(s.mods)&&s.mods!==n&&l(s.mods)},[s.mods]);const H=()=>{let f=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:E=>f=E,className:"input",type:"text",placeholder:"/path/to/my-mod",autoFocus:!0})]}),footer:e.jsxs("div",{className:"modal-footer-actions",children:[e.jsx($,{variant:"ghost",onClick:()=>i.close(),children:"Cancel"}),e.jsx($,{variant:"primary",onClick:async()=>{const E=((f==null?void 0:f.value)||"").trim();if(!E){a.warning("Path is required.");return}try{const G=await z.post("/mods",{path:E});l(D=>[...D,G]),a.success(`Mod "${G.id}" installed.`),i.close(),await t()}catch(G){a.error(`Install failed: ${G.message}`)}},children:"Install"})]})})},R=async f=>{if(confirm(`Uninstall mod "${f}"? This removes the folder from ~/.config/bizar/mods/.`))try{await z.del(`/mods/${encodeURIComponent(f)}`),l(E=>E.filter(G=>G.id!==f)),p===f&&u(null),a.success("Mod uninstalled.")}catch(E){a.error(`Uninstall failed: ${E.message}`)}},q=async f=>{try{const E=await z.put(`/mods/${encodeURIComponent(f.id)}`,{enabled:!f.enabled});l(G=>G.map(D=>D.id===f.id?E:D)),a.success(`Mod ${E.enabled?"enabled":"disabled"}.`)}catch(E){a.error(`Toggle failed: ${E.message}`)}},_=n.find(f=>f.id===p)||null;return o?e.jsx("div",{className:"view-loading",children:e.jsx(fe,{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(ws,{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($,{variant:"secondary",size:"sm",onClick:I,children:[e.jsx(he,{size:14})," Refresh"]}),e.jsxs($,{variant:"primary",size:"sm",onClick:H,children:[e.jsx(Ne,{size:14})," Install mod"]})]})]}),n.length===0?e.jsx(ze,{icon:e.jsx(ws,{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(f=>e.jsxs("div",{className:ee("mod-list-item",p===f.id&&"mod-list-item-active"),onClick:()=>u(f.id),children:[e.jsxs("div",{className:"mod-list-item-head",children:[e.jsxs("div",{children:[e.jsx("div",{className:"mod-list-item-name",children:f.name}),e.jsxs("div",{className:"mod-list-item-meta",children:["v",f.version," · ",f.type," · ",f.author]})]}),e.jsxs("div",{className:"mod-list-item-actions",onClick:E=>E.stopPropagation(),children:[e.jsx("button",{type:"button",className:"icon-btn","aria-label":"Toggle enabled",title:f.enabled?"Disable":"Enable",onClick:()=>q(f),children:e.jsx(bt,{size:12})}),e.jsx("button",{type:"button",className:"icon-btn icon-btn-danger","aria-label":"Uninstall",title:"Uninstall",onClick:()=>R(f.id),children:e.jsx(Te,{size:12})})]})]}),e.jsx("div",{className:"mod-list-item-desc ellipsis-2",title:f.description,children:f.description}),e.jsx("div",{className:"mod-list-item-status",children:e.jsx("span",{className:`mod-mini-pill ${f.enabled?"mod-mini-pill-on":"mod-mini-pill-off"}`,children:f.enabled?"enabled":"disabled"})})]},f.id))}),_&&e.jsx(lr,{mod:_})]}),e.jsxs(ie,{className:"mods-registry-card",children:[e.jsxs("div",{className:"mods-registry-head",onClick:()=>{!w&&!v&&M(),g(f=>!f)},children:[e.jsx(rs,{size:14}),e.jsx("span",{className:"mods-registry-title",children:"Mod registry"}),e.jsx("span",{className:"muted",style:{fontSize:11},children:w!=null&&w.mods?`${w.mods.length} available`:"click to browse"}),e.jsx("span",{className:"mods-registry-spacer"}),b?e.jsx(Le,{size:14}):e.jsx(_e,{size:14})]}),b&&e.jsx("div",{className:"mods-registry-body",children:v?e.jsx("div",{className:"muted",style:{padding:12,fontSize:12},children:"Loading registry…"}):w!=null&&w.error?e.jsxs("div",{className:"mods-registry-error",children:[e.jsx(Ss,{size:12})," Could not load registry: ",w.error]}):!w||w.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:[w.source&&e.jsxs("div",{className:"muted",style:{fontSize:11,marginBottom:8},children:["Source: ",e.jsx("code",{children:w.source})]}),e.jsx("div",{className:"mods-registry-grid",children:w.mods.map(f=>{const E=n.some(D=>D.id===f.id),G=!!L[f.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:f.name}),f.latest&&e.jsxs("span",{className:ee("mod-registry-version",f.upgradeAvailable&&"mod-registry-version-upgrade"),children:["v",f.latest,f.upgradeAvailable?" ↑":""]})]}),f.description&&e.jsx("div",{className:"mod-registry-card-desc",children:f.description}),e.jsxs("div",{className:"mod-registry-card-meta",children:[f.author&&e.jsxs("span",{className:"muted",children:["by ",f.author]}),f.homepage&&e.jsx("a",{href:f.homepage,target:"_blank",rel:"noopener noreferrer",className:"mod-registry-link",children:"homepage"})]}),(f.permissions||[]).length>0&&e.jsxs("div",{className:"mod-registry-perms",children:[e.jsx(Ss,{size:10}),(f.permissions||[]).slice(0,4).map(D=>e.jsx("span",{className:"mod-registry-perm",children:D},D)),(f.permissions||[]).length>4&&e.jsxs("span",{className:"mod-registry-perm-more",children:["+",f.permissions.length-4]})]}),e.jsxs("div",{className:"mod-registry-card-actions",children:[!E&&e.jsx($,{variant:"primary",size:"sm",disabled:G,onClick:()=>F(f.id),title:"Install from registry",children:G?e.jsx(fe,{size:"sm"}):e.jsxs(e.Fragment,{children:[e.jsx(Qe,{size:12})," Install"]})}),E&&f.upgradeAvailable&&e.jsx($,{variant:"primary",size:"sm",disabled:G,onClick:()=>S(f.id),title:`Upgrade from v${f.installedVersion||"?"} to v${f.upgradeAvailable}`,children:G?e.jsx(fe,{size:"sm"}):e.jsxs(e.Fragment,{children:[e.jsx(Qe,{size:12})," Upgrade to v",f.upgradeAvailable]})}),E&&!f.upgradeAvailable&&e.jsxs($,{variant:"ghost",size:"sm",disabled:!0,title:`Installed v${f.installedVersion||"?"}`,children:["Installed v",f.installedVersion||"?"]})]})]},f.id)})})]})})]}),j.length>0&&e.jsxs(ie,{className:"mod-views-hint",children:[e.jsxs(re,{children:[e.jsx(rs,{size:14})," Mod views"]}),e.jsxs(ce,{children:[j.length," mod-supplied view",j.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:()=>x(null),children:e.jsx(Ee,{size:14})})]}),e.jsx("iframe",{src:d,className:"mod-iframe",title:"Mod view",sandbox:"allow-scripts allow-same-origin allow-forms allow-popups"})]})]})}function lr({mod:s}){const t=de(),[a,i]=r.useState(null),[n,l]=r.useState(!1),[o,c]=r.useState(!1),[p,u]=r.useState(null),j=async()=>{l(!0);try{const d=await z.get(`/mods/${s.id}/instructions`);i(d),c(!0)}catch(d){t.error(`Failed to load instructions: ${d.message}`)}finally{l(!1)}},m=async()=>{try{const d=await z.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 j()}catch(d){t.error(`Reinstall failed: ${d.message}`)}};return e.jsxs(ie,{className:"mod-details",children:[e.jsxs(re,{children:[e.jsx(Xs,{size:14})," Mod details — ",s.name]}),e.jsx(ce,{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&&j(),c(d=>!d)},children:[e.jsx($a,{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(Le,{size:14}):e.jsx(_e,{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(sn,{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:()=>u(x=>x===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]})]}),p===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(is,{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:()=>u(x=>x===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]})]}),p===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(zt,{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:()=>u(x=>x===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]})]}),p===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($,{variant:"ghost",size:"sm",onClick:m,children:[e.jsx(he,{size:11})," Reinstall from mod folder"]})})]})]})]})}function or({viewId:s,reloadKey:t,setActiveTab:a}){const i=de(),[n,l]=r.useState(null),[o,c]=r.useState(!0),[p,u]=r.useState(0);if(r.useEffect(()=>{let j=!1;return(async()=>{try{const m=await z.get("/mods/views");if(j)return;const d=(m.views||[]).find(x=>x.id===s);l(d||null)}catch(m){i.error(`Failed to load mod view: ${m.message}`)}finally{j||c(!1)}})(),()=>{j=!0}},[s,i]),o)return e.jsx(ze,{title:"Loading mod view…"});if(!n)return e.jsx(ze,{title:"Mod view not found",message:`No view with id "${s}" is currently installed.`,action:e.jsx($,{onClick:()=>a("mods"),variant:"primary",size:"sm",children:"Open Mods"})});if(n.kind==="iframe"){const j=`/api/mods/${n.modId}/web/index.html?t=${p+(t||0)}`;return e.jsxs("div",{className:"mod-view-iframe-pane",children:[e.jsxs("div",{className:"mod-view-iframe-header",children:[e.jsxs("span",{className:"mod-view-iframe-label",children:[e.jsx(rs,{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($,{variant:"ghost",size:"sm",onClick:()=>u(m=>m+1),title:"Reload this view",children:[e.jsx(he,{size:11})," Reload"]}),e.jsx("a",{href:j,target:"_blank",rel:"noopener noreferrer",className:"icon-btn",title:"Open in new tab",children:e.jsx(Ms,{size:12})})]})]}),e.jsx("iframe",{src:j,className:"mod-view-iframe",title:n.label},p+(t||0))]})}if(n.component){const j=n.component,m=n.modId,d=r.lazy(()=>xa(()=>import(`/api/mods/${encodeURIComponent(m)}/views/${encodeURIComponent(j)}`),[]).then(x=>({default:x.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(Hs,{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(cr,{modId:n.modId,component:n.component,children:e.jsx(r.Suspense,{fallback:e.jsxs("div",{style:{padding:24},children:[e.jsx(fe,{size:"md"})," ",e.jsx("span",{className:"muted",children:"Loading mod view…"})]}),children:e.jsx(d,{})})})})]})}return e.jsxs(ie,{children:[e.jsxs(re,{children:[e.jsx(Hs,{size:14})," ",n.label]}),e.jsxs(ce,{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($,{variant:"secondary",size:"sm",onClick:()=>a("mods"),children:"Open Mods page"})})]})}class cr extends r.Component{constructor(){super(...arguments);Is(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(we,{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 dr=["interval","cron","once"],hr=["command","agent","webhook"],Ks=[{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)"}],mr=Array.from({length:12},(s,t)=>t*5),tt=Array.from({length:24},(s,t)=>({value:t,label:t===0?"12 AM":t<12?`${t} AM`:t===12?"12 PM":`${t-12} PM`})),at=[{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"}],Ot=[{value:"s",label:"seconds"},{value:"m",label:"minutes"},{value:"h",label:"hours"},{value:"d",label:"days"}];function Ft(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 ur(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 xr(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"?Ft(s.schedule):null,a=s.type==="interval"?ur(s.schedule):null,i=s.timezone||"UTC",n=Ks.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"?pr(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 pr(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 gr(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=at.find(j=>j.value===s.cronDow))==null?void 0:a.label)||"",c=((i=tt.find(j=>j.value===s.cronHour))==null?void 0:i.label)||`${s.cronHour}`,p=String(s.cronMinute).padStart(2,"0"),u=o==="Every day"?`Every day at ${c.replace(" ","")} (min ${p})`:`Every ${o} at ${c.replace(" ","")} (min ${p})`;return{schedule:l,humanLabel:s.humanLabel||u}}if(s.type==="interval"){const l=((n=Ot.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 jr({snapshot:s,refreshSnapshot:t}){var d;const a=de(),i=$e(),[n,l]=r.useState(s.schedules||[]),[o,c]=r.useState(!s.schedules),p=async()=>{try{const x=await z.get("/projects/active/schedules");l(x.schedules||[])}catch(x){a.error(`Schedules load failed: ${x.message}`)}finally{c(!1)}};r.useEffect(()=>{var x;if((x=s.schedules)!=null&&x.length||s.schedules){l(s.schedules||[]),c(!1);return}p()},[s.schedules]);const u=x=>{i.open({title:x?`Edit schedule: ${x.name}`:"New schedule",width:640,children:e.jsx(fr,{initial:x,onClose:i.close,onSubmitted:async b=>{l(g=>{const w=g.findIndex(v=>v.id===b.id);if(w===-1)return[...g,b];const T=g.slice();return T[w]=b,T}),a.success(x?"Schedule updated.":"Schedule created."),i.close(),await t()},onError:b=>a.error(b)})})},j=async x=>{var b;try{const g=await z.post(`/schedules/${encodeURIComponent(x.id)}/run`);a.success(g.ok?"Schedule ran.":`Run failed: ${((b=g.runResult)==null?void 0:b.error)||"unknown"}`),await p()}catch(g){a.error(`Run failed: ${g.message}`)}},m=async x=>{if(confirm(`Delete schedule "${x.name}"?`))try{await z.del(`/schedules/${encodeURIComponent(x.id)}`),l(b=>b.filter(g=>g.id!==x.id)),a.success("Schedule deleted.")}catch(b){a.error(`Delete failed: ${b.message}`)}};return o?e.jsx("div",{className:"view-loading",children:e.jsx(fe,{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(ys,{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($,{variant:"secondary",size:"sm",onClick:p,children:[e.jsx(he,{size:14})," Refresh"]}),e.jsxs($,{variant:"primary",size:"sm",onClick:()=>u(),children:[e.jsx(Ne,{size:14})," New schedule"]})]})]}),n.length===0?e.jsx(ze,{icon:e.jsx(ys,{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(x=>{var b;return e.jsxs(ie,{className:"schedule-card",children:[e.jsxs("div",{className:"schedule-card-head",children:[e.jsxs("div",{children:[e.jsx(re,{children:x.name}),e.jsxs(ce,{children:[e.jsx("code",{children:x.type})," ·"," ",e.jsx("span",{title:x.schedule,children:vr(x)||x.schedule}),x.timezone&&x.timezone!=="UTC"?e.jsxs(e.Fragment,{children:[" · ",e.jsx("code",{children:x.timezone})]}):null," · ",e.jsx("span",{className:x.enabled?"status-on":"status-neutral",children:x.enabled?"enabled":"disabled"})]})]}),e.jsxs("div",{className:"schedule-card-actions",children:[e.jsxs($,{variant:"secondary",size:"sm",onClick:()=>u(x),children:[e.jsx($s,{size:12})," Edit"]}),e.jsxs($,{variant:"secondary",size:"sm",onClick:()=>j(x),children:[e.jsx(Sa,{size:12})," Run now"]}),e.jsx("button",{type:"button",className:"icon-btn icon-btn-danger","aria-label":"Delete",title:"Delete",onClick:()=>m(x),children:e.jsx(Te,{size:12})})]})]}),e.jsxs("div",{className:"schedule-card-action",children:[e.jsx("span",{className:"muted",children:"action:"})," ",e.jsxs("code",{children:[x.action.type," ",x.action.target]}),x.action.type==="agent"&&x.action.prompt&&e.jsxs("div",{className:"schedule-card-prompt",children:[e.jsx("span",{className:"muted",children:"prompt:"})," ",x.action.prompt]})]}),((b=x.budgetCheck)==null?void 0:b.skipIfBudgetLow)&&e.jsxs("div",{className:"schedule-card-budget",children:[e.jsx("span",{className:"muted",children:"budget gate:"})," ","skip if concurrent ≥ ",x.budgetCheck.maxConcurrent??6]}),e.jsxs("div",{className:"schedule-card-times",children:[e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"last"})," ",x.lastRun?ye(x.lastRun):"—",x.lastResult&&e.jsx("span",{className:`tag ${pt(x.lastResult)}`,children:x.lastResult}),x.lastError&&e.jsxs("span",{className:"muted schedule-card-error",title:x.lastError,children:[" ","— ",gt(x.lastError,80)]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"next"})," ",x.nextRun?e.jsx("span",{title:new Date(x.nextRun).toISOString(),children:yr(x.nextRun,x.timezone)}):"—",x.nextRun&&e.jsxs("span",{className:"muted",children:[" · ",ye(x.nextRun)]})]})]}),x.history&&x.history.length>0&&e.jsxs("details",{className:"schedule-card-history",children:[e.jsxs("summary",{children:[e.jsx(ns,{size:12})," ",x.history.length," run",x.history.length===1?"":"s"]}),e.jsx("ul",{children:x.history.slice(-10).reverse().map((g,w)=>e.jsxs("li",{children:[e.jsx("span",{className:"tabular-nums muted",children:ye(g.ts)})," ",e.jsx("span",{className:`tag ${pt(g.result)}`,children:g.result}),g.error&&e.jsxs("span",{className:"muted",children:[" — ",gt(g.error,80)]})]},w))})]})]},x.id)})})]})}function fr({initial:s,onClose:t,onSubmitted:a,onError:i}){const[n,l]=r.useState(()=>xr(s)),[o,c]=r.useState(!1),p=r.useMemo(()=>Ks.some(m=>m.value===n.timezone)?n.timezone:"Other…",[n.timezone]),u=(m,d)=>{l(x=>({...x,[m]:d}))},j=async m=>{m.preventDefault();const d=n.name.trim();if(!d){i("Name is required.");return}const x=gr(n);if(!x.schedule){i("Schedule value is required.");return}if(!n.actionTarget.trim()){i("Action target is required.");return}const b=n.timezone==="Other…"?n.customTimezone.trim():n.timezone,g={type:n.actionType,target:n.actionTarget.trim()};n.actionType==="agent"&&n.actionPrompt.trim()&&(g.prompt=n.actionPrompt.trim());const w={name:d,type:n.type,schedule:x.schedule,timezone:b||"UTC",action:g,budgetCheck:{maxConcurrent:n.maxConcurrent,skipIfBudgetLow:n.skipIfBudgetLow},enabled:n.enabled};c(!0);try{const T=s?await z.put(`/schedules/${encodeURIComponent(s.id)}`,w):await z.post("/schedules",w);await a(T)}catch(T){i(`${s?"Update":"Create"} failed: ${T.message}`)}finally{c(!1)}};return e.jsxs("form",{className:"schedule-form",onSubmit:j,children:[e.jsx("label",{className:"field-label",children:"Name"}),e.jsx("input",{className:"input",type:"text",placeholder:"Weekly code review",value:n.name,onChange:m=>u("name",m.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:m=>u("type",m.target.value),children:dr.map(m=>e.jsx("option",{value:m,children:m},m))})]})}),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:m=>u("cronDow",m.target.value),children:at.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:"Hour"}),e.jsx("select",{className:"select",value:String(n.cronHour),onChange:m=>u("cronHour",parseInt(m.target.value,10)),children:tt.map(m=>e.jsx("option",{value:String(m.value),children:m.label},m.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:m=>u("cronMinute",parseInt(m.target.value,10)),children:mr.map(m=>e.jsx("option",{value:String(m),children:String(m).padStart(2,"0")},m))})]})]})}),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:m=>u("rawCron",m.target.value),placeholder:"0 13 * * 0"})]}),e.jsxs("button",{type:"button",className:"link-btn",onClick:()=>u("showAdvanced",!n.showAdvanced),children:[e.jsx(Le,{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:m=>u("intervalN",parseInt(m.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:m=>u("intervalUnit",m.target.value),children:Ot.map(m=>e.jsx("option",{value:m.value,children:m.label},m.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:m=>u("onceAt",m.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:p,onChange:m=>u("timezone",m.target.value),children:[Ks.map(m=>e.jsx("option",{value:m.value,children:m.label},m.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:m=>u("customTimezone",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:"Action"}),e.jsx("select",{className:"select",value:n.actionType,onChange:m=>u("actionType",m.target.value),children:hr.map(m=>e.jsx("option",{value:m,children:m},m))})]}),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:m=>u("actionTarget",m.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:m=>u("actionPrompt",m.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:m=>u("skipIfBudgetLow",m.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:m=>u("maxConcurrent",parseInt(m.target.value,10)||6),disabled:!n.skipIfBudgetLow})]})]}),e.jsxs("label",{className:"checkbox-row",children:[e.jsx("input",{type:"checkbox",checked:n.enabled,onChange:m=>u("enabled",m.target.checked)}),e.jsx("span",{children:"Enabled"})]}),e.jsxs("div",{className:"modal-footer-actions",children:[e.jsx($,{variant:"ghost",type:"button",onClick:t,disabled:o,children:"Cancel"}),e.jsx($,{variant:"primary",type:"submit",disabled:o,children:s?"Save":"Create"})]})]})}function vr(s){var l,o;if(s.type!=="cron")return s.schedule;const t=Ft(s.schedule);if(!t)return s.schedule;const a=((l=at.find(c=>c.value===t.dow))==null?void 0:l.label)||"",i=((o=tt.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 pt(s){return s==="success"?"tag-success":s==="skipped"?"tag-warning":"tag-error"}function gt(s,t){return s.length<=t?s:s.slice(0,t-1)+"…"}const br=[{id:"all",label:"All",icon:Oe},{id:"shipped",label:"Shipped",icon:et},{id:"user",label:"User",icon:Lt},{id:"project",label:"Project",icon:Ie}],vs={shipped:"Shipped",user:"User",project:"Project"},kr={shipped:et,user:Lt,project:Ie};function Nr({snapshot:s,refreshSnapshot:t}){const a=de(),i=$e(),[n,l]=r.useState([]),[o,c]=r.useState({shipped:0,user:0,project:0,all:0}),[p,u]=r.useState(!0),[j,m]=r.useState("all"),[d,x]=r.useState(""),[b,g]=r.useState(null),[w,T]=r.useState(!1),v=async()=>{var M,F,S;u(!0);try{const I=await z.get("/skills");l(I.skills||[]),c({shipped:((M=I.counts)==null?void 0:M.shipped)??0,user:((F=I.counts)==null?void 0:F.user)??0,project:((S=I.counts)==null?void 0:S.project)??0,all:(I.skills||[]).length})}catch(I){a.error(`Skills load failed: ${I.message}`)}finally{u(!1)}};r.useEffect(()=>{v()},[]),r.useEffect(()=>{if(!d.trim()){g(null);return}T(!0);const M=setTimeout(async()=>{try{const F=await z.get(`/skills/search?q=${encodeURIComponent(d.trim())}`);g(F.results||[])}catch(F){a.error(`Search failed: ${F.message}`)}finally{T(!1)}},280);return()=>clearTimeout(M)},[d]);const k=r.useMemo(()=>b!==null?b:j==="all"?n:n.filter(M=>M.source===j),[n,j,b]),L=async()=>{try{await z.post("/skills/refresh",{}),a.success("Skills refreshed."),await v()}catch(M){a.error(`Refresh failed: ${M.message}`)}},y=async M=>{try{const F=await z.get(`/skills/${encodeURIComponent(M.source)}/${encodeURIComponent(M.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:vs[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($,{variant:"ghost",onClick:()=>i.close(),children:"Close"})})}catch{i.open({title:M.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":M.source,children:vs[M.source]||M.source}),e.jsx("code",{className:"mono text-sm muted",children:M.path})]}),M.description&&e.jsx("p",{className:"skill-detail-desc",children:M.description})]}),footer:e.jsx($,{variant:"ghost",onClick:()=>i.close(),children:"Close"})})}};return e.jsxs("div",{className:"view view-skills",children:[e.jsxs("header",{className:"view-header",children:[e.jsxs("div",{className:"view-header-text",children:[e.jsxs("h2",{className:"view-title",children:[e.jsx(Oe,{size:18})," Skills"]}),e.jsx("p",{className:"view-subtitle",children:"Browse all available skills — shipped, user, and project-local."})]}),e.jsxs("div",{className:"view-actions",children:[e.jsxs("div",{className:"search-input",children:[e.jsx(Pe,{size:14}),e.jsx("input",{className:"input",type:"text",placeholder:"Search skills…",value:d,onChange:M=>x(M.target.value)}),d&&e.jsx("button",{type:"button",className:"icon-btn","aria-label":"Clear search",onClick:()=>x(""),children:e.jsx(Rt,{size:12})})]}),e.jsxs($,{variant:"secondary",size:"sm",onClick:L,children:[e.jsx(he,{size:14})," Refresh"]})]})]}),!d.trim()&&e.jsx("div",{className:"skills-tabs",children:br.map(M=>{const F=M.icon,S=M.id==="all"?o.all:o[M.id]??0;return e.jsxs("button",{type:"button",className:ee("skills-tab",j===M.id&&"skills-tab-active"),onClick:()=>m(M.id),children:[e.jsx(F,{size:14}),e.jsx("span",{children:M.label}),e.jsx("span",{className:"skills-tab-count",children:S})]},M.id)})}),d.trim()&&e.jsxs("section",{className:"skills-section",children:[e.jsxs("h3",{className:"skills-section-title",children:[e.jsx(Pe,{size:14})," Search results",w&&e.jsx(fe,{size:"sm"})]}),w?e.jsx("div",{className:"skills-grid",children:[0,1,2].map(M=>e.jsx("div",{className:"skill-card skill-card-skeleton"},M))}):b&&b.length===0?e.jsx(ze,{icon:e.jsx(Pe,{size:28}),title:"No matches",message:`No skills match "${d}".`}):e.jsx("div",{className:"skills-grid",children:(b||[]).map((M,F)=>e.jsx(jt,{skill:M,onShow:()=>y(M),searchQ:d},`search-${F}`))})]}),!d.trim()&&e.jsx("section",{className:"skills-section",children:p?e.jsx("div",{className:"view-loading",children:e.jsx(fe,{size:"lg"})}):k.length===0?e.jsx(ze,{icon:e.jsx(zt,{size:28}),title:"No skills here",message:j==="all"?"No skills found. Install skills with the skills CLI or add SKILL.md files to a skills directory.":`No skills in the ${vs[j]} tab.`}):e.jsx("div",{className:"skills-grid",children:k.map((M,F)=>e.jsx(jt,{skill:M,onShow:()=>y(M)},`${M.source}-${M.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 jt({skill:s,onShow:t,searchQ:a=""}){const i=kr[s.source]||et,n=s.description?s.description.length>200?s.description.slice(0,200)+"…":s.description:"No description.";return e.jsxs(ie,{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:wr(s.name,a)}),e.jsx("span",{className:"skill-source-badge","data-source":s.source,children:vs[s.source]||s.source})]})]}),e.jsx("p",{className:"skill-card-desc",children:n}),e.jsx("div",{className:"skill-card-actions",children:e.jsxs($,{variant:"ghost",size:"sm",onClick:t,children:[e.jsx(Ms,{size:12})," View"]})})]})}function wr(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 Ze=[{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 Sr({snapshot:s}){var w,T;const t=de(),[a,i]=r.useState(null),[n,l]=r.useState(!0),[o,c]=r.useState("1d"),[p,u]=r.useState(new Set),[j,m]=r.useState(0),d=async v=>{try{const k=v?`?since=${encodeURIComponent(v)}&limit=1000`:"?limit=1000",L=await z.get(`/history${k}`);i(L),u(new Set(L.projects.filter(y=>L.events.some(M=>M.projectId===y.id)).map(y=>y.id)))}catch(k){t.error(`History load failed: ${k.message}`)}finally{l(!1)}};r.useEffect(()=>{l(!0);const v=Ze.find(k=>k.id===o)||Ze[1];if(v.ms>0){const k=new Date(Date.now()-v.ms).toISOString();d(k)}else d()},[o]),r.useEffect(()=>{const v=setInterval(()=>m(k=>k+1),3e4);return()=>clearInterval(v)},[]);const x=new Map;for(const v of(a==null?void 0:a.events)||[]){const k=v.projectId||"global";x.has(k)||x.set(k,[]),x.get(k).push(v)}const b=v=>{u(k=>{const L=new Set(k);return L.has(v)?L.delete(v):L.add(v),L})},g=()=>{if(!a)return;const v=new Blob([JSON.stringify(a,null,2)],{type:"application/json"}),k=URL.createObjectURL(v),L=document.createElement("a");L.href=k,L.download=`bizar-history-${new Date().toISOString().replace(/[:.]/g,"-")}.json`,L.click(),URL.revokeObjectURL(k),t.success("History exported.")};return e.jsxs("div",{className:"view view-history","data-tick":j,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(ns,{size:18})," History"]}),e.jsxs("p",{className:"view-subtitle",children:["Cross-project history of events, tasks, and plans.",((w=a==null?void 0:a.stats)==null?void 0:w.lastTs)&&e.jsxs(e.Fragment,{children:[" · last event ",ye(a.stats.lastTs)]})]})]}),e.jsxs("div",{className:"view-actions",children:[e.jsxs("div",{className:"tasks-toolbar-group",children:[e.jsx(Ra,{size:14,style:{color:"var(--text-dim)"}}),e.jsx("select",{className:"select select-sm",value:o,onChange:v=>c(v.target.value),title:"Time range",children:Ze.map(v=>e.jsx("option",{value:v.id,children:v.label},v.id))})]}),e.jsxs($,{variant:"ghost",size:"sm",onClick:()=>{l(!0);const v=Ze.find(k=>k.id===o)||Ze[1];v.ms>0?d(new Date(Date.now()-v.ms).toISOString()):d()},children:[e.jsx(he,{size:14})," Refresh"]}),e.jsxs($,{variant:"secondary",size:"sm",onClick:g,children:[e.jsx(Qe,{size:14})," Export"]})]})]}),n&&e.jsxs("div",{className:"view-loading",children:[e.jsx(fe,{size:"lg"}),e.jsx("p",{children:"Loading history…"})]}),!n&&a&&e.jsxs("div",{className:"history-list",children:[a.projects.length===0&&e.jsxs(ie,{children:[e.jsxs(re,{children:[e.jsx(Ie,{size:14})," No projects"]}),e.jsx(ce,{children:"Register a project in Overview to start tracking history."})]}),a.projects.map(v=>{const k=x.get(v.id)||[],L=p.has(v.id);return e.jsxs(ie,{className:"history-project",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(Ie,{size:16})," ",v.name]}),e.jsx("div",{className:"history-project-meta",children:v.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:v.tasks.done}),e.jsxs("span",{className:"muted",children:["/ ",v.tasks.total," done"]})]}),v.tasks.doing>0&&e.jsxs("span",{className:"history-project-stat",children:[e.jsx("span",{className:"history-project-stat-num",children:v.tasks.doing}),e.jsx("span",{className:"muted",children:"doing"})]}),v.tasks.blocked>0&&e.jsxs("span",{className:"history-project-stat",children:[e.jsx("span",{className:"history-project-stat-num",children:v.tasks.blocked}),e.jsx("span",{className:"muted",children:"blocked"})]}),e.jsxs("span",{className:"history-project-stat",children:[e.jsx(Xs,{size:11})," ",e.jsx("span",{className:"history-project-stat-num",children:v.plans}),e.jsxs("span",{className:"muted",children:[" plan",v.plans===1?"":"s"]})]}),v.lastAccessed&&e.jsx("span",{className:"history-project-stat",children:e.jsxs("span",{className:"muted",children:["last opened ",ye(v.lastAccessed)]})})]}),e.jsx("button",{type:"button",className:"icon-btn",onClick:()=>b(v.id),"aria-label":L?"Collapse":"Expand",children:L?e.jsx(Le,{size:14}):e.jsx(_e,{size:14})})]}),L&&e.jsx("div",{className:"history-timeline-mini",children:k.length===0?e.jsx("div",{className:"muted",style:{padding:"12px 8px",fontSize:12},children:"No events in this time range."}):k.slice(-100).reverse().map((y,M)=>e.jsxs("div",{className:"history-timeline-row",children:[e.jsx("span",{className:"history-timeline-ts",children:new Date(y.ts).toLocaleTimeString()}),e.jsx("span",{className:"history-timeline-kind",children:y.kind||"event"}),e.jsxs("span",{className:"history-timeline-msg",title:String(y.text||y.title||""),children:[y.author?`@${y.author} `:"",String(y.text??y.title??y.name??"")]})]},M))})]},v.id)}),x.has("global")&&e.jsxs(ie,{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(ns,{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:(x.get("global")||[]).slice(-100).reverse().map((v,k)=>e.jsxs("div",{className:"history-timeline-row",children:[e.jsx("span",{className:"history-timeline-ts",children:new Date(v.ts).toLocaleTimeString()}),e.jsx("span",{className:"history-timeline-kind",children:v.kind||"event"}),e.jsxs("span",{className:"history-timeline-msg",title:String(v.text||v.title||""),children:[v.author?`@${v.author} `:"",String(v.text??v.title??v.name??"")]})]},k))})]}),((T=a.stats)==null?void 0:T.counts)&&Object.keys(a.stats.counts).length>0&&e.jsxs(ie,{children:[e.jsx(re,{children:"Event counts by kind"}),e.jsxs(ce,{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((v,k)=>k[1]-v[1]).slice(0,30).map(([v,k])=>e.jsxs("span",{className:ee("tag","tag-neutral"),style:{fontFamily:"var(--font-mono)"},children:[v,": ",k]},v))})]})]})]})}const je={top:16,right:20,bottom:40,left:52};function Cr({series:s,height:t=280,onHover:a,className:i}){const n=r.useRef(null),[l,o]=r.useState(null),{labels:c,requests:p,tokens:u}=s,j=c.length;if(j===0)return e.jsx("div",{className:ee("usage-chart-empty",i),style:{height:t},children:e.jsx("span",{children:"No data for this range"})});const m=600-je.left-je.right,d=t-je.top-je.bottom,x=Math.max(...p,1),b=Math.max(...u,1),g=Math.max(4,Math.min(24,Math.floor(m/j)-4)),w=(m-g*j)/(j+1);function T(q){return je.left+w+q*(g+w)}function v(q){return q/x*d*.75}function k(q){return je.top+d-q/b*d*.75}const L=u.map((q,_)=>`${T(_)+g/2},${k(q)}`).join(" "),y=[0,.25,.5,.75,1].map(q=>({y:je.top+d-q*d*.75,label:q===0?"0":`${Math.round(x*q).toLocaleString()}`})),M=[0,.25,.5,.75,1].map(q=>({y:je.top+d-q*d*.75,label:q===0?"0":`${Math.round(b*q/1e3)}k`})),F=Math.max(1,Math.floor(j/7)),S=c.map((q,_)=>({i:_,l:q,x:T(_)+g/2})).filter((q,_)=>_%F===0),I=r.useCallback(q=>{if(!n.current)return;const _=n.current.getBoundingClientRect(),f=(q.clientX-_.left)*(600/_.width),E=(q.clientY-_.top)*(t/_.height),G=f-je.left,D=Math.round((G-w/2)/(g+w)),V=Math.max(0,Math.min(j-1,D));o({index:V,x:q.clientX-_.left,y:q.clientY-_.top}),a==null||a(V,f,E)},[j,g,w,a,t]),H=r.useCallback(()=>{o(null),a==null||a(null,0,0)},[a]),R=l;return e.jsxs("div",{ref:n,className:ee("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:I,onMouseLeave:H,children:[y.map((q,_)=>e.jsx("line",{x1:je.left,y1:q.y,x2:600-je.right,y2:q.y,stroke:"var(--border)",strokeWidth:1,strokeDasharray:"4,3",opacity:.5},`grid-${_}`)),y.map((q,_)=>e.jsx("text",{x:je.left-6,y:q.y+4,textAnchor:"end",fontSize:10,fill:"var(--text-muted)",fontFamily:"var(--font-mono, ui-monospace, monospace)",children:q.label},`ly-${_}`)),M.map((q,_)=>e.jsx("text",{x:600-je.right+6,y:q.y+4,textAnchor:"start",fontSize:10,fill:"var(--text-muted)",fontFamily:"var(--font-mono, ui-monospace, monospace)",children:q.label},`ry-${_}`)),p.map((q,_)=>{const f=v(q),E=T(_),G=je.top+d-f;return e.jsx("rect",{x:E,y:G,width:g,height:f,rx:2,fill:((R==null?void 0:R.index)===_,"var(--accent)"),opacity:(R==null?void 0:R.index)===_?1:.75,style:{transition:"opacity 120ms ease"}},`bar-${_}`)}),e.jsx("polyline",{points:L,fill:"none",stroke:"var(--warning, #d29922)",strokeWidth:2,strokeLinejoin:"round",strokeLinecap:"round",opacity:.9}),u.map((q,_)=>e.jsx("circle",{cx:T(_)+g/2,cy:k(q),r:(R==null?void 0:R.index)===_?5:3,fill:"var(--warning, #d29922)",opacity:(R==null?void 0:R.index)===_?1:.7,style:{transition:"r 120ms ease"}},`dot-${_}`)),S.map(({i:q,l:_,x:f})=>e.jsx("text",{x:f,y:je.top+d+18,textAnchor:"middle",fontSize:10,fill:"var(--text-muted)",fontFamily:"var(--font-mono, ui-monospace, monospace)",children:_},`xl-${q}`)),e.jsx("line",{x1:je.left,y1:je.top+d,x2:600-je.right,y2:je.top+d,stroke:"var(--border)",strokeWidth:1})]}),R!==null&&e.jsxs("div",{className:"usage-chart-tooltip",style:{left:Math.min(R.x+12,460),top:R.y-60},children:[e.jsx("div",{className:"usage-tooltip-date",children:c[R.index]}),e.jsxs("div",{className:"usage-tooltip-row",children:[e.jsx("span",{className:"usage-tooltip-dot",style:{background:"var(--accent)"}}),e.jsx("span",{children:"Requests:"}),e.jsx("strong",{children:p[R.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:u[R.index].toLocaleString()})]})]})]})}function Be({label:s,col:t,sortKey:a,sortDir:i,onSort:n}){const l=a===t;return e.jsxs("th",{className:ee("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 zr({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(Be,{label:"Model",col:"modelId",sortKey:t,sortDir:a,onSort:i}),e.jsx(Be,{label:"Requests",col:"requests",sortKey:t,sortDir:a,onSort:i}),e.jsx(Be,{label:"Prompt Tok",col:"promptTokens",sortKey:t,sortDir:a,onSort:i}),e.jsx(Be,{label:"Compl Tok",col:"completionTokens",sortKey:t,sortDir:a,onSort:i}),e.jsx(Be,{label:"Total Tok",col:"totalTokens",sortKey:t,sortDir:a,onSort:i}),e.jsx(Be,{label:"Avg Latency",col:"avgLatencyMs",sortKey:t,sortDir:a,onSort:i}),e.jsx(Be,{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:ee("mono",n.errors>0&&"is-err"),children:n.errors>0?n.errors:"—"})]},`${n.providerId}::${n.modelId}`))})]})})}function Tr({activeTab:s,setActiveTab:t}){const[a,i]=r.useState("quota"),n=de();return e.jsxs("div",{className:"view-container view-minimax-usage",children:[e.jsxs("div",{className:"minimax-sub-tabs",children:[e.jsxs("button",{className:ee("minimax-sub-tab",a==="quota"&&"is-active"),onClick:()=>i("quota"),children:[e.jsx(Js,{size:13})," Token Plan"]}),e.jsxs("button",{className:ee("minimax-sub-tab",a==="analytics"&&"is-active"),onClick:()=>i("analytics"),children:[e.jsx(At,{size:13})," Usage Analytics"]})]}),a==="quota"?e.jsx(Mr,{activeTab:s,setActiveTab:t}):e.jsx($r,{toast:n})]})}function Mr({activeTab:s,setActiveTab:t}){var J;const a=de(),[i,n]=r.useState(null),[l,o]=r.useState(null),[c,p]=r.useState(null),[u,j]=r.useState(!0),[m,d]=r.useState(!1),[x,b]=r.useState(null),[g,w]=r.useState(null),[T,v]=r.useState(!1),[k,L]=r.useState(0),[y,M]=r.useState(!1),[F,S]=r.useState(null),[I,H]=r.useState(""),[R,q]=r.useState(!1),[_,f]=r.useState(!1),E=r.useCallback(async()=>{j(!0),b(null);try{const[X,ae,ue]=await Promise.all([z.get("/minimax/status"),z.get("/minimax/remains"),z.get("/minimax/onboarding")]);n(X),o(ae),p(ue),X.configured&&L(4)}catch(X){b(X.message||"Failed to load MiniMax data")}finally{j(!1)}},[]);r.useEffect(()=>{E()},[E]);const G=r.useCallback(async()=>{try{await z.post("/minimax/onboarding",{dismissedAt:Date.now()}),p(X=>X&&{...X,dismissedAt:Date.now()})}catch{}},[]),D=r.useCallback(async()=>{if(!I.trim()){a.error("Paste a Subscription Key first.");return}M(!0),S(null);try{const X=await z.post("/minimax/test",{prompt:"Reply with a single word: pong",model:"MiniMax-M3",maxTokens:16});if(S(X),X.ok){L(3),a.success("Key works. Saving…");try{await z.post("/minimax/onboarding/save-key",{key:I.trim(),groupId:"default"}),se(),a.success("Subscription Key saved.")}catch(ae){a.error(`Save failed: ${ae.message}`)}E()}else a.error(`Verification failed: ${X.message??X.error??"unknown"}`)}catch(X){a.error(`Test request failed: ${X.message}`)}finally{M(!1)}},[I,a,E]),V=r.useCallback(async()=>{if(!I.trim()){a.error("Paste a Subscription Key first.");return}f(!0);try{const X=await z.post("/minimax/onboarding/save-key",{key:I.trim(),groupId:"default"});if(!X.ok){a.error(`Save failed: ${X.message??X.error??"unknown"}`);return}H(""),se(),a.success("Subscription Key saved. Loading quota…"),E()}catch(X){a.error(`Save failed: ${X.message}`)}finally{f(!1)}},[I,a,E]),se=r.useCallback(async()=>{try{await z.del("/minimax/cache")}catch{}},[]),Q=r.useCallback(async()=>{d(!0),b(null);try{await z.post("/minimax/remains/refresh"),await E(),a.success("Refreshed")}catch(X){a.error(`Refresh failed: ${X.message}`)}finally{d(!1)}},[E,a]),B=r.useCallback(async()=>{var X;v(!0),w(null);try{const ae=await z.post("/minimax/test",{prompt:"Reply with a single word: pong",model:"MiniMax-M3",maxTokens:16});w(ae),ae.ok?a.success(`Test ok — used ${((X=ae.usage)==null?void 0:X.total_tokens)??"?"} tokens`):a.error(`Test failed: ${ae.message??ae.error??"unknown"}`)}catch(ae){a.error(`Test request failed: ${ae.message}`)}finally{v(!1)}},[a]);return u&&!i?e.jsxs("div",{className:"view-container",children:[e.jsx(fe,{})," Loading MiniMax data…"]}):i?!i.configured&&(c==null?void 0:c.dismissedAt)==null&&k<4?e.jsx(Ir,{step:k,setStep:L,keyDraft:I,setKeyDraft:H,showKey:R,setShowKey:q,verifying:y,verifyResult:F,onVerify:D,onSkip:async()=>{await G(),a.success("Skipped.")},onManualKeySave:V,savingKey:_,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(Js,{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($,{variant:"secondary",size:"sm",onClick:()=>t("settings"),title:"Configure your Subscription Key",children:[e.jsx(Zs,{size:14})," ",i.configured?`Key ${i.apiKeyHint}`:"Add key"]}),e.jsxs($,{variant:"secondary",size:"sm",onClick:Q,disabled:m,children:[m?e.jsx(ls,{size:14,className:"spin"}):e.jsx(he,{size:14})," Refresh"]})]})]}),l&&!l.ok&&e.jsxs("div",{className:"banner banner-err",children:[e.jsx(we,{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(ps,{label:"Models tracked",value:String(l.models.length),hint:"Distinct model quotas returned by the API"}),e.jsx(ps,{label:"Last fetched",value:l.fetchedAt?Rr(l.fetchedAt):"—",hint:"Refreshed on demand + every 60s"}),e.jsx(ps,{label:"Group",value:l.groupId??"—",hint:"Usually 'default' for an individual team"}),e.jsx(ps,{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(X=>e.jsx(Ar,{model:X},X.model_name))})]}),i.configured&&e.jsxs(ie,{id:"minimax-test",children:[e.jsxs(re,{children:[e.jsx(qe,{size:14})," Test the API key"]}),e.jsxs(ce,{children:["One-shot chat completion to ",e.jsxs("code",{children:[i.chatBaseUrl,"/chat/completions"]}),"."]}),e.jsxs("div",{className:"minimax-test-actions",children:[e.jsxs($,{onClick:B,disabled:T,variant:"primary",size:"sm",children:[T?e.jsx(ls,{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"'})]}),g&&e.jsxs("div",{className:ee("minimax-test-result",g.ok?"ok":"err"),children:[g.ok?e.jsx(Xe,{size:14}):e.jsx(we,{size:14}),e.jsx("div",{className:"minimax-test-body",children:g.ok?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"minimax-test-line",children:[e.jsx("strong",{children:"model:"})," ",e.jsx("code",{children:g.model})," ·"," ",e.jsx("strong",{children:"finish:"})," ",g.finishReason??"—"]}),g.content&&e.jsx("div",{className:"minimax-test-content",children:e.jsx("code",{children:g.content})}),g.usage&&e.jsxs("div",{className:"minimax-test-usage",children:[e.jsx("strong",{children:"usage:"})," total ",e.jsx("code",{children:g.usage.total_tokens??"?"})," · prompt"," ",e.jsx("code",{children:g.usage.prompt_tokens??"?"})," · completion"," ",e.jsx("code",{children:g.usage.completion_tokens??"?"}),((J=g.usage.prompt_tokens_details)==null?void 0:J.cached_tokens)!=null&&e.jsxs(e.Fragment,{children:[" · cached ",e.jsx("code",{children:g.usage.prompt_tokens_details.cached_tokens})]})]})]}):e.jsx("pre",{children:g.message??g.error??"unknown error"})})]})]})]}):e.jsx("div",{className:"view-container",children:e.jsxs("div",{className:"error-card",children:[e.jsx(we,{size:20}),e.jsxs("div",{children:[e.jsx("strong",{children:"Couldn't load MiniMax status"}),e.jsx("pre",{children:x??"unknown error"})]})]})})}function $r({toast:s}){const[t,a]=r.useState("24h"),[i,n]=r.useState(""),[l,o]=r.useState(""),[c,p]=r.useState(!0),[u,j]=r.useState(null),[m,d]=r.useState([]),[x,b]=r.useState("requests"),[g,w]=r.useState("desc"),[T,v]=r.useState(!1),k=r.useCallback(async(R,q,_)=>{p(!0);try{const f=new URLSearchParams({range:R});R==="custom"&&q&&_&&(f.set("from",String(q)),f.set("to",String(_)));const[E,G]=await Promise.all([z.get(`/usage?${f.toString()}`),z.get("/usage/recent?limit=20")]);j(E),d(G.records)}catch(f){s.error(`Failed to load usage data: ${f.message}`)}finally{p(!1)}},[s]);r.useEffect(()=>{if(t==="custom"){const R=i?new Date(i).getTime():Date.now()-6048e5,q=l?new Date(l).getTime():Date.now();k("custom",R,q)}else k(t)},[t,k]);const L=r.useCallback(R=>{x===R?w(q=>q==="asc"?"desc":"asc"):(b(R),w("desc"))},[x]),y=r.useMemo(()=>u!=null&&u.perModel?[...u.perModel].sort((R,q)=>{const _=R[x]??0,f=q[x]??0,E=typeof _=="number"&&typeof f=="number"?_-f:String(_).localeCompare(String(f));return g==="asc"?E:-E}):[],[u==null?void 0:u.perModel,x,g]),M=r.useMemo(()=>u!=null&&u.daily?{labels:u.daily.map(R=>R.date.slice(5)),requests:u.daily.map(R=>R.requests),tokens:u.daily.map(R=>R.totalTokens)}:{labels:[],requests:[],tokens:[]},[u==null?void 0:u.daily]),F=r.useCallback(async()=>{v(!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),v(!1)},[k,t,i,l]);if(c&&!u)return e.jsxs("div",{className:"view-container",children:[e.jsx(fe,{})," Loading usage data…"]});const S=u==null?void 0:u.totals,I=(u==null?void 0:u.errors)??[],H=(u==null?void 0:u.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(At,{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($,{variant:"secondary",size:"sm",onClick:F,disabled:T,children:[T?e.jsx(ls,{size:14,className:"spin"}):e.jsx(he,{size:14})," Refresh"]})})]}),e.jsxs("div",{className:"usage-time-range",children:[["24h","7d","30d","custom"].map(R=>e.jsx("button",{className:ee("usage-range-chip",t===R&&"is-active"),onClick:()=>a(R),children:R==="custom"?"Custom":R.toUpperCase()},R)),t==="custom"&&e.jsxs("div",{className:"usage-custom-dates",children:[e.jsx("input",{type:"date",className:"usage-date-input",value:i,onChange:R=>n(R.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:R=>o(R.target.value)})]})]}),e.jsxs("div",{className:"usage-kpi-row",children:[e.jsx(es,{label:"Total Requests",value:(S==null?void 0:S.requests.toLocaleString())??"—",sub:S?`${S.errors} errors`:void 0,tone:S&&S.errors>S.requests*.1?"warn":void 0}),e.jsx(es,{label:"Total Tokens",value:S?S.totalTokens>=1e3?`${Math.round(S.totalTokens/1e3)}k`:String(S.totalTokens):"—",sub:S?`${S.promptTokens.toLocaleString()} prompt · ${S.completionTokens.toLocaleString()} completion`:void 0}),e.jsx(es,{label:"Errors",value:String((S==null?void 0:S.errors)??"—"),sub:I.length>0?`${I[0].code}: ${I[0].count}`:void 0,tone:S&&S.errors>0?"err":void 0}),e.jsx(es,{label:"Avg Latency",value:(S==null?void 0:S.avgLatencyMs)!=null?`${S.avgLatencyMs}ms`:"—",sub:(S==null?void 0:S.p95LatencyMs)!=null?`p95 ${S.p95LatencyMs}ms`:void 0}),e.jsx(es,{label:"Est. Cost",value:(S==null?void 0:S.costEstimate)!=null&&S.costEstimate>0?`$${S.costEstimate.toFixed(4)}`:"—",sub:"approximate USD",tone:void 0})]}),e.jsxs(ie,{className:"usage-chart-card",children:[e.jsx("div",{className:"usage-chart-wrap",children:e.jsx(Cr,{series:M,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(ie,{children:[e.jsx(re,{children:"Per-model breakdown"}),e.jsx(zr,{rows:y,sortKey:x,sortDir:g,onSort:L})]}),H.length>0&&e.jsxs(ie,{children:[e.jsx(re,{children:"API Keys"}),e.jsx("div",{className:"usage-key-row",children:H.map(R=>e.jsxs("span",{className:ee("usage-key-badge",R.isBackup?"is-backup":"is-active"),children:[e.jsx("span",{className:"usage-key-dot"}),R.keyEnvVar,R.isBackup?" (backup)":" (active)"," · ",R.requests," req"]},R.keyEnvVar))})]}),m.length>0&&e.jsxs(ie,{children:[e.jsx(re,{children:"Recent activity"}),e.jsx("div",{className:"usage-recent-list",children:m.map((R,q)=>e.jsxs("div",{className:ee("usage-recent-item",R.error&&"is-err"),children:[e.jsx("span",{className:"usage-recent-time",children:new Date(R.ts).toLocaleTimeString()}),e.jsx("span",{className:"usage-recent-model",children:e.jsx("code",{children:R.modelId})}),e.jsxs("span",{className:"usage-recent-tokens",children:[R.totalTokens.toLocaleString()," tok"]}),e.jsxs("span",{className:"usage-recent-latency",children:[R.latencyMs,"ms"]}),e.jsx("span",{className:"usage-recent-endpoint",children:R.endpoint})]},`${R.requestId}-${q}`))})]})]})}function es({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:ee("usage-kpi-value",i&&`is-${i}`),children:t}),a&&e.jsx("div",{className:"usage-kpi-sub",children:a})]})}function ps({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 Ar({model:s}){const t=gs(s.current_interval_remaining_percent??0,0,100),a=gs(s.current_weekly_remaining_percent??0,0,100),i=gs(100-t,0,100),n=gs(100-a,0,100);return e.jsxs(ie,{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:ee("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(ft,{icon:e.jsx(Re,{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(ft,{icon:e.jsx(ba,{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 ft({icon:s,label:t,remainingPct:a,consumedPct:i,used:n,total:l,resetIn:o,resetISO:c}){const p=a>=75?"good":a>=25?"warn":"low";return e.jsxs("div",{className:`minimax-quota-row is-${p}`,children:[e.jsxs("div",{className:"minimax-quota-head",children:[e.jsxs("span",{className:"minimax-quota-label",children:[s," ",t]}),e.jsxs("span",{className:"minimax-quota-remaining",children:[a,"% remaining"]})]}),e.jsx("div",{className:"minimax-bar",children:e.jsx("div",{className:"minimax-bar-fill",style:{width:`${i}%`},"aria-label":`${i}% consumed`})}),e.jsxs("div",{className:"minimax-quota-meta",children:[e.jsxs("span",{children:[e.jsx("strong",{children:n})," / ",l||"—"," requests"]}),e.jsx("span",{title:c,children:o?`resets in ${o}`:"—"})]})]})}function gs(s,t,a){return Math.max(t,Math.min(a,s))}function Rr(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 Ir({step:s,setStep:t,keyDraft:a,setKeyDraft:i,showKey:n,setShowKey:l,verifying:o,verifyResult:c,onVerify:p,onSkip:u,onManualKeySave:j,savingKey:m,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(Oe,{size:20,style:{verticalAlign:"text-bottom",marginRight:6}}),"Set up MiniMax Token Plan tracking"]}),e.jsx("p",{className:"view-subtitle",children:"We'll read your Subscription Key and show your remaining quota."})]}),e.jsx("div",{className:"view-header-actions",children:e.jsxs($,{variant:"ghost",size:"sm",onClick:u,children:[e.jsx(Ee,{size:14})," Skip for now"]})})]}),e.jsx("div",{className:"minimax-wizard-stepper",children:["Welcome","Get a key","Paste & test","Done"].map((x,b)=>e.jsxs("div",{className:ee("minimax-wizard-step",b===s&&"is-current",b<s&&"is-done",b>s&&"is-todo"),children:[e.jsx("div",{className:"minimax-wizard-step-bullet",children:b<s?e.jsx(Xe,{size:14}):b+1}),e.jsx("div",{className:"minimax-wizard-step-label",children:x})]},x))}),e.jsxs(ie,{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($,{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(Ms,{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($,{variant:"secondary",size:"md",onClick:()=>t(0),children:"← Back"}),e.jsxs($,{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(Zs,{size:12,className:"minimax-key-icon"}),e.jsx("input",{type:n?"text":"password",value:a,onChange:x=>i(x.target.value),placeholder:"sk-cp-...",spellCheck:!1,autoComplete:"off",className:"minimax-key-input",autoFocus:!0}),e.jsx("button",{type:"button",onClick:()=>l(x=>!x),className:"minimax-key-toggle","aria-label":n?"Hide key":"Show key",children:n?e.jsx(_s,{size:13}):e.jsx(Je,{size:13})})]})}),c&&!c.ok&&e.jsxs("div",{className:"minimax-wizard-error",children:[e.jsx(we,{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($,{variant:"secondary",size:"md",onClick:()=>t(1),children:"← Back"}),e.jsxs($,{variant:"primary",size:"md",onClick:p,disabled:o||!a.trim(),children:[o?e.jsx(ls,{size:14,className:"spin"}):e.jsx(Ss,{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:x=>{x.preventDefault(),j()},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(Xe,{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($,{variant:"primary",size:"md",onClick:()=>window.location.reload(),children:"View your quota →"})})]}),e.jsxs("div",{className:"minimax-wizard-footer",children:[e.jsx(Ss,{size:11}),e.jsxs("span",{children:["Key written to ",e.jsx("code",{children:"~/.local/share/opencode/auth.json"})," with mode 0600."]})]})]})]})}const Lr={pending:"info",running:"accent",done:"success",failed:"error",killed:"neutral",timed_out:"warning"},Er={pending:"Pending",running:"Running",done:"Done",failed:"Failed",killed:"Killed",timed_out:"Timed out"};function Dr({status:s,dot:t}){const a=Lr[s]||"neutral",i=Er[s]||s;return e.jsx(Ye,{kind:a,dot:t,children:i})}function Pr({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($,{variant:"ghost",onClick:i,children:"Cancel"}),e.jsx($,{variant:"danger",onClick:async()=>{await a(),i()},children:"Kill"})]})]})}function Or(s,t,a,i,n){s.open({title:"Kill instance?",width:400,children:e.jsx(Pr,{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 Fr({instance:s}){const t=de(),[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 p=await z.post(`/background/${encodeURIComponent(s.instanceId)}/open-terminal`,{emulator:"system"});if(p.ok)t.success("Opening terminal…");else if(t.error(p.error||"Failed to open terminal"),l)try{await navigator.clipboard.writeText(l),t.success("Command copied to clipboard")}catch{}}catch(p){if(t.error(`Failed: ${p.message}`),l)try{await navigator.clipboard.writeText(l),t.success("Command copied to clipboard")}catch{}}finally{i(!1)}}};return n?e.jsxs(ie,{variant:"outlined",className:"bg-tmux-card",children:[e.jsxs("div",{className:"bg-tmux-card-header",children:[e.jsx(is,{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($,{variant:"ghost",size:"sm",onClick:o,title:"Copy attach command",children:[e.jsx(As,{size:14})," Copy"]}),e.jsxs($,{variant:"primary",size:"sm",onClick:c,loading:a,title:"Open in system terminal",children:[e.jsx(is,{size:14})," Open terminal"]})]})]}):e.jsxs(ie,{variant:"outlined",className:"bg-tmux-card bg-tmux-card-warn",children:[e.jsxs("div",{className:"bg-tmux-card-header",children:[e.jsx(we,{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 Br=5e3,Ur=2e3,qr=120;function _r(s){return s.status==="pending"||s.status==="running"}function Hr(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 Wr(s){const t=de(),a=$e(),[i,n]=r.useState([]),[l,o]=r.useState(!0),[c,p]=r.useState(null),[,u]=r.useState(0),j=r.useCallback(async()=>{try{const g=await z.get("/background");n(Array.isArray(g==null?void 0:g.instances)?g.instances:[]),p(null)}catch(g){p((g==null?void 0:g.message)||"Failed to load background agents.")}finally{o(!1)}},[]);r.useEffect(()=>{j();const g=setInterval(j,Br);return()=>clearInterval(g)},[j]),r.useEffect(()=>{const g=setInterval(()=>u(w=>(w+1)%1e6),1e3);return()=>clearInterval(g)},[]),r.useEffect(()=>{const g=new Qs,w=g.on(T=>{const v=T.type;(v==="background:change"||v==="background:cleanup")&&j()});return()=>{w(),g.close()}},[j]);const m=i.filter(_r),d=g=>{Kr(a,g)},x=async g=>{try{const w=await z.get(`/background/${encodeURIComponent(g.instanceId)}/tmux`);Yr(a,w)}catch(w){t.error(`Tmux info failed: ${w.message}`)}},b=g=>{Or(a,t,g.instanceId,g.agent||g.prompt,()=>{n(w=>w.filter(T=>T.instanceId!==g.instanceId))})};return l?e.jsx("div",{className:"bg-active-view",children:e.jsxs("div",{className:"bg-active-loading",children:[e.jsx(fe,{size:"md"}),e.jsx("span",{children:"Loading background agents…"})]})}):c?e.jsx("div",{className:"bg-active-view",children:e.jsx(ze,{icon:e.jsx(Re,{size:32}),title:"Couldn't load background agents",message:c,action:e.jsxs($,{variant:"primary",onClick:j,children:[e.jsx(he,{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:[m.length," active · ",i.length," total in store"]})]}),e.jsxs($,{variant:"ghost",size:"sm",onClick:j,title:"Refresh now",children:[e.jsx(he,{size:14})," Refresh"]})]}),m.length===0?e.jsx(ze,{icon:e.jsx(Re,{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:m.map(g=>e.jsx(Vr,{inst:g,onViewOutput:()=>d(g),onOpenTmux:()=>x(g),onKill:()=>b(g)},g.instanceId))})]})}function Vr({inst:s,onViewOutput:t,onOpenTmux:a,onKill:i}){const n=typeof s.startedAt=="number"?s.startedAt:0,l=n?yt(n):"—",o=n?Date.now()-n:0,c=kt(s.prompt,qr);return e.jsxs(ie,{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(Dr,{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:"})," ",Hr(o)]}),e.jsxs("span",{children:[e.jsx("strong",{children:"Tool calls:"})," ",s.toolCallCount??0]}),s.tmuxSession&&e.jsxs("span",{className:ee(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($,{variant:"secondary",size:"sm",onClick:t,children:[e.jsx(Je,{size:14})," View output"]}),e.jsxs($,{variant:"ghost",size:"sm",onClick:a,children:[e.jsx(is,{size:14})," Open in tmux"]}),e.jsxs($,{variant:"danger",size:"sm",onClick:i,children:[e.jsx(Te,{size:14})," Kill"]})]}),e.jsx(Fr,{instance:s})]})}function Kr(s,t){s.open({title:`Output — ${t.agent||t.instanceId}`,width:720,children:e.jsx(Gr,{instanceId:t.instanceId})})}function Gr({instanceId:s}){const t=de(),[a,i]=r.useState(""),[n,l]=r.useState(!0),[o,c]=r.useState(null),[p,u]=r.useState(!0),j=r.useRef(null),m=r.useRef(!0),d=r.useCallback(async()=>{try{const g=await z.get(`/background/${encodeURIComponent(s)}/output?lines=200`);i((g==null?void 0:g.output)??""),u((g==null?void 0:g.available)!==!1),c(null)}catch(g){c((g==null?void 0:g.message)||"Failed to load output.")}finally{l(!1)}},[s]);r.useEffect(()=>{d();const g=setInterval(d,Ur);return()=>clearInterval(g)},[d]),r.useEffect(()=>{var g;m.current&&((g=j.current)==null||g.scrollIntoView({behavior:"auto",block:"end"}))},[a]);const x=g=>{const w=g.currentTarget,T=w.scrollHeight-w.scrollTop-w.clientHeight<24;m.current=T},b=async()=>{try{await navigator.clipboard.writeText(a),t.success("Output copied.")}catch{}};return e.jsxs("div",{className:"bg-output-modal",children:[e.jsxs("div",{className:"bg-output-toolbar",children:[e.jsx("span",{className:"muted",children:p?`${a.length} chars · auto-refresh 2s`:"Output unavailable"}),e.jsxs("div",{className:"bg-output-toolbar-actions",children:[e.jsxs($,{variant:"ghost",size:"sm",onClick:d,title:"Refresh now",children:[e.jsx(he,{size:14})," Refresh"]}),e.jsxs($,{variant:"ghost",size:"sm",onClick:b,disabled:!a,children:[e.jsx(As,{size:14})," Copy"]})]})]}),n&&!a?e.jsxs("div",{className:"bg-output-loading",children:[e.jsx(ls,{size:16,className:"spin"})," Loading…"]}):o?e.jsx("div",{className:"bg-output-error",children:o}):a?e.jsxs("div",{className:"bg-output-scroll",onScroll:x,children:[e.jsx("pre",{className:"bg-output-pre mono",children:e.jsx("code",{children:a})}),e.jsx("div",{ref:j})]}):e.jsx("div",{className:"bg-output-empty muted",children:"No output captured yet."})]})}function Yr(s,t){const a=t.attachCommand||t.session||"";s.open({title:"Attach to tmux",width:520,children:e.jsx(Xr,{info:t,cmd:a})})}function Xr({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($,{variant:"secondary",size:"sm",onClick:n,children:[e.jsx(As,{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 Us={overview:Tn,chat:ei,agents:ni,artifacts:Ai,tasks:Pi,activity:Qi,background:Wr,config:xt,settings:xt,mods:rr,schedules:jr,skills:Nr,history:Sr,minimax:Tr},Qr="v4.5.0";function Jr(s,t,a,i){if(Us[s]){const o=Us[s];return e.jsx(o,{...t})}const n=a.find(o=>o.id===s);if(n)return e.jsx(or,{viewId:n.id,reloadKey:i,activeTab:t.activeTab,setActiveTab:t.setActiveTab});const l=Us.overview;return e.jsx(l,{...t})}function Zr({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&&(z.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($,{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 el(){return e.jsx(pa,{children:e.jsx(ga,{children:e.jsx(sl,{})})})}function sl(){var X,ae,ue;const s=de(),t=$e(),{isModalOpen:a}=t,i=r.useRef(!1),[n,l]=r.useState("overview"),[o,c]=r.useState(null),[p,u]=r.useState(null),[j,m]=r.useState("connecting"),[d,x]=r.useState(null),[b,g]=r.useState(!1),[w,T]=r.useState(!1),[v,k]=r.useState([]),[L,y]=r.useState(!1),[M,F]=r.useState([]),[S,I]=r.useState(0),H=r.useRef(null),[R,q]=r.useState(null);r.useEffect(()=>{let W=!1;return(async()=>{try{const C=await z.get("/mods/views");if(W)return;F(C.views||[])}catch{W||F([])}})(),()=>{W=!0}},[S,o==null?void 0:o.mods]),r.useEffect(()=>{if(!R)return;const W=R.on(C=>{((C==null?void 0:C.type)==="mod:change"||(C==null?void 0:C.type)==="mod:enabled"||(C==null?void 0:C.type)==="mod:installed")&&I(P=>P+1)});return()=>W()},[R]),r.useEffect(()=>{p!=null&&p.theme&&(ts(p.theme),Ge(p.theme))},[p==null?void 0:p.theme]),r.useEffect(()=>{i.current=a},[a]),r.useEffect(()=>{var P;if(((P=p==null?void 0:p.theme)==null?void 0:P.mode)!=="system")return;const W=window.matchMedia("(prefers-color-scheme: light)"),C=()=>ts(p.theme.mode);return W.addEventListener("change",C),()=>W.removeEventListener("change",C)},[(X=p==null?void 0:p.theme)==null?void 0:X.mode]);const _=r.useCallback(async()=>{let W=!1;const C=()=>Promise.all([z.get("/snapshot").catch(()=>null),z.get("/settings").catch(()=>null),z.get("/agents/stuck").catch(()=>null)]),P=(h,O,U)=>{h&&c(h),O!=null&&O.data&&u(O.data),U!=null&&U.stuck&&k(U.stuck)};try{const h=await z.probeAuthStatus(),[O,U,A]=await C();if(P(O,U,A),O||U){x(null);return}if(!h.loopback){x("Dashboard server unreachable.");return}await new Promise(le=>setTimeout(le,1e3));const[ne,te,me]=await C();P(ne,te,me),!ne&&!te&&x("Dashboard server unreachable.")}catch(h){const O=(h==null?void 0:h.message)??"unknown error";if(h instanceof ja&&h.status===401){x(O),g(!0),s.error(`Auth required: ${O}`);return}x(O),s.error(`Failed to load: ${O}`)}},[s]);r.useEffect(()=>{let W=!1;const C=setTimeout(()=>{W||_()},0);return()=>{W=!0,clearTimeout(C)}},[_]),r.useEffect(()=>{let W=!1;return z.get("/settings").then(C=>{var h,O;if(W)return;const P=(O=(h=C==null?void 0:C.data)==null?void 0:h.ui)==null?void 0:O.defaultTab;P&&l(P)}).catch(()=>{}),()=>{W=!0}},[]),r.useEffect(()=>{let W=!1;const C=async()=>{try{const h=await z.get("/agents/stuck");W||k(O=>{const U=h.stuck||[];return O.length===0&&U.length>0&&s.warning(`${U.length} agent${U.length===1?"":"s"} stuck`,5e3),U})}catch{}},P=setInterval(C,3e4);return C(),()=>{W=!0,clearInterval(P)}},[]),r.useEffect(()=>{const W=new Qs;H.current=W,q(W);const C=W.onStatus(h=>m(h)),P=W.on(h=>{var O;if(h.type==="snapshot"&&"data"in h&&h.data)c(U=>({...U??{},...h.data}));else if(h.type==="change"){const U=h,A=((O=U.path)==null?void 0:O.split("/").pop())||U.path||"";s.info(`File changed: ${A}`,2500),z.get("/snapshot").then(ne=>c(te=>({...te??{},...ne}))).catch(()=>{})}else if(h.type==="tasks:change"){const U=h;c(A=>{if(!A)return A;const ne=(A.tasks||[]).map(me=>me.id===U.task.id?U.task:me),te=ne.some(me=>me.id===U.task.id);return{...A,tasks:te?ne:[U.task,...ne]}})}else if(h.type==="tasks:delete"){const U=h;c(A=>A&&{...A,tasks:(A.tasks||[]).filter(ne=>ne.id!==U.id)})}else if(h.type==="settings:change"){const U=h;U.settings&&u(U.settings)}else if(h.type==="project:change")z.get("/snapshot").then(U=>c(A=>({...A??{},...U}))).catch(()=>{});else if(h.type==="agents:change"||h.type==="schedules:change")z.get("/snapshot").then(U=>c(A=>({...A??{},...U}))).catch(()=>{});else if(h.type==="agent:status"||h.type==="agent:restarted"){const U=h;c(A=>{if(!A)return A;const ne=(A.agents||[]).map(te=>te.name===U.agent.name?U.agent:te);return{...A,agents:ne}})}else if(h.type==="artifact:change")z.get("/artifacts").then(U=>{c(A=>A&&{...A,artifacts:U.artifacts||[]})}).catch(()=>{});else if(h.type==="agent:stuck")k(h.agents||[]);else if(h.type==="dialog:show"){const U=h;U.dialog&&t.open({title:U.dialog.title,width:520,children:e.jsx(zn,{dialog:U.dialog,onClose:()=>t.close()})})}});return()=>{C(),P(),W.close(),q(null)}},[s]);const f=r.useCallback(W=>R?R.on(W):()=>{},[R]),E=r.useRef(0);r.useEffect(()=>{const W=()=>{E.current=Date.now()+1500};return document.addEventListener("mousedown",W,!0),document.addEventListener("click",W,!0),document.addEventListener("focusin",W,!0),document.addEventListener("keydown",W,!0),()=>{document.removeEventListener("mousedown",W,!0),document.removeEventListener("click",W,!0),document.removeEventListener("focusin",W,!0),document.removeEventListener("keydown",W,!0)}},[]),r.useEffect(()=>{const W={};Ws.forEach((P,h)=>{W[String(h+1)]=P.id});const C=P=>{var le,os,cs,ds;if((P.metaKey||P.ctrlKey)&&P.key.toLowerCase()==="k"){P.preventDefault(),T(!0);return}if(P.key==="/"&&!P.metaKey&&!P.ctrlKey){const hs=(os=(le=P.target)==null?void 0:le.tagName)==null?void 0:os.toLowerCase();if(hs!=="input"&&hs!=="textarea"&&!((cs=P.target)!=null&&cs.isContentEditable)){P.preventDefault(),T(!0);return}}const h=document.activeElement;if(!h||h===document.body||h===document.documentElement)return;const U=P.target,A=(ds=U==null?void 0:U.tagName)==null?void 0:ds.toLowerCase(),ne=A==="input"||A==="textarea"||A==="select"||A==="button"||A==="option"||A==="label"||!!(U!=null&&U.isContentEditable);let te=!1;if(U&&typeof U.closest=="function"&&(te=!!U.closest('form, [role="dialog"], [contenteditable], [data-no-key]')),P.repeat||i.current||ne||te||P.metaKey||P.ctrlKey||P.altKey||P.shiftKey||Date.now()<E.current)return;const me=W[P.key];me&&(P.preventDefault(),l(me))};return document.addEventListener("keydown",C),()=>document.removeEventListener("keydown",C)},[]);const G=r.useMemo(()=>async()=>{try{const W=await z.get("/snapshot");c(C=>({...C??{},...W}))}catch(W){s.error(`Refresh failed: ${W.message}`)}},[s]),D=r.useMemo(()=>{const W=M.map(C=>({id:C.id,label:C.label,icon:C.kind==="iframe"?rs:Hs,isMod:!0,modId:C.modId}));return[...Ws,...W]},[M]),V=r.useMemo(()=>o&&p?Jr(n,{snapshot:o,settings:p,activeTab:n,setActiveTab:l,refreshSnapshot:G},M,S):null,[n,o,p,M,S,G]),se=async()=>{try{const W=await z.get("/projects");c(C=>{var P;return C&&{...C,projects:W.projects||[],activeProject:((P=W.projects)==null?void 0:P.find(h=>h.id===W.active))||null}})}catch(W){s.error(`Projects refresh failed: ${W.message}`)}},Q=async W=>{try{await z.post(`/projects/${encodeURIComponent(W)}/activate`),c(C=>C&&{...C,activeProject:C.projects.find(P=>P.id===W)||null})}catch(C){s.error(`Activate failed: ${C.message}`)}},B=W=>{const C=W.type;if(C==="agent")l("agents");else if(C==="task")l("tasks");else if(C==="mod")l("mods");else if(C==="schedule")l("schedules");else if(C==="project"){const P=W.item.id;Q(P)}else if(C==="command")s.info(`/${W.item.name} — run from the TUI`,2500);else if(C==="setting"){const P=W.item.id||W.item.path||"";l("settings");const h=O=>{if(O<=0)return;const U=P?document.querySelector(`[data-setting-id="${CSS.escape(P)}"]`):null;U?(U.scrollIntoView({behavior:"smooth",block:"center"}),U.classList.remove("setting-flash"),U.offsetWidth,U.classList.add("setting-flash"),window.setTimeout(()=>U.classList.remove("setting-flash"),1500)):window.setTimeout(()=>h(O-1),80)};window.setTimeout(()=>h(15),60)}},Y=((ae=p==null?void 0:p.ui)==null?void 0:ae.layout)||"topnav",J=((ue=p==null?void 0:p.ui)==null?void 0:ue.showHeader)!==!1;return e.jsxs("div",{className:"app","data-layout":Y,"data-active-tab":n,children:[J&&e.jsx(mn,{activeTab:n,onTabChange:l,wsStatus:j,version:Qr,activeProject:(o==null?void 0:o.activeProject)||null,projects:(o==null?void 0:o.projects)||[],onProjectChange:Q,onProjectsRefresh:se,onOpenSearch:()=>T(!0),settings:p,notificationsSlot:e.jsx(vn,{wsSubscribe:f}),showTabs:Y==="topnav",extraTabs:D}),v.length>0&&!L&&e.jsxs("div",{className:"stuck-banner",role:"alert",children:[e.jsx(we,{size:16}),e.jsxs("span",{children:[e.jsx("strong",{children:v.length})," agent",v.length===1?"":"s"," stuck:"," ",e.jsx("span",{className:"mono",children:v.map(W=>W.name).join(", ")})]}),e.jsx($,{variant:"secondary",size:"sm",onClick:()=>{l("agents"),y(!0)},children:"Review"}),e.jsx("button",{type:"button",className:"icon-btn","aria-label":"Dismiss",onClick:()=>y(!0),children:e.jsx(Ee,{size:14})})]}),e.jsxs("div",{className:"layout-body",children:[Y!=="topnav"&&e.jsx(pn,{tabs:D,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}),b&&e.jsx(Zr,{onSaved:()=>{g(!1),_()}}),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||!p)&&e.jsxs("div",{className:"loading",children:[e.jsx(fe,{size:"lg"}),e.jsx("p",{children:"Loading Bizar…"})]}),V]})]}),e.jsx(gn,{open:w,onClose:()=>T(!1),onSelect:B})]})}function tl(){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(va,{}):e.jsx(el,{})}const Bt=document.getElementById("root");if(!Bt)throw new Error("Root element #root not found");fa(Bt).render(e.jsx(r.StrictMode,{children:e.jsx(tl,{})}));
|
|
312
|
+
//# sourceMappingURL=main-NYFpS2wY.js.map
|