agent-relay 1.1.0 → 1.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (567) hide show
  1. package/.gitattributes +3 -0
  2. package/.nvmrc +1 -0
  3. package/.trajectories/completed/2026-01/traj_1dviorhnkcb5.json +65 -0
  4. package/.trajectories/completed/2026-01/traj_1dviorhnkcb5.md +37 -0
  5. package/.trajectories/completed/2026-01/traj_1k5if5snst2e.json +65 -0
  6. package/.trajectories/completed/2026-01/traj_1k5if5snst2e.md +37 -0
  7. package/.trajectories/completed/2026-01/traj_1rp3rges5811.json +49 -0
  8. package/.trajectories/completed/2026-01/traj_1rp3rges5811.md +31 -0
  9. package/.trajectories/completed/2026-01/traj_22bhyulruouw.json +113 -0
  10. package/.trajectories/completed/2026-01/traj_22bhyulruouw.md +57 -0
  11. package/.trajectories/completed/2026-01/traj_2dao7ddgnta0.json +53 -0
  12. package/.trajectories/completed/2026-01/traj_2dao7ddgnta0.md +32 -0
  13. package/.trajectories/completed/2026-01/traj_3t0440mjeunc.json +26 -0
  14. package/.trajectories/completed/2026-01/traj_3t0440mjeunc.md +6 -0
  15. package/.trajectories/completed/2026-01/traj_45x9494d9xnr.json +47 -0
  16. package/.trajectories/completed/2026-01/traj_45x9494d9xnr.md +32 -0
  17. package/.trajectories/completed/2026-01/traj_4aa0bb77s4nh.json +53 -0
  18. package/.trajectories/completed/2026-01/traj_4aa0bb77s4nh.md +32 -0
  19. package/.trajectories/completed/2026-01/traj_5lhmzq8rxpqv.json +59 -0
  20. package/.trajectories/completed/2026-01/traj_5lhmzq8rxpqv.md +33 -0
  21. package/.trajectories/completed/2026-01/traj_5vr4e9erb1fs.json +53 -0
  22. package/.trajectories/completed/2026-01/traj_5vr4e9erb1fs.md +32 -0
  23. package/.trajectories/completed/2026-01/traj_6fgiwdoklvym.json +48 -0
  24. package/.trajectories/completed/2026-01/traj_6fgiwdoklvym.md +24 -0
  25. package/.trajectories/completed/2026-01/traj_7ludwvz45veh.json +209 -0
  26. package/.trajectories/completed/2026-01/traj_7ludwvz45veh.md +97 -0
  27. package/.trajectories/completed/2026-01/traj_9921cuhel0pj.json +48 -0
  28. package/.trajectories/completed/2026-01/traj_9921cuhel0pj.md +24 -0
  29. package/.trajectories/completed/2026-01/traj_ajs7zqfux4wc.json +49 -0
  30. package/.trajectories/completed/2026-01/traj_ajs7zqfux4wc.md +23 -0
  31. package/.trajectories/completed/2026-01/traj_cvtqhlwcq9s0.json +53 -0
  32. package/.trajectories/completed/2026-01/traj_cvtqhlwcq9s0.md +32 -0
  33. package/.trajectories/completed/2026-01/traj_cxofprm2m2en.json +49 -0
  34. package/.trajectories/completed/2026-01/traj_cxofprm2m2en.md +31 -0
  35. package/.trajectories/completed/2026-01/traj_d2hhz3k0vrhn.json +26 -0
  36. package/.trajectories/completed/2026-01/traj_d2hhz3k0vrhn.md +6 -0
  37. package/.trajectories/completed/2026-01/traj_dfuvww9pege5.json +59 -0
  38. package/.trajectories/completed/2026-01/traj_dfuvww9pege5.md +37 -0
  39. package/.trajectories/completed/2026-01/traj_g0fisy9h51mf.json +77 -0
  40. package/.trajectories/completed/2026-01/traj_g0fisy9h51mf.md +42 -0
  41. package/.trajectories/completed/2026-01/traj_gjdre5voouod.json +53 -0
  42. package/.trajectories/completed/2026-01/traj_gjdre5voouod.md +32 -0
  43. package/.trajectories/completed/2026-01/traj_gtlyqtta3x8l.json +25 -0
  44. package/.trajectories/completed/2026-01/traj_gtlyqtta3x8l.md +15 -0
  45. package/.trajectories/completed/2026-01/traj_h4xijiuip3w4.json +101 -0
  46. package/.trajectories/completed/2026-01/traj_h4xijiuip3w4.md +44 -0
  47. package/.trajectories/completed/2026-01/traj_hhxte7w4gjjx.json +22 -0
  48. package/.trajectories/completed/2026-01/traj_hhxte7w4gjjx.md +5 -0
  49. package/.trajectories/completed/2026-01/traj_hpungyhoj6v5.json +53 -0
  50. package/.trajectories/completed/2026-01/traj_hpungyhoj6v5.md +32 -0
  51. package/.trajectories/completed/2026-01/traj_m2xkjv0w2sq7.json +25 -0
  52. package/.trajectories/completed/2026-01/traj_m2xkjv0w2sq7.md +15 -0
  53. package/.trajectories/completed/2026-01/traj_noq5zbvnrdvz.json +53 -0
  54. package/.trajectories/completed/2026-01/traj_noq5zbvnrdvz.md +32 -0
  55. package/.trajectories/completed/2026-01/traj_ntbs6ppopf46.json +53 -0
  56. package/.trajectories/completed/2026-01/traj_ntbs6ppopf46.md +32 -0
  57. package/.trajectories/completed/2026-01/traj_ozd98si6a7ns.json +48 -0
  58. package/.trajectories/completed/2026-01/traj_ozd98si6a7ns.md +24 -0
  59. package/.trajectories/completed/2026-01/traj_prdza7a5cxp5.json +53 -0
  60. package/.trajectories/completed/2026-01/traj_prdza7a5cxp5.md +32 -0
  61. package/.trajectories/completed/2026-01/traj_qb3twvvywfwi.json +77 -0
  62. package/.trajectories/completed/2026-01/traj_qb3twvvywfwi.md +42 -0
  63. package/.trajectories/completed/2026-01/traj_qft54mi7nfor.json +53 -0
  64. package/.trajectories/completed/2026-01/traj_qft54mi7nfor.md +32 -0
  65. package/.trajectories/completed/2026-01/traj_qx9uhf8whhxo.json +83 -0
  66. package/.trajectories/completed/2026-01/traj_qx9uhf8whhxo.md +47 -0
  67. package/.trajectories/completed/2026-01/traj_rd9toccj18a0.json +59 -0
  68. package/.trajectories/completed/2026-01/traj_rd9toccj18a0.md +37 -0
  69. package/.trajectories/completed/2026-01/traj_rt4fiw3ecp50.json +48 -0
  70. package/.trajectories/completed/2026-01/traj_rt4fiw3ecp50.md +16 -0
  71. package/.trajectories/completed/2026-01/traj_st8j35b0hrlc.json +59 -0
  72. package/.trajectories/completed/2026-01/traj_st8j35b0hrlc.md +37 -0
  73. package/.trajectories/completed/2026-01/traj_t1yy8m7hbuxp.json +53 -0
  74. package/.trajectories/completed/2026-01/traj_t1yy8m7hbuxp.md +32 -0
  75. package/.trajectories/completed/2026-01/traj_tmux_orchestrator_analysis.json +84 -0
  76. package/.trajectories/completed/2026-01/traj_tmux_orchestrator_analysis.md +109 -0
  77. package/.trajectories/completed/2026-01/traj_u9n9eqasw16k.json +53 -0
  78. package/.trajectories/completed/2026-01/traj_u9n9eqasw16k.md +32 -0
  79. package/.trajectories/completed/2026-01/traj_v87hypnongqx.json +71 -0
  80. package/.trajectories/completed/2026-01/traj_v87hypnongqx.md +42 -0
  81. package/.trajectories/completed/2026-01/traj_wkp2fgzdyinb.json +53 -0
  82. package/.trajectories/completed/2026-01/traj_wkp2fgzdyinb.md +32 -0
  83. package/.trajectories/completed/2026-01/traj_x14t8w8rn7xg.json +20 -0
  84. package/.trajectories/completed/2026-01/traj_x14t8w8rn7xg.md +6 -0
  85. package/.trajectories/completed/2026-01/traj_xnwbznkvv8ua.json +175 -0
  86. package/.trajectories/completed/2026-01/traj_xnwbznkvv8ua.md +82 -0
  87. package/.trajectories/completed/2026-01/traj_ysjc8zaeqtd3.json +47 -0
  88. package/.trajectories/completed/2026-01/traj_ysjc8zaeqtd3.md +32 -0
  89. package/.trajectories/completed/2026-01/traj_yvdadtvdgnz3.json +59 -0
  90. package/.trajectories/completed/2026-01/traj_yvdadtvdgnz3.md +37 -0
  91. package/.trajectories/completed/2026-01/traj_z0vcw1wrzide.json +53 -0
  92. package/.trajectories/completed/2026-01/traj_z0vcw1wrzide.md +32 -0
  93. package/.trajectories/index.json +314 -0
  94. package/ARCHITECTURE.md +1245 -0
  95. package/README.md +1 -1
  96. package/TESTING.md +278 -0
  97. package/deploy/init-db.sql +5 -0
  98. package/deploy/scripts/setup-fly-workspaces.sh +69 -0
  99. package/deploy/scripts/setup-railway.sh +75 -0
  100. package/deploy/workspace/entrypoint-browser.sh +118 -0
  101. package/deploy/workspace/entrypoint.sh +348 -0
  102. package/deploy/workspace/git-credential-relay +111 -0
  103. package/dist/bridge/spawner.d.ts +53 -0
  104. package/dist/bridge/spawner.js +203 -19
  105. package/dist/bridge/types.d.ts +12 -0
  106. package/dist/cli/index.js +618 -5
  107. package/dist/cloud/api/auth.d.ts +3 -2
  108. package/dist/cloud/api/auth.js +10 -98
  109. package/dist/cloud/api/billing.js +30 -9
  110. package/dist/cloud/api/cli-pty-runner.d.ts +54 -0
  111. package/dist/cloud/api/cli-pty-runner.js +119 -0
  112. package/dist/cloud/api/codex-auth-helper.d.ts +15 -0
  113. package/dist/cloud/api/codex-auth-helper.js +100 -0
  114. package/dist/cloud/api/generic-webhooks.d.ts +8 -0
  115. package/dist/cloud/api/generic-webhooks.js +129 -0
  116. package/dist/cloud/api/git.d.ts +8 -0
  117. package/dist/cloud/api/git.js +152 -0
  118. package/dist/cloud/api/github-app.d.ts +11 -0
  119. package/dist/cloud/api/github-app.js +189 -0
  120. package/dist/cloud/api/middleware/planLimits.d.ts +7 -0
  121. package/dist/cloud/api/middleware/planLimits.js +39 -1
  122. package/dist/cloud/api/monitoring.d.ts +11 -0
  123. package/dist/cloud/api/monitoring.js +578 -0
  124. package/dist/cloud/api/nango-auth.d.ts +9 -0
  125. package/dist/cloud/api/nango-auth.js +377 -0
  126. package/dist/cloud/api/onboarding.d.ts +8 -1
  127. package/dist/cloud/api/onboarding.js +313 -119
  128. package/dist/cloud/api/policy.d.ts +8 -0
  129. package/dist/cloud/api/policy.js +229 -0
  130. package/dist/cloud/api/providers.js +114 -42
  131. package/dist/cloud/api/repos.d.ts +1 -0
  132. package/dist/cloud/api/repos.js +186 -0
  133. package/dist/cloud/api/test-helpers.d.ts +10 -0
  134. package/dist/cloud/api/test-helpers.js +575 -0
  135. package/dist/cloud/api/webhooks.d.ts +8 -0
  136. package/dist/cloud/api/webhooks.js +645 -0
  137. package/dist/cloud/api/workspaces.js +320 -12
  138. package/dist/cloud/billing/plans.js +32 -19
  139. package/dist/cloud/billing/types.d.ts +9 -3
  140. package/dist/cloud/config.d.ts +9 -2
  141. package/dist/cloud/config.js +13 -4
  142. package/dist/cloud/db/drizzle.d.ts +84 -1
  143. package/dist/cloud/db/drizzle.js +470 -0
  144. package/dist/cloud/db/index.d.ts +9 -4
  145. package/dist/cloud/db/index.js +11 -3
  146. package/dist/cloud/db/schema.d.ts +3283 -556
  147. package/dist/cloud/db/schema.js +314 -1
  148. package/dist/cloud/index.d.ts +1 -0
  149. package/dist/cloud/index.js +2 -0
  150. package/dist/cloud/provisioner/index.d.ts +56 -0
  151. package/dist/cloud/provisioner/index.js +676 -34
  152. package/dist/cloud/server.d.ts +1 -0
  153. package/dist/cloud/server.js +362 -13
  154. package/dist/cloud/services/auto-scaler.d.ts +152 -0
  155. package/dist/cloud/services/auto-scaler.js +439 -0
  156. package/dist/cloud/services/capacity-manager.d.ts +148 -0
  157. package/dist/cloud/services/capacity-manager.js +449 -0
  158. package/dist/cloud/services/ci-agent-spawner.d.ts +49 -0
  159. package/dist/cloud/services/ci-agent-spawner.js +373 -0
  160. package/dist/cloud/services/index.d.ts +12 -0
  161. package/dist/cloud/services/index.js +15 -0
  162. package/dist/cloud/services/mention-handler.d.ts +65 -0
  163. package/dist/cloud/services/mention-handler.js +405 -0
  164. package/dist/cloud/services/nango.d.ts +186 -0
  165. package/dist/cloud/services/nango.js +344 -0
  166. package/dist/cloud/services/persistence.d.ts +131 -0
  167. package/dist/cloud/services/persistence.js +200 -0
  168. package/dist/cloud/services/planLimits.d.ts +37 -0
  169. package/dist/cloud/services/planLimits.js +86 -5
  170. package/dist/cloud/services/scaling-orchestrator.d.ts +159 -0
  171. package/dist/cloud/services/scaling-orchestrator.js +502 -0
  172. package/dist/cloud/services/scaling-policy.d.ts +121 -0
  173. package/dist/cloud/services/scaling-policy.js +415 -0
  174. package/dist/cloud/vault/index.js +1 -1
  175. package/dist/cloud/webhooks/index.d.ts +24 -0
  176. package/dist/cloud/webhooks/index.js +29 -0
  177. package/dist/cloud/webhooks/parsers/github.d.ts +8 -0
  178. package/dist/cloud/webhooks/parsers/github.js +234 -0
  179. package/dist/cloud/webhooks/parsers/index.d.ts +23 -0
  180. package/dist/cloud/webhooks/parsers/index.js +30 -0
  181. package/dist/cloud/webhooks/parsers/linear.d.ts +9 -0
  182. package/dist/cloud/webhooks/parsers/linear.js +258 -0
  183. package/dist/cloud/webhooks/parsers/slack.d.ts +9 -0
  184. package/dist/cloud/webhooks/parsers/slack.js +214 -0
  185. package/dist/cloud/webhooks/responders/github.d.ts +8 -0
  186. package/dist/cloud/webhooks/responders/github.js +73 -0
  187. package/dist/cloud/webhooks/responders/index.d.ts +23 -0
  188. package/dist/cloud/webhooks/responders/index.js +30 -0
  189. package/dist/cloud/webhooks/responders/linear.d.ts +9 -0
  190. package/dist/cloud/webhooks/responders/linear.js +149 -0
  191. package/dist/cloud/webhooks/responders/slack.d.ts +20 -0
  192. package/dist/cloud/webhooks/responders/slack.js +178 -0
  193. package/dist/cloud/webhooks/router.d.ts +25 -0
  194. package/dist/cloud/webhooks/router.js +504 -0
  195. package/dist/cloud/webhooks/rules-engine.d.ts +24 -0
  196. package/dist/cloud/webhooks/rules-engine.js +287 -0
  197. package/dist/cloud/webhooks/types.d.ts +186 -0
  198. package/dist/cloud/webhooks/types.js +8 -0
  199. package/dist/continuity/formatter.d.ts +51 -0
  200. package/dist/continuity/formatter.js +313 -0
  201. package/dist/continuity/handoff-store.d.ts +67 -0
  202. package/dist/continuity/handoff-store.js +472 -0
  203. package/dist/continuity/index.d.ts +45 -0
  204. package/dist/continuity/index.js +48 -0
  205. package/dist/continuity/ledger-store.d.ts +110 -0
  206. package/dist/continuity/ledger-store.js +500 -0
  207. package/dist/continuity/manager.d.ts +178 -0
  208. package/dist/continuity/manager.js +562 -0
  209. package/dist/continuity/parser.d.ts +76 -0
  210. package/dist/continuity/parser.js +579 -0
  211. package/dist/continuity/types.d.ts +180 -0
  212. package/dist/continuity/types.js +9 -0
  213. package/dist/daemon/agent-manager.d.ts +27 -0
  214. package/dist/daemon/agent-manager.js +107 -6
  215. package/dist/daemon/agent-registry.d.ts +32 -0
  216. package/dist/daemon/agent-registry.js +42 -2
  217. package/dist/daemon/api.d.ts +12 -0
  218. package/dist/daemon/api.js +131 -2
  219. package/dist/daemon/cli-auth.d.ts +67 -0
  220. package/dist/daemon/cli-auth.js +537 -0
  221. package/dist/daemon/cloud-sync.js +9 -7
  222. package/dist/daemon/orchestrator.js +30 -0
  223. package/dist/daemon/router.d.ts +5 -0
  224. package/dist/daemon/router.js +78 -26
  225. package/dist/daemon/server.d.ts +5 -0
  226. package/dist/daemon/server.js +9 -1
  227. package/dist/daemon/services/browser-testing.d.ts +88 -0
  228. package/dist/daemon/services/browser-testing.js +244 -0
  229. package/dist/daemon/services/container-spawner.d.ts +135 -0
  230. package/dist/daemon/services/container-spawner.js +313 -0
  231. package/dist/daemon/types.d.ts +5 -1
  232. package/dist/dashboard/out/404.html +1 -1
  233. package/dist/dashboard/out/_next/static/chunks/116-2502180def231162.js +1 -0
  234. package/dist/dashboard/out/_next/static/chunks/282-980c2eb8fff20123.js +1 -0
  235. package/dist/dashboard/out/_next/static/chunks/699-3b1cd6618a45d259.js +1 -0
  236. package/dist/dashboard/out/_next/static/chunks/724-2dae7627550ab88f.js +9 -0
  237. package/dist/dashboard/out/_next/static/chunks/766-1f2dd8cb7f766b0b.js +1 -0
  238. package/dist/dashboard/out/_next/static/chunks/app/app/onboarding/page-3fdfa60e53f2810d.js +1 -0
  239. package/dist/dashboard/out/_next/static/chunks/app/app/page-e6381e5a6e1fbcfd.js +1 -0
  240. package/dist/dashboard/out/_next/static/chunks/app/connect-repos/page-3538dfe0ffe984b8.js +1 -0
  241. package/dist/dashboard/out/_next/static/chunks/app/history/{page-b6edd4dde8d08194.js → page-abb9ab2d329f56e9.js} +1 -1
  242. package/dist/dashboard/out/_next/static/chunks/app/layout-c0d118c0f92d969c.js +1 -0
  243. package/dist/dashboard/out/_next/static/chunks/app/login/page-c22d080201cbd9fb.js +1 -0
  244. package/dist/dashboard/out/_next/static/chunks/app/metrics/page-67a3e98d9a43a6ed.js +1 -0
  245. package/dist/dashboard/out/_next/static/chunks/app/page-77e9c65420a06cfb.js +1 -0
  246. package/dist/dashboard/out/_next/static/chunks/app/pricing/page-b08ed1c34d14434a.js +1 -0
  247. package/dist/dashboard/out/_next/static/chunks/app/providers/page-e88bc117ef7671c3.js +1 -0
  248. package/dist/dashboard/out/_next/static/chunks/app/signup/page-68d34f50baa8ab6b.js +1 -0
  249. package/dist/dashboard/out/_next/static/chunks/e868780c-48e5f147c90a3a41.js +18 -0
  250. package/dist/dashboard/out/_next/static/chunks/{main-app-5d692157a8eb1fd9.js → main-app-6e8e8d3ef4e0192a.js} +1 -1
  251. package/dist/dashboard/out/_next/static/chunks/{main-c2f423b9c9f4591b.js → main-ed4e1fb6f29c34cf.js} +1 -1
  252. package/dist/dashboard/out/_next/static/chunks/webpack-1cdd8ed57114d5e1.js +1 -0
  253. package/dist/dashboard/out/_next/static/css/29852f26181969a0.css +1 -0
  254. package/dist/dashboard/out/_next/static/css/7c3ae9e8617d42a5.css +1 -0
  255. package/dist/dashboard/out/app/onboarding.html +1 -0
  256. package/dist/dashboard/out/app/onboarding.txt +7 -0
  257. package/dist/dashboard/out/app.html +1 -14
  258. package/dist/dashboard/out/app.txt +2 -2
  259. package/dist/dashboard/out/connect-repos.html +1 -0
  260. package/dist/dashboard/out/connect-repos.txt +7 -0
  261. package/dist/dashboard/out/history.html +1 -1
  262. package/dist/dashboard/out/history.txt +2 -2
  263. package/dist/dashboard/out/index.html +1 -1
  264. package/dist/dashboard/out/index.txt +2 -2
  265. package/dist/dashboard/out/login.html +6 -0
  266. package/dist/dashboard/out/login.txt +7 -0
  267. package/dist/dashboard/out/metrics.html +1 -1
  268. package/dist/dashboard/out/metrics.txt +2 -2
  269. package/dist/dashboard/out/pricing.html +3 -3
  270. package/dist/dashboard/out/pricing.txt +2 -2
  271. package/dist/dashboard/out/providers.html +1 -0
  272. package/dist/dashboard/out/providers.txt +7 -0
  273. package/dist/dashboard/out/signup.html +6 -0
  274. package/dist/dashboard/out/signup.txt +7 -0
  275. package/dist/dashboard-server/server.js +1308 -8
  276. package/dist/hooks/emitter.d.ts +40 -0
  277. package/dist/hooks/emitter.js +63 -0
  278. package/dist/hooks/index.d.ts +3 -0
  279. package/dist/hooks/index.js +3 -0
  280. package/dist/hooks/registry.d.ts +173 -0
  281. package/dist/hooks/registry.js +476 -0
  282. package/dist/hooks/trajectory-hooks.d.ts +52 -0
  283. package/dist/hooks/trajectory-hooks.js +183 -0
  284. package/dist/hooks/types.d.ts +141 -0
  285. package/dist/index.d.ts +2 -0
  286. package/dist/index.js +3 -0
  287. package/dist/memory/adapters/index.d.ts +8 -0
  288. package/dist/memory/adapters/index.js +8 -0
  289. package/dist/memory/adapters/inmemory.d.ts +59 -0
  290. package/dist/memory/adapters/inmemory.js +195 -0
  291. package/dist/memory/adapters/supermemory.d.ts +71 -0
  292. package/dist/memory/adapters/supermemory.js +338 -0
  293. package/dist/memory/factory.d.ts +48 -0
  294. package/dist/memory/factory.js +143 -0
  295. package/dist/memory/index.d.ts +32 -0
  296. package/dist/memory/index.js +32 -0
  297. package/dist/memory/memory-hooks.d.ts +60 -0
  298. package/dist/memory/memory-hooks.js +313 -0
  299. package/dist/memory/service.d.ts +49 -0
  300. package/dist/memory/service.js +146 -0
  301. package/dist/memory/types.d.ts +195 -0
  302. package/dist/memory/types.js +8 -0
  303. package/dist/policy/agent-policy.d.ts +225 -0
  304. package/dist/policy/agent-policy.js +665 -0
  305. package/dist/policy/cloud-policy-fetcher.d.ts +12 -0
  306. package/dist/policy/cloud-policy-fetcher.js +64 -0
  307. package/dist/resiliency/crash-insights.d.ts +156 -0
  308. package/dist/resiliency/crash-insights.js +492 -0
  309. package/dist/resiliency/gossip-health.d.ts +137 -0
  310. package/dist/resiliency/gossip-health.js +241 -0
  311. package/dist/resiliency/index.d.ts +5 -0
  312. package/dist/resiliency/index.js +5 -0
  313. package/dist/resiliency/leader-watchdog.d.ts +109 -0
  314. package/dist/resiliency/leader-watchdog.js +189 -0
  315. package/dist/resiliency/memory-monitor.d.ts +172 -0
  316. package/dist/resiliency/memory-monitor.js +593 -0
  317. package/dist/resiliency/stateless-lead.d.ts +149 -0
  318. package/dist/resiliency/stateless-lead.js +308 -0
  319. package/dist/resiliency/supervisor.d.ts +38 -0
  320. package/dist/resiliency/supervisor.js +122 -0
  321. package/dist/shared/cli-auth-config.d.ts +91 -0
  322. package/dist/shared/cli-auth-config.js +264 -0
  323. package/dist/storage/adapter.d.ts +1 -1
  324. package/dist/trajectory/config.d.ts +84 -0
  325. package/dist/trajectory/config.js +163 -0
  326. package/dist/trajectory/index.d.ts +8 -0
  327. package/dist/trajectory/index.js +8 -0
  328. package/dist/trajectory/integration.d.ts +292 -0
  329. package/dist/trajectory/integration.js +834 -0
  330. package/dist/utils/logger.js +1 -1
  331. package/dist/utils/project-namespace.d.ts +24 -0
  332. package/dist/utils/project-namespace.js +84 -0
  333. package/dist/wrapper/parser.d.ts +10 -0
  334. package/dist/wrapper/parser.js +100 -33
  335. package/dist/wrapper/pty-wrapper.d.ts +197 -16
  336. package/dist/wrapper/pty-wrapper.js +943 -106
  337. package/dist/wrapper/shared.d.ts +165 -0
  338. package/dist/wrapper/shared.js +270 -0
  339. package/dist/wrapper/tmux-wrapper.d.ts +73 -11
  340. package/dist/wrapper/tmux-wrapper.js +541 -120
  341. package/package.json +16 -16
  342. package/scripts/postinstall.js +60 -0
  343. package/test-push.txt +1 -0
  344. package/bin/tmux +0 -0
  345. package/dist/bridge/config.d.ts.map +0 -1
  346. package/dist/bridge/config.js.map +0 -1
  347. package/dist/bridge/index.d.ts.map +0 -1
  348. package/dist/bridge/index.js.map +0 -1
  349. package/dist/bridge/multi-project-client.d.ts.map +0 -1
  350. package/dist/bridge/multi-project-client.js.map +0 -1
  351. package/dist/bridge/shadow-cli.d.ts.map +0 -1
  352. package/dist/bridge/shadow-cli.js.map +0 -1
  353. package/dist/bridge/shadow-config.d.ts.map +0 -1
  354. package/dist/bridge/shadow-config.js.map +0 -1
  355. package/dist/bridge/spawner.d.ts.map +0 -1
  356. package/dist/bridge/spawner.js.map +0 -1
  357. package/dist/bridge/teams-config.d.ts.map +0 -1
  358. package/dist/bridge/teams-config.js.map +0 -1
  359. package/dist/bridge/types.d.ts.map +0 -1
  360. package/dist/bridge/types.js.map +0 -1
  361. package/dist/bridge/utils.d.ts.map +0 -1
  362. package/dist/bridge/utils.js.map +0 -1
  363. package/dist/cli/index.d.ts.map +0 -1
  364. package/dist/cli/index.js.map +0 -1
  365. package/dist/cloud/api/auth.d.ts.map +0 -1
  366. package/dist/cloud/api/auth.js.map +0 -1
  367. package/dist/cloud/api/billing.d.ts.map +0 -1
  368. package/dist/cloud/api/billing.js.map +0 -1
  369. package/dist/cloud/api/coordinators.d.ts.map +0 -1
  370. package/dist/cloud/api/coordinators.js.map +0 -1
  371. package/dist/cloud/api/daemons.d.ts.map +0 -1
  372. package/dist/cloud/api/daemons.js.map +0 -1
  373. package/dist/cloud/api/middleware/planLimits.d.ts.map +0 -1
  374. package/dist/cloud/api/middleware/planLimits.js.map +0 -1
  375. package/dist/cloud/api/onboarding.d.ts.map +0 -1
  376. package/dist/cloud/api/onboarding.js.map +0 -1
  377. package/dist/cloud/api/providers.d.ts.map +0 -1
  378. package/dist/cloud/api/providers.js.map +0 -1
  379. package/dist/cloud/api/repos.d.ts.map +0 -1
  380. package/dist/cloud/api/repos.js.map +0 -1
  381. package/dist/cloud/api/teams.d.ts.map +0 -1
  382. package/dist/cloud/api/teams.js.map +0 -1
  383. package/dist/cloud/api/usage.d.ts.map +0 -1
  384. package/dist/cloud/api/usage.js.map +0 -1
  385. package/dist/cloud/api/workspaces.d.ts.map +0 -1
  386. package/dist/cloud/api/workspaces.js.map +0 -1
  387. package/dist/cloud/billing/index.d.ts.map +0 -1
  388. package/dist/cloud/billing/index.js.map +0 -1
  389. package/dist/cloud/billing/plans.d.ts.map +0 -1
  390. package/dist/cloud/billing/plans.js.map +0 -1
  391. package/dist/cloud/billing/service.d.ts.map +0 -1
  392. package/dist/cloud/billing/service.js.map +0 -1
  393. package/dist/cloud/billing/types.d.ts.map +0 -1
  394. package/dist/cloud/billing/types.js.map +0 -1
  395. package/dist/cloud/config.d.ts.map +0 -1
  396. package/dist/cloud/config.js.map +0 -1
  397. package/dist/cloud/db/drizzle.d.ts.map +0 -1
  398. package/dist/cloud/db/drizzle.js.map +0 -1
  399. package/dist/cloud/db/index.d.ts.map +0 -1
  400. package/dist/cloud/db/index.js.map +0 -1
  401. package/dist/cloud/db/schema.d.ts.map +0 -1
  402. package/dist/cloud/db/schema.js.map +0 -1
  403. package/dist/cloud/index.d.ts.map +0 -1
  404. package/dist/cloud/index.js.map +0 -1
  405. package/dist/cloud/provisioner/index.d.ts.map +0 -1
  406. package/dist/cloud/provisioner/index.js.map +0 -1
  407. package/dist/cloud/server.d.ts.map +0 -1
  408. package/dist/cloud/server.js.map +0 -1
  409. package/dist/cloud/services/coordinator.d.ts.map +0 -1
  410. package/dist/cloud/services/coordinator.js.map +0 -1
  411. package/dist/cloud/services/planLimits.d.ts.map +0 -1
  412. package/dist/cloud/services/planLimits.js.map +0 -1
  413. package/dist/cloud/vault/index.d.ts.map +0 -1
  414. package/dist/cloud/vault/index.js.map +0 -1
  415. package/dist/daemon/agent-manager.d.ts.map +0 -1
  416. package/dist/daemon/agent-manager.js.map +0 -1
  417. package/dist/daemon/agent-registry.d.ts.map +0 -1
  418. package/dist/daemon/agent-registry.js.map +0 -1
  419. package/dist/daemon/api.d.ts.map +0 -1
  420. package/dist/daemon/api.js.map +0 -1
  421. package/dist/daemon/auth.d.ts.map +0 -1
  422. package/dist/daemon/auth.js.map +0 -1
  423. package/dist/daemon/cloud-sync.d.ts.map +0 -1
  424. package/dist/daemon/cloud-sync.js.map +0 -1
  425. package/dist/daemon/connection.d.ts.map +0 -1
  426. package/dist/daemon/connection.js.map +0 -1
  427. package/dist/daemon/index.d.ts.map +0 -1
  428. package/dist/daemon/index.js.map +0 -1
  429. package/dist/daemon/orchestrator.d.ts.map +0 -1
  430. package/dist/daemon/orchestrator.js.map +0 -1
  431. package/dist/daemon/registry.d.ts.map +0 -1
  432. package/dist/daemon/registry.js.map +0 -1
  433. package/dist/daemon/router.d.ts.map +0 -1
  434. package/dist/daemon/router.js.map +0 -1
  435. package/dist/daemon/server.d.ts.map +0 -1
  436. package/dist/daemon/server.js.map +0 -1
  437. package/dist/daemon/types.d.ts.map +0 -1
  438. package/dist/daemon/types.js.map +0 -1
  439. package/dist/daemon/workspace-manager.d.ts.map +0 -1
  440. package/dist/daemon/workspace-manager.js.map +0 -1
  441. package/dist/dashboard/out/_next/static/chunks/693-7b3301d8f6bc5014.js +0 -1
  442. package/dist/dashboard/out/_next/static/chunks/713-f78477eb185f1f4d.js +0 -1
  443. package/dist/dashboard/out/_next/static/chunks/766-e53e1cfe39b0b5b5.js +0 -1
  444. package/dist/dashboard/out/_next/static/chunks/900-037c64bfd797fb2a.js +0 -1
  445. package/dist/dashboard/out/_next/static/chunks/app/app/page-e3d9e1f4466b9bae.js +0 -1
  446. package/dist/dashboard/out/_next/static/chunks/app/layout-2433bb48965f4333.js +0 -1
  447. package/dist/dashboard/out/_next/static/chunks/app/metrics/page-e68825a81db67ba1.js +0 -1
  448. package/dist/dashboard/out/_next/static/chunks/app/page-cc108bf68c8a657f.js +0 -1
  449. package/dist/dashboard/out/_next/static/chunks/app/pricing/page-d80e03a5297f95b6.js +0 -1
  450. package/dist/dashboard/out/_next/static/chunks/webpack-a5acc2831d094776.js +0 -1
  451. package/dist/dashboard/out/_next/static/css/79b80143647a07d7.css +0 -1
  452. package/dist/dashboard/out/_next/static/css/8cf277370ad48cfe.css +0 -1
  453. package/dist/dashboard-server/metrics.d.ts.map +0 -1
  454. package/dist/dashboard-server/metrics.js.map +0 -1
  455. package/dist/dashboard-server/needs-attention.d.ts.map +0 -1
  456. package/dist/dashboard-server/needs-attention.js.map +0 -1
  457. package/dist/dashboard-server/server.d.ts.map +0 -1
  458. package/dist/dashboard-server/server.js.map +0 -1
  459. package/dist/dashboard-server/start.d.ts.map +0 -1
  460. package/dist/dashboard-server/start.js.map +0 -1
  461. package/dist/hooks/inbox-check/hook.d.ts.map +0 -1
  462. package/dist/hooks/inbox-check/hook.js.map +0 -1
  463. package/dist/hooks/inbox-check/index.d.ts.map +0 -1
  464. package/dist/hooks/inbox-check/index.js.map +0 -1
  465. package/dist/hooks/inbox-check/types.d.ts.map +0 -1
  466. package/dist/hooks/inbox-check/types.js.map +0 -1
  467. package/dist/hooks/inbox-check/utils.d.ts.map +0 -1
  468. package/dist/hooks/inbox-check/utils.js.map +0 -1
  469. package/dist/hooks/index.d.ts.map +0 -1
  470. package/dist/hooks/index.js.map +0 -1
  471. package/dist/hooks/types.d.ts.map +0 -1
  472. package/dist/hooks/types.js.map +0 -1
  473. package/dist/index.d.ts.map +0 -1
  474. package/dist/index.js.map +0 -1
  475. package/dist/protocol/framing.d.ts.map +0 -1
  476. package/dist/protocol/framing.js.map +0 -1
  477. package/dist/protocol/index.d.ts.map +0 -1
  478. package/dist/protocol/index.js.map +0 -1
  479. package/dist/protocol/types.d.ts.map +0 -1
  480. package/dist/protocol/types.js.map +0 -1
  481. package/dist/resiliency/context-persistence.d.ts.map +0 -1
  482. package/dist/resiliency/context-persistence.js.map +0 -1
  483. package/dist/resiliency/health-monitor.d.ts.map +0 -1
  484. package/dist/resiliency/health-monitor.js.map +0 -1
  485. package/dist/resiliency/index.d.ts.map +0 -1
  486. package/dist/resiliency/index.js.map +0 -1
  487. package/dist/resiliency/logger.d.ts.map +0 -1
  488. package/dist/resiliency/logger.js.map +0 -1
  489. package/dist/resiliency/metrics.d.ts.map +0 -1
  490. package/dist/resiliency/metrics.js.map +0 -1
  491. package/dist/resiliency/provider-context.d.ts.map +0 -1
  492. package/dist/resiliency/provider-context.js.map +0 -1
  493. package/dist/resiliency/supervisor.d.ts.map +0 -1
  494. package/dist/resiliency/supervisor.js.map +0 -1
  495. package/dist/state/agent-state.d.ts.map +0 -1
  496. package/dist/state/agent-state.js.map +0 -1
  497. package/dist/storage/adapter.d.ts.map +0 -1
  498. package/dist/storage/adapter.js.map +0 -1
  499. package/dist/storage/sqlite-adapter.d.ts.map +0 -1
  500. package/dist/storage/sqlite-adapter.js.map +0 -1
  501. package/dist/utils/agent-config.d.ts.map +0 -1
  502. package/dist/utils/agent-config.js.map +0 -1
  503. package/dist/utils/command-resolver.d.ts.map +0 -1
  504. package/dist/utils/command-resolver.js.map +0 -1
  505. package/dist/utils/index.d.ts.map +0 -1
  506. package/dist/utils/index.js.map +0 -1
  507. package/dist/utils/logger.d.ts.map +0 -1
  508. package/dist/utils/logger.js.map +0 -1
  509. package/dist/utils/name-generator.d.ts.map +0 -1
  510. package/dist/utils/name-generator.js.map +0 -1
  511. package/dist/utils/project-namespace.d.ts.map +0 -1
  512. package/dist/utils/project-namespace.js.map +0 -1
  513. package/dist/utils/tmux-resolver.d.ts.map +0 -1
  514. package/dist/utils/tmux-resolver.js.map +0 -1
  515. package/dist/utils/update-checker.d.ts.map +0 -1
  516. package/dist/utils/update-checker.js.map +0 -1
  517. package/dist/wrapper/client.d.ts.map +0 -1
  518. package/dist/wrapper/client.js.map +0 -1
  519. package/dist/wrapper/inbox.d.ts.map +0 -1
  520. package/dist/wrapper/inbox.js.map +0 -1
  521. package/dist/wrapper/index.d.ts.map +0 -1
  522. package/dist/wrapper/index.js.map +0 -1
  523. package/dist/wrapper/parser.d.ts.map +0 -1
  524. package/dist/wrapper/parser.js.map +0 -1
  525. package/dist/wrapper/pty-wrapper.d.ts.map +0 -1
  526. package/dist/wrapper/pty-wrapper.js.map +0 -1
  527. package/dist/wrapper/tmux-wrapper.d.ts.map +0 -1
  528. package/dist/wrapper/tmux-wrapper.js.map +0 -1
  529. package/docs/AGENTS.md +0 -513
  530. package/docs/ARCHITECTURE_DECISIONS.md +0 -175
  531. package/docs/CHANGELOG.md +0 -11
  532. package/docs/CLI-SIMPLIFICATION-COMPLETE.md +0 -48
  533. package/docs/CLOUD-ARCHITECTURE.md +0 -652
  534. package/docs/CLOUD-ONBOARDING-DESIGN.md +0 -1983
  535. package/docs/COMPETITIVE_ANALYSIS.md +0 -897
  536. package/docs/CONTRIBUTING.md +0 -151
  537. package/docs/DESIGN_BRIDGE_STAFFING.md +0 -878
  538. package/docs/DESIGN_V2.md +0 -1079
  539. package/docs/INTEGRATION-GUIDE.md +0 -926
  540. package/docs/MONETIZATION.md +0 -1679
  541. package/docs/PROPOSAL-trajectories.md +0 -1582
  542. package/docs/PROTOCOL.md +0 -325
  543. package/docs/SCALING_ANALYSIS.md +0 -280
  544. package/docs/TESTING_PRESENCE_FEATURES.md +0 -327
  545. package/docs/TMUX_IMPLEMENTATION_NOTES.md +0 -364
  546. package/docs/TMUX_IMPROVEMENTS.md +0 -968
  547. package/docs/agent-relay-snippet.md +0 -168
  548. package/docs/competitive-analysis-mcp-agent-mail.md +0 -389
  549. package/docs/dashboard-v2-plan.md +0 -179
  550. package/docs/guides/CLOUD.md +0 -236
  551. package/docs/guides/LOCAL.md +0 -535
  552. package/docs/guides/SELF-HOSTED.md +0 -494
  553. package/docs/proposals/shadow-as-subagent.md +0 -765
  554. package/docs/proposals/slack-bot-integration.md +0 -1457
  555. package/docs/removable-code-analysis.md +0 -24
  556. package/scripts/dev/PUBLIC_RELEASE_PLAN.md +0 -88
  557. package/scripts/dev/dev-team-setup.sh +0 -431
  558. package/scripts/e2e-test.sh +0 -119
  559. package/scripts/games/game-protocol.md +0 -79
  560. package/scripts/games/hearts-setup.sh +0 -264
  561. package/scripts/tictactoe-setup.sh +0 -181
  562. /package/dist/dashboard/out/_next/static/chunks/{117-b2cd8d6485aacf2b.js → 117-f7b8ab0809342e77.js} +0 -0
  563. /package/dist/dashboard/out/_next/static/chunks/{648-8f3f26864ce515e5.js → 648-5cc6e1921389a58a.js} +0 -0
  564. /package/dist/dashboard/out/_next/static/chunks/app/_not-found/{page-0b990dbb71d72a98.js → page-53b8a69f76db17d0.js} +0 -0
  565. /package/dist/dashboard/out/_next/static/chunks/{fd9d1056-bf46c09eb57e019c.js → fd9d1056-609918ca7b6280bb.js} +0 -0
  566. /package/dist/dashboard/out/_next/static/{6HHWb2ZmnJ4OSm0zUP7h4 → wPgKJtcOmTFLpUncDg16A}/_buildManifest.js +0 -0
  567. /package/dist/dashboard/out/_next/static/{6HHWb2ZmnJ4OSm0zUP7h4 → wPgKJtcOmTFLpUncDg16A}/_ssgManifest.js +0 -0
@@ -0,0 +1 @@
1
+ "use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[699],{9165:function(e,t,r){r.d(t,{Zk:function(){return l},_V:function(){return o},xv:function(){return d}});var s=r(9116);let n=new Set,a=null;function o(){return a}function i(e){let t=e.headers.get("X-CSRF-Token");t&&(a=t,(0,s.aM)(t))}function l(e){return n.add(e),()=>n.delete(e)}async function c(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};try{let r={"Content-Type":"application/json",...t.headers};t.method&&"GET"!==t.method&&a&&(r["X-CSRF-Token"]=a);let s=await fetch(e,{...t,credentials:"include",headers:r});i(s);let o=await s.json();if(401===s.status||"object"==typeof o&&null!==o&&("SESSION_EXPIRED"===o.code||"USER_NOT_FOUND"===o.code)){let e={error:o.error||"Session expired",code:o.code||"SESSION_EXPIRED",message:o.message||"Your session has expired. Please log in again."};return!function(e){for(let t of n)try{t(e)}catch(e){console.error("[cloudApi] Session expired listener error:",e)}}(e),{success:!1,error:e.message,sessionExpired:!0}}if(!s.ok)return{success:!1,error:o.error||"Request failed with status ".concat(s.status)};return{success:!0,data:o}}catch(e){return{success:!1,error:e instanceof Error?e.message:"Network error"}}}let d={async getNangoLoginSession(){try{let e=await fetch("/api/auth/nango/login-session",{credentials:"include"});i(e);let t=await e.json();if(!e.ok)return{success:!1,error:t.error||"Failed to create login session"};return{success:!0,data:t}}catch(e){return{success:!1,error:e instanceof Error?e.message:"Network error"}}},async checkNangoLoginStatus(e){try{let t=await fetch("/api/auth/nango/login-status/".concat(encodeURIComponent(e)),{credentials:"include"});i(t);let r=await t.json();if(!t.ok)return{success:!1,error:r.error||"Failed to check login status"};return{success:!0,data:r}}catch(e){return{success:!1,error:e instanceof Error?e.message:"Network error"}}},getNangoRepoSession:async()=>c("/api/auth/nango/repo-session"),checkNangoRepoStatus:async e=>c("/api/auth/nango/repo-status/".concat(encodeURIComponent(e))),async checkSession(){try{let e=await fetch("/api/auth/session",{credentials:"include"});return i(e),await e.json()}catch(e){return{authenticated:!1,code:"SESSION_ERROR",message:"Failed to check session status"}}},getMe:async()=>c("/api/auth/me"),async logout(){try{let e={};a&&(e["X-CSRF-Token"]=a);let t=await fetch("/api/auth/logout",{method:"POST",credentials:"include",headers:e});return await t.json()}catch(e){return{success:!1,error:"Network error"}}},getWorkspaces:async()=>c("/api/workspaces"),getWorkspace:async e=>c("/api/workspaces/".concat(encodeURIComponent(e))),createWorkspace:async e=>c("/api/workspaces",{method:"POST",body:JSON.stringify(e)}),getPrimaryWorkspace:async()=>c("/api/workspaces/primary"),getWorkspaceSummary:async()=>c("/api/workspaces/summary"),getWorkspaceStatus:async e=>c("/api/workspaces/".concat(encodeURIComponent(e),"/status")),wakeupWorkspace:async e=>c("/api/workspaces/".concat(encodeURIComponent(e),"/wakeup"),{method:"POST"}),restartWorkspace:async e=>c("/api/workspaces/".concat(encodeURIComponent(e),"/restart"),{method:"POST"}),getProviders:async()=>c("/api/providers"),disconnectProvider:async e=>c("/api/providers/".concat(encodeURIComponent(e)),{method:"DELETE"}),getWorkspaceMembers:async e=>c("/api/workspaces/".concat(encodeURIComponent(e),"/members")),async inviteMember(e,t){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"member";return c("/api/workspaces/".concat(encodeURIComponent(e),"/members"),{method:"POST",body:JSON.stringify({githubUsername:t,role:r})})},getPendingInvites:async()=>c("/api/invites"),acceptInvite:async e=>c("/api/invites/".concat(encodeURIComponent(e),"/accept"),{method:"POST"}),declineInvite:async e=>c("/api/invites/".concat(encodeURIComponent(e),"/decline"),{method:"POST"}),updateMemberRole:async(e,t,r)=>c("/api/workspaces/".concat(encodeURIComponent(e),"/members/").concat(encodeURIComponent(t)),{method:"PATCH",body:JSON.stringify({role:r})}),removeMember:async(e,t)=>c("/api/workspaces/".concat(encodeURIComponent(e),"/members/").concat(encodeURIComponent(t)),{method:"DELETE"}),getBillingPlans:async()=>c("/api/billing/plans"),getSubscription:async()=>c("/api/billing/subscription"),async createCheckoutSession(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"month";return c("/api/billing/checkout",{method:"POST",body:JSON.stringify({tier:e,interval:t})})},createBillingPortal:async()=>c("/api/billing/portal",{method:"POST"}),async changeSubscription(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"month";return c("/api/billing/change",{method:"POST",body:JSON.stringify({tier:e,interval:t})})},cancelSubscription:async()=>c("/api/billing/cancel",{method:"POST"}),resumeSubscription:async()=>c("/api/billing/resume",{method:"POST"}),getInvoices:async()=>c("/api/billing/invoices"),stopWorkspace:async e=>c("/api/workspaces/".concat(encodeURIComponent(e),"/stop"),{method:"POST"}),deleteWorkspace:async e=>c("/api/workspaces/".concat(encodeURIComponent(e)),{method:"DELETE"}),addReposToWorkspace:async(e,t)=>c("/api/workspaces/".concat(encodeURIComponent(e),"/repos"),{method:"POST",body:JSON.stringify({repositoryIds:t})}),setCustomDomain:async(e,t)=>c("/api/workspaces/".concat(encodeURIComponent(e),"/domain"),{method:"POST",body:JSON.stringify({domain:t})}),verifyCustomDomain:async e=>c("/api/workspaces/".concat(encodeURIComponent(e),"/domain/verify"),{method:"POST"}),removeCustomDomain:async e=>c("/api/workspaces/".concat(encodeURIComponent(e),"/domain"),{method:"DELETE"}),getWorkspaceDetails:async e=>c("/api/workspaces/".concat(encodeURIComponent(e))),getRepos:async()=>c("/api/github-app/repos")}},637:function(e,t,r){r.d(t,{GW:function(){return l},hP:function(){return c},oU:function(){return i},yh:function(){return a}});let s={backend:{primary:"#1264a3",light:"#e8f4fd",dark:"#0d4f82",text:"#ffffff"},frontend:{primary:"#7c3aed",light:"#f3e8ff",dark:"#5b21b6",text:"#ffffff"},infra:{primary:"#ea580c",light:"#fff7ed",dark:"#c2410c",text:"#ffffff"},lead:{primary:"#2bac76",light:"#ecfdf5",dark:"#059669",text:"#ffffff"},test:{primary:"#0d9488",light:"#f0fdfa",dark:"#0f766e",text:"#ffffff"},data:{primary:"#dc2626",light:"#fef2f2",dark:"#b91c1c",text:"#ffffff"},api:{primary:"#2563eb",light:"#eff6ff",dark:"#1d4ed8",text:"#ffffff"},worker:{primary:"#9333ea",light:"#faf5ff",dark:"#7e22ce",text:"#ffffff"},monitor:{primary:"#0891b2",light:"#ecfeff",dark:"#0e7490",text:"#ffffff"},security:{primary:"#be123c",light:"#fff1f2",dark:"#9f1239",text:"#ffffff"}},n=[{primary:"#6366f1",light:"#eef2ff",dark:"#4f46e5",text:"#ffffff"},{primary:"#ec4899",light:"#fdf2f8",dark:"#db2777",text:"#ffffff"},{primary:"#14b8a6",light:"#f0fdfa",dark:"#0d9488",text:"#ffffff"},{primary:"#f59e0b",light:"#fffbeb",dark:"#d97706",text:"#000000"},{primary:"#8b5cf6",light:"#f5f3ff",dark:"#7c3aed",text:"#ffffff"},{primary:"#06b6d4",light:"#ecfeff",dark:"#0891b2",text:"#ffffff"},{primary:"#f43f5e",light:"#fff1f2",dark:"#e11d48",text:"#ffffff"},{primary:"#84cc16",light:"#f7fee7",dark:"#65a30d",text:"#000000"}],a={online:"#22c55e",offline:"#6b7280",busy:"#eab308",processing:"#6366f1",error:"#ef4444",attention:"#ef4444",stuck:"#f97316"};function o(e){return e.toLowerCase().split("-").filter(Boolean)}function i(e){return o(e)[0]||e.toLowerCase()}function l(e){let t=i(e);return t in s?s[t]:n[function(e){let t=0;for(let r=0;r<e.length;r++)t=(t<<5)-t+e.charCodeAt(r),t&=t;return Math.abs(t)}(t)%n.length]}function c(e){let t=o(e);return 0===t.length?e.substring(0,2).toUpperCase():t.length>=2?(t[0][0]+t[1][0]).toUpperCase():t[0].substring(0,2).toUpperCase()}},6699:function(e,t,r){r.d(t,{g:function(){return s8}});var s=r(7437),n=r(2265),a=r(637);function o(e){let t=new Map;for(let r of e){let e=r.team||(0,a.oU)(r.name),s=(0,a.GW)(r.name),n=t.get(e);n||(n={prefix:e,displayName:d(e),color:s,agents:[],isExpanded:!0},t.set(e,n)),n.agents.push(r)}let r=Array.from(t.values()).sort((e,t)=>e.prefix.localeCompare(t.prefix));for(let e of r)e.agents.sort((e,t)=>e.name.localeCompare(t.name));return r}function i(e){let t=e.split("-").filter(Boolean);return 0===t.length?e:d(t[t.length-1])}function l(e){return e.split("-").filter(Boolean).map(d).join(" > ")}function c(e,t){return t?e.filter(e=>(function(e,t){if(!t)return!0;let r=t.toLowerCase(),s=e.toLowerCase();return!!s.includes(r)||s.split("-").some(e=>e.includes(r))})(e.name,t)):e}function d(e){return e?e.charAt(0).toUpperCase()+e.slice(1):e}function x(e){let t=0,r=0,s=0;for(let n of e)"online"===n.status?t++:"offline"===n.status&&r++,n.needsAttention&&s++;return{total:e.length,online:t,offline:r,needsAttention:s}}function u(e){let{isProcessing:t,processingStartedAt:r,size:a="medium",showElapsed:o=!1,showLabel:i=!1}=e,[l,c]=(0,n.useState)(0);if((0,n.useEffect)(()=>{if(!t||!r){c(0);return}let e=()=>{c(Date.now()-r)};e();let s=setInterval(e,1e3);return()=>clearInterval(s)},[t,r]),!t)return null;let d={small:"w-1 h-1",medium:"w-1.5 h-1.5",large:"w-2 h-2"};return(0,s.jsxs)("span",{className:"inline-flex items-center gap-1.5 text-accent-purple",title:"Processing...",children:[(0,s.jsxs)("span",{className:"inline-flex items-center ".concat({small:"gap-0.5",medium:"gap-1",large:"gap-1.5"}[a]),children:[(0,s.jsx)("span",{className:"".concat(d[a]," rounded-full bg-accent-purple animate-bounce"),style:{animationDelay:"0ms",animationDuration:"800ms"}}),(0,s.jsx)("span",{className:"".concat(d[a]," rounded-full bg-accent-purple animate-bounce"),style:{animationDelay:"150ms",animationDuration:"800ms"}}),(0,s.jsx)("span",{className:"".concat(d[a]," rounded-full bg-accent-purple animate-bounce"),style:{animationDelay:"300ms",animationDuration:"800ms"}})]}),i&&(0,s.jsx)("span",{className:"text-xs font-medium text-accent-purple",children:"thinking"}),o&&l>0&&(0,s.jsx)("span",{className:"text-xs text-accent-purple/70",children:(e=>{let t=Math.floor(e/1e3);return t<60?"".concat(t,"s"):"".concat(Math.floor(t/60),"m ").concat(t%60,"s")})(l)})]})}function m(e){let{isProcessing:t}=e;return t?(0,s.jsx)("span",{className:"thinking-dot-inline",title:"Processing...",children:(0,s.jsx)("span",{className:"thinking-dot-pulse"})}):null}function h(e){if(e<6e4)return"<1m";let t=Math.floor(e/6e4);if(t<60)return"".concat(t,"m");let r=Math.floor(t/60),s=t%60;return 0===s?"".concat(r,"h"):"".concat(r,"h ").concat(s,"m")}function p(e){let{agent:t,isSelected:r=!1,showBreadcrumb:n=!1,compact:o=!1,displayNameOverride:c,onClick:d,onMessageClick:x,onReleaseClick:p,onLogsClick:v,onProfileClick:w}=e,N=(0,a.GW)(t.name),k=(0,a.hP)(t.name),C=c||i(t.name),S=!t.lastMessageReceivedAt||t.lastOutputAt&&t.lastOutputAt>=t.lastMessageReceivedAt?0:Date.now()-t.lastMessageReceivedAt,A=t.isStuck||S>0,L=A?a.yh.stuck:a.yh[t.status]||a.yh.offline,E="online"===t.status,W=function(e,t,r,s){if(r&&s)return"Stuck - Agent received message ".concat(h(s)," ago but hasn't responded");if(t)return"Processing - Agent is actively working";switch(e){case"online":return"Connected - Agent is online and ready";case"offline":return"Disconnected - Agent is not connected";case"busy":return"Busy - Agent is occupied with a task";case"processing":return"Processing - Agent is actively working";case"error":return"Error - Agent encountered an error";case"attention":return"Attention - Agent requires user input";case"stuck":return"Stuck - Agent may be blocked or unresponsive";default:return"Status: ".concat(e)}}(t.status,t.isProcessing,A,S),M=()=>{null==d||d(t)},D=e=>{e.stopPropagation(),null==p||p(t)},T=e=>{e.stopPropagation(),null==v||v(t)},R=e=>{e.stopPropagation(),null==w||w(t)};return o?(0,s.jsxs)("div",{className:"\n group relative flex items-center gap-3 py-2.5 px-3 rounded-lg cursor-pointer\n transition-all duration-300 ease-out\n hover:bg-gradient-to-r hover:from-[rgba(255,255,255,0.03)] hover:to-transparent\n ".concat(r?"bg-gradient-to-r from-[rgba(255,255,255,0.06)] to-transparent":"","\n "),onClick:M,style:{borderLeft:r?"2px solid ".concat(N.primary):"2px solid transparent",boxShadow:r?"inset 4px 0 12px -4px ".concat(N.primary,"40"):"none"},children:[(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsxs)("div",{className:"\n w-8 h-8 rounded-lg flex items-center justify-center font-bold text-[11px] tracking-wide\n transition-all duration-300 relative overflow-hidden\n ".concat(E?"shadow-lg":"opacity-60","\n "),style:{background:"linear-gradient(135deg, ".concat(N.primary,", ").concat(N.primary,"99)"),boxShadow:E?"0 2px 12px ".concat(N.primary,"50"):"none"},children:[(0,s.jsx)("div",{className:"absolute inset-0 opacity-30",style:{background:"linear-gradient(135deg, rgba(255,255,255,0.3) 0%, transparent 50%)"}}),(0,s.jsx)("span",{className:"relative z-10",style:{color:N.text},children:k})]}),E&&(0,s.jsx)("div",{className:"absolute -bottom-0.5 -right-0.5 w-3 h-3 rounded-full border-2 border-bg-primary",style:{backgroundColor:L,boxShadow:"0 0 8px ".concat(L)},title:W})]}),(0,s.jsxs)("div",{className:"flex-1 min-w-0 flex flex-col gap-0.5",children:[(0,s.jsx)("span",{className:"\n text-[13px] font-semibold tracking-tight truncate transition-colors duration-200\n ".concat(E?"text-text-primary":"text-text-secondary","\n "),children:C}),!c&&(0,s.jsx)("span",{className:"text-[10px] text-text-muted truncate font-mono opacity-70",children:l(t.name)})]}),(0,s.jsxs)("div",{className:"flex items-center gap-2 shrink-0",children:[w&&(0,s.jsx)("button",{className:"relative bg-transparent border border-transparent text-text-dim p-1.5 cursor-pointer flex items-center justify-center rounded-md transition-all duration-200 opacity-100 md:opacity-0 md:group-hover:opacity-100 hover:bg-[#a855f7]/10 hover:border-[#a855f7]/30 hover:text-[#a855f7] hover:shadow-[0_0_12px_rgba(168,85,247,0.25)]",onClick:R,title:"View profile",children:(0,s.jsx)(y,{})}),t.isSpawned&&v&&(0,s.jsx)("button",{className:"relative bg-transparent border border-transparent text-text-dim p-1.5 cursor-pointer flex items-center justify-center rounded-md transition-all duration-200 opacity-100 md:opacity-0 md:group-hover:opacity-100 hover:bg-accent-cyan/10 hover:border-accent-cyan/30 hover:text-accent-cyan hover:shadow-[0_0_12px_rgba(0,217,255,0.25)]",onClick:T,title:"View logs",children:(0,s.jsx)(f,{})}),t.isSpawned&&p&&(0,s.jsx)("button",{className:"relative bg-transparent border border-transparent text-text-dim p-1.5 cursor-pointer flex items-center justify-center rounded-md transition-all duration-200 opacity-100 md:opacity-0 md:group-hover:opacity-100 hover:bg-error/10 hover:border-error/30 hover:text-error hover:shadow-[0_0_12px_rgba(255,68,68,0.25)]",onClick:D,title:"Kill agent",children:(0,s.jsx)(b,{})}),t.isProcessing?(0,s.jsx)("div",{title:W,children:(0,s.jsx)(m,{isProcessing:!0})}):(0,s.jsx)("div",{className:"\n w-2 h-2 rounded-full transition-all duration-300\n ".concat(E?"animate-pulse":"","\n "),style:{backgroundColor:L,boxShadow:E?"0 0 6px ".concat(L):"none"},title:W}),t.needsAttention&&(0,s.jsx)("div",{className:"w-2 h-2 rounded-full bg-warning animate-pulse shadow-[0_0_8px_rgba(255,107,53,0.5)]",title:"Needs Attention - Agent requires user input or has pending decisions"}),A&&(0,s.jsxs)("div",{className:"flex items-center gap-1 px-1.5 py-0.5 rounded bg-[#f97316]/20 text-[#f97316] text-[10px] font-medium animate-pulse",title:W,children:[(0,s.jsx)(j,{}),(0,s.jsx)("span",{children:h(S)})]})]})]}):(0,s.jsxs)("div",{className:"\n rounded-lg p-3 cursor-pointer transition-all duration-200\n hover:shadow-md hover:-translate-y-px\n ".concat(r?"border-2 shadow-[0_0_0_2px_rgba(74,158,255,0.15)]":"border","\n "),onClick:M,style:{backgroundColor:N.light,borderColor:N.primary},children:[(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsxs)("div",{className:"w-10 h-10 rounded-lg flex items-center justify-center font-semibold text-sm relative",style:{backgroundColor:N.primary},children:[(0,s.jsx)("span",{style:{color:N.text},children:k}),(0,s.jsx)("div",{className:"absolute -bottom-0.5 -right-0.5 w-3 h-3 rounded-full border-2 border-white",style:{backgroundColor:L},title:W})]}),(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:"font-semibold text-sm text-text-primary",children:C}),t.needsAttention&&(0,s.jsx)("span",{className:"bg-red-500 text-white text-[10px] font-bold w-4 h-4 rounded-full flex items-center justify-center",title:"Needs Attention - Agent requires user input or has pending decisions",children:"!"}),A&&(0,s.jsxs)("span",{className:"bg-[#f97316] text-white text-[10px] font-bold px-1.5 py-0.5 rounded flex items-center gap-1",title:W,children:[(0,s.jsx)(j,{})," ",h(S)]})]}),n?(0,s.jsx)("span",{className:"text-xs text-text-muted truncate block",children:l(t.name)}):(0,s.jsx)("span",{className:"text-xs text-text-muted truncate block",children:t.name}),t.agentId&&(0,s.jsxs)("span",{className:"text-[10px] text-text-muted font-mono opacity-70",title:"Agent ID (use to resume)",children:["ID: ",t.agentId]})]})]}),t.isProcessing&&(0,s.jsxs)("div",{className:"mt-2 p-2 bg-indigo-50 rounded flex items-center gap-2 border border-indigo-200",children:[(0,s.jsx)(u,{isProcessing:!0,processingStartedAt:t.processingStartedAt,size:"medium",showElapsed:!0}),(0,s.jsx)("span",{className:"text-xs text-indigo-500 font-medium",children:"Thinking..."})]}),t.currentTask&&!t.isProcessing&&(0,s.jsxs)("div",{className:"mt-2 p-2 bg-bg-hover rounded text-xs",children:[(0,s.jsx)("span",{className:"text-text-muted mr-1",children:"Working on:"}),(0,s.jsx)("span",{className:"text-text-primary line-clamp-2",title:t.currentTask,children:t.currentTask})]}),(0,s.jsxs)("div",{className:"mt-3 flex justify-between items-center",children:[(0,s.jsxs)("div",{className:"flex gap-2 text-xs text-text-muted",children:[t.cli&&(0,s.jsx)("span",{className:"bg-bg-hover py-0.5 px-1.5 rounded",children:t.cli}),void 0!==t.messageCount&&t.messageCount>0&&(0,s.jsxs)("span",{style:{color:N.primary},children:[t.messageCount," msgs"]}),t.isSpawned&&(0,s.jsx)("span",{className:"bg-accent-light text-accent text-[10px] py-0.5 px-1.5 rounded uppercase font-medium",children:"spawned"})]}),(0,s.jsxs)("div",{className:"flex gap-1.5",children:[w&&(0,s.jsx)("button",{className:"relative bg-gradient-to-b from-[#2a1a3a] to-[#1a0f2a] text-[#a855f7] border border-[#402060] rounded-md py-1.5 px-2.5 cursor-pointer flex items-center justify-center gap-1 transition-all duration-200 shadow-[inset_0_1px_0_rgba(168,85,247,0.1),0_2px_4px_rgba(0,0,0,0.3)] overflow-hidden hover:bg-gradient-to-b hover:from-[#402060] hover:to-[#301a50] hover:border-[#a855f7] hover:shadow-[inset_0_1px_0_rgba(168,85,247,0.2),0_0_12px_rgba(168,85,247,0.4),0_2px_8px_rgba(0,0,0,0.4)] hover:scale-105 active:scale-[0.98]",onClick:R,title:"View profile",children:(0,s.jsx)(y,{})}),t.isSpawned&&v&&(0,s.jsx)("button",{className:"relative bg-gradient-to-b from-[#1a2a3a] to-[#0f1a2a] text-accent-cyan border border-[#204060] rounded-md py-1.5 px-2.5 cursor-pointer flex items-center justify-center gap-1 transition-all duration-200 shadow-[inset_0_1px_0_rgba(0,217,255,0.1),0_2px_4px_rgba(0,0,0,0.3)] overflow-hidden hover:bg-gradient-to-b hover:from-[#204060] hover:to-[#1a3a50] hover:border-accent-cyan hover:shadow-[inset_0_1px_0_rgba(0,217,255,0.2),0_0_12px_rgba(0,217,255,0.4),0_2px_8px_rgba(0,0,0,0.4)] hover:scale-105 active:scale-[0.98]",onClick:T,title:"View logs",children:(0,s.jsx)(f,{})}),t.isSpawned&&p&&(0,s.jsx)("button",{className:"relative bg-gradient-to-b from-[#3a1a1a] to-[#2a0f0f] text-[#ff6b6b] border border-[#4a2020] rounded-md py-1.5 px-2.5 cursor-pointer flex items-center justify-center gap-1 transition-all duration-200 shadow-[inset_0_1px_0_rgba(255,107,107,0.1),0_2px_4px_rgba(0,0,0,0.3)] overflow-hidden hover:bg-gradient-to-b hover:from-[#4a2020] hover:to-[#3a1515] hover:border-[#ff4444] hover:text-[#ff4444] hover:shadow-[inset_0_1px_0_rgba(255,68,68,0.2),0_0_12px_rgba(255,68,68,0.4),0_2px_8px_rgba(0,0,0,0.4)] hover:scale-105 active:scale-[0.98]",onClick:D,title:"Release agent",children:(0,s.jsx)(b,{})}),x&&(0,s.jsx)("button",{className:"text-white border-none rounded py-1 px-2 cursor-pointer flex items-center justify-center transition-opacity duration-200 hover:opacity-90",style:{backgroundColor:N.primary},onClick:e=>{e.stopPropagation(),null==x||x(t)},title:"Send message",children:(0,s.jsx)(g,{})})]})]})]})}function g(){return(0,s.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,s.jsx)("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}function b(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",className:"release-icon",children:[(0,s.jsx)("path",{d:"M12 22c5.523 0 10-4.477 10-10a9.96 9.96 0 0 0-3-7.141",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"}),(0,s.jsx)("path",{d:"M12 22C6.477 22 2 17.523 2 12a9.96 9.96 0 0 1 3-7.141",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"}),(0,s.jsx)("line",{x1:"12",y1:"2",x2:"12",y2:"12",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round"})]})}function f(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("polyline",{points:"4 17 10 11 4 5"}),(0,s.jsx)("line",{x1:"12",y1:"19",x2:"20",y2:"19"})]})}function j(){return(0,s.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,s.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),(0,s.jsx)("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]})}function y(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("path",{d:"M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"}),(0,s.jsx)("circle",{cx:"12",cy:"7",r:"4"})]})}function v(e){let{agents:t,selectedAgent:r,searchQuery:a="",onAgentSelect:i,onAgentMessage:l,onReleaseClick:d,onLogsClick:x,compact:u=!1,showGroupStats:m=!0}=e,[h,p]=(0,n.useState)(new Set),[g,b]=(0,n.useState)(!0),f=(0,n.useMemo)(()=>c(t,a),[t,a]),j=(0,n.useMemo)(()=>o(f),[f]);(0,n.useMemo)(()=>{0===h.size&&j.length>0&&p(new Set(j.map(e=>e.prefix)))},[j]);let y=e=>{p(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})};return 0===t.length?(0,s.jsxs)("div",{className:"flex flex-col items-center justify-center py-10 px-5 text-text-muted text-center",children:[(0,s.jsx)(k,{}),(0,s.jsx)("p",{children:"No agents connected"})]}):0===f.length?(0,s.jsxs)("div",{className:"flex flex-col items-center justify-center py-10 px-5 text-text-muted text-center",children:[(0,s.jsx)(C,{}),(0,s.jsxs)("p",{children:['No agents match "',a,'"']})]}):(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[j.length>1&&(0,s.jsxs)("div",{className:"flex justify-between items-center py-2 px-3 text-xs text-text-muted",children:[(0,s.jsxs)("span",{children:[f.length," agents"]}),(0,s.jsx)("button",{className:"bg-transparent border-none text-accent cursor-pointer text-xs hover:underline",onClick:()=>{g?p(new Set):p(new Set(j.map(e=>e.prefix))),b(!g)},children:g?"Collapse all":"Expand all"})]}),j.map(e=>(0,s.jsx)(w,{group:e,isExpanded:h.has(e.prefix),selectedAgent:r,compact:u,showStats:m,onToggle:()=>y(e.prefix),onAgentSelect:i,onAgentMessage:l,onReleaseClick:d,onLogsClick:x},e.prefix))]})}function w(e){let{group:t,isExpanded:r,selectedAgent:n,compact:o,showStats:l,onToggle:c,onAgentSelect:d,onAgentMessage:u,onReleaseClick:m,onLogsClick:h}=e,g=l?x(t.agents):null;if(1===t.agents.length&&t.agents[0].name.toLowerCase()===t.prefix.toLowerCase()){let e=t.agents[0];return(0,s.jsx)("div",{className:"mb-1 py-1 px-2",children:(0,s.jsx)(p,{agent:e,isSelected:e.name===n,compact:o,onClick:d,onMessageClick:u,onReleaseClick:m,onLogsClick:h},e.name)})}return(0,s.jsxs)("div",{className:"mb-1",children:[(0,s.jsxs)("button",{className:"flex items-center gap-2 w-full py-2 px-3 bg-transparent border-none cursor-pointer text-sm text-left rounded transition-colors duration-200 relative hover:bg-[var(--group-light)]",onClick:c,style:{"--group-color":t.color.primary,"--group-light":t.color.light},children:[(0,s.jsx)("div",{className:"absolute left-0 top-1 bottom-1 w-[3px] rounded-sm",style:{backgroundColor:t.color.primary}}),(0,s.jsx)(N,{expanded:r}),(0,s.jsx)("span",{className:"font-semibold text-text-primary",children:t.displayName}),(0,s.jsxs)("span",{className:"text-text-muted font-normal",children:["(",t.agents.length,")"]}),l&&g&&(0,s.jsxs)("div",{className:"ml-auto flex gap-2",children:[g.online>0&&(0,s.jsxs)("span",{className:"flex items-center gap-1 text-xs text-text-muted",title:"".concat(g.online," agent").concat(g.online>1?"s":""," online"),children:[(0,s.jsx)("span",{className:"w-1.5 h-1.5 rounded-full",style:{backgroundColor:a.yh.online}}),g.online]}),g.needsAttention>0&&(0,s.jsxs)("span",{className:"flex items-center gap-1 text-xs text-text-muted",title:"".concat(g.needsAttention," agent").concat(g.needsAttention>1?"s":""," need").concat(1===g.needsAttention?"s":""," attention"),children:[(0,s.jsx)("span",{className:"w-1.5 h-1.5 rounded-full",style:{backgroundColor:a.yh.attention}}),g.needsAttention]})]})]}),r&&(0,s.jsx)("div",{className:"py-1 pl-4 flex flex-col gap-1",children:t.agents.map(e=>(0,s.jsx)(p,{agent:e,isSelected:e.name===n,compact:o,displayNameOverride:i(e.name),onClick:d,onMessageClick:u,onReleaseClick:m,onLogsClick:h},e.name))})]})}function N(e){let{expanded:t}=e;return(0,s.jsx)("svg",{className:"text-text-muted transition-transform duration-200 ".concat(t?"rotate-90":""),width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.jsx)("polyline",{points:"9 18 15 12 9 6"})})}function k(){return(0,s.jsxs)("svg",{className:"mb-3 opacity-50",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1",children:[(0,s.jsx)("circle",{cx:"12",cy:"8",r:"5"}),(0,s.jsx)("path",{d:"M20 21a8 8 0 1 0-16 0"})]})}function C(){return(0,s.jsxs)("svg",{className:"mb-3 opacity-50",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1",children:[(0,s.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,s.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]})}function S(e){return e.split(/[-_]/).map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(" ")}function A(e){let{projects:t,localAgents:r=[],bridgeAgents:a=[],currentProject:o,selectedAgent:i,searchQuery:l="",onProjectSelect:c,onAgentSelect:d,onReleaseClick:x,onLogsClick:u,compact:m=!1}=e,[h,p]=(0,n.useState)(()=>new Set(t.map(e=>e.id))),g=(0,n.useMemo)(()=>{let e=l.toLowerCase().trim();if(!e)return{projects:t,localAgents:r,bridgeAgents:a};let s=r.filter(t=>{var r;return t.name.toLowerCase().includes(e)||(null===(r=t.currentTask)||void 0===r?void 0:r.toLowerCase().includes(e))}),n=a.filter(t=>{var r;return t.name.toLowerCase().includes(e)||(null===(r=t.currentTask)||void 0===r?void 0:r.toLowerCase().includes(e))});return{projects:t.map(t=>{var r;let s=(null===(r=t.name)||void 0===r?void 0:r.toLowerCase().includes(e))||t.path.toLowerCase().includes(e),n=t.agents.filter(t=>{var r;return t.name.toLowerCase().includes(e)||(null===(r=t.currentTask)||void 0===r?void 0:r.toLowerCase().includes(e))});return s||n.length>0?{...t,agents:s?t.agents:n}:null}).filter(Boolean),localAgents:s,bridgeAgents:n}},[t,r,a,l]),b=e=>{p(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},f=g.localAgents.length+g.projects.reduce((e,t)=>e+t.agents.length,0);if(0===f&&0===t.length&&0===r.length)return(0,s.jsxs)("div",{className:"flex flex-col items-center justify-center py-10 px-5 text-[#888] text-center",children:[(0,s.jsx)(R,{}),(0,s.jsx)("p",{children:"No projects or agents"})]});if(0===f&&l)return(0,s.jsxs)("div",{className:"flex flex-col items-center justify-center py-10 px-5 text-[#888] text-center",children:[(0,s.jsx)(P,{}),(0,s.jsxs)("p",{children:['No results for "',l,'"']})]});let j=g.projects.length>1;return(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[j&&g.bridgeAgents.length>0&&(0,s.jsx)(E,{agents:g.bridgeAgents,selectedAgent:i,compact:m,onAgentSelect:e=>null==d?void 0:d(e),onReleaseClick:x,onLogsClick:u}),!j&&g.localAgents.length>0&&(0,s.jsx)(L,{project:{id:"__local__",path:"",name:"Local",agents:g.localAgents},isExpanded:h.has("__local__"),isCurrentProject:!0,selectedAgent:i,compact:m,onToggle:()=>b("__local__"),onAgentSelect:e=>null==d?void 0:d(e),onReleaseClick:x,onLogsClick:u}),g.projects.map(e=>(0,s.jsx)(L,{project:e,isExpanded:h.has(e.id),isCurrentProject:e.id===o,selectedAgent:i,compact:m,isBridgeMode:j,onToggle:()=>b(e.id),onProjectSelect:()=>null==c?void 0:c(e),onAgentSelect:t=>null==d?void 0:d(t,e),onReleaseClick:x,onLogsClick:u},e.id))]})}function L(e){var t;let{project:r,isExpanded:o,isCurrentProject:i,selectedAgent:l,compact:c,isBridgeMode:d=!1,onToggle:x,onProjectSelect:u,onAgentSelect:m,onReleaseClick:h,onLogsClick:g}=e,[b,f]=(0,n.useState)(new Set),j=(0,n.useMemo)(()=>{let e=0,t=0;for(let s of r.agents)"online"===s.status&&e++,s.needsAttention&&t++;return{online:e,needsAttention:t,total:r.agents.length}},[r.agents]),{teams:y,ungroupedAgents:v}=(0,n.useMemo)(()=>{let e=new Map,t=[];for(let s of r.agents)if(s.team){let t=e.get(s.team)||[];t.push(s),e.set(s.team,t)}else t.push(s);return{teams:Array.from(e.entries()).map(e=>{let[t,r]=e;return{name:t,agents:r}}).sort((e,t)=>e.name.localeCompare(t.name)),ungroupedAgents:t}},[r.agents]),w=e=>{f(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})};(0,n.useEffect)(()=>{o&&0===b.size&&y.length>0&&f(new Set(y.map(e=>e.name)))},[o,y,b]);let N=(0,a.GW)(r.name||r.id),k=r.name||r.path.split("/").pop()||r.id;return(0,s.jsxs)("div",{className:"mb-1",children:[(0,s.jsxs)("button",{className:"group flex items-center gap-2 w-full py-2.5 px-3 bg-none border-none cursor-pointer text-[13px] text-left rounded-md transition-colors duration-200 relative text-[#e8e8e8] hover:bg-[var(--project-light)] ".concat(i?"bg-[rgba(0,255,200,0.08)]":""),onClick:x,onDoubleClick:u,style:{"--project-color":N.primary,"--project-light":N.light},children:[(0,s.jsx)("div",{className:"absolute left-0 top-1 bottom-1 w-[3px] rounded-sm",style:{background:N.primary}}),(0,s.jsx)(M,{expanded:o}),(0,s.jsx)(D,{color:N.primary}),(0,s.jsx)("span",{className:"font-semibold text-[#e8e8e8] whitespace-nowrap overflow-hidden text-ellipsis",children:k}),(0,s.jsxs)("span",{className:"text-[#888] font-normal flex-shrink-0",children:["(",j.total,")"]}),(0,s.jsxs)("div",{className:"ml-auto flex gap-2 flex-shrink-0",children:[j.online>0&&(0,s.jsxs)("span",{className:"flex items-center gap-1 text-[11px] text-[#666]",children:[(0,s.jsx)("span",{className:"w-1.5 h-1.5 rounded-full",style:{backgroundColor:a.yh.online}}),j.online]}),j.needsAttention>0&&(0,s.jsxs)("span",{className:"flex items-center gap-1 text-[11px] text-[#666]",children:[(0,s.jsx)("span",{className:"w-1.5 h-1.5 rounded-full",style:{backgroundColor:a.yh.attention}}),j.needsAttention]})]}),(null===(t=r.lead)||void 0===t?void 0:t.connected)&&(0,s.jsx)("span",{className:"text-[#ffd700] text-xs ml-1",title:"Lead: ".concat(r.lead.name),children:"★"}),d&&!i&&u&&(0,s.jsx)("button",{className:"ml-2 py-1 px-2 text-[10px] font-medium bg-accent-cyan/20 text-accent-cyan rounded border-none cursor-pointer opacity-0 group-hover:opacity-100 transition-opacity hover:bg-accent-cyan/30",onClick:e=>{e.stopPropagation(),u()},title:"Switch to this project",children:"Switch"})]}),o&&(0,s.jsxs)("div",{className:"py-1 pl-5 flex flex-col gap-1",children:[y.map(e=>(0,s.jsxs)("div",{className:"mb-0.5",children:[(0,s.jsxs)("button",{className:"flex items-center gap-1.5 w-full py-1.5 px-2 bg-none border-none cursor-pointer text-xs text-left rounded transition-colors duration-200 text-[#b8b8b8] hover:bg-white/5",onClick:()=>w(e.name),children:[(0,s.jsx)(M,{expanded:b.has(e.name)}),(0,s.jsx)(T,{}),(0,s.jsx)("span",{className:"font-medium text-[#b8b8b8]",children:e.name}),(0,s.jsxs)("span",{className:"text-[#666] font-normal",children:["(",e.agents.length,")"]})]}),b.has(e.name)&&(0,s.jsx)("div",{className:"py-0.5 pl-4 flex flex-col gap-1",children:e.agents.map(t=>(0,s.jsx)(p,{agent:t,isSelected:t.name===l,compact:c,displayNameOverride:function(e,t){let r=e.toLowerCase(),s=t.toLowerCase().replace(/-?team$/i,"");if(s&&r.startsWith(s+"-")||s&&r.startsWith(s+"_"))return S(e.substring(s.length+1));let n=e.split("-");return n.length>1?S(n[n.length-1]):S(e)}(t.name,e.name),onClick:m,onReleaseClick:h,onLogsClick:g},t.name))})]},e.name)),v.map(e=>(0,s.jsx)(p,{agent:e,isSelected:e.name===l,compact:c,onClick:m,onReleaseClick:h,onLogsClick:g},e.name))]})]})}function E(e){let{agents:t,selectedAgent:r,compact:a,onAgentSelect:o,onReleaseClick:i,onLogsClick:l}=e,[c,d]=(0,n.useState)(!0);return(0,s.jsxs)("div",{className:"mb-2",children:[(0,s.jsxs)("button",{className:"flex items-center gap-2 w-full py-2.5 px-3 bg-none border-none cursor-pointer text-[13px] text-left rounded-md transition-colors duration-200 relative text-[#e8e8e8] hover:bg-[rgba(168,85,247,0.1)]",onClick:()=>d(!c),children:[(0,s.jsx)("div",{className:"absolute left-0 top-1 bottom-1 w-[3px] rounded-sm",style:{background:"#a855f7"}}),(0,s.jsx)(M,{expanded:c}),(0,s.jsx)(W,{}),(0,s.jsx)("span",{className:"font-semibold text-[#e8e8e8]",children:"Bridge"}),(0,s.jsxs)("span",{className:"text-[#888] font-normal flex-shrink-0",children:["(",t.length,")"]})]}),c&&(0,s.jsx)("div",{className:"py-1 pl-5 flex flex-col gap-1",children:t.map(e=>(0,s.jsx)(p,{agent:e,isSelected:e.name===r,compact:a,onClick:o,onReleaseClick:i,onLogsClick:l},e.name))})]})}function W(){return(0,s.jsxs)("svg",{className:"flex-shrink-0 text-[#a855f7]",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"3"}),(0,s.jsx)("circle",{cx:"5",cy:"5",r:"2"}),(0,s.jsx)("circle",{cx:"19",cy:"5",r:"2"}),(0,s.jsx)("circle",{cx:"5",cy:"19",r:"2"}),(0,s.jsx)("circle",{cx:"19",cy:"19",r:"2"}),(0,s.jsx)("line",{x1:"9.5",y1:"9.5",x2:"6.5",y2:"6.5"}),(0,s.jsx)("line",{x1:"14.5",y1:"9.5",x2:"17.5",y2:"6.5"}),(0,s.jsx)("line",{x1:"9.5",y1:"14.5",x2:"6.5",y2:"17.5"}),(0,s.jsx)("line",{x1:"14.5",y1:"14.5",x2:"17.5",y2:"17.5"})]})}function M(e){let{expanded:t}=e;return(0,s.jsx)("svg",{className:"transition-transform duration-200 text-[#888] flex-shrink-0 ".concat(t?"rotate-90":""),width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.jsx)("polyline",{points:"9 18 15 12 9 6"})})}function D(e){let{color:t}=e;return(0,s.jsx)("svg",{className:"flex-shrink-0",style:{color:t},width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.jsx)("path",{d:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"})})}function T(){return(0,s.jsxs)("svg",{className:"text-[#888] flex-shrink-0",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("path",{d:"M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"}),(0,s.jsx)("circle",{cx:"9",cy:"7",r:"4"}),(0,s.jsx)("path",{d:"M23 21v-2a4 4 0 0 0-3-3.87"}),(0,s.jsx)("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]})}function R(){return(0,s.jsx)("svg",{className:"mb-3 opacity-50",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1",children:(0,s.jsx)("path",{d:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"})})}function P(){return(0,s.jsxs)("svg",{className:"mb-3 opacity-50",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1",children:[(0,s.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,s.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]})}function B(e){let{threads:t,currentThread:r,onThreadSelect:n,totalUnreadCount:a=0,isCollapsed:o=!1,onToggleCollapse:i}=e;return 0===t.length?null:(0,s.jsxs)("div",{className:"px-2 py-2",children:[(0,s.jsxs)("button",{className:"w-full flex items-center justify-between px-2 py-2 mb-1.5 bg-transparent border-none cursor-pointer rounded-lg transition-all duration-200 hover:bg-gradient-to-r hover:from-[rgba(255,255,255,0.03)] hover:to-transparent",onClick:i,"aria-expanded":!o,"aria-label":o?"Expand threads":"Collapse threads",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(F,{isCollapsed:o}),(0,s.jsx)("span",{className:"text-xs font-semibold uppercase tracking-wider text-text-muted",children:"Threads"}),(0,s.jsxs)("span",{className:"text-xs text-text-dim font-mono",children:["(",t.length,")"]})]}),a>0&&(0,s.jsx)("span",{className:"min-w-[18px] h-[18px] flex items-center justify-center text-[10px] font-bold bg-accent-cyan text-bg-deep rounded-full px-1.5",style:{boxShadow:"0 0 8px rgba(0, 217, 255, 0.5)"},children:a>99?"99+":a})]}),!o&&(0,s.jsx)("div",{className:"space-y-1",children:t.map(e=>(0,s.jsx)(_,{thread:e,isSelected:r===e.id,onClick:()=>n(e.id)},e.id))})]})}function _(e){let{thread:t,isSelected:r,onClick:n}=e,a=t.unreadCount>0,o=function(e){let t=new Date(e),r=new Date().getTime()-t.getTime(),s=Math.floor(r/6e4),n=Math.floor(r/36e5),a=Math.floor(r/864e5);return s<1?"now":s<60?"".concat(s,"m"):n<24?"".concat(n,"h"):a<7?"".concat(a,"d"):t.toLocaleDateString([],{month:"short",day:"numeric"})}(t.lastMessage.timestamp);return(0,s.jsxs)("button",{className:"\n group w-full flex items-center gap-3 px-2.5 py-2.5 rounded-lg text-left transition-all duration-200 cursor-pointer border-none\n hover:bg-gradient-to-r hover:from-[rgba(255,255,255,0.03)] hover:to-transparent\n ".concat(r?"bg-gradient-to-r from-[rgba(255,255,255,0.06)] to-transparent":"bg-transparent","\n "),onClick:n,style:{borderLeft:r?"2px solid #00d9ff":"2px solid transparent",boxShadow:r?"inset 4px 0 12px -4px rgba(0, 217, 255, 0.25)":"none"},children:[(0,s.jsxs)("div",{className:"\n relative shrink-0 w-8 h-8 rounded-lg flex items-center justify-center overflow-hidden transition-all duration-200\n ".concat(a?"text-accent-cyan":"text-text-muted","\n "),style:{background:a?"linear-gradient(135deg, rgba(0, 217, 255, 0.2), rgba(0, 217, 255, 0.1))":"rgba(255, 255, 255, 0.03)",boxShadow:a?"0 0 8px rgba(0, 217, 255, 0.2)":"none"},children:[(0,s.jsx)("div",{className:"absolute inset-0 opacity-20",style:{background:"linear-gradient(135deg, rgba(255,255,255,0.2) 0%, transparent 50%)"}}),(0,s.jsx)(I,{})]}),(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:"\n text-[13px] truncate transition-colors duration-200\n ".concat(a?"font-semibold text-text-primary":"text-text-secondary group-hover:text-text-primary","\n "),children:t.name}),a&&(0,s.jsx)("span",{className:"shrink-0 min-w-[16px] h-[16px] flex items-center justify-center text-[9px] font-bold bg-accent-cyan text-bg-deep rounded-full px-1",style:{boxShadow:"0 0 6px rgba(0, 217, 255, 0.4)"},children:t.unreadCount>99?"99+":t.unreadCount})]}),(0,s.jsxs)("div",{className:"flex items-center gap-1.5 text-[11px] text-text-muted font-mono",children:[(0,s.jsx)("span",{className:"truncate",children:t.participants.slice(0,2).join(", ")}),t.participants.length>2&&(0,s.jsxs)("span",{className:"text-text-dim",children:["+",t.participants.length-2]}),(0,s.jsx)("span",{className:"text-text-dim opacity-50",children:"\xb7"}),(0,s.jsx)("span",{className:"text-text-dim",children:o})]})]})]})}function I(){return(0,s.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.jsx)("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}function F(e){let{isCollapsed:t}=e;return(0,s.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-text-muted transition-transform duration-200 ".concat(t?"":"rotate-90"),children:(0,s.jsx)("polyline",{points:"9 18 15 12 9 6"})})}var U=r(6272);let O="agent-relay-threads-collapsed",z="agent-relay-sidebar-tab";function H(e){let{agents:t,bridgeAgents:r=[],projects:a=[],currentProject:o,selectedAgent:i,viewMode:l,isFleetAvailable:c,isConnected:d,isOpen:x=!1,activeThreads:u=[],currentThread:m,totalUnreadThreadCount:h=0,onAgentSelect:p,onProjectSelect:g,onViewModeChange:b,onSpawnClick:f,onReleaseClick:j,onLogsClick:y,onThreadSelect:w,onClose:N,onSettingsClick:k,onTrajectoryClick:C,hasActiveTrajectory:S,onFleetClick:L,isFleetViewActive:E,onCoordinatorClick:W,hasMultipleProjects:M}=e,[D,T]=(0,n.useState)(""),[R,P]=(0,n.useState)(()=>{try{let e=localStorage.getItem(z);return"team"===e?"team":"agents"}catch(e){return"agents"}}),[_,I]=(0,n.useState)(()=>{try{let e=localStorage.getItem(O);return"true"===e}catch(e){return!1}});(0,n.useEffect)(()=>{try{localStorage.setItem(z,R)}catch(e){}},[R]),(0,n.useEffect)(()=>{try{localStorage.setItem(O,String(_))}catch(e){}},[_]);let F=t.filter(e=>!e.isHuman),H=t.filter(e=>e.isHuman),er=a.length>0;return(0,s.jsxs)("aside",{className:"flex-1 flex flex-col overflow-hidden",children:[(0,s.jsxs)("div",{className:"p-3 sm:p-4 border-b border-border-subtle",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2 sm:gap-3 mb-3",children:[(0,s.jsx)(U.K7,{size:24,withGlow:!0}),(0,s.jsx)("h1",{className:"text-base sm:text-lg font-display font-semibold m-0 text-text-primary",children:"Agent Relay"}),(0,s.jsx)(V,{isConnected:d}),(0,s.jsx)("button",{className:"md:hidden ml-auto p-2 -mr-1 sm:-mr-2 bg-transparent border-none text-text-muted cursor-pointer rounded-lg transition-colors hover:bg-bg-hover hover:text-text-primary active:bg-bg-hover",onClick:N,"aria-label":"Close sidebar",children:(0,s.jsx)(X,{})})]}),c&&(0,s.jsxs)("div",{className:"flex bg-bg-tertiary rounded-lg p-1",children:[(0,s.jsx)("button",{className:"\n flex-1 py-2 px-4 bg-transparent border-none text-xs font-medium cursor-pointer rounded-md transition-all duration-150\n ".concat("local"===l?"bg-bg-elevated text-accent-cyan shadow-sm":"text-text-muted hover:text-text-secondary","\n "),onClick:()=>null==b?void 0:b("local"),children:"Local"}),(0,s.jsx)("button",{className:"\n flex-1 py-2 px-4 bg-transparent border-none text-xs font-medium cursor-pointer rounded-md transition-all duration-150\n ".concat("fleet"===l?"bg-bg-elevated text-accent-cyan shadow-sm":"text-text-muted hover:text-text-secondary","\n "),onClick:()=>null==b?void 0:b("fleet"),children:"Fleet"})]})]}),H.length>0&&(0,s.jsxs)("div",{className:"flex bg-bg-tertiary rounded-lg p-1 mx-3 mt-3",children:[(0,s.jsxs)("button",{className:"\n flex-1 py-2 px-4 bg-transparent border-none text-xs font-medium cursor-pointer rounded-md transition-all duration-150 flex items-center justify-center gap-1.5\n ".concat("agents"===R?"bg-bg-elevated text-accent-cyan shadow-sm":"text-text-muted hover:text-text-secondary","\n "),onClick:()=>P("agents"),children:[(0,s.jsx)(q,{}),"Agents",F.length>0&&(0,s.jsxs)("span",{className:"text-[10px] opacity-70",children:["(",F.length,")"]})]}),(0,s.jsxs)("button",{className:"\n flex-1 py-2 px-4 bg-transparent border-none text-xs font-medium cursor-pointer rounded-md transition-all duration-150 flex items-center justify-center gap-1.5\n ".concat("team"===R?"bg-bg-elevated text-accent-cyan shadow-sm":"text-text-muted hover:text-text-secondary","\n "),onClick:()=>P("team"),children:[(0,s.jsx)($,{}),"Team",H.length>0&&(0,s.jsxs)("span",{className:"text-[10px] opacity-70",children:["(",H.length,")"]})]})]}),(0,s.jsxs)("div",{className:"flex items-center gap-2 py-2 sm:py-2.5 px-2 sm:px-3 bg-bg-tertiary m-2 sm:m-3 rounded-lg border border-border-subtle focus-within:border-accent-cyan/50 transition-colors",children:[(0,s.jsx)(G,{}),(0,s.jsx)("input",{type:"text",placeholder:"agents"===R?"Search agents...":"Search team...",value:D,onChange:e=>T(e.target.value),className:"flex-1 bg-transparent border-none text-text-primary text-sm outline-none placeholder:text-text-muted"}),D&&(0,s.jsx)("button",{className:"bg-transparent border-none text-text-muted cursor-pointer p-1 flex items-center justify-center hover:text-text-secondary rounded transition-colors active:text-text-secondary",onClick:()=>T(""),children:(0,s.jsx)(K,{})})]}),u.length>0&&(0,s.jsx)("div",{className:"border-b border-border-subtle",children:(0,s.jsx)(B,{threads:u,currentThread:m,onThreadSelect:e=>null==w?void 0:w(e),totalUnreadCount:h,isCollapsed:_,onToggleCollapse:()=>I(!_)})}),(0,s.jsx)("div",{className:"flex-1 overflow-y-auto px-2",children:"team"===R&&H.length>0?(0,s.jsxs)("div",{className:"flex flex-col gap-1 py-2",children:[H.filter(e=>!D||e.name.toLowerCase().includes(D.toLowerCase())).map(e=>(0,s.jsxs)("button",{onClick:()=>null==p?void 0:p(e),className:"\n flex items-center gap-3 p-3 rounded-lg border transition-all duration-150 text-left w-full\n ".concat(i===e.name?"bg-accent-cyan/10 border-accent-cyan/30":"bg-bg-tertiary border-border-subtle hover:border-accent-cyan/30 hover:bg-bg-hover","\n "),children:[e.avatarUrl?(0,s.jsx)("img",{src:e.avatarUrl,alt:e.name,className:"w-9 h-9 rounded-full object-cover"}):(0,s.jsx)("div",{className:"w-9 h-9 rounded-full bg-gradient-to-br from-purple-500 to-pink-500 flex items-center justify-center text-white font-medium text-sm",children:e.name.charAt(0).toUpperCase()}),(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsx)("p",{className:"text-sm font-medium text-text-primary truncate",children:e.name}),(0,s.jsx)("p",{className:"text-xs text-text-muted truncate",children:e.role||"Team Member"})]}),(0,s.jsx)("div",{className:"w-2 h-2 rounded-full ".concat("online"===e.status?"bg-success":"bg-text-dim")})]},e.name)),0===H.filter(e=>!D||e.name.toLowerCase().includes(D.toLowerCase())).length&&(0,s.jsxs)("div",{className:"flex flex-col items-center justify-center py-10 px-5 text-text-muted text-center",children:[(0,s.jsx)(G,{}),(0,s.jsxs)("p",{className:"mt-3",children:['No team members match "',D,'"']})]})]}):er?(0,s.jsx)(A,{projects:a,localAgents:F,bridgeAgents:r,currentProject:o,selectedAgent:i,searchQuery:D,onProjectSelect:g,onAgentSelect:p,onReleaseClick:j,onLogsClick:y,compact:!0}):(0,s.jsx)(v,{agents:F,selectedAgent:i,searchQuery:D,onAgentSelect:e=>null==p?void 0:p(e),onReleaseClick:j,onLogsClick:y,compact:!0,showGroupStats:!0})}),(0,s.jsxs)("div",{className:"md:hidden border-t border-border-subtle p-3",children:[(0,s.jsx)("p",{className:"text-xs text-text-muted font-medium mb-2 px-1",children:"Quick Actions"}),(0,s.jsxs)("div",{className:"grid grid-cols-2 gap-2",children:[L&&(0,s.jsxs)("button",{className:"flex items-center gap-2 p-2.5 rounded-lg border text-sm transition-all duration-150 ".concat(E?"bg-accent-cyan/20 border-accent-cyan text-accent-cyan":"bg-bg-tertiary border-border-subtle text-text-secondary hover:bg-bg-hover hover:text-text-primary"),onClick:()=>{L(),null==N||N()},children:[(0,s.jsx)(Z,{}),(0,s.jsx)("span",{children:"Fleet"})]}),C&&(0,s.jsxs)("button",{className:"flex items-center gap-2 p-2.5 rounded-lg border text-sm transition-all duration-150 relative ".concat(S?"bg-accent-cyan/20 border-accent-cyan text-accent-cyan":"bg-bg-tertiary border-border-subtle text-text-secondary hover:bg-bg-hover hover:text-text-primary"),onClick:()=>{C(),null==N||N()},children:[(0,s.jsx)(Q,{}),(0,s.jsx)("span",{children:"Trajectory"}),S&&(0,s.jsx)("span",{className:"absolute top-1 right-1 w-2 h-2 bg-accent-cyan rounded-full animate-pulse"})]}),M&&W&&(0,s.jsxs)("button",{className:"flex items-center gap-2 p-2.5 bg-bg-tertiary border border-border-subtle rounded-lg text-text-secondary text-sm transition-all duration-150 hover:bg-bg-hover hover:text-accent-purple",onClick:()=>{W(),null==N||N()},children:[(0,s.jsx)(ee,{}),(0,s.jsx)("span",{children:"Coordinator"})]}),(0,s.jsxs)("a",{href:"/metrics",className:"flex items-center gap-2 p-2.5 bg-bg-tertiary border border-border-subtle rounded-lg text-text-secondary text-sm transition-all duration-150 hover:bg-bg-hover hover:text-accent-orange no-underline",onClick:()=>null==N?void 0:N(),children:[(0,s.jsx)(et,{}),(0,s.jsx)("span",{children:"Metrics"})]})]})]}),(0,s.jsxs)("div",{className:"p-3 sm:p-4 border-t border-border-subtle space-y-2",children:[(0,s.jsxs)("button",{className:"w-full py-2.5 sm:py-3 px-3 sm:px-4 bg-gradient-to-r from-accent-cyan to-[#00b8d9] text-bg-deep font-semibold text-sm cursor-pointer flex items-center justify-center gap-2 rounded-lg transition-all duration-150 hover:shadow-glow-cyan hover:-translate-y-0.5 active:scale-[0.98]",onClick:f,children:[(0,s.jsx)(J,{}),"Spawn Agent"]}),(0,s.jsxs)("button",{className:"w-full py-2 sm:py-2.5 px-3 sm:px-4 bg-bg-tertiary text-text-secondary text-sm cursor-pointer flex items-center justify-center gap-2 rounded-lg border border-border-subtle transition-all duration-150 hover:bg-bg-hover hover:text-text-primary hover:border-border-subtle active:bg-bg-hover",onClick:k,children:[(0,s.jsx)(Y,{}),"Settings"]})]})]})}function V(e){let{isConnected:t}=e;return(0,s.jsxs)("div",{className:"flex items-center gap-1.5 ml-auto",children:[(0,s.jsx)("div",{className:"w-2 h-2 rounded-full ".concat(t?"bg-success animate-pulse-glow":"bg-text-dim")}),(0,s.jsx)("span",{className:"text-xs text-text-muted",children:t?"Live":"Offline"})]})}function G(){return(0,s.jsxs)("svg",{className:"text-text-muted",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,s.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]})}function K(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function J(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[(0,s.jsx)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,s.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function X(){return(0,s.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function Y(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"3"}),(0,s.jsx)("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"})]})}function q(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("rect",{x:"3",y:"11",width:"18",height:"10",rx:"2"}),(0,s.jsx)("circle",{cx:"12",cy:"5",r:"2"}),(0,s.jsx)("path",{d:"M12 7v4"}),(0,s.jsx)("line",{x1:"8",y1:"16",x2:"8",y2:"16"}),(0,s.jsx)("line",{x1:"16",y1:"16",x2:"16",y2:"16"})]})}function $(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("path",{d:"M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"}),(0,s.jsx)("circle",{cx:"9",cy:"7",r:"4"}),(0,s.jsx)("path",{d:"M23 21v-2a4 4 0 0 0-3-3.87"}),(0,s.jsx)("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]})}function Z(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2",ry:"2"}),(0,s.jsx)("line",{x1:"8",y1:"21",x2:"16",y2:"21"}),(0,s.jsx)("line",{x1:"12",y1:"17",x2:"12",y2:"21"})]})}function Q(){return(0,s.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,s.jsx)("path",{d:"M3 12h4l3 9 4-18 3 9h4"})})}function ee(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"3"}),(0,s.jsx)("circle",{cx:"5",cy:"5",r:"2"}),(0,s.jsx)("circle",{cx:"19",cy:"5",r:"2"}),(0,s.jsx)("circle",{cx:"5",cy:"19",r:"2"}),(0,s.jsx)("circle",{cx:"19",cy:"19",r:"2"}),(0,s.jsx)("line",{x1:"9.5",y1:"9.5",x2:"6.5",y2:"6.5"}),(0,s.jsx)("line",{x1:"14.5",y1:"9.5",x2:"17.5",y2:"6.5"}),(0,s.jsx)("line",{x1:"9.5",y1:"14.5",x2:"6.5",y2:"17.5"}),(0,s.jsx)("line",{x1:"14.5",y1:"14.5",x2:"17.5",y2:"17.5"})]})}function et(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("path",{d:"M3 3v18h18"}),(0,s.jsx)("path",{d:"M18 17V9"}),(0,s.jsx)("path",{d:"M13 17V5"}),(0,s.jsx)("path",{d:"M8 17v-3"})]})}function er(e){let{projects:t,recentProjects:r=[],currentProject:a,onProjectChange:o}=e,[i,l]=(0,n.useState)(!1),[c,d]=(0,n.useState)(-1),x=(0,n.useRef)(null),u=(0,n.useRef)([]),m=t.length>1,h=new Set(r.map(e=>e.id)),p=t.filter(e=>!h.has(e.id)),g=[...r,...p],b=e=>{if(!e)return"No project";if(e.name)return e.name;let t=e.path.split("/").filter(Boolean);return t.length>=2?"".concat(t[t.length-2],"/").concat(t[t.length-1]):t[t.length-1]||e.id};return((0,n.useEffect)(()=>{let e=e=>{x.current&&!x.current.contains(e.target)&&l(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,n.useEffect)(()=>{let e=e=>{if(i)switch(e.key){case"Escape":l(!1),d(-1);break;case"ArrowDown":e.preventDefault(),d(e=>{var t;let r=e<g.length-1?e+1:0;return null===(t=u.current[r])||void 0===t||t.focus(),r});break;case"ArrowUp":e.preventDefault(),d(e=>{var t;let r=e>0?e-1:g.length-1;return null===(t=u.current[r])||void 0===t||t.focus(),r});break;case"Enter":c>=0&&c<g.length&&(o(g[c]),l(!1),d(-1))}};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[i,c,g,o]),(0,n.useEffect)(()=>{if(i){let e=g.findIndex(e=>e.id===(null==a?void 0:a.id));d(e>=0?e:0)}else d(-1)},[i,g,a]),0===t.length)?null:(0,s.jsxs)("div",{className:"relative",ref:x,children:[(0,s.jsxs)("button",{className:"flex items-center gap-2 px-3 py-1.5 rounded-lg text-sm font-medium transition-all duration-150 border ".concat(m?"bg-bg-tertiary/80 border-border-subtle hover:bg-bg-elevated hover:border-border-medium cursor-pointer":"bg-transparent border-transparent cursor-default"),onClick:()=>m&&l(!i),disabled:!m,"aria-expanded":i,"aria-haspopup":"listbox",children:[(0,s.jsx)(ea,{}),(0,s.jsx)("span",{className:"text-text-primary truncate max-w-[200px]",children:b(a)}),m&&(0,s.jsx)(eo,{isOpen:i})]}),i&&m&&(0,s.jsxs)("div",{className:"absolute top-[calc(100%+4px)] left-0 min-w-[280px] bg-bg-primary border border-border-subtle rounded-xl shadow-[0_10px_40px_rgba(0,0,0,0.4)] z-[1000] overflow-hidden",children:[(0,s.jsx)("div",{className:"px-3 py-2 border-b border-border-subtle",children:(0,s.jsx)("span",{className:"text-xs font-medium text-text-muted uppercase tracking-wider",children:"Switch Project"})}),(0,s.jsxs)("div",{className:"max-h-[300px] overflow-y-auto",role:"listbox",children:[r.length>0&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"px-3 py-1.5 bg-bg-tertiary/50",children:(0,s.jsxs)("span",{className:"text-[10px] font-medium text-text-muted uppercase tracking-wider flex items-center gap-1.5",children:[(0,s.jsx)(en,{}),"Recent"]})}),(0,s.jsx)("div",{className:"py-1",children:r.map((e,t)=>(0,s.jsx)(es,{project:e,index:t,isActive:(null==a?void 0:a.id)===e.id,isFocused:c===t,formatProjectName:b,buttonRefs:u,onSelect:()=>{o(e),l(!1)}},e.id))})]}),p.length>0&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"px-3 py-1.5 bg-bg-tertiary/50",children:(0,s.jsx)("span",{className:"text-[10px] font-medium text-text-muted uppercase tracking-wider",children:r.length>0?"All Projects":"Projects"})}),(0,s.jsx)("div",{className:"py-1",children:p.map((e,t)=>{let n=r.length+t;return(0,s.jsx)(es,{project:e,index:n,isActive:(null==a?void 0:a.id)===e.id,isFocused:c===n,formatProjectName:b,buttonRefs:u,onSelect:()=>{o(e),l(!1)}},e.id)})})]})]})]})]})}function es(e){var t,r;let{project:n,index:a,isActive:o,isFocused:i,formatProjectName:l,buttonRefs:c,onSelect:d}=e,x=l(n),u=(null===(t=n.agents)||void 0===t?void 0:t.length)||0;return(0,s.jsxs)("button",{ref:e=>{c.current[a]=e},className:"w-full flex items-center gap-3 px-3 py-2.5 text-left transition-colors border-none cursor-pointer ".concat(o?"bg-accent-cyan/10 text-accent-cyan":i?"bg-bg-hover text-text-primary":"bg-transparent text-text-primary hover:bg-bg-hover"),onClick:d,role:"option","aria-selected":o,tabIndex:i?0:-1,children:[(0,s.jsx)(ea,{className:o?"text-accent-cyan":"text-text-muted"}),(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsx)("div",{className:"font-medium text-sm truncate",children:x}),(0,s.jsx)("div",{className:"text-xs text-text-muted truncate",children:n.path})]}),(0,s.jsxs)("span",{className:"text-xs px-2 py-0.5 rounded-full ".concat(o?"bg-accent-cyan/20 text-accent-cyan":"bg-bg-tertiary text-text-muted"),children:[u," ",1===u?"agent":"agents"]}),(null===(r=n.lead)||void 0===r?void 0:r.connected)&&(0,s.jsx)("span",{className:"w-2 h-2 rounded-full bg-success animate-pulse",title:"Lead: ".concat(n.lead.name)}),o&&(0,s.jsx)(ei,{})]})}function en(){return(0,s.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,s.jsx)("polyline",{points:"12 6 12 12 16 14"})]})}function ea(e){let{className:t="text-text-muted"}=e;return(0,s.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:(0,s.jsx)("path",{d:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"})})}function eo(e){let{isOpen:t}=e;return(0,s.jsx)("svg",{className:"text-text-muted transition-transform duration-150 ".concat(t?"rotate-180":""),width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:(0,s.jsx)("polyline",{points:"6 9 12 15 18 9"})})}function ei(){return(0,s.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-accent-cyan",children:(0,s.jsx)("polyline",{points:"20 6 9 17 4 12"})})}var el=r(9165);let ec={autoRefresh:!0,refreshInterval:3e4,autoWakeup:!1,onStatusChange:()=>{}};function ed(e){let{expanded:t=!1,autoWakeup:r=!1,onWakeup:a,onStatusChange:o,className:i=""}=e,[l,c]=(0,n.useState)(!1),[d,x]=(0,n.useState)(""),{workspace:u,exists:m,isLoading:h,isWakingUp:p,statusMessage:g,actionNeeded:b,wakeup:f}=function(){var e,t,r,s,a;let o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=null!==(e=o.autoRefresh)&&void 0!==e?e:ec.autoRefresh,l=null!==(t=o.refreshInterval)&&void 0!==t?t:ec.refreshInterval,c=null!==(r=o.autoWakeup)&&void 0!==r?r:ec.autoWakeup,d=(0,n.useRef)(null!==(s=o.onStatusChange)&&void 0!==s?s:ec.onStatusChange);d.current=null!==(a=o.onStatusChange)&&void 0!==a?a:ec.onStatusChange;let[x,u]=(0,n.useState)(null),[m,h]=(0,n.useState)(!1),[p,g]=(0,n.useState)(!0),[b,f]=(0,n.useState)(!1),[j,y]=(0,n.useState)(""),[v,w]=(0,n.useState)(null),[N,k]=(0,n.useState)(null),C=(0,n.useRef)(null),S=(0,n.useRef)(!0),A=(0,n.useRef)(null),L=(0,n.useCallback)(async()=>{try{g(!0),k(null);let e=await el.xv.getPrimaryWorkspace();if(!S.current)return;if(e.success){if(h(e.data.exists),y(e.data.statusMessage),w(e.data.actionNeeded||null),e.data.workspace){let t=e.data.workspace;u(t),A.current&&A.current!==t.status&&d.current(t.status,!1),A.current=t.status}else u(null)}else k(e.error)}catch(e){S.current&&k("Failed to fetch workspace status")}finally{S.current&&g(!1)}},[]),E=(0,n.useRef)(l);E.current=l;let W=(0,n.useRef)(i);W.current=i;let M=(0,n.useCallback)(async()=>{if(!(null==x?void 0:x.id))return{success:!1,message:"No workspace to wake up"};try{f(!0),k(null);let e=await el.xv.wakeupWorkspace(x.id);if(!S.current)return{success:!1,message:"Component unmounted"};if(e.success)return e.data.wasRestarted&&(y(e.data.message),w(null),d.current("starting",!0),C.current&&clearInterval(C.current),C.current=setInterval(L,5e3),setTimeout(()=>{S.current&&C.current&&(clearInterval(C.current),W.current&&(C.current=setInterval(L,E.current)))},12e4)),{success:!0,message:e.data.message};return k(e.error),{success:!1,message:e.error}}catch(t){let e=t instanceof Error?t.message:"Failed to wake up workspace";return S.current&&k(e),{success:!1,message:e}}finally{S.current&&f(!1)}},[null==x?void 0:x.id,L]);return(0,n.useEffect)(()=>(S.current=!0,L(),()=>{S.current=!1}),[L]),(0,n.useEffect)(()=>{if(i)return C.current=setInterval(L,l),()=>{C.current&&(clearInterval(C.current),C.current=null)}},[i,l,L]),(0,n.useEffect)(()=>{c&&(null==x?void 0:x.isStopped)&&!b&&M()},[c,null==x?void 0:x.isStopped,b,M]),{workspace:x,exists:m,isLoading:p,isWakingUp:b,statusMessage:j,actionNeeded:v,error:N,refresh:L,wakeup:M}}({autoWakeup:r,onStatusChange:(e,t)=>{null==o||o(e),t?(x("Workspace is starting up..."),c(!0),setTimeout(()=>c(!1),5e3)):"running"===e&&(x("Workspace is ready!"),c(!0),setTimeout(()=>c(!1),3e3))}}),j=(0,n.useCallback)(async()=>{let e=await f();e.success&&(null==a||a(),x(e.message),c(!0),setTimeout(()=>c(!1),5e3))},[f,a]),y=m?h&&!u?{color:"text-text-muted",bgColor:"bg-bg-tertiary",borderColor:"border-border-subtle",icon:(0,s.jsx)(eg,{}),label:"Loading...",pulseColor:null}:(null==u?void 0:u.isRunning)?{color:"text-success",bgColor:"bg-success/10",borderColor:"border-success/30",icon:(0,s.jsx)(ex,{}),label:"Running",pulseColor:"bg-success"}:(null==u?void 0:u.isStopped)?{color:"text-amber-400",bgColor:"bg-amber-400/10",borderColor:"border-amber-400/30",icon:(0,s.jsx)(eu,{}),label:"Stopped",pulseColor:null}:(null==u?void 0:u.isProvisioning)||p?{color:"text-accent-cyan",bgColor:"bg-accent-cyan/10",borderColor:"border-accent-cyan/30",icon:(0,s.jsx)(em,{}),label:p?"Starting...":"Provisioning",pulseColor:"bg-accent-cyan"}:(null==u?void 0:u.hasError)?{color:"text-error",bgColor:"bg-error/10",borderColor:"border-error/30",icon:(0,s.jsx)(eh,{}),label:"Error",pulseColor:null}:{color:"text-text-muted",bgColor:"bg-bg-tertiary",borderColor:"border-border-subtle",icon:(0,s.jsx)(ep,{}),label:"Unknown",pulseColor:null}:{color:"text-text-muted",bgColor:"bg-bg-tertiary",borderColor:"border-border-subtle",icon:(0,s.jsx)(ep,{}),label:"No workspace",pulseColor:null};return t?(0,s.jsxs)("div",{className:"rounded-lg border ".concat(y.borderColor," ").concat(y.bgColor," p-4 ").concat(i),children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:y.color,children:y.icon}),(0,s.jsx)("span",{className:"text-sm font-semibold ".concat(y.color),children:"Workspace Status"})]}),y.pulseColor&&(0,s.jsx)("span",{className:"w-2.5 h-2.5 rounded-full ".concat(y.pulseColor," animate-pulse")})]}),(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsx)("span",{className:"text-xs text-text-muted",children:"Name"}),(0,s.jsx)("span",{className:"text-sm text-text-primary font-medium truncate max-w-[150px]",children:(null==u?void 0:u.name)||"None"})]}),(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsx)("span",{className:"text-xs text-text-muted",children:"Status"}),(0,s.jsx)("span",{className:"text-sm font-medium ".concat(y.color),children:y.label})]}),g&&(0,s.jsx)("p",{className:"text-xs text-text-muted mt-2",children:g}),"wakeup"===b&&!p&&(0,s.jsx)("button",{onClick:j,className:"w-full mt-3 px-3 py-2 text-sm font-medium text-amber-400 bg-amber-400/10 border border-amber-400/30 rounded-lg hover:bg-amber-400/20 transition-colors",children:"Wake up workspace"}),"check_error"===b&&(0,s.jsx)("a",{href:"/workspaces/".concat(null==u?void 0:u.id),className:"block w-full mt-3 px-3 py-2 text-sm font-medium text-center text-error bg-error/10 border border-error/30 rounded-lg hover:bg-error/20 transition-colors no-underline",children:"View error details"})]}),l&&(0,s.jsx)("div",{className:"mt-3 px-3 py-2 bg-bg-card border border-border-medium rounded-lg text-sm text-text-primary animate-in fade-in",children:d})]}):(0,s.jsxs)("div",{className:"relative ".concat(i),children:[(0,s.jsxs)("div",{className:"flex items-center gap-2 px-2.5 py-1.5 rounded-lg border ".concat(y.bgColor," ").concat(y.borderColor," cursor-default"),title:g||y.label,children:[(0,s.jsx)("span",{className:y.color,children:y.icon}),(0,s.jsx)("span",{className:"text-xs font-medium ".concat(y.color," truncate max-w-[100px]"),title:g||y.label,children:y.label}),y.pulseColor&&(0,s.jsx)("span",{className:"w-2 h-2 rounded-full ".concat(y.pulseColor," animate-pulse")})]}),"wakeup"===b&&!p&&(0,s.jsx)("button",{onClick:j,className:"ml-2 px-2 py-1 text-xs font-medium text-amber-400 bg-amber-400/10 border border-amber-400/30 rounded hover:bg-amber-400/20 transition-colors",children:"Wake up"}),l&&(0,s.jsx)("div",{className:"absolute top-full mt-2 left-0 z-50 px-3 py-2 bg-bg-card border border-border-medium rounded-lg shadow-lg text-sm text-text-primary whitespace-nowrap animate-in fade-in slide-in-from-top-2",children:d})]})}function ex(){return(0,s.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,s.jsx)("polygon",{points:"5 3 19 12 5 21 5 3"})})}function eu(){return(0,s.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,s.jsx)("rect",{x:"6",y:"6",width:"12",height:"12"})})}function em(){return(0,s.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"animate-spin",children:(0,s.jsx)("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})})}function eh(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,s.jsx)("line",{x1:"15",y1:"9",x2:"9",y2:"15"}),(0,s.jsx)("line",{x1:"9",y1:"9",x2:"15",y2:"15"})]})}function ep(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"}),(0,s.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"16"}),(0,s.jsx)("line",{x1:"8",y1:"12",x2:"16",y2:"12"})]})}function eg(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"animate-spin",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10",strokeOpacity:"0.25"}),(0,s.jsx)("path",{d:"M12 2a10 10 0 0 1 10 10"})]})}function eb(e){let{currentChannel:t,selectedAgent:r,projects:n=[],currentProject:o,recentProjects:i=[],onProjectChange:c,onCommandPaletteOpen:d,onSettingsClick:x,onHistoryClick:u,onNewConversationClick:m,onCoordinatorClick:h,onFleetClick:p,isFleetViewActive:g,onTrajectoryClick:b,hasActiveTrajectory:f,onMenuClick:j,hasUnreadNotifications:y}=e,v="general"===t,w=r?(0,a.GW)(r.name):null,N=n.length>1;return(0,s.jsxs)("header",{className:"h-[52px] bg-bg-secondary border-b border-border-subtle flex items-center justify-between px-2 sm:px-4",children:[(0,s.jsxs)("button",{className:"flex md:hidden items-center justify-center w-10 h-10 sm:w-11 sm:h-11 bg-transparent border-none text-text-primary cursor-pointer rounded-lg transition-colors hover:bg-bg-hover active:bg-bg-hover relative flex-shrink-0",onClick:j,"aria-label":"Open menu",children:[(0,s.jsx)(eC,{}),y&&(0,s.jsx)("span",{className:"absolute top-1 right-1 sm:top-1.5 sm:right-1.5 w-2.5 h-2.5 bg-error rounded-full animate-pulse shadow-[0_0_8px_rgba(239,68,68,0.6)]"})]}),n.length>0&&c&&(0,s.jsx)("div",{className:"max-md:hidden mr-3",children:(0,s.jsx)(er,{projects:n,recentProjects:i,currentProject:null!=o?o:null,onProjectChange:c})}),n.length>0&&c&&(0,s.jsx)("div",{className:"w-px h-6 bg-border-subtle mr-3 max-md:hidden"}),(0,s.jsx)(ed,{className:"max-md:hidden mr-3"}),(0,s.jsx)("div",{className:"w-px h-6 bg-border-subtle mr-3 max-md:hidden"}),(0,s.jsx)("div",{className:"flex items-center gap-2 sm:gap-3 flex-1 min-w-0",children:v?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("span",{className:"text-accent-cyan text-base sm:text-lg font-mono",children:"#"}),(0,s.jsx)("span",{className:"font-display font-semibold text-sm sm:text-base text-text-primary truncate max-w-[100px] sm:max-w-none",children:"general"}),(0,s.jsx)("span",{className:"text-text-muted text-sm ml-2 pl-3 border-l border-border-subtle hidden md:inline",children:"All agent communications"})]}):r?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"w-7 h-7 sm:w-8 sm:h-8 rounded-lg flex items-center justify-center font-semibold text-[10px] sm:text-xs border-2 flex-shrink-0",style:{backgroundColor:null==w?void 0:w.primary,borderColor:null==w?void 0:w.primary,boxShadow:"0 0 12px ".concat(null==w?void 0:w.primary,"40")},children:(0,s.jsx)("span",{style:{color:null==w?void 0:w.text},children:(0,a.hP)(r.name)})}),(0,s.jsxs)("div",{className:"flex flex-col min-w-0",children:[(0,s.jsx)("span",{className:"font-display font-semibold text-sm sm:text-base text-text-primary truncate",children:r.name}),(0,s.jsx)("span",{className:"text-text-muted text-xs font-mono hidden md:block truncate",children:l(r.name)})]}),r.status&&(0,s.jsx)("span",{className:"hidden sm:inline text-xs py-1 px-2.5 rounded-full font-medium ml-2 flex-shrink-0 truncate max-w-[80px] ".concat("online"===r.status?"bg-success/20 text-success":"bg-bg-tertiary text-text-muted"),title:r.status,children:r.status})]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("span",{className:"text-accent-cyan text-base sm:text-lg font-mono",children:"@"}),(0,s.jsx)("span",{className:"font-display font-semibold text-sm sm:text-base text-text-primary truncate",children:t})]})}),(0,s.jsxs)("div",{className:"flex items-center gap-1 sm:gap-2",children:[(0,s.jsxs)("button",{className:"flex items-center gap-1 sm:gap-2 py-1.5 sm:py-2 px-2 sm:px-4 bg-gradient-to-r from-accent-cyan to-[#00b8d9] text-bg-deep font-semibold border-none rounded-lg text-xs sm:text-sm cursor-pointer transition-all duration-150 hover:shadow-glow-cyan hover:-translate-y-0.5",onClick:m,title:"Start new conversation (⌘N)",children:[(0,s.jsx)(ef,{}),(0,s.jsx)("span",{className:"hidden sm:inline",children:"New"}),(0,s.jsx)("span",{className:"hidden md:inline",children:"Message"})]}),(0,s.jsxs)("button",{className:"flex items-center gap-1 sm:gap-2 py-1.5 sm:py-2 px-2 sm:px-3 bg-bg-tertiary border border-border-subtle rounded-lg text-text-secondary text-xs sm:text-sm cursor-pointer transition-all duration-150 hover:bg-bg-elevated hover:border-border-medium hover:text-text-primary",onClick:d,title:"Command Palette (⌘K)",children:[(0,s.jsx)(ej,{}),(0,s.jsx)("span",{className:"hidden md:inline",children:"Search"}),(0,s.jsx)("kbd",{className:"hidden md:inline bg-bg-card border border-border-subtle rounded px-1.5 py-0.5 text-xs text-text-muted font-mono",children:"⌘K"})]}),(0,s.jsx)("button",{className:"hidden sm:flex items-center justify-center p-1.5 sm:p-2 bg-bg-tertiary border border-border-subtle rounded-lg text-text-secondary cursor-pointer transition-all duration-150 hover:bg-bg-elevated hover:border-border-medium hover:text-accent-cyan",onClick:u,title:"Message History",children:(0,s.jsx)(ey,{})}),N&&(0,s.jsx)("button",{className:"hidden md:flex items-center justify-center p-2 bg-bg-tertiary border border-border-subtle rounded-lg text-text-secondary cursor-pointer transition-all duration-150 hover:bg-bg-elevated hover:border-border-medium hover:text-accent-purple",onClick:h,title:"Coordinator Agent",children:(0,s.jsx)(eS,{})}),p&&(0,s.jsx)("button",{className:"hidden sm:flex items-center justify-center p-1.5 sm:p-2 border rounded-lg cursor-pointer transition-all duration-150 ".concat(g?"bg-accent-cyan/20 border-accent-cyan text-accent-cyan":"bg-bg-tertiary border-border-subtle text-text-secondary hover:bg-bg-elevated hover:border-border-medium hover:text-accent-cyan"),onClick:p,title:g?"Back to Chat":"Fleet Overview",children:(0,s.jsx)(ew,{})}),b&&(0,s.jsxs)("button",{className:"hidden md:flex items-center justify-center p-2 border rounded-lg cursor-pointer transition-all duration-150 relative ".concat(f?"bg-accent-cyan/20 border-accent-cyan text-accent-cyan":"bg-bg-tertiary border-border-subtle text-text-secondary hover:bg-bg-elevated hover:border-border-medium hover:text-accent-cyan"),onClick:b,title:"Trajectory Viewer",children:[(0,s.jsx)(eN,{}),f&&(0,s.jsx)("span",{className:"absolute -top-1 -right-1 w-2 h-2 bg-accent-cyan rounded-full animate-pulse"})]}),(0,s.jsx)("a",{href:"/metrics",className:"hidden sm:flex items-center justify-center p-1.5 sm:p-2 bg-bg-tertiary border border-border-subtle rounded-lg text-text-secondary cursor-pointer transition-all duration-150 hover:bg-bg-elevated hover:border-border-medium hover:text-accent-orange no-underline",title:"Fleet Metrics",children:(0,s.jsx)(ev,{})}),(0,s.jsx)("button",{className:"flex items-center justify-center p-1.5 sm:p-2 bg-bg-tertiary border border-border-subtle rounded-lg text-text-secondary cursor-pointer transition-all duration-150 hover:bg-bg-elevated hover:border-border-medium hover:text-accent-purple",onClick:x,title:"Settings",children:(0,s.jsx)(ek,{})})]})]})}function ef(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[(0,s.jsx)("path",{d:"M12 20h9"}),(0,s.jsx)("path",{d:"M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z"})]})}function ej(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,s.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]})}function ey(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,s.jsx)("polyline",{points:"12 6 12 12 16 14"})]})}function ev(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("path",{d:"M3 3v18h18"}),(0,s.jsx)("path",{d:"M18 17V9"}),(0,s.jsx)("path",{d:"M13 17V5"}),(0,s.jsx)("path",{d:"M8 17v-3"})]})}function ew(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2",ry:"2"}),(0,s.jsx)("line",{x1:"8",y1:"21",x2:"16",y2:"21"}),(0,s.jsx)("line",{x1:"12",y1:"17",x2:"12",y2:"21"})]})}function eN(){return(0,s.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,s.jsx)("path",{d:"M3 12h4l3 9 4-18 3 9h4"})})}function ek(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"3"}),(0,s.jsx)("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"})]})}function eC(){return(0,s.jsxs)("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("line",{x1:"3",y1:"12",x2:"21",y2:"12"}),(0,s.jsx)("line",{x1:"3",y1:"6",x2:"21",y2:"6"}),(0,s.jsx)("line",{x1:"3",y1:"18",x2:"21",y2:"18"})]})}function eS(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"3"}),(0,s.jsx)("circle",{cx:"5",cy:"5",r:"2"}),(0,s.jsx)("circle",{cx:"19",cy:"5",r:"2"}),(0,s.jsx)("circle",{cx:"5",cy:"19",r:"2"}),(0,s.jsx)("circle",{cx:"19",cy:"19",r:"2"}),(0,s.jsx)("line",{x1:"9.5",y1:"9.5",x2:"6.5",y2:"6.5"}),(0,s.jsx)("line",{x1:"14.5",y1:"9.5",x2:"17.5",y2:"6.5"}),(0,s.jsx)("line",{x1:"9.5",y1:"14.5",x2:"6.5",y2:"17.5"}),(0,s.jsx)("line",{x1:"14.5",y1:"14.5",x2:"17.5",y2:"17.5"})]})}var eA=r(2500),eL=r(9880);function eE(e){let{status:t,size:r="small"}=e;if(!t)return null;let n={small:"w-3.5 h-3.5",medium:"w-4 h-4"}[r];return"sending"===t||"unread"===t?(0,s.jsx)("span",{className:"inline-flex items-center justify-center ".concat(n," text-text-muted"),title:"Sending...",children:(0,s.jsx)(eW,{className:n})}):"acked"===t||"read"===t?(0,s.jsx)("span",{className:"inline-flex items-center justify-center ".concat(n," text-success"),title:"Delivered",children:(0,s.jsx)(eM,{className:n})}):"failed"===t?(0,s.jsx)("span",{className:"inline-flex items-center justify-center ".concat(n," text-error"),title:"Delivery failed",children:(0,s.jsx)(eD,{className:n})}):null}function eW(e){let{className:t}=e;return(0,s.jsxs)("svg",{className:"animate-pulse ".concat(t),viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[(0,s.jsx)("circle",{cx:"8",cy:"8",r:"6"}),(0,s.jsx)("path",{d:"M8 5v3l2 1",strokeLinecap:"round",strokeLinejoin:"round"})]})}function eM(e){let{className:t}=e;return(0,s.jsx)("svg",{className:t,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.jsx)("path",{d:"M3 8l3 3 7-7",strokeLinecap:"round",strokeLinejoin:"round"})})}function eD(e){let{className:t}=e;return(0,s.jsxs)("svg",{className:t,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"8",cy:"8",r:"6"}),(0,s.jsx)("line",{x1:"8",y1:"5",x2:"8",y2:"8",strokeLinecap:"round"}),(0,s.jsx)("circle",{cx:"8",cy:"11",r:"0.5",fill:"currentColor",stroke:"none"})]})}let eT={claude:{icon:"◈",color:"#00d9ff"},codex:{icon:"⬡",color:"#ff6b35"},gemini:{icon:"◇",color:"#a855f7"},openai:{icon:"◆",color:"#10a37f"},default:{icon:"●",color:"#00d9ff"}};function eR(e){let{messages:t,currentChannel:r,onThreadClick:a,highlightedMessageId:o,currentThread:i,agents:l=[],currentUser:c}=e,d=new Map;for(let e of l)e.isProcessing&&d.set(e.name,{isProcessing:!0,processingStartedAt:e.processingStartedAt});let x=new Map,u=(0,n.useRef)(null),[m,h]=(0,n.useState)(!0),p=(0,n.useRef)(0),g=(0,n.useRef)(r),b=(0,n.useRef)(!1),f=(0,n.useRef)(!1),j=t.filter(e=>i?e.id===i||e.thread===i:"general"===r?"*"===e.to||e.isBroadcast||"general"===e.channel:e.from===r||e.to===r);for(let e of j)("Dashboard"===e.from||c&&e.from===c.displayName)&&"*"!==e.to&&x.set(e.to,e.id);let y=j.length;if(y>p.current){let e=j[j.length-1],t=(null==e?void 0:e.from)==="Dashboard"||c&&(null==e?void 0:e.from)===c.displayName;(t||m)&&(b.current=!0,t&&!m&&h(!0))}p.current=y;let v=(0,n.useCallback)(()=>{if(!u.current||f.current)return;let e=u.current,t=e.scrollHeight-e.scrollTop-e.clientHeight;t<50&&!m?h(!0):t>150&&m&&h(!1)},[m]);return((0,n.useLayoutEffect)(()=>{if(b.current&&u.current){b.current=!1,f.current=!0;let e=u.current;e.scrollTop=e.scrollHeight,requestAnimationFrame(()=>{setTimeout(()=>{f.current=!1},50)})}},[j.length]),(0,n.useLayoutEffect)(()=>{if(r!==g.current&&(g.current=r,p.current=j.length,h(!0),u.current)){f.current=!0;let e=u.current;e.scrollTop=e.scrollHeight,requestAnimationFrame(()=>{setTimeout(()=>{f.current=!1},50)})}},[r,j.length]),0===j.length)?(0,s.jsxs)("div",{className:"flex flex-col items-center justify-center h-full text-text-muted text-center",children:[(0,s.jsx)(eO,{}),(0,s.jsx)("h3",{className:"m-0 mb-2 text-base font-display text-text-secondary",children:"No messages yet"}),(0,s.jsx)("p",{className:"m-0 text-sm",children:"general"===r?"Broadcast messages will appear here":"Messages with ".concat(r," will appear here")})]}):(0,s.jsx)("div",{className:"flex flex-col gap-1 p-2 sm:p-4 bg-bg-secondary h-full overflow-y-auto",ref:u,onScroll:v,children:j.map(e=>{let t=("Dashboard"===e.from||c&&e.from===c.displayName)&&"*"!==e.to&&x.get(e.to)===e.id?d.get(e.to):void 0;return(0,s.jsx)(eP,{message:e,isHighlighted:e.id===o,onThreadClick:a,recipientProcessing:t,currentUser:c},e.id)})})}function eP(e){let{message:t,isHighlighted:r,onThreadClick:a,recipientProcessing:o,currentUser:i}=e,l=function(e){let t=new Date(e),r=new Date;if(t.toDateString()===r.toDateString())return t.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"});let s=new Date(r);return(s.setDate(s.getDate()-1),t.toDateString()===s.toDateString())?"Yesterday ".concat(t.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})):t.toLocaleDateString([],{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}(t.timestamp),c="Dashboard"===t.from||i&&t.from===i.displayName,d=c&&i?{icon:"",color:"#a855f7"}:function(e){let t=e.toLowerCase();if(t.includes("claude")||t.includes("anthropic"))return eT.claude;if(t.includes("codex")||t.includes("openai")||t.includes("gpt"))return eT.codex;if(t.includes("gemini")||t.includes("google")||t.includes("bard"))return eT.gemini;let r=e.split("").reduce((e,t)=>e+t.charCodeAt(0),0),s=Object.keys(eT).filter(e=>"default"!==e);return eT[s[r%s.length]]}(t.from),x=c&&i?i.displayName:t.from,m=t.replyCount&&t.replyCount>0,h=c&&("acked"===t.status||"read"===t.status)&&(null==o?void 0:o.isProcessing);return(0,s.jsxs)("div",{className:"\n group flex gap-2 sm:gap-3 py-2 sm:py-3 px-2 sm:px-4 rounded-xl transition-all duration-150\n hover:bg-bg-card/50\n ".concat(r?"bg-warning-light/20 border-l-2 border-l-warning pl-2 sm:pl-3":"","\n "),children:[c&&(null==i?void 0:i.avatarUrl)?(0,s.jsx)("img",{src:i.avatarUrl,alt:x,className:"shrink-0 w-8 h-8 sm:w-10 sm:h-10 rounded-lg sm:rounded-xl border-2 object-cover",style:{borderColor:d.color,boxShadow:"0 0 16px ".concat(d.color,"30")}}):(0,s.jsx)("div",{className:"shrink-0 w-8 h-8 sm:w-10 sm:h-10 rounded-lg sm:rounded-xl flex items-center justify-center text-base sm:text-lg font-medium border-2",style:{backgroundColor:"".concat(d.color,"15"),borderColor:d.color,color:d.color,boxShadow:"0 0 16px ".concat(d.color,"30")},children:d.icon}),(0,s.jsxs)("div",{className:"flex-1 min-w-0 overflow-hidden",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2 mb-1.5 flex-wrap",children:[(0,s.jsx)("span",{className:"font-display font-semibold text-sm",style:{color:d.color},children:x}),"*"!==t.to&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("span",{className:"text-text-dim text-xs",children:"→"}),(0,s.jsx)("span",{className:"font-medium text-sm text-accent-cyan",children:t.to})]}),t.thread&&(0,s.jsx)("span",{className:"text-xs py-0.5 px-2 rounded-full font-mono font-medium bg-accent-purple/20 text-accent-purple",children:t.thread}),"*"===t.to&&(0,s.jsx)("span",{className:"text-xs py-0.5 px-2 rounded-full uppercase font-medium bg-warning/20 text-warning",children:"broadcast"}),(0,s.jsx)("span",{className:"text-text-dim text-xs ml-auto font-mono",children:l}),c&&(0,s.jsx)(eE,{status:t.status,size:"small"}),h&&(0,s.jsx)(u,{isProcessing:!0,processingStartedAt:null==o?void 0:o.processingStartedAt,size:"small",showLabel:!0}),(0,s.jsxs)("button",{className:"\n inline-flex items-center gap-1.5 p-1.5 rounded-lg transition-all duration-150 cursor-pointer border-none\n ".concat(m||t.thread?"text-accent-cyan bg-accent-cyan/10 hover:bg-accent-cyan/20":"text-text-muted bg-transparent opacity-0 group-hover:opacity-100 hover:text-accent-cyan hover:bg-accent-cyan/10","\n "),onClick:()=>null==a?void 0:a(t.thread||t.id),title:t.thread?"View thread: ".concat(t.thread):m?"".concat(t.replyCount," ").concat(1===t.replyCount?"reply":"replies"):"Reply in thread",children:[(0,s.jsx)(ez,{}),m&&(0,s.jsx)("span",{className:"text-xs font-medium",children:t.replyCount})]})]}),(0,s.jsx)("div",{className:"text-sm leading-relaxed text-text-primary whitespace-pre-wrap break-words",children:function(e){let t=e.replace(/\\n/g,"\n").replace(/\r\n/g,"\n").replace(/\r/g,"\n"),r=function(e){let t;let r=[],s=/```(\w*)\n([\s\S]*?)```/g,n=0;for(;null!==(t=s.exec(e));){if(t.index>n){let s=eF(e.slice(n,t.index));r.push(...s)}r.push({type:"code",language:t[1]||"text",content:t[2]}),n=t.index+t[0].length}if(n<e.length){let t=eF(e.slice(n));r.push(...t)}return 0===r.length?eF(e):r}(t);return 1===r.length&&"text"===r[0].type?t.split("\n").map((e,t)=>(0,s.jsxs)(n.Fragment,{children:[t>0&&(0,s.jsx)("br",{}),eU(e)]},t)):r.map((e,t)=>{if("code"===e.type)return(0,s.jsx)(eI,{code:e.content,language:e.language||"text"},t);if("table"===e.type)return(0,s.jsx)("pre",{className:"font-mono text-xs leading-relaxed whitespace-pre overflow-x-auto my-2 p-3 bg-bg-tertiary/50 rounded-lg border border-border-subtle",children:e.content},t);let r=e.content.split("\n");return(0,s.jsx)("span",{children:r.map((e,t)=>(0,s.jsxs)(n.Fragment,{children:[t>0&&(0,s.jsx)("br",{}),eU(e)]},t))},t)})}(t.content)}),t.attachments&&t.attachments.length>0&&(0,s.jsx)(eB,{attachments:t.attachments})]})]})}function eB(e){let{attachments:t}=e,[r,a]=(0,n.useState)(null),o=t.filter(e=>e.mimeType.startsWith("image/"));return 0===o.length?null:(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"flex flex-wrap gap-2 mt-2",children:o.map(e=>(0,s.jsxs)("button",{type:"button",onClick:()=>a(e),className:"relative group cursor-pointer bg-transparent border-0 p-0",title:"View ".concat(e.filename),children:[(0,s.jsx)("img",{src:e.data||e.url,alt:e.filename,className:"max-h-48 max-w-xs rounded-lg border border-border-subtle object-cover transition-all duration-150 group-hover:border-accent-cyan/50 group-hover:shadow-[0_0_8px_rgba(0,217,255,0.2)]",loading:"lazy"}),(0,s.jsx)("div",{className:"absolute inset-0 bg-black/0 group-hover:bg-black/10 rounded-lg transition-colors flex items-center justify-center opacity-0 group-hover:opacity-100",children:(0,s.jsxs)("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"2",className:"drop-shadow-lg",children:[(0,s.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,s.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"}),(0,s.jsx)("line",{x1:"11",y1:"8",x2:"11",y2:"14"}),(0,s.jsx)("line",{x1:"8",y1:"11",x2:"14",y2:"11"})]})})]},e.id))}),r&&(0,s.jsx)("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-black/80 backdrop-blur-sm",onClick:()=>a(null),children:(0,s.jsxs)("div",{className:"relative max-w-[90vw] max-h-[90vh]",children:[(0,s.jsx)("img",{src:r.data||r.url,alt:r.filename,className:"max-w-full max-h-[90vh] rounded-lg shadow-2xl",onClick:e=>e.stopPropagation()}),(0,s.jsx)("button",{type:"button",onClick:()=>a(null),className:"absolute -top-3 -right-3 w-8 h-8 bg-bg-tertiary border border-border-subtle rounded-full flex items-center justify-center text-text-muted hover:text-text-primary hover:bg-bg-card transition-colors shadow-lg",title:"Close",children:(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}),(0,s.jsx)("div",{className:"absolute bottom-0 left-0 right-0 p-3 bg-gradient-to-t from-black/60 to-transparent rounded-b-lg",children:(0,s.jsx)("p",{className:"text-white text-sm truncate",children:r.filename})})]})})]})}let e_={...eL.Z,'pre[class*="language-"]':{...eL.Z['pre[class*="language-"]'],background:"rgba(15, 23, 42, 0.8)",margin:"0.5rem 0",padding:"1rem",borderRadius:"0.5rem",border:"1px solid rgba(148, 163, 184, 0.1)",fontSize:"0.75rem",lineHeight:"1.5"},'code[class*="language-"]':{...eL.Z['code[class*="language-"]'],background:"transparent",fontSize:"0.75rem"}};function eI(e){let{code:t,language:r}=e,[a,o]=(0,n.useState)(!1),i=(0,n.useCallback)(async()=>{try{await navigator.clipboard.writeText(t),o(!0),setTimeout(()=>o(!1),2e3)}catch(e){console.error("Failed to copy:",e)}},[t]),l=r.toLowerCase().replace(/^(js|jsx)$/,"javascript").replace(/^(ts|tsx)$/,"typescript").replace(/^(py)$/,"python").replace(/^(rb)$/,"ruby").replace(/^(sh|shell|zsh)$/,"bash");return(0,s.jsxs)("div",{className:"relative group my-2",children:[(0,s.jsxs)("div",{className:"absolute top-2 right-2 flex items-center gap-2 z-10",children:[r&&"text"!==r&&(0,s.jsx)("span",{className:"text-xs px-2 py-0.5 rounded bg-accent-cyan/20 text-accent-cyan font-mono",children:r}),(0,s.jsx)("button",{onClick:i,className:"opacity-0 group-hover:opacity-100 transition-opacity text-xs px-2 py-1 rounded bg-bg-tertiary hover:bg-bg-card text-text-muted hover:text-text-primary border border-border-subtle",title:"Copy code",children:a?"✓ Copied":"Copy"})]}),(0,s.jsx)(eA.Z,{language:l,style:e_,customStyle:{margin:0,background:"rgba(15, 23, 42, 0.8)"},showLineNumbers:t.split("\n").length>3,lineNumberStyle:{minWidth:"2.5em",paddingRight:"1em",color:"rgba(148, 163, 184, 0.4)",userSelect:"none"},children:t.trim()})]})}function eF(e){let t=e.split("\n"),r=[],s=null;for(let e of t){let t=(e.match(/\|/g)||[]).length>=2||e.trim().startsWith("|")&&e.trim().endsWith("|")||/^[\s|:-]+$/.test(e)&&e.includes("-")&&e.includes("|")?"table":"text";s&&s.type===t?s.content+="\n"+e:(s&&r.push(s),s={type:t,content:e})}return s&&r.push(s),r}function eU(e){return e.split(/(`[^`]+`|https?:\/\/[^\s]+)/g).map((e,t)=>{if(!e)return null;if(e.startsWith("`")&&e.endsWith("`")&&e.length>2){let r=e.slice(1,-1);return(0,s.jsx)("code",{className:"px-1.5 py-0.5 mx-0.5 rounded bg-bg-elevated/80 text-accent-cyan font-mono text-[0.85em] border border-border-subtle/50",children:r},t)}return/^https?:\/\//.test(e)?(0,s.jsx)("a",{href:e,target:"_blank",rel:"noopener noreferrer",className:"text-accent-cyan no-underline hover:underline",children:e},t):e})}function eO(){return(0,s.jsx)("svg",{className:"mb-4 opacity-50 text-text-muted",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:(0,s.jsx)("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}function ez(){return(0,s.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.jsx)("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}function eH(e){let{originalMessage:t,replies:r,onClose:a,onReply:o,isSending:i=!1,currentUser:l}=e,[c,d]=(0,n.useState)(""),x=(0,n.useRef)(null),u=(0,n.useRef)(null);(0,n.useEffect)(()=>{requestAnimationFrame(()=>{var e;null===(e=x.current)||void 0===e||e.scrollIntoView({behavior:"smooth"})})},[r.length]),(0,n.useEffect)(()=>{var e;null===(e=u.current)||void 0===e||e.focus()},[null==t?void 0:t.id]);let m=async e=>{e.preventDefault(),c.trim()&&!i&&await o(c.trim())&&d("")};return t?(0,s.jsxs)("div",{className:"flex flex-col h-full bg-bg-primary border-l border-border",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border bg-bg-secondary",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(eK,{}),(0,s.jsx)("span",{className:"font-semibold text-sm text-text-primary",children:"Thread"}),(0,s.jsxs)("span",{className:"text-text-muted text-xs",children:[r.length," ",1===r.length?"reply":"replies"]})]}),(0,s.jsx)("button",{onClick:a,className:"p-1.5 rounded hover:bg-bg-hover transition-colors text-text-muted hover:text-text-primary",title:"Close thread",children:(0,s.jsx)(eJ,{})})]}),(0,s.jsxs)("div",{className:"flex-1 overflow-y-auto",children:[(0,s.jsx)("div",{className:"p-4 border-b border-border",children:(0,s.jsx)(eV,{message:t,isOriginal:!0,currentUser:l})}),(0,s.jsxs)("div",{className:"p-4 space-y-3",children:[0===r.length?(0,s.jsx)("div",{className:"text-center text-text-muted text-sm py-8",children:"No replies yet. Be the first to reply!"}):r.map(e=>(0,s.jsx)(eV,{message:e,currentUser:l},e.id)),(0,s.jsx)("div",{ref:x})]})]}),(0,s.jsx)("div",{className:"p-4 border-t border-border bg-bg-secondary",children:(0,s.jsxs)("form",{onSubmit:m,className:"flex gap-2",children:[(0,s.jsx)("textarea",{ref:u,value:c,onChange:e=>d(e.target.value),onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),m(e))},placeholder:"Reply to thread...",disabled:i,rows:1,className:"flex-1 py-2 px-3 bg-bg-primary border border-border rounded-md text-sm text-text-primary resize-none min-h-[40px] max-h-[100px] overflow-y-auto focus:outline-none focus:border-accent transition-colors placeholder:text-text-muted"}),(0,s.jsx)("button",{type:"submit",disabled:!c.trim()||i,className:"px-4 py-2 bg-accent text-white rounded-md text-sm font-medium transition-colors hover:bg-accent-hover disabled:opacity-50 disabled:cursor-not-allowed",children:i?"Sending...":"Reply"})]})})]}):null}function eV(e){let{message:t,isOriginal:r,currentUser:o}=e,i=(0,a.GW)(t.from),l=function(e){let t=new Date(e),r=new Date;return t.toDateString()===r.toDateString()?t.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):t.toLocaleDateString([],{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}(t.timestamp),c="Dashboard"===t.from||o&&t.from===o.displayName,d=c&&o?o.displayName:t.from;return(0,s.jsxs)("div",{className:"flex gap-3 ".concat(r?"":"pl-2"),children:[c&&(null==o?void 0:o.avatarUrl)?(0,s.jsx)("img",{src:o.avatarUrl,alt:d,className:"shrink-0 w-8 h-8 rounded-lg object-cover"}):(0,s.jsx)("div",{className:"shrink-0 w-8 h-8 rounded-lg flex items-center justify-center font-semibold text-xs",style:{backgroundColor:i.primary,color:i.text},children:(0,a.hP)(t.from)}),(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2 mb-1",children:[(0,s.jsx)("span",{className:"font-semibold text-sm text-text-primary",children:d}),"*"!==t.to&&!r&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("span",{className:"text-text-muted text-xs",children:"→"}),(0,s.jsx)("span",{className:"text-sm text-accent",children:t.to})]}),(0,s.jsx)("span",{className:"text-text-muted text-xs",children:l}),r&&(0,s.jsx)("span",{className:"text-[10px] py-0.5 px-1.5 rounded bg-accent-light text-accent font-medium",children:"Original"})]}),(0,s.jsx)("div",{className:"text-sm leading-relaxed text-text-primary whitespace-pre-wrap break-words",children:t.content.replace(/\\n/g,"\n").replace(/\r\n/g,"\n").replace(/\r/g,"\n").split("\n").map((e,t)=>(0,s.jsxs)(n.Fragment,{children:[t>0&&(0,s.jsx)("br",{}),function(e){let t=/(https?:\/\/[^\s]+)/g;return e.split(t).map((e,r)=>t.test(e)?(0,s.jsx)("a",{href:e,target:"_blank",rel:"noopener noreferrer",className:"text-accent hover:underline",children:e},r):e)}(e)]},t))}),t.attachments&&t.attachments.length>0&&(0,s.jsx)(eG,{attachments:t.attachments})]})]})}function eG(e){let{attachments:t}=e,[r,a]=(0,n.useState)(null),o=t.filter(e=>e.mimeType.startsWith("image/"));return 0===o.length?null:(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"flex flex-wrap gap-2 mt-2",children:o.map(e=>(0,s.jsxs)("button",{type:"button",onClick:()=>a(e),className:"relative group cursor-pointer bg-transparent border-0 p-0",title:"View ".concat(e.filename),children:[(0,s.jsx)("img",{src:e.data||e.url,alt:e.filename,className:"max-h-32 max-w-[200px] rounded-lg border border-border object-cover transition-all duration-150 group-hover:border-accent/50 group-hover:shadow-md",loading:"lazy"}),(0,s.jsx)("div",{className:"absolute inset-0 bg-black/0 group-hover:bg-black/10 rounded-lg transition-colors flex items-center justify-center opacity-0 group-hover:opacity-100",children:(0,s.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"2",className:"drop-shadow-lg",children:[(0,s.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,s.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"}),(0,s.jsx)("line",{x1:"11",y1:"8",x2:"11",y2:"14"}),(0,s.jsx)("line",{x1:"8",y1:"11",x2:"14",y2:"11"})]})})]},e.id))}),r&&(0,s.jsx)("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-black/80 backdrop-blur-sm",onClick:()=>a(null),children:(0,s.jsxs)("div",{className:"relative max-w-[90vw] max-h-[90vh]",children:[(0,s.jsx)("img",{src:r.data||r.url,alt:r.filename,className:"max-w-full max-h-[90vh] rounded-lg shadow-2xl",onClick:e=>e.stopPropagation()}),(0,s.jsx)("button",{type:"button",onClick:()=>a(null),className:"absolute -top-3 -right-3 w-8 h-8 bg-bg-primary border border-border rounded-full flex items-center justify-center text-text-muted hover:text-text-primary hover:bg-bg-secondary transition-colors shadow-lg",title:"Close",children:(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}),(0,s.jsx)("div",{className:"absolute bottom-0 left-0 right-0 p-3 bg-gradient-to-t from-black/60 to-transparent rounded-b-lg",children:(0,s.jsx)("p",{className:"text-white text-sm truncate",children:r.filename})})]})})]})}function eK(){return(0,s.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-text-primary",children:(0,s.jsx)("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}function eJ(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}let eX=["projects","agents","actions","navigation","settings"],eY={critical:{label:"Critical",beadsPriority:0,color:"#ef4444"},high:{label:"High",beadsPriority:1,color:"#f97316"},medium:{label:"Medium",beadsPriority:2,color:"#f59e0b"},low:{label:"Low",beadsPriority:3,color:"#6366f1"}};function eq(e){return e.isOpen?(0,s.jsx)(e$,{...e}):null}function e$(e){let{onClose:t,agents:r,projects:o=[],currentProject:i,onAgentSelect:l,onProjectSelect:c,onSpawnClick:d,onTaskCreate:x,onSettingsClick:u,onGeneralClick:m,customCommands:h=[]}=e,[p,g]=(0,n.useState)(""),[b,f]=(0,n.useState)(0),[j,y]=(0,n.useState)(null),v=(0,n.useRef)(b),w=(0,n.useRef)(null),N=(0,n.useRef)(null),k=(0,n.useRef)([]),[C,S]=(0,n.useState)("search"),[A,L]=(0,n.useState)(null),[E,W]=(0,n.useState)(""),[M,D]=(0,n.useState)("medium"),[T,R]=(0,n.useState)(!1),P=(0,n.useMemo)(()=>r.filter(e=>"offline"!==e.status&&"error"!==e.status),[r]),B=(0,n.useMemo)(()=>{if(!p.trim())return P;let e=p.toLowerCase();return P.filter(t=>t.name.toLowerCase().includes(e))},[P,p]),_=(0,n.useCallback)(()=>{S("task-select-agent"),g(""),f(0),L(null),W(""),D("medium")},[]),I=(0,n.useCallback)(async()=>{if(A&&E.trim()&&x){R(!0);try{await x({agentName:A.name,title:E.trim(),priority:M}),t()}catch(e){console.error("Failed to create task:",e)}finally{R(!1)}}},[A,E,M,x,t]);(0,n.useEffect)(()=>{v.current=b},[b]);let F=(0,n.useMemo)(()=>[...[...o].sort((e,t)=>{let r=e.id===i,s=t.id===i;if(r&&!s)return -1;if(!r&&s)return 1;let n=e.name||e.path.split("/").pop()||e.id,a=t.name||t.path.split("/").pop()||t.id;return n.localeCompare(a)}).map(e=>{let r=e.name||e.path.split("/").pop()||e.id,n=e.id===i;return{id:"project-".concat(e.id),label:r,description:n?"Current project • ".concat(e.agents.length," agents"):"".concat(e.agents.length," agents"),category:"projects",icon:n?(0,s.jsx)(e3,{}):(0,s.jsx)(e4,{}),action:()=>{null==c||c(e),t()}}}),...r.map(e=>({id:"agent-".concat(e.name),label:e.name,description:e.currentTask||e.status,category:"agents",icon:(0,s.jsx)(eZ,{name:e.name}),action:()=>{l(e),t()}})),{id:"spawn-agent",label:"Spawn Agent",description:"Launch a new agent instance",category:"actions",icon:(0,s.jsx)(e0,{}),shortcut:"⌘⇧S",action:()=>{d(),t()}},{id:"broadcast",label:"Broadcast Message",description:"Send message to all agents",category:"actions",icon:(0,s.jsx)(e1,{}),action:()=>{t()}},...x?[{id:"assign-task",label:"Assign Task",description:"Create a task for an agent (creates bead)",category:"actions",icon:(0,s.jsx)(e6,{}),shortcut:"⌘⇧T",action:()=>{_()}}]:[],{id:"nav-general",label:"Go to #general",description:"View all broadcast messages",category:"navigation",icon:(0,s.jsx)(e2,{}),action:()=>{null==m||m(),t()}},...u?[{id:"settings",label:"Settings",description:"Configure dashboard preferences",category:"settings",icon:(0,s.jsx)(e5,{}),shortcut:"⌘,",action:()=>{u(),t()}}]:[],...h],[r,o,i,l,c,d,u,m,t,h]),U=(0,n.useMemo)(()=>{let e=F;if(j&&(e=e.filter(e=>e.category===j)),p.trim()){let t=p.toLowerCase();e=e.filter(e=>{var r;return e.label.toLowerCase().includes(t)||(null===(r=e.description)||void 0===r?void 0:r.toLowerCase().includes(t))||e.category.toLowerCase().includes(t)})}return e},[F,p,j]),O=(0,n.useMemo)(()=>{let e={};for(let t of U)e[t.category]||(e[t.category]=[]),e[t.category].push(t);return e},[U]),z=(0,n.useMemo)(()=>eX.flatMap(e=>O[e]||[]),[O]);(0,n.useEffect)(()=>{f(0)},[p]),(0,n.useEffect)(()=>{g(""),f(0),y(null),S("search"),L(null),W(""),D("medium")},[]),(0,n.useEffect)(()=>{let e=k.current[b];e&&e.scrollIntoView({block:"nearest",behavior:"smooth"})},[b]),(0,n.useEffect)(()=>{let e=e=>{if("task-details"===C){"Escape"===e.key?(e.preventDefault(),S("task-select-agent"),g("")):"Enter"===e.key&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),I());return}if("task-select-agent"===C){switch(e.key){case"ArrowDown":e.preventDefault(),f(e=>Math.min(e+1,B.length-1));break;case"ArrowUp":e.preventDefault(),f(e=>Math.max(e-1,0));break;case"Enter":e.preventDefault(),B[v.current]&&(L(B[v.current]),S("task-details"),g(""));break;case"Escape":e.preventDefault(),S("search"),g("")}return}switch(e.key){case"ArrowDown":e.preventDefault(),f(e=>Math.min(e+1,z.length-1));break;case"ArrowUp":e.preventDefault(),f(e=>Math.max(e-1,0));break;case"Enter":e.preventDefault(),z[v.current]&&z[v.current].action();break;case"Tab":e.preventDefault(),y(t=>{if(null===t)return eX[0];let r=eX.indexOf(t);return e.shiftKey?0===r?null:eX[r-1]:r===eX.length-1?null:eX[r+1]}),f(0);break;case"Escape":e.preventDefault(),j?(y(null),f(0)):t()}};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[z,B,C,b,j,t,I]);let H={projects:"Projects",agents:"Agents",actions:"Actions",navigation:"Navigation",settings:"Settings"},V=0;if("task-select-agent"===C)return(0,s.jsx)("div",{className:"fixed inset-0 bg-black/60 flex items-start justify-center pt-[15vh] z-[1000] animate-fade-in",onClick:()=>{S("search"),g("")},children:(0,s.jsxs)("div",{className:"bg-sidebar-bg border border-sidebar-border rounded-xl w-[560px] max-w-[90vw] max-h-[60vh] flex flex-col shadow-modal animate-slide-down",onClick:e=>e.stopPropagation(),children:[(0,s.jsxs)("div",{className:"flex items-center gap-3 p-4 border-b border-sidebar-border",children:[(0,s.jsx)("button",{className:"p-1 rounded hover:bg-sidebar-border text-text-muted",onClick:()=>{S("search"),g("")},children:(0,s.jsx)(e8,{})}),(0,s.jsx)(e6,{}),(0,s.jsx)("input",{ref:w,autoFocus:!0,type:"text",className:"flex-1 border-none text-base font-sans outline-none bg-transparent text-text-primary placeholder:text-text-muted",placeholder:"Select agent to assign task...",value:p,onChange:e=>{g(e.target.value),f(0)}}),(0,s.jsx)("kbd",{className:"bg-sidebar-border border border-sidebar-hover rounded px-1.5 py-0.5 text-xs text-text-muted font-sans",children:"ESC"})]}),(0,s.jsx)("div",{className:"flex-1 overflow-y-auto p-2",ref:N,children:0===B.length?(0,s.jsx)("div",{className:"py-8 text-center text-text-muted text-sm",children:p?'No agents matching "'.concat(p,'"'):"No available agents"}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"text-xs font-semibold text-text-muted uppercase tracking-wider py-2 px-3",children:"Select Agent"}),B.map((e,t)=>{let r=(0,a.GW)(e.name);return(0,s.jsxs)("button",{ref:e=>{k.current[t]=e},className:"\n flex items-center gap-3 w-full py-2.5 px-3 border-none rounded-lg cursor-pointer text-left font-sans transition-colors duration-100\n ".concat(t===b?"bg-accent-light border border-accent/30":"bg-transparent hover:bg-sidebar-border","\n "),onClick:()=>{L(e),S("task-details"),g("")},onMouseEnter:()=>f(t),children:[(0,s.jsx)("div",{className:"w-7 h-7 rounded-md flex items-center justify-center text-xs font-semibold",style:{backgroundColor:r.primary,color:r.text},children:(0,a.hP)(e.name)}),(0,s.jsxs)("span",{className:"flex-1 min-w-0 flex flex-col gap-0.5",children:[(0,s.jsx)("span",{className:"text-sm font-medium text-text-primary",children:e.name}),(0,s.jsx)("span",{className:"text-xs text-text-muted truncate",children:e.currentTask||e.status})]})]},e.name)})]})})]})});if("task-details"===C&&A){let e=(0,a.GW)(A.name);return(0,s.jsx)("div",{className:"fixed inset-0 bg-black/60 flex items-start justify-center pt-[15vh] z-[1000] animate-fade-in",onClick:()=>{S("task-select-agent"),g("")},children:(0,s.jsxs)("div",{className:"bg-sidebar-bg border border-sidebar-border rounded-xl w-[560px] max-w-[90vw] flex flex-col shadow-modal animate-slide-down",onClick:e=>e.stopPropagation(),children:[(0,s.jsxs)("div",{className:"flex items-center gap-3 p-4 border-b border-sidebar-border",children:[(0,s.jsx)("button",{className:"p-1 rounded hover:bg-sidebar-border text-text-muted",onClick:()=>{S("task-select-agent"),g("")},children:(0,s.jsx)(e8,{})}),(0,s.jsx)("div",{className:"w-7 h-7 rounded-md flex items-center justify-center text-xs font-semibold",style:{backgroundColor:e.primary,color:e.text},children:(0,a.hP)(A.name)}),(0,s.jsxs)("span",{className:"text-base font-medium text-text-primary",children:["Assign task to ",A.name]})]}),(0,s.jsxs)("div",{className:"p-4 flex flex-col gap-4",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"block text-xs font-medium text-text-muted mb-1.5",children:"Task Title"}),(0,s.jsx)("input",{autoFocus:!0,type:"text",value:E,onChange:e=>W(e.target.value),placeholder:"What needs to be done?",className:"w-full px-3 py-2 text-sm bg-bg-tertiary border border-sidebar-border rounded-md text-text-primary placeholder:text-text-dim focus:outline-none focus:border-accent-cyan"})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"block text-xs font-medium text-text-muted mb-1.5",children:"Priority"}),(0,s.jsx)("div",{className:"flex gap-2",children:Object.keys(eY).map(e=>{let t=eY[e],r=M===e;return(0,s.jsx)("button",{type:"button",className:"px-3 py-1.5 text-xs font-medium rounded-md border transition-all ".concat(r?"border-transparent text-white":"border-sidebar-border text-text-muted hover:border-sidebar-hover"),style:{backgroundColor:r?t.color:"transparent"},onClick:()=>D(e),children:t.label},e)})}),(0,s.jsxs)("p",{className:"text-xs text-text-dim mt-1.5",children:["Maps to beads priority P",eY[M].beadsPriority]})]}),(0,s.jsxs)("div",{className:"flex justify-end gap-2 pt-2 border-t border-sidebar-border",children:[(0,s.jsx)("button",{type:"button",className:"px-4 py-2 text-sm text-text-muted hover:text-text-primary transition-colors",onClick:()=>{S("task-select-agent"),g("")},children:"Back"}),(0,s.jsx)("button",{type:"button",disabled:!E.trim()||T,onClick:I,className:"px-4 py-2 text-sm font-medium bg-accent-cyan text-bg-deep rounded-md hover:bg-accent-cyan/90 transition-colors disabled:opacity-50 disabled:cursor-not-allowed flex items-center gap-2",children:T?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(e9,{}),"Creating..."]}):(0,s.jsxs)(s.Fragment,{children:["Create Task",(0,s.jsx)("kbd",{className:"bg-black/20 rounded px-1 py-0.5 text-[10px]",children:"⌘↵"})]})})]})]})]})})}return(0,s.jsx)("div",{className:"fixed inset-0 bg-black/60 flex items-start justify-center pt-[15vh] z-[1000] animate-fade-in",onClick:t,children:(0,s.jsxs)("div",{className:"bg-sidebar-bg border border-sidebar-border rounded-xl w-[560px] max-w-[90vw] max-h-[60vh] flex flex-col shadow-modal animate-slide-down",onClick:e=>e.stopPropagation(),children:[(0,s.jsxs)("div",{className:"flex items-center gap-3 p-4 border-b border-sidebar-border",children:[(0,s.jsx)(eQ,{}),j&&(0,s.jsxs)("button",{onClick:()=>{y(null),f(0)},className:"flex items-center gap-1 px-2 py-0.5 text-xs font-medium bg-accent-cyan/20 text-accent-cyan rounded-md hover:bg-accent-cyan/30 transition-colors",children:[H[j],(0,s.jsx)("span",{className:"text-accent-cyan/60",children:"\xd7"})]}),(0,s.jsx)("input",{ref:w,autoFocus:!0,type:"text",className:"flex-1 border-none text-base font-sans outline-none bg-transparent text-text-primary placeholder:text-text-muted",placeholder:j?"Search ".concat(H[j].toLowerCase(),"..."):"Search commands, agents...",value:p,onChange:e=>g(e.target.value)}),(0,s.jsx)("kbd",{className:"bg-sidebar-border border border-sidebar-hover rounded px-1.5 py-0.5 text-xs text-text-muted font-sans",title:"Cycle categories",children:"Tab"}),(0,s.jsx)("kbd",{className:"bg-sidebar-border border border-sidebar-hover rounded px-1.5 py-0.5 text-xs text-text-muted font-sans",children:"ESC"})]}),(0,s.jsx)("div",{className:"flex-1 overflow-y-auto p-2",ref:N,children:0===z.length?(0,s.jsxs)("div",{className:"py-8 text-center text-text-muted text-sm",children:['No results for "',p,'"']}):eX.map(e=>{let t=O[e];return(null==t?void 0:t.length)?(0,s.jsxs)("div",{className:"mb-2",children:[(0,s.jsx)("div",{className:"text-xs font-semibold text-text-muted uppercase tracking-wider py-2 px-3",children:H[e]||e}),t.map(e=>{let t=V++;return(0,s.jsxs)("button",{ref:e=>{k.current[t]=e},className:"\n flex items-center gap-3 w-full py-2.5 px-3 border-none rounded-lg cursor-pointer text-left font-sans transition-colors duration-100\n ".concat(t===b?"bg-accent-light border border-accent/30":"bg-transparent hover:bg-sidebar-border","\n "),onClick:e.action,onMouseEnter:()=>f(t),children:[(0,s.jsx)("span",{className:"flex items-center justify-center w-7 h-7 text-text-muted",children:e.icon}),(0,s.jsxs)("span",{className:"flex-1 min-w-0 flex flex-col gap-0.5",children:[(0,s.jsx)("span",{className:"text-sm font-medium text-text-primary",children:e.label}),e.description&&(0,s.jsx)("span",{className:"text-xs text-text-muted truncate",children:e.description})]}),e.shortcut&&(0,s.jsx)("kbd",{className:"bg-sidebar-border border border-sidebar-hover rounded px-1.5 py-0.5 text-xs text-text-muted font-sans",children:e.shortcut})]},e.id)})]},e):null})})]})})}function eZ(e){let{name:t}=e,r=(0,a.GW)(t);return(0,s.jsx)("div",{className:"w-7 h-7 rounded-md flex items-center justify-center text-xs font-semibold",style:{backgroundColor:r.primary,color:r.text},children:(0,a.hP)(t)})}function eQ(){return(0,s.jsxs)("svg",{className:"text-text-muted shrink-0",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,s.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]})}function e0(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,s.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function e1(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"2"}),(0,s.jsx)("path",{d:"M16.24 7.76a6 6 0 0 1 0 8.49m-8.48-.01a6 6 0 0 1 0-8.49m11.31-2.82a10 10 0 0 1 0 14.14m-14.14 0a10 10 0 0 1 0-14.14"})]})}function e2(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"4",y1:"9",x2:"20",y2:"9"}),(0,s.jsx)("line",{x1:"4",y1:"15",x2:"20",y2:"15"}),(0,s.jsx)("line",{x1:"10",y1:"3",x2:"8",y2:"21"}),(0,s.jsx)("line",{x1:"16",y1:"3",x2:"14",y2:"21"})]})}function e5(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"3"}),(0,s.jsx)("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"})]})}function e4(){return(0,s.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.jsx)("path",{d:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"})})}function e3(){return(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-accent-cyan",children:(0,s.jsx)("path",{d:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"})}),(0,s.jsx)("svg",{className:"absolute -bottom-0.5 -right-0.5 text-accent-cyan bg-sidebar-bg rounded-full",width:"10",height:"10",viewBox:"0 0 24 24",fill:"currentColor",children:(0,s.jsx)("path",{d:"M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"})})]})}function e6(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-text-muted",children:[(0,s.jsx)("path",{d:"M9 11l3 3L22 4"}),(0,s.jsx)("path",{d:"M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"})]})}function e8(){return(0,s.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.jsx)("polyline",{points:"15 18 9 12 15 6"})})}function e9(){return(0,s.jsx)("svg",{className:"animate-spin",width:"14",height:"14",viewBox:"0 0 24 24",children:(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeDasharray:"32",strokeLinecap:"round"})})}let e7=[{id:"claude",name:"Claude",command:"claude",description:"Claude Code CLI agent",icon:"\uD83E\uDD16"},{id:"codex",name:"Codex",command:"codex",description:"OpenAI Codex agent",icon:"⚡"},{id:"gemini",name:"Gemini",command:"gemini",description:"Google Gemini CLI agent",icon:"\uD83D\uDC8E"},{id:"opencode",name:"OpenCode",command:"opencode",description:"OpenCode AI agent",icon:"\uD83D\uDD37"},{id:"droid",name:"Droid",command:"droid",description:"Factory Droid agent",icon:"\uD83E\uDD16"},{id:"custom",name:"Custom",command:"",description:"Custom command",icon:"\uD83D\uDD27"}];function te(e){let{isOpen:t,onClose:r,onSpawn:o,existingAgents:i,isSpawning:l=!1,error:c}=e,[d,x]=(0,n.useState)(e7[0]),[u,m]=(0,n.useState)(""),[h,p]=(0,n.useState)(""),[g,b]=(0,n.useState)(""),[f,j]=(0,n.useState)(""),[y,v]=(0,n.useState)(!1),[w,N]=(0,n.useState)(""),[k,C]=(0,n.useState)(""),[S,A]=(0,n.useState)(["EXPLICIT_ASK"]),[L,E]=(0,n.useState)(null),W=(0,n.useRef)(null),M="custom"===d.id?h:d.command,D=(0,n.useMemo)(()=>(function(e){let t=e.trim().split(" ")[0].toLowerCase();return t.startsWith("claude")||"codex"===t||"opencode"===t||"gemini"===t||"droid"===t?"subagent":"process"})(M),[M]),T=(0,n.useCallback)(()=>{let e="claude"===d.id?"claude":d.id,t=1;for(;i.includes("".concat(e,"-").concat(t));)t++;return"".concat(e,"-").concat(t)},[d,i]);(0,n.useEffect)(()=>{t&&(x(e7[0]),m(""),p(""),b(""),j(""),v(!1),N(""),C(""),A(["EXPLICIT_ASK"]),E(null),setTimeout(()=>{var e;return null===(e=W.current)||void 0===e?void 0:e.focus()},100))},[t]);let R=(0,n.useCallback)(e=>e.trim()?/^[a-zA-Z][a-zA-Z0-9-]*$/.test(e)?i.includes(e)?"An agent with this name already exists":null:"Name must start with a letter and contain only letters, numbers, and hyphens":"Name is required",[i]),P=async e=>{e.preventDefault();let t=u.trim()||T(),s=R(t);if(s){E(s);return}if(!M.trim()){E("Command is required");return}if(y&&!w){E("Please select an agent to shadow");return}E(null),await o({name:t,command:M.trim(),cwd:g.trim()||void 0,team:f.trim()||void 0,shadowMode:D,shadowOf:y?w:void 0,shadowAgent:k.trim()||void 0,shadowTriggers:y?S:void 0,shadowSpeakOn:y?S:void 0})&&r()};if(!t)return null;let B=u?(0,a.GW)(u):(0,a.GW)(T()),_=c||L;return(0,s.jsx)("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-[1000] animate-fade-in",onClick:r,children:(0,s.jsxs)("div",{className:"bg-bg-primary border border-border rounded-xl w-[480px] max-w-[90vw] max-h-[90vh] overflow-y-auto shadow-modal animate-slide-up",onClick:e=>e.stopPropagation(),onKeyDown:e=>{"Escape"===e.key&&(e.preventDefault(),r())},children:[(0,s.jsxs)("div",{className:"flex items-center justify-between p-5 border-b border-border",children:[(0,s.jsx)("h2",{className:"m-0 text-lg font-semibold text-text-primary",children:"Spawn New Agent"}),(0,s.jsx)("button",{className:"flex items-center justify-center w-8 h-8 bg-transparent border-none rounded-md text-text-muted cursor-pointer transition-all duration-150 hover:bg-bg-hover hover:text-text-primary",onClick:r,"aria-label":"Close",children:(0,s.jsx)(tt,{})})]}),(0,s.jsxs)("form",{onSubmit:P,className:"p-6",children:[(0,s.jsxs)("div",{className:"mb-5",children:[(0,s.jsx)("label",{className:"block text-sm font-semibold text-text-primary mb-2",children:"Agent Type"}),(0,s.jsx)("div",{className:"grid grid-cols-3 gap-2",children:e7.map(e=>(0,s.jsxs)("button",{type:"button",className:"\n flex flex-col items-center gap-1 py-3 px-2 border-2 rounded-lg cursor-pointer font-sans transition-all duration-150\n ".concat(d.id===e.id?"bg-accent/10 border-accent":"bg-bg-hover border-transparent hover:bg-bg-active","\n "),onClick:()=>x(e),children:[(0,s.jsx)("span",{className:"text-2xl",children:e.icon}),(0,s.jsx)("span",{className:"text-sm font-semibold text-text-primary",children:e.name}),(0,s.jsx)("span",{className:"text-xs text-text-muted text-center",children:e.description})]},e.id))})]}),(0,s.jsxs)("div",{className:"mb-5",children:[(0,s.jsx)("label",{className:"block text-sm font-semibold text-text-primary mb-2",htmlFor:"agent-name",children:"Agent Name"}),(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsx)("div",{className:"shrink-0 w-10 h-10 rounded-lg flex items-center justify-center text-sm font-semibold",style:{backgroundColor:B.primary,color:B.text},children:(0,a.hP)(u||T())}),(0,s.jsx)("input",{ref:W,id:"agent-name",type:"text",className:"flex-1 py-2.5 px-3.5 border border-border rounded-md text-sm font-sans outline-none bg-transparent text-text-primary transition-colors duration-150 focus:border-accent disabled:bg-bg-hover disabled:text-text-muted placeholder:text-text-muted",placeholder:T(),value:u,onChange:e=>{m(e.target.value),E(null)},disabled:l})]})]}),(0,s.jsxs)("div",{className:"mb-5",children:[(0,s.jsxs)("label",{className:"block text-sm font-semibold text-text-primary mb-2",htmlFor:"agent-team",children:["Team ",(0,s.jsx)("span",{className:"font-normal text-text-muted",children:"(optional)"})]}),(0,s.jsx)("input",{id:"agent-team",type:"text",className:"w-full py-2.5 px-3.5 border border-border rounded-md text-sm font-sans outline-none bg-transparent text-text-primary transition-colors duration-150 focus:border-accent disabled:bg-bg-hover disabled:text-text-muted placeholder:text-text-muted",placeholder:"e.g., frontend, backend, infra",value:f,onChange:e=>j(e.target.value),disabled:l})]}),"custom"===d.id&&(0,s.jsxs)("div",{className:"mb-5",children:[(0,s.jsx)("label",{className:"block text-sm font-semibold text-text-primary mb-2",htmlFor:"agent-command",children:"Command"}),(0,s.jsx)("input",{id:"agent-command",type:"text",className:"w-full py-2.5 px-3.5 border border-border rounded-md text-sm font-sans outline-none bg-transparent text-text-primary transition-colors duration-150 focus:border-accent disabled:bg-bg-hover disabled:text-text-muted placeholder:text-text-muted",placeholder:"e.g., python agent.py",value:h,onChange:e=>p(e.target.value),disabled:l})]}),(0,s.jsxs)("div",{className:"mb-5",children:[(0,s.jsxs)("label",{className:"block text-sm font-semibold text-text-primary mb-2",htmlFor:"agent-cwd",children:["Working Directory ",(0,s.jsx)("span",{className:"font-normal text-text-muted",children:"(optional)"})]}),(0,s.jsx)("input",{id:"agent-cwd",type:"text",className:"w-full py-2.5 px-3.5 border border-border rounded-md text-sm font-sans outline-none bg-transparent text-text-primary transition-colors duration-150 focus:border-accent disabled:bg-bg-hover disabled:text-text-muted placeholder:text-text-muted",placeholder:"Current directory",value:g,onChange:e=>b(e.target.value),disabled:l})]}),(0,s.jsxs)("div",{className:"mb-5 p-4 border border-border rounded-lg bg-bg-hover/50",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"block text-sm font-semibold text-text-primary",children:"Shadow Mode"}),(0,s.jsxs)("span",{className:"text-xs text-text-muted",children:["Shadow execution: ","subagent"===D?"Subagent (in-process)":"Process (separate)"]})]}),(0,s.jsx)("button",{type:"button",className:"\n relative w-11 h-6 rounded-full transition-colors duration-200\n ".concat(y?"bg-accent":"bg-bg-active","\n "),onClick:()=>v(!y),disabled:l,"aria-pressed":y,children:(0,s.jsx)("span",{className:"\n absolute top-0.5 left-0.5 w-5 h-5 bg-white rounded-full transition-transform duration-200 shadow-sm\n ".concat(y?"translate-x-5":"translate-x-0","\n ")})})]}),y&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:"mb-4",children:[(0,s.jsx)("label",{className:"block text-sm font-medium text-text-secondary mb-2",htmlFor:"shadow-of",children:"Shadow Agent"}),(0,s.jsxs)("select",{id:"shadow-of",className:"w-full py-2.5 px-3.5 border border-border rounded-md text-sm font-sans outline-none bg-bg-primary text-text-primary transition-colors duration-150 focus:border-accent disabled:bg-bg-hover disabled:text-text-muted",value:w,onChange:e=>N(e.target.value),disabled:l,children:[(0,s.jsx)("option",{value:"",children:"Select an agent to shadow..."}),i.map(e=>(0,s.jsx)("option",{value:e,children:e},e))]})]}),(0,s.jsxs)("div",{className:"mb-4",children:[(0,s.jsxs)("label",{className:"block text-sm font-medium text-text-secondary mb-2",htmlFor:"shadow-agent",children:["Shadow Agent Profile ",(0,s.jsx)("span",{className:"font-normal text-text-muted",children:"(optional)"})]}),(0,s.jsx)("input",{id:"shadow-agent",type:"text",className:"w-full py-2.5 px-3.5 border border-border rounded-md text-sm font-sans outline-none bg-bg-primary text-text-primary transition-colors duration-150 focus:border-accent disabled:bg-bg-hover disabled:text-text-muted placeholder:text-text-muted",placeholder:"e.g., shadow-reviewer",value:k,onChange:e=>C(e.target.value),disabled:l})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"block text-sm font-medium text-text-secondary mb-2",children:"Speak When"}),(0,s.jsx)("div",{className:"flex flex-wrap gap-2",children:[{value:"EXPLICIT_ASK",label:"Explicit Ask",description:"When directly asked"},{value:"SESSION_END",label:"Session End",description:"When session ends"},{value:"CODE_WRITTEN",label:"Code Written",description:"When code is written"},{value:"REVIEW_REQUEST",label:"Review Request",description:"When review requested"},{value:"ALL_MESSAGES",label:"All Messages",description:"On every message"}].map(e=>(0,s.jsx)("button",{type:"button",className:"\n py-1.5 px-3 rounded-md text-xs font-medium transition-all duration-150 border\n ".concat(S.includes(e.value)?"bg-accent/20 border-accent text-accent":"bg-bg-primary border-border text-text-secondary hover:bg-bg-active hover:text-text-primary","\n "),onClick:()=>{S.includes(e.value)?A(S.filter(t=>t!==e.value)):A([...S,e.value])},disabled:l,title:e.description,children:e.label},e.value))})]})]})]}),_&&(0,s.jsxs)("div",{className:"flex items-center gap-2 p-3 bg-error/10 border border-error/30 rounded-md text-error text-sm mb-5",children:[(0,s.jsx)(tr,{}),(0,s.jsx)("span",{children:_})]}),(0,s.jsxs)("div",{className:"flex justify-end gap-2 pt-2 border-t border-border",children:[(0,s.jsx)("button",{type:"button",className:"flex items-center gap-1.5 py-2.5 px-4 border-none rounded-md text-sm font-medium cursor-pointer font-sans transition-all duration-150 bg-bg-hover text-text-secondary hover:bg-bg-active hover:text-text-primary disabled:opacity-50 disabled:cursor-not-allowed",onClick:r,disabled:l,children:"Cancel"}),(0,s.jsx)("button",{type:"submit",className:"flex items-center gap-1.5 py-2.5 px-4 border-none rounded-md text-sm font-medium cursor-pointer font-sans transition-all duration-150 bg-accent text-white hover:bg-accent-hover disabled:opacity-50 disabled:cursor-not-allowed",disabled:l,children:l?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(tn,{}),"Spawning..."]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(ts,{}),"Spawn Agent"]})})]})]})]})})}function tt(){return(0,s.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function tr(){return(0,s.jsxs)("svg",{className:"shrink-0",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,s.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),(0,s.jsx)("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]})}function ts(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("path",{d:"M4.5 16.5c-1.5 1.26-2 5-2 5s3.74-.5 5-2c.71-.84.7-2.13-.09-2.91a2.18 2.18 0 0 0-2.91-.09z"}),(0,s.jsx)("path",{d:"m12 15-3-3a22 22 0 0 1 2-3.95A12.88 12.88 0 0 1 22 2c0 2.72-.78 7.5-6 11a22.35 22.35 0 0 1-4 2z"}),(0,s.jsx)("path",{d:"M9 12H4s.55-3.03 2-4c1.62-1.08 5 0 5 0"}),(0,s.jsx)("path",{d:"M12 15v5s3.03-.55 4-2c1.08-1.62 0-5 0-5"})]})}function tn(){return(0,s.jsx)("svg",{className:"animate-spin",width:"16",height:"16",viewBox:"0 0 24 24",children:(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeDasharray:"32",strokeLinecap:"round"})})}function ta(e){let{isOpen:t,onClose:r,onSend:o,agents:i,isSending:l=!1,error:c,preselectedAgent:d}=e,[x,u]=(0,n.useState)(""),[m,h]=(0,n.useState)(""),[p,g]=(0,n.useState)(""),[b,f]=(0,n.useState)(null),j=(0,n.useRef)(null),y=(0,n.useRef)(null),v=(0,n.useMemo)(()=>{if(!p.trim())return i;let e=p.toLowerCase();return i.filter(t=>{var r,s;return t.name.toLowerCase().includes(e)||(null===(r=t.role)||void 0===r?void 0:r.toLowerCase().includes(e))||(null===(s=t.team)||void 0===s?void 0:s.toLowerCase().includes(e))})},[i,p]);(0,n.useEffect)(()=>{t&&(u(d||""),h(""),g(""),f(null),setTimeout(()=>{var e,t;d?null===(e=j.current)||void 0===e||e.focus():null===(t=y.current)||void 0===t||t.focus()},100))},[t,d]);let w=async e=>{if(e.preventDefault(),!x){f("Please select an agent");return}if(!m.trim()){f("Please enter a message");return}f(null),await o(x,m.trim())&&r()},N=(0,n.useCallback)(e=>{u(e),f(null),setTimeout(()=>{var e;return null===(e=j.current)||void 0===e?void 0:e.focus()},50)},[]);if(!t)return null;let k=c||b,C=i.find(e=>e.name===x),S=C?(0,a.GW)(C.name):null;return(0,s.jsx)("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-[1000] animate-fade-in",onClick:r,children:(0,s.jsxs)("div",{className:"bg-bg-primary border border-border rounded-xl w-[520px] max-w-[90vw] max-h-[85vh] overflow-hidden shadow-modal animate-slide-up flex flex-col",onClick:e=>e.stopPropagation(),onKeyDown:e=>{"Escape"===e.key&&(e.preventDefault(),r())},children:[(0,s.jsxs)("div",{className:"flex items-center justify-between p-5 border-b border-border shrink-0",children:[(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsx)("div",{className:"w-9 h-9 rounded-lg bg-accent/10 flex items-center justify-center",children:(0,s.jsx)(to,{})}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h2",{className:"m-0 text-lg font-semibold text-text-primary",children:"New Conversation"}),(0,s.jsx)("p",{className:"m-0 text-xs text-text-muted",children:"Start a direct message with an agent"})]})]}),(0,s.jsx)("button",{className:"flex items-center justify-center w-8 h-8 bg-transparent border-none rounded-md text-text-muted cursor-pointer transition-all duration-150 hover:bg-bg-hover hover:text-text-primary",onClick:r,"aria-label":"Close",children:(0,s.jsx)(ti,{})})]}),(0,s.jsxs)("form",{onSubmit:w,className:"flex flex-col flex-1 overflow-hidden",children:[(0,s.jsxs)("div",{className:"p-5 border-b border-border",children:[(0,s.jsx)("label",{className:"block text-sm font-semibold text-text-primary mb-2",children:"To"}),x?(0,s.jsxs)("div",{className:"flex items-center gap-3 p-3 bg-bg-hover rounded-lg",children:[(0,s.jsx)("div",{className:"shrink-0 w-10 h-10 rounded-lg flex items-center justify-center text-sm font-semibold",style:{backgroundColor:null==S?void 0:S.primary,color:null==S?void 0:S.text},children:(0,a.hP)(x)}),(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsx)("div",{className:"font-semibold text-text-primary",children:x}),(null==C?void 0:C.role)&&(0,s.jsx)("div",{className:"text-xs text-text-muted truncate",children:C.role})]}),(0,s.jsx)("button",{type:"button",className:"flex items-center justify-center w-8 h-8 bg-bg-active border-none rounded-md text-text-muted cursor-pointer transition-all duration-150 hover:bg-bg-tertiary hover:text-text-primary",onClick:()=>{u(""),setTimeout(()=>{var e;return null===(e=y.current)||void 0===e?void 0:e.focus()},50)},"aria-label":"Change agent",children:(0,s.jsx)(tc,{})})]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:"relative mb-3",children:[(0,s.jsx)("div",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-text-muted",children:(0,s.jsx)(tl,{})}),(0,s.jsx)("input",{ref:y,type:"text",className:"w-full py-2.5 pl-10 pr-3.5 border border-border rounded-md text-sm font-sans outline-none bg-transparent text-text-primary transition-colors duration-150 focus:border-accent placeholder:text-text-muted",placeholder:"Search agents...",value:p,onChange:e=>g(e.target.value)})]}),(0,s.jsx)("div",{className:"max-h-[200px] overflow-y-auto border border-border rounded-lg",children:0===v.length?(0,s.jsx)("div",{className:"p-4 text-center text-text-muted text-sm",children:p?"No agents found":"No agents available"}):(0,s.jsxs)("div",{className:"divide-y divide-border",children:[(0,s.jsxs)("button",{type:"button",className:"w-full flex items-center gap-3 p-3 bg-transparent border-none cursor-pointer transition-colors duration-150 hover:bg-bg-hover text-left",onClick:()=>N("*"),children:[(0,s.jsx)("div",{className:"shrink-0 w-9 h-9 rounded-lg bg-warning/20 flex items-center justify-center",children:(0,s.jsx)(td,{})}),(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsx)("div",{className:"font-semibold text-text-primary",children:"Everyone"}),(0,s.jsx)("div",{className:"text-xs text-text-muted",children:"Broadcast to all agents"})]})]}),v.map(e=>{let t=(0,a.GW)(e.name);return(0,s.jsxs)("button",{type:"button",className:"w-full flex items-center gap-3 p-3 bg-transparent border-none cursor-pointer transition-colors duration-150 hover:bg-bg-hover text-left",onClick:()=>N(e.name),children:[(0,s.jsx)("div",{className:"shrink-0 w-9 h-9 rounded-lg flex items-center justify-center text-xs font-semibold",style:{backgroundColor:t.primary,color:t.text},children:(0,a.hP)(e.name)}),(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:"font-semibold text-text-primary",children:e.name}),(0,s.jsx)("span",{className:"w-2 h-2 rounded-full ".concat("online"===e.status?"bg-success":"bg-text-muted")})]}),(e.role||e.team)&&(0,s.jsxs)("div",{className:"text-xs text-text-muted truncate",children:[e.role,e.role&&e.team&&" - ",e.team]})]})]},e.name)})]})})]})]}),(0,s.jsxs)("div",{className:"p-5 flex-1 overflow-hidden flex flex-col",children:[(0,s.jsx)("label",{className:"block text-sm font-semibold text-text-primary mb-2",htmlFor:"message",children:"Message"}),(0,s.jsx)("textarea",{ref:j,id:"message",className:"flex-1 min-h-[120px] w-full py-3 px-3.5 border border-border rounded-md text-sm font-sans outline-none bg-transparent text-text-primary transition-colors duration-150 focus:border-accent resize-none placeholder:text-text-muted",placeholder:"*"===x?"Write a message to all agents...":x?"Write a message to ".concat(x,"..."):"Select an agent first...",value:m,onChange:e=>{h(e.target.value),f(null)},disabled:l||!x})]}),k&&(0,s.jsxs)("div",{className:"flex items-center gap-2 mx-5 mb-4 p-3 bg-error/10 border border-error/30 rounded-md text-error text-sm",children:[(0,s.jsx)(tu,{}),(0,s.jsx)("span",{children:k})]}),(0,s.jsxs)("div",{className:"flex justify-end gap-2 p-5 pt-0 border-t border-border",children:[(0,s.jsx)("button",{type:"button",className:"flex items-center gap-1.5 py-2.5 px-4 border-none rounded-md text-sm font-medium cursor-pointer font-sans transition-all duration-150 bg-bg-hover text-text-secondary hover:bg-bg-active hover:text-text-primary disabled:opacity-50 disabled:cursor-not-allowed",onClick:r,disabled:l,children:"Cancel"}),(0,s.jsx)("button",{type:"submit",className:"flex items-center gap-1.5 py-2.5 px-4 border-none rounded-md text-sm font-medium cursor-pointer font-sans transition-all duration-150 bg-accent text-white hover:bg-accent-hover disabled:opacity-50 disabled:cursor-not-allowed",disabled:l||!x||!m.trim(),children:l?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(tm,{}),"Sending..."]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(tx,{}),"Send Message"]})})]})]})]})})}function to(){return(0,s.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-accent",children:[(0,s.jsx)("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"}),(0,s.jsx)("line",{x1:"9",y1:"10",x2:"15",y2:"10"})]})}function ti(){return(0,s.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function tl(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,s.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]})}function tc(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("polyline",{points:"1 4 1 10 7 10"}),(0,s.jsx)("path",{d:"M3.51 15a9 9 0 1 0 2.13-9.36L1 10"})]})}function td(){return(0,s.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-warning",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"2"}),(0,s.jsx)("path",{d:"M16.24 7.76a6 6 0 0 1 0 8.49m-8.48-.01a6 6 0 0 1 0-8.49m11.31-2.82a10 10 0 0 1 0 14.14m-14.14 0a10 10 0 0 1 0-14.14"})]})}function tx(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),(0,s.jsx)("polygon",{points:"22 2 15 22 11 13 2 9 22 2"})]})}function tu(){return(0,s.jsxs)("svg",{className:"shrink-0",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,s.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),(0,s.jsx)("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]})}function tm(){return(0,s.jsx)("svg",{className:"animate-spin",width:"16",height:"16",viewBox:"0 0 24 24",children:(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeDasharray:"32",strokeLinecap:"round"})})}let th={theme:"system",notifications:{enabled:!0,sound:!0,desktop:!1,mentionsOnly:!1},display:{compactMode:!1,showTimestamps:!0,showAvatars:!0,animationsEnabled:!0},connection:{autoReconnect:!0,reconnectDelay:3e3,keepAliveInterval:3e4}},tp=[{id:"anthropic",name:"Anthropic",displayName:"Claude",description:"Claude Code - recommended for code tasks",color:"#D97757",cliCommand:"claude",apiKeyUrl:"https://console.anthropic.com/settings/keys",apiKeyName:"API key",supportsOAuth:!0},{id:"openai",name:"OpenAI",displayName:"Codex",description:"Codex - OpenAI coding assistant",color:"#10A37F",cliCommand:"codex login",apiKeyUrl:"https://platform.openai.com/api-keys",apiKeyName:"API key",supportsOAuth:!0},{id:"google",name:"Google",displayName:"Gemini",description:"Gemini - Google AI coding assistant",color:"#4285F4",cliCommand:"gemini",apiKeyUrl:"https://aistudio.google.com/app/apikey",apiKeyName:"API key",supportsOAuth:!0},{id:"opencode",name:"OpenCode",displayName:"OpenCode",description:"OpenCode - AI coding assistant",color:"#00D4AA",cliCommand:"opencode",supportsOAuth:!0},{id:"droid",name:"Factory",displayName:"Droid",description:"Droid - Factory AI coding agent",color:"#6366F1",cliCommand:"droid",supportsOAuth:!0}];function tg(e){var t,r,a,o;let{isOpen:i,onClose:l,settings:c,onSettingsChange:d,onResetSettings:x,workspaceId:u,csrfToken:m}=e,[h,p]=(0,n.useState)("appearance"),[g,b]=(0,n.useState)({}),[f,j]=(0,n.useState)(null),[y,v]=(0,n.useState)(""),[w,N]=(0,n.useState)(null),[k,C]=(0,n.useState)(null),[S,A]=(0,n.useState)({}),[L,E]=(0,n.useState)({storeInRepo:!1,storageLocation:"",loading:!0,error:null});n.useEffect(()=>{i&&"trajectories"===h&&W()},[i,h]);let W=async()=>{try{E(e=>({...e,loading:!0,error:null}));let e=await fetch("/api/settings/trajectory");if(!e.ok)throw Error("Failed to load settings");let t=await e.json();E({storeInRepo:t.settings.storeInRepo,storageLocation:t.settings.storageLocation,loading:!1,error:null,documentation:t.documentation})}catch(e){E(t=>({...t,loading:!1,error:e instanceof Error?e.message:"Failed to load settings"}))}},M=async e=>{try{E(e=>({...e,loading:!0,error:null}));let t={"Content-Type":"application/json"};m&&(t["X-CSRF-Token"]=m);let r=await fetch("/api/settings/trajectory",{method:"PUT",credentials:"include",headers:t,body:JSON.stringify({storeInRepo:e})});if(!r.ok){let e=await r.json();throw Error(e.error||"Failed to update settings")}let s=await r.json();E(e=>({...e,storeInRepo:s.settings.storeInRepo,storageLocation:s.settings.storageLocation,loading:!1,error:null}))}catch(e){E(t=>({...t,loading:!1,error:e instanceof Error?e.message:"Failed to update settings"}))}},D=async e=>{N(null),j(e.id),C({providerId:e.id,sessionId:"",status:"starting"});try{let t={"Content-Type":"application/json"};m&&(t["X-CSRF-Token"]=m);let r=await fetch("/api/onboarding/cli/".concat(e.id,"/start"),{method:"POST",credentials:"include",headers:t}),s=await r.json();if(!r.ok)throw Error(s.error||"Failed to start authentication");if("success"===s.status||s.alreadyAuthenticated){b(t=>({...t,[e.id]:!0})),C(null),j(null);return}let n={providerId:e.id,sessionId:s.sessionId,authUrl:s.authUrl,status:s.status||"starting"};C(n),s.authUrl?(T(s.authUrl,e.displayName),R(e.id,s.sessionId)):"starting"===s.status&&R(e.id,s.sessionId)}catch(e){N(e instanceof Error?e.message:"Failed to start OAuth"),C(null),j(null)}},T=(e,t)=>{let r=window.screenX+(window.outerWidth-600)/2,s=window.screenY+(window.outerHeight-700)/2;window.open(e,"".concat(t," Login"),"width=".concat(600,",height=").concat(700,",left=").concat(r,",top=").concat(s,",popup=yes"))},R=async(e,t)=>{let r=0,s=async()=>{if(r>=60){N("Authentication timed out. Please try again."),C(null),j(null);return}try{let a=await fetch("/api/onboarding/cli/".concat(e,"/status/").concat(t),{credentials:"include"}),o=await a.json();if(!a.ok)throw Error(o.error||"Failed to check status");if("success"===o.status){await P(e,t);return}if("error"===o.status)throw Error(o.error||"Authentication failed");if("waiting_auth"===o.status&&o.authUrl&&!(null==k?void 0:k.authUrl)){var n;C(e=>e?{...e,authUrl:o.authUrl,status:"waiting_auth"}:null),T(o.authUrl,(null===(n=tp.find(t=>t.id===e))||void 0===n?void 0:n.displayName)||"Provider")}r++,setTimeout(s,5e3)}catch(e){N(e instanceof Error?e.message:"Auth check failed"),C(null),j(null)}};s()},P=async(e,t)=>{try{let r={"Content-Type":"application/json"};m&&(r["X-CSRF-Token"]=m);let s=await fetch("/api/onboarding/cli/".concat(e,"/complete/").concat(t),{method:"POST",credentials:"include",headers:r});if(!s.ok){let e=await s.json();throw Error(e.error||"Failed to complete authentication")}b(t=>({...t,[e]:!0})),C(null),j(null)}catch(e){N(e instanceof Error?e.message:"Failed to complete auth"),C(null),j(null)}},B=async()=>{if(null==k?void 0:k.sessionId)try{await fetch("/api/onboarding/cli/".concat(k.providerId,"/cancel/").concat(k.sessionId),{method:"POST",credentials:"include"})}catch(e){}C(null),j(null)},_=async e=>{if(!y.trim()){N("Please enter an API key");return}N(null),j(e.id);try{let t={"Content-Type":"application/json"};m&&(t["X-CSRF-Token"]=m);let r=await fetch("/api/onboarding/token/".concat(e.id),{method:"POST",credentials:"include",headers:t,body:JSON.stringify({token:y.trim()})});if(!r.ok){let e=await r.json();throw Error(e.error||"Failed to connect")}b(t=>({...t,[e.id]:!0})),v(""),j(null),A(t=>({...t,[e.id]:!1}))}catch(e){N(e instanceof Error?e.message:"Failed to connect"),j(null)}},I=(0,n.useCallback)((e,t,r)=>{let s=c[e];d({...c,[e]:{...s,[t]:r}})},[c,d]),F=(0,n.useCallback)(e=>{d({...c,theme:e})},[c,d]);return i?(0,s.jsx)("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-[1000] animate-fade-in",onClick:l,children:(0,s.jsxs)("div",{className:"bg-bg-secondary rounded-xl w-[500px] max-w-[90vw] max-h-[80vh] flex flex-col shadow-modal animate-slide-up",onClick:e=>e.stopPropagation(),children:[(0,s.jsxs)("div",{className:"flex items-center justify-between py-5 px-6 border-b border-border",children:[(0,s.jsx)("h2",{className:"m-0 text-lg font-semibold text-text-primary",children:"Settings"}),(0,s.jsx)("button",{className:"flex items-center justify-center w-8 h-8 bg-transparent border-none rounded-md text-text-secondary cursor-pointer transition-all duration-150 hover:bg-bg-hover hover:text-text-primary",onClick:l,children:(0,s.jsx)(tf,{})})]}),(0,s.jsxs)("div",{className:"flex gap-1 py-3 px-6 border-b border-border bg-bg-tertiary",children:[(0,s.jsxs)("button",{className:"flex items-center gap-1.5 py-2 px-3.5 bg-transparent border-none rounded-md text-[13px] cursor-pointer font-[inherit] transition-all duration-150 ".concat("appearance"===h?"bg-accent text-white":"text-text-secondary hover:bg-bg-hover hover:text-text-primary"),onClick:()=>p("appearance"),children:[(0,s.jsx)(tj,{}),"Appearance"]}),(0,s.jsxs)("button",{className:"flex items-center gap-1.5 py-2 px-3.5 bg-transparent border-none rounded-md text-[13px] cursor-pointer font-[inherit] transition-all duration-150 ".concat("notifications"===h?"bg-accent text-white":"text-text-secondary hover:bg-bg-hover hover:text-text-primary"),onClick:()=>p("notifications"),children:[(0,s.jsx)(ty,{}),"Notifications"]}),(0,s.jsxs)("button",{className:"flex items-center gap-1.5 py-2 px-3.5 bg-transparent border-none rounded-md text-[13px] cursor-pointer font-[inherit] transition-all duration-150 ".concat("connection"===h?"bg-accent text-white":"text-text-secondary hover:bg-bg-hover hover:text-text-primary"),onClick:()=>p("connection"),children:[(0,s.jsx)(tv,{}),"Connection"]}),(0,s.jsxs)("button",{className:"flex items-center gap-1.5 py-2 px-3.5 bg-transparent border-none rounded-md text-[13px] cursor-pointer font-[inherit] transition-all duration-150 ".concat("providers"===h?"bg-accent text-white":"text-text-secondary hover:bg-bg-hover hover:text-text-primary"),onClick:()=>p("providers"),children:[(0,s.jsx)(tC,{}),"Providers"]}),(0,s.jsxs)("button",{className:"flex items-center gap-1.5 py-2 px-3.5 bg-transparent border-none rounded-md text-[13px] cursor-pointer font-[inherit] transition-all duration-150 ".concat("trajectories"===h?"bg-accent text-white":"text-text-secondary hover:bg-bg-hover hover:text-text-primary"),onClick:()=>p("trajectories"),children:[(0,s.jsx)(tS,{}),"Trajectories"]})]}),(0,s.jsxs)("div",{className:"flex-1 overflow-y-auto p-6",children:["appearance"===h&&(0,s.jsxs)("div",{className:"flex flex-col gap-6",children:[(0,s.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,s.jsx)("label",{className:"text-xs font-semibold text-text-muted uppercase tracking-[0.5px]",children:"Theme"}),(0,s.jsx)("div",{className:"flex gap-2",children:["light","dark","system"].map(e=>(0,s.jsxs)("button",{className:"flex flex-col items-center gap-1.5 py-4 px-5 border-2 rounded-lg text-xs cursor-pointer font-[inherit] transition-all duration-150 flex-1 ".concat(c.theme===e?"bg-accent-light border-accent text-accent":"bg-bg-hover border-transparent text-text-secondary hover:bg-bg-active"),onClick:()=>F(e),children:["light"===e&&(0,s.jsx)(tw,{}),"dark"===e&&(0,s.jsx)(tN,{}),"system"===e&&(0,s.jsx)(tk,{}),(0,s.jsx)("span",{children:e.charAt(0).toUpperCase()+e.slice(1)})]},e))})]}),(0,s.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,s.jsx)("label",{className:"text-xs font-semibold text-text-muted uppercase tracking-[0.5px]",children:"Display Options"}),(0,s.jsx)(tb,{label:"Compact mode",description:"Show more content in less space",checked:c.display.compactMode,onChange:e=>I("display","compactMode",e)}),(0,s.jsx)(tb,{label:"Show timestamps",description:"Display time for each message",checked:c.display.showTimestamps,onChange:e=>I("display","showTimestamps",e)}),(0,s.jsx)(tb,{label:"Show avatars",description:"Display agent avatars in messages",checked:c.display.showAvatars,onChange:e=>I("display","showAvatars",e)}),(0,s.jsx)(tb,{label:"Enable animations",description:"Smooth transitions and effects",checked:c.display.animationsEnabled,onChange:e=>I("display","animationsEnabled",e)})]})]}),"notifications"===h&&(0,s.jsx)("div",{className:"flex flex-col gap-6",children:(0,s.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,s.jsx)("label",{className:"text-xs font-semibold text-text-muted uppercase tracking-[0.5px]",children:"Notification Preferences"}),(0,s.jsx)(tb,{label:"Enable notifications",description:"Receive alerts for new messages",checked:c.notifications.enabled,onChange:e=>I("notifications","enabled",e)}),(0,s.jsx)(tb,{label:"Sound alerts",description:"Play sound for new messages",checked:c.notifications.sound,onChange:e=>I("notifications","sound",e),disabled:!c.notifications.enabled}),(0,s.jsx)(tb,{label:"Desktop notifications",description:"Show system notifications",checked:c.notifications.desktop,onChange:e=>I("notifications","desktop",e),disabled:!c.notifications.enabled}),(0,s.jsx)(tb,{label:"Mentions only",description:"Only notify when mentioned",checked:c.notifications.mentionsOnly,onChange:e=>I("notifications","mentionsOnly",e),disabled:!c.notifications.enabled})]})}),"connection"===h&&(0,s.jsx)("div",{className:"flex flex-col gap-6",children:(0,s.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,s.jsx)("label",{className:"text-xs font-semibold text-text-muted uppercase tracking-[0.5px]",children:"Connection Settings"}),(0,s.jsx)(tb,{label:"Auto-reconnect",description:"Automatically reconnect on disconnect",checked:c.connection.autoReconnect,onChange:e=>I("connection","autoReconnect",e)}),(0,s.jsxs)("div",{className:"flex flex-col gap-1.5 p-3 bg-bg-hover rounded-lg",children:[(0,s.jsx)("label",{className:"text-sm font-medium text-text-primary",children:"Reconnect delay (ms)"}),(0,s.jsx)("input",{type:"number",className:"py-2 px-3 border border-border rounded-md text-sm font-[inherit] outline-none transition-colors duration-150 bg-bg-tertiary text-text-primary focus:border-accent disabled:bg-bg-hover disabled:text-text-muted",value:c.connection.reconnectDelay,onChange:e=>I("connection","reconnectDelay",parseInt(e.target.value)||3e3),min:1e3,max:3e4,step:1e3,disabled:!c.connection.autoReconnect})]}),(0,s.jsxs)("div",{className:"flex flex-col gap-1.5 p-3 bg-bg-hover rounded-lg",children:[(0,s.jsx)("label",{className:"text-sm font-medium text-text-primary",children:"Keep-alive interval (ms)"}),(0,s.jsx)("input",{type:"number",className:"py-2 px-3 border border-border rounded-md text-sm font-[inherit] outline-none transition-colors duration-150 bg-bg-tertiary text-text-primary focus:border-accent disabled:bg-bg-hover disabled:text-text-muted",value:c.connection.keepAliveInterval,onChange:e=>I("connection","keepAliveInterval",parseInt(e.target.value)||3e4),min:5e3,max:12e4,step:5e3})]})]})}),"providers"===h&&(0,s.jsx)("div",{className:"flex flex-col gap-6",children:(0,s.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,s.jsx)("label",{className:"text-xs font-semibold text-text-muted uppercase tracking-[0.5px]",children:"AI Providers"}),(0,s.jsx)("p",{className:"text-sm text-text-secondary",children:"Connect AI providers to spawn agents. API keys are stored securely."}),w&&(0,s.jsx)("div",{className:"p-3 bg-red-500/10 border border-red-500/30 rounded-md text-red-400 text-sm",children:w}),(0,s.jsx)("div",{className:"flex flex-col gap-2",children:tp.map(e=>(0,s.jsxs)("div",{className:"p-4 bg-bg-hover rounded-lg border border-border",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsx)("div",{className:"w-10 h-10 rounded-lg flex items-center justify-center text-white font-bold text-sm",style:{backgroundColor:e.color},children:e.displayName[0]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h4",{className:"text-sm font-semibold text-text-primary",children:e.displayName}),(0,s.jsx)("p",{className:"text-xs text-text-muted",children:e.description})]})]}),g[e.id]&&(0,s.jsx)("span",{className:"px-2 py-1 bg-green-500/20 text-green-400 text-xs rounded-full",children:"Connected"})]}),!g[e.id]&&(0,s.jsx)("div",{className:"mt-3",children:(null==k?void 0:k.providerId)===e.id?(0,s.jsxs)("div",{className:"space-y-3",children:["starting"===k.status&&(0,s.jsxs)("div",{className:"flex items-center gap-2 text-sm text-text-secondary",children:[(0,s.jsx)("span",{className:"animate-spin",children:"⏳"}),"Starting authentication..."]}),"waiting_auth"===k.status&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:"flex items-center gap-2 text-sm text-text-secondary",children:[(0,s.jsx)("span",{className:"animate-pulse",children:"\uD83D\uDD10"}),"Complete login in the popup window"]}),k.authUrl&&(0,s.jsxs)("div",{className:"text-xs text-text-muted",children:["Popup didn't open?"," ",(0,s.jsx)("button",{onClick:()=>T(k.authUrl,e.displayName),className:"text-accent hover:underline",children:"Click here"})]})]}),(0,s.jsx)("button",{onClick:B,className:"text-sm text-text-muted hover:text-text-secondary",children:"Cancel"})]}):S[e.id]?(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsx)("input",{type:"password",placeholder:"Enter ".concat(e.displayName," ").concat(e.apiKeyName||"API key"),value:f===e.id?y:"",onChange:t=>{j(e.id),v(t.target.value)},onFocus:()=>j(e.id),className:"flex-1 py-2 px-3 border border-border rounded-md text-sm bg-bg-tertiary text-text-primary placeholder-text-muted focus:outline-none focus:border-accent"}),(0,s.jsx)("button",{onClick:()=>_(e),disabled:f!==e.id||!y.trim(),className:"px-4 py-2 bg-accent text-white text-sm font-medium rounded-md hover:bg-accent-hover disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:"Connect"})]}),e.apiKeyUrl&&(0,s.jsxs)("div",{className:"text-xs text-text-muted",children:["Get your API key from"," ",(0,s.jsx)("a",{href:e.apiKeyUrl,target:"_blank",rel:"noopener noreferrer",className:"text-accent hover:underline",children:new URL(e.apiKeyUrl).hostname})]}),(0,s.jsx)("button",{onClick:()=>A(t=>({...t,[e.id]:!1})),className:"text-xs text-text-muted hover:text-text-secondary",children:"← Back to OAuth login"})]}):(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsxs)("button",{onClick:()=>D(e),disabled:null!==f,className:"w-full py-2.5 px-4 bg-accent text-white text-sm font-medium rounded-md hover:bg-accent-hover disabled:opacity-50 disabled:cursor-not-allowed transition-colors flex items-center justify-center gap-2",children:[(0,s.jsx)("span",{children:"\uD83D\uDD10"}),"Connect with ",e.displayName]}),e.apiKeyUrl&&(0,s.jsx)("button",{onClick:()=>A(t=>({...t,[e.id]:!0})),className:"w-full text-xs text-text-muted hover:text-text-secondary",children:"Or enter API key manually"})]})}),(0,s.jsxs)("div",{className:"mt-2 text-xs text-text-dim",children:["CLI: ",(0,s.jsx)("code",{className:"px-1 py-0.5 bg-bg-tertiary rounded",children:e.cliCommand})]})]},e.id))})]})}),"trajectories"===h&&(0,s.jsx)("div",{className:"flex flex-col gap-6",children:L.loading?(0,s.jsx)("div",{className:"flex items-center justify-center py-8",children:(0,s.jsx)("div",{className:"text-text-muted",children:"Loading settings..."})}):L.error?(0,s.jsxs)("div",{className:"p-4 bg-red-500/10 border border-red-500/30 rounded-lg",children:[(0,s.jsx)("p",{className:"text-red-400 text-sm",children:L.error}),(0,s.jsx)("button",{className:"mt-2 text-sm text-accent hover:underline",onClick:W,children:"Retry"})]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:"p-4 bg-gradient-to-r from-accent/10 to-accent/5 border border-accent/20 rounded-lg",children:[(0,s.jsxs)("h3",{className:"text-base font-semibold text-text-primary mb-2 flex items-center gap-2",children:[(0,s.jsx)(tS,{}),"What are Trajectories?"]}),(0,s.jsx)("p",{className:"text-sm text-text-secondary mb-3",children:(null===(t=L.documentation)||void 0===t?void 0:t.description)||"Trajectories record the journey of agent work using the PDERO paradigm (Plan, Design, Execute, Review, Observe). They capture decisions, phase transitions, and retrospectives."}),(0,s.jsxs)("div",{className:"mb-3",children:[(0,s.jsx)("h4",{className:"text-xs font-semibold text-text-muted uppercase mb-2",children:"Benefits"}),(0,s.jsx)("ul",{className:"list-none p-0 m-0 space-y-1.5",children:((null===(r=L.documentation)||void 0===r?void 0:r.benefits)||["Track why decisions were made, not just what was built","Enable session recovery when agents crash","Provide learning data for future agents","Create audit trails of AI work"]).map((e,t)=>(0,s.jsxs)("li",{className:"flex items-start gap-2 text-sm text-text-secondary",children:[(0,s.jsx)("span",{className:"text-accent",children:"✓"}),e]},t))})]}),(0,s.jsxs)("a",{href:(null===(a=L.documentation)||void 0===a?void 0:a.learnMore)||"https://pdero.com",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-sm text-accent hover:underline",children:["Learn more about PDERO",(0,s.jsx)(tA,{})]})]}),(0,s.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,s.jsx)("label",{className:"text-xs font-semibold text-text-muted uppercase tracking-[0.5px]",children:"Storage Settings"}),(0,s.jsx)(tb,{label:"Store trajectories in repository",description:(null===(o=L.documentation)||void 0===o?void 0:o.storeInRepoExplanation)||"When enabled, trajectories are saved to .trajectories/ in your repo and can be committed to source control.",checked:L.storeInRepo,onChange:e=>M(e)}),(0,s.jsxs)("div",{className:"p-3 bg-bg-hover rounded-lg",children:[(0,s.jsx)("div",{className:"flex items-center gap-2 mb-1",children:(0,s.jsx)("span",{className:"text-sm font-medium text-text-primary",children:"Current storage location"})}),(0,s.jsx)("code",{className:"text-xs text-text-muted bg-bg-tertiary px-2 py-1 rounded",children:L.storageLocation||"user (~/.config/agent-relay/trajectories/)"})]})]}),(0,s.jsxs)("div",{className:"p-3 bg-bg-hover rounded-lg border border-border",children:[(0,s.jsx)("h4",{className:"text-sm font-medium text-text-primary mb-1",children:"Why opt-in to repo storage?"}),(0,s.jsx)("p",{className:"text-xs text-text-muted",children:"Teams who want to review agent decision-making processes can store trajectories in the repo to version control them alongside code. This makes it easy to understand why agents made specific choices during code review."})]})]})})]}),(0,s.jsxs)("div",{className:"flex items-center justify-between py-4 px-6 border-t border-border",children:[x&&(0,s.jsx)("button",{className:"py-2 px-4 bg-transparent border border-border rounded-md text-[13px] text-text-secondary cursor-pointer font-[inherit] transition-all duration-150 hover:bg-bg-hover hover:text-text-primary",onClick:x,children:"Reset to defaults"}),(0,s.jsx)("button",{className:"py-2 px-5 bg-accent border-none rounded-md text-[13px] font-medium text-white cursor-pointer font-[inherit] transition-colors duration-150 hover:bg-accent-hover",onClick:l,children:"Done"})]})]})}):null}function tb(e){let{label:t,description:r,checked:n,onChange:a,disabled:o}=e;return(0,s.jsxs)("div",{className:"flex items-center justify-between p-3 bg-bg-hover rounded-lg ".concat(o?"opacity-50":""),children:[(0,s.jsxs)("div",{className:"flex flex-col gap-0.5",children:[(0,s.jsx)("span",{className:"text-sm font-medium text-text-primary",children:t}),(0,s.jsx)("span",{className:"text-xs text-text-muted",children:r})]}),(0,s.jsx)("button",{className:"w-11 h-6 border-none rounded-xl cursor-pointer relative transition-colors duration-200 ".concat(n?"bg-accent":"bg-border-medium"," ").concat(o?"cursor-not-allowed":""),onClick:()=>!o&&a(!n),disabled:o,role:"switch","aria-checked":n,children:(0,s.jsx)("span",{className:"absolute top-0.5 left-0.5 w-5 h-5 bg-white rounded-full transition-transform duration-200 shadow-[0_1px_3px_rgba(0,0,0,0.2)] ".concat(n?"translate-x-5":"")})})]})}function tf(){return(0,s.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function tj(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"13.5",cy:"6.5",r:".5"}),(0,s.jsx)("circle",{cx:"17.5",cy:"10.5",r:".5"}),(0,s.jsx)("circle",{cx:"8.5",cy:"7.5",r:".5"}),(0,s.jsx)("circle",{cx:"6.5",cy:"12.5",r:".5"}),(0,s.jsx)("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.555C21.965 6.012 17.461 2 12 2z"})]})}function ty(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("path",{d:"M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9"}),(0,s.jsx)("path",{d:"M13.73 21a2 2 0 0 1-3.46 0"})]})}function tv(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("path",{d:"M5 12.55a11 11 0 0 1 14.08 0"}),(0,s.jsx)("path",{d:"M1.42 9a16 16 0 0 1 21.16 0"}),(0,s.jsx)("path",{d:"M8.53 16.11a6 6 0 0 1 6.95 0"}),(0,s.jsx)("line",{x1:"12",y1:"20",x2:"12.01",y2:"20"})]})}function tw(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"5"}),(0,s.jsx)("line",{x1:"12",y1:"1",x2:"12",y2:"3"}),(0,s.jsx)("line",{x1:"12",y1:"21",x2:"12",y2:"23"}),(0,s.jsx)("line",{x1:"4.22",y1:"4.22",x2:"5.64",y2:"5.64"}),(0,s.jsx)("line",{x1:"18.36",y1:"18.36",x2:"19.78",y2:"19.78"}),(0,s.jsx)("line",{x1:"1",y1:"12",x2:"3",y2:"12"}),(0,s.jsx)("line",{x1:"21",y1:"12",x2:"23",y2:"12"}),(0,s.jsx)("line",{x1:"4.22",y1:"19.78",x2:"5.64",y2:"18.36"}),(0,s.jsx)("line",{x1:"18.36",y1:"5.64",x2:"19.78",y2:"4.22"})]})}function tN(){return(0,s.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.jsx)("path",{d:"M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"})})}function tk(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2",ry:"2"}),(0,s.jsx)("line",{x1:"8",y1:"21",x2:"16",y2:"21"}),(0,s.jsx)("line",{x1:"12",y1:"17",x2:"12",y2:"21"})]})}function tC(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("path",{d:"M12 2L2 7l10 5 10-5-10-5z"}),(0,s.jsx)("path",{d:"M2 17l10 5 10-5"}),(0,s.jsx)("path",{d:"M2 12l10 5 10-5"})]})}function tS(){return(0,s.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.jsx)("path",{d:"M22 12h-4l-3 9L9 3l-3 9H2"})})}function tA(){return(0,s.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"}),(0,s.jsx)("polyline",{points:"15 3 21 3 21 9"}),(0,s.jsx)("line",{x1:"10",y1:"14",x2:"21",y2:"3"})]})}var tL=r(3083);function tE(e){let{workspaces:t=[],onWorkspaceCreated:r,onOpenWorkspace:a,csrfToken:o,className:i=""}=e,[l,c]=(0,n.useState)([]),[d,x]=(0,n.useState)("idle"),[u,m]=(0,n.useState)(null),[h,p]=(0,n.useState)(null),[g,b]=(0,n.useState)(""),[f,j]=(0,n.useState)("all"),y=new Map;t.forEach(e=>{e.repositoryFullName&&y.set(e.repositoryFullName,e)});let v=(0,n.useCallback)(async()=>{x("loading"),m(null);try{let e=await fetch("/api/repos/accessible?perPage=100",{credentials:"include"});if(!e.ok){let t=await e.json();if("NANGO_NOT_CONNECTED"===t.code)throw Error("GitHub not connected. Please reconnect your GitHub account.");throw Error(t.error||"Failed to fetch repositories")}let t=await e.json();c(t.repositories||[]),x("loaded")}catch(e){console.error("Error fetching accessible repos:",e),m(e instanceof Error?e.message:"Failed to load repositories"),x("error")}},[]);(0,n.useEffect)(()=>{v()},[v]);let w=(0,n.useCallback)(async e=>{p(e),m(null);try{let t={"Content-Type":"application/json"};o&&(t["X-CSRF-Token"]=o);let s=await fetch("/api/workspaces/quick",{method:"POST",credentials:"include",headers:t,body:JSON.stringify({repositoryFullName:e})}),n=await s.json();if(!s.ok)throw Error(n.error||"Failed to create workspace");null==r||r(n.workspaceId,e)}catch(e){console.error("Error creating workspace:",e),m(e instanceof Error?e.message:"Failed to create workspace")}finally{p(null)}},[o,r]),N=l.filter(e=>{if(g&&!e.fullName.toLowerCase().includes(g.toLowerCase()))return!1;let t=y.has(e.fullName);return("with-workspace"!==f||!!t)&&("without-workspace"!==f||!t)});return"loading"===d?(0,s.jsx)("div",{className:"flex items-center justify-center py-12 ".concat(i),children:(0,s.jsxs)("div",{className:"text-center",children:[(0,s.jsxs)("svg",{className:"w-8 h-8 text-accent-cyan animate-spin mx-auto",fill:"none",viewBox:"0 0 24 24",children:[(0,s.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,s.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),(0,s.jsx)("p",{className:"mt-4 text-text-muted",children:"Loading repositories..."})]})}):"error"===d?(0,s.jsx)("div",{className:"p-6 ".concat(i),children:(0,s.jsxs)("div",{className:"bg-error/10 border border-error/20 rounded-xl p-4 text-center",children:[(0,s.jsx)("div",{className:"w-12 h-12 mx-auto mb-3 bg-error/20 rounded-full flex items-center justify-center",children:(0,s.jsx)("svg",{className:"w-6 h-6 text-error",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,s.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})})}),(0,s.jsx)("p",{className:"text-error mb-4",children:u}),(0,s.jsx)("button",{onClick:v,className:"px-4 py-2 bg-bg-tertiary border border-border-subtle rounded-lg text-text-primary hover:bg-bg-hover transition-colors",children:"Try Again"})]})}):(0,s.jsxs)("div",{className:i,children:[(0,s.jsxs)("div",{className:"p-4 border-b border-border-subtle",children:[(0,s.jsx)("h2",{className:"text-lg font-semibold text-text-primary mb-1",children:"Repository Access"}),(0,s.jsx)("p",{className:"text-sm text-text-muted",children:"Repositories you have access to on GitHub. Create workspaces to enable dashboard and chat access."})]}),u&&(0,s.jsx)("div",{className:"mx-4 mt-4 p-3 bg-error/10 border border-error/20 rounded-lg",children:(0,s.jsx)("p",{className:"text-error text-sm",children:u})}),(0,s.jsx)("div",{className:"p-4 border-b border-border-subtle",children:(0,s.jsxs)("div",{className:"flex flex-col sm:flex-row gap-3",children:[(0,s.jsxs)("div",{className:"flex-1 relative",children:[(0,s.jsx)(tW,{className:"absolute left-3 top-1/2 -translate-y-1/2 text-text-muted"}),(0,s.jsx)("input",{type:"text",placeholder:"Search repositories...",value:g,onChange:e=>b(e.target.value),className:"w-full pl-10 pr-4 py-2 bg-bg-tertiary border border-border-subtle rounded-lg text-text-primary placeholder:text-text-muted focus:outline-none focus:border-accent-cyan/50 transition-colors"})]}),(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsxs)("button",{onClick:()=>j("all"),className:"px-3 py-2 text-sm rounded-lg border transition-colors ".concat("all"===f?"bg-accent-cyan/10 border-accent-cyan/30 text-accent-cyan":"bg-bg-tertiary border-border-subtle text-text-muted hover:text-text-primary"),children:["All (",l.length,")"]}),(0,s.jsx)("button",{onClick:()=>j("with-workspace"),className:"px-3 py-2 text-sm rounded-lg border transition-colors ".concat("with-workspace"===f?"bg-success/10 border-success/30 text-success":"bg-bg-tertiary border-border-subtle text-text-muted hover:text-text-primary"),children:"With Access"}),(0,s.jsx)("button",{onClick:()=>j("without-workspace"),className:"px-3 py-2 text-sm rounded-lg border transition-colors ".concat("without-workspace"===f?"bg-warning/10 border-warning/30 text-warning":"bg-bg-tertiary border-border-subtle text-text-muted hover:text-text-primary"),children:"No Access"})]})]})}),(0,s.jsx)("div",{className:"max-h-[500px] overflow-y-auto",children:0===N.length?(0,s.jsx)("div",{className:"py-12 text-center text-text-muted",children:g?(0,s.jsxs)("p",{children:['No repositories match "',g,'"']}):"all"!==f?(0,s.jsx)("p",{children:"No repositories in this category"}):(0,s.jsx)("p",{children:"No repositories found. Connect your GitHub account to see your repos."})}):(0,s.jsx)("div",{className:"divide-y divide-border-subtle",children:N.map(e=>{var t;let r=(t=e.permissions).admin?{level:"admin",label:"Admin",color:"text-accent-purple bg-accent-purple/10 border-accent-purple/30"}:t.push?{level:"write",label:"Write",color:"text-accent-cyan bg-accent-cyan/10 border-accent-cyan/30"}:{level:"read",label:"Read",color:"text-text-muted bg-bg-tertiary border-border-subtle"},n=y.get(e.fullName),o=h===e.fullName;return(0,s.jsxs)("div",{className:"flex items-center gap-4 p-4 hover:bg-bg-hover/50 transition-colors",children:[(0,s.jsx)("div",{className:"w-10 h-10 rounded-lg bg-bg-tertiary border border-border-subtle flex items-center justify-center flex-shrink-0",children:(0,s.jsx)(tM,{className:"text-text-muted"})}),(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2 mb-0.5",children:[(0,s.jsx)("p",{className:"font-medium text-text-primary truncate",children:e.fullName}),e.isPrivate&&(0,s.jsx)("span",{className:"px-1.5 py-0.5 text-xs bg-bg-tertiary border border-border-subtle rounded text-text-muted",children:"Private"})]}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:"px-2 py-0.5 text-xs rounded-full border ".concat(r.color),children:r.label}),(0,s.jsx)("span",{className:"text-xs text-text-muted",children:e.defaultBranch})]})]}),(0,s.jsx)("div",{className:"flex-shrink-0",children:n?(0,s.jsx)("button",{onClick:()=>null==a?void 0:a(n.id),className:"px-4 py-2 text-sm rounded-lg border transition-colors ".concat("running"===n.status?"bg-success/10 border-success/30 text-success hover:bg-success/20":"provisioning"===n.status?"bg-accent-cyan/10 border-accent-cyan/30 text-accent-cyan":"bg-bg-tertiary border-border-subtle text-text-muted hover:bg-bg-hover"),children:"running"===n.status?"Open Dashboard":"provisioning"===n.status?"Starting...":"stopped"===n.status?"Start":"View"}):(0,s.jsx)("button",{onClick:()=>w(e.fullName),disabled:o,className:"px-4 py-2 text-sm bg-gradient-to-r from-accent-cyan to-[#00b8d9] text-bg-deep font-medium rounded-lg hover:shadow-glow-cyan transition-all disabled:opacity-50 disabled:cursor-not-allowed",children:o?(0,s.jsxs)("span",{className:"flex items-center gap-2",children:[(0,s.jsxs)("svg",{className:"w-4 h-4 animate-spin",fill:"none",viewBox:"0 0 24 24",children:[(0,s.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,s.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),"Creating..."]}):"Enable Access"})})]},e.id)})})}),(0,s.jsx)("div",{className:"p-4 border-t border-border-subtle bg-bg-tertiary/50",children:(0,s.jsxs)("p",{className:"text-xs text-text-muted text-center",children:["Showing ",N.length," of ",l.length," repositories you have GitHub access to.",(0,s.jsx)("button",{onClick:v,className:"ml-2 text-accent-cyan hover:underline",children:"Refresh"})]})})]})}function tW(e){let{className:t=""}=e;return(0,s.jsxs)("svg",{className:t,width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,s.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]})}function tM(e){let{className:t=""}=e;return(0,s.jsx)("svg",{className:t,width:"18",height:"18",viewBox:"0 0 16 16",fill:"currentColor",children:(0,s.jsx)("path",{d:"M2 2.5A2.5 2.5 0 014.5 0h8.75a.75.75 0 01.75.75v12.5a.75.75 0 01-.75.75h-2.5a.75.75 0 110-1.5h1.75v-2h-8a1 1 0 00-.714 1.7.75.75 0 01-1.072 1.05A2.495 2.495 0 012 11.5v-9zm10.5-1V9h-8c-.356 0-.694.074-1 .208V2.5a1 1 0 011-1h8z"})})}let tD=[{id:"anthropic",name:"Anthropic",displayName:"Claude",description:"Claude Code - recommended for code tasks",color:"#D97757",cliCommand:"claude",apiKeyUrl:"https://console.anthropic.com/settings/keys",apiKeyName:"API key",supportsOAuth:!0},{id:"openai",name:"OpenAI",displayName:"Codex",description:"Codex - OpenAI coding assistant",color:"#10A37F",cliCommand:"codex login",apiKeyUrl:"https://platform.openai.com/api-keys",apiKeyName:"API key",supportsOAuth:!0,supportsDeviceFlow:!0},{id:"google",name:"Google",displayName:"Gemini",description:"Gemini - Google AI coding assistant",color:"#4285F4",cliCommand:"gemini",apiKeyUrl:"https://aistudio.google.com/app/apikey",apiKeyName:"API key",supportsOAuth:!0},{id:"opencode",name:"OpenCode",displayName:"OpenCode",description:"OpenCode - AI coding assistant",color:"#00D4AA",cliCommand:"opencode",supportsOAuth:!0},{id:"droid",name:"Factory",displayName:"Droid",description:"Droid - Factory AI coding agent",color:"#6366F1",cliCommand:"droid",supportsOAuth:!0}];function tT(e){var t;let{workspaceId:r,csrfToken:a,onClose:o}=e,[i,l]=(0,n.useState)(null),[c,d]=(0,n.useState)([]),[x,u]=(0,n.useState)(!0),[m,h]=(0,n.useState)(null),[p,g]=(0,n.useState)("general"),[b,f]=(0,n.useState)({}),[j,y]=(0,n.useState)(null),[v,w]=(0,n.useState)(""),[N,k]=(0,n.useState)(""),[C,S]=(0,n.useState)(null),[A,L]=(0,n.useState)(null),[E,W]=(0,n.useState)({}),M=(0,n.useRef)(null),[D,T]=(0,n.useState)({}),[R,P]=(0,n.useState)(""),[B,_]=(0,n.useState)(!1),[I,F]=(0,n.useState)(null),[U,O]=(0,n.useState)(null);(0,n.useEffect)(()=>{!async function(){u(!0),h(null);let[e,t]=await Promise.all([el.xv.getWorkspaceDetails(r),el.xv.getRepos()]);if(e.success){l(e.data),e.data.customDomain&&P(e.data.customDomain);let t={};e.data.config.providers.forEach(e=>{t[e]=!0}),f(t)}else h(e.error);t.success&&d(t.data.repositories),u(!1)}()},[r]);let z=async e=>{S(null),y(e.id),L({providerId:e.id,sessionId:"",status:"starting"}),M.current=null;try{let t={"Content-Type":"application/json"};a&&(t["X-CSRF-Token"]=a);let s=await fetch("/api/onboarding/cli/".concat(e.id,"/start"),{method:"POST",credentials:"include",headers:t,body:JSON.stringify({workspaceId:r,useDeviceFlow:D[e.id]||!1})}),n=await s.json();if(!s.ok)throw Error(n.error||"Failed to start authentication");if("success"===n.status||n.alreadyAuthenticated){f(t=>({...t,[e.id]:!0})),L(null),y(null);return}let o={providerId:e.id,sessionId:n.sessionId,authUrl:n.authUrl,status:n.authUrl?"waiting_auth":n.status||"starting"};L(o),n.authUrl?(M.current=n.sessionId,H(n.authUrl,e.displayName),V(e.id,n.sessionId)):"starting"===n.status&&V(e.id,n.sessionId)}catch(e){S(e instanceof Error?e.message:"Failed to start OAuth"),L(null),y(null)}},H=(e,t)=>{let r=window.screenX+(window.outerWidth-600)/2,s=window.screenY+(window.outerHeight-700)/2;window.open(e,"".concat(t," Login"),"width=".concat(600,",height=").concat(700,",left=").concat(r,",top=").concat(s,",popup=yes"))},V=async(e,t)=>{let r=0,s=async()=>{if(r>=60){S("Authentication timed out. Please try again."),L(null),y(null),M.current=null;return}try{let a=await fetch("/api/onboarding/cli/".concat(e,"/status/").concat(t),{credentials:"include"}),o=await a.json();if(!a.ok)throw Error(o.error||"Failed to check status");if("success"===o.status){await G(e,t);return}if("error"===o.status)throw Error(o.error||"Authentication failed");if("waiting_auth"===o.status&&o.authUrl&&M.current!==t){var n;M.current=t,L(e=>e?{...e,authUrl:o.authUrl,status:"waiting_auth"}:null),H(o.authUrl,(null===(n=tD.find(t=>t.id===e))||void 0===n?void 0:n.displayName)||"Provider")}r++,setTimeout(s,5e3)}catch(e){S(e instanceof Error?e.message:"Auth check failed"),L(null),y(null),M.current=null}};s()},G=async(e,t)=>{try{let r={"Content-Type":"application/json"};a&&(r["X-CSRF-Token"]=a);let s=await fetch("/api/onboarding/cli/".concat(e,"/complete/").concat(t),{method:"POST",credentials:"include",headers:r});if(!s.ok){let e=await s.json();throw Error(e.error||"Failed to complete authentication")}f(t=>({...t,[e]:!0})),L(null),y(null),M.current=null}catch(e){S(e instanceof Error?e.message:"Failed to complete auth"),L(null),y(null),M.current=null}},K=async e=>{if(!v.trim()){S("Please enter an API key");return}S(null),y(e.id);try{let t={"Content-Type":"application/json"};a&&(t["X-CSRF-Token"]=a);let r=await fetch("/api/onboarding/token/".concat(e.id),{method:"POST",credentials:"include",headers:t,body:JSON.stringify({token:v.trim()})});if(!r.ok){let e=await r.json();throw Error(e.error||"Failed to connect")}f(t=>({...t,[e.id]:!0})),w(""),y(null),W(t=>({...t,[e.id]:!1}))}catch(e){S(e instanceof Error?e.message:"Failed to connect"),y(null)}},J=(0,n.useCallback)(async()=>{if(!i||!window.confirm("Are you sure you want to restart this workspace?"))return;let e=await el.xv.restartWorkspace(i.id);if(e.success){let e=await el.xv.getWorkspaceDetails(r);e.success&&l(e.data)}else h(e.error)},[i,r]),X=(0,n.useCallback)(async()=>{if(!i||!window.confirm("Are you sure you want to stop this workspace?"))return;let e=await el.xv.stopWorkspace(i.id);if(e.success){let e=await el.xv.getWorkspaceDetails(r);e.success&&l(e.data)}else h(e.error)},[i,r]),Y=(0,n.useCallback)(async e=>{if(!i)return;let t=await el.xv.addReposToWorkspace(i.id,[e]);if(t.success){let e=await el.xv.getWorkspaceDetails(r);e.success&&l(e.data)}else h(t.error)},[i,r]),q=(0,n.useCallback)(async()=>{if(!i||!R.trim())return;_(!0),F(null),O(null);let e=await el.xv.setCustomDomain(i.id,R.trim());if(e.success){O(e.data.instructions);let t=await el.xv.getWorkspaceDetails(r);t.success&&l(t.data)}else F(e.error);_(!1)},[i,R,r]),$=(0,n.useCallback)(async()=>{if(!i)return;_(!0),F(null);let e=await el.xv.verifyCustomDomain(i.id);if(e.success){let t=await el.xv.getWorkspaceDetails(r);t.success&&l(t.data),"active"===e.data.status&&O(null)}else F(e.error);_(!1)},[i,r]),Z=(0,n.useCallback)(async()=>{if(!i||!window.confirm("Are you sure you want to remove the custom domain?"))return;_(!0);let e=await el.xv.removeCustomDomain(i.id);if(e.success){P(""),O(null);let e=await el.xv.getWorkspaceDetails(r);e.success&&l(e.data)}else F(e.error);_(!1)},[i,r]),Q=(0,n.useCallback)(async()=>{if(!i||!window.confirm('Are you sure you want to delete "'.concat(i.name,'"? This action cannot be undone.'))||!window.confirm("This will permanently delete all workspace data. Are you absolutely sure?"))return;let e=await el.xv.deleteWorkspace(i.id);e.success?window.location.href="/app/onboarding?reason=deleted":h(e.error)},[i]);if(x)return(0,s.jsxs)("div",{className:"flex items-center justify-center h-64",children:[(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsx)("div",{className:"w-12 h-12 rounded-full border-2 border-accent-cyan/20 border-t-accent-cyan animate-spin"}),(0,s.jsx)("div",{className:"absolute inset-0 flex items-center justify-center",children:(0,s.jsx)("div",{className:"w-4 h-4 rounded-full bg-accent-cyan/40 animate-pulse"})})]}),(0,s.jsx)("span",{className:"ml-4 text-text-muted font-mono text-sm tracking-wide",children:"LOADING WORKSPACE CONFIG..."})]});if(m&&!i)return(0,s.jsx)("div",{className:"p-6",children:(0,s.jsxs)("div",{className:"p-4 bg-error/10 border border-error/30 rounded-lg text-error flex items-center gap-3",children:[(0,s.jsx)(tV,{}),(0,s.jsx)("span",{children:m})]})});if(!i)return null;let ee=c.filter(e=>!i.repositories.some(t=>t.id===e.id)),et=[{id:"general",label:"General",icon:(0,s.jsx)(tF,{})},{id:"providers",label:"AI Providers",icon:(0,s.jsx)(tU,{})},{id:"repos",label:"Repositories",icon:(0,s.jsx)(tO,{})},{id:"github-access",label:"GitHub Access",icon:(0,s.jsx)(tH,{})},{id:"domain",label:"Domain",icon:(0,s.jsx)(tz,{})},{id:"danger",label:"Danger",icon:(0,s.jsx)(tV,{})}];return(0,s.jsxs)("div",{className:"flex flex-col h-full bg-bg-primary",children:[(0,s.jsx)("div",{className:"flex gap-1 p-3 border-b border-border-subtle bg-gradient-to-b from-bg-tertiary to-bg-primary",children:et.map(e=>(0,s.jsxs)("button",{onClick:()=>g(e.id),className:"flex items-center gap-2 px-4 py-2.5 rounded-lg text-sm font-medium transition-all duration-200 ".concat(p===e.id?"bg-accent-cyan/15 text-accent-cyan border border-accent-cyan/30 shadow-[0_0_12px_rgba(0,217,255,0.15)]":"text-text-secondary hover:bg-bg-hover hover:text-text-primary border border-transparent"),children:[(0,s.jsx)("span",{className:p===e.id?"text-accent-cyan":"text-text-muted",children:e.icon}),e.label]},e.id))}),(0,s.jsxs)("div",{className:"flex-1 overflow-y-auto p-6",children:[m&&(0,s.jsxs)("div",{className:"mb-6 p-4 bg-error/10 border border-error/30 rounded-lg text-error text-sm flex items-center gap-3",children:[(0,s.jsx)(tV,{}),(0,s.jsx)("span",{className:"flex-1",children:m}),(0,s.jsx)("button",{onClick:()=>h(null),className:"text-error/60 hover:text-error",children:(0,s.jsx)(tq,{})})]}),"general"===p&&(0,s.jsxs)("div",{className:"space-y-8",children:[(0,s.jsx)(tR,{title:"Workspace Overview",subtitle:"Core configuration and status"}),(0,s.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,s.jsx)(tP,{label:"Name",value:i.name}),(0,s.jsx)(tP,{label:"Status",value:i.status.charAt(0).toUpperCase()+i.status.slice(1),valueColor:"running"===i.status?"text-success":"stopped"===i.status?"text-amber-400":"error"===i.status?"text-error":"text-text-muted",indicator:"running"===i.status}),(0,s.jsx)(tP,{label:"Public URL",value:i.publicUrl||"Not available",mono:!0}),(0,s.jsx)(tP,{label:"Compute Provider",value:i.computeProvider.charAt(0).toUpperCase()+i.computeProvider.slice(1)})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)(tR,{title:"Actions",subtitle:"Manage workspace state"}),(0,s.jsxs)("div",{className:"flex gap-3 mt-4",children:["running"===i.status&&(0,s.jsx)(tB,{onClick:X,variant:"warning",icon:(0,s.jsx)(tK,{}),children:"Stop Workspace"}),(0,s.jsx)(tB,{onClick:J,variant:"primary",icon:(0,s.jsx)(tJ,{}),children:"Restart Workspace"})]})]})]}),"providers"===p&&(0,s.jsxs)("div",{className:"space-y-8",children:[(0,s.jsx)(tR,{title:"AI Providers",subtitle:"Connect AI providers to spawn agents in this workspace"}),C&&(0,s.jsxs)("div",{className:"p-4 bg-error/10 border border-error/30 rounded-lg text-error text-sm flex items-center gap-3",children:[(0,s.jsx)(tV,{}),(0,s.jsx)("span",{children:C})]}),(0,s.jsx)("div",{className:"space-y-4",children:tD.map(e=>(0,s.jsxs)("div",{className:"p-5 bg-bg-tertiary rounded-xl border border-border-subtle hover:border-border-medium transition-all duration-200",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsxs)("div",{className:"flex items-center gap-4",children:[(0,s.jsx)("div",{className:"w-12 h-12 rounded-xl flex items-center justify-center text-white font-bold text-lg shadow-lg",style:{backgroundColor:e.color,boxShadow:"0 4px 20px ".concat(e.color,"40")},children:e.displayName[0]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h4",{className:"text-base font-semibold text-text-primary",children:e.displayName}),(0,s.jsx)("p",{className:"text-sm text-text-muted",children:e.description})]})]}),b[e.id]?(0,s.jsxs)("div",{className:"flex items-center gap-2 px-4 py-2 bg-success/15 rounded-full border border-success/30",children:[(0,s.jsx)("div",{className:"w-2 h-2 rounded-full bg-success animate-pulse"}),(0,s.jsx)("span",{className:"text-sm font-medium text-success",children:"Connected"})]}):null]}),!b[e.id]&&(0,s.jsx)("div",{className:"mt-5 pt-5 border-t border-border-subtle",children:j===e.id?(0,s.jsx)(tL.j,{provider:{id:e.id,name:e.name,displayName:e.displayName,color:e.color,requiresUrlCopy:"openai"===e.id},workspaceId:r,csrfToken:a,useDeviceFlow:D[e.id]||!1,onSuccess:()=>{f(t=>({...t,[e.id]:!0})),y(null),L(null)},onCancel:()=>{y(null),L(null)},onError:e=>{S(e),y(null),L(null)}}):E[e.id]?(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsxs)("div",{className:"flex gap-3",children:[(0,s.jsx)("input",{type:"password",placeholder:"Enter ".concat(e.displayName," ").concat(e.apiKeyName||"API key"),value:j===e.id?v:"",onChange:t=>{y(e.id),w(t.target.value)},onFocus:()=>y(e.id),className:"flex-1 px-4 py-3 bg-bg-card border border-border-subtle rounded-lg text-sm text-text-primary placeholder:text-text-muted focus:outline-none focus:border-accent-cyan focus:ring-1 focus:ring-accent-cyan/30 transition-all"}),(0,s.jsx)("button",{onClick:()=>K(e),disabled:j!==e.id||!v.trim(),className:"px-5 py-3 bg-accent-cyan text-bg-deep font-semibold rounded-lg text-sm hover:bg-accent-cyan/90 disabled:opacity-50 disabled:cursor-not-allowed transition-all",children:"Connect"})]}),e.apiKeyUrl&&(0,s.jsxs)("p",{className:"text-xs text-text-muted",children:["Get your API key from"," ",(0,s.jsx)("a",{href:e.apiKeyUrl,target:"_blank",rel:"noopener noreferrer",className:"text-accent-cyan hover:underline",children:new URL(e.apiKeyUrl).hostname})]}),e.supportsOAuth&&(0,s.jsx)("button",{onClick:()=>W(t=>({...t,[e.id]:!1})),className:"text-xs text-text-muted hover:text-text-secondary transition-colors",children:"← Back to OAuth login"})]}):e.supportsOAuth?(0,s.jsxs)("div",{className:"space-y-3",children:[e.supportsDeviceFlow&&(0,s.jsxs)("label",{className:"flex items-center gap-2 text-xs text-text-secondary cursor-pointer",children:[(0,s.jsx)("input",{type:"checkbox",checked:D[e.id]||!1,onChange:t=>T(r=>({...r,[e.id]:t.target.checked})),className:"w-4 h-4 rounded border-border-subtle bg-bg-card text-accent-cyan focus:ring-accent-cyan/30 cursor-pointer"}),"Use device flow (easier for containers/headless)"]}),(0,s.jsxs)("button",{onClick:()=>z(e),disabled:null!==j,className:"w-full py-3 px-4 bg-gradient-to-r from-accent-cyan to-[#00b8d9] text-bg-deep font-semibold rounded-lg text-sm hover:shadow-glow-cyan hover:-translate-y-0.5 disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:translate-y-0 disabled:hover:shadow-none transition-all duration-200 flex items-center justify-center gap-2",children:[(0,s.jsx)(tG,{}),"Connect with ",e.displayName]}),e.apiKeyUrl&&(0,s.jsx)("button",{onClick:()=>W(t=>({...t,[e.id]:!0})),className:"w-full text-xs text-text-muted hover:text-text-secondary transition-colors",children:"Or enter API key manually"})]}):(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsxs)("div",{className:"flex gap-3",children:[(0,s.jsx)("input",{type:"password",placeholder:"Enter ".concat(e.displayName," ").concat(e.apiKeyName||"API key"),value:j===e.id?v:"",onChange:t=>{y(e.id),w(t.target.value)},onFocus:()=>y(e.id),className:"flex-1 px-4 py-3 bg-bg-card border border-border-subtle rounded-lg text-sm text-text-primary placeholder:text-text-muted focus:outline-none focus:border-accent-cyan focus:ring-1 focus:ring-accent-cyan/30 transition-all"}),(0,s.jsx)("button",{onClick:()=>K(e),disabled:j!==e.id||!v.trim(),className:"px-5 py-3 bg-accent-cyan text-bg-deep font-semibold rounded-lg text-sm hover:bg-accent-cyan/90 disabled:opacity-50 disabled:cursor-not-allowed transition-all",children:"Connect"})]}),e.apiKeyUrl&&(0,s.jsxs)("p",{className:"text-xs text-text-muted",children:["Get your API key from"," ",(0,s.jsx)("a",{href:e.apiKeyUrl,target:"_blank",rel:"noopener noreferrer",className:"text-accent-cyan hover:underline",children:new URL(e.apiKeyUrl).hostname})]}),(0,s.jsxs)("p",{className:"text-xs text-amber-400/80",children:["OAuth not available for ",e.displayName," in container environments"]})]})}),(0,s.jsx)("div",{className:"mt-4 pt-4 border-t border-border-subtle",children:(0,s.jsxs)("p",{className:"text-xs text-text-muted",children:["CLI: ",(0,s.jsx)("code",{className:"px-2 py-1 bg-bg-card rounded font-mono",children:e.cliCommand})]})})]},e.id))})]}),"repos"===p&&(0,s.jsxs)("div",{className:"space-y-8",children:[(0,s.jsx)(tR,{title:"Connected Repositories",subtitle:"Repositories linked to this workspace"}),(0,s.jsx)("div",{className:"space-y-3",children:i.repositories.length>0?i.repositories.map(e=>(0,s.jsxs)("div",{className:"flex items-center justify-between p-4 bg-bg-tertiary rounded-lg border border-border-subtle",children:[(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsx)("div",{className:"w-10 h-10 rounded-lg bg-bg-card flex items-center justify-center",children:(0,s.jsx)(tO,{})}),(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"text-sm font-medium text-text-primary",children:e.fullName}),(0,s.jsx)("p",{className:"text-xs text-text-muted",children:e.lastSyncedAt?"Synced ".concat(new Date(e.lastSyncedAt).toLocaleDateString()):"Not synced"})]})]}),(0,s.jsx)(t_,{status:e.syncStatus})]},e.id)):(0,s.jsxs)("div",{className:"p-6 bg-bg-tertiary rounded-lg border border-border-subtle border-dashed text-center",children:[(0,s.jsx)(tO,{className:"w-8 h-8 mx-auto mb-3 text-text-muted"}),(0,s.jsx)("p",{className:"text-sm text-text-muted",children:"No repositories connected"})]})}),ee.length>0&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(tR,{title:"Available Repositories",subtitle:"Add more repositories to this workspace"}),(0,s.jsx)("div",{className:"space-y-3",children:ee.map(e=>(0,s.jsxs)("div",{className:"flex items-center justify-between p-4 bg-bg-tertiary rounded-lg border border-border-subtle hover:border-accent-cyan/30 transition-colors",children:[(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsx)("div",{className:"w-10 h-10 rounded-lg bg-bg-card flex items-center justify-center",children:(0,s.jsx)(tO,{})}),(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"text-sm font-medium text-text-primary",children:e.fullName}),(0,s.jsx)("p",{className:"text-xs text-text-muted",children:e.isPrivate?"Private":"Public"})]})]}),(0,s.jsx)("button",{onClick:()=>Y(e.id),className:"px-4 py-2 bg-accent-cyan/10 border border-accent-cyan/30 text-accent-cyan rounded-lg text-xs font-semibold hover:bg-accent-cyan/20 transition-colors",children:"Add to Workspace"})]},e.id))})]})]}),"github-access"===p&&(0,s.jsxs)("div",{className:"space-y-6",children:[(0,s.jsx)(tR,{title:"GitHub Repository Access",subtitle:"Repositories you have access to via your GitHub account"}),(0,s.jsx)(tE,{workspaces:i&&(null===(t=i.repositories)||void 0===t?void 0:t.length)>0?[{id:i.id,name:i.name,repositoryFullName:i.repositories[0].fullName,status:i.status}]:[],onWorkspaceCreated:(e,t)=>{el.xv.getWorkspaceDetails(e).then(e=>{e.success&&l(e.data)})},onOpenWorkspace:e=>{o&&o()},csrfToken:a,className:"bg-bg-tertiary rounded-xl border border-border-subtle overflow-hidden"})]}),"domain"===p&&(0,s.jsxs)("div",{className:"space-y-8",children:[(0,s.jsx)(tR,{title:"Custom Domain",subtitle:"Connect your own domain to this workspace"}),(0,s.jsx)("div",{className:"p-5 bg-gradient-to-r from-accent-purple/10 to-accent-cyan/10 border border-accent-purple/20 rounded-xl",children:(0,s.jsxs)("div",{className:"flex items-center gap-3 mb-3",children:[(0,s.jsx)("div",{className:"w-10 h-10 rounded-lg bg-accent-purple/20 flex items-center justify-center",children:(0,s.jsx)(tz,{className:"text-accent-purple"})}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h4",{className:"text-sm font-semibold text-text-primary",children:"Premium Feature"}),(0,s.jsx)("p",{className:"text-xs text-text-secondary",children:"Requires Team or Enterprise plan"})]})]})}),i.customDomain?(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsxs)("div",{className:"p-5 bg-bg-tertiary rounded-xl border border-border-subtle",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,s.jsx)("span",{className:"text-xs text-text-muted uppercase tracking-wide font-semibold",children:"Current Domain"}),(0,s.jsx)(t_,{status:i.customDomainStatus||"pending"})]}),(0,s.jsx)("p",{className:"text-lg font-mono text-text-primary",children:i.customDomain})]}),"pending"===i.customDomainStatus&&(0,s.jsx)(tB,{onClick:$,disabled:B,variant:"primary",icon:(0,s.jsx)(tX,{}),fullWidth:!0,children:B?"Verifying...":"Verify DNS Configuration"}),(0,s.jsx)(tB,{onClick:Z,disabled:B,variant:"danger",icon:(0,s.jsx)(tY,{}),fullWidth:!0,children:"Remove Custom Domain"})]}):(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-xs font-semibold text-text-muted uppercase tracking-wide mb-2 block",children:"Domain Name"}),(0,s.jsx)("input",{type:"text",value:R,onChange:e=>P(e.target.value),placeholder:"workspace.yourdomain.com",className:"w-full px-4 py-3 bg-bg-tertiary border border-border-subtle rounded-lg text-sm text-text-primary font-mono placeholder:text-text-muted focus:outline-none focus:border-accent-cyan focus:ring-1 focus:ring-accent-cyan/30 transition-all"})]}),(0,s.jsx)(tB,{onClick:q,disabled:B||!R.trim(),variant:"primary",icon:(0,s.jsx)(tz,{}),fullWidth:!0,children:B?"Setting up...":"Set Custom Domain"})]}),I&&(0,s.jsx)("div",{className:"p-4 bg-error/10 border border-error/30 rounded-lg text-error text-sm",children:I}),U&&(0,s.jsxs)("div",{className:"p-5 bg-bg-tertiary rounded-xl border border-border-subtle space-y-4",children:[(0,s.jsxs)("h4",{className:"text-sm font-semibold text-text-primary flex items-center gap-2",children:[(0,s.jsx)(t$,{}),"DNS Configuration Required"]}),(0,s.jsx)("p",{className:"text-xs text-text-secondary",children:"Add the following DNS record to your domain provider:"}),(0,s.jsxs)("div",{className:"grid grid-cols-3 gap-3",children:[(0,s.jsx)(tI,{label:"Type",value:U.type}),(0,s.jsx)(tI,{label:"Name",value:U.name}),(0,s.jsx)(tI,{label:"Value",value:U.value})]})]})]}),"danger"===p&&(0,s.jsx)("div",{className:"space-y-8",children:(0,s.jsxs)("div",{className:"p-6 bg-error/5 border-2 border-error/20 rounded-xl",children:[(0,s.jsxs)("div",{className:"flex items-center gap-3 mb-4",children:[(0,s.jsx)("div",{className:"w-10 h-10 rounded-lg bg-error/20 flex items-center justify-center",children:(0,s.jsx)(tV,{className:"text-error"})}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h3",{className:"text-base font-semibold text-error",children:"Danger Zone"}),(0,s.jsx)("p",{className:"text-xs text-text-secondary",children:"These actions are destructive and cannot be undone"})]})]}),(0,s.jsx)("div",{className:"p-5 border border-error/30 rounded-lg bg-bg-primary",children:(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("h4",{className:"text-sm font-semibold text-text-primary",children:"Delete Workspace"}),(0,s.jsx)("p",{className:"text-xs text-text-muted mt-1",children:"Permanently delete this workspace and all its data"})]}),(0,s.jsx)("button",{onClick:Q,className:"px-5 py-2.5 bg-error text-white rounded-lg text-sm font-semibold hover:bg-error/90 transition-colors",children:"Delete Workspace"})]})})]})})]})]})}function tR(e){let{title:t,subtitle:r}=e;return(0,s.jsxs)("div",{className:"mb-4",children:[(0,s.jsx)("h3",{className:"text-sm font-semibold text-text-muted uppercase tracking-wide",children:t}),(0,s.jsx)("p",{className:"text-xs text-text-muted mt-1",children:r})]})}function tP(e){let{label:t,value:r,valueColor:n="text-text-primary",mono:a=!1,indicator:o=!1}=e;return(0,s.jsxs)("div",{className:"p-4 bg-bg-tertiary rounded-lg border border-border-subtle",children:[(0,s.jsx)("label",{className:"text-xs text-text-muted uppercase tracking-wide font-medium",children:t}),(0,s.jsxs)("div",{className:"flex items-center gap-2 mt-1",children:[o&&(0,s.jsx)("div",{className:"w-2 h-2 rounded-full bg-success animate-pulse"}),(0,s.jsx)("p",{className:"text-sm font-medium ".concat(n," ").concat(a?"font-mono":""," break-all"),children:r})]})]})}function tB(e){let{children:t,onClick:r,disabled:n,variant:a,icon:o,fullWidth:i}=e;return(0,s.jsxs)("button",{onClick:r,disabled:n,className:"".concat(i?"w-full":""," px-5 py-2.5 border rounded-lg text-sm font-semibold transition-all duration-200 disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-2 ").concat({primary:"bg-accent-cyan/10 border-accent-cyan/30 text-accent-cyan hover:bg-accent-cyan/20",warning:"bg-amber-400/10 border-amber-400/30 text-amber-400 hover:bg-amber-400/20",danger:"bg-error/10 border-error/30 text-error hover:bg-error/20"}[a]),children:[o,t]})}function t_(e){let{status:t}=e;return(0,s.jsx)("span",{className:"text-xs px-3 py-1 rounded-full border ".concat({synced:"bg-success/15 text-success border-success/30",active:"bg-success/15 text-success border-success/30",syncing:"bg-accent-cyan/15 text-accent-cyan border-accent-cyan/30",verifying:"bg-accent-cyan/15 text-accent-cyan border-accent-cyan/30",pending:"bg-amber-400/15 text-amber-400 border-amber-400/30",error:"bg-error/15 text-error border-error/30"}[t]||"bg-bg-hover text-text-muted border-border-subtle"),children:t})}function tI(e){let{label:t,value:r}=e;return(0,s.jsxs)("div",{className:"p-3 bg-bg-card rounded-lg",children:[(0,s.jsx)("label",{className:"text-xs text-text-muted block mb-1",children:t}),(0,s.jsx)("p",{className:"font-mono text-sm text-text-primary break-all",children:r})]})}function tF(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"3"}),(0,s.jsx)("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"})]})}function tU(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("path",{d:"M12 2L2 7l10 5 10-5-10-5z"}),(0,s.jsx)("path",{d:"M2 17l10 5 10-5"}),(0,s.jsx)("path",{d:"M2 12l10 5 10-5"})]})}function tO(e){let{className:t=""}=e;return(0,s.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-text-muted ".concat(t),children:(0,s.jsx)("path",{d:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"})})}function tz(e){let{className:t=""}=e;return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,s.jsx)("line",{x1:"2",y1:"12",x2:"22",y2:"12"}),(0,s.jsx)("path",{d:"M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z"})]})}function tH(){return(0,s.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"currentColor",children:(0,s.jsx)("path",{d:"M12 0C5.37 0 0 5.37 0 12c0 5.31 3.435 9.795 8.205 11.385.6.105.825-.255.825-.57 0-.285-.015-1.23-.015-2.235-3.015.555-3.795-.735-4.035-1.41-.135-.345-.72-1.41-1.23-1.695-.42-.225-1.02-.78-.015-.795.945-.015 1.62.87 1.845 1.23 1.08 1.815 2.805 1.305 3.495.99.105-.78.42-1.305.765-1.605-2.67-.3-5.46-1.335-5.46-5.925 0-1.305.465-2.385 1.23-3.225-.12-.3-.54-1.53.12-3.18 0 0 1.005-.315 3.3 1.23.96-.27 1.98-.405 3-.405s2.04.135 3 .405c2.295-1.56 3.3-1.23 3.3-1.23.66 1.65.24 2.88.12 3.18.765.84 1.23 1.905 1.23 3.225 0 4.605-2.805 5.625-5.475 5.925.435.375.81 1.095.81 2.22 0 1.605-.015 2.895-.015 3.3 0 .315.225.69.825.57A12.02 12.02 0 0024 12c0-6.63-5.37-12-12-12z"})})}function tV(e){let{className:t=""}=e;return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:[(0,s.jsx)("path",{d:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"}),(0,s.jsx)("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),(0,s.jsx)("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]})}function tG(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),(0,s.jsx)("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})}function tK(){return(0,s.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,s.jsx)("rect",{x:"6",y:"6",width:"12",height:"12"})})}function tJ(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("path",{d:"M23 4v6h-6"}),(0,s.jsx)("path",{d:"M20.49 15a9 9 0 1 1-2.12-9.36L23 10"})]})}function tX(){return(0,s.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,s.jsx)("polyline",{points:"20 6 9 17 4 12"})})}function tY(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,s.jsx)("path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"})]})}function tq(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function t$(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,s.jsx)("line",{x1:"12",y1:"16",x2:"12",y2:"12"}),(0,s.jsx)("line",{x1:"12",y1:"8",x2:"12.01",y2:"8"})]})}let tZ={owner:"bg-accent-purple/20 text-accent-purple",admin:"bg-accent-cyan/20 text-accent-cyan",member:"bg-success/20 text-success",viewer:"bg-bg-hover text-text-muted"},tQ={owner:"Full access, can delete workspace and transfer ownership",admin:"Can manage members, settings, and all workspace features",member:"Can use workspace, spawn agents, and send messages",viewer:"Read-only access to workspace activity"};function t0(e){var t;let{workspaceId:r,currentUserId:a}=e,[o,i]=(0,n.useState)([]),[l,c]=(0,n.useState)([]),[d,x]=(0,n.useState)(!0),[u,m]=(0,n.useState)(null),[h,p]=(0,n.useState)(null),[g,b]=(0,n.useState)(!1),[f,j]=(0,n.useState)(""),[y,v]=(0,n.useState)("member"),[w,N]=(0,n.useState)(!1),[k,C]=(0,n.useState)(null),[S,A]=(0,n.useState)(null);(0,n.useEffect)(()=>{!async function(){x(!0),m(null);let[e,t]=await Promise.all([el.xv.getWorkspaceMembers(r),el.xv.getPendingInvites()]);e.success?i(e.data.members):m(e.error),t.success&&c(t.data.invites.filter(e=>e.workspaceId===r)),x(!1)}()},[r]);let L=(0,n.useCallback)(async()=>{if(!f.trim()){C("Please enter a GitHub username");return}N(!0),C(null);let e=await el.xv.inviteMember(r,f.trim(),y);if(e.success){let e=await el.xv.getWorkspaceMembers(r);e.success&&i(e.data.members),j(""),b(!1),p("Invitation sent to ".concat(f)),setTimeout(()=>p(null),3e3)}else C(e.error);N(!1)},[r,f,y]),E=(0,n.useCallback)(async(e,t)=>{A(e);let s=await el.xv.updateMemberRole(r,e,t);s.success?(i(r=>r.map(r=>r.id===e?{...r,role:t}:r)),p("Role updated successfully"),setTimeout(()=>p(null),3e3)):m(s.error),A(null)},[r]),W=(0,n.useCallback)(async e=>{var t;if(!window.confirm("Are you sure you want to remove ".concat((null===(t=e.user)||void 0===t?void 0:t.githubUsername)||"this member"," from the workspace?")))return;let s=await el.xv.removeMember(r,e.id);s.success?(i(t=>t.filter(t=>t.id!==e.id)),p("Member removed successfully"),setTimeout(()=>p(null),3e3)):m(s.error)},[r]),M=null===(t=o.find(e=>e.userId===a))||void 0===t?void 0:t.role,D="owner"===M||"admin"===M;return d?(0,s.jsxs)("div",{className:"flex items-center justify-center h-64",children:[(0,s.jsx)(t1,{}),(0,s.jsx)("span",{className:"ml-3 text-text-muted",children:"Loading team members..."})]}):(0,s.jsxs)("div",{className:"space-y-6",children:[(0,s.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("h3",{className:"text-sm font-semibold text-text-muted uppercase tracking-wide",children:"Team Members"}),(0,s.jsxs)("p",{className:"text-xs text-text-muted mt-1",children:[o.length," member",1!==o.length?"s":""]})]}),D&&(0,s.jsxs)("button",{onClick:()=>b(!g),className:"px-3 md:px-4 py-2 bg-accent-cyan text-bg-deep rounded-lg text-xs md:text-sm font-medium hover:bg-accent-cyan/90 transition-colors flex items-center justify-center gap-2 w-full sm:w-auto",children:[(0,s.jsx)(t2,{}),"Invite Member"]})]}),u&&(0,s.jsxs)("div",{className:"p-3 bg-error/10 border border-error/30 rounded-lg text-error text-sm",children:[u,(0,s.jsx)("button",{onClick:()=>m(null),className:"ml-2 text-error/70 hover:text-error",children:"\xd7"})]}),h&&(0,s.jsx)("div",{className:"p-3 bg-success/10 border border-success/30 rounded-lg text-success text-sm",children:h}),g&&(0,s.jsxs)("div",{className:"p-4 bg-bg-tertiary rounded-lg border border-border-subtle space-y-4",children:[(0,s.jsx)("h4",{className:"text-sm font-medium text-text-primary",children:"Invite New Member"}),k&&(0,s.jsx)("div",{className:"p-2 bg-error/10 border border-error/30 rounded text-error text-xs",children:k}),(0,s.jsxs)("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-xs text-text-muted mb-1 block",children:"GitHub Username"}),(0,s.jsx)("input",{type:"text",value:f,onChange:e=>j(e.target.value),placeholder:"username",className:"w-full px-3 py-2 bg-bg-card border border-border-subtle rounded-lg text-sm text-text-primary placeholder:text-text-muted focus:outline-none focus:border-accent-cyan"})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-xs text-text-muted mb-1 block",children:"Role"}),(0,s.jsxs)("select",{value:y,onChange:e=>v(e.target.value),className:"w-full px-3 py-2 bg-bg-card border border-border-subtle rounded-lg text-sm text-text-primary focus:outline-none focus:border-accent-cyan",children:[(0,s.jsx)("option",{value:"admin",children:"Admin"}),(0,s.jsx)("option",{value:"member",children:"Member"}),(0,s.jsx)("option",{value:"viewer",children:"Viewer"})]})]})]}),(0,s.jsx)("p",{className:"text-xs text-text-muted",children:tQ[y]}),(0,s.jsxs)("div",{className:"flex flex-col sm:flex-row gap-2",children:[(0,s.jsx)("button",{onClick:L,disabled:w||!f.trim(),className:"px-4 py-2 bg-accent-cyan text-bg-deep rounded-lg text-sm font-medium hover:bg-accent-cyan/90 disabled:opacity-50 transition-colors",children:w?"Sending...":"Send Invitation"}),(0,s.jsx)("button",{onClick:()=>{b(!1),j(""),C(null)},className:"px-4 py-2 bg-bg-hover text-text-secondary rounded-lg text-sm font-medium hover:text-text-primary transition-colors",children:"Cancel"})]})]}),(0,s.jsx)("div",{className:"space-y-2",children:o.map(e=>{var t,r,n,o,i,l;return(0,s.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3 p-3 md:p-4 bg-bg-tertiary rounded-lg",children:[(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(null===(t=e.user)||void 0===t?void 0:t.avatarUrl)?(0,s.jsx)("img",{src:e.user.avatarUrl,alt:e.user.githubUsername,className:"w-9 h-9 md:w-10 md:h-10 rounded-full"}):(0,s.jsx)("div",{className:"w-9 h-9 md:w-10 md:h-10 rounded-full bg-accent-cyan/20 flex items-center justify-center text-accent-cyan font-bold text-xs md:text-sm",children:(null===(o=e.user)||void 0===o?void 0:null===(n=o.githubUsername)||void 0===n?void 0:null===(r=n[0])||void 0===r?void 0:r.toUpperCase())||"?"}),(0,s.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,s.jsx)("p",{className:"text-sm font-medium text-text-primary truncate",children:(null===(i=e.user)||void 0===i?void 0:i.githubUsername)||"Unknown User"}),e.isPending&&(0,s.jsx)("span",{className:"text-[10px] px-2 py-0.5 bg-amber-400/20 text-amber-400 rounded-full",children:"Pending"}),e.userId===a&&(0,s.jsx)("span",{className:"text-xs text-text-muted",children:"(you)"})]}),(null===(l=e.user)||void 0===l?void 0:l.email)&&(0,s.jsx)("p",{className:"text-xs text-text-muted truncate",children:e.user.email})]})]}),(0,s.jsxs)("div",{className:"flex items-center gap-2 sm:gap-3 ml-12 sm:ml-0",children:[D&&"owner"!==e.role&&e.userId!==a?(0,s.jsxs)("select",{value:e.role,onChange:t=>E(e.id,t.target.value),disabled:S===e.id,className:"px-2 md:px-3 py-1 md:py-1.5 rounded-full text-[10px] md:text-xs font-medium border-none cursor-pointer ".concat(tZ[e.role]," focus:outline-none"),children:[(0,s.jsx)("option",{value:"admin",children:"Admin"}),(0,s.jsx)("option",{value:"member",children:"Member"}),(0,s.jsx)("option",{value:"viewer",children:"Viewer"})]}):(0,s.jsx)("span",{className:"px-2 md:px-3 py-1 md:py-1.5 rounded-full text-[10px] md:text-xs font-medium ".concat(tZ[e.role]),children:e.role.charAt(0).toUpperCase()+e.role.slice(1)}),D&&"owner"!==e.role&&e.userId!==a&&(0,s.jsx)("button",{onClick:()=>W(e),className:"p-1.5 text-text-muted hover:text-error rounded transition-colors",title:"Remove member",children:(0,s.jsx)(t5,{})})]})]},e.id)})}),l.length>0&&(0,s.jsxs)("div",{className:"mt-8",children:[(0,s.jsx)("h3",{className:"text-sm font-semibold text-text-muted uppercase tracking-wide mb-4",children:"Your Pending Invitations"}),(0,s.jsx)("div",{className:"space-y-2",children:l.map(e=>(0,s.jsxs)("div",{className:"flex items-center justify-between p-4 bg-bg-tertiary rounded-lg border border-accent-cyan/30",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"text-sm font-medium text-text-primary",children:e.workspaceName}),(0,s.jsxs)("p",{className:"text-xs text-text-muted",children:["Invited by ",e.invitedBy," as ",e.role]})]}),(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsx)("button",{onClick:async()=>{(await el.xv.acceptInvite(e.id)).success&&(c(t=>t.filter(t=>t.id!==e.id)),p("Invitation accepted!"),setTimeout(()=>p(null),3e3))},className:"px-3 py-1.5 bg-success/20 text-success rounded text-xs font-medium hover:bg-success/30 transition-colors",children:"Accept"}),(0,s.jsx)("button",{onClick:async()=>{(await el.xv.declineInvite(e.id)).success&&c(t=>t.filter(t=>t.id!==e.id))},className:"px-3 py-1.5 bg-bg-hover text-text-muted rounded text-xs font-medium hover:text-text-primary transition-colors",children:"Decline"})]})]},e.id))})]}),(0,s.jsxs)("div",{className:"mt-8 p-4 bg-bg-tertiary/50 rounded-lg",children:[(0,s.jsx)("h4",{className:"text-xs font-semibold text-text-muted uppercase tracking-wide mb-3",children:"Role Permissions"}),(0,s.jsx)("div",{className:"space-y-2",children:Object.entries(tQ).map(e=>{let[t,r]=e;return(0,s.jsxs)("div",{className:"flex items-start gap-2",children:[(0,s.jsx)("span",{className:"px-2 py-0.5 rounded-full text-xs font-medium ".concat(tZ[t]," shrink-0"),children:t.charAt(0).toUpperCase()+t.slice(1)}),(0,s.jsx)("p",{className:"text-xs text-text-muted",children:r})]},t)})})]})]})}function t1(){return(0,s.jsx)("svg",{className:"animate-spin h-5 w-5 text-accent-cyan",viewBox:"0 0 24 24",children:(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeDasharray:"32",strokeLinecap:"round"})})}function t2(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,s.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function t5(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,s.jsx)("path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"})]})}let t4={free:"bg-bg-tertiary border-border-subtle text-text-muted",pro:"bg-accent-cyan/10 border-accent-cyan/30 text-accent-cyan",team:"bg-accent-purple/10 border-accent-purple/30 text-accent-purple",enterprise:"bg-amber-400/10 border-amber-400/30 text-amber-400"};function t3(e){let{onUpgrade:t}=e,[r,a]=(0,n.useState)([]),[o,i]=(0,n.useState)("free"),[l,c]=(0,n.useState)(null),[d,x]=(0,n.useState)([]),[u,m]=(0,n.useState)(!0),[h,p]=(0,n.useState)(null),[g,b]=(0,n.useState)(null),[f,j]=(0,n.useState)("month"),[y,v]=(0,n.useState)(null),[w,N]=(0,n.useState)(!1),[k,C]=(0,n.useState)(!1),[S,A]=(0,n.useState)(!1);(0,n.useEffect)(()=>{!async function(){m(!0),p(null);let[e,t,r]=await Promise.all([el.xv.getBillingPlans(),el.xv.getSubscription(),el.xv.getInvoices()]);if(e.success&&a(e.data.plans),t.success){var s;i(t.data.tier),c(t.data.subscription),(null===(s=t.data.subscription)||void 0===s?void 0:s.interval)&&j(t.data.subscription.interval)}r.success&&x(r.data.invoices),e.success||p(e.error),m(!1)}()},[]);let L=(0,n.useCallback)(async e=>{v(e);let t=await el.xv.createCheckoutSession(e,f);t.success&&t.data.checkoutUrl?window.location.href=t.data.checkoutUrl:t.success||(p(t.error),v(null))},[f]),E=(0,n.useCallback)(async()=>{N(!0);let e=await el.xv.createBillingPortal();e.success&&e.data.portalUrl?window.location.href=e.data.portalUrl:e.success||p(e.error),N(!1)},[]),W=(0,n.useCallback)(async()=>{if(!window.confirm("Are you sure you want to cancel your subscription? You will retain access until the end of your billing period."))return;C(!0);let e=await el.xv.cancelSubscription();e.success?(c(e=>e?{...e,cancelAtPeriodEnd:!0}:null),b(e.data.message),setTimeout(()=>b(null),5e3)):p(e.error),C(!1)},[]),M=(0,n.useCallback)(async()=>{A(!0);let e=await el.xv.resumeSubscription();e.success?(c(e=>e?{...e,cancelAtPeriodEnd:!1}:null),b(e.data.message),setTimeout(()=>b(null),3e3)):p(e.error),A(!1)},[]);return u?(0,s.jsxs)("div",{className:"flex items-center justify-center h-64",children:[(0,s.jsx)(t6,{}),(0,s.jsx)("span",{className:"ml-3 text-text-muted",children:"Loading billing information..."})]}):(0,s.jsxs)("div",{className:"space-y-8",children:[h&&(0,s.jsxs)("div",{className:"p-3 bg-error/10 border border-error/30 rounded-lg text-error text-sm",children:[h,(0,s.jsx)("button",{onClick:()=>p(null),className:"ml-2 text-error/70 hover:text-error",children:"\xd7"})]}),g&&(0,s.jsx)("div",{className:"p-3 bg-success/10 border border-success/30 rounded-lg text-success text-sm",children:g}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h3",{className:"text-sm font-semibold text-text-muted uppercase tracking-wide mb-4",children:"Current Plan"}),(0,s.jsx)("div",{className:"p-4 md:p-6 rounded-lg border-2 ".concat(t4[o]),children:(0,s.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4",children:[(0,s.jsxs)("div",{children:[(0,s.jsxs)("h4",{className:"text-lg md:text-xl font-bold text-text-primary capitalize",children:[o," Plan"]}),l?(0,s.jsx)("p",{className:"text-xs md:text-sm text-text-secondary mt-1",children:l.cancelAtPeriodEnd?(0,s.jsxs)("span",{className:"text-amber-400",children:["Cancels on ",new Date(l.currentPeriodEnd).toLocaleDateString()]}):(0,s.jsxs)(s.Fragment,{children:["Renews on ",new Date(l.currentPeriodEnd).toLocaleDateString(),(0,s.jsxs)("span",{className:"text-text-muted ml-2",children:["(","year"===l.interval?"Yearly":"Monthly",")"]})]})}):(0,s.jsx)("p",{className:"text-xs md:text-sm text-text-muted mt-1",children:"Free tier - upgrade to unlock more features"})]}),(0,s.jsxs)("div",{className:"flex flex-wrap gap-2",children:[l&&!l.cancelAtPeriodEnd&&(0,s.jsx)("button",{onClick:W,disabled:k,className:"px-3 md:px-4 py-2 bg-bg-hover text-text-secondary rounded-lg text-xs md:text-sm font-medium hover:text-text-primary disabled:opacity-50 transition-colors",children:k?"Canceling...":"Cancel Plan"}),(null==l?void 0:l.cancelAtPeriodEnd)&&(0,s.jsx)("button",{onClick:M,disabled:S,className:"px-3 md:px-4 py-2 bg-success/20 text-success rounded-lg text-xs md:text-sm font-medium hover:bg-success/30 disabled:opacity-50 transition-colors",children:S?"Resuming...":"Resume Plan"}),l&&(0,s.jsx)("button",{onClick:E,disabled:w,className:"px-3 md:px-4 py-2 bg-accent-cyan text-bg-deep rounded-lg text-xs md:text-sm font-medium hover:bg-accent-cyan/90 disabled:opacity-50 transition-colors",children:w?"Opening...":"Manage Billing"})]})]})})]}),(0,s.jsxs)("div",{className:"flex items-center justify-center gap-4",children:[(0,s.jsx)("span",{className:"text-sm font-medium ".concat("month"===f?"text-text-primary":"text-text-muted"),children:"Monthly"}),(0,s.jsx)("button",{onClick:()=>j(e=>"month"===e?"year":"month"),className:"relative w-14 h-7 bg-bg-tertiary rounded-full transition-colors",children:(0,s.jsx)("span",{className:"absolute top-1 w-5 h-5 bg-accent-cyan rounded-full transition-transform ".concat("year"===f?"translate-x-8":"translate-x-1")})}),(0,s.jsxs)("span",{className:"text-sm font-medium ".concat("year"===f?"text-text-primary":"text-text-muted"),children:["Yearly",(0,s.jsx)("span",{className:"ml-1 text-xs text-success",children:"(Save 20%)"})]})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h3",{className:"text-sm font-semibold text-text-muted uppercase tracking-wide mb-4",children:"Available Plans"}),(0,s.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4",children:r.filter(e=>"free"!==e.tier).map(e=>(0,s.jsxs)("div",{className:"relative p-6 rounded-lg border ".concat(e.recommended?"border-accent-cyan shadow-glow-cyan":"border-border-subtle"," bg-bg-tertiary"),children:[e.recommended&&(0,s.jsx)("div",{className:"absolute -top-3 left-1/2 -translate-x-1/2 px-3 py-1 bg-accent-cyan text-bg-deep text-xs font-bold rounded-full",children:"Most Popular"}),(0,s.jsx)("h4",{className:"text-lg font-bold text-text-primary",children:e.name}),(0,s.jsx)("p",{className:"text-xs text-text-muted mt-1 mb-4",children:e.description}),(0,s.jsxs)("div",{className:"mb-4",children:[(0,s.jsxs)("span",{className:"text-3xl font-bold text-text-primary",children:["$","year"===f?e.price.yearly:e.price.monthly]}),(0,s.jsxs)("span",{className:"text-text-muted",children:["/","year"===f?"year":"month"]})]}),(0,s.jsx)("ul",{className:"space-y-2 mb-6",children:e.features.slice(0,5).map((e,t)=>(0,s.jsxs)("li",{className:"flex items-start gap-2 text-sm text-text-secondary",children:[(0,s.jsx)(t8,{className:"text-success shrink-0 mt-0.5"}),e]},t))}),o===e.tier?(0,s.jsx)("button",{disabled:!0,className:"w-full py-2.5 bg-bg-hover text-text-muted rounded-lg text-sm font-medium cursor-default",children:"Current Plan"}):(0,s.jsx)("button",{onClick:()=>L(e.tier),disabled:null!==y,className:"w-full py-2.5 rounded-lg text-sm font-medium transition-colors disabled:opacity-50 ".concat(e.recommended?"bg-accent-cyan text-bg-deep hover:bg-accent-cyan/90":"bg-bg-hover text-text-primary hover:bg-bg-active"),children:y===e.tier?"Loading...":"free"===o?"Upgrade":"Switch"})]},e.tier))})]}),(0,s.jsx)("div",{className:"p-4 md:p-6 bg-gradient-to-r from-amber-400/10 to-accent-purple/10 border border-amber-400/20 rounded-lg",children:(0,s.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("h4",{className:"text-base md:text-lg font-bold text-text-primary",children:"Enterprise"}),(0,s.jsx)("p",{className:"text-xs md:text-sm text-text-secondary mt-1",children:"Custom solutions for large teams with dedicated support, SLA, and custom integrations."})]}),(0,s.jsx)("a",{href:"mailto:enterprise@agent-relay.com",className:"px-4 md:px-6 py-2 md:py-2.5 bg-amber-400 text-bg-deep rounded-lg text-xs md:text-sm font-bold hover:bg-amber-300 transition-colors text-center shrink-0",children:"Contact Sales"})]})}),d.length>0&&(0,s.jsxs)("div",{children:[(0,s.jsx)("h3",{className:"text-sm font-semibold text-text-muted uppercase tracking-wide mb-4",children:"Billing History"}),(0,s.jsx)("div",{className:"hidden md:block bg-bg-tertiary rounded-lg overflow-hidden",children:(0,s.jsxs)("table",{className:"w-full",children:[(0,s.jsx)("thead",{children:(0,s.jsxs)("tr",{className:"border-b border-border-subtle",children:[(0,s.jsx)("th",{className:"text-left px-4 py-3 text-xs font-semibold text-text-muted uppercase",children:"Invoice"}),(0,s.jsx)("th",{className:"text-left px-4 py-3 text-xs font-semibold text-text-muted uppercase",children:"Date"}),(0,s.jsx)("th",{className:"text-left px-4 py-3 text-xs font-semibold text-text-muted uppercase",children:"Amount"}),(0,s.jsx)("th",{className:"text-left px-4 py-3 text-xs font-semibold text-text-muted uppercase",children:"Status"}),(0,s.jsx)("th",{className:"text-right px-4 py-3 text-xs font-semibold text-text-muted uppercase"})]})}),(0,s.jsx)("tbody",{children:d.map(e=>(0,s.jsxs)("tr",{className:"border-b border-border-subtle last:border-0",children:[(0,s.jsx)("td",{className:"px-4 py-3 text-sm text-text-primary font-medium",children:e.number}),(0,s.jsx)("td",{className:"px-4 py-3 text-sm text-text-secondary",children:new Date(e.date).toLocaleDateString()}),(0,s.jsxs)("td",{className:"px-4 py-3 text-sm text-text-primary",children:["$",(e.amount/100).toFixed(2)]}),(0,s.jsx)("td",{className:"px-4 py-3",children:(0,s.jsx)("span",{className:"text-xs px-2 py-1 rounded-full ".concat("paid"===e.status?"bg-success/20 text-success":"open"===e.status?"bg-amber-400/20 text-amber-400":"bg-error/20 text-error"),children:e.status})}),(0,s.jsx)("td",{className:"px-4 py-3 text-right",children:e.pdfUrl&&(0,s.jsx)("a",{href:e.pdfUrl,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-accent-cyan hover:underline",children:"Download"})})]},e.id))})]})}),(0,s.jsx)("div",{className:"md:hidden space-y-3",children:d.map(e=>(0,s.jsxs)("div",{className:"bg-bg-tertiary rounded-lg p-4",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,s.jsx)("span",{className:"text-sm font-medium text-text-primary",children:e.number}),(0,s.jsx)("span",{className:"text-xs px-2 py-1 rounded-full ".concat("paid"===e.status?"bg-success/20 text-success":"open"===e.status?"bg-amber-400/20 text-amber-400":"bg-error/20 text-error"),children:e.status})]}),(0,s.jsxs)("div",{className:"flex items-center justify-between text-xs",children:[(0,s.jsx)("span",{className:"text-text-muted",children:new Date(e.date).toLocaleDateString()}),(0,s.jsxs)("span",{className:"text-text-primary font-medium",children:["$",(e.amount/100).toFixed(2)]})]}),e.pdfUrl&&(0,s.jsx)("a",{href:e.pdfUrl,target:"_blank",rel:"noopener noreferrer",className:"mt-3 block text-center text-xs text-accent-cyan py-2 border border-accent-cyan/30 rounded-lg hover:bg-accent-cyan/10 transition-colors",children:"Download PDF"})]},e.id))})]})]})}function t6(){return(0,s.jsx)("svg",{className:"animate-spin h-5 w-5 text-accent-cyan",viewBox:"0 0 24 24",children:(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeDasharray:"32",strokeLinecap:"round"})})}function t8(e){let{className:t=""}=e;return(0,s.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:(0,s.jsx)("polyline",{points:"20 6 9 17 4 12"})})}let t9={theme:"dark",compactMode:!1,showTimestamps:!0,soundEnabled:!0,notificationsEnabled:!0,autoScrollMessages:!0};function t7(e){var t,r;let{currentUserId:a,initialTab:o="dashboard",onClose:i}=e,[l,c]=(0,n.useState)(o),[d,x]=(0,n.useState)([]),[u,m]=(0,n.useState)(null),[h,p]=(0,n.useState)(!0),[g,b]=(0,n.useState)(t9);(0,n.useEffect)(()=>{(async function(){p(!0);let e=await el.xv.getWorkspaceSummary();e.success&&e.data.workspaces.length>0&&(x(e.data.workspaces),m(e.data.workspaces[0].id)),p(!1)})()},[]),(0,n.useEffect)(()=>{let e=localStorage.getItem("dashboard-settings");if(e)try{b({...t9,...JSON.parse(e)})}catch(e){}},[]);let f=(e,t)=>{let r={...g,[e]:t};b(r),localStorage.setItem("dashboard-settings",JSON.stringify(r)),"theme"===e&&document.documentElement.setAttribute("data-theme",t)},j=[{id:"dashboard",label:"Dashboard",icon:(0,s.jsx)(ro,{})},{id:"workspace",label:"Workspace",icon:(0,s.jsx)(ri,{})},{id:"team",label:"Team",icon:(0,s.jsx)(rl,{})},{id:"billing",label:"Billing",icon:(0,s.jsx)(rc,{})}];return(0,s.jsxs)("div",{className:"fixed inset-0 z-50 bg-bg-deep",children:[(0,s.jsxs)("div",{className:"absolute inset-0 opacity-30",children:[(0,s.jsx)("div",{className:"absolute inset-0 bg-[radial-gradient(ellipse_at_top_right,_rgba(0,217,255,0.08)_0%,_transparent_50%)]"}),(0,s.jsx)("div",{className:"absolute inset-0 bg-[radial-gradient(ellipse_at_bottom_left,_rgba(168,85,247,0.06)_0%,_transparent_50%)]"})]}),(0,s.jsxs)("div",{className:"relative h-full flex flex-col",children:[(0,s.jsxs)("header",{className:"h-14 md:h-16 px-4 md:px-6 flex items-center justify-between border-b border-border-subtle bg-bg-secondary/80 backdrop-blur-sm",children:[(0,s.jsxs)("div",{className:"flex items-center gap-3 md:gap-4",children:[(0,s.jsx)("div",{className:"w-8 h-8 md:w-10 md:h-10 rounded-xl bg-gradient-to-br from-accent-cyan to-accent-purple flex items-center justify-center shadow-lg shadow-accent-cyan/20",children:(0,s.jsx)(ra,{className:"text-white w-4 h-4 md:w-[18px] md:h-[18px]"})}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h1",{className:"text-base md:text-lg font-bold text-text-primary tracking-tight",children:"Settings"}),(0,s.jsx)("p",{className:"text-[10px] md:text-xs text-text-muted hidden sm:block",children:"Manage your workspace and preferences"})]})]}),(0,s.jsx)("button",{onClick:i,className:"w-9 h-9 md:w-10 md:h-10 rounded-lg bg-bg-tertiary border border-border-subtle flex items-center justify-center text-text-muted hover:text-text-primary hover:bg-bg-hover transition-colors",children:(0,s.jsx)(rd,{})})]}),(0,s.jsx)("div",{className:"md:hidden flex border-b border-border-subtle bg-bg-secondary/50 overflow-x-auto scrollbar-hide",children:j.map(e=>(0,s.jsxs)("button",{onClick:()=>c(e.id),className:"flex-1 min-w-[80px] flex flex-col items-center gap-1 px-3 py-3 text-xs font-medium transition-all ".concat(l===e.id?"text-accent-cyan border-b-2 border-accent-cyan bg-accent-cyan/5":"text-text-muted border-b-2 border-transparent"),children:[(0,s.jsx)("span",{className:l===e.id?"text-accent-cyan":"text-text-muted",children:e.icon}),e.label]},e.id))}),("workspace"===l||"team"===l)&&d.length>0&&(0,s.jsx)("div",{className:"md:hidden px-4 py-2 border-b border-border-subtle bg-bg-tertiary/50",children:(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("div",{className:"w-2 h-2 rounded-full shrink-0 ".concat((null===(t=d.find(e=>e.id===u))||void 0===t?void 0:t.status)==="running"?"bg-success":(null===(r=d.find(e=>e.id===u))||void 0===r?void 0:r.status)==="stopped"?"bg-amber-400":"bg-text-muted")}),1===d.length?(0,s.jsx)("span",{className:"text-sm text-text-primary",children:d[0].name}):(0,s.jsx)("select",{value:u||"",onChange:e=>m(e.target.value),className:"flex-1 px-3 py-2 bg-bg-card border border-border-subtle rounded-lg text-sm text-text-primary focus:outline-none focus:border-accent-cyan",children:d.map(e=>(0,s.jsx)("option",{value:e.id,children:e.name},e.id))})]})}),(0,s.jsxs)("div",{className:"flex-1 flex overflow-hidden",children:[(0,s.jsxs)("nav",{className:"hidden md:flex w-64 border-r border-border-subtle bg-bg-secondary/50 p-4 flex-col",children:[(0,s.jsx)("div",{className:"space-y-1",children:j.map(e=>(0,s.jsxs)("button",{onClick:()=>c(e.id),className:"w-full flex items-center gap-3 px-4 py-3 rounded-xl text-sm font-medium transition-all duration-200 ".concat(l===e.id?"bg-accent-cyan/15 text-accent-cyan border border-accent-cyan/30 shadow-[0_0_20px_rgba(0,217,255,0.1)]":"text-text-secondary hover:bg-bg-hover hover:text-text-primary border border-transparent"),children:[(0,s.jsx)("span",{className:l===e.id?"text-accent-cyan":"text-text-muted",children:e.icon}),e.label]},e.id))}),("workspace"===l||"team"===l)&&d.length>0&&(0,s.jsxs)("div",{className:"mt-8 pt-6 border-t border-border-subtle",children:[(0,s.jsx)("label",{className:"text-xs font-semibold text-text-muted uppercase tracking-wider mb-3 block",children:"Select Workspace"}),(0,s.jsx)("div",{className:"space-y-2",children:d.map(e=>(0,s.jsxs)("button",{onClick:()=>m(e.id),className:"w-full flex items-center gap-3 px-3 py-2.5 rounded-lg text-sm transition-all ".concat(u===e.id?"bg-bg-tertiary border border-accent-cyan/30 text-text-primary":"text-text-secondary hover:bg-bg-hover hover:text-text-primary border border-transparent"),children:[(0,s.jsx)("div",{className:"w-2 h-2 rounded-full ".concat("running"===e.status?"bg-success":"stopped"===e.status?"bg-amber-400":"bg-text-muted")}),(0,s.jsx)("span",{className:"truncate",children:e.name})]},e.id))})]}),(0,s.jsx)("div",{className:"mt-auto pt-6",children:(0,s.jsxs)("div",{className:"px-4 py-3 bg-bg-tertiary/50 rounded-lg",children:[(0,s.jsx)("p",{className:"text-xs text-text-muted",children:"Agent Relay"}),(0,s.jsx)("p",{className:"text-xs font-mono text-text-muted/60",children:"v1.0.0"})]})})]}),(0,s.jsx)("main",{className:"flex-1 overflow-y-auto",children:(0,s.jsxs)("div",{className:"max-w-4xl mx-auto p-4 md:p-8",children:["dashboard"===l&&(0,s.jsxs)("div",{className:"space-y-8",children:[(0,s.jsx)(re,{title:"Dashboard Settings",subtitle:"Customize your dashboard experience"}),(0,s.jsxs)(rt,{title:"Appearance",icon:(0,s.jsx)(rx,{}),children:[(0,s.jsx)(rr,{label:"Theme",description:"Choose your preferred color scheme",children:(0,s.jsxs)("select",{value:g.theme,onChange:e=>f("theme",e.target.value),className:"px-4 py-2 bg-bg-tertiary border border-border-subtle rounded-lg text-sm text-text-primary focus:outline-none focus:border-accent-cyan",children:[(0,s.jsx)("option",{value:"dark",children:"Dark"}),(0,s.jsx)("option",{value:"light",children:"Light"}),(0,s.jsx)("option",{value:"system",children:"System"})]})}),(0,s.jsx)(rr,{label:"Compact Mode",description:"Reduce spacing and show more content",children:(0,s.jsx)(rs,{checked:g.compactMode,onChange:e=>f("compactMode",e)})}),(0,s.jsx)(rr,{label:"Show Timestamps",description:"Display timestamps on messages",children:(0,s.jsx)(rs,{checked:g.showTimestamps,onChange:e=>f("showTimestamps",e)})})]}),(0,s.jsxs)(rt,{title:"Notifications",icon:(0,s.jsx)(ru,{}),children:[(0,s.jsx)(rr,{label:"Sound Effects",description:"Play sounds for new messages",children:(0,s.jsx)(rs,{checked:g.soundEnabled,onChange:e=>f("soundEnabled",e)})}),(0,s.jsx)(rr,{label:"Browser Notifications",description:"Show desktop notifications",children:(0,s.jsx)(rs,{checked:g.notificationsEnabled,onChange:e=>f("notificationsEnabled",e)})})]}),(0,s.jsx)(rt,{title:"Behavior",icon:(0,s.jsx)(ra,{}),children:(0,s.jsx)(rr,{label:"Auto-scroll Messages",description:"Automatically scroll to new messages",children:(0,s.jsx)(rs,{checked:g.autoScrollMessages,onChange:e=>f("autoScrollMessages",e)})})})]}),"workspace"===l&&(0,s.jsx)(s.Fragment,{children:h?(0,s.jsxs)("div",{className:"flex items-center justify-center h-64",children:[(0,s.jsx)("div",{className:"relative",children:(0,s.jsx)("div",{className:"w-12 h-12 rounded-full border-2 border-accent-cyan/20 border-t-accent-cyan animate-spin"})}),(0,s.jsx)("span",{className:"ml-4 text-text-muted",children:"Loading workspaces..."})]}):u?(0,s.jsx)(tT,{workspaceId:u,csrfToken:(0,el._V)()||void 0,onClose:i}):(0,s.jsx)(rn,{icon:(0,s.jsx)(ri,{}),title:"No Workspace",description:"Create a workspace to get started with Agent Relay.",action:(0,s.jsx)("button",{className:"px-6 py-3 bg-accent-cyan text-bg-deep font-semibold rounded-lg hover:bg-accent-cyan/90 transition-colors",children:"Create Workspace"})})}),"team"===l&&(0,s.jsx)(s.Fragment,{children:u?(0,s.jsxs)("div",{className:"space-y-8",children:[(0,s.jsx)(re,{title:"Team Settings",subtitle:"Manage workspace members and permissions"}),(0,s.jsx)(t0,{workspaceId:u,currentUserId:a})]}):(0,s.jsx)(rn,{icon:(0,s.jsx)(rl,{}),title:"No Workspace Selected",description:"Select a workspace to manage team members."})}),"billing"===l&&(0,s.jsxs)("div",{className:"space-y-8",children:[(0,s.jsx)(re,{title:"Billing & Subscription",subtitle:"Manage your plan and payment methods"}),(0,s.jsx)(t3,{})]})]})})]})]})]})}function re(e){let{title:t,subtitle:r}=e;return(0,s.jsxs)("div",{className:"mb-8",children:[(0,s.jsx)("h2",{className:"text-2xl font-bold text-text-primary",children:t}),(0,s.jsx)("p",{className:"text-sm text-text-muted mt-1",children:r})]})}function rt(e){let{title:t,icon:r,children:n}=e;return(0,s.jsxs)("div",{className:"bg-bg-tertiary rounded-xl border border-border-subtle overflow-hidden",children:[(0,s.jsxs)("div",{className:"px-6 py-4 border-b border-border-subtle bg-bg-secondary/50 flex items-center gap-3",children:[(0,s.jsx)("span",{className:"text-accent-cyan",children:r}),(0,s.jsx)("h3",{className:"text-sm font-semibold text-text-primary uppercase tracking-wide",children:t})]}),(0,s.jsx)("div",{className:"divide-y divide-border-subtle",children:n})]})}function rr(e){let{label:t,description:r,children:n}=e;return(0,s.jsxs)("div",{className:"px-6 py-4 flex items-center justify-between",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"text-sm font-medium text-text-primary",children:t}),(0,s.jsx)("p",{className:"text-xs text-text-muted mt-0.5",children:r})]}),n]})}function rs(e){let{checked:t,onChange:r}=e;return(0,s.jsx)("button",{onClick:()=>r(!t),className:"relative w-12 h-6 rounded-full transition-colors ".concat(t?"bg-accent-cyan":"bg-bg-hover"),children:(0,s.jsx)("span",{className:"absolute top-1 w-4 h-4 bg-white rounded-full shadow transition-transform ".concat(t?"translate-x-7":"translate-x-1")})})}function rn(e){let{icon:t,title:r,description:n,action:a}=e;return(0,s.jsxs)("div",{className:"flex flex-col items-center justify-center h-64 text-center",children:[(0,s.jsx)("div",{className:"w-16 h-16 rounded-2xl bg-bg-tertiary flex items-center justify-center text-text-muted mb-4",children:t}),(0,s.jsx)("h3",{className:"text-lg font-semibold text-text-primary mb-2",children:r}),(0,s.jsx)("p",{className:"text-sm text-text-muted max-w-sm mb-6",children:n}),a]})}function ra(e){let{className:t=""}=e;return(0,s.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"3"}),(0,s.jsx)("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"})]})}function ro(){return(0,s.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("rect",{x:"3",y:"3",width:"7",height:"9"}),(0,s.jsx)("rect",{x:"14",y:"3",width:"7",height:"5"}),(0,s.jsx)("rect",{x:"14",y:"12",width:"7",height:"9"}),(0,s.jsx)("rect",{x:"3",y:"16",width:"7",height:"5"})]})}function ri(){return(0,s.jsx)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,s.jsx)("path",{d:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"})})}function rl(){return(0,s.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("path",{d:"M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"}),(0,s.jsx)("circle",{cx:"9",cy:"7",r:"4"}),(0,s.jsx)("path",{d:"M23 21v-2a4 4 0 0 0-3-3.87"}),(0,s.jsx)("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]})}function rc(){return(0,s.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("rect",{x:"1",y:"4",width:"22",height:"16",rx:"2",ry:"2"}),(0,s.jsx)("line",{x1:"1",y1:"10",x2:"23",y2:"10"})]})}function rd(){return(0,s.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function rx(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("circle",{cx:"13.5",cy:"6.5",r:"2.5"}),(0,s.jsx)("circle",{cx:"19",cy:"13.5",r:"2.5"}),(0,s.jsx)("circle",{cx:"6",cy:"12",r:"2.5"}),(0,s.jsx)("circle",{cx:"11",cy:"19",r:"2.5"}),(0,s.jsx)("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.555C21.965 6.012 17.461 2 12 2z"})]})}function ru(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("path",{d:"M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9"}),(0,s.jsx)("path",{d:"M13.73 21a2 2 0 0 1-3.46 0"})]})}var rm=r(9116);function rh(e){let{isOpen:t,onClose:r}=e,[a,o]=(0,n.useState)("conversations"),[i,l]=(0,n.useState)([]),[c,d]=(0,n.useState)([]),[x,u]=(0,n.useState)([]),[m,h]=(0,n.useState)(null),[p,g]=(0,n.useState)(!1),[b,f]=(0,n.useState)(null),[j,y]=(0,n.useState)(""),[v,w]=(0,n.useState)(""),[N,k]=(0,n.useState)(null);(0,n.useEffect)(()=>{t&&(async()=>{let e=await rm.hi.getHistoryStats();e.success&&e.data&&h(e.data)})()},[t]),(0,n.useEffect)(()=>{t&&(async()=>{g(!0),f(null);try{if("conversations"===a){let e=await rm.hi.getHistoryConversations();e.success&&e.data?l(e.data.conversations):f(e.error||"Failed to fetch conversations")}else if("sessions"===a){let e=await rm.hi.getHistorySessions({agent:v||void 0,limit:50});e.success&&e.data?d(e.data.sessions):f(e.error||"Failed to fetch sessions")}else if("messages"===a){let r={limit:100,order:"desc"};if(j&&(r.search=j),N){let[s,n]=N.participants,a=await rm.hi.getHistoryMessages({...r,from:s,to:n}),o=await rm.hi.getHistoryMessages({...r,from:n,to:s});if(a.success&&o.success){var e,t;let r=[...(null===(e=a.data)||void 0===e?void 0:e.messages)||[],...(null===(t=o.data)||void 0===t?void 0:t.messages)||[]].sort((e,t)=>new Date(t.timestamp).getTime()-new Date(e.timestamp).getTime());u(r)}}else{let e=await rm.hi.getHistoryMessages(r);e.success&&e.data?u(e.data.messages):f(e.error||"Failed to fetch messages")}}}catch(e){f("Failed to load data")}finally{g(!1)}})()},[t,a,v,j,N]);let C=(0,n.useCallback)(e=>{k(e),o("messages")},[]),S=(0,n.useCallback)(()=>{k(null),o("conversations")},[]);return t?(0,s.jsx)("div",{className:"fixed inset-0 z-[1000] flex items-center justify-center bg-black/50",children:(0,s.jsxs)("div",{className:"bg-bg-primary rounded-lg shadow-xl w-[90vw] max-w-4xl h-[80vh] flex flex-col",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between p-4 border-b border-border",children:[(0,s.jsxs)("div",{className:"flex items-center gap-4",children:[(0,s.jsx)("h2",{className:"text-lg font-semibold text-text-primary",children:"Conversation History"}),m&&(0,s.jsxs)("div",{className:"flex gap-4 text-sm text-text-muted",children:[(0,s.jsxs)("span",{children:[m.messageCount," messages"]}),(0,s.jsxs)("span",{children:[m.sessionCount," sessions"]}),(0,s.jsxs)("span",{children:[m.uniqueAgents," agents"]})]})]}),(0,s.jsx)("button",{onClick:r,className:"p-2 text-text-muted hover:text-text-primary rounded transition-colors","aria-label":"Close",children:(0,s.jsx)(rv,{})})]}),(0,s.jsxs)("div",{className:"flex items-center gap-4 p-4 border-b border-border",children:[(0,s.jsxs)("div",{className:"flex gap-1 bg-bg-secondary rounded-md p-1",children:[(0,s.jsx)(rp,{active:"conversations"===a,onClick:()=>{k(null),o("conversations")},children:"Conversations"}),(0,s.jsx)(rp,{active:"sessions"===a,onClick:()=>o("sessions"),children:"Sessions"}),(0,s.jsx)(rp,{active:"messages"===a,onClick:()=>o("messages"),children:"Messages"})]}),"messages"===a&&(0,s.jsx)("div",{className:"flex-1 max-w-xs",children:(0,s.jsx)("input",{type:"text",placeholder:"Search messages...",value:j,onChange:e=>y(e.target.value),className:"w-full px-3 py-2 bg-bg-secondary border border-border rounded-md text-sm text-text-primary placeholder:text-text-muted focus:outline-none focus:border-accent"})}),"sessions"===a&&(0,s.jsx)("div",{className:"flex-1 max-w-xs",children:(0,s.jsx)("input",{type:"text",placeholder:"Filter by agent...",value:v,onChange:e=>w(e.target.value),className:"w-full px-3 py-2 bg-bg-secondary border border-border rounded-md text-sm text-text-primary placeholder:text-text-muted focus:outline-none focus:border-accent"})}),N&&(0,s.jsxs)("button",{onClick:S,className:"flex items-center gap-1 px-3 py-2 text-sm text-text-muted hover:text-text-primary",children:[(0,s.jsx)(rw,{})," Back to conversations"]})]}),(0,s.jsx)("div",{className:"flex-1 overflow-y-auto p-4",children:p?(0,s.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,s.jsx)(rN,{})}):b?(0,s.jsx)("div",{className:"flex items-center justify-center h-full text-error",children:b}):"conversations"===a?(0,s.jsx)(rg,{conversations:i,onConversationClick:C}):"sessions"===a?(0,s.jsx)(rb,{sessions:c}):(0,s.jsx)(rj,{messages:x,conversationTitle:N?"".concat(N.participants[0]," & ").concat(N.participants[1]):void 0})})]})}):null}function rp(e){let{active:t,onClick:r,children:n}=e;return(0,s.jsx)("button",{onClick:r,className:"px-3 py-1.5 text-sm rounded transition-colors ".concat(t?"bg-accent text-white":"text-text-muted hover:text-text-primary hover:bg-bg-primary"),children:n})}function rg(e){let{conversations:t,onConversationClick:r}=e;return 0===t.length?(0,s.jsx)("div",{className:"flex items-center justify-center h-full text-text-muted",children:"No conversations found"}):(0,s.jsx)("div",{className:"space-y-2",children:t.map((e,t)=>(0,s.jsxs)("div",{onClick:()=>r(e),className:"p-4 bg-bg-secondary rounded-lg cursor-pointer hover:bg-bg-tertiary transition-colors",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:"font-medium text-text-primary",children:e.participants.join(" & ")}),(0,s.jsxs)("span",{className:"text-xs px-2 py-0.5 bg-accent/10 text-accent rounded-full",children:[e.messageCount," messages"]})]}),(0,s.jsx)("span",{className:"text-xs text-text-muted",children:ry(e.lastTimestamp)})]}),(0,s.jsx)("p",{className:"text-sm text-text-muted truncate",children:e.lastMessage})]},t))})}function rb(e){let{sessions:t}=e;return 0===t.length?(0,s.jsx)("div",{className:"flex items-center justify-center h-full text-text-muted",children:"No sessions found"}):(0,s.jsx)("div",{className:"space-y-2",children:t.map(e=>(0,s.jsxs)("div",{className:"p-4 bg-bg-secondary rounded-lg",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:"font-medium text-text-primary",children:e.agentName}),e.cli&&(0,s.jsx)("span",{className:"text-xs px-2 py-0.5 bg-bg-tertiary text-text-muted rounded",children:e.cli}),(0,s.jsx)(rf,{isActive:e.isActive,closedBy:e.closedBy})]}),(0,s.jsx)("span",{className:"text-xs text-text-muted",children:e.duration})]}),(0,s.jsxs)("div",{className:"flex items-center gap-4 text-sm text-text-muted",children:[(0,s.jsx)("span",{children:new Date(e.startedAt).toLocaleString()}),(0,s.jsxs)("span",{children:[e.messageCount," messages"]})]}),e.summary&&(0,s.jsx)("p",{className:"mt-2 text-sm text-text-muted truncate",children:e.summary})]},e.id))})}function rf(e){let{isActive:t,closedBy:r}=e;if(t)return(0,s.jsx)("span",{className:"text-xs px-2 py-0.5 bg-success/10 text-success rounded-full",children:"Active"});let n={agent:"bg-text-muted/10 text-text-muted",disconnect:"bg-warning/10 text-warning",error:"bg-error/10 text-error"},a=r?n[r]:n.agent;return(0,s.jsx)("span",{className:"text-xs px-2 py-0.5 rounded-full ".concat(a),children:r?({agent:"Closed",disconnect:"Disconnected",error:"Error"})[r]:"Ended"})}function rj(e){let{messages:t,conversationTitle:r}=e;return 0===t.length?(0,s.jsx)("div",{className:"flex items-center justify-center h-full text-text-muted",children:"No messages found"}):(0,s.jsxs)("div",{className:"space-y-4",children:[r&&(0,s.jsx)("h3",{className:"text-lg font-medium text-text-primary mb-4",children:r}),t.map(e=>(0,s.jsxs)("div",{className:"p-4 bg-bg-secondary rounded-lg",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:"font-medium text-accent",children:e.from}),(0,s.jsx)("span",{className:"text-text-muted",children:"to"}),(0,s.jsx)("span",{className:"font-medium text-text-primary",children:"*"===e.to?"Everyone":e.to}),e.isBroadcast&&(0,s.jsx)("span",{className:"text-xs px-2 py-0.5 bg-accent/10 text-accent rounded-full",children:"Broadcast"}),e.isUrgent&&(0,s.jsx)("span",{className:"text-xs px-2 py-0.5 bg-error/10 text-error rounded-full",children:"Urgent"})]}),(0,s.jsx)("span",{className:"text-xs text-text-muted",children:ry(e.timestamp)})]}),(0,s.jsx)("p",{className:"text-sm text-text-primary whitespace-pre-wrap",children:e.content}),e.thread&&(0,s.jsxs)("div",{className:"mt-2 text-xs text-text-muted",children:["Thread: ",e.thread.slice(0,8),"..."]})]},e.id))]})}function ry(e){let t=new Date(e),r=new Date().getTime()-t.getTime(),s=Math.floor(r/6e4),n=Math.floor(r/36e5),a=Math.floor(r/864e5);return s<1?"just now":s<60?"".concat(s,"m ago"):n<24?"".concat(n,"h ago"):a<7?"".concat(a,"d ago"):t.toLocaleDateString()}function rv(){return(0,s.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function rw(){return(0,s.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.jsx)("polyline",{points:"15 18 9 12 15 6"})})}function rN(){return(0,s.jsx)("svg",{className:"animate-spin text-accent",width:"24",height:"24",viewBox:"0 0 24 24",children:(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeDasharray:"32",strokeLinecap:"round"})})}function rk(e,t){let r=e.substring(0,t).match(/(?:^|[\s(])@(\S*)$/);return r?r[1]:null}function rC(e,t,r){let s=e.substring(0,r),n=e.substring(r),a=s.match(/(?:^|[\s(])@(\S*)$/);if(a){let r=a.index||0,s=a[0].charAt(0),o=e.substring(0,"@"===s?r:r+1),i="@".concat(t," "),l=o.length+i.length;return{value:o+i+n,cursorPosition:l}}return{value:e,cursorPosition:r}}function rS(e){let{agents:t,humanUsers:r=[],inputValue:o,cursorPosition:i,onSelect:l,onClose:c,isVisible:d}=e,[x,u]=(0,n.useState)(0),m=(0,n.useRef)(null),h=(0,n.useMemo)(()=>rk(o,i),[o,i]),p=(0,n.useMemo)(()=>{let e=new Map;return t.forEach(t=>{if(t.team){let r=e.get(t.team)||[];r.push(t),e.set(t.team,r)}}),e},[t]),g=(0,n.useMemo)(()=>{if(null===h)return[];let e=h.toLowerCase(),s=[];("*".includes(e)||"everyone".includes(e)||"all".includes(e)||"broadcast".includes(e)||""===e)&&s.push({name:"*",displayName:"@everyone",description:"Broadcast to all agents",isBroadcast:!0});let n=e.startsWith("team:")||e.startsWith("team"),a=e.startsWith("team:")?e.substring(5):e.replace(/^team/,"");(n||""===e)&&p.forEach((t,r)=>{let n=r.toLowerCase();(""===a||n.includes(a)||"team:".concat(n).includes(e))&&s.push({name:"team:".concat(r),displayName:"@team:".concat(r),description:"".concat(t.length," agent").concat(1!==t.length?"s":"",": ").concat(t.map(e=>e.name).join(", ")),isTeam:!0,memberCount:t.length})});let o=new Set(t.map(e=>e.name.toLowerCase()));return r.filter(t=>{let r=t.username.toLowerCase();return r.includes(e)&&!o.has(r)}).forEach(e=>{s.push({name:e.username,displayName:"@".concat(e.username),description:"Human user",isHuman:!0,avatarUrl:e.avatarUrl})}),t.filter(t=>t.name.toLowerCase().includes(e)).forEach(e=>{s.push({name:e.name,displayName:"@".concat(e.name),description:e.team?"".concat(e.status||"Agent"," \xb7 ").concat(e.team):e.status||"Agent"})}),s},[h,t,r,p]);(0,n.useEffect)(()=>{u(0)},[g.length]),(0,n.useEffect)(()=>{if(!m.current)return;let e=m.current.querySelector('[data-selected="true"]');e&&e.scrollIntoView({block:"nearest"})},[x]);let b=(0,n.useCallback)(e=>{if(d&&0!==g.length)switch(e.key){case"ArrowDown":e.preventDefault(),u(e=>(e+1)%g.length);break;case"ArrowUp":e.preventDefault(),u(e=>(e-1+g.length)%g.length);break;case"Enter":case"Tab":e.preventDefault();let t=g[x];if(t){let e=rC(o,t.name,i);l(t.name,e.value)}break;case"Escape":e.preventDefault(),c()}},[d,g,x,o,i,l,c]);(0,n.useEffect)(()=>{if(d)return window.addEventListener("keydown",b),()=>window.removeEventListener("keydown",b)},[d,b]);let f=(0,n.useCallback)(e=>{let t=rC(o,e.name,i);l(e.name,t.value)},[o,i,l]);return d&&0!==g.length?(0,s.jsx)("div",{className:"absolute bottom-full left-0 right-0 max-h-[200px] overflow-y-auto bg-[#1a1d21] border border-white/10 rounded-lg shadow-[0_-4px_20px_rgba(0,0,0,0.4)] z-[100] mb-1",ref:m,children:g.map((e,t)=>(0,s.jsxs)("div",{"data-selected":t===x,className:"flex items-center gap-2.5 py-2 px-3 cursor-pointer transition-colors duration-150 ".concat(t===x?"bg-white/[0.08]":"hover:bg-white/[0.08]"),onClick:()=>f(e),onMouseEnter:()=>u(t),children:[e.isHuman&&e.avatarUrl?(0,s.jsx)("img",{src:e.avatarUrl,alt:e.name,className:"w-7 h-7 rounded-md object-cover"}):(0,s.jsx)("div",{className:"w-7 h-7 rounded-md flex items-center justify-center text-white text-[11px] font-semibold",style:{background:e.isBroadcast?"var(--color-warning, #f59e0b)":e.isTeam?"var(--color-accent-purple, #a855f7)":e.isHuman?"#a855f7":(0,a.GW)(e.name).primary},children:e.isBroadcast?"*":e.isTeam?(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("path",{d:"M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"}),(0,s.jsx)("circle",{cx:"9",cy:"7",r:"4"}),(0,s.jsx)("path",{d:"M23 21v-2a4 4 0 0 0-3-3.87"}),(0,s.jsx)("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]}):e.isHuman?(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("path",{d:"M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"}),(0,s.jsx)("circle",{cx:"12",cy:"7",r:"4"})]}):(0,a.hP)(e.name)}),(0,s.jsxs)("div",{className:"flex flex-col gap-0.5 min-w-0 flex-1",children:[(0,s.jsx)("span",{className:"text-sm font-medium text-[#d1d2d3]",children:e.displayName}),(0,s.jsx)("span",{className:"text-xs text-[#8d8d8e] truncate",children:e.description})]})]},e.name))}):null}function rA(e,t){let r=e.substring(0,t).match(/(?:^|[\s(])@(\S*)$/);if(r){let e=r[1];if(e.includes("/")||/\.[a-zA-Z0-9]{1,10}$/.test(e))return e}return null}function rL(e,t,r){let s=e.substring(0,r),n=e.substring(r),a=s.match(/(?:^|[\s(])@(\S*)$/);if(a){let r=a.index||0,s=a[0].charAt(0);return e.substring(0,"@"===s?r:r+1)+"@".concat(t," ")+n}return e}let rE=new Map;function rW(e){let{inputValue:t,cursorPosition:r,onSelect:a,onClose:o,isVisible:i,apiBase:l=""}=e,[c,d]=(0,n.useState)(0),[x,u]=(0,n.useState)([]),[m,h]=(0,n.useState)(!1),[p,g]=(0,n.useState)(null),b=(0,n.useRef)(null),f=(0,n.useRef)(null),j=(0,n.useMemo)(()=>rA(t,r),[t,r]);(0,n.useEffect)(()=>{if(!i||null===j){u([]);return}let e=j||"__root__",t=rE.get(e);if(t&&Date.now()-t.timestamp<3e4){u(t.files),g(null);return}f.current&&f.current.abort();let r=new AbortController;f.current=r;let s=setTimeout(async()=>{h(!0),g(null);try{let t=j||"",s=await fetch("".concat(l,"/api/files?q=").concat(encodeURIComponent(t),"&limit=15"),{signal:r.signal});if(!s.ok)throw Error("Failed to fetch files");let n=((await s.json()).files||[]).map(e=>({path:e.path,name:e.name,isDirectory:e.isDirectory||!1}));rE.set(e,{files:n,timestamp:Date.now()}),u(n)}catch(e){if(e instanceof Error&&"AbortError"===e.name)return;g("Failed to load files"),u([])}finally{h(!1)}},150);return()=>{clearTimeout(s),r.abort()}},[i,j,l]),(0,n.useEffect)(()=>{d(0)},[x.length]),(0,n.useEffect)(()=>{if(!b.current)return;let e=b.current.querySelector('[data-selected="true"]');e&&e.scrollIntoView({block:"nearest"})},[c]);let y=(0,n.useCallback)(e=>{if(i&&0!==x.length)switch(e.key){case"ArrowDown":e.preventDefault(),d(e=>(e+1)%x.length);break;case"ArrowUp":e.preventDefault(),d(e=>(e-1+x.length)%x.length);break;case"Enter":case"Tab":e.preventDefault();let s=x[c];if(s){let e=rL(t,s.path,r);a(s.path,e)}break;case"Escape":e.preventDefault(),o()}},[i,x,c,t,r,a,o]);(0,n.useEffect)(()=>{if(i)return window.addEventListener("keydown",y),()=>window.removeEventListener("keydown",y)},[i,y]);let v=(0,n.useCallback)(e=>{let s=rL(t,e.path,r);a(e.path,s)},[t,r,a]);return i&&(0!==x.length||m||p)?(0,s.jsxs)("div",{className:"absolute bottom-full left-0 right-0 max-h-[240px] overflow-y-auto bg-[#1a1d21] border border-white/10 rounded-lg shadow-[0_-4px_20px_rgba(0,0,0,0.4)] z-[100] mb-1",ref:b,children:[(0,s.jsxs)("div",{className:"px-3 py-1.5 text-[10px] uppercase tracking-wider text-[#8d8d8e] border-b border-white/5 flex items-center gap-2",children:[(0,s.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("path",{d:"M13 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9z"}),(0,s.jsx)("polyline",{points:"13 2 13 9 20 9"})]}),"Files ",j&&(0,s.jsxs)("span",{className:"text-[#6b6b6c]",children:['matching "',j,'"']})]}),m&&0===x.length&&(0,s.jsxs)("div",{className:"px-3 py-4 text-sm text-[#8d8d8e] text-center",children:[(0,s.jsx)("svg",{className:"animate-spin mx-auto mb-2",width:"16",height:"16",viewBox:"0 0 24 24",children:(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeDasharray:"32",strokeLinecap:"round"})}),"Searching files..."]}),p&&(0,s.jsx)("div",{className:"px-3 py-4 text-sm text-red-400 text-center",children:p}),x.map((e,t)=>(0,s.jsxs)("div",{"data-selected":t===c,className:"flex items-center gap-2.5 py-2 px-3 cursor-pointer transition-colors duration-150 ".concat(t===c?"bg-white/[0.08]":"hover:bg-white/[0.08]"),onClick:()=>v(e),onMouseEnter:()=>d(t),children:[(0,s.jsx)("div",{className:"w-7 h-7 rounded-md flex items-center justify-center text-[#8d8d8e]",style:{background:e.isDirectory?"rgba(251, 191, 36, 0.15)":"rgba(96, 165, 250, 0.15)"},children:e.isDirectory?(0,s.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"#fbbf24",strokeWidth:"2",children:(0,s.jsx)("path",{d:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"})}):(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"#60a5fa",strokeWidth:"2",children:[(0,s.jsx)("path",{d:"M13 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9z"}),(0,s.jsx)("polyline",{points:"13 2 13 9 20 9"})]})}),(0,s.jsxs)("div",{className:"flex flex-col gap-0.5 min-w-0 flex-1",children:[(0,s.jsx)("span",{className:"text-sm font-medium text-[#d1d2d3] truncate",children:e.name}),(0,s.jsx)("span",{className:"text-xs text-[#6b6b6c] truncate",children:e.path})]})]},e.path)),!m&&!p&&0===x.length&&j&&(0,s.jsxs)("div",{className:"px-3 py-4 text-sm text-[#8d8d8e] text-center",children:['No files found matching "',j,'"']})]}):null}function rM(e){let{workspaces:t,activeWorkspaceId:r,onSelect:a,onAddWorkspace:o,onWorkspaceSettings:i,isLoading:l=!1}=e,[c,d]=(0,n.useState)(!1),x=(0,n.useRef)(null),u=t.find(e=>e.id===r);return(0,n.useEffect)(()=>{let e=e=>{x.current&&!x.current.contains(e.target)&&d(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,n.useEffect)(()=>{let e=e=>{"Escape"===e.key&&d(!1)};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[]),(0,s.jsxs)("div",{className:"relative w-full",ref:x,children:[(0,s.jsxs)("button",{className:"w-full flex items-center gap-2 px-3 py-2.5 bg-[#2a2a3e] border border-[#3a3a4e] rounded-lg text-[#e8e8e8] text-sm cursor-pointer transition-all hover:bg-[#3a3a4e] hover:border-[#4a4a5e] disabled:opacity-60 disabled:cursor-not-allowed",onClick:()=>d(!c),disabled:l,children:[l?(0,s.jsx)("span",{className:"flex-1 text-left text-[#666]",children:"Loading..."}):u?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(rD,{provider:u.provider}),(0,s.jsx)("span",{className:"flex-1 text-left font-medium",children:u.name}),u.gitBranch&&(0,s.jsxs)("span",{className:"flex items-center gap-1 text-xs text-[#888] bg-white/5 px-1.5 py-0.5 rounded",children:[(0,s.jsx)(rP,{}),u.gitBranch]})]}):(0,s.jsx)("span",{className:"flex-1 text-left text-[#666]",children:"Select workspace..."}),(0,s.jsx)(rR,{isOpen:c})]}),c&&(0,s.jsxs)("div",{className:"absolute top-[calc(100%+4px)] left-0 right-0 bg-[#1a1a2e] border border-[#3a3a4e] rounded-lg shadow-[0_10px_40px_rgba(0,0,0,0.4)] z-[1000] overflow-hidden",children:[(0,s.jsx)("div",{className:"max-h-[300px] overflow-y-auto",children:0===t.length?(0,s.jsxs)("div",{className:"py-6 px-4 text-center text-[#666] text-[13px] leading-relaxed",children:["No workspaces added yet.",(0,s.jsx)("br",{}),"Add a repository to get started."]}):t.map(e=>(0,s.jsxs)("button",{className:"w-full flex items-center gap-2.5 px-3 py-2.5 bg-transparent border-none text-[#e8e8e8] text-sm cursor-pointer transition-colors text-left hover:bg-white/5 ".concat(e.id===r?"bg-[rgba(0,200,150,0.1)]":""),onClick:()=>{a(e),d(!1)},children:[(0,s.jsx)(rD,{provider:e.provider}),(0,s.jsxs)("div",{className:"flex-1 flex flex-col gap-0.5 min-w-0",children:[(0,s.jsx)("span",{className:"font-medium",children:e.name}),(0,s.jsx)("span",{className:"text-[11px] text-[#666] overflow-hidden text-ellipsis whitespace-nowrap",children:e.path})]}),(0,s.jsx)(rT,{status:e.status})]},e.id))}),(0,s.jsxs)("div",{className:"p-2 border-t border-[#3a3a4e] space-y-1.5",children:[i&&u&&(0,s.jsxs)("button",{className:"w-full flex items-center justify-center gap-1.5 px-3 py-2 bg-transparent border border-[#3a3a4e] rounded-md text-[#888] text-[13px] cursor-pointer transition-all hover:bg-white/5 hover:border-[#4a4a5e] hover:text-[#e8e8e8]",onClick:()=>{i(),d(!1)},children:[(0,s.jsx)(r_,{}),"Workspace Settings"]}),(0,s.jsxs)("button",{className:"w-full flex items-center justify-center gap-1.5 px-3 py-2 bg-transparent border border-dashed border-[#3a3a4e] rounded-md text-[#888] text-[13px] cursor-pointer transition-all hover:bg-white/5 hover:border-[#4a4a5e] hover:text-[#e8e8e8]",onClick:o,children:[(0,s.jsx)(rB,{}),"Add Workspace"]})]})]})]})}function rD(e){let{provider:t}=e,r={claude:"\uD83E\uDD16",codex:"\uD83E\uDDE0",gemini:"✨",generic:"\uD83D\uDCC1"};return(0,s.jsx)("span",{className:"text-base",title:t,children:r[t]||r.generic})}function rT(e){let{status:t}=e,r={active:"bg-green-500",inactive:"bg-gray-500",error:"bg-red-500"};return(0,s.jsx)("span",{className:"w-2 h-2 rounded-full flex-shrink-0 ".concat(r[t]||r.inactive),title:t})}function rR(e){let{isOpen:t}=e;return(0,s.jsx)("svg",{className:"text-[#666] transition-transform ".concat(t?"rotate-180":""),width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.jsx)("polyline",{points:"6 9 12 15 18 9"})})}function rP(){return(0,s.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,s.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,s.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,s.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]})}function rB(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,s.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function r_(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"3"}),(0,s.jsx)("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"})]})}function rI(e){let{isOpen:t,onClose:r,onAdd:a,isAdding:o=!1,error:i}=e,[l,c]=(0,n.useState)(""),[d,x]=(0,n.useState)(""),[u,m]=(0,n.useState)(null),h=(0,n.useRef)(null);(0,n.useEffect)(()=>{t&&h.current&&h.current.focus()},[t]),(0,n.useEffect)(()=>{t||(c(""),x(""),m(null))},[t]);let p=async e=>{if(e.preventDefault(),!l.trim()){m("Path is required");return}try{await a(l.trim(),d.trim()||void 0),r()}catch(e){m(e instanceof Error?e.message:"Failed to add workspace")}};if(!t)return null;let g=i||u;return(0,s.jsx)("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-[9999] backdrop-blur-sm",onClick:r,onKeyDown:e=>{"Escape"===e.key&&r()},children:(0,s.jsxs)("div",{className:"bg-[#1a1a2e] border border-[#3a3a4e] rounded-xl p-6 min-w-[450px] max-w-[90vw] shadow-[0_20px_60px_rgba(0,0,0,0.5)]",onClick:e=>e.stopPropagation(),children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-6",children:[(0,s.jsx)("h2",{className:"m-0 text-lg font-semibold text-[#e8e8e8]",children:"Add Workspace"}),(0,s.jsx)("button",{className:"bg-transparent border-none text-[#666] cursor-pointer p-1 flex items-center justify-center rounded transition-all hover:bg-white/10 hover:text-[#e8e8e8]",onClick:r,children:(0,s.jsx)(rF,{})})]}),(0,s.jsxs)("form",{onSubmit:p,children:[(0,s.jsxs)("div",{className:"mb-5",children:[(0,s.jsx)("label",{htmlFor:"workspace-path",className:"block mb-2 text-[13px] font-medium text-[#e8e8e8]",children:"Repository Path"}),(0,s.jsx)("input",{ref:h,id:"workspace-path",type:"text",value:l,onChange:e=>{c(e.target.value),m(null)},placeholder:"/path/to/repository",disabled:o,autoComplete:"off",className:"w-full px-3 py-2.5 bg-[#2a2a3e] border border-[#3a3a4e] rounded-md text-[#e8e8e8] text-sm outline-none transition-colors box-border focus:border-[#00c896] placeholder:text-[#666] disabled:opacity-60 disabled:cursor-not-allowed"}),(0,s.jsx)("p",{className:"mt-1.5 text-xs text-[#666] leading-relaxed",children:"Enter the full path to your repository. Use ~ for home directory."})]}),(0,s.jsxs)("div",{className:"mb-5",children:[(0,s.jsx)("label",{htmlFor:"workspace-name",className:"block mb-2 text-[13px] font-medium text-[#e8e8e8]",children:"Display Name (optional)"}),(0,s.jsx)("input",{id:"workspace-name",type:"text",value:d,onChange:e=>x(e.target.value),placeholder:"My Project",disabled:o,autoComplete:"off",className:"w-full px-3 py-2.5 bg-[#2a2a3e] border border-[#3a3a4e] rounded-md text-[#e8e8e8] text-sm outline-none transition-colors box-border focus:border-[#00c896] placeholder:text-[#666] disabled:opacity-60 disabled:cursor-not-allowed"}),(0,s.jsx)("p",{className:"mt-1.5 text-xs text-[#666] leading-relaxed",children:"A friendly name for this workspace. Defaults to the folder name."})]}),g&&(0,s.jsx)("div",{className:"px-3 py-2.5 bg-red-500/10 border border-red-500/30 rounded-md text-red-500 text-[13px] mb-5",children:g}),(0,s.jsxs)("div",{className:"flex gap-3 justify-end mt-6",children:[(0,s.jsx)("button",{type:"button",className:"px-5 py-2.5 rounded-md text-sm font-medium cursor-pointer transition-all bg-transparent border border-[#3a3a4e] text-[#e8e8e8] hover:bg-white/5 disabled:opacity-50 disabled:cursor-not-allowed",onClick:r,disabled:o,children:"Cancel"}),(0,s.jsx)("button",{type:"submit",className:"px-5 py-2.5 rounded-md text-sm font-medium cursor-pointer transition-all bg-[#00c896] border-none text-[#1a1a2e] hover:bg-[#00a87d] disabled:opacity-50 disabled:cursor-not-allowed",disabled:o||!l.trim(),children:o?"Adding...":"Add Workspace"})]})]})]})})}function rF(){return(0,s.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}let rU=0;function rO(){return"log-".concat(Date.now(),"-").concat(++rU)}var rz=r(9540),rH=r(1561),rV=r(7418);let rG=(0,n.createContext)({wsBaseUrl:null,isCloudMode:!1});function rK(e){let{children:t,wsUrl:r}=e,a=(0,n.useMemo)(()=>{if(!r)return{wsBaseUrl:null,isCloudMode:!1};let e=function(e){try{let t=new URL(e);return"".concat(t.protocol,"//").concat(t.host)}catch(t){return e}}(r),t=!1;try{t=new URL(r).host!==window.location.host}catch(e){}return{wsBaseUrl:e,isCloudMode:t}},[r]);return(0,s.jsx)(rG.Provider,{value:a,children:t})}let rJ={background:"#0d0f14",foreground:"#c9d1d9",cursor:"#58a6ff",cursorAccent:"#0d0f14",selectionBackground:"#264f78",selectionForeground:"#ffffff",black:"#484f58",red:"#f85149",green:"#3fb950",yellow:"#d29922",blue:"#58a6ff",magenta:"#bc8cff",cyan:"#39c5cf",white:"#b1bac4",brightBlack:"#6e7681",brightRed:"#ff7b72",brightGreen:"#56d364",brightYellow:"#e3b341",brightBlue:"#79c0ff",brightMagenta:"#d2a8ff",brightCyan:"#56d4dd",brightWhite:"#ffffff"};function rX(e){let{agentName:t,maxHeight:r="500px",showHeader:o=!0,onClose:i,className:l=""}=e,c=(0,n.useRef)(null),d=(0,n.useRef)(null),x=(0,n.useRef)(null),u=(0,n.useRef)(null),m=(0,n.useRef)(null),h=(0,n.useRef)(null),p=(0,n.useRef)(0),[g,b]=(0,n.useState)(!1),[f,j]=(0,n.useState)(!1),[y,v]=(0,n.useState)(null),[w,N]=(0,n.useState)(!1),[k,C]=(0,n.useState)(""),[S,A]=(0,n.useState)(0),L=(0,n.useRef)(null),E=(0,a.GW)(t),W=function(e){let{wsBaseUrl:t}=(0,n.useContext)(rG);return(0,n.useMemo)(()=>{if(t)return"".concat(t).concat(e);let r="https:"===window.location.protocol?"wss:":"ws:",{hostname:s,port:n}=window.location;return"".concat(r,"//").concat(window.location.host).concat(e)},[t,e])}("/ws/logs/".concat(encodeURIComponent(t)));(0,n.useEffect)(()=>{if(!c.current)return;let e=new rz.o({theme:rJ,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace',fontSize:12,lineHeight:1.4,convertEol:!0,scrollback:1e4,cursorBlink:!1,cursorStyle:"bar",disableStdin:!0,allowProposedApi:!0}),t=new rH.X,r=new rV.Z;e.loadAddon(t),e.loadAddon(r),e.open(c.current),t.fit(),d.current=e,x.current=t,u.current=r;let s=new ResizeObserver(()=>{t.fit()});return s.observe(c.current),()=>{s.disconnect(),e.dispose(),d.current=null,x.current=null,u.current=null}},[]);let M=(0,n.useCallback)(()=>{var e,r;if((null===(e=m.current)||void 0===e?void 0:e.readyState)===WebSocket.OPEN||(null===(r=m.current)||void 0===r?void 0:r.readyState)===WebSocket.CONNECTING)return;j(!0),v(null);let s=new WebSocket(W);m.current=s,s.onopen=()=>{var e;b(!0),j(!1),v(null),p.current=0,null===(e=d.current)||void 0===e||e.writeln("\x1b[90m[Connected to ".concat(t," log stream]\x1b[0m"))},s.onclose=e=>{var t,r;if(b(!1),j(!1),m.current=null,h.current&&(clearTimeout(h.current),h.current=null),4404===e.code){null===(r=d.current)||void 0===r||r.writeln("\x1b[31m[Agent not found]\x1b[0m");return}let s=Math.min(1e3*Math.pow(2,p.current),3e4);p.current++,null===(t=d.current)||void 0===t||t.writeln("\x1b[90m[Disconnected. Reconnecting in ".concat(s/1e3,"s...]\x1b[0m")),h.current=setTimeout(()=>{M()},s)},s.onerror=()=>{v(Error("WebSocket connection error")),j(!1)},s.onmessage=e=>{var t,r,s;try{let s=JSON.parse(e.data);if("error"===s.type){null===(t=d.current)||void 0===t||t.writeln("\x1b[31mError: ".concat(s.error,"\x1b[0m"));return}if("subscribed"===s.type)return;if("history"===s.type&&Array.isArray(s.lines)){s.lines.forEach(e=>{var t;null===(t=d.current)||void 0===t||t.writeln(e),A(e=>e+1)});return}if("log"===s.type||"output"===s.type){let e=s.content||s.data||s.message||"";if(e){null===(r=d.current)||void 0===r||r.write(e);let t=(e.match(/\n/g)||[]).length;t>0&&A(e=>e+t)}return}s.lines&&Array.isArray(s.lines)&&s.lines.forEach(e=>{var t;let r="string"==typeof e?e:e.content;null===(t=d.current)||void 0===t||t.writeln(r),A(e=>e+1)})}catch(t){if("string"==typeof e.data){null===(s=d.current)||void 0===s||s.write(e.data);let t=(e.data.match(/\n/g)||[]).length;t>0&&A(e=>e+t)}}}},[W,t]),D=(0,n.useCallback)(()=>{h.current&&(clearTimeout(h.current),h.current=null),m.current&&(m.current.close(),m.current=null),b(!1),j(!1)},[]),T=(0,n.useCallback)(()=>{var e;null===(e=d.current)||void 0===e||e.clear(),A(0)},[]),R=(0,n.useCallback)(e=>{C(e),e&&u.current&&u.current.findNext(e,{caseSensitive:!1})},[]),P=(0,n.useCallback)(()=>{k&&u.current&&u.current.findNext(k,{caseSensitive:!1})},[k]),B=(0,n.useCallback)(()=>{k&&u.current&&u.current.findPrevious(k,{caseSensitive:!1})},[k]);return(0,n.useEffect)(()=>(M(),()=>{D()}),[M,D]),(0,n.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&"f"===e.key&&(e.preventDefault(),N(!0),setTimeout(()=>{var e;return null===(e=L.current)||void 0===e?void 0:e.focus()},0)),"Escape"===e.key&&w&&(N(!1),C("")),"Enter"===e.key&&w&&(e.preventDefault(),e.shiftKey?B():P())};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[w,P,B]),(0,s.jsxs)("div",{className:"xterm-log-viewer flex flex-col rounded-xl overflow-hidden border border-[#2a2d35] shadow-2xl ".concat(l),style:{background:"linear-gradient(180deg, #0d0f14 0%, #0a0c10 100%)",boxShadow:"0 0 60px -15px ".concat(E.primary,"25, 0 25px 50px -12px rgba(0, 0, 0, 0.8), inset 0 1px 0 rgba(255,255,255,0.02)")},children:[o&&(0,s.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-[#21262d]",style:{background:"linear-gradient(180deg, #161b22 0%, #0d1117 100%)"},children:[(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsx)("div",{className:"flex items-center gap-2",children:(0,s.jsxs)("div",{className:"flex gap-1.5",children:[(0,s.jsx)("div",{className:"w-3 h-3 rounded-full bg-[#ff5f56] border border-[#e0443e] transition-shadow hover:shadow-[0_0_8px_rgba(255,95,86,0.5)]"}),(0,s.jsx)("div",{className:"w-3 h-3 rounded-full bg-[#ffbd2e] border border-[#dea123] transition-shadow hover:shadow-[0_0_8px_rgba(255,189,46,0.5)]"}),(0,s.jsx)("div",{className:"w-3 h-3 rounded-full bg-[#27c93f] border border-[#1aab29] transition-shadow hover:shadow-[0_0_8px_rgba(39,201,63,0.5)]"})]})}),(0,s.jsx)("div",{className:"w-px h-4 bg-[#30363d]"}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(rY,{}),(0,s.jsx)("span",{className:"text-sm font-semibold",style:{color:E.primary},children:t}),(0,s.jsx)(r2,{isConnected:g,isConnecting:f})]})]}),(0,s.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,s.jsx)("button",{className:"p-1.5 rounded-lg transition-all duration-200 ".concat(w?"bg-accent-cyan/20 text-accent-cyan shadow-[0_0_12px_rgba(0,217,255,0.25)]":"hover:bg-[#21262d] text-[#8b949e] hover:text-[#c9d1d9]"),onClick:()=>{N(!w),w||setTimeout(()=>{var e;return null===(e=L.current)||void 0===e?void 0:e.focus()},0)},title:"Search (Cmd+F)",children:(0,s.jsx)(rq,{})}),(0,s.jsx)("button",{className:"p-1.5 rounded-lg hover:bg-[#21262d] text-[#8b949e] hover:text-[#c9d1d9] transition-all duration-200",onClick:T,title:"Clear logs",children:(0,s.jsx)(r$,{})}),(0,s.jsx)("button",{className:"p-1.5 rounded-lg transition-all duration-200 ".concat(g?"hover:bg-[#f85149]/10 text-[#8b949e] hover:text-[#f85149]":"bg-[#3fb950]/20 text-[#3fb950] shadow-[0_0_12px_rgba(63,185,80,0.25)]"),onClick:g?D:M,title:g?"Disconnect":"Connect",children:g?(0,s.jsx)(r0,{}):(0,s.jsx)(rQ,{})}),i&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"w-px h-4 bg-[#30363d] mx-1"}),(0,s.jsx)("button",{className:"p-1.5 rounded-lg hover:bg-[#f85149]/10 text-[#8b949e] hover:text-[#f85149] transition-all duration-200",onClick:i,title:"Close",children:(0,s.jsx)(rZ,{})})]})]})]}),w&&(0,s.jsxs)("div",{className:"flex items-center gap-3 px-4 py-2 border-b border-[#21262d] bg-[#161b22]",children:[(0,s.jsx)(rq,{}),(0,s.jsx)("input",{ref:L,type:"text",className:"flex-1 bg-transparent border-none text-sm text-[#c9d1d9] placeholder:text-[#484f58] outline-none font-mono",placeholder:"Search logs... (Enter: next, Shift+Enter: prev)",value:k,onChange:e=>R(e.target.value)}),(0,s.jsxs)("div",{className:"flex items-center gap-1",children:[(0,s.jsx)("button",{className:"px-2 py-0.5 text-xs rounded bg-[#21262d] text-[#8b949e] hover:text-[#c9d1d9] transition-colors",onClick:B,title:"Previous (Shift+Enter)",children:"↑"}),(0,s.jsx)("button",{className:"px-2 py-0.5 text-xs rounded bg-[#21262d] text-[#8b949e] hover:text-[#c9d1d9] transition-colors",onClick:P,title:"Next (Enter)",children:"↓"})]})]}),y&&(0,s.jsxs)("div",{className:"px-4 py-2 bg-[#3d1d20] border-b border-[#f85149]/30 text-sm text-[#f85149] flex items-center gap-2",children:[(0,s.jsx)(r1,{}),(0,s.jsx)("span",{children:y.message}),(0,s.jsx)("button",{className:"ml-auto text-xs px-2 py-0.5 rounded bg-[#f85149]/20 hover:bg-[#f85149]/30 transition-colors",onClick:M,children:"Retry"})]}),(0,s.jsx)("div",{ref:c,className:"flex-1 overflow-hidden",style:{maxHeight:r,minHeight:"200px"}}),(0,s.jsxs)("div",{className:"flex items-center justify-between px-4 py-2.5 border-t border-[#21262d] text-xs",style:{background:"linear-gradient(180deg, #0d1117 0%, #0a0c10 100%)"},children:[(0,s.jsx)("div",{className:"flex items-center gap-3",children:(0,s.jsxs)("span",{className:"tabular-nums font-mono text-[#6e7681]",children:[S," lines"]})}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:"text-[#6e7681] font-mono uppercase tracking-wider text-[10px]",children:"PTY stream"}),(0,s.jsx)("div",{className:"w-2 h-2 rounded-full transition-all duration-300 ".concat(g?"bg-[#3fb950]":f?"bg-[#d29922] animate-pulse":"bg-[#484f58]"),style:{boxShadow:g?"0 0 8px rgba(63,185,80,0.6)":"none"}})]})]})]})}function rY(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-[#8b949e]",children:[(0,s.jsx)("polyline",{points:"4 17 10 11 4 5"}),(0,s.jsx)("line",{x1:"12",y1:"19",x2:"20",y2:"19"})]})}function rq(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-[#8b949e]",children:[(0,s.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,s.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]})}function r$(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,s.jsx)("path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"})]})}function rZ(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function rQ(){return(0,s.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"currentColor",children:(0,s.jsx)("polygon",{points:"5 3 19 12 5 21 5 3"})})}function r0(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"currentColor",children:[(0,s.jsx)("rect",{x:"6",y:"4",width:"4",height:"16"}),(0,s.jsx)("rect",{x:"14",y:"4",width:"4",height:"16"})]})}function r1(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,s.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),(0,s.jsx)("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]})}function r2(e){let{isConnected:t,isConnecting:r}=e;return r?(0,s.jsxs)("span",{className:"flex items-center gap-1 px-1.5 py-0.5 rounded-full bg-[#d29922]/20 text-[10px] text-[#d29922] uppercase tracking-wider",children:[(0,s.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-[#d29922] animate-pulse"}),"connecting"]}):t?(0,s.jsxs)("span",{className:"flex items-center gap-1 px-1.5 py-0.5 rounded-full bg-[#238636]/20 text-[10px] text-[#3fb950] uppercase tracking-wider",children:[(0,s.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-[#3fb950] shadow-[0_0_4px_rgba(63,185,80,0.5)]"}),"live"]}):(0,s.jsxs)("span",{className:"flex items-center gap-1 px-1.5 py-0.5 rounded-full bg-[#484f58]/20 text-[10px] text-[#484f58] uppercase tracking-wider",children:[(0,s.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-[#484f58]"}),"offline"]})}function r5(e){let{agentName:t,mode:r="panel",maxHeight:o="500px",showHeader:i=!0,autoScrollDefault:l=!0,onClose:c,onExpand:d,className:x=""}=e,[u,m]=(0,n.useState)(l),h=(0,n.useRef)(null),{logs:p,isConnected:g,isConnecting:b}=function(e){let{agentName:t,maxLines:r=5e3,autoConnect:s=!0,reconnect:a=!0,maxReconnectAttempts:o=1/0}=e,[i,l]=(0,n.useState)([]),[c,d]=(0,n.useState)(!1),[x,u]=(0,n.useState)(!1),[m,h]=(0,n.useState)(null),p=(0,n.useRef)(null),g=(0,n.useRef)(0),b=(0,n.useRef)(null),f=(0,n.useRef)(t),j=(0,n.useRef)(!0),y=(0,n.useRef)(!1),v=(0,n.useRef)(new WeakMap),w=(0,n.useRef)(new WeakMap);f.current=t;let N=(0,n.useCallback)(()=>{var e,t;if(j.current=!0,(null===(e=p.current)||void 0===e?void 0:e.readyState)===WebSocket.OPEN||(null===(t=p.current)||void 0===t?void 0:t.readyState)===WebSocket.CONNECTING||y.current)return;y.current=!0,u(!0),h(null);let s=function(e){let t="/ws/logs/".concat(encodeURIComponent(e)),r="https:"===window.location.protocol?"wss:":"ws:",{hostname:s,port:n}=window.location;return"".concat(r,"//").concat(window.location.host).concat(t)}(f.current);try{let e=new WebSocket(s);p.current=e,v.current.set(e,!1),w.current.set(e,!1),e.onopen=()=>{y.current=!1,d(!0),u(!1),h(null),g.current=0,l(e=>[...e,{id:rO(),timestamp:Date.now(),content:"Connected to ".concat(f.current," log stream"),type:"system",agentName:f.current}])},e.onclose=t=>{var r,s;let n=null!==(r=v.current.get(e))&&void 0!==r&&r,i=null!==(s=w.current.get(e))&&void 0!==s&&s;if(y.current=!1,d(!1),u(!1),p.current=null,b.current&&(clearTimeout(b.current),b.current=null),!n&&4404!==t.code){if(!t.wasClean&&i){let e=j.current&&a&&g.current<o;l(r=>[...r,{id:rO(),timestamp:Date.now(),content:e?"Lost connection to log stream (code: ".concat(t.code,"). Reconnecting..."):"Disconnected from log stream (code: ".concat(t.code,")"),type:"system",agentName:f.current}])}if(j.current&&a&&g.current<o){let e=Math.min(1e3*Math.pow(2,g.current),3e4);g.current++,b.current=setTimeout(()=>{N()},e)}}},e.onerror=()=>{y.current=!1,h(Error("WebSocket connection error")),u(!1)},e.onmessage=t=>{try{let s=JSON.parse(t.data);if("error"===s.type){h(Error(s.error||"Failed to stream logs for ".concat(s.agent||f.current))),l(e=>[...e,{id:rO(),timestamp:Date.now(),content:"Error: ".concat(s.error||"Unknown error"),type:"system",agentName:s.agent||f.current}]);return}if("subscribed"===s.type){console.log("[useAgentLogs] Subscribed to ".concat(s.agent));return}if("history"===s.type&&Array.isArray(s.lines)){s.lines.length>0&&w.current.set(e,!0),l(e=>{let t=s.lines.map(e=>({id:rO(),timestamp:Date.now(),content:e,type:"stdout",agentName:s.agent||f.current}));return[...e,...t].slice(-r)});return}"string"==typeof s?(w.current.set(e,!0),l(e=>[...e,{id:rO(),timestamp:Date.now(),content:s,type:"stdout",agentName:f.current}].slice(-r))):"log"===s.type||"output"===s.type?(w.current.set(e,!0),l(e=>{let t="stderr"===s.stream?"stderr":"stdout";return[...e,{id:rO(),timestamp:s.timestamp||Date.now(),content:s.content||s.data||s.message||"",type:t,agentName:s.agentName||f.current}].slice(-r)})):s.lines&&Array.isArray(s.lines)&&(w.current.set(e,!0),l(e=>{let t=s.lines.map(e=>{let t="object"==typeof e&&"stderr"===e.type?"stderr":"stdout";return{id:rO(),timestamp:Date.now(),content:"string"==typeof e?e:e.content,type:t,agentName:f.current}});return[...e,...t].slice(-r)}))}catch(s){"string"==typeof t.data&&(w.current.set(e,!0),l(e=>[...e,{id:rO(),timestamp:Date.now(),content:t.data,type:"stdout",agentName:f.current}].slice(-r)))}}}catch(e){y.current=!1,h(e instanceof Error?e:Error("Failed to create WebSocket")),u(!1)}},[r,a,o]),k=(0,n.useCallback)(()=>{j.current=!1,b.current&&(clearTimeout(b.current),b.current=null),p.current&&(v.current.set(p.current,!0),p.current.close(),p.current=null),y.current=!1,d(!1),u(!1)},[]),C=(0,n.useCallback)(()=>{l([])},[]);return(0,n.useEffect)(()=>(s&&t&&N(),()=>{k()}),[t,s,N,k]),{logs:i,isConnected:c,isConnecting:x,error:m,connect:N,disconnect:k,clear:C}}({agentName:t,autoConnect:!0}),f=(0,a.GW)(t),j=(0,n.useMemo)(()=>p.filter(e=>{let t=r6(e.content).trim();return 0!==t.length&&!(t.length<=2&&/^[⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏⣾⣽⣻⢿⡿⣟⣯⣷◐◓◑◒●○◉◎|\\\/\-*.\u2800-\u28FF]+$/.test(t))}),[p]);(0,n.useEffect)(()=>{if(u&&h.current){let e=h.current;e.scrollTop=e.scrollHeight}},[p,u]);let y=(0,n.useCallback)(()=>{if(!h.current)return;let e=h.current,t=e.scrollHeight-e.scrollTop-e.clientHeight<50;t&&!u?m(!0):!t&&u&&m(!1)},[u]);return"inline"===r?(0,s.jsxs)("div",{className:"log-viewer-inline rounded-lg overflow-hidden border border-[#2a2d35] ".concat(x),style:{background:"linear-gradient(180deg, #0d0f14 0%, #12151c 100%)",boxShadow:"inset 0 1px 0 rgba(255,255,255,0.02), 0 4px 12px rgba(0,0,0,0.3)"},children:[(0,s.jsxs)("div",{className:"flex items-center justify-between px-3 py-2 border-b border-[#2a2d35]",style:{background:"linear-gradient(180deg, #161b22 0%, #0d1117 100%)"},children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(r8,{}),(0,s.jsx)("span",{className:"text-xs font-medium",style:{color:f.primary},children:"Live logs"}),(0,s.jsx)(r3,{isConnected:g,isConnecting:b})]}),(0,s.jsx)("div",{className:"flex items-center gap-1",children:(0,s.jsx)("button",{className:"p-1.5 rounded-lg hover:bg-[#21262d] text-[#8b949e] hover:text-accent-cyan transition-all duration-200 hover:shadow-[0_0_8px_rgba(0,217,255,0.15)]",onClick:d,title:"Expand",children:(0,s.jsx)(r9,{})})})]}),(0,s.jsxs)("div",{className:"font-mono text-xs leading-relaxed p-3 overflow-y-auto",style:{maxHeight:"150px"},ref:h,onScroll:y,children:[j.slice(-20).map(e=>(0,s.jsx)(r4,{log:e,compact:!0},e.id)),0===j.length&&(0,s.jsxs)("div",{className:"text-[#484f58] italic flex items-center gap-2",children:[(0,s.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-[#484f58] animate-pulse"}),"Waiting for output..."]})]})]}):(0,s.jsx)(rX,{agentName:t,maxHeight:o,showHeader:i,onClose:c,className:x})}function r4(e){let{log:t,compact:r=!1}=e,n=r6(t.content);return(0,s.jsx)("div",{className:"".concat((()=>{switch(t.type){case"stderr":return"text-[#f85149]";case"system":return"text-[#58a6ff] italic";case"input":return"text-[#d29922]";default:return"text-[#c9d1d9]"}})()," leading-5 whitespace-pre-wrap break-all min-w-0 overflow-hidden"),children:n})}function r3(e){let{isConnected:t,isConnecting:r}=e;return r?(0,s.jsxs)("span",{className:"flex items-center gap-1 px-1.5 py-0.5 rounded-full bg-[#d29922]/20 text-[10px] text-[#d29922] uppercase tracking-wider",children:[(0,s.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-[#d29922] animate-pulse"}),"connecting"]}):t?(0,s.jsxs)("span",{className:"flex items-center gap-1 px-1.5 py-0.5 rounded-full bg-[#238636]/20 text-[10px] text-[#3fb950] uppercase tracking-wider",children:[(0,s.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-[#3fb950] shadow-[0_0_4px_rgba(63,185,80,0.5)]"}),"live"]}):(0,s.jsxs)("span",{className:"flex items-center gap-1 px-1.5 py-0.5 rounded-full bg-[#484f58]/20 text-[10px] text-[#484f58] uppercase tracking-wider",children:[(0,s.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-[#484f58]"}),"offline"]})}function r6(e){if(!e)return"";let t=e;return(t=(t=(t=(t=(t=(t=(t=(t=(t=t.replace(RegExp("\\x1b\\].*?(?:\\x07|\\x1b\\\\)","gs"),"")).replace(RegExp("\\x1bP.*?\\x1b\\\\","gs"),"")).replace(/\x1b\[[0-9;?]*[ -/]*[@-~]/g,"")).replace(/\x1b[@-Z\\-_]/g,"")).replace(/^\[\??\d+[hlKJHfABCDGPXsu]/gm,"")).replace(/\[\d+(?:;\d+)*m/g,"")).replace(/\r/g,"")).replace(/.\x08/g,"")).replace(/\x08+/g,"")).replace(/[\x00-\x08\x0B\x0C\x0E-\x1F]/g,"")}function r8(e){let{size:t=16}=e;return(0,s.jsxs)("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-[#8b949e]",children:[(0,s.jsx)("polyline",{points:"4 17 10 11 4 5"}),(0,s.jsx)("line",{x1:"12",y1:"19",x2:"20",y2:"19"})]})}function r9(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("polyline",{points:"15 3 21 3 21 9"}),(0,s.jsx)("polyline",{points:"9 21 3 21 3 15"}),(0,s.jsx)("line",{x1:"21",y1:"3",x2:"14",y2:"10"}),(0,s.jsx)("line",{x1:"3",y1:"21",x2:"10",y2:"14"})]})}function r7(e){let{agent:t,position:r="right",isOpen:o,onClose:i,onAgentChange:l,availableAgents:c=[]}=e,d=(0,a.GW)(t.name),[x,u]=(0,n.useState)(!0);return((0,n.useEffect)(()=>{let e=e=>{"Escape"===e.key&&o&&i()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[o,i]),(0,n.useEffect)(()=>{if(o&&"fullscreen"===r)return document.body.style.overflow="hidden",()=>{document.body.style.overflow=""}},[o,r]),o)?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"fixed inset-0 bg-black/60 z-[1099] animate-fade-in",onClick:i}),(0,s.jsxs)("div",{className:"flex flex-col ".concat((()=>{switch(r){case"right":return"animate-slide-in-right";case"bottom":return"animate-slide-in-bottom";case"fullscreen":return"animate-fade-in"}})()),style:(()=>{let e={position:"fixed",zIndex:1100,background:"linear-gradient(180deg, #0d0f14 0%, #0a0c10 100%)"};switch(r){case"right":return{...e,top:0,right:0,bottom:0,width:"600px",maxWidth:"100vw",borderLeft:"1px solid #21262d",boxShadow:"-20px 0 60px rgba(0, 0, 0, 0.5)"};case"bottom":return{...e,left:0,right:0,bottom:0,height:"400px",maxHeight:"60vh",borderTop:"1px solid #21262d",boxShadow:"0 -20px 60px rgba(0, 0, 0, 0.5)"};case"fullscreen":return{...e,inset:0}}})(),children:[(0,s.jsxs)("div",{className:"flex items-center justify-between border-b border-[#21262d] transition-all duration-200 ".concat(x?"px-4 py-2":"px-5 py-4"),style:{background:"linear-gradient(180deg, #161b22 0%, #0d1117 100%)"},children:[(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsx)("button",{className:"p-1 rounded-md text-[#8b949e] hover:text-[#c9d1d9] hover:bg-[#21262d] transition-colors",onClick:()=>u(!x),title:x?"Expand header":"Collapse header",children:(0,s.jsx)(si,{collapsed:x})}),(0,s.jsxs)("div",{className:"relative shrink-0 rounded-xl flex items-center justify-center font-bold overflow-hidden transition-all duration-200 ".concat(x?"w-8 h-8 text-xs":"w-11 h-11 text-sm"),style:{backgroundColor:d.primary,color:d.text,boxShadow:x?"0 0 12px ".concat(d.primary,"40"):"0 0 24px ".concat(d.primary,"50, inset 0 1px 0 rgba(255,255,255,0.2)")},children:[(0,s.jsx)("div",{className:"absolute inset-0 opacity-30",style:{background:"linear-gradient(135deg, rgba(255,255,255,0.35) 0%, transparent 50%)"}}),(0,s.jsx)("span",{className:"relative z-10",children:(0,a.hP)(t.name)})]}),x?(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:"text-sm font-semibold",style:{color:d.primary},children:t.name}),(0,s.jsx)("span",{className:"px-2 py-0.5 rounded text-[9px] uppercase tracking-wider font-medium ".concat("online"===t.status?"bg-[#3fb950]/15 text-[#3fb950]":"busy"===t.status?"bg-[#d29922]/15 text-[#d29922]":"bg-[#484f58]/15 text-[#484f58]"),children:t.status})]}):(0,s.jsxs)("div",{className:"flex flex-col",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2.5",children:[(0,s.jsx)("h2",{className:"text-lg font-semibold m-0",style:{color:d.primary},children:t.name}),(0,s.jsx)("span",{className:"px-2.5 py-0.5 rounded-md text-[10px] uppercase tracking-wider font-medium ".concat("online"===t.status?"bg-[#3fb950]/15 text-[#3fb950]":"busy"===t.status?"bg-[#d29922]/15 text-[#d29922]":"bg-[#484f58]/15 text-[#484f58]"),style:{boxShadow:"online"===t.status?"0 0 8px rgba(63,185,80,0.2)":"none"},children:t.status})]}),t.currentTask&&(0,s.jsx)("span",{className:"text-sm text-[#8b949e] truncate max-w-[300px] mt-0.5",children:t.currentTask})]})]}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[c.length>1&&l&&(0,s.jsx)(se,{agents:c,currentAgent:t,onSelect:l}),(0,s.jsxs)("div",{className:"flex items-center gap-1 bg-[#21262d]/80 rounded-lg p-1 border border-[#30363d]/50",children:[(0,s.jsx)("button",{className:"p-1.5 rounded-md transition-all duration-200 ".concat("right"===r?"bg-accent-cyan/15 text-accent-cyan shadow-[0_0_8px_rgba(0,217,255,0.15)]":"text-[#8b949e] hover:text-[#c9d1d9] hover:bg-[#30363d]"),title:"Sidebar view",children:(0,s.jsx)(sr,{})}),(0,s.jsx)("button",{className:"p-1.5 rounded-md transition-all duration-200 ".concat("bottom"===r?"bg-accent-cyan/15 text-accent-cyan shadow-[0_0_8px_rgba(0,217,255,0.15)]":"text-[#8b949e] hover:text-[#c9d1d9] hover:bg-[#30363d]"),title:"Bottom panel",children:(0,s.jsx)(ss,{})}),(0,s.jsx)("button",{className:"p-1.5 rounded-md transition-all duration-200 ".concat("fullscreen"===r?"bg-accent-cyan/15 text-accent-cyan shadow-[0_0_8px_rgba(0,217,255,0.15)]":"text-[#8b949e] hover:text-[#c9d1d9] hover:bg-[#30363d]"),title:"Fullscreen",children:(0,s.jsx)(sn,{})})]}),(0,s.jsx)("button",{className:"p-2 rounded-lg text-[#8b949e] hover:text-[#f85149] hover:bg-[#f85149]/10 transition-all duration-200 hover:shadow-[0_0_8px_rgba(248,81,73,0.2)]",onClick:i,children:(0,s.jsx)(st,{})})]})]}),(0,s.jsx)("div",{className:"flex-1 min-h-0",children:(0,s.jsx)(r5,{agentName:t.name,mode:"panel",showHeader:!1,maxHeight:"100%",className:"h-full rounded-none border-none"})})]}),(0,s.jsx)("style",{children:"\n @keyframes slideInRight {\n from {\n transform: translateX(100%);\n opacity: 0;\n }\n to {\n transform: translateX(0);\n opacity: 1;\n }\n }\n\n @keyframes slideInBottom {\n from {\n transform: translateY(100%);\n opacity: 0;\n }\n to {\n transform: translateY(0);\n opacity: 1;\n }\n }\n\n .animate-slide-in-right {\n animation: slideInRight 0.3s cubic-bezier(0.32, 0.72, 0, 1);\n }\n\n .animate-slide-in-bottom {\n animation: slideInBottom 0.3s cubic-bezier(0.32, 0.72, 0, 1);\n }\n "})]}):null}function se(e){let{agents:t,currentAgent:r,onSelect:o}=e,[i,l]=n.useState(!1),c=n.useRef(null);return(0,n.useEffect)(()=>{let e=e=>{c.current&&!c.current.contains(e.target)&&l(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,s.jsxs)("div",{className:"relative",ref:c,children:[(0,s.jsxs)("button",{className:"flex items-center gap-2 px-3 py-1.5 bg-[#21262d] hover:bg-[#30363d] rounded-lg text-sm text-[#c9d1d9] transition-colors",onClick:()=>l(!i),children:[(0,s.jsx)("span",{children:"Switch agent"}),(0,s.jsx)(sa,{})]}),i&&(0,s.jsx)("div",{className:"absolute right-0 top-full mt-2 w-64 bg-[#161b22] border border-[#30363d] rounded-lg shadow-xl overflow-hidden z-10",children:(0,s.jsx)("div",{className:"max-h-64 overflow-y-auto",children:t.map(e=>{let t=(0,a.GW)(e.name),n=e.name===r.name;return(0,s.jsxs)("button",{className:"w-full flex items-center gap-3 px-3 py-2 text-left transition-colors ".concat(n?"bg-[#238636]/20":"hover:bg-[#21262d]"),onClick:()=>{o(e),l(!1)},children:[(0,s.jsx)("div",{className:"w-8 h-8 rounded flex items-center justify-center text-xs font-semibold shrink-0",style:{backgroundColor:t.primary,color:t.text},children:(0,a.hP)(e.name)}),(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsx)("div",{className:"text-sm text-[#c9d1d9] truncate",children:e.name}),(0,s.jsx)("div",{className:"text-xs text-[#8b949e]",children:e.status})]}),n&&(0,s.jsx)(so,{})]},e.name)})})})]})}function st(){return(0,s.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function sr(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),(0,s.jsx)("line",{x1:"15",y1:"3",x2:"15",y2:"21"})]})}function ss(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),(0,s.jsx)("line",{x1:"3",y1:"15",x2:"21",y2:"15"})]})}function sn(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("polyline",{points:"15 3 21 3 21 9"}),(0,s.jsx)("polyline",{points:"9 21 3 21 3 15"}),(0,s.jsx)("line",{x1:"21",y1:"3",x2:"14",y2:"10"}),(0,s.jsx)("line",{x1:"3",y1:"21",x2:"10",y2:"14"})]})}function sa(){return(0,s.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.jsx)("polyline",{points:"6 9 12 15 18 9"})})}function so(){return(0,s.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"#3fb950",strokeWidth:"2",children:(0,s.jsx)("polyline",{points:"20 6 9 17 4 12"})})}function si(e){let{collapsed:t}=e;return(0,s.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"transition-transform duration-200 ".concat(t?"":"rotate-90"),children:(0,s.jsx)("polyline",{points:"9 18 15 12 9 6"})})}function sl(e){let{agentName:t,steps:r,history:a=[],selectedTrajectoryId:o,onSelectTrajectory:i,isLoading:l=!1,onStepClick:c,compact:d=!1}=e,[x,u]=(0,n.useState)(new Set),[m,h]=(0,n.useState)("all"),p=(0,n.useMemo)(()=>"all"===m?r:r.filter(e=>e.type===m),[r,m]),g=e=>{u(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},b=[{value:"all",label:"All",icon:(0,s.jsx)(su,{})},{value:"tool_call",label:"Tools",icon:(0,s.jsx)(sm,{})},{value:"decision",label:"Decisions",icon:(0,s.jsx)(sh,{})},{value:"message",label:"Messages",icon:(0,s.jsx)(sp,{})},{value:"state_change",label:"State",icon:(0,s.jsx)(sg,{})},{value:"phase_transition",label:"Phases",icon:(0,s.jsx)(sb,{})},{value:"error",label:"Errors",icon:(0,s.jsx)(sf,{})}],f=(0,n.useMemo)(()=>{let e=r.filter(e=>e.phase).reduce((e,t)=>(t.phase&&(e[t.phase]=(e[t.phase]||0)+1),e),{}),t=Object.values(e).reduce((e,t)=>e+t,0);return{phases:e,total:t}},[r]);return(0,s.jsxs)("div",{className:"h-full flex flex-col bg-gradient-to-b from-bg-card to-bg-tertiary rounded-xl border border-border/50 overflow-hidden shadow-lg backdrop-blur-sm",children:[(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsx)("div",{className:"absolute top-0 left-0 right-0 h-[2px] bg-gradient-to-r from-blue-500 via-accent-cyan to-blue-500 opacity-60"}),(0,s.jsxs)("div",{className:"flex items-center justify-between px-5 py-4 border-b border-border/30",children:[(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[o&&i&&(0,s.jsxs)("button",{onClick:()=>i(null),className:"flex items-center gap-1.5 px-2 py-1.5 text-[11px] font-medium text-text-muted hover:text-accent-cyan bg-bg-elevated/50 hover:bg-bg-elevated rounded-lg border border-border/30 hover:border-accent-cyan/30 transition-all duration-200",title:"Back to trajectory list",children:[(0,s.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:(0,s.jsx)("path",{d:"M19 12H5M12 19l-7-7 7-7",strokeLinecap:"round",strokeLinejoin:"round"})}),(0,s.jsx)("span",{children:"List"})]}),(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsx)("div",{className:"w-9 h-9 rounded-lg bg-gradient-to-br from-blue-500/20 to-accent-cyan/20 flex items-center justify-center border border-blue-500/30",children:(0,s.jsx)(sx,{})}),r.some(e=>"running"===e.status)&&(0,s.jsx)("span",{className:"absolute -top-1 -right-1 w-3 h-3 bg-accent-cyan rounded-full animate-pulse shadow-[0_0_8px_rgba(0,217,255,0.6)]"})]}),(0,s.jsxs)("div",{className:"flex flex-col",children:[(0,s.jsx)("span",{className:"font-semibold text-sm text-text-primary tracking-wide",children:"Trajectory"}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsxs)("span",{className:"text-[11px] text-text-muted font-mono",children:[r.length," ",1===r.length?"step":"steps"]}),t&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("span",{className:"text-text-dim",children:"|"}),(0,s.jsx)("span",{className:"text-[11px] text-accent-cyan/80 font-medium truncate max-w-[120px]",children:t})]})]})]})]}),f.total>0&&!d&&(0,s.jsx)("div",{className:"flex items-center gap-1.5",children:["plan","design","execute","review","observe"].map(e=>{let t=f.phases[e]||0,r=sd(e);return t>0?(0,s.jsx)("div",{className:"h-1.5 rounded-full transition-all duration-300",style:{width:"".concat(Math.max(8,t/f.total*48),"px"),backgroundColor:r||"var(--color-border)"},title:"".concat(e,": ").concat(t)},e):null})})]}),!d&&(0,s.jsx)("div",{className:"flex items-center gap-1 px-4 py-2 bg-bg-elevated/50 border-b border-border/20 overflow-x-auto scrollbar-thin",children:b.map(e=>(0,s.jsxs)("button",{className:"flex items-center gap-1.5 px-3 py-1.5 text-[11px] font-medium rounded-lg transition-all duration-200 whitespace-nowrap ".concat(m===e.value?"bg-blue-500/20 text-blue-500 border border-blue-500/30 shadow-[0_0_12px_rgba(59,130,246,0.15)]":"text-text-muted hover:text-text-secondary hover:bg-bg-hover/50"),onClick:()=>h(e.value),children:[(0,s.jsx)("span",{className:"opacity-70",children:e.icon}),e.label]},e.value))})]}),(0,s.jsx)("div",{className:"flex-1 min-h-0 overflow-y-auto px-4 py-3 scrollbar-thin scrollbar-thumb-border scrollbar-track-transparent",children:l?(0,s.jsxs)("div",{className:"flex flex-col items-center justify-center gap-4 py-12 text-text-muted",children:[(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsx)(sv,{}),(0,s.jsx)("div",{className:"absolute inset-0 bg-accent-cyan/10 rounded-full blur-xl"})]}),(0,s.jsx)("span",{className:"text-sm font-medium",children:"Loading trajectory..."})]}):0===p.length?(0,s.jsx)("div",{className:"flex flex-col gap-4 py-4 text-text-muted",children:0===r.length&&a.length>0?(0,s.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between px-2",children:[(0,s.jsx)("span",{className:"text-xs font-medium text-text-secondary uppercase tracking-wider",children:"Recent Trajectories"}),o&&i&&(0,s.jsx)("button",{onClick:()=>i(null),className:"text-[10px] text-accent-cyan hover:underline",children:"← Back to current"})]}),(0,s.jsx)("div",{className:"flex flex-col gap-1",children:a.slice(0,10).map(e=>(0,s.jsxs)("button",{onClick:()=>null==i?void 0:i(e.id),className:"w-full text-left px-3 py-2.5 rounded-lg transition-all duration-200 border ".concat(o===e.id?"bg-blue-500/15 border-blue-500/40 text-text-primary":"bg-bg-tertiary/50 border-transparent hover:bg-bg-elevated/60 hover:border-border/40"),children:[(0,s.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,s.jsx)("span",{className:"text-[13px] font-medium text-text-primary truncate flex-1",children:e.title}),(0,s.jsx)("span",{className:"text-[10px] px-1.5 py-0.5 rounded font-medium flex-shrink-0 ".concat("completed"===e.status?"bg-green-500/15 text-green-500":"active"===e.status?"bg-blue-500/15 text-blue-500":"bg-amber-500/15 text-amber-500"),children:e.status})]}),(0,s.jsxs)("div",{className:"flex items-center gap-2 mt-1",children:[(0,s.jsx)("span",{className:"text-[10px] text-text-dim",children:function(e){let t=new Date(e),r=new Date().getTime()-t.getTime(),s=Math.floor(r/6e4),n=Math.floor(r/36e5),a=Math.floor(r/864e5);return s<1?"just now":s<60?"".concat(s,"m ago"):n<24?"".concat(n,"h ago"):a<7?"".concat(a,"d ago"):t.toLocaleDateString()}(e.startedAt)}),e.confidence&&(0,s.jsxs)("span",{className:"text-[10px] text-text-dim",children:["• ",Math.round(100*e.confidence),"% confidence"]})]}),e.summary&&(0,s.jsx)("p",{className:"text-[11px] text-text-muted mt-1 line-clamp-2",children:e.summary})]},e.id))})]}):0===r.length?(0,s.jsxs)("div",{className:"flex flex-col items-center justify-center gap-4 py-8",children:[(0,s.jsx)("div",{className:"w-16 h-16 rounded-2xl bg-bg-elevated/50 flex items-center justify-center border border-border/30",children:(0,s.jsx)(sy,{})}),(0,s.jsxs)("div",{className:"text-center",children:[(0,s.jsx)("p",{className:"text-sm font-medium text-text-secondary",children:"No steps recorded"}),(0,s.jsx)("p",{className:"text-xs text-text-dim mt-1",children:"Steps will appear here as the agent works"})]})]}):(0,s.jsxs)("div",{className:"flex flex-col items-center justify-center gap-4 py-8",children:[(0,s.jsx)("div",{className:"w-16 h-16 rounded-2xl bg-bg-elevated/50 flex items-center justify-center border border-border/30",children:(0,s.jsx)(sy,{})}),(0,s.jsxs)("div",{className:"text-center",children:[(0,s.jsx)("p",{className:"text-sm font-medium text-text-secondary",children:"No matching steps"}),(0,s.jsx)("p",{className:"text-xs text-text-dim mt-1",children:'Try a different filter or select "All"'})]})]})}):(0,s.jsx)("div",{className:"flex flex-col gap-0.5",children:p.map((e,t)=>(0,s.jsx)(sc,{step:e,isExpanded:x.has(e.id),isLast:t===p.length-1,isFirst:0===t,compact:d,onToggle:()=>g(e.id),onClick:c?()=>c(e):void 0},e.id))})})]})}function sc(e){var t;let{step:r,isExpanded:n,isLast:a,isFirst:o=!1,compact:i=!1,onToggle:l,onClick:c}=e,d=new Date(r.timestamp).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"}),x=function(e){switch(e){case"tool_call":return(0,s.jsx)(sm,{});case"decision":return(0,s.jsx)(sh,{});case"message":return(0,s.jsx)(sp,{});case"state_change":return(0,s.jsx)(sg,{});case"phase_transition":return(0,s.jsx)(sb,{});case"error":return(0,s.jsx)(sf,{});default:return null}}(r.type),u=function(e){switch(e){case"running":return"#ff6b35";case"success":return"#00ffc8";case"error":return"#ff4757";default:return null}}(r.status),m=sd(r.phase),h=function(e){switch(e){case"tool_call":return"#00d9ff";case"decision":case"message":return"#3b82f6";case"state_change":return"#10b981";case"phase_transition":return"#f59e0b";case"error":return"#ef4444";default:return"#6b7280"}}(r.type),p=r.metadata&&Object.keys(r.metadata).length>0,g=!!r.description||p||!!c;return(0,s.jsxs)("div",{className:"flex gap-3 group",children:[(0,s.jsxs)("div",{className:"flex flex-col items-center w-7 relative",children:[!o&&(0,s.jsx)("div",{className:"absolute top-0 w-px h-2 transition-colors",style:{backgroundColor:m?"".concat(m,"40"):"var(--color-border)"}}),(0,s.jsx)("div",{className:"w-7 h-7 rounded-lg flex items-center justify-center flex-shrink-0 z-10 mt-2 transition-all duration-200 ".concat("running"===r.status?"animate-pulse shadow-[0_0_12px_rgba(0,217,255,0.4)]":"group-hover:scale-110"),style:{background:u?"linear-gradient(135deg, ".concat(u,"40, ").concat(u,"20)"):m?"linear-gradient(135deg, ".concat(m,"30, ").concat(m,"10)"):"linear-gradient(135deg, ".concat(h,"30, ").concat(h,"10)"),borderWidth:"1px",borderStyle:"solid",borderColor:u||m||h||"var(--color-border)",color:u||m||h||"var(--color-text-secondary)"},children:x}),!a&&(0,s.jsx)("div",{className:"w-px flex-1 mt-1 transition-colors",style:{background:"linear-gradient(to bottom, ".concat(m||h||"var(--color-border)","40, transparent)")}})]}),(0,s.jsxs)("div",{className:"flex-1 min-w-0 pt-1 ".concat(a?"pb-1":"pb-3"),children:[(0,s.jsxs)("button",{className:"w-full flex items-center justify-between gap-3 px-3 py-2.5 rounded-lg transition-all duration-200 text-left border ".concat(n?"bg-bg-elevated/80 border-border/60 shadow-sm":"bg-bg-tertiary/50 border-transparent hover:bg-bg-elevated/60 hover:border-border/40"),onClick:l,children:[(0,s.jsxs)("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[(0,s.jsx)("span",{className:"text-[13px] font-medium text-text-primary truncate",children:r.title}),(0,s.jsx)("span",{className:"text-[10px] px-1.5 py-0.5 rounded font-medium flex-shrink-0",style:{backgroundColor:"".concat(h,"15"),color:h},children:{tool_call:"Tool",decision:"Decision",message:"Message",state_change:"State",phase_transition:"Phase",error:"Error"}[r.type]}),r.phase&&m&&(0,s.jsx)("span",{className:"text-[10px] px-1.5 py-0.5 rounded font-medium flex-shrink-0",style:{backgroundColor:"".concat(m,"15"),color:m},children:r.phase})]}),(0,s.jsxs)("div",{className:"flex items-center gap-2 flex-shrink-0",children:[void 0!==r.duration&&(0,s.jsx)("span",{className:"text-[10px] font-mono text-text-muted px-1.5 py-0.5 bg-bg-elevated/50 rounded",children:(t=r.duration)<1e3?"".concat(t,"ms"):t<6e4?"".concat((t/1e3).toFixed(1),"s"):"".concat((t/6e4).toFixed(1),"m")}),(0,s.jsx)("span",{className:"text-[10px] text-text-dim",children:d}),!i&&(0,s.jsx)(sj,{isExpanded:n})]})]}),n&&!i&&g&&(0,s.jsxs)("div",{className:"mt-2 ml-1 pl-3 border-l-2 border-border/30",children:[r.description&&(0,s.jsx)("p",{className:"text-[13px] text-text-secondary mb-3 leading-relaxed",children:r.description}),p&&(0,s.jsx)("div",{className:"bg-bg-elevated/50 rounded-lg p-3 mb-3 overflow-x-auto border border-border/20",children:(0,s.jsx)("pre",{className:"text-[11px] font-mono text-text-muted whitespace-pre-wrap break-words leading-relaxed",children:JSON.stringify(r.metadata,null,2)})}),c&&(0,s.jsxs)("button",{className:"inline-flex items-center gap-1.5 px-3 py-1.5 text-[11px] font-medium text-accent-cyan bg-accent-cyan/10 border border-accent-cyan/20 rounded-md hover:bg-accent-cyan/20 hover:border-accent-cyan/30 transition-colors",onClick:e=>{e.stopPropagation(),c()},children:[(0,s.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[(0,s.jsx)("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"}),(0,s.jsx)("polyline",{points:"15 3 21 3 21 9"}),(0,s.jsx)("line",{x1:"10",y1:"14",x2:"21",y2:"3"})]}),"View Details"]})]})]})]})}function sd(e){switch(e){case"plan":return"#3b82f6";case"design":return"#00d9ff";case"execute":return"#ff6b35";case"review":return"#00ffc8";case"observe":return"#fbbf24";default:return null}}function sx(){return(0,s.jsx)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"text-blue-500",children:(0,s.jsx)("path",{d:"M3 12h4l3 9 4-18 3 9h4",strokeLinecap:"round",strokeLinejoin:"round"})})}function su(){return(0,s.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"3"}),(0,s.jsx)("path",{d:"M12 2v4m0 12v4m-7.07-14.93l2.83 2.83m8.48 8.48l2.83 2.83M2 12h4m12 0h4M4.93 19.07l2.83-2.83m8.48-8.48l2.83-2.83"})]})}function sm(){return(0,s.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.jsx)("path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z"})})}function sh(){return(0,s.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.jsx)("path",{d:"M12 2l2.4 7.4H22l-6 4.6 2.3 7-6.3-4.6L5.7 21l2.3-7-6-4.6h7.6z"})})}function sp(){return(0,s.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.jsx)("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}function sg(){return(0,s.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"}),(0,s.jsx)("path",{d:"M9 12h6m-3-3v6"})]})}function sb(){return(0,s.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,s.jsx)("path",{d:"M12 6v6l4 2"})]})}function sf(){return(0,s.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,s.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),(0,s.jsx)("circle",{cx:"12",cy:"16",r:"0.5",fill:"currentColor"})]})}function sj(e){let{isExpanded:t}=e;return(0,s.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-text-muted transition-transform duration-200 ".concat(t?"rotate-180":""),children:(0,s.jsx)("polyline",{points:"6 9 12 15 18 9"})})}function sy(){return(0,s.jsxs)("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"text-text-dim",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,s.jsx)("line",{x1:"8",y1:"12",x2:"16",y2:"12"})]})}function sv(){return(0,s.jsx)("svg",{className:"animate-spin",width:"20",height:"20",viewBox:"0 0 24 24",children:(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeDasharray:"32",strokeLinecap:"round",className:"text-accent"})})}function sw(e){let{decisions:t,onApprove:r,onReject:a,onDismiss:o,isProcessing:i={}}=e,[l,c]=(0,n.useState)(null),[d,x]=(0,n.useState)({}),u=(0,n.useMemo)(()=>{let e={critical:0,high:1,medium:2,low:3};return[...t].sort((t,r)=>{let s=e[t.priority]-e[r.priority];return 0!==s?s:new Date(t.timestamp).getTime()-new Date(r.timestamp).getTime()})},[t]),m=(0,n.useMemo)(()=>t.reduce((e,t)=>(e[t.priority]=(e[t.priority]||0)+1,e),{}),[t]),h=async(e,t)=>{await (null==r?void 0:r(e.id,t))},p=async e=>{await (null==a?void 0:a(e.id,d[e.id])),x(t=>{let r={...t};return delete r[e.id],r})};return 0===t.length?(0,s.jsxs)("div",{className:"decision-queue decision-queue-empty",children:[(0,s.jsx)(sS,{}),(0,s.jsx)("span",{children:"No pending decisions"})]}):(0,s.jsxs)("div",{className:"decision-queue",children:[(0,s.jsxs)("div",{className:"decision-queue-header",children:[(0,s.jsxs)("div",{className:"decision-queue-title",children:[(0,s.jsx)(sC,{}),(0,s.jsx)("span",{children:"Pending Decisions"}),(0,s.jsx)("span",{className:"decision-queue-count",children:t.length})]}),(0,s.jsxs)("div",{className:"decision-queue-summary",children:[m.critical&&(0,s.jsxs)("span",{className:"decision-priority-badge critical",children:[m.critical," critical"]}),m.high&&(0,s.jsxs)("span",{className:"decision-priority-badge high",children:[m.high," high"]})]})]}),(0,s.jsx)("div",{className:"decision-queue-list",children:u.map(e=>(0,s.jsx)(sN,{decision:e,isExpanded:l===e.id,isProcessing:i[e.id]||!1,rejectReason:d[e.id]||"",onToggle:()=>c(t=>t===e.id?null:e.id),onApprove:t=>h(e,t),onReject:()=>p(e),onRejectReasonChange:t=>x(r=>({...r,[e.id]:t})),onDismiss:()=>null==o?void 0:o(e.id)},e.id))})]})}function sN(e){let{decision:t,isExpanded:r,isProcessing:n,rejectReason:o,onToggle:i,onApprove:l,onReject:c,onRejectReasonChange:d,onDismiss:x}=e,u=(0,a.GW)(t.agentName),m=function(e){let t=new Date(e),r=Math.floor((new Date().getTime()-t.getTime())/6e4);return r<1?"just now":r<60?"".concat(r,"m ago"):r<1440?"".concat(Math.floor(r/60),"h ago"):t.toLocaleDateString()}(t.timestamp),h=t.expiresAt?function(e){let t=new Date(e),r=new Date,s=t.getTime()-r.getTime();if(s<=0)return{text:"Expired",urgent:!0};let n=Math.floor(s/6e4);return n<5?{text:"".concat(n,"m left"),urgent:!0}:n<60?{text:"".concat(n,"m left"),urgent:!1}:{text:"".concat(Math.floor(n/60),"h left"),urgent:!1}}(t.expiresAt):null;return(0,s.jsxs)("div",{className:"decision-card ".concat(t.priority),children:[(0,s.jsxs)("div",{className:"decision-card-header",onClick:i,children:[(0,s.jsx)("div",{className:"decision-card-avatar",style:{backgroundColor:u.primary,color:u.text},children:(0,a.hP)(t.agentName)}),(0,s.jsxs)("div",{className:"decision-card-info",children:[(0,s.jsxs)("div",{className:"decision-card-title",children:[(0,s.jsx)("span",{className:"decision-card-agent",children:t.agentName}),(0,s.jsx)("span",{className:"decision-card-type",children:{approval:"Approval",choice:"Choice",confirmation:"Confirm",input:"Input"}[t.type]}),(0,s.jsx)(sk,{priority:t.priority})]}),(0,s.jsx)("div",{className:"decision-card-subtitle",children:t.title})]}),(0,s.jsxs)("div",{className:"decision-card-meta",children:[h&&(0,s.jsx)("span",{className:"decision-card-expires ".concat(h.urgent?"urgent":""),children:h.text}),(0,s.jsx)("span",{className:"decision-card-time",children:m}),(0,s.jsx)(sL,{isExpanded:r})]})]}),r&&(0,s.jsxs)("div",{className:"decision-card-body",children:[(0,s.jsx)("p",{className:"decision-card-desc",children:t.description}),t.context&&Object.keys(t.context).length>0&&(0,s.jsxs)("div",{className:"decision-card-context",children:[(0,s.jsx)("span",{className:"decision-card-context-label",children:"Context"}),(0,s.jsx)("pre",{children:JSON.stringify(t.context,null,2)})]}),"choice"===t.type&&t.options&&(0,s.jsx)("div",{className:"decision-card-options",children:t.options.map(e=>(0,s.jsxs)("button",{className:"decision-card-option",onClick:()=>l(e.id),disabled:n,children:[(0,s.jsx)("span",{className:"decision-option-label",children:e.label}),e.description&&(0,s.jsx)("span",{className:"decision-option-desc",children:e.description})]},e.id))}),"choice"!==t.type&&(0,s.jsxs)("div",{className:"decision-card-actions",children:[(0,s.jsxs)("button",{className:"decision-btn decision-btn-approve",onClick:()=>l(),disabled:n,children:[n?(0,s.jsx)(sE,{}):(0,s.jsx)(sS,{}),"confirmation"===t.type?"Confirm":"Approve"]}),(0,s.jsxs)("div",{className:"decision-reject-group",children:[(0,s.jsx)("input",{type:"text",className:"decision-reject-input",placeholder:"Reason (optional)",value:o,onChange:e=>d(e.target.value),disabled:n}),(0,s.jsxs)("button",{className:"decision-btn decision-btn-reject",onClick:c,disabled:n,children:[(0,s.jsx)(sA,{}),"Reject"]})]})]}),(0,s.jsx)("button",{className:"decision-card-dismiss",onClick:x,disabled:n,children:"Dismiss without action"})]})]})}function sk(e){let{priority:t}=e;return(0,s.jsx)("span",{className:"decision-priority-badge ".concat(t),children:t})}function sC(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,s.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),(0,s.jsx)("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]})}function sS(){return(0,s.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.jsx)("polyline",{points:"20 6 9 17 4 12"})})}function sA(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function sL(e){let{isExpanded:t}=e;return(0,s.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",style:{transform:t?"rotate(180deg)":"rotate(0deg)",transition:"transform 0.2s"},children:(0,s.jsx)("polyline",{points:"6 9 12 15 18 9"})})}function sE(){return(0,s.jsx)("svg",{className:"decision-spinner",width:"14",height:"14",viewBox:"0 0 24 24",children:(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeDasharray:"32",strokeLinecap:"round"})})}function sW(e){var t;let{server:r,isSelected:n=!1,onClick:a,onReconnect:o,compact:i=!1}=e,l=function(e){switch(e){case"online":return"#10b981";case"offline":return"#ef4444";case"degraded":return"#f59e0b";case"connecting":return"#6366f1";default:return"#888888"}}(r.status),c=function(e){switch(e){case"online":return"Online";case"offline":return"Offline";case"degraded":return"Degraded";case"connecting":return"Connecting...";default:return"Unknown"}}(r.status);return i?(0,s.jsxs)("button",{className:"\n flex items-center gap-2 py-2 px-3 bg-bg-tertiary border border-border-subtle rounded-md cursor-pointer font-inherit transition-all duration-150\n hover:bg-bg-hover\n ".concat(n?"bg-bg-elevated border-accent-cyan":"","\n ").concat("offline"===r.status?"opacity-70":"","\n "),onClick:a,children:[(0,s.jsx)("div",{className:"w-2 h-2 rounded-full flex-shrink-0",style:{backgroundColor:l}}),(0,s.jsx)("span",{className:"flex-1 text-sm font-medium text-text-primary text-left",children:r.name}),(0,s.jsx)("span",{className:"text-xs text-text-muted bg-bg-tertiary px-1.5 py-0.5 rounded-full",children:r.agentCount})]}):(0,s.jsxs)("div",{className:"\n bg-bg-card border border-border-subtle rounded-lg p-4 cursor-pointer transition-all duration-150\n hover:border-border-hover hover:shadow-md\n ".concat(n?"border-accent-cyan bg-bg-elevated":"","\n ").concat("offline"===r.status?"opacity-70":"","\n ").concat("degraded"===r.status?"border-l-[3px] border-l-warning":"","\n "),onClick:a,role:a?"button":void 0,tabIndex:a?0:void 0,children:[(0,s.jsxs)("div",{className:"flex items-start justify-between mb-4",children:[(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsx)(sM,{}),(0,s.jsxs)("div",{className:"flex flex-col",children:[(0,s.jsx)("span",{className:"font-semibold text-sm text-text-primary",children:r.name}),r.region&&(0,s.jsx)("span",{className:"text-xs text-text-muted",children:r.region})]})]}),(0,s.jsxs)("div",{className:"flex items-center gap-1.5 text-xs font-medium",style:{color:l},children:[(0,s.jsx)("span",{className:"w-2 h-2 rounded-full flex-shrink-0 ".concat("connecting"===r.status?"animate-pulse":""),style:{backgroundColor:l}}),(0,s.jsx)("span",{children:c})]})]}),(0,s.jsxs)("div",{className:"grid grid-cols-[repeat(auto-fit,minmax(60px,1fr))] gap-3 mb-4",children:[(0,s.jsxs)("div",{className:"flex flex-col items-center text-center",children:[(0,s.jsx)("span",{className:"text-lg font-semibold text-text-primary",children:r.agentCount}),(0,s.jsx)("span",{className:"text-[11px] text-text-muted uppercase tracking-wide",children:"Agents"})]}),void 0!==r.messageRate&&(0,s.jsxs)("div",{className:"flex flex-col items-center text-center",children:[(0,s.jsxs)("span",{className:"text-lg font-semibold text-text-primary",children:[r.messageRate,"/s"]}),(0,s.jsx)("span",{className:"text-[11px] text-text-muted uppercase tracking-wide",children:"Messages"})]}),void 0!==r.latency&&(0,s.jsxs)("div",{className:"flex flex-col items-center text-center",children:[(0,s.jsxs)("span",{className:"text-lg font-semibold text-text-primary",children:[r.latency,"ms"]}),(0,s.jsx)("span",{className:"text-[11px] text-text-muted uppercase tracking-wide",children:"Latency"})]}),void 0!==r.uptime&&(0,s.jsxs)("div",{className:"flex flex-col items-center text-center",children:[(0,s.jsx)("span",{className:"text-lg font-semibold text-text-primary",children:(t=r.uptime)<60?"".concat(t,"s"):t<3600?"".concat(Math.floor(t/60),"m"):t<86400?"".concat(Math.floor(t/3600),"h"):"".concat(Math.floor(t/86400),"d")}),(0,s.jsx)("span",{className:"text-[11px] text-text-muted uppercase tracking-wide",children:"Uptime"})]})]}),(0,s.jsxs)("div",{className:"flex items-center justify-between pt-3 border-t border-border-subtle",children:[(0,s.jsx)("span",{className:"text-[11px] text-text-muted font-mono",children:r.url}),r.version&&(0,s.jsxs)("span",{className:"text-[11px] text-text-muted bg-bg-tertiary px-1.5 py-0.5 rounded",children:["v",r.version]})]}),"offline"===r.status&&o&&(0,s.jsxs)("button",{className:"flex items-center justify-center gap-1.5 w-full mt-3 py-2 px-3 bg-error/10 border border-error/30 rounded-md text-error text-xs font-medium cursor-pointer font-inherit transition-all duration-150 hover:bg-error/20 hover:border-error/50",onClick:e=>{e.stopPropagation(),o()},children:[(0,s.jsx)(sD,{}),"Reconnect"]})]})}function sM(){return(0,s.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("rect",{x:"2",y:"2",width:"20",height:"8",rx:"2",ry:"2"}),(0,s.jsx)("rect",{x:"2",y:"14",width:"20",height:"8",rx:"2",ry:"2"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"6.01",y2:"6"}),(0,s.jsx)("line",{x1:"6",y1:"18",x2:"6.01",y2:"18"})]})}function sD(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("polyline",{points:"23 4 23 10 17 10"}),(0,s.jsx)("polyline",{points:"1 20 1 14 7 14"}),(0,s.jsx)("path",{d:"M3.51 9a9 9 0 0 1 14.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0 0 20.49 15"})]})}function sT(e){let{servers:t,agents:r,selectedServerId:o,onServerSelect:i,onServerReconnect:l,isLoading:c=!1}=e,[d,x]=(0,n.useState)("grid"),u=(0,n.useMemo)(()=>{let e=t.filter(e=>"online"===e.status).length,r=t.reduce((e,t)=>e+t.agentCount,0),s=t.filter(e=>void 0!==e.latency).length>0?Math.round(t.reduce((e,t)=>e+(t.latency||0),0)/t.filter(e=>void 0!==e.latency).length):null,n=t.reduce((e,t)=>e+(t.messageRate||0),0);return{online:e,total:t.length,totalAgents:r,avgLatency:s,totalMessages:n}},[t]),m=(0,n.useMemo)(()=>{let e={};return t.forEach(t=>{e[t.id]=[]}),r.forEach((r,s)=>{let n=s%t.length;t[n]&&e[t[n].id].push(r)}),e},[t,r]);return c?(0,s.jsxs)("div",{className:"bg-bg-card rounded-lg border border-border-subtle overflow-hidden flex flex-col items-center justify-center p-12 text-text-muted text-center",children:[(0,s.jsx)(sI,{}),(0,s.jsx)("span",{className:"mt-3 text-sm",children:"Loading fleet data..."})]}):0===t.length?(0,s.jsxs)("div",{className:"bg-bg-card rounded-lg border border-border-subtle overflow-hidden flex flex-col items-center justify-center p-12 text-text-muted text-center",children:[(0,s.jsx)(s_,{}),(0,s.jsx)("h3",{className:"mt-4 mb-2 text-base font-semibold text-text-primary",children:"No Fleet Servers"}),(0,s.jsx)("p",{className:"text-sm",children:"Connect to peer servers to enable fleet view"})]}):(0,s.jsxs)("div",{className:"bg-bg-card rounded-lg border border-border-subtle overflow-hidden",children:[(0,s.jsxs)("div",{className:"flex items-center gap-6 p-4 border-b border-border-subtle bg-bg-secondary",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2 font-semibold text-sm text-text-primary",children:[(0,s.jsx)(sR,{}),(0,s.jsx)("span",{children:"Fleet Overview"})]}),(0,s.jsxs)("div",{className:"flex gap-6 flex-1",children:[(0,s.jsxs)("div",{className:"flex flex-col items-center",children:[(0,s.jsxs)("span",{className:"text-base font-semibold text-text-primary",children:[u.online,"/",u.total]}),(0,s.jsx)("span",{className:"text-xs text-text-muted uppercase tracking-wide",children:"Servers"})]}),(0,s.jsxs)("div",{className:"flex flex-col items-center",children:[(0,s.jsx)("span",{className:"text-base font-semibold text-text-primary",children:u.totalAgents}),(0,s.jsx)("span",{className:"text-xs text-text-muted uppercase tracking-wide",children:"Agents"})]}),null!==u.avgLatency&&(0,s.jsxs)("div",{className:"flex flex-col items-center",children:[(0,s.jsxs)("span",{className:"text-base font-semibold text-text-primary",children:[u.avgLatency,"ms"]}),(0,s.jsx)("span",{className:"text-xs text-text-muted uppercase tracking-wide",children:"Avg Latency"})]}),(0,s.jsxs)("div",{className:"flex flex-col items-center",children:[(0,s.jsxs)("span",{className:"text-base font-semibold text-text-primary",children:[u.totalMessages,"/s"]}),(0,s.jsx)("span",{className:"text-xs text-text-muted uppercase tracking-wide",children:"Messages"})]})]}),(0,s.jsxs)("div",{className:"flex gap-1 bg-bg-tertiary rounded-md p-0.5",children:[(0,s.jsx)("button",{className:"flex items-center justify-center w-7 h-7 bg-transparent border-none rounded cursor-pointer transition-all duration-150 ".concat("grid"===d?"bg-bg-card text-text-primary shadow-sm":"text-text-muted hover:text-text-secondary"),onClick:()=>x("grid"),title:"Grid view",children:(0,s.jsx)(sP,{})}),(0,s.jsx)("button",{className:"flex items-center justify-center w-7 h-7 bg-transparent border-none rounded cursor-pointer transition-all duration-150 ".concat("list"===d?"bg-bg-card text-text-primary shadow-sm":"text-text-muted hover:text-text-secondary"),onClick:()=>x("list"),title:"List view",children:(0,s.jsx)(sB,{})})]})]}),(0,s.jsx)("div",{className:"flex h-1 bg-bg-tertiary",children:t.map(e=>(0,s.jsx)("div",{className:"transition-all duration-300 ".concat({online:"bg-success",offline:"bg-error",degraded:"bg-warning",connecting:"bg-accent-purple"}[e.status]||"bg-text-dim"),style:{flex:e.agentCount||1},title:"".concat(e.name,": ").concat(e.agentCount," agents")},e.id))}),(0,s.jsx)("div",{className:"p-4 ".concat("grid"===d?"grid grid-cols-[repeat(auto-fill,minmax(280px,1fr))] gap-4":"flex flex-col gap-2"),children:t.map(e=>{var t;return(0,s.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,s.jsx)(sW,{server:e,isSelected:e.id===o,onClick:()=>null==i?void 0:i(e.id),onReconnect:()=>null==l?void 0:l(e.id),compact:"list"===d}),"grid"===d&&(null===(t=m[e.id])||void 0===t?void 0:t.length)>0&&(0,s.jsxs)("div",{className:"flex gap-1 px-2",children:[m[e.id].slice(0,5).map((e,t)=>{let r=(0,a.GW)(e.name);return(0,s.jsx)("div",{className:"w-6 h-6 rounded-md flex items-center justify-center text-[9px] font-semibold border-2 border-bg-card",style:{backgroundColor:r.primary,color:r.text,marginLeft:t>0?"-4px":0},title:e.name,children:(0,a.hP)(e.name)},e.name)}),m[e.id].length>5&&(0,s.jsxs)("div",{className:"w-6 h-6 rounded-md flex items-center justify-center text-[9px] font-semibold bg-bg-tertiary text-text-muted border-2 border-bg-card",style:{marginLeft:"-4px"},children:["+",m[e.id].length-5]})]})]},e.id)})})]})}function sR(){return(0,s.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2",ry:"2"}),(0,s.jsx)("line",{x1:"8",y1:"21",x2:"16",y2:"21"}),(0,s.jsx)("line",{x1:"12",y1:"17",x2:"12",y2:"21"})]})}function sP(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("rect",{x:"3",y:"3",width:"7",height:"7"}),(0,s.jsx)("rect",{x:"14",y:"3",width:"7",height:"7"}),(0,s.jsx)("rect",{x:"3",y:"14",width:"7",height:"7"}),(0,s.jsx)("rect",{x:"14",y:"14",width:"7",height:"7"})]})}function sB(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"8",y1:"6",x2:"21",y2:"6"}),(0,s.jsx)("line",{x1:"8",y1:"12",x2:"21",y2:"12"}),(0,s.jsx)("line",{x1:"8",y1:"18",x2:"21",y2:"18"}),(0,s.jsx)("line",{x1:"3",y1:"6",x2:"3.01",y2:"6"}),(0,s.jsx)("line",{x1:"3",y1:"12",x2:"3.01",y2:"12"}),(0,s.jsx)("line",{x1:"3",y1:"18",x2:"3.01",y2:"18"})]})}function s_(){return(0,s.jsxs)("svg",{width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[(0,s.jsx)("rect",{x:"2",y:"2",width:"20",height:"8",rx:"2",ry:"2"}),(0,s.jsx)("rect",{x:"2",y:"14",width:"20",height:"8",rx:"2",ry:"2"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"6.01",y2:"6"}),(0,s.jsx)("line",{x1:"6",y1:"18",x2:"6.01",y2:"18"})]})}function sI(){return(0,s.jsx)("svg",{className:"animate-spin",width:"24",height:"24",viewBox:"0 0 24 24",children:(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeDasharray:"32",strokeLinecap:"round"})})}function sF(e){let{typingUsers:t}=e;return 0===t.length?null:(0,s.jsxs)("div",{className:"flex items-center gap-2 px-4 py-2 text-sm text-[#8d8d8e]",children:[(0,s.jsx)("div",{className:"flex -space-x-1.5",children:t.slice(0,3).map(e=>(0,s.jsx)("div",{className:"relative",title:e.username,children:e.avatarUrl?(0,s.jsx)("img",{src:e.avatarUrl,alt:e.username,className:"w-5 h-5 rounded-full border border-[#1a1d21]"}):(0,s.jsx)("div",{className:"w-5 h-5 rounded-full bg-[#a855f7] border border-[#1a1d21] flex items-center justify-center text-[9px] text-white font-medium",children:e.username.charAt(0).toUpperCase()})},e.username))}),(0,s.jsxs)("span",{className:"flex items-center gap-1",children:[1===t.length?"".concat(t[0].username," is typing"):2===t.length?"".concat(t[0].username," and ").concat(t[1].username," are typing"):"".concat(t[0].username," and ").concat(t.length-1," others are typing"),(0,s.jsxs)("span",{className:"flex gap-0.5",children:[(0,s.jsx)("span",{className:"w-1 h-1 bg-[#8d8d8e] rounded-full animate-bounce",style:{animationDelay:"0ms"}}),(0,s.jsx)("span",{className:"w-1 h-1 bg-[#8d8d8e] rounded-full animate-bounce",style:{animationDelay:"150ms"}}),(0,s.jsx)("span",{className:"w-1 h-1 bg-[#8d8d8e] rounded-full animate-bounce",style:{animationDelay:"300ms"}})]})]})]})}function sU(e){let{onlineUsers:t,onUserClick:r,maxAvatars:a=4}=e,[o,i]=(0,n.useState)(!1),l=(0,n.useRef)(null);if((0,n.useEffect)(()=>{let e=e=>{l.current&&!l.current.contains(e.target)&&i(!1)};return o&&document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[o]),0===t.length)return null;let c=t.slice(0,a),d=Math.max(0,t.length-a);return(0,s.jsxs)("div",{className:"relative",ref:l,children:[(0,s.jsxs)("button",{onClick:()=>i(!o),className:"flex items-center gap-1.5 px-2 py-1 rounded-md hover:bg-white/[0.05] transition-colors",title:"".concat(t.length," user").concat(1!==t.length?"s":""," online"),children:[(0,s.jsx)("div",{className:"w-2 h-2 bg-green-500 rounded-full"}),(0,s.jsxs)("div",{className:"flex -space-x-1.5",children:[c.map(e=>(0,s.jsx)("div",{className:"relative ring-2 ring-[#1a1d21] rounded-full",title:e.username,children:e.avatarUrl?(0,s.jsx)("img",{src:e.avatarUrl,alt:e.username,className:"w-6 h-6 rounded-full object-cover"}):(0,s.jsx)("div",{className:"w-6 h-6 rounded-full bg-[#a855f7] flex items-center justify-center text-[10px] text-white font-medium",children:e.username.charAt(0).toUpperCase()})},e.username)),d>0&&(0,s.jsxs)("div",{className:"w-6 h-6 rounded-full bg-[#3d4043] ring-2 ring-[#1a1d21] flex items-center justify-center text-[10px] text-[#d1d2d3] font-medium",children:["+",d]})]}),(0,s.jsxs)("span",{className:"text-xs text-[#8d8d8e]",children:[t.length," online"]})]}),o&&(0,s.jsxs)("div",{className:"absolute right-0 top-full mt-1 w-64 bg-[#1a1d21] border border-white/10 rounded-lg shadow-xl z-50 max-h-[300px] overflow-y-auto",children:[(0,s.jsx)("div",{className:"p-2 border-b border-white/10",children:(0,s.jsx)("h3",{className:"text-sm font-medium text-[#d1d2d3]",children:"Online Users"})}),(0,s.jsx)("div",{className:"py-1",children:t.map(e=>(0,s.jsxs)("button",{onClick:()=>{null==r||r(e),i(!1)},className:"w-full flex items-center gap-3 px-3 py-2 hover:bg-white/[0.05] transition-colors text-left",children:[(0,s.jsxs)("div",{className:"relative",children:[e.avatarUrl?(0,s.jsx)("img",{src:e.avatarUrl,alt:e.username,className:"w-8 h-8 rounded-full object-cover"}):(0,s.jsx)("div",{className:"w-8 h-8 rounded-full bg-[#a855f7] flex items-center justify-center text-xs text-white font-medium",children:e.username.charAt(0).toUpperCase()}),(0,s.jsx)("div",{className:"absolute -bottom-0.5 -right-0.5 w-3 h-3 bg-green-500 rounded-full border-2 border-[#1a1d21]"})]}),(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsx)("div",{className:"text-sm font-medium text-[#d1d2d3] truncate",children:e.username}),(0,s.jsxs)("div",{className:"text-xs text-[#8d8d8e]",children:["Online since ",function(e){let t=new Date(e),r=new Date;return t.toDateString()===r.toDateString()?t.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):t.toLocaleDateString([],{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}(e.connectedAt)]})]})]},e.username))})]})]})}function sO(e){let{user:t,onClose:r,onMention:a}=e,o=(0,n.useRef)(null);(0,n.useEffect)(()=>{let e=e=>{"Escape"===e.key&&r()};return t&&window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[t,r]);let i=(0,n.useRef)(!1);if((0,n.useEffect)(()=>{t&&(i.current=!0)},[t]),(0,n.useEffect)(()=>{let e=e=>{if(i.current){i.current=!1;return}o.current&&!o.current.contains(e.target)&&r()};if(t)return document.addEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}},[t,r]),!t)return null;let l="https://github.com/".concat(t.username);return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"fixed inset-0 bg-black/50 z-40"}),(0,s.jsxs)("div",{ref:o,className:"fixed right-0 top-0 h-full w-80 bg-[#1a1d21] border-l border-white/10 shadow-2xl z-50 flex flex-col animate-slide-in-right",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between p-4 border-b border-white/10",children:[(0,s.jsx)("h2",{className:"text-lg font-semibold text-[#d1d2d3]",children:"Profile"}),(0,s.jsx)("button",{onClick:r,className:"p-1 hover:bg-white/10 rounded-md transition-colors",title:"Close",children:(0,s.jsx)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.jsx)("path",{d:"M18 6L6 18M6 6l12 12"})})})]}),(0,s.jsxs)("div",{className:"flex flex-col items-center p-6 border-b border-white/10",children:[(0,s.jsxs)("div",{className:"relative mb-4",children:[t.avatarUrl?(0,s.jsx)("img",{src:t.avatarUrl,alt:t.username,className:"w-24 h-24 rounded-full object-cover border-4 border-[#a855f7]/30"}):(0,s.jsx)("div",{className:"w-24 h-24 rounded-full bg-[#a855f7] flex items-center justify-center text-3xl text-white font-bold border-4 border-[#a855f7]/30",children:t.username.charAt(0).toUpperCase()}),(0,s.jsx)("div",{className:"absolute bottom-1 right-1 w-5 h-5 bg-green-500 rounded-full border-4 border-[#1a1d21]"})]}),(0,s.jsx)("h3",{className:"text-xl font-semibold text-[#d1d2d3] mb-1",children:t.username}),(0,s.jsxs)("span",{className:"text-sm text-green-400 flex items-center gap-1.5",children:[(0,s.jsx)("div",{className:"w-2 h-2 bg-green-500 rounded-full"}),"Online"]})]}),(0,s.jsx)("div",{className:"flex-1 p-4 overflow-y-auto",children:(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-xs text-[#8d8d8e] uppercase tracking-wide",children:"Online Since"}),(0,s.jsx)("p",{className:"text-sm text-[#d1d2d3] mt-1",children:sz(t.connectedAt)})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-xs text-[#8d8d8e] uppercase tracking-wide",children:"Last Active"}),(0,s.jsx)("p",{className:"text-sm text-[#d1d2d3] mt-1",children:sz(t.lastSeen)})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-xs text-[#8d8d8e] uppercase tracking-wide",children:"GitHub"}),(0,s.jsxs)("a",{href:l,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-2 mt-1 text-sm text-[#a855f7] hover:text-[#c084fc] transition-colors",children:[(0,s.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor",children:(0,s.jsx)("path",{d:"M12 0C5.37 0 0 5.37 0 12c0 5.31 3.435 9.795 8.205 11.385.6.105.825-.255.825-.57 0-.285-.015-1.23-.015-2.235-3.015.555-3.795-.735-4.035-1.41-.135-.345-.72-1.41-1.23-1.695-.42-.225-1.02-.78-.015-.795.945-.015 1.62.87 1.845 1.23 1.08 1.815 2.805 1.305 3.495.99.105-.78.42-1.305.765-1.605-2.67-.3-5.46-1.335-5.46-5.925 0-1.305.465-2.385 1.23-3.225-.12-.3-.54-1.53.12-3.18 0 0 1.005-.315 3.3 1.23.96-.27 1.98-.405 3-.405s2.04.135 3 .405c2.295-1.56 3.3-1.23 3.3-1.23.66 1.65.24 2.88.12 3.18.765.84 1.23 1.905 1.23 3.225 0 4.605-2.805 5.625-5.475 5.925.435.375.81 1.095.81 2.22 0 1.605-.015 2.895-.015 3.3 0 .315.225.69.825.57A12.02 12.02 0 0024 12c0-6.63-5.37-12-12-12z"})}),"@",t.username,(0,s.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.jsx)("path",{d:"M18 13v6a2 2 0 01-2 2H5a2 2 0 01-2-2V8a2 2 0 012-2h6M15 3h6v6M10 14L21 3"})})]})]})]})}),(0,s.jsxs)("div",{className:"p-4 border-t border-white/10 space-y-2",children:[(0,s.jsxs)("button",{onClick:()=>{null==a||a(t.username),r()},className:"w-full flex items-center justify-center gap-2 py-2.5 bg-[#a855f7] hover:bg-[#9333ea] text-white font-medium rounded-lg transition-colors",children:[(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"4"}),(0,s.jsx)("path",{d:"M16 8v5a3 3 0 006 0v-1a10 10 0 10-3.92 7.94"})]}),"Mention @",t.username]}),(0,s.jsxs)("a",{href:l,target:"_blank",rel:"noopener noreferrer",className:"w-full flex items-center justify-center gap-2 py-2.5 border border-white/20 text-[#d1d2d3] hover:bg-white/5 font-medium rounded-lg transition-colors",children:[(0,s.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor",children:(0,s.jsx)("path",{d:"M12 0C5.37 0 0 5.37 0 12c0 5.31 3.435 9.795 8.205 11.385.6.105.825-.255.825-.57 0-.285-.015-1.23-.015-2.235-3.015.555-3.795-.735-4.035-1.41-.135-.345-.72-1.41-1.23-1.695-.42-.225-1.02-.78-.015-.795.945-.015 1.62.87 1.845 1.23 1.08 1.815 2.805 1.305 3.495.99.105-.78.42-1.305.765-1.605-2.67-.3-5.46-1.335-5.46-5.925 0-1.305.465-2.385 1.23-3.225-.12-.3-.54-1.53.12-3.18 0 0 1.005-.315 3.3 1.23.96-.27 1.98-.405 3-.405s2.04.135 3 .405c2.295-1.56 3.3-1.23 3.3-1.23.66 1.65.24 2.88.12 3.18.765.84 1.23 1.905 1.23 3.225 0 4.605-2.805 5.625-5.475 5.925.435.375.81 1.095.81 2.22 0 1.605-.015 2.895-.015 3.3 0 .315.225.69.825.57A12.02 12.02 0 0024 12c0-6.63-5.37-12-12-12z"})}),"View on GitHub"]})]})]})]})}function sz(e){return new Date(e).toLocaleString([],{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"})}function sH(e){let{isOpen:t,onClose:r,projects:a,isCloudMode:o=!1,hasArchitect:i=!1,onArchitectSpawned:l}=e,[c,d]=(0,n.useState)([]),[x,u]=(0,n.useState)(!1),[m,h]=(0,n.useState)(null),[p,g]=(0,n.useState)(!1),[b,f]=(0,n.useState)(""),[j,y]=(0,n.useState)(new Set),[v,w]=(0,n.useState)(!1),[N,k]=(0,n.useState)("claude");(0,n.useEffect)(()=>{t&&o&&C()},[t,o]);let C=async()=>{u(!0),h(null);try{let e=await fetch("/api/project-groups");if(e.ok){let t=await e.json();d(t.groups||[])}else h("Failed to load project groups")}catch(e){h("Failed to load project groups")}finally{u(!1)}},S=async()=>{if(b.trim()&&0!==j.size){u(!0),h(null);try{let e=await fetch("/api/project-groups",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:b,repositoryIds:Array.from(j)})});if(e.ok){let t=await e.json();t.group&&(d(e=>[...e,t.group]),g(!1),f(""),y(new Set))}else h("Failed to create project group")}catch(e){h("Failed to create project group")}finally{u(!1)}}},A=async(e,t)=>{h(null);try{let r="/api/project-groups/".concat(e,"/coordinator/").concat(t?"enable":"disable");(await fetch(r,{method:"POST"})).ok?d(r=>r.map(r=>r.id===e?{...r,coordinator:{...r.coordinator,enabled:t,status:t?"starting":"stopped"}}:r)):h("Failed to ".concat(t?"enable":"disable"," coordinator"))}catch(e){h("Failed to ".concat(t?"enable":"disable"," coordinator"))}},L=async e=>{if(window.confirm("Delete this project group? The coordinator will be stopped."))try{(await fetch("/api/project-groups/".concat(e),{method:"DELETE"})).ok?d(t=>t.filter(t=>t.id!==e)):h("Failed to delete project group")}catch(e){h("Failed to delete project group")}},E=e=>{y(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})};if(!t)return null;let W=async()=>{w(!0),h(null);try{let e=await fetch("/api/spawn/architect",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cli:N})}),t=await e.json();e.ok&&t.success?(null==l||l(),r()):h(t.error||"Failed to spawn Architect")}catch(e){h("Failed to spawn Architect")}finally{w(!1)}};if(!o){let e=a.length>1;return(0,s.jsx)("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-[1000] animate-fade-in",onClick:r,children:(0,s.jsxs)("div",{className:"bg-bg-secondary rounded-xl w-[500px] max-w-[90vw] max-h-[80vh] flex flex-col shadow-modal animate-slide-up",onClick:e=>e.stopPropagation(),children:[(0,s.jsxs)("div",{className:"flex items-center justify-between py-5 px-6 border-b border-border-subtle",children:[(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsx)(sK,{}),(0,s.jsx)("h2",{className:"m-0 text-lg font-semibold text-text-primary",children:"Coordinator Agent"})]}),(0,s.jsx)("button",{className:"flex items-center justify-center w-8 h-8 bg-transparent border-none rounded-md text-text-secondary cursor-pointer transition-all duration-150 hover:bg-bg-hover hover:text-text-primary",onClick:r,children:(0,s.jsx)(sJ,{})})]}),(0,s.jsxs)("div",{className:"flex-1 overflow-y-auto p-6",children:[m&&(0,s.jsx)("div",{className:"bg-error/10 border border-error/30 rounded-lg p-3 mb-4 text-error text-sm",children:m}),e&&(0,s.jsxs)("div",{className:"bg-gradient-to-r from-accent-purple/10 to-accent-cyan/10 border border-accent-purple/30 rounded-lg p-4 mb-4",children:[(0,s.jsxs)("h3",{className:"text-sm font-semibold text-text-primary mb-3 flex items-center gap-2",children:[(0,s.jsx)(sK,{}),"Spawn Architect"]}),i?(0,s.jsxs)("div",{className:"flex items-center gap-2 text-sm text-success",children:[(0,s.jsx)(s$,{}),"Architect is running"]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("p",{className:"text-sm text-text-secondary mb-4",children:["Spawn an Architect agent to coordinate across your ",a.length," connected projects."]}),(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsxs)("select",{className:"flex-1 py-2 px-3 bg-bg-card border border-border-subtle rounded-md text-sm text-text-primary outline-none focus:border-accent-purple/50",value:N,onChange:e=>k(e.target.value),children:[(0,s.jsx)("option",{value:"claude",children:"Claude (default)"}),(0,s.jsx)("option",{value:"claude:opus",children:"Claude Opus"}),(0,s.jsx)("option",{value:"claude:sonnet",children:"Claude Sonnet"}),(0,s.jsx)("option",{value:"codex",children:"Codex"})]}),(0,s.jsx)("button",{className:"py-2 px-4 bg-gradient-to-r from-accent-purple to-accent-cyan text-bg-deep rounded-md text-sm font-semibold hover:shadow-lg transition-all disabled:opacity-50",onClick:W,disabled:v,children:v?"Spawning...":"Spawn"})]})]})]}),!e&&(0,s.jsxs)("div",{className:"bg-bg-tertiary rounded-lg p-4 mb-4 border border-border-subtle",children:[(0,s.jsx)("h3",{className:"text-sm font-semibold text-text-primary mb-2",children:"Not in Bridge Mode"}),(0,s.jsx)("p",{className:"text-sm text-text-secondary",children:"The Architect coordinates multiple projects. Start bridge mode to enable:"}),(0,s.jsxs)("div",{className:"bg-bg-card rounded-lg p-3 font-mono text-sm mt-3",children:[(0,s.jsx)("span",{className:"text-text-muted",children:"$"})," ",(0,s.jsx)("span",{className:"text-accent-cyan",children:"relay bridge"})," ",(0,s.jsx)("span",{className:"text-accent-orange",children:"~/project1 ~/project2"})]})]}),(0,s.jsxs)("div",{className:"bg-bg-tertiary rounded-lg p-4 mb-4",children:[(0,s.jsx)("h3",{className:"text-sm font-semibold text-text-primary mb-2",children:"CLI Alternative"}),(0,s.jsxs)("p",{className:"text-sm text-text-secondary mb-3",children:["You can also spawn the Architect via CLI with the ",(0,s.jsx)("code",{className:"bg-bg-card px-1.5 py-0.5 rounded text-accent-cyan",children:"--architect"})," flag:"]}),(0,s.jsxs)("div",{className:"bg-bg-card rounded-lg p-3 font-mono text-sm",children:[(0,s.jsx)("span",{className:"text-text-muted",children:"$"})," ",(0,s.jsx)("span",{className:"text-accent-cyan",children:"relay bridge"})," ",(0,s.jsx)("span",{className:"text-accent-orange",children:"~/project1 ~/project2"})," ",(0,s.jsx)("span",{className:"text-accent-purple",children:"--architect"})]})]})]}),(0,s.jsx)("div",{className:"flex justify-end py-4 px-6 border-t border-border-subtle",children:(0,s.jsx)("button",{className:"py-2 px-5 bg-bg-tertiary border border-border-subtle rounded-md text-sm text-text-secondary cursor-pointer transition-colors duration-150 hover:bg-bg-hover",onClick:r,children:"Close"})})]})})}return(0,s.jsx)("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-[1000] animate-fade-in",onClick:r,children:(0,s.jsxs)("div",{className:"bg-bg-secondary rounded-xl w-[600px] max-w-[90vw] max-h-[80vh] flex flex-col shadow-modal animate-slide-up",onClick:e=>e.stopPropagation(),children:[(0,s.jsxs)("div",{className:"flex items-center justify-between py-5 px-6 border-b border-border-subtle",children:[(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsx)(sK,{}),(0,s.jsx)("h2",{className:"m-0 text-lg font-semibold text-text-primary",children:"Coordinator Agents"})]}),(0,s.jsx)("button",{className:"flex items-center justify-center w-8 h-8 bg-transparent border-none rounded-md text-text-secondary cursor-pointer transition-all duration-150 hover:bg-bg-hover hover:text-text-primary",onClick:r,children:(0,s.jsx)(sJ,{})})]}),(0,s.jsxs)("div",{className:"flex-1 overflow-y-auto p-6",children:[m&&(0,s.jsx)("div",{className:"bg-error/10 border border-error/30 rounded-lg p-3 mb-4 text-error text-sm",children:m}),x&&0===c.length?(0,s.jsx)("div",{className:"flex items-center justify-center py-12 text-text-muted",children:(0,s.jsx)(sG,{})}):(0,s.jsxs)(s.Fragment,{children:[c.length>0&&(0,s.jsxs)("div",{className:"space-y-3 mb-6",children:[(0,s.jsx)("h4",{className:"text-xs font-semibold text-text-muted uppercase tracking-wider",children:"Project Groups"}),c.map(e=>{var t,r,n,a;return(0,s.jsxs)("div",{className:"bg-bg-tertiary rounded-lg p-4 border border-border-subtle",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:"font-semibold text-text-primary",children:e.name}),(0,s.jsxs)("span",{className:"text-xs text-text-muted",children:[e.repositoryIds.length," repos"]})]}),(0,s.jsx)("button",{className:"text-text-muted hover:text-error transition-colors p-1",onClick:()=>L(e.id),title:"Delete group",children:(0,s.jsx)(sY,{})})]}),(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(sV,{status:(null===(t=e.coordinator)||void 0===t?void 0:t.status)||"stopped"}),(null===(r=e.coordinator)||void 0===r?void 0:r.name)&&(0,s.jsx)("span",{className:"text-sm text-text-secondary",children:e.coordinator.name})]}),(0,s.jsxs)("button",{className:"py-1.5 px-3 rounded-md text-xs font-medium transition-colors ".concat((null===(n=e.coordinator)||void 0===n?void 0:n.enabled)?"bg-error/20 text-error hover:bg-error/30":"bg-accent-cyan/20 text-accent-cyan hover:bg-accent-cyan/30"),onClick:()=>{var t;return A(e.id,!(null===(t=e.coordinator)||void 0===t?void 0:t.enabled))},children:[(null===(a=e.coordinator)||void 0===a?void 0:a.enabled)?"Stop":"Start"," Coordinator"]})]})]},e.id)})]}),p?(0,s.jsxs)("div",{className:"bg-bg-tertiary rounded-lg p-4 border border-accent-cyan/30",children:[(0,s.jsx)("h4",{className:"text-sm font-semibold text-text-primary mb-4",children:"Create Project Group"}),(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"block text-xs font-medium text-text-muted mb-1.5",children:"Group Name"}),(0,s.jsx)("input",{type:"text",className:"w-full py-2 px-3 bg-bg-card border border-border-subtle rounded-md text-sm text-text-primary outline-none focus:border-accent-cyan/50",placeholder:"e.g., Frontend Team",value:b,onChange:e=>f(e.target.value)})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"block text-xs font-medium text-text-muted mb-1.5",children:"Select Projects"}),(0,s.jsxs)("div",{className:"space-y-2 max-h-[200px] overflow-y-auto",children:[a.map(e=>(0,s.jsxs)("label",{className:"flex items-center gap-2 p-2 bg-bg-card rounded-md cursor-pointer hover:bg-bg-hover",children:[(0,s.jsx)("input",{type:"checkbox",className:"accent-accent-cyan",checked:j.has(e.id),onChange:()=>E(e.id)}),(0,s.jsx)("span",{className:"text-sm text-text-primary",children:e.name||e.path})]},e.id)),0===a.length&&(0,s.jsx)("p",{className:"text-sm text-text-muted py-4 text-center",children:"No projects available. Add workspaces first."})]})]}),(0,s.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,s.jsx)("button",{className:"py-2 px-4 bg-transparent border border-border-subtle rounded-md text-sm text-text-secondary hover:bg-bg-hover",onClick:()=>{g(!1),f(""),y(new Set)},children:"Cancel"}),(0,s.jsx)("button",{className:"py-2 px-4 bg-accent-cyan text-bg-deep rounded-md text-sm font-medium hover:bg-accent-cyan/90 disabled:opacity-50",onClick:S,disabled:!b.trim()||0===j.size||x,children:"Create Group"})]})]})]}):(0,s.jsxs)("button",{className:"w-full py-3 px-4 border-2 border-dashed border-border-subtle rounded-lg text-text-muted hover:border-accent-cyan/50 hover:text-accent-cyan transition-colors flex items-center justify-center gap-2",onClick:()=>g(!0),children:[(0,s.jsx)(sX,{}),"Create Project Group"]}),(0,s.jsxs)("div",{className:"mt-6 p-4 bg-bg-tertiary/50 rounded-lg border border-border-subtle",children:[(0,s.jsxs)("h4",{className:"text-sm font-semibold text-text-primary mb-2 flex items-center gap-2",children:[(0,s.jsx)(sq,{}),"What is a Coordinator?"]}),(0,s.jsx)("p",{className:"text-sm text-text-secondary",children:"A coordinator is a high-level AI agent that oversees multiple projects. It can delegate tasks to project leads, ensure consistency across codebases, and manage cross-project dependencies."})]})]})]})]})})}function sV(e){let{status:t}=e,r={stopped:"bg-text-muted/20 text-text-muted",starting:"bg-accent-orange/20 text-accent-orange",running:"bg-success/20 text-success",error:"bg-error/20 text-error"};return(0,s.jsx)("span",{className:"px-2 py-0.5 rounded-full text-xs font-medium ".concat(r[t]||r.stopped),children:t})}function sG(){return(0,s.jsx)("svg",{className:"animate-spin h-6 w-6 text-accent-cyan",viewBox:"0 0 24 24",children:(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeDasharray:"32",strokeLinecap:"round"})})}function sK(){return(0,s.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-accent-cyan",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"3"}),(0,s.jsx)("circle",{cx:"5",cy:"5",r:"2"}),(0,s.jsx)("circle",{cx:"19",cy:"5",r:"2"}),(0,s.jsx)("circle",{cx:"5",cy:"19",r:"2"}),(0,s.jsx)("circle",{cx:"19",cy:"19",r:"2"}),(0,s.jsx)("line",{x1:"9.5",y1:"9.5",x2:"6.5",y2:"6.5"}),(0,s.jsx)("line",{x1:"14.5",y1:"9.5",x2:"17.5",y2:"6.5"}),(0,s.jsx)("line",{x1:"9.5",y1:"14.5",x2:"6.5",y2:"17.5"}),(0,s.jsx)("line",{x1:"14.5",y1:"14.5",x2:"17.5",y2:"17.5"})]})}function sJ(){return(0,s.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function sX(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,s.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function sY(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,s.jsx)("path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"})]})}function sq(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-accent-cyan",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,s.jsx)("line",{x1:"12",y1:"16",x2:"12",y2:"12"}),(0,s.jsx)("line",{x1:"12",y1:"8",x2:"12.01",y2:"8"})]})}function s$(){return(0,s.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:"text-success",children:(0,s.jsx)("polyline",{points:"20 6 9 17 4 12"})})}function sZ(){let e=(0,n.useMemo)(()=>Array.from({length:50},(e,t)=>({id:t,x:100*Math.random(),delay:.5*Math.random(),duration:2+2*Math.random(),size:4+8*Math.random(),color:["#00d9ff","#00b8d9","#4ade80","#facc15","#f472b6","#a78bfa"][Math.floor(6*Math.random())],rotation:360*Math.random()})),[]);return(0,s.jsxs)("div",{className:"fixed inset-0 pointer-events-none overflow-hidden z-50",children:[e.map(e=>(0,s.jsx)("div",{className:"absolute animate-confetti-fall",style:{left:"".concat(e.x,"%"),top:"-20px",width:e.size,height:.6*e.size,backgroundColor:e.color,transform:"rotate(".concat(e.rotation,"deg)"),animationDelay:"".concat(e.delay,"s"),animationDuration:"".concat(e.duration,"s"),borderRadius:"2px"}},e.id)),(0,s.jsx)("style",{children:"\n @keyframes confetti-fall {\n 0% {\n transform: translateY(0) rotate(0deg) scale(1);\n opacity: 1;\n }\n 100% {\n transform: translateY(100vh) rotate(720deg) scale(0.5);\n opacity: 0;\n }\n }\n .animate-confetti-fall {\n animation: confetti-fall linear forwards;\n }\n "})]})}function sQ(){return(0,s.jsxs)("div",{className:"relative w-20 h-20",children:[(0,s.jsx)("div",{className:"absolute inset-0 rounded-full bg-gradient-to-r from-emerald-400 to-cyan-400 opacity-20 animate-pulse-slow"}),(0,s.jsx)("div",{className:"absolute inset-1 rounded-full bg-gradient-to-br from-emerald-400 via-emerald-500 to-cyan-500 p-0.5 animate-scale-in",children:(0,s.jsx)("div",{className:"w-full h-full rounded-full bg-bg-primary flex items-center justify-center",children:(0,s.jsxs)("svg",{className:"w-10 h-10",viewBox:"0 0 24 24",fill:"none",children:[(0,s.jsx)("path",{d:"M5 12l5 5L19 7",stroke:"url(#check-gradient)",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",className:"animate-draw-check",style:{strokeDasharray:30,strokeDashoffset:30}}),(0,s.jsx)("defs",{children:(0,s.jsxs)("linearGradient",{id:"check-gradient",x1:"5",y1:"12",x2:"19",y2:"7",children:[(0,s.jsx)("stop",{stopColor:"#34d399"}),(0,s.jsx)("stop",{offset:"1",stopColor:"#22d3ee"})]})})]})})}),(0,s.jsx)("div",{className:"absolute -top-1 -right-1 w-3 h-3 bg-yellow-400 rounded-full animate-sparkle",style:{animationDelay:"0.5s"}}),(0,s.jsx)("div",{className:"absolute top-0 -left-2 w-2 h-2 bg-cyan-400 rounded-full animate-sparkle",style:{animationDelay:"0.7s"}}),(0,s.jsx)("div",{className:"absolute -bottom-1 right-2 w-2 h-2 bg-emerald-400 rounded-full animate-sparkle",style:{animationDelay:"0.9s"}}),(0,s.jsx)("style",{children:"\n @keyframes scale-in {\n 0% { transform: scale(0); opacity: 0; }\n 50% { transform: scale(1.1); }\n 100% { transform: scale(1); opacity: 1; }\n }\n @keyframes draw-check {\n to { stroke-dashoffset: 0; }\n }\n @keyframes sparkle {\n 0%, 100% { transform: scale(0); opacity: 0; }\n 50% { transform: scale(1); opacity: 1; }\n }\n @keyframes pulse-slow {\n 0%, 100% { transform: scale(1); opacity: 0.2; }\n 50% { transform: scale(1.2); opacity: 0.4; }\n }\n .animate-scale-in {\n animation: scale-in 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;\n }\n .animate-draw-check {\n animation: draw-check 0.4s ease-out 0.4s forwards;\n }\n .animate-sparkle {\n animation: sparkle 1s ease-in-out infinite;\n }\n .animate-pulse-slow {\n animation: pulse-slow 2s ease-in-out infinite;\n }\n "})]})}function s0(){return(0,s.jsxs)("div",{className:"relative w-20 h-20",children:[(0,s.jsx)("div",{className:"absolute inset-0 rounded-full border-2 border-transparent border-t-accent-cyan border-r-accent-cyan/50 animate-spin"}),(0,s.jsx)("div",{className:"absolute inset-3 rounded-full bg-gradient-to-br from-accent-cyan/20 to-transparent animate-pulse"}),(0,s.jsx)("div",{className:"absolute inset-0 flex items-center justify-center",children:(0,s.jsx)("div",{className:"w-3 h-3 rounded-full bg-accent-cyan animate-ping"})}),(0,s.jsx)("div",{className:"absolute inset-0 animate-spin",style:{animationDuration:"3s"},children:(0,s.jsx)("div",{className:"absolute top-0 left-1/2 -translate-x-1/2 w-2 h-2 rounded-full bg-accent-cyan/80"})}),(0,s.jsx)("div",{className:"absolute inset-0 animate-spin",style:{animationDuration:"4s",animationDirection:"reverse"},children:(0,s.jsx)("div",{className:"absolute bottom-1 left-1/2 -translate-x-1/2 w-1.5 h-1.5 rounded-full bg-cyan-300/60"})})]})}function s1(e){let{children:t,delay:r}=e;return(0,s.jsxs)("li",{className:"flex items-center gap-3 opacity-0 animate-slide-in-left",style:{animationDelay:"".concat(r,"s"),animationFillMode:"forwards"},children:[(0,s.jsx)("div",{className:"w-5 h-5 rounded-full bg-gradient-to-br from-emerald-400 to-cyan-400 flex items-center justify-center flex-shrink-0",children:(0,s.jsx)("svg",{className:"w-3 h-3 text-white",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",children:(0,s.jsx)("path",{d:"M20 6L9 17l-5-5",strokeLinecap:"round",strokeLinejoin:"round"})})}),(0,s.jsx)("span",{className:"text-text-secondary",children:t}),(0,s.jsx)("style",{children:"\n @keyframes slide-in-left {\n from {\n opacity: 0;\n transform: translateX(-20px);\n }\n to {\n opacity: 1;\n transform: translateX(0);\n }\n }\n .animate-slide-in-left {\n animation: slide-in-left 0.4s ease-out forwards;\n }\n "})]})}function s2(e){let{type:t,sessionId:r,onClose:a}=e,[o,i]=(0,n.useState)(null),[l,c]=(0,n.useState)("success"===t),[d,x]=(0,n.useState)(null),[u,m]=(0,n.useState)(!1);(0,n.useEffect)(()=>{"success"===t&&(async()=>{try{await new Promise(e=>setTimeout(e,1500));let r=await el.xv.getSubscription();if(r.success&&r.data){var e,t;i({plan:(null===(e=r.data.subscription)||void 0===e?void 0:e.tier)||"pro",status:(null===(t=r.data.subscription)||void 0===t?void 0:t.status)||"active"}),setTimeout(()=>m(!0),200)}}catch(e){x("Could not verify subscription. Please check your billing settings.")}finally{c(!1)}})()},[t,r]);let h=(null==o?void 0:o.plan)==="pro"?"Pro":(null==o?void 0:o.plan)==="team"?"Team":(null==o?void 0:o.plan)==="enterprise"?"Enterprise":"Premium";return"success"===t?(0,s.jsxs)("div",{className:"min-h-screen bg-bg-deep flex items-center justify-center p-4 overflow-hidden",children:[(0,s.jsxs)("div",{className:"fixed inset-0 overflow-hidden pointer-events-none",children:[(0,s.jsx)("div",{className:"absolute top-1/4 -left-32 w-96 h-96 bg-accent-cyan/10 rounded-full blur-3xl animate-float"}),(0,s.jsx)("div",{className:"absolute bottom-1/4 -right-32 w-96 h-96 bg-emerald-500/10 rounded-full blur-3xl animate-float",style:{animationDelay:"1s"}})]}),u&&(0,s.jsx)(sZ,{}),(0,s.jsxs)("div",{className:"relative max-w-md w-full bg-bg-primary/95 backdrop-blur-xl rounded-3xl border border-border-subtle p-10 text-center shadow-2xl opacity-0 animate-fade-scale-in",style:{animationFillMode:"forwards"},children:[(0,s.jsx)("div",{className:"absolute top-0 left-8 right-8 h-1 rounded-full bg-gradient-to-r from-transparent via-accent-cyan to-transparent"}),l?(0,s.jsxs)("div",{className:"py-8",children:[(0,s.jsx)("div",{className:"flex justify-center mb-8",children:(0,s.jsx)(s0,{})}),(0,s.jsx)("h1",{className:"text-2xl font-bold text-text-primary mb-3 tracking-tight",children:"Processing your upgrade"}),(0,s.jsx)("p",{className:"text-text-muted",children:"Confirming your subscription..."})]}):d?(0,s.jsxs)("div",{className:"py-4",children:[(0,s.jsx)("div",{className:"w-16 h-16 mx-auto mb-6 rounded-full bg-amber-500/20 flex items-center justify-center",children:(0,s.jsxs)("svg",{className:"w-8 h-8 text-amber-400",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,s.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),(0,s.jsx)("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]})}),(0,s.jsx)("h1",{className:"text-2xl font-bold text-text-primary mb-3",children:"Almost there!"}),(0,s.jsx)("p",{className:"text-text-muted mb-8",children:d}),(0,s.jsx)("button",{onClick:a,className:"group w-full py-4 px-6 bg-gradient-to-r from-accent-cyan to-cyan-400 text-bg-deep font-bold rounded-2xl transition-all duration-300 hover:shadow-[0_0_30px_rgba(0,217,255,0.4)] hover:scale-[1.02] active:scale-[0.98]",children:"Go to Billing Settings"})]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"flex justify-center mb-6",children:(0,s.jsx)(sQ,{})}),(0,s.jsxs)("h1",{className:"text-3xl font-extrabold text-transparent bg-clip-text bg-gradient-to-r from-text-primary via-accent-cyan to-emerald-400 mb-3 tracking-tight opacity-0 animate-fade-in",style:{animationDelay:"0.3s",animationFillMode:"forwards"},children:["Welcome to ",h,"!"]}),(0,s.jsx)("p",{className:"text-text-muted mb-8 opacity-0 animate-fade-in",style:{animationDelay:"0.5s",animationFillMode:"forwards"},children:"Your subscription is active. Time to supercharge your workflow."}),(0,s.jsxs)("div",{className:"bg-gradient-to-br from-bg-secondary to-bg-deep rounded-2xl p-5 mb-8 text-left border border-border-subtle/50 opacity-0 animate-fade-in",style:{animationDelay:"0.6s",animationFillMode:"forwards"},children:[(0,s.jsx)("h3",{className:"text-xs font-bold text-accent-cyan uppercase tracking-wider mb-4",children:"Your new powers"}),(0,s.jsxs)("ul",{className:"space-y-3 text-sm",children:[(0,s.jsx)(s1,{delay:.8,children:"Expanded workspace & repository limits"}),(0,s.jsx)(s1,{delay:.9,children:"More compute hours for your agents"}),(0,s.jsx)(s1,{delay:1,children:"Increased concurrent agent capacity"}),(0,s.jsx)(s1,{delay:1.1,children:"Priority support & faster responses"})]})]}),(0,s.jsx)("button",{onClick:a,className:"group w-full py-4 px-6 bg-gradient-to-r from-accent-cyan via-cyan-400 to-emerald-400 text-bg-deep font-bold rounded-2xl transition-all duration-300 hover:shadow-[0_0_40px_rgba(0,217,255,0.5)] hover:scale-[1.02] active:scale-[0.98] opacity-0 animate-fade-in",style:{animationDelay:"1.2s",animationFillMode:"forwards"},children:(0,s.jsxs)("span",{className:"flex items-center justify-center gap-2",children:["Launch Dashboard",(0,s.jsx)("svg",{className:"w-5 h-5 transition-transform group-hover:translate-x-1",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:(0,s.jsx)("path",{d:"M5 12h14M12 5l7 7-7 7",strokeLinecap:"round",strokeLinejoin:"round"})})]})})]})]}),(0,s.jsx)("style",{children:"\n @keyframes fade-scale-in {\n from {\n opacity: 0;\n transform: scale(0.95) translateY(10px);\n }\n to {\n opacity: 1;\n transform: scale(1) translateY(0);\n }\n }\n @keyframes fade-in {\n from { opacity: 0; }\n to { opacity: 1; }\n }\n @keyframes float {\n 0%, 100% { transform: translateY(0) scale(1); }\n 50% { transform: translateY(-20px) scale(1.05); }\n }\n .animate-fade-scale-in {\n animation: fade-scale-in 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;\n }\n .animate-fade-in {\n animation: fade-in 0.5s ease-out forwards;\n }\n .animate-float {\n animation: float 6s ease-in-out infinite;\n }\n "})]}):(0,s.jsxs)("div",{className:"min-h-screen bg-bg-deep flex items-center justify-center p-4",children:[(0,s.jsx)("div",{className:"fixed inset-0 overflow-hidden pointer-events-none",children:(0,s.jsx)("div",{className:"absolute top-1/3 left-1/4 w-64 h-64 bg-text-muted/5 rounded-full blur-3xl"})}),(0,s.jsxs)("div",{className:"relative max-w-md w-full bg-bg-primary/95 backdrop-blur-xl rounded-3xl border border-border-subtle p-10 text-center shadow-xl opacity-0 animate-fade-scale-in",style:{animationFillMode:"forwards"},children:[(0,s.jsx)("div",{className:"w-16 h-16 mx-auto mb-6 rounded-full bg-bg-secondary border border-border-subtle flex items-center justify-center",children:(0,s.jsx)("svg",{className:"w-7 h-7 text-text-muted",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.jsx)("path",{d:"M18 6L6 18M6 6l12 12",strokeLinecap:"round",strokeLinejoin:"round"})})}),(0,s.jsx)("h1",{className:"text-2xl font-bold text-text-primary mb-3",children:"No problem!"}),(0,s.jsx)("p",{className:"text-text-muted mb-8 leading-relaxed",children:"Checkout was canceled and you haven't been charged. You can upgrade anytime when you're ready."}),(0,s.jsxs)("div",{className:"space-y-3",children:[(0,s.jsx)("button",{onClick:a,className:"group w-full py-4 px-6 bg-gradient-to-r from-accent-cyan to-cyan-400 text-bg-deep font-bold rounded-2xl transition-all duration-300 hover:shadow-[0_0_30px_rgba(0,217,255,0.4)] hover:scale-[1.02] active:scale-[0.98]",children:(0,s.jsxs)("span",{className:"flex items-center justify-center gap-2",children:["Return to Dashboard",(0,s.jsx)("svg",{className:"w-5 h-5 transition-transform group-hover:translate-x-1",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:(0,s.jsx)("path",{d:"M5 12h14M12 5l7 7-7 7",strokeLinecap:"round",strokeLinejoin:"round"})})]})}),(0,s.jsx)("button",{onClick:()=>{window.location.href="/?settings=billing"},className:"w-full py-4 px-6 bg-bg-secondary text-text-primary font-semibold rounded-2xl border border-border-subtle transition-all duration-300 hover:border-accent-cyan/50 hover:bg-bg-secondary/80",children:"View Plans"})]})]}),(0,s.jsx)("style",{children:"\n @keyframes fade-scale-in {\n from {\n opacity: 0;\n transform: scale(0.95) translateY(10px);\n }\n to {\n opacity: 1;\n transform: scale(1) translateY(0);\n }\n }\n .animate-fade-scale-in {\n animation: fade-scale-in 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;\n }\n "})]})}let s5={url:"",autoConnect:!0,reconnect:!0,maxReconnectAttempts:10,reconnectDelay:1e3},s4="relay:recentRepos";function s3(e){try{localStorage.setItem(s4,JSON.stringify(e))}catch(e){}}var s6=r(5372);function s8(e){var t,r,i,l,d,u,m;let{wsUrl:h,orchestratorUrl:p}=e,{data:g,isConnected:b,error:f}=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t={...s5,...e},[r,s]=(0,n.useState)(null),[a,o]=(0,n.useState)(!1),[i,l]=(0,n.useState)(null),c=(0,n.useRef)(null),d=(0,n.useRef)(0),x=(0,n.useRef)(null),u=(0,n.useCallback)(()=>{var e;if((null===(e=c.current)||void 0===e?void 0:e.readyState)===WebSocket.OPEN)return;let r=t.url||function(){let e="https:"===window.location.protocol?"wss:":"ws:";return"".concat(e,"//").concat(window.location.host,"/ws")}();try{let e=new WebSocket(r);e.onopen=()=>{o(!0),l(null),d.current=0},e.onclose=()=>{if(o(!1),c.current=null,t.reconnect&&d.current<t.maxReconnectAttempts){let e=Math.min(t.reconnectDelay*Math.pow(2,d.current),3e4);d.current++,x.current=setTimeout(()=>{u()},e)}},e.onerror=e=>{l(Error("WebSocket connection error")),console.error("[useWebSocket] Error:",e)},e.onmessage=e=>{try{let t=JSON.parse(e.data);s(t)}catch(e){console.error("[useWebSocket] Failed to parse message:",e)}},c.current=e}catch(e){l(e instanceof Error?e:Error("Failed to create WebSocket"))}},[t.url,t.reconnect,t.maxReconnectAttempts,t.reconnectDelay]),m=(0,n.useCallback)(()=>{x.current&&(clearTimeout(x.current),x.current=null),c.current&&(c.current.close(),c.current=null),o(!1)},[]);return(0,n.useEffect)(()=>(t.autoConnect&&u(),()=>{m()}),[t.autoConnect,u,m]),{data:r,isConnected:a,error:i,connect:u,disconnect:m}}({url:h}),{workspaces:j,activeWorkspaceId:y,agents:v,isConnected:w,isLoading:N,error:k,switchWorkspace:C,addWorkspace:S,removeWorkspace:A,spawnAgent:L,stopAgent:E}=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{apiUrl:t="http://localhost:3456",enabled:r=!1}=e,[s,a]=(0,n.useState)([]),[o,i]=(0,n.useState)(),[l,c]=(0,n.useState)([]),[d,x]=(0,n.useState)(!1),[u,m]=(0,n.useState)(r),[h,p]=(0,n.useState)(null),g=(0,n.useRef)(null),b=(0,n.useRef)(),f=t.replace(/^http/,"ws"),j=(0,n.useCallback)(async()=>{if(r)try{m(!0),p(null);let e=await fetch("".concat(t,"/workspaces"));if(!e.ok)throw Error("Failed to fetch workspaces: ".concat(e.statusText));let r=await e.json();if(a(r.workspaces.map(e=>({...e,lastActiveAt:new Date(e.lastActiveAt)}))),i(r.activeWorkspaceId),r.activeWorkspaceId){let e=await fetch("".concat(t,"/workspaces/").concat(r.activeWorkspaceId,"/agents"));if(e.ok){let t=await e.json();c(t.agents.map(e=>({...e,spawnedAt:new Date(e.spawnedAt)})))}}}catch(e){p(e instanceof Error?e:Error(String(e)))}finally{m(!1)}},[t,r]);(0,n.useEffect)(()=>{if(!r)return;let e=()=>{try{let t=new WebSocket(f);t.onopen=()=>{x(!0),p(null)},t.onmessage=e=>{try{let r=JSON.parse(e.data);if("init"===r.type){var t;a(r.data.workspaces.map(e=>({...e,lastActiveAt:new Date(e.lastActiveAt)}))),i(r.data.activeWorkspaceId),c((null===(t=r.data.agents)||void 0===t?void 0:t.map(e=>({...e,spawnedAt:new Date(e.spawnedAt)})))||[]),m(!1)}else"event"===r.type&&y(r.data)}catch(e){console.error("Failed to parse WebSocket message:",e)}},t.onclose=()=>{x(!1),g.current=null,b.current=setTimeout(e,3e3)},t.onerror=e=>{console.error("WebSocket error:",e),t.close()},g.current=t}catch(t){p(t instanceof Error?t:Error(String(t))),b.current=setTimeout(e,3e3)}};return j().then(e),()=>{b.current&&clearTimeout(b.current),g.current&&g.current.close()}},[f,j,r]);let y=(0,n.useCallback)(e=>{switch(e.type){case"workspace:added":a(t=>[...t,e.data]);break;case"workspace:removed":a(t=>t.filter(t=>t.id!==e.workspaceId));break;case"workspace:updated":a(t=>t.map(t=>t.id===e.workspaceId?{...t,...e.data}:t));break;case"workspace:switched":i(e.data.currentId);break;case"agent:spawned":c(t=>[...t,e.data]);break;case"agent:stopped":case"agent:crashed":c(t=>t.filter(t=>t.name!==e.data.name));break;case"agent:restarted":c(t=>t.map(t=>t.name===e.data.name?{...t,status:"running",restartCount:t.restartCount+1}:t))}},[]),v=(0,n.useCallback)(async e=>{let r=await fetch("".concat(t,"/workspaces/").concat(e,"/switch"),{method:"POST"});if(!r.ok)throw Error("Failed to switch workspace: ".concat(r.statusText));let s=await fetch("".concat(t,"/workspaces/").concat(e,"/agents"));s.ok&&c((await s.json()).agents.map(e=>({...e,spawnedAt:new Date(e.spawnedAt)})))},[t]),w=(0,n.useCallback)(async(e,r)=>{let s=await fetch("".concat(t,"/workspaces"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e,name:r})});if(!s.ok)throw Error((await s.json()).error||"Failed to add workspace");return s.json()},[t]),N=(0,n.useCallback)(async e=>{let r=await fetch("".concat(t,"/workspaces/").concat(e),{method:"DELETE"});if(!r.ok)throw Error("Failed to remove workspace: ".concat(r.statusText))},[t]),k=(0,n.useCallback)(async(e,r,s)=>{if(!o)throw Error("No active workspace");let n=await fetch("".concat(t,"/workspaces/").concat(o,"/agents"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:e,task:r,provider:s})});if(!n.ok)throw Error((await n.json()).error||"Failed to spawn agent");return n.json()},[t,o]),C=(0,n.useCallback)(async e=>{if(!o)throw Error("No active workspace");let r=await fetch("".concat(t,"/workspaces/").concat(o,"/agents/").concat(e),{method:"DELETE"});if(!r.ok)throw Error("Failed to stop agent: ".concat(r.statusText))},[t,o]);return{workspaces:s,activeWorkspaceId:o,agents:l,isConnected:d,isLoading:u,error:h,switchWorkspace:v,addWorkspace:w,removeWorkspace:N,spawnAgent:k,stopAgent:C,refresh:j}}({apiUrl:p}),W=(0,s6.uo)(),M=(null==W?void 0:W.user)?{displayName:W.user.githubUsername,avatarUrl:W.user.avatarUrl}:void 0,[D,T]=(0,n.useState)([]),[R,P]=(0,n.useState)(null),[B,_]=(0,n.useState)(!1);(0,n.useEffect)(()=>{if(!(null==W?void 0:W.user))return;let e=async()=>{_(!0);try{let e=await el.xv.getWorkspaceSummary();e.success&&e.data.workspaces&&(T(e.data.workspaces),!R&&e.data.workspaces.length>0&&P(e.data.workspaces[0].id))}catch(e){console.error("Failed to fetch cloud workspaces:",e)}finally{_(!1)}};e();let t=setInterval(e,3e4);return()=>clearInterval(t)},[null==W?void 0:W.user,R]);let I=!!(null==W?void 0:W.user),F=(0,n.useMemo)(()=>I&&D.length>0?D.map(e=>({id:e.id,name:e.name,path:e.path||"/workspace/".concat(e.name),status:"running"===e.status?"active":"inactive",provider:"claude",lastActiveAt:new Date})):j,[I,D,j]),U=I?R:y,O=I?B:N;(0,n.useEffect)(()=>{I&&R?(0,rm.hc)(R):I||(0,rm.hc)(null)},[I,R]);let z=(0,n.useCallback)(async e=>{I?P(e.id):await C(e.id)},[I,C]),{onlineUsers:V,typingUsers:G,sendTyping:K,isConnected:J}=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{currentUser:t,wsUrl:r,autoConnect:s=!0}=e,[a,o]=(0,n.useState)([]),[i,l]=(0,n.useState)([]),[c,d]=(0,n.useState)(!1),x=(0,n.useRef)(null),u=(0,n.useRef)(null),m=(0,n.useRef)(null),h=(0,n.useRef)(!1);(0,n.useEffect)(()=>{let e=setInterval(()=>{let e=Date.now();l(t=>t.filter(t=>e-t.startedAt<3e3))},1e3);return()=>clearInterval(e)},[]);let p=(0,n.useCallback)(()=>{var e;if(!t||(null===(e=x.current)||void 0===e?void 0:e.readyState)===WebSocket.OPEN||h.current)return;h.current=!0;let s=r||function(){let e="https:"===window.location.protocol?"wss:":"ws:";return"".concat(e,"//").concat(window.location.host,"/ws/presence")}();try{let e=new WebSocket(s);e.onopen=()=>{h.current=!1,d(!0),e.send(JSON.stringify({type:"presence",action:"join",user:{username:t.username,avatarUrl:t.avatarUrl}}))},e.onclose=()=>{h.current=!1,d(!1),x.current=null,t&&(u.current=setTimeout(()=>{p()},2e3))},e.onerror=e=>{console.error("[usePresence] Error:",e)},e.onmessage=e=>{try{let r=JSON.parse(e.data);switch(r.type){case"presence_list":o(r.users||[]);break;case"presence_join":o(e=>[...e.filter(e=>e.username!==r.user.username),r.user]);break;case"presence_leave":o(e=>e.filter(e=>e.username!==r.username)),l(e=>e.filter(e=>e.username!==r.username));break;case"typing":if(r.username===(null==t?void 0:t.username))break;r.isTyping?l(e=>[...e.filter(e=>e.username!==r.username),{username:r.username,avatarUrl:r.avatarUrl,startedAt:Date.now()}]):l(e=>e.filter(e=>e.username!==r.username))}}catch(e){console.error("[usePresence] Failed to parse message:",e)}},x.current=e}catch(e){console.error("[usePresence] Failed to create WebSocket:",e)}},[t,r]),g=(0,n.useCallback)(()=>{if(u.current&&(clearTimeout(u.current),u.current=null),h.current=!1,x.current){let e=x.current;e.onclose=null,e.onerror=null,e.readyState===WebSocket.OPEN&&t&&e.send(JSON.stringify({type:"presence",action:"leave",username:t.username})),e.close(),x.current=null}d(!1)},[t]),b=(0,n.useCallback)(e=>{x.current&&x.current.readyState===WebSocket.OPEN&&t&&(m.current&&(clearTimeout(m.current),m.current=null),x.current.send(JSON.stringify({type:"typing",isTyping:e,username:t.username,avatarUrl:t.avatarUrl})),e&&(m.current=setTimeout(()=>{m.current=null,b(!1)},3e3)))},[t]),f=(0,n.useRef)(t);return f.current=t,(0,n.useEffect)(()=>{if(s&&f.current&&(!x.current||x.current.readyState===WebSocket.CLOSED))return p(),()=>{g()}},[s,null==t?void 0:t.username,p,g]),(0,n.useEffect)(()=>{let e=()=>{var e;(null===(e=x.current)||void 0===e?void 0:e.readyState)===WebSocket.OPEN&&t&&x.current.send(JSON.stringify({type:"presence",action:"leave",username:t.username}))};return window.addEventListener("beforeunload",e),()=>window.removeEventListener("beforeunload",e)},[t]),{onlineUsers:a,typingUsers:i,sendTyping:b,isConnected:c}}({currentUser:M?{username:M.displayName,avatarUrl:M.avatarUrl}:void 0}),[X,Y]=(0,n.useState)(null),[q,$]=(0,n.useState)("local"),[Z,Q]=(0,n.useState)([]),[ee,et]=(0,n.useState)(),[er,es]=(0,n.useState)(!1),[en,ea]=(0,n.useState)(!1),[eo,ei]=(0,n.useState)(null),[ec,ed]=(0,n.useState)(!1),[ex,eu]=(0,n.useState)(!1),[em,eh]=(0,n.useState)(null),[ep,eg]=(0,n.useState)(!1),[ef,ej]=(0,n.useState)(!1),[ey,ev]=(0,n.useState)(th),[ew,eN]=(0,n.useState)(!1),[ek,eC]=(0,n.useState)("dashboard"),[eS,eA]=(0,n.useState)(!1),[eL,eE]=(0,n.useState)(!1),[eW,eM]=(0,n.useState)(null),[eD,eT]=(0,n.useState)(!1),{steps:eP,status:eB,history:e_,isLoading:eI,selectTrajectory:eF,selectedTrajectoryId:eU}=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{pollInterval:t=2e3,autoPoll:r=!0,trajectoryId:s,apiBaseUrl:a=""}=e,[o,i]=(0,n.useState)([]),[l,c]=(0,n.useState)(null),[d,x]=(0,n.useState)([]),[u,m]=(0,n.useState)(!0),[h,p]=(0,n.useState)(null),[g,b]=(0,n.useState)(s||null),f=(0,n.useRef)(null),j=(0,n.useCallback)(async()=>{try{let e=a?"".concat(a,"/api/trajectory"):(0,rm.kG)("/api/trajectory"),t=await fetch(e,{credentials:"include"}),r=await t.json();!1!==r.success&&c({active:r.active,trajectoryId:r.trajectoryId,phase:r.phase,task:r.task})}catch(e){console.error("[useTrajectory] Status fetch error:",e)}},[a]),y=(0,n.useCallback)(async()=>{try{let e=a?"".concat(a,"/api/trajectory/history"):(0,rm.kG)("/api/trajectory/history"),t=await fetch(e,{credentials:"include"}),r=await t.json();r.success&&x(r.trajectories||[])}catch(e){console.error("[useTrajectory] History fetch error:",e)}},[a]),v=(0,n.useCallback)(async()=>{try{let e=g?"/api/trajectory/steps?trajectoryId=".concat(encodeURIComponent(g)):"/api/trajectory/steps",t=a?"".concat(a).concat(e):(0,rm.kG)(e),r=await fetch(t,{credentials:"include"}),s=await r.json();s.success?(i(s.steps||[]),p(null)):p(s.error||"Failed to fetch trajectory steps")}catch(e){console.error("[useTrajectory] Steps fetch error:",e),p(e.message)}},[a,g]),w=(0,n.useCallback)(e=>{b(e)},[]),N=(0,n.useCallback)(async()=>{m(!0),await Promise.all([j(),v(),y()]),m(!1)},[j,v,y]);return(0,n.useEffect)(()=>{N()},[N]),(0,n.useEffect)(()=>{v()},[g,v]),(0,n.useEffect)(()=>{if(!r)return;f.current=setInterval(()=>{v(),j()},t);let e=setInterval(y,1e4);return()=>{f.current&&clearInterval(f.current),clearInterval(e)}},[r,t,v,j,y]),{steps:o,status:l,history:d,isLoading:u,error:h,refresh:N,selectTrajectory:w,selectedTrajectoryId:g}}({autoPoll:eD}),{recentRepos:eO,addRecentRepo:ez,getRecentProjects:eV}=function(){var e;let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=null!==(e=t.maxRecent)&&void 0!==e?e:5,[s,a]=(0,n.useState)([]);(0,n.useEffect)(()=>{a(function(){try{let e=localStorage.getItem(s4);if(!e)return[];let t=JSON.parse(e);if(!Array.isArray(t))return[];return t}catch(e){return[]}}())},[]);let o=(0,n.useCallback)(e=>{a(t=>{let s=t.filter(t=>t.id!==e.id),n=[{id:e.id,path:e.path,name:e.name,lastAccessed:Date.now()},...s].slice(0,r);return s3(n),n})},[r]),i=(0,n.useCallback)(e=>{a(t=>{let r=t.filter(t=>t.id!==e);return s3(r),r})},[]),l=(0,n.useCallback)(()=>{a([]),s3([])},[]),c=(0,n.useCallback)(e=>{let t=new Map(e.map(e=>[e.id,e]));return s.map(e=>t.get(e.id)).filter(e=>void 0!==e)},[s]);return{recentRepos:s,addRecentRepo:o,removeRecentRepo:i,clearRecentRepos:l,getRecentProjects:c}}(),[eG,eK]=(0,n.useState)(!1),[eJ,eX]=(0,n.useState)(!1),[e$,eZ]=(0,n.useState)([]),[eQ,e0]=(0,n.useState)({}),[e1,e2]=(0,n.useState)(!1),[e5,e4]=(0,n.useState)([]),[e3,e6]=(0,n.useState)(),[e8,e9]=(0,n.useState)(!1),[e7,tt]=(0,n.useState)(!1),[tr,ts]=(0,n.useState)(!1),tn=(0,n.useRef)(0),to=(0,n.useRef)(!0),ti=(0,n.useCallback)(()=>{window.innerWidth<=768&&tt(!1)},[]),{agents:tl,groups:tc,selectedAgent:td,selectAgent:tx,searchQuery:tu,setSearchQuery:tm,totalCount:tp,onlineCount:tb,needsAttentionCount:tf}=function(e){let{agents:t,initialSelected:r,initialSearchQuery:s=""}=e,[i,l]=(0,n.useState)(null!=r?r:null),[d,u]=(0,n.useState)(s),m=(0,n.useMemo)(()=>c(t,d),[t,d]),h=(0,n.useMemo)(()=>o(m),[m]),p=(0,n.useMemo)(()=>[...m].sort((e,t)=>e.name.localeCompare(t.name)),[m]),g=(0,n.useMemo)(()=>{var e;return null!==(e=t.find(e=>e.name===i))&&void 0!==e?e:null},[t,i]),b=(0,n.useMemo)(()=>{let e=x(t);return{totalCount:e.total,onlineCount:e.online,needsAttentionCount:e.needsAttention}},[t]),f=(0,n.useCallback)(e=>{l(e)},[]),j=(0,n.useCallback)(e=>t.find(t=>t.name===e),[t]),y=(0,n.useCallback)(e=>({...e,color:(0,a.GW)(e.name)}),[]);return{agents:m,groups:h,sortedAgents:p,selectedAgent:g,selectAgent:f,searchQuery:d,setSearchQuery:u,...b,getAgentByName:j,getAgentWithColor:y}}({agents:null!==(d=null==g?void 0:g.agents)&&void 0!==d?d:[]}),{messages:tj,threadMessages:ty,currentChannel:tv,setCurrentChannel:tw,currentThread:tN,setCurrentThread:tk,activeThreads:tC,totalUnreadThreadCount:tS,sendMessage:tA,isSending:tL,sendError:tE}=function(e){let{messages:t,currentChannel:r="general",senderName:s}=e,[a,o]=(0,n.useState)(r),[i,l]=(0,n.useState)(null),[c,d]=(0,n.useState)(!1),[x,u]=(0,n.useState)(null),[m,h]=(0,n.useState)(new Map),p=s||"Dashboard",[g,b]=(0,n.useState)([]);(0,n.useEffect)(()=>{if(0===g.length)return;let e=new Set(t.slice(-50).map(e=>"".concat(e.from,":").concat(e.to,":").concat(e.content.slice(0,100))));b(t=>t.filter(t=>{let r="".concat(t.from,":").concat(t.to,":").concat(t.content.slice(0,100));return!e.has(r)}))},[t,g.length]);let f=(0,n.useMemo)(()=>0===g.length?t:[...t,...g],[t,g]),j=(0,n.useMemo)(()=>{let e=new Set(f.map(e=>e.id)),t=f.filter(t=>!t.thread||!e.has(t.thread));return"general"===a?t:t.filter(e=>e.from===a||e.to===a)},[f,a]),y=(0,n.useCallback)(e=>f.filter(t=>t.thread===e),[f]),v=(0,n.useMemo)(()=>{let e=new Map,t=new Set(f.map(e=>e.id));for(let t of f)if(t.thread){let r=e.get(t.thread)||[];r.push(t),e.set(t.thread,r)}let r=[];for(let[s,n]of e.entries()){let e=[...n].sort((e,t)=>new Date(t.timestamp).getTime()-new Date(e.timestamp).getTime()),a=[...new Set(n.flatMap(e=>[e.from,e.to]))].filter(e=>"*"!==e),o=m.get(s),i=n.filter(e=>e.from!==p&&!e.isRead&&(!o||new Date(e.timestamp).getTime()>o)).length,l=s;if(t.has(s)){let e=f.find(e=>e.id===s);if(e){let t=e.content.split("\n")[0];l=t.length>30?t.substring(0,30)+"...":t}}r.push({id:s,name:l,lastMessage:e[0],messageCount:n.length,unreadCount:i,participants:a})}return r.sort((e,t)=>new Date(t.lastMessage.timestamp).getTime()-new Date(e.lastMessage.timestamp).getTime())},[f,m]),w=(0,n.useCallback)(e=>{l(e),e&&h(t=>{let r=new Map(t);return r.set(e,Date.now()),r})},[]),N=(0,n.useMemo)(()=>v.filter(e=>e.unreadCount>0).length,[v]),k=(0,n.useMemo)(()=>{let e=f.filter(e=>!e.isRead).length;return{totalCount:f.length,unreadCount:e}},[f]);return{messages:j,threadMessages:y,currentChannel:a,setCurrentChannel:o,currentThread:i,setCurrentThread:w,activeThreads:v,totalUnreadThreadCount:N,sendMessage:(0,n.useCallback)(async(e,t,r,n)=>{d(!0),u(null);let a="optimistic-".concat(Date.now(),"-").concat(Math.random().toString(36).slice(2,9)),o={id:a,from:p,to:e,content:t,timestamp:new Date().toISOString(),status:"sending",thread:r,isRead:!0};b(e=>[...e,o]);try{let o={to:e,message:t,thread:r,attachments:n};s&&(o.from=s);let i=await rm.hi.sendMessage(o);if(i.success)return!0;return b(e=>e.filter(e=>e.id!==a)),u(i.error||"Failed to send message"),!1}catch(e){return b(e=>e.filter(e=>e.id!==a)),u("Network error"),!1}finally{d(!1)}},[p,s]),isSending:c,sendError:x,...k}}({messages:null!==(u=null==g?void 0:g.messages)&&void 0!==u?u:[],senderName:null==M?void 0:M.displayName}),tW=(0,n.useMemo)(()=>{var e;let t=new Set(tl.map(e=>e.name.toLowerCase())),r=new Map;for(let s of(M&&r.set(M.displayName.toLowerCase(),{username:M.displayName,avatarUrl:M.avatarUrl}),null!==(e=null==g?void 0:g.messages)&&void 0!==e?e:[])){let e=s.from;!e||"Dashboard"===e||"*"===e||t.has(e.toLowerCase())||r.has(e.toLowerCase())||r.set(e.toLowerCase(),{username:e})}return Array.from(r.values())},[null==g?void 0:g.messages,tl,M]);(0,n.useEffect)(()=>{if(!(window.innerWidth<=768)){ts(!1);return}let e=tj.length;!e7&&e>tn.current&&ts(!0),to.current=!e7},[tj.length,e7]),(0,n.useEffect)(()=>{e7&&(ts(!1),tn.current=tj.length)},[e7,tj.length]),(0,n.useEffect)(()=>{tn.current=tj.length},[]);let tM=!!(null==g?void 0:null===(r=g.fleet)||void 0===r?void 0:null===(t=r.servers)||void 0===t?void 0:t.length)||j.length>0;(0,n.useEffect)(()=>{j.length>0&&(Q(j.map(e=>({id:e.id,path:e.path,name:e.name,agents:v.filter(t=>t.workspaceId===e.id).map(e=>({name:e.name,status:"running"===e.status?"online":"offline",isSpawned:!0,cli:e.provider})),lead:void 0}))),et(y))},[j,v,y]),(0,n.useEffect)(()=>{if(j.length>0)return;let e=async()=>{let e=await rm.hi.getBridgeData();if(e.success&&e.data){let t=e.data;if(t.projects&&t.projects.length>0){let e=t.projects.map(e=>({id:e.id,path:e.path,name:e.name||e.path.split("/").pop(),agents:(e.agents||[]).map(e=>({name:e.name,status:"online"===e.status||"active"===e.status?"online":"offline",currentTask:e.task,cli:e.cli})),lead:e.lead}));Q(e),!ee&&e.length>0&&et(e[0].id)}}};e();let t=setInterval(e,5e3);return()=>clearInterval(t)},[j.length,ee]);let tD=["architect"],{bridgeAgents:tT,projectAgents:tR}=(0,n.useMemo)(()=>{let e=[],t=[];for(let r of tl)tD.includes(r.name.toLowerCase())?e.push(r):t.push(r);return{bridgeAgents:e,projectAgents:t}},[tl]),tP=(0,n.useMemo)(()=>0===Z.length||0===new Set(tR.map(e=>e.name.toLowerCase())).size?Z:Z.map((e,t)=>{if(0===t||e.id===ee){let t=new Set(e.agents.map(e=>e.name.toLowerCase())),r=tR.filter(e=>!t.has(e.name.toLowerCase()));return{...e,agents:[...e.agents,...r]}}return e}),[Z,tR,ee]),tB=(0,n.useMemo)(()=>tP.length>0?[]:tR,[tP,tR]);(0,n.useCallback)(async e=>{try{await C(e.id)}catch(e){console.error("Failed to switch workspace:",e)}},[C]);let t_=(0,n.useCallback)(async(e,t)=>{eu(!0),eh(null);try{await S(e,t),ed(!1)}catch(e){throw eh(e instanceof Error?e.message:"Failed to add workspace"),e}finally{eu(!1)}},[S]),tI=(0,n.useCallback)(e=>{et(e.id),ez(e),j.length>0&&C(e.id).catch(e=>{console.error("Failed to switch workspace:",e)}),e.agents.length>0&&(tx(e.agents[0].name),tw(e.agents[0].name)),ti()},[tx,tw,ti,j.length,C,ez]),tF=(0,n.useCallback)(e=>{tx(e.name),tw(e.name),ti()},[tx,tw,ti]),tU=(0,n.useCallback)(()=>{ei(null),es(!0)},[]),tO=(0,n.useCallback)(()=>{eC("dashboard"),eN(!0)},[]),tz=(0,n.useCallback)(()=>{eC("workspace"),eN(!0)},[]),tH=(0,n.useCallback)(()=>{eA(!0)},[]),tV=(0,n.useCallback)(()=>{eE(!0)},[]),tG=(0,n.useCallback)(()=>{eK(!0)},[]),tK=(0,n.useCallback)(async(e,t)=>{let r=await tA(e,t);if(r){if("*"===e)tx(null),tw("general");else{let t=tl.find(t=>t.name===e);t?(tx(t.name),tw(t.name)):tw(e)}}return r},[tA,tx,tw,tl]),tJ=(0,n.useCallback)(async e=>{ea(!0),ei(null);try{if(j.length>0&&y)return await L(e.name,void 0,e.command),!0;let t=await rm.hi.spawnAgent({name:e.name,cli:e.command,team:e.team,shadowMode:e.shadowMode,shadowOf:e.shadowOf,shadowAgent:e.shadowAgent,shadowTriggers:e.shadowTriggers,shadowSpeakOn:e.shadowSpeakOn});if(!t.success)return ei(t.error||"Failed to spawn agent"),!1;return!0}catch(e){return ei(e instanceof Error?e.message:"Failed to spawn agent"),!1}finally{ea(!1)}},[j.length,y,L]),tX=(0,n.useCallback)(async e=>{if(e.isSpawned&&window.confirm('Are you sure you want to release agent "'.concat(e.name,'"?')))try{if(j.length>0&&y){await E(e.name);return}let t=await rm.hi.releaseAgent(e.name);t.success||console.error("Failed to release agent:",t.error)}catch(e){console.error("Failed to release agent:",e)}},[j.length,y,E]),tY=(0,n.useCallback)(e=>{eM(e)},[]);(0,n.useEffect)(()=>{if(!e1)return;let e=async()=>{let e=await rm.hi.getFleetServers();e.success&&e.data&&e4(e.data.servers.map(e=>({id:e.id,name:e.name,url:"local"===e.id?window.location.origin:"http://".concat(e.id),status:"healthy"===e.status?"online":"degraded"===e.status?"degraded":"offline",agentCount:e.agents.length,uptime:e.uptime,lastSeen:e.lastHeartbeat})))};e();let t=setInterval(e,5e3);return()=>clearInterval(t)},[e1]),(0,n.useEffect)(()=>{if(!eJ)return;let e=async()=>{let e=await rm.hi.getDecisions();e.success&&e.data&&eZ(e.data.decisions.map(rm.XP))};e();let t=setInterval(e,5e3);return()=>clearInterval(t)},[eJ]);let tq=(0,n.useCallback)(async(e,t)=>{e0(t=>({...t,[e]:!0}));try{let r=await rm.hi.approveDecision(e,t);r.success?eZ(t=>t.filter(t=>t.id!==e)):console.error("Failed to approve decision:",r.error)}catch(e){console.error("Failed to approve decision:",e)}finally{e0(t=>({...t,[e]:!1}))}},[]),t$=(0,n.useCallback)(async(e,t)=>{e0(t=>({...t,[e]:!0}));try{let r=await rm.hi.rejectDecision(e,t);r.success?eZ(t=>t.filter(t=>t.id!==e)):console.error("Failed to reject decision:",r.error)}catch(e){console.error("Failed to reject decision:",e)}finally{e0(t=>({...t,[e]:!1}))}},[]),tZ=(0,n.useCallback)(async e=>{(await rm.hi.dismissDecision(e)).success&&eZ(t=>t.filter(t=>t.id!==e))},[]),tQ=(0,n.useCallback)(async e=>{e9(!0);try{var t;let r=eY[e.priority].beadsPriority,s=await rm.hi.createBead({title:e.title,assignee:e.agentName,priority:r,type:"task"});if(s.success&&(null===(t=s.data)||void 0===t?void 0:t.bead))await rm.hi.sendRelayMessage({to:e.agentName,content:'\uD83D\uDCCB New task assigned: "'.concat(e.title,'" (P').concat(r,")\nCheck `bd ready` for details.")}),console.log("Task created:",s.data.bead.id);else throw console.error("Failed to create task bead:",s.error),Error(s.error||"Failed to create task")}catch(e){throw console.error("Failed to create task:",e),e}finally{e9(!1)}},[]),t0=(0,n.useCallback)(()=>{eg(!0)},[]),t1=(0,n.useCallback)(()=>{eg(!1)},[]);n.useEffect(()=>{let e=e=>{let t;t="system"===e?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":e,document.documentElement.setAttribute("data-theme",t)};if(e(ey.theme),"system"===ey.theme){let t=window.matchMedia("(prefers-color-scheme: dark)"),r=()=>e("system");return t.addEventListener("change",r),()=>t.removeEventListener("change",r)}},[ey.theme]),n.useEffect(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&"k"===e.key&&(e.preventDefault(),eg(!0)),(e.metaKey||e.ctrlKey)&&e.shiftKey&&"s"===e.key&&(e.preventDefault(),tU()),(e.metaKey||e.ctrlKey)&&"n"===e.key&&(e.preventDefault(),tV()),"Escape"===e.key&&(eg(!1),es(!1),eE(!1),eT(!1),eN(!1))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[tU,tV]);let t2=window.location.pathname,t5=new URLSearchParams(window.location.search);return"/billing/success"===t2?(0,s.jsx)(s2,{type:"success",sessionId:t5.get("session_id")||void 0,onClose:()=>{window.location.href="/"}}):"/billing/canceled"===t2?(0,s.jsx)(s2,{type:"canceled",onClose:()=>{window.location.href="/"}}):(0,s.jsx)(rK,{wsUrl:h,children:(0,s.jsxs)("div",{className:"flex h-screen bg-bg-deep font-sans text-text-primary",children:[(0,s.jsx)("div",{className:"\n fixed inset-0 bg-black/60 backdrop-blur-sm z-[999] transition-opacity duration-200\n md:hidden\n ".concat(e7?"opacity-100 pointer-events-auto":"opacity-0 pointer-events-none","\n "),onClick:()=>tt(!1)}),(0,s.jsxs)("div",{className:"\n flex flex-col w-[280px] max-md:w-[85vw] max-md:max-w-[280px] h-screen bg-bg-primary border-r border-border-subtle\n fixed left-0 top-0 z-[1000] transition-transform duration-200\n md:relative md:translate-x-0 md:flex-shrink-0\n ".concat(e7?"translate-x-0":"-translate-x-full","\n "),children:[(0,s.jsx)("div",{className:"p-3 border-b border-sidebar-border",children:(0,s.jsx)(rM,{workspaces:F,activeWorkspaceId:null!=U?U:void 0,onSelect:z,onAddWorkspace:()=>ed(!0),onWorkspaceSettings:tz,isLoading:O})}),(0,s.jsx)(H,{agents:tB,bridgeAgents:tT,projects:tP,currentProject:ee,selectedAgent:null==td?void 0:td.name,viewMode:q,isFleetAvailable:tM,isConnected:b||w,isOpen:e7,activeThreads:tC,currentThread:tN,totalUnreadThreadCount:tS,onAgentSelect:tF,onProjectSelect:tI,onViewModeChange:$,onSpawnClick:tU,onReleaseClick:tX,onLogsClick:tY,onThreadSelect:tk,onClose:()=>tt(!1),onSettingsClick:tO,onTrajectoryClick:()=>eT(!0),hasActiveTrajectory:null==eB?void 0:eB.active,onFleetClick:()=>e2(!e1),isFleetViewActive:e1,onCoordinatorClick:tG,hasMultipleProjects:tP.length>1})]}),(0,s.jsxs)("main",{className:"flex-1 flex flex-col min-w-0 bg-bg-secondary/50 overflow-hidden",children:[(0,s.jsxs)("div",{className:"sticky top-0 z-50 flex-shrink-0",children:[(0,s.jsx)(eb,{currentChannel:tv,selectedAgent:td,projects:tP,currentProject:tP.find(e=>e.id===ee)||null,recentProjects:eV(tP),onProjectChange:tI,onCommandPaletteOpen:t0,onSettingsClick:tO,onHistoryClick:tH,onNewConversationClick:tV,onCoordinatorClick:tG,onFleetClick:()=>e2(!e1),isFleetViewActive:e1,onTrajectoryClick:()=>eT(!0),hasActiveTrajectory:null==eB?void 0:eB.active,onMenuClick:()=>tt(!0),hasUnreadNotifications:tr}),M&&V.length>0&&(0,s.jsx)("div",{className:"flex items-center justify-end px-4 py-1 bg-bg-tertiary/80 border-b border-border-subtle",children:(0,s.jsx)(sU,{onlineUsers:V,onUserClick:Y})})]}),(0,s.jsxs)("div",{className:"flex-1 flex overflow-hidden min-h-0",children:[(0,s.jsx)("div",{className:"flex-1 min-h-0 overflow-y-auto ".concat(tN?"hidden md:block md:flex-[2]":""),children:f?(0,s.jsxs)("div",{className:"flex flex-col items-center justify-center h-full text-text-muted text-center px-4",children:[(0,s.jsx)(ne,{}),(0,s.jsx)("h2",{className:"m-0 mb-2 font-display text-text-primary",children:"Connection Error"}),(0,s.jsx)("p",{className:"text-text-secondary",children:f.message}),(0,s.jsx)("button",{className:"mt-6 py-3 px-6 bg-gradient-to-r from-accent-cyan to-[#00b8d9] text-bg-deep font-semibold border-none rounded-xl cursor-pointer transition-all duration-150 hover:shadow-glow-cyan hover:-translate-y-0.5",onClick:()=>window.location.reload(),children:"Retry Connection"})]}):g?e1?(0,s.jsx)("div",{className:"p-4 h-full overflow-y-auto",children:(0,s.jsx)(sT,{servers:e5,agents:tl,selectedServerId:e3,onServerSelect:e6,onServerReconnect:e=>{console.log("Reconnecting to server:",e)},isLoading:!g})}):(0,s.jsx)(eR,{messages:tj,currentChannel:tv,currentThread:tN,onThreadClick:e=>tk(e),highlightedMessageId:null!=tN?tN:void 0,agents:null==g?void 0:g.agents,currentUser:M}):(0,s.jsxs)("div",{className:"flex flex-col items-center justify-center h-full text-text-muted text-center",children:[(0,s.jsx)(s7,{}),(0,s.jsx)("p",{className:"font-display text-text-secondary",children:"Connecting to dashboard..."})]})}),tN&&(()=>{let e=tj.find(e=>e.id===tN),t=!e;if(!e){var r;e=null!==(r=tj.filter(e=>e.thread===tN).sort((e,t)=>new Date(e.timestamp).getTime()-new Date(t.timestamp).getTime())[0])&&void 0!==r?r:null}return(0,s.jsx)("div",{className:"w-full md:w-[400px] md:min-w-[320px] md:max-w-[500px] flex-shrink-0",children:(0,s.jsx)(eH,{originalMessage:null!=e?e:null,replies:ty(tN),onClose:()=>tk(null),onReply:async r=>{let s="*";return!t&&e&&(s="Dashboard"===e.from||M&&e.from===M.displayName?e.to:e.from),tA(s,r,tN)},isSending:tL,currentUser:M})})})()]}),G.length>0&&(0,s.jsx)("div",{className:"px-4 bg-bg-tertiary border-t border-border-subtle",children:(0,s.jsx)(sF,{typingUsers:G})}),(0,s.jsx)("div",{className:"p-2 sm:p-4 bg-bg-tertiary border-t border-border-subtle",children:(0,s.jsx)(s9,{recipient:"general"===tv?"*":tv,agents:tl,humanUsers:tW,onSend:tA,onTyping:K,isSending:tL,error:tE})})]}),(0,s.jsx)(eq,{isOpen:ep,onClose:t1,agents:tl,projects:Z,currentProject:ee,onAgentSelect:tF,onProjectSelect:tI,onSpawnClick:tU,onTaskCreate:tQ,onGeneralClick:()=>{tx(null),tw("general")}}),(0,s.jsx)(te,{isOpen:er,onClose:()=>es(!1),onSpawn:tJ,existingAgents:tl.map(e=>e.name),isSpawning:en,error:eo}),(0,s.jsx)(tg,{isOpen:ef,onClose:()=>ej(!1),settings:ey,onSettingsChange:ev,onResetSettings:()=>ev(th),csrfToken:null!==(m=null==W?void 0:W.csrfToken)&&void 0!==m?m:void 0}),(0,s.jsx)(rI,{isOpen:ec,onClose:()=>{ed(!1),eh(null)},onAdd:t_,isAdding:ex,error:em}),(0,s.jsx)(rh,{isOpen:eS,onClose:()=>eA(!1)}),(0,s.jsx)(ta,{isOpen:eL,onClose:()=>eE(!1),onSend:tK,agents:tl,isSending:tL,error:tE}),eW&&(0,s.jsx)(r7,{agent:eW,isOpen:!0,onClose:()=>eM(null),availableAgents:tl,onAgentChange:eM}),eD&&(0,s.jsx)("div",{className:"fixed inset-0 z-50 flex bg-black/50 backdrop-blur-sm",onClick:()=>eT(!1),children:(0,s.jsxs)("div",{className:"ml-auto w-full max-w-3xl h-full bg-bg-primary shadow-2xl animate-in slide-in-from-right duration-300 flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,s.jsxs)("div",{className:"flex items-center justify-between px-6 py-4 border-b border-border-subtle bg-bg-secondary",children:[(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsx)("div",{className:"w-10 h-10 rounded-xl bg-gradient-to-br from-blue-500/20 to-accent-cyan/20 flex items-center justify-center border border-blue-500/30",children:(0,s.jsx)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"text-blue-500",children:(0,s.jsx)("path",{d:"M3 12h4l3 9 4-18 3 9h4",strokeLinecap:"round",strokeLinejoin:"round"})})}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h2",{className:"text-lg font-semibold text-text-primary m-0",children:"Trajectory Viewer"}),(0,s.jsx)("p",{className:"text-xs text-text-muted m-0",children:(null==eB?void 0:eB.active)?"Active: ".concat(eB.task||"Working..."):"Browse past trajectories"})]})]}),(0,s.jsx)("button",{onClick:()=>eT(!1),className:"w-10 h-10 rounded-lg bg-bg-tertiary border border-border-subtle flex items-center justify-center text-text-muted hover:text-text-primary hover:bg-bg-hover hover:border-blue-500/50 transition-all",title:"Close (Esc)",children:(0,s.jsx)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.jsx)("path",{d:"M18 6L6 18M6 6l12 12"})})})]}),(0,s.jsx)("div",{className:"flex-1 overflow-hidden p-6",children:(0,s.jsx)(sl,{agentName:(null==eB?void 0:null===(i=eB.task)||void 0===i?void 0:i.slice(0,30))||"Current",steps:eP,history:e_,selectedTrajectoryId:eU,onSelectTrajectory:eF,isLoading:eI})})]})}),eJ&&(0,s.jsx)("div",{className:"fixed left-4 bottom-4 w-[400px] max-h-[500px] z-50 shadow-modal",children:(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsx)("button",{onClick:()=>eX(!1),className:"absolute -top-2 -right-2 w-6 h-6 bg-bg-elevated border border-border rounded-full flex items-center justify-center text-text-muted hover:text-text-primary hover:bg-bg-hover z-10",title:"Close decisions",children:(0,s.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.jsx)("path",{d:"M18 6L6 18M6 6l12 12"})})}),(0,s.jsx)(sw,{decisions:e$,onApprove:tq,onReject:t$,onDismiss:tZ,isProcessing:eQ})]})}),!eJ&&e$.length>0&&(0,s.jsxs)("button",{onClick:()=>eX(!0),className:"fixed left-4 bottom-4 w-12 h-12 bg-warning text-bg-deep rounded-full shadow-[0_0_20px_rgba(255,107,53,0.4)] flex items-center justify-center hover:scale-105 transition-transform z-50",title:"".concat(e$.length," pending decision").concat(e$.length>1?"s":""),children:[(0,s.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,s.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),(0,s.jsx)("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]}),e$.length>0&&(0,s.jsx)("span",{className:"absolute -top-1 -right-1 w-5 h-5 bg-error text-white text-[10px] font-bold rounded-full flex items-center justify-center",children:e$.length})]}),(0,s.jsx)(sO,{user:X,onClose:()=>Y(null),onMention:e=>{Y(null)}}),(0,s.jsx)(sH,{isOpen:eG,onClose:()=>eK(!1),projects:tP,isCloudMode:!!M,hasArchitect:tT.some(e=>"architect"===e.name.toLowerCase()),onArchitectSpawned:()=>{eK(!1)}}),ew&&(0,s.jsx)(t7,{currentUserId:null==W?void 0:null===(l=W.user)||void 0===l?void 0:l.id,initialTab:ek,onClose:()=>eN(!1)})]})})}function s9(e){let{recipient:t,agents:r,humanUsers:a,onSend:o,onTyping:i,isSending:l,error:c}=e,[d,x]=(0,n.useState)(""),[u,m]=(0,n.useState)(0),[h,p]=(0,n.useState)(!1),[g,b]=(0,n.useState)(!1),[f,j]=(0,n.useState)([]),y=(0,n.useRef)(null),v=(0,n.useRef)(null),w=(0,n.useCallback)(async e=>{for(let t of e){let e=crypto.randomUUID(),r=URL.createObjectURL(t);j(s=>[...s,{id:e,file:t,preview:r,isUploading:!0}]);try{let r=await rm.hi.uploadAttachment(t);r.success&&r.data?j(t=>t.map(t=>t.id===e?{...t,isUploading:!1,uploadedId:r.data.attachment.id}:t)):j(t=>t.map(t=>t.id===e?{...t,isUploading:!1,error:r.error||"Upload failed"}:t))}catch(t){j(t=>t.map(t=>t.id===e?{...t,isUploading:!1,error:"Upload failed"}:t))}}},[]),N=(0,n.useCallback)(e=>{if(!e||0===e.length)return;let t=Array.from(e).filter(e=>e.type.startsWith("image/"));t.length>0&&w(t)},[w]),k=(0,n.useCallback)(e=>{let t=e.clipboardData;if(!t)return;let r=[];if(t.files&&t.files.length>0&&(r=Array.from(t.files).filter(e=>e.type.startsWith("image/"))),0===r.length&&t.items){for(let e of Array.from(t.items))if("file"===e.kind&&e.type.startsWith("image/")){let t=e.getAsFile();t&&r.push(t)}}r.length>0&&(e.preventDefault(),w(r))},[w]),C=(0,n.useCallback)(e=>{j(t=>{let r=t.find(t=>t.id===e);return r&&URL.revokeObjectURL(r.preview),t.filter(t=>t.id!==e)})},[]),S=async e=>{let r,s;e.preventDefault();let n=d.trim().length>0,a=f.length>0;if(!n&&!a||l||f.some(e=>e.isUploading))return;let i=f.filter(e=>e.uploadedId).map(e=>e.uploadedId),c=d.match(/^@(\S+)\s*([\s\S]*)/);if(c){let e=c[1];s=c[2]||"","*"===e||"everyone"===e.toLowerCase()||"all"===e.toLowerCase()?r="*":e.toLowerCase().startsWith("team:")?r=e:e.includes("/")||/\.(ts|tsx|js|jsx|json|md|py|go|rs|java|c|cpp|h|css|html|yaml|yml|toml)$/i.test(e)?(r=t,s=d):r=e}else r=t,s=d;!s.trim()&&i.length>0&&(s="[Screenshot attached]"),await o(r,s||d,void 0,i.length>0?i:void 0)&&(f.forEach(e=>URL.revokeObjectURL(e.preview)),x(""),j([]),p(!1),b(!1))},A=(d.trim()||f.length>0)&&!l&&!f.some(e=>e.isUploading);return(0,s.jsxs)("form",{className:"flex flex-col gap-1.5 sm:gap-2",onSubmit:S,children:[f.length>0&&(0,s.jsx)("div",{className:"flex flex-wrap gap-1.5 sm:gap-2 p-1.5 sm:p-2 bg-bg-card rounded-lg border border-border-subtle",children:f.map(e=>(0,s.jsxs)("div",{className:"relative group",children:[(0,s.jsx)("img",{src:e.preview,alt:e.file.name,className:"h-16 w-auto rounded-lg object-cover ".concat(e.isUploading?"opacity-50":""," ").concat(e.error?"border-2 border-error":"")}),e.isUploading&&(0,s.jsx)("div",{className:"absolute inset-0 flex items-center justify-center",children:(0,s.jsx)("svg",{className:"animate-spin h-5 w-5 text-accent-cyan",viewBox:"0 0 24 24",children:(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeDasharray:"32",strokeLinecap:"round"})})}),e.error&&(0,s.jsx)("div",{className:"absolute bottom-0 left-0 right-0 bg-error/90 text-white text-[10px] px-1 py-0.5 truncate",children:e.error}),(0,s.jsx)("button",{type:"button",onClick:()=>C(e.id),className:"absolute -top-1.5 -right-1.5 w-5 h-5 bg-bg-tertiary border border-border-subtle rounded-full flex items-center justify-center text-text-muted hover:text-error hover:border-error transition-colors opacity-0 group-hover:opacity-100",title:"Remove",children:(0,s.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",children:[(0,s.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},e.id))}),(0,s.jsxs)("div",{className:"flex items-center gap-1.5 sm:gap-3",children:[(0,s.jsx)("input",{ref:v,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:e=>N(e.target.files)}),(0,s.jsx)("button",{type:"button",onClick:()=>{var e;return null===(e=v.current)||void 0===e?void 0:e.click()},className:"p-2 sm:p-2.5 bg-bg-card border border-border-subtle rounded-lg sm:rounded-xl text-text-muted hover:text-accent-cyan hover:border-accent-cyan/50 transition-colors flex-shrink-0",title:"Attach screenshot (or paste from clipboard)",children:(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"sm:w-[18px] sm:h-[18px]",children:[(0,s.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"}),(0,s.jsx)("circle",{cx:"8.5",cy:"8.5",r:"1.5"}),(0,s.jsx)("polyline",{points:"21 15 16 10 5 21"})]})}),(0,s.jsxs)("div",{className:"flex-1 relative min-w-0",children:[(0,s.jsx)(rS,{agents:r,humanUsers:a,inputValue:d,cursorPosition:u,onSelect:(e,t)=>{x(t),p(!1),b(!1),setTimeout(()=>{if(y.current){y.current.focus();let e=t.indexOf(" ")+1;y.current.setSelectionRange(e,e)}},0)},onClose:()=>p(!1),isVisible:h}),(0,s.jsx)(rW,{inputValue:d,cursorPosition:u,onSelect:(e,t)=>{x(t),b(!1),p(!1),setTimeout(()=>{if(y.current){y.current.focus();let e=t.indexOf(" ",1)+1;y.current.setSelectionRange(e,e)}},0)},onClose:()=>b(!1),isVisible:g}),(0,s.jsx)("textarea",{ref:y,className:"w-full py-2 sm:py-3 px-3 sm:px-4 bg-bg-card border border-border-subtle rounded-lg sm:rounded-xl text-sm font-sans text-text-primary outline-none transition-all duration-200 resize-none min-h-[40px] sm:min-h-[44px] max-h-[100px] sm:max-h-[120px] overflow-y-auto focus:border-accent-cyan/50 focus:shadow-[0_0_0_3px_rgba(0,217,255,0.1)] placeholder:text-text-muted",placeholder:"Message ".concat("*"===t?"everyone":"@"+t,"..."),value:d,onChange:e=>{let t=e.target.value,r=e.target.selectionStart||0;if(x(t),m(r),null==i||i(t.trim().length>0),null!==rA(t,r)){b(!0),p(!1);return}if(null!==rk(t,r)){p(!0),b(!1);return}p(!1),b(!1)},onKeyDown:e=>{(!h&&!g||"ArrowDown"!==e.key&&"ArrowUp"!==e.key&&"Tab"!==e.key)&&("Enter"!==e.key||e.shiftKey||h||g||(e.preventDefault(),(d.trim()||f.length>0)&&!l&&S(e)))},onPaste:k,onSelect:e=>m(e.target.selectionStart||0),disabled:l,rows:1})]}),(0,s.jsx)("button",{type:"submit",className:"py-2 sm:py-3 px-3 sm:px-5 bg-gradient-to-r from-accent-cyan to-[#00b8d9] text-bg-deep font-semibold border-none rounded-lg sm:rounded-xl text-xs sm:text-sm cursor-pointer transition-all duration-150 hover:shadow-glow-cyan hover:-translate-y-0.5 disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:translate-y-0 disabled:hover:shadow-none flex-shrink-0",disabled:!A,title:l?"Sending...":f.some(e=>e.isUploading)?"Uploading...":"Send message",children:l?(0,s.jsx)("span",{className:"hidden sm:inline",children:"Sending..."}):f.some(e=>e.isUploading)?(0,s.jsx)("span",{className:"hidden sm:inline",children:"Uploading..."}):(0,s.jsxs)("span",{className:"flex items-center gap-1 sm:gap-2",children:[(0,s.jsx)("span",{className:"hidden sm:inline",children:"Send"}),(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),(0,s.jsx)("polygon",{points:"22 2 15 22 11 13 2 9 22 2"})]})]})}),c&&(0,s.jsx)("span",{className:"text-error text-xs ml-2",children:c})]})]})}function s7(){return(0,s.jsx)("svg",{className:"animate-spin mb-4 text-accent-cyan",width:"28",height:"28",viewBox:"0 0 24 24",children:(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeDasharray:"32",strokeLinecap:"round"})})}function ne(){return(0,s.jsxs)("svg",{className:"text-error mb-4",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,s.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),(0,s.jsx)("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]})}},5372:function(e,t,r){r.d(t,{TI:function(){return c},uo:function(){return d}});var s=r(7437),n=r(2265),a=r(9165);let o={checkOnMount:!0,checkInterval:6e4,onExpired:()=>{}};function i(e){let{isOpen:t,error:r,onLogin:n,onDismiss:a}=e;return t?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"fixed inset-0 bg-black/60 backdrop-blur-sm z-[9998]",onClick:a,"aria-hidden":"true"}),(0,s.jsx)("div",{className:"fixed inset-0 flex items-center justify-center z-[9999] p-4",role:"dialog","aria-modal":"true","aria-labelledby":"session-expired-title",children:(0,s.jsxs)("div",{className:"bg-bg-primary rounded-lg shadow-xl max-w-md w-full p-6 animate-in fade-in zoom-in-95 duration-200",children:[(0,s.jsx)("div",{className:"flex justify-center mb-4",children:(0,s.jsx)("div",{className:"w-16 h-16 rounded-full bg-warning/10 flex items-center justify-center",children:(0,s.jsx)("svg",{className:"w-8 h-8 text-warning",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:(0,s.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})})})}),(0,s.jsx)("h2",{id:"session-expired-title",className:"text-xl font-semibold text-text-primary text-center mb-2",children:"Session Expired"}),(0,s.jsx)("p",{className:"text-text-muted text-center mb-6",children:(()=>{if(!r)return"Your session has expired. Please log in again to continue.";switch(r.code){case"SESSION_EXPIRED":return"Your session has expired. Please log in again to continue.";case"USER_NOT_FOUND":return"Your account was not found. Please log in again.";case"SESSION_ERROR":return"There was a problem with your session. Please log in again.";default:return r.message||"Your session has expired. Please log in again."}})()}),(0,s.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,s.jsx)("button",{onClick:n,className:"w-full py-3 px-4 bg-accent text-white font-medium rounded-lg hover:bg-accent-hover transition-colors duration-200 focus:outline-none focus:ring-2 focus:ring-accent focus:ring-offset-2 focus:ring-offset-bg-primary",children:"Log In Again"}),a&&(0,s.jsx)("button",{onClick:a,className:"w-full py-3 px-4 text-text-muted hover:text-text-primary font-medium rounded-lg transition-colors duration-200 hover:bg-bg-secondary",children:"Dismiss"})]}),(0,s.jsx)("p",{className:"text-xs text-text-muted text-center mt-4",children:"You'll be redirected to the login page where you can sign in with GitHub."})]})})]}):null}let l=(0,n.createContext)(void 0);function c(e){let{children:t,cloudMode:r,checkInterval:c=6e4,onSessionExpired:d}=e,x=null!=r?r:function(){let e=window.location.hostname;if(e.includes("agent-relay.com")||e.includes("agentrelay.cloud"))return!0;let t=document.querySelector('meta[name="agent-relay-cloud"]');return(null==t?void 0:t.getAttribute("content"))==="true"||"true"===localStorage.getItem("agent-relay-cloud-mode")}(),u=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t={...o,...e},[r,s]=(0,n.useState)(null),[i,l]=(0,n.useState)(!0),[c,d]=(0,n.useState)(!1),[x,u]=(0,n.useState)(null),m=(0,n.useRef)(null),h=(0,n.useRef)(!0),p=(0,n.useCallback)(async()=>{try{let e=await a.xv.checkSession();if(!h.current)return e;if(!e.authenticated&&(s(null),e.code)){let r={error:"Session expired",code:e.code,message:e.message||"Your session has expired. Please log in again."};u(r),d(!0),t.onExpired(r)}return e}catch(e){return{authenticated:!1,code:"SESSION_ERROR",message:"Failed to check session"}}},[t]),g=(0,n.useCallback)(async()=>{l(!0);try{let e=await a.xv.getMe();if(!h.current)return;e.success?(s(e.data),d(!1),u(null)):e.sessionExpired?(s(null),d(!0)):u({error:e.error,code:"SESSION_ERROR",message:e.error})}finally{h.current&&l(!1)}},[]);(0,n.useEffect)(()=>(0,a.Zk)(e=>{h.current&&(s(null),d(!0),u(e),t.onExpired(e))}),[t]),(0,n.useEffect)(()=>(h.current=!0,t.checkOnMount&&g(),()=>{h.current=!1}),[t.checkOnMount,g]),(0,n.useEffect)(()=>{if(!(t.checkInterval<=0))return m.current=setInterval(()=>{r&&p()},t.checkInterval),()=>{m.current&&(clearInterval(m.current),m.current=null)}},[t.checkInterval,r,p]);let b=(0,n.useCallback)(()=>{d(!1),u(null)},[]),f=(0,n.useCallback)(()=>{let e=encodeURIComponent(window.location.pathname+window.location.search);window.location.href="/login?returnTo=".concat(e)},[]),j=(0,n.useCallback)(async()=>{await a.xv.logout(),s(null),d(!1),u(null),window.location.href="/login"},[]);return{user:r,isLoading:i,isAuthenticated:null!==r,isExpired:c,error:x,csrfToken:(0,a._V)(),checkSession:p,clearExpired:b,redirectToLogin:f,logout:j}}({checkOnMount:x,checkInterval:x?c:0,onExpired:d}),m=(0,n.useCallback)(()=>{u.redirectToLogin()},[u]),h=(0,n.useCallback)(()=>{u.clearExpired()},[u]),p={...u,isCloudMode:x};return(0,s.jsxs)(l.Provider,{value:p,children:[t,x&&(0,s.jsx)(i,{isOpen:u.isExpired,error:u.error,onLogin:m,onDismiss:h})]})}function d(){return(0,n.useContext)(l)}},6272:function(e,t,r){r.d(t,{K7:function(){return n}});var s=r(7437);function n(e){let{size:t=24,className:r="",withGlow:n=!1}=e;return(0,s.jsxs)("svg",{width:t,height:t,viewBox:"0 0 100 100",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:"\n transition-all duration-300\n ".concat(n?"drop-shadow-[0_0_8px_rgba(0,217,255,0.3)]":"","\n ").concat(r,"\n "),"aria-label":"Agent Relay Logo",role:"img",children:[(0,s.jsx)("path",{d:"M30 80 L 50 20 L 70 80",stroke:"#00d9ff",strokeWidth:"5",strokeLinejoin:"round",strokeLinecap:"round",fill:"none"}),(0,s.jsx)("line",{x1:"40",y1:"50",x2:"60",y2:"50",stroke:"#00d9ff",strokeWidth:"5",strokeLinecap:"round"}),(0,s.jsx)("path",{d:"M50 20 L 50 80",stroke:"#00ffc8",strokeWidth:"2.5",strokeLinecap:"round",opacity:"0.7"}),(0,s.jsx)("path",{d:"M50 20 C 80 20 80 50 50 50 L 80 80",stroke:"#00ffc8",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",fill:"none",opacity:"0.7"})]})}r(2265)},3083:function(e,t,r){r.d(t,{j:function(){return o}});var s=r(7437),n=r(2265);let a={codex:"openai"};function o(e){let{provider:t,workspaceId:r,csrfToken:o,onSuccess:i,onCancel:l,onError:c,useDeviceFlow:d=!1}=e,[x,u]=(0,n.useState)("idle"),[m,h]=(0,n.useState)(null),[p,g]=(0,n.useState)(null),[b,f]=(0,n.useState)(""),[j,y]=(0,n.useState)(null),[v,w]=(0,n.useState)(null),[N,k]=(0,n.useState)(null),[C,S]=(0,n.useState)(!1),[A,L]=(0,n.useState)(!1),E=(0,n.useRef)(!1),W=(0,n.useRef)(!1),M=(0,n.useRef)(!1),D=a[t.id]||t.id,T=(0,n.useCallback)(async()=>{u("starting"),y(null),E.current=!1;try{let e={"Content-Type":"application/json"};o&&(e["X-CSRF-Token"]=o);let t=await fetch("/api/onboarding/cli/".concat(D,"/start"),{method:"POST",credentials:"include",headers:e,body:JSON.stringify({workspaceId:r,useDeviceFlow:d})}),s=await t.json();if(!t.ok)throw Error(s.error||"Failed to start authentication");if("success"===s.status||s.alreadyAuthenticated){u("success"),i();return}g(s.sessionId),s.authUrl?(h(s.authUrl),u("waiting"),I(s.authUrl),F(s.sessionId)):s.sessionId&&F(s.sessionId)}catch(t){let e=t instanceof Error?t.message:"Failed to start authentication";y(e),u("error"),c(e)}},[D,r,o,d,i,c]),R=t.requiresUrlCopy||"codex"===t.id||"openai"===D,P=(0,n.useRef)(null),B=(0,n.useCallback)(e=>{if(M.current)return;M.current=!0,L(!0);let t=0,r=async()=>{if(t>=120||!M.current){M.current=!1,L(!1);return}try{let s=await fetch("/api/auth/codex-helper/status/".concat(e),{credentials:"include"});if(s.ok){let e=await s.json();if(e.ready&&e.code){M.current=!1,L(!1),f(e.code),P.current&&P.current(e.code);return}}t++,setTimeout(r,5e3)}catch(e){console.error("CLI poll error:",e),t++,setTimeout(r,5e3)}};r()},[]),_=(0,n.useCallback)(async()=>{if(R)try{let e={"Content-Type":"application/json"};o&&(e["X-CSRF-Token"]=o);let t=await fetch("/api/auth/codex-helper/cli-session",{method:"POST",credentials:"include",headers:e});if(t.ok){let e=await t.json();w(e.command),k(e.authSessionId),B(e.authSessionId)}}catch(e){console.error("Failed to fetch CLI session:",e)}},[R,o,B]);(0,n.useEffect)(()=>{"waiting"===x&&R&&!v&&_()},[x,R,v,_]);let I=(0,n.useCallback)(e=>{let r=window.screenX+(window.outerWidth-600)/2,s=window.screenY+(window.outerHeight-700)/2;window.open(e,"".concat(t.displayName," Login"),"width=".concat(600,",height=").concat(700,",left=").concat(r,",top=").concat(s,",popup=yes")),E.current=!0},[t.displayName]),F=(0,n.useCallback)(e=>{if(W.current)return;W.current=!0;let t=0,r=async()=>{if(t>=60){W.current=!1,y("Authentication timed out. Please try again."),u("error"),c("Authentication timed out");return}try{let s=await fetch("/api/onboarding/cli/".concat(D,"/status/").concat(e),{credentials:"include"}),n=await s.json();if(!s.ok)throw Error(n.error||"Failed to check status");if("success"===n.status){W.current=!1,await U(e);return}if("error"===n.status)throw Error(n.error||"Authentication failed");"waiting_auth"===n.status&&n.authUrl&&(h(n.authUrl),u("waiting"),E.current||I(n.authUrl)),t++,setTimeout(r,5e3)}catch(t){W.current=!1;let e=t instanceof Error?t.message:"Auth check failed";y(e),u("error"),c(e)}};r()},[D,I,c]),U=(0,n.useCallback)(async e=>{let t=e||p;if(t){u("submitting"),y(null);try{let e={"Content-Type":"application/json"};o&&(e["X-CSRF-Token"]=o);let r=await fetch("/api/onboarding/cli/".concat(D,"/complete/").concat(t),{method:"POST",credentials:"include",headers:e}),s=await r.json();if(!r.ok)throw Error(s.error||"Failed to complete authentication");u("success"),setTimeout(()=>i(),1500)}catch(t){let e=t instanceof Error?t.message:"Failed to complete authentication";y(e),u("error"),c(e)}}},[p,D,o,i,c]),O=(0,n.useCallback)(async()=>{if(!p||!b.trim())return;u("submitting"),y(null);let e=b.trim();if(e.includes("code="))try{let t=new URL(e).searchParams.get("code");t&&(e=t)}catch(r){let t=e.match(/code=([^&\s]+)/);t&&(e=t[1])}try{let t={"Content-Type":"application/json"};o&&(t["X-CSRF-Token"]=o);let r=await fetch("/api/onboarding/cli/".concat(D,"/code/").concat(p),{method:"POST",credentials:"include",headers:t,body:JSON.stringify({code:e})}),s=await r.json();if(!r.ok){if(s.needsRestart){y('The authentication session timed out. Please click "Try Again" to restart.'),u("error");return}throw Error(s.error||"Failed to submit auth code")}f(""),s.success&&await U()}catch(t){let e=t instanceof Error?t.message:"Failed to submit auth code";y(e),u("error"),c(e)}},[p,b,D,o,U,c]);(0,n.useEffect)(()=>{P.current=async e=>{if(p){u("submitting"),y(null);try{let t={"Content-Type":"application/json"};o&&(t["X-CSRF-Token"]=o);let r=await fetch("/api/onboarding/cli/".concat(D,"/code/").concat(p),{method:"POST",credentials:"include",headers:t,body:JSON.stringify({code:e})}),s=await r.json();if(!r.ok){if(s.needsRestart){y('The authentication session timed out. Please click "Try Again" to restart.'),u("error");return}throw Error(s.error||"Failed to submit auth code")}s.success&&await U()}catch(t){let e=t instanceof Error?t.message:"Failed to submit auth code";y(e),u("error"),c(e)}}}},[p,D,o,U,c]);let z=(0,n.useCallback)(async()=>{if(W.current=!1,p)try{await fetch("/api/onboarding/cli/".concat(D,"/cancel/").concat(p),{method:"POST",credentials:"include"})}catch(e){}u("idle"),h(null),g(null),f(""),y(null),l()},[p,D,l]);(0,n.useEffect)(()=>("idle"===x&&T(),()=>{W.current=!1,M.current=!1,L(!1)}),[T,x]);let H="anthropic"===t.id||"anthropic"===D;return(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsx)("div",{className:"w-10 h-10 rounded-lg flex items-center justify-center text-white font-bold",style:{backgroundColor:t.color},children:t.displayName[0]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h3",{className:"font-medium text-white",children:t.displayName}),(0,s.jsxs)("p",{className:"text-sm text-text-muted",children:["starting"===x&&"Starting authentication...","waiting"===x&&"Complete authentication below","submitting"===x&&"Verifying...","success"===x&&"Connected!","error"===x&&(j||"Authentication failed")]})]})]}),"starting"===x&&(0,s.jsxs)("div",{className:"flex items-center justify-center gap-3 py-4",children:[(0,s.jsxs)("svg",{className:"w-5 h-5 text-accent-cyan animate-spin",fill:"none",viewBox:"0 0 24 24",children:[(0,s.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,s.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),(0,s.jsx)("span",{className:"text-text-muted",children:"Preparing authentication..."})]}),"waiting"===x&&m&&(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsxs)("div",{className:"p-4 bg-bg-tertiary rounded-lg border border-border-subtle",children:[(0,s.jsx)("h4",{className:"font-medium text-white mb-2",children:"Complete authentication:"}),R?(0,s.jsxs)("ol",{className:"text-sm text-text-muted space-y-2 list-decimal list-inside",children:[(0,s.jsx)("li",{children:"Click the button below to open the login page"}),(0,s.jsxs)("li",{children:["Sign in with your ",t.displayName," account"]}),(0,s.jsxs)("li",{className:"text-amber-400",children:[(0,s.jsx)("strong",{children:"Important:"})," After signing in, you'll see a \"This site can't be reached\" error - this is expected!"]}),(0,s.jsxs)("li",{children:["Copy the ",(0,s.jsx)("strong",{children:"entire URL"})," from your browser's address bar (it starts with ",(0,s.jsx)("code",{className:"px-1 py-0.5 bg-bg-card rounded text-xs",children:"http://localhost..."}),")"]}),(0,s.jsx)("li",{children:"Paste it in the input below and click Submit"})]}):H?(0,s.jsxs)("ol",{className:"text-sm text-text-muted space-y-2 list-decimal list-inside",children:[(0,s.jsx)("li",{children:"Click the button below to open the login page"}),(0,s.jsx)("li",{children:"Sign in with your Anthropic account"}),(0,s.jsxs)("li",{children:["After signing in, Anthropic will display an ",(0,s.jsx)("strong",{children:"authentication code"})]}),(0,s.jsx)("li",{children:"Copy that code and paste it in the input below"}),(0,s.jsx)("li",{children:"Click Submit to complete authentication"})]}):(0,s.jsxs)("ol",{className:"text-sm text-text-muted space-y-2 list-decimal list-inside",children:[(0,s.jsx)("li",{children:"Click the button below to open the login page"}),(0,s.jsxs)("li",{children:["Sign in with your ",t.displayName," account"]}),(0,s.jsx)("li",{children:'If you receive a code, paste it below. Otherwise click "I\'ve completed login"'})]})]}),(0,s.jsxs)("a",{href:m,target:"_blank",rel:"noopener noreferrer",className:"block w-full py-3 px-4 bg-gradient-to-r from-accent-cyan to-[#00b8d9] text-bg-deep font-semibold rounded-xl text-center hover:shadow-glow-cyan transition-all",children:["Open ",t.displayName," Login Page"]}),R?(0,s.jsxs)("div",{className:"space-y-4",children:[v&&!C&&(0,s.jsxs)("div",{className:"space-y-3",children:[(0,s.jsxs)("div",{className:"p-3 bg-accent-cyan/10 border border-accent-cyan/30 rounded-lg",children:[(0,s.jsxs)("p",{className:"text-sm text-accent-cyan mb-2",children:[(0,s.jsx)("strong",{children:"Step 1:"})," Run this command in your terminal:"]}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("code",{className:"flex-1 px-3 py-2 bg-bg-deep rounded-lg text-xs font-mono text-white overflow-x-auto",children:v}),(0,s.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(v)},className:"px-3 py-2 bg-bg-tertiary border border-border-subtle rounded-lg text-text-muted hover:text-white hover:border-accent-cyan/50 transition-colors text-xs",children:"Copy"})]}),(0,s.jsxs)("p",{className:"text-sm text-accent-cyan mt-3",children:[(0,s.jsx)("strong",{children:"Step 2:"})," Then click the button above to sign in with OpenAI"]}),(0,s.jsx)("p",{className:"text-xs text-text-muted mt-2",children:"The CLI will automatically capture the callback and complete authentication."}),A&&(0,s.jsxs)("div",{className:"flex items-center gap-2 mt-3 text-xs text-accent-cyan",children:[(0,s.jsxs)("svg",{className:"w-3 h-3 animate-spin",fill:"none",viewBox:"0 0 24 24",children:[(0,s.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,s.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),(0,s.jsx)("span",{children:"Waiting for CLI to capture callback..."})]})]}),(0,s.jsx)("button",{onClick:()=>S(!0),className:"text-xs text-text-muted hover:text-white transition-colors",children:"Having trouble? Click here for manual method"})]}),(C||!v)&&(0,s.jsxs)("div",{className:"space-y-3",children:[(0,s.jsx)("div",{className:"p-3 bg-amber-500/10 border border-amber-500/30 rounded-lg",children:(0,s.jsxs)("p",{className:"text-xs text-amber-400",children:[(0,s.jsx)("strong",{children:"Manual method:"})," After login, you'll see \"This site can't be reached\" - this is expected! Copy the full URL from your browser's address bar and paste it below."]})}),(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsx)("input",{type:"text",placeholder:"Paste the localhost URL here (e.g., http://localhost:...)",value:b,onChange:e=>f(e.target.value),className:"flex-1 px-4 py-3 bg-bg-tertiary border border-border-subtle rounded-xl text-white placeholder-text-muted focus:outline-none focus:border-accent-cyan transition-colors font-mono text-sm",onKeyDown:e=>{"Enter"===e.key&&b.trim()&&O()}}),(0,s.jsx)("button",{onClick:O,disabled:!b.trim(),className:"px-6 py-3 bg-accent-cyan text-bg-deep font-semibold rounded-xl hover:bg-accent-cyan/90 disabled:opacity-50 disabled:cursor-not-allowed transition-all",children:"Submit"})]}),v&&(0,s.jsx)("button",{onClick:()=>S(!1),className:"text-xs text-accent-cyan hover:underline",children:"← Back to CLI method"})]})]}):H?(0,s.jsxs)("div",{className:"space-y-3",children:[(0,s.jsx)("div",{className:"p-3 bg-accent-cyan/10 border border-accent-cyan/30 rounded-lg",children:(0,s.jsxs)("p",{className:"text-xs text-accent-cyan",children:[(0,s.jsx)("strong",{children:"Look for the code:"})," After signing in, Anthropic will show you an authentication code. Copy it and paste it below."]})}),(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsx)("input",{type:"text",placeholder:"Paste the authentication code here",value:b,onChange:e=>f(e.target.value),className:"flex-1 px-4 py-3 bg-bg-tertiary border border-border-subtle rounded-xl text-white placeholder-text-muted focus:outline-none focus:border-accent-cyan transition-colors font-mono text-sm",onKeyDown:e=>{"Enter"===e.key&&b.trim()&&O()}}),(0,s.jsx)("button",{onClick:O,disabled:!b.trim(),className:"px-6 py-3 bg-accent-cyan text-bg-deep font-semibold rounded-xl hover:bg-accent-cyan/90 disabled:opacity-50 disabled:cursor-not-allowed transition-all",children:"Submit"})]})]}):(0,s.jsxs)("div",{className:"space-y-3",children:[(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsx)("input",{type:"text",placeholder:"Paste authentication code (if provided)",value:b,onChange:e=>f(e.target.value),className:"flex-1 px-4 py-3 bg-bg-tertiary border border-border-subtle rounded-xl text-white placeholder-text-muted focus:outline-none focus:border-accent-cyan transition-colors font-mono text-sm",onKeyDown:e=>{"Enter"===e.key&&b.trim()&&O()}}),(0,s.jsx)("button",{onClick:O,disabled:!b.trim(),className:"px-6 py-3 bg-accent-cyan text-bg-deep font-semibold rounded-xl hover:bg-accent-cyan/90 disabled:opacity-50 disabled:cursor-not-allowed transition-all",children:"Submit"})]}),(0,s.jsx)("button",{onClick:()=>U(),className:"w-full py-2 text-text-muted hover:text-white transition-colors text-sm",children:"No code? Click here if you've completed login"})]}),(0,s.jsx)("button",{onClick:z,className:"w-full py-2 text-text-muted hover:text-white transition-colors text-sm",children:"Cancel"})]}),"submitting"===x&&(0,s.jsxs)("div",{className:"flex items-center justify-center gap-3 py-4",children:[(0,s.jsxs)("svg",{className:"w-5 h-5 text-accent-cyan animate-spin",fill:"none",viewBox:"0 0 24 24",children:[(0,s.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,s.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),(0,s.jsx)("span",{className:"text-text-muted",children:"Verifying authentication..."})]}),"success"===x&&(0,s.jsxs)("div",{className:"flex items-center justify-center gap-3 py-4",children:[(0,s.jsx)("div",{className:"w-10 h-10 bg-success/20 rounded-full flex items-center justify-center",children:(0,s.jsx)("svg",{className:"w-6 h-6 text-success",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,s.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})}),(0,s.jsxs)("span",{className:"text-white font-medium",children:[t.displayName," connected!"]})]}),"error"===x&&(0,s.jsxs)("div",{className:"space-y-3",children:[(0,s.jsx)("div",{className:"p-4 bg-error/10 border border-error/30 rounded-lg text-error text-sm",children:j||"Authentication failed. Please try again."}),(0,s.jsxs)("div",{className:"flex gap-3",children:[(0,s.jsx)("button",{onClick:T,className:"flex-1 py-2 px-4 bg-bg-tertiary border border-border-subtle text-white rounded-lg hover:border-accent-cyan/50 transition-colors",children:"Try Again"}),(0,s.jsx)("button",{onClick:z,className:"py-2 px-4 text-text-muted hover:text-white transition-colors",children:"Cancel"})]})]})]})}}}]);