@withbuddi/buddi 0.1.0-pre.37 → 0.1.0-pre.39

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 (815) hide show
  1. package/extension/background.js +764 -32
  2. package/extension/manifest.json +2 -2
  3. package/node_modules/@buddi/cli/dist/.tsbuildinfo +1 -1
  4. package/node_modules/@buddi/cli/dist/access-cmd.d.ts +10 -0
  5. package/node_modules/@buddi/cli/dist/access-cmd.d.ts.map +1 -0
  6. package/node_modules/@buddi/cli/dist/access-cmd.js +180 -0
  7. package/node_modules/@buddi/cli/dist/access-cmd.js.map +1 -0
  8. package/node_modules/@buddi/cli/dist/args.d.ts +10 -0
  9. package/node_modules/@buddi/cli/dist/args.d.ts.map +1 -1
  10. package/node_modules/@buddi/cli/dist/args.js +34 -1
  11. package/node_modules/@buddi/cli/dist/args.js.map +1 -1
  12. package/node_modules/@buddi/cli/dist/commands.d.ts.map +1 -1
  13. package/node_modules/@buddi/cli/dist/commands.js +39 -2
  14. package/node_modules/@buddi/cli/dist/commands.js.map +1 -1
  15. package/node_modules/@buddi/cli/dist/doctor-probes.d.ts.map +1 -1
  16. package/node_modules/@buddi/cli/dist/doctor-probes.js +54 -29
  17. package/node_modules/@buddi/cli/dist/doctor-probes.js.map +1 -1
  18. package/node_modules/@buddi/cli/dist/doctor.d.ts +36 -12
  19. package/node_modules/@buddi/cli/dist/doctor.d.ts.map +1 -1
  20. package/node_modules/@buddi/cli/dist/doctor.js +32 -9
  21. package/node_modules/@buddi/cli/dist/doctor.js.map +1 -1
  22. package/node_modules/@buddi/cli/dist/main.d.ts +2 -0
  23. package/node_modules/@buddi/cli/dist/main.d.ts.map +1 -1
  24. package/node_modules/@buddi/cli/dist/main.js +20 -2
  25. package/node_modules/@buddi/cli/dist/main.js.map +1 -1
  26. package/node_modules/@buddi/core/dist/.tsbuildinfo +1 -1
  27. package/node_modules/@buddi/core/dist/agents/catalog.d.ts +2 -0
  28. package/node_modules/@buddi/core/dist/agents/catalog.d.ts.map +1 -1
  29. package/node_modules/@buddi/core/dist/agents/catalog.js +1 -0
  30. package/node_modules/@buddi/core/dist/agents/catalog.js.map +1 -1
  31. package/node_modules/@buddi/core/dist/agents/edit.d.ts +2 -0
  32. package/node_modules/@buddi/core/dist/agents/edit.d.ts.map +1 -1
  33. package/node_modules/@buddi/core/dist/agents/edit.js +3 -1
  34. package/node_modules/@buddi/core/dist/agents/edit.js.map +1 -1
  35. package/node_modules/@buddi/core/dist/agents/frontmatter.d.ts +11 -0
  36. package/node_modules/@buddi/core/dist/agents/frontmatter.d.ts.map +1 -1
  37. package/node_modules/@buddi/core/dist/agents/frontmatter.js +7 -0
  38. package/node_modules/@buddi/core/dist/agents/frontmatter.js.map +1 -1
  39. package/node_modules/@buddi/core/dist/index.d.ts +1 -0
  40. package/node_modules/@buddi/core/dist/index.d.ts.map +1 -1
  41. package/node_modules/@buddi/core/dist/index.js +1 -0
  42. package/node_modules/@buddi/core/dist/index.js.map +1 -1
  43. package/node_modules/@buddi/core/dist/plugin/index.d.ts +3 -0
  44. package/node_modules/@buddi/core/dist/plugin/index.d.ts.map +1 -1
  45. package/node_modules/@buddi/core/dist/plugin/index.js +3 -0
  46. package/node_modules/@buddi/core/dist/plugin/index.js.map +1 -1
  47. package/node_modules/@buddi/core/dist/plugin/version.d.ts +1 -1
  48. package/node_modules/@buddi/core/dist/plugin/version.js +1 -1
  49. package/node_modules/@buddi/core/dist/questions/store.d.ts +12 -0
  50. package/node_modules/@buddi/core/dist/questions/store.d.ts.map +1 -1
  51. package/node_modules/@buddi/core/dist/questions/store.js +11 -1
  52. package/node_modules/@buddi/core/dist/questions/store.js.map +1 -1
  53. package/node_modules/@buddi/core/dist/questions/types.d.ts +8 -0
  54. package/node_modules/@buddi/core/dist/questions/types.d.ts.map +1 -1
  55. package/node_modules/@buddi/core/dist/questions/types.js +15 -0
  56. package/node_modules/@buddi/core/dist/questions/types.js.map +1 -1
  57. package/node_modules/@buddi/core/dist/queue/jobs.d.ts +8 -0
  58. package/node_modules/@buddi/core/dist/queue/jobs.d.ts.map +1 -1
  59. package/node_modules/@buddi/core/dist/queue/jobs.js +9 -3
  60. package/node_modules/@buddi/core/dist/queue/jobs.js.map +1 -1
  61. package/node_modules/@buddi/core/dist/queue/worker.d.ts +2 -0
  62. package/node_modules/@buddi/core/dist/queue/worker.d.ts.map +1 -1
  63. package/node_modules/@buddi/core/dist/queue/worker.js +2 -1
  64. package/node_modules/@buddi/core/dist/queue/worker.js.map +1 -1
  65. package/node_modules/@buddi/core/dist/registry.d.ts +7 -1
  66. package/node_modules/@buddi/core/dist/registry.d.ts.map +1 -1
  67. package/node_modules/@buddi/core/dist/registry.js +73 -11
  68. package/node_modules/@buddi/core/dist/registry.js.map +1 -1
  69. package/node_modules/@buddi/core/dist/routes.d.ts +153 -0
  70. package/node_modules/@buddi/core/dist/routes.d.ts.map +1 -0
  71. package/node_modules/@buddi/core/dist/routes.js +47 -0
  72. package/node_modules/@buddi/core/dist/routes.js.map +1 -0
  73. package/node_modules/@buddi/core/dist/scheduler/missions.d.ts +5 -3
  74. package/node_modules/@buddi/core/dist/scheduler/missions.d.ts.map +1 -1
  75. package/node_modules/@buddi/core/dist/scheduler/missions.js +9 -7
  76. package/node_modules/@buddi/core/dist/scheduler/missions.js.map +1 -1
  77. package/node_modules/@buddi/core/dist/scheduler/types.d.ts +7 -0
  78. package/node_modules/@buddi/core/dist/scheduler/types.d.ts.map +1 -1
  79. package/node_modules/@buddi/core/dist/scheduler/types.js +1 -0
  80. package/node_modules/@buddi/core/dist/scheduler/types.js.map +1 -1
  81. package/node_modules/@buddi/core/dist/tools.d.ts +59 -2
  82. package/node_modules/@buddi/core/dist/tools.d.ts.map +1 -1
  83. package/node_modules/@buddi/core/dist/tools.js.map +1 -1
  84. package/node_modules/@buddi/core/migrations/075_access_providers.sql +43 -0
  85. package/node_modules/@buddi/core/migrations/076_mission_browser.sql +7 -0
  86. package/node_modules/@buddi/gateway/dist/.tsbuildinfo +1 -1
  87. package/node_modules/@buddi/gateway/dist/agents/canvas.d.ts +12 -12
  88. package/node_modules/@buddi/gateway/dist/agents/catalogue-package.d.ts +38 -20
  89. package/node_modules/@buddi/gateway/dist/agents/catalogue-package.d.ts.map +1 -1
  90. package/node_modules/@buddi/gateway/dist/agents/catalogue-package.js +6 -0
  91. package/node_modules/@buddi/gateway/dist/agents/catalogue-package.js.map +1 -1
  92. package/node_modules/@buddi/gateway/dist/agents/delegation.d.ts +10 -0
  93. package/node_modules/@buddi/gateway/dist/agents/delegation.d.ts.map +1 -1
  94. package/node_modules/@buddi/gateway/dist/agents/delegation.js +1 -0
  95. package/node_modules/@buddi/gateway/dist/agents/delegation.js.map +1 -1
  96. package/node_modules/@buddi/gateway/dist/agents/platform-catalogue.d.ts +7 -1
  97. package/node_modules/@buddi/gateway/dist/agents/platform-catalogue.d.ts.map +1 -1
  98. package/node_modules/@buddi/gateway/dist/agents/platform-catalogue.js +15 -6
  99. package/node_modules/@buddi/gateway/dist/agents/platform-catalogue.js.map +1 -1
  100. package/node_modules/@buddi/gateway/dist/bootstrap.d.ts.map +1 -1
  101. package/node_modules/@buddi/gateway/dist/bootstrap.js +8 -0
  102. package/node_modules/@buddi/gateway/dist/bootstrap.js.map +1 -1
  103. package/node_modules/@buddi/gateway/dist/browser-host.d.ts +30 -1
  104. package/node_modules/@buddi/gateway/dist/browser-host.d.ts.map +1 -1
  105. package/node_modules/@buddi/gateway/dist/browser-host.js +56 -1
  106. package/node_modules/@buddi/gateway/dist/browser-host.js.map +1 -1
  107. package/node_modules/@buddi/gateway/dist/chat/session.d.ts.map +1 -1
  108. package/node_modules/@buddi/gateway/dist/chat/session.js +9 -5
  109. package/node_modules/@buddi/gateway/dist/chat/session.js.map +1 -1
  110. package/node_modules/@buddi/gateway/dist/index.d.ts +2 -1
  111. package/node_modules/@buddi/gateway/dist/index.d.ts.map +1 -1
  112. package/node_modules/@buddi/gateway/dist/index.js +2 -1
  113. package/node_modules/@buddi/gateway/dist/index.js.map +1 -1
  114. package/node_modules/@buddi/gateway/dist/missions/ask-cap.d.ts +26 -0
  115. package/node_modules/@buddi/gateway/dist/missions/ask-cap.d.ts.map +1 -0
  116. package/node_modules/@buddi/gateway/dist/missions/ask-cap.js +83 -0
  117. package/node_modules/@buddi/gateway/dist/missions/ask-cap.js.map +1 -0
  118. package/node_modules/@buddi/gateway/dist/missions/execute.d.ts +45 -1
  119. package/node_modules/@buddi/gateway/dist/missions/execute.d.ts.map +1 -1
  120. package/node_modules/@buddi/gateway/dist/missions/execute.js +156 -10
  121. package/node_modules/@buddi/gateway/dist/missions/execute.js.map +1 -1
  122. package/node_modules/@buddi/gateway/dist/missions/parked.d.ts +139 -0
  123. package/node_modules/@buddi/gateway/dist/missions/parked.d.ts.map +1 -0
  124. package/node_modules/@buddi/gateway/dist/missions/parked.js +255 -0
  125. package/node_modules/@buddi/gateway/dist/missions/parked.js.map +1 -0
  126. package/node_modules/@buddi/gateway/dist/serve.d.ts +7 -0
  127. package/node_modules/@buddi/gateway/dist/serve.d.ts.map +1 -1
  128. package/node_modules/@buddi/gateway/dist/serve.js +49 -9
  129. package/node_modules/@buddi/gateway/dist/serve.js.map +1 -1
  130. package/node_modules/@buddi/gateway/dist/surfaces/browser-cards.d.ts +18 -0
  131. package/node_modules/@buddi/gateway/dist/surfaces/browser-cards.d.ts.map +1 -0
  132. package/node_modules/@buddi/gateway/dist/surfaces/browser-cards.js +42 -0
  133. package/node_modules/@buddi/gateway/dist/surfaces/browser-cards.js.map +1 -0
  134. package/node_modules/@buddi/gateway/dist/surfaces/browser-continuation.js +1 -1
  135. package/node_modules/@buddi/gateway/dist/surfaces/browser-continuation.js.map +1 -1
  136. package/node_modules/@buddi/gateway/dist/surfaces/owner-request.d.ts +6 -0
  137. package/node_modules/@buddi/gateway/dist/surfaces/owner-request.d.ts.map +1 -1
  138. package/node_modules/@buddi/gateway/dist/surfaces/owner-request.js +7 -1
  139. package/node_modules/@buddi/gateway/dist/surfaces/owner-request.js.map +1 -1
  140. package/node_modules/@buddi/gateway/dist/system-context.d.ts +7 -0
  141. package/node_modules/@buddi/gateway/dist/system-context.d.ts.map +1 -1
  142. package/node_modules/@buddi/gateway/dist/system-context.js +14 -7
  143. package/node_modules/@buddi/gateway/dist/system-context.js.map +1 -1
  144. package/node_modules/@buddi/gateway/dist/telegram/browser-view.d.ts +17 -17
  145. package/node_modules/@buddi/gateway/dist/telegram/browser-view.d.ts.map +1 -1
  146. package/node_modules/@buddi/gateway/dist/telegram/browser-view.js +33 -37
  147. package/node_modules/@buddi/gateway/dist/telegram/browser-view.js.map +1 -1
  148. package/node_modules/@buddi/gateway/dist/telegram/channel.d.ts.map +1 -1
  149. package/node_modules/@buddi/gateway/dist/telegram/channel.js +17 -1
  150. package/node_modules/@buddi/gateway/dist/telegram/channel.js.map +1 -1
  151. package/node_modules/@buddi/gateway/dist/telegram/main.d.ts.map +1 -1
  152. package/node_modules/@buddi/gateway/dist/telegram/main.js +11 -3
  153. package/node_modules/@buddi/gateway/dist/telegram/main.js.map +1 -1
  154. package/node_modules/@buddi/gateway/dist/telegram/surface.d.ts.map +1 -1
  155. package/node_modules/@buddi/gateway/dist/telegram/surface.js +10 -0
  156. package/node_modules/@buddi/gateway/dist/telegram/surface.js.map +1 -1
  157. package/node_modules/@buddi/gateway/dist/tips/facts.d.ts +8 -0
  158. package/node_modules/@buddi/gateway/dist/tips/facts.d.ts.map +1 -1
  159. package/node_modules/@buddi/gateway/dist/tips/facts.js +8 -2
  160. package/node_modules/@buddi/gateway/dist/tips/facts.js.map +1 -1
  161. package/node_modules/@buddi/gateway/dist/tips/rules.d.ts +2 -0
  162. package/node_modules/@buddi/gateway/dist/tips/rules.d.ts.map +1 -1
  163. package/node_modules/@buddi/gateway/dist/tips/rules.js +15 -0
  164. package/node_modules/@buddi/gateway/dist/tips/rules.js.map +1 -1
  165. package/node_modules/@buddi/gateway/dist/web/access/arrival.d.ts +24 -0
  166. package/node_modules/@buddi/gateway/dist/web/access/arrival.d.ts.map +1 -0
  167. package/node_modules/@buddi/gateway/dist/web/access/arrival.js +18 -0
  168. package/node_modules/@buddi/gateway/dist/web/access/arrival.js.map +1 -0
  169. package/node_modules/@buddi/gateway/dist/web/access/cloudflare-api.d.ts +124 -0
  170. package/node_modules/@buddi/gateway/dist/web/access/cloudflare-api.d.ts.map +1 -0
  171. package/node_modules/@buddi/gateway/dist/web/access/cloudflare-api.js +206 -0
  172. package/node_modules/@buddi/gateway/dist/web/access/cloudflare-api.js.map +1 -0
  173. package/node_modules/@buddi/gateway/dist/web/access/cloudflare-setup.d.ts +163 -0
  174. package/node_modules/@buddi/gateway/dist/web/access/cloudflare-setup.d.ts.map +1 -0
  175. package/node_modules/@buddi/gateway/dist/web/access/cloudflare-setup.js +438 -0
  176. package/node_modules/@buddi/gateway/dist/web/access/cloudflare-setup.js.map +1 -0
  177. package/node_modules/@buddi/gateway/dist/web/access/cloudflare-token.d.ts +31 -0
  178. package/node_modules/@buddi/gateway/dist/web/access/cloudflare-token.d.ts.map +1 -0
  179. package/node_modules/@buddi/gateway/dist/web/access/cloudflare-token.js +74 -0
  180. package/node_modules/@buddi/gateway/dist/web/access/cloudflare-token.js.map +1 -0
  181. package/node_modules/@buddi/gateway/dist/web/access/cloudflare.d.ts +145 -0
  182. package/node_modules/@buddi/gateway/dist/web/access/cloudflare.d.ts.map +1 -0
  183. package/node_modules/@buddi/gateway/dist/web/access/cloudflare.js +474 -0
  184. package/node_modules/@buddi/gateway/dist/web/access/cloudflare.js.map +1 -0
  185. package/node_modules/@buddi/gateway/dist/web/access/index.d.ts +9 -0
  186. package/node_modules/@buddi/gateway/dist/web/access/index.d.ts.map +1 -0
  187. package/node_modules/@buddi/gateway/dist/web/access/index.js +9 -0
  188. package/node_modules/@buddi/gateway/dist/web/access/index.js.map +1 -0
  189. package/node_modules/@buddi/gateway/dist/web/access/ingress.d.ts +30 -0
  190. package/node_modules/@buddi/gateway/dist/web/access/ingress.d.ts.map +1 -0
  191. package/node_modules/@buddi/gateway/dist/web/access/ingress.js +76 -0
  192. package/node_modules/@buddi/gateway/dist/web/access/ingress.js.map +1 -0
  193. package/node_modules/@buddi/gateway/dist/web/access/provider.d.ts +173 -0
  194. package/node_modules/@buddi/gateway/dist/web/access/provider.d.ts.map +1 -0
  195. package/node_modules/@buddi/gateway/dist/web/access/provider.js +11 -0
  196. package/node_modules/@buddi/gateway/dist/web/access/provider.js.map +1 -0
  197. package/node_modules/@buddi/gateway/dist/web/access/registry.d.ts +33 -0
  198. package/node_modules/@buddi/gateway/dist/web/access/registry.d.ts.map +1 -0
  199. package/node_modules/@buddi/gateway/dist/web/access/registry.js +32 -0
  200. package/node_modules/@buddi/gateway/dist/web/access/registry.js.map +1 -0
  201. package/node_modules/@buddi/gateway/dist/web/{tailscale.d.ts → access/tailscale.d.ts} +27 -0
  202. package/node_modules/@buddi/gateway/dist/web/access/tailscale.d.ts.map +1 -0
  203. package/node_modules/@buddi/gateway/dist/web/{tailscale.js → access/tailscale.js} +118 -3
  204. package/node_modules/@buddi/gateway/dist/web/access/tailscale.js.map +1 -0
  205. package/node_modules/@buddi/gateway/dist/web/agents.d.ts +2 -0
  206. package/node_modules/@buddi/gateway/dist/web/agents.d.ts.map +1 -1
  207. package/node_modules/@buddi/gateway/dist/web/agents.js +19 -1
  208. package/node_modules/@buddi/gateway/dist/web/agents.js.map +1 -1
  209. package/node_modules/@buddi/gateway/dist/web/api-routes.d.ts +4 -3
  210. package/node_modules/@buddi/gateway/dist/web/api-routes.d.ts.map +1 -1
  211. package/node_modules/@buddi/gateway/dist/web/api-routes.js +106 -19
  212. package/node_modules/@buddi/gateway/dist/web/api-routes.js.map +1 -1
  213. package/node_modules/@buddi/gateway/dist/web/attention.d.ts.map +1 -1
  214. package/node_modules/@buddi/gateway/dist/web/attention.js +11 -3
  215. package/node_modules/@buddi/gateway/dist/web/attention.js.map +1 -1
  216. package/node_modules/@buddi/gateway/dist/web/chat.d.ts +23 -0
  217. package/node_modules/@buddi/gateway/dist/web/chat.d.ts.map +1 -1
  218. package/node_modules/@buddi/gateway/dist/web/chat.js +62 -2
  219. package/node_modules/@buddi/gateway/dist/web/chat.js.map +1 -1
  220. package/node_modules/@buddi/gateway/dist/web/client-key.d.ts +3 -0
  221. package/node_modules/@buddi/gateway/dist/web/client-key.d.ts.map +1 -1
  222. package/node_modules/@buddi/gateway/dist/web/client-key.js +8 -1
  223. package/node_modules/@buddi/gateway/dist/web/client-key.js.map +1 -1
  224. package/node_modules/@buddi/gateway/dist/web/extension.d.ts +21 -1
  225. package/node_modules/@buddi/gateway/dist/web/extension.d.ts.map +1 -1
  226. package/node_modules/@buddi/gateway/dist/web/extension.js +183 -3
  227. package/node_modules/@buddi/gateway/dist/web/extension.js.map +1 -1
  228. package/node_modules/@buddi/gateway/dist/web/http.d.ts +7 -0
  229. package/node_modules/@buddi/gateway/dist/web/http.d.ts.map +1 -1
  230. package/node_modules/@buddi/gateway/dist/web/http.js +15 -1
  231. package/node_modules/@buddi/gateway/dist/web/http.js.map +1 -1
  232. package/node_modules/@buddi/gateway/dist/web/index.d.ts +1 -1
  233. package/node_modules/@buddi/gateway/dist/web/index.d.ts.map +1 -1
  234. package/node_modules/@buddi/gateway/dist/web/index.js +1 -1
  235. package/node_modules/@buddi/gateway/dist/web/index.js.map +1 -1
  236. package/node_modules/@buddi/gateway/dist/web/onboarding.js +1 -1
  237. package/node_modules/@buddi/gateway/dist/web/onboarding.js.map +1 -1
  238. package/node_modules/@buddi/gateway/dist/web/remote-hand.d.ts.map +1 -1
  239. package/node_modules/@buddi/gateway/dist/web/remote-hand.js +45 -2
  240. package/node_modules/@buddi/gateway/dist/web/remote-hand.js.map +1 -1
  241. package/node_modules/@buddi/gateway/dist/web/secrets.d.ts +26 -1
  242. package/node_modules/@buddi/gateway/dist/web/secrets.d.ts.map +1 -1
  243. package/node_modules/@buddi/gateway/dist/web/secrets.js +66 -3
  244. package/node_modules/@buddi/gateway/dist/web/secrets.js.map +1 -1
  245. package/node_modules/@buddi/gateway/dist/web/server.d.ts +38 -2
  246. package/node_modules/@buddi/gateway/dist/web/server.d.ts.map +1 -1
  247. package/node_modules/@buddi/gateway/dist/web/server.js +634 -147
  248. package/node_modules/@buddi/gateway/dist/web/server.js.map +1 -1
  249. package/node_modules/@buddi/gateway/dist/web/sessions.d.ts +24 -14
  250. package/node_modules/@buddi/gateway/dist/web/sessions.d.ts.map +1 -1
  251. package/node_modules/@buddi/gateway/dist/web/sessions.js +42 -14
  252. package/node_modules/@buddi/gateway/dist/web/sessions.js.map +1 -1
  253. package/node_modules/@buddi/gateway/dist/web/signed-out.d.ts +10 -0
  254. package/node_modules/@buddi/gateway/dist/web/signed-out.d.ts.map +1 -1
  255. package/node_modules/@buddi/gateway/dist/web/signed-out.js +47 -0
  256. package/node_modules/@buddi/gateway/dist/web/signed-out.js.map +1 -1
  257. package/node_modules/@buddi/gateway/dist/web/version.d.ts +2 -0
  258. package/node_modules/@buddi/gateway/dist/web/version.d.ts.map +1 -1
  259. package/node_modules/@buddi/gateway/dist/web/version.js +5 -1
  260. package/node_modules/@buddi/gateway/dist/web/version.js.map +1 -1
  261. package/node_modules/@buddi/install/dist/.tsbuildinfo +1 -1
  262. package/node_modules/@buddi/install/dist/app-layout.d.ts +127 -0
  263. package/node_modules/@buddi/install/dist/app-layout.d.ts.map +1 -0
  264. package/node_modules/@buddi/install/dist/app-layout.js +323 -0
  265. package/node_modules/@buddi/install/dist/app-layout.js.map +1 -0
  266. package/node_modules/@buddi/install/dist/index.d.ts +1 -0
  267. package/node_modules/@buddi/install/dist/index.d.ts.map +1 -1
  268. package/node_modules/@buddi/install/dist/index.js +1 -0
  269. package/node_modules/@buddi/install/dist/index.js.map +1 -1
  270. package/node_modules/@buddi/install/dist/launcher.d.ts.map +1 -1
  271. package/node_modules/@buddi/install/dist/launcher.js +18 -4
  272. package/node_modules/@buddi/install/dist/launcher.js.map +1 -1
  273. package/node_modules/@buddi/install/dist/provenance.d.ts +34 -0
  274. package/node_modules/@buddi/install/dist/provenance.d.ts.map +1 -0
  275. package/node_modules/@buddi/install/dist/provenance.js +200 -0
  276. package/node_modules/@buddi/install/dist/provenance.js.map +1 -0
  277. package/node_modules/@buddi/install/dist/supervisor.d.ts.map +1 -1
  278. package/node_modules/@buddi/install/dist/supervisor.js +9 -4
  279. package/node_modules/@buddi/install/dist/supervisor.js.map +1 -1
  280. package/node_modules/@buddi/install/dist/upgrade.d.ts +77 -3
  281. package/node_modules/@buddi/install/dist/upgrade.d.ts.map +1 -1
  282. package/node_modules/@buddi/install/dist/upgrade.js +325 -43
  283. package/node_modules/@buddi/install/dist/upgrade.js.map +1 -1
  284. package/node_modules/@buddi/runtime/dist/.tsbuildinfo +1 -1
  285. package/node_modules/@buddi/runtime/dist/delegate.d.ts +8 -0
  286. package/node_modules/@buddi/runtime/dist/delegate.d.ts.map +1 -1
  287. package/node_modules/@buddi/runtime/dist/delegate.js +19 -1
  288. package/node_modules/@buddi/runtime/dist/delegate.js.map +1 -1
  289. package/node_modules/@buddi/runtime/dist/loop.d.ts +2 -0
  290. package/node_modules/@buddi/runtime/dist/loop.d.ts.map +1 -1
  291. package/node_modules/@buddi/runtime/dist/loop.js +18 -4
  292. package/node_modules/@buddi/runtime/dist/loop.js.map +1 -1
  293. package/node_modules/@buddi/tool-artifacts/dist/.tsbuildinfo +1 -1
  294. package/node_modules/@buddi/tool-browser/dist/.tsbuildinfo +1 -1
  295. package/node_modules/@buddi/tool-browser/dist/availability.d.ts +2 -2
  296. package/node_modules/@buddi/tool-browser/dist/availability.d.ts.map +1 -1
  297. package/node_modules/@buddi/tool-browser/dist/availability.js +2 -2
  298. package/node_modules/@buddi/tool-browser/dist/availability.js.map +1 -1
  299. package/node_modules/@buddi/tool-browser/dist/controller.d.ts +82 -58
  300. package/node_modules/@buddi/tool-browser/dist/controller.d.ts.map +1 -1
  301. package/node_modules/@buddi/tool-browser/dist/controller.js +823 -217
  302. package/node_modules/@buddi/tool-browser/dist/controller.js.map +1 -1
  303. package/node_modules/@buddi/tool-browser/dist/driver.d.ts +3 -1
  304. package/node_modules/@buddi/tool-browser/dist/driver.d.ts.map +1 -1
  305. package/node_modules/@buddi/tool-browser/dist/driver.js +82 -1
  306. package/node_modules/@buddi/tool-browser/dist/driver.js.map +1 -1
  307. package/node_modules/@buddi/tool-browser/dist/extension.d.ts +70 -5
  308. package/node_modules/@buddi/tool-browser/dist/extension.d.ts.map +1 -1
  309. package/node_modules/@buddi/tool-browser/dist/extension.js +94 -9
  310. package/node_modules/@buddi/tool-browser/dist/extension.js.map +1 -1
  311. package/node_modules/@buddi/tool-browser/dist/index.d.ts +17 -7
  312. package/node_modules/@buddi/tool-browser/dist/index.d.ts.map +1 -1
  313. package/node_modules/@buddi/tool-browser/dist/index.js +35 -15
  314. package/node_modules/@buddi/tool-browser/dist/index.js.map +1 -1
  315. package/node_modules/@buddi/tool-browser/dist/logins.d.ts +150 -0
  316. package/node_modules/@buddi/tool-browser/dist/logins.d.ts.map +1 -0
  317. package/node_modules/@buddi/tool-browser/dist/logins.js +476 -0
  318. package/node_modules/@buddi/tool-browser/dist/logins.js.map +1 -0
  319. package/node_modules/@buddi/tool-browser/dist/manager.d.ts +39 -21
  320. package/node_modules/@buddi/tool-browser/dist/manager.d.ts.map +1 -1
  321. package/node_modules/@buddi/tool-browser/dist/manager.js +229 -136
  322. package/node_modules/@buddi/tool-browser/dist/manager.js.map +1 -1
  323. package/node_modules/@buddi/tool-browser/dist/routes.d.ts +151 -0
  324. package/node_modules/@buddi/tool-browser/dist/routes.d.ts.map +1 -0
  325. package/node_modules/@buddi/tool-browser/dist/routes.js +331 -0
  326. package/node_modules/@buddi/tool-browser/dist/routes.js.map +1 -0
  327. package/node_modules/@buddi/tool-browser/dist/secrets.d.ts +3 -1
  328. package/node_modules/@buddi/tool-browser/dist/secrets.d.ts.map +1 -1
  329. package/node_modules/@buddi/tool-browser/dist/secrets.js +10 -6
  330. package/node_modules/@buddi/tool-browser/dist/secrets.js.map +1 -1
  331. package/node_modules/@buddi/tool-browser/dist/service.d.ts +182 -115
  332. package/node_modules/@buddi/tool-browser/dist/service.d.ts.map +1 -1
  333. package/node_modules/@buddi/tool-browser/dist/service.js +491 -388
  334. package/node_modules/@buddi/tool-browser/dist/service.js.map +1 -1
  335. package/node_modules/@buddi/tool-browser/dist/settings.d.ts +88 -0
  336. package/node_modules/@buddi/tool-browser/dist/settings.d.ts.map +1 -0
  337. package/node_modules/@buddi/tool-browser/dist/settings.js +86 -0
  338. package/node_modules/@buddi/tool-browser/dist/settings.js.map +1 -0
  339. package/node_modules/@buddi/tool-browser/dist/telemetry.d.ts +203 -0
  340. package/node_modules/@buddi/tool-browser/dist/telemetry.d.ts.map +1 -0
  341. package/node_modules/@buddi/tool-browser/dist/telemetry.js +142 -0
  342. package/node_modules/@buddi/tool-browser/dist/telemetry.js.map +1 -0
  343. package/node_modules/@buddi/tool-browser/dist/types.d.ts +102 -3
  344. package/node_modules/@buddi/tool-browser/dist/types.d.ts.map +1 -1
  345. package/node_modules/@buddi/tool-browser/dist/types.js +27 -9
  346. package/node_modules/@buddi/tool-browser/dist/types.js.map +1 -1
  347. package/node_modules/@buddi/tool-email/dist/.tsbuildinfo +1 -1
  348. package/node_modules/@buddi/tool-host/dist/.tsbuildinfo +1 -1
  349. package/node_modules/@buddi/tool-mcp/dist/.tsbuildinfo +1 -1
  350. package/node_modules/@buddi/tool-memory/dist/.tsbuildinfo +1 -1
  351. package/node_modules/@buddi/tool-web/dist/.tsbuildinfo +1 -1
  352. package/node_modules/hono/dist/cjs/hono-base.js +2 -0
  353. package/node_modules/hono/dist/cjs/middleware/language/language.js +1 -1
  354. package/node_modules/hono/dist/cjs/middleware/mount/index.js +71 -0
  355. package/node_modules/hono/dist/cjs/request.js +4 -4
  356. package/node_modules/hono/dist/hono-base.js +2 -0
  357. package/node_modules/hono/dist/middleware/mount/index.js +70 -0
  358. package/node_modules/hono/dist/request.js +4 -4
  359. package/node_modules/hono/dist/types/hono-base.d.ts +2 -0
  360. package/node_modules/hono/dist/types/jsx/base.d.ts +1 -1
  361. package/node_modules/hono/dist/types/middleware/mount/index.d.ts +46 -0
  362. package/node_modules/hono/dist/types/request.d.ts +4 -4
  363. package/node_modules/hono/package.json +9 -1
  364. package/node_modules/imapflow/CHANGELOG.md +15 -0
  365. package/node_modules/imapflow/dist/cjs/package-info.d.ts +1 -1
  366. package/node_modules/imapflow/dist/cjs/package-info.js +1 -1
  367. package/node_modules/imapflow/dist/cjs/search-compiler.js +21 -31
  368. package/node_modules/imapflow/dist/esm/package-info.d.ts +1 -1
  369. package/node_modules/imapflow/dist/esm/package-info.js +1 -1
  370. package/node_modules/imapflow/dist/esm/search-compiler.js +21 -31
  371. package/node_modules/imapflow/package.json +2 -2
  372. package/node_modules/pino/CONTRIBUTING.md +1 -5
  373. package/node_modules/pino/LICENSE +1 -1
  374. package/node_modules/pino/README.md +1 -1
  375. package/node_modules/pino/SECURITY.md +2 -18
  376. package/node_modules/pino/browser.js +8 -68
  377. package/node_modules/pino/docs/api.md +4 -75
  378. package/node_modules/pino/docs/asynchronous.md +3 -18
  379. package/node_modules/pino/docs/browser.md +0 -63
  380. package/node_modules/pino/docs/child-loggers.md +1 -22
  381. package/node_modules/pino/docs/ecosystem.md +0 -1
  382. package/node_modules/pino/docs/help.md +3 -11
  383. package/node_modules/pino/docs/lts.md +0 -29
  384. package/node_modules/pino/docs/pretty.md +0 -3
  385. package/node_modules/pino/docs/redaction.md +8 -3
  386. package/node_modules/pino/docs/transports.md +0 -71
  387. package/node_modules/pino/docs/web.md +14 -11
  388. package/node_modules/pino/eslint.config.js +7 -15
  389. package/node_modules/pino/lib/caller.js +0 -10
  390. package/node_modules/pino/lib/meta.js +1 -1
  391. package/node_modules/pino/lib/multistream.js +7 -15
  392. package/node_modules/pino/lib/redaction.js +3 -8
  393. package/node_modules/pino/lib/symbols.js +1 -3
  394. package/node_modules/pino/lib/tools.js +2 -2
  395. package/node_modules/pino/lib/transport.js +1 -14
  396. package/node_modules/pino/lib/worker.js +1 -4
  397. package/node_modules/pino/package.json +22 -14
  398. package/node_modules/pino/pino.d.ts +736 -709
  399. package/node_modules/pino/pino.js +2 -27
  400. package/node_modules/pino/test/basic.test.js +0 -66
  401. package/node_modules/pino/test/escaping.test.js +0 -17
  402. package/node_modules/pino/test/fixtures/ts/transpile.cjs +3 -3
  403. package/node_modules/pino/test/helper.js +2 -6
  404. package/node_modules/pino/test/multistream.test.js +0 -64
  405. package/node_modules/pino/test/redact.test.js +0 -30
  406. package/node_modules/pino/test/transport/core.test.js +0 -85
  407. package/node_modules/pino/test/transport/sync-false.test.js +0 -12
  408. package/node_modules/pino/test/transport/uses-pino-config.test.js +4 -4
  409. package/node_modules/pino/test/types/pino-import.test-d.cts +30 -0
  410. package/node_modules/pino/test/types/pino-multistream.test-d.ts +28 -0
  411. package/node_modules/pino/test/types/pino-top-export.test-d.ts +34 -0
  412. package/node_modules/pino/test/types/{pino-transport.tst.ts → pino-transport.test-d.ts} +70 -85
  413. package/node_modules/pino/test/types/pino-type-only.test-d.ts +75 -0
  414. package/node_modules/pino/test/types/{pino.tst.ts → pino.test-d.ts} +137 -135
  415. package/node_modules/pino/test/types/pino.ts +7 -14
  416. package/node_modules/pino/tsconfig.json +6 -6
  417. package/node_modules/real-require/README.md +6 -6
  418. package/node_modules/real-require/package.json +21 -10
  419. package/node_modules/real-require/src/index.js +2 -2
  420. package/node_modules/thread-stream/node_modules/real-require/LICENSE.md +21 -0
  421. package/node_modules/thread-stream/node_modules/real-require/README.md +51 -0
  422. package/node_modules/thread-stream/node_modules/real-require/package.json +38 -0
  423. package/node_modules/thread-stream/node_modules/real-require/src/index.js +14 -0
  424. package/package.json +2 -2
  425. package/packages/cli/dist/.tsbuildinfo +1 -1
  426. package/packages/cli/dist/access-cmd.d.ts +10 -0
  427. package/packages/cli/dist/access-cmd.d.ts.map +1 -0
  428. package/packages/cli/dist/access-cmd.js +180 -0
  429. package/packages/cli/dist/access-cmd.js.map +1 -0
  430. package/packages/cli/dist/args.d.ts +10 -0
  431. package/packages/cli/dist/args.d.ts.map +1 -1
  432. package/packages/cli/dist/args.js +34 -1
  433. package/packages/cli/dist/args.js.map +1 -1
  434. package/packages/cli/dist/commands.d.ts.map +1 -1
  435. package/packages/cli/dist/commands.js +39 -2
  436. package/packages/cli/dist/commands.js.map +1 -1
  437. package/packages/cli/dist/doctor-probes.d.ts.map +1 -1
  438. package/packages/cli/dist/doctor-probes.js +54 -29
  439. package/packages/cli/dist/doctor-probes.js.map +1 -1
  440. package/packages/cli/dist/doctor.d.ts +36 -12
  441. package/packages/cli/dist/doctor.d.ts.map +1 -1
  442. package/packages/cli/dist/doctor.js +32 -9
  443. package/packages/cli/dist/doctor.js.map +1 -1
  444. package/packages/cli/dist/main.d.ts +2 -0
  445. package/packages/cli/dist/main.d.ts.map +1 -1
  446. package/packages/cli/dist/main.js +20 -2
  447. package/packages/cli/dist/main.js.map +1 -1
  448. package/packages/core/dist/.tsbuildinfo +1 -1
  449. package/packages/core/dist/agents/catalog.d.ts +2 -0
  450. package/packages/core/dist/agents/catalog.d.ts.map +1 -1
  451. package/packages/core/dist/agents/catalog.js +1 -0
  452. package/packages/core/dist/agents/catalog.js.map +1 -1
  453. package/packages/core/dist/agents/edit.d.ts +2 -0
  454. package/packages/core/dist/agents/edit.d.ts.map +1 -1
  455. package/packages/core/dist/agents/edit.js +3 -1
  456. package/packages/core/dist/agents/edit.js.map +1 -1
  457. package/packages/core/dist/agents/frontmatter.d.ts +11 -0
  458. package/packages/core/dist/agents/frontmatter.d.ts.map +1 -1
  459. package/packages/core/dist/agents/frontmatter.js +7 -0
  460. package/packages/core/dist/agents/frontmatter.js.map +1 -1
  461. package/packages/core/dist/index.d.ts +1 -0
  462. package/packages/core/dist/index.d.ts.map +1 -1
  463. package/packages/core/dist/index.js +1 -0
  464. package/packages/core/dist/index.js.map +1 -1
  465. package/packages/core/dist/plugin/index.d.ts +3 -0
  466. package/packages/core/dist/plugin/index.d.ts.map +1 -1
  467. package/packages/core/dist/plugin/index.js +3 -0
  468. package/packages/core/dist/plugin/index.js.map +1 -1
  469. package/packages/core/dist/plugin/version.d.ts +1 -1
  470. package/packages/core/dist/plugin/version.js +1 -1
  471. package/packages/core/dist/questions/store.d.ts +12 -0
  472. package/packages/core/dist/questions/store.d.ts.map +1 -1
  473. package/packages/core/dist/questions/store.js +11 -1
  474. package/packages/core/dist/questions/store.js.map +1 -1
  475. package/packages/core/dist/questions/types.d.ts +8 -0
  476. package/packages/core/dist/questions/types.d.ts.map +1 -1
  477. package/packages/core/dist/questions/types.js +15 -0
  478. package/packages/core/dist/questions/types.js.map +1 -1
  479. package/packages/core/dist/queue/jobs.d.ts +8 -0
  480. package/packages/core/dist/queue/jobs.d.ts.map +1 -1
  481. package/packages/core/dist/queue/jobs.js +9 -3
  482. package/packages/core/dist/queue/jobs.js.map +1 -1
  483. package/packages/core/dist/queue/worker.d.ts +2 -0
  484. package/packages/core/dist/queue/worker.d.ts.map +1 -1
  485. package/packages/core/dist/queue/worker.js +2 -1
  486. package/packages/core/dist/queue/worker.js.map +1 -1
  487. package/packages/core/dist/registry.d.ts +7 -1
  488. package/packages/core/dist/registry.d.ts.map +1 -1
  489. package/packages/core/dist/registry.js +73 -11
  490. package/packages/core/dist/registry.js.map +1 -1
  491. package/packages/core/dist/routes.d.ts +153 -0
  492. package/packages/core/dist/routes.d.ts.map +1 -0
  493. package/packages/core/dist/routes.js +47 -0
  494. package/packages/core/dist/routes.js.map +1 -0
  495. package/packages/core/dist/scheduler/missions.d.ts +5 -3
  496. package/packages/core/dist/scheduler/missions.d.ts.map +1 -1
  497. package/packages/core/dist/scheduler/missions.js +9 -7
  498. package/packages/core/dist/scheduler/missions.js.map +1 -1
  499. package/packages/core/dist/scheduler/types.d.ts +7 -0
  500. package/packages/core/dist/scheduler/types.d.ts.map +1 -1
  501. package/packages/core/dist/scheduler/types.js +1 -0
  502. package/packages/core/dist/scheduler/types.js.map +1 -1
  503. package/packages/core/dist/tools.d.ts +59 -2
  504. package/packages/core/dist/tools.d.ts.map +1 -1
  505. package/packages/core/dist/tools.js.map +1 -1
  506. package/packages/core/migrations/075_access_providers.sql +43 -0
  507. package/packages/core/migrations/076_mission_browser.sql +7 -0
  508. package/packages/gateway/dist/.tsbuildinfo +1 -1
  509. package/packages/gateway/dist/agents/canvas.d.ts +12 -12
  510. package/packages/gateway/dist/agents/catalogue-package.d.ts +38 -20
  511. package/packages/gateway/dist/agents/catalogue-package.d.ts.map +1 -1
  512. package/packages/gateway/dist/agents/catalogue-package.js +6 -0
  513. package/packages/gateway/dist/agents/catalogue-package.js.map +1 -1
  514. package/packages/gateway/dist/agents/delegation.d.ts +10 -0
  515. package/packages/gateway/dist/agents/delegation.d.ts.map +1 -1
  516. package/packages/gateway/dist/agents/delegation.js +1 -0
  517. package/packages/gateway/dist/agents/delegation.js.map +1 -1
  518. package/packages/gateway/dist/agents/platform-catalogue.d.ts +7 -1
  519. package/packages/gateway/dist/agents/platform-catalogue.d.ts.map +1 -1
  520. package/packages/gateway/dist/agents/platform-catalogue.js +15 -6
  521. package/packages/gateway/dist/agents/platform-catalogue.js.map +1 -1
  522. package/packages/gateway/dist/bootstrap.d.ts.map +1 -1
  523. package/packages/gateway/dist/bootstrap.js +8 -0
  524. package/packages/gateway/dist/bootstrap.js.map +1 -1
  525. package/packages/gateway/dist/browser-host.d.ts +30 -1
  526. package/packages/gateway/dist/browser-host.d.ts.map +1 -1
  527. package/packages/gateway/dist/browser-host.js +56 -1
  528. package/packages/gateway/dist/browser-host.js.map +1 -1
  529. package/packages/gateway/dist/chat/session.d.ts.map +1 -1
  530. package/packages/gateway/dist/chat/session.js +9 -5
  531. package/packages/gateway/dist/chat/session.js.map +1 -1
  532. package/packages/gateway/dist/index.d.ts +2 -1
  533. package/packages/gateway/dist/index.d.ts.map +1 -1
  534. package/packages/gateway/dist/index.js +2 -1
  535. package/packages/gateway/dist/index.js.map +1 -1
  536. package/packages/gateway/dist/missions/ask-cap.d.ts +26 -0
  537. package/packages/gateway/dist/missions/ask-cap.d.ts.map +1 -0
  538. package/packages/gateway/dist/missions/ask-cap.js +83 -0
  539. package/packages/gateway/dist/missions/ask-cap.js.map +1 -0
  540. package/packages/gateway/dist/missions/execute.d.ts +45 -1
  541. package/packages/gateway/dist/missions/execute.d.ts.map +1 -1
  542. package/packages/gateway/dist/missions/execute.js +156 -10
  543. package/packages/gateway/dist/missions/execute.js.map +1 -1
  544. package/packages/gateway/dist/missions/parked.d.ts +139 -0
  545. package/packages/gateway/dist/missions/parked.d.ts.map +1 -0
  546. package/packages/gateway/dist/missions/parked.js +255 -0
  547. package/packages/gateway/dist/missions/parked.js.map +1 -0
  548. package/packages/gateway/dist/serve.d.ts +7 -0
  549. package/packages/gateway/dist/serve.d.ts.map +1 -1
  550. package/packages/gateway/dist/serve.js +49 -9
  551. package/packages/gateway/dist/serve.js.map +1 -1
  552. package/packages/gateway/dist/surfaces/browser-cards.d.ts +18 -0
  553. package/packages/gateway/dist/surfaces/browser-cards.d.ts.map +1 -0
  554. package/packages/gateway/dist/surfaces/browser-cards.js +42 -0
  555. package/packages/gateway/dist/surfaces/browser-cards.js.map +1 -0
  556. package/packages/gateway/dist/surfaces/browser-continuation.js +1 -1
  557. package/packages/gateway/dist/surfaces/browser-continuation.js.map +1 -1
  558. package/packages/gateway/dist/surfaces/owner-request.d.ts +6 -0
  559. package/packages/gateway/dist/surfaces/owner-request.d.ts.map +1 -1
  560. package/packages/gateway/dist/surfaces/owner-request.js +7 -1
  561. package/packages/gateway/dist/surfaces/owner-request.js.map +1 -1
  562. package/packages/gateway/dist/system-context.d.ts +7 -0
  563. package/packages/gateway/dist/system-context.d.ts.map +1 -1
  564. package/packages/gateway/dist/system-context.js +14 -7
  565. package/packages/gateway/dist/system-context.js.map +1 -1
  566. package/packages/gateway/dist/telegram/browser-view.d.ts +17 -17
  567. package/packages/gateway/dist/telegram/browser-view.d.ts.map +1 -1
  568. package/packages/gateway/dist/telegram/browser-view.js +33 -37
  569. package/packages/gateway/dist/telegram/browser-view.js.map +1 -1
  570. package/packages/gateway/dist/telegram/channel.d.ts.map +1 -1
  571. package/packages/gateway/dist/telegram/channel.js +17 -1
  572. package/packages/gateway/dist/telegram/channel.js.map +1 -1
  573. package/packages/gateway/dist/telegram/main.d.ts.map +1 -1
  574. package/packages/gateway/dist/telegram/main.js +11 -3
  575. package/packages/gateway/dist/telegram/main.js.map +1 -1
  576. package/packages/gateway/dist/telegram/surface.d.ts.map +1 -1
  577. package/packages/gateway/dist/telegram/surface.js +10 -0
  578. package/packages/gateway/dist/telegram/surface.js.map +1 -1
  579. package/packages/gateway/dist/tips/facts.d.ts +8 -0
  580. package/packages/gateway/dist/tips/facts.d.ts.map +1 -1
  581. package/packages/gateway/dist/tips/facts.js +8 -2
  582. package/packages/gateway/dist/tips/facts.js.map +1 -1
  583. package/packages/gateway/dist/tips/rules.d.ts +2 -0
  584. package/packages/gateway/dist/tips/rules.d.ts.map +1 -1
  585. package/packages/gateway/dist/tips/rules.js +15 -0
  586. package/packages/gateway/dist/tips/rules.js.map +1 -1
  587. package/packages/gateway/dist/web/access/arrival.d.ts +24 -0
  588. package/packages/gateway/dist/web/access/arrival.d.ts.map +1 -0
  589. package/packages/gateway/dist/web/access/arrival.js +18 -0
  590. package/packages/gateway/dist/web/access/arrival.js.map +1 -0
  591. package/packages/gateway/dist/web/access/cloudflare-api.d.ts +124 -0
  592. package/packages/gateway/dist/web/access/cloudflare-api.d.ts.map +1 -0
  593. package/packages/gateway/dist/web/access/cloudflare-api.js +206 -0
  594. package/packages/gateway/dist/web/access/cloudflare-api.js.map +1 -0
  595. package/packages/gateway/dist/web/access/cloudflare-setup.d.ts +163 -0
  596. package/packages/gateway/dist/web/access/cloudflare-setup.d.ts.map +1 -0
  597. package/packages/gateway/dist/web/access/cloudflare-setup.js +438 -0
  598. package/packages/gateway/dist/web/access/cloudflare-setup.js.map +1 -0
  599. package/packages/gateway/dist/web/access/cloudflare-token.d.ts +31 -0
  600. package/packages/gateway/dist/web/access/cloudflare-token.d.ts.map +1 -0
  601. package/packages/gateway/dist/web/access/cloudflare-token.js +74 -0
  602. package/packages/gateway/dist/web/access/cloudflare-token.js.map +1 -0
  603. package/packages/gateway/dist/web/access/cloudflare.d.ts +145 -0
  604. package/packages/gateway/dist/web/access/cloudflare.d.ts.map +1 -0
  605. package/packages/gateway/dist/web/access/cloudflare.js +474 -0
  606. package/packages/gateway/dist/web/access/cloudflare.js.map +1 -0
  607. package/packages/gateway/dist/web/access/index.d.ts +9 -0
  608. package/packages/gateway/dist/web/access/index.d.ts.map +1 -0
  609. package/packages/gateway/dist/web/access/index.js +9 -0
  610. package/packages/gateway/dist/web/access/index.js.map +1 -0
  611. package/packages/gateway/dist/web/access/ingress.d.ts +30 -0
  612. package/packages/gateway/dist/web/access/ingress.d.ts.map +1 -0
  613. package/packages/gateway/dist/web/access/ingress.js +76 -0
  614. package/packages/gateway/dist/web/access/ingress.js.map +1 -0
  615. package/packages/gateway/dist/web/access/provider.d.ts +173 -0
  616. package/packages/gateway/dist/web/access/provider.d.ts.map +1 -0
  617. package/packages/gateway/dist/web/access/provider.js +11 -0
  618. package/packages/gateway/dist/web/access/provider.js.map +1 -0
  619. package/packages/gateway/dist/web/access/registry.d.ts +33 -0
  620. package/packages/gateway/dist/web/access/registry.d.ts.map +1 -0
  621. package/packages/gateway/dist/web/access/registry.js +32 -0
  622. package/packages/gateway/dist/web/access/registry.js.map +1 -0
  623. package/packages/gateway/dist/web/{tailscale.d.ts → access/tailscale.d.ts} +27 -0
  624. package/packages/gateway/dist/web/access/tailscale.d.ts.map +1 -0
  625. package/packages/gateway/dist/web/{tailscale.js → access/tailscale.js} +118 -3
  626. package/packages/gateway/dist/web/access/tailscale.js.map +1 -0
  627. package/packages/gateway/dist/web/agents.d.ts +2 -0
  628. package/packages/gateway/dist/web/agents.d.ts.map +1 -1
  629. package/packages/gateway/dist/web/agents.js +19 -1
  630. package/packages/gateway/dist/web/agents.js.map +1 -1
  631. package/packages/gateway/dist/web/api-routes.d.ts +4 -3
  632. package/packages/gateway/dist/web/api-routes.d.ts.map +1 -1
  633. package/packages/gateway/dist/web/api-routes.js +106 -19
  634. package/packages/gateway/dist/web/api-routes.js.map +1 -1
  635. package/packages/gateway/dist/web/attention.d.ts.map +1 -1
  636. package/packages/gateway/dist/web/attention.js +11 -3
  637. package/packages/gateway/dist/web/attention.js.map +1 -1
  638. package/packages/gateway/dist/web/chat.d.ts +23 -0
  639. package/packages/gateway/dist/web/chat.d.ts.map +1 -1
  640. package/packages/gateway/dist/web/chat.js +62 -2
  641. package/packages/gateway/dist/web/chat.js.map +1 -1
  642. package/packages/gateway/dist/web/client-key.d.ts +3 -0
  643. package/packages/gateway/dist/web/client-key.d.ts.map +1 -1
  644. package/packages/gateway/dist/web/client-key.js +8 -1
  645. package/packages/gateway/dist/web/client-key.js.map +1 -1
  646. package/packages/gateway/dist/web/extension.d.ts +21 -1
  647. package/packages/gateway/dist/web/extension.d.ts.map +1 -1
  648. package/packages/gateway/dist/web/extension.js +183 -3
  649. package/packages/gateway/dist/web/extension.js.map +1 -1
  650. package/packages/gateway/dist/web/http.d.ts +7 -0
  651. package/packages/gateway/dist/web/http.d.ts.map +1 -1
  652. package/packages/gateway/dist/web/http.js +15 -1
  653. package/packages/gateway/dist/web/http.js.map +1 -1
  654. package/packages/gateway/dist/web/index.d.ts +1 -1
  655. package/packages/gateway/dist/web/index.d.ts.map +1 -1
  656. package/packages/gateway/dist/web/index.js +1 -1
  657. package/packages/gateway/dist/web/index.js.map +1 -1
  658. package/packages/gateway/dist/web/onboarding.js +1 -1
  659. package/packages/gateway/dist/web/onboarding.js.map +1 -1
  660. package/packages/gateway/dist/web/remote-hand.d.ts.map +1 -1
  661. package/packages/gateway/dist/web/remote-hand.js +45 -2
  662. package/packages/gateway/dist/web/remote-hand.js.map +1 -1
  663. package/packages/gateway/dist/web/secrets.d.ts +26 -1
  664. package/packages/gateway/dist/web/secrets.d.ts.map +1 -1
  665. package/packages/gateway/dist/web/secrets.js +66 -3
  666. package/packages/gateway/dist/web/secrets.js.map +1 -1
  667. package/packages/gateway/dist/web/server.d.ts +38 -2
  668. package/packages/gateway/dist/web/server.d.ts.map +1 -1
  669. package/packages/gateway/dist/web/server.js +634 -147
  670. package/packages/gateway/dist/web/server.js.map +1 -1
  671. package/packages/gateway/dist/web/sessions.d.ts +24 -14
  672. package/packages/gateway/dist/web/sessions.d.ts.map +1 -1
  673. package/packages/gateway/dist/web/sessions.js +42 -14
  674. package/packages/gateway/dist/web/sessions.js.map +1 -1
  675. package/packages/gateway/dist/web/signed-out.d.ts +10 -0
  676. package/packages/gateway/dist/web/signed-out.d.ts.map +1 -1
  677. package/packages/gateway/dist/web/signed-out.js +47 -0
  678. package/packages/gateway/dist/web/signed-out.js.map +1 -1
  679. package/packages/gateway/dist/web/version.d.ts +2 -0
  680. package/packages/gateway/dist/web/version.d.ts.map +1 -1
  681. package/packages/gateway/dist/web/version.js +5 -1
  682. package/packages/gateway/dist/web/version.js.map +1 -1
  683. package/packages/install/dist/.tsbuildinfo +1 -1
  684. package/packages/install/dist/app-layout.d.ts +127 -0
  685. package/packages/install/dist/app-layout.d.ts.map +1 -0
  686. package/packages/install/dist/app-layout.js +323 -0
  687. package/packages/install/dist/app-layout.js.map +1 -0
  688. package/packages/install/dist/index.d.ts +1 -0
  689. package/packages/install/dist/index.d.ts.map +1 -1
  690. package/packages/install/dist/index.js +1 -0
  691. package/packages/install/dist/index.js.map +1 -1
  692. package/packages/install/dist/launcher.d.ts.map +1 -1
  693. package/packages/install/dist/launcher.js +18 -4
  694. package/packages/install/dist/launcher.js.map +1 -1
  695. package/packages/install/dist/provenance.d.ts +34 -0
  696. package/packages/install/dist/provenance.d.ts.map +1 -0
  697. package/packages/install/dist/provenance.js +200 -0
  698. package/packages/install/dist/provenance.js.map +1 -0
  699. package/packages/install/dist/supervisor.d.ts.map +1 -1
  700. package/packages/install/dist/supervisor.js +9 -4
  701. package/packages/install/dist/supervisor.js.map +1 -1
  702. package/packages/install/dist/upgrade.d.ts +77 -3
  703. package/packages/install/dist/upgrade.d.ts.map +1 -1
  704. package/packages/install/dist/upgrade.js +325 -43
  705. package/packages/install/dist/upgrade.js.map +1 -1
  706. package/packages/runtime/dist/.tsbuildinfo +1 -1
  707. package/packages/runtime/dist/delegate.d.ts +8 -0
  708. package/packages/runtime/dist/delegate.d.ts.map +1 -1
  709. package/packages/runtime/dist/delegate.js +19 -1
  710. package/packages/runtime/dist/delegate.js.map +1 -1
  711. package/packages/runtime/dist/loop.d.ts +2 -0
  712. package/packages/runtime/dist/loop.d.ts.map +1 -1
  713. package/packages/runtime/dist/loop.js +18 -4
  714. package/packages/runtime/dist/loop.js.map +1 -1
  715. package/packages/tools/artifacts/dist/.tsbuildinfo +1 -1
  716. package/packages/tools/browser/dist/.tsbuildinfo +1 -1
  717. package/packages/tools/browser/dist/availability.d.ts +2 -2
  718. package/packages/tools/browser/dist/availability.d.ts.map +1 -1
  719. package/packages/tools/browser/dist/availability.js +2 -2
  720. package/packages/tools/browser/dist/availability.js.map +1 -1
  721. package/packages/tools/browser/dist/controller.d.ts +82 -58
  722. package/packages/tools/browser/dist/controller.d.ts.map +1 -1
  723. package/packages/tools/browser/dist/controller.js +823 -217
  724. package/packages/tools/browser/dist/controller.js.map +1 -1
  725. package/packages/tools/browser/dist/driver.d.ts +3 -1
  726. package/packages/tools/browser/dist/driver.d.ts.map +1 -1
  727. package/packages/tools/browser/dist/driver.js +82 -1
  728. package/packages/tools/browser/dist/driver.js.map +1 -1
  729. package/packages/tools/browser/dist/extension.d.ts +70 -5
  730. package/packages/tools/browser/dist/extension.d.ts.map +1 -1
  731. package/packages/tools/browser/dist/extension.js +94 -9
  732. package/packages/tools/browser/dist/extension.js.map +1 -1
  733. package/packages/tools/browser/dist/index.d.ts +17 -7
  734. package/packages/tools/browser/dist/index.d.ts.map +1 -1
  735. package/packages/tools/browser/dist/index.js +35 -15
  736. package/packages/tools/browser/dist/index.js.map +1 -1
  737. package/packages/tools/browser/dist/logins.d.ts +150 -0
  738. package/packages/tools/browser/dist/logins.d.ts.map +1 -0
  739. package/packages/tools/browser/dist/logins.js +476 -0
  740. package/packages/tools/browser/dist/logins.js.map +1 -0
  741. package/packages/tools/browser/dist/manager.d.ts +39 -21
  742. package/packages/tools/browser/dist/manager.d.ts.map +1 -1
  743. package/packages/tools/browser/dist/manager.js +229 -136
  744. package/packages/tools/browser/dist/manager.js.map +1 -1
  745. package/packages/tools/browser/dist/routes.d.ts +151 -0
  746. package/packages/tools/browser/dist/routes.d.ts.map +1 -0
  747. package/packages/tools/browser/dist/routes.js +331 -0
  748. package/packages/tools/browser/dist/routes.js.map +1 -0
  749. package/packages/tools/browser/dist/secrets.d.ts +3 -1
  750. package/packages/tools/browser/dist/secrets.d.ts.map +1 -1
  751. package/packages/tools/browser/dist/secrets.js +10 -6
  752. package/packages/tools/browser/dist/secrets.js.map +1 -1
  753. package/packages/tools/browser/dist/service.d.ts +182 -115
  754. package/packages/tools/browser/dist/service.d.ts.map +1 -1
  755. package/packages/tools/browser/dist/service.js +491 -388
  756. package/packages/tools/browser/dist/service.js.map +1 -1
  757. package/packages/tools/browser/dist/settings.d.ts +88 -0
  758. package/packages/tools/browser/dist/settings.d.ts.map +1 -0
  759. package/packages/tools/browser/dist/settings.js +86 -0
  760. package/packages/tools/browser/dist/settings.js.map +1 -0
  761. package/packages/tools/browser/dist/telemetry.d.ts +203 -0
  762. package/packages/tools/browser/dist/telemetry.d.ts.map +1 -0
  763. package/packages/tools/browser/dist/telemetry.js +142 -0
  764. package/packages/tools/browser/dist/telemetry.js.map +1 -0
  765. package/packages/tools/browser/dist/types.d.ts +102 -3
  766. package/packages/tools/browser/dist/types.d.ts.map +1 -1
  767. package/packages/tools/browser/dist/types.js +27 -9
  768. package/packages/tools/browser/dist/types.js.map +1 -1
  769. package/packages/tools/email/dist/.tsbuildinfo +1 -1
  770. package/packages/tools/host/dist/.tsbuildinfo +1 -1
  771. package/packages/tools/mcp/dist/.tsbuildinfo +1 -1
  772. package/packages/tools/memory/dist/.tsbuildinfo +1 -1
  773. package/packages/tools/web/dist/.tsbuildinfo +1 -1
  774. package/packages/web/dist/assets/index-DYfeUW-0.css +1 -0
  775. package/packages/web/dist/assets/index-vpc904_b.js +146 -0
  776. package/packages/web/dist/assets/{lottie_light-CKJ88Yuk.js → lottie_light-BFAMYgLA.js} +1 -1
  777. package/packages/web/dist/build.json +1 -1
  778. package/packages/web/dist/index.html +2 -2
  779. package/packages/web/dist/precache.json +4 -4
  780. package/node_modules/@buddi/gateway/dist/web/apps.d.ts +0 -18
  781. package/node_modules/@buddi/gateway/dist/web/apps.d.ts.map +0 -1
  782. package/node_modules/@buddi/gateway/dist/web/apps.js +0 -84
  783. package/node_modules/@buddi/gateway/dist/web/apps.js.map +0 -1
  784. package/node_modules/@buddi/gateway/dist/web/tailscale.d.ts.map +0 -1
  785. package/node_modules/@buddi/gateway/dist/web/tailscale.js.map +0 -1
  786. package/node_modules/@buddi/tool-browser/dist/computer.d.ts +0 -153
  787. package/node_modules/@buddi/tool-browser/dist/computer.d.ts.map +0 -1
  788. package/node_modules/@buddi/tool-browser/dist/computer.js +0 -392
  789. package/node_modules/@buddi/tool-browser/dist/computer.js.map +0 -1
  790. package/node_modules/@buddi/tool-browser/dist/native/buddi-computer +0 -0
  791. package/node_modules/pino/test/browser-bindings.test.js +0 -114
  792. package/node_modules/pino/test/browser-redaction.test.js +0 -264
  793. package/node_modules/pino/test/browser-set-bindings.test.js +0 -99
  794. package/node_modules/pino/test/caller.test.js +0 -20
  795. package/node_modules/pino/test/fixtures/caller-loop.js +0 -6
  796. package/node_modules/pino/test/smoke.js +0 -59
  797. package/node_modules/pino/test/types/pino-import.tst.cts +0 -30
  798. package/node_modules/pino/test/types/pino-import.tst.js +0 -73
  799. package/node_modules/pino/test/types/pino-multistream.tst.ts +0 -49
  800. package/node_modules/pino/test/types/pino-top-export.tst.ts +0 -32
  801. package/node_modules/pino/test/types/pino-type-only.tst.ts +0 -77
  802. package/node_modules/pino/test/types/tsconfig.json +0 -10
  803. package/packages/gateway/dist/web/apps.d.ts +0 -18
  804. package/packages/gateway/dist/web/apps.d.ts.map +0 -1
  805. package/packages/gateway/dist/web/apps.js +0 -84
  806. package/packages/gateway/dist/web/apps.js.map +0 -1
  807. package/packages/gateway/dist/web/tailscale.d.ts.map +0 -1
  808. package/packages/gateway/dist/web/tailscale.js.map +0 -1
  809. package/packages/tools/browser/dist/computer.d.ts +0 -153
  810. package/packages/tools/browser/dist/computer.d.ts.map +0 -1
  811. package/packages/tools/browser/dist/computer.js +0 -392
  812. package/packages/tools/browser/dist/computer.js.map +0 -1
  813. package/packages/tools/browser/dist/native/buddi-computer +0 -0
  814. package/packages/web/dist/assets/index-CN1AXMI1.css +0 -1
  815. package/packages/web/dist/assets/index-CQRE9LJX.js +0 -145
@@ -1,145 +0,0 @@
1
- var xM=Object.defineProperty;var hb=e=>{throw TypeError(e)};var vM=(e,n,s)=>n in e?xM(e,n,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[n]=s;var fb=(e,n,s)=>vM(e,typeof n!="symbol"?n+"":n,s),mb=(e,n,s)=>n.has(e)||hb("Cannot "+s);var Mn=(e,n,s)=>(mb(e,n,"read from private field"),s?s.call(e):n.get(e)),pb=(e,n,s)=>n.has(e)?hb("Cannot add the same private member more than once"):n instanceof WeakSet?n.add(e):n.set(e,s),bm=(e,n,s,r)=>(mb(e,n,"write to private field"),r?r.call(e,s):n.set(e,s),s);function jM(e,n){for(var s=0;s<n.length;s++){const r=n[s];if(typeof r!="string"&&!Array.isArray(r)){for(const a in r)if(a!=="default"&&!(a in e)){const i=Object.getOwnPropertyDescriptor(r,a);i&&Object.defineProperty(e,a,i.get?i:{enumerable:!0,get:()=>r[a]})}}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}(function(){const n=document.createElement("link").relList;if(n&&n.supports&&n.supports("modulepreload"))return;for(const a of document.querySelectorAll('link[rel="modulepreload"]'))r(a);new MutationObserver(a=>{for(const i of a)if(i.type==="childList")for(const l of i.addedNodes)l.tagName==="LINK"&&l.rel==="modulepreload"&&r(l)}).observe(document,{childList:!0,subtree:!0});function s(a){const i={};return a.integrity&&(i.integrity=a.integrity),a.referrerPolicy&&(i.referrerPolicy=a.referrerPolicy),a.crossOrigin==="use-credentials"?i.credentials="include":a.crossOrigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function r(a){if(a.ep)return;a.ep=!0;const i=s(a);fetch(a.href,i)}})();var Yte=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function yM(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var MS={exports:{}},lf={},DS={exports:{}},it={};/**
2
- * @license React
3
- * react.production.min.js
4
- *
5
- * Copyright (c) Facebook, Inc. and its affiliates.
6
- *
7
- * This source code is licensed under the MIT license found in the
8
- * LICENSE file in the root directory of this source tree.
9
- */var lu=Symbol.for("react.element"),wM=Symbol.for("react.portal"),bM=Symbol.for("react.fragment"),kM=Symbol.for("react.strict_mode"),NM=Symbol.for("react.profiler"),SM=Symbol.for("react.provider"),CM=Symbol.for("react.context"),EM=Symbol.for("react.forward_ref"),AM=Symbol.for("react.suspense"),$M=Symbol.for("react.memo"),TM=Symbol.for("react.lazy"),gb=Symbol.iterator;function RM(e){return e===null||typeof e!="object"?null:(e=gb&&e[gb]||e["@@iterator"],typeof e=="function"?e:null)}var OS={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},LS=Object.assign,FS={};function io(e,n,s){this.props=e,this.context=n,this.refs=FS,this.updater=s||OS}io.prototype.isReactComponent={};io.prototype.setState=function(e,n){if(typeof e!="object"&&typeof e!="function"&&e!=null)throw Error("setState(...): takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,e,n,"setState")};io.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")};function _S(){}_S.prototype=io.prototype;function zv(e,n,s){this.props=e,this.context=n,this.refs=FS,this.updater=s||OS}var Uv=zv.prototype=new _S;Uv.constructor=zv;LS(Uv,io.prototype);Uv.isPureReactComponent=!0;var xb=Array.isArray,zS=Object.prototype.hasOwnProperty,Bv={current:null},US={key:!0,ref:!0,__self:!0,__source:!0};function BS(e,n,s){var r,a={},i=null,l=null;if(n!=null)for(r in n.ref!==void 0&&(l=n.ref),n.key!==void 0&&(i=""+n.key),n)zS.call(n,r)&&!US.hasOwnProperty(r)&&(a[r]=n[r]);var o=arguments.length-2;if(o===1)a.children=s;else if(1<o){for(var c=Array(o),u=0;u<o;u++)c[u]=arguments[u+2];a.children=c}if(e&&e.defaultProps)for(r in o=e.defaultProps,o)a[r]===void 0&&(a[r]=o[r]);return{$$typeof:lu,type:e,key:i,ref:l,props:a,_owner:Bv.current}}function IM(e,n){return{$$typeof:lu,type:e.type,key:n,ref:e.ref,props:e.props,_owner:e._owner}}function Wv(e){return typeof e=="object"&&e!==null&&e.$$typeof===lu}function PM(e){var n={"=":"=0",":":"=2"};return"$"+e.replace(/[=:]/g,function(s){return n[s]})}var vb=/\/+/g;function km(e,n){return typeof e=="object"&&e!==null&&e.key!=null?PM(""+e.key):n.toString(36)}function Nd(e,n,s,r,a){var i=typeof e;(i==="undefined"||i==="boolean")&&(e=null);var l=!1;if(e===null)l=!0;else switch(i){case"string":case"number":l=!0;break;case"object":switch(e.$$typeof){case lu:case wM:l=!0}}if(l)return l=e,a=a(l),e=r===""?"."+km(l,0):r,xb(a)?(s="",e!=null&&(s=e.replace(vb,"$&/")+"/"),Nd(a,n,s,"",function(u){return u})):a!=null&&(Wv(a)&&(a=IM(a,s+(!a.key||l&&l.key===a.key?"":(""+a.key).replace(vb,"$&/")+"/")+e)),n.push(a)),1;if(l=0,r=r===""?".":r+":",xb(e))for(var o=0;o<e.length;o++){i=e[o];var c=r+km(i,o);l+=Nd(i,n,s,c,a)}else if(c=RM(e),typeof c=="function")for(e=c.call(e),o=0;!(i=e.next()).done;)i=i.value,c=r+km(i,o++),l+=Nd(i,n,s,c,a);else if(i==="object")throw n=String(e),Error("Objects are not valid as a React child (found: "+(n==="[object Object]"?"object with keys {"+Object.keys(e).join(", ")+"}":n)+"). If you meant to render a collection of children, use an array instead.");return l}function Mu(e,n,s){if(e==null)return e;var r=[],a=0;return Nd(e,r,"","",function(i){return n.call(s,i,a++)}),r}function MM(e){if(e._status===-1){var n=e._result;n=n(),n.then(function(s){(e._status===0||e._status===-1)&&(e._status=1,e._result=s)},function(s){(e._status===0||e._status===-1)&&(e._status=2,e._result=s)}),e._status===-1&&(e._status=0,e._result=n)}if(e._status===1)return e._result.default;throw e._result}var Qn={current:null},Sd={transition:null},DM={ReactCurrentDispatcher:Qn,ReactCurrentBatchConfig:Sd,ReactCurrentOwner:Bv};function WS(){throw Error("act(...) is not supported in production builds of React.")}it.Children={map:Mu,forEach:function(e,n,s){Mu(e,function(){n.apply(this,arguments)},s)},count:function(e){var n=0;return Mu(e,function(){n++}),n},toArray:function(e){return Mu(e,function(n){return n})||[]},only:function(e){if(!Wv(e))throw Error("React.Children.only expected to receive a single React element child.");return e}};it.Component=io;it.Fragment=bM;it.Profiler=NM;it.PureComponent=zv;it.StrictMode=kM;it.Suspense=AM;it.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=DM;it.act=WS;it.cloneElement=function(e,n,s){if(e==null)throw Error("React.cloneElement(...): The argument must be a React element, but you passed "+e+".");var r=LS({},e.props),a=e.key,i=e.ref,l=e._owner;if(n!=null){if(n.ref!==void 0&&(i=n.ref,l=Bv.current),n.key!==void 0&&(a=""+n.key),e.type&&e.type.defaultProps)var o=e.type.defaultProps;for(c in n)zS.call(n,c)&&!US.hasOwnProperty(c)&&(r[c]=n[c]===void 0&&o!==void 0?o[c]:n[c])}var c=arguments.length-2;if(c===1)r.children=s;else if(1<c){o=Array(c);for(var u=0;u<c;u++)o[u]=arguments[u+2];r.children=o}return{$$typeof:lu,type:e.type,key:a,ref:i,props:r,_owner:l}};it.createContext=function(e){return e={$$typeof:CM,_currentValue:e,_currentValue2:e,_threadCount:0,Provider:null,Consumer:null,_defaultValue:null,_globalName:null},e.Provider={$$typeof:SM,_context:e},e.Consumer=e};it.createElement=BS;it.createFactory=function(e){var n=BS.bind(null,e);return n.type=e,n};it.createRef=function(){return{current:null}};it.forwardRef=function(e){return{$$typeof:EM,render:e}};it.isValidElement=Wv;it.lazy=function(e){return{$$typeof:TM,_payload:{_status:-1,_result:e},_init:MM}};it.memo=function(e,n){return{$$typeof:$M,type:e,compare:n===void 0?null:n}};it.startTransition=function(e){var n=Sd.transition;Sd.transition={};try{e()}finally{Sd.transition=n}};it.unstable_act=WS;it.useCallback=function(e,n){return Qn.current.useCallback(e,n)};it.useContext=function(e){return Qn.current.useContext(e)};it.useDebugValue=function(){};it.useDeferredValue=function(e){return Qn.current.useDeferredValue(e)};it.useEffect=function(e,n){return Qn.current.useEffect(e,n)};it.useId=function(){return Qn.current.useId()};it.useImperativeHandle=function(e,n,s){return Qn.current.useImperativeHandle(e,n,s)};it.useInsertionEffect=function(e,n){return Qn.current.useInsertionEffect(e,n)};it.useLayoutEffect=function(e,n){return Qn.current.useLayoutEffect(e,n)};it.useMemo=function(e,n){return Qn.current.useMemo(e,n)};it.useReducer=function(e,n,s){return Qn.current.useReducer(e,n,s)};it.useRef=function(e){return Qn.current.useRef(e)};it.useState=function(e){return Qn.current.useState(e)};it.useSyncExternalStore=function(e,n,s){return Qn.current.useSyncExternalStore(e,n,s)};it.useTransition=function(){return Qn.current.useTransition()};it.version="18.3.1";DS.exports=it;var h=DS.exports;const OM=yM(h),lo=jM({__proto__:null,default:OM},[h]);/**
10
- * @license React
11
- * react-jsx-runtime.production.min.js
12
- *
13
- * Copyright (c) Facebook, Inc. and its affiliates.
14
- *
15
- * This source code is licensed under the MIT license found in the
16
- * LICENSE file in the root directory of this source tree.
17
- */var LM=h,FM=Symbol.for("react.element"),_M=Symbol.for("react.fragment"),zM=Object.prototype.hasOwnProperty,UM=LM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,BM={key:!0,ref:!0,__self:!0,__source:!0};function HS(e,n,s){var r,a={},i=null,l=null;s!==void 0&&(i=""+s),n.key!==void 0&&(i=""+n.key),n.ref!==void 0&&(l=n.ref);for(r in n)zM.call(n,r)&&!BM.hasOwnProperty(r)&&(a[r]=n[r]);if(e&&e.defaultProps)for(r in n=e.defaultProps,n)a[r]===void 0&&(a[r]=n[r]);return{$$typeof:FM,type:e,key:i,ref:l,props:a,_owner:UM.current}}lf.Fragment=_M;lf.jsx=HS;lf.jsxs=HS;MS.exports=lf;var t=MS.exports,KS={exports:{}},Cs={},VS={exports:{}},GS={};/**
18
- * @license React
19
- * scheduler.production.min.js
20
- *
21
- * Copyright (c) Facebook, Inc. and its affiliates.
22
- *
23
- * This source code is licensed under the MIT license found in the
24
- * LICENSE file in the root directory of this source tree.
25
- */(function(e){function n(P,H){var U=P.length;P.push(H);e:for(;0<U;){var V=U-1>>>1,z=P[V];if(0<a(z,H))P[V]=H,P[U]=z,U=V;else break e}}function s(P){return P.length===0?null:P[0]}function r(P){if(P.length===0)return null;var H=P[0],U=P.pop();if(U!==H){P[0]=U;e:for(var V=0,z=P.length,X=z>>>1;V<X;){var K=2*(V+1)-1,ee=P[K],ce=K+1,pe=P[ce];if(0>a(ee,U))ce<z&&0>a(pe,ee)?(P[V]=pe,P[ce]=U,V=ce):(P[V]=ee,P[K]=U,V=K);else if(ce<z&&0>a(pe,U))P[V]=pe,P[ce]=U,V=ce;else break e}}return H}function a(P,H){var U=P.sortIndex-H.sortIndex;return U!==0?U:P.id-H.id}if(typeof performance=="object"&&typeof performance.now=="function"){var i=performance;e.unstable_now=function(){return i.now()}}else{var l=Date,o=l.now();e.unstable_now=function(){return l.now()-o}}var c=[],u=[],d=1,f=null,m=3,p=!1,g=!1,v=!1,b=typeof setTimeout=="function"?setTimeout:null,j=typeof clearTimeout=="function"?clearTimeout:null,x=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function y(P){for(var H=s(u);H!==null;){if(H.callback===null)r(u);else if(H.startTime<=P)r(u),H.sortIndex=H.expirationTime,n(c,H);else break;H=s(u)}}function w(P){if(v=!1,y(P),!g)if(s(c)!==null)g=!0,O(k);else{var H=s(u);H!==null&&M(w,H.startTime-P)}}function k(P,H){g=!1,v&&(v=!1,j(C),C=-1),p=!0;var U=m;try{for(y(H),f=s(c);f!==null&&(!(f.expirationTime>H)||P&&!I());){var V=f.callback;if(typeof V=="function"){f.callback=null,m=f.priorityLevel;var z=V(f.expirationTime<=H);H=e.unstable_now(),typeof z=="function"?f.callback=z:f===s(c)&&r(c),y(H)}else r(c);f=s(c)}if(f!==null)var X=!0;else{var K=s(u);K!==null&&M(w,K.startTime-H),X=!1}return X}finally{f=null,m=U,p=!1}}var N=!1,S=null,C=-1,E=5,T=-1;function I(){return!(e.unstable_now()-T<E)}function F(){if(S!==null){var P=e.unstable_now();T=P;var H=!0;try{H=S(!0,P)}finally{H?D():(N=!1,S=null)}}else N=!1}var D;if(typeof x=="function")D=function(){x(F)};else if(typeof MessageChannel<"u"){var $=new MessageChannel,L=$.port2;$.port1.onmessage=F,D=function(){L.postMessage(null)}}else D=function(){b(F,0)};function O(P){S=P,N||(N=!0,D())}function M(P,H){C=b(function(){P(e.unstable_now())},H)}e.unstable_IdlePriority=5,e.unstable_ImmediatePriority=1,e.unstable_LowPriority=4,e.unstable_NormalPriority=3,e.unstable_Profiling=null,e.unstable_UserBlockingPriority=2,e.unstable_cancelCallback=function(P){P.callback=null},e.unstable_continueExecution=function(){g||p||(g=!0,O(k))},e.unstable_forceFrameRate=function(P){0>P||125<P?console.error("forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported"):E=0<P?Math.floor(1e3/P):5},e.unstable_getCurrentPriorityLevel=function(){return m},e.unstable_getFirstCallbackNode=function(){return s(c)},e.unstable_next=function(P){switch(m){case 1:case 2:case 3:var H=3;break;default:H=m}var U=m;m=H;try{return P()}finally{m=U}},e.unstable_pauseExecution=function(){},e.unstable_requestPaint=function(){},e.unstable_runWithPriority=function(P,H){switch(P){case 1:case 2:case 3:case 4:case 5:break;default:P=3}var U=m;m=P;try{return H()}finally{m=U}},e.unstable_scheduleCallback=function(P,H,U){var V=e.unstable_now();switch(typeof U=="object"&&U!==null?(U=U.delay,U=typeof U=="number"&&0<U?V+U:V):U=V,P){case 1:var z=-1;break;case 2:z=250;break;case 5:z=1073741823;break;case 4:z=1e4;break;default:z=5e3}return z=U+z,P={id:d++,callback:H,priorityLevel:P,startTime:U,expirationTime:z,sortIndex:-1},U>V?(P.sortIndex=U,n(u,P),s(c)===null&&P===s(u)&&(v?(j(C),C=-1):v=!0,M(w,U-V))):(P.sortIndex=z,n(c,P),g||p||(g=!0,O(k))),P},e.unstable_shouldYield=I,e.unstable_wrapCallback=function(P){var H=m;return function(){var U=m;m=H;try{return P.apply(this,arguments)}finally{m=U}}}})(GS);VS.exports=GS;var WM=VS.exports;/**
26
- * @license React
27
- * react-dom.production.min.js
28
- *
29
- * Copyright (c) Facebook, Inc. and its affiliates.
30
- *
31
- * This source code is licensed under the MIT license found in the
32
- * LICENSE file in the root directory of this source tree.
33
- */var HM=h,bs=WM;function be(e){for(var n="https://reactjs.org/docs/error-decoder.html?invariant="+e,s=1;s<arguments.length;s++)n+="&args[]="+encodeURIComponent(arguments[s]);return"Minified React error #"+e+"; visit "+n+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}var qS=new Set,yc={};function zi(e,n){zl(e,n),zl(e+"Capture",n)}function zl(e,n){for(yc[e]=n,e=0;e<n.length;e++)qS.add(n[e])}var ca=!(typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),rg=Object.prototype.hasOwnProperty,KM=/^[:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD][:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\-.0-9\u00B7\u0300-\u036F\u203F-\u2040]*$/,jb={},yb={};function VM(e){return rg.call(yb,e)?!0:rg.call(jb,e)?!1:KM.test(e)?yb[e]=!0:(jb[e]=!0,!1)}function GM(e,n,s,r){if(s!==null&&s.type===0)return!1;switch(typeof n){case"function":case"symbol":return!0;case"boolean":return r?!1:s!==null?!s.acceptsBooleans:(e=e.toLowerCase().slice(0,5),e!=="data-"&&e!=="aria-");default:return!1}}function qM(e,n,s,r){if(n===null||typeof n>"u"||GM(e,n,s,r))return!0;if(r)return!1;if(s!==null)switch(s.type){case 3:return!n;case 4:return n===!1;case 5:return isNaN(n);case 6:return isNaN(n)||1>n}return!1}function Xn(e,n,s,r,a,i,l){this.acceptsBooleans=n===2||n===3||n===4,this.attributeName=r,this.attributeNamespace=a,this.mustUseProperty=s,this.propertyName=e,this.type=n,this.sanitizeURL=i,this.removeEmptyString=l}var Tn={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(e){Tn[e]=new Xn(e,0,!1,e,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(e){var n=e[0];Tn[n]=new Xn(n,1,!1,e[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(e){Tn[e]=new Xn(e,2,!1,e.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(e){Tn[e]=new Xn(e,2,!1,e,null,!1,!1)});"allowFullScreen async autoFocus autoPlay controls default defer disabled disablePictureInPicture disableRemotePlayback formNoValidate hidden loop noModule noValidate open playsInline readOnly required reversed scoped seamless itemScope".split(" ").forEach(function(e){Tn[e]=new Xn(e,3,!1,e.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(e){Tn[e]=new Xn(e,3,!0,e,null,!1,!1)});["capture","download"].forEach(function(e){Tn[e]=new Xn(e,4,!1,e,null,!1,!1)});["cols","rows","size","span"].forEach(function(e){Tn[e]=new Xn(e,6,!1,e,null,!1,!1)});["rowSpan","start"].forEach(function(e){Tn[e]=new Xn(e,5,!1,e.toLowerCase(),null,!1,!1)});var Hv=/[\-:]([a-z])/g;function Kv(e){return e[1].toUpperCase()}"accent-height alignment-baseline arabic-form baseline-shift cap-height clip-path clip-rule color-interpolation color-interpolation-filters color-profile color-rendering dominant-baseline enable-background fill-opacity fill-rule flood-color flood-opacity font-family font-size font-size-adjust font-stretch font-style font-variant font-weight glyph-name glyph-orientation-horizontal glyph-orientation-vertical horiz-adv-x horiz-origin-x image-rendering letter-spacing lighting-color marker-end marker-mid marker-start overline-position overline-thickness paint-order panose-1 pointer-events rendering-intent shape-rendering stop-color stop-opacity strikethrough-position strikethrough-thickness stroke-dasharray stroke-dashoffset stroke-linecap stroke-linejoin stroke-miterlimit stroke-opacity stroke-width text-anchor text-decoration text-rendering underline-position underline-thickness unicode-bidi unicode-range units-per-em v-alphabetic v-hanging v-ideographic v-mathematical vector-effect vert-adv-y vert-origin-x vert-origin-y word-spacing writing-mode xmlns:xlink x-height".split(" ").forEach(function(e){var n=e.replace(Hv,Kv);Tn[n]=new Xn(n,1,!1,e,null,!1,!1)});"xlink:actuate xlink:arcrole xlink:role xlink:show xlink:title xlink:type".split(" ").forEach(function(e){var n=e.replace(Hv,Kv);Tn[n]=new Xn(n,1,!1,e,"http://www.w3.org/1999/xlink",!1,!1)});["xml:base","xml:lang","xml:space"].forEach(function(e){var n=e.replace(Hv,Kv);Tn[n]=new Xn(n,1,!1,e,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(e){Tn[e]=new Xn(e,1,!1,e.toLowerCase(),null,!1,!1)});Tn.xlinkHref=new Xn("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(e){Tn[e]=new Xn(e,1,!1,e.toLowerCase(),null,!0,!0)});function Vv(e,n,s,r){var a=Tn.hasOwnProperty(n)?Tn[n]:null;(a!==null?a.type!==0:r||!(2<n.length)||n[0]!=="o"&&n[0]!=="O"||n[1]!=="n"&&n[1]!=="N")&&(qM(n,s,a,r)&&(s=null),r||a===null?VM(n)&&(s===null?e.removeAttribute(n):e.setAttribute(n,""+s)):a.mustUseProperty?e[a.propertyName]=s===null?a.type===3?!1:"":s:(n=a.attributeName,r=a.attributeNamespace,s===null?e.removeAttribute(n):(a=a.type,s=a===3||a===4&&s===!0?"":""+s,r?e.setAttributeNS(r,n,s):e.setAttribute(n,s))))}var ga=HM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,Du=Symbol.for("react.element"),hl=Symbol.for("react.portal"),fl=Symbol.for("react.fragment"),Gv=Symbol.for("react.strict_mode"),ag=Symbol.for("react.profiler"),YS=Symbol.for("react.provider"),JS=Symbol.for("react.context"),qv=Symbol.for("react.forward_ref"),ig=Symbol.for("react.suspense"),lg=Symbol.for("react.suspense_list"),Yv=Symbol.for("react.memo"),Na=Symbol.for("react.lazy"),QS=Symbol.for("react.offscreen"),wb=Symbol.iterator;function Io(e){return e===null||typeof e!="object"?null:(e=wb&&e[wb]||e["@@iterator"],typeof e=="function"?e:null)}var Ht=Object.assign,Nm;function Go(e){if(Nm===void 0)try{throw Error()}catch(s){var n=s.stack.trim().match(/\n( *(at )?)/);Nm=n&&n[1]||""}return`
34
- `+Nm+e}var Sm=!1;function Cm(e,n){if(!e||Sm)return"";Sm=!0;var s=Error.prepareStackTrace;Error.prepareStackTrace=void 0;try{if(n)if(n=function(){throw Error()},Object.defineProperty(n.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(n,[])}catch(u){var r=u}Reflect.construct(e,[],n)}else{try{n.call()}catch(u){r=u}e.call(n.prototype)}else{try{throw Error()}catch(u){r=u}e()}}catch(u){if(u&&r&&typeof u.stack=="string"){for(var a=u.stack.split(`
35
- `),i=r.stack.split(`
36
- `),l=a.length-1,o=i.length-1;1<=l&&0<=o&&a[l]!==i[o];)o--;for(;1<=l&&0<=o;l--,o--)if(a[l]!==i[o]){if(l!==1||o!==1)do if(l--,o--,0>o||a[l]!==i[o]){var c=`
37
- `+a[l].replace(" at new "," at ");return e.displayName&&c.includes("<anonymous>")&&(c=c.replace("<anonymous>",e.displayName)),c}while(1<=l&&0<=o);break}}}finally{Sm=!1,Error.prepareStackTrace=s}return(e=e?e.displayName||e.name:"")?Go(e):""}function YM(e){switch(e.tag){case 5:return Go(e.type);case 16:return Go("Lazy");case 13:return Go("Suspense");case 19:return Go("SuspenseList");case 0:case 2:case 15:return e=Cm(e.type,!1),e;case 11:return e=Cm(e.type.render,!1),e;case 1:return e=Cm(e.type,!0),e;default:return""}}function og(e){if(e==null)return null;if(typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case fl:return"Fragment";case hl:return"Portal";case ag:return"Profiler";case Gv:return"StrictMode";case ig:return"Suspense";case lg:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case JS:return(e.displayName||"Context")+".Consumer";case YS:return(e._context.displayName||"Context")+".Provider";case qv:var n=e.render;return e=e.displayName,e||(e=n.displayName||n.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case Yv:return n=e.displayName||null,n!==null?n:og(e.type)||"Memo";case Na:n=e._payload,e=e._init;try{return og(e(n))}catch{}}return null}function JM(e){var n=e.type;switch(e.tag){case 24:return"Cache";case 9:return(n.displayName||"Context")+".Consumer";case 10:return(n._context.displayName||"Context")+".Provider";case 18:return"DehydratedFragment";case 11:return e=n.render,e=e.displayName||e.name||"",n.displayName||(e!==""?"ForwardRef("+e+")":"ForwardRef");case 7:return"Fragment";case 5:return n;case 4:return"Portal";case 3:return"Root";case 6:return"Text";case 16:return og(n);case 8:return n===Gv?"StrictMode":"Mode";case 22:return"Offscreen";case 12:return"Profiler";case 21:return"Scope";case 13:return"Suspense";case 19:return"SuspenseList";case 25:return"TracingMarker";case 1:case 0:case 17:case 2:case 14:case 15:if(typeof n=="function")return n.displayName||n.name||null;if(typeof n=="string")return n}return null}function Wa(e){switch(typeof e){case"boolean":case"number":case"string":case"undefined":return e;case"object":return e;default:return""}}function XS(e){var n=e.type;return(e=e.nodeName)&&e.toLowerCase()==="input"&&(n==="checkbox"||n==="radio")}function QM(e){var n=XS(e)?"checked":"value",s=Object.getOwnPropertyDescriptor(e.constructor.prototype,n),r=""+e[n];if(!e.hasOwnProperty(n)&&typeof s<"u"&&typeof s.get=="function"&&typeof s.set=="function"){var a=s.get,i=s.set;return Object.defineProperty(e,n,{configurable:!0,get:function(){return a.call(this)},set:function(l){r=""+l,i.call(this,l)}}),Object.defineProperty(e,n,{enumerable:s.enumerable}),{getValue:function(){return r},setValue:function(l){r=""+l},stopTracking:function(){e._valueTracker=null,delete e[n]}}}}function Ou(e){e._valueTracker||(e._valueTracker=QM(e))}function ZS(e){if(!e)return!1;var n=e._valueTracker;if(!n)return!0;var s=n.getValue(),r="";return e&&(r=XS(e)?e.checked?"true":"false":e.value),e=r,e!==s?(n.setValue(e),!0):!1}function Qd(e){if(e=e||(typeof document<"u"?document:void 0),typeof e>"u")return null;try{return e.activeElement||e.body}catch{return e.body}}function cg(e,n){var s=n.checked;return Ht({},n,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:s??e._wrapperState.initialChecked})}function bb(e,n){var s=n.defaultValue==null?"":n.defaultValue,r=n.checked!=null?n.checked:n.defaultChecked;s=Wa(n.value!=null?n.value:s),e._wrapperState={initialChecked:r,initialValue:s,controlled:n.type==="checkbox"||n.type==="radio"?n.checked!=null:n.value!=null}}function eC(e,n){n=n.checked,n!=null&&Vv(e,"checked",n,!1)}function ug(e,n){eC(e,n);var s=Wa(n.value),r=n.type;if(s!=null)r==="number"?(s===0&&e.value===""||e.value!=s)&&(e.value=""+s):e.value!==""+s&&(e.value=""+s);else if(r==="submit"||r==="reset"){e.removeAttribute("value");return}n.hasOwnProperty("value")?dg(e,n.type,s):n.hasOwnProperty("defaultValue")&&dg(e,n.type,Wa(n.defaultValue)),n.checked==null&&n.defaultChecked!=null&&(e.defaultChecked=!!n.defaultChecked)}function kb(e,n,s){if(n.hasOwnProperty("value")||n.hasOwnProperty("defaultValue")){var r=n.type;if(!(r!=="submit"&&r!=="reset"||n.value!==void 0&&n.value!==null))return;n=""+e._wrapperState.initialValue,s||n===e.value||(e.value=n),e.defaultValue=n}s=e.name,s!==""&&(e.name=""),e.defaultChecked=!!e._wrapperState.initialChecked,s!==""&&(e.name=s)}function dg(e,n,s){(n!=="number"||Qd(e.ownerDocument)!==e)&&(s==null?e.defaultValue=""+e._wrapperState.initialValue:e.defaultValue!==""+s&&(e.defaultValue=""+s))}var qo=Array.isArray;function Al(e,n,s,r){if(e=e.options,n){n={};for(var a=0;a<s.length;a++)n["$"+s[a]]=!0;for(s=0;s<e.length;s++)a=n.hasOwnProperty("$"+e[s].value),e[s].selected!==a&&(e[s].selected=a),a&&r&&(e[s].defaultSelected=!0)}else{for(s=""+Wa(s),n=null,a=0;a<e.length;a++){if(e[a].value===s){e[a].selected=!0,r&&(e[a].defaultSelected=!0);return}n!==null||e[a].disabled||(n=e[a])}n!==null&&(n.selected=!0)}}function hg(e,n){if(n.dangerouslySetInnerHTML!=null)throw Error(be(91));return Ht({},n,{value:void 0,defaultValue:void 0,children:""+e._wrapperState.initialValue})}function Nb(e,n){var s=n.value;if(s==null){if(s=n.children,n=n.defaultValue,s!=null){if(n!=null)throw Error(be(92));if(qo(s)){if(1<s.length)throw Error(be(93));s=s[0]}n=s}n==null&&(n=""),s=n}e._wrapperState={initialValue:Wa(s)}}function tC(e,n){var s=Wa(n.value),r=Wa(n.defaultValue);s!=null&&(s=""+s,s!==e.value&&(e.value=s),n.defaultValue==null&&e.defaultValue!==s&&(e.defaultValue=s)),r!=null&&(e.defaultValue=""+r)}function Sb(e){var n=e.textContent;n===e._wrapperState.initialValue&&n!==""&&n!==null&&(e.value=n)}function nC(e){switch(e){case"svg":return"http://www.w3.org/2000/svg";case"math":return"http://www.w3.org/1998/Math/MathML";default:return"http://www.w3.org/1999/xhtml"}}function fg(e,n){return e==null||e==="http://www.w3.org/1999/xhtml"?nC(n):e==="http://www.w3.org/2000/svg"&&n==="foreignObject"?"http://www.w3.org/1999/xhtml":e}var Lu,sC=function(e){return typeof MSApp<"u"&&MSApp.execUnsafeLocalFunction?function(n,s,r,a){MSApp.execUnsafeLocalFunction(function(){return e(n,s,r,a)})}:e}(function(e,n){if(e.namespaceURI!=="http://www.w3.org/2000/svg"||"innerHTML"in e)e.innerHTML=n;else{for(Lu=Lu||document.createElement("div"),Lu.innerHTML="<svg>"+n.valueOf().toString()+"</svg>",n=Lu.firstChild;e.firstChild;)e.removeChild(e.firstChild);for(;n.firstChild;)e.appendChild(n.firstChild)}});function wc(e,n){if(n){var s=e.firstChild;if(s&&s===e.lastChild&&s.nodeType===3){s.nodeValue=n;return}}e.textContent=n}var nc={animationIterationCount:!0,aspectRatio:!0,borderImageOutset:!0,borderImageSlice:!0,borderImageWidth:!0,boxFlex:!0,boxFlexGroup:!0,boxOrdinalGroup:!0,columnCount:!0,columns:!0,flex:!0,flexGrow:!0,flexPositive:!0,flexShrink:!0,flexNegative:!0,flexOrder:!0,gridArea:!0,gridRow:!0,gridRowEnd:!0,gridRowSpan:!0,gridRowStart:!0,gridColumn:!0,gridColumnEnd:!0,gridColumnSpan:!0,gridColumnStart:!0,fontWeight:!0,lineClamp:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,tabSize:!0,widows:!0,zIndex:!0,zoom:!0,fillOpacity:!0,floodOpacity:!0,stopOpacity:!0,strokeDasharray:!0,strokeDashoffset:!0,strokeMiterlimit:!0,strokeOpacity:!0,strokeWidth:!0},XM=["Webkit","ms","Moz","O"];Object.keys(nc).forEach(function(e){XM.forEach(function(n){n=n+e.charAt(0).toUpperCase()+e.substring(1),nc[n]=nc[e]})});function rC(e,n,s){return n==null||typeof n=="boolean"||n===""?"":s||typeof n!="number"||n===0||nc.hasOwnProperty(e)&&nc[e]?(""+n).trim():n+"px"}function aC(e,n){e=e.style;for(var s in n)if(n.hasOwnProperty(s)){var r=s.indexOf("--")===0,a=rC(s,n[s],r);s==="float"&&(s="cssFloat"),r?e.setProperty(s,a):e[s]=a}}var ZM=Ht({menuitem:!0},{area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0});function mg(e,n){if(n){if(ZM[e]&&(n.children!=null||n.dangerouslySetInnerHTML!=null))throw Error(be(137,e));if(n.dangerouslySetInnerHTML!=null){if(n.children!=null)throw Error(be(60));if(typeof n.dangerouslySetInnerHTML!="object"||!("__html"in n.dangerouslySetInnerHTML))throw Error(be(61))}if(n.style!=null&&typeof n.style!="object")throw Error(be(62))}}function pg(e,n){if(e.indexOf("-")===-1)return typeof n.is=="string";switch(e){case"annotation-xml":case"color-profile":case"font-face":case"font-face-src":case"font-face-uri":case"font-face-format":case"font-face-name":case"missing-glyph":return!1;default:return!0}}var gg=null;function Jv(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var xg=null,$l=null,Tl=null;function Cb(e){if(e=uu(e)){if(typeof xg!="function")throw Error(be(280));var n=e.stateNode;n&&(n=hf(n),xg(e.stateNode,e.type,n))}}function iC(e){$l?Tl?Tl.push(e):Tl=[e]:$l=e}function lC(){if($l){var e=$l,n=Tl;if(Tl=$l=null,Cb(e),n)for(e=0;e<n.length;e++)Cb(n[e])}}function oC(e,n){return e(n)}function cC(){}var Em=!1;function uC(e,n,s){if(Em)return e(n,s);Em=!0;try{return oC(e,n,s)}finally{Em=!1,($l!==null||Tl!==null)&&(cC(),lC())}}function bc(e,n){var s=e.stateNode;if(s===null)return null;var r=hf(s);if(r===null)return null;s=r[n];e:switch(n){case"onClick":case"onClickCapture":case"onDoubleClick":case"onDoubleClickCapture":case"onMouseDown":case"onMouseDownCapture":case"onMouseMove":case"onMouseMoveCapture":case"onMouseUp":case"onMouseUpCapture":case"onMouseEnter":(r=!r.disabled)||(e=e.type,r=!(e==="button"||e==="input"||e==="select"||e==="textarea")),e=!r;break e;default:e=!1}if(e)return null;if(s&&typeof s!="function")throw Error(be(231,n,typeof s));return s}var vg=!1;if(ca)try{var Po={};Object.defineProperty(Po,"passive",{get:function(){vg=!0}}),window.addEventListener("test",Po,Po),window.removeEventListener("test",Po,Po)}catch{vg=!1}function e2(e,n,s,r,a,i,l,o,c){var u=Array.prototype.slice.call(arguments,3);try{n.apply(s,u)}catch(d){this.onError(d)}}var sc=!1,Xd=null,Zd=!1,jg=null,t2={onError:function(e){sc=!0,Xd=e}};function n2(e,n,s,r,a,i,l,o,c){sc=!1,Xd=null,e2.apply(t2,arguments)}function s2(e,n,s,r,a,i,l,o,c){if(n2.apply(this,arguments),sc){if(sc){var u=Xd;sc=!1,Xd=null}else throw Error(be(198));Zd||(Zd=!0,jg=u)}}function Ui(e){var n=e,s=e;if(e.alternate)for(;n.return;)n=n.return;else{e=n;do n=e,n.flags&4098&&(s=n.return),e=n.return;while(e)}return n.tag===3?s:null}function dC(e){if(e.tag===13){var n=e.memoizedState;if(n===null&&(e=e.alternate,e!==null&&(n=e.memoizedState)),n!==null)return n.dehydrated}return null}function Eb(e){if(Ui(e)!==e)throw Error(be(188))}function r2(e){var n=e.alternate;if(!n){if(n=Ui(e),n===null)throw Error(be(188));return n!==e?null:e}for(var s=e,r=n;;){var a=s.return;if(a===null)break;var i=a.alternate;if(i===null){if(r=a.return,r!==null){s=r;continue}break}if(a.child===i.child){for(i=a.child;i;){if(i===s)return Eb(a),e;if(i===r)return Eb(a),n;i=i.sibling}throw Error(be(188))}if(s.return!==r.return)s=a,r=i;else{for(var l=!1,o=a.child;o;){if(o===s){l=!0,s=a,r=i;break}if(o===r){l=!0,r=a,s=i;break}o=o.sibling}if(!l){for(o=i.child;o;){if(o===s){l=!0,s=i,r=a;break}if(o===r){l=!0,r=i,s=a;break}o=o.sibling}if(!l)throw Error(be(189))}}if(s.alternate!==r)throw Error(be(190))}if(s.tag!==3)throw Error(be(188));return s.stateNode.current===s?e:n}function hC(e){return e=r2(e),e!==null?fC(e):null}function fC(e){if(e.tag===5||e.tag===6)return e;for(e=e.child;e!==null;){var n=fC(e);if(n!==null)return n;e=e.sibling}return null}var mC=bs.unstable_scheduleCallback,Ab=bs.unstable_cancelCallback,a2=bs.unstable_shouldYield,i2=bs.unstable_requestPaint,Qt=bs.unstable_now,l2=bs.unstable_getCurrentPriorityLevel,Qv=bs.unstable_ImmediatePriority,pC=bs.unstable_UserBlockingPriority,eh=bs.unstable_NormalPriority,o2=bs.unstable_LowPriority,gC=bs.unstable_IdlePriority,of=null,Ar=null;function c2(e){if(Ar&&typeof Ar.onCommitFiberRoot=="function")try{Ar.onCommitFiberRoot(of,e,void 0,(e.current.flags&128)===128)}catch{}}var rr=Math.clz32?Math.clz32:h2,u2=Math.log,d2=Math.LN2;function h2(e){return e>>>=0,e===0?32:31-(u2(e)/d2|0)|0}var Fu=64,_u=4194304;function Yo(e){switch(e&-e){case 1:return 1;case 2:return 2;case 4:return 4;case 8:return 8;case 16:return 16;case 32:return 32;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return e&4194240;case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:return e&130023424;case 134217728:return 134217728;case 268435456:return 268435456;case 536870912:return 536870912;case 1073741824:return 1073741824;default:return e}}function th(e,n){var s=e.pendingLanes;if(s===0)return 0;var r=0,a=e.suspendedLanes,i=e.pingedLanes,l=s&268435455;if(l!==0){var o=l&~a;o!==0?r=Yo(o):(i&=l,i!==0&&(r=Yo(i)))}else l=s&~a,l!==0?r=Yo(l):i!==0&&(r=Yo(i));if(r===0)return 0;if(n!==0&&n!==r&&!(n&a)&&(a=r&-r,i=n&-n,a>=i||a===16&&(i&4194240)!==0))return n;if(r&4&&(r|=s&16),n=e.entangledLanes,n!==0)for(e=e.entanglements,n&=r;0<n;)s=31-rr(n),a=1<<s,r|=e[s],n&=~a;return r}function f2(e,n){switch(e){case 1:case 2:case 4:return n+250;case 8:case 16:case 32:case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return n+5e3;case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:return-1;case 134217728:case 268435456:case 536870912:case 1073741824:return-1;default:return-1}}function m2(e,n){for(var s=e.suspendedLanes,r=e.pingedLanes,a=e.expirationTimes,i=e.pendingLanes;0<i;){var l=31-rr(i),o=1<<l,c=a[l];c===-1?(!(o&s)||o&r)&&(a[l]=f2(o,n)):c<=n&&(e.expiredLanes|=o),i&=~o}}function yg(e){return e=e.pendingLanes&-1073741825,e!==0?e:e&1073741824?1073741824:0}function xC(){var e=Fu;return Fu<<=1,!(Fu&4194240)&&(Fu=64),e}function Am(e){for(var n=[],s=0;31>s;s++)n.push(e);return n}function ou(e,n,s){e.pendingLanes|=n,n!==536870912&&(e.suspendedLanes=0,e.pingedLanes=0),e=e.eventTimes,n=31-rr(n),e[n]=s}function p2(e,n){var s=e.pendingLanes&~n;e.pendingLanes=n,e.suspendedLanes=0,e.pingedLanes=0,e.expiredLanes&=n,e.mutableReadLanes&=n,e.entangledLanes&=n,n=e.entanglements;var r=e.eventTimes;for(e=e.expirationTimes;0<s;){var a=31-rr(s),i=1<<a;n[a]=0,r[a]=-1,e[a]=-1,s&=~i}}function Xv(e,n){var s=e.entangledLanes|=n;for(e=e.entanglements;s;){var r=31-rr(s),a=1<<r;a&n|e[r]&n&&(e[r]|=n),s&=~a}}var wt=0;function vC(e){return e&=-e,1<e?4<e?e&268435455?16:536870912:4:1}var jC,Zv,yC,wC,bC,wg=!1,zu=[],Ia=null,Pa=null,Ma=null,kc=new Map,Nc=new Map,Ca=[],g2="mousedown mouseup touchcancel touchend touchstart auxclick dblclick pointercancel pointerdown pointerup dragend dragstart drop compositionend compositionstart keydown keypress keyup input textInput copy cut paste click change contextmenu reset submit".split(" ");function $b(e,n){switch(e){case"focusin":case"focusout":Ia=null;break;case"dragenter":case"dragleave":Pa=null;break;case"mouseover":case"mouseout":Ma=null;break;case"pointerover":case"pointerout":kc.delete(n.pointerId);break;case"gotpointercapture":case"lostpointercapture":Nc.delete(n.pointerId)}}function Mo(e,n,s,r,a,i){return e===null||e.nativeEvent!==i?(e={blockedOn:n,domEventName:s,eventSystemFlags:r,nativeEvent:i,targetContainers:[a]},n!==null&&(n=uu(n),n!==null&&Zv(n)),e):(e.eventSystemFlags|=r,n=e.targetContainers,a!==null&&n.indexOf(a)===-1&&n.push(a),e)}function x2(e,n,s,r,a){switch(n){case"focusin":return Ia=Mo(Ia,e,n,s,r,a),!0;case"dragenter":return Pa=Mo(Pa,e,n,s,r,a),!0;case"mouseover":return Ma=Mo(Ma,e,n,s,r,a),!0;case"pointerover":var i=a.pointerId;return kc.set(i,Mo(kc.get(i)||null,e,n,s,r,a)),!0;case"gotpointercapture":return i=a.pointerId,Nc.set(i,Mo(Nc.get(i)||null,e,n,s,r,a)),!0}return!1}function kC(e){var n=ji(e.target);if(n!==null){var s=Ui(n);if(s!==null){if(n=s.tag,n===13){if(n=dC(s),n!==null){e.blockedOn=n,bC(e.priority,function(){yC(s)});return}}else if(n===3&&s.stateNode.current.memoizedState.isDehydrated){e.blockedOn=s.tag===3?s.stateNode.containerInfo:null;return}}}e.blockedOn=null}function Cd(e){if(e.blockedOn!==null)return!1;for(var n=e.targetContainers;0<n.length;){var s=bg(e.domEventName,e.eventSystemFlags,n[0],e.nativeEvent);if(s===null){s=e.nativeEvent;var r=new s.constructor(s.type,s);gg=r,s.target.dispatchEvent(r),gg=null}else return n=uu(s),n!==null&&Zv(n),e.blockedOn=s,!1;n.shift()}return!0}function Tb(e,n,s){Cd(e)&&s.delete(n)}function v2(){wg=!1,Ia!==null&&Cd(Ia)&&(Ia=null),Pa!==null&&Cd(Pa)&&(Pa=null),Ma!==null&&Cd(Ma)&&(Ma=null),kc.forEach(Tb),Nc.forEach(Tb)}function Do(e,n){e.blockedOn===n&&(e.blockedOn=null,wg||(wg=!0,bs.unstable_scheduleCallback(bs.unstable_NormalPriority,v2)))}function Sc(e){function n(a){return Do(a,e)}if(0<zu.length){Do(zu[0],e);for(var s=1;s<zu.length;s++){var r=zu[s];r.blockedOn===e&&(r.blockedOn=null)}}for(Ia!==null&&Do(Ia,e),Pa!==null&&Do(Pa,e),Ma!==null&&Do(Ma,e),kc.forEach(n),Nc.forEach(n),s=0;s<Ca.length;s++)r=Ca[s],r.blockedOn===e&&(r.blockedOn=null);for(;0<Ca.length&&(s=Ca[0],s.blockedOn===null);)kC(s),s.blockedOn===null&&Ca.shift()}var Rl=ga.ReactCurrentBatchConfig,nh=!0;function j2(e,n,s,r){var a=wt,i=Rl.transition;Rl.transition=null;try{wt=1,ej(e,n,s,r)}finally{wt=a,Rl.transition=i}}function y2(e,n,s,r){var a=wt,i=Rl.transition;Rl.transition=null;try{wt=4,ej(e,n,s,r)}finally{wt=a,Rl.transition=i}}function ej(e,n,s,r){if(nh){var a=bg(e,n,s,r);if(a===null)Fm(e,n,r,sh,s),$b(e,r);else if(x2(a,e,n,s,r))r.stopPropagation();else if($b(e,r),n&4&&-1<g2.indexOf(e)){for(;a!==null;){var i=uu(a);if(i!==null&&jC(i),i=bg(e,n,s,r),i===null&&Fm(e,n,r,sh,s),i===a)break;a=i}a!==null&&r.stopPropagation()}else Fm(e,n,r,null,s)}}var sh=null;function bg(e,n,s,r){if(sh=null,e=Jv(r),e=ji(e),e!==null)if(n=Ui(e),n===null)e=null;else if(s=n.tag,s===13){if(e=dC(n),e!==null)return e;e=null}else if(s===3){if(n.stateNode.current.memoizedState.isDehydrated)return n.tag===3?n.stateNode.containerInfo:null;e=null}else n!==e&&(e=null);return sh=e,null}function NC(e){switch(e){case"cancel":case"click":case"close":case"contextmenu":case"copy":case"cut":case"auxclick":case"dblclick":case"dragend":case"dragstart":case"drop":case"focusin":case"focusout":case"input":case"invalid":case"keydown":case"keypress":case"keyup":case"mousedown":case"mouseup":case"paste":case"pause":case"play":case"pointercancel":case"pointerdown":case"pointerup":case"ratechange":case"reset":case"resize":case"seeked":case"submit":case"touchcancel":case"touchend":case"touchstart":case"volumechange":case"change":case"selectionchange":case"textInput":case"compositionstart":case"compositionend":case"compositionupdate":case"beforeblur":case"afterblur":case"beforeinput":case"blur":case"fullscreenchange":case"focus":case"hashchange":case"popstate":case"select":case"selectstart":return 1;case"drag":case"dragenter":case"dragexit":case"dragleave":case"dragover":case"mousemove":case"mouseout":case"mouseover":case"pointermove":case"pointerout":case"pointerover":case"scroll":case"toggle":case"touchmove":case"wheel":case"mouseenter":case"mouseleave":case"pointerenter":case"pointerleave":return 4;case"message":switch(l2()){case Qv:return 1;case pC:return 4;case eh:case o2:return 16;case gC:return 536870912;default:return 16}default:return 16}}var Aa=null,tj=null,Ed=null;function SC(){if(Ed)return Ed;var e,n=tj,s=n.length,r,a="value"in Aa?Aa.value:Aa.textContent,i=a.length;for(e=0;e<s&&n[e]===a[e];e++);var l=s-e;for(r=1;r<=l&&n[s-r]===a[i-r];r++);return Ed=a.slice(e,1<r?1-r:void 0)}function Ad(e){var n=e.keyCode;return"charCode"in e?(e=e.charCode,e===0&&n===13&&(e=13)):e=n,e===10&&(e=13),32<=e||e===13?e:0}function Uu(){return!0}function Rb(){return!1}function Es(e){function n(s,r,a,i,l){this._reactName=s,this._targetInst=a,this.type=r,this.nativeEvent=i,this.target=l,this.currentTarget=null;for(var o in e)e.hasOwnProperty(o)&&(s=e[o],this[o]=s?s(i):i[o]);return this.isDefaultPrevented=(i.defaultPrevented!=null?i.defaultPrevented:i.returnValue===!1)?Uu:Rb,this.isPropagationStopped=Rb,this}return Ht(n.prototype,{preventDefault:function(){this.defaultPrevented=!0;var s=this.nativeEvent;s&&(s.preventDefault?s.preventDefault():typeof s.returnValue!="unknown"&&(s.returnValue=!1),this.isDefaultPrevented=Uu)},stopPropagation:function(){var s=this.nativeEvent;s&&(s.stopPropagation?s.stopPropagation():typeof s.cancelBubble!="unknown"&&(s.cancelBubble=!0),this.isPropagationStopped=Uu)},persist:function(){},isPersistent:Uu}),n}var oo={eventPhase:0,bubbles:0,cancelable:0,timeStamp:function(e){return e.timeStamp||Date.now()},defaultPrevented:0,isTrusted:0},nj=Es(oo),cu=Ht({},oo,{view:0,detail:0}),w2=Es(cu),$m,Tm,Oo,cf=Ht({},cu,{screenX:0,screenY:0,clientX:0,clientY:0,pageX:0,pageY:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,getModifierState:sj,button:0,buttons:0,relatedTarget:function(e){return e.relatedTarget===void 0?e.fromElement===e.srcElement?e.toElement:e.fromElement:e.relatedTarget},movementX:function(e){return"movementX"in e?e.movementX:(e!==Oo&&(Oo&&e.type==="mousemove"?($m=e.screenX-Oo.screenX,Tm=e.screenY-Oo.screenY):Tm=$m=0,Oo=e),$m)},movementY:function(e){return"movementY"in e?e.movementY:Tm}}),Ib=Es(cf),b2=Ht({},cf,{dataTransfer:0}),k2=Es(b2),N2=Ht({},cu,{relatedTarget:0}),Rm=Es(N2),S2=Ht({},oo,{animationName:0,elapsedTime:0,pseudoElement:0}),C2=Es(S2),E2=Ht({},oo,{clipboardData:function(e){return"clipboardData"in e?e.clipboardData:window.clipboardData}}),A2=Es(E2),$2=Ht({},oo,{data:0}),Pb=Es($2),T2={Esc:"Escape",Spacebar:" ",Left:"ArrowLeft",Up:"ArrowUp",Right:"ArrowRight",Down:"ArrowDown",Del:"Delete",Win:"OS",Menu:"ContextMenu",Apps:"ContextMenu",Scroll:"ScrollLock",MozPrintableKey:"Unidentified"},R2={8:"Backspace",9:"Tab",12:"Clear",13:"Enter",16:"Shift",17:"Control",18:"Alt",19:"Pause",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",45:"Insert",46:"Delete",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NumLock",145:"ScrollLock",224:"Meta"},I2={Alt:"altKey",Control:"ctrlKey",Meta:"metaKey",Shift:"shiftKey"};function P2(e){var n=this.nativeEvent;return n.getModifierState?n.getModifierState(e):(e=I2[e])?!!n[e]:!1}function sj(){return P2}var M2=Ht({},cu,{key:function(e){if(e.key){var n=T2[e.key]||e.key;if(n!=="Unidentified")return n}return e.type==="keypress"?(e=Ad(e),e===13?"Enter":String.fromCharCode(e)):e.type==="keydown"||e.type==="keyup"?R2[e.keyCode]||"Unidentified":""},code:0,location:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,repeat:0,locale:0,getModifierState:sj,charCode:function(e){return e.type==="keypress"?Ad(e):0},keyCode:function(e){return e.type==="keydown"||e.type==="keyup"?e.keyCode:0},which:function(e){return e.type==="keypress"?Ad(e):e.type==="keydown"||e.type==="keyup"?e.keyCode:0}}),D2=Es(M2),O2=Ht({},cf,{pointerId:0,width:0,height:0,pressure:0,tangentialPressure:0,tiltX:0,tiltY:0,twist:0,pointerType:0,isPrimary:0}),Mb=Es(O2),L2=Ht({},cu,{touches:0,targetTouches:0,changedTouches:0,altKey:0,metaKey:0,ctrlKey:0,shiftKey:0,getModifierState:sj}),F2=Es(L2),_2=Ht({},oo,{propertyName:0,elapsedTime:0,pseudoElement:0}),z2=Es(_2),U2=Ht({},cf,{deltaX:function(e){return"deltaX"in e?e.deltaX:"wheelDeltaX"in e?-e.wheelDeltaX:0},deltaY:function(e){return"deltaY"in e?e.deltaY:"wheelDeltaY"in e?-e.wheelDeltaY:"wheelDelta"in e?-e.wheelDelta:0},deltaZ:0,deltaMode:0}),B2=Es(U2),W2=[9,13,27,32],rj=ca&&"CompositionEvent"in window,rc=null;ca&&"documentMode"in document&&(rc=document.documentMode);var H2=ca&&"TextEvent"in window&&!rc,CC=ca&&(!rj||rc&&8<rc&&11>=rc),Db=" ",Ob=!1;function EC(e,n){switch(e){case"keyup":return W2.indexOf(n.keyCode)!==-1;case"keydown":return n.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function AC(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var ml=!1;function K2(e,n){switch(e){case"compositionend":return AC(n);case"keypress":return n.which!==32?null:(Ob=!0,Db);case"textInput":return e=n.data,e===Db&&Ob?null:e;default:return null}}function V2(e,n){if(ml)return e==="compositionend"||!rj&&EC(e,n)?(e=SC(),Ed=tj=Aa=null,ml=!1,e):null;switch(e){case"paste":return null;case"keypress":if(!(n.ctrlKey||n.altKey||n.metaKey)||n.ctrlKey&&n.altKey){if(n.char&&1<n.char.length)return n.char;if(n.which)return String.fromCharCode(n.which)}return null;case"compositionend":return CC&&n.locale!=="ko"?null:n.data;default:return null}}var G2={color:!0,date:!0,datetime:!0,"datetime-local":!0,email:!0,month:!0,number:!0,password:!0,range:!0,search:!0,tel:!0,text:!0,time:!0,url:!0,week:!0};function Lb(e){var n=e&&e.nodeName&&e.nodeName.toLowerCase();return n==="input"?!!G2[e.type]:n==="textarea"}function $C(e,n,s,r){iC(r),n=rh(n,"onChange"),0<n.length&&(s=new nj("onChange","change",null,s,r),e.push({event:s,listeners:n}))}var ac=null,Cc=null;function q2(e){zC(e,0)}function uf(e){var n=xl(e);if(ZS(n))return e}function Y2(e,n){if(e==="change")return n}var TC=!1;if(ca){var Im;if(ca){var Pm="oninput"in document;if(!Pm){var Fb=document.createElement("div");Fb.setAttribute("oninput","return;"),Pm=typeof Fb.oninput=="function"}Im=Pm}else Im=!1;TC=Im&&(!document.documentMode||9<document.documentMode)}function _b(){ac&&(ac.detachEvent("onpropertychange",RC),Cc=ac=null)}function RC(e){if(e.propertyName==="value"&&uf(Cc)){var n=[];$C(n,Cc,e,Jv(e)),uC(q2,n)}}function J2(e,n,s){e==="focusin"?(_b(),ac=n,Cc=s,ac.attachEvent("onpropertychange",RC)):e==="focusout"&&_b()}function Q2(e){if(e==="selectionchange"||e==="keyup"||e==="keydown")return uf(Cc)}function X2(e,n){if(e==="click")return uf(n)}function Z2(e,n){if(e==="input"||e==="change")return uf(n)}function eD(e,n){return e===n&&(e!==0||1/e===1/n)||e!==e&&n!==n}var or=typeof Object.is=="function"?Object.is:eD;function Ec(e,n){if(or(e,n))return!0;if(typeof e!="object"||e===null||typeof n!="object"||n===null)return!1;var s=Object.keys(e),r=Object.keys(n);if(s.length!==r.length)return!1;for(r=0;r<s.length;r++){var a=s[r];if(!rg.call(n,a)||!or(e[a],n[a]))return!1}return!0}function zb(e){for(;e&&e.firstChild;)e=e.firstChild;return e}function Ub(e,n){var s=zb(e);e=0;for(var r;s;){if(s.nodeType===3){if(r=e+s.textContent.length,e<=n&&r>=n)return{node:s,offset:n-e};e=r}e:{for(;s;){if(s.nextSibling){s=s.nextSibling;break e}s=s.parentNode}s=void 0}s=zb(s)}}function IC(e,n){return e&&n?e===n?!0:e&&e.nodeType===3?!1:n&&n.nodeType===3?IC(e,n.parentNode):"contains"in e?e.contains(n):e.compareDocumentPosition?!!(e.compareDocumentPosition(n)&16):!1:!1}function PC(){for(var e=window,n=Qd();n instanceof e.HTMLIFrameElement;){try{var s=typeof n.contentWindow.location.href=="string"}catch{s=!1}if(s)e=n.contentWindow;else break;n=Qd(e.document)}return n}function aj(e){var n=e&&e.nodeName&&e.nodeName.toLowerCase();return n&&(n==="input"&&(e.type==="text"||e.type==="search"||e.type==="tel"||e.type==="url"||e.type==="password")||n==="textarea"||e.contentEditable==="true")}function tD(e){var n=PC(),s=e.focusedElem,r=e.selectionRange;if(n!==s&&s&&s.ownerDocument&&IC(s.ownerDocument.documentElement,s)){if(r!==null&&aj(s)){if(n=r.start,e=r.end,e===void 0&&(e=n),"selectionStart"in s)s.selectionStart=n,s.selectionEnd=Math.min(e,s.value.length);else if(e=(n=s.ownerDocument||document)&&n.defaultView||window,e.getSelection){e=e.getSelection();var a=s.textContent.length,i=Math.min(r.start,a);r=r.end===void 0?i:Math.min(r.end,a),!e.extend&&i>r&&(a=r,r=i,i=a),a=Ub(s,i);var l=Ub(s,r);a&&l&&(e.rangeCount!==1||e.anchorNode!==a.node||e.anchorOffset!==a.offset||e.focusNode!==l.node||e.focusOffset!==l.offset)&&(n=n.createRange(),n.setStart(a.node,a.offset),e.removeAllRanges(),i>r?(e.addRange(n),e.extend(l.node,l.offset)):(n.setEnd(l.node,l.offset),e.addRange(n)))}}for(n=[],e=s;e=e.parentNode;)e.nodeType===1&&n.push({element:e,left:e.scrollLeft,top:e.scrollTop});for(typeof s.focus=="function"&&s.focus(),s=0;s<n.length;s++)e=n[s],e.element.scrollLeft=e.left,e.element.scrollTop=e.top}}var nD=ca&&"documentMode"in document&&11>=document.documentMode,pl=null,kg=null,ic=null,Ng=!1;function Bb(e,n,s){var r=s.window===s?s.document:s.nodeType===9?s:s.ownerDocument;Ng||pl==null||pl!==Qd(r)||(r=pl,"selectionStart"in r&&aj(r)?r={start:r.selectionStart,end:r.selectionEnd}:(r=(r.ownerDocument&&r.ownerDocument.defaultView||window).getSelection(),r={anchorNode:r.anchorNode,anchorOffset:r.anchorOffset,focusNode:r.focusNode,focusOffset:r.focusOffset}),ic&&Ec(ic,r)||(ic=r,r=rh(kg,"onSelect"),0<r.length&&(n=new nj("onSelect","select",null,n,s),e.push({event:n,listeners:r}),n.target=pl)))}function Bu(e,n){var s={};return s[e.toLowerCase()]=n.toLowerCase(),s["Webkit"+e]="webkit"+n,s["Moz"+e]="moz"+n,s}var gl={animationend:Bu("Animation","AnimationEnd"),animationiteration:Bu("Animation","AnimationIteration"),animationstart:Bu("Animation","AnimationStart"),transitionend:Bu("Transition","TransitionEnd")},Mm={},MC={};ca&&(MC=document.createElement("div").style,"AnimationEvent"in window||(delete gl.animationend.animation,delete gl.animationiteration.animation,delete gl.animationstart.animation),"TransitionEvent"in window||delete gl.transitionend.transition);function df(e){if(Mm[e])return Mm[e];if(!gl[e])return e;var n=gl[e],s;for(s in n)if(n.hasOwnProperty(s)&&s in MC)return Mm[e]=n[s];return e}var DC=df("animationend"),OC=df("animationiteration"),LC=df("animationstart"),FC=df("transitionend"),_C=new Map,Wb="abort auxClick cancel canPlay canPlayThrough click close contextMenu copy cut drag dragEnd dragEnter dragExit dragLeave dragOver dragStart drop durationChange emptied encrypted ended error gotPointerCapture input invalid keyDown keyPress keyUp load loadedData loadedMetadata loadStart lostPointerCapture mouseDown mouseMove mouseOut mouseOver mouseUp paste pause play playing pointerCancel pointerDown pointerMove pointerOut pointerOver pointerUp progress rateChange reset resize seeked seeking stalled submit suspend timeUpdate touchCancel touchEnd touchStart volumeChange scroll toggle touchMove waiting wheel".split(" ");function Za(e,n){_C.set(e,n),zi(n,[e])}for(var Dm=0;Dm<Wb.length;Dm++){var Om=Wb[Dm],sD=Om.toLowerCase(),rD=Om[0].toUpperCase()+Om.slice(1);Za(sD,"on"+rD)}Za(DC,"onAnimationEnd");Za(OC,"onAnimationIteration");Za(LC,"onAnimationStart");Za("dblclick","onDoubleClick");Za("focusin","onFocus");Za("focusout","onBlur");Za(FC,"onTransitionEnd");zl("onMouseEnter",["mouseout","mouseover"]);zl("onMouseLeave",["mouseout","mouseover"]);zl("onPointerEnter",["pointerout","pointerover"]);zl("onPointerLeave",["pointerout","pointerover"]);zi("onChange","change click focusin focusout input keydown keyup selectionchange".split(" "));zi("onSelect","focusout contextmenu dragend focusin keydown keyup mousedown mouseup selectionchange".split(" "));zi("onBeforeInput",["compositionend","keypress","textInput","paste"]);zi("onCompositionEnd","compositionend focusout keydown keypress keyup mousedown".split(" "));zi("onCompositionStart","compositionstart focusout keydown keypress keyup mousedown".split(" "));zi("onCompositionUpdate","compositionupdate focusout keydown keypress keyup mousedown".split(" "));var Jo="abort canplay canplaythrough durationchange emptied encrypted ended error loadeddata loadedmetadata loadstart pause play playing progress ratechange resize seeked seeking stalled suspend timeupdate volumechange waiting".split(" "),aD=new Set("cancel close invalid load scroll toggle".split(" ").concat(Jo));function Hb(e,n,s){var r=e.type||"unknown-event";e.currentTarget=s,s2(r,n,void 0,e),e.currentTarget=null}function zC(e,n){n=(n&4)!==0;for(var s=0;s<e.length;s++){var r=e[s],a=r.event;r=r.listeners;e:{var i=void 0;if(n)for(var l=r.length-1;0<=l;l--){var o=r[l],c=o.instance,u=o.currentTarget;if(o=o.listener,c!==i&&a.isPropagationStopped())break e;Hb(a,o,u),i=c}else for(l=0;l<r.length;l++){if(o=r[l],c=o.instance,u=o.currentTarget,o=o.listener,c!==i&&a.isPropagationStopped())break e;Hb(a,o,u),i=c}}}if(Zd)throw e=jg,Zd=!1,jg=null,e}function It(e,n){var s=n[$g];s===void 0&&(s=n[$g]=new Set);var r=e+"__bubble";s.has(r)||(UC(n,e,2,!1),s.add(r))}function Lm(e,n,s){var r=0;n&&(r|=4),UC(s,e,r,n)}var Wu="_reactListening"+Math.random().toString(36).slice(2);function Ac(e){if(!e[Wu]){e[Wu]=!0,qS.forEach(function(s){s!=="selectionchange"&&(aD.has(s)||Lm(s,!1,e),Lm(s,!0,e))});var n=e.nodeType===9?e:e.ownerDocument;n===null||n[Wu]||(n[Wu]=!0,Lm("selectionchange",!1,n))}}function UC(e,n,s,r){switch(NC(n)){case 1:var a=j2;break;case 4:a=y2;break;default:a=ej}s=a.bind(null,n,s,e),a=void 0,!vg||n!=="touchstart"&&n!=="touchmove"&&n!=="wheel"||(a=!0),r?a!==void 0?e.addEventListener(n,s,{capture:!0,passive:a}):e.addEventListener(n,s,!0):a!==void 0?e.addEventListener(n,s,{passive:a}):e.addEventListener(n,s,!1)}function Fm(e,n,s,r,a){var i=r;if(!(n&1)&&!(n&2)&&r!==null)e:for(;;){if(r===null)return;var l=r.tag;if(l===3||l===4){var o=r.stateNode.containerInfo;if(o===a||o.nodeType===8&&o.parentNode===a)break;if(l===4)for(l=r.return;l!==null;){var c=l.tag;if((c===3||c===4)&&(c=l.stateNode.containerInfo,c===a||c.nodeType===8&&c.parentNode===a))return;l=l.return}for(;o!==null;){if(l=ji(o),l===null)return;if(c=l.tag,c===5||c===6){r=i=l;continue e}o=o.parentNode}}r=r.return}uC(function(){var u=i,d=Jv(s),f=[];e:{var m=_C.get(e);if(m!==void 0){var p=nj,g=e;switch(e){case"keypress":if(Ad(s)===0)break e;case"keydown":case"keyup":p=D2;break;case"focusin":g="focus",p=Rm;break;case"focusout":g="blur",p=Rm;break;case"beforeblur":case"afterblur":p=Rm;break;case"click":if(s.button===2)break e;case"auxclick":case"dblclick":case"mousedown":case"mousemove":case"mouseup":case"mouseout":case"mouseover":case"contextmenu":p=Ib;break;case"drag":case"dragend":case"dragenter":case"dragexit":case"dragleave":case"dragover":case"dragstart":case"drop":p=k2;break;case"touchcancel":case"touchend":case"touchmove":case"touchstart":p=F2;break;case DC:case OC:case LC:p=C2;break;case FC:p=z2;break;case"scroll":p=w2;break;case"wheel":p=B2;break;case"copy":case"cut":case"paste":p=A2;break;case"gotpointercapture":case"lostpointercapture":case"pointercancel":case"pointerdown":case"pointermove":case"pointerout":case"pointerover":case"pointerup":p=Mb}var v=(n&4)!==0,b=!v&&e==="scroll",j=v?m!==null?m+"Capture":null:m;v=[];for(var x=u,y;x!==null;){y=x;var w=y.stateNode;if(y.tag===5&&w!==null&&(y=w,j!==null&&(w=bc(x,j),w!=null&&v.push($c(x,w,y)))),b)break;x=x.return}0<v.length&&(m=new p(m,g,null,s,d),f.push({event:m,listeners:v}))}}if(!(n&7)){e:{if(m=e==="mouseover"||e==="pointerover",p=e==="mouseout"||e==="pointerout",m&&s!==gg&&(g=s.relatedTarget||s.fromElement)&&(ji(g)||g[ua]))break e;if((p||m)&&(m=d.window===d?d:(m=d.ownerDocument)?m.defaultView||m.parentWindow:window,p?(g=s.relatedTarget||s.toElement,p=u,g=g?ji(g):null,g!==null&&(b=Ui(g),g!==b||g.tag!==5&&g.tag!==6)&&(g=null)):(p=null,g=u),p!==g)){if(v=Ib,w="onMouseLeave",j="onMouseEnter",x="mouse",(e==="pointerout"||e==="pointerover")&&(v=Mb,w="onPointerLeave",j="onPointerEnter",x="pointer"),b=p==null?m:xl(p),y=g==null?m:xl(g),m=new v(w,x+"leave",p,s,d),m.target=b,m.relatedTarget=y,w=null,ji(d)===u&&(v=new v(j,x+"enter",g,s,d),v.target=y,v.relatedTarget=b,w=v),b=w,p&&g)t:{for(v=p,j=g,x=0,y=v;y;y=nl(y))x++;for(y=0,w=j;w;w=nl(w))y++;for(;0<x-y;)v=nl(v),x--;for(;0<y-x;)j=nl(j),y--;for(;x--;){if(v===j||j!==null&&v===j.alternate)break t;v=nl(v),j=nl(j)}v=null}else v=null;p!==null&&Kb(f,m,p,v,!1),g!==null&&b!==null&&Kb(f,b,g,v,!0)}}e:{if(m=u?xl(u):window,p=m.nodeName&&m.nodeName.toLowerCase(),p==="select"||p==="input"&&m.type==="file")var k=Y2;else if(Lb(m))if(TC)k=Z2;else{k=Q2;var N=J2}else(p=m.nodeName)&&p.toLowerCase()==="input"&&(m.type==="checkbox"||m.type==="radio")&&(k=X2);if(k&&(k=k(e,u))){$C(f,k,s,d);break e}N&&N(e,m,u),e==="focusout"&&(N=m._wrapperState)&&N.controlled&&m.type==="number"&&dg(m,"number",m.value)}switch(N=u?xl(u):window,e){case"focusin":(Lb(N)||N.contentEditable==="true")&&(pl=N,kg=u,ic=null);break;case"focusout":ic=kg=pl=null;break;case"mousedown":Ng=!0;break;case"contextmenu":case"mouseup":case"dragend":Ng=!1,Bb(f,s,d);break;case"selectionchange":if(nD)break;case"keydown":case"keyup":Bb(f,s,d)}var S;if(rj)e:{switch(e){case"compositionstart":var C="onCompositionStart";break e;case"compositionend":C="onCompositionEnd";break e;case"compositionupdate":C="onCompositionUpdate";break e}C=void 0}else ml?EC(e,s)&&(C="onCompositionEnd"):e==="keydown"&&s.keyCode===229&&(C="onCompositionStart");C&&(CC&&s.locale!=="ko"&&(ml||C!=="onCompositionStart"?C==="onCompositionEnd"&&ml&&(S=SC()):(Aa=d,tj="value"in Aa?Aa.value:Aa.textContent,ml=!0)),N=rh(u,C),0<N.length&&(C=new Pb(C,e,null,s,d),f.push({event:C,listeners:N}),S?C.data=S:(S=AC(s),S!==null&&(C.data=S)))),(S=H2?K2(e,s):V2(e,s))&&(u=rh(u,"onBeforeInput"),0<u.length&&(d=new Pb("onBeforeInput","beforeinput",null,s,d),f.push({event:d,listeners:u}),d.data=S))}zC(f,n)})}function $c(e,n,s){return{instance:e,listener:n,currentTarget:s}}function rh(e,n){for(var s=n+"Capture",r=[];e!==null;){var a=e,i=a.stateNode;a.tag===5&&i!==null&&(a=i,i=bc(e,s),i!=null&&r.unshift($c(e,i,a)),i=bc(e,n),i!=null&&r.push($c(e,i,a))),e=e.return}return r}function nl(e){if(e===null)return null;do e=e.return;while(e&&e.tag!==5);return e||null}function Kb(e,n,s,r,a){for(var i=n._reactName,l=[];s!==null&&s!==r;){var o=s,c=o.alternate,u=o.stateNode;if(c!==null&&c===r)break;o.tag===5&&u!==null&&(o=u,a?(c=bc(s,i),c!=null&&l.unshift($c(s,c,o))):a||(c=bc(s,i),c!=null&&l.push($c(s,c,o)))),s=s.return}l.length!==0&&e.push({event:n,listeners:l})}var iD=/\r\n?/g,lD=/\u0000|\uFFFD/g;function Vb(e){return(typeof e=="string"?e:""+e).replace(iD,`
38
- `).replace(lD,"")}function Hu(e,n,s){if(n=Vb(n),Vb(e)!==n&&s)throw Error(be(425))}function ah(){}var Sg=null,Cg=null;function Eg(e,n){return e==="textarea"||e==="noscript"||typeof n.children=="string"||typeof n.children=="number"||typeof n.dangerouslySetInnerHTML=="object"&&n.dangerouslySetInnerHTML!==null&&n.dangerouslySetInnerHTML.__html!=null}var Ag=typeof setTimeout=="function"?setTimeout:void 0,oD=typeof clearTimeout=="function"?clearTimeout:void 0,Gb=typeof Promise=="function"?Promise:void 0,cD=typeof queueMicrotask=="function"?queueMicrotask:typeof Gb<"u"?function(e){return Gb.resolve(null).then(e).catch(uD)}:Ag;function uD(e){setTimeout(function(){throw e})}function _m(e,n){var s=n,r=0;do{var a=s.nextSibling;if(e.removeChild(s),a&&a.nodeType===8)if(s=a.data,s==="/$"){if(r===0){e.removeChild(a),Sc(n);return}r--}else s!=="$"&&s!=="$?"&&s!=="$!"||r++;s=a}while(s);Sc(n)}function Da(e){for(;e!=null;e=e.nextSibling){var n=e.nodeType;if(n===1||n===3)break;if(n===8){if(n=e.data,n==="$"||n==="$!"||n==="$?")break;if(n==="/$")return null}}return e}function qb(e){e=e.previousSibling;for(var n=0;e;){if(e.nodeType===8){var s=e.data;if(s==="$"||s==="$!"||s==="$?"){if(n===0)return e;n--}else s==="/$"&&n++}e=e.previousSibling}return null}var co=Math.random().toString(36).slice(2),Nr="__reactFiber$"+co,Tc="__reactProps$"+co,ua="__reactContainer$"+co,$g="__reactEvents$"+co,dD="__reactListeners$"+co,hD="__reactHandles$"+co;function ji(e){var n=e[Nr];if(n)return n;for(var s=e.parentNode;s;){if(n=s[ua]||s[Nr]){if(s=n.alternate,n.child!==null||s!==null&&s.child!==null)for(e=qb(e);e!==null;){if(s=e[Nr])return s;e=qb(e)}return n}e=s,s=e.parentNode}return null}function uu(e){return e=e[Nr]||e[ua],!e||e.tag!==5&&e.tag!==6&&e.tag!==13&&e.tag!==3?null:e}function xl(e){if(e.tag===5||e.tag===6)return e.stateNode;throw Error(be(33))}function hf(e){return e[Tc]||null}var Tg=[],vl=-1;function ei(e){return{current:e}}function Mt(e){0>vl||(e.current=Tg[vl],Tg[vl]=null,vl--)}function Rt(e,n){vl++,Tg[vl]=e.current,e.current=n}var Ha={},zn=ei(Ha),is=ei(!1),Ai=Ha;function Ul(e,n){var s=e.type.contextTypes;if(!s)return Ha;var r=e.stateNode;if(r&&r.__reactInternalMemoizedUnmaskedChildContext===n)return r.__reactInternalMemoizedMaskedChildContext;var a={},i;for(i in s)a[i]=n[i];return r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=n,e.__reactInternalMemoizedMaskedChildContext=a),a}function ls(e){return e=e.childContextTypes,e!=null}function ih(){Mt(is),Mt(zn)}function Yb(e,n,s){if(zn.current!==Ha)throw Error(be(168));Rt(zn,n),Rt(is,s)}function BC(e,n,s){var r=e.stateNode;if(n=n.childContextTypes,typeof r.getChildContext!="function")return s;r=r.getChildContext();for(var a in r)if(!(a in n))throw Error(be(108,JM(e)||"Unknown",a));return Ht({},s,r)}function lh(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||Ha,Ai=zn.current,Rt(zn,e),Rt(is,is.current),!0}function Jb(e,n,s){var r=e.stateNode;if(!r)throw Error(be(169));s?(e=BC(e,n,Ai),r.__reactInternalMemoizedMergedChildContext=e,Mt(is),Mt(zn),Rt(zn,e)):Mt(is),Rt(is,s)}var Xr=null,ff=!1,zm=!1;function WC(e){Xr===null?Xr=[e]:Xr.push(e)}function fD(e){ff=!0,WC(e)}function ti(){if(!zm&&Xr!==null){zm=!0;var e=0,n=wt;try{var s=Xr;for(wt=1;e<s.length;e++){var r=s[e];do r=r(!0);while(r!==null)}Xr=null,ff=!1}catch(a){throw Xr!==null&&(Xr=Xr.slice(e+1)),mC(Qv,ti),a}finally{wt=n,zm=!1}}return null}var jl=[],yl=0,oh=null,ch=0,Fs=[],_s=0,$i=null,na=1,sa="";function pi(e,n){jl[yl++]=ch,jl[yl++]=oh,oh=e,ch=n}function HC(e,n,s){Fs[_s++]=na,Fs[_s++]=sa,Fs[_s++]=$i,$i=e;var r=na;e=sa;var a=32-rr(r)-1;r&=~(1<<a),s+=1;var i=32-rr(n)+a;if(30<i){var l=a-a%5;i=(r&(1<<l)-1).toString(32),r>>=l,a-=l,na=1<<32-rr(n)+a|s<<a|r,sa=i+e}else na=1<<i|s<<a|r,sa=e}function ij(e){e.return!==null&&(pi(e,1),HC(e,1,0))}function lj(e){for(;e===oh;)oh=jl[--yl],jl[yl]=null,ch=jl[--yl],jl[yl]=null;for(;e===$i;)$i=Fs[--_s],Fs[_s]=null,sa=Fs[--_s],Fs[_s]=null,na=Fs[--_s],Fs[_s]=null}var js=null,xs=null,Ft=!1,er=null;function KC(e,n){var s=Ws(5,null,null,0);s.elementType="DELETED",s.stateNode=n,s.return=e,n=e.deletions,n===null?(e.deletions=[s],e.flags|=16):n.push(s)}function Qb(e,n){switch(e.tag){case 5:var s=e.type;return n=n.nodeType!==1||s.toLowerCase()!==n.nodeName.toLowerCase()?null:n,n!==null?(e.stateNode=n,js=e,xs=Da(n.firstChild),!0):!1;case 6:return n=e.pendingProps===""||n.nodeType!==3?null:n,n!==null?(e.stateNode=n,js=e,xs=null,!0):!1;case 13:return n=n.nodeType!==8?null:n,n!==null?(s=$i!==null?{id:na,overflow:sa}:null,e.memoizedState={dehydrated:n,treeContext:s,retryLane:1073741824},s=Ws(18,null,null,0),s.stateNode=n,s.return=e,e.child=s,js=e,xs=null,!0):!1;default:return!1}}function Rg(e){return(e.mode&1)!==0&&(e.flags&128)===0}function Ig(e){if(Ft){var n=xs;if(n){var s=n;if(!Qb(e,n)){if(Rg(e))throw Error(be(418));n=Da(s.nextSibling);var r=js;n&&Qb(e,n)?KC(r,s):(e.flags=e.flags&-4097|2,Ft=!1,js=e)}}else{if(Rg(e))throw Error(be(418));e.flags=e.flags&-4097|2,Ft=!1,js=e}}}function Xb(e){for(e=e.return;e!==null&&e.tag!==5&&e.tag!==3&&e.tag!==13;)e=e.return;js=e}function Ku(e){if(e!==js)return!1;if(!Ft)return Xb(e),Ft=!0,!1;var n;if((n=e.tag!==3)&&!(n=e.tag!==5)&&(n=e.type,n=n!=="head"&&n!=="body"&&!Eg(e.type,e.memoizedProps)),n&&(n=xs)){if(Rg(e))throw VC(),Error(be(418));for(;n;)KC(e,n),n=Da(n.nextSibling)}if(Xb(e),e.tag===13){if(e=e.memoizedState,e=e!==null?e.dehydrated:null,!e)throw Error(be(317));e:{for(e=e.nextSibling,n=0;e;){if(e.nodeType===8){var s=e.data;if(s==="/$"){if(n===0){xs=Da(e.nextSibling);break e}n--}else s!=="$"&&s!=="$!"&&s!=="$?"||n++}e=e.nextSibling}xs=null}}else xs=js?Da(e.stateNode.nextSibling):null;return!0}function VC(){for(var e=xs;e;)e=Da(e.nextSibling)}function Bl(){xs=js=null,Ft=!1}function oj(e){er===null?er=[e]:er.push(e)}var mD=ga.ReactCurrentBatchConfig;function Lo(e,n,s){if(e=s.ref,e!==null&&typeof e!="function"&&typeof e!="object"){if(s._owner){if(s=s._owner,s){if(s.tag!==1)throw Error(be(309));var r=s.stateNode}if(!r)throw Error(be(147,e));var a=r,i=""+e;return n!==null&&n.ref!==null&&typeof n.ref=="function"&&n.ref._stringRef===i?n.ref:(n=function(l){var o=a.refs;l===null?delete o[i]:o[i]=l},n._stringRef=i,n)}if(typeof e!="string")throw Error(be(284));if(!s._owner)throw Error(be(290,e))}return e}function Vu(e,n){throw e=Object.prototype.toString.call(n),Error(be(31,e==="[object Object]"?"object with keys {"+Object.keys(n).join(", ")+"}":e))}function Zb(e){var n=e._init;return n(e._payload)}function GC(e){function n(j,x){if(e){var y=j.deletions;y===null?(j.deletions=[x],j.flags|=16):y.push(x)}}function s(j,x){if(!e)return null;for(;x!==null;)n(j,x),x=x.sibling;return null}function r(j,x){for(j=new Map;x!==null;)x.key!==null?j.set(x.key,x):j.set(x.index,x),x=x.sibling;return j}function a(j,x){return j=_a(j,x),j.index=0,j.sibling=null,j}function i(j,x,y){return j.index=y,e?(y=j.alternate,y!==null?(y=y.index,y<x?(j.flags|=2,x):y):(j.flags|=2,x)):(j.flags|=1048576,x)}function l(j){return e&&j.alternate===null&&(j.flags|=2),j}function o(j,x,y,w){return x===null||x.tag!==6?(x=Gm(y,j.mode,w),x.return=j,x):(x=a(x,y),x.return=j,x)}function c(j,x,y,w){var k=y.type;return k===fl?d(j,x,y.props.children,w,y.key):x!==null&&(x.elementType===k||typeof k=="object"&&k!==null&&k.$$typeof===Na&&Zb(k)===x.type)?(w=a(x,y.props),w.ref=Lo(j,x,y),w.return=j,w):(w=Dd(y.type,y.key,y.props,null,j.mode,w),w.ref=Lo(j,x,y),w.return=j,w)}function u(j,x,y,w){return x===null||x.tag!==4||x.stateNode.containerInfo!==y.containerInfo||x.stateNode.implementation!==y.implementation?(x=qm(y,j.mode,w),x.return=j,x):(x=a(x,y.children||[]),x.return=j,x)}function d(j,x,y,w,k){return x===null||x.tag!==7?(x=Si(y,j.mode,w,k),x.return=j,x):(x=a(x,y),x.return=j,x)}function f(j,x,y){if(typeof x=="string"&&x!==""||typeof x=="number")return x=Gm(""+x,j.mode,y),x.return=j,x;if(typeof x=="object"&&x!==null){switch(x.$$typeof){case Du:return y=Dd(x.type,x.key,x.props,null,j.mode,y),y.ref=Lo(j,null,x),y.return=j,y;case hl:return x=qm(x,j.mode,y),x.return=j,x;case Na:var w=x._init;return f(j,w(x._payload),y)}if(qo(x)||Io(x))return x=Si(x,j.mode,y,null),x.return=j,x;Vu(j,x)}return null}function m(j,x,y,w){var k=x!==null?x.key:null;if(typeof y=="string"&&y!==""||typeof y=="number")return k!==null?null:o(j,x,""+y,w);if(typeof y=="object"&&y!==null){switch(y.$$typeof){case Du:return y.key===k?c(j,x,y,w):null;case hl:return y.key===k?u(j,x,y,w):null;case Na:return k=y._init,m(j,x,k(y._payload),w)}if(qo(y)||Io(y))return k!==null?null:d(j,x,y,w,null);Vu(j,y)}return null}function p(j,x,y,w,k){if(typeof w=="string"&&w!==""||typeof w=="number")return j=j.get(y)||null,o(x,j,""+w,k);if(typeof w=="object"&&w!==null){switch(w.$$typeof){case Du:return j=j.get(w.key===null?y:w.key)||null,c(x,j,w,k);case hl:return j=j.get(w.key===null?y:w.key)||null,u(x,j,w,k);case Na:var N=w._init;return p(j,x,y,N(w._payload),k)}if(qo(w)||Io(w))return j=j.get(y)||null,d(x,j,w,k,null);Vu(x,w)}return null}function g(j,x,y,w){for(var k=null,N=null,S=x,C=x=0,E=null;S!==null&&C<y.length;C++){S.index>C?(E=S,S=null):E=S.sibling;var T=m(j,S,y[C],w);if(T===null){S===null&&(S=E);break}e&&S&&T.alternate===null&&n(j,S),x=i(T,x,C),N===null?k=T:N.sibling=T,N=T,S=E}if(C===y.length)return s(j,S),Ft&&pi(j,C),k;if(S===null){for(;C<y.length;C++)S=f(j,y[C],w),S!==null&&(x=i(S,x,C),N===null?k=S:N.sibling=S,N=S);return Ft&&pi(j,C),k}for(S=r(j,S);C<y.length;C++)E=p(S,j,C,y[C],w),E!==null&&(e&&E.alternate!==null&&S.delete(E.key===null?C:E.key),x=i(E,x,C),N===null?k=E:N.sibling=E,N=E);return e&&S.forEach(function(I){return n(j,I)}),Ft&&pi(j,C),k}function v(j,x,y,w){var k=Io(y);if(typeof k!="function")throw Error(be(150));if(y=k.call(y),y==null)throw Error(be(151));for(var N=k=null,S=x,C=x=0,E=null,T=y.next();S!==null&&!T.done;C++,T=y.next()){S.index>C?(E=S,S=null):E=S.sibling;var I=m(j,S,T.value,w);if(I===null){S===null&&(S=E);break}e&&S&&I.alternate===null&&n(j,S),x=i(I,x,C),N===null?k=I:N.sibling=I,N=I,S=E}if(T.done)return s(j,S),Ft&&pi(j,C),k;if(S===null){for(;!T.done;C++,T=y.next())T=f(j,T.value,w),T!==null&&(x=i(T,x,C),N===null?k=T:N.sibling=T,N=T);return Ft&&pi(j,C),k}for(S=r(j,S);!T.done;C++,T=y.next())T=p(S,j,C,T.value,w),T!==null&&(e&&T.alternate!==null&&S.delete(T.key===null?C:T.key),x=i(T,x,C),N===null?k=T:N.sibling=T,N=T);return e&&S.forEach(function(F){return n(j,F)}),Ft&&pi(j,C),k}function b(j,x,y,w){if(typeof y=="object"&&y!==null&&y.type===fl&&y.key===null&&(y=y.props.children),typeof y=="object"&&y!==null){switch(y.$$typeof){case Du:e:{for(var k=y.key,N=x;N!==null;){if(N.key===k){if(k=y.type,k===fl){if(N.tag===7){s(j,N.sibling),x=a(N,y.props.children),x.return=j,j=x;break e}}else if(N.elementType===k||typeof k=="object"&&k!==null&&k.$$typeof===Na&&Zb(k)===N.type){s(j,N.sibling),x=a(N,y.props),x.ref=Lo(j,N,y),x.return=j,j=x;break e}s(j,N);break}else n(j,N);N=N.sibling}y.type===fl?(x=Si(y.props.children,j.mode,w,y.key),x.return=j,j=x):(w=Dd(y.type,y.key,y.props,null,j.mode,w),w.ref=Lo(j,x,y),w.return=j,j=w)}return l(j);case hl:e:{for(N=y.key;x!==null;){if(x.key===N)if(x.tag===4&&x.stateNode.containerInfo===y.containerInfo&&x.stateNode.implementation===y.implementation){s(j,x.sibling),x=a(x,y.children||[]),x.return=j,j=x;break e}else{s(j,x);break}else n(j,x);x=x.sibling}x=qm(y,j.mode,w),x.return=j,j=x}return l(j);case Na:return N=y._init,b(j,x,N(y._payload),w)}if(qo(y))return g(j,x,y,w);if(Io(y))return v(j,x,y,w);Vu(j,y)}return typeof y=="string"&&y!==""||typeof y=="number"?(y=""+y,x!==null&&x.tag===6?(s(j,x.sibling),x=a(x,y),x.return=j,j=x):(s(j,x),x=Gm(y,j.mode,w),x.return=j,j=x),l(j)):s(j,x)}return b}var Wl=GC(!0),qC=GC(!1),uh=ei(null),dh=null,wl=null,cj=null;function uj(){cj=wl=dh=null}function dj(e){var n=uh.current;Mt(uh),e._currentValue=n}function Pg(e,n,s){for(;e!==null;){var r=e.alternate;if((e.childLanes&n)!==n?(e.childLanes|=n,r!==null&&(r.childLanes|=n)):r!==null&&(r.childLanes&n)!==n&&(r.childLanes|=n),e===s)break;e=e.return}}function Il(e,n){dh=e,cj=wl=null,e=e.dependencies,e!==null&&e.firstContext!==null&&(e.lanes&n&&(rs=!0),e.firstContext=null)}function Vs(e){var n=e._currentValue;if(cj!==e)if(e={context:e,memoizedValue:n,next:null},wl===null){if(dh===null)throw Error(be(308));wl=e,dh.dependencies={lanes:0,firstContext:e}}else wl=wl.next=e;return n}var yi=null;function hj(e){yi===null?yi=[e]:yi.push(e)}function YC(e,n,s,r){var a=n.interleaved;return a===null?(s.next=s,hj(n)):(s.next=a.next,a.next=s),n.interleaved=s,da(e,r)}function da(e,n){e.lanes|=n;var s=e.alternate;for(s!==null&&(s.lanes|=n),s=e,e=e.return;e!==null;)e.childLanes|=n,s=e.alternate,s!==null&&(s.childLanes|=n),s=e,e=e.return;return s.tag===3?s.stateNode:null}var Sa=!1;function fj(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function JC(e,n){e=e.updateQueue,n.updateQueue===e&&(n.updateQueue={baseState:e.baseState,firstBaseUpdate:e.firstBaseUpdate,lastBaseUpdate:e.lastBaseUpdate,shared:e.shared,effects:e.effects})}function aa(e,n){return{eventTime:e,lane:n,tag:0,payload:null,callback:null,next:null}}function Oa(e,n,s){var r=e.updateQueue;if(r===null)return null;if(r=r.shared,pt&2){var a=r.pending;return a===null?n.next=n:(n.next=a.next,a.next=n),r.pending=n,da(e,s)}return a=r.interleaved,a===null?(n.next=n,hj(r)):(n.next=a.next,a.next=n),r.interleaved=n,da(e,s)}function $d(e,n,s){if(n=n.updateQueue,n!==null&&(n=n.shared,(s&4194240)!==0)){var r=n.lanes;r&=e.pendingLanes,s|=r,n.lanes=s,Xv(e,s)}}function ek(e,n){var s=e.updateQueue,r=e.alternate;if(r!==null&&(r=r.updateQueue,s===r)){var a=null,i=null;if(s=s.firstBaseUpdate,s!==null){do{var l={eventTime:s.eventTime,lane:s.lane,tag:s.tag,payload:s.payload,callback:s.callback,next:null};i===null?a=i=l:i=i.next=l,s=s.next}while(s!==null);i===null?a=i=n:i=i.next=n}else a=i=n;s={baseState:r.baseState,firstBaseUpdate:a,lastBaseUpdate:i,shared:r.shared,effects:r.effects},e.updateQueue=s;return}e=s.lastBaseUpdate,e===null?s.firstBaseUpdate=n:e.next=n,s.lastBaseUpdate=n}function hh(e,n,s,r){var a=e.updateQueue;Sa=!1;var i=a.firstBaseUpdate,l=a.lastBaseUpdate,o=a.shared.pending;if(o!==null){a.shared.pending=null;var c=o,u=c.next;c.next=null,l===null?i=u:l.next=u,l=c;var d=e.alternate;d!==null&&(d=d.updateQueue,o=d.lastBaseUpdate,o!==l&&(o===null?d.firstBaseUpdate=u:o.next=u,d.lastBaseUpdate=c))}if(i!==null){var f=a.baseState;l=0,d=u=c=null,o=i;do{var m=o.lane,p=o.eventTime;if((r&m)===m){d!==null&&(d=d.next={eventTime:p,lane:0,tag:o.tag,payload:o.payload,callback:o.callback,next:null});e:{var g=e,v=o;switch(m=n,p=s,v.tag){case 1:if(g=v.payload,typeof g=="function"){f=g.call(p,f,m);break e}f=g;break e;case 3:g.flags=g.flags&-65537|128;case 0:if(g=v.payload,m=typeof g=="function"?g.call(p,f,m):g,m==null)break e;f=Ht({},f,m);break e;case 2:Sa=!0}}o.callback!==null&&o.lane!==0&&(e.flags|=64,m=a.effects,m===null?a.effects=[o]:m.push(o))}else p={eventTime:p,lane:m,tag:o.tag,payload:o.payload,callback:o.callback,next:null},d===null?(u=d=p,c=f):d=d.next=p,l|=m;if(o=o.next,o===null){if(o=a.shared.pending,o===null)break;m=o,o=m.next,m.next=null,a.lastBaseUpdate=m,a.shared.pending=null}}while(!0);if(d===null&&(c=f),a.baseState=c,a.firstBaseUpdate=u,a.lastBaseUpdate=d,n=a.shared.interleaved,n!==null){a=n;do l|=a.lane,a=a.next;while(a!==n)}else i===null&&(a.shared.lanes=0);Ri|=l,e.lanes=l,e.memoizedState=f}}function tk(e,n,s){if(e=n.effects,n.effects=null,e!==null)for(n=0;n<e.length;n++){var r=e[n],a=r.callback;if(a!==null){if(r.callback=null,r=s,typeof a!="function")throw Error(be(191,a));a.call(r)}}}var du={},$r=ei(du),Rc=ei(du),Ic=ei(du);function wi(e){if(e===du)throw Error(be(174));return e}function mj(e,n){switch(Rt(Ic,n),Rt(Rc,e),Rt($r,du),e=n.nodeType,e){case 9:case 11:n=(n=n.documentElement)?n.namespaceURI:fg(null,"");break;default:e=e===8?n.parentNode:n,n=e.namespaceURI||null,e=e.tagName,n=fg(n,e)}Mt($r),Rt($r,n)}function Hl(){Mt($r),Mt(Rc),Mt(Ic)}function QC(e){wi(Ic.current);var n=wi($r.current),s=fg(n,e.type);n!==s&&(Rt(Rc,e),Rt($r,s))}function pj(e){Rc.current===e&&(Mt($r),Mt(Rc))}var Bt=ei(0);function fh(e){for(var n=e;n!==null;){if(n.tag===13){var s=n.memoizedState;if(s!==null&&(s=s.dehydrated,s===null||s.data==="$?"||s.data==="$!"))return n}else if(n.tag===19&&n.memoizedProps.revealOrder!==void 0){if(n.flags&128)return n}else if(n.child!==null){n.child.return=n,n=n.child;continue}if(n===e)break;for(;n.sibling===null;){if(n.return===null||n.return===e)return null;n=n.return}n.sibling.return=n.return,n=n.sibling}return null}var Um=[];function gj(){for(var e=0;e<Um.length;e++)Um[e]._workInProgressVersionPrimary=null;Um.length=0}var Td=ga.ReactCurrentDispatcher,Bm=ga.ReactCurrentBatchConfig,Ti=0,Wt=null,cn=null,vn=null,mh=!1,lc=!1,Pc=0,pD=0;function Dn(){throw Error(be(321))}function xj(e,n){if(n===null)return!1;for(var s=0;s<n.length&&s<e.length;s++)if(!or(e[s],n[s]))return!1;return!0}function vj(e,n,s,r,a,i){if(Ti=i,Wt=n,n.memoizedState=null,n.updateQueue=null,n.lanes=0,Td.current=e===null||e.memoizedState===null?jD:yD,e=s(r,a),lc){i=0;do{if(lc=!1,Pc=0,25<=i)throw Error(be(301));i+=1,vn=cn=null,n.updateQueue=null,Td.current=wD,e=s(r,a)}while(lc)}if(Td.current=ph,n=cn!==null&&cn.next!==null,Ti=0,vn=cn=Wt=null,mh=!1,n)throw Error(be(300));return e}function jj(){var e=Pc!==0;return Pc=0,e}function br(){var e={memoizedState:null,baseState:null,baseQueue:null,queue:null,next:null};return vn===null?Wt.memoizedState=vn=e:vn=vn.next=e,vn}function Gs(){if(cn===null){var e=Wt.alternate;e=e!==null?e.memoizedState:null}else e=cn.next;var n=vn===null?Wt.memoizedState:vn.next;if(n!==null)vn=n,cn=e;else{if(e===null)throw Error(be(310));cn=e,e={memoizedState:cn.memoizedState,baseState:cn.baseState,baseQueue:cn.baseQueue,queue:cn.queue,next:null},vn===null?Wt.memoizedState=vn=e:vn=vn.next=e}return vn}function Mc(e,n){return typeof n=="function"?n(e):n}function Wm(e){var n=Gs(),s=n.queue;if(s===null)throw Error(be(311));s.lastRenderedReducer=e;var r=cn,a=r.baseQueue,i=s.pending;if(i!==null){if(a!==null){var l=a.next;a.next=i.next,i.next=l}r.baseQueue=a=i,s.pending=null}if(a!==null){i=a.next,r=r.baseState;var o=l=null,c=null,u=i;do{var d=u.lane;if((Ti&d)===d)c!==null&&(c=c.next={lane:0,action:u.action,hasEagerState:u.hasEagerState,eagerState:u.eagerState,next:null}),r=u.hasEagerState?u.eagerState:e(r,u.action);else{var f={lane:d,action:u.action,hasEagerState:u.hasEagerState,eagerState:u.eagerState,next:null};c===null?(o=c=f,l=r):c=c.next=f,Wt.lanes|=d,Ri|=d}u=u.next}while(u!==null&&u!==i);c===null?l=r:c.next=o,or(r,n.memoizedState)||(rs=!0),n.memoizedState=r,n.baseState=l,n.baseQueue=c,s.lastRenderedState=r}if(e=s.interleaved,e!==null){a=e;do i=a.lane,Wt.lanes|=i,Ri|=i,a=a.next;while(a!==e)}else a===null&&(s.lanes=0);return[n.memoizedState,s.dispatch]}function Hm(e){var n=Gs(),s=n.queue;if(s===null)throw Error(be(311));s.lastRenderedReducer=e;var r=s.dispatch,a=s.pending,i=n.memoizedState;if(a!==null){s.pending=null;var l=a=a.next;do i=e(i,l.action),l=l.next;while(l!==a);or(i,n.memoizedState)||(rs=!0),n.memoizedState=i,n.baseQueue===null&&(n.baseState=i),s.lastRenderedState=i}return[i,r]}function XC(){}function ZC(e,n){var s=Wt,r=Gs(),a=n(),i=!or(r.memoizedState,a);if(i&&(r.memoizedState=a,rs=!0),r=r.queue,yj(n1.bind(null,s,r,e),[e]),r.getSnapshot!==n||i||vn!==null&&vn.memoizedState.tag&1){if(s.flags|=2048,Dc(9,t1.bind(null,s,r,a,n),void 0,null),bn===null)throw Error(be(349));Ti&30||e1(s,n,a)}return a}function e1(e,n,s){e.flags|=16384,e={getSnapshot:n,value:s},n=Wt.updateQueue,n===null?(n={lastEffect:null,stores:null},Wt.updateQueue=n,n.stores=[e]):(s=n.stores,s===null?n.stores=[e]:s.push(e))}function t1(e,n,s,r){n.value=s,n.getSnapshot=r,s1(n)&&r1(e)}function n1(e,n,s){return s(function(){s1(n)&&r1(e)})}function s1(e){var n=e.getSnapshot;e=e.value;try{var s=n();return!or(e,s)}catch{return!0}}function r1(e){var n=da(e,1);n!==null&&ar(n,e,1,-1)}function nk(e){var n=br();return typeof e=="function"&&(e=e()),n.memoizedState=n.baseState=e,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:Mc,lastRenderedState:e},n.queue=e,e=e.dispatch=vD.bind(null,Wt,e),[n.memoizedState,e]}function Dc(e,n,s,r){return e={tag:e,create:n,destroy:s,deps:r,next:null},n=Wt.updateQueue,n===null?(n={lastEffect:null,stores:null},Wt.updateQueue=n,n.lastEffect=e.next=e):(s=n.lastEffect,s===null?n.lastEffect=e.next=e:(r=s.next,s.next=e,e.next=r,n.lastEffect=e)),e}function a1(){return Gs().memoizedState}function Rd(e,n,s,r){var a=br();Wt.flags|=e,a.memoizedState=Dc(1|n,s,void 0,r===void 0?null:r)}function mf(e,n,s,r){var a=Gs();r=r===void 0?null:r;var i=void 0;if(cn!==null){var l=cn.memoizedState;if(i=l.destroy,r!==null&&xj(r,l.deps)){a.memoizedState=Dc(n,s,i,r);return}}Wt.flags|=e,a.memoizedState=Dc(1|n,s,i,r)}function sk(e,n){return Rd(8390656,8,e,n)}function yj(e,n){return mf(2048,8,e,n)}function i1(e,n){return mf(4,2,e,n)}function l1(e,n){return mf(4,4,e,n)}function o1(e,n){if(typeof n=="function")return e=e(),n(e),function(){n(null)};if(n!=null)return e=e(),n.current=e,function(){n.current=null}}function c1(e,n,s){return s=s!=null?s.concat([e]):null,mf(4,4,o1.bind(null,n,e),s)}function wj(){}function u1(e,n){var s=Gs();n=n===void 0?null:n;var r=s.memoizedState;return r!==null&&n!==null&&xj(n,r[1])?r[0]:(s.memoizedState=[e,n],e)}function d1(e,n){var s=Gs();n=n===void 0?null:n;var r=s.memoizedState;return r!==null&&n!==null&&xj(n,r[1])?r[0]:(e=e(),s.memoizedState=[e,n],e)}function h1(e,n,s){return Ti&21?(or(s,n)||(s=xC(),Wt.lanes|=s,Ri|=s,e.baseState=!0),n):(e.baseState&&(e.baseState=!1,rs=!0),e.memoizedState=s)}function gD(e,n){var s=wt;wt=s!==0&&4>s?s:4,e(!0);var r=Bm.transition;Bm.transition={};try{e(!1),n()}finally{wt=s,Bm.transition=r}}function f1(){return Gs().memoizedState}function xD(e,n,s){var r=Fa(e);if(s={lane:r,action:s,hasEagerState:!1,eagerState:null,next:null},m1(e))p1(n,s);else if(s=YC(e,n,s,r),s!==null){var a=qn();ar(s,e,r,a),g1(s,n,r)}}function vD(e,n,s){var r=Fa(e),a={lane:r,action:s,hasEagerState:!1,eagerState:null,next:null};if(m1(e))p1(n,a);else{var i=e.alternate;if(e.lanes===0&&(i===null||i.lanes===0)&&(i=n.lastRenderedReducer,i!==null))try{var l=n.lastRenderedState,o=i(l,s);if(a.hasEagerState=!0,a.eagerState=o,or(o,l)){var c=n.interleaved;c===null?(a.next=a,hj(n)):(a.next=c.next,c.next=a),n.interleaved=a;return}}catch{}finally{}s=YC(e,n,a,r),s!==null&&(a=qn(),ar(s,e,r,a),g1(s,n,r))}}function m1(e){var n=e.alternate;return e===Wt||n!==null&&n===Wt}function p1(e,n){lc=mh=!0;var s=e.pending;s===null?n.next=n:(n.next=s.next,s.next=n),e.pending=n}function g1(e,n,s){if(s&4194240){var r=n.lanes;r&=e.pendingLanes,s|=r,n.lanes=s,Xv(e,s)}}var ph={readContext:Vs,useCallback:Dn,useContext:Dn,useEffect:Dn,useImperativeHandle:Dn,useInsertionEffect:Dn,useLayoutEffect:Dn,useMemo:Dn,useReducer:Dn,useRef:Dn,useState:Dn,useDebugValue:Dn,useDeferredValue:Dn,useTransition:Dn,useMutableSource:Dn,useSyncExternalStore:Dn,useId:Dn,unstable_isNewReconciler:!1},jD={readContext:Vs,useCallback:function(e,n){return br().memoizedState=[e,n===void 0?null:n],e},useContext:Vs,useEffect:sk,useImperativeHandle:function(e,n,s){return s=s!=null?s.concat([e]):null,Rd(4194308,4,o1.bind(null,n,e),s)},useLayoutEffect:function(e,n){return Rd(4194308,4,e,n)},useInsertionEffect:function(e,n){return Rd(4,2,e,n)},useMemo:function(e,n){var s=br();return n=n===void 0?null:n,e=e(),s.memoizedState=[e,n],e},useReducer:function(e,n,s){var r=br();return n=s!==void 0?s(n):n,r.memoizedState=r.baseState=n,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:e,lastRenderedState:n},r.queue=e,e=e.dispatch=xD.bind(null,Wt,e),[r.memoizedState,e]},useRef:function(e){var n=br();return e={current:e},n.memoizedState=e},useState:nk,useDebugValue:wj,useDeferredValue:function(e){return br().memoizedState=e},useTransition:function(){var e=nk(!1),n=e[0];return e=gD.bind(null,e[1]),br().memoizedState=e,[n,e]},useMutableSource:function(){},useSyncExternalStore:function(e,n,s){var r=Wt,a=br();if(Ft){if(s===void 0)throw Error(be(407));s=s()}else{if(s=n(),bn===null)throw Error(be(349));Ti&30||e1(r,n,s)}a.memoizedState=s;var i={value:s,getSnapshot:n};return a.queue=i,sk(n1.bind(null,r,i,e),[e]),r.flags|=2048,Dc(9,t1.bind(null,r,i,s,n),void 0,null),s},useId:function(){var e=br(),n=bn.identifierPrefix;if(Ft){var s=sa,r=na;s=(r&~(1<<32-rr(r)-1)).toString(32)+s,n=":"+n+"R"+s,s=Pc++,0<s&&(n+="H"+s.toString(32)),n+=":"}else s=pD++,n=":"+n+"r"+s.toString(32)+":";return e.memoizedState=n},unstable_isNewReconciler:!1},yD={readContext:Vs,useCallback:u1,useContext:Vs,useEffect:yj,useImperativeHandle:c1,useInsertionEffect:i1,useLayoutEffect:l1,useMemo:d1,useReducer:Wm,useRef:a1,useState:function(){return Wm(Mc)},useDebugValue:wj,useDeferredValue:function(e){var n=Gs();return h1(n,cn.memoizedState,e)},useTransition:function(){var e=Wm(Mc)[0],n=Gs().memoizedState;return[e,n]},useMutableSource:XC,useSyncExternalStore:ZC,useId:f1,unstable_isNewReconciler:!1},wD={readContext:Vs,useCallback:u1,useContext:Vs,useEffect:yj,useImperativeHandle:c1,useInsertionEffect:i1,useLayoutEffect:l1,useMemo:d1,useReducer:Hm,useRef:a1,useState:function(){return Hm(Mc)},useDebugValue:wj,useDeferredValue:function(e){var n=Gs();return cn===null?n.memoizedState=e:h1(n,cn.memoizedState,e)},useTransition:function(){var e=Hm(Mc)[0],n=Gs().memoizedState;return[e,n]},useMutableSource:XC,useSyncExternalStore:ZC,useId:f1,unstable_isNewReconciler:!1};function Xs(e,n){if(e&&e.defaultProps){n=Ht({},n),e=e.defaultProps;for(var s in e)n[s]===void 0&&(n[s]=e[s]);return n}return n}function Mg(e,n,s,r){n=e.memoizedState,s=s(r,n),s=s==null?n:Ht({},n,s),e.memoizedState=s,e.lanes===0&&(e.updateQueue.baseState=s)}var pf={isMounted:function(e){return(e=e._reactInternals)?Ui(e)===e:!1},enqueueSetState:function(e,n,s){e=e._reactInternals;var r=qn(),a=Fa(e),i=aa(r,a);i.payload=n,s!=null&&(i.callback=s),n=Oa(e,i,a),n!==null&&(ar(n,e,a,r),$d(n,e,a))},enqueueReplaceState:function(e,n,s){e=e._reactInternals;var r=qn(),a=Fa(e),i=aa(r,a);i.tag=1,i.payload=n,s!=null&&(i.callback=s),n=Oa(e,i,a),n!==null&&(ar(n,e,a,r),$d(n,e,a))},enqueueForceUpdate:function(e,n){e=e._reactInternals;var s=qn(),r=Fa(e),a=aa(s,r);a.tag=2,n!=null&&(a.callback=n),n=Oa(e,a,r),n!==null&&(ar(n,e,r,s),$d(n,e,r))}};function rk(e,n,s,r,a,i,l){return e=e.stateNode,typeof e.shouldComponentUpdate=="function"?e.shouldComponentUpdate(r,i,l):n.prototype&&n.prototype.isPureReactComponent?!Ec(s,r)||!Ec(a,i):!0}function x1(e,n,s){var r=!1,a=Ha,i=n.contextType;return typeof i=="object"&&i!==null?i=Vs(i):(a=ls(n)?Ai:zn.current,r=n.contextTypes,i=(r=r!=null)?Ul(e,a):Ha),n=new n(s,i),e.memoizedState=n.state!==null&&n.state!==void 0?n.state:null,n.updater=pf,e.stateNode=n,n._reactInternals=e,r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=a,e.__reactInternalMemoizedMaskedChildContext=i),n}function ak(e,n,s,r){e=n.state,typeof n.componentWillReceiveProps=="function"&&n.componentWillReceiveProps(s,r),typeof n.UNSAFE_componentWillReceiveProps=="function"&&n.UNSAFE_componentWillReceiveProps(s,r),n.state!==e&&pf.enqueueReplaceState(n,n.state,null)}function Dg(e,n,s,r){var a=e.stateNode;a.props=s,a.state=e.memoizedState,a.refs={},fj(e);var i=n.contextType;typeof i=="object"&&i!==null?a.context=Vs(i):(i=ls(n)?Ai:zn.current,a.context=Ul(e,i)),a.state=e.memoizedState,i=n.getDerivedStateFromProps,typeof i=="function"&&(Mg(e,n,i,s),a.state=e.memoizedState),typeof n.getDerivedStateFromProps=="function"||typeof a.getSnapshotBeforeUpdate=="function"||typeof a.UNSAFE_componentWillMount!="function"&&typeof a.componentWillMount!="function"||(n=a.state,typeof a.componentWillMount=="function"&&a.componentWillMount(),typeof a.UNSAFE_componentWillMount=="function"&&a.UNSAFE_componentWillMount(),n!==a.state&&pf.enqueueReplaceState(a,a.state,null),hh(e,s,a,r),a.state=e.memoizedState),typeof a.componentDidMount=="function"&&(e.flags|=4194308)}function Kl(e,n){try{var s="",r=n;do s+=YM(r),r=r.return;while(r);var a=s}catch(i){a=`
39
- Error generating stack: `+i.message+`
40
- `+i.stack}return{value:e,source:n,stack:a,digest:null}}function Km(e,n,s){return{value:e,source:null,stack:s??null,digest:n??null}}function Og(e,n){try{console.error(n.value)}catch(s){setTimeout(function(){throw s})}}var bD=typeof WeakMap=="function"?WeakMap:Map;function v1(e,n,s){s=aa(-1,s),s.tag=3,s.payload={element:null};var r=n.value;return s.callback=function(){xh||(xh=!0,Vg=r),Og(e,n)},s}function j1(e,n,s){s=aa(-1,s),s.tag=3;var r=e.type.getDerivedStateFromError;if(typeof r=="function"){var a=n.value;s.payload=function(){return r(a)},s.callback=function(){Og(e,n)}}var i=e.stateNode;return i!==null&&typeof i.componentDidCatch=="function"&&(s.callback=function(){Og(e,n),typeof r!="function"&&(La===null?La=new Set([this]):La.add(this));var l=n.stack;this.componentDidCatch(n.value,{componentStack:l!==null?l:""})}),s}function ik(e,n,s){var r=e.pingCache;if(r===null){r=e.pingCache=new bD;var a=new Set;r.set(n,a)}else a=r.get(n),a===void 0&&(a=new Set,r.set(n,a));a.has(s)||(a.add(s),e=OD.bind(null,e,n,s),n.then(e,e))}function lk(e){do{var n;if((n=e.tag===13)&&(n=e.memoizedState,n=n!==null?n.dehydrated!==null:!0),n)return e;e=e.return}while(e!==null);return null}function ok(e,n,s,r,a){return e.mode&1?(e.flags|=65536,e.lanes=a,e):(e===n?e.flags|=65536:(e.flags|=128,s.flags|=131072,s.flags&=-52805,s.tag===1&&(s.alternate===null?s.tag=17:(n=aa(-1,1),n.tag=2,Oa(s,n,1))),s.lanes|=1),e)}var kD=ga.ReactCurrentOwner,rs=!1;function Kn(e,n,s,r){n.child=e===null?qC(n,null,s,r):Wl(n,e.child,s,r)}function ck(e,n,s,r,a){s=s.render;var i=n.ref;return Il(n,a),r=vj(e,n,s,r,i,a),s=jj(),e!==null&&!rs?(n.updateQueue=e.updateQueue,n.flags&=-2053,e.lanes&=~a,ha(e,n,a)):(Ft&&s&&ij(n),n.flags|=1,Kn(e,n,r,a),n.child)}function uk(e,n,s,r,a){if(e===null){var i=s.type;return typeof i=="function"&&!$j(i)&&i.defaultProps===void 0&&s.compare===null&&s.defaultProps===void 0?(n.tag=15,n.type=i,y1(e,n,i,r,a)):(e=Dd(s.type,null,r,n,n.mode,a),e.ref=n.ref,e.return=n,n.child=e)}if(i=e.child,!(e.lanes&a)){var l=i.memoizedProps;if(s=s.compare,s=s!==null?s:Ec,s(l,r)&&e.ref===n.ref)return ha(e,n,a)}return n.flags|=1,e=_a(i,r),e.ref=n.ref,e.return=n,n.child=e}function y1(e,n,s,r,a){if(e!==null){var i=e.memoizedProps;if(Ec(i,r)&&e.ref===n.ref)if(rs=!1,n.pendingProps=r=i,(e.lanes&a)!==0)e.flags&131072&&(rs=!0);else return n.lanes=e.lanes,ha(e,n,a)}return Lg(e,n,s,r,a)}function w1(e,n,s){var r=n.pendingProps,a=r.children,i=e!==null?e.memoizedState:null;if(r.mode==="hidden")if(!(n.mode&1))n.memoizedState={baseLanes:0,cachePool:null,transitions:null},Rt(kl,ps),ps|=s;else{if(!(s&1073741824))return e=i!==null?i.baseLanes|s:s,n.lanes=n.childLanes=1073741824,n.memoizedState={baseLanes:e,cachePool:null,transitions:null},n.updateQueue=null,Rt(kl,ps),ps|=e,null;n.memoizedState={baseLanes:0,cachePool:null,transitions:null},r=i!==null?i.baseLanes:s,Rt(kl,ps),ps|=r}else i!==null?(r=i.baseLanes|s,n.memoizedState=null):r=s,Rt(kl,ps),ps|=r;return Kn(e,n,a,s),n.child}function b1(e,n){var s=n.ref;(e===null&&s!==null||e!==null&&e.ref!==s)&&(n.flags|=512,n.flags|=2097152)}function Lg(e,n,s,r,a){var i=ls(s)?Ai:zn.current;return i=Ul(n,i),Il(n,a),s=vj(e,n,s,r,i,a),r=jj(),e!==null&&!rs?(n.updateQueue=e.updateQueue,n.flags&=-2053,e.lanes&=~a,ha(e,n,a)):(Ft&&r&&ij(n),n.flags|=1,Kn(e,n,s,a),n.child)}function dk(e,n,s,r,a){if(ls(s)){var i=!0;lh(n)}else i=!1;if(Il(n,a),n.stateNode===null)Id(e,n),x1(n,s,r),Dg(n,s,r,a),r=!0;else if(e===null){var l=n.stateNode,o=n.memoizedProps;l.props=o;var c=l.context,u=s.contextType;typeof u=="object"&&u!==null?u=Vs(u):(u=ls(s)?Ai:zn.current,u=Ul(n,u));var d=s.getDerivedStateFromProps,f=typeof d=="function"||typeof l.getSnapshotBeforeUpdate=="function";f||typeof l.UNSAFE_componentWillReceiveProps!="function"&&typeof l.componentWillReceiveProps!="function"||(o!==r||c!==u)&&ak(n,l,r,u),Sa=!1;var m=n.memoizedState;l.state=m,hh(n,r,l,a),c=n.memoizedState,o!==r||m!==c||is.current||Sa?(typeof d=="function"&&(Mg(n,s,d,r),c=n.memoizedState),(o=Sa||rk(n,s,o,r,m,c,u))?(f||typeof l.UNSAFE_componentWillMount!="function"&&typeof l.componentWillMount!="function"||(typeof l.componentWillMount=="function"&&l.componentWillMount(),typeof l.UNSAFE_componentWillMount=="function"&&l.UNSAFE_componentWillMount()),typeof l.componentDidMount=="function"&&(n.flags|=4194308)):(typeof l.componentDidMount=="function"&&(n.flags|=4194308),n.memoizedProps=r,n.memoizedState=c),l.props=r,l.state=c,l.context=u,r=o):(typeof l.componentDidMount=="function"&&(n.flags|=4194308),r=!1)}else{l=n.stateNode,JC(e,n),o=n.memoizedProps,u=n.type===n.elementType?o:Xs(n.type,o),l.props=u,f=n.pendingProps,m=l.context,c=s.contextType,typeof c=="object"&&c!==null?c=Vs(c):(c=ls(s)?Ai:zn.current,c=Ul(n,c));var p=s.getDerivedStateFromProps;(d=typeof p=="function"||typeof l.getSnapshotBeforeUpdate=="function")||typeof l.UNSAFE_componentWillReceiveProps!="function"&&typeof l.componentWillReceiveProps!="function"||(o!==f||m!==c)&&ak(n,l,r,c),Sa=!1,m=n.memoizedState,l.state=m,hh(n,r,l,a);var g=n.memoizedState;o!==f||m!==g||is.current||Sa?(typeof p=="function"&&(Mg(n,s,p,r),g=n.memoizedState),(u=Sa||rk(n,s,u,r,m,g,c)||!1)?(d||typeof l.UNSAFE_componentWillUpdate!="function"&&typeof l.componentWillUpdate!="function"||(typeof l.componentWillUpdate=="function"&&l.componentWillUpdate(r,g,c),typeof l.UNSAFE_componentWillUpdate=="function"&&l.UNSAFE_componentWillUpdate(r,g,c)),typeof l.componentDidUpdate=="function"&&(n.flags|=4),typeof l.getSnapshotBeforeUpdate=="function"&&(n.flags|=1024)):(typeof l.componentDidUpdate!="function"||o===e.memoizedProps&&m===e.memoizedState||(n.flags|=4),typeof l.getSnapshotBeforeUpdate!="function"||o===e.memoizedProps&&m===e.memoizedState||(n.flags|=1024),n.memoizedProps=r,n.memoizedState=g),l.props=r,l.state=g,l.context=c,r=u):(typeof l.componentDidUpdate!="function"||o===e.memoizedProps&&m===e.memoizedState||(n.flags|=4),typeof l.getSnapshotBeforeUpdate!="function"||o===e.memoizedProps&&m===e.memoizedState||(n.flags|=1024),r=!1)}return Fg(e,n,s,r,i,a)}function Fg(e,n,s,r,a,i){b1(e,n);var l=(n.flags&128)!==0;if(!r&&!l)return a&&Jb(n,s,!1),ha(e,n,i);r=n.stateNode,kD.current=n;var o=l&&typeof s.getDerivedStateFromError!="function"?null:r.render();return n.flags|=1,e!==null&&l?(n.child=Wl(n,e.child,null,i),n.child=Wl(n,null,o,i)):Kn(e,n,o,i),n.memoizedState=r.state,a&&Jb(n,s,!0),n.child}function k1(e){var n=e.stateNode;n.pendingContext?Yb(e,n.pendingContext,n.pendingContext!==n.context):n.context&&Yb(e,n.context,!1),mj(e,n.containerInfo)}function hk(e,n,s,r,a){return Bl(),oj(a),n.flags|=256,Kn(e,n,s,r),n.child}var _g={dehydrated:null,treeContext:null,retryLane:0};function zg(e){return{baseLanes:e,cachePool:null,transitions:null}}function N1(e,n,s){var r=n.pendingProps,a=Bt.current,i=!1,l=(n.flags&128)!==0,o;if((o=l)||(o=e!==null&&e.memoizedState===null?!1:(a&2)!==0),o?(i=!0,n.flags&=-129):(e===null||e.memoizedState!==null)&&(a|=1),Rt(Bt,a&1),e===null)return Ig(n),e=n.memoizedState,e!==null&&(e=e.dehydrated,e!==null)?(n.mode&1?e.data==="$!"?n.lanes=8:n.lanes=1073741824:n.lanes=1,null):(l=r.children,e=r.fallback,i?(r=n.mode,i=n.child,l={mode:"hidden",children:l},!(r&1)&&i!==null?(i.childLanes=0,i.pendingProps=l):i=vf(l,r,0,null),e=Si(e,r,s,null),i.return=n,e.return=n,i.sibling=e,n.child=i,n.child.memoizedState=zg(s),n.memoizedState=_g,e):bj(n,l));if(a=e.memoizedState,a!==null&&(o=a.dehydrated,o!==null))return ND(e,n,l,r,o,a,s);if(i){i=r.fallback,l=n.mode,a=e.child,o=a.sibling;var c={mode:"hidden",children:r.children};return!(l&1)&&n.child!==a?(r=n.child,r.childLanes=0,r.pendingProps=c,n.deletions=null):(r=_a(a,c),r.subtreeFlags=a.subtreeFlags&14680064),o!==null?i=_a(o,i):(i=Si(i,l,s,null),i.flags|=2),i.return=n,r.return=n,r.sibling=i,n.child=r,r=i,i=n.child,l=e.child.memoizedState,l=l===null?zg(s):{baseLanes:l.baseLanes|s,cachePool:null,transitions:l.transitions},i.memoizedState=l,i.childLanes=e.childLanes&~s,n.memoizedState=_g,r}return i=e.child,e=i.sibling,r=_a(i,{mode:"visible",children:r.children}),!(n.mode&1)&&(r.lanes=s),r.return=n,r.sibling=null,e!==null&&(s=n.deletions,s===null?(n.deletions=[e],n.flags|=16):s.push(e)),n.child=r,n.memoizedState=null,r}function bj(e,n){return n=vf({mode:"visible",children:n},e.mode,0,null),n.return=e,e.child=n}function Gu(e,n,s,r){return r!==null&&oj(r),Wl(n,e.child,null,s),e=bj(n,n.pendingProps.children),e.flags|=2,n.memoizedState=null,e}function ND(e,n,s,r,a,i,l){if(s)return n.flags&256?(n.flags&=-257,r=Km(Error(be(422))),Gu(e,n,l,r)):n.memoizedState!==null?(n.child=e.child,n.flags|=128,null):(i=r.fallback,a=n.mode,r=vf({mode:"visible",children:r.children},a,0,null),i=Si(i,a,l,null),i.flags|=2,r.return=n,i.return=n,r.sibling=i,n.child=r,n.mode&1&&Wl(n,e.child,null,l),n.child.memoizedState=zg(l),n.memoizedState=_g,i);if(!(n.mode&1))return Gu(e,n,l,null);if(a.data==="$!"){if(r=a.nextSibling&&a.nextSibling.dataset,r)var o=r.dgst;return r=o,i=Error(be(419)),r=Km(i,r,void 0),Gu(e,n,l,r)}if(o=(l&e.childLanes)!==0,rs||o){if(r=bn,r!==null){switch(l&-l){case 4:a=2;break;case 16:a=8;break;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:a=32;break;case 536870912:a=268435456;break;default:a=0}a=a&(r.suspendedLanes|l)?0:a,a!==0&&a!==i.retryLane&&(i.retryLane=a,da(e,a),ar(r,e,a,-1))}return Aj(),r=Km(Error(be(421))),Gu(e,n,l,r)}return a.data==="$?"?(n.flags|=128,n.child=e.child,n=LD.bind(null,e),a._reactRetry=n,null):(e=i.treeContext,xs=Da(a.nextSibling),js=n,Ft=!0,er=null,e!==null&&(Fs[_s++]=na,Fs[_s++]=sa,Fs[_s++]=$i,na=e.id,sa=e.overflow,$i=n),n=bj(n,r.children),n.flags|=4096,n)}function fk(e,n,s){e.lanes|=n;var r=e.alternate;r!==null&&(r.lanes|=n),Pg(e.return,n,s)}function Vm(e,n,s,r,a){var i=e.memoizedState;i===null?e.memoizedState={isBackwards:n,rendering:null,renderingStartTime:0,last:r,tail:s,tailMode:a}:(i.isBackwards=n,i.rendering=null,i.renderingStartTime=0,i.last=r,i.tail=s,i.tailMode=a)}function S1(e,n,s){var r=n.pendingProps,a=r.revealOrder,i=r.tail;if(Kn(e,n,r.children,s),r=Bt.current,r&2)r=r&1|2,n.flags|=128;else{if(e!==null&&e.flags&128)e:for(e=n.child;e!==null;){if(e.tag===13)e.memoizedState!==null&&fk(e,s,n);else if(e.tag===19)fk(e,s,n);else if(e.child!==null){e.child.return=e,e=e.child;continue}if(e===n)break e;for(;e.sibling===null;){if(e.return===null||e.return===n)break e;e=e.return}e.sibling.return=e.return,e=e.sibling}r&=1}if(Rt(Bt,r),!(n.mode&1))n.memoizedState=null;else switch(a){case"forwards":for(s=n.child,a=null;s!==null;)e=s.alternate,e!==null&&fh(e)===null&&(a=s),s=s.sibling;s=a,s===null?(a=n.child,n.child=null):(a=s.sibling,s.sibling=null),Vm(n,!1,a,s,i);break;case"backwards":for(s=null,a=n.child,n.child=null;a!==null;){if(e=a.alternate,e!==null&&fh(e)===null){n.child=a;break}e=a.sibling,a.sibling=s,s=a,a=e}Vm(n,!0,s,null,i);break;case"together":Vm(n,!1,null,null,void 0);break;default:n.memoizedState=null}return n.child}function Id(e,n){!(n.mode&1)&&e!==null&&(e.alternate=null,n.alternate=null,n.flags|=2)}function ha(e,n,s){if(e!==null&&(n.dependencies=e.dependencies),Ri|=n.lanes,!(s&n.childLanes))return null;if(e!==null&&n.child!==e.child)throw Error(be(153));if(n.child!==null){for(e=n.child,s=_a(e,e.pendingProps),n.child=s,s.return=n;e.sibling!==null;)e=e.sibling,s=s.sibling=_a(e,e.pendingProps),s.return=n;s.sibling=null}return n.child}function SD(e,n,s){switch(n.tag){case 3:k1(n),Bl();break;case 5:QC(n);break;case 1:ls(n.type)&&lh(n);break;case 4:mj(n,n.stateNode.containerInfo);break;case 10:var r=n.type._context,a=n.memoizedProps.value;Rt(uh,r._currentValue),r._currentValue=a;break;case 13:if(r=n.memoizedState,r!==null)return r.dehydrated!==null?(Rt(Bt,Bt.current&1),n.flags|=128,null):s&n.child.childLanes?N1(e,n,s):(Rt(Bt,Bt.current&1),e=ha(e,n,s),e!==null?e.sibling:null);Rt(Bt,Bt.current&1);break;case 19:if(r=(s&n.childLanes)!==0,e.flags&128){if(r)return S1(e,n,s);n.flags|=128}if(a=n.memoizedState,a!==null&&(a.rendering=null,a.tail=null,a.lastEffect=null),Rt(Bt,Bt.current),r)break;return null;case 22:case 23:return n.lanes=0,w1(e,n,s)}return ha(e,n,s)}var C1,Ug,E1,A1;C1=function(e,n){for(var s=n.child;s!==null;){if(s.tag===5||s.tag===6)e.appendChild(s.stateNode);else if(s.tag!==4&&s.child!==null){s.child.return=s,s=s.child;continue}if(s===n)break;for(;s.sibling===null;){if(s.return===null||s.return===n)return;s=s.return}s.sibling.return=s.return,s=s.sibling}};Ug=function(){};E1=function(e,n,s,r){var a=e.memoizedProps;if(a!==r){e=n.stateNode,wi($r.current);var i=null;switch(s){case"input":a=cg(e,a),r=cg(e,r),i=[];break;case"select":a=Ht({},a,{value:void 0}),r=Ht({},r,{value:void 0}),i=[];break;case"textarea":a=hg(e,a),r=hg(e,r),i=[];break;default:typeof a.onClick!="function"&&typeof r.onClick=="function"&&(e.onclick=ah)}mg(s,r);var l;s=null;for(u in a)if(!r.hasOwnProperty(u)&&a.hasOwnProperty(u)&&a[u]!=null)if(u==="style"){var o=a[u];for(l in o)o.hasOwnProperty(l)&&(s||(s={}),s[l]="")}else u!=="dangerouslySetInnerHTML"&&u!=="children"&&u!=="suppressContentEditableWarning"&&u!=="suppressHydrationWarning"&&u!=="autoFocus"&&(yc.hasOwnProperty(u)?i||(i=[]):(i=i||[]).push(u,null));for(u in r){var c=r[u];if(o=a!=null?a[u]:void 0,r.hasOwnProperty(u)&&c!==o&&(c!=null||o!=null))if(u==="style")if(o){for(l in o)!o.hasOwnProperty(l)||c&&c.hasOwnProperty(l)||(s||(s={}),s[l]="");for(l in c)c.hasOwnProperty(l)&&o[l]!==c[l]&&(s||(s={}),s[l]=c[l])}else s||(i||(i=[]),i.push(u,s)),s=c;else u==="dangerouslySetInnerHTML"?(c=c?c.__html:void 0,o=o?o.__html:void 0,c!=null&&o!==c&&(i=i||[]).push(u,c)):u==="children"?typeof c!="string"&&typeof c!="number"||(i=i||[]).push(u,""+c):u!=="suppressContentEditableWarning"&&u!=="suppressHydrationWarning"&&(yc.hasOwnProperty(u)?(c!=null&&u==="onScroll"&&It("scroll",e),i||o===c||(i=[])):(i=i||[]).push(u,c))}s&&(i=i||[]).push("style",s);var u=i;(n.updateQueue=u)&&(n.flags|=4)}};A1=function(e,n,s,r){s!==r&&(n.flags|=4)};function Fo(e,n){if(!Ft)switch(e.tailMode){case"hidden":n=e.tail;for(var s=null;n!==null;)n.alternate!==null&&(s=n),n=n.sibling;s===null?e.tail=null:s.sibling=null;break;case"collapsed":s=e.tail;for(var r=null;s!==null;)s.alternate!==null&&(r=s),s=s.sibling;r===null?n||e.tail===null?e.tail=null:e.tail.sibling=null:r.sibling=null}}function On(e){var n=e.alternate!==null&&e.alternate.child===e.child,s=0,r=0;if(n)for(var a=e.child;a!==null;)s|=a.lanes|a.childLanes,r|=a.subtreeFlags&14680064,r|=a.flags&14680064,a.return=e,a=a.sibling;else for(a=e.child;a!==null;)s|=a.lanes|a.childLanes,r|=a.subtreeFlags,r|=a.flags,a.return=e,a=a.sibling;return e.subtreeFlags|=r,e.childLanes=s,n}function CD(e,n,s){var r=n.pendingProps;switch(lj(n),n.tag){case 2:case 16:case 15:case 0:case 11:case 7:case 8:case 12:case 9:case 14:return On(n),null;case 1:return ls(n.type)&&ih(),On(n),null;case 3:return r=n.stateNode,Hl(),Mt(is),Mt(zn),gj(),r.pendingContext&&(r.context=r.pendingContext,r.pendingContext=null),(e===null||e.child===null)&&(Ku(n)?n.flags|=4:e===null||e.memoizedState.isDehydrated&&!(n.flags&256)||(n.flags|=1024,er!==null&&(Yg(er),er=null))),Ug(e,n),On(n),null;case 5:pj(n);var a=wi(Ic.current);if(s=n.type,e!==null&&n.stateNode!=null)E1(e,n,s,r,a),e.ref!==n.ref&&(n.flags|=512,n.flags|=2097152);else{if(!r){if(n.stateNode===null)throw Error(be(166));return On(n),null}if(e=wi($r.current),Ku(n)){r=n.stateNode,s=n.type;var i=n.memoizedProps;switch(r[Nr]=n,r[Tc]=i,e=(n.mode&1)!==0,s){case"dialog":It("cancel",r),It("close",r);break;case"iframe":case"object":case"embed":It("load",r);break;case"video":case"audio":for(a=0;a<Jo.length;a++)It(Jo[a],r);break;case"source":It("error",r);break;case"img":case"image":case"link":It("error",r),It("load",r);break;case"details":It("toggle",r);break;case"input":bb(r,i),It("invalid",r);break;case"select":r._wrapperState={wasMultiple:!!i.multiple},It("invalid",r);break;case"textarea":Nb(r,i),It("invalid",r)}mg(s,i),a=null;for(var l in i)if(i.hasOwnProperty(l)){var o=i[l];l==="children"?typeof o=="string"?r.textContent!==o&&(i.suppressHydrationWarning!==!0&&Hu(r.textContent,o,e),a=["children",o]):typeof o=="number"&&r.textContent!==""+o&&(i.suppressHydrationWarning!==!0&&Hu(r.textContent,o,e),a=["children",""+o]):yc.hasOwnProperty(l)&&o!=null&&l==="onScroll"&&It("scroll",r)}switch(s){case"input":Ou(r),kb(r,i,!0);break;case"textarea":Ou(r),Sb(r);break;case"select":case"option":break;default:typeof i.onClick=="function"&&(r.onclick=ah)}r=a,n.updateQueue=r,r!==null&&(n.flags|=4)}else{l=a.nodeType===9?a:a.ownerDocument,e==="http://www.w3.org/1999/xhtml"&&(e=nC(s)),e==="http://www.w3.org/1999/xhtml"?s==="script"?(e=l.createElement("div"),e.innerHTML="<script><\/script>",e=e.removeChild(e.firstChild)):typeof r.is=="string"?e=l.createElement(s,{is:r.is}):(e=l.createElement(s),s==="select"&&(l=e,r.multiple?l.multiple=!0:r.size&&(l.size=r.size))):e=l.createElementNS(e,s),e[Nr]=n,e[Tc]=r,C1(e,n,!1,!1),n.stateNode=e;e:{switch(l=pg(s,r),s){case"dialog":It("cancel",e),It("close",e),a=r;break;case"iframe":case"object":case"embed":It("load",e),a=r;break;case"video":case"audio":for(a=0;a<Jo.length;a++)It(Jo[a],e);a=r;break;case"source":It("error",e),a=r;break;case"img":case"image":case"link":It("error",e),It("load",e),a=r;break;case"details":It("toggle",e),a=r;break;case"input":bb(e,r),a=cg(e,r),It("invalid",e);break;case"option":a=r;break;case"select":e._wrapperState={wasMultiple:!!r.multiple},a=Ht({},r,{value:void 0}),It("invalid",e);break;case"textarea":Nb(e,r),a=hg(e,r),It("invalid",e);break;default:a=r}mg(s,a),o=a;for(i in o)if(o.hasOwnProperty(i)){var c=o[i];i==="style"?aC(e,c):i==="dangerouslySetInnerHTML"?(c=c?c.__html:void 0,c!=null&&sC(e,c)):i==="children"?typeof c=="string"?(s!=="textarea"||c!=="")&&wc(e,c):typeof c=="number"&&wc(e,""+c):i!=="suppressContentEditableWarning"&&i!=="suppressHydrationWarning"&&i!=="autoFocus"&&(yc.hasOwnProperty(i)?c!=null&&i==="onScroll"&&It("scroll",e):c!=null&&Vv(e,i,c,l))}switch(s){case"input":Ou(e),kb(e,r,!1);break;case"textarea":Ou(e),Sb(e);break;case"option":r.value!=null&&e.setAttribute("value",""+Wa(r.value));break;case"select":e.multiple=!!r.multiple,i=r.value,i!=null?Al(e,!!r.multiple,i,!1):r.defaultValue!=null&&Al(e,!!r.multiple,r.defaultValue,!0);break;default:typeof a.onClick=="function"&&(e.onclick=ah)}switch(s){case"button":case"input":case"select":case"textarea":r=!!r.autoFocus;break e;case"img":r=!0;break e;default:r=!1}}r&&(n.flags|=4)}n.ref!==null&&(n.flags|=512,n.flags|=2097152)}return On(n),null;case 6:if(e&&n.stateNode!=null)A1(e,n,e.memoizedProps,r);else{if(typeof r!="string"&&n.stateNode===null)throw Error(be(166));if(s=wi(Ic.current),wi($r.current),Ku(n)){if(r=n.stateNode,s=n.memoizedProps,r[Nr]=n,(i=r.nodeValue!==s)&&(e=js,e!==null))switch(e.tag){case 3:Hu(r.nodeValue,s,(e.mode&1)!==0);break;case 5:e.memoizedProps.suppressHydrationWarning!==!0&&Hu(r.nodeValue,s,(e.mode&1)!==0)}i&&(n.flags|=4)}else r=(s.nodeType===9?s:s.ownerDocument).createTextNode(r),r[Nr]=n,n.stateNode=r}return On(n),null;case 13:if(Mt(Bt),r=n.memoizedState,e===null||e.memoizedState!==null&&e.memoizedState.dehydrated!==null){if(Ft&&xs!==null&&n.mode&1&&!(n.flags&128))VC(),Bl(),n.flags|=98560,i=!1;else if(i=Ku(n),r!==null&&r.dehydrated!==null){if(e===null){if(!i)throw Error(be(318));if(i=n.memoizedState,i=i!==null?i.dehydrated:null,!i)throw Error(be(317));i[Nr]=n}else Bl(),!(n.flags&128)&&(n.memoizedState=null),n.flags|=4;On(n),i=!1}else er!==null&&(Yg(er),er=null),i=!0;if(!i)return n.flags&65536?n:null}return n.flags&128?(n.lanes=s,n):(r=r!==null,r!==(e!==null&&e.memoizedState!==null)&&r&&(n.child.flags|=8192,n.mode&1&&(e===null||Bt.current&1?hn===0&&(hn=3):Aj())),n.updateQueue!==null&&(n.flags|=4),On(n),null);case 4:return Hl(),Ug(e,n),e===null&&Ac(n.stateNode.containerInfo),On(n),null;case 10:return dj(n.type._context),On(n),null;case 17:return ls(n.type)&&ih(),On(n),null;case 19:if(Mt(Bt),i=n.memoizedState,i===null)return On(n),null;if(r=(n.flags&128)!==0,l=i.rendering,l===null)if(r)Fo(i,!1);else{if(hn!==0||e!==null&&e.flags&128)for(e=n.child;e!==null;){if(l=fh(e),l!==null){for(n.flags|=128,Fo(i,!1),r=l.updateQueue,r!==null&&(n.updateQueue=r,n.flags|=4),n.subtreeFlags=0,r=s,s=n.child;s!==null;)i=s,e=r,i.flags&=14680066,l=i.alternate,l===null?(i.childLanes=0,i.lanes=e,i.child=null,i.subtreeFlags=0,i.memoizedProps=null,i.memoizedState=null,i.updateQueue=null,i.dependencies=null,i.stateNode=null):(i.childLanes=l.childLanes,i.lanes=l.lanes,i.child=l.child,i.subtreeFlags=0,i.deletions=null,i.memoizedProps=l.memoizedProps,i.memoizedState=l.memoizedState,i.updateQueue=l.updateQueue,i.type=l.type,e=l.dependencies,i.dependencies=e===null?null:{lanes:e.lanes,firstContext:e.firstContext}),s=s.sibling;return Rt(Bt,Bt.current&1|2),n.child}e=e.sibling}i.tail!==null&&Qt()>Vl&&(n.flags|=128,r=!0,Fo(i,!1),n.lanes=4194304)}else{if(!r)if(e=fh(l),e!==null){if(n.flags|=128,r=!0,s=e.updateQueue,s!==null&&(n.updateQueue=s,n.flags|=4),Fo(i,!0),i.tail===null&&i.tailMode==="hidden"&&!l.alternate&&!Ft)return On(n),null}else 2*Qt()-i.renderingStartTime>Vl&&s!==1073741824&&(n.flags|=128,r=!0,Fo(i,!1),n.lanes=4194304);i.isBackwards?(l.sibling=n.child,n.child=l):(s=i.last,s!==null?s.sibling=l:n.child=l,i.last=l)}return i.tail!==null?(n=i.tail,i.rendering=n,i.tail=n.sibling,i.renderingStartTime=Qt(),n.sibling=null,s=Bt.current,Rt(Bt,r?s&1|2:s&1),n):(On(n),null);case 22:case 23:return Ej(),r=n.memoizedState!==null,e!==null&&e.memoizedState!==null!==r&&(n.flags|=8192),r&&n.mode&1?ps&1073741824&&(On(n),n.subtreeFlags&6&&(n.flags|=8192)):On(n),null;case 24:return null;case 25:return null}throw Error(be(156,n.tag))}function ED(e,n){switch(lj(n),n.tag){case 1:return ls(n.type)&&ih(),e=n.flags,e&65536?(n.flags=e&-65537|128,n):null;case 3:return Hl(),Mt(is),Mt(zn),gj(),e=n.flags,e&65536&&!(e&128)?(n.flags=e&-65537|128,n):null;case 5:return pj(n),null;case 13:if(Mt(Bt),e=n.memoizedState,e!==null&&e.dehydrated!==null){if(n.alternate===null)throw Error(be(340));Bl()}return e=n.flags,e&65536?(n.flags=e&-65537|128,n):null;case 19:return Mt(Bt),null;case 4:return Hl(),null;case 10:return dj(n.type._context),null;case 22:case 23:return Ej(),null;case 24:return null;default:return null}}var qu=!1,Fn=!1,AD=typeof WeakSet=="function"?WeakSet:Set,De=null;function bl(e,n){var s=e.ref;if(s!==null)if(typeof s=="function")try{s(null)}catch(r){Vt(e,n,r)}else s.current=null}function Bg(e,n,s){try{s()}catch(r){Vt(e,n,r)}}var mk=!1;function $D(e,n){if(Sg=nh,e=PC(),aj(e)){if("selectionStart"in e)var s={start:e.selectionStart,end:e.selectionEnd};else e:{s=(s=e.ownerDocument)&&s.defaultView||window;var r=s.getSelection&&s.getSelection();if(r&&r.rangeCount!==0){s=r.anchorNode;var a=r.anchorOffset,i=r.focusNode;r=r.focusOffset;try{s.nodeType,i.nodeType}catch{s=null;break e}var l=0,o=-1,c=-1,u=0,d=0,f=e,m=null;t:for(;;){for(var p;f!==s||a!==0&&f.nodeType!==3||(o=l+a),f!==i||r!==0&&f.nodeType!==3||(c=l+r),f.nodeType===3&&(l+=f.nodeValue.length),(p=f.firstChild)!==null;)m=f,f=p;for(;;){if(f===e)break t;if(m===s&&++u===a&&(o=l),m===i&&++d===r&&(c=l),(p=f.nextSibling)!==null)break;f=m,m=f.parentNode}f=p}s=o===-1||c===-1?null:{start:o,end:c}}else s=null}s=s||{start:0,end:0}}else s=null;for(Cg={focusedElem:e,selectionRange:s},nh=!1,De=n;De!==null;)if(n=De,e=n.child,(n.subtreeFlags&1028)!==0&&e!==null)e.return=n,De=e;else for(;De!==null;){n=De;try{var g=n.alternate;if(n.flags&1024)switch(n.tag){case 0:case 11:case 15:break;case 1:if(g!==null){var v=g.memoizedProps,b=g.memoizedState,j=n.stateNode,x=j.getSnapshotBeforeUpdate(n.elementType===n.type?v:Xs(n.type,v),b);j.__reactInternalSnapshotBeforeUpdate=x}break;case 3:var y=n.stateNode.containerInfo;y.nodeType===1?y.textContent="":y.nodeType===9&&y.documentElement&&y.removeChild(y.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(be(163))}}catch(w){Vt(n,n.return,w)}if(e=n.sibling,e!==null){e.return=n.return,De=e;break}De=n.return}return g=mk,mk=!1,g}function oc(e,n,s){var r=n.updateQueue;if(r=r!==null?r.lastEffect:null,r!==null){var a=r=r.next;do{if((a.tag&e)===e){var i=a.destroy;a.destroy=void 0,i!==void 0&&Bg(n,s,i)}a=a.next}while(a!==r)}}function gf(e,n){if(n=n.updateQueue,n=n!==null?n.lastEffect:null,n!==null){var s=n=n.next;do{if((s.tag&e)===e){var r=s.create;s.destroy=r()}s=s.next}while(s!==n)}}function Wg(e){var n=e.ref;if(n!==null){var s=e.stateNode;switch(e.tag){case 5:e=s;break;default:e=s}typeof n=="function"?n(e):n.current=e}}function $1(e){var n=e.alternate;n!==null&&(e.alternate=null,$1(n)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(n=e.stateNode,n!==null&&(delete n[Nr],delete n[Tc],delete n[$g],delete n[dD],delete n[hD])),e.stateNode=null,e.return=null,e.dependencies=null,e.memoizedProps=null,e.memoizedState=null,e.pendingProps=null,e.stateNode=null,e.updateQueue=null}function T1(e){return e.tag===5||e.tag===3||e.tag===4}function pk(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||T1(e.return))return null;e=e.return}for(e.sibling.return=e.return,e=e.sibling;e.tag!==5&&e.tag!==6&&e.tag!==18;){if(e.flags&2||e.child===null||e.tag===4)continue e;e.child.return=e,e=e.child}if(!(e.flags&2))return e.stateNode}}function Hg(e,n,s){var r=e.tag;if(r===5||r===6)e=e.stateNode,n?s.nodeType===8?s.parentNode.insertBefore(e,n):s.insertBefore(e,n):(s.nodeType===8?(n=s.parentNode,n.insertBefore(e,s)):(n=s,n.appendChild(e)),s=s._reactRootContainer,s!=null||n.onclick!==null||(n.onclick=ah));else if(r!==4&&(e=e.child,e!==null))for(Hg(e,n,s),e=e.sibling;e!==null;)Hg(e,n,s),e=e.sibling}function Kg(e,n,s){var r=e.tag;if(r===5||r===6)e=e.stateNode,n?s.insertBefore(e,n):s.appendChild(e);else if(r!==4&&(e=e.child,e!==null))for(Kg(e,n,s),e=e.sibling;e!==null;)Kg(e,n,s),e=e.sibling}var An=null,Zs=!1;function wa(e,n,s){for(s=s.child;s!==null;)R1(e,n,s),s=s.sibling}function R1(e,n,s){if(Ar&&typeof Ar.onCommitFiberUnmount=="function")try{Ar.onCommitFiberUnmount(of,s)}catch{}switch(s.tag){case 5:Fn||bl(s,n);case 6:var r=An,a=Zs;An=null,wa(e,n,s),An=r,Zs=a,An!==null&&(Zs?(e=An,s=s.stateNode,e.nodeType===8?e.parentNode.removeChild(s):e.removeChild(s)):An.removeChild(s.stateNode));break;case 18:An!==null&&(Zs?(e=An,s=s.stateNode,e.nodeType===8?_m(e.parentNode,s):e.nodeType===1&&_m(e,s),Sc(e)):_m(An,s.stateNode));break;case 4:r=An,a=Zs,An=s.stateNode.containerInfo,Zs=!0,wa(e,n,s),An=r,Zs=a;break;case 0:case 11:case 14:case 15:if(!Fn&&(r=s.updateQueue,r!==null&&(r=r.lastEffect,r!==null))){a=r=r.next;do{var i=a,l=i.destroy;i=i.tag,l!==void 0&&(i&2||i&4)&&Bg(s,n,l),a=a.next}while(a!==r)}wa(e,n,s);break;case 1:if(!Fn&&(bl(s,n),r=s.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=s.memoizedProps,r.state=s.memoizedState,r.componentWillUnmount()}catch(o){Vt(s,n,o)}wa(e,n,s);break;case 21:wa(e,n,s);break;case 22:s.mode&1?(Fn=(r=Fn)||s.memoizedState!==null,wa(e,n,s),Fn=r):wa(e,n,s);break;default:wa(e,n,s)}}function gk(e){var n=e.updateQueue;if(n!==null){e.updateQueue=null;var s=e.stateNode;s===null&&(s=e.stateNode=new AD),n.forEach(function(r){var a=FD.bind(null,e,r);s.has(r)||(s.add(r),r.then(a,a))})}}function Qs(e,n){var s=n.deletions;if(s!==null)for(var r=0;r<s.length;r++){var a=s[r];try{var i=e,l=n,o=l;e:for(;o!==null;){switch(o.tag){case 5:An=o.stateNode,Zs=!1;break e;case 3:An=o.stateNode.containerInfo,Zs=!0;break e;case 4:An=o.stateNode.containerInfo,Zs=!0;break e}o=o.return}if(An===null)throw Error(be(160));R1(i,l,a),An=null,Zs=!1;var c=a.alternate;c!==null&&(c.return=null),a.return=null}catch(u){Vt(a,n,u)}}if(n.subtreeFlags&12854)for(n=n.child;n!==null;)I1(n,e),n=n.sibling}function I1(e,n){var s=e.alternate,r=e.flags;switch(e.tag){case 0:case 11:case 14:case 15:if(Qs(n,e),vr(e),r&4){try{oc(3,e,e.return),gf(3,e)}catch(v){Vt(e,e.return,v)}try{oc(5,e,e.return)}catch(v){Vt(e,e.return,v)}}break;case 1:Qs(n,e),vr(e),r&512&&s!==null&&bl(s,s.return);break;case 5:if(Qs(n,e),vr(e),r&512&&s!==null&&bl(s,s.return),e.flags&32){var a=e.stateNode;try{wc(a,"")}catch(v){Vt(e,e.return,v)}}if(r&4&&(a=e.stateNode,a!=null)){var i=e.memoizedProps,l=s!==null?s.memoizedProps:i,o=e.type,c=e.updateQueue;if(e.updateQueue=null,c!==null)try{o==="input"&&i.type==="radio"&&i.name!=null&&eC(a,i),pg(o,l);var u=pg(o,i);for(l=0;l<c.length;l+=2){var d=c[l],f=c[l+1];d==="style"?aC(a,f):d==="dangerouslySetInnerHTML"?sC(a,f):d==="children"?wc(a,f):Vv(a,d,f,u)}switch(o){case"input":ug(a,i);break;case"textarea":tC(a,i);break;case"select":var m=a._wrapperState.wasMultiple;a._wrapperState.wasMultiple=!!i.multiple;var p=i.value;p!=null?Al(a,!!i.multiple,p,!1):m!==!!i.multiple&&(i.defaultValue!=null?Al(a,!!i.multiple,i.defaultValue,!0):Al(a,!!i.multiple,i.multiple?[]:"",!1))}a[Tc]=i}catch(v){Vt(e,e.return,v)}}break;case 6:if(Qs(n,e),vr(e),r&4){if(e.stateNode===null)throw Error(be(162));a=e.stateNode,i=e.memoizedProps;try{a.nodeValue=i}catch(v){Vt(e,e.return,v)}}break;case 3:if(Qs(n,e),vr(e),r&4&&s!==null&&s.memoizedState.isDehydrated)try{Sc(n.containerInfo)}catch(v){Vt(e,e.return,v)}break;case 4:Qs(n,e),vr(e);break;case 13:Qs(n,e),vr(e),a=e.child,a.flags&8192&&(i=a.memoizedState!==null,a.stateNode.isHidden=i,!i||a.alternate!==null&&a.alternate.memoizedState!==null||(Sj=Qt())),r&4&&gk(e);break;case 22:if(d=s!==null&&s.memoizedState!==null,e.mode&1?(Fn=(u=Fn)||d,Qs(n,e),Fn=u):Qs(n,e),vr(e),r&8192){if(u=e.memoizedState!==null,(e.stateNode.isHidden=u)&&!d&&e.mode&1)for(De=e,d=e.child;d!==null;){for(f=De=d;De!==null;){switch(m=De,p=m.child,m.tag){case 0:case 11:case 14:case 15:oc(4,m,m.return);break;case 1:bl(m,m.return);var g=m.stateNode;if(typeof g.componentWillUnmount=="function"){r=m,s=m.return;try{n=r,g.props=n.memoizedProps,g.state=n.memoizedState,g.componentWillUnmount()}catch(v){Vt(r,s,v)}}break;case 5:bl(m,m.return);break;case 22:if(m.memoizedState!==null){vk(f);continue}}p!==null?(p.return=m,De=p):vk(f)}d=d.sibling}e:for(d=null,f=e;;){if(f.tag===5){if(d===null){d=f;try{a=f.stateNode,u?(i=a.style,typeof i.setProperty=="function"?i.setProperty("display","none","important"):i.display="none"):(o=f.stateNode,c=f.memoizedProps.style,l=c!=null&&c.hasOwnProperty("display")?c.display:null,o.style.display=rC("display",l))}catch(v){Vt(e,e.return,v)}}}else if(f.tag===6){if(d===null)try{f.stateNode.nodeValue=u?"":f.memoizedProps}catch(v){Vt(e,e.return,v)}}else if((f.tag!==22&&f.tag!==23||f.memoizedState===null||f===e)&&f.child!==null){f.child.return=f,f=f.child;continue}if(f===e)break e;for(;f.sibling===null;){if(f.return===null||f.return===e)break e;d===f&&(d=null),f=f.return}d===f&&(d=null),f.sibling.return=f.return,f=f.sibling}}break;case 19:Qs(n,e),vr(e),r&4&&gk(e);break;case 21:break;default:Qs(n,e),vr(e)}}function vr(e){var n=e.flags;if(n&2){try{e:{for(var s=e.return;s!==null;){if(T1(s)){var r=s;break e}s=s.return}throw Error(be(160))}switch(r.tag){case 5:var a=r.stateNode;r.flags&32&&(wc(a,""),r.flags&=-33);var i=pk(e);Kg(e,i,a);break;case 3:case 4:var l=r.stateNode.containerInfo,o=pk(e);Hg(e,o,l);break;default:throw Error(be(161))}}catch(c){Vt(e,e.return,c)}e.flags&=-3}n&4096&&(e.flags&=-4097)}function TD(e,n,s){De=e,P1(e)}function P1(e,n,s){for(var r=(e.mode&1)!==0;De!==null;){var a=De,i=a.child;if(a.tag===22&&r){var l=a.memoizedState!==null||qu;if(!l){var o=a.alternate,c=o!==null&&o.memoizedState!==null||Fn;o=qu;var u=Fn;if(qu=l,(Fn=c)&&!u)for(De=a;De!==null;)l=De,c=l.child,l.tag===22&&l.memoizedState!==null?jk(a):c!==null?(c.return=l,De=c):jk(a);for(;i!==null;)De=i,P1(i),i=i.sibling;De=a,qu=o,Fn=u}xk(e)}else a.subtreeFlags&8772&&i!==null?(i.return=a,De=i):xk(e)}}function xk(e){for(;De!==null;){var n=De;if(n.flags&8772){var s=n.alternate;try{if(n.flags&8772)switch(n.tag){case 0:case 11:case 15:Fn||gf(5,n);break;case 1:var r=n.stateNode;if(n.flags&4&&!Fn)if(s===null)r.componentDidMount();else{var a=n.elementType===n.type?s.memoizedProps:Xs(n.type,s.memoizedProps);r.componentDidUpdate(a,s.memoizedState,r.__reactInternalSnapshotBeforeUpdate)}var i=n.updateQueue;i!==null&&tk(n,i,r);break;case 3:var l=n.updateQueue;if(l!==null){if(s=null,n.child!==null)switch(n.child.tag){case 5:s=n.child.stateNode;break;case 1:s=n.child.stateNode}tk(n,l,s)}break;case 5:var o=n.stateNode;if(s===null&&n.flags&4){s=o;var c=n.memoizedProps;switch(n.type){case"button":case"input":case"select":case"textarea":c.autoFocus&&s.focus();break;case"img":c.src&&(s.src=c.src)}}break;case 6:break;case 4:break;case 12:break;case 13:if(n.memoizedState===null){var u=n.alternate;if(u!==null){var d=u.memoizedState;if(d!==null){var f=d.dehydrated;f!==null&&Sc(f)}}}break;case 19:case 17:case 21:case 22:case 23:case 25:break;default:throw Error(be(163))}Fn||n.flags&512&&Wg(n)}catch(m){Vt(n,n.return,m)}}if(n===e){De=null;break}if(s=n.sibling,s!==null){s.return=n.return,De=s;break}De=n.return}}function vk(e){for(;De!==null;){var n=De;if(n===e){De=null;break}var s=n.sibling;if(s!==null){s.return=n.return,De=s;break}De=n.return}}function jk(e){for(;De!==null;){var n=De;try{switch(n.tag){case 0:case 11:case 15:var s=n.return;try{gf(4,n)}catch(c){Vt(n,s,c)}break;case 1:var r=n.stateNode;if(typeof r.componentDidMount=="function"){var a=n.return;try{r.componentDidMount()}catch(c){Vt(n,a,c)}}var i=n.return;try{Wg(n)}catch(c){Vt(n,i,c)}break;case 5:var l=n.return;try{Wg(n)}catch(c){Vt(n,l,c)}}}catch(c){Vt(n,n.return,c)}if(n===e){De=null;break}var o=n.sibling;if(o!==null){o.return=n.return,De=o;break}De=n.return}}var RD=Math.ceil,gh=ga.ReactCurrentDispatcher,kj=ga.ReactCurrentOwner,Hs=ga.ReactCurrentBatchConfig,pt=0,bn=null,nn=null,$n=0,ps=0,kl=ei(0),hn=0,Oc=null,Ri=0,xf=0,Nj=0,cc=null,ss=null,Sj=0,Vl=1/0,Jr=null,xh=!1,Vg=null,La=null,Yu=!1,$a=null,vh=0,uc=0,Gg=null,Pd=-1,Md=0;function qn(){return pt&6?Qt():Pd!==-1?Pd:Pd=Qt()}function Fa(e){return e.mode&1?pt&2&&$n!==0?$n&-$n:mD.transition!==null?(Md===0&&(Md=xC()),Md):(e=wt,e!==0||(e=window.event,e=e===void 0?16:NC(e.type)),e):1}function ar(e,n,s,r){if(50<uc)throw uc=0,Gg=null,Error(be(185));ou(e,s,r),(!(pt&2)||e!==bn)&&(e===bn&&(!(pt&2)&&(xf|=s),hn===4&&Ea(e,$n)),os(e,r),s===1&&pt===0&&!(n.mode&1)&&(Vl=Qt()+500,ff&&ti()))}function os(e,n){var s=e.callbackNode;m2(e,n);var r=th(e,e===bn?$n:0);if(r===0)s!==null&&Ab(s),e.callbackNode=null,e.callbackPriority=0;else if(n=r&-r,e.callbackPriority!==n){if(s!=null&&Ab(s),n===1)e.tag===0?fD(yk.bind(null,e)):WC(yk.bind(null,e)),cD(function(){!(pt&6)&&ti()}),s=null;else{switch(vC(r)){case 1:s=Qv;break;case 4:s=pC;break;case 16:s=eh;break;case 536870912:s=gC;break;default:s=eh}s=U1(s,M1.bind(null,e))}e.callbackPriority=n,e.callbackNode=s}}function M1(e,n){if(Pd=-1,Md=0,pt&6)throw Error(be(327));var s=e.callbackNode;if(Pl()&&e.callbackNode!==s)return null;var r=th(e,e===bn?$n:0);if(r===0)return null;if(r&30||r&e.expiredLanes||n)n=jh(e,r);else{n=r;var a=pt;pt|=2;var i=O1();(bn!==e||$n!==n)&&(Jr=null,Vl=Qt()+500,Ni(e,n));do try{MD();break}catch(o){D1(e,o)}while(!0);uj(),gh.current=i,pt=a,nn!==null?n=0:(bn=null,$n=0,n=hn)}if(n!==0){if(n===2&&(a=yg(e),a!==0&&(r=a,n=qg(e,a))),n===1)throw s=Oc,Ni(e,0),Ea(e,r),os(e,Qt()),s;if(n===6)Ea(e,r);else{if(a=e.current.alternate,!(r&30)&&!ID(a)&&(n=jh(e,r),n===2&&(i=yg(e),i!==0&&(r=i,n=qg(e,i))),n===1))throw s=Oc,Ni(e,0),Ea(e,r),os(e,Qt()),s;switch(e.finishedWork=a,e.finishedLanes=r,n){case 0:case 1:throw Error(be(345));case 2:gi(e,ss,Jr);break;case 3:if(Ea(e,r),(r&130023424)===r&&(n=Sj+500-Qt(),10<n)){if(th(e,0)!==0)break;if(a=e.suspendedLanes,(a&r)!==r){qn(),e.pingedLanes|=e.suspendedLanes&a;break}e.timeoutHandle=Ag(gi.bind(null,e,ss,Jr),n);break}gi(e,ss,Jr);break;case 4:if(Ea(e,r),(r&4194240)===r)break;for(n=e.eventTimes,a=-1;0<r;){var l=31-rr(r);i=1<<l,l=n[l],l>a&&(a=l),r&=~i}if(r=a,r=Qt()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*RD(r/1960))-r,10<r){e.timeoutHandle=Ag(gi.bind(null,e,ss,Jr),r);break}gi(e,ss,Jr);break;case 5:gi(e,ss,Jr);break;default:throw Error(be(329))}}}return os(e,Qt()),e.callbackNode===s?M1.bind(null,e):null}function qg(e,n){var s=cc;return e.current.memoizedState.isDehydrated&&(Ni(e,n).flags|=256),e=jh(e,n),e!==2&&(n=ss,ss=s,n!==null&&Yg(n)),e}function Yg(e){ss===null?ss=e:ss.push.apply(ss,e)}function ID(e){for(var n=e;;){if(n.flags&16384){var s=n.updateQueue;if(s!==null&&(s=s.stores,s!==null))for(var r=0;r<s.length;r++){var a=s[r],i=a.getSnapshot;a=a.value;try{if(!or(i(),a))return!1}catch{return!1}}}if(s=n.child,n.subtreeFlags&16384&&s!==null)s.return=n,n=s;else{if(n===e)break;for(;n.sibling===null;){if(n.return===null||n.return===e)return!0;n=n.return}n.sibling.return=n.return,n=n.sibling}}return!0}function Ea(e,n){for(n&=~Nj,n&=~xf,e.suspendedLanes|=n,e.pingedLanes&=~n,e=e.expirationTimes;0<n;){var s=31-rr(n),r=1<<s;e[s]=-1,n&=~r}}function yk(e){if(pt&6)throw Error(be(327));Pl();var n=th(e,0);if(!(n&1))return os(e,Qt()),null;var s=jh(e,n);if(e.tag!==0&&s===2){var r=yg(e);r!==0&&(n=r,s=qg(e,r))}if(s===1)throw s=Oc,Ni(e,0),Ea(e,n),os(e,Qt()),s;if(s===6)throw Error(be(345));return e.finishedWork=e.current.alternate,e.finishedLanes=n,gi(e,ss,Jr),os(e,Qt()),null}function Cj(e,n){var s=pt;pt|=1;try{return e(n)}finally{pt=s,pt===0&&(Vl=Qt()+500,ff&&ti())}}function Ii(e){$a!==null&&$a.tag===0&&!(pt&6)&&Pl();var n=pt;pt|=1;var s=Hs.transition,r=wt;try{if(Hs.transition=null,wt=1,e)return e()}finally{wt=r,Hs.transition=s,pt=n,!(pt&6)&&ti()}}function Ej(){ps=kl.current,Mt(kl)}function Ni(e,n){e.finishedWork=null,e.finishedLanes=0;var s=e.timeoutHandle;if(s!==-1&&(e.timeoutHandle=-1,oD(s)),nn!==null)for(s=nn.return;s!==null;){var r=s;switch(lj(r),r.tag){case 1:r=r.type.childContextTypes,r!=null&&ih();break;case 3:Hl(),Mt(is),Mt(zn),gj();break;case 5:pj(r);break;case 4:Hl();break;case 13:Mt(Bt);break;case 19:Mt(Bt);break;case 10:dj(r.type._context);break;case 22:case 23:Ej()}s=s.return}if(bn=e,nn=e=_a(e.current,null),$n=ps=n,hn=0,Oc=null,Nj=xf=Ri=0,ss=cc=null,yi!==null){for(n=0;n<yi.length;n++)if(s=yi[n],r=s.interleaved,r!==null){s.interleaved=null;var a=r.next,i=s.pending;if(i!==null){var l=i.next;i.next=a,r.next=l}s.pending=r}yi=null}return e}function D1(e,n){do{var s=nn;try{if(uj(),Td.current=ph,mh){for(var r=Wt.memoizedState;r!==null;){var a=r.queue;a!==null&&(a.pending=null),r=r.next}mh=!1}if(Ti=0,vn=cn=Wt=null,lc=!1,Pc=0,kj.current=null,s===null||s.return===null){hn=1,Oc=n,nn=null;break}e:{var i=e,l=s.return,o=s,c=n;if(n=$n,o.flags|=32768,c!==null&&typeof c=="object"&&typeof c.then=="function"){var u=c,d=o,f=d.tag;if(!(d.mode&1)&&(f===0||f===11||f===15)){var m=d.alternate;m?(d.updateQueue=m.updateQueue,d.memoizedState=m.memoizedState,d.lanes=m.lanes):(d.updateQueue=null,d.memoizedState=null)}var p=lk(l);if(p!==null){p.flags&=-257,ok(p,l,o,i,n),p.mode&1&&ik(i,u,n),n=p,c=u;var g=n.updateQueue;if(g===null){var v=new Set;v.add(c),n.updateQueue=v}else g.add(c);break e}else{if(!(n&1)){ik(i,u,n),Aj();break e}c=Error(be(426))}}else if(Ft&&o.mode&1){var b=lk(l);if(b!==null){!(b.flags&65536)&&(b.flags|=256),ok(b,l,o,i,n),oj(Kl(c,o));break e}}i=c=Kl(c,o),hn!==4&&(hn=2),cc===null?cc=[i]:cc.push(i),i=l;do{switch(i.tag){case 3:i.flags|=65536,n&=-n,i.lanes|=n;var j=v1(i,c,n);ek(i,j);break e;case 1:o=c;var x=i.type,y=i.stateNode;if(!(i.flags&128)&&(typeof x.getDerivedStateFromError=="function"||y!==null&&typeof y.componentDidCatch=="function"&&(La===null||!La.has(y)))){i.flags|=65536,n&=-n,i.lanes|=n;var w=j1(i,o,n);ek(i,w);break e}}i=i.return}while(i!==null)}F1(s)}catch(k){n=k,nn===s&&s!==null&&(nn=s=s.return);continue}break}while(!0)}function O1(){var e=gh.current;return gh.current=ph,e===null?ph:e}function Aj(){(hn===0||hn===3||hn===2)&&(hn=4),bn===null||!(Ri&268435455)&&!(xf&268435455)||Ea(bn,$n)}function jh(e,n){var s=pt;pt|=2;var r=O1();(bn!==e||$n!==n)&&(Jr=null,Ni(e,n));do try{PD();break}catch(a){D1(e,a)}while(!0);if(uj(),pt=s,gh.current=r,nn!==null)throw Error(be(261));return bn=null,$n=0,hn}function PD(){for(;nn!==null;)L1(nn)}function MD(){for(;nn!==null&&!a2();)L1(nn)}function L1(e){var n=z1(e.alternate,e,ps);e.memoizedProps=e.pendingProps,n===null?F1(e):nn=n,kj.current=null}function F1(e){var n=e;do{var s=n.alternate;if(e=n.return,n.flags&32768){if(s=ED(s,n),s!==null){s.flags&=32767,nn=s;return}if(e!==null)e.flags|=32768,e.subtreeFlags=0,e.deletions=null;else{hn=6,nn=null;return}}else if(s=CD(s,n,ps),s!==null){nn=s;return}if(n=n.sibling,n!==null){nn=n;return}nn=n=e}while(n!==null);hn===0&&(hn=5)}function gi(e,n,s){var r=wt,a=Hs.transition;try{Hs.transition=null,wt=1,DD(e,n,s,r)}finally{Hs.transition=a,wt=r}return null}function DD(e,n,s,r){do Pl();while($a!==null);if(pt&6)throw Error(be(327));s=e.finishedWork;var a=e.finishedLanes;if(s===null)return null;if(e.finishedWork=null,e.finishedLanes=0,s===e.current)throw Error(be(177));e.callbackNode=null,e.callbackPriority=0;var i=s.lanes|s.childLanes;if(p2(e,i),e===bn&&(nn=bn=null,$n=0),!(s.subtreeFlags&2064)&&!(s.flags&2064)||Yu||(Yu=!0,U1(eh,function(){return Pl(),null})),i=(s.flags&15990)!==0,s.subtreeFlags&15990||i){i=Hs.transition,Hs.transition=null;var l=wt;wt=1;var o=pt;pt|=4,kj.current=null,$D(e,s),I1(s,e),tD(Cg),nh=!!Sg,Cg=Sg=null,e.current=s,TD(s),i2(),pt=o,wt=l,Hs.transition=i}else e.current=s;if(Yu&&(Yu=!1,$a=e,vh=a),i=e.pendingLanes,i===0&&(La=null),c2(s.stateNode),os(e,Qt()),n!==null)for(r=e.onRecoverableError,s=0;s<n.length;s++)a=n[s],r(a.value,{componentStack:a.stack,digest:a.digest});if(xh)throw xh=!1,e=Vg,Vg=null,e;return vh&1&&e.tag!==0&&Pl(),i=e.pendingLanes,i&1?e===Gg?uc++:(uc=0,Gg=e):uc=0,ti(),null}function Pl(){if($a!==null){var e=vC(vh),n=Hs.transition,s=wt;try{if(Hs.transition=null,wt=16>e?16:e,$a===null)var r=!1;else{if(e=$a,$a=null,vh=0,pt&6)throw Error(be(331));var a=pt;for(pt|=4,De=e.current;De!==null;){var i=De,l=i.child;if(De.flags&16){var o=i.deletions;if(o!==null){for(var c=0;c<o.length;c++){var u=o[c];for(De=u;De!==null;){var d=De;switch(d.tag){case 0:case 11:case 15:oc(8,d,i)}var f=d.child;if(f!==null)f.return=d,De=f;else for(;De!==null;){d=De;var m=d.sibling,p=d.return;if($1(d),d===u){De=null;break}if(m!==null){m.return=p,De=m;break}De=p}}}var g=i.alternate;if(g!==null){var v=g.child;if(v!==null){g.child=null;do{var b=v.sibling;v.sibling=null,v=b}while(v!==null)}}De=i}}if(i.subtreeFlags&2064&&l!==null)l.return=i,De=l;else e:for(;De!==null;){if(i=De,i.flags&2048)switch(i.tag){case 0:case 11:case 15:oc(9,i,i.return)}var j=i.sibling;if(j!==null){j.return=i.return,De=j;break e}De=i.return}}var x=e.current;for(De=x;De!==null;){l=De;var y=l.child;if(l.subtreeFlags&2064&&y!==null)y.return=l,De=y;else e:for(l=x;De!==null;){if(o=De,o.flags&2048)try{switch(o.tag){case 0:case 11:case 15:gf(9,o)}}catch(k){Vt(o,o.return,k)}if(o===l){De=null;break e}var w=o.sibling;if(w!==null){w.return=o.return,De=w;break e}De=o.return}}if(pt=a,ti(),Ar&&typeof Ar.onPostCommitFiberRoot=="function")try{Ar.onPostCommitFiberRoot(of,e)}catch{}r=!0}return r}finally{wt=s,Hs.transition=n}}return!1}function wk(e,n,s){n=Kl(s,n),n=v1(e,n,1),e=Oa(e,n,1),n=qn(),e!==null&&(ou(e,1,n),os(e,n))}function Vt(e,n,s){if(e.tag===3)wk(e,e,s);else for(;n!==null;){if(n.tag===3){wk(n,e,s);break}else if(n.tag===1){var r=n.stateNode;if(typeof n.type.getDerivedStateFromError=="function"||typeof r.componentDidCatch=="function"&&(La===null||!La.has(r))){e=Kl(s,e),e=j1(n,e,1),n=Oa(n,e,1),e=qn(),n!==null&&(ou(n,1,e),os(n,e));break}}n=n.return}}function OD(e,n,s){var r=e.pingCache;r!==null&&r.delete(n),n=qn(),e.pingedLanes|=e.suspendedLanes&s,bn===e&&($n&s)===s&&(hn===4||hn===3&&($n&130023424)===$n&&500>Qt()-Sj?Ni(e,0):Nj|=s),os(e,n)}function _1(e,n){n===0&&(e.mode&1?(n=_u,_u<<=1,!(_u&130023424)&&(_u=4194304)):n=1);var s=qn();e=da(e,n),e!==null&&(ou(e,n,s),os(e,s))}function LD(e){var n=e.memoizedState,s=0;n!==null&&(s=n.retryLane),_1(e,s)}function FD(e,n){var s=0;switch(e.tag){case 13:var r=e.stateNode,a=e.memoizedState;a!==null&&(s=a.retryLane);break;case 19:r=e.stateNode;break;default:throw Error(be(314))}r!==null&&r.delete(n),_1(e,s)}var z1;z1=function(e,n,s){if(e!==null)if(e.memoizedProps!==n.pendingProps||is.current)rs=!0;else{if(!(e.lanes&s)&&!(n.flags&128))return rs=!1,SD(e,n,s);rs=!!(e.flags&131072)}else rs=!1,Ft&&n.flags&1048576&&HC(n,ch,n.index);switch(n.lanes=0,n.tag){case 2:var r=n.type;Id(e,n),e=n.pendingProps;var a=Ul(n,zn.current);Il(n,s),a=vj(null,n,r,e,a,s);var i=jj();return n.flags|=1,typeof a=="object"&&a!==null&&typeof a.render=="function"&&a.$$typeof===void 0?(n.tag=1,n.memoizedState=null,n.updateQueue=null,ls(r)?(i=!0,lh(n)):i=!1,n.memoizedState=a.state!==null&&a.state!==void 0?a.state:null,fj(n),a.updater=pf,n.stateNode=a,a._reactInternals=n,Dg(n,r,e,s),n=Fg(null,n,r,!0,i,s)):(n.tag=0,Ft&&i&&ij(n),Kn(null,n,a,s),n=n.child),n;case 16:r=n.elementType;e:{switch(Id(e,n),e=n.pendingProps,a=r._init,r=a(r._payload),n.type=r,a=n.tag=zD(r),e=Xs(r,e),a){case 0:n=Lg(null,n,r,e,s);break e;case 1:n=dk(null,n,r,e,s);break e;case 11:n=ck(null,n,r,e,s);break e;case 14:n=uk(null,n,r,Xs(r.type,e),s);break e}throw Error(be(306,r,""))}return n;case 0:return r=n.type,a=n.pendingProps,a=n.elementType===r?a:Xs(r,a),Lg(e,n,r,a,s);case 1:return r=n.type,a=n.pendingProps,a=n.elementType===r?a:Xs(r,a),dk(e,n,r,a,s);case 3:e:{if(k1(n),e===null)throw Error(be(387));r=n.pendingProps,i=n.memoizedState,a=i.element,JC(e,n),hh(n,r,null,s);var l=n.memoizedState;if(r=l.element,i.isDehydrated)if(i={element:r,isDehydrated:!1,cache:l.cache,pendingSuspenseBoundaries:l.pendingSuspenseBoundaries,transitions:l.transitions},n.updateQueue.baseState=i,n.memoizedState=i,n.flags&256){a=Kl(Error(be(423)),n),n=hk(e,n,r,s,a);break e}else if(r!==a){a=Kl(Error(be(424)),n),n=hk(e,n,r,s,a);break e}else for(xs=Da(n.stateNode.containerInfo.firstChild),js=n,Ft=!0,er=null,s=qC(n,null,r,s),n.child=s;s;)s.flags=s.flags&-3|4096,s=s.sibling;else{if(Bl(),r===a){n=ha(e,n,s);break e}Kn(e,n,r,s)}n=n.child}return n;case 5:return QC(n),e===null&&Ig(n),r=n.type,a=n.pendingProps,i=e!==null?e.memoizedProps:null,l=a.children,Eg(r,a)?l=null:i!==null&&Eg(r,i)&&(n.flags|=32),b1(e,n),Kn(e,n,l,s),n.child;case 6:return e===null&&Ig(n),null;case 13:return N1(e,n,s);case 4:return mj(n,n.stateNode.containerInfo),r=n.pendingProps,e===null?n.child=Wl(n,null,r,s):Kn(e,n,r,s),n.child;case 11:return r=n.type,a=n.pendingProps,a=n.elementType===r?a:Xs(r,a),ck(e,n,r,a,s);case 7:return Kn(e,n,n.pendingProps,s),n.child;case 8:return Kn(e,n,n.pendingProps.children,s),n.child;case 12:return Kn(e,n,n.pendingProps.children,s),n.child;case 10:e:{if(r=n.type._context,a=n.pendingProps,i=n.memoizedProps,l=a.value,Rt(uh,r._currentValue),r._currentValue=l,i!==null)if(or(i.value,l)){if(i.children===a.children&&!is.current){n=ha(e,n,s);break e}}else for(i=n.child,i!==null&&(i.return=n);i!==null;){var o=i.dependencies;if(o!==null){l=i.child;for(var c=o.firstContext;c!==null;){if(c.context===r){if(i.tag===1){c=aa(-1,s&-s),c.tag=2;var u=i.updateQueue;if(u!==null){u=u.shared;var d=u.pending;d===null?c.next=c:(c.next=d.next,d.next=c),u.pending=c}}i.lanes|=s,c=i.alternate,c!==null&&(c.lanes|=s),Pg(i.return,s,n),o.lanes|=s;break}c=c.next}}else if(i.tag===10)l=i.type===n.type?null:i.child;else if(i.tag===18){if(l=i.return,l===null)throw Error(be(341));l.lanes|=s,o=l.alternate,o!==null&&(o.lanes|=s),Pg(l,s,n),l=i.sibling}else l=i.child;if(l!==null)l.return=i;else for(l=i;l!==null;){if(l===n){l=null;break}if(i=l.sibling,i!==null){i.return=l.return,l=i;break}l=l.return}i=l}Kn(e,n,a.children,s),n=n.child}return n;case 9:return a=n.type,r=n.pendingProps.children,Il(n,s),a=Vs(a),r=r(a),n.flags|=1,Kn(e,n,r,s),n.child;case 14:return r=n.type,a=Xs(r,n.pendingProps),a=Xs(r.type,a),uk(e,n,r,a,s);case 15:return y1(e,n,n.type,n.pendingProps,s);case 17:return r=n.type,a=n.pendingProps,a=n.elementType===r?a:Xs(r,a),Id(e,n),n.tag=1,ls(r)?(e=!0,lh(n)):e=!1,Il(n,s),x1(n,r,a),Dg(n,r,a,s),Fg(null,n,r,!0,e,s);case 19:return S1(e,n,s);case 22:return w1(e,n,s)}throw Error(be(156,n.tag))};function U1(e,n){return mC(e,n)}function _D(e,n,s,r){this.tag=e,this.key=s,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.ref=null,this.pendingProps=n,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=r,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function Ws(e,n,s,r){return new _D(e,n,s,r)}function $j(e){return e=e.prototype,!(!e||!e.isReactComponent)}function zD(e){if(typeof e=="function")return $j(e)?1:0;if(e!=null){if(e=e.$$typeof,e===qv)return 11;if(e===Yv)return 14}return 2}function _a(e,n){var s=e.alternate;return s===null?(s=Ws(e.tag,n,e.key,e.mode),s.elementType=e.elementType,s.type=e.type,s.stateNode=e.stateNode,s.alternate=e,e.alternate=s):(s.pendingProps=n,s.type=e.type,s.flags=0,s.subtreeFlags=0,s.deletions=null),s.flags=e.flags&14680064,s.childLanes=e.childLanes,s.lanes=e.lanes,s.child=e.child,s.memoizedProps=e.memoizedProps,s.memoizedState=e.memoizedState,s.updateQueue=e.updateQueue,n=e.dependencies,s.dependencies=n===null?null:{lanes:n.lanes,firstContext:n.firstContext},s.sibling=e.sibling,s.index=e.index,s.ref=e.ref,s}function Dd(e,n,s,r,a,i){var l=2;if(r=e,typeof e=="function")$j(e)&&(l=1);else if(typeof e=="string")l=5;else e:switch(e){case fl:return Si(s.children,a,i,n);case Gv:l=8,a|=8;break;case ag:return e=Ws(12,s,n,a|2),e.elementType=ag,e.lanes=i,e;case ig:return e=Ws(13,s,n,a),e.elementType=ig,e.lanes=i,e;case lg:return e=Ws(19,s,n,a),e.elementType=lg,e.lanes=i,e;case QS:return vf(s,a,i,n);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case YS:l=10;break e;case JS:l=9;break e;case qv:l=11;break e;case Yv:l=14;break e;case Na:l=16,r=null;break e}throw Error(be(130,e==null?e:typeof e,""))}return n=Ws(l,s,n,a),n.elementType=e,n.type=r,n.lanes=i,n}function Si(e,n,s,r){return e=Ws(7,e,r,n),e.lanes=s,e}function vf(e,n,s,r){return e=Ws(22,e,r,n),e.elementType=QS,e.lanes=s,e.stateNode={isHidden:!1},e}function Gm(e,n,s){return e=Ws(6,e,null,n),e.lanes=s,e}function qm(e,n,s){return n=Ws(4,e.children!==null?e.children:[],e.key,n),n.lanes=s,n.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},n}function UD(e,n,s,r,a){this.tag=n,this.containerInfo=e,this.finishedWork=this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.pendingContext=this.context=null,this.callbackPriority=0,this.eventTimes=Am(0),this.expirationTimes=Am(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Am(0),this.identifierPrefix=r,this.onRecoverableError=a,this.mutableSourceEagerHydrationData=null}function Tj(e,n,s,r,a,i,l,o,c){return e=new UD(e,n,s,o,c),n===1?(n=1,i===!0&&(n|=8)):n=0,i=Ws(3,null,null,n),e.current=i,i.stateNode=e,i.memoizedState={element:r,isDehydrated:s,cache:null,transitions:null,pendingSuspenseBoundaries:null},fj(i),e}function BD(e,n,s){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:hl,key:r==null?null:""+r,children:e,containerInfo:n,implementation:s}}function B1(e){if(!e)return Ha;e=e._reactInternals;e:{if(Ui(e)!==e||e.tag!==1)throw Error(be(170));var n=e;do{switch(n.tag){case 3:n=n.stateNode.context;break e;case 1:if(ls(n.type)){n=n.stateNode.__reactInternalMemoizedMergedChildContext;break e}}n=n.return}while(n!==null);throw Error(be(171))}if(e.tag===1){var s=e.type;if(ls(s))return BC(e,s,n)}return n}function W1(e,n,s,r,a,i,l,o,c){return e=Tj(s,r,!0,e,a,i,l,o,c),e.context=B1(null),s=e.current,r=qn(),a=Fa(s),i=aa(r,a),i.callback=n??null,Oa(s,i,a),e.current.lanes=a,ou(e,a,r),os(e,r),e}function jf(e,n,s,r){var a=n.current,i=qn(),l=Fa(a);return s=B1(s),n.context===null?n.context=s:n.pendingContext=s,n=aa(i,l),n.payload={element:e},r=r===void 0?null:r,r!==null&&(n.callback=r),e=Oa(a,n,l),e!==null&&(ar(e,a,l,i),$d(e,a,l)),l}function yh(e){if(e=e.current,!e.child)return null;switch(e.child.tag){case 5:return e.child.stateNode;default:return e.child.stateNode}}function bk(e,n){if(e=e.memoizedState,e!==null&&e.dehydrated!==null){var s=e.retryLane;e.retryLane=s!==0&&s<n?s:n}}function Rj(e,n){bk(e,n),(e=e.alternate)&&bk(e,n)}function WD(){return null}var H1=typeof reportError=="function"?reportError:function(e){console.error(e)};function Ij(e){this._internalRoot=e}yf.prototype.render=Ij.prototype.render=function(e){var n=this._internalRoot;if(n===null)throw Error(be(409));jf(e,n,null,null)};yf.prototype.unmount=Ij.prototype.unmount=function(){var e=this._internalRoot;if(e!==null){this._internalRoot=null;var n=e.containerInfo;Ii(function(){jf(null,e,null,null)}),n[ua]=null}};function yf(e){this._internalRoot=e}yf.prototype.unstable_scheduleHydration=function(e){if(e){var n=wC();e={blockedOn:null,target:e,priority:n};for(var s=0;s<Ca.length&&n!==0&&n<Ca[s].priority;s++);Ca.splice(s,0,e),s===0&&kC(e)}};function Pj(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function wf(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11&&(e.nodeType!==8||e.nodeValue!==" react-mount-point-unstable "))}function kk(){}function HD(e,n,s,r,a){if(a){if(typeof r=="function"){var i=r;r=function(){var u=yh(l);i.call(u)}}var l=W1(n,r,e,0,null,!1,!1,"",kk);return e._reactRootContainer=l,e[ua]=l.current,Ac(e.nodeType===8?e.parentNode:e),Ii(),l}for(;a=e.lastChild;)e.removeChild(a);if(typeof r=="function"){var o=r;r=function(){var u=yh(c);o.call(u)}}var c=Tj(e,0,!1,null,null,!1,!1,"",kk);return e._reactRootContainer=c,e[ua]=c.current,Ac(e.nodeType===8?e.parentNode:e),Ii(function(){jf(n,c,s,r)}),c}function bf(e,n,s,r,a){var i=s._reactRootContainer;if(i){var l=i;if(typeof a=="function"){var o=a;a=function(){var c=yh(l);o.call(c)}}jf(n,l,e,a)}else l=HD(s,n,e,a,r);return yh(l)}jC=function(e){switch(e.tag){case 3:var n=e.stateNode;if(n.current.memoizedState.isDehydrated){var s=Yo(n.pendingLanes);s!==0&&(Xv(n,s|1),os(n,Qt()),!(pt&6)&&(Vl=Qt()+500,ti()))}break;case 13:Ii(function(){var r=da(e,1);if(r!==null){var a=qn();ar(r,e,1,a)}}),Rj(e,1)}};Zv=function(e){if(e.tag===13){var n=da(e,134217728);if(n!==null){var s=qn();ar(n,e,134217728,s)}Rj(e,134217728)}};yC=function(e){if(e.tag===13){var n=Fa(e),s=da(e,n);if(s!==null){var r=qn();ar(s,e,n,r)}Rj(e,n)}};wC=function(){return wt};bC=function(e,n){var s=wt;try{return wt=e,n()}finally{wt=s}};xg=function(e,n,s){switch(n){case"input":if(ug(e,s),n=s.name,s.type==="radio"&&n!=null){for(s=e;s.parentNode;)s=s.parentNode;for(s=s.querySelectorAll("input[name="+JSON.stringify(""+n)+'][type="radio"]'),n=0;n<s.length;n++){var r=s[n];if(r!==e&&r.form===e.form){var a=hf(r);if(!a)throw Error(be(90));ZS(r),ug(r,a)}}}break;case"textarea":tC(e,s);break;case"select":n=s.value,n!=null&&Al(e,!!s.multiple,n,!1)}};oC=Cj;cC=Ii;var KD={usingClientEntryPoint:!1,Events:[uu,xl,hf,iC,lC,Cj]},_o={findFiberByHostInstance:ji,bundleType:0,version:"18.3.1",rendererPackageName:"react-dom"},VD={bundleType:_o.bundleType,version:_o.version,rendererPackageName:_o.rendererPackageName,rendererConfig:_o.rendererConfig,overrideHookState:null,overrideHookStateDeletePath:null,overrideHookStateRenamePath:null,overrideProps:null,overridePropsDeletePath:null,overridePropsRenamePath:null,setErrorHandler:null,setSuspenseHandler:null,scheduleUpdate:null,currentDispatcherRef:ga.ReactCurrentDispatcher,findHostInstanceByFiber:function(e){return e=hC(e),e===null?null:e.stateNode},findFiberByHostInstance:_o.findFiberByHostInstance||WD,findHostInstancesForRefresh:null,scheduleRefresh:null,scheduleRoot:null,setRefreshHandler:null,getCurrentFiber:null,reconcilerVersion:"18.3.1-next-f1338f8080-20240426"};if(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"){var Ju=__REACT_DEVTOOLS_GLOBAL_HOOK__;if(!Ju.isDisabled&&Ju.supportsFiber)try{of=Ju.inject(VD),Ar=Ju}catch{}}Cs.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=KD;Cs.createPortal=function(e,n){var s=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!Pj(n))throw Error(be(200));return BD(e,n,null,s)};Cs.createRoot=function(e,n){if(!Pj(e))throw Error(be(299));var s=!1,r="",a=H1;return n!=null&&(n.unstable_strictMode===!0&&(s=!0),n.identifierPrefix!==void 0&&(r=n.identifierPrefix),n.onRecoverableError!==void 0&&(a=n.onRecoverableError)),n=Tj(e,1,!1,null,null,s,!1,r,a),e[ua]=n.current,Ac(e.nodeType===8?e.parentNode:e),new Ij(n)};Cs.findDOMNode=function(e){if(e==null)return null;if(e.nodeType===1)return e;var n=e._reactInternals;if(n===void 0)throw typeof e.render=="function"?Error(be(188)):(e=Object.keys(e).join(","),Error(be(268,e)));return e=hC(n),e=e===null?null:e.stateNode,e};Cs.flushSync=function(e){return Ii(e)};Cs.hydrate=function(e,n,s){if(!wf(n))throw Error(be(200));return bf(null,e,n,!0,s)};Cs.hydrateRoot=function(e,n,s){if(!Pj(e))throw Error(be(405));var r=s!=null&&s.hydratedSources||null,a=!1,i="",l=H1;if(s!=null&&(s.unstable_strictMode===!0&&(a=!0),s.identifierPrefix!==void 0&&(i=s.identifierPrefix),s.onRecoverableError!==void 0&&(l=s.onRecoverableError)),n=W1(n,null,e,1,s??null,a,!1,i,l),e[ua]=n.current,Ac(e),r)for(e=0;e<r.length;e++)s=r[e],a=s._getVersion,a=a(s._source),n.mutableSourceEagerHydrationData==null?n.mutableSourceEagerHydrationData=[s,a]:n.mutableSourceEagerHydrationData.push(s,a);return new yf(n)};Cs.render=function(e,n,s){if(!wf(n))throw Error(be(200));return bf(null,e,n,!1,s)};Cs.unmountComponentAtNode=function(e){if(!wf(e))throw Error(be(40));return e._reactRootContainer?(Ii(function(){bf(null,null,e,!1,function(){e._reactRootContainer=null,e[ua]=null})}),!0):!1};Cs.unstable_batchedUpdates=Cj;Cs.unstable_renderSubtreeIntoContainer=function(e,n,s,r){if(!wf(s))throw Error(be(200));if(e==null||e._reactInternals===void 0)throw Error(be(38));return bf(e,n,s,!1,r)};Cs.version="18.3.1-next-f1338f8080-20240426";function K1(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(K1)}catch(e){console.error(e)}}K1(),KS.exports=Cs;var uo=KS.exports,V1,Nk=uo;V1=Nk.createRoot,Nk.hydrateRoot;const GD=["use","new","stop","quiet"];function Sk(e){return GD.includes(e)}function qD(e,n){return[{group:"This chat",name:"use",args:"<agent>",desc:"Talk to another agent from here on",source:"chat"},{group:"This chat",name:"new",args:"[what it is for]",desc:"Make a new agent with Agent Father",source:"chat"},{group:"This chat",name:"stop",desc:n?`Stop what ${e} is doing`:"Nothing is running",key:"Esc",off:!n,source:"chat"},{group:"This chat",name:"quiet",args:"[1d|1w|off]",desc:"No messages from agents for a while",source:"chat"}]}const YD=e=>e.replace(/^plugin-/,"").replace(/[-_]+/g," ").replace(/^./,n=>n.toUpperCase());function JD(e){return e.map(n=>({group:`From ${YD(n.plugin)}`,name:n.name,...n.args?{args:n.args}:{},desc:n.description,source:"plugin"}))}const QD=e=>!!(e.args&&e.args.startsWith("<"));let wh=[];const Jg=new Set;function XD(e){const n=e??[];JSON.stringify(n)!==JSON.stringify(wh)&&(wh=n,Jg.forEach(s=>s()))}function ZD(){return h.useSyncExternalStore(e=>(Jg.add(e),()=>Jg.delete(e)),()=>wh,()=>wh)}var eO=Object.defineProperty,ho=(e,n)=>eO(e,"name",{value:n,configurable:!0}),G1=!!(typeof window<"u"&&window.document&&window.document.createElement);function _e(e,n,{checkForDefaultPrevented:s=!0}={}){return ho(function(a){if(e==null||e(a),s===!1||!a||!a.defaultPrevented)return n==null?void 0:n(a)},"handleEvent")}ho(_e,"composeEventHandlers");function tO(e){var n;if(!G1)throw new Error("Cannot access window outside of the DOM");return((n=e==null?void 0:e.ownerDocument)==null?void 0:n.defaultView)??window}ho(tO,"getOwnerWindow");function Qg(e){if(!G1)throw new Error("Cannot access document outside of the DOM");return(e==null?void 0:e.ownerDocument)??document}ho(Qg,"getOwnerDocument");function q1(e,n=!1){const{activeElement:s}=Qg(e);if(!(s!=null&&s.nodeName))return null;if(Y1(s)&&s.contentDocument)return q1(s.contentDocument.body,n);if(n){const r=s.getAttribute("aria-activedescendant");if(r){const a=Qg(s).getElementById(r);if(a)return a}}return s}ho(q1,"getActiveElement");function Y1(e){return e.tagName==="IFRAME"}ho(Y1,"isFrame");var nO=Object.defineProperty,Mj=(e,n)=>nO(e,"name",{value:n,configurable:!0});function Xg(e,n){if(typeof e=="function")return e(n);e!=null&&(e.current=n)}Mj(Xg,"setRef");function J1(...e){return n=>{let s=!1;const r=e.map(a=>{const i=Xg(a,n);return!s&&typeof i=="function"&&(s=!0),i});if(s)return()=>{for(let a=0;a<r.length;a++){const i=r[a];typeof i=="function"?i():Xg(e[a],null)}}}}Mj(J1,"composeRefs");function $t(...e){return h.useCallback(J1(...e),e)}Mj($t,"useComposedRefs");var sO=Object.defineProperty,Bs=(e,n)=>sO(e,"name",{value:n,configurable:!0});function rO(e,n){const s=h.createContext(n);s.displayName=e+"Context";const r=Bs(i=>{const{children:l,...o}=i,c=h.useMemo(()=>o,Object.values(o));return t.jsx(s.Provider,{value:c,children:l})},"Provider");r.displayName=e+"Provider";function a(i,l={}){const{optional:o=!1}=l,c=h.useContext(s);if(c)return c;if(n!==void 0)return n;if(!o)throw new Error(`\`${i}\` must be used within \`${e}\``)}return Bs(a,"useContext"),[r,a]}Bs(rO,"createContext");function fr(e,n=[]){let s=[];function r(i,l){const o=h.createContext(l);o.displayName=i+"Context";const c=s.length;s=[...s,l];const u=Bs(f=>{var j;const{scope:m,children:p,...g}=f,v=((j=m==null?void 0:m[e])==null?void 0:j[c])||o,b=h.useMemo(()=>g,Object.values(g));return t.jsx(v.Provider,{value:b,children:p})},"Provider");u.displayName=i+"Provider";function d(f,m,p={}){var j;const{optional:g=!1}=p,v=((j=m==null?void 0:m[e])==null?void 0:j[c])||o,b=h.useContext(v);if(b)return b;if(l!==void 0)return l;if(!g)throw new Error(`\`${f}\` must be used within \`${i}\``)}return Bs(d,"useContext"),[u,d]}Bs(r,"createContext");const a=Bs(()=>{const i=s.map(l=>h.createContext(l));return Bs(function(o){const c=(o==null?void 0:o[e])||i;return h.useMemo(()=>({[`__scope${e}`]:{...o,[e]:c}}),[o,c])},"useScope")},"createScope");return a.scopeName=e,[r,Q1(a,...n)]}Bs(fr,"createContextScope");function Q1(...e){const n=e[0];if(e.length===1)return n;const s=Bs(()=>{const r=e.map(a=>({useScope:a(),scopeName:a.scopeName}));return Bs(function(i){const l=r.reduce((o,{useScope:c,scopeName:u})=>{const f=c(i)[`__scope${u}`];return{...o,...f}},{});return h.useMemo(()=>({[`__scope${n.scopeName}`]:l}),[l])},"useComposedScopes")},"createScope");return s.scopeName=n.scopeName,s}Bs(Q1,"composeContextScopes");var aO=Object.defineProperty,mr=(e,n)=>aO(e,"name",{value:n,configurable:!0});function Ka(e){const n=h.forwardRef((s,r)=>{let{children:a,...i}=s,l=null,o=!1;const c=[];Zg(a)&&typeof Qu=="function"&&(a=Qu(a._payload)),h.Children.forEach(a,m=>{var p;if(nE(m)){o=!0;const g=m;let v="child"in g.props?g.props.child:g.props.children;Zg(v)&&typeof Qu=="function"&&(v=Qu(v._payload)),l=iO(g,v),c.push((p=l==null?void 0:l.props)==null?void 0:p.children)}else c.push(m)}),l?l=h.cloneElement(l,void 0,c):!o&&h.Children.count(a)===1&&h.isValidElement(a)&&(l=a);const u=l?tE(l):void 0,d=$t(r,u);if(!l){if(a||a===0)throw new Error(o?cO(e):oO(e));return a}const f=eE(i,l.props??{});return l.type!==h.Fragment&&(f.ref=r?d:u),h.cloneElement(l,f)});return n.displayName=`${e}.Slot`,n}mr(Ka,"createSlot");var X1=Symbol.for("radix.slottable");function Z1(e){const n=mr(s=>"child"in s?s.children(s.child):s.children,"Slottable");return n.displayName=`${e}.Slottable`,n.__radixId=X1,n}mr(Z1,"createSlottable");var iO=mr((e,n)=>{if("child"in e.props){const s=e.props.child;return h.isValidElement(s)?h.cloneElement(s,void 0,e.props.children(s.props.children)):null}return h.isValidElement(n)?n:null},"getSlottableElementFromSlottable");function eE(e,n){const s={...n};for(const r in n){const a=e[r],i=n[r];/^on[A-Z]/.test(r)?a&&i?s[r]=(...o)=>{const c=i(...o);return a(...o),c}:a&&(s[r]=a):r==="style"?s[r]={...a,...i}:r==="className"&&(s[r]=[a,i].filter(Boolean).join(" "))}return{...e,...s}}mr(eE,"mergeProps");function tE(e){var r,a;let n=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,s=n&&"isReactWarning"in n&&n.isReactWarning;return s?e.ref:(n=(a=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:a.get,s=n&&"isReactWarning"in n&&n.isReactWarning,s?e.props.ref:e.props.ref||e.ref)}mr(tE,"getElementRef");function nE(e){return h.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===X1}mr(nE,"isSlottable");var lO=Symbol.for("react.lazy");function Zg(e){return e!=null&&typeof e=="object"&&"$$typeof"in e&&e.$$typeof===lO&&"_payload"in e&&sE(e._payload)}mr(Zg,"isLazyComponent");function sE(e){return typeof e=="object"&&e!==null&&"then"in e}mr(sE,"isPromiseLike");var oO=mr(e=>`${e} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,"createSlotError"),cO=mr(e=>`${e} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,"createSlottableError"),Qu=lo[" use ".trim().toString()],uO=Object.defineProperty,jn=(e,n)=>uO(e,"name",{value:n,configurable:!0});function kf(e){const n=e+"CollectionProvider",[s,r]=fr(n),[a,i]=s(n,{collectionRef:{current:null},itemMap:new Map}),l=jn(v=>{const{scope:b,children:j}=v,x=h.useRef(null),y=h.useRef(new Map).current;return t.jsx(a,{scope:b,itemMap:y,collectionRef:x,children:j})},"CollectionProvider");l.displayName=n;const o=e+"CollectionSlot",c=Ka(o),u=h.forwardRef((v,b)=>{const{scope:j,children:x}=v,y=i(o,j),w=$t(b,y.collectionRef);return t.jsx(c,{ref:w,children:x})});u.displayName=o;const d=e+"CollectionItemSlot",f="data-radix-collection-item",m=Ka(d),p=h.forwardRef((v,b)=>{const{scope:j,children:x,...y}=v,w=h.useRef(null),k=$t(b,w),N=i(d,j);return h.useEffect(()=>(N.itemMap.set(w,{ref:w,...y}),()=>void N.itemMap.delete(w))),t.jsx(m,{[f]:"",ref:k,children:x})});p.displayName=d;function g(v){const b=i(e+"CollectionConsumer",v);return h.useCallback(()=>{const x=b.collectionRef.current;if(!x)return[];const y=Array.from(x.querySelectorAll(`[${f}]`));return Array.from(b.itemMap.values()).sort((N,S)=>y.indexOf(N.ref.current)-y.indexOf(S.ref.current))},[b.collectionRef,b.itemMap])}return jn(g,"useCollection"),[{Provider:l,Slot:u,ItemSlot:p},g,r]}jn(kf,"createCollection");var Ck=new WeakMap,tn,gs,Ym=(gs=class extends Map{constructor(s){super(s);pb(this,tn);bm(this,tn,[...super.keys()]),Ck.set(this,!0)}set(s,r){return Ck.get(this)&&(this.has(s)?Mn(this,tn)[Mn(this,tn).indexOf(s)]=s:Mn(this,tn).push(s)),super.set(s,r),this}insert(s,r,a){const i=this.has(r),l=Mn(this,tn).length,o=Dj(s);let c=o>=0?o:l+o;const u=c<0||c>=l?-1:c;if(u===this.size||i&&u===this.size-1||u===-1)return this.set(r,a),this;const d=this.size+(i?0:1);o<0&&c++;const f=[...Mn(this,tn)];let m,p=!1;for(let g=c;g<d;g++)if(c===g){let v=f[g];f[g]===r&&(v=f[g+1]),i&&this.delete(r),m=this.get(v),this.set(r,a)}else{!p&&f[g-1]===r&&(p=!0);const v=f[p?g:g-1],b=m;m=this.get(v),this.delete(v),this.set(v,b)}return this}with(s,r,a){const i=new gs(this);return i.insert(s,r,a),i}before(s){const r=Mn(this,tn).indexOf(s)-1;if(!(r<0))return this.entryAt(r)}setBefore(s,r,a){const i=Mn(this,tn).indexOf(s);return i===-1?this:this.insert(i,r,a)}after(s){let r=Mn(this,tn).indexOf(s);if(r=r===-1||r===this.size-1?-1:r+1,r!==-1)return this.entryAt(r)}setAfter(s,r,a){const i=Mn(this,tn).indexOf(s);return i===-1?this:this.insert(i+1,r,a)}first(){return this.entryAt(0)}last(){return this.entryAt(-1)}clear(){return bm(this,tn,[]),super.clear()}delete(s){const r=super.delete(s);return r&&Mn(this,tn).splice(Mn(this,tn).indexOf(s),1),r}deleteAt(s){const r=this.keyAt(s);return r!==void 0?this.delete(r):!1}at(s){const r=Od(Mn(this,tn),s);if(r!==void 0)return this.get(r)}entryAt(s){const r=Od(Mn(this,tn),s);if(r!==void 0)return[r,this.get(r)]}indexOf(s){return Mn(this,tn).indexOf(s)}keyAt(s){return Od(Mn(this,tn),s)}from(s,r){const a=this.indexOf(s);if(a===-1)return;let i=a+r;return i<0&&(i=0),i>=this.size&&(i=this.size-1),this.at(i)}keyFrom(s,r){const a=this.indexOf(s);if(a===-1)return;let i=a+r;return i<0&&(i=0),i>=this.size&&(i=this.size-1),this.keyAt(i)}find(s,r){let a=0;for(const i of this){if(Reflect.apply(s,r,[i,a,this]))return i;a++}}findIndex(s,r){let a=0;for(const i of this){if(Reflect.apply(s,r,[i,a,this]))return a;a++}return-1}filter(s,r){const a=[];let i=0;for(const l of this)Reflect.apply(s,r,[l,i,this])&&a.push(l),i++;return new gs(a)}map(s,r){const a=[];let i=0;for(const l of this)a.push([l[0],Reflect.apply(s,r,[l,i,this])]),i++;return new gs(a)}reduce(...s){const[r,a]=s;let i=0,l=a??this.at(0);for(const o of this)i===0&&s.length===1?l=o:l=Reflect.apply(r,this,[l,o,i,this]),i++;return l}reduceRight(...s){const[r,a]=s;let i=a??this.at(-1);for(let l=this.size-1;l>=0;l--){const o=this.at(l);l===this.size-1&&s.length===1?i=o:i=Reflect.apply(r,this,[i,o,l,this])}return i}toSorted(s){const r=[...this.entries()].sort(s);return new gs(r)}toReversed(){const s=new gs;for(let r=this.size-1;r>=0;r--){const a=this.keyAt(r),i=this.get(a);s.set(a,i)}return s}toSpliced(...s){const r=[...this.entries()];return r.splice(...s),new gs(r)}slice(s,r){const a=new gs;let i=this.size-1;if(s===void 0)return a;s<0&&(s=s+this.size),r!==void 0&&r>0&&(i=r-1);for(let l=s;l<=i;l++){const o=this.keyAt(l),c=this.get(o);a.set(o,c)}return a}every(s,r){let a=0;for(const i of this){if(!Reflect.apply(s,r,[i,a,this]))return!1;a++}return!0}some(s,r){let a=0;for(const i of this){if(Reflect.apply(s,r,[i,a,this]))return!0;a++}return!1}},tn=new WeakMap,jn(gs,"OrderedDict"),gs);function Od(e,n){if("at"in Array.prototype)return Array.prototype.at.call(e,n);const s=rE(e,n);return s===-1?void 0:e[s]}jn(Od,"at");function rE(e,n){const s=e.length,r=Dj(n),a=r>=0?r:s+r;return a<0||a>=s?-1:a}jn(rE,"toSafeIndex");function Dj(e){return e!==e||e===0?0:Math.trunc(e)}jn(Dj,"toSafeInteger");function dO(e){const n=e+"CollectionProvider",[s,r]=fr(n),[a,i]=s(n,{collectionElement:null,collectionRef:{current:null},collectionRefObject:{current:null},itemMap:new Ym,setItemMap:jn(()=>{},"setItemMap")}),l=jn(({state:y,...w})=>y?t.jsx(c,{...w,state:y}):t.jsx(o,{...w}),"CollectionProvider");l.displayName=n;const o=jn(y=>{const w=b();return t.jsx(c,{...y,state:w})},"CollectionInit");o.displayName=n+"Init";const c=jn(y=>{const{scope:w,children:k,state:N}=y,S=h.useRef(null),[C,E]=h.useState(null),T=$t(S,E),[I,F]=N;return h.useEffect(()=>{if(!C)return;const D=lE(()=>{});return D.observe(C,{childList:!0,subtree:!0}),()=>{D.disconnect()}},[C]),t.jsx(a,{scope:w,itemMap:I,setItemMap:F,collectionRef:T,collectionRefObject:S,collectionElement:C,children:k})},"CollectionProviderImpl");c.displayName=n+"Impl";const u=e+"CollectionSlot",d=Ka(u),f=h.forwardRef((y,w)=>{const{scope:k,children:N}=y,S=i(u,k),C=$t(w,S.collectionRef);return t.jsx(d,{ref:C,children:N})});f.displayName=u;const m=e+"CollectionItemSlot",p="data-radix-collection-item",g=Ka(m),v=h.forwardRef((y,w)=>{const{scope:k,children:N,...S}=y,C=h.useRef(null),[E,T]=h.useState(null),I=$t(w,C,T),F=i(m,k),{setItemMap:D}=F,$=h.useRef(S);aE($.current,S)||($.current=S);const L=$.current;return h.useEffect(()=>{const O=L;return D(M=>E?M.has(E)?M.set(E,{...O,element:E}).toSorted(ex):(M.set(E,{...O,element:E}),M.toSorted(ex)):M),()=>{D(M=>!E||!M.has(E)?M:(M.delete(E),new Ym(M)))}},[E,L,D]),t.jsx(g,{[p]:"",ref:I,children:N})});v.displayName=m;function b(){return h.useState(new Ym)}jn(b,"useInitCollection");function j(y){const{itemMap:w}=i(e+"CollectionConsumer",y);return w}return jn(j,"useCollection"),[{Provider:l,Slot:f,ItemSlot:v},{createCollectionScope:r,useCollection:j,useInitCollection:b}]}jn(dO,"createCollection");function aE(e,n){if(e===n)return!0;if(typeof e!="object"||typeof n!="object"||e==null||n==null)return!1;const s=Object.keys(e),r=Object.keys(n);if(s.length!==r.length)return!1;for(const a of s)if(!Object.prototype.hasOwnProperty.call(n,a)||e[a]!==n[a])return!1;return!0}jn(aE,"shallowEqual");function iE(e,n){return!!(n.compareDocumentPosition(e)&Node.DOCUMENT_POSITION_PRECEDING)}jn(iE,"isElementPreceding");function ex(e,n){return!e[1].element||!n[1].element?0:iE(e[1].element,n[1].element)?-1:1}jn(ex,"sortByDocumentPosition");function lE(e){return new MutationObserver(s=>{for(const r of s)if(r.type==="childList"){e();return}})}jn(lE,"getChildListObserver");var hO=Object.defineProperty,fO=(e,n)=>hO(e,"name",{value:n,configurable:!0}),mO=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],bt=mO.reduce((e,n)=>{const s=Ka(`Primitive.${n}`),r=h.forwardRef((a,i)=>{const{asChild:l,...o}=a,c=l?s:n;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),t.jsx(c,{...o,ref:i})});return r.displayName=`Primitive.${n}`,{...e,[n]:r}},{});function Nf(e,n){e&&uo.flushSync(()=>e.dispatchEvent(n))}fO(Nf,"dispatchDiscreteCustomEvent");var pO=Object.defineProperty,gO=(e,n)=>pO(e,"name",{value:n,configurable:!0});function Yn(e){const n=h.useRef(e);return h.useEffect(()=>{n.current=e}),h.useMemo(()=>(...s)=>{var r;return(r=n.current)==null?void 0:r.call(n,...s)},[])}gO(Yn,"useCallbackRef");var xO=Object.defineProperty,un=(e,n)=>xO(e,"name",{value:n,configurable:!0}),tx="dismissableLayer.update",vO="dismissableLayer.pointerDownOutside",jO="dismissableLayer.focusOutside",Ek,Oj=h.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set,dismissableSurfaces:new Set}),Sf=h.forwardRef(un(function(n,s){const{disableOutsidePointerEvents:r=!1,deferPointerDownOutside:a=!1,onEscapeKeyDown:i,onPointerDownOutside:l,onFocusOutside:o,onInteractOutside:c,onDismiss:u,...d}=n,f=h.useContext(Oj),[m,p]=h.useState(null),g=(m==null?void 0:m.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,v]=h.useState({}),b=$t(s,p),j=Array.from(f.layers),[x]=[...f.layersWithOutsidePointerEventsDisabled].slice(-1),y=x?j.indexOf(x):-1,w=m?j.indexOf(m):-1,k=f.layersWithOutsidePointerEventsDisabled.size>0,N=w>=y,S=h.useRef(!1),C=cE(F=>{l==null||l(F),c==null||c(F),F.defaultPrevented||u==null||u()},{ownerDocument:g,deferPointerDownOutside:a,isDeferredPointerDownOutsideRef:S,dismissableSurfaces:f.dismissableSurfaces,shouldHandlePointerDownOutside:h.useCallback(F=>{if(!(F instanceof Node))return!1;const D=[...f.branches].some($=>$.contains(F));return N&&!D},[f.branches,N])}),E=uE(F=>{if(a&&S.current)return;const D=F.target;[...f.branches].some(L=>L.contains(D))||(o==null||o(F),c==null||c(F),F.defaultPrevented||u==null||u())},g),T=m?w===j.length-1:!1,I=Yn(F=>{F.key==="Escape"&&(i==null||i(F),!F.defaultPrevented&&u&&(F.preventDefault(),u()))});return h.useEffect(()=>{if(T)return g.addEventListener("keydown",I,{capture:!0}),()=>g.removeEventListener("keydown",I,{capture:!0})},[g,T,I]),h.useEffect(()=>{if(m)return r&&(f.layersWithOutsidePointerEventsDisabled.size===0&&(Ek=g.body.style.pointerEvents,g.body.style.pointerEvents="none"),f.layersWithOutsidePointerEventsDisabled.add(m)),f.layers.add(m),nx(),()=>{r&&(f.layersWithOutsidePointerEventsDisabled.delete(m),f.layersWithOutsidePointerEventsDisabled.size===0&&(g.body.style.pointerEvents=Ek))}},[m,g,r,f]),h.useEffect(()=>()=>{m&&(f.layers.delete(m),f.layersWithOutsidePointerEventsDisabled.delete(m),nx())},[m,f]),h.useEffect(()=>{const F=un(()=>v({}),"handleUpdate");return document.addEventListener(tx,F),()=>document.removeEventListener(tx,F)},[]),t.jsx(bt.div,{...d,ref:b,style:{pointerEvents:k?N?"auto":"none":void 0,...n.style},onFocusCapture:_e(n.onFocusCapture,E.onFocusCapture),onBlurCapture:_e(n.onBlurCapture,E.onBlurCapture),onPointerDownCapture:_e(n.onPointerDownCapture,C.onPointerDownCapture)})},"DismissableLayer")),yO=h.forwardRef(un(function(n,s){const r=h.useContext(Oj),a=h.useRef(null),i=$t(s,a);return h.useEffect(()=>{const l=a.current;if(l)return r.branches.add(l),()=>{r.branches.delete(l)}},[r.branches]),t.jsx(bt.div,{...n,ref:i})},"DismissableLayerBranch"));function oE(){const e=h.useContext(Oj),[n,s]=h.useState(null);return h.useEffect(()=>{if(n)return e.dismissableSurfaces.add(n),()=>{e.dismissableSurfaces.delete(n)}},[n,e.dismissableSurfaces]),s}un(oE,"useDismissableLayerSurface");var wO=un(()=>!0,"IS_TRUE");function cE(e,n){const{ownerDocument:s=globalThis==null?void 0:globalThis.document,deferPointerDownOutside:r=!1,isDeferredPointerDownOutsideRef:a,dismissableSurfaces:i,shouldHandlePointerDownOutside:l=wO}=n,o=Yn(e),c=h.useRef(!1),u=h.useRef(!1),d=h.useRef(new Map),f=h.useRef(()=>{});return h.useEffect(()=>{function m(){u.current=!1,a.current=!1,d.current.clear()}un(m,"resetOutsideInteraction");function p(){return Array.from(d.current.values()).some(Boolean)}un(p,"isOutsideInteractionIntercepted");function g(y){if(!u.current)return;const w=y.target;w instanceof Node&&[...i].some(N=>N.contains(w))||d.current.set(y.type,!0),y.type==="click"&&window.setTimeout(()=>{u.current&&f.current()},0)}un(g,"handleInteractionCapture");function v(y){u.current&&d.current.set(y.type,!1)}un(v,"handleInteractionBubble");const b=un(y=>{if(y.target&&!c.current){let w=function(){s.removeEventListener("click",f.current);const N=p();m(),N||Lj(vO,o,k,{discrete:!0})};if(un(w,"handleAndDispatchPointerDownOutsideEvent"),!l(y.target)){s.removeEventListener("click",f.current),m(),c.current=!1;return}const k={originalEvent:y};u.current=!0,a.current=r&&y.button===0,d.current.clear(),!r||y.button!==0?w():(s.removeEventListener("click",f.current),f.current=w,s.addEventListener("click",f.current,{once:!0}))}else s.removeEventListener("click",f.current),m();c.current=!1},"handlePointerDown"),j=["pointerup","mousedown","mouseup","touchstart","touchend","click"];for(const y of j)s.addEventListener(y,g,!0),s.addEventListener(y,v);const x=window.setTimeout(()=>{s.addEventListener("pointerdown",b)},0);return()=>{window.clearTimeout(x),s.removeEventListener("pointerdown",b),s.removeEventListener("click",f.current);for(const y of j)s.removeEventListener(y,g,!0),s.removeEventListener(y,v)}},[s,o,r,a,i,l]),{onPointerDownCapture:un(()=>c.current=!0,"onPointerDownCapture")}}un(cE,"usePointerDownOutside");function uE(e,n=globalThis==null?void 0:globalThis.document){const s=Yn(e),r=h.useRef(!1);return h.useEffect(()=>{const a=un(i=>{i.target&&!r.current&&Lj(jO,s,{originalEvent:i},{discrete:!1})},"handleFocus");return n.addEventListener("focusin",a),()=>n.removeEventListener("focusin",a)},[n,s]),{onFocusCapture:un(()=>r.current=!0,"onFocusCapture"),onBlurCapture:un(()=>r.current=!1,"onBlurCapture")}}un(uE,"useFocusOutside");function nx(){const e=new CustomEvent(tx);document.dispatchEvent(e)}un(nx,"dispatchUpdate");function Lj(e,n,s,{discrete:r}){const a=s.originalEvent.target,i=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:s});n&&a.addEventListener(e,n,{once:!0}),r?Nf(a,i):a.dispatchEvent(i)}un(Lj,"handleAndDispatchCustomEvent");var bO=Sf,kO=yO,cs=globalThis!=null&&globalThis.document?h.useLayoutEffect:()=>{},NO=Object.defineProperty,SO=(e,n)=>NO(e,"name",{value:n,configurable:!0}),Cf=h.forwardRef(SO(function(n,s){var c;const{container:r,...a}=n,[i,l]=h.useState(!1);cs(()=>l(!0),[]);const o=r||i&&((c=globalThis==null?void 0:globalThis.document)==null?void 0:c.body);return o?uo.createPortal(t.jsx(bt.div,{...a,ref:s}),o):null},"Portal")),CO=Object.defineProperty,fa=(e,n)=>CO(e,"name",{value:n,configurable:!0});function dE(e,n){return h.useReducer((s,r)=>n[s][r]??s,e)}fa(dE,"useStateMachine");var Br=fa(e=>{const{present:n,children:s}=e,r=hE(n),a=typeof s=="function"?s({present:r.isPresent}):h.Children.only(s),i=fE(r.ref,mE(a));return typeof s=="function"||r.isPresent?h.cloneElement(a,{ref:i}):null},"Presence");function hE(e){const[n,s]=h.useState(),r=h.useRef(null),a=h.useRef(e),i=h.useRef("none"),l=h.useRef(void 0),o=e?"mounted":"unmounted",[c,u]=dE(o,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return h.useEffect(()=>{c==="mounted"?(i.current=l.current??dl(r.current),l.current=void 0):i.current="none"},[c]),cs(()=>{const d=r.current,f=a.current;if(f!==e){const p=i.current,g=dl(d);e?(l.current=g,u("MOUNT")):g==="none"||(d==null?void 0:d.display)==="none"?u("UNMOUNT"):u(f&&p!==g?"ANIMATION_OUT":"UNMOUNT"),a.current=e}},[e,u]),cs(()=>{if(n){let d;const f=n.ownerDocument.defaultView??window,m=fa(g=>{const b=dl(r.current).includes(CSS.escape(g.animationName));if(g.target===n&&b&&(u("ANIMATION_END"),!a.current)){const j=n.style.animationFillMode;n.style.animationFillMode="forwards",d=f.setTimeout(()=>{n.style.animationFillMode==="forwards"&&(n.style.animationFillMode=j)})}},"handleAnimationEnd"),p=fa(g=>{g.target===n&&(i.current=dl(r.current))},"handleAnimationStart");return n.addEventListener("animationstart",p),n.addEventListener("animationcancel",m),n.addEventListener("animationend",m),()=>{f.clearTimeout(d),n.removeEventListener("animationstart",p),n.removeEventListener("animationcancel",m),n.removeEventListener("animationend",m)}}else u("ANIMATION_END")},[n,u]),{isPresent:["mounted","unmountSuspended"].includes(c),ref:h.useCallback(d=>{if(d){const f=getComputedStyle(d);r.current=f,l.current=dl(f)}else r.current=null;s(d)},[])}}fa(hE,"usePresence");function sx(e,n){if(typeof e=="function")return e(n);e!=null&&(e.current=n)}fa(sx,"setRef");function fE(...e){const n=h.useRef(e);return n.current=e,h.useCallback(s=>{const r=n.current;let a=!1;const i=r.map(l=>{const o=sx(l,s);return!a&&typeof o=="function"&&(a=!0),o});if(a)return()=>{for(let l=0;l<i.length;l++){const o=i[l];typeof o=="function"?o():sx(r[l],null)}}},[])}fa(fE,"useStableComposedRefs");function dl(e){return(e==null?void 0:e.animationName)||"none"}fa(dl,"getAnimationName");function mE(e){var r,a;let n=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,s=n&&"isReactWarning"in n&&n.isReactWarning;return s?e.ref:(n=(a=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:a.get,s=n&&"isReactWarning"in n&&n.isReactWarning,s?e.props.ref:e.props.ref||e.ref)}fa(mE,"getElementRef");var EO=Object.defineProperty,AO=(e,n)=>EO(e,"name",{value:n,configurable:!0}),Ak=lo[" useEffectEvent ".trim().toString()],$k=lo[" useInsertionEffect ".trim().toString()];function pE(e){if(typeof Ak=="function")return Ak(e);const n=h.useRef(()=>{throw new Error("Cannot call an event handler while rendering.")});return typeof $k=="function"?$k(()=>{n.current=e}):cs(()=>{n.current=e}),h.useMemo(()=>(...s)=>{var r;return(r=n.current)==null?void 0:r.call(n,...s)},[])}AO(pE,"useEffectEvent");var $O=Object.defineProperty,hu=(e,n)=>$O(e,"name",{value:n,configurable:!0}),TO=lo[" useInsertionEffect ".trim().toString()]||cs;function ni({prop:e,defaultProp:n,onChange:s=hu(()=>{},"onChange"),caller:r}){const[a,i,l]=gE({defaultProp:n,onChange:s}),o=e!==void 0,c=o?e:a,u=h.useCallback(d=>{var f;if(o){const m=xE(d)?d(e):d;m!==e&&((f=l.current)==null||f.call(l,m))}else i(d)},[o,e,i,l]);return[c,u]}hu(ni,"useControllableState");function gE({defaultProp:e,onChange:n}){const[s,r]=h.useState(e),a=h.useRef(s),i=h.useRef(n);return TO(()=>{i.current=n},[n]),h.useEffect(()=>{var l;a.current!==s&&((l=i.current)==null||l.call(i,s),a.current=s)},[s,a]),[s,r,i]}hu(gE,"useUncontrolledState");function xE(e){return typeof e=="function"}hu(xE,"isFunction");var Tk=Symbol("RADIX:SYNC_STATE");function RO(e,n,s,r){const{prop:a,defaultProp:i,onChange:l,caller:o}=n,c=a!==void 0,u=pE(l),d=[{...s,state:i}];r&&d.push(r);const[f,m]=h.useReducer((b,j)=>{if(j.type===Tk)return{...b,state:j.state};const x=e(b,j);return c&&!Object.is(x.state,b.state)&&u(x.state),x},...d),p=f.state,g=h.useRef(p);h.useEffect(()=>{g.current!==p&&(g.current=p,c||u(p))},[p,g,c]);const v=h.useMemo(()=>a!==void 0?{...f,state:a}:f,[f,a]);return h.useEffect(()=>{c&&!Object.is(a,f.state)&&m({type:Tk,state:a})},[a,f.state,c]),[v,m]}hu(RO,"useControllableStateReducer");var IO=Object.defineProperty,PO=(e,n)=>IO(e,"name",{value:n,configurable:!0}),MO=Object.freeze({position:"absolute",border:0,width:1,height:1,padding:0,margin:-1,overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",wordWrap:"normal"}),Fj=h.forwardRef(PO(function(n,s){return t.jsx(bt.span,{...n,ref:s,style:{...MO,...n.style}})},"VisuallyHidden")),DO=Fj,OO=Object.defineProperty,Et=(e,n)=>OO(e,"name",{value:n,configurable:!0}),vE="ToastProvider",[_j,jE,LO]=kf("Toast"),[yE,Jte]=fr("Toast",[LO]),[FO,Ef]=yE(vE),_O=Et(e=>{const{__scopeToast:n,label:s="Notification",duration:r=5e3,swipeDirection:a="right",swipeThreshold:i=50,announcerContainer:l,children:o}=e,[c,u]=h.useState(null),[d,f]=h.useState(0),m=h.useRef(!1);return s.trim()||console.error(`Invalid prop \`label\` supplied to \`${vE}\`. Expected non-empty \`string\`.`),t.jsx(_j.Provider,{scope:n,children:t.jsx(FO,{scope:n,label:s,duration:r,swipeDirection:a,swipeThreshold:i,toastCount:d,viewport:c,onViewportChange:u,onToastAdd:h.useCallback(()=>f(p=>p+1),[]),onToastRemove:h.useCallback(()=>f(p=>p-1),[]),isClosePausedRef:m,announcerContainer:l,children:o})})},"ToastProvider"),zO="ToastViewport",UO=["F8"],rx="toast.viewportPause",ax="toast.viewportResume",BO=h.forwardRef(Et(function(n,s){const{__scopeToast:r,hotkey:a=UO,label:i="Notifications ({hotkey})",...l}=n,o=Ef(zO,r),c=jE(r),u=h.useRef(null),d=h.useRef(null),f=h.useRef(null),m=h.useRef(null),p=$t(s,m,o.onViewportChange),g=a.join("+").replace(/Key/g,"").replace(/Digit/g,""),v=o.toastCount>0;h.useEffect(()=>{const j=Et(x=>{var w;a.length!==0&&a.every(k=>x[k]||x.code===k)&&((w=m.current)==null||w.focus())},"handleKeyDown");return document.addEventListener("keydown",j),()=>document.removeEventListener("keydown",j)},[a]),h.useEffect(()=>{const j=u.current,x=m.current;if(v&&j&&x){const y=Et(()=>{if(!o.isClosePausedRef.current){const S=new CustomEvent(rx);x.dispatchEvent(S),o.isClosePausedRef.current=!0}},"handlePause"),w=Et(()=>{if(o.isClosePausedRef.current){const S=new CustomEvent(ax);x.dispatchEvent(S),o.isClosePausedRef.current=!1}},"handleResume"),k=Et(S=>{!j.contains(S.relatedTarget)&&w()},"handleFocusOutResume"),N=Et(()=>{j.contains(document.activeElement)||w()},"handlePointerLeaveResume");return j.addEventListener("focusin",y),j.addEventListener("focusout",k),j.addEventListener("pointermove",y),j.addEventListener("pointerleave",N),window.addEventListener("blur",y),window.addEventListener("focus",w),()=>{j.removeEventListener("focusin",y),j.removeEventListener("focusout",k),j.removeEventListener("pointermove",y),j.removeEventListener("pointerleave",N),window.removeEventListener("blur",y),window.removeEventListener("focus",w)}}},[v,o.isClosePausedRef]);const b=h.useCallback(({tabbingDirection:j})=>{const y=c().map(w=>{const k=w.ref.current,N=[k,...NE(k)];return j==="forwards"?N:N.reverse()});return(j==="forwards"?y.reverse():y).flat()},[c]);return h.useEffect(()=>{const j=m.current;if(j){const x=Et(y=>{var N,S,C;const w=y.altKey||y.ctrlKey||y.metaKey;if(y.key==="Tab"&&!w){const E=document.activeElement,T=y.shiftKey;if(y.target===j&&T){(N=d.current)==null||N.focus();return}const D=b({tabbingDirection:T?"backwards":"forwards"}),$=D.findIndex(L=>L===E);Ld(D.slice($+1))?y.preventDefault():T?(S=d.current)==null||S.focus():(C=f.current)==null||C.focus()}},"handleKeyDown");return j.addEventListener("keydown",x),()=>j.removeEventListener("keydown",x)}},[c,b]),t.jsxs(kO,{ref:u,role:"region","aria-label":i.replace("{hotkey}",g),tabIndex:-1,style:{pointerEvents:v?void 0:"none"},children:[v&&t.jsx(Rk,{ref:d,onFocusFromOutsideViewport:()=>{const j=b({tabbingDirection:"forwards"});Ld(j)}}),t.jsx(_j.Slot,{scope:r,children:t.jsx(bt.ol,{tabIndex:-1,...l,ref:p})}),v&&t.jsx(Rk,{ref:f,onFocusFromOutsideViewport:()=>{const j=b({tabbingDirection:"backwards"});Ld(j)}})]})},"ToastViewport")),WO="ToastFocusProxy",Rk=h.forwardRef(Et(function(n,s){const{__scopeToast:r,onFocusFromOutsideViewport:a,...i}=n,l=Ef(WO,r);return t.jsx(Fj,{tabIndex:0,...i,ref:s,style:{position:"fixed"},onFocus:o=>{var d;const c=o.relatedTarget;!((d=l.viewport)!=null&&d.contains(c))&&a()}})},"ToastFocusProxy")),Af="Toast",HO="toast.swipeStart",KO="toast.swipeMove",VO="toast.swipeCancel",GO="toast.swipeEnd",qO=h.forwardRef(Et(function(n,s){const{forceMount:r,open:a,defaultOpen:i,onOpenChange:l,...o}=n,[c,u]=ni({prop:a,defaultProp:i??!0,onChange:l,caller:Af});return t.jsx(Br,{present:r||c,children:t.jsx(QO,{open:c,...o,ref:s,onClose:()=>u(!1),onPause:Yn(n.onPause),onResume:Yn(n.onResume),onSwipeStart:_e(n.onSwipeStart,d=>{d.currentTarget.setAttribute("data-swipe","start")}),onSwipeMove:_e(n.onSwipeMove,d=>{const{x:f,y:m}=d.detail.delta;d.currentTarget.setAttribute("data-swipe","move"),d.currentTarget.style.setProperty("--radix-toast-swipe-move-x",`${f}px`),d.currentTarget.style.setProperty("--radix-toast-swipe-move-y",`${m}px`)}),onSwipeCancel:_e(n.onSwipeCancel,d=>{d.currentTarget.setAttribute("data-swipe","cancel"),d.currentTarget.style.removeProperty("--radix-toast-swipe-move-x"),d.currentTarget.style.removeProperty("--radix-toast-swipe-move-y"),d.currentTarget.style.removeProperty("--radix-toast-swipe-end-x"),d.currentTarget.style.removeProperty("--radix-toast-swipe-end-y")}),onSwipeEnd:_e(n.onSwipeEnd,d=>{const{x:f,y:m}=d.detail.delta;d.currentTarget.setAttribute("data-swipe","end"),d.currentTarget.style.removeProperty("--radix-toast-swipe-move-x"),d.currentTarget.style.removeProperty("--radix-toast-swipe-move-y"),d.currentTarget.style.setProperty("--radix-toast-swipe-end-x",`${f}px`),d.currentTarget.style.setProperty("--radix-toast-swipe-end-y",`${m}px`),u(!1)})})})},"Toast")),[YO,JO]=yE(Af,{onClose(){}}),QO=h.forwardRef(Et(function(n,s){const{__scopeToast:r,type:a="foreground",duration:i,open:l,onClose:o,onEscapeKeyDown:c,onPause:u,onResume:d,onSwipeStart:f,onSwipeMove:m,onSwipeCancel:p,onSwipeEnd:g,...v}=n,b=Ef(Af,r),j=jE(r),[x,y]=h.useState(null),w=$t(s,y),k=h.useRef(null),N=h.useRef(null),S=i||b.duration,C=h.useRef(0),E=h.useRef(S),T=h.useRef(0),{onToastAdd:I,onToastRemove:F}=b,D=Yn(()=>{var M;(x==null?void 0:x.contains(document.activeElement))&&((M=b.viewport)==null||M.focus()),o()}),$=h.useCallback(O=>{!O||O===1/0||(window.clearTimeout(T.current),C.current=new Date().getTime(),T.current=window.setTimeout(D,O))},[D]);h.useEffect(()=>{const O=b.viewport;if(O){const M=Et(()=>{$(E.current),d==null||d()},"handleResume"),P=Et(()=>{const H=new Date().getTime()-C.current;E.current=E.current-H,window.clearTimeout(T.current),u==null||u()},"handlePause");return O.addEventListener(rx,P),O.addEventListener(ax,M),()=>{O.removeEventListener(rx,P),O.removeEventListener(ax,M)}}},[b.viewport,S,u,d,$]),h.useEffect(()=>{l&&!b.isClosePausedRef.current&&$(S)},[l,S,b.isClosePausedRef,$]),h.useEffect(()=>()=>{window.clearTimeout(T.current)},[]),h.useEffect(()=>(I(),()=>F()),[I,F]);const L=h.useMemo(()=>x?zj(x):null,[x]);return b.viewport?t.jsxs(t.Fragment,{children:[L&&t.jsx(XO,{__scopeToast:r,role:"status","aria-live":a==="foreground"?"assertive":"polite",children:L}),t.jsx(YO,{scope:r,onClose:D,children:uo.createPortal(t.jsx(_j.ItemSlot,{scope:r,children:t.jsx(bO,{asChild:!0,onEscapeKeyDown:_e(c,O=>{j().some(P=>{var H;return(H=P.ref.current)==null?void 0:H.contains(O.target)})||D()}),children:t.jsx(bt.li,{tabIndex:0,"data-state":l?"open":"closed","data-swipe-direction":b.swipeDirection,...v,ref:w,style:{userSelect:"none",touchAction:"none",...n.style},onKeyDown:_e(n.onKeyDown,O=>{O.key==="Escape"&&(c==null||c(O.nativeEvent),O.nativeEvent.defaultPrevented||D())}),onPointerDown:_e(n.onPointerDown,O=>{O.button===0&&(k.current={x:O.clientX,y:O.clientY})}),onPointerMove:_e(n.onPointerMove,O=>{if(!k.current)return;const M=O.clientX-k.current.x,P=O.clientY-k.current.y,H=!!N.current,U=["left","right"].includes(b.swipeDirection),V=["left","up"].includes(b.swipeDirection)?Math.min:Math.max,z=U?V(0,M):0,X=U?0:V(0,P),K=O.pointerType==="touch"?10:2,ee={x:z,y:X},ce={originalEvent:O,delta:ee};H?(N.current=ee,Qo(KO,m,ce,{discrete:!1})):Ik(ee,b.swipeDirection,K)?(N.current=ee,Qo(HO,f,ce,{discrete:!1}),O.target.setPointerCapture(O.pointerId)):(Math.abs(M)>K||Math.abs(P)>K)&&(k.current=null)}),onPointerUp:_e(n.onPointerUp,O=>{const M=N.current,P=O.target;if(P.hasPointerCapture(O.pointerId)&&P.releasePointerCapture(O.pointerId),N.current=null,k.current=null,M){const H=O.currentTarget,U={originalEvent:O,delta:M};Ik(M,b.swipeDirection,b.swipeThreshold)?Qo(GO,g,U,{discrete:!0}):Qo(VO,p,U,{discrete:!0}),H.addEventListener("click",V=>V.preventDefault(),{once:!0})}})})})}),b.viewport)})]}):null},"ToastImpl")),XO=Et(e=>{const{__scopeToast:n,children:s,...r}=e,a=Ef(Af,n),[i,l]=h.useState(!1),[o,c]=h.useState(!1);return bE(()=>l(!0)),h.useEffect(()=>{const u=window.setTimeout(()=>c(!0),1e3);return()=>window.clearTimeout(u)},[]),o?null:t.jsx(Cf,{asChild:!0,container:a.announcerContainer||void 0,children:t.jsx(Fj,{...r,children:i&&t.jsxs(t.Fragment,{children:[a.label," ",s]})})})},"ToastAnnounce"),ZO=h.forwardRef(Et(function(n,s){const{__scopeToast:r,...a}=n;return t.jsx(bt.div,{...a,ref:s})},"ToastTitle")),eL=h.forwardRef(Et(function(n,s){const{__scopeToast:r,...a}=n;return t.jsx(bt.div,{...a,ref:s})},"ToastDescription")),tL="ToastAction",nL=h.forwardRef(Et(function(n,s){const{altText:r,...a}=n;return r.trim()?t.jsx(wE,{altText:r,asChild:!0,children:t.jsx(rL,{...a,ref:s})}):(console.error(`Invalid prop \`altText\` supplied to \`${tL}\`. Expected non-empty \`string\`.`),null)},"ToastAction")),sL="ToastClose",rL=h.forwardRef(Et(function(n,s){const{__scopeToast:r,...a}=n,i=JO(sL,r);return t.jsx(wE,{asChild:!0,children:t.jsx(bt.button,{type:"button",...a,ref:s,onClick:_e(n.onClick,i.onClose)})})},"ToastClose")),wE=h.forwardRef(Et(function(n,s){const{__scopeToast:r,altText:a,...i}=n;return t.jsx(bt.div,{"data-radix-toast-announce-exclude":"","data-radix-toast-announce-alt":a||void 0,...i,ref:s})},"ToastAnnounceExclude"));function zj(e){const n=[];return Array.from(e.childNodes).forEach(r=>{if(r.nodeType===r.TEXT_NODE&&r.textContent&&n.push(r.textContent),kE(r)){const a=r.ariaHidden||r.hidden||r.style.display==="none",i=r.dataset.radixToastAnnounceExclude==="";if(!a)if(i){const l=r.dataset.radixToastAnnounceAlt;l&&n.push(l)}else n.push(...zj(r))}}),n}Et(zj,"getAnnounceTextContent");function Qo(e,n,s,{discrete:r}){const a=s.originalEvent.currentTarget,i=new CustomEvent(e,{bubbles:!0,cancelable:!0,detail:s});n&&a.addEventListener(e,n,{once:!0}),r?Nf(a,i):a.dispatchEvent(i)}Et(Qo,"handleAndDispatchCustomEvent");var Ik=Et((e,n,s=0)=>{const r=Math.abs(e.x),a=Math.abs(e.y),i=r>a;return n==="left"||n==="right"?i&&r>s:!i&&a>s},"isDeltaInDirection");function bE(e=()=>{}){const n=Yn(e);cs(()=>{let s=0,r=0;return s=window.requestAnimationFrame(()=>r=window.requestAnimationFrame(n)),()=>{window.cancelAnimationFrame(s),window.cancelAnimationFrame(r)}},[n])}Et(bE,"useNextFrame");function kE(e){return e.nodeType===e.ELEMENT_NODE}Et(kE,"isHTMLElement");function NE(e){const n=[],s=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:Et(r=>{const a=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||a?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP},"acceptNode")});for(;s.nextNode();)n.push(s.currentNode);return n}Et(NE,"getTabbableCandidates");function Ld(e){const n=document.activeElement;return e.some(s=>s===n?!0:(s.focus(),document.activeElement!==n))}Et(Ld,"focusFirst");var Pk=_O,Mk=BO,aL=qO,iL=ZO,lL=eL,oL=nL,cL=Object.defineProperty,uL=(e,n)=>cL(e,"name",{value:n,configurable:!0}),dL=lo[" useId ".trim().toString()]||(()=>{}),hL=0;function ir(e){const[n,s]=h.useState(dL());return cs(()=>{e||s(r=>r??String(hL++))},[e]),e||(n?`radix-${n}`:"")}uL(ir,"useId");const fL=["top","right","bottom","left"],Va=Math.min,ia=Math.max,bh=Math.round,Xu=Math.floor,la=e=>({x:e,y:e}),mL={left:"right",right:"left",bottom:"top",top:"bottom"};function SE(e,n,s){return ia(e,Va(n,s))}function ma(e,n){return typeof e=="function"?e(n):e}function Ga(e){return e.split("-")[0]}function fo(e){return e.split("-")[1]}function Uj(e){return e==="x"?"y":"x"}function Bj(e){return e==="y"?"height":"width"}function Cr(e){const n=e[0];return n==="t"||n==="b"?"y":"x"}function Wj(e){return Uj(Cr(e))}function pL(e,n,s){s===void 0&&(s=!1);const r=fo(e),a=Wj(e),i=Bj(a);let l=a==="x"?r===(s?"end":"start")?"right":"left":r==="start"?"bottom":"top";return n.reference[i]>n.floating[i]&&(l=kh(l)),[l,kh(l)]}function gL(e){const n=kh(e);return[ix(e),n,ix(n)]}function ix(e){return e.includes("start")?e.replace("start","end"):e.replace("end","start")}const Dk=["left","right"],Ok=["right","left"],xL=["top","bottom"],vL=["bottom","top"];function jL(e,n,s){switch(e){case"top":case"bottom":return s?n?Ok:Dk:n?Dk:Ok;case"left":case"right":return n?xL:vL;default:return[]}}function yL(e,n,s,r){const a=fo(e);let i=jL(Ga(e),s==="start",r);return a&&(i=i.map(l=>l+"-"+a),n&&(i=i.concat(i.map(ix)))),i}function kh(e){const n=Ga(e);return mL[n]+e.slice(n.length)}function wL(e){var n,s,r,a;return{top:(n=e.top)!=null?n:0,right:(s=e.right)!=null?s:0,bottom:(r=e.bottom)!=null?r:0,left:(a=e.left)!=null?a:0}}function CE(e){return typeof e!="number"?wL(e):{top:e,right:e,bottom:e,left:e}}function Nh(e){const{x:n,y:s,width:r,height:a}=e;return{width:r,height:a,top:s,left:n,right:n+r,bottom:s+a,x:n,y:s}}function Lk(e,n,s){let{reference:r,floating:a}=e;const i=Cr(n),l=Wj(n),o=Bj(l),c=Ga(n),u=i==="y",d=r.x+r.width/2-a.width/2,f=r.y+r.height/2-a.height/2,m=r[o]/2-a[o]/2;let p;switch(c){case"top":p={x:d,y:r.y-a.height};break;case"bottom":p={x:d,y:r.y+r.height};break;case"right":p={x:r.x+r.width,y:f};break;case"left":p={x:r.x-a.width,y:f};break;default:p={x:r.x,y:r.y}}const g=fo(n);return g&&(p[l]+=m*(g==="end"?1:-1)*(s&&u?-1:1)),p}async function bL(e,n){var s;n===void 0&&(n={});const{x:r,y:a,platform:i,rects:l,elements:o,strategy:c}=e,{boundary:u="clippingAncestors",rootBoundary:d="viewport",elementContext:f="floating",altBoundary:m=!1,padding:p=0}=ma(n,e),g=CE(p),b=o[m?f==="floating"?"reference":"floating":f],j=Nh(await i.getClippingRect({element:(s=await(i.isElement==null?void 0:i.isElement(b)))==null||s?b:b.contextElement||await(i.getDocumentElement==null?void 0:i.getDocumentElement(o.floating)),boundary:u,rootBoundary:d,strategy:c})),x=f==="floating"?{x:r,y:a,width:l.floating.width,height:l.floating.height}:l.reference,y=await(i.getOffsetParent==null?void 0:i.getOffsetParent(o.floating)),w=await(i.isElement==null?void 0:i.isElement(y))&&await(i.getScale==null?void 0:i.getScale(y))||{x:1,y:1},k=Nh(i.convertOffsetParentRelativeRectToViewportRelativeRect?await i.convertOffsetParentRelativeRectToViewportRelativeRect({elements:o,rect:x,offsetParent:y,strategy:c}):x);return{top:(j.top-k.top+g.top)/w.y,bottom:(k.bottom-j.bottom+g.bottom)/w.y,left:(j.left-k.left+g.left)/w.x,right:(k.right-j.right+g.right)/w.x}}const kL=50,NL=async(e,n,s)=>{const{placement:r="bottom",strategy:a="absolute",middleware:i=[],platform:l}=s,o=l.detectOverflow?l:{...l,detectOverflow:bL},c=await(l.isRTL==null?void 0:l.isRTL(n));let u=await l.getElementRects({reference:e,floating:n,strategy:a}),{x:d,y:f}=Lk(u,r,c),m=r,p=0;const g={};for(let v=0;v<i.length;v++){const b=i[v];if(!b)continue;const{name:j,fn:x}=b,{x:y,y:w,data:k,reset:N}=await x({x:d,y:f,initialPlacement:r,placement:m,strategy:a,middlewareData:g,rects:u,platform:o,elements:{reference:e,floating:n}});d=y??d,f=w??f,g[j]={...g[j],...k},N&&p<kL&&(p++,typeof N=="object"&&(N.placement&&(m=N.placement),N.rects&&(u=N.rects===!0?await l.getElementRects({reference:e,floating:n,strategy:a}):N.rects),{x:d,y:f}=Lk(u,m,c)),v=-1)}return{x:d,y:f,placement:m,strategy:a,middlewareData:g}},SL=e=>({name:"arrow",options:e,async fn(n){const{x:s,y:r,placement:a,rects:i,platform:l,elements:o,middlewareData:c}=n,{element:u,padding:d=0}=ma(e,n)||{};if(u==null)return{};const f=CE(d),m={x:s,y:r},p=Wj(a),g=Bj(p),v=await l.getDimensions(u),b=p==="y",j=b?"top":"left",x=b?"bottom":"right",y=b?"clientHeight":"clientWidth",w=i.reference[g]+i.reference[p]-m[p]-i.floating[g],k=m[p]-i.reference[p],N=await(l.getOffsetParent==null?void 0:l.getOffsetParent(u));let S=N?N[y]:0;(!S||!await(l.isElement==null?void 0:l.isElement(N)))&&(S=o.floating[y]||i.floating[g]);const C=w/2-k/2,E=S/2-v[g]/2-1,T=Va(f[j],E),I=Va(f[x],E),F=S-v[g]-I,D=S/2-v[g]/2+C,$=SE(T,D,F),L=!c.arrow&&fo(a)!=null&&D!==$&&i.reference[g]/2-(D<T?T:I)-v[g]/2<0,O=L?D<T?D-T:D-F:0;return{[p]:m[p]+O,data:{[p]:$,centerOffset:D-$-O,...L&&{alignmentOffset:O}},reset:L}}}),CL=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(n){var s,r;const{placement:a,middlewareData:i,rects:l,initialPlacement:o,platform:c,elements:u}=n,{mainAxis:d=!0,crossAxis:f=!0,fallbackPlacements:m,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:g="none",flipAlignment:v=!0,...b}=ma(e,n);if((s=i.arrow)!=null&&s.alignmentOffset)return{};const j=Ga(a),x=Cr(o),y=Ga(o)===o,w=await(c.isRTL==null?void 0:c.isRTL(u.floating)),k=m||(y||!v?[kh(o)]:gL(o)),N=g!=="none";!m&&N&&k.push(...yL(o,v,g,w));const S=[o,...k],C=await c.detectOverflow(n,b),E=[];let T=((r=i.flip)==null?void 0:r.overflows)||[];if(d&&E.push(C[j]),f){const $=pL(a,l,w);E.push(C[$[0]],C[$[1]])}if(T=[...T,{placement:a,overflows:E}],!E.every($=>$<=0)){var I,F;const $=(((I=i.flip)==null?void 0:I.index)||0)+1,L=S[$];if(L&&(!(f==="alignment"?x!==Cr(L):!1)||T.every(P=>Cr(P.placement)===x?P.overflows[0]>0:!0)))return{data:{index:$,overflows:T},reset:{placement:L}};let O=(F=T.filter(M=>M.overflows[0]<=0).sort((M,P)=>M.overflows[1]-P.overflows[1])[0])==null?void 0:F.placement;if(!O)switch(p){case"bestFit":{var D;const M=(D=T.filter(P=>{if(N){const H=Cr(P.placement);return H===x||H==="y"}return!0}).map(P=>[P.placement,P.overflows.filter(H=>H>0).reduce((H,U)=>H+U,0)]).sort((P,H)=>P[1]-H[1])[0])==null?void 0:D[0];M&&(O=M);break}case"initialPlacement":O=o;break}if(a!==O)return{reset:{placement:O}}}return{}}}};function Fk(e,n){return{top:e.top-n.height,right:e.right-n.width,bottom:e.bottom-n.height,left:e.left-n.width}}function _k(e){return fL.some(n=>e[n]>=0)}const EL=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(n){const{rects:s,platform:r}=n,{strategy:a="referenceHidden",...i}=ma(e,n);switch(a){case"referenceHidden":{const l=await r.detectOverflow(n,{...i,elementContext:"reference"}),o=Fk(l,s.reference);return{data:{referenceHiddenOffsets:o,referenceHidden:_k(o)}}}case"escaped":{const l=await r.detectOverflow(n,{...i,altBoundary:!0}),o=Fk(l,s.floating);return{data:{escapedOffsets:o,escaped:_k(o)}}}default:return{}}}}},EE=new Set(["left","top"]);async function AL(e,n){const{placement:s,platform:r,elements:a}=e,i=await(r.isRTL==null?void 0:r.isRTL(a.floating)),l=Ga(s),o=fo(s),c=Cr(s)==="y",u=EE.has(l)?-1:1,d=i&&c?-1:1,f=ma(n,e);let{mainAxis:m,crossAxis:p,alignmentAxis:g}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return o&&typeof g=="number"&&(p=o==="end"?g*-1:g),c?{x:p*d,y:m*u}:{x:m*u,y:p*d}}const $L=function(e){return e===void 0&&(e=0),{name:"offset",options:e,async fn(n){var s,r;const{x:a,y:i,placement:l,middlewareData:o}=n,c=await AL(n,e);return l===((s=o.offset)==null?void 0:s.placement)&&(r=o.arrow)!=null&&r.alignmentOffset?{}:{x:a+c.x,y:i+c.y,data:{...c,placement:l}}}}},TL=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(n){const{x:s,y:r,placement:a,platform:i}=n,{mainAxis:l=!0,crossAxis:o=!1,limiter:c={fn:x=>{let{x:y,y:w}=x;return{x:y,y:w}}},...u}=ma(e,n),d={x:s,y:r},f=await i.detectOverflow(n,u),m=Cr(a),p=Uj(m);let g=d[p],v=d[m];const b=(x,y)=>SE(y+f[x==="y"?"top":"left"],y,y-f[x==="y"?"bottom":"right"]);l&&(g=b(p,g)),o&&(v=b(m,v));const j=c.fn({...n,[p]:g,[m]:v});return{...j,data:{x:j.x-s,y:j.y-r,enabled:{[p]:l,[m]:o}}}}}},RL=function(e){return e===void 0&&(e={}),{options:e,fn(n){var s,r;const{x:a,y:i,placement:l,rects:o,middlewareData:c}=n,{offset:u=0,mainAxis:d=!0,crossAxis:f=!0}=ma(e,n),m={x:a,y:i},p=Cr(l),g=Uj(p);let v=m[g],b=m[p];const j=ma(u,n),x=typeof j=="number"?{mainAxis:j,crossAxis:0}:{mainAxis:(s=j.mainAxis)!=null?s:0,crossAxis:(r=j.crossAxis)!=null?r:0};if(d){const k=g==="y"?"height":"width",N=o.reference[g]-o.floating[k]+x.mainAxis,S=o.reference[g]+o.reference[k]-x.mainAxis;v<N?v=N:v>S&&(v=S)}if(f){var y,w;const k=g==="y"?"width":"height",N=EE.has(Ga(l)),S=o.reference[p]-o.floating[k]+(N&&((y=c.offset)==null?void 0:y[p])||0)+(N?0:x.crossAxis),C=o.reference[p]+o.reference[k]+(N?0:((w=c.offset)==null?void 0:w[p])||0)-(N?x.crossAxis:0);b<S?b=S:b>C&&(b=C)}return{[g]:v,[p]:b}}}},IL=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(n){const{placement:s,rects:r,platform:a,elements:i}=n,{apply:l=()=>{},...o}=ma(e,n),c=await a.detectOverflow(n,o),u=Ga(s),d=fo(s),f=Cr(s)==="y",{width:m,height:p}=r.floating;let g,v;u==="top"||u==="bottom"?(g=u,v=d===(await(a.isRTL==null?void 0:a.isRTL(i.floating))?"start":"end")?"left":"right"):(v=u,g=d==="end"?"top":"bottom");const b=p-c.top-c.bottom,j=m-c.left-c.right,x=Va(p-c[g],b),y=Va(m-c[v],j),w=n.middlewareData.shift,k=!w;let N=x,S=y;w!=null&&w.enabled.x&&(S=j),w!=null&&w.enabled.y&&(N=b),k&&!d&&(f?S=m-2*ia(c.left,c.right):N=p-2*ia(c.top,c.bottom)),await l({...n,availableWidth:S,availableHeight:N});const C=await a.getDimensions(i.floating);return m!==C.width||p!==C.height?{reset:{rects:!0}}:{}}}};function $f(){return typeof window<"u"}function mo(e){return AE(e)?(e.nodeName||"").toLowerCase():"#document"}function us(e){var n;return(e==null||(n=e.ownerDocument)==null?void 0:n.defaultView)||window}function xa(e){var n;return(n=(AE(e)?e.ownerDocument:e.document)||window.document)==null?void 0:n.documentElement}function AE(e){return $f()?e instanceof Node||e instanceof us(e).Node:!1}function Pr(e){return $f()?e instanceof Element||e instanceof us(e).Element:!1}function si(e){return $f()?e instanceof HTMLElement||e instanceof us(e).HTMLElement:!1}function zk(e){return!$f()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof us(e).ShadowRoot}function Tf(e){const{overflow:n,overflowX:s,overflowY:r,display:a}=Mr(e);return/auto|scroll|overlay|hidden|clip/.test(n+r+s)&&a!=="inline"&&a!=="contents"}function PL(e){return/^(table|td|th)$/.test(mo(e))}function Rf(e){try{if(e.matches(":popover-open"))return!0}catch{}try{return e.matches(":modal")}catch{return!1}}const ML=/transform|translate|scale|rotate|perspective|filter/,DL=/paint|layout|strict|content/,hi=e=>!!e&&e!=="none";let Jm;function Hj(e){const n=Pr(e)?Mr(e):e;return hi(n.transform)||hi(n.translate)||hi(n.scale)||hi(n.rotate)||hi(n.perspective)||!Kj()&&(hi(n.backdropFilter)||hi(n.filter))||ML.test(n.willChange||"")||DL.test(n.contain||"")}function OL(e){let n=Pi(e);for(;si(n)&&!Lc(n);){if(Hj(n))return n;if(Rf(n))return null;n=Pi(n)}return null}function Kj(){return Jm==null&&(Jm=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),Jm}function Lc(e){return/^(html|body|#document)$/.test(mo(e))}function Mr(e){return us(e).getComputedStyle(e)}function If(e){return Pr(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Pi(e){if(mo(e)==="html")return e;const n=e.assignedSlot||e.parentNode||zk(e)&&e.host||xa(e);return zk(n)?n.host:n}function $E(e){const n=Pi(e);return Lc(n)?(e.ownerDocument||e).body:si(n)&&Tf(n)?n:$E(n)}function Fc(e,n,s){var r;n===void 0&&(n=[]),s===void 0&&(s=!0);const a=$E(e),i=a===((r=e.ownerDocument)==null?void 0:r.body),l=us(a);if(i){const o=lx(l);return n.concat(l,l.visualViewport||[],Tf(a)?a:[],o&&s?Fc(o):[])}else return n.concat(a,Fc(a,[],s))}function lx(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function TE(e){const n=Mr(e);let s=parseFloat(n.width)||0,r=parseFloat(n.height)||0;const a=si(e),i=a?e.offsetWidth:s,l=a?e.offsetHeight:r,o=bh(s)!==i||bh(r)!==l;return o&&(s=i,r=l),{width:s,height:r,$:o}}function Vj(e){return Pr(e)?e:e.contextElement}function Ml(e){const n=Vj(e);if(!si(n))return la(1);const s=n.getBoundingClientRect(),{width:r,height:a,$:i}=TE(n);let l=(i?bh(s.width):s.width)/r,o=(i?bh(s.height):s.height)/a;return(!l||!Number.isFinite(l))&&(l=1),(!o||!Number.isFinite(o))&&(o=1),{x:l,y:o}}const LL=la(0);function RE(e){const n=us(e);return!Kj()||!n.visualViewport?LL:{x:n.visualViewport.offsetLeft,y:n.visualViewport.offsetTop}}function FL(e,n,s){return n===void 0&&(n=!1),!!s&&n&&s===us(e)}function Mi(e,n,s,r){n===void 0&&(n=!1),s===void 0&&(s=!1);const a=e.getBoundingClientRect(),i=Vj(e);let l=la(1);n&&(r?Pr(r)&&(l=Ml(r)):l=Ml(e));const o=FL(i,s,r)?RE(i):la(0);let c=(a.left+o.x)/l.x,u=(a.top+o.y)/l.y,d=a.width/l.x,f=a.height/l.y;if(i&&r){const m=us(i),p=Pr(r)?us(r):r;let g=m,v=lx(g);for(;v&&p!==g;){const b=Ml(v),j=v.getBoundingClientRect(),x=Mr(v),y=j.left+(v.clientLeft+parseFloat(x.paddingLeft))*b.x,w=j.top+(v.clientTop+parseFloat(x.paddingTop))*b.y;c*=b.x,u*=b.y,d*=b.x,f*=b.y,c+=y,u+=w,g=us(v),v=lx(g)}}return Nh({width:d,height:f,x:c,y:u})}function Pf(e,n){const s=If(e).scrollLeft;return n?n.left+s:Mi(xa(e)).left+s}function IE(e,n){const s=e.getBoundingClientRect(),r=s.left+n.scrollLeft-Pf(e,s),a=s.top+n.scrollTop;return{x:r,y:a}}function _L(e){let{elements:n,rect:s,offsetParent:r,strategy:a}=e;const i=a==="fixed",l=xa(r),o=n?Rf(n.floating):!1;if(r===l||o&&i)return s;let c={scrollLeft:0,scrollTop:0},u=la(1);const d=la(0),f=si(r);if((f||!i)&&((mo(r)!=="body"||Tf(l))&&(c=If(r)),f)){const p=Mi(r);u=Ml(r),d.x=p.x+r.clientLeft,d.y=p.y+r.clientTop}const m=l&&!f&&!i?IE(l,c):la(0);return{width:s.width*u.x,height:s.height*u.y,x:s.x*u.x-c.scrollLeft*u.x+d.x+m.x,y:s.y*u.y-c.scrollTop*u.y+d.y+m.y}}function zL(e){return e.getClientRects?Array.from(e.getClientRects()):[]}function UL(e){const n=If(e),s=e.ownerDocument.body,r=ia(e.scrollWidth,e.clientWidth,s.scrollWidth,s.clientWidth),a=ia(e.scrollHeight,e.clientHeight,s.scrollHeight,s.clientHeight);let i=-n.scrollLeft+Pf(e);const l=-n.scrollTop;return Mr(s).direction==="rtl"&&(i+=ia(e.clientWidth,s.clientWidth)-r),{width:r,height:a,x:i,y:l}}const BL=25;function WL(e,n,s){s===void 0&&(s="viewport");const r=s==="layoutViewport",a=us(e),i=xa(e),l=a.visualViewport;let o=i.clientWidth,c=i.clientHeight,u=0,d=0;if(l){const m=!Kj()||n==="fixed";r?m||(u=-l.offsetLeft,d=-l.offsetTop):(o=l.width,c=l.height,m&&(u=l.offsetLeft,d=l.offsetTop))}if(Pf(i)<=0){const m=i.ownerDocument,p=m.body,g=getComputedStyle(p),v=m.compatMode==="CSS1Compat"&&parseFloat(g.marginLeft)+parseFloat(g.marginRight)||0,b=Math.abs(i.clientWidth-p.clientWidth-v),j=getComputedStyle(i).scrollbarGutter==="stable both-edges"?b/2:b;j<=BL&&(o-=j)}return{width:o,height:c,x:u,y:d}}function HL(e,n){const s=Mi(e,!0,n==="fixed"),r=s.top+e.clientTop,a=s.left+e.clientLeft,i=Ml(e),l=e.clientWidth*i.x,o=e.clientHeight*i.y,c=a*i.x,u=r*i.y;return{width:l,height:o,x:c,y:u}}function Uk(e,n,s){let r;if(n==="viewport"||n==="layoutViewport")r=WL(e,s,n);else if(n==="document")r=UL(xa(e));else if(Pr(n))r=HL(n,s);else{const a=RE(e);r={x:n.x-a.x,y:n.y-a.y,width:n.width,height:n.height}}return Nh(r)}function KL(e,n){const s=n.get(e);if(s)return s;let r=Fc(e,[],!1).filter(o=>Pr(o)&&mo(o)!=="body"),a=null;const i=Mr(e).position==="fixed";let l=i?Pi(e):e;for(;Pr(l)&&!Lc(l);){const o=Mr(l),c=Hj(l),u=a?a.position:i?"fixed":"";!c&&(u==="fixed"||u==="absolute"&&o.position==="static")?r=r.filter(f=>f!==l):a=o,l=Pi(l)}return n.set(e,r),r}function VL(e){let{element:n,boundary:s,rootBoundary:r,strategy:a}=e;const l=[...s==="clippingAncestors"?Rf(n)?[]:KL(n,this._c):[].concat(s),r],o=Uk(n,l[0],a);let c=o.top,u=o.right,d=o.bottom,f=o.left;for(let m=1;m<l.length;m++){const p=Uk(n,l[m],a);c=ia(p.top,c),u=Va(p.right,u),d=Va(p.bottom,d),f=ia(p.left,f)}return{width:u-f,height:d-c,x:f,y:c}}function GL(e){const{width:n,height:s}=TE(e);return{width:n,height:s}}function qL(e,n,s){const r=si(n),a=xa(n),i=s==="fixed",l=Mi(e,!0,i,n);let o={scrollLeft:0,scrollTop:0};const c=la(0);if((r||!i)&&((mo(n)!=="body"||Tf(a))&&(o=If(n)),r)){const m=Mi(n,!0,i,n);c.x=m.x+n.clientLeft,c.y=m.y+n.clientTop}!r&&a&&(c.x=Pf(a));const u=a&&!r&&!i?IE(a,o):la(0),d=l.left+o.scrollLeft-c.x-u.x,f=l.top+o.scrollTop-c.y-u.y;return{x:d,y:f,width:l.width,height:l.height}}function Qm(e){return Mr(e).position==="static"}function Bk(e,n){if(!si(e)||Mr(e).position==="fixed")return null;if(n)return n(e);let s=e.offsetParent;return xa(e)===s&&(s=s.ownerDocument.body),s}function PE(e,n){const s=us(e);if(Rf(e))return s;if(!si(e)){let a=Pi(e);for(;a&&!Lc(a);){if(Pr(a)&&!Qm(a))return a;a=Pi(a)}return s}let r=Bk(e,n);for(;r&&PL(r)&&Qm(r);)r=Bk(r,n);return r&&Lc(r)&&Qm(r)&&!Hj(r)?s:r||OL(e)||s}const YL=async function(e){const n=this.getOffsetParent||PE,s=this.getDimensions,r=await s(e.floating);return{reference:qL(e.reference,await n(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function JL(e){return Mr(e).direction==="rtl"}const QL={convertOffsetParentRelativeRectToViewportRelativeRect:_L,getDocumentElement:xa,getClippingRect:VL,getOffsetParent:PE,getElementRects:YL,getClientRects:zL,getDimensions:GL,getScale:Ml,isElement:Pr,isRTL:JL};function ME(e,n){return e.x===n.x&&e.y===n.y&&e.width===n.width&&e.height===n.height}function XL(e,n,s){let r=null,a;const i=xa(e);function l(){var d;clearTimeout(a),(d=r)==null||d.disconnect(),r=null}function o(d,f){d===void 0&&(d=!1),f===void 0&&(f=1),l();const m=e.getBoundingClientRect(),{left:p,top:g,width:v,height:b}=m;if(d||n(),!v||!b)return;const j=Xu(g),x=Xu(i.clientWidth-(p+v)),y=Xu(i.clientHeight-(g+b)),w=Xu(p),N={rootMargin:-j+"px "+-x+"px "+-y+"px "+-w+"px",threshold:ia(0,Va(1,f))||1};let S=!0;function C(E){const T=E[0].intersectionRatio;if(!ME(m,e.getBoundingClientRect()))return o();if(T!==f){if(!S)return o();T?o(!1,T):a=setTimeout(()=>{o(!1,1e-7)},1e3)}S=!1}try{r=new IntersectionObserver(C,{...N,root:i.ownerDocument})}catch{r=new IntersectionObserver(C,N)}r.observe(e)}const c=us(e),u=()=>o(s);return c.addEventListener("resize",u),o(!0),()=>{c.removeEventListener("resize",u),l()}}function ZL(e,n,s,r){r===void 0&&(r={});const{ancestorScroll:a=!0,ancestorResize:i=!0,elementResize:l=typeof ResizeObserver=="function",layoutShift:o=typeof IntersectionObserver=="function",animationFrame:c=!1}=r,u=Vj(e),d=a||i?[...u?Fc(u):[],...n?Fc(n):[]]:[];d.forEach(j=>{a&&j.addEventListener("scroll",s),i&&j.addEventListener("resize",s)});const f=u&&o?XL(u,s,i):null;let m=-1,p=null;l&&(p=new ResizeObserver(j=>{let[x]=j;x&&x.target===u&&p&&n&&(p.unobserve(n),cancelAnimationFrame(m),m=requestAnimationFrame(()=>{var y;(y=p)==null||y.observe(n)})),s()}),u&&!c&&p.observe(u),n&&p.observe(n));let g,v=c?Mi(e):null;c&&b();function b(){const j=Mi(e);v&&!ME(v,j)&&s(),v=j,g=requestAnimationFrame(b)}return s(),()=>{var j;d.forEach(x=>{a&&x.removeEventListener("scroll",s),i&&x.removeEventListener("resize",s)}),f==null||f(),(j=p)==null||j.disconnect(),p=null,c&&cancelAnimationFrame(g)}}const eF=$L,tF=TL,nF=CL,sF=IL,rF=EL,Wk=SL,aF=RL,iF=(e,n,s)=>{const r=new Map,a=s??{},i={...QL,...a.platform,_c:r};return NL(e,n,{...a,platform:i})};var lF=typeof document<"u",oF=function(){},Fd=lF?h.useLayoutEffect:oF;function Sh(e,n){if(e===n)return!0;if(typeof e!=typeof n)return!1;if(typeof e=="function"&&e.toString()===n.toString())return!0;let s,r,a;if(e&&n&&typeof e=="object"){if(Array.isArray(e)){if(s=e.length,s!==n.length)return!1;for(r=s;r--!==0;)if(!Sh(e[r],n[r]))return!1;return!0}if(a=Object.keys(e),s=a.length,s!==Object.keys(n).length)return!1;for(r=s;r--!==0;)if(!{}.hasOwnProperty.call(n,a[r]))return!1;for(r=s;r--!==0;){const i=a[r];if(!(i==="_owner"&&e.$$typeof)&&!Sh(e[i],n[i]))return!1}return!0}return e!==e&&n!==n}function DE(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Hk(e,n){const s=DE(e);return Math.round(n*s)/s}function Xm(e){const n=h.useRef(e);return Fd(()=>{n.current=e}),n}function cF(e){e===void 0&&(e={});const{placement:n="bottom",strategy:s="absolute",middleware:r=[],platform:a,elements:{reference:i,floating:l}={},transform:o=!0,whileElementsMounted:c,open:u}=e,[d,f]=h.useState({x:0,y:0,strategy:s,placement:n,middlewareData:{},isPositioned:!1}),[m,p]=h.useState(r);Sh(m,r)||p(r);const[g,v]=h.useState(null),[b,j]=h.useState(null),x=h.useCallback(P=>{P!==N.current&&(N.current=P,v(P))},[]),y=h.useCallback(P=>{P!==S.current&&(S.current=P,j(P))},[]),w=i||g,k=l||b,N=h.useRef(null),S=h.useRef(null),C=h.useRef(d),E=c!=null,T=Xm(c),I=Xm(a),F=Xm(u),D=h.useCallback(()=>{if(!N.current||!S.current)return;const P={placement:n,strategy:s,middleware:m};I.current&&(P.platform=I.current),iF(N.current,S.current,P).then(H=>{const U={...H,isPositioned:F.current!==!1};$.current&&!Sh(C.current,U)&&(C.current=U,uo.flushSync(()=>{f(U)}))})},[m,n,s,I,F]);Fd(()=>{u===!1&&C.current.isPositioned&&(C.current.isPositioned=!1,f(P=>({...P,isPositioned:!1})))},[u]);const $=h.useRef(!1);Fd(()=>($.current=!0,()=>{$.current=!1}),[]),Fd(()=>{if(w&&(N.current=w),k&&(S.current=k),w&&k){if(T.current)return T.current(w,k,D);D()}},[w,k,D,T,E]);const L=h.useMemo(()=>({reference:N,floating:S,setReference:x,setFloating:y}),[x,y]),O=h.useMemo(()=>({reference:w,floating:k}),[w,k]),M=h.useMemo(()=>{const P={position:s,left:0,top:0};if(!O.floating)return P;const H=Hk(O.floating,d.x),U=Hk(O.floating,d.y);return o?{...P,transform:"translate("+H+"px, "+U+"px)",...DE(O.floating)>=1.5&&{willChange:"transform"}}:{position:s,left:H,top:U}},[s,o,O.floating,d.x,d.y]);return h.useMemo(()=>({...d,update:D,refs:L,elements:O,floatingStyles:M}),[d,D,L,O,M])}const uF=e=>{function n(s){return{}.hasOwnProperty.call(s,"current")}return{name:"arrow",options:e,fn(s){const{element:r,padding:a}=typeof e=="function"?e(s):e;return r&&n(r)?r.current!=null?Wk({element:r.current,padding:a}).fn(s):{}:r?Wk({element:r,padding:a}).fn(s):{}}}},dF=(e,n)=>{const s=eF(e);return{name:s.name,fn:s.fn,options:[e,n]}},hF=(e,n)=>{const s=tF(e);return{name:s.name,fn:s.fn,options:[e,n]}},fF=(e,n)=>({fn:aF(e).fn,options:[e,n]}),mF=(e,n)=>{const s=nF(e);return{name:s.name,fn:s.fn,options:[e,n]}},pF=(e,n)=>{const s=sF(e);return{name:s.name,fn:s.fn,options:[e,n]}},gF=(e,n)=>{const s=rF(e);return{name:s.name,fn:s.fn,options:[e,n]}},xF=(e,n)=>{const s=uF(e);return{name:s.name,fn:s.fn,options:[e,n]}};var vF=Object.defineProperty,jF=(e,n)=>vF(e,"name",{value:n,configurable:!0});function OE(e){const[n,s]=h.useState(void 0);return cs(()=>{if(e){s({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(a=>{if(!Array.isArray(a)||!a.length)return;const i=a[0];let l,o;if("borderBoxSize"in i){const c=i.borderBoxSize,u=Array.isArray(c)?c[0]:c;l=u.inlineSize,o=u.blockSize}else l=e.offsetWidth,o=e.offsetHeight;s({width:l,height:o})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else s(void 0)},[e]),n}jF(OE,"useSize");var yF=Object.defineProperty,za=(e,n)=>yF(e,"name",{value:n,configurable:!0}),LE="Popper",[FE,Mf]=fr(LE),[wF,_E]=FE(LE),bF=za(e=>{const{__scopePopper:n,children:s}=e,[r,a]=h.useState(null),[i,l]=h.useState(void 0);return t.jsx(wF,{scope:n,anchor:r,onAnchorChange:a,placementState:i,setPlacementState:l,children:s})},"Popper"),kF="PopperAnchor",NF=h.forwardRef(za(function(n,s){const{__scopePopper:r,virtualRef:a,...i}=n,l=_E(kF,r),o=h.useRef(null),c=l.onAnchorChange,u=h.useCallback(v=>{o.current=v,v&&c(v)},[c]),d=$t(s,u),f=h.useRef(null);h.useEffect(()=>{if(!a)return;const v=f.current;f.current=a.current,v!==f.current&&c(f.current)});const m=l.placementState&&Df(l.placementState),p=m==null?void 0:m[0],g=m==null?void 0:m[1];return a?null:t.jsx(bt.div,{"data-radix-popper-side":p,"data-radix-popper-align":g,...i,ref:d})},"PopperAnchor")),zE="PopperContent",[SF,Qte]=FE(zE),CF=h.forwardRef(za(function(n,s){var Re,Oe,Je,W,se,Y,Ne;const{__scopePopper:r,side:a="bottom",sideOffset:i=0,align:l="center",alignOffset:o=0,arrowPadding:c=0,avoidCollisions:u=!0,collisionBoundary:d=[],collisionPadding:f=0,sticky:m="partial",hideWhenDetached:p=!1,updatePositionStrategy:g="optimized",onPlaced:v,...b}=n,j=_E(zE,r),[x,y]=h.useState(null),w=$t(s,y),[k,N]=h.useState(null),S=OE(k),C=(S==null?void 0:S.width)??0,E=(S==null?void 0:S.height)??0,T=a+(l!=="center"?"-"+l:""),I=typeof f=="number"?f:{top:0,right:0,bottom:0,left:0,...f},F=Array.isArray(d)?d:[d],D=F.length>0,$={padding:I,boundary:F.filter(UE),altBoundary:D},{refs:L,floatingStyles:O,placement:M,isPositioned:P,middlewareData:H}=cF({strategy:"fixed",placement:T,whileElementsMounted:za((...we)=>ZL(...we,{animationFrame:g==="always"}),"whileElementsMounted"),elements:{reference:j.anchor},middleware:[dF({mainAxis:i+E,alignmentAxis:o}),u&&hF({mainAxis:!0,crossAxis:!1,limiter:m==="partial"?fF():void 0,...$}),u&&mF({...$}),pF({...$,apply:za(({elements:we,rects:fe,availableWidth:ge,availableHeight:Pe})=>{const{width:je,height:de}=fe.reference,ke=we.floating.style;ke.setProperty("--radix-popper-available-width",`${ge}px`),ke.setProperty("--radix-popper-available-height",`${Pe}px`),ke.setProperty("--radix-popper-anchor-width",`${je}px`),ke.setProperty("--radix-popper-anchor-height",`${de}px`)},"apply")}),k&&xF({element:k,padding:c}),EF({arrowWidth:C,arrowHeight:E}),p&&gF({strategy:"referenceHidden",...$,boundary:D?$.boundary:void 0})]}),U=j.setPlacementState;cs(()=>(U(M),()=>{U(void 0)}),[M,U]);const[V,z]=Df(M),X=Yn(v);cs(()=>{P&&(X==null||X())},[P,X]);const K=(Re=H.arrow)==null?void 0:Re.x,ee=(Oe=H.arrow)==null?void 0:Oe.y,ce=((Je=H.arrow)==null?void 0:Je.centerOffset)!==0,[pe,oe]=h.useState();return cs(()=>{x&&oe(window.getComputedStyle(x).zIndex)},[x]),t.jsx("div",{ref:L.setFloating,"data-radix-popper-content-wrapper":"",style:{...O,transform:P?O.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:pe,"--radix-popper-transform-origin":[(W=H.transformOrigin)==null?void 0:W.x,(se=H.transformOrigin)==null?void 0:se.y].join(" "),...((Y=H.hide)==null?void 0:Y.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:n.dir,children:t.jsx(SF,{scope:r,placedSide:V,placedAlign:z,onArrowChange:N,arrowX:K,arrowY:ee,shouldHideArrow:ce,children:t.jsx(bt.div,{"data-side":V,"data-align":z,...b,ref:w,style:{...b.style,animation:P?(Ne=b.style)==null?void 0:Ne.animation:"none"}})})})},"PopperContent"));function UE(e){return e!==null}za(UE,"isNotNull");var EF=za(e=>({name:"transformOrigin",options:e,fn(n){var b,j,x;const{placement:s,rects:r,middlewareData:a}=n,l=((b=a.arrow)==null?void 0:b.centerOffset)!==0,o=l?0:e.arrowWidth,c=l?0:e.arrowHeight,[u,d]=Df(s),f={start:"0%",center:"50%",end:"100%"}[d],m=(((j=a.arrow)==null?void 0:j.x)??0)+o/2,p=(((x=a.arrow)==null?void 0:x.y)??0)+c/2;let g="",v="";return u==="bottom"?(g=l?f:`${m}px`,v=`${-c}px`):u==="top"?(g=l?f:`${m}px`,v=`${r.floating.height+c}px`):u==="right"?(g=`${-c}px`,v=l?f:`${p}px`):u==="left"&&(g=`${r.floating.width+c}px`,v=l?f:`${p}px`),{data:{x:g,y:v}}}}),"transformOrigin");function Df(e){const[n,s="center"]=e.split("-");return[n,s]}za(Df,"getSideAndAlignFromPlacement");var Gj=bF,BE=NF,WE=CF,AF=Object.defineProperty,wn=(e,n)=>AF(e,"name",{value:n,configurable:!0}),[qj,Xte]=fr("Tooltip",[Mf]),Yj=Mf(),$F="TooltipProvider",TF=700,ox="tooltip.open",[RF,Jj]=qj($F),IF=wn(e=>{const{__scopeTooltip:n,delayDuration:s=TF,skipDelayDuration:r=300,disableHoverableContent:a=!1,children:i}=e,l=h.useRef(!0),o=h.useRef(!1),c=h.useRef(0);return h.useEffect(()=>{const u=c.current;return()=>window.clearTimeout(u)},[]),t.jsx(RF,{scope:n,isOpenDelayedRef:l,delayDuration:s,onOpen:h.useCallback(()=>{r<=0||(window.clearTimeout(c.current),l.current=!1)},[r]),onClose:h.useCallback(()=>{r<=0||(window.clearTimeout(c.current),c.current=window.setTimeout(()=>l.current=!0,r))},[r]),isPointerInTransitRef:o,onPointerInTransitChange:h.useCallback(u=>{o.current=u},[]),disableHoverableContent:a,children:i})},"TooltipProvider"),cx="Tooltip",[PF,fu]=qj(cx),MF=wn(e=>{const{__scopeTooltip:n,children:s,open:r,defaultOpen:a,onOpenChange:i,disableHoverableContent:l,delayDuration:o}=e,c=Jj(cx,e.__scopeTooltip),u=Yj(n),[d,f]=h.useState(null),[m,p]=h.useState(void 0),g=ir(),v=h.useRef(0),b=l??c.disableHoverableContent,j=o??c.delayDuration,x=h.useRef(!1),[y,w]=ni({prop:r,defaultProp:a??!1,onChange:wn(T=>{T?(c.onOpen(),document.dispatchEvent(new CustomEvent(ox))):c.onClose(),i==null||i(T)},"onChange"),caller:cx}),k=h.useMemo(()=>y?x.current?"delayed-open":"instant-open":"closed",[y]),N=h.useCallback(()=>{window.clearTimeout(v.current),v.current=0,x.current=!1,w(!0)},[w]),S=h.useCallback(()=>{window.clearTimeout(v.current),v.current=0,w(!1)},[w]),C=h.useCallback(()=>{window.clearTimeout(v.current),v.current=window.setTimeout(()=>{x.current=!0,w(!0),v.current=0},j)},[j,w]);h.useEffect(()=>()=>{v.current&&(window.clearTimeout(v.current),v.current=0)},[]);const E=m??g;return t.jsx(Gj,{...u,children:t.jsx(PF,{scope:n,contentId:E,setContentId:p,open:y,stateAttribute:k,trigger:d,onTriggerChange:f,onTriggerEnter:h.useCallback(()=>{c.isOpenDelayedRef.current?C():N()},[c.isOpenDelayedRef,C,N]),onTriggerLeave:h.useCallback(()=>{b?S():(window.clearTimeout(v.current),v.current=0)},[S,b]),onOpen:N,onClose:S,disableHoverableContent:b,children:s})})},"Tooltip"),Kk="TooltipTrigger",DF=h.forwardRef(wn(function(n,s){const{__scopeTooltip:r,...a}=n,i=fu(Kk,r),l=Jj(Kk,r),o=Yj(r),c=h.useRef(null),u=$t(s,c,i.onTriggerChange),d=h.useRef(!1),f=h.useRef(!1),m=h.useCallback(()=>d.current=!1,[]);return h.useEffect(()=>()=>document.removeEventListener("pointerup",m),[m]),t.jsx(BE,{asChild:!0,...o,children:t.jsx(bt.button,{"aria-describedby":i.open?i.contentId:void 0,"data-state":i.stateAttribute,...a,ref:u,onPointerMove:_e(n.onPointerMove,p=>{p.pointerType!=="touch"&&!f.current&&!l.isPointerInTransitRef.current&&(i.onTriggerEnter(),f.current=!0)}),onPointerLeave:_e(n.onPointerLeave,()=>{i.onTriggerLeave(),f.current=!1}),onPointerDown:_e(n.onPointerDown,()=>{i.open&&i.onClose(),d.current=!0,document.addEventListener("pointerup",m,{once:!0})}),onFocus:_e(n.onFocus,()=>{d.current||i.onOpen()}),onBlur:_e(n.onBlur,i.onClose),onClick:_e(n.onClick,i.onClose)})})},"TooltipTrigger")),HE="TooltipPortal",[OF,LF]=qj(HE,{forceMount:void 0}),FF=wn(e=>{const{__scopeTooltip:n,forceMount:s,children:r,container:a}=e,i=fu(HE,n);return t.jsx(OF,{scope:n,forceMount:s,children:t.jsx(Br,{present:s||i.open,children:t.jsx(Cf,{asChild:!0,container:a,children:r})})})},"TooltipPortal"),_c="TooltipContent",_F=h.forwardRef(wn(function(n,s){const r=LF(_c,n.__scopeTooltip),{forceMount:a=r.forceMount,side:i="top",...l}=n,o=fu(_c,n.__scopeTooltip);return t.jsx(Br,{present:a||o.open,children:o.disableHoverableContent?t.jsx(KE,{side:i,...l,ref:s}):t.jsx(zF,{side:i,...l,ref:s})})},"TooltipContent")),zF=h.forwardRef(wn(function(n,s){const r=fu(_c,n.__scopeTooltip),a=Jj(_c,n.__scopeTooltip),i=h.useRef(null),l=$t(s,i),[o,c]=h.useState(null),{trigger:u,onClose:d}=r,f=i.current,{onPointerInTransitChange:m}=a,p=h.useCallback(()=>{c(null),m(!1)},[m]),g=h.useCallback((v,b)=>{const j=v.currentTarget,x={x:v.clientX,y:v.clientY},y=VE(x,j.getBoundingClientRect()),w=GE(x,y),k=qE(b.getBoundingClientRect()),N=JE([...w,...k]);c(N),m(!0)},[m]);return h.useEffect(()=>()=>p(),[p]),h.useEffect(()=>{if(u&&f){const v=wn(j=>g(j,f),"handleTriggerLeave"),b=wn(j=>g(j,u),"handleContentLeave");return u.addEventListener("pointerleave",v),f.addEventListener("pointerleave",b),()=>{u.removeEventListener("pointerleave",v),f.removeEventListener("pointerleave",b)}}},[u,f,g,p]),h.useEffect(()=>{if(o){const v=wn(b=>{const j=b.target,x={x:b.clientX,y:b.clientY},y=(u==null?void 0:u.contains(j))||(f==null?void 0:f.contains(j)),w=!YE(x,o);y?p():w&&(p(),d())},"handleTrackPointerGrace");return document.addEventListener("pointermove",v),()=>document.removeEventListener("pointermove",v)}},[u,f,o,d,p]),t.jsx(KE,{...n,ref:l})},"TooltipContentHoverable")),UF=Z1("TooltipContent"),KE=h.forwardRef(wn(function(n,s){const{__scopeTooltip:r,children:a,"aria-label":i,id:l,onEscapeKeyDown:o,onPointerDownOutside:c,...u}=n,d=fu(_c,r),f=Yj(r),{onClose:m}=d;h.useEffect(()=>(document.addEventListener(ox,m),()=>document.removeEventListener(ox,m)),[m]),h.useEffect(()=>{if(d.trigger){const g=wn(v=>{v.target instanceof Node&&v.target.contains(d.trigger)&&m()},"handleScroll");return window.addEventListener("scroll",g,{capture:!0}),()=>window.removeEventListener("scroll",g,{capture:!0})}},[d.trigger,m]);const{setContentId:p}=d;return cs(()=>(p(l),()=>{p(void 0)}),[l,p]),t.jsx(Sf,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:o,onPointerDownOutside:c,onFocusOutside:g=>g.preventDefault(),onDismiss:m,children:t.jsxs(WE,{"data-state":d.stateAttribute,role:i?void 0:"tooltip",id:i?void 0:d.contentId,...f,...u,ref:s,style:{...u.style,"--radix-tooltip-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-tooltip-content-available-width":"var(--radix-popper-available-width)","--radix-tooltip-content-available-height":"var(--radix-popper-available-height)","--radix-tooltip-trigger-width":"var(--radix-popper-anchor-width)","--radix-tooltip-trigger-height":"var(--radix-popper-anchor-height)"},children:[t.jsx(UF,{children:a}),i?t.jsx(DO,{id:d.contentId,role:"tooltip",children:i}):null]})})},"TooltipContentImpl"));function VE(e,n){const s=Math.abs(n.top-e.y),r=Math.abs(n.bottom-e.y),a=Math.abs(n.right-e.x),i=Math.abs(n.left-e.x);switch(Math.min(s,r,a,i)){case i:return"left";case a:return"right";case s:return"top";case r:return"bottom";default:throw new Error("unreachable")}}wn(VE,"getExitSideFromRect");function GE(e,n,s=5){const r=[];switch(n){case"top":r.push({x:e.x-s,y:e.y+s},{x:e.x+s,y:e.y+s});break;case"bottom":r.push({x:e.x-s,y:e.y-s},{x:e.x+s,y:e.y-s});break;case"left":r.push({x:e.x+s,y:e.y-s},{x:e.x+s,y:e.y+s});break;case"right":r.push({x:e.x-s,y:e.y-s},{x:e.x-s,y:e.y+s});break}return r}wn(GE,"getPaddedExitPoints");function qE(e){const{top:n,right:s,bottom:r,left:a}=e;return[{x:a,y:n},{x:s,y:n},{x:s,y:r},{x:a,y:r}]}wn(qE,"getPointsFromRect");function YE(e,n){const{x:s,y:r}=e;let a=!1;for(let i=0,l=n.length-1;i<n.length;l=i++){const o=n[i],c=n[l],u=o.x,d=o.y,f=c.x,m=c.y;d>r!=m>r&&s<(f-u)*(r-d)/(m-d)+u&&(a=!a)}return a}wn(YE,"isPointInPolygon");function JE(e){const n=e.slice();return n.sort((s,r)=>s.x<r.x?-1:s.x>r.x?1:s.y<r.y?-1:s.y>r.y?1:0),QE(n)}wn(JE,"getHull");function QE(e){if(e.length<=1)return e.slice();const n=[];for(let r=0;r<e.length;r++){const a=e[r];for(;n.length>=2;){const i=n[n.length-1],l=n[n.length-2];if((i.x-l.x)*(a.y-l.y)>=(i.y-l.y)*(a.x-l.x))n.pop();else break}n.push(a)}n.pop();const s=[];for(let r=e.length-1;r>=0;r--){const a=e[r];for(;s.length>=2;){const i=s[s.length-1],l=s[s.length-2];if((i.x-l.x)*(a.y-l.y)>=(i.y-l.y)*(a.x-l.x))s.pop();else break}s.push(a)}return s.pop(),n.length===1&&s.length===1&&n[0].x===s[0].x&&n[0].y===s[0].y?n:n.concat(s)}wn(QE,"getHullPresorted");var Vk=IF,zc=MF,Uc=DF,Bc=FF,Wc=_F;let an={time:"auto",date:"auto",locale:void 0};function Qj(e){const n=e.timeFormat===void 0?an.time:e.timeFormat==="12h"||e.timeFormat==="24h"?e.timeFormat:"auto",s=e.dateFormat===void 0?an.date:e.dateFormat==="short"||e.dateFormat==="long"||e.dateFormat==="iso"?e.dateFormat:"auto";an={time:n,date:s,locale:e.locale??an.locale}}function XE(){return{time:an.time,date:an.date}}function mu(e,n){const s=an;Qj(e);try{return n()}finally{an=s}}const ux="buddi:formats";function pu(){if(an.locale)return an.locale;try{return typeof navigator<"u"&&navigator.language?navigator.language:"en-US"}catch{return"en-US"}}const Gk=new Map;function po(e,n){const s=`${e}|${JSON.stringify(n)}`;let r=Gk.get(s);if(!r){try{r=new Intl.DateTimeFormat(e,n)}catch{r=new Intl.DateTimeFormat(e,{...n,timeZone:"UTC"})}Gk.set(s,r)}return r}function Zm(e,n,s,r){return Object.fromEntries(po(s,{timeZone:n,...r}).formatToParts(e).map(a=>[a.type,a.value]))}function BF(){return an.time==="12h"?{hour:"numeric",minute:"2-digit",hourCycle:"h12"}:an.time==="24h"?{hour:"2-digit",minute:"2-digit",hourCycle:"h23"}:{hour:Of()?"numeric":"2-digit",minute:"2-digit"}}function WF(){return an.time==="auto"?pu():"en-US"}function Xt(e,n){return Number.isNaN(e.getTime())?"—":po(WF(),{timeZone:n,...BF()}).format(e)}function HF(e){return e>=1440&&!Of()?"24:00":Xt(new Date(Date.UTC(2026,0,1,Math.floor(e/60)%24,e%60)),"UTC")}function Of(){var e;return an.time!=="auto"?an.time==="12h":((e=po(pu(),{hour:"numeric"}).resolvedOptions().hourCycle)==null?void 0:e.startsWith("h1"))===!0}function ZE(){return`Profile (${Of()?"12-hour":"24-hour"})`}function KF(){if(an.date!=="auto")return an.date==="short";const e=po(pu(),{month:"short",day:"numeric"}).formatToParts(new Date(Date.UTC(2026,9,1))).map(n=>n.type);return e.indexOf("month")<e.indexOf("day")}function Wr(e,n,s={}){return VF(e,n,s).replace(/\bSept\b/g,"Sep")}function VF(e,n,s){if(Number.isNaN(e.getTime()))return"—";const{weekday:r=!1,year:a=!1,compact:i=!1}=s;switch(an.date){case"iso":{const l=Zm(e,n,"en-CA",{year:"numeric",month:"2-digit",day:"2-digit",...r?{weekday:i?"short":"long"}:{}}),o=`${l.year}-${l.month}-${l.day}`;return r?`${l.weekday} ${o}`:o}case"short":{const l=Zm(e,n,"en-US",{month:"short",day:"numeric",year:"numeric",weekday:"short"});return`${r?`${l.weekday}, `:""}${l.month} ${l.day}${a?`, ${l.year}`:""}`}case"long":{const l=Zm(e,n,"en-GB",{month:i?"short":"long",day:"numeric",year:"numeric",weekday:i?"short":"long"});return`${r?`${l.weekday}, `:""}${l.day} ${l.month}${a?` ${l.year}`:""}`}default:return po(pu(),{timeZone:n,month:i?"short":"long",day:"numeric",...a?{year:"numeric"}:{},...r?{weekday:i?"short":"long"}:{}}).format(e)}}function eA(e,n){if(an.date==="iso")return`${e}-${String(n).padStart(2,"0")}`;const s=new Date(Date.UTC(e,n-1,15)),r=an.date==="auto"?pu():"en-GB";return po(r,{timeZone:"UTC",month:"long",year:"numeric"}).format(s)}function gu(e,n={}){const s=/^(\d{4})-(\d{2})-(\d{2})/.exec(e);if(!s)return e;const r=new Date(`${s[0]}T12:00:00Z`);return Number.isNaN(r.getTime())?e:Wr(r,"UTC",n)}function ct(e,n){if(!e)return"—";const s=new Date(e);return Number.isNaN(s.getTime())?String(e):`${Wr(s,n,{year:!0,compact:!0})}, ${Xt(s,n)}`}function Xj(e,n){return`${Wr(e,n,{weekday:!0,compact:!0})}, ${Xt(e,n)}`}function Ve(e,n=Date.now()){if(!e)return"";const s=new Date(e).getTime();if(Number.isNaN(s))return"";const r=Math.round((s-n)/1e3),a=Math.abs(r),[i,l]=a<60?[r,"second"]:a<3600?[Math.round(r/60),"minute"]:a<86400?[Math.round(r/3600),"hour"]:[Math.round(r/86400),"day"];return new Intl.RelativeTimeFormat("en",{numeric:"auto"}).format(i,l)}function Zj(e,n=Date.now()){if(!e)return"";const s=new Date(e).getTime();if(Number.isNaN(s))return"";const r=Math.abs(Math.round((n-s)/1e3));return r<60?"now":r<3600?`${Math.floor(r/60)} min`:r<86400?`${Math.floor(r/3600)} h`:`${Math.floor(r/86400)} d`}function GF(e,n=Date.now()){const s=Zj(e,n);return s===""?"":s==="now"||new Date(e).getTime()>n?"just now":s==="1 d"?"yesterday":`${s} ago`}function qF(e,n){if(e==null||!Number.isFinite(e))return"—";try{return new Intl.NumberFormat("en-US",{style:"currency",currency:n??"USD",maximumFractionDigits:0}).format(e)}catch{return e.toFixed(2)}}function dn(e){return new Intl.NumberFormat("en-US").format(e)}function dx(e){return[...e.cacheRead?[`cached ${dn(e.cacheRead)}`]:[],...e.cacheWrite?[`cache write ${dn(e.cacheWrite)}`]:[]].join(", ")}function YF(e){const n=dx(e);return`${dn(e.input)} in${n?` (${n})`:""} / ${dn(e.output)} out`}function ks(e){try{return JSON.stringify(e,null,2)??"null"}catch{return String(e)}}function Hc(e,n=8){return e.length<=n?e:e.slice(0,n)}function cr(e,n){return e.length<=n?e:`${e.slice(0,n-1)}…`}function Kc(e){if(e.kind!=="agent")return e.title;const n=e.title.replace(/^@[^\s:]+:\s+/,"");return n.trim()===""?e.title:n}const qk="buddi_csrf",go="x-buddi-csrf",Dr="buddi:agents-changed",bi="buddi:status-changed",zo=e=>(window.dispatchEvent(new Event(bi)),e),hx="buddi:locked",JF="This page's sign-in no longer matches its cookies. Reload the page and try again.";class xe extends Error{constructor(n,s,r){super(s),this.status=n,this.detail=r,this.name="ApiError"}}function Bi(){var r;const e=Number(location.port)||(location.protocol==="https:"?443:80),n=document.cookie.match(new RegExp(`(?:^|; )${qk}_${e}=([^;]*)`));if(n!=null&&n[1])return decodeURIComponent(n[1]);const s=[...document.cookie.matchAll(new RegExp(`(?:^|; )${qk}(?:_\\d+)?=([^;]*)`,"g"))];return s.length===1&&((r=s[0])!=null&&r[1])?decodeURIComponent(s[0][1]):""}const Ch="buddi isn't answering.";let fx=null;const mx=new Set;function Uo(e){if(e!==(fx===null)){fx=e?null:Date.now();for(const n of mx)n()}}function Vc(){return fx}function ey(e){return mx.add(e),()=>mx.delete(e)}function Eh(e){return e instanceof xe&&(e.status===0||e.status===502||e.status===503)&&e.message===Ch}async function Wi(e,n={}){var l;let s;try{s=await fetch(e,{...n,credentials:"same-origin",redirect:"error",headers:{Accept:"application/json",...n.headers??{}}})}catch(o){throw(o==null?void 0:o.name)==="AbortError"||(l=n.signal)!=null&&l.aborted?o:(Uo(!1),new xe(0,Ch,o))}if(s.status===401)throw Uo(!0),new xe(401,"This session has expired. Run `buddi dashboard` for a fresh link.");if(s.status===423)throw Uo(!0),window.dispatchEvent(new Event(hx)),new xe(423,"This dashboard is locked.");const r=await s.text(),a=r===""?null:QF(r),i=a&&typeof a=="object"&&"error"in a?String(a.error):void 0;if((s.status===502||s.status===503)&&i===void 0)throw Uo(!1),new xe(s.status,Ch,a);if(Uo(!0),!s.ok){const o=(n.method??"GET").toUpperCase(),c=i??(s.status===403&&o!=="GET"&&o!=="HEAD"?JF:`request failed (${s.status})`);throw new xe(s.status,c,a)}return a}function QF(e){try{return JSON.parse(e)}catch{return null}}function ep(){return XE().time==="auto"?{hour:Of()?"12":"24"}:{}}function ye(e,n={}){const s=new URLSearchParams;for(const[a,i]of Object.entries(n))i!==void 0&&i!==""&&s.set(a,String(i));const r=s.toString();return Wi(`/api${e}${r?`?${r}`:""}`)}function px(e,n){return Wi(`/api${e}`,{method:"POST",headers:{[go]:Bi()},body:n})}function tr(e){return Wi(`/api${e}`,{method:"DELETE",headers:{[go]:Bi()}})}function Z(e,n={}){return Wi(`/api${e}`,{method:"POST",headers:{"Content-Type":"application/json",[go]:Bi()},body:JSON.stringify(n??{})})}function ty(e,n,s,r={}){const a=n.name.replace(/[^\w.-]+/g,"_").slice(-120)||s;return Wi(`/api${e}`,{method:"POST",headers:{"Content-Type":"application/octet-stream",[go]:Bi(),"X-Filename":a,...r},body:n})}function Yk(e,n,s){return ty(e,n,"backup.tar.gz",{...s.passphrase?{"X-Backup-Passphrase":s.passphrase}:{},...s.confirm?{"X-Backup-Confirm":s.confirm}:{}})}function XF(e,n={}){return Wi(`/api${e}`,{method:"PATCH",headers:{"Content-Type":"application/json",[go]:Bi()},body:JSON.stringify(n??{})})}function jr(e,n={}){return Wi(`/api${e}`,{method:"PUT",headers:{"Content-Type":"application/json",[go]:Bi()},body:JSON.stringify(n??{})})}function ZF(e){if(e.dismissedAt)return"You said no to this one.";switch(e.lapseReason){case"owner-moved-on":return"The conversation moved on.";case"rolled-over":return"That conversation ended.";case"agent-removed":return"That agent is no longer here.";default:return"It lapsed."}}const _d="gpt-oss:120b",e_=["approval","question","watcher","reminder","failure","recap","plugin","agent"],gx=["mon","tue","wed","thu","fri","sat","sun"],qe={agents:()=>ye("/chat/agents"),views:()=>ye("/chat/views"),conversations:(e,n)=>ye(`/chat/${encodeURIComponent(e)}/conversations`,{limit:n}),startConversation:e=>Z(`/chat/${encodeURIComponent(e)}/conversations`),conversation:e=>ye(`/chat/conversations/${encodeURIComponent(e)}`),deleteCarryOver:e=>tr(`/chat/conversations/${encodeURIComponent(e)}/carry-over`),send:(e,n)=>Z(`/chat/${encodeURIComponent(e)}/messages`,n),answerQuestion:(e,n)=>Z(`/chat/questions/${encodeURIComponent(e)}/answer`,n),cancel:e=>Z(`/chat/conversations/${encodeURIComponent(e)}/cancel`),attach:e=>{const n=new FormData;return n.append("file",e,e.name),px("/chat/attachments",n)},transcribe:e=>Z("/speech/transcribe",e),say:e=>Z("/speech/say",e),discardAttachment:e=>tr(`/artifacts/${encodeURIComponent(e)}`),groups:()=>ye("/groups"),group:e=>ye(`/groups/${encodeURIComponent(e)}`),createGroup:e=>Z("/groups",e),updateGroup:(e,n)=>XF(`/groups/${encodeURIComponent(e)}`,n),deleteGroup:e=>tr(`/groups/${encodeURIComponent(e)}`),restoreGroup:e=>Z(`/groups/${encodeURIComponent(e)}/restore`),clearGroup:e=>Z(`/groups/${encodeURIComponent(e)}/clear`),groupConversations:e=>ye(`/groups/${encodeURIComponent(e)}/conversations`),startGroupConversation:e=>Z(`/groups/${encodeURIComponent(e)}/conversations`),sendToGroup:(e,n)=>Z(`/groups/${encodeURIComponent(e)}/messages`,n),streamUrl:e=>`/api/chat/conversations/${encodeURIComponent(e)}/stream`};function ny(e){return e.httpStatus===401||e.httpStatus===403||e.state==="authentication-error"||e.state==="access-denied"}const R={providers:()=>ye("/providers"),providerAccounts:()=>ye("/provider-accounts"),probeModels:e=>Z("/provider-accounts/probe-models",e),accountModels:(e,n=!1)=>Z(`/provider-accounts/${encodeURIComponent(e)}/models`,{refresh:n}),saveProviderAccount:e=>Z("/provider-accounts/save",e),testProviderAccount:e=>Z(`/provider-accounts/${encodeURIComponent(e)}/test`),removeProviderAccount:(e,n)=>Z(`/provider-accounts/${encodeURIComponent(e)}/remove`,{revision:n}),codexAccountAction:(e,n,s)=>Z(`/provider-accounts/${encodeURIComponent(e)}/${n}`,{revision:s}),ollamaConnect:(e,n)=>Z(`/provider-accounts/${encodeURIComponent(e)}/ollama/connect`,{revision:n}),ollamaPoll:(e,n)=>Z(`/provider-accounts/${encodeURIComponent(e)}/ollama/poll`,{attemptId:n}),ollamaDisconnect:(e,n)=>Z(`/provider-accounts/${encodeURIComponent(e)}/ollama/disconnect`,{revision:n}),anthropicAccountAction:(e,n,s,r)=>Z(`/provider-accounts/${encodeURIComponent(e)}/anthropic/${n}`,{revision:s,...r}),assignProviderAccount:(e,n,s)=>Z(`/agents/${encodeURIComponent(e)}/account`,{accountId:n,model:s}),configureProvider:(e,n)=>Z(`/providers/${encodeURIComponent(e)}/settings`,n),saveCredential:(e,n)=>Z(`/providers/credentials/${encodeURIComponent(e)}/save`,{value:n}),removeCredential:e=>Z(`/providers/credentials/${encodeURIComponent(e)}/remove`),testProvider:e=>Z(`/providers/${encodeURIComponent(e)}/test`),browserProfiles:e=>ye("/host/browser-profiles",{app:e}),installedApps:()=>ye("/host/apps"),browser:e=>ye(`/browser${e?`?agentId=${encodeURIComponent(e.agentId)}&conversationId=${encodeURIComponent(e.conversationId)}`:""}`),browserControl:(e,n)=>Z(`/browser/${e}`,n===void 0?{}:{sessionId:n}),browserSettings:e=>Z("/browser/settings",e),computerPermissions:(e=!1)=>Z("/browser/permissions",{prompt:e}),browserInstall:()=>Z("/browser/install",{}),browserCheck:()=>Z("/browser/check",{}),previewLink:(e,n)=>ye(`/preview/${encodeURIComponent(e)}/${encodeURIComponent(n)}/link`),previewCheck:(e,n)=>ye(`/preview/${encodeURIComponent(e)}/${encodeURIComponent(n)}/check`),extension:()=>ye("/extension"),pairExtension:e=>Z("/extension/pair",{code:e}),forgetExtension:()=>tr("/extension/pair"),session:()=>ye("/session"),overview:()=>ye("/overview"),events:e=>ye("/events",e),eventKinds:()=>ye("/events/kinds"),conversations:()=>ye("/conversations"),conversation:e=>ye(`/conversations/${encodeURIComponent(e)}`),missions:()=>ye("/missions"),jobs:(e={})=>ye("/jobs",e),approvals:()=>ye("/approvals"),approval:e=>ye(`/approvals/${encodeURIComponent(e)}`).then(n=>n.action),offers:()=>ye("/offers"),dismissOffer:e=>Z(`/offers/${encodeURIComponent(e)}/dismiss`,{}),dismissOffers:e=>Z("/offers/dismiss-all",{ids:e}),agentOffers:()=>ye("/agent-offers"),catalogue:(e=!1)=>ye(`/catalogue${e?"?refresh=1":""}`),cataloguePlan:(e,n={})=>Z(`/catalogue/${encodeURIComponent(e)}/plan`,n),catalogueInstall:(e,n)=>Z(`/catalogue/${encodeURIComponent(e)}/install`,n),catalogueJob:e=>ye(`/catalogue/jobs/${encodeURIComponent(e)}`),catalogueConfirm:(e,n)=>Z(`/catalogue/jobs/${encodeURIComponent(e)}/confirm`,{approve:n}),catalogueUpdatePlan:(e,n)=>Z(`/catalogue/${encodeURIComponent(e)}/update/plan`,{agentId:n}),catalogueUpdate:(e,n,s,r=!1)=>Z(`/catalogue/${encodeURIComponent(e)}/update`,{agentId:n,plan:s,...r?{replace:!0}:{}}),agentRemovePreview:e=>ye(`/agents/${encodeURIComponent(e)}/remove`),removeAgent:e=>Z(`/agents/${encodeURIComponent(e)}/remove`),dismissAgentOffer:(e,n)=>Z(`/agent-offers/${encodeURIComponent(e)}/${encodeURIComponent(n)}/dismiss`,{}),proposals:()=>ye("/proposals"),setDigestSchedule:(e,n)=>Z("/proposals/digest-schedule",{day:e,hour:n}),keepProposal:(e,n)=>Z(`/proposals/${encodeURIComponent(e)}/keep`,n===void 0?{}:{text:n}),keepAllProposals:e=>Z("/proposals/keep-all",{ids:e}),discardProposal:(e,n)=>Z(`/proposals/${encodeURIComponent(e)}/discard`,n?{reason:n}:{}),reminders:()=>ye("/reminders"),sentinels:()=>ye("/sentinels"),setSentinelEnabled:(e,n)=>Z(`/sentinels/${encodeURIComponent(e)}/enabled`,{enabled:n}),widgets:(e="home")=>ye("/widgets",{...e==="lock"?{surface:e}:{},...ep()}),saveWidgets:(e,n)=>jr(`/widgets/${e}`,{placements:n.map(({key:s,widget:r,size:a,settings:i})=>({...s?{key:s}:{},widget:r,size:a,settings:i}))}),widgetSettings:e=>ye(`/widgets/settings/${encodeURIComponent(e)}`),previewWidget:e=>Z("/widgets/preview",{...e,...ep()}),refreshWidget:(e,n="home")=>Z(`/widgets/${encodeURIComponent(e)}/refresh${n==="lock"?"?surface=lock":""}`),homeDismiss:(e,n)=>Z("/home/dismiss",{slot:e,token:n}),setGlanceHidden:(e,n)=>Z(`/home/glances/${encodeURIComponent(e)}/hidden`,{hidden:n}),rail:()=>ye("/rail"),setRailHidden:(e,n,s)=>Z(`/rail/pages/${encodeURIComponent(e)}/${encodeURIComponent(n)}/hidden`,{hidden:s}),snoozeAlerts:(e,n,s)=>Z("/alerts/snooze",{keys:e,snoozed:n,...s!==void 0?{days:s}:{}}),muteAlert:(e,n)=>Z("/alerts/mute",{key:e,scope:n}),unmuteAlert:e=>Z(`/alerts/mutes/${encodeURIComponent(e)}/remove`,{}),actOnAlerts:e=>Z("/alerts/act",{entries:e}),askAboutAlerts:e=>Z("/alerts/ask",{keys:e}),agents:()=>ye("/agents"),library:e=>ye("/artifacts",e),libraryEntry:(e,n=0)=>ye(`/artifacts/${encodeURIComponent(e)}`,n?{contexts:n}:{}),onboarding:()=>ye("/onboarding"),onboardingStep:(e,n={})=>Z("/onboarding/step",{step:e,...n}),takeOn:e=>Z("/onboarding/take-on",{tiles:e}),takeOnProgress:()=>ye("/onboarding/take-on"),completeOnboarding:()=>Z("/onboarding/complete"),skipOnboarding:()=>Z("/onboarding/skip"),createFirstAgent:e=>Z("/onboarding/agent",e),ollama:()=>ye("/onboarding/ollama"),ollamaPull:e=>Z("/onboarding/ollama/pull",{model:e}),ollamaPullState:()=>ye("/onboarding/ollama/pull"),mlxh:()=>ye("/onboarding/mlxh"),firstAgentPersona:()=>ye("/onboarding/agent"),updateFirstAgent:e=>Z("/onboarding/agent/update",e),bindBrain:e=>Z("/onboarding/brain",e),pages:()=>ye("/pages"),pageQuery:(e,n,s={})=>ye(`/pages/${encodeURIComponent(e)}/${encodeURIComponent(n)}`,s),pageFileUrl:(e,n,s={})=>{const r=new URLSearchParams(Object.entries(s).filter(([,a])=>a!=="")).toString();return`/api/pages/${encodeURIComponent(e)}/${encodeURIComponent(n)}${r?`?${r}`:""}`},pageAct:(e,n)=>Z(`/pages/${encodeURIComponent(e)}/act`,n),telegram:()=>ye("/telegram"),saveTelegramToken:e=>Z("/telegram/token",{token:e}),telegramPairing:()=>Z("/telegram/pairing"),telegramBot:()=>ye("/telegram/bot"),telegramDevices:()=>ye("/telegram/devices"),unpairTelegramDevice:e=>tr(`/telegram/devices/${encodeURIComponent(e)}`),notifications:(e=20)=>ye("/notifications",{limit:e}),notificationsNeedingYou:()=>ye("/notifications",{needs:1}),notificationSeen:e=>Z(`/notifications/${encodeURIComponent(e)}/seen`),notificationSettings:()=>ye("/notifications/settings"),saveNotificationSettings:e=>jr("/notifications/settings",e),focus:()=>ye("/notifications/focus"),lockState:()=>ye("/lock"),lockScreen:()=>ye("/lock/screen",ep()),lockNow:(e="owner",n)=>Z("/lock",{reason:e,...e==="idle"&&n!==void 0?{idleForMs:Math.max(0,Math.round(n))}:{}}),unlock:e=>Z("/lock/unlock",{pin:e}),lockActivity:()=>Z("/lock/activity"),setPin:(e,n)=>jr("/lock/pin",n===void 0?{pin:e}:{pin:e,current:n}),removePin:e=>Z("/lock/pin/remove",{current:e}),setLockSettings:e=>jr("/lock/settings",e),uploadLockBackground:e=>{const n=new FormData;return n.append("file",e),px("/lock/background",n)},removeLockBackground:()=>tr("/lock/background"),setFocus:(e,n)=>jr("/notifications/focus",n?{mode:e,duration:n}:{mode:e}).then(zo),testChannel:e=>Z("/notifications/test",{channel:e}),setAgentMuted:(e,n)=>Z("/notifications/agent-mute",{agentId:e,muted:n}),currentTip:e=>ye(e?`/tips/current?preview=${encodeURIComponent(e)}`:"/tips/current"),tips:()=>ye("/tips"),restoreTip:e=>Z(`/tips/${encodeURIComponent(e)}/restore`),dismissTip:e=>Z(`/tips/${encodeURIComponent(e)}/dismiss`),laterTip:e=>Z(`/tips/${encodeURIComponent(e)}/later`),tipsSeenPage:e=>Z("/tips/seen-page",{page:e}),tipsSettings:()=>ye("/tips/settings"),saveTipsSettings:e=>jr("/tips/settings",{enabled:e}),presence:e=>Z("/presence",{state:e}),owner:()=>ye("/owner"),setOwner:e=>Z("/owner",e),findPlace:e=>Z("/owner/places/find",{address:e}),savePlace:e=>Z("/owner/places",e),removePlace:e=>Z("/owner/places/remove",{id:e}),memory:e=>ye(e?`/memory?agent=${encodeURIComponent(e)}`:"/memory"),setPreference:e=>Z("/memory/preferences",e),forgetPreference:e=>Z("/memory/preferences/forget",e),updateNote:(e,n)=>Z(`/memory/notes/${encodeURIComponent(e)}`,n),forgetNote:e=>Z(`/memory/notes/${encodeURIComponent(e)}/forget`),people:()=>ye("/memory/people"),savePerson:e=>Z("/memory/people",e),forgetPerson:e=>Z(`/memory/people/${encodeURIComponent(e)}/forget`),restorePerson:e=>Z(`/memory/people/${encodeURIComponent(e)}/restore`),birthday:()=>ye("/owner/birthday"),setDelegates:(e,n)=>Z(`/agents/${encodeURIComponent(e)}/delegates`,{delegates:n}),agentProfile:e=>ye(`/agents/${encodeURIComponent(e)}/profile`),agentSkills:e=>ye(`/agents/${encodeURIComponent(e)}/skills`),removeSkill:(e,n)=>Z(`/agents/${encodeURIComponent(e)}/skills/${encodeURIComponent(n)}/remove`,{}),host:(e,n)=>ye("/host",{agentId:e,conversationId:n}),connections:()=>ye("/connections"),connection:e=>ye(`/connections/${e}`),addConnection:(e,n)=>Z("/connections",{url:e,...n?{name:n}:{}}),addProgram:e=>Z("/connections",{transport:"stdio",...e}),updateProgram:(e,n)=>Z(`/connections/${e}/program`,n),connectionConsent:(e,n)=>Z(`/connections/${e}/consent`,n?{clientId:n}:{}),connectionToken:(e,n)=>Z(`/connections/${e}/token`,n),connectionDevice:e=>Z(`/connections/${e}/device`,{}),connectionCallback:e=>Z("/connections/callback",e),connectionReview:e=>ye(`/connections/${e}/review`),saveConnectionReview:(e,n)=>Z(`/connections/${e}/review`,n),grantConnection:(e,n,s=!1)=>Z(`/connections/${e}/grant`,s?{agents:n,exact:!0}:{agents:n}),setConnectionHolder:(e,n,s)=>Z(`/connections/${e}/holders/${encodeURIComponent(n)}`,{held:s}),disconnect:e=>tr(`/connections/${e}`),connectionSignals:()=>ye("/connections/signals"),connectionTools:e=>ye(`/connections/${e}/tools`),rememberedApprovals:e=>ye(`/connections/remembered/${encodeURIComponent(e)}`),setRememberedApproval:(e,n,s)=>Z("/connections/remembered",{agent:e,tool:n,remember:s}),secrets:()=>ye("/secrets"),secretUses:(e,n)=>ye("/secrets/uses",{name:e,limit:n}),secretsAct:(e,n)=>Z("/secrets/act",{tool:e,args:n}),stopHost:(e,n)=>Z("/host/stop",{agentId:e,conversationId:n}),revokeHost:e=>Z("/host/revoke",{id:e}),decide:(e,n,s,r)=>Z(`/approvals/${encodeURIComponent(e)}/${n}`,s||r?{...s?{permissionScope:s}:{},...r?{ownerChoices:r}:{}}:void 0),setPaused:e=>Z("/pause",{paused:e}).then(zo),service:()=>ye("/service"),serviceAction:e=>Z(`/service/${e}`),version:()=>ye("/version"),checkVersion:()=>Z("/version/check"),setVersionCheck:e=>jr("/version/check",{enabled:e}),tailscale:()=>ye("/tailscale"),setTailscale:e=>jr("/tailscale",e),apiTokens:()=>ye("/api-tokens"),createApiToken:e=>Z("/api-tokens",{name:e}),revokeApiToken:e=>tr(`/api-tokens/${encodeURIComponent(e)}`),startUpgrade:e=>Z("/upgrade",e===void 0?{}:{version:e}),upgradeJob:e=>ye(`/upgrade/jobs/${encodeURIComponent(e)}`),backups:()=>ye("/backups"),startBackup:e=>Z("/backups",{encrypt:e}),verifyArchive:e=>Z("/backups/verify",{name:e}),restoreArchive:e=>Z("/backups/restore",e),restoreUpload:(e,n)=>Yk("/backups/restore",e,n),backupJob:e=>ye(`/backups/jobs/${encodeURIComponent(e)}`),backupSchedule:()=>ye("/backups/schedule"),setBackupSchedule:e=>jr("/backups/schedule",e),backupPassphrase:()=>ye("/backups/passphrase"),setBackupPassphrase:e=>jr("/backups/passphrase",{passphrase:e}),plugins:()=>ye("/plugins"),market:(e=!1)=>ye(`/market${e?"?refresh=1":""}`),marketAssetUrl:e=>`/api/market/asset?url=${encodeURIComponent(e)}`,pluginFolders:e=>ye("/plugins/folders",e?{path:e}:{}),stagePlugin:e=>Z("/plugins/stage",{spec:e}),uploadPlugin:e=>ty("/plugins/upload",e,"plugin.tgz"),pluginJob:e=>ye(`/plugins/jobs/${encodeURIComponent(e)}`),approveStaged:(e,n)=>Z(`/plugins/staged/${encodeURIComponent(e)}/approve`,n),rejectStaged:e=>Z(`/plugins/staged/${encodeURIComponent(e)}/reject`),openedStaged:e=>Z(`/plugins/staged/${encodeURIComponent(e)}/opened`),updatePlugin:(e,n,s)=>Z(`/plugins/${encodeURIComponent(e)}/update`,{...n?{version:n}:{},...s?{from:s}:{}}),setPluginEnabled:(e,n)=>Z(`/plugins/${encodeURIComponent(e)}/${n?"enable":"disable"}`,{}),uninstallPlugin:(e,n)=>Z(`/plugins/${encodeURIComponent(e)}/uninstall`,n),acceptPluginAgent:(e,n)=>Z(`/plugins/${encodeURIComponent(e)}/agents/${encodeURIComponent(n)}/accept`),recovery:()=>ye("/recovery"),leaveRecovery:e=>Z("/recovery/leave",e),firstRunRestore:(e,n)=>Yk("/onboarding/restore",e,{passphrase:n}),setMissionEnabled:(e,n)=>Z(`/missions/${encodeURIComponent(e)}/enabled`,{enabled:n}),keepMission:e=>Z(`/missions/${encodeURIComponent(e)}/keep`,{}),answerStillUseful:(e,n)=>Z(`/missions/${encodeURIComponent(e)}/still-useful`,{answer:n}),setMisfirePolicy:(e,n,s)=>Z(`/missions/${encodeURIComponent(e)}/schedule`,{misfirePolicy:n,...s===void 0?{}:{deadlineMinutes:s}}),retryJob:e=>Z(`/jobs/${encodeURIComponent(e)}/retry`),cancelJob:e=>Z(`/jobs/${encodeURIComponent(e)}/cancel`),jobFailures:()=>ye("/jobs/failures"),dismissJobs:e=>Z("/jobs/dismiss",e).then(zo),undismissJobs:e=>Z("/jobs/undismiss",{ids:e}).then(zo),retryJobs:e=>Z("/jobs/retry",e).then(zo),setDefaultAgent:e=>Z("/agents/default",{agentId:e}),agentTools:e=>ye(`/agents/${encodeURIComponent(e)}/tools`),agentFile:e=>ye(`/agents/${encodeURIComponent(e)}/file`),uploadAgentPicture:(e,n)=>{const s=new FormData;return s.append("file",n,n.name),px(`/agents/${encodeURIComponent(e)}/avatar`,s)},removeAgentPicture:e=>tr(`/agents/${encodeURIComponent(e)}/avatar`),updateAgentFile:(e,n)=>Z(`/agents/${encodeURIComponent(e)}/file`,n),setAgentEngine:(e,n)=>Z(`/agents/${encodeURIComponent(e)}/engine`,n),quiet:e=>Z("/quiet",{arg:e}),takeOffer:(e,n)=>Z(`/offers/${encodeURIComponent(e)}/take`,n?{conversationId:n}:{}),cancelReminder:e=>Z(`/reminders/${encodeURIComponent(e)}/cancel`,{reason:"cancelled from the dashboard"})},xx="buddi.chatDraft";function xu(e,n){try{window.sessionStorage.setItem(xx,JSON.stringify({agentId:e,text:n}))}catch{}}function t_(e){try{const n=window.sessionStorage.getItem(xx);if(!n)return null;const s=JSON.parse(n);return s.agentId!==e||typeof s.text!="string"?null:(window.sessionStorage.removeItem(xx),s.text)}catch{return null}}const n_=4e3,s_={ts:"TypeScript",tsx:"TypeScript",js:"JavaScript",jsx:"JavaScript",py:"Python",sh:"Shell",bash:"Shell",json:"JSON",sql:"SQL",md:"Markdown",html:"HTML",css:"CSS",go:"Go",rs:"Rust",yaml:"YAML",yml:"YAML"},tA=e=>s_[e.toLowerCase()]??e;function Lf(e,n){const s=e.lastIndexOf(`
41
- `,n-1)+1,r=e.indexOf(`
42
- `,n),a=r<0?e.length:r;return{start:s,end:a,text:e.slice(s,a)}}function dc(e,n){return(e.slice(0,Lf(e,n).start).match(/^```/gm)??[]).length%2===1}function r_(e,n){const s=e.slice(0,n),r=/(^|[\s(])@([a-z0-9-]*)$/i.exec(s);return!r||dc(e,n)?null:{start:n-r[2].length-1,query:r[2]}}function a_(e,n){const s=/^\/([a-z0-9-]*)$/i.exec(e.slice(0,n));return s?{query:s[1]}:null}function i_(e,n){return/^\/use @?[a-z0-9-]*$/i.test(e.slice(0,n))}function l_(e){const n=/^\/([a-z][a-z0-9-]*)(?:[ \t]+([\s\S]*))?$/i.exec(e.trim());return n?{name:n[1].toLowerCase(),arg:(n[2]??"").trim()}:null}function o_(e,n,s,r){const a=e.slice(n),i=a.startsWith(" ")?"":" ";return{value:`${e.slice(0,s)}@${r}${i}${a}`,caret:s+r.length+2}}const c_=/^(\s*)([-*]|\d+\.)( )(.*)$/;function sy(e,n){if(dc(e,n))return null;const s=c_.exec(Lf(e,n).text);return s?{indent:s[1],mark:s[2],body:s[4]}:null}function u_(e,n){const s=sy(e,n);if(!s)return null;const r=Lf(e,n);if(s.body.trim()==="")return{value:e.slice(0,r.start)+e.slice(r.end),caret:r.start};const a=/\d/.test(s.mark)?`${parseInt(s.mark,10)+1}.`:s.mark,i=`
43
- ${s.indent}${a} `;return{value:e.slice(0,n)+i+e.slice(n),caret:n+i.length}}function d_(e,n,s){if(!sy(e,n))return null;const r=Lf(e,n);if(!s)return{value:e.slice(0,r.start)+" "+e.slice(r.start),caret:n+2};const a=r.text.replace(/^ {1,2}/,""),i=r.text.length-a.length;return{value:e.slice(0,r.start)+a+e.slice(r.end),caret:Math.max(r.start,n-i)}}function h_(e){const n=e.replace(/\n$/,"").split(`
44
- `);return n.length<3||/^```/m.test(e)?!1:n.filter(r=>/[;{}()=<>]\s*$|^\s{2,}\S|^\t+\S|^\s*(const|let|var|function|def|import|from|export|return|if|for|while|class|SELECT|INSERT|UPDATE|<\w)/.test(r)).length/n.length>.5}function f_(e){return/\bdef \w+\(|^\s*import \w+$|^\s*from \w+ import /m.test(e)?"py":/^\s*(SELECT|INSERT|UPDATE|WITH)\b/im.test(e)?"sql":/^\s*[{[]/.test(e)&&/"\w+"\s*:/.test(e)&&!/;\s*$/m.test(e)?"json":/:\s*\w+[\]>]?\s*[=;),]|\binterface \w+|\bas const\b|\btype \w+ =/.test(e)?"ts":"js"}function m_(e,n,s,r){const i=`${n>0&&e[n-1]!==`
45
- `?`
46
- `:""}\`\`\`${r}
47
- ${s.replace(/\n$/,"")}
48
- \`\`\`
49
- `;return{value:e.slice(0,n)+i+e.slice(n),caret:n+i.length}}function p_(e){const n=e.replace(/```[\s\S]*?(```|$)/g," ").replace(/`[^`\n]*`/g," "),s=[];for(const r of n.matchAll(/(^|[\s(])@([a-z][a-z0-9-]*)/gi)){const a=r[2].toLowerCase();s.includes(a)||s.push(a)}return s}function nA(e){const n=/^@([a-z][a-z0-9-]*)\s*[:,]?[ \t]*([\s\S]*)$/i.exec(e.trim());return n?{handle:n[1].toLowerCase(),rest:n[2].trim()}:null}function sA(e){return e==="anthropic"||e==="openai"}function rA(e,n){var a,i;if(!e)return null;const s=e.credentialEnv&&(n!=null&&n.accounts.some(l=>l.id===e.credentialEnv))?e.credentialEnv:(i=(a=n==null?void 0:n.bindings)==null?void 0:a.find(l=>l.agentId===e.id))==null?void 0:i.accountId,r=s?n==null?void 0:n.accounts.find(l=>l.id===s):void 0;return(r==null?void 0:r.kind)??e.provider}const g_="Thinking is up to this model. What it writes while thinking is shown apart and kept out of the answer.";var x_=Object.defineProperty,v_=(e,n)=>x_(e,"name",{value:n,configurable:!0}),j_=h.createContext(void 0);function Ff(e){const n=h.useContext(j_);return e||n||"ltr"}v_(Ff,"useDirection");var y_=Object.defineProperty,ry=(e,n)=>y_(e,"name",{value:n,configurable:!0}),Zu=0,yr=null;function w_(e){return _f(),e.children}ry(w_,"FocusGuards");function _f(){h.useEffect(()=>{yr||(yr={start:vx(),end:vx()});const{start:e,end:n}=yr;return document.body.firstElementChild!==e&&document.body.insertAdjacentElement("afterbegin",e),document.body.lastElementChild!==n&&document.body.insertAdjacentElement("beforeend",n),Zu++,()=>{Zu===1&&(yr==null||yr.start.remove(),yr==null||yr.end.remove(),yr=null),Zu=Math.max(0,Zu-1)}},[])}ry(_f,"useFocusGuards");function vx(){const e=document.createElement("span");return e.setAttribute("data-radix-focus-guard",""),e.tabIndex=0,e.style.outline="none",e.style.opacity="0",e.style.position="fixed",e.style.pointerEvents="none",e}ry(vx,"createFocusGuard");var b_=Object.defineProperty,Gn=(e,n)=>b_(e,"name",{value:n,configurable:!0}),tp="focusScope.autoFocusOnMount",np="focusScope.autoFocusOnUnmount",Jk={bubbles:!1,cancelable:!0},aA=h.forwardRef(Gn(function(n,s){const{loop:r=!1,trapped:a=!1,onMountAutoFocus:i,onUnmountAutoFocus:l,...o}=n,[c,u]=h.useState(null),d=Yn(i),f=Yn(l),m=h.useRef(null),p=$t(s,u),g=h.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;h.useEffect(()=>{if(a){let b=function(w){if(g.paused||!c)return;const k=w.target;c.contains(k)?m.current=k:Qr(m.current,{select:!0})},j=function(w){if(g.paused||!c)return;const k=w.relatedTarget;k!==null&&(c.contains(k)||Qr(m.current,{select:!0}))},x=function(w){if(document.activeElement===document.body)for(const N of w)N.removedNodes.length>0&&Qr(c)};Gn(b,"handleFocusIn"),Gn(j,"handleFocusOut"),Gn(x,"handleMutations"),document.addEventListener("focusin",b),document.addEventListener("focusout",j);const y=new MutationObserver(x);return c&&y.observe(c,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",b),document.removeEventListener("focusout",j),y.disconnect()}}},[a,c,g.paused]),h.useEffect(()=>{if(c){Qk.add(g);const b=document.activeElement;if(!c.contains(b)){const x=new CustomEvent(tp,Jk);c.addEventListener(tp,d),c.dispatchEvent(x),x.defaultPrevented||(iA(dA(ay(c)),{select:!0}),document.activeElement===b&&Qr(c))}return()=>{c.removeEventListener(tp,d),setTimeout(()=>{const x=new CustomEvent(np,Jk);c.addEventListener(np,f),c.dispatchEvent(x),x.defaultPrevented||Qr(b??document.body,{select:!0}),c.removeEventListener(np,f),Qk.remove(g)},0)}}},[c,d,f,g]);const v=h.useCallback(b=>{if(!r&&!a||g.paused)return;const j=b.key==="Tab"&&!b.altKey&&!b.ctrlKey&&!b.metaKey,x=document.activeElement;if(j&&x){const y=b.currentTarget,[w,k]=lA(y);w&&k?!b.shiftKey&&x===k?(b.preventDefault(),r&&Qr(w,{select:!0})):b.shiftKey&&x===w&&(b.preventDefault(),r&&Qr(k,{select:!0})):x===y&&b.preventDefault()}},[r,a,g.paused]);return t.jsx(bt.div,{tabIndex:-1,...o,ref:p,onKeyDown:v})},"FocusScope"));function iA(e,{select:n=!1}={}){const s=document.activeElement;for(const r of e)if(Qr(r,{select:n}),document.activeElement!==s)return}Gn(iA,"focusFirst");function lA(e){const n=ay(e),s=jx(n,e),r=jx(n.reverse(),e);return[s,r]}Gn(lA,"getTabbableEdges");function ay(e){const n=[],s=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:Gn(r=>{const a=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||a?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP},"acceptNode")});for(;s.nextNode();)n.push(s.currentNode);return n}Gn(ay,"getTabbableCandidates");function jx(e,n){const s=typeof n.checkVisibility=="function"&&n.checkVisibility({checkVisibilityCSS:!0});for(const r of e)if(!(s?!r.checkVisibility({checkVisibilityCSS:!0}):oA(r,{upTo:n})))return r}Gn(jx,"findVisible");function oA(e,{upTo:n}){if(getComputedStyle(e).visibility==="hidden")return!0;for(;e;){if(n!==void 0&&e===n)return!1;if(getComputedStyle(e).display==="none")return!0;e=e.parentElement}return!1}Gn(oA,"isHidden");function cA(e){return e instanceof HTMLInputElement&&"select"in e}Gn(cA,"isSelectableInput");function Qr(e,{select:n=!1}={}){if(e&&e.focus){const s=document.activeElement;e.focus({preventScroll:!0}),e!==s&&cA(e)&&n&&e.select()}}Gn(Qr,"focus");var Qk=uA();function uA(){let e=[];return{add(n){const s=e[0];n!==s&&(s==null||s.pause()),e=yx(e,n),e.unshift(n)},remove(n){var s;e=yx(e,n),(s=e[0])==null||s.resume()}}}Gn(uA,"createFocusScopesStack");function yx(e,n){const s=[...e],r=s.indexOf(n);return r!==-1&&s.splice(r,1),s}Gn(yx,"arrayRemove");function dA(e){return e.filter(n=>n.tagName!=="A")}Gn(dA,"removeLinks");var k_=Object.defineProperty,iy=(e,n)=>k_(e,"name",{value:n,configurable:!0}),sp=!1;function hA(){const[e,n]=h.useState(sp);return h.useEffect(()=>{sp||(sp=!0,n(!0))},[]),e}iy(hA,"useIsHydrated");var fA=lo[" useSyncExternalStore ".trim().toString()];function mA(){return()=>{}}iy(mA,"subscribe");function pA(){return fA(mA,()=>!0,()=>!1)}iy(pA,"useIsHydratedModern");var N_=typeof fA=="function"?pA:hA,S_=Object.defineProperty,Hi=(e,n)=>S_(e,"name",{value:n,configurable:!0}),rp="rovingFocusGroup.onEntryFocus",C_={bubbles:!1,cancelable:!0},zf="RovingFocusGroup",[wx,gA,E_]=kf(zf),[A_,Uf]=fr(zf,[E_]),[$_,T_]=A_(zf),R_=h.forwardRef(Hi(function(n,s){return t.jsx(wx.Provider,{scope:n.__scopeRovingFocusGroup,children:t.jsx(wx.Slot,{scope:n.__scopeRovingFocusGroup,children:t.jsx(I_,{...n,ref:s})})})},"RovingFocusGroup")),I_=h.forwardRef(Hi(function(n,s){const{__scopeRovingFocusGroup:r,orientation:a,loop:i=!1,dir:l,currentTabStopId:o,defaultCurrentTabStopId:c,onCurrentTabStopIdChange:u,onEntryFocus:d,preventScrollOnEntryFocus:f=!1,...m}=n,p=h.useRef(null),g=$t(s,p),v=Ff(l),[b,j]=ni({prop:o,defaultProp:c??null,onChange:u,caller:zf}),[x,y]=h.useState(!1),w=Yn(d),k=gA(r),N=h.useRef(!1),[S,C]=h.useState(0);return h.useEffect(()=>{const E=p.current;if(E)return E.addEventListener(rp,w),()=>E.removeEventListener(rp,w)},[w]),t.jsx($_,{scope:r,orientation:a,dir:v,loop:i,currentTabStopId:b,onItemFocus:h.useCallback(E=>j(E),[j]),onItemShiftTab:h.useCallback(()=>y(!0),[]),onFocusableItemAdd:h.useCallback(()=>C(E=>E+1),[]),onFocusableItemRemove:h.useCallback(()=>C(E=>E-1),[]),children:t.jsx(bt.div,{tabIndex:x||S===0?-1:0,"data-orientation":a,...m,ref:g,style:{outline:"none",...n.style},onMouseDown:_e(n.onMouseDown,()=>{N.current=!0}),onFocus:_e(n.onFocus,E=>{const T=!N.current;if(E.target===E.currentTarget&&T&&!x){const I=new CustomEvent(rp,C_);if(E.currentTarget.dispatchEvent(I),!I.defaultPrevented){const F=k().filter(M=>M.focusable),D=F.find(M=>M.active),$=F.find(M=>M.id===b),O=[D,$,...F].filter(Boolean).map(M=>M.ref.current);ly(O,f)}}N.current=!1}),onBlur:_e(n.onBlur,()=>y(!1))})})},"RovingFocusGroupImpl")),P_="RovingFocusGroupItem",M_=h.forwardRef(Hi(function(n,s){const{__scopeRovingFocusGroup:r,focusable:a=!0,active:i=!1,tabStopId:l,children:o,...c}=n,u=ir(),d=l||u,f=T_(P_,r),m=f.currentTabStopId===d,p=gA(r),{onFocusableItemAdd:g,onFocusableItemRemove:v,currentTabStopId:b}=f,j=N_();return cs(()=>{if(!(!j||!a))return g(),()=>v()},[j,a,g,v]),h.useEffect(()=>{if(!(j||!a))return g(),()=>v()},[j,a,g,v]),t.jsx(wx.ItemSlot,{scope:r,id:d,focusable:a,active:i,children:t.jsx(bt.span,{tabIndex:m?0:-1,"data-orientation":f.orientation,...c,ref:s,onMouseDown:_e(n.onMouseDown,x=>{a?f.onItemFocus(d):x.preventDefault()}),onFocus:_e(n.onFocus,()=>f.onItemFocus(d)),onKeyDown:_e(n.onKeyDown,x=>{if(x.key==="Tab"&&x.shiftKey){f.onItemShiftTab();return}if(x.target!==x.currentTarget)return;const y=vA(x,f.orientation,f.dir);if(y!==void 0){if(x.metaKey||x.ctrlKey||x.altKey||x.shiftKey)return;x.preventDefault();let k=p().filter(N=>N.focusable).map(N=>N.ref.current);if(y==="last")k.reverse();else if(y==="prev"||y==="next"){y==="prev"&&k.reverse();const N=k.indexOf(x.currentTarget);k=f.loop?jA(k,N+1):k.slice(N+1)}setTimeout(()=>ly(k))}}),children:typeof o=="function"?o({isCurrentTabStop:m,hasTabStop:b!=null}):o})})},"RovingFocusGroupItem")),D_={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function xA(e,n){return n!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}Hi(xA,"getDirectionAwareKey");function vA(e,n,s){const r=xA(e.key,s);if(!(n==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(n==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return D_[r]}Hi(vA,"getFocusIntent");function ly(e,n=!1){const s=document.activeElement;for(const r of e)if(r===s||(r.focus({preventScroll:n}),document.activeElement!==s))return}Hi(ly,"focusFirst");function jA(e,n){return e.map((s,r)=>e[(n+r)%e.length])}Hi(jA,"wrapArray");var yA=R_,wA=M_,O_=function(e){if(typeof document>"u")return null;var n=Array.isArray(e)?e[0]:e;return n.ownerDocument.body},sl=new WeakMap,ed=new WeakMap,td={},ap=0,bA=function(e){return e&&(e.host||bA(e.parentNode))},L_=function(e,n){return n.map(function(s){if(e.contains(s))return s;var r=bA(s);return r&&e.contains(r)?r:(console.error("aria-hidden",s,"in not contained inside",e,". Doing nothing"),null)}).filter(function(s){return!!s})},F_=function(e,n,s,r){var a=L_(n,Array.isArray(e)?e:[e]);td[s]||(td[s]=new WeakMap);var i=td[s],l=[],o=new Set,c=new Set(a),u=function(f){!f||o.has(f)||(o.add(f),u(f.parentNode))};a.forEach(u);var d=function(f){!f||c.has(f)||Array.prototype.forEach.call(f.children,function(m){if(o.has(m))d(m);else try{var p=m.getAttribute(r),g=p!==null&&p!=="false",v=(sl.get(m)||0)+1,b=(i.get(m)||0)+1;sl.set(m,v),i.set(m,b),l.push(m),v===1&&g&&ed.set(m,!0),b===1&&m.setAttribute(s,"true"),g||m.setAttribute(r,"true")}catch(j){console.error("aria-hidden: cannot operate on ",m,j)}})};return d(n),o.clear(),ap++,function(){l.forEach(function(f){var m=sl.get(f)-1,p=i.get(f)-1;sl.set(f,m),i.set(f,p),m||(ed.has(f)||f.removeAttribute(r),ed.delete(f)),p||f.removeAttribute(s)}),ap--,ap||(sl=new WeakMap,sl=new WeakMap,ed=new WeakMap,td={})}},kA=function(e,n,s){s===void 0&&(s="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),a=O_(e);return a?(r.push.apply(r,Array.from(a.querySelectorAll("[aria-live], script"))),F_(r,a,s,"aria-hidden")):function(){return null}},Sr=function(){return Sr=Object.assign||function(n){for(var s,r=1,a=arguments.length;r<a;r++){s=arguments[r];for(var i in s)Object.prototype.hasOwnProperty.call(s,i)&&(n[i]=s[i])}return n},Sr.apply(this,arguments)};function NA(e,n){var s={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&n.indexOf(r)<0&&(s[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var a=0,r=Object.getOwnPropertySymbols(e);a<r.length;a++)n.indexOf(r[a])<0&&Object.prototype.propertyIsEnumerable.call(e,r[a])&&(s[r[a]]=e[r[a]]);return s}function __(e,n,s){if(s||arguments.length===2)for(var r=0,a=n.length,i;r<a;r++)(i||!(r in n))&&(i||(i=Array.prototype.slice.call(n,0,r)),i[r]=n[r]);return e.concat(i||Array.prototype.slice.call(n))}var zd="right-scroll-bar-position",Ud="width-before-scroll-bar",z_="with-scroll-bars-hidden",U_="--removed-body-scroll-bar-size";function ip(e,n){return typeof e=="function"?e(n):e&&(e.current=n),e}function B_(e,n){var s=h.useState(function(){return{value:e,callback:n,facade:{get current(){return s.value},set current(r){var a=s.value;a!==r&&(s.value=r,s.callback(r,a))}}}})[0];return s.callback=n,s.facade}var W_=typeof window<"u"?h.useLayoutEffect:h.useEffect,Xk=new WeakMap;function H_(e,n){var s=B_(null,function(r){return e.forEach(function(a){return ip(a,r)})});return W_(function(){var r=Xk.get(s);if(r){var a=new Set(r),i=new Set(e),l=s.current;a.forEach(function(o){i.has(o)||ip(o,null)}),i.forEach(function(o){a.has(o)||ip(o,l)})}Xk.set(s,e)},[e]),s}function K_(e){return e}function V_(e,n){n===void 0&&(n=K_);var s=[],r=!1,a={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return s.length?s[s.length-1]:e},useMedium:function(i){var l=n(i,r);return s.push(l),function(){s=s.filter(function(o){return o!==l})}},assignSyncMedium:function(i){for(r=!0;s.length;){var l=s;s=[],l.forEach(i)}s={push:function(o){return i(o)},filter:function(){return s}}},assignMedium:function(i){r=!0;var l=[];if(s.length){var o=s;s=[],o.forEach(i),l=s}var c=function(){var d=l;l=[],d.forEach(i)},u=function(){return Promise.resolve().then(c)};u(),s={push:function(d){l.push(d),u()},filter:function(d){return l=l.filter(d),s}}}};return a}function G_(e){e===void 0&&(e={});var n=V_(null);return n.options=Sr({async:!0,ssr:!1},e),n}var SA=function(e){var n=e.sideCar,s=NA(e,["sideCar"]);if(!n)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=n.read();if(!r)throw new Error("Sidecar medium not found");return h.createElement(r,Sr({},s))};SA.isSideCarExport=!0;function q_(e,n){return e.useMedium(n),SA}var CA=G_(),lp=function(){},Bf=h.forwardRef(function(e,n){var s=h.useRef(null),r=h.useState({onScrollCapture:lp,onWheelCapture:lp,onTouchMoveCapture:lp}),a=r[0],i=r[1],l=e.forwardProps,o=e.children,c=e.className,u=e.removeScrollBar,d=e.enabled,f=e.shards,m=e.sideCar,p=e.noRelative,g=e.noIsolation,v=e.inert,b=e.allowPinchZoom,j=e.as,x=j===void 0?"div":j,y=e.gapMode,w=NA(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),k=m,N=H_([s,n]),S=Sr(Sr({},w),a);return h.createElement(h.Fragment,null,d&&h.createElement(k,{sideCar:CA,removeScrollBar:u,shards:f,noRelative:p,noIsolation:g,inert:v,setCallbacks:i,allowPinchZoom:!!b,lockRef:s,gapMode:y}),l?h.cloneElement(h.Children.only(o),Sr(Sr({},S),{ref:N})):h.createElement(x,Sr({},S,{className:c,ref:N}),o))});Bf.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};Bf.classNames={fullWidth:Ud,zeroRight:zd};var Y_=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function J_(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var n=Y_();return n&&e.setAttribute("nonce",n),e}function Q_(e,n){e.styleSheet?e.styleSheet.cssText=n:e.appendChild(document.createTextNode(n))}function X_(e){var n=document.head||document.getElementsByTagName("head")[0];n.appendChild(e)}var Z_=function(){var e=0,n=null;return{add:function(s){e==0&&(n=J_())&&(Q_(n,s),X_(n)),e++},remove:function(){e--,!e&&n&&(n.parentNode&&n.parentNode.removeChild(n),n=null)}}},e4=function(){var e=Z_();return function(n,s){h.useEffect(function(){return e.add(n),function(){e.remove()}},[n&&s])}},EA=function(){var e=e4(),n=function(s){var r=s.styles,a=s.dynamic;return e(r,a),null};return n},t4={left:0,top:0,right:0,gap:0},op=function(e){return parseInt(e||"",10)||0},n4=function(e){var n=window.getComputedStyle(document.body),s=n[e==="padding"?"paddingLeft":"marginLeft"],r=n[e==="padding"?"paddingTop":"marginTop"],a=n[e==="padding"?"paddingRight":"marginRight"];return[op(s),op(r),op(a)]},s4=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return t4;var n=n4(e),s=document.documentElement.clientWidth,r=window.innerWidth;return{left:n[0],top:n[1],right:n[2],gap:Math.max(0,r-s+n[2]-n[0])}},r4=EA(),Dl="data-scroll-locked",a4=function(e,n,s,r){var a=e.left,i=e.top,l=e.right,o=e.gap;return s===void 0&&(s="margin"),`
50
- .`.concat(z_,` {
51
- overflow: hidden `).concat(r,`;
52
- padding-right: `).concat(o,"px ").concat(r,`;
53
- }
54
- body[`).concat(Dl,`] {
55
- overflow: hidden `).concat(r,`;
56
- overscroll-behavior: contain;
57
- `).concat([n&&"position: relative ".concat(r,";"),s==="margin"&&`
58
- padding-left: `.concat(a,`px;
59
- padding-top: `).concat(i,`px;
60
- padding-right: `).concat(l,`px;
61
- margin-left:0;
62
- margin-top:0;
63
- margin-right: `).concat(o,"px ").concat(r,`;
64
- `),s==="padding"&&"padding-right: ".concat(o,"px ").concat(r,";")].filter(Boolean).join(""),`
65
- }
66
-
67
- .`).concat(zd,` {
68
- right: `).concat(o,"px ").concat(r,`;
69
- }
70
-
71
- .`).concat(Ud,` {
72
- margin-right: `).concat(o,"px ").concat(r,`;
73
- }
74
-
75
- .`).concat(zd," .").concat(zd,` {
76
- right: 0 `).concat(r,`;
77
- }
78
-
79
- .`).concat(Ud," .").concat(Ud,` {
80
- margin-right: 0 `).concat(r,`;
81
- }
82
-
83
- body[`).concat(Dl,`] {
84
- `).concat(U_,": ").concat(o,`px;
85
- }
86
- `)},Zk=function(){var e=parseInt(document.body.getAttribute(Dl)||"0",10);return isFinite(e)?e:0},i4=function(){h.useEffect(function(){return document.body.setAttribute(Dl,(Zk()+1).toString()),function(){var e=Zk()-1;e<=0?document.body.removeAttribute(Dl):document.body.setAttribute(Dl,e.toString())}},[])},l4=function(e){var n=e.noRelative,s=e.noImportant,r=e.gapMode,a=r===void 0?"margin":r;i4();var i=h.useMemo(function(){return s4(a)},[a]);return h.createElement(r4,{styles:a4(i,!n,a,s?"":"!important")})},bx=!1;if(typeof window<"u")try{var nd=Object.defineProperty({},"passive",{get:function(){return bx=!0,!0}});window.addEventListener("test",nd,nd),window.removeEventListener("test",nd,nd)}catch{bx=!1}var rl=bx?{passive:!1}:!1,o4=function(e){return e.tagName==="TEXTAREA"},AA=function(e,n){if(!(e instanceof Element))return!1;var s=window.getComputedStyle(e);return s[n]!=="hidden"&&!(s.overflowY===s.overflowX&&!o4(e)&&s[n]==="visible")},c4=function(e){return AA(e,"overflowY")},u4=function(e){return AA(e,"overflowX")},e0=function(e,n){var s=n.ownerDocument,r=n;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var a=$A(e,r);if(a){var i=TA(e,r),l=i[1],o=i[2];if(l>o)return!0}r=r.parentNode}while(r&&r!==s.body);return!1},d4=function(e){var n=e.scrollTop,s=e.scrollHeight,r=e.clientHeight;return[n,s,r]},h4=function(e){var n=e.scrollLeft,s=e.scrollWidth,r=e.clientWidth;return[n,s,r]},$A=function(e,n){return e==="v"?c4(n):u4(n)},TA=function(e,n){return e==="v"?d4(n):h4(n)},f4=function(e,n){return e==="h"&&n==="rtl"?-1:1},m4=function(e,n,s,r,a){var i=f4(e,window.getComputedStyle(n).direction),l=i*r,o=s.target,c=n.contains(o),u=!1,d=l>0,f=0,m=0;do{if(!o)break;var p=TA(e,o),g=p[0],v=p[1],b=p[2],j=v-b-i*g;(g||j)&&$A(e,o)&&(f+=j,m+=g);var x=o.parentNode;o=x&&x.nodeType===Node.DOCUMENT_FRAGMENT_NODE?x.host:x}while(!c&&o!==document.body||c&&(n.contains(o)||n===o));return(d&&Math.abs(f)<1||!d&&Math.abs(m)<1)&&(u=!0),u},sd=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},t0=function(e){return[e.deltaX,e.deltaY]},n0=function(e){return e&&"current"in e?e.current:e},p4=function(e,n){return e[0]===n[0]&&e[1]===n[1]},g4=function(e){return`
87
- .block-interactivity-`.concat(e,` {pointer-events: none;}
88
- .allow-interactivity-`).concat(e,` {pointer-events: all;}
89
- `)},x4=0,al=[];function v4(e){var n=h.useRef([]),s=h.useRef([0,0]),r=h.useRef(),a=h.useState(x4++)[0],i=h.useState(EA)[0],l=h.useRef(e);h.useEffect(function(){l.current=e},[e]),h.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(a));var v=__([e.lockRef.current],(e.shards||[]).map(n0),!0).filter(Boolean);return v.forEach(function(b){return b.classList.add("allow-interactivity-".concat(a))}),function(){document.body.classList.remove("block-interactivity-".concat(a)),v.forEach(function(b){return b.classList.remove("allow-interactivity-".concat(a))})}}},[e.inert,e.lockRef.current,e.shards]);var o=h.useCallback(function(v,b){if("touches"in v&&v.touches.length===2||v.type==="wheel"&&v.ctrlKey)return!l.current.allowPinchZoom;var j=sd(v),x=s.current,y="deltaX"in v?v.deltaX:x[0]-j[0],w="deltaY"in v?v.deltaY:x[1]-j[1],k,N=v.target,S=Math.abs(y)>Math.abs(w)?"h":"v";if("touches"in v&&S==="h"&&N.type==="range")return!1;var C=window.getSelection(),E=C&&C.anchorNode,T=E?E===N||E.contains(N):!1;if(T)return!1;var I=e0(S,N);if(!I)return!0;if(I?k=S:(k=S==="v"?"h":"v",I=e0(S,N)),!I)return!1;if(!r.current&&"changedTouches"in v&&(y||w)&&(r.current=k),!k)return!0;var F=r.current||k;return m4(F,b,v,F==="h"?y:w)},[]),c=h.useCallback(function(v){var b=v;if(!(!al.length||al[al.length-1]!==i)){var j="deltaY"in b?t0(b):sd(b),x=n.current.filter(function(k){return k.name===b.type&&(k.target===b.target||b.target===k.shadowParent)&&p4(k.delta,j)})[0];if(x&&x.should){b.cancelable&&b.preventDefault();return}if(!x){var y=(l.current.shards||[]).map(n0).filter(Boolean).filter(function(k){return k.contains(b.target)}),w=y.length>0?o(b,y[0]):!l.current.noIsolation;w&&b.cancelable&&b.preventDefault()}}},[]),u=h.useCallback(function(v,b,j,x){var y={name:v,delta:b,target:j,should:x,shadowParent:j4(j)};n.current.push(y),setTimeout(function(){n.current=n.current.filter(function(w){return w!==y})},1)},[]),d=h.useCallback(function(v){s.current=sd(v),r.current=void 0},[]),f=h.useCallback(function(v){u(v.type,t0(v),v.target,o(v,e.lockRef.current))},[]),m=h.useCallback(function(v){u(v.type,sd(v),v.target,o(v,e.lockRef.current))},[]);h.useEffect(function(){return al.push(i),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:m}),document.addEventListener("wheel",c,rl),document.addEventListener("touchmove",c,rl),document.addEventListener("touchstart",d,rl),function(){al=al.filter(function(v){return v!==i}),document.removeEventListener("wheel",c,rl),document.removeEventListener("touchmove",c,rl),document.removeEventListener("touchstart",d,rl)}},[]);var p=e.removeScrollBar,g=e.inert;return h.createElement(h.Fragment,null,g?h.createElement(i,{styles:g4(a)}):null,p?h.createElement(l4,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function j4(e){for(var n=null;e!==null;)e instanceof ShadowRoot&&(n=e.host,e=e.host),e=e.parentNode;return n}const y4=q_(CA,v4);var oy=h.forwardRef(function(e,n){return h.createElement(Bf,Sr({},e,{ref:n,sideCar:y4}))});oy.classNames=Bf.classNames;var w4=Object.defineProperty,gt=(e,n)=>w4(e,"name",{value:n,configurable:!0}),kx=["Enter"," "],b4=["ArrowDown","PageUp","Home"],RA=["ArrowUp","PageDown","End"],k4=[...b4,...RA],N4={ltr:[...kx,"ArrowRight"],rtl:[...kx,"ArrowLeft"]},S4={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Wf="Menu",[Gc,C4,E4]=kf(Wf),[Ki,IA]=fr(Wf,[E4,Mf,Uf]),Hf=Mf(),PA=Uf(),[MA,ri]=Ki(Wf),[A4,vu]=Ki(Wf),$4=gt(e=>{const{__scopeMenu:n,open:s=!1,children:r,dir:a,onOpenChange:i,modal:l=!0}=e,o=Hf(n),[c,u]=h.useState(null),d=h.useRef(!1),f=Yn(i),m=Ff(a);return h.useEffect(()=>{const p=gt(()=>{d.current=!0,document.addEventListener("pointerdown",g,{capture:!0,once:!0}),document.addEventListener("pointermove",g,{capture:!0,once:!0})},"handleKeyDown"),g=gt(()=>d.current=!1,"handlePointer");return document.addEventListener("keydown",p,{capture:!0}),()=>{document.removeEventListener("keydown",p,{capture:!0}),document.removeEventListener("pointerdown",g,{capture:!0}),document.removeEventListener("pointermove",g,{capture:!0})}},[]),h.useEffect(()=>{if(!s)return;const p=gt(()=>f(!1),"handleBlur");return window.addEventListener("blur",p),()=>window.removeEventListener("blur",p)},[s,f]),t.jsx(Gj,{...o,children:t.jsx(MA,{scope:n,open:s,onOpenChange:f,content:c,onContentChange:u,children:t.jsx(A4,{scope:n,onClose:h.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:d,dir:m,modal:l,children:r})})})},"Menu"),DA=h.forwardRef(gt(function(n,s){const{__scopeMenu:r,...a}=n,i=Hf(r);return t.jsx(BE,{...i,...a,ref:s})},"MenuAnchor")),OA="MenuPortal",[T4,LA]=Ki(OA,{forceMount:void 0}),R4=gt(e=>{const{__scopeMenu:n,forceMount:s,children:r,container:a}=e,i=ri(OA,n);return t.jsx(T4,{scope:n,forceMount:s,children:t.jsx(Br,{present:s||i.open,children:t.jsx(Cf,{asChild:!0,container:a,children:r})})})},"MenuPortal"),lr="MenuContent",[I4,cy]=Ki(lr),P4=h.forwardRef(gt(function(n,s){const r=LA(lr,n.__scopeMenu),{forceMount:a=r.forceMount,...i}=n,l=ri(lr,n.__scopeMenu),o=vu(lr,n.__scopeMenu);return t.jsx(Gc.Provider,{scope:n.__scopeMenu,children:t.jsx(Br,{present:a||l.open,children:t.jsx(Gc.Slot,{scope:n.__scopeMenu,children:o.modal?t.jsx(M4,{...i,ref:s}):t.jsx(D4,{...i,ref:s})})})})},"MenuContent")),M4=h.forwardRef(gt(function(n,s){const r=ri(lr,n.__scopeMenu),a=h.useRef(null),i=$t(s,a);return h.useEffect(()=>{const l=a.current;if(l)return kA(l)},[]),t.jsx(uy,{...n,ref:i,trapFocus:r.open,disableOutsidePointerEvents:r.open,disableOutsideScroll:!0,onFocusOutside:_e(n.onFocusOutside,l=>l.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>r.onOpenChange(!1)})},"MenuRootContentModal")),D4=h.forwardRef(gt(function(n,s){const r=ri(lr,n.__scopeMenu);return t.jsx(uy,{...n,ref:s,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>r.onOpenChange(!1)})},"MenuRootContentNonModal")),O4=Ka("MenuContent.ScrollLock"),uy=h.forwardRef(gt(function(n,s){const{__scopeMenu:r,loop:a=!1,trapFocus:i,onOpenAutoFocus:l,onCloseAutoFocus:o,disableOutsidePointerEvents:c,onEntryFocus:u,onEscapeKeyDown:d,onPointerDownOutside:f,onFocusOutside:m,onInteractOutside:p,onDismiss:g,disableOutsideScroll:v,...b}=n,j=ri(lr,r),x=vu(lr,r),y=Hf(r),w=PA(r),k=C4(r),[N,S]=h.useState(null),C=h.useRef(null),E=$t(s,C,j.onContentChange),T=h.useRef(0),I=h.useRef(""),F=h.useRef(0),D=h.useRef(null),$=h.useRef("right"),L=h.useRef(0),O=v?oy:h.Fragment,M=v?{as:O4,allowPinchZoom:!0}:void 0,P=gt(U=>{var oe,Re;const V=I.current+U,z=k().filter(Oe=>!Oe.disabled),X=document.activeElement,K=(oe=z.find(Oe=>Oe.ref.current===X))==null?void 0:oe.textValue,ee=z.map(Oe=>Oe.textValue),ce=GA(ee,V,K),pe=(Re=z.find(Oe=>Oe.textValue===ce))==null?void 0:Re.ref.current;gt(function Oe(Je){I.current=Je,window.clearTimeout(T.current),Je!==""&&(T.current=window.setTimeout(()=>Oe(""),1e3))},"updateSearch")(V),pe&&setTimeout(()=>pe.focus())},"handleTypeaheadSearch");h.useEffect(()=>()=>window.clearTimeout(T.current),[]),_f();const H=h.useCallback(U=>{var z,X;return $.current===((z=D.current)==null?void 0:z.side)&&YA(U,(X=D.current)==null?void 0:X.area)},[]);return t.jsx(I4,{scope:r,searchRef:I,onItemEnter:h.useCallback(U=>{H(U)&&U.preventDefault()},[H]),onItemLeave:h.useCallback(U=>{var V;H(U)||((V=C.current)==null||V.focus(),S(null))},[H]),onTriggerLeave:h.useCallback(U=>{H(U)&&U.preventDefault()},[H]),pointerGraceTimerRef:F,onPointerGraceIntentChange:h.useCallback(U=>{D.current=U},[]),children:t.jsx(O,{...M,children:t.jsx(aA,{asChild:!0,trapped:i,onMountAutoFocus:_e(l,U=>{var V;U.preventDefault(),(V=C.current)==null||V.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:t.jsx(Sf,{asChild:!0,disableOutsidePointerEvents:c,onEscapeKeyDown:d,onPointerDownOutside:f,onFocusOutside:m,onInteractOutside:p,onDismiss:g,children:t.jsx(yA,{asChild:!0,...w,dir:x.dir,orientation:"vertical",loop:a,currentTabStopId:N,onCurrentTabStopIdChange:S,onEntryFocus:_e(u,U=>{x.isUsingKeyboardRef.current||U.preventDefault()}),preventScrollOnEntryFocus:!0,children:t.jsx(WE,{role:"menu","aria-orientation":"vertical","data-state":dy(j.open),"data-radix-menu-content":"",dir:x.dir,...y,...b,ref:E,style:{outline:"none",...b.style},onKeyDown:_e(b.onKeyDown,U=>{const z=U.target.closest("[data-radix-menu-content]")===U.currentTarget,X=U.ctrlKey||U.altKey||U.metaKey,K=U.key.length===1;z&&(U.key==="Tab"&&U.preventDefault(),!X&&K&&P(U.key));const ee=C.current;if(U.target!==ee||!k4.includes(U.key))return;U.preventDefault();const pe=k().filter(oe=>!oe.disabled).map(oe=>oe.ref.current);RA.includes(U.key)&&pe.reverse(),KA(pe)}),onBlur:_e(n.onBlur,U=>{U.currentTarget.contains(U.target)||(window.clearTimeout(T.current),I.current="")}),onPointerMove:_e(n.onPointerMove,Gl(U=>{const V=U.target,z=L.current!==U.clientX;if(U.currentTarget.contains(V)&&z){const X=U.clientX>L.current?"right":"left";$.current=X,L.current=U.clientX}}))})})})})})})},"MenuContentImpl")),FA=h.forwardRef(gt(function(n,s){const{__scopeMenu:r,...a}=n;return t.jsx(bt.div,{role:"group",...a,ref:s})},"MenuGroup")),L4=h.forwardRef(gt(function(n,s){const{__scopeMenu:r,...a}=n;return t.jsx(bt.div,{...a,ref:s})},"MenuLabel")),Nx="MenuItem",s0="menu.itemSelect",_A=h.forwardRef(gt(function(n,s){const{disabled:r=!1,onSelect:a,...i}=n,l=h.useRef(null),o=vu(Nx,n.__scopeMenu),c=cy(Nx,n.__scopeMenu),u=$t(s,l),d=h.useRef(!1),f=gt(()=>{const m=l.current;if(!r&&m){const p=new CustomEvent(s0,{bubbles:!0,cancelable:!0});m.addEventListener(s0,g=>a==null?void 0:a(g),{once:!0}),Nf(m,p),p.defaultPrevented?d.current=!1:o.onClose()}},"handleSelect");return t.jsx(zA,{...i,ref:u,disabled:r,onClick:_e(n.onClick,f),onPointerDown:m=>{var p;(p=n.onPointerDown)==null||p.call(n,m),d.current=!0},onPointerUp:_e(n.onPointerUp,m=>{var p;d.current||(p=m.currentTarget)==null||p.click()}),onKeyDown:_e(n.onKeyDown,m=>{r||m.target!==m.currentTarget||c.searchRef.current!==""&&m.key===" "||kx.includes(m.key)&&(m.currentTarget.click(),m.preventDefault())})})},"MenuItem")),zA=h.forwardRef(gt(function(n,s){const{__scopeMenu:r,disabled:a=!1,textValue:i,...l}=n,o=cy(Nx,r),c=PA(r),u=h.useRef(null),d=$t(s,u),[f,m]=h.useState(!1),[p,g]=h.useState("");return h.useEffect(()=>{const v=u.current;v&&g((v.textContent??"").trim())},[l.children]),t.jsx(Gc.ItemSlot,{scope:r,disabled:a,textValue:i??p,children:t.jsx(wA,{asChild:!0,...c,focusable:!a,children:t.jsx(bt.div,{role:"menuitem","data-highlighted":f?"":void 0,"aria-disabled":a||void 0,"data-disabled":a?"":void 0,...l,ref:d,onPointerMove:_e(n.onPointerMove,Gl(v=>{a?o.onItemLeave(v):(o.onItemEnter(v),v.defaultPrevented||v.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:_e(n.onPointerLeave,Gl(v=>o.onItemLeave(v))),onFocus:_e(n.onFocus,()=>m(!0)),onBlur:_e(n.onBlur,()=>m(!1))})})})},"MenuItemImpl")),F4="MenuRadioGroup",[_4,z4]=Ki(F4,{value:void 0,onValueChange:gt(()=>{},"onValueChange")}),U4=h.forwardRef(gt(function(n,s){const{value:r,onValueChange:a,...i}=n,l=Yn(a);return t.jsx(_4,{scope:n.__scopeMenu,value:r,onValueChange:l,children:t.jsx(FA,{...i,ref:s})})},"MenuRadioGroup")),B4="MenuRadioItem",W4=h.forwardRef(gt(function(n,s){const{value:r,...a}=n,i=z4(B4,n.__scopeMenu),l=r===i.value;return t.jsx(K4,{scope:n.__scopeMenu,checked:l,children:t.jsx(_A,{role:"menuitemradio","aria-checked":l,...a,ref:s,"data-state":HA(l),onSelect:_e(a.onSelect,()=>{var o;return(o=i.onValueChange)==null?void 0:o.call(i,r)},{checkForDefaultPrevented:!1})})})},"MenuRadioItem")),H4="MenuItemIndicator",[K4,Zte]=Ki(H4,{checked:!1}),V4=h.forwardRef(gt(function(n,s){const{__scopeMenu:r,...a}=n;return t.jsx(bt.div,{role:"separator","aria-orientation":"horizontal",...a,ref:s})},"MenuSeparator")),UA="MenuSub",[G4,BA]=Ki(UA),q4=gt(e=>{const{__scopeMenu:n,children:s,open:r=!1,onOpenChange:a}=e,i=ri(UA,n),l=Hf(n),[o,c]=h.useState(null),[u,d]=h.useState(null),f=Yn(a);return h.useEffect(()=>(i.open===!1&&f(!1),()=>f(!1)),[i.open,f]),t.jsx(Gj,{...l,children:t.jsx(MA,{scope:n,open:r,onOpenChange:f,content:u,onContentChange:d,children:t.jsx(G4,{scope:n,contentId:ir(),triggerId:ir(),trigger:o,onTriggerChange:c,children:s})})})},"MenuSub"),rd="MenuSubTrigger",Y4=h.forwardRef(gt(function(n,s){const r=ri(rd,n.__scopeMenu),a=vu(rd,n.__scopeMenu),i=BA(rd,n.__scopeMenu),l=cy(rd,n.__scopeMenu),o=h.useRef(null),{pointerGraceTimerRef:c,onPointerGraceIntentChange:u}=l,d={__scopeMenu:n.__scopeMenu},f=h.useCallback(()=>{o.current&&window.clearTimeout(o.current),o.current=null},[]);h.useEffect(()=>f,[f]),h.useEffect(()=>{const p=c.current;return()=>{window.clearTimeout(p),u(null)}},[c,u]);const m=$t(s,i.onTriggerChange);return t.jsx(DA,{asChild:!0,...d,children:t.jsx(zA,{id:i.triggerId,"aria-haspopup":"menu","aria-expanded":r.open,"aria-controls":r.open?i.contentId:void 0,"data-state":dy(r.open),...n,ref:m,onClick:p=>{var g;(g=n.onClick)==null||g.call(n,p),!(n.disabled||p.defaultPrevented)&&(p.currentTarget.focus(),r.open||r.onOpenChange(!0))},onPointerMove:_e(n.onPointerMove,Gl(p=>{l.onItemEnter(p),!p.defaultPrevented&&!n.disabled&&!r.open&&!o.current&&(l.onPointerGraceIntentChange(null),o.current=window.setTimeout(()=>{r.onOpenChange(!0),f()},100))})),onPointerLeave:_e(n.onPointerLeave,Gl(p=>{var v,b;f();const g=(v=r.content)==null?void 0:v.getBoundingClientRect();if(g){const j=(b=r.content)==null?void 0:b.dataset.side,x=j==="right",y=x?-5:5,w=g[x?"left":"right"],k=g[x?"right":"left"];l.onPointerGraceIntentChange({area:[{x:p.clientX+y,y:p.clientY},{x:w,y:g.top},{x:k,y:g.top},{x:k,y:g.bottom},{x:w,y:g.bottom}],side:j}),window.clearTimeout(c.current),c.current=window.setTimeout(()=>l.onPointerGraceIntentChange(null),300)}else{if(l.onTriggerLeave(p),p.defaultPrevented)return;l.onPointerGraceIntentChange(null)}})),onKeyDown:_e(n.onKeyDown,p=>{var v;n.disabled||p.target!==p.currentTarget||l.searchRef.current!==""&&p.key===" "||N4[a.dir].includes(p.key)&&(r.onOpenChange(!0),(v=r.content)==null||v.focus(),p.preventDefault())})})})},"MenuSubTrigger")),J4="MenuSubContent",Q4=h.forwardRef(gt(function(n,s){const r=LA(lr,n.__scopeMenu),{forceMount:a=r.forceMount,align:i="start",...l}=n,o=ri(lr,n.__scopeMenu),c=vu(lr,n.__scopeMenu),u=BA(J4,n.__scopeMenu),d=h.useRef(null),f=$t(s,d);return t.jsx(Gc.Provider,{scope:n.__scopeMenu,children:t.jsx(Br,{present:a||o.open,children:t.jsx(Gc.Slot,{scope:n.__scopeMenu,children:t.jsx(uy,{id:u.contentId,"aria-labelledby":u.triggerId,...l,ref:f,align:i,side:c.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:m=>{var p;c.isUsingKeyboardRef.current&&((p=d.current)==null||p.focus()),m.preventDefault()},onCloseAutoFocus:m=>m.preventDefault(),onFocusOutside:_e(n.onFocusOutside,m=>{m.target!==u.trigger&&o.onOpenChange(!1)}),onEscapeKeyDown:_e(n.onEscapeKeyDown,m=>{c.onClose(),m.preventDefault()}),onKeyDown:_e(n.onKeyDown,m=>{var v;const p=m.currentTarget.contains(m.target),g=S4[c.dir].includes(m.key);p&&g&&(o.onOpenChange(!1),(v=u.trigger)==null||v.focus(),m.preventDefault())})})})})})},"MenuSubContent"));function dy(e){return e?"open":"closed"}gt(dy,"getOpenState");function WA(e){return e==="indeterminate"}gt(WA,"isIndeterminate");function HA(e){return WA(e)?"indeterminate":e?"checked":"unchecked"}gt(HA,"getCheckedState");function KA(e){const n=document.activeElement;for(const s of e)if(s===n||(s.focus(),document.activeElement!==n))return}gt(KA,"focusFirst");function VA(e,n){return e.map((s,r)=>e[(n+r)%e.length])}gt(VA,"wrapArray");function GA(e,n,s){const a=n.length>1&&Array.from(n).every(u=>u===n[0])?n[0]:n,i=s?e.indexOf(s):-1;let l=VA(e,Math.max(i,0));a.length===1&&(l=l.filter(u=>u!==s));const c=l.find(u=>u.toLowerCase().startsWith(a.toLowerCase()));return c!==s?c:void 0}gt(GA,"getNextMatch");function qA(e,n){const{x:s,y:r}=e;let a=!1;for(let i=0,l=n.length-1;i<n.length;l=i++){const o=n[i],c=n[l],u=o.x,d=o.y,f=c.x,m=c.y;d>r!=m>r&&s<(f-u)*(r-d)/(m-d)+u&&(a=!a)}return a}gt(qA,"isPointInPolygon");function YA(e,n){if(!n)return!1;const s={x:e.clientX,y:e.clientY};return qA(s,n)}gt(YA,"isPointerInGraceArea");function Gl(e){return n=>n.pointerType==="mouse"?e(n):void 0}gt(Gl,"whenMouse");var X4=$4,Z4=DA,ez=R4,tz=P4,nz=FA,sz=L4,rz=_A,az=U4,iz=W4,lz=V4,oz=q4,cz=Y4,uz=Q4,dz=Object.defineProperty,As=(e,n)=>dz(e,"name",{value:n,configurable:!0}),hy="DropdownMenu",[hz,ene]=fr(hy,[IA]),$s=IA(),[fz,JA]=hz(hy),mz=As(e=>{const{__scopeDropdownMenu:n,children:s,dir:r,open:a,defaultOpen:i,onOpenChange:l,modal:o=!0}=e,c=$s(n),u=h.useRef(null),[d,f]=ni({prop:a,defaultProp:i??!1,onChange:l,caller:hy});return t.jsx(fz,{scope:n,triggerId:ir(),triggerRef:u,contentId:ir(),open:d,onOpenChange:f,onOpenToggle:h.useCallback(()=>f(m=>!m),[f]),modal:o,children:t.jsx(X4,{...c,open:d,onOpenChange:f,dir:r,modal:o,children:s})})},"DropdownMenu"),pz="DropdownMenuTrigger",gz=h.forwardRef(As(function(n,s){const{__scopeDropdownMenu:r,disabled:a=!1,...i}=n,l=JA(pz,r),o=$s(r),c=$t(s,l.triggerRef);return t.jsx(Z4,{asChild:!0,...o,children:t.jsx(bt.button,{type:"button",id:l.triggerId,"aria-haspopup":"menu","aria-expanded":l.open,"aria-controls":l.open?l.contentId:void 0,"data-state":l.open?"open":"closed","data-disabled":a?"":void 0,disabled:a,...i,ref:c,onPointerDown:_e(n.onPointerDown,u=>{!a&&u.button===0&&u.ctrlKey===!1&&(l.onOpenToggle(),l.open||u.preventDefault())}),onKeyDown:_e(n.onKeyDown,u=>{a||(["Enter"," "].includes(u.key)&&l.onOpenToggle(),u.key==="ArrowDown"&&l.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(u.key)&&u.preventDefault())})})})},"DropdownMenuTrigger")),xz=As(e=>{const{__scopeDropdownMenu:n,...s}=e,r=$s(n);return t.jsx(ez,{...r,...s})},"DropdownMenuPortal"),vz="DropdownMenuContent",jz=h.forwardRef(As(function(n,s){const{__scopeDropdownMenu:r,...a}=n,i=JA(vz,r),l=$s(r),o=h.useRef(!1);return t.jsx(tz,{id:i.contentId,"aria-labelledby":i.triggerId,...l,...a,ref:s,onCloseAutoFocus:_e(n.onCloseAutoFocus,c=>{var u;o.current||(u=i.triggerRef.current)==null||u.focus(),o.current=!1,c.preventDefault()}),onInteractOutside:_e(n.onInteractOutside,c=>{const u=c.detail.originalEvent,d=u.button===0&&u.ctrlKey===!0,f=u.button===2||d;(!i.modal||f)&&(o.current=!0)}),style:{...n.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})},"DropdownMenuContent")),yz=h.forwardRef(As(function(n,s){const{__scopeDropdownMenu:r,...a}=n,i=$s(r);return t.jsx(nz,{...i,...a,ref:s})},"DropdownMenuGroup")),wz=h.forwardRef(As(function(n,s){const{__scopeDropdownMenu:r,...a}=n,i=$s(r);return t.jsx(sz,{...i,...a,ref:s})},"DropdownMenuLabel")),bz=h.forwardRef(As(function(n,s){const{__scopeDropdownMenu:r,...a}=n,i=$s(r);return t.jsx(rz,{...i,...a,ref:s})},"DropdownMenuItem")),kz=h.forwardRef(As(function(n,s){const{__scopeDropdownMenu:r,...a}=n,i=$s(r);return t.jsx(az,{...i,...a,ref:s})},"DropdownMenuRadioGroup")),Nz=h.forwardRef(As(function(n,s){const{__scopeDropdownMenu:r,...a}=n,i=$s(r);return t.jsx(iz,{...i,...a,ref:s})},"DropdownMenuRadioItem")),Sz=h.forwardRef(As(function(n,s){const{__scopeDropdownMenu:r,...a}=n,i=$s(r);return t.jsx(lz,{...i,...a,ref:s})},"DropdownMenuSeparator")),Cz=As(e=>{const{__scopeDropdownMenu:n,children:s,open:r,onOpenChange:a,defaultOpen:i}=e,l=$s(n),[o,c]=ni({prop:r,defaultProp:i??!1,onChange:a,caller:"DropdownMenuSub"});return t.jsx(oz,{...l,open:o,onOpenChange:c,children:s})},"DropdownMenuSub"),Ez=h.forwardRef(As(function(n,s){const{__scopeDropdownMenu:r,...a}=n,i=$s(r);return t.jsx(cz,{...i,...a,ref:s})},"DropdownMenuSubTrigger")),Az=h.forwardRef(As(function(n,s){const{__scopeDropdownMenu:r,...a}=n,i=$s(r);return t.jsx(uz,{...i,...a,ref:s,style:{...n.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})},"DropdownMenuSubContent")),ju=mz,yu=gz,xo=xz,wu=jz,QA=yz,Di=wz,zs=bz,$z=kz,Tz=Nz,ra=Sz,Rz=Cz,Iz=Ez,Pz=Az,Mz=Object.defineProperty,vo=(e,n)=>Mz(e,"name",{value:n,configurable:!0}),fy="Tabs",[Dz,tne]=fr(fy,[Uf]),XA=Uf(),[Oz,my]=Dz(fy),Lz=h.forwardRef(vo(function(n,s){const{__scopeTabs:r,value:a,onValueChange:i,defaultValue:l,orientation:o="horizontal",dir:c,activationMode:u="automatic",...d}=n,f=Ff(c),[m,p]=ni({prop:a,onChange:i,defaultProp:l??"",caller:fy});return t.jsx(Oz,{scope:r,baseId:ir(),value:m,onValueChange:p,orientation:o,dir:f,activationMode:u,children:t.jsx(bt.div,{dir:f,"data-orientation":o,...d,ref:s})})},"Tabs")),Fz="TabsList",_z=h.forwardRef(vo(function(n,s){const{__scopeTabs:r,loop:a=!0,...i}=n,l=my(Fz,r),o=XA(r);return t.jsx(yA,{asChild:!0,...o,orientation:l.orientation,dir:l.dir,loop:a,children:t.jsx(bt.div,{role:"tablist","aria-orientation":l.orientation,...i,ref:s})})},"TabsList")),zz="TabsTrigger",Uz=h.forwardRef(vo(function(n,s){const{__scopeTabs:r,value:a,disabled:i=!1,...l}=n,o=my(zz,r),c=XA(r),u=py(o.baseId,a),d=gy(o.baseId,a),f=a===o.value;return t.jsx(wA,{asChild:!0,...c,focusable:!i,active:f,children:t.jsx(bt.button,{type:"button",role:"tab","aria-selected":f,"aria-controls":d,"data-state":f?"active":"inactive","data-disabled":i?"":void 0,disabled:i,id:u,...l,ref:s,onMouseDown:_e(n.onMouseDown,m=>{!i&&m.button===0&&m.ctrlKey===!1?o.onValueChange(a):m.preventDefault()}),onKeyDown:_e(n.onKeyDown,m=>{i||m.target!==m.currentTarget||[" ","Enter"].includes(m.key)&&o.onValueChange(a)}),onFocus:_e(n.onFocus,()=>{const m=o.activationMode!=="manual";!f&&!i&&m&&o.onValueChange(a)})})})},"TabsTrigger")),Bz="TabsContent",Wz=h.forwardRef(vo(function(n,s){const{__scopeTabs:r,value:a,forceMount:i,children:l,...o}=n,c=my(Bz,r),u=py(c.baseId,a),d=gy(c.baseId,a),f=a===c.value,m=h.useRef(f);return h.useEffect(()=>{const p=requestAnimationFrame(()=>m.current=!1);return()=>cancelAnimationFrame(p)},[]),t.jsx(Br,{present:i||f,children:({present:p})=>t.jsx(bt.div,{"data-state":f?"active":"inactive","data-orientation":c.orientation,role:"tabpanel","aria-labelledby":u,hidden:!p,id:d,tabIndex:0,...o,ref:s,style:{...n.style,animationDuration:m.current?"0s":void 0},children:p&&l})})},"TabsContent"));function py(e,n){return`${e}-trigger-${n}`}vo(py,"makeTriggerId");function gy(e,n){return`${e}-content-${n}`}vo(gy,"makeContentId");var Hz=Lz,Kz=_z,Vz=Uz,Gz=Wz;function pn(e,n,s){if(e==null)return"—";switch(n){case"currency":{const r=typeof e=="number"?e:Number(e);return Number.isFinite(r)?qz(r,s):String(e)}case"percent":{const r=typeof e=="number"?e:Number(e);return Number.isFinite(r)?`${r0(r)}%`:String(e)}case"number":{const r=typeof e=="number"?e:Number(e);return Number.isFinite(r)?Number.isInteger(r)?dn(r):r0(r):String(e)}case"date":return Yz(String(e));default:return typeof e=="string"?e:typeof e=="number"?dn(e):typeof e=="boolean"?e?"yes":"no":JSON.stringify(e)??String(e)}}function qz(e,n){if(!(Math.abs(e)<1e3&&!Number.isInteger(e)))return qF(e,n);try{return new Intl.NumberFormat("en-US",{style:"currency",currency:n??"USD",maximumFractionDigits:2}).format(e)}catch{return e.toFixed(2)}}function Yz(e){const n=/^(\d{4})-(\d{2})-(\d{2})/.exec(e);return n?gu(n[0],{year:!0,compact:!0}):e}function Sx(e){const n=/^(\d{4})-(\d{2})-(\d{2})/.exec(e);return n?gu(n[0],{compact:!0}):e}function r0(e){return String(Math.round(e*100)/100)}function Ah(e,n,s=4){if(!Number.isFinite(e)||!Number.isFinite(n))return[];if(e===n)return[e];const r=(n-e)/Math.max(1,s),a=10**Math.floor(Math.log10(r)),i=[1,2,2.5,5,10].map(o=>o*a).find(o=>o>=r)??a*10,l=[];for(let o=Math.ceil(e/i)*i;o<=n+i/1e3;o+=i)l.push(Math.round(o*1e6)/1e6);return l.filter(o=>o>=e&&o<=n)}function Jz({props:e}){if(e.bars.length===0)return t.jsx("p",{className:"wb-empty",children:"No categories came back."});const n=e.bars.map(i=>i.value),s=Math.max(0,...n),r=Math.min(0,...n),a=s-r||1;return t.jsx("div",{className:"wb-bars",children:e.bars.map(i=>{const l=Math.abs(i.value)/a;return t.jsxs("div",{className:"wb-bar-row",children:[t.jsx("div",{className:"wb-bar-cat",title:i.category,children:i.category}),t.jsx("div",{className:"wb-bar-track",children:t.jsx("div",{className:"wb-bar-fill",style:{width:`${Math.max(1,l*100)}%`,background:i.value<0?"var(--chart-bar-negative)":"var(--chart-bar)"}})}),t.jsx("div",{className:"wb-bar-val",children:pn(i.value,e.unit,e.currency)})]},i.category)})})}const Qz=/^(diff --git |index [0-9a-f]|--- (a\/|\/dev\/null)|\+\+\+ (b\/|\/dev\/null)|new file mode|deleted file mode|similarity index|rename (from|to) |old mode|new mode|Binary files )/,Xz=/^(… |\.\.\. |\(no change\)$|\)/;function Zz(e){return e.replace(/\n$/,"").split(`
90
- `).map(s=>({kind:e3(s),text:s}))}function e3(e){return e.startsWith("@@")?"hunk":Qz.test(e)||Xz.test(e)?"meta":e.startsWith("+")?"add":e.startsWith("-")?"del":"context"}function t3({text:e,marks:n}){const s=e.toLowerCase(),r=[];for(const l of n){const o=l.trim().toLowerCase();if(o!=="")for(let c=s.indexOf(o);c!==-1;c=s.indexOf(o,c+o.length))r.push([c,c+o.length])}if(r.length===0)return t.jsx(t.Fragment,{children:e===""?" ":e});r.sort((l,o)=>l[0]-o[0]);const a=[];let i=0;for(const[l,o]of r)l<i||(l>i&&a.push(t.jsx("span",{children:e.slice(i,l)},`t${i}`)),a.push(t.jsx("mark",{className:"wb-diff-mark",children:e.slice(l,o)},`m${l}`)),i=o);return i<e.length&&a.push(t.jsx("span",{children:e.slice(i)},`t${i}`)),t.jsx(t.Fragment,{children:a})}function $h({text:e,limit:n,more:s,label:r="Diff",marks:a}){const i=Zz(e),l=n===void 0?i:i.slice(0,n),o=i.length-l.length;return t.jsxs("div",{className:"wb-diff-wrap",children:[t.jsx("pre",{className:"wb-diff","aria-label":r,"data-testid":"diff",children:l.map((c,u)=>t.jsx("span",{className:"wb-diff-line","data-kind":c.kind,children:a&&a.length>0?t.jsx(t3,{text:c.text,marks:a}):c.text===""?" ":c.text},u))}),o>0?t.jsxs("p",{className:"wb-diff-more",children:[o," more line",o===1?"":"s",s?t.jsxs(t.Fragment,{children:[" · ",t.jsx("button",{type:"button",className:"wb-diff-open",onClick:s.onClick,children:s.label})]}):null]}):null]})}function n3({props:e}){return t.jsxs("div",{children:[e.title?t.jsx("h4",{className:"wb-doc-title mono",children:e.title}):null,e.metadata.length>0?t.jsx("dl",{className:"ui-kv wb-block",children:e.metadata.map(n=>t.jsxs("div",{className:"contents",children:[t.jsx("dt",{children:n.label}),t.jsx("dd",{children:pn(n.value,n.unit,null)})]},n.label))}):null,e.diff?t.jsx($h,{text:e.diff,label:e.title?`Diff of ${e.title}`:"Diff"}):t.jsx("p",{className:"wb-empty",children:"This change came back with no diff."})]})}const kn="#/",ql="#/needs",oa="#/chat",vt="#/agents",At="#/activity",yn="#/settings",pa="#/files",s3="#/welcome";function Bd(e){const n=/^#\/welcome(?:\?(.*))?$/.exec(e);if(!n)return null;try{return{step:new URLSearchParams(n[1]??"").get("step")}}catch{return{step:null}}}function ad(e,n={}){const s=new URLSearchParams;n.q&&s.set("q",n.q),n.origin&&s.set("origin",n.origin),n.family&&s.set("family",n.family);const r=s.toString();return`${pa}${e?`/${encodeURIComponent(e)}`:""}${r?`?${r}`:""}`}function r3(e){const n=/^#\/files(?:\/([^/?]+))?(?:\?(.*))?$/.exec(e);if(!n)return null;try{const s=new URLSearchParams(n[2]??""),r={};return s.get("q")&&(r.q=s.get("q")),s.get("origin")&&(r.origin=s.get("origin")),s.get("family")&&(r.family=s.get("family")),{...n[1]?{artifactId:decodeURIComponent(n[1])}:{},filters:r}}catch{return null}}function Ze(e,n,s){return`#/chat/${encodeURIComponent(e)}${n?`/${encodeURIComponent(n)}`:""}`}function a3(e){if(ZA(e))return null;const n=/^#\/chat\/([^/?]+)(?:\/([^/?]+))?(?:\?(.*))?$/.exec(e);if(!n)return null;try{const s=new URLSearchParams(n[3]??"").get("tab");return{agentId:decodeURIComponent(n[1]),...n[2]?{conversationId:decodeURIComponent(n[2])}:{},...s?{tab:s}:{}}}catch{return null}}function xi(e,n){return`#/chat/g/${encodeURIComponent(e)}${n?`/${encodeURIComponent(n)}`:""}`}function ZA(e){const n=/^#\/chat\/g\/([^/?]+)(?:\/([^/?]+))?(?:\?.*)?$/.exec(e);if(!n)return null;try{return{groupId:decodeURIComponent(n[1]),...n[2]?{conversationId:decodeURIComponent(n[2])}:{}}}catch{return null}}function Pt(e,n,s){return`${vt}/${encodeURIComponent(e)}${n?`/${n}${s?`/${s}`:""}`:""}`}function i3(e){const n=/^#\/agents\/([^/]+)(?:\/([a-z-]+)(?:\/([a-z-]+))?)?$/.exec(e);if(!n||n[1]===e$)return null;try{return{agentId:decodeURIComponent(n[1]),...n[2]?{tab:n[2]}:{},...n[3]?{section:n[3]}:{}}}catch{return null}}const e$="catalogue",a0=`${vt}/${e$}`;function sn(e){return e?`${a0}/${encodeURIComponent(e)}`:a0}function l3(e){return`${sn(e)}?add=1`}function o3(e,n){const s=/^#\/agents\/catalogue\/([a-z0-9-]+)\?(?:.*&)?add=1(?:&|$)/.exec(e);return(s==null?void 0:s[1])===n}function c3(e){const n=/^#\/agents\/catalogue(?:\/([a-z0-9-]+))?(?:\?.*)?$/.exec(e);return n?n[1]?{name:n[1]}:{}:null}function qc(e){return`${At}/conversations/${encodeURIComponent(e)}`}const u3="#/p";function Or(e,n,s){const r=`${u3}/${encodeURIComponent(e)}/${encodeURIComponent(n)}`;return s?`${r}/${encodeURIComponent(s)}`:r}function xy(e){const n=/^#\/p\/([^/?]+)\/([^/?]+)(?:\/([^/?]+))?(?:\?.*)?$/.exec(e);if(!n)return null;try{return{plugin:decodeURIComponent(n[1]),page:decodeURIComponent(n[2]),...n[3]?{item:decodeURIComponent(n[3])}:{}}}catch{return null}}const d3="p.";function Lr(e,n=e,s){const r=s?new URLSearchParams(s).toString():"";return`${yn}/${encodeURIComponent(n$(e,n))}${r?`?${r}`:""}`}function h3(e,n){const s=t$(e);if(!s)return null;const r=n.filter(i=>i.plugin===s.plugin);if(r.length===0||r.some(i=>i.id===s.page))return null;const a=vy(e);return Lr(s.plugin,r[0].id,Object.keys(a).length>0?a:void 0)}function vy(e){const n=e.indexOf("?");if(n===-1)return{};try{const s={};for(const[r,a]of new URLSearchParams(e.slice(n+1)))a!==""&&(s[r]=a);return s}catch{return{}}}function t$(e){const n=/^#\/settings\/p\.([^/?.]+)(?:\.([^/?.]+))?(?:\?.*)?$/.exec(e);if(!n)return null;const s=decodeURIComponent(n[1]);return{plugin:s,page:n[2]?decodeURIComponent(n[2]):s}}function n$(e,n){return`${d3}${e}${n===e?"":`.${n}`}`}function Le(e){return e?`${yn}/${e}`:yn}function s$(e){return`${Le("accounts")}?account=${encodeURIComponent(e)}`}function f3(e){const n=/^#\/settings\/accounts\?(.*)$/.exec(e);if(!n)return null;try{return new URLSearchParams(n[1]).get("account")||null}catch{return null}}function jy(e,n,s){const r=new RegExp(`^#/settings/${n}\\?(.*)$`).exec(e);if(!r)return null;try{return new URLSearchParams(r[1]).get(s)||null}catch{return null}}function r$(e){return`${Le("connections")}?connection=${encodeURIComponent(e)}`}function m3(e){return jy(e,"connections","connection")}function p3(e){return jy(e,"secrets","secret")}const i0=`${Le("secrets")}?add=1`;function g3(e){return jy(e,"secrets","add")==="1"}function x3(e){return`${Le("plugins")}?install=${encodeURIComponent(e)}`}const Cx=`${Le("plugins")}?tab=browse`;function Ex(e="all"){return e==="all"?Cx:`${Cx}&kind=${e}`}function v3(e){return`${Le("proposals")}${e?`?plugin=${encodeURIComponent(e)}`:""}`}function j3(e){const n=/^#\/settings\/proposals\?(.*)$/.exec(e);if(!n)return null;try{return new URLSearchParams(n[1]).get("plugin")||null}catch{return null}}function yy(e){const n=/^#\/settings\/plugins\?(.*)$/.exec(e);if(!n)return null;try{return new URLSearchParams(n[1])}catch{return null}}function y3(e){var s,r;const n=(r=(s=yy(e))==null?void 0:s.get("install"))==null?void 0:r.trim();return n||null}function l0(e){var s;const n=(s=yy(e))==null?void 0:s.get("kind");return n==="plugins"||n==="widgets"||n==="agents"?n:"all"}function o0(e){const n=yy(e);return n!=null&&n.get("install")?"installed":(n==null?void 0:n.get("tab"))==="browse"?"browse":"installed"}const w3=[{route:kn,label:"Home"},{route:oa,label:"Chat"},{route:vt,label:"Agents"},{route:At,label:"Activity"},{route:pa,label:"Files"},{route:yn,label:"Settings"}],b3=[{id:"you",label:"You"},{id:"access",label:"Models and access"},{id:"running",label:"Running"},{id:"plugins",label:"Plugins"}],k3=[{id:"you",label:"Profile",group:"you"},{id:"appearance",label:"Appearance",group:"you"},{id:"notifications",label:"Notifications",group:"you"},{id:"telegram",label:"Telegram",group:"you"},{id:"memory",label:"Memory",group:"you"},{id:"proposals",label:"Proposals",group:"you"},{id:"accounts",label:"Model accounts",group:"access"},{id:"computer",label:"Computer & browser",group:"access"},{id:"secrets",label:"Keys and secrets",group:"access"},{id:"connections",label:"Connections",group:"access"},{id:"lock",label:"Lock screen",group:"access"},{id:"api",label:"API tokens",group:"access"},{id:"watchers",label:"Watchers",group:"running"},{id:"backup",label:"Backup",group:"running"},{id:"system",label:"System",group:"running"},{id:"plugins",label:"All plugins",group:"plugins"}];function N3(e){var n;return((n=/^#\/settings\/([a-z0-9.-]+)/.exec(e))==null?void 0:n[1])??"you"}const Ax="#/settings/notifications/recent",$x=Le("backup");function S3(e){const n=/^#\/conversations\/(.+)$/.exec(e);if(n)return qc(decodeURIComponent(n[1]));const s=/^#\/email(?:\/([^/?]+))?(?:\?.*)?$/.exec(e);if(s)try{return Or("email","mail",s[1]?decodeURIComponent(s[1]):null)}catch{return Or("email","mail")}return e==="#/settings/email"?Lr("email","settings"):{"#/overview":kn,"#/approvals":kn,"#/events":`${At}/events`,"#/jobs":`${At}/jobs`,"#/conversations":At,"#/missions":`${vt}?tab=missions`,"#/offers":`${vt}?tab=offers`,"#/reminders":`${vt}?tab=reminders`,"#/providers":Le("accounts"),"#/browser":Le("computer"),"#/sentinels":Le("watchers"),"#/settings/sentinels":Le("watchers")}[e]??null}function a$(e){if(e===""||e==="#"||e===kn)return kn;if(e.startsWith(oa))return oa;if(e.startsWith(vt))return vt;if(e.startsWith(At))return At;if(e.startsWith(pa))return pa;if(e.startsWith(yn))return yn;const n=xy(e);return n?Or(n.plugin,n.page):kn}const C3="#/chat?group=new";function E3(e){const n=e.replace(/^#\/?/,"").split("?")[0].toLowerCase();if(n==="")return"home";const[s,r]=n.split("/");return!s||!/^[a-z0-9-]+$/.test(s)?null:(s==="settings"||s==="p")&&r&&/^[a-z0-9.-]+$/.test(r)?`${s}/${r}`:s}const bu="front-desk",wy=[{id:bu,label:"Front desk",meaning:"Where things go when you do not say who."},{id:"overview",label:"Overview",meaning:"Answers /status and speaks for the watchers."},{id:"recap",label:"Recap",meaning:"Runs /recap."},{id:"maker",label:"Maker",meaning:"/new opens its interview."}],i$=new Set(wy.map(e=>e.id)),c0=e=>i$.has(e);function u0(e,n){const s=n.filter(r=>!i$.has(r));return[...wy.filter(r=>e.has(r.id)).map(r=>r.id),...s.filter((r,a)=>s.indexOf(r)===a)]}function A3(e,n){return e.find(s=>(s.roles??[]).includes(n))}const d0=["coding","finance","mail","research","calendar","files","memory"],$3={developer:"coding",coding:"coding",finance:"finance",credit:"finance",mail:"mail",email:"mail",research:"research",calendar:"calendar",files:"files",memory:"memory",[bu]:"buddi"},T3=[["mail",["email"]],["finance",["finance"]],["coding",["developer"]],["research",["web","browser"]],["art",["image"]]];function R3(e){const n=new Set(e.map(s=>s.split(".")[0]??s));for(const[s,r]of T3)if(r.some(a=>n.has(a)))return s;return n.size>0&&[...n].every(s=>s==="memory")?"memory":null}let Tx=null;function I3(e){Tx=e}function jo(e){if(e.accent&&/^#[0-9a-fA-F]{6}$/.test(e.accent))return{key:"own",hex:e.accent.toLowerCase()};for(const s of e.roles??[]){const r=$3[s];if(r)return{key:r}}const n=R3(e.tools??[]);return n?{key:n}:Tx!==null&&e.id===Tx?{key:"buddi"}:{key:d0[P3(e.id)%d0.length]??"coding"}}function Oi(e){return e.key==="own"?{"data-agent":"own",style:{"--agent-fill":e.hex}}:{"data-agent":e.key}}function P3(e){let n=0;for(const s of e)n=(n*31+s.charCodeAt(0))%997;return n}const M3=["run.started","tool.called","tool.result","message.appended","awaiting-approval","run.finished","reaction","live","live.settle","live.snapshot","attention","closing","ping"];function D3(e){const s=e.replace(/\r\n/g,`
91
- `).split(`
92
-
93
- `),r=s.pop()??"",a=[];for(const i of s){let l=null,o="message";const c=[];for(const u of i.split(`
94
- `)){if(u===""||u.startsWith(":"))continue;const d=u.indexOf(":"),f=d===-1?u:u.slice(0,d),m=d===-1?"":u.slice(d+1).replace(/^ /,"");f==="id"?l=m:f==="event"?o=m:f==="data"&&c.push(m)}c.length===0&&o==="message"||a.push({id:l,name:M3.includes(o)?o:"ping",data:O3(c.join(`
95
- `))})}return{events:a,rest:r}}function O3(e){if(e==="")return{};try{const n=JSON.parse(e);return n!==null&&typeof n=="object"?n:{value:n}}catch{return{value:e}}}function Kf(e){const n=e.fetchImpl??globalThis.fetch.bind(globalThis),s=e.wait??(u=>new Promise(d=>setTimeout(d,u))),r=e.retryMs??1500;let a=e.lastEventId??null,i=!1,l=!1,o=null;return(async()=>{var u,d,f,m,p;for(;!i;){(u=e.onStatus)==null||u.call(e,"connecting"),o=new AbortController;try{const g=await n(e.url,{credentials:"same-origin",signal:o.signal,headers:{Accept:"text/event-stream",...a===null?{}:{"Last-Event-ID":a}}});if(!g.ok||!g.body)throw new Error(`stream ${g.status}`);(d=e.onStatus)==null||d.call(e,"open"),l&&((f=e.onReconnect)==null||f.call(e));const v=g.body.getReader(),b=new TextDecoder;let j="";for(;;){const{done:x,value:y}=await v.read();if(x)break;j+=b.decode(y,{stream:!0});const{events:w,rest:k}=D3(j);j=k;for(const N of w)e.onEvent(N),N.id!==null&&(a=N.id);if(i)break}}catch{}if(i)break;l=!0,(m=e.onStatus)==null||m.call(e,"closed"),await s(r)}(p=e.onStatus)==null||p.call(e,"closed")})(),{close:()=>{i=!0,o==null||o.abort()},lastEventId:()=>a}}const by="0.1.0+ce2ce57";function ky(e,n=by){return typeof e=="string"&&e!==""&&typeof n=="string"&&n!==""&&e!==n}function L3(){var e;try{if((e=window.matchMedia)!=null&&e.call(window,"(display-mode: standalone)").matches)return!0}catch{}return window.navigator.standalone===!0}const F3=5*6e4,_3=6e4,z3=5e3,Yc="buddi:stream-reconnected",l$="buddi.autoReloadedFor";function U3(){window.dispatchEvent(new Event(Yc))}const h0=["keydown","pointerdown","pointermove","wheel","touchstart","input"];let Ny=Date.now(),id=0;const f0=()=>{Ny=Date.now()};function B3(){if(id===0){Ny=Date.now();for(const e of h0)window.addEventListener(e,f0,{capture:!0,passive:!0})}return id+=1,()=>{if(id-=1,id===0)for(const e of h0)window.removeEventListener(e,f0,{capture:!0})}}function W3(e=Date.now()){return e-Ny}function o$(e=document){return e.querySelector('.wb-composer[data-busy="true"]')!==null||e.querySelector('.wb-listening, [data-recording="true"]')!==null||e.querySelector('[role="dialog"], [role="alertdialog"], dialog[open]')!==null}function H3(e){return e.hidden?!0:e.idleMs>=_3&&!e.busy}function K3(e){try{return window.sessionStorage.getItem(l$)===e}catch{return!1}}function V3(e){try{window.sessionStorage.setItem(l$,e)}catch{}}function G3(e){const n=h.useRef(e);n.current=e,h.useEffect(()=>{const s=()=>n.current();return window.addEventListener(Yc,s),()=>window.removeEventListener(Yc,s)},[])}function q3(e,n=()=>window.location.reload(),s=by){const r=ky(e,s),a=h.useRef(n);a.current=n,h.useEffect(()=>B3(),[]),h.useEffect(()=>{if(!r||e===void 0||K3(e))return;let i=!1;const l=()=>{if(i)return;const c=document.visibilityState==="hidden";H3({hidden:c,idleMs:W3(),busy:o$()})&&(i=!0,V3(e),a.current())};l();const o=window.setInterval(l,z3);return document.addEventListener("visibilitychange",l),()=>{window.clearInterval(o),document.removeEventListener("visibilitychange",l)}},[r,e])}const Y3=9e4,c$=5*6e4,J3=500,Q3=2e3,X3=3e3,Z3="/_buddi/ready",Ol={reload:()=>window.location.reload(),now:()=>Date.now()};let qa=null,Nl=null,Xo=null;const Rx=new Set;function Th(e){qa=e;for(const n of Rx)n()}function m0(){return qa}function eU(e){return Rx.add(e),()=>Rx.delete(e)}function tU(){const e=new Uint8Array(32);return crypto.getRandomValues(e),[...e].map(n=>n.toString(16).padStart(2,"0")).join("")}async function Sy(e=X3){const n=new AbortController,s=setTimeout(()=>n.abort(),e);try{const r=await fetch(`${Z3}?challenge=${tU()}`,{cache:"no-store",credentials:"omit",redirect:"error",signal:n.signal,headers:{Accept:"application/json"}});if(r.status!==200)return null;const a=await r.json().catch(()=>null);return typeof(a==null?void 0:a.boot)=="string"?a.boot:""}catch{return null}finally{clearTimeout(s)}}async function nU(){const e=await Sy();e&&(Nl=e)}function sU(){let e=Nl,n=!1,s=!1,r=J3,a;const i=async()=>{if(n)return;const l=await Sy();if(!n){if(l===null)s=!0;else if(e!==null?l!==e:s){n=!0,Ol.reload();return}else e===null&&l!==""&&(e=l);r=Math.min(Math.round(r*1.5),Q3),a=setTimeout(()=>void i(),r)}};return a=setTimeout(()=>void i(),r),()=>{n=!0,clearTimeout(a)}}function Vf(e){if(qa){if(e.kind==="detected")return;Th({...qa,...e});return}Th({...e,startedAt:Ol.now()}),Xo=sU()}function u$(e){qa&&Th({...qa,...e})}function Yl(){Xo==null||Xo(),Xo=null,Th(null)}async function Gf(e,n){Vf(e);try{return await n()}catch(s){if(Eh(s))return;throw Yl(),s}}function rU(e){Vf({kind:e.for==="stop"?"stop":"detected"})}async function p0(){if(qa)return;const e=await Sy();if(Nl===null){e&&(Nl=e);return}if(!(!e||e===Nl||qa)){if(o$()){Nl=e;return}Vf({kind:"detected"})}}function aU(e){const[n,s]=e;if(!n)return null;const r=`${n.name} ${n.version}`;return s?e.length===2?`${r} and ${s.name} ${s.version}`:`${r} and ${e.length-1} more`:r}const iU="/api/chat/attention/stream";function d$(e,n){const s=(i,l)=>i.name.localeCompare(l.name),r=i=>e.filter(l=>l.anchor===i).sort(s),a=e.filter(i=>i.anchor!=="top"&&i.anchor!=="bottom").sort((i,l)=>i.id===n?l.id===n?0:-1:l.id===n?1:s(i,l));return{top:r("top"),middle:a,bottom:r("bottom")}}function h$(e,n){const s=d$(e,n);return[...s.top,...s.middle,...s.bottom]}function qf(e){if(!e)return null;const n=[];return e.approvals>0&&n.push(e.approvals===1?"one approval is waiting for you":`${e.approvals} approvals are waiting for you`),e.question&&n.push("asked you a question and is holding for the answer"),n.length===0?null:n.join(", and ")}function lU(e){if(!e)return null;const n=e.approvals,s=n===1?"1 approval":`${n} approvals`;return n>0&&e.question?`${s} and a question`:n>0?`${s} waiting`:e.question?"Has a question":null}function oU(e,n){return e&&(e.approvals>0||e.question)?"needs":n?"working":null}function cU(e){return new Map(((e==null?void 0:e.agents)??[]).map(n=>[n.agentId,n]))}function uU(){const[e,n]=h.useState(null);return h.useEffect(()=>{let s=!1;const r=()=>{ye("/chat/attention").then(i=>{s||n(i)}).catch(()=>{})};r();const a=Kf({url:iU,onEvent:i=>i.name==="closing"?rU(i.data):r(),onReconnect:U3});return()=>{s=!0,a.close()}},[]),cU(e)}const Fr="maker";function Cy(e){return e.filter(n=>n.available&&!n.roles.includes(Fr))}function f$(e){return Cy(e).length>=2}function dU(e){var n;return((n=e.find(s=>s.roles.includes(Fr)))==null?void 0:n.name)??"the agent maker"}const hU="{{default}}";function fU(e,n){return e.split(hU).join(n??"your assistant")}function mU(e,n){return((e==null?void 0:e.starters)??[]).slice(0,3).map(s=>fU(s,n))}function pU(e){var s,r;const n=(s=e==null?void 0:e.intro)==null?void 0:s.trim();return n&&n!==""?n:((r=e==null?void 0:e.description)==null?void 0:r.trim())??""}function gU(e){const n=(e??"·").trim().split(/\s+/).filter(Boolean);return n.length===0?"·":n.length===1?n[0].slice(0,2).toUpperCase():(n[0][0]+n[1][0]).toUpperCase()}function m$(e){var r,a;const n=(r=e.heldBack)==null?void 0:r.message.trim();if(n!==void 0&&n!=="")return`${e.name??"This agent"} is held back. ${n}`;const s=(a=e.unavailableReason)==null?void 0:a.trim();return s&&s!==""?`${e.name??"This agent"} cannot run: ${s}`:`${e.name??"This agent"} cannot run: it has no model account yet.`}const xU="Settings → Model accounts",vU="Install it in Settings → Plugins";function Ix(e){return e!=null&&e.heldBack?{section:"plugins",label:vU}:{section:"accounts",label:xU}}const jU={home:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M3.5 9.2 10 3.6l6.5 5.6"}),t.jsx("path",{d:"M5.2 8.4v7.4a1 1 0 0 0 1 1h2.6v-4.6h2.4v4.6h2.6a1 1 0 0 0 1-1V8.4"})]})],chat:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M17 10.6a4.9 4.9 0 0 1-4.9 4.9H7.8L3.6 18l.9-3A4.9 4.9 0 0 1 3 11V8.2A4.9 4.9 0 0 1 7.9 3.3h4.2A4.9 4.9 0 0 1 17 8.2Z"}),t.jsx("path",{d:"M7 8.3h6M7 11.3h3.6"})]})],agents:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("circle",{cx:"7.5",cy:"7",r:"2.8"}),t.jsx("path",{d:"M2.8 16.2a4.7 4.7 0 0 1 9.4 0"}),t.jsx("circle",{cx:"14",cy:"7.8",r:"2.2"}),t.jsx("path",{d:"M13.2 12.5a3.9 3.9 0 0 1 4.3 3.7"})]})],activity:[20,1.6,t.jsx("path",{d:"M2.8 10.5h3.4l2-5.2 3.4 9.8 2.2-4.6h3.4"})],settings:[24,1.9,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"}),t.jsx("circle",{cx:"12",cy:"12",r:"3"})]}),20],files:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M7.5 2.8h5.2L16.5 6.6v8.6a1.2 1.2 0 0 1-1.2 1.2H7.5a1.2 1.2 0 0 1-1.2-1.2V4a1.2 1.2 0 0 1 1.2-1.2z"}),t.jsx("path",{d:"M12.7 2.8v3.8h3.8"}),t.jsx("path",{d:"M4.4 6.2v9.4a1.6 1.6 0 0 0 1.6 1.6h6.6"})]})],mail:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("rect",{x:"3",y:"5",width:"14",height:"10.5",rx:"1.4"}),t.jsx("path",{d:"M3.4 6 10 11l6.6-5"})]})],money:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("rect",{x:"2.6",y:"5.2",width:"14.8",height:"9.6",rx:"1.6"}),t.jsx("circle",{cx:"10",cy:"10",r:"2.2"}),t.jsx("path",{d:"M5.4 10h.5M14.1 10h.5"})]})],calendar:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("rect",{x:"3",y:"4.4",width:"14",height:"12.2",rx:"1.6"}),t.jsx("path",{d:"M3 8.2h14M6.8 2.9v2.6M13.2 2.9v2.6"})]})],chart:[20,1.6,t.jsx("path",{d:"M3.2 16.4V8.6M8.4 16.4V3.9M13.6 16.4v-5.8M3.2 16.4h13.6"})],bell:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M5.4 13.6V9a4.6 4.6 0 0 1 9.2 0v4.6l1.2 1.7H4.2Z"}),t.jsx("path",{d:"M8.4 17.1a1.8 1.8 0 0 0 3.2 0"})]})],plug:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M7.4 2.8v3.4M12.6 2.8v3.4"}),t.jsx("path",{d:"M5 6.2h10v3.1a5 5 0 0 1-10 0Z"}),t.jsx("path",{d:"M10 14.3v3"})]})],key:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("circle",{cx:"6.6",cy:"10",r:"3.2"}),t.jsx("path",{d:"M9.8 10h7.2M14.4 10v2.6M16.6 10v1.8"})]})],globe:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("circle",{cx:"10",cy:"10",r:"7.1"}),t.jsx("path",{d:"M2.9 10h14.2M10 2.9c3.4 3.7 3.4 10.5 0 14.2-3.4-3.7-3.4-10.5 0-14.2Z"})]})],news:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M4 3.6h9.2a.8.8 0 0 1 .8.8v11.2a.8.8 0 0 0 .8.8H5.2A1.6 1.6 0 0 1 3.6 14.8V4a.4.4 0 0 1 .4-.4Z"}),t.jsx("path",{d:"M14 7h1.6a.8.8 0 0 1 .8.8v7.2a1.4 1.4 0 0 1-1.4 1.4"}),t.jsx("path",{d:"M6.4 6.8h4.4M6.4 9.8h4.4M6.4 12.8h2.8"})]})],terminal:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("rect",{x:"2.8",y:"3.6",width:"14.4",height:"12.8",rx:"1.6"}),t.jsx("path",{d:"M6.2 8l2.6 2.4-2.6 2.4M10.6 12.8h3.4"})]})],person:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("circle",{cx:"10",cy:"7",r:"3.2"}),t.jsx("path",{d:"M4 16.6a6 6 0 0 1 12 0"})]})],briefcase:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("rect",{x:"2.8",y:"6",width:"14.4",height:"10.2",rx:"1.6"}),t.jsx("path",{d:"M7.4 6V4.6a1 1 0 0 1 1-1h3.2a1 1 0 0 1 1 1V6M2.8 10.4h14.4"})]})],pin:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M10 17.2s5.2-4.9 5.2-9a5.2 5.2 0 0 0-10.4 0c0 4.1 5.2 9 5.2 9Z"}),t.jsx("circle",{cx:"10",cy:"8.2",r:"1.9"})]})],sun:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("circle",{cx:"10",cy:"10",r:"3.2"}),t.jsx("path",{d:"M10 2.6v1.6M10 15.8v1.6M2.6 10h1.6M15.8 10h1.6M4.8 4.8l1.1 1.1M14.1 14.1l1.1 1.1M4.8 15.2l1.1-1.1M14.1 5.9l1.1-1.1"})]})],notebook:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M5.5 3.2h8.3a1 1 0 0 1 1 1v11.6a1 1 0 0 1-1 1H5.5a1 1 0 0 1-1-1V4.2a1 1 0 0 1 1-1Z"}),t.jsx("path",{d:"M7.6 3.2v13.6M10 7h2.6M10 9.8h2.6"})]})],bulb:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M7.2 13.2a5 5 0 1 1 5.6 0v1.6H7.2Z"}),t.jsx("path",{d:"M8 17.2h4"})]})],monitor:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("rect",{x:"2.8",y:"3.6",width:"14.4",height:"10",rx:"1.4"}),t.jsx("path",{d:"M7.4 16.8h5.2M10 13.6v3.2"})]})],lock:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("rect",{x:"4",y:"8.6",width:"12",height:"8.6",rx:"2.2"}),t.jsx("path",{d:"M6.8 8.6V6.2a3.2 3.2 0 0 1 6.4 0v2.4"})]})],eye:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M2.4 10S5.2 4.8 10 4.8 17.6 10 17.6 10 14.8 15.2 10 15.2 2.4 10 2.4 10Z"}),t.jsx("circle",{cx:"10",cy:"10",r:"2.4"})]})],archive:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("rect",{x:"2.8",y:"3.6",width:"14.4",height:"3.6",rx:"1"}),t.jsx("path",{d:"M4 7.2v8a1.2 1.2 0 0 0 1.2 1.2h9.6a1.2 1.2 0 0 0 1.2-1.2v-8M8.2 10.4h3.6"})]})],chip:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("rect",{x:"5.4",y:"5.4",width:"9.2",height:"9.2",rx:"1.4"}),t.jsx("path",{d:"M8 2.8v2.6M12 2.8v2.6M8 14.6v2.6M12 14.6v2.6M2.8 8h2.6M2.8 12h2.6M14.6 8h2.6M14.6 12h2.6"})]})],"partly-cloudy":[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("circle",{cx:"7.4",cy:"7.4",r:"2.4"}),t.jsx("path",{d:"M7.4 2.8v1M2.8 7.4h1M4.2 4.2l.7.7M10.6 4.2l-.7.7"}),t.jsx("path",{d:"M7.8 16.8h6.4a2.9 2.9 0 0 0 .3-5.8 4 4 0 0 0-7.6 1.1 2.4 2.4 0 0 0 .9 4.7Z"})]})],cloud:[20,1.6,t.jsx("path",{d:"M6 15.6h8.2a3.3 3.3 0 0 0 .4-6.6 4.6 4.6 0 0 0-8.9 1A2.8 2.8 0 0 0 6 15.6Z"})],rain:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M6 12.2h8.2a3 3 0 0 0 .4-6 4.3 4.3 0 0 0-8.3.9A2.6 2.6 0 0 0 6 12.2Z"}),t.jsx("path",{d:"M7.2 14.6l-.8 2M10.4 14.6l-.8 2M13.6 14.6l-.8 2"})]})],drizzle:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M6 12.2h8.2a3 3 0 0 0 .4-6 4.3 4.3 0 0 0-8.3.9A2.6 2.6 0 0 0 6 12.2Z"}),t.jsx("path",{d:"M7 15.2v.3M10 16.4v.3M13 15.2v.3"})]})],snow:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M6 12.2h8.2a3 3 0 0 0 .4-6 4.3 4.3 0 0 0-8.3.9A2.6 2.6 0 0 0 6 12.2Z"}),t.jsx("path",{d:"M7.4 14.4v2.4M6.2 15.6h2.4M12.6 14.4v2.4M11.4 15.6h2.4"})]})],storm:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M6 12.2h8.2a3 3 0 0 0 .4-6 4.3 4.3 0 0 0-8.3.9A2.6 2.6 0 0 0 6 12.2Z"}),t.jsx("path",{d:"M10.8 13.2 9 15.6h2.4l-1.8 2.6"})]})],fog:[20,1.6,t.jsx("path",{d:"M3.6 7.2h12.8M5.2 10.2h9.6M3.6 13.2h12.8M6.4 16.2h7.2"})],wind:[20,1.6,t.jsx("path",{d:"M3 8h9.4a2.2 2.2 0 1 0-2.2-2.2M3 12h11.6a2.2 2.2 0 1 1-2.2 2.2M3 10h5.4"})],"moon-clear":[20,1.6,t.jsx("path",{d:"M15.8 12.2A6.2 6.2 0 0 1 7.8 4.2a6.2 6.2 0 1 0 8 8Z"})],"moon-cloud":[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M9.4 6.8A3.6 3.6 0 0 1 4.6 2a3.6 3.6 0 1 0 4.8 4.8Z"}),t.jsx("path",{d:"M7.8 16.8h6.4a2.9 2.9 0 0 0 .3-5.8 4 4 0 0 0-7.6 1.1 2.4 2.4 0 0 0 .9 4.7Z"})]})],clock:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("circle",{cx:"10",cy:"10",r:"7.1"}),t.jsx("path",{d:"M10 5.8V10l2.8 1.8"})]})],dot:[20,1.6,t.jsx("circle",{cx:"10",cy:"10",r:"2.2"})],camera:[17,1.5,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M2.6 6.2a1.4 1.4 0 0 1 1.4-1.4h2l1.1-1.6h2.8l1.1 1.6h2a1.4 1.4 0 0 1 1.4 1.4v6.4a1.4 1.4 0 0 1-1.4 1.4H4a1.4 1.4 0 0 1-1.4-1.4z"}),t.jsx("circle",{cx:"8.5",cy:"9.2",r:"2.4"})]})],clip:[17,1.5,t.jsx("path",{d:"M13.2 8 8.4 12.8a3 3 0 0 1-4.2-4.2l5.1-5.1a2 2 0 1 1 2.8 2.8l-5 5"})],mic:[17,1.5,t.jsxs(t.Fragment,{children:[t.jsx("rect",{x:"6.3",y:"2.4",width:"4.4",height:"7.6",rx:"2.2"}),t.jsx("path",{d:"M3.9 8.4a4.6 4.6 0 0 0 9.2 0M8.5 13v2"})]})],speaker:[17,1.5,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M2.8 6.6h2.4l3.4-2.8v9.4l-3.4-2.8H2.8z"}),t.jsx("path",{d:"M11.2 6.2a3.2 3.2 0 0 1 0 4.6M13.2 4.4a5.8 5.8 0 0 1 0 8.2"})]})],send:[16,1.8,t.jsx("path",{d:"M8 13V3.5M3.8 7.7 8 3.5l4.2 4.2"})],check:[16,1.8,t.jsx("path",{d:"M3.5 8.4 6.6 11.4 12.5 4.8"})],close:[16,1.8,t.jsx("path",{d:"M4.5 4.5l7 7M11.5 4.5l-7 7"})],search:[16,1.6,t.jsxs(t.Fragment,{children:[t.jsx("circle",{cx:"7",cy:"7",r:"4.5"}),t.jsx("path",{d:"M10.5 10.5L14 14"})]})],alert:[16,1.6,t.jsxs(t.Fragment,{children:[t.jsx("circle",{cx:"8",cy:"8",r:"6.2"}),t.jsx("path",{d:"M8 4.8v3.8M8 11.2v.01"})]})],thought:[13,1.4,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M4.2 9.6a3.6 3.6 0 1 1 4.6 0v1.2H4.2z"}),t.jsx("path",{d:"M5.2 12.2h2.6"})]})],chevron:[11,1.5,t.jsx("path",{d:"M2.8 4.2 5.5 6.9l2.7-2.7"})],arrow:[13,1.5,t.jsx("path",{d:"M4.8 2.6 9 6.5l-4.2 3.9"})],copy:[16,1.5,t.jsxs(t.Fragment,{children:[t.jsx("rect",{x:"5.6",y:"5.6",width:"7.6",height:"7.6",rx:"1.4"}),t.jsx("path",{d:"M10.4 5.6V4a1.2 1.2 0 0 0-1.2-1.2H4A1.2 1.2 0 0 0 2.8 4v5.2A1.2 1.2 0 0 0 4 10.4h1.6"})]})],play:[16,1.5,t.jsx("path",{d:"M5.2 3.4v9.2L12.6 8z"})],pause:[16,1.5,t.jsx("path",{d:"M5.6 3.6v8.8M10.4 3.6v8.8"})],stop:[16,1.5,t.jsx("rect",{x:"4.2",y:"4.2",width:"7.6",height:"7.6",rx:"1.2"})],download:[16,1.5,t.jsx("path",{d:"M8 2.8v7.2M4.9 7 8 10.1 11.1 7M3 12.8h10"})],out:[12,1.6,t.jsxs(t.Fragment,{children:[t.jsx("circle",{cx:"6",cy:"6",r:"4.4"}),t.jsx("path",{d:"M3.4 8.6 8.6 3.4"})]}),11],"chevron-left":[14,1.6,t.jsx("path",{d:"M9 2.5 4.5 7 9 11.5"})],"chevron-right":[14,1.6,t.jsx("path",{d:"M5 2.5 9.5 7 5 11.5"})],plus:[14,1.6,t.jsx("path",{d:"M7 2.5v9M2.5 7h9"})],grip:[16,0,t.jsxs("g",{fill:"currentColor",stroke:"none",children:[t.jsx("circle",{cx:"6",cy:"4",r:"1.2"}),t.jsx("circle",{cx:"10",cy:"4",r:"1.2"}),t.jsx("circle",{cx:"6",cy:"8",r:"1.2"}),t.jsx("circle",{cx:"10",cy:"8",r:"1.2"}),t.jsx("circle",{cx:"6",cy:"12",r:"1.2"}),t.jsx("circle",{cx:"10",cy:"12",r:"1.2"})]})],more:[16,0,t.jsxs("g",{fill:"currentColor",stroke:"none",children:[t.jsx("circle",{cx:"8",cy:"3.4",r:"1.35"}),t.jsx("circle",{cx:"8",cy:"8",r:"1.35"}),t.jsx("circle",{cx:"8",cy:"12.6",r:"1.35"})]})],drop:[28,1.8,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M14 4v13M8.5 11.5 14 17l5.5-5.5"}),t.jsx("path",{d:"M5 19.5v2a2.5 2.5 0 0 0 2.5 2.5h13a2.5 2.5 0 0 0 2.5-2.5v-2"})]})],folder:[20,1.6,t.jsx("path",{d:"M2.8 5.6a1.4 1.4 0 0 1 1.4-1.4h3.4l1.7 1.9h6.5a1.4 1.4 0 0 1 1.4 1.4v7.3a1.4 1.4 0 0 1-1.4 1.4H4.2a1.4 1.4 0 0 1-1.4-1.4Z"})],"chevron-down":[14,1.4,t.jsx("path",{d:"M4 5.5 7 8.5l3-3"}),12],frame:[22,1.3,t.jsxs(t.Fragment,{children:[t.jsx("rect",{x:"2.6",y:"3.6",width:"16.8",height:"14.8",rx:"2"}),t.jsx("path",{d:"M2.6 14.2 7.4 9.6l3.4 3 3-2.6 3.6 3.2"}),t.jsx("circle",{cx:"7.4",cy:"7.6",r:"1.2"})]})],"shape-timeseries":[16,1.4,t.jsx("path",{d:"M2 11.5 5.4 7.2l2.6 2.2L14 3.5"})],"shape-table":[16,1.4,t.jsx("path",{d:"M2.2 3.5h11.6v9H2.2zM2.2 6.6h11.6M6.6 6.6v5.9"})],"shape-bars":[16,1.4,t.jsx("path",{d:"M3 13V8.2M7 13V3.6M11 13V6.4M2 13.6h12"})],"shape-keyvalue":[16,1.4,t.jsx("path",{d:"M2.6 4.6h4M9.4 4.6h4M2.6 8h4M9.4 8h4M2.6 11.4h4M9.4 11.4h4"})],"shape-tiles":[16,1.4,t.jsx("path",{d:"M2.4 3.4h4.8v4.2H2.4zM8.8 3.4h4.8v4.2H8.8zM2.4 9.2h4.8v4.2H2.4zM8.8 9.2h4.8v4.2H8.8z"})],"shape-document":[16,1.4,t.jsx("path",{d:"M4 2.4h5l3 3v8.2H4zM9 2.4v3h3M6 9h4M6 11.2h3"})],"shape-diff":[16,1.4,t.jsx("path",{d:"M8 2.6v5M5.5 5.1h5M5.5 11.6h5M3 14h10"})],"shape-terminal":[16,1.4,t.jsx("path",{d:"M2.2 3.4h11.6v9.2H2.2zM4.6 6.4l2 1.6-2 1.6M8 10h3"})],"shape-image":[16,1.4,t.jsx("path",{d:"M2.2 3.4h11.6v9.2H2.2zM2.2 11l3.6-3.4 2.6 2.4 2-1.8 3.4 3M10.6 6.2h.01"})],"shape-preview":[16,1.4,t.jsx("path",{d:"M2.2 3.4h11.6v9.2H2.2zM2.2 6h11.6M4.1 4.7h.01M6 4.7h.01"})],"shape-envelope":[16,1.4,t.jsx("path",{d:"M2.2 4h11.6v8H2.2zM2.2 4.4 8 8.8l5.8-4.4"})],moon:[16,1.5,t.jsx("path",{d:"M12.9 9.7A5.3 5.3 0 0 1 6.3 3.1a5.3 5.3 0 1 0 6.6 6.6z"})],code:[16,1.6,t.jsx("path",{d:"M5.8 4.6L2.4 8l3.4 3.4M10.2 4.6L13.6 8l-3.4 3.4"})],"pasted-doc":[16,1.5,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M4 2.5h5.2L12 5.3v8.2H4z"}),t.jsx("path",{d:"M9 2.5v3h3M6 8.5h4M6 10.8h4"})]})],"shape-structured":[16,1.4,t.jsx("path",{d:"M4 2.6h8v10.8H4zM6.2 5.6h3.6M6.2 8h3.6M6.2 10.4h2.2"})]};function le({name:e,size:n,className:s,...r}){const[a,i,l,o]=jU[e],c=n??o??a;return t.jsx("svg",{className:s,width:c,height:c,viewBox:`0 0 ${a} ${a}`,"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeWidth:i,strokeLinecap:"round",strokeLinejoin:"round","data-icon":e,...r,children:l})}const p$="buddi.rosterCollapsed";function yU(){try{return window.localStorage.getItem(p$)==="1"}catch{return!1}}function wU(e){try{window.localStorage.setItem(p$,e?"1":"0")}catch{}}function g$({agents:e,currentId:n,attention:s,onSelect:r,orientation:a="vertical",lastActivity:i,working:l,groups:o=[],currentGroupId:c=null,onSelectGroup:u,onNewGroup:d}){const f=[...e.top,...e.middle,...e.bottom],m=a==="vertical"?"right":"bottom",[p,g]=h.useState(yU),v=b=>t.jsx(bU,{agent:b,active:b.id===n,attention:s.get(b.id),side:m,onSelect:r,lastAt:(i==null?void 0:i.get(b.id))??null,working:(l==null?void 0:l.has(b.id))??!1},b.id);return t.jsxs("nav",{className:a==="vertical"?"wb-agent-rail":"wb-agent-strip","aria-label":"Agents","data-testid":"agent-rail","data-collapsed":a==="vertical"&&p?"true":void 0,children:[e.top.map(v),e.top.length>0&&e.middle.length>0?t.jsx("span",{className:"wb-agent-sep","data-testid":"agent-rail-sep","aria-hidden":"true"}):null,a==="vertical"&&!p&&e.middle.length>0?t.jsx("span",{className:"wb-roster-label",children:"Your team"}):null,t.jsxs("div",{className:"wb-agent-scroll",children:[e.middle.map(v),u&&f$(f)?t.jsxs("div",{className:"wb-groups","data-testid":"group-rail",children:[t.jsx("span",{className:"wb-agent-sep","aria-hidden":"true"}),t.jsxs("div",{className:"wb-groups-head",children:[t.jsx("span",{className:"wb-groups-label",children:"Groups"}),d?t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":"New group",title:"A team of agents in one conversation",onClick:d,children:t.jsx(le,{name:"plus"})}):null]}),o.map(b=>t.jsxs("button",{type:"button",className:"wb-face wb-group-face","data-active":b.id===c?"true":void 0,"aria-current":b.id===c?"true":void 0,"aria-label":`${b.name}, ${b.members.length} agents`,onClick:()=>u(b.id),children:[t.jsx("span",{className:"wb-group-stack","aria-hidden":"true",children:b.members.slice(0,2).map(j=>{const x=f.find(y=>y.id===j);return t.jsx(Yf,{className:"wb-group-chip",id:j,name:(x==null?void 0:x.name)??"?",face:x,initials:1},j)})}),t.jsxs("span",{className:"wb-face-text",children:[t.jsx("span",{className:"wb-face-name",children:b.name}),t.jsx("span",{className:"wb-face-status",children:b.members.map(j=>{var x;return((x=f.find(y=>y.id===j))==null?void 0:x.name)??j}).join(", ")})]})]},b.id))]}):u?t.jsxs("div",{className:"wb-groups","data-testid":"group-rail-hint",children:[t.jsx("span",{className:"wb-agent-sep","aria-hidden":"true"}),t.jsx("div",{className:"wb-groups-head",children:t.jsx("span",{className:"wb-groups-label",children:"Groups"})}),t.jsxs("p",{className:"wb-groups-hint",children:["A group needs two agents; ",t.jsx("a",{href:vt,children:"add a teammate"}),"."]})]}):null]}),e.bottom.map(v),a==="vertical"?t.jsx("button",{type:"button",className:"ui-icon-btn wb-roster-toggle","data-size":"sm","aria-label":p?"Show agent names":"Hide agent names","aria-pressed":p,onClick:()=>g(b=>(wU(!b),!b)),children:t.jsx(le,{name:p?"chevron-right":"chevron-left"})}):null]})}function bU({agent:e,active:n,attention:s,side:r,onSelect:a,lastAt:i=null,working:l=!1}){const o=qf(s),c=lU(s)??(e.available?i?GF(i):e.description:e.unavailableReason??"Cannot run right now"),u=oU(s,l&&e.available),d=e.unavailableReason??"This agent cannot run on this machine right now.",f=[`${e.name} @${e.handle}`,e.available?null:"unavailable",o,u==="working"?"working now":null,n?"current":null].filter(m=>m!==null&&m!=="").join(" — ");return t.jsxs(zc,{children:[t.jsx(Uc,{asChild:!0,children:t.jsxs("button",{className:"wb-face",...Oi(jo(e)),"data-active":n?"true":void 0,"data-unavailable":e.available?void 0:"true","data-testid":`agent-face-${e.id}`,"aria-label":f,"aria-current":n?"true":void 0,disabled:!e.available,onClick:()=>e.available&&a(e.id),children:[t.jsxs("span",{className:"wb-face-frame",children:[t.jsx(Yf,{className:"wb-face-mark",id:e.id,name:e.name,face:e}),u?t.jsx("span",{className:"wb-face-dot","data-state":u,"data-testid":`agent-dot-${e.id}`,"aria-hidden":"true"}):null]}),t.jsxs("span",{className:"wb-face-text","aria-hidden":"true",children:[t.jsx("span",{className:"wb-face-name",children:e.name}),t.jsx("span",{className:"wb-face-status","data-tone":o?"critical":void 0,children:c})]}),e.available?null:t.jsx("span",{className:"wb-face-out","aria-hidden":"true",children:t.jsx(le,{name:"out"})})]})}),t.jsx(Bc,{children:t.jsxs(Wc,{className:"ui-tip",side:r,sideOffset:8,children:[t.jsx("span",{className:"ui-tip-title",children:e.name}),t.jsx("span",{className:"ui-tip-hint",children:e.available?`@${e.handle} · ${e.model}`:d}),o?t.jsx("span",{className:"ui-tip-alert",children:kU(o)}):null]})})]})}function kU(e){return`${e.slice(0,1).toUpperCase()}${e.slice(1)}.`}function NU(e){let n=0;for(const s of e)n=(n*31+s.charCodeAt(0))%997;return n%6+1}const SU="modulepreload",CU=function(e,n){return new URL(e,n).href},g0={},EU=function(n,s,r){let a=Promise.resolve();if(s&&s.length>0){const l=document.getElementsByTagName("link"),o=document.querySelector("meta[property=csp-nonce]"),c=(o==null?void 0:o.nonce)||(o==null?void 0:o.getAttribute("nonce"));a=Promise.allSettled(s.map(u=>{if(u=CU(u,r),u in g0)return;g0[u]=!0;const d=u.endsWith(".css"),f=d?'[rel="stylesheet"]':"";if(!!r)for(let g=l.length-1;g>=0;g--){const v=l[g];if(v.href===u&&(!d||v.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${u}"]${f}`))return;const p=document.createElement("link");if(p.rel=d?"stylesheet":SU,d||(p.as="script"),p.crossOrigin="",p.href=u,c&&p.setAttribute("nonce",c),document.head.appendChild(p),d)return new Promise((g,v)=>{p.addEventListener("load",g),p.addEventListener("error",()=>v(new Error(`Unable to preload CSS for ${u}`)))})}))}function i(l){const o=new Event("vite:preloadError",{cancelable:!0});if(o.payload=l,window.dispatchEvent(o),!o.defaultPrevented)throw l}return a.then(l=>{for(const o of l||[])o.status==="rejected"&&i(o.reason);return n().catch(i)})},AU="buddi",$U=["core","coding","finance","garage","mail","maker","playground","research"],Vi=e=>`./mascot/${e}.png`,TU=["core"],Px=(e,n)=>TU.includes(e)?`./mascot/anim/${e}-${n}.json`:null,RU=["🙂","📚","🧭","🦊","🛟","🌿","🛠️","🎧"],IU="Introduce yourself by name and say one thing you can do today.",PU=["Hello","A brain","What I take on","Reach me","Your assistant"],ld=(e,n=!1)=>e.length<2?e.join(""):`${e.slice(0,-1).join(", ")}${n&&e.length>2?", and ":" and "}${e[e.length-1]}`,cp=e=>e.charAt(0).toUpperCase()+e.slice(1),MU=["No","One","Two","Three","Four","Five","Six","Seven","Eight"],hc=[{id:"days",title:"My days",plugins:"Weather · Calendar",line:"Weather and your calendars, for a brief every morning.",note:"Weather needs nothing. Calendar asks for your calendar’s private link later, on its own page."},{id:"mail",title:"My mail",plugins:"Mail Triage (built in)",line:"Mail Triage reads new mail and brings you only what needs you.",mate:"Mail Triage",note:"Mail asks for a mailbox in chapter 4."},{id:"money",title:"My money",plugins:"Finance",line:"Accounts, cards and cash flow, kept on this computer.",note:"Finance asks for your bank on its own page."},{id:"voice",title:"Voice",plugins:"Speech",line:"Talk to me and hear me back, here and on your phone. Runs on this computer.",note:"Speech needs nothing."},{id:"code",title:"My code",plugins:"Developer",line:"Developer works in one folder you name, and shows you what it changed.",mate:"Developer",note:"Developer asks for its folder the first time you talk."},{id:"pictures",title:"Pictures",plugins:"Image",line:"One picture from a prompt, with an account you pick.",note:"Image asks which account to draw with."}],DU=["days","mail"],x0=[{id:"buddi",role:"core",label:"Blue"},{id:"mail",role:"mail",label:"Orange"},{id:"finance",role:"finance",label:"Green"},{id:"coding",role:"coding",label:"Violet"},{id:"research",role:"research",label:"Purple"}],_={tagline:"Setting up, on this Mac.",taglineElsewhere:"Setting up, on this computer.",chapters:PU,mapNotes:["Two minutes. Everything can be changed later in Settings, and nothing leaves this computer until you say so.","One line decides which company sees your assistant’s conversations. You can add more brains later and give each agent its own.","Each choice installs a plugin from withbuddi.com. At the end I suggest teammates for what you picked; nothing runs until you have read its card, and you can say no to any of them.","All three are optional. The mailbox is what “My mail” needs; the phone is how I reach you when you are away.","The persona is a plain text file the assistant grows over time. Keep it, rewrite it, or let Agent Father write one after an interview."],count:e=>`Chapter ${e} of 5`,back:"Back",change:"change",later:"Set up later",startOver:{link:"Start over",said:e=>`Starting again. What you already connected stays in Settings: ${e}.`,telegram:"Telegram",browser:"the browser"},strip:(e,n)=>`${e} · ${n}`,hello:{title:"Hi. I’m buddi.",opening:["I live on this computer and I’m about to introduce you to your first assistant. Nothing you tell me leaves this machine, except what your assistant sends to the AI you pick next.","First, what should we call you, and what time is it where you are?"],foot:"Your agents use your name in every reply, and your clock for reminders and the morning brief.",submit:"That’s me",answer:e=>e},name:{label:"Your first name",placeholder:"Sam"},clock:{label:"Your clock",hint:e=>`What this browser says. ${e} right now.`,change:"Change"},brain:{title:"Which AI should your team think with?",ask:"Pick what you already have. I test it with one small call before we go on.",submit:"Use this brain",cards:{free:{title:"Free to start, no key",line:"Ollama Cloud, one tap. Good enough to meet your assistant today.",pill:"Recommended to begin"},claude:{title:"I pay for Claude",line:"Sign in with your Claude account. Uses its extra usage."},chatgpt:{title:"I pay for ChatGPT",line:"Sign in with a code on openai.com. Uses your plan."},key:{title:"I have an API key",line:"Anthropic, OpenAI, Google AI, or another service with an address."},local:{title:"On this computer",line:"Free and private. Looking on this computer…"}},keyKinds:{label:"Which key",key:"Anthropic or OpenAI",gemini:"Google AI",service:"Another service"},claude:{label:"Claude",start:"Sign in with Claude",open:"Open the Claude sign-in page",paste:"Paste what Claude gave you",finish:"Done",waiting:"Sign in on the claude.ai page that just opened, then paste the code Claude shows you."},chatgpt:{label:"ChatGPT",codeBefore:"Here is your code: ",codeAfter:". Type it on the openai.com page that just opened and approve buddi. I’ll notice.",code:"Your code",open:"Open openai.com",again:"Try again",failed:"The sign-in did not finish. Try again."},cloud:{label:"Ollama Cloud",waiting:"Press Connect on the ollama.com page that just opened. Sign in there first if it asks. I’ll notice.",open:"Open the ollama.com page",again:"Try again"},gemini:{label:"Gemini",field:"Your Google AI key",placeholder:"Paste it here",submit:"Use this key",get:"Get a key at aistudio.google.com"},key:{field:"Your key",placeholder:"Paste it here",hint:"I can tell which AI it belongs to from the key. It stays on this computer.",submit:"Use this key",which:"Not right?",anthropic:"Anthropic",openai:"OpenAI",refused:"That key was refused. Check it and paste it again."},local:{looking:"Free and private. Looking on this computer…",found:e=>{const n=r=>r===1?"one model":`${r} models`;return`Free and private. I found ${[e.ollama!==void 0?`Ollama with ${n(e.ollama)}`:null,e.mlxh!==void 0?`mlxh with ${n(e.mlxh)}`:null].filter(Boolean).join(" and ")}; the first answer takes a minute.`},missing:"Free, private, no key. Not here yet: I show you how to install Ollama and fetch a model."},mlxh:{label:"mlxh",connect:"Use mlxh",noBrain:"mlxh has no language model installed. Pull one with `mlxh pull`, then come back."},ollama:{label:"Ollama",connect:"Use Ollama",download:"Get Ollama",copy:"Copy",copied:"Copied",missing:e=>`Ollama isn’t on ${e} yet. Install it, open it, and I’ll notice; I never run an installer for you.`,missingHow:(e,n)=>e==="linux"?`The official script from ollama.com. Paste it into a terminal on ${n}.`:e==="darwin"?"In Terminal, with Homebrew. Or download the app.":"Download it from ollama.com and open it.",stopped:e=>`Ollama is installed but not running. Open the Ollama app${e==="linux"?", or start it with the command below":""}, and I’ll notice.`,empty:(e,n,s,r)=>`Ollama is running, with no model yet. For ${e}’s ${Math.round(n)} GB I’d fetch ${s}: about ${r} GB, once.`,emptyFoot:e=>`Free and private: it runs here, and nothing you say leaves ${e}.`,fetch:e=>`Fetch ${e}`,fetching:(e,n,s)=>s?`Fetching ${e}: ${n} of ${s} GB.`:`Fetching ${e}…`,fetchingFoot:"Keep this page open or not: Ollama keeps fetching, and I pick up where it is.",failed:e=>`The download stopped: ${e} Try again; it picks up where it was.`,again:"Try again",cloud:(e,n)=>e==="memory"?`${Math.round(n)} GB is little for a model of its own: it would be slow. Ollama Cloud runs bigger models for you, free to start.`:e==="gpu"?"No graphics chip Ollama can use here: it would be slow. Ollama Cloud runs bigger models for you, free to start.":"Rather not run a model here? Ollama Cloud runs bigger models for you, free to start.",useCloud:"Use Ollama Cloud instead",honestTitle:"A small model, honestly",honest:"Private and free, but slower and less able than Claude or ChatGPT: fine for chat, notes and reminders; weaker at long plans, careful tool use and code. Home shows how to add a stronger brain whenever you like."},model:{ask:"Which one should it think with?",label:"The model",submit:"Use this one",retry:"Try again",change:"Think with another"},checking:{key:"Checking that key…",service:"Asking the service…",ollama:"Asking the first model one small question. It can take a minute.",cloud:"Asking Ollama Cloud…",claude:"Checking with Claude…",chatgpt:"Asking ChatGPT…",gemini:"Asking Gemini…"},service:{label:"Another service",address:"Address",addressPlaceholder:"The address they gave you",key:"Key",submit:"Connect it"},works:e=>`That works. Your assistant will think with ${e}.`,worksOnFlash:e=>`That works. Google's free tier has no Pro allowance, so your assistant will think with ${e}; turn on billing at Google to use Pro.`,answer:e=>e},takeOn:{title:"What should I take on for you?",ask:"Pick a few. Each one brings a plugin and, for some, a teammate who owns that job. Skip this and I stay a plain assistant; you can add any of it later.",submit:"Take these on",none:"Just an assistant for now",nothing:"Nothing picked. I’ll be a plain assistant, and Home will offer these again.",builtIn:"Mail is built in.",nothingToFetch:"Nothing to fetch.",fetching:(e,n,s)=>`Fetching ${ld(e)} from withbuddi.com and reading them. ${n} of ${s}.`,ready:e=>`${ld(e)} ${e.length>1?"are":"is"} in, read and ready.`,failed:(e,n)=>`${e} did not come: ${n}.`,installing:(e,n)=>`Installing, ${e} of ${n} ready`,installed:"Installed",answer:e=>e.length===0?"Just an assistant":cp(e.join(", ").toLowerCase())},reach:{title:"How do we reach each other?",ask:"Three things, each a minute. Do the ones you want; the rest wait in Settings.",submit:"Continue",phone:{title:"Your phone, through Telegram",line:"Scan the code with your phone and press Start. Approvals, voice notes and the morning brief land there.",setUp:"Set up Telegram",paired:"Paired",hello:"✓ That is your phone, talking to me. Approvals reach you there from now on."},mailbox:{title:"A mailbox",forTriage:"A mailbox, for Mail Triage",line:"Gmail, iCloud, Fastmail or any IMAP account. Reading only; sending always stops at a card you approve.",add:"Add a mailbox",sheet:"Add a mailbox",added:"Mailbox added",unavailable:"Mail is not ready on this computer yet. Settings → Mail can add one later."},app:{title:"buddi as an app, and a browser of its own",line:"Keep buddi in your Dock; give your assistant Chrome or its own Chromium (150 MB) so it can look at websites.",install:"Install app",installed:"App installed",chrome:"Use Chrome",chromium:"Use its Chromium",fetch:"Fetch a browser",ready:e=>e==="chrome"?"Chrome, ready":"Chromium, ready"},answer:e=>e.length===0?"Later, in Settings":cp(e.join(", ")),done:{phone:"phone paired",mailbox:"mailbox added",app:"app and browser"}},browser:{chrome:"Your assistant will browse with Google Chrome.",chromium:"Your assistant will browse with its own Chromium.",needs:"Your assistant needs a browser of its own to look at websites. I am fetching one now, about 150 MB.",installing:"Fetching the browser…",launching:"Making sure it opens…",installed:"Installed.",failed:e=>`That did not work: ${e}`,retry:"Try again"},telegram:{sheet:"Your phone, through Telegram",how:"Two minutes: open Telegram, message @BotFather, send /newbot, paste the token it gives you here.",field:"The token",submit:"Save it",restart:"Saved. It will be ready the next time buddi starts.",scan:"Scan this with your phone and press Start.",expired:"That code has run out. I can make you another one.",newCode:"Show a new code",paired:"That is your phone, talking to me. You can close this and carry on.",close:"Done",notNow:"Not now"},assistant:{title:"Meet your assistant.",ask:"I’ve picked a name, a face and a way of working. Change any of it, or keep them.",team:e=>` Your team so far: ${ld(e)}, waiting to be introduced.`,name:"Name",face:"A face",colour:"A colour for the face",swatch:e=>`Colour: ${e.toLowerCase()}`,mascot:e=>e==="core"?"Buddi Blob":`Buddi Blob, ${e}`,purpose:"How it works",purposeHint:"Plain text. It becomes the assistant’s file, which is yours from then on.",purposeValue:["You're not a chatbot. You're becoming someone this person can count on.","","Some starting truths:","",`- Help for real. No "Great question", no "I'd be happy to". Do the thing, then say what you did.`,"- Have a view. Prefer things, disagree when you should, say when something is a bad idea. A search engine with manners is not a colleague.","- Look before you ask. Read the file, check what you remember, try it. Come back with an answer and one question at most.","- You are a guest here. You can see messages, files and a calendar. Treat that with care, keep what you learn to yourself, and never lecture.","- Remember what matters. Names, preferences, the things they said once and expect you to keep.","- When you change how you work, say so. This file is yours to grow, and the owner should always know what it says."].join(`
96
- `),submit:"Introduce us"},restore:{offer:"I have a backup",sheet:"Restore from a backup",lede:"Pick the backup file buddi made and type its passphrase. Your agents, memory and settings come back as they were; this chapter map is skipped.",file:"Backup file",passphrase:"Passphrase",passphraseHint:"The one you typed when you turned backups on, if it was locked with one. I can’t recover it.",submit:"Restore",cancel:"Never mind",title:"Bringing your buddi back.",started:"Right. Give me a couple of minutes.",phases:{stopping:"Putting everything down for a moment.",snapshot:"Keeping a copy of what is here now, just in case.",database:"Bringing back your conversations and everything you told it to remember.",recovery:"Almost there. Nothing will run on its own until you say so.",files:"Bringing back your files.",starting:"Starting back up.",done:"That is everything.","rolled-back":"That did not work, so I put everything back the way it was.",failed:"That did not work."},welcome:e=>`Welcome back, ${e}.`,keys:"A backup never carries keys, so the AI you think with needs its key one more time."},handover:{waiting:"One moment.",looking:e=>`${e} is looking around…`,slow:"Still waking up. A brain on this computer takes a minute the first time.",silent:"Your assistant isn't answering. The AI you picked may be down; try again, or pick another brain.",again:"Pick another brain",starters:e=>[e.days?"What’s my day like?":"What can you do?","Show me around",e.days?"Link my calendar":e.mail&&!e.mailbox?"Add my mailbox":"What do you know about me?","Remind me at 9 tomorrow"],starterLabel:"Ask first",waitingTitle:e=>`${MU[e]??String(e)} ${e===1?"thing":"things"} still waiting.`,waitingBody:e=>`${cp(ld(e,!0))}. ${e.length>1?e.length===2?"Both are":"They are all":"It’s"} on Home whenever you like.`,home:"Open Home"},done:{open:"Open buddi"}};let od=null;const v0=new Map;function OU(){return od??(od=EU(()=>import("./lottie_light-CKJ88Yuk.js").then(e=>e.l),[],import.meta.url).then(e=>e.default)),od.catch(()=>{od=null}),od}function LU(e){let n=v0.get(e);return n||(n=fetch(e).then(s=>s.ok?s.text():null).catch(()=>null),v0.set(e,n)),n}const j0="(prefers-reduced-motion: reduce)";function x$(){const[e,n]=h.useState(()=>typeof window.matchMedia=="function"&&!window.matchMedia(j0).matches);return h.useEffect(()=>{var a;if(typeof window.matchMedia!="function")return;const s=window.matchMedia(j0),r=()=>n(!s.matches);return(a=s.addEventListener)==null||a.call(s,"change",r),()=>{var i;return(i=s.removeEventListener)==null?void 0:i.call(s,"change",r)}},[]),e}function ku({role:e="core",state:n,size:s,still:r,className:a,onStillError:i}){const l=h.useRef(null),o=x$(),[c,u]=h.useState(!1),d=s==="xs"?null:Px(e,n);return h.useEffect(()=>{if(u(!1),!o||!d)return;let f=!1,m=null;return Promise.all([OU(),LU(d)]).then(([p,g])=>{if(f||!g||!l.current)return;const v=p.loadAnimation({container:l.current,renderer:"svg",loop:!0,autoplay:!document.hidden,animationData:JSON.parse(g),rendererSettings:{preserveAspectRatio:"xMidYMid meet"}}),b=()=>{document.hidden?v.pause():v.play()};document.addEventListener("visibilitychange",b),m=()=>{document.removeEventListener("visibilitychange",b),v.destroy()},u(!0)}).catch(()=>{}),()=>{f=!0,m==null||m()}},[o,d]),t.jsx("span",{ref:l,className:a?`ui-blob ${a}`:"ui-blob","data-size":s,"data-playing":c?"true":void 0,"data-testid":"blob","data-state":n,"aria-hidden":"true",children:c?null:t.jsx("img",{src:r??Vi(e),alt:"",onError:i})})}async function y0(e){const n=new Image;n.src=e,await n.decode();const s=document.createElement("canvas");s.width=8,s.height=8;const r=s.getContext("2d");return r?(r.fillStyle="#fff",r.fillRect(0,0,8,8),r.drawImage(n,0,0,8,8),Array.from(r.getImageData(0,0,8,8).data)):null}function v$(e,n="core"){const s=x$(),r=e!==null&&FU(e,n),[a,i]=h.useState(!1);return h.useEffect(()=>{if(i(!1),!e||r||!s||!Px(n,"idle"))return;let l=!1;return Promise.all([y0(e),y0(Vi(n))]).then(([o,c])=>{if(l||!o||!c||o.length!==c.length)return;const u=o.reduce((d,f,m)=>d+Math.abs(f-c[m]),0)/o.length;i(u<12)}).catch(()=>{}),()=>{l=!0}},[e,r,s,n]),s&&Px(n,"idle")!==null&&(r||a)}function FU(e,n){const s=Vi(n);if(e===s)return!0;try{const r=typeof window>"u"?"http://localhost/":window.location.href;return new URL(e,r).href===new URL(s,r).href}catch{return!1}}function Yf({className:e,id:n,name:s,face:r,tint:a,size:i,unavailable:l,initials:o=2}){const[c,u]=h.useState(null),d=r!=null&&r.picture&&r.picture!==c?r.picture:void 0,f=r==null?void 0:r.avatar,m=d?"image":f==null?void 0:f.kind,p=n?Oi(jo({id:n,accent:r==null?void 0:r.accent,roles:r==null?void 0:r.roles,tools:r==null?void 0:r.tools})):void 0;return t.jsx("span",{className:e,"data-tint":p?void 0:a,"data-size":i,"data-kind":m,"data-unavailable":l?"true":void 0,...p,"aria-hidden":"true",children:d?t.jsx("img",{src:d,alt:"",onError:()=>u(d)}):(f==null?void 0:f.kind)==="image"?t.jsx("img",{src:f.url,alt:""}):(f==null?void 0:f.kind)==="emoji"?f.value:gU(s).slice(0,o)})}function Nn({id:e,name:n,size:s,unavailable:r,face:a}){return t.jsx(Yf,{className:"ui-avatar",id:e,tint:NU(e),name:n,size:s,unavailable:r,face:a})}function fn({agents:e,id:n,size:s}){const r=e.find(a=>a.id===n);return t.jsx(Nn,{id:n,name:(r==null?void 0:r.name)??n,size:s,unavailable:r?!r.available:!1,face:r})}const j$=h.createContext(null);function _U({picture:e,children:n}){return t.jsx(j$.Provider,{value:e??null,children:n})}function y$({size:e,anim:n}){const s=h.useContext(j$),[r,a]=h.useState(null),i=v$(n?s:null);return!s||s===r?null:t.jsx("span",{className:"ui-mascot","data-size":e,"data-testid":"mascot","aria-hidden":"true",children:n&&i?t.jsx(ku,{state:n,still:s,className:"ui-mascot-blob",onStillError:()=>a(s)}):t.jsx("img",{src:s,alt:"",onError:()=>a(s)})})}const w$=h.createContext([]);function ur({text:e,className:n}){const s=Mx(e.replace(/\r\n/g,`
97
- `).split(`
98
- `));return t.jsx("div",{className:n??"wb-md",children:s.map((r,a)=>t.jsx(Dx,{block:r},a))})}const w0=/^(\s*)(```|~~~)\s*([\w+-]*)\s*$/,b0=/^(#{1,6})\s+(.*?)\s*#*\s*$/,k0=/^\s*([-*_])(\s*\1){2,}\s*$/,cd=/^(\s*)([-*+])\s+(.*)$/,Bo=/^(\s*)(\d{1,9})[.)]\s+(.*)$/,ud=/^\s*>\s?(.*)$/,up=/^\s*\|.*\|\s*$/,N0=/^\s*\|?\s*:?-{2,}:?\s*(\|\s*:?-{2,}:?\s*)*\|?\s*$/;function Mx(e){const n=[];let s=0;for(;s<e.length;){const r=e[s];if(r.trim()===""){s+=1;continue}const a=w0.exec(r);if(a){const o=a[2],c=[];for(s+=1;s<e.length&&!new RegExp(`^\\s*${o}\\s*$`).test(e[s]);)c.push(e[s]),s+=1;s+=1,n.push({type:"code",lang:a[3]||null,text:c.join(`
99
- `)});continue}const i=b0.exec(r);if(i){n.push({type:"h",level:i[1].length,text:i[2]}),s+=1;continue}if(k0.test(r)){n.push({type:"hr"}),s+=1;continue}if(ud.test(r)){const o=[];for(;s<e.length&&ud.test(e[s]);)o.push(ud.exec(e[s])[1]),s+=1;n.push({type:"quote",blocks:Mx(o),raw:o.join(`
100
- `)});continue}if(up.test(r)&&s+1<e.length&&N0.test(e[s+1])){const o=hp(r),c=hp(e[s+1]).map(d=>{const f=d.startsWith(":"),m=d.endsWith(":");return f&&m?"center":m?"right":f?"left":null});s+=2;const u=[];for(;s<e.length&&up.test(e[s]);)u.push(hp(e[s])),s+=1;n.push({type:"table",head:o,rows:u,align:c});continue}if(cd.test(r)||Bo.test(r)){const o=Bo.exec(r)??cd.exec(r),c=Bo.test(r),u=o[1].length,d=c?Number(o[2]):1,f=[];for(;s<e.length;){const m=c?Bo.exec(e[s]):cd.exec(e[s]);if(!m||m[1].length!==u)break;const p=[m[3]];for(s+=1;s<e.length;){const g=e[s],v=g.trim()!==""&&dp(g)>u,b=g.trim()===""&&s+1<e.length&&e[s+1].trim()!==""&&dp(e[s+1])>u;if(!v&&!b)break;p.push(g.trim()===""?"":g.slice(Math.min(dp(g),u+2))),s+=1}f.push(Mx(p))}n.push({type:"list",ordered:c,start:d,items:f});continue}const l=[];for(;s<e.length;){const o=e[s];if(o.trim()===""||w0.test(o)||b0.test(o)||k0.test(o)||ud.test(o)||cd.test(o)||Bo.test(o)||up.test(o)&&s+1<e.length&&N0.test(e[s+1]))break;l.push(o.trim()),s+=1}l.length>0&&n.push({type:"p",text:l.join(`
101
- `)})}return n}function dp(e){return e.length-e.trimStart().length}function hp(e){const n=e.trim().replace(/^\|/,"").replace(/\|$/,""),s=[];let r="";for(let a=0;a<n.length;a+=1){const i=n[a];if(i==="\\"&&n[a+1]==="|"){r+="|",a+=1;continue}if(i==="|"){s.push(r.trim()),r="";continue}r+=i}return s.push(r.trim()),s}function Dx({block:e}){switch(e.type){case"p":return t.jsx("p",{children:nr(e.text)});case"h":{const n=Math.min(6,Math.max(1,e.level)),s=`h${Math.min(n+2,6)}`;return t.jsx(s,{className:"wb-md-h","data-level":n,children:nr(e.text)})}case"code":return t.jsxs("div",{className:"wb-md-code-frame",children:[t.jsxs("div",{className:"wb-md-code-head",children:[t.jsx("span",{className:"wb-md-code-lang",children:e.lang??"text"}),t.jsx(S0,{text:e.text,what:"code",always:!0})]}),t.jsx("pre",{className:"wb-md-code","data-lang":e.lang??void 0,children:t.jsx("code",{children:e.text})})]});case"quote":return t.jsxs("div",{className:"wb-md-copyable",children:[t.jsx("blockquote",{children:e.blocks.map((n,s)=>t.jsx(Dx,{block:n},s))}),t.jsx(S0,{text:e.raw,what:"quote"})]});case"hr":return t.jsx("hr",{});case"list":{const n=e.items.map((s,r)=>t.jsx("li",{children:s.map((a,i)=>a.type==="p"?t.jsx(h.Fragment,{children:nr(a.text)},i):t.jsx(Dx,{block:a},i))},r));return e.ordered?t.jsx("ol",{start:e.start,children:n}):t.jsx("ul",{children:n})}case"table":return t.jsx("div",{className:"ui-table-wrap",children:t.jsxs("table",{className:"ui-table wb-md-table",children:[t.jsx("thead",{children:t.jsx("tr",{children:e.head.map((n,s)=>t.jsx("th",{style:e.align[s]?{textAlign:e.align[s]}:void 0,children:nr(n)},s))})}),t.jsx("tbody",{children:e.rows.map((n,s)=>t.jsx("tr",{children:n.map((r,a)=>t.jsx("td",{style:e.align[a]?{textAlign:e.align[a]}:void 0,children:nr(r)},a))},s))})]})})}}function S0({text:e,what:n,always:s=!1}){const[r,a]=h.useState("idle"),i=()=>{var l;if(!((l=navigator.clipboard)!=null&&l.writeText)){a("failed");return}navigator.clipboard.writeText(e).then(()=>a("done"),()=>a("failed")),window.setTimeout(()=>a("idle"),1500)};return t.jsx("button",{type:"button",className:"wb-md-copy","data-state":r,"data-always":s||void 0,"aria-label":`Copy ${n}`,title:`Copy ${n}`,onClick:i,children:r==="done"?"Copied":r==="failed"?"Select to copy":t.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 13 13","aria-hidden":"true",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("rect",{x:"4.5",y:"4.5",width:"6.5",height:"6.5",rx:"1.2"}),t.jsx("path",{d:"M8.5 4.5V3a1 1 0 0 0-1-1H3a1 1 0 0 0-1 1v4.5a1 1 0 0 0 1 1h1.5"})]})})}function zU({handle:e}){const s=h.useContext(w$).find(r=>r.handle.toLowerCase()===e.toLowerCase());return s?t.jsxs(zc,{children:[t.jsx(Uc,{asChild:!0,children:t.jsxs("a",{className:"wb-mention-link",href:Ze(s.id),children:["@",s.handle]})}),t.jsx(Bc,{children:t.jsxs(Wc,{className:"wb-agent-card",sideOffset:6,children:[t.jsx(Nn,{id:s.id,name:s.name,face:s,unavailable:!s.available}),t.jsxs("span",{className:"wb-agent-card-text",children:[t.jsx("span",{className:"wb-agent-card-name",children:s.name}),t.jsx("span",{className:"wb-agent-card-desc",children:s.description}),t.jsxs("span",{className:"wb-agent-card-meta",children:[s.model,s.available?"":" · unavailable"]})]})]})})]}):t.jsxs(t.Fragment,{children:["@",e]})}const UU=new RegExp("(`+)([\\s\\S]*?[^`])\\1(?!`)|\\*\\*([^*]+?)\\*\\*|__([^_]+?)__|~~([^~]+?)~~|(?<![\\w*])\\*([^*\\n]+?)\\*(?![\\w*])|(?<![\\w_])_([^_\\n]+?)_(?![\\w_])|\\[([^\\]\\n]+)\\]\\((https?:\\/\\/[^\\s)]+)\\)|<?(https?:\\/\\/[^\\s<>)\\]]+[^\\s<>)\\].,;:!?'\"])>?|(?<![\\w@/])@([a-z0-9][a-z0-9_-]{0,63})(?![\\w-])","i");function nr(e){const n=[];let s=e,r=0;for(;s!=="";){const a=UU.exec(s);if(!a){n.push(...C0(s,r));break}a.index>0&&n.push(...C0(s.slice(0,a.index),r)),r+=100,a[2]!==void 0?n.push(t.jsx("code",{children:a[2]},r)):a[3]!==void 0?n.push(t.jsx("strong",{children:nr(a[3])},r)):a[4]!==void 0?n.push(t.jsx("strong",{children:nr(a[4])},r)):a[5]!==void 0?n.push(t.jsx("s",{children:nr(a[5])},r)):a[6]!==void 0?n.push(t.jsx("em",{children:nr(a[6])},r)):a[7]!==void 0?n.push(t.jsx("em",{children:nr(a[7])},r)):a[8]!==void 0&&a[9]!==void 0?n.push(t.jsx("a",{href:a[9],target:"_blank",rel:"noopener noreferrer",children:nr(a[8])},r)):a[10]!==void 0?n.push(t.jsx("a",{href:a[10],target:"_blank",rel:"noopener noreferrer",children:a[10]},r)):a[11]!==void 0&&n.push(t.jsx(zU,{handle:a[11]},r)),s=s.slice(a.index+a[0].length)}return n}function C0(e,n){return e.split(`
102
- `).flatMap((r,a)=>a===0?[r]:[t.jsx("br",{},`${n}-br-${a}`),r])}function BU({props:e}){return t.jsxs("div",{children:[e.title?t.jsx("h4",{className:"wb-doc-title",children:e.title}):null,e.metadata.length>0?t.jsx("dl",{className:"ui-kv wb-block",children:e.metadata.map(n=>t.jsxs("div",{className:"contents",children:[t.jsx("dt",{children:n.label}),t.jsx("dd",{children:pn(n.value,n.unit,null)})]},n.label))}):null,e.kind==="image"&&e.src?t.jsx("img",{src:e.src,alt:e.title??"Attached image",className:"wb-doc-image"}):e.kind==="pdf"&&e.src?t.jsx("object",{data:e.src,type:"application/pdf",className:"wb-doc-pdf",children:t.jsx("a",{href:e.src,children:"Open the PDF"})}):e.text?t.jsx("div",{className:"wb-doc",children:t.jsx(ur,{text:e.text})}):t.jsx("p",{className:"wb-empty",children:"This document came back with no body."})]})}const WU=["mail","money","calendar","people","file","chart","bell","plug","key","globe","sun","partly-cloudy","cloud","rain","drizzle","snow","storm","fog","wind","moon-clear","check","clock","moon-cloud"];function Ce(e,n){if(n===""||n==="$")return e;let s=e;for(const r of n.split(".")){const a=/^([^[\]]*)((?:\[\d+\])*)$/.exec(r);if(!a)return;const[,i="",l=""]=a;if(i!==""){if(s===null||typeof s!="object")return;s=s[i]}for(const o of l.match(/\d+/g)??[]){if(!Array.isArray(s))return;s=s[Number(o)]}if(s===void 0)return}return s}function Ke(e,n){if(n)return"const"in n?n.const:Ce(e,n.path)}function ys(e){if(typeof e=="number")return Number.isFinite(e)?e:null;if(typeof e=="string"&&e.trim()!==""){const n=Number(e);return Number.isFinite(n)?n:null}return null}function jt(e){return typeof e=="string"?e:typeof e=="number"||typeof e=="boolean"?String(e):null}function Ua(e){return Array.isArray(e)?e:[]}function HU(e,n){const s=Ua(Ce(e,n.points)).map(a=>{const i=ys(Ce(a,n.y)),l=jt(Ce(a,n.x));return i===null||l===null?null:{x:l,y:i}}).filter(a=>a!==null),r=(n.referenceLines??[]).map(a=>{const i=ys(Ke(e,a.value));return i===null?null:{value:i,label:a.label,tone:a.tone??"neutral"}}).filter(a=>a!==null);return{points:s,unit:n.unit??"number",currency:jt(Ke(e,n.currency)),label:jt(Ke(e,n.label)),referenceLines:r,mark:n.mark??null,shadeBelow:ys(Ke(e,n.shadeBelow)),events:KU(e,n)}}function KU(e,n){const s=n.events;if(!s)return[];const r=[],a=(i,l)=>{const o=jt(Ce(i,s.label));if(o===null)return;const c=jt(Ce(i,s.at))??l;c!==null&&r.push({at:c,label:o,amount:s.amount?ys(Ce(i,s.amount)):null})};if(s.parent){for(const i of Ua(Ce(e,n.points))){const l=jt(Ce(i,n.x));for(const o of Ua(Ce(i,s.parent)))a(o,l)}return r}for(const i of Ua(Ce(e,s.path??n.points)))a(i,null);return r}function VU(e,n){const s=(n.columns??[]).map(o=>({key:o.key,label:o.label,type:o.type??"text"})),r=o=>(n.columns??[]).map(c=>{const u=Ce(o,c.key);let d=null;if(c.bar){const f=ys(Ke(o,c.bar.max))??ys(Ke(e,c.bar.max)),m=ys(u);if(f!==null&&f>0&&m!==null){const p=Math.max(0,Math.min(1,m/f));d={fraction:p,tone:qU(p*100,c.bar.thresholds)}}}return{value:u,type:c.type??"text",currency:jt(Ke(o,c.currency))??jt(Ke(e,c.currency)),bar:d}}),a=Ua(Ce(e,n.rows)),i=n.groupBy?GU(a,n.groupBy,r):[{label:null,rows:a.map(r)}],l=(n.summary??[]).map(o=>({label:o.label,value:Ke(e,o.value),unit:o.unit??"text",currency:jt(Ke(e,o.currency)),tone:o.tone??"neutral"}));return{columns:s,groups:i,summary:l,empty:n.empty??"Nothing to show."}}function GU(e,n,s){const r=new Map;for(const a of e){const i=String(Ce(a,n.key)??""),l=r.get(i);l?l.push(a):r.set(i,[a])}return[...r.entries()].map(([a,i])=>{var l;return{label:((l=n.labels)==null?void 0:l[a])??a,rows:i.map(s)}})}function qU(e,n){var r;return!n||n.length===0?"neutral":((r=[...n].sort((a,i)=>i.atLeast-a.atLeast).find(a=>e>=a.atLeast))==null?void 0:r.tone)??"neutral"}function YU(e,n){return{bars:Ua(Ce(e,n.bars)).map(r=>{const a=ys(Ce(r,n.value)),i=jt(Ce(r,n.category));return a===null||i===null?null:{category:i,value:a}}).filter(r=>r!==null),unit:n.unit??"number",currency:jt(Ke(e,n.currency))}}function JU(e,n){if(n.pairs)return{pairs:n.pairs.map(r=>({label:r.label,value:Ke(e,r.value),unit:r.unit??"text",currency:jt(Ke(e,r.currency)),tone:r.tone??"neutral"}))};const s=Ce(e,n.from??"$");return s===null||typeof s!="object"||Array.isArray(s)?{pairs:[]}:{pairs:Object.entries(s).map(([r,a])=>({label:_n(r),value:a,unit:"text",currency:null,tone:"neutral"}))}}const QU=new Set(["good","warning","critical","neutral","accent"]),XU=new Set(WU);function Ox(e){return typeof e=="string"&&XU.has(e)?e:null}function Ey(e,n,s=""){const r=n.empty??"Nothing to show.",a=s.split(".")[0]??"";if(n.notice){const l=jt(Ce(e,n.notice.text));if(l!==null&&l.trim()!==""){const o=n.notice.link&&a!==""?{plugin:a,page:n.notice.link.page}:null;return{tiles:[{icon:Ox(n.notice.icon??"bell"),value:"",label:l.trim(),lines:[],tone:"neutral",link:o}],notice:!0,empty:r}}}return{tiles:Ua(Ce(e,n.items)).map(l=>{const o=jt(Ce(l,n.value))??"",c=jt(Ce(l,n.label))??"";if(o===""&&c==="")return null;const u=n.tone?jt(Ce(l,n.tone)):null;return{icon:Ox(Ke(l,n.icon)),value:o,label:c,lines:(n.lines??[]).slice(0,2).map(d=>jt(Ce(l,d))).filter(d=>d!==null&&d.trim()!==""),tone:u!==null&&QU.has(u)?u:"neutral",link:null}}).filter(l=>l!==null),notice:!1,empty:r}}function ZU(e,n){const s=jt(Ke(e,n.kind)),r=s==="image"||s==="pdf"?s:"text",a=n.src?jt(Ce(e,n.src)):null;return{kind:r,text:n.text?jt(Ce(e,n.text)):null,src:a&&k$(a)?a:null,title:jt(Ke(e,n.title)),metadata:(n.metadata??[]).map(i=>({label:i.label,value:Ke(e,i.value),unit:i.unit??"text"}))}}function e6(e,n){const s=n.diff?Ce(e,n.diff):void 0;return{diff:typeof s=="string"&&s.trim()!==""?s:null,title:jt(Ke(e,n.title)),metadata:(n.metadata??[]).map(r=>({label:r.label,value:Ke(e,r.value),unit:r.unit??"text"}))}}function t6(e,n){const s=n.output?Ce(e,n.output):void 0,r=l=>{const o=l?Ce(e,l):void 0;return typeof o=="number"&&Number.isInteger(o)?o:null},a=r(n.omittedBytes),i=n.elapsedMs?Ce(e,n.elapsedMs):void 0;return{command:jt(Ke(e,n.command)),output:typeof s=="string"?s:null,exitCode:r(n.exitCode),elapsedMs:typeof i=="number"&&Number.isFinite(i)&&i>=0?i:null,omittedBytes:a!==null&&a>0?a:null,metadata:(n.metadata??[]).map(l=>({label:l.label,value:Ke(e,l.value),unit:l.unit??"text"}))}}const n6=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function b$(e){const n=e!==null&&typeof e=="object"&&!Array.isArray(e)?e.artifactId??e.id:e;return typeof n=="string"&&n6.test(n)?n.toLowerCase():null}function s6(e,n){return{artifactId:n.src?b$(Ce(e,n.src)):null,title:jt(Ke(e,n.title)),caption:jt(Ke(e,n.caption)),...n.captionLabel?{captionLabel:jt(Ke(e,n.captionLabel))}:{}}}function E0(e){if(!k$(e))return null;let n;try{n=new URL(e,"file:///").pathname}catch{return null}const s=/^\/preview\/([A-Za-z0-9][A-Za-z0-9_.-]*)\/([A-Za-z0-9][A-Za-z0-9_.-]*)\/?$/.exec(n);return s?{plugin:s[1],name:s[2]}:null}function r6(e,n){const s=n.src?jt(Ce(e,n.src)):null,r=n.port?Ce(e,n.port):null,a=n.awaiting?jt(Ce(e,n.awaiting)):null;return{target:s?E0(s):null,title:jt(Ke(e,n.title)),output:n.output?jt(Ce(e,n.output)):null,port:typeof r=="number"&&Number.isInteger(r)&&r>0&&r<=65535?r:null,awaiting:a?E0(a):null,reloadsItself:n.reloadsItself?Ce(e,n.reloadsItself)===!0:!1,ports:n.ports?a6(Ce(e,n.ports)):[]}}function a6(e){const n=Ua(e).filter(s=>typeof s=="number"&&Number.isInteger(s)&&s>0&&s<=65535);return[...new Set(n)].sort((s,r)=>s-r)}function k$(e){return e.startsWith("/")&&!e.startsWith("//")}function _n(e){const n=e.replace(/[_-]+/g," ").replace(/([a-z0-9])([A-Z])/g,"$1 $2").trim().toLowerCase();return n.charAt(0).toUpperCase()+n.slice(1)}function N$(e,n){const s=e.map??{};switch(e.renderer){case"timeseries":return{renderer:"timeseries",props:HU(n,s)};case"table":return{renderer:"table",props:VU(n,s)};case"bars":return{renderer:"bars",props:YU(n,s)};case"keyvalue":return{renderer:"keyvalue",props:JU(n,s)};case"tiles":return{renderer:"tiles",props:Ey(n,s,e.tool)};case"document":return{renderer:"document",props:ZU(n,s)};case"diff":return{renderer:"diff",props:e6(n,s)};case"terminal":return{renderer:"terminal",props:t6(n,s)};case"image":return{renderer:"image",props:s6(n,s)};case"preview":return{renderer:"preview",props:r6(n,s)};default:return{renderer:"structured",props:{value:n}}}}var i6=Object.defineProperty,qs=(e,n)=>i6(e,"name",{value:n,configurable:!0}),Ay="Dialog",[S$,nne]=fr(Ay),[l6,Hr]=S$(Ay),Jf=qs(e=>{const{__scopeDialog:n,children:s,open:r,defaultOpen:a,onOpenChange:i,modal:l=!0}=e,o=h.useRef(null),c=h.useRef(null),[u,d]=ni({prop:r,defaultProp:a??!1,onChange:i,caller:Ay}),[f,m]=h.useState(0),[p,g]=h.useState(0);return t.jsx(l6,{scope:n,triggerRef:o,contentRef:c,contentId:ir(),titleId:ir(),descriptionId:ir(),titlePresent:f>0,descriptionPresent:p>0,setTitleCount:m,setDescriptionCount:g,open:u,onOpenChange:d,onOpenToggle:h.useCallback(()=>d(v=>!v),[d]),modal:l,children:s})},"Dialog"),o6="DialogTrigger",c6=h.forwardRef(qs(function(n,s){const{__scopeDialog:r,...a}=n,i=Hr(o6,r),l=$t(s,i.triggerRef);return t.jsx(bt.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.open?i.contentId:void 0,"data-state":em(i.open),...a,ref:l,onClick:_e(n.onClick,i.onOpenToggle)})},"DialogTrigger")),C$="DialogPortal",[u6,E$]=S$(C$,{forceMount:void 0}),Qf=qs(e=>{const{__scopeDialog:n,forceMount:s,children:r,container:a}=e,i=Hr(C$,n);return t.jsx(u6,{scope:n,forceMount:s,children:h.Children.map(r,l=>t.jsx(Br,{present:s||i.open,children:t.jsx(Cf,{asChild:!0,container:a,children:l})}))})},"DialogPortal"),Lx="DialogOverlay",$y=h.forwardRef(qs(function(n,s){const r=E$(Lx,n.__scopeDialog),{forceMount:a=r.forceMount,...i}=n,l=Hr(Lx,n.__scopeDialog);return l.modal?t.jsx(Br,{present:a||l.open,children:t.jsx(h6,{...i,ref:s})}):null},"DialogOverlay")),d6=Ka("DialogOverlay.RemoveScroll"),h6=h.forwardRef(qs(function(n,s){const{__scopeDialog:r,...a}=n,i=Hr(Lx,r),l=oE(),o=$t(s,l);return t.jsx(oy,{as:d6,allowPinchZoom:!0,shards:[i.contentRef],children:t.jsx(bt.div,{"data-state":em(i.open),...a,ref:o,style:{pointerEvents:"auto",...a.style}})})},"DialogOverlayImpl")),Jc="DialogContent",Xf=h.forwardRef(qs(function(n,s){const r=E$(Jc,n.__scopeDialog),{forceMount:a=r.forceMount,...i}=n,l=Hr(Jc,n.__scopeDialog);return t.jsx(Br,{present:a||l.open,children:l.modal?t.jsx(f6,{...i,ref:s}):t.jsx(m6,{...i,ref:s})})},"DialogContent")),f6=h.forwardRef(qs(function(n,s){const r=Hr(Jc,n.__scopeDialog),a=h.useRef(null),i=$t(s,r.contentRef,a);return h.useEffect(()=>{const l=a.current;if(l)return kA(l)},[]),t.jsx(A$,{...n,ref:i,trapFocus:r.open,disableOutsidePointerEvents:r.open,onCloseAutoFocus:_e(n.onCloseAutoFocus,l=>{var o;l.preventDefault(),(o=r.triggerRef.current)==null||o.focus()}),onPointerDownOutside:_e(n.onPointerDownOutside,l=>{const o=l.detail.originalEvent,c=o.button===0&&o.ctrlKey===!0;(o.button===2||c)&&l.preventDefault()}),onFocusOutside:_e(n.onFocusOutside,l=>l.preventDefault())})},"DialogContentModal")),m6=h.forwardRef(qs(function(n,s){const r=Hr(Jc,n.__scopeDialog),a=h.useRef(!1),i=h.useRef(!1);return t.jsx(A$,{...n,ref:s,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:l=>{var o,c;(o=n.onCloseAutoFocus)==null||o.call(n,l),l.defaultPrevented||(a.current||(c=r.triggerRef.current)==null||c.focus(),l.preventDefault()),a.current=!1,i.current=!1},onInteractOutside:l=>{var u,d;(u=n.onInteractOutside)==null||u.call(n,l),l.defaultPrevented||(a.current=!0,l.detail.originalEvent.type==="pointerdown"&&(i.current=!0));const o=l.target;((d=r.triggerRef.current)==null?void 0:d.contains(o))&&l.preventDefault(),l.detail.originalEvent.type==="focusin"&&i.current&&l.preventDefault()}})},"DialogContentNonModal")),A$=h.forwardRef(qs(function(n,s){const{__scopeDialog:r,trapFocus:a,onOpenAutoFocus:i,onCloseAutoFocus:l,...o}=n,c=Hr(Jc,r);return _f(),t.jsx(t.Fragment,{children:t.jsx(aA,{asChild:!0,loop:!0,trapped:a,onMountAutoFocus:i,onUnmountAutoFocus:l,children:t.jsx(Sf,{role:"dialog",id:c.contentId,"aria-describedby":c.descriptionPresent?c.descriptionId:void 0,"aria-labelledby":c.titlePresent?c.titleId:void 0,"data-state":em(c.open),...o,ref:s,deferPointerDownOutside:!0,onDismiss:()=>c.onOpenChange(!1)})})})},"DialogContentImpl")),p6="DialogTitle",Zf=h.forwardRef(qs(function(n,s){const{__scopeDialog:r,...a}=n,i=Hr(p6,r),{setTitleCount:l}=i;return cs(()=>(l(o=>o+1),()=>l(o=>o-1)),[l]),t.jsx(bt.h2,{id:i.titleId,...a,ref:s})},"DialogTitle")),g6="DialogClose",Ty=h.forwardRef(qs(function(n,s){const{__scopeDialog:r,...a}=n,i=Hr(g6,r);return t.jsx(bt.button,{type:"button",...a,ref:s,onClick:_e(n.onClick,()=>i.onOpenChange(!1))})},"DialogClose"));function em(e){return e?"open":"closed"}qs(em,"getState");const x6=5;function me(e,n,s){const[r,a]=h.useState(void 0),[i,l]=h.useState(null),[o,c]=h.useState(!0),[u,d]=h.useState(0),[f,m]=h.useState(0),p=h.useRef(e);return p.current=e,h.useEffect(()=>{let g=!1;return c(!0),p.current().then(v=>{g||(a(v),l(null),m(0))}).catch(v=>{g||(l(v instanceof xe?v.message:String(v)),m(b=>b+1))}).finally(()=>{g||c(!1)}),()=>{g=!0}},[...n,u]),h.useEffect(()=>{if(!s||f>=x6)return;const g=window.setTimeout(()=>d(v=>v+1),s*2**f);return()=>window.clearTimeout(g)},[s,f,u]),{data:r,error:i,loading:o,reload:()=>{m(0),d(g=>g+1)}}}const $$={width:480,height:160,top:10,right:10,bottom:22,left:40},T$={width:1200,height:180,top:10,right:40,bottom:22,left:40};function v6({xs:e,series:n}){const s=T$,r=s.width-s.left-s.right,a=s.height-s.top-s.bottom,i=D=>D.filter($=>$!==null&&Number.isFinite($)),l=n.filter(D=>D.type!=="bar"),o=n.filter(D=>D.type==="bar"),c=l.flatMap(D=>i(D.values)),u=c.length>0?Math.min(...c):0,d=c.length>0?Math.max(...c):1;let f=u,m=d;if(f===m)f-=1,m+=1;else{const D=(m-f)*.08;f-=D,m+=D}const p=D=>Us(s.top+a-(D-f)/(m-f)*a),g=o.length>0&&o.every(D=>D.unit==="percent"),v=g?100:Math.max(1,...o.flatMap(D=>i(D.values))),b=D=>Us(s.top+a-Math.max(0,D)/v*a),j=e.length,x=j>0?r/j:r,y=D=>Us(s.left+x*(D+.5)),w=n.map(D=>{if(D.type==="bar")return"";let $="M";const L=[];return D.values.forEach((O,M)=>{if(O===null||!Number.isFinite(O)){$="M";return}L.push(`${$}${y(M)},${p(O)}`),$="L"}),L.join(" ")}),k=[],N=x*.6/Math.max(1,o.length),S=s.height-s.bottom;let C=0;n.forEach((D,$)=>{if(D.type!=="bar")return;const L=C++;D.values.forEach((O,M)=>{if(O===null||!Number.isFinite(O)||O<=0)return;const P=b(O);k.push({series:$,index:M,x:Us(y(M)-x*.3+N*L),y:P,width:Us(N),height:Us(S-P)})})});const E=c.length>0?Ah(u,d,2).map(D=>({value:D,y:p(D)})):[],T=o.length===0?[]:(g?[0,50,100]:Ah(0,v,2)).map(D=>({value:D,y:b(D),percent:g})),I=Math.max(1,Math.ceil(j/8)),F=e.flatMap((D,$)=>$%I===0?[{index:$,x:y($)}]:[]);return{lines:w,bars:k,targetY:null,ticks:E,xLabels:F,rightTicks:T}}function j6({xs:e,series:n,type:s="line",target:r=null}){const a=$$,i=a.width-a.left-a.right,l=a.height-a.top-a.bottom,o=n.flatMap(y=>y.values.filter(w=>w!==null&&Number.isFinite(w)));r!==null&&Number.isFinite(r)&&o.push(r),s==="bar"&&o.push(0);let c=o.length>0?Math.min(...o):0,u=o.length>0?Math.max(...o):1;if(c===u)c-=1,u+=1;else if(s==="line"){const y=(u-c)*.08;c-=y,u+=y}const d=y=>Us(a.top+l-(y-c)/(u-c)*l),f=e.length,m=f>0?i/f:i,p=y=>Us(s==="bar"?a.left+m*(y+.5):a.left+(f<=1?i/2:y/(f-1)*i)),g=s==="line"?n.map(y=>{let w="M";const k=[];return y.values.forEach((N,S)=>{if(N===null||!Number.isFinite(N)){w="M";return}k.push(`${w}${p(S)},${d(N)}`),w="L"}),k.join(" ")}):[],v=[];if(s==="bar"&&f>0){const y=m*.7,w=y/Math.max(1,n.length),k=d(0);n.forEach((N,S)=>{N.values.forEach((C,E)=>{if(C===null||!Number.isFinite(C))return;const T=d(C);v.push({series:S,index:E,x:Us(a.left+m*E+(m-y)/2+w*S),y:Math.min(T,k),width:Us(w),height:Us(Math.abs(k-T))})})})}const j=(o.length>0?Ah(Math.min(...o),Math.max(...o),2):[]).map(y=>({value:y,y:d(y)})),x=f===0?[]:f===1?[0]:f<5?[0,f-1]:[0,Math.floor((f-1)/2),f-1];return{lines:g,bars:v,targetY:r!==null&&Number.isFinite(r)?d(r):null,ticks:j,xLabels:x.map(y=>({index:y,x:p(y)}))}}function y6(e){const n=e.formatX??(o=>o),s=e.formatY??(o=>String(o)),r=e.xs.length;if(r===0)return`${e.label??"Chart"}: nothing recorded yet.`;const a=r===1?`on ${n(e.xs[0])}`:`from ${n(e.xs[0])} to ${n(e.xs[r-1])}`,i=e.series.map(o=>{const c=o.values.filter(d=>d!==null&&Number.isFinite(d));if(c.length===0)return`${o.label}: no values`;const u=c[c.length-1];return`${o.label}: latest ${s(u)}, lowest ${s(Math.min(...c))}, highest ${s(Math.max(...c))}`}),l=e.target!==null&&e.target!==void 0&&Number.isFinite(e.target)?` Target ${s(e.target)}.`:"";return`${e.label??"Chart"}, ${r} ${r===1?"point":"points"} ${a}. ${i.join("; ")}.${l}`}function w6({xs:e,series:n,type:s="line",target:r=null,label:a,formatX:i=o=>o,formatY:l=o=>String(o)}){const o=s==="mixed",c=o?T$:$$,u=o?v6({xs:e,series:n}):j6({xs:e,series:n,type:s,target:r}),d=y6({xs:e,series:n,target:r,...a?{label:a}:{},formatX:i,formatY:l});return t.jsxs("figure",{className:"ui-chart","data-type":s,children:[t.jsxs("svg",{viewBox:`0 0 ${c.width} ${c.height}`,"aria-hidden":"true",focusable:"false","data-testid":"chart-svg",children:[u.ticks.map(f=>t.jsxs("g",{children:[t.jsx("line",{className:"ui-chart-grid",x1:c.left,x2:c.width-c.right,y1:f.y,y2:f.y}),t.jsx("text",{x:c.left-6,y:f.y,textAnchor:"end",dominantBaseline:"middle",children:l(f.value)})]},f.value)),(u.rightTicks??[]).map(f=>t.jsx("text",{x:c.width-c.right+6,y:f.y,textAnchor:"start",dominantBaseline:"middle",children:f.percent?`${f.value}%`:l(f.value)},`r-${f.value}`)),t.jsx("line",{className:"ui-chart-axis",x1:c.left,x2:c.width-c.right,y1:c.height-c.bottom,y2:c.height-c.bottom}),u.bars.map(f=>t.jsx("rect",{className:"ui-chart-bar","data-series":f.series,x:f.x,y:f.y,width:f.width,height:f.height},`${f.series}-${f.index}`)),u.lines.map((f,m)=>f?t.jsx("path",{className:"ui-chart-line","data-series":m,d:f},m):null),u.targetY!==null?t.jsx("line",{className:"ui-chart-target","data-testid":"chart-target",x1:c.left,x2:c.width-c.right,y1:u.targetY,y2:u.targetY}):null,u.xLabels.map(f=>t.jsx("text",{x:f.x,y:c.height-6,textAnchor:o?"middle":u.xLabels.length>1&&f.index===0?"start":f.index===e.length-1&&e.length>1?"end":"middle",children:i(e[f.index])},f.index))]}),t.jsx("figcaption",{className:"sr-only",children:d}),n.length>1?t.jsx("ul",{className:"ui-chart-legend","aria-hidden":"true",children:n.map((f,m)=>t.jsx("li",{"data-series":m,"data-type":o?f.type??"line":void 0,children:f.label},f.label))}):null]})}function Us(e){return Math.round(e*10)/10}const Ry="(max-width: 900px)";function ws(e){const[n,s]=h.useState(()=>{try{return window.matchMedia(e).matches}catch{return!1}});return h.useEffect(()=>{var i;let r;try{r=window.matchMedia(e)}catch{return}const a=l=>s(l.matches);return(i=r.addEventListener)==null||i.call(r,"change",a),()=>{var l;return(l=r.removeEventListener)==null?void 0:l.call(r,"change",a)}},[e]),n}function ai(...e){return e.filter(Boolean).join(" ")}function A({variant:e,size:n,className:s,type:r="button",...a}){return t.jsx("button",{type:r,className:ai("ui-btn",s),"data-variant":e&&e!=="default"?e:void 0,"data-size":n,...a})}function ht({variant:e,size:n,className:s,...r}){return t.jsx("a",{className:ai("ui-btn",s),"data-variant":e&&e!=="default"?e:void 0,"data-size":n,...r})}function R$({checked:e,onChange:n,label:s,disabled:r}){return t.jsxs("label",{className:"ui-switch","data-disabled":r?"true":void 0,children:[t.jsx("input",{type:"checkbox",role:"switch",checked:e,disabled:r,"aria-label":s,onChange:a=>n(a.target.checked)}),t.jsx("i",{"aria-hidden":"true"})]})}function te({children:e,align:n,valign:s,className:r}){return t.jsx("div",{className:ai("ui-toolbar",r),"data-align":n,"data-valign":s,children:e})}function et(){return t.jsx("span",{className:"ui-toolbar-spacer"})}function re({label:e,hint:n,inline:s,grow:r,wide:a,group:i,action:l,after:o,children:c}){const u=h.useId();return t.jsxs("div",{className:"ui-field","data-inline":s?"true":void 0,"data-grow":r?"true":void 0,"data-wide":a?"true":void 0,children:[l?t.jsxs("div",{className:"ui-field-row",children:[t.jsxs("label",{className:"ui-field-control",children:[t.jsx("span",{className:"ui-field-label",children:e}),c]}),l]}):i?t.jsxs("div",{className:"ui-field-control",role:"group","aria-labelledby":u,children:[t.jsx("span",{className:"ui-field-label",id:u,children:e}),c]}):t.jsxs("label",{className:"ui-field-control",children:[t.jsx("span",{className:"ui-field-label",children:e}),c]}),n?t.jsx("span",{className:"ui-field-hint",children:n}):null,o]})}function Ns({children:e,dense:n,columns:s}){return t.jsx("div",{className:"ui-formgrid","data-dense":n?"true":void 0,"data-columns":s===3?"3":void 0,children:e})}function Ee({tone:e,mono:n,dot:s,children:r,className:a,title:i}){return t.jsxs("span",{className:ai("ui-pill",n&&"mono",a),"data-tone":e,title:i,children:[s?t.jsx("span",{className:"ui-pill-dot","aria-hidden":"true"}):null,r]})}function Jl({children:e}){return t.jsx("span",{className:"ui-tag",children:e})}function Nu({state:e}){const n=e==="succeeded"||e==="approved"||e==="fired"||e==="running"||e==="leased"?"good":e==="failed"||e==="rejected"||e==="unknown"||e==="error"||e==="refused"?"critical":e==="pending"||e==="suspended"||e==="expired"||e==="paused"?"warning":void 0;return t.jsx(Ee,{tone:n,children:e})}function G({tone:e,title:n,children:s,role:r,action:a}){return a?t.jsx("div",{className:"ui-notice","data-tone":e,role:r,children:t.jsxs("div",{className:"ui-notice-row",children:[t.jsxs("div",{className:"ui-notice-body",children:[n?t.jsx("div",{className:"ui-notice-title",children:n}):null,s]}),a]})}):t.jsxs("div",{className:"ui-notice","data-tone":e,role:r,children:[n?t.jsx("div",{className:"ui-notice-title",children:n}):null,s]})}function ne({message:e}){return e?t.jsx(G,{tone:"critical",role:"alert",children:e}):null}function ve({mascot:e,warm:n,title:s,action:r,children:a}){return n||s?t.jsxs("div",{className:"ui-empty","data-warm":n?"true":void 0,children:[s?t.jsx("div",{className:"ui-empty-title",children:s}):null,t.jsx("div",{children:a}),r]}):e?t.jsxs("div",{className:"ui-empty","data-mascot":"true",children:[t.jsx(y$,{size:"sm"}),t.jsx("p",{children:a})]}):t.jsx("p",{className:"ui-empty",children:a})}function Jn({icon:e,title:n,action:s,children:r}){return t.jsxs("div",{className:"ui-empty-state",children:[e?t.jsx("span",{className:"ui-empty-state-icon",children:typeof e=="string"?t.jsx(le,{name:e}):e}):null,t.jsx("div",{className:"ui-empty-state-title",children:n}),r?t.jsx("p",{className:"ui-empty-state-line",children:r}):null,s?t.jsx("div",{className:"ui-empty-state-action",children:s}):null]})}function Iy({children:e}){return t.jsx("div",{className:"ui-page",children:e})}function Ql({title:e,lede:n,actions:s,before:r}){return t.jsxs("header",{className:"ui-page-head",children:[t.jsxs("div",{className:"ui-page-head-row",children:[t.jsxs("h2",{className:"ui-page-title",children:[r,t.jsx("span",{children:e})]}),s?t.jsx("div",{className:"ui-page-actions",children:s}):null]}),n?t.jsx("p",{className:"ui-page-lede",children:n}):null]})}function Zn({embedded:e,title:n,lede:s,actions:r,children:a}){return e?t.jsxs("div",{className:"ui-stack","data-gap":"lg",children:[r?t.jsx("div",{className:"ui-toolbar","data-align":"end",children:r}):null,a]}):t.jsxs(Iy,{children:[t.jsx(Ql,{title:n,lede:s,actions:r}),a]})}function ue({title:e,aside:n,actions:s,panel:r,flush:a,foot:i,children:l}){const o=e||n||s?t.jsxs("div",{className:"ui-section-head",children:[e?t.jsx("h3",{className:"ui-section-title",children:e}):t.jsx("span",{}),n||s?t.jsxs("div",{className:"ui-section-side",children:[n?t.jsx("span",{className:"ui-section-aside",children:n}):null,s?t.jsx("div",{className:"ui-section-actions",children:s}):null]}):null]}):null;return t.jsxs("section",{className:"ui-section","data-panel":r?"true":void 0,children:[o,r?t.jsxs("div",{className:"ui-panel","data-flush":a?"true":void 0,children:[l,i?t.jsx("div",{className:"ui-panel-foot",children:i}):null]}):t.jsxs(t.Fragment,{children:[l,i?t.jsx("div",{className:"ui-toolbar","data-align":"end",children:i}):null]})]})}function Ye({title:e,tool:n,actions:s,flush:r,children:a}){return t.jsxs("section",{className:"ui-panel","data-flush":r?"true":void 0,children:[e||n||s?t.jsxs("header",{className:"ui-panel-head",children:[e?t.jsx("h3",{className:"ui-panel-title",children:e}):t.jsx("span",{}),n?t.jsx("span",{className:"ui-panel-tool",children:n}):null,s?t.jsx("div",{className:"ui-panel-actions",children:s}):null]}):null,a]})}function Ts({tone:e,title:n,meta:s,actions:r,children:a,foot:i,onClick:l,label:o,as:c="div"}){const u=l?{"data-interactive":"true",tabIndex:0,"aria-label":o,onClick:l,onKeyDown:d=>{d.target!==d.currentTarget||d.key!=="Enter"&&d.key!==" "||(d.preventDefault(),l())}}:{};return t.jsxs(c,{className:"ui-card","data-tone":e,...u,children:[n||s||r?t.jsxs("div",{className:"ui-card-head",children:[n?t.jsx("h3",{className:"ui-card-title",children:n}):null,s,r?t.jsx("div",{className:"ui-card-actions",children:r}):null]}):null,a,i?t.jsx("div",{className:"ui-card-foot",children:i}):null]})}function ie({gap:e,divided:n,children:s}){return t.jsx("div",{className:"ui-stack","data-gap":e,"data-divided":n?"true":void 0,children:s})}function b6({children:e}){return t.jsx("div",{className:"ui-row",children:e})}function tm({inline:e,children:n}){return t.jsx("div",{className:"ui-stats","data-inline":e?"true":void 0,children:n})}function Er({label:e,value:n,note:s,tone:r,size:a}){return t.jsxs("div",{className:"ui-stat",children:[t.jsx("div",{className:"ui-stat-k",children:e}),t.jsx("div",{className:"ui-stat-v","data-tone":r,"data-size":a,children:n}),s?t.jsx("div",{className:"ui-stat-n",children:s}):null]})}function qt({items:e}){return t.jsx("dl",{className:"ui-kv",children:e.map((n,s)=>t.jsxs("div",{className:"contents",children:[t.jsx("dt",{children:n.label}),t.jsx("dd",{children:n.value})]},n.key??s))})}function Kr({children:e}){return t.jsx("div",{className:"ui-table-wrap",children:t.jsx("table",{className:"ui-table",children:e})})}function Py({value:e,label:n}){const s=Math.max(0,Math.min(100,Math.round(Number.isFinite(e)?e:0)));return t.jsx("div",{className:"ui-progress",role:"progressbar","aria-label":n,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":s,"aria-valuetext":`${s}%`,children:t.jsx("div",{className:"ui-progress-fill",style:{inlineSize:`${s}%`}})})}function Dt({children:e,label:n}){return t.jsx("pre",{className:"ui-code","aria-label":n,children:e})}function Ot({summary:e,boxed:n,open:s,className:r,onToggle:a,children:i}){return t.jsxs("details",{className:ai("ui-details",r),"data-boxed":n?"true":void 0,open:s,onToggle:a?l=>a(l.currentTarget.open):void 0,children:[t.jsx("summary",{children:e}),i]})}function Ge({title:e,onClose:n,size:s,foot:r,children:a}){return t.jsx(Jf,{open:!0,onOpenChange:i=>{i||n()},children:t.jsxs(Qf,{children:[t.jsx($y,{className:"ui-sheet-overlay"}),t.jsxs(Xf,{className:"ui-sheet","data-size":s,"aria-describedby":void 0,children:[t.jsxs("div",{className:"ui-sheet-head",children:[t.jsx(Zf,{className:"ui-sheet-title",children:e}),t.jsx(Ty,{asChild:!0,children:t.jsx(A,{size:"sm",children:"Close"})})]}),a,r?t.jsx("div",{className:"ui-sheet-foot",children:r}):null]})]})})}function zt({title:e,onClose:n,foot:s,children:r}){return t.jsx(Jf,{open:!0,onOpenChange:a=>{a||n()},children:t.jsxs(Qf,{children:[t.jsx($y,{className:"ui-sheet-overlay","data-layer":"modal"}),t.jsxs(Xf,{className:"ui-modal",role:"alertdialog","aria-describedby":void 0,children:[t.jsx(Zf,{className:"ui-modal-title",children:e}),r,s?t.jsx("div",{className:"ui-modal-foot",children:s}):null]})]})})}function Rs({label:e,items:n,note:s,trigger:r,sheet:a,stacked:i}){const l=ws(k6);return a&&l&&!r?t.jsx(N6,{label:e,items:n,title:a.title,sub:a.sub}):t.jsx(S6,{label:e,items:n,note:s,trigger:r,stacked:i})}const k6="(max-width: 720px)";function N6({label:e,items:n,title:s,sub:r}){const[a,i]=h.useState(!1);return t.jsxs(Jf,{open:a,onOpenChange:i,children:[t.jsx(c6,{asChild:!0,children:t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":e,title:e,onClick:l=>l.stopPropagation(),children:t.jsx(le,{name:"more"})})}),t.jsxs(Qf,{children:[t.jsx($y,{className:"ui-sheet-overlay",onClick:l=>l.stopPropagation()}),t.jsxs(Xf,{className:"ui-action-sheet","aria-describedby":void 0,onClick:l=>l.stopPropagation(),children:[t.jsxs("div",{className:"ui-action-sheet-head",children:[t.jsx(Zf,{className:"ui-action-sheet-title",children:s}),r?t.jsx("span",{className:"ui-action-sheet-sub",children:r}):null]}),t.jsx("div",{className:"ui-menu ui-action-sheet-list",role:"menu",children:n.map((l,o)=>l?l==="separator"?t.jsx("div",{className:"ui-menu-sep",role:"separator"},`sep-${o}`):"heading"in l?t.jsx("div",{className:"ui-menu-label",children:l.heading},`head-${o}`):t.jsxs("button",{type:"button",role:"menuitem",className:"ui-menu-item","data-tone":l.tone,onClick:()=>{i(!1),l.onSelect()},children:[t.jsx("span",{children:l.label}),l.hint?t.jsx("span",{className:"ui-menu-item-hint",children:l.hint}):null]},o):null)}),t.jsx(Ty,{asChild:!0,children:t.jsx(A,{className:"ui-action-sheet-cancel",children:"Cancel"})})]})]})]})}function S6({label:e,items:n,note:s,trigger:r,stacked:a}){const i=o=>o.stopPropagation(),l=h.useRef(!1);return t.jsxs(ju,{modal:!1,onOpenChange:o=>{o&&(l.current=!1)},children:[t.jsx(yu,{asChild:!0,children:r??t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":e,title:e,onClick:i,children:t.jsx(le,{name:"more"})})}),t.jsx(xo,{children:t.jsxs(wu,{className:"ui-menu","data-stacked":a?"true":void 0,align:"end",sideOffset:4,onClick:i,onKeyDown:i,onCloseAutoFocus:o=>{l.current&&o.preventDefault()},children:[s?t.jsx(Di,{className:"ui-menu-label",children:s}):null,n.map((o,c)=>o?o==="separator"?t.jsx(ra,{className:"ui-menu-sep"},`sep-${c}`):"heading"in o?t.jsx(Di,{className:"ui-menu-label",children:o.heading},`head-${c}`):t.jsxs(zs,{className:"ui-menu-item","data-tone":o.tone,onSelect:()=>{l.current=!0,o.onSelect()},children:[t.jsx("span",{children:o.label}),o.hint?t.jsx("span",{className:"ui-menu-item-hint",children:o.hint}):null]},c):null)]})})]})}function C6({title:e,actions:n,onClose:s,onCloseAutoFocus:r,onOpenAutoFocus:a,label:i,children:l}){return t.jsx(Jf,{open:!0,modal:!1,onOpenChange:o=>{o||s()},children:t.jsx(Qf,{children:t.jsxs(Xf,{className:"ui-dock","aria-describedby":void 0,...i?{"aria-label":i}:{},onInteractOutside:o=>o.preventDefault(),...r?{onCloseAutoFocus:r}:{},...a?{onOpenAutoFocus:a}:{},children:[t.jsxs("div",{className:"ui-dock-head",children:[t.jsx(Zf,{className:"ui-dock-title",children:e}),t.jsxs("div",{className:"ui-dock-actions",children:[n,t.jsx(Ty,{asChild:!0,children:t.jsx(A,{size:"sm",variant:"ghost",children:"Close"})})]})]}),t.jsx("div",{className:"ui-dock-body",children:l})]})})})}function yo({level:e,label:n,children:s}){return t.jsx("nav",{className:"ui-tabs","data-level":e,"aria-label":n,children:s})}function Li({href:e,active:n,count:s,onClick:r,children:a}){return t.jsxs("a",{className:"ui-tab",href:e,"aria-current":n?"page":void 0,onClick:r,children:[a,s?t.jsx("span",{className:"ui-count",children:s}):null]})}function ln({label:e,options:n,value:s,onChange:r}){return t.jsx("div",{className:"ui-segment",role:"radiogroup","aria-label":e,children:n.map(a=>t.jsx("button",{type:"button",role:"radio",className:"ui-tab","aria-checked":a.value===s,onClick:()=>r(a.value),children:a.label},a.value))})}function at({children:e}){return t.jsx("div",{className:"ui-list",children:e})}function Xe({href:e,onClick:n,lead:s,title:r,sub:a,side:i,dimmed:l,label:o}){const c=t.jsxs(t.Fragment,{children:[s,t.jsxs("span",{className:"ui-list-main",children:[t.jsx("span",{className:"ui-list-title",children:r}),a?t.jsx("span",{className:"ui-list-sub",children:a}):null]}),i?t.jsx("span",{className:"ui-list-side",children:i}):null]}),u=l?"true":void 0;return e?t.jsx("a",{className:"ui-list-row","data-dimmed":u,href:e,onClick:n?d=>{d.preventDefault(),n()}:void 0,children:c}):n?t.jsx("div",{className:"ui-list-row","data-interactive":"true","data-dimmed":u,tabIndex:0,"aria-label":o,onClick:n,onKeyDown:d=>{d.target!==d.currentTarget||d.key!=="Enter"&&d.key!==" "||(d.preventDefault(),n())},children:c}):t.jsx("div",{className:"ui-list-row","data-dimmed":u,children:c})}function I$({href:e,onClick:n,current:s,lead:r,title:a,meta:i,sub:l,snippet:o,side:c}){return t.jsxs("a",{className:"ui-pick",href:e,"aria-current":s?"true":void 0,onClick:n?u=>{u.preventDefault(),n()}:void 0,children:[r?t.jsx("span",{className:"ui-pick-lead",children:r}):null,t.jsxs("span",{className:"ui-pick-main",children:[t.jsxs("span",{className:"ui-pick-top",children:[t.jsx("span",{className:"ui-pick-title",children:a}),i?t.jsx("span",{className:"ui-pick-meta",children:i}):null]}),l||c?t.jsxs("span",{className:"ui-pick-line",children:[l?t.jsx("span",{className:"ui-pick-sub",children:l}):null,c?t.jsx("span",{className:"ui-pick-side",children:c}):null]}):null,o?t.jsx("span",{className:"ui-pick-snippet",children:o}):null]})]})}function P$({list:e,detail:n,empty:s,label:r,className:a}){return t.jsxs("div",{className:ai("ui-split",a),"data-open":n?"true":void 0,children:[t.jsx("section",{className:"ui-split-list","aria-label":r,children:e}),t.jsx("section",{className:"ui-split-detail","data-empty":n?void 0:"true",children:n??t.jsx("p",{className:"ui-empty ui-split-empty",children:s})})]})}function Rh({children:e,onRemove:n,label:s,disabled:r}){return t.jsxs("span",{className:"ui-chip",children:[e,t.jsx("button",{type:"button",className:"ui-chip-x","aria-label":`Remove ${s}`,onClick:n,disabled:r,children:"×"})]})}const E6=8;function A6({label:e,options:n,value:s,onChange:r,max:a,disabled:i,id:l}){const[o,c]=h.useState(!1),[u,d]=h.useState(""),[f,m]=h.useState(0),p=h.useRef(null),g=h.useRef(null),v=h.useRef(null),b=h.useRef(null),j=h.useId(),x=$=>{var L;return((L=n.find(O=>O.value===$))==null?void 0:L.label)??$},y=a!==void 0&&s.length>=a,w=n.filter($=>!s.includes($.value)),k=n.length>E6,N=u.trim().toLowerCase(),S=N===""?w:w.filter($=>$.label.toLowerCase().includes(N)),C=Math.min(f,Math.max(0,S.length-1)),E=$=>{var L;c(!1),d(""),m(0),$&&((L=g.current)==null||L.focus())};h.useEffect(()=>{var L;if(!o)return;(L=k?v.current:b.current)==null||L.focus();const $=O=>{p.current&&!p.current.contains(O.target)&&E(!1)};return document.addEventListener("mousedown",$),()=>document.removeEventListener("mousedown",$)},[o,k]);const T=$=>{const L=[...s,$];r(L),d(""),m(0);const O=a!==void 0&&L.length>=a;(O||L.length>=n.length)&&E(!O)},I=$=>{if($.key==="Escape")$.preventDefault(),E(!0);else if($.key==="ArrowDown")$.preventDefault(),m(S.length===0?0:(C+1)%S.length);else if($.key==="ArrowUp")$.preventDefault(),m(S.length===0?0:(C-1+S.length)%S.length);else if($.key==="Enter"){$.preventDefault();const L=S[C];L&&T(L.value)}else $.key==="Backspace"&&u===""&&s.length>0&&($.preventDefault(),r(s.slice(0,-1)))},F=$=>`${j}-${$}`,D=o&&S.length>0?F(C):void 0;return t.jsxs("div",{className:"ui-chippicker",ref:p,id:l,children:[s.map($=>t.jsx(Rh,{label:x($),disabled:i,onRemove:()=>r(s.filter(L=>L!==$)),children:x($)},$)),t.jsxs("div",{className:"ui-chippicker-add",children:[t.jsx("button",{ref:g,type:"button",className:"ui-btn","data-size":"sm","data-variant":"ghost","aria-haspopup":"listbox","aria-expanded":o,"aria-controls":o?j:void 0,disabled:i||y||w.length===0,onClick:()=>o?E(!1):c(!0),children:"Add…"}),o?t.jsxs("div",{className:"ui-menu ui-chippicker-menu",onKeyDown:I,children:[k?t.jsx("input",{ref:v,type:"search",className:"ui-chippicker-filter","aria-label":`Filter ${e}`,"aria-controls":j,"aria-activedescendant":D,value:u,onChange:$=>{d($.target.value),m(0)}}):null,t.jsxs("div",{ref:b,id:j,role:"listbox","aria-multiselectable":"true","aria-label":e,"aria-activedescendant":k?void 0:D,tabIndex:k?-1:0,className:"ui-chippicker-list",children:[S.map(($,L)=>t.jsx("div",{id:F(L),role:"option","aria-selected":"false",className:"ui-menu-item","data-highlighted":L===C?"":void 0,onMouseEnter:()=>m(L),onMouseDown:O=>O.preventDefault(),onClick:()=>T($.value),children:$.label},$.value)),S.length===0?t.jsx("p",{className:"ui-menu-empty",children:"Nothing matches"}):null]})]}):null]})]})}function M$({label:e,options:n,value:s,onChange:r}){return t.jsx("div",{className:"ui-filter-chips",role:"group","aria-label":e,children:n.map(a=>t.jsx("button",{type:"button",className:"ui-btn ui-filter-chip","data-size":"sm","aria-pressed":a.value===s,onClick:()=>r(a.value),children:a.label},a.value))})}function nm({label:e,value:n,onChange:s,placeholder:r,grow:a}){return t.jsx("span",{className:"ui-search","data-grow":a?"true":void 0,children:t.jsx("input",{type:"search","aria-label":e,value:n,placeholder:r,onChange:i=>s(i.target.value)})})}function Un({svg:e,icon:n="plug",letter:s,size:r}){return t.jsx("span",{className:"ui-app-icon","data-size":r,"data-tone":e||s?"accent":void 0,"aria-hidden":"true",children:e?t.jsx("span",{className:"ui-app-icon-svg",dangerouslySetInnerHTML:{__html:e}}):s?t.jsx("span",{className:"ui-app-icon-letter",children:s}):t.jsx(le,{name:n})})}function Ih({items:e,label:n="Where this is",inline:s}){const r=e.map((a,i)=>{const l=a.key??String(i);if(a.current)return t.jsx("span",{className:"ui-crumb","aria-current":"page",children:a.label},l);const o=a.href?t.jsx("a",{className:"ui-crumb",href:a.href,onClick:a.onClick?c=>{var u;c.preventDefault(),(u=a.onClick)==null||u.call(a)}:void 0,children:a.label}):t.jsx("button",{type:"button",className:"ui-crumb",onClick:a.onClick,children:a.label});return t.jsxs("span",{className:"ui-crumb-step",children:[o,t.jsx(le,{name:"chevron-right",size:12})]},l)});return s?t.jsx("span",{className:"ui-crumbs","aria-label":n,children:r}):t.jsx("nav",{className:"ui-crumbs","aria-label":n,children:r})}function D$({main:e,filters:n,filtersOpen:s,onToggleFilters:r,active:a,chips:i,actions:l,onSubmit:o,label:c}){return t.jsxs("form",{className:"ui-panel ui-searchbar",role:"search","aria-label":c,onSubmit:u=>{u.preventDefault(),o()},children:[t.jsxs("div",{className:"ui-searchbar-row",children:[e?t.jsx("div",{className:"ui-searchbar-main",children:e}):null,n&&r?t.jsxs(A,{"aria-expanded":s===!0,"aria-pressed":s===!0,onClick:r,children:["Filters",a?t.jsx("span",{className:"ui-count",children:a}):null]}):null,!r&&n?t.jsx("div",{className:"ui-searchbar-inline",children:n}):null,l?t.jsx("div",{className:"ui-searchbar-actions",children:l}):null]}),n&&r&&s?t.jsx("div",{className:"ui-searchbar-filters",children:n}):null,i?t.jsx("div",{className:"ui-searchbar-chips",children:i}):null]})}function Qc({size:e}){return t.jsx("span",{className:"ui-mark","data-size":e,"aria-hidden":"true",children:"b"})}function O$({quiet:e,still:n,className:s,children:r}){return t.jsx("div",{className:ai("ui-fieldbg",s),"data-quiet":e?"true":void 0,"data-still":n?"true":void 0,children:r})}function $6({dock:e,className:n,children:s}){return t.jsxs("div",{className:ai("ui-float",n),children:[t.jsx("div",{className:"ui-float-body",children:s}),e?t.jsx("div",{className:"ui-float-dock",children:e}):null]})}function T6(e){const n={};for(const s of e??[])n[s.key]=s.default;return n}function My(e){const[n,s]=h.useState({}),r=e??[],a={...T6(r),...n};return r.length===0?{values:void 0,controls:null}:{values:a,controls:t.jsx("div",{className:"ui-choices",children:r.map(i=>t.jsx(re,{label:i.label,inline:!0,children:t.jsx("select",{value:a[i.key],onChange:l=>s(o=>({...o,[i.key]:l.target.value})),children:i.options.map(l=>t.jsx("option",{value:l,children:l},l))})},i.key))})}}function R6({props:e,timezone:n="UTC",onDecided:s}){var y;const[r,a]=h.useState(null),[i,l]=h.useState(null),[o,c]=h.useState(!1),[u,d]=h.useState(null);h.useEffect(()=>{let w=!1;return a(null),l(null),R.approval(e.approvalId).then(k=>{w||a(k)}).catch(k=>{w||l(k instanceof xe?k.message:String(k))}),()=>{w=!0}},[e.approvalId]);const{values:f,controls:m}=My(r==null?void 0:r.choices),p=(w,k)=>{d(w),l(null),(f&&w==="approve"?R.decide(e.approvalId,w,k,f):R.decide(e.approvalId,w,k)).then(N=>{a(N.action),s==null||s(N.action)}).catch(N=>l(N instanceof xe?N.message:String(N))).finally(()=>d(null))};if(i&&!r)return t.jsx("p",{className:"wb-empty",children:i});if(!r)return t.jsx("p",{className:"wb-empty",children:"Loading the envelope…"});const g=r.state==="pending",v=(y=r.permissionScopes)==null?void 0:y.includes("always"),b=I6(r),j=(r.preview??"").split(`
103
- `).length>12||(r.preview??"").length>900,x=[r.decidedBy?`by ${r.decidedBy}`:"",r.decidedVia?`via ${r.decidedVia}`:""].filter(Boolean).join(" ");return t.jsxs("div",{className:"wb-envelope",children:[t.jsxs("div",{className:"envelope",children:[t.jsxs("dl",{className:"envelope-head",children:[t.jsx("dt",{children:"Action"}),t.jsx("dd",{className:"wb-envelope-action",children:r.tool.split(".").map(w=>_n(w)).join(" · ")}),t.jsx("dt",{children:"Status"}),t.jsxs("dd",{children:[g?t.jsx(Ee,{tone:"warning",dot:!0,children:"waiting for you"}):t.jsx(Nu,{state:r.state}),!g&&x?t.jsxs("span",{className:"wb-envelope-note",children:[" ",x]}):null]}),t.jsx("dt",{children:g?"Expires":"Decided"}),t.jsx("dd",{children:ct(g?r.expiresAt:r.decidedAt,n)})]}),t.jsxs("div",{className:"envelope-body","data-clamp":j&&!o?"true":void 0,children:[r.preview||"(this tool wrote no preview)",j&&!o?t.jsx("button",{type:"button",className:"wb-doc-more",onClick:()=>c(!0),children:"Show the whole preview"}):null]})]}),t.jsx(ne,{message:i}),g?m:null,g?t.jsxs("div",{className:"wb-envelope-decide",children:[t.jsx("p",{className:"wb-envelope-note",children:v?"Auto and Always also approve later calls to this tool in that scope; you can take it back on the agent's Tools tab.":"This runs the action exactly as shown above."}),t.jsxs("div",{className:"wb-envelope-buttons",children:[t.jsx("button",{className:"ui-btn","data-variant":"danger",disabled:u!==null,onClick:()=>p("reject"),children:u==="reject"?"Rejecting…":"Reject"}),v?t.jsxs(t.Fragment,{children:[t.jsx("button",{className:"ui-btn",disabled:u!==null,onClick:()=>p("approve","conversation"),children:"Auto: this conversation"}),t.jsx("button",{className:"ui-btn",disabled:u!==null,onClick:()=>p("approve","always"),children:"Always: this agent"})]}):null,t.jsx("button",{className:"ui-btn","data-variant":"good",disabled:u!==null,onClick:()=>p("approve"),children:u==="approve"?"Approving…":v?"Allow once":"Approve"})]})]}):null,t.jsxs("details",{className:"ui-details",children:[t.jsx("summary",{children:"The envelope, field by field"}),t.jsx("dl",{className:"ui-kv wb-envelope-fields",children:b.map(w=>t.jsxs("div",{className:"contents",children:[t.jsx("dt",{children:w.label}),w.block?t.jsx("dd",{className:"wb-envelope-block",children:t.jsx("pre",{className:"mono",children:w.value})}):t.jsx("dd",{className:w.mono?"mono":void 0,children:w.value})]},w.label))})]})]})}function I6(e){const n=[],s=e.envelope;if(s!==null&&typeof s=="object"&&!Array.isArray(s))for(const[a,i]of Object.entries(s))n.push(A0(_n(a),i));else s!=null&&n.push({label:"Envelope",value:Dy(s)});const r=e.canonicalArgs;if(r!==null&&typeof r=="object"&&!Array.isArray(r))for(const[a,i]of Object.entries(r)){const l=`Argument · ${_n(a)}`;n.some(o=>o.label===l)||n.push(A0(l,i))}return n.push({label:"Action id",value:e.id,mono:!0},{label:"Tool version",value:e.toolVersion,mono:!0},{label:"Agent",value:e.agentId,mono:!0},{label:"Args hash",value:e.argsHash,mono:!0},{label:"Policy version",value:String(e.policyVersion)}),e.conversationId&&n.push({label:"Conversation",value:e.conversationId,mono:!0}),e.jobId&&n.push({label:"Job",value:e.jobId,mono:!0}),n}function A0(e,n){return n!==null&&typeof n=="object"&&(!Array.isArray(n)||n.some(r=>r!==null&&typeof r=="object"))?{label:e,value:JSON.stringify(n,null,2),block:!0}:{label:e,value:Dy(n)}}function Dy(e){return e==null?"—":Array.isArray(e)?e.map(n=>Dy(n)).join(", ")||"—":typeof e=="object"?JSON.stringify(e):pn(e,"text",null)}const P6=new Set(["image/png","image/jpeg","image/gif","image/webp"]),M6=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function Ph(e){const n=e!==null&&typeof e=="object"?e.artifacts:null;return Array.isArray(n)?n.flatMap(s=>{if(s===null||typeof s!="object")return[];const r=s;return typeof r.id!="string"||!M6.test(r.id)?[]:[{type:"attachment",artifactId:r.id,filename:typeof r.filename=="string"?r.filename:null,mime:typeof r.mime=="string"?r.mime:"application/octet-stream",kind:typeof r.kind=="string"?r.kind:"other",sizeBytes:null}]}):[]}function Oy(e){return P6.has(e.toLowerCase())}function _r(e){return`/api/artifacts/${encodeURIComponent(e)}/preview`}function Ya(e){return`/api/artifacts/${encodeURIComponent(e)}/download`}function ds(e){return e==null||!Number.isFinite(e)?"":e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(e<10*1024?1:0)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function Ly(e,n){const s=e.toLowerCase(),r=(n??"").toLowerCase().split(".").pop()??"";return s.startsWith("image/")?"image":s==="application/pdf"?"pdf":s.startsWith("audio/")?"audio":s.startsWith("video/")?"video":s==="text/csv"||s==="text/tab-separated-values"||s.includes("spreadsheet")||s.includes("excel")||["csv","tsv","xls","xlsx","numbers"].includes(r)?"table":s.includes("zip")||s.includes("tar")||s.includes("compressed")||["zip","gz","tgz","rar","7z"].includes(r)?"archive":s==="application/json"||s.includes("javascript")||s.includes("xml")||["ts","tsx","js","py","rb","go","rs","swift","json","yaml","yml","toml","sh","sql","html","css"].includes(r)?"code":s.startsWith("text/")||["md","txt","rtf","doc","docx"].includes(r)?"text":"file"}const Ci={image:"Image",pdf:"PDF",table:"Spreadsheet",text:"Document",code:"Code",audio:"Audio",video:"Video",archive:"Archive",file:"File"};function Wd(e){return`artifact:${e}`}function D6(e){const n=Ly(e.mime,e.filename);return{id:Wd(e.artifactId),tool:Ci[n],title:e.filename??"Untitled file",renderer:"artifact",props:{attachment:e},at:null,source:"artifact",substantial:!1}}function O6({props:e}){const n=b$(e.artifactId),[s,r]=h.useState(null),[a,i]=h.useState(null),[l,o]=h.useState(!1);if(h.useEffect(()=>{if(n===null)return;let d=!0;return r(null),i(null),o(!1),R.libraryEntry(n).then(f=>{d&&r({filename:f.entry.filename,sizeBytes:f.entry.sizeBytes})}).catch(()=>{}),()=>{d=!1}},[n]),n===null)return t.jsx("p",{className:"wb-empty",children:"This result names no file in the Files library."});const c=e.title??(s==null?void 0:s.filename)??"Image",u=[a?`${a.width} × ${a.height}`:null,s!=null&&s.sizeBytes?ds(s.sizeBytes):null].filter(d=>d!==null);return t.jsxs("figure",{className:"wb-image",children:[t.jsx("div",{className:"wb-image-frame",children:l?t.jsx("p",{className:"wb-empty",children:"This file cannot be shown here. Download it to open it."}):t.jsx("a",{href:_r(n),className:"wb-image-link",title:"Open at full size",children:t.jsx("img",{src:_r(n),alt:e.caption??c,onLoad:d=>{const f=d.currentTarget;f.naturalWidth>0&&i({width:f.naturalWidth,height:f.naturalHeight})},onError:()=>o(!0)})})}),t.jsxs("figcaption",{className:"wb-image-caption",children:[t.jsxs(te,{children:[t.jsx("span",{className:"wb-image-name",children:c}),u.length>0?t.jsx("span",{className:"wb-image-facts",children:u.join(" · ")}):null,t.jsx("span",{className:"ui-toolbar-spacer"}),t.jsx(ht,{size:"sm",href:Ya(n),download:(s==null?void 0:s.filename)??c,children:"Download"})]}),e.caption&&e.captionLabel?t.jsx(Ot,{summary:e.captionLabel,className:"wb-image-note",children:t.jsx("p",{className:"wb-image-note-body",children:e.caption})}):e.caption?t.jsx("p",{className:"wb-image-note",children:e.caption}):null]})]})}function L6({props:e}){return e.pairs.length===0?t.jsx("p",{className:"wb-empty",children:"Nothing to show."}):t.jsx("dl",{className:"ui-kv",children:e.pairs.map(n=>t.jsxs("div",{className:"contents",children:[t.jsx("dt",{children:n.label}),t.jsx("dd",{className:"tnum",style:n.tone==="neutral"?void 0:{color:`var(--${n.tone})`},children:pn(n.value,n.unit,n.currency)})]},n.label))})}const F6=8;function L$({text:e,label:n="Output",className:s}){const r=h.useRef(null),a=h.useRef(!0);return h.useLayoutEffect(()=>{const i=r.current;i&&a.current&&(i.scrollTop=i.scrollHeight)},[e]),t.jsx("pre",{ref:r,className:s?`wb-terminal-body ${s}`:"wb-terminal-body","aria-label":n,tabIndex:0,onScroll:i=>{const l=i.currentTarget;a.current=l.scrollHeight-l.scrollTop-l.clientHeight<=F6},children:e})}function _6(e){if(e<1e3)return`${Math.round(e)} ms`;const n=e/1e3;if(n<60)return`${n.toFixed(n<10?1:0)} s`;const s=Math.floor(n/60);return`${s} min ${Math.round(n-s*60)} s`}function z6({text:e}){const[n,s]=h.useState("");return t.jsxs(t.Fragment,{children:[n?t.jsx("span",{role:"status",className:"wb-hint",children:n}):null,t.jsx(A,{size:"sm",onClick:()=>{var r;if(s(""),!((r=navigator.clipboard)!=null&&r.writeText)){s("Copy unavailable; select the text to copy.");return}navigator.clipboard.writeText(e).then(()=>s("Copied"),()=>s("Copy failed; select the text to copy."))},children:"Copy"})]})}function U6({props:e}){const n=e.output??"";return t.jsxs("div",{className:"wb-terminal",children:[t.jsxs(te,{className:"wb-terminal-head",children:[e.command!==null?t.jsx("code",{className:"wb-terminal-command",title:e.command,children:e.command}):null,e.exitCode!==null?t.jsxs(Ee,{tone:e.exitCode===0?"good":"critical",mono:!0,children:["exit ",e.exitCode]}):null,e.elapsedMs!==null?t.jsx("span",{className:"wb-terminal-fact",children:_6(e.elapsedMs)}):null,t.jsx("span",{className:"ui-toolbar-spacer"}),n!==""?t.jsx(z6,{text:n}):null]}),e.omittedBytes!==null?t.jsxs("p",{className:"wb-terminal-note",children:["First ",ds(e.omittedBytes)," not shown."]}):null,n!==""?t.jsx(L$,{text:n}):t.jsx("p",{className:"wb-empty",children:"No output."}),e.metadata.length>0?t.jsx("dl",{className:"ui-kv wb-terminal-facts",children:e.metadata.map(s=>t.jsxs("div",{className:"contents",children:[t.jsx("dt",{children:s.label}),t.jsx("dd",{children:pn(s.value,s.unit,null)})]},s.label))}):null]})}function B6(){const e=window.location.hostname.replace(/^\[|\]$/g,"").toLowerCase();return e==="127.0.0.1"||e==="::1"||e==="localhost"}function $0(e){try{const n=new URL(e);return n.searchParams.delete("ticket"),n.toString()}catch{return e}}function W6(e){const n=new Set(e.ports??[]);return e.port!==null&&n.add(e.port),[...n].sort((s,r)=>s-r)}function H6({props:e}){var k;const[n,s]=h.useState(null),[r,a]=h.useState(null),[i,l]=h.useState(null),[o,c]=h.useState(!1),u=((k=e.target)==null?void 0:k.plugin)??null,d=W6(e),[f,m]=h.useState(null),p=f!==null&&d.includes(f)?f:e.port,g=e.target?p!==null&&p!==e.port?`${e.target.name}.${p}`:e.target.name:null,v=e.changes??0,b=h.useRef(v),[j,x]=h.useState(0);h.useEffect(()=>{v<=b.current||(b.current=v,e.reloadsItself||x(N=>N+1))},[v,e.reloadsItself]),h.useEffect(()=>{if(u===null||g===null)return;let N=!0;return s(null),a(null),l(null),x(0),R.previewLink(u,g).then(S=>{N&&(s(S.url),a($0(S.url)))}).catch(S=>{N&&l(S instanceof Error?S.message:"That preview could not be opened.")}),()=>{N=!1}},[u,g]);const y=()=>{u===null||g===null||R.previewLink(u,g).then(N=>a(N.url)).catch(()=>{})};if(e.target===null)return t.jsxs("p",{className:"wb-empty",children:["This panel names no preview. A preview is ",t.jsx("code",{children:"/preview/<plugin>/<name>/"}),", and nothing else is framed here."]});const w=!(e.output===null||e.output==="");return t.jsxs("div",{className:"wb-preview","data-output":o||void 0,children:[t.jsxs("div",{className:"wb-row wb-preview-head",children:[e.title?t.jsx("h4",{className:"wb-doc-title",children:e.title}):null,d.length>1?t.jsx("select",{className:"wb-preview-port","aria-label":"Port",title:"The ports this process is listening on.",value:p??"",onChange:N=>m(Number(N.target.value)),children:d.map(N=>t.jsxs("option",{value:N,children:[":",N]},N))}):null,w?t.jsx("button",{type:"button",className:"ui-btn wb-preview-toggle","data-variant":"ghost","data-size":"sm","aria-pressed":o,onClick:()=>c(N=>!N),children:o?"Hide output":"Output"}):null,r?t.jsx("a",{className:"wb-preview-open",href:r,target:"_blank",rel:"noreferrer noopener",onPointerEnter:y,onFocus:y,title:"Through buddi: works from anywhere the dashboard does, including the tailnet.",children:"Open in a tab"}):null,p!==null&&B6()?t.jsxs("a",{className:"wb-preview-direct",href:`http://localhost:${p}/`,target:"_blank",rel:"noreferrer noopener",title:"The process itself, on this machine only.",children:["localhost:",p]}):null]}),t.jsxs("div",{className:"wb-preview-body",children:[n?t.jsx("iframe",{className:"wb-preview-frame",src:j===0?n:$0(n),title:e.title??"Preview",sandbox:"allow-scripts allow-forms allow-same-origin allow-modals allow-downloads"},j):t.jsx("p",{className:"wb-empty wb-preview-frame",children:i??"Opening the preview…"}),w&&o?t.jsx(L$,{text:e.output??"",className:"wb-preview-output"}):null]})]})}const K6=50,V6=9,G6=24,q6=.6,Y6=48,J6=/(amount|total|balance|price|cost|paid|pay|payment|net|spend|spent|due|limit|owed|fee|income|charge|burn|minimum|principal|interest|worth|cash|debt|deposit|credit|debit|value|revenue|budget|floor|avg|mean|median)/i,Q6=/^\d{4}-\d{2}-\d{2}([T ]\d{2}:\d{2}|$)/,X6=/^id$|(^|[a-z0-9])Id$|_id$/;function Sl(e){return e===null||typeof e=="string"||typeof e=="number"||typeof e=="boolean"}function vs(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function F$(...e){for(const n of e)if(vs(n))for(const s of["currency","currencyCode"]){const r=n[s];if(typeof r=="string"&&/^[A-Za-z]{3}$/.test(r))return r.toUpperCase()}return null}function _$(e,n,s){const r=n.filter(a=>a!=null&&a!=="");return r.length===0?"text":r.every(a=>typeof a=="boolean")?"boolean":r.every(a=>typeof a=="number"&&Number.isFinite(a))?s!==null&&J6.test(e)?"currency":"number":r.every(a=>typeof a=="string"&&Q6.test(a))?"date":"text"}function Z6(e,n){if(!X6.test(e))return!1;const s=n.filter(r=>!wo(r));return s.length<2?!1:new Set(s.map(r=>String(r))).size===s.length}function wo(e){return e==null||e===""?!0:Array.isArray(e)?e.length===0:vs(e)?Object.keys(e).length===0:!1}function T0(e,n){const s=e.filter(vs);if(s.length===0||s.length/e.length<.8)return null;const r=s.slice(0,K6),a=new Map,i=[];for(const d of r)for(const f of Object.keys(d))a.has(f)||i.push(f),a.set(f,(a.get(f)??0)+1);if(a.size===0||a.size>G6||[...a.values()].reduce((d,f)=>d+f,0)/(a.size*r.length)<q6)return null;const o=[...a.keys()].sort((d,f)=>{const m=(a.get(f)??0)-(a.get(d)??0);return m!==0?m:i.indexOf(d)-i.indexOf(f)}),c=[],u=[];for(const d of o){const f=r.map(v=>v[d]),m=f.filter(v=>!wo(v));if(m.length===0||Z6(d,f))continue;const p=F$(r[0],n),g=_$(d,f,p);if(r.length>=4&&m.length===f.length&&f.every(v=>Sl(v)&&v===f[0])){u.push({label:_n(d),value:f[0],type:g,currency:p});continue}if(c.push({key:d,label:_n(d),type:g,currency:g==="currency"?p:null}),c.length===V6)break}return c.length===0?null:{columns:c,rows:s,constants:u}}function eB(e,n,s){const r=F$(s);return{label:_n(e),value:n,type:_$(e,[n],r),currency:r}}function z$(e){return typeof e=="string"&&e.length>Y6}function tB(e){return e==null?"This tool returned nothing.":typeof e=="string"&&e.trim()===""?"This tool returned an empty string.":Array.isArray(e)&&e.length===0?"This tool returned no items.":vs(e)&&Object.keys(e).length===0?"This tool returned an empty result.":null}function Fx(e){if(typeof e=="string"&&e.trim()!=="")return e;if(vs(e))for(const n of["message","error","reason","detail","description"]){const s=e[n];if(typeof s=="string"&&s.trim()!=="")return s;if(vs(s)){const r=Fx(s);if(r!=="The call failed with no reason given.")return r}}return"The call failed with no reason given."}function Fy(e,n={}){if(n.failed){let f=e;if(typeof e=="string")try{const m=JSON.parse(e.replace(/^tool-error:\s*/,""));vs(m)&&(f=m)}catch{}return{kind:"error",summary:Fx(f),detail:R0(f)}}if(vs(e)){const f=e.error,m=e.ok;if(typeof f=="string"&&f.trim()!==""||m===!1)return{kind:"error",summary:Fx(e),detail:R0(e)}}const s=tB(e);if(s)return{kind:"empty",note:s,stats:[]};if(Array.isArray(e)){const f=T0(e,e);return f?{kind:"table",label:null,columns:f.columns,rows:f.rows,total:f.rows.length,stats:f.constants,notes:[],asides:[]}:e.every(Sl)?{kind:"list",label:null,items:e,total:e.length,stats:[],notes:[],asides:[]}:{kind:"tree",value:e}}if(!vs(e))return{kind:"tree",value:e};const r=Object.entries(e);let a=null,i=null;for(const[f,m]of r){if(!Array.isArray(m))continue;const p=T0(m,e);if(p){(!a||p.rows.length>a.candidate.rows.length)&&(a={key:f,candidate:p});continue}m.length>0&&m.every(Sl)&&(!i||m.length>i.items.length)&&(i={key:f,items:m})}const l=(a==null?void 0:a.key)??(i==null?void 0:i.key)??null,o=[],c=[],u=[];for(const[f,m]of r)if(f!==l){if(z$(m)){c.push(m);continue}if(Sl(m)){if(m==="")continue;o.push(eB(f,m,e));continue}m!==void 0&&u.push({label:_n(f),value:m})}if(a)return{kind:"table",label:_n(a.key),columns:a.candidate.columns,rows:a.candidate.rows,total:a.candidate.rows.length,stats:[...o,...a.candidate.constants],notes:c,asides:u};if(i)return{kind:"list",label:_n(i.key),items:i.items,total:i.items.length,stats:o,notes:c,asides:u};const d=r.filter(([,f])=>Array.isArray(f)&&f.length===0);return d.length>0&&d.length===r.filter(([,f])=>Array.isArray(f)).length?{kind:"empty",note:`No ${d.map(([m])=>_n(m).toLowerCase()).join(", ")} to show.`,stats:o}:r.every(([,f])=>Sl(f)||vs(f)||Array.isArray(f))?{kind:"record",pairs:o,notes:c,asides:u}:{kind:"tree",value:e}}function R0(e){if(!vs(e))return null;const n=Object.entries(e).filter(([s])=>s!=="message"&&s!=="error");return n.length===0?null:Object.fromEntries(n)}const Mh=25,nB=3,_x=8,U$=6;function zx(e,n=0){if(n>U$||wo(e)||z$(e))return 0;if(Sl(e))return 1;if(Array.isArray(e)){let s=0;for(const r of e)if(s+=zx(r,n+1),s>=_x)return s;return s}if(vs(e)){let s=0;for(const r of Object.values(e))if(s+=zx(r,n+1),s>=_x)return s;return s}return 0}function Ux(e,n=0){if(n>U$)return!1;if(Array.isArray(e))return e.some(i=>Ux(i,n+1));if(!vs(e))return!1;const s=e.artifactId??e.artifact_id;if(typeof s=="string"&&s.trim()!=="")return!0;const r=e.mime??e.mimeType??e.contentType,a=e.url??e.src??e.downloadUrl??e.path;return typeof r=="string"&&r.includes("/")&&typeof a=="string"&&a.trim()!==""?!0:Object.values(e).some(i=>Ux(i,n+1))}function sB(e){if(Ux(e))return!0;const n=Fy(e);switch(n.kind){case"table":return n.rows.length>0;case"list":return n.items.length>=nB;case"record":case"tree":return zx(e)>=_x;default:return!1}}function fp(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}function _y(e){const n=fp(e);if(!n)return null;const s=fp(n.output)??n;if(typeof s.state!="string"||typeof s.stdout!="string"||typeof s.stderr!="string"||!(s.exitCode===null||typeof s.exitCode=="number"&&Number.isFinite(s.exitCode)))return null;const r=s===n?null:fp(n.input),a=(r==null?void 0:r.command)??s.command;return{command:typeof a=="string"?a:null,input:r,result:s}}function rB({text:e,label:n}){const[s,r]=h.useState("");return t.jsxs("span",{className:"wb-command-copy",children:[t.jsx("button",{className:"ui-btn",onClick:()=>{var a;if(r(""),!((a=navigator.clipboard)!=null&&a.writeText)){r("Copy unavailable; select the text to copy.");return}navigator.clipboard.writeText(e).then(()=>r("Copied"),()=>r("Copy failed; select the text to copy."))},children:n}),s&&t.jsx("span",{role:"status",className:"wb-hint",children:s})]})}function mp({title:e,text:n,error:s=!1}){return t.jsxs("section",{className:"wb-command-stream","data-error":s||void 0,children:[t.jsxs("div",{className:"wb-command-bar",children:[t.jsx("h4",{children:e}),t.jsx(rB,{text:n,label:`Copy ${e.toLowerCase()}`})]}),t.jsx("pre",{className:"wb-command-text","aria-label":e,tabIndex:0,children:n})]})}function aB({value:e,children:n}){const{result:s,command:r,input:a}=e,i=s.state==="completed"&&s.exitCode!==null&&s.exitCode!==0,l=typeof s.signal=="string"&&s.signal?s.signal:null,o=s.state==="completed"&&s.exitCode===0,c=Object.fromEntries(Object.entries(s).filter(([d,f])=>!["stdout","stderr","state","exitCode","artifacts","outputErrors","command"].includes(d)&&f!==null&&f!==void 0&&f!=="")),u=Array.isArray(s.outputErrors)?s.outputErrors.filter(d=>typeof d=="string"):[];return t.jsxs("div",{className:"wb-command-result",children:[t.jsxs("div",{className:"wb-command-bar",children:[t.jsx("span",{className:"ui-pill","data-tone":o?"good":"critical",children:i?"Failed":s.state==="completed"&&l?"Terminated":s.state}),s.exitCode!==null&&t.jsxs("span",{className:"mono",children:["Exit code ",s.exitCode]}),l&&t.jsxs("span",{className:"mono",children:["Signal ",l]}),t.jsx("span",{className:"wb-hint",children:"Recorded command result"})]}),r!==null&&t.jsx(mp,{title:"Command",text:r}),s.state==="output-limit"&&t.jsx("p",{className:"wb-fail",children:"Output limit reached. The command was stopped and the captured output may be incomplete."}),s.state==="timed-out"&&t.jsx("p",{className:"wb-fail",children:"The command exceeded its time limit. Output below may be partial."}),s.state==="cancelled"&&t.jsx("p",{className:"wb-note",children:"The command was cancelled. Completed changes were not undone."}),s.stdout?t.jsx(mp,{title:"Output",text:s.stdout}):t.jsx("p",{className:"wb-note",children:"No standard output."}),s.stderr?t.jsx(mp,{title:"Standard error",text:s.stderr,error:!0}):null,u.length>0&&t.jsxs("section",{children:[t.jsx("h4",{children:"File export errors"}),u.map((d,f)=>t.jsx("p",{className:"wb-fail",children:d},f))]}),n,(Object.keys(c).length>0||a!==null)&&t.jsxs("details",{className:"wb-aside",children:[t.jsx("summary",{children:"Execution details"}),t.jsx("pre",{children:ks({...c,...a?{input:a}:{}})})]})]})}const dd=2,I0=64;function iB({props:e}){const[n,s]=h.useState(!1),r=_y(e.value),a=lB((r==null?void 0:r.result)??e.value),i=h.useMemo(()=>Fy(e.value,{failed:e.failed??!1}),[e.value,e.failed]);return t.jsxs("div",{children:[!r&&t.jsx(P0,{files:a}),n?t.jsx("pre",{className:"ui-code",children:ks(e.value)}):r?t.jsx(aB,{value:r,children:a.length>0&&t.jsxs("section",{children:[t.jsx("h4",{children:"Generated files"}),t.jsx(P0,{files:a})]})}):a.length?t.jsxs("details",{className:"wb-aside",children:[t.jsx("summary",{children:"Tool details"}),t.jsx(M0,{shape:i})]}):t.jsx(M0,{shape:i}),t.jsx("div",{className:"wb-row-end wb-section",children:t.jsx("button",{className:"ui-btn","data-variant":"ghost","data-size":"sm",onClick:()=>s(l=>!l),"aria-pressed":n,children:n?"Readable":"Raw JSON"})})]})}function lB(e){const n=e&&typeof e=="object"&&"artifacts"in e?e.artifacts:null;return Array.isArray(n)?n.filter(s=>s&&typeof s.id=="string"&&/^[0-9a-f-]{36}$/i.test(s.id)&&typeof s.filename=="string"):[]}function P0({files:e}){return e.length?t.jsx("div",{className:"wb-artifacts",children:e.map(n=>{var s;return t.jsxs("div",{children:[["image/png","image/jpeg","image/gif","image/webp"].includes(n.mime??"")?t.jsx(oB,{file:n}):null,t.jsx("a",{className:"ui-btn",href:`/api/artifacts/${encodeURIComponent(n.id)}/download`,download:!0,children:(s=n.mime)!=null&&s.startsWith("image/")?`Download ${n.filename}`:n.filename})]},n.id)})}):null}function oB({file:e}){const[n,s]=h.useState(!1);return n?t.jsx("p",{className:"wb-note",children:"Preview unavailable. You can still download the file."}):t.jsx("img",{className:"wb-artifact-image",src:`/api/artifacts/${e.id}/preview`,alt:e.filename,onError:()=>s(!0)})}function M0({shape:e}){switch(e.kind){case"error":return t.jsxs("div",{children:[t.jsx("p",{className:"wb-fail",role:"status",children:e.summary}),e.detail===null?null:t.jsxs("details",{className:"wb-aside",children:[t.jsx("summary",{children:"What came back with it"}),t.jsx("div",{className:"wb-tree",children:Xc(e.detail,1)})]})]});case"empty":return t.jsxs("div",{children:[t.jsx(pp,{stats:e.stats}),t.jsx("p",{className:"wb-note",children:e.note})]});case"table":{const n=mB(e.columns,e.rows);return t.jsxs("div",{children:[t.jsx(pp,{stats:e.stats}),t.jsx(gp,{notes:e.notes}),n?t.jsx(pB,{label:e.label,plan:n,rows:e.rows,total:e.total}):t.jsx(uB,{label:e.label,columns:e.columns,rows:e.rows,total:e.total}),t.jsx(xp,{asides:e.asides})]})}case"list":return t.jsxs("div",{children:[t.jsx(pp,{stats:e.stats}),t.jsx(gp,{notes:e.notes}),e.label?t.jsx("h4",{className:"wb-sub",children:e.label}):null,t.jsx("ul",{className:"wb-list",children:e.items.slice(0,100).map((n,s)=>t.jsx("li",{children:pn(n,"text",null)},s))}),e.total>100?t.jsxs("p",{className:"wb-note",children:["Showing 100 of ",e.total,"."]}):null,t.jsx(xp,{asides:e.asides})]});case"record":return t.jsxs("div",{children:[t.jsx(gp,{notes:e.notes}),t.jsx(cB,{pairs:e.pairs}),t.jsx(xp,{asides:e.asides})]});default:return t.jsx("div",{className:"wb-tree",children:Xc(e.value,0)})}}function pp({stats:e}){return e.length===0?null:t.jsx("div",{className:"ui-stats","data-inline":"true",children:e.map(n=>t.jsxs("div",{children:[t.jsx("div",{className:"ui-stat-k",children:n.label}),t.jsx("div",{className:"ui-stat-v",children:zy(n.value,n.type,n.currency)})]},n.label))})}const D0=200;function gp({notes:e}){if(e.length===0)return null;const n=e.filter(r=>r.length<=D0),s=e.filter(r=>r.length>D0);return t.jsxs(t.Fragment,{children:[n.map(r=>t.jsx("p",{className:"wb-note",children:r},r)),s.length>0?t.jsxs("details",{className:"wb-aside",children:[t.jsx("summary",{children:s.length===1?"A note that came with this result":`${s.length} notes that came with this result`}),s.map(r=>t.jsx("p",{className:"wb-note",children:r},r))]}):null]})}function cB({pairs:e}){return e.length===0?t.jsx("p",{className:"wb-note",children:"Nothing to show."}):t.jsx("dl",{className:"ui-kv",children:e.map(n=>t.jsxs("div",{className:"contents",children:[t.jsx("dt",{children:n.label}),t.jsx("dd",{className:n.type==="text"?void 0:"tnum",children:zy(n.value,n.type,n.currency)})]},n.label))})}function xp({asides:e}){return e.length===0?null:t.jsx("div",{className:"wb-section",children:e.map(n=>t.jsxs("details",{className:"wb-aside",children:[t.jsx("summary",{children:n.label}),t.jsx("div",{className:"wb-tree",children:Xc(n.value,1)})]},n.label))})}function uB({label:e,columns:n,rows:s,total:r}){const[a,i]=h.useState(!1),l=r<=Mh+5?r:Mh,o=a?s:s.slice(0,l);return t.jsxs("div",{children:[e?t.jsx("h4",{className:"wb-sub",children:e}):null,t.jsx("div",{className:"ui-table-wrap",children:t.jsxs("table",{className:"ui-table",children:[t.jsx("thead",{children:t.jsx("tr",{children:n.map(c=>t.jsx("th",{className:W$(c.type)?"num":void 0,children:c.label},c.key))})}),t.jsx("tbody",{children:o.map((c,u)=>t.jsx("tr",{children:n.map(d=>t.jsx(gB,{value:c[d.key],column:d},d.key))},u))})]})}),r>o.length?t.jsxs("p",{className:"wb-note wb-note-row",children:[t.jsxs("span",{children:["Showing ",o.length," of ",r]}),t.jsxs("button",{className:"ui-btn",onClick:()=>i(!0),children:["Show all ",r]})]}):null]})}const dB=/^(title|name|headline|subject|label|heading)$/i,hB=/^(url|link|href|uri|permalink)$/i;function Dh(e){return typeof e=="string"&&/^https?:\/\/[^\s]+$/i.test(e.trim())}function fB(e){try{return new URL(e).hostname.replace(/^www\./,"")}catch{return e}}function B$(e,n=48){try{const s=new URL(e),r=s.pathname==="/"?"":s.pathname,a=`${s.hostname.replace(/^www\./,"")}${r}${s.search}`;return a.length>n?`${a.slice(0,n-1)}…`:a}catch{return e.length>n?`${e.slice(0,n-1)}…`:e}}function hd(e,n){const s=e.map(r=>r[n]).filter(r=>typeof r=="string"&&r.trim()!=="");return s.length===0?0:s.reduce((r,a)=>r+a.length,0)/s.length}function mB(e,n){if(n.length===0)return null;const s=e.filter(d=>d.type==="text"),r=s.find(d=>hB.test(d.key)&&n.some(f=>Dh(f[d.key])))??s.find(d=>{const f=n.map(m=>m[d.key]).filter(m=>!wo(m));return f.length>0&&f.filter(Dh).length/f.length>=.6});if(!r)return null;const a=s.filter(d=>d.key!==r.key),i=a.find(d=>dB.test(d.key))??a.find(d=>hd(n,d.key)>0);if(!i)return null;const o=[...a.filter(d=>d.key!==i.key)].sort((d,f)=>hd(n,f.key)-hd(n,d.key)),c=o[0]&&hd(n,o[0].key)>40?o[0]:null,u=e.filter(d=>d.key!==r.key&&d.key!==i.key&&d.key!==(c==null?void 0:c.key)).map(d=>d.key);return{url:r.key,title:i.key,description:(c==null?void 0:c.key)??null,meta:u}}function pB({label:e,plan:n,rows:s,total:r}){const[a,i]=h.useState(!1),l=r<=Mh+5?r:Mh,o=a?s:s.slice(0,l);return t.jsxs("div",{children:[e?t.jsx("h4",{className:"wb-sub",children:e}):null,t.jsx("ol",{className:"wb-records",children:o.map((c,u)=>{const d=c[n.url],f=Dh(d)?d.trim():null,m=typeof c[n.title]=="string"&&c[n.title].trim()!==""?c[n.title]:f?B$(f):"Untitled",p=n.description&&typeof c[n.description]=="string"?c[n.description]:null,g=f?fB(f):null,v=n.meta.map(b=>c[b]).filter(b=>!wo(b)&&typeof b!="object").map(b=>String(b)).filter(b=>g===null||b.replace(/^www\./,"")!==g);return t.jsxs("li",{className:"wb-record",children:[f?t.jsx("a",{className:"wb-record-title",href:f,target:"_blank",rel:"noopener noreferrer",children:m}):t.jsx("span",{className:"wb-record-title",children:m}),t.jsxs("div",{className:"wb-record-meta",children:[g?t.jsx("span",{className:"wb-record-host",title:f??void 0,children:g}):null,v.map((b,j)=>t.jsx("span",{children:b.length>60?`${b.slice(0,59)}…`:b},j))]}),p?t.jsx("p",{className:"wb-record-desc",children:p.length>280?`${p.slice(0,279)}…`:p}):null]},u)})}),r>o.length?t.jsxs("p",{className:"wb-note wb-note-row",children:[t.jsxs("span",{children:["Showing ",o.length," of ",r]}),t.jsxs("button",{className:"ui-btn",onClick:()=>i(!0),children:["Show all ",r]})]}):null]})}function gB({value:e,column:n}){if(wo(e))return t.jsx("td",{className:"wb-cell-soft",children:"—"});if(Dh(e)){const a=e.trim();return t.jsx("td",{className:"wb-cell-link",children:t.jsx("a",{href:a,target:"_blank",rel:"noopener noreferrer",title:a,children:B$(a)})})}if(e!==null&&typeof e=="object"){const a=Array.isArray(e)?`${e.length} item${e.length===1?"":"s"}`:`${Object.keys(e).length} fields`;return t.jsx("td",{className:"wb-cell-soft",title:ks(e),children:a})}const s=zy(e,n.type,n.currency),r=s.length>I0?`${s.slice(0,I0-1)}…`:s;return t.jsx("td",{className:W$(n.type)?"num":"wb-cell-text",...r===s?{}:{title:s},children:r})}function W$(e){return e==="number"||e==="currency"}function zy(e,n,s){return e==null?"—":n==="boolean"?e?"yes":"no":pn(e,n==="text"?"text":n,s)}function Xc(e,n){if(e===null)return t.jsx("span",{className:"wb-tree-null",children:"null"});if(e===void 0)return t.jsx("span",{className:"wb-tree-null",children:"—"});if(typeof e=="number")return t.jsx("span",{className:"wb-tree-num",children:e});if(typeof e=="boolean")return t.jsx("span",{className:"wb-tree-bool",children:e?"true":"false"});if(typeof e=="string")return t.jsx("span",{children:e===""?t.jsx("em",{className:"wb-tree-null",children:"empty"}):e});if(Array.isArray(e)){if(e.length===0)return t.jsx("span",{className:"wb-tree-null",children:"none"});const a=t.jsxs("div",{className:"wb-tree-branch",children:[e.slice(0,50).map((i,l)=>t.jsxs("div",{children:[t.jsxs("span",{className:"wb-tree-key",children:[l,". "]}),Xc(i,n+1)]},l)),e.length>50?t.jsxs("div",{className:"wb-tree-key",children:["…and ",e.length-50," more"]}):null]});return n>=dd?t.jsx(O0,{summary:`${e.length} items`,open:n===dd,children:a}):a}const s=Object.entries(e);if(s.length===0)return t.jsx("span",{className:"wb-tree-null",children:"empty"});const r=t.jsx("div",{className:n===0?void 0:"wb-tree-branch",children:s.map(([a,i])=>t.jsxs("div",{children:[t.jsxs("span",{className:"wb-tree-key",children:[_n(a),": "]}),Xc(i,n+1)]},a))});return n>=dd?t.jsx(O0,{summary:`${s.length} fields`,open:n===dd,children:r}):r}function O0({summary:e,open:n,children:s}){return t.jsxs("details",{open:n,children:[t.jsx("summary",{className:"wb-tree-key",children:e}),s]})}function xB({props:e}){const n=e.groups.every(s=>s.rows.length===0);return t.jsxs("div",{children:[e.summary.length>0?t.jsx("div",{className:"ui-stats","data-inline":"true",children:e.summary.map(s=>t.jsxs("div",{children:[t.jsx("div",{className:"ui-stat-k",children:s.label}),t.jsx("div",{className:"ui-stat-v","data-tone":s.tone,children:pn(s.value,s.unit,s.currency)})]},s.label))}):null,n?t.jsx("p",{className:"wb-empty",children:e.empty}):e.groups.map((s,r)=>t.jsxs("div",{className:r>0?"wb-section":void 0,children:[s.label?t.jsx("h4",{className:"ui-stat-k wb-label",children:s.label}):null,t.jsx("div",{className:"ui-table-wrap",children:t.jsxs("table",{className:"ui-table",children:[t.jsx("thead",{children:t.jsx("tr",{children:e.columns.map(a=>t.jsx("th",{className:H$(a.type)?"num":void 0,"data-type":a.type,children:a.label},a.key))})}),t.jsx("tbody",{children:s.rows.map((a,i)=>t.jsx("tr",{children:a.map((l,o)=>{var c;return t.jsx(vB,{cell:l},((c=e.columns[o])==null?void 0:c.key)??o)})},i))})]})})]},s.label??r))]})}function vB({cell:e}){const n=pn(e.value,e.type,e.currency);return e.bar?t.jsx("td",{className:"num",children:t.jsxs("div",{className:"wb-row wb-row-end",children:[t.jsx("div",{className:"ui-meter",role:"meter","aria-valuenow":Math.round(e.bar.fraction*100),"aria-valuemin":0,"aria-valuemax":100,"aria-label":n,children:t.jsx("div",{className:"ui-meter-fill","data-tone":e.bar.tone,style:{width:`${Math.round(e.bar.fraction*100)}%`}})}),t.jsx("span",{className:"tnum",children:n})]})}):t.jsx("td",{className:H$(e.type)?"num":void 0,"data-type":e.type,title:n.length>40?n:void 0,children:n})}function H$(e){return e==="number"||e==="currency"||e==="percent"}const L0={mail:"mail",money:"money",calendar:"calendar",people:"agents",file:"files",chart:"chart",bell:"bell",plug:"plug",key:"key",globe:"globe",sun:"sun","partly-cloudy":"partly-cloudy",cloud:"cloud",rain:"rain",drizzle:"drizzle",snow:"snow",storm:"storm",fog:"fog",wind:"wind","moon-clear":"moon-clear","moon-cloud":"moon-cloud",check:"check",clock:"clock"};function bo(e){return(e&&Object.prototype.hasOwnProperty.call(L0,e)?L0[e]:void 0)??"dot"}function Oh(e,n){return(e??[]).filter(s=>s.place===n).map((s,r)=>({page:s,index:r})).sort((s,r)=>(s.page.order??0)-(r.page.order??0)||s.index-r.index).map(s=>s.page)}const Lh="buddi:plugin-pages-changed";function jB(){window.dispatchEvent(new Event(Lh))}function K$(e=!1){const[n,s]=h.useState([]);return h.useEffect(()=>{if(e)return;let r=!1;const a=()=>{Promise.resolve().then(()=>R.pages()).then(l=>{r||s(Array.isArray(l==null?void 0:l.pages)?l.pages:[])}).catch(()=>{})};a();const i=()=>{document.visibilityState==="visible"&&a()};return window.addEventListener(Lh,a),document.addEventListener("visibilitychange",i),()=>{r=!0,window.removeEventListener(Lh,a),document.removeEventListener("visibilitychange",i)}},[e]),{all:n,rail:Oh(n,"rail"),settings:Oh(n,"settings"),find:(r,a)=>n.find(i=>i.plugin===r&&i.id===a)}}function V$(e,n){const s=(n??[]).filter(i=>i.plugin===e),r=Oh(s,"rail")[0]??Oh(s,"settings")[0];if(r!=null&&r.title.trim())return r.title.trim();const a=e.replace(/[-_]+/g," ").trim();return a?a.charAt(0).toUpperCase()+a.slice(1):e}let Hd=null;typeof window<"u"&&window.addEventListener(Lh,()=>{Hd=null});function yB(){return Hd??(Hd=Promise.resolve().then(()=>R.pages()).then(e=>Array.isArray(e==null?void 0:e.pages)?e.pages:[]).catch(()=>(Hd=null,[]))),Hd}function Uy(e,n,s){return s==="settings"?Lr(e,n):Or(e,n)}function wB(e){const[n,s]=h.useState(null),r=e==null?void 0:e.plugin,a=e==null?void 0:e.page;return h.useEffect(()=>{if(!r||!a)return;let i=!1;return yB().then(l=>{const o=l.find(c=>c.plugin===r&&c.id===a);i||s(o?{href:Uy(r,a,o.place),label:o.place==="settings"?`Settings → ${o.title}`:o.title}:null)}),()=>{i=!0}},[r,a]),n}function G$({props:e,layout:n,selected:s,onPick:r}){return e.tiles.length===0?t.jsx("p",{className:"wb-empty",children:e.empty}):t.jsx("ul",{className:"wb-tiles","data-notice":e.notice?"true":void 0,"data-layout":n&&n!=="grid"?n:void 0,style:n==="row"?{"--tiles-n":e.tiles.length}:void 0,children:e.tiles.map((a,i)=>t.jsx(bB,{tile:a,...r?{picked:i===s,onPick:()=>r(i)}:{}},`${i}-${a.label}`))})}function bB({tile:e,picked:n,onPick:s}){const r=wB(e.link),a=[e.label,e.value,...e.lines].filter(l=>l!=="").join(", "),i=t.jsxs("div",{className:"wb-tile-body","aria-hidden":"true",children:[t.jsx("span",{className:"wb-tile-icon","data-icon":e.icon??"dot",children:t.jsx(le,{name:bo(e.icon),size:22})}),e.value!==""?t.jsx("span",{className:"wb-tile-value tnum",children:e.value}):null,t.jsx("span",{className:"wb-tile-label",children:e.label}),e.lines.map((l,o)=>t.jsx("span",{className:"wb-tile-line",children:l},o))]});return s?t.jsx("li",{className:"wb-tile",children:t.jsx("button",{type:"button",className:"ui-card","data-tone":n?"accent":e.tone==="neutral"?void 0:e.tone,"data-selected":n?"true":void 0,"aria-pressed":n===!0,"aria-label":a,onClick:s,children:i})}):t.jsxs("li",{className:"wb-tile",children:[t.jsx("span",{className:"sr-only",children:a}),t.jsxs(Ts,{tone:e.tone==="neutral"?void 0:e.tone,children:[i,r?t.jsx("a",{className:"wb-tile-link",href:r.href,children:r.label}):null]})]})}const il=760,vp=400,Jt={top:18,right:18,bottom:36,left:66},kB=5;function NB({props:e}){const{points:n,referenceLines:s,unit:r,currency:a}=e;if(n.length===0)return t.jsx("p",{className:"wb-empty",children:"This result carried no points to plot."});const i=[...n.map(w=>w.y),...s.map(w=>w.value)],l=Math.min(...i),o=Math.max(...i),c=o-l||Math.abs(o)||1,u=l-c*.08,d=o+c*.08,f=il-Jt.left-Jt.right,m=vp-Jt.top-Jt.bottom,p=w=>Jt.left+(n.length===1?f/2:w/(n.length-1)*f),g=w=>Jt.top+m-(w-u)/(d-u)*m,v=Ah(l,o,4),b=CB(n.map(w=>w.y),e.mark),j=e.shadeBelow===null?[]:EB(n.map(w=>w.y),e.shadeBelow),x=n.map((w,k)=>`${k===0?"M":"L"}${p(k)},${g(w.y)}`).join(" "),y=w=>pn(w,r,a);return t.jsxs("div",{children:[e.label?t.jsx("p",{className:"ui-panel-sub",children:e.label}):null,t.jsxs("div",{className:"wb-chart-layout",children:[t.jsx("div",{className:"wb-chart-plot",children:t.jsxs("svg",{className:"wb-chart",viewBox:`0 0 ${il} ${vp}`,role:"img","aria-label":SB(e,y),preserveAspectRatio:"xMidYMid meet",children:[j.map(w=>t.jsx("rect",{className:"wb-chart-breach",x:p(w.from),width:Math.max(2,p(w.to)-p(w.from)),y:Jt.top,height:m},`band-${w.from}`)),v.map(w=>t.jsxs("g",{children:[t.jsx("line",{className:"wb-chart-grid",x1:Jt.left,x2:il-Jt.right,y1:g(w),y2:g(w)}),t.jsx("text",{x:Jt.left-8,y:g(w)+4,textAnchor:"end",children:y(w)})]},`tick-${w}`)),s.map(w=>t.jsxs("g",{children:[t.jsx("line",{className:"wb-chart-floor",x1:Jt.left,x2:il-Jt.right,y1:g(w.value),y2:g(w.value)}),t.jsxs("text",{x:il-Jt.right,y:g(w.value)-6,textAnchor:"end",children:[w.label," ",y(w.value)]})]},`rule-${w.label}`)),t.jsx("line",{className:"wb-chart-axis",x1:Jt.left,x2:Jt.left,y1:Jt.top,y2:Jt.top+m}),t.jsx("line",{className:"wb-chart-axis",x1:Jt.left,x2:il-Jt.right,y1:Jt.top+m,y2:Jt.top+m}),t.jsx("path",{className:"wb-chart-series",d:x}),b!==null?t.jsxs("g",{children:[t.jsx("circle",{className:"wb-chart-min",cx:p(b),cy:g(n[b].y),r:4.5}),t.jsx("text",{x:p(b),y:g(n[b].y)+20,textAnchor:"middle",children:y(n[b].y)})]}):null,AB(n.length).map(w=>t.jsx("text",{x:p(w),y:vp-10,textAnchor:"middle",children:Sx(n[w].x)},`x-${w}`))]})}),e.events.length>0?t.jsxs("aside",{className:"wb-chart-events",children:[t.jsx("h4",{className:"ui-stat-k wb-label",children:"What happens"}),t.jsx("ul",{className:"wb-chart-event-list",children:e.events.map((w,k)=>t.jsxs("li",{className:"wb-chart-event",children:[t.jsxs("span",{children:[t.jsx("span",{className:"wb-chart-event-day",children:Sx(w.at)}),w.label]}),w.amount===null?null:t.jsx("span",{className:w.amount<0?"tnum critical":"tnum good",children:pn(w.amount,r,a)})]},`${w.at}-${w.label}-${k}`))})]}):null]})]})}function SB(e,n){const s=e.points.map(l=>l.y),r=e.points[0],a=e.points[e.points.length-1],i=e.referenceLines.map(l=>`${l.label} at ${n(l.value)}`).join(", ");return[`${e.points.length} points from ${r==null?void 0:r.x} to ${a==null?void 0:a.x}`,`low ${n(Math.min(...s))}, high ${n(Math.max(...s))}`,i].filter(Boolean).join("; ")}function CB(e,n){if(!n||e.length===0)return null;let s=0;for(let r=1;r<e.length;r+=1)(n==="min"?e[r]<e[s]:e[r]>e[s])&&(s=r);return s}function EB(e,n){const s=[];let r=null;return e.forEach((a,i)=>{a<n?r===null&&(r=i):r!==null&&(s.push({from:r,to:i}),r=null)}),r!==null&&s.push({from:r,to:e.length-1}),s}function AB(e,n=kB){if(e<=0)return[];if(e<=n)return[...Array(e).keys()];const s=e-1,r=new Set;for(let a=0;a<n;a+=1)r.add(Math.round(a/(n-1)*s));return[...r].sort((a,i)=>a-i)}const Ds=e=>e,Bx={timeseries:Ds(NB),table:Ds(xB),bars:Ds(Jz),keyvalue:Ds(L6),tiles:Ds(G$),document:Ds(BU),diff:Ds(n3),terminal:Ds(U6),image:Ds(O6),preview:Ds(H6),envelope:Ds(R6),structured:Ds(iB)},$B="structured";function TB(e){return(Fh(e)?Bx[e]:void 0)??Bx[$B]}function Fh(e){return Object.prototype.hasOwnProperty.call(Bx,e)}function RB({renderer:e,props:n,timezone:s,onDecided:r}){const a=TB(e),l=Fh(e)?n:{value:n};return t.jsx(a,{props:l,timezone:s,onDecided:r})}function IB({profile:e,onChange:n}){return t.jsxs("div",{className:"wb-prof","data-testid":"agent-profile",children:[t.jsx("p",{className:"wb-prof-lead",children:e.description}),t.jsxs("div",{className:"wb-prof-tags",children:[e.isDefault?t.jsx(jp,{children:"Opens by default"}):null,t.jsx(jp,{children:e.source==="example"?"Shipped with buddi":"Yours"}),e.roles.map(s=>t.jsx(jp,{title:`A surface command that asks for "${s}" lands on this agent.`,children:_n(s)},s))]}),e.available?null:t.jsxs("p",{className:"wb-prof-blocked","data-testid":"agent-profile-unavailable",children:[t.jsx("strong",{children:"This agent cannot run here."})," ",e.unavailableReason]}),(e.disabled??[]).map(s=>t.jsx("p",{className:"wb-prof-blocked","data-testid":"agent-profile-disabled",children:s},s)),t.jsx(Wo,{title:"How it works with you",note:"Live decisions stay in the conversation; this page explains the standing rules.",children:t.jsxs("ul",{className:"wb-prof-list",children:[t.jsxs("li",{className:"wb-prof-row",children:[t.jsxs("span",{className:"wb-prof-row-main",children:[t.jsx("span",{className:"wb-prof-row-name",children:"Quick questions"}),t.jsx("span",{className:"wb-prof-row-desc",children:"When it knows the likely answers, it can show one-tap choices in the dashboard and Telegram. You can still write a different answer when the question allows it."})]}),t.jsx("span",{className:"wb-prof-auto",children:"Answers only"})]}),t.jsxs("li",{className:"wb-prof-row","data-gated":"true",children:[t.jsxs("span",{className:"wb-prof-row-main",children:[t.jsx("span",{className:"wb-prof-row-name",children:"Action approvals"}),t.jsx("span",{className:"wb-prof-row-desc",children:"A request to send, spend, publish or otherwise affect the world appears in the conversation with the exact action. Answering a question never approves it."})]}),t.jsxs("span",{className:"wb-prof-gate",children:[t.jsx(q$,{}),"Exact action"]})]})]})}),t.jsx(Wo,{title:"What it can do",note:PB(e),tone:e.gatedCount>0?"warning":void 0,children:e.tools.length===0?t.jsx("p",{className:"wb-prof-empty",children:"No tools at all. It answers from the conversation and from what it remembers, and it can change nothing."}):[...e.tools].sort((s,r)=>+(r.gated>0)-+(s.gated>0)).map(s=>t.jsx(MB,{family:s},s.family))}),t.jsx(Wo,{title:"What it runs on",children:t.jsxs("dl",{className:"wb-prof-kv",children:[t.jsx(Ho,{label:"Provider",children:e.engine.provider}),t.jsx(Ho,{label:"Model",children:t.jsx("span",{className:"mono",children:e.engine.model})}),t.jsxs(Ho,{label:"Credential",children:[e.engine.credentialKind," from"," ",t.jsx("span",{className:"mono",children:e.engine.credentialEnv})]}),t.jsxs(Ho,{label:"Turn budget",children:[e.engine.maxTurns," ",e.engine.maxTurns===1?"turn":"turns"," per message"]}),t.jsx(Ho,{label:"Language",children:_B(e.engine.language)})]})}),e.skills.length>0?t.jsx(Wo,{title:"What it has read",note:`${e.skills.length} ${e.skills.length===1?"skill":"skills"}, composed into every run`,children:t.jsx("ul",{className:"wb-prof-list",children:e.skills.map(s=>t.jsxs("li",{className:"wb-prof-row",children:[t.jsxs("span",{className:"wb-prof-row-main",children:[t.jsx("span",{className:"wb-prof-row-name mono",children:s.name}),s.description?t.jsx("span",{className:"wb-prof-row-desc",children:s.description}):null]}),t.jsxs("span",{className:"wb-prof-row-side",title:s.file,children:[s.scope==="private"?"its own":"shared"," · ",s.provenance]})]},s.file))})}):null,e.delegates.length>0?t.jsx(Wo,{title:"Who it can hand work to",note:"A colleague's tools are reached through the colleague, never held here",children:t.jsx("ul",{className:"wb-prof-list",children:e.delegates.map(s=>t.jsxs("li",{className:"wb-prof-row",children:[t.jsxs("span",{className:"wb-prof-row-main",children:[t.jsxs("span",{className:"wb-prof-row-name mono",children:["@",s.handle]}),t.jsx("span",{className:"wb-prof-row-desc",children:s.description})]}),t.jsx("span",{className:"wb-prof-row-side",children:s.available?s.name:`${s.name} · cannot run`})]},s.id))})}):null,t.jsxs("footer",{className:"wb-prof-foot",children:[t.jsx("p",{className:"wb-prof-note",children:e.note}),t.jsx("p",{className:"wb-prof-file mono",title:e.file,children:e.file}),e.changeVia&&n?t.jsxs("button",{className:"ui-btn","data-testid":"agent-profile-change",title:e.changeVia.prompt,onClick:()=>n({agentId:e.changeVia.agentId,prompt:e.changeVia.prompt}),children:["Ask @",e.changeVia.handle," to change this"]}):null]})]})}function PB(e){if(e.toolCount===0)return"Nothing. This agent holds no tools.";const n=`${e.toolCount} ${e.toolCount===1?"tool":"tools"}`;if(e.gatedCount===0)return`${n}, every one of them running without asking you. None of them can send, spend or write to the world.`;const s=e.gatedCount===1?"one of them stops and waits for you":`${e.gatedCount} of them stop and wait for you`;return`${n}, and ${s}.`}function MB({family:e}){const n=[...e.tools].sort((s,r)=>Number(r.gated)-Number(s.gated));return t.jsxs("section",{className:"wb-prof-family",children:[t.jsxs("h4",{className:"wb-prof-family-head",children:[t.jsx("span",{className:"wb-prof-family-name",children:_n(e.family)}),t.jsxs("span",{className:"wb-prof-family-note",children:[e.tools.length," ",e.tools.length===1?"tool":"tools",e.gated>0?` · ${e.gated} needs you`:""]})]}),t.jsx("ul",{className:"wb-prof-list",children:n.map(s=>t.jsx(DB,{tool:s},s.name))})]})}function DB({tool:e}){return t.jsxs("li",{className:"wb-prof-row","data-gated":e.gated?"true":void 0,"data-testid":"agent-profile-tool",children:[t.jsxs("span",{className:"wb-prof-row-main",children:[t.jsx("span",{className:"wb-prof-row-name mono",children:FB(e.name)}),t.jsx("span",{className:"wb-prof-row-desc","data-clamp":"true",title:e.description,children:e.description})]}),e.gated?t.jsxs("span",{className:"wb-prof-gate",title:"The call is recorded and waits; nothing happens until you approve it.",children:[t.jsx(q$,{}),"Needs your approval"]}):t.jsx("span",{className:"wb-prof-auto",title:LB(e.tier),children:OB(e.tier)})]})}function OB(e){return e==="auto"?"Runs on its own":e==="gated"?"Needs your approval":"Not runnable here"}function LB(e){return e==="auto"?"Called during a run without asking you. It reads, or records something you can see.":`Tier "${e}" does not execute in this build; a call to it is refused.`}function FB(e){const n=e.split(".");return(n[n.length-1]??e).replace(/_/g," ")}function _B(e){return e==="mirror"?"Mirrors whichever language you write in":e==="en"?"Always English":e==="fr"?"Always French":e}function Wo({title:e,note:n,tone:s,children:r}){return t.jsxs("section",{className:"wb-prof-section",children:[t.jsx("h3",{className:"wb-prof-title",children:e}),n?t.jsx("p",{className:"wb-prof-note-lead","data-tone":s,children:n}):null,r]})}function Ho({label:e,children:n}){return t.jsxs(t.Fragment,{children:[t.jsx("dt",{className:"wb-prof-k",children:e}),t.jsx("dd",{className:"wb-prof-v",children:n})]})}function jp({children:e,title:n}){return t.jsx("span",{className:"wb-prof-tag",title:n,children:e})}function q$(){return t.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 14 14","aria-hidden":"true",fill:"none",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("rect",{x:"2.8",y:"6",width:"8.4",height:"6.2",rx:"1.4"}),t.jsx("path",{d:"M4.8 6V4.4a2.2 2.2 0 0 1 4.4 0V6"})]})}const F0=16e3,zB=10*6e4,UB="The microphone is blocked for this page: allow it in the browser’s site settings to talk.",Y$="This browser cannot record here: talking needs a microphone and a secure page (https or localhost).";function BB(){const e=window;return e.AudioContext??e.webkitAudioContext}function WB(e){const n=e&&typeof e=="object"&&"name"in e?String(e.name):"";return n==="NotAllowedError"||n==="SecurityError"||n==="PermissionDeniedError"?UB:n==="NotFoundError"||n==="DevicesNotFoundError"?"No microphone was found on this computer.":n==="NotReadableError"?"The microphone is in use by another app.":Y$}async function HB(e){var c;const n=BB();if(!((c=navigator.mediaDevices)!=null&&c.getUserMedia)||!n)throw Object.assign(new Error(Y$),{name:"Unsupported"});const s=await navigator.mediaDevices.getUserMedia({audio:{channelCount:1,echoCancellation:!0,noiseSuppression:!0}}),r=new n,a=r.createMediaStreamSource(s),i=r.createScriptProcessor(4096,1,1),l=[];i.onaudioprocess=u=>{const d=u.inputBuffer.getChannelData(0);l.push(new Float32Array(d));let f=0;for(let m=0;m<d.length;m++)f+=d[m]*d[m];e(Math.min(1,Math.sqrt(f/d.length)*6))},a.connect(i),i.connect(r.destination),r.state==="suspended"&&await r.resume().catch(()=>{});const o=()=>{i.onaudioprocess=null;try{a.disconnect(),i.disconnect()}catch{}s.getTracks().forEach(u=>u.stop()),r.close().catch(()=>{})};return{async stop(){const u=r.sampleRate;return o(),GB(VB(KB(l),u,F0),F0)},cancel:o}}function KB(e){const n=new Float32Array(e.reduce((r,a)=>r+a.length,0));let s=0;for(const r of e)n.set(r,s),s+=r.length;return n}function VB(e,n,s){if(n<=s)return e;const r=n/s,a=new Float32Array(Math.floor(e.length/r));for(let i=0;i<a.length;i++){const l=Math.floor(i*r),o=Math.min(e.length,Math.floor((i+1)*r));let c=0;for(let u=l;u<o;u++)c+=e[u];a[i]=o>l?c/(o-l):0}return a}function GB(e,n){const s=new ArrayBuffer(44+e.length*2),r=new DataView(s),a=(i,l)=>{for(let o=0;o<l.length;o++)r.setUint8(i+o,l.charCodeAt(o))};a(0,"RIFF"),r.setUint32(4,36+e.length*2,!0),a(8,"WAVEfmt "),r.setUint32(16,16,!0),r.setUint16(20,1,!0),r.setUint16(22,1,!0),r.setUint32(24,n,!0),r.setUint32(28,n*2,!0),r.setUint16(32,2,!0),r.setUint16(34,16,!0),a(36,"data"),r.setUint32(40,e.length*2,!0);for(let i=0;i<e.length;i++){const l=Math.max(-1,Math.min(1,e[i]));r.setInt16(44+i*2,Math.round(l<0?l*32768:l*32767),!0)}return new Blob([s],{type:"audio/wav"})}const Wx="buddi.readAloud";function J$(){try{return window.localStorage.getItem(Wx)==="on"}catch{return!1}}function Q$(e){try{e?window.localStorage.setItem(Wx,"on"):window.localStorage.removeItem(Wx)}catch{}}let kr=null,fc=null,Zc=0,Hx=null;const Kx=new Set;function _h(e){Hx!==e&&(Hx=e,Kx.forEach(n=>n()))}function qB(){return Hx}function YB(e){return Kx.add(e),()=>Kx.delete(e)}function X$(e){return ko(),_h(e),Zc}function _0(e){return e===Zc}function ko(){Zc++,kr&&(kr.pause(),kr.removeAttribute("src")),fc&&typeof URL.revokeObjectURL=="function"&&URL.revokeObjectURL(fc),fc=null,_h(null)}async function JB(e,n,s=null){var a;const r=X$(s);try{const i=await fetch(e,{credentials:"same-origin"});if(!i.ok)throw new Error(`The spoken reply could not be fetched (${i.status}).`);const l=new Blob([await i.arrayBuffer()],{type:n});if(r!==Zc)return;kr||(kr=new Audio,(a=kr.addEventListener)==null||a.call(kr,"ended",()=>_h(null))),fc=URL.createObjectURL(l),kr.src=fc,await kr.play()}catch(i){throw r===Zc&&_h(null),i}}const QB=new Set(["audio/ogg","audio/mpeg","audio/mp4","audio/wav","audio/x-wav","audio/webm"]);function By(e){return QB.has(e.toLowerCase().split(";")[0].trim())}function mc(e){if(e===null||!Number.isFinite(e)||e<0)return"–:––";const n=Math.floor(e);return`${Math.floor(n/60)}:${String(n%60).padStart(2,"0")}`}function Z$(e,n){const s=h.useRef(null),r=h.useRef(null),[a,i]=h.useState(!1),[l,o]=h.useState(!1),[c,u]=h.useState(!1),[d,f]=h.useState(0),[m,p]=h.useState(null);return h.useEffect(()=>()=>{var b;(b=s.current)==null||b.pause(),r.current&&typeof URL.revokeObjectURL=="function"&&URL.revokeObjectURL(r.current)},[]),{playing:a,loading:l,failed:c,position:d,duration:m,toggle:async()=>{const b=s.current;if(b){if(a){b.pause();return}ko(),u(!1);try{if(!r.current){o(!0);const j=await fetch(Ya(e),{credentials:"same-origin"});if(!j.ok)throw new Error(String(j.status));r.current=URL.createObjectURL(new Blob([await j.arrayBuffer()],{type:n})),b.src=r.current}await b.play()}catch{u(!0)}finally{o(!1)}}},bind:{ref:s,preload:"none",onPlay:()=>i(!0),onPause:()=>i(!1),onEnded:()=>{i(!1),f(0)},onTimeUpdate:b=>f(b.currentTarget.currentTime),onLoadedMetadata:b=>p(Number.isFinite(b.currentTarget.duration)?b.currentTarget.duration:null),onDurationChange:b=>p(Number.isFinite(b.currentTarget.duration)?b.currentTarget.duration:null)}}}function sm({artifactId:e,name:n,mime:s,sizeBytes:r}){const{playing:a,loading:i,failed:l,position:o,duration:c,toggle:u,bind:d}=Z$(e,s),f=l?"Could not play. Download it instead.":`${mc(o)} / ${mc(c)}`;return t.jsxs("span",{className:"wb-audio","data-testid":"audio-card","data-playing":a?"true":void 0,children:[t.jsx("button",{type:"button",className:"ui-icon-btn wb-audio-play","data-size":"sm","aria-label":a?`Pause ${n}`:`Play ${n}`,disabled:i,onClick:()=>void u(),children:t.jsx(le,{name:a?"pause":"play",size:14})}),t.jsxs("span",{className:"wb-file-text",children:[t.jsx("span",{className:"wb-file-name",title:n,children:n}),t.jsxs("span",{className:"wb-file-meta","data-testid":"audio-time",children:[i?"Loading…":f,!l&&ds(r)?` · ${ds(r)}`:""]})]}),t.jsx("a",{className:"ui-icon-btn wb-audio-download","data-size":"sm",href:Ya(e),download:n,"aria-label":`Download ${n}`,title:"Download",children:t.jsx(le,{name:"download",size:14})}),t.jsx("audio",{...d})]})}const yp=1e5,wp=200,bp=30;function eT({artifactId:e,filename:n,mime:s,family:r,available:a=!0}){const[i,l]=h.useState(!1);return a?r==="image"&&!i?t.jsx("figure",{className:"file-preview file-preview-image",children:t.jsx("img",{src:_r(e),alt:n??"Image",onError:()=>l(!0)})}):r==="audio"&&By(s)?t.jsx("div",{className:"file-preview file-preview-audio",children:t.jsx(sm,{artifactId:e,name:n??"Audio",mime:s})}):r==="pdf"?t.jsx("div",{className:"file-preview file-preview-pdf",children:t.jsx("object",{data:_r(e),type:"application/pdf","aria-label":n??"PDF",children:t.jsx(G,{children:"Your browser cannot show this PDF here. Download it to open it."})})}):r==="text"||r==="code"||r==="table"?t.jsx(XB,{artifactId:e,filename:n,mime:s,family:r}):t.jsx(G,{children:"Preview not supported for this kind of file. Download it to open it."}):t.jsx(G,{children:"The file is no longer available; its record is kept."})}function XB({artifactId:e,filename:n,mime:s,family:r}){const[a,i]=h.useState("loading");if(h.useEffect(()=>{let o=!1;return i("loading"),fetch(_r(e),{credentials:"same-origin"}).then(async c=>{if(!c.ok)throw new Error(String(c.status));const u=await c.text();o||i({text:u.slice(0,yp),truncated:c.headers.get("X-Preview-Truncated")==="1"||u.length>yp})}).catch(()=>{o||i("failed")}),()=>{o=!0}},[e]),a==="loading")return t.jsx("div",{className:"file-preview",children:t.jsx(ve,{children:"Loading preview…"})});if(a==="failed")return t.jsx(G,{children:"The preview could not be loaded. Download the file to open it."});const l=r==="table"&&(/csv|tab-separated/.test(s)||/\.(csv|tsv)$/i.test(n??""));return t.jsxs("div",{className:"file-preview",children:[l?t.jsx(e5,{text:a.text,delimiter:/tab|\.tsv$/i.test(s+(n??""))?" ":","}):t.jsx("pre",{className:"file-preview-text",children:a.text}),a.truncated?t.jsxs("p",{className:"muted",children:["Showing the first ",yp.toLocaleString()," characters. The download has the whole file."]}):null]})}function ZB(e,n,s,r){const a=[];let i=[],l="",o=!1,c=!1,u=!1;const d=()=>{i.length<r?i.push(l):c=!0,l=""},f=()=>{d(),a.push(i),i=[]};let m=0;for(;m<e.length;m+=1){if(a.length>=s){u=e.slice(m).trim()!=="";break}const p=e[m];if(o){p==='"'?e[m+1]==='"'?(l+='"',m+=1):o=!1:l+=p;continue}if(p==='"'){o=!0;continue}if(p===n){d();continue}if(p!=="\r"){if(p===`
104
- `){f();continue}l+=p}}return a.length<s&&(l!==""||i.length>0)&&f(),{rows:a,truncatedRows:u,truncatedCols:c}}function e5({text:e,delimiter:n}){const s=h.useMemo(()=>ZB(e,n,wp+1,bp),[e,n]),[r,...a]=s.rows;if(!r)return t.jsx("p",{className:"muted",children:"The file is empty."});const i=Math.min(bp,s.rows.reduce((o,c)=>Math.max(o,c.length),0)),l=Array.from({length:i},(o,c)=>c);return t.jsxs("div",{className:"ui-table-wrap file-preview-table",children:[t.jsxs("table",{className:"ui-table",children:[t.jsx("thead",{children:t.jsx("tr",{children:l.map(o=>t.jsx("th",{children:r[o]??""},o))})}),t.jsx("tbody",{children:a.slice(0,wp).map((o,c)=>t.jsx("tr",{children:l.map(u=>t.jsx("td",{children:o[u]??""},u))},c))})]}),s.truncatedRows||s.truncatedCols?t.jsxs("p",{className:"muted",children:["Showing the first ",wp," rows",s.truncatedCols?` and ${bp} columns`:"",". The download has the whole file."]}):null]})}function t5(e,n){const s=e.toLowerCase().split(";")[0].trim(),r=(n??"").toLowerCase().split(".").pop()??"";return s==="text/markdown"||s==="text/x-markdown"||s==="text/plain"&&(r==="md"||r==="markdown")?[{format:"pdf",label:"PDF",hint:".pdf"},{format:"docx",label:"Word",hint:".docx"},{format:"md",label:"Markdown",hint:".md, as written",asWritten:!0}]:s==="text/csv"||s==="text/plain"&&r==="csv"?[{format:"xlsx",label:"Excel",hint:".xlsx"},{format:"csv",label:"CSV",hint:".csv, as written",asWritten:!0}]:[]}function n5(e,n){return`/api/artifacts/${encodeURIComponent(e)}/export/${n}`}function s5(e,n){return`${(e??"document").replace(/\.[a-z0-9]{1,8}$/i,"")||"document"}.${n}`}function z0(e,n){const s=document.createElement("a");s.href=e,s.download=n,s.rel="noopener",document.body.appendChild(s),s.click(),s.remove()}function tT({artifactId:e,filename:n,mime:s,accent:r=!0}){const a=n??"download",i=t5(s,n),l=r?"accent":void 0;if(i.length===0)return t.jsx("a",{className:"ui-btn","data-variant":l,href:Ya(e),download:a,children:"Download"});const o=i.filter(d=>!d.asWritten),c=i.filter(d=>d.asWritten),u=d=>({label:d.label,hint:d.hint,onSelect:()=>d.asWritten?z0(Ya(e),a):z0(n5(e,d.format),s5(n,d.format))});return t.jsx(Rs,{label:`Download ${a}`,note:"Download as",items:[...o.map(u),"separator",...c.map(u)],trigger:t.jsxs("button",{type:"button",className:"ui-btn","data-variant":l,"aria-label":`Download ${a}`,children:["Download ",t.jsx(le,{name:"chevron-down"})]})})}function r5({attachment:e}){const n=Ly(e.mime,e.filename);return t.jsxs("div",{className:"wb-artifact","data-family":n,"data-testid":"artifact-view",children:[t.jsx(eT,{artifactId:e.artifactId,filename:e.filename??null,mime:e.mime,family:n}),t.jsxs("dl",{className:"ui-kv",children:[t.jsx("dt",{children:"Type"}),t.jsxs("dd",{children:[Ci[n],t.jsx("span",{className:"wb-artifact-mime mono",children:e.mime})]}),e.sizeBytes?t.jsxs(t.Fragment,{children:[t.jsx("dt",{children:"Size"}),t.jsx("dd",{children:ds(e.sizeBytes)})]}):null,t.jsx("dt",{children:"Id"}),t.jsx("dd",{className:"mono",children:e.artifactId})]}),t.jsx("div",{className:"ui-toolbar","data-align":"end",children:t.jsx(tT,{artifactId:e.artifactId,filename:e.filename,mime:e.mime})})]})}const U0=80,a5=["query","path","url","dir"],i5=["message","task"];function Wy(e,n){const s=l5(n);if(!s)return null;const r=ll(s.command);if(r!==null){const l=ll(s.name);return fd(l===null?r:`${l}: ${r}`)}for(const l of a5){const o=ll(s[l]);if(o!==null)return fd(o)}const a=ll(s.action);if(a!==null){const l=i5.map(o=>ll(s[o])).find(o=>o!==null)??null;return fd(l===null?a:`${a} · ${l}`)}const i=Object.values(s).filter(l=>typeof l=="string");return i.length===1?fd(ll(i[0])):null}function ll(e){if(typeof e!="string")return null;const n=e.replace(/\s+/g," ").trim();return n===""?null:n}function fd(e){return e===null?null:e.length>U0?`${e.slice(0,U0-1)}…`:e}function l5(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}const nT="owner.notify",Zr=e=>typeof e=="string"&&e.trim()!==""?e:null;function o5(e){const n=e!==null&&typeof e=="object"?e:{};return{title:Zr(n.title)??"(no title)",text:Zr(n.text),urgency:Zr(n.urgency)??"now",key:Zr(n.key),link:Zr(n.link)}}function sT(e){if(e===null||typeof e!="object")return Zr(e);const n=e;return Zr(n.delivered)??Zr(n.message)??Zr(n.error)}function c5(e,n){if(!n||!e)return"critical";const s=e.toLowerCase();return/^(refused|not sent)/.test(s)?"critical":/^sent\b/.test(s)?"good":"warning"}const u5=/^[a-z0-9](?:[a-z0-9._-]{0,94}[a-z0-9])?$/,d5=/^[a-z][a-z0-9_-]{0,63}$/;function Su(e,n,s=64){return!d5.test(e)||typeof n!="string"||!u5.test(n)||n.includes("..")?null:`/api/plugin-assets/${e}/${n}?size=${s}`}function rT(e){return typeof e=="string"&&/^\/api\/plugin-assets\/[a-z][a-z0-9_-]{0,63}\/[a-z0-9._-]+(\?size=(64|128))?$/.test(e)}function h5(e){var n,s;return((s=(n=e.match(/[\p{L}\p{N}]/u))==null?void 0:n[0])==null?void 0:s.toUpperCase())??"?"}function No({src:e,label:n,className:s}){const[r,a]=h.useState(!1),i=e!==null&&rT(e)&&!r;return t.jsx("span",{className:["pl-logo",s].filter(Boolean).join(" "),"data-letter":i?void 0:"true","aria-hidden":"true",children:i?t.jsx("img",{src:e,alt:"",loading:"lazy",decoding:"async",onError:()=>a(!0)}):h5(n)})}const Kd="news",f5="edition";function aT(e){if(!e)return null;const n=/^#\/p\/news\/stories\?(.*)$/.exec(e);if(!n)return null;const s=new URLSearchParams(n[1]).get("edition");return s&&/^[A-Za-z0-9_-]{1,40}$/.test(s)?s:null}const Lt=e=>typeof e=="string"?e:"",m5=e=>/^https?:\/\/[^\s]+$/i.test(e),B0=/^[a-z][a-z0-9_]*\.[a-z][a-z0-9_]*$/,zh=e=>e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null;function W0(e){const n=zh(e);if(!n)return null;const s={};for(const[r,a]of Object.entries(n)){const i=zh(a);if(!i||!("const"in i))return null;s[r]=i.const}return s}function p5(e){return(Array.isArray(e)?e:[]).flatMap(n=>{const s=zh(n);if(!s)return[];const r=Lt(s.label).trim(),a=Lt(s.tool),i=W0(s.args??{});if(r===""||!B0.test(a)||!i)return[];const l=zh(s.undo),o=l?W0(l.args??{}):null,c=l&&B0.test(Lt(l.tool))&&o?{tool:Lt(l.tool),label:Lt(l.label).trim()||"Undo",args:o}:null,u=Lt(s.hint).trim(),d=Lt(s.group).trim(),f=Lt(s.confirm).trim();return[{label:r,tool:a,args:i,...u?{hint:u}:{},...d?{group:d}:{},...f?{confirm:f}:{},done:Lt(s.done).trim()||"Done.",...c?{undo:c}:{}}]}).slice(0,12)}function g5(e){const n=e!==null&&typeof e=="object"?e.edition:null;if(n===null||typeof n!="object")return null;const s=n,r=(Array.isArray(s.groups)?s.groups:[]).flatMap(i=>{if(i===null||typeof i!="object")return[];const l=(Array.isArray(i.stories)?i.stories:[]).flatMap(o=>{if(o===null||typeof o!="object")return[];const c=o,u=Lt(c.title).trim();if(u==="")return[];const d=c.link!==null&&typeof c.link=="object"?c.link:null,f=d?Lt(d.url):"",m=c.mark==="update"||c.mark==="opinion"?c.mark:void 0,p=Lt(c.topicName).trim(),g=p5(c.actions);return[{...m?{mark:m,markLabel:Lt(c.markLabel)||void 0}:{},title:u,lead:Lt(c.lead),outlet:Lt(c.outlet),more:typeof c.more=="number"&&Number.isFinite(c.more)&&c.more>0?Math.floor(c.more):0,...m5(f)?{link:{url:f,label:Lt(d.label)||f}}:{},logos:(Array.isArray(c.logos)?c.logos:[]).flatMap(v=>{if(v===null||typeof v!="object")return[];const b=Lt(v.name),j=Lt(v.logo);return b?[{name:b,...j?{logo:j}:{}}]:[]}),...p?{topicName:p}:{},...g.length>0?{actions:g}:{}}]});return l.length>0?[{topic:Lt(i.topic),stories:l}]:[]});if(r.length===0)return null;const a=Lt(s.next);return{id:Lt(s.id),name:Lt(s.name)||"Edition",when:Lt(s.when),lede:Lt(s.lede),groups:r,notes:(Array.isArray(s.notes)?s.notes:[]).filter(i=>typeof i=="string"&&i.trim()!==""),.../^\d{1,2}:\d{2}$/.test(a)?{next:a}:{}}}function x5(e,n){const s=[];let r=null;return e.forEach((a,i)=>{const l=a.group??a.tool;i>0&&l!==r&&s.push("separator"),a.group&&l!==r&&s.push({heading:a.group}),r=l,s.push({label:a.label,...a.hint?{hint:a.hint}:{},onSelect:()=>n(a)})}),s}function v5({s:e}){const[n,s]=h.useState(null),r=e.logos[0]??{name:e.outlet||e.title},a=e.outlet||r.name,[i,l]=h.useState(null),o=e.actions??[],c=async f=>{try{const m=await R.pageAct(Kd,{tool:f.tool,args:f.args});s(m.approvalId?{text:"Waiting for your approval."}:{text:f.done,...f.undo?{undo:f.undo}:{}})}catch(m){s({text:m instanceof Error&&m.message?`That did not work: ${m.message}`:"That did not work."})}},u=async f=>{try{await R.pageAct(Kd,{tool:f.tool,args:f.args}),s(null)}catch{s({text:"Could not take it back. Undo it in News → Sources."})}};if(n)return t.jsxs("li",{className:"ed-story ed-story-gone",role:"status",children:[t.jsx("span",{children:n.text}),n.undo?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"pl-story-gone-sep","aria-hidden":"true",children:"·"}),t.jsx(A,{size:"sm",variant:"ghost",onClick:()=>void u(n.undo),children:n.undo.label})]}):null]});const d=[e.topicName,a?e.more>0?`${a} and ${e.more} more`:a:""].filter(Boolean).join(" · ");return t.jsxs("li",{className:"ed-story",children:[o.length>0?t.jsx("span",{className:"ed-more-btn",children:t.jsx(Rs,{label:`Ways out for ${e.title}`,items:x5(o,f=>f.confirm?l(f):void c(f)),sheet:{title:e.title,sub:d},stacked:!0})}):null,i?t.jsx(zt,{title:i.confirm??i.label,onClose:()=>l(null),foot:t.jsxs(t.Fragment,{children:[t.jsx(A,{variant:"ghost",onClick:()=>l(null),children:"Cancel"}),t.jsx(A,{variant:"accent",onClick:()=>{const f=i;l(null),c(f)},children:i.label})]})}):null,t.jsx(No,{src:r.logo?Su(Kd,r.logo):null,label:r.name,className:"pl-logo-md"}),t.jsxs("span",{className:"ed-story-text",children:[t.jsxs("span",{className:"ed-story-title",children:[e.mark?t.jsx("span",{className:"ed-mark","data-kind":e.mark==="update"?"update":void 0,children:e.mark==="update"?"Update":"Opinion"}):null,e.title]}),e.lead?t.jsx("span",{className:"ed-story-line",children:e.lead}):null,a?t.jsxs("span",{className:"ed-story-src",children:[e.link?t.jsxs("a",{className:"wb-src-link",href:e.link.url,target:"_blank",rel:"noopener noreferrer",title:e.link.label,children:[a,t.jsx("span",{className:"wb-src-out","aria-hidden":"true",children:"↗"})]}):t.jsx("span",{children:a}),e.more>0?t.jsxs("span",{className:"ed-more",children:["and ",e.more," more"]}):null]}):null]})]})}const H0=Array.from({length:64},(e,n)=>30+Math.round(Math.abs(Math.sin(n*1.7)*Math.cos(n*.4))*70));function j5({audio:e}){const{playing:n,loading:s,failed:r,position:a,duration:i,toggle:l,bind:o}=Z$(e.fileId,e.mime),c=i?Math.min(1,a/i):0,u=r?"Could not play":s?"Loading…":i===null?"Listen":n||a>0?`${mc(a)} / ${mc(i)}`:mc(i);return t.jsxs("button",{type:"button",className:"ed-audio","aria-label":n?"Pause the edition":"Listen to the edition","aria-pressed":n,disabled:s,onClick:()=>void l(),"data-testid":"edition-audio",children:[t.jsx("span",{className:"ed-play","aria-hidden":"true",children:n?t.jsxs("svg",{viewBox:"0 0 16 16",width:"12",height:"12",fill:"currentColor",children:[t.jsx("rect",{x:"4",y:"3",width:"3",height:"10",rx:"1"}),t.jsx("rect",{x:"9",y:"3",width:"3",height:"10",rx:"1"})]}):t.jsx("svg",{viewBox:"0 0 16 16",width:"12",height:"12",fill:"currentColor",children:t.jsx("path",{d:"M5 3.2v9.6c0 .5.5.8.9.5l7.2-4.8a.6.6 0 0 0 0-1L5.9 2.7c-.4-.3-.9 0-.9.5Z"})})}),t.jsx("span",{className:"ed-wave","aria-hidden":"true",children:H0.map((d,f)=>t.jsx("i",{style:{"--h":`${d}%`},"data-on":(n||a>0)&&f<Math.round(c*H0.length)?"true":void 0},f))}),t.jsx("span",{className:"ed-dur",children:u}),t.jsx("audio",{...o})]})}function y5({edition:e,audio:n}){const s=[...e.notes,`${e.next?`Next edition at ${e.next}. `:""}Tell me what to leave out, or mute anything from News.`];return t.jsxs("div",{className:"ed","data-testid":"edition-card",children:[t.jsxs("div",{className:"ed-head",children:[t.jsx("span",{className:"ed-kicker",children:e.name}),e.when?t.jsx("span",{className:"ed-when",children:e.when}):null]}),n,e.lede?t.jsx("p",{className:"ed-lede",children:e.lede}):null,e.groups.map((r,a)=>t.jsxs("section",{className:"ed-group",children:[r.topic?t.jsx("h4",{className:"ed-topic",children:r.topic}):null,t.jsx("ul",{className:"ed-list",children:r.stories.map((i,l)=>t.jsx(v5,{s:i},l))})]},a)),t.jsx("p",{className:"ed-foot",children:s.join(" ")})]})}function w5({editionId:e,text:n,audio:s,link:r}){const[a,i]=h.useState(void 0),[l,o]=h.useState(!1);h.useEffect(()=>{let u=!0;return i(void 0),R.pageQuery(Kd,f5,{id:e}).then(d=>{u&&i(g5(d.data))}).catch(()=>{u&&i(null)}),()=>{u=!1}},[e]);const c=a&&!l;return t.jsxs("div",{className:"wb-report ed-report","data-testid":"mission-report",children:[c?t.jsx("div",{className:"ed-bubble",children:t.jsx(y5,{edition:a,audio:s?t.jsx(j5,{audio:s}):null})}):a===void 0?t.jsx("div",{className:"ed-bubble","aria-busy":"true",children:t.jsx("div",{className:"ed ed-loading"})}):t.jsxs(t.Fragment,{children:[s?t.jsx(sm,{artifactId:s.fileId,name:s.filename??"Voice note",mime:s.mime,sizeBytes:s.sizeBytes}):null,n]}),t.jsxs("div",{className:"ed-actions",children:[a?t.jsx(A,{size:"sm",variant:"ghost","aria-pressed":l,onClick:()=>o(!l),children:l?"Show as card":"Show as text"}):null,t.jsx(ht,{className:"wb-report-link",size:"sm",href:r.route,children:r.label})]})]})}const b5="mission.report",ol=e=>typeof e=="string"&&e.trim()!==""?e.trim():null,k5=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function N5(e,n){const s=e!==null&&typeof e=="object"?e:{},r=n!==null&&typeof n=="object"?n:{},a=ol(r.link),i=r.audio!==null&&typeof r.audio=="object"?r.audio:null,l=i?ol(i.fileId):null,o=i?ol(i.mime):null;return{text:ol(s.text),link:a&&a.startsWith("#/")?{route:a,label:ol(r.linkLabel)??"Open"}:null,audio:l&&k5.test(l)&&o&&By(o)?{fileId:l,mime:o,filename:i?ol(i.filename):null,sizeBytes:i&&typeof i.sizeBytes=="number"?i.sizeBytes:null}:null}}function S5(e){return!!(e.text&&e.link&&aT(e.link.route))}function K0({view:e}){var a;if(!e.text&&!e.audio)return null;const n=e.audio?t.jsx(sm,{artifactId:e.audio.fileId,name:e.audio.filename??"Voice note",mime:e.audio.mime,sizeBytes:e.audio.sizeBytes}):null,s=e.text?t.jsx("div",{className:"wb-bubble","data-rich":"true",children:t.jsx(ur,{text:e.text})}):null,r=aT((a=e.link)==null?void 0:a.route);return r&&e.link&&e.text?t.jsx(w5,{editionId:r,text:s,audio:e.audio,link:e.link}):t.jsxs("div",{className:"wb-report","data-testid":"mission-report",children:[n,s,e.link?t.jsx("a",{className:"ui-btn wb-report-link","data-size":"sm",href:e.link.route,children:e.link.label}):null]})}const Ja="agent.delegate";function C5(e){if(e===null||typeof e!="object")return null;const n=e,s=n.conversationId;if(typeof s!="string"||s==="")return null;const r=n.agentId??n.agent;return{conversationId:s,agentId:typeof r=="string"?r:"",runId:typeof n.runId=="string"?n.runId:null}}function E5(e){if(typeof e=="string")return e;if(e===null||typeof e!="object")return null;const n=e.text;return typeof n=="string"?n:null}const Vx="canvas.show",V0="canvas.clear",G0=12;function A5(e){return`sources:${e}`}function $5(e){return e.role==="user"&&(e.blocks??[]).some(n=>n.type==="text"&&n.text.trim()!=="")}function Ll(e){return`${e.plugin}/${e.name}`}function T5(e){if(e===null||typeof e!="object"||Array.isArray(e))return!1;const n=e.diff;return typeof n=="string"&&n.trim()!==""}function R5({messages:e,descriptors:n}){const s=new Map(n.filter(i=>i.renderer==="preview").map(i=>[i.tool,i]));if(s.size===0)return[];const r=new Map,a=[];for(const i of e)for(const l of i.blocks??[]){if(l.type==="tool_use"&&r.set(l.id,l.name),l.type!=="tool_result"||l.ok===!1)continue;const o=s.get(l.name||r.get(l.toolUseId)||"");if(!o)continue;const c=N$(o,Gx(l.output)).props;c.target===null&&c.awaiting!==null&&a.push({...c.awaiting,at:i.at??null})}return a}function iT({messages:e,descriptors:n,awaiting:s,folded:r,served:a,gathered:i}){var m;const l=new Map(n.map(p=>[p.tool,p])),o=new Map;let c=[],u=0,d=null;const f=p=>{d||(d={id:A5(p.id),tool:p.tool,title:"Sources",renderer:"sources",source:"sources",props:{entries:[]},at:p.at,substantial:!1,count:0},c.push(d));const g=d.props,v=g.entries.some(j=>j.id===p.id)?g.entries.map(j=>j.id===p.id?{...p,input:p.input??j.input}:j):[...g.entries,p],b=[...new Set(v.map(j=>j.tool))];d.props={entries:v},d.tool=b.join(" · "),d.count=v.length,d.substantial=v.some(j=>j.ok===!0),d.tone=v.every(j=>j.ok===!1)?"critical":void 0};for(const p of e){$5(p)&&(d=null);for(const g of p.blocks??[]){if(g.type==="tool_use"){if(o.set(g.id,{name:g.name,input:g.input,at:p.at??null}),i!=null&&i.has(g.name)){f({id:g.id,tool:g.name,input:g.input,output:null,ok:null,at:p.at??null});continue}if(g.name===Vx){const S=P5(g.id,g.input,p.at??null);S&&c.push(S)}if(g.name===V0&&(c=[],d=null),g.name===Ja){const S=C5(g.input);S&&c.push({id:g.id,tool:Ja,title:"Delegation",renderer:"delegate",props:{...S,result:null},at:p.at??null,source:"delegate",substantial:!0})}continue}if(g.type!=="tool_result"||g.name===Vx||g.name===V0)continue;const v=o.get(g.toolUseId),b=p.at??(v==null?void 0:v.at)??null,j=g.name||(v==null?void 0:v.name)||"tool",x=c.find(S=>S.source==="delegate"&&S.id===g.toolUseId);if(x&&((m=g.delegation)==null?void 0:m.state)==="waiting"){x.props={...x.props,result:null,waiting:{approvalId:g.delegation.approvalId}},g.delegation.approvalId&&(x.tone="warning");continue}if(x){x.props={...x.props,result:{ok:g.ok,text:E5(g.ok?g.output:g.error??g.output),...g.ok&&Ph(g.output).length>0?{files:Ph(g.output)}:{}}},g.ok||(x.tone="critical");continue}const y=g.approval?Yx(g):(s==null?void 0:s.get(g.toolUseId))??Yx(g);if(y){c.push({id:g.toolUseId,tool:j,title:"Approval",renderer:"envelope",props:{approvalId:y},at:b,tone:"warning",source:"approval",substantial:!0});continue}if(r!=null&&r.has(j))continue;if(i!=null&&i.has(j)){f({id:g.toolUseId,tool:j,input:(v==null?void 0:v.input)??null,output:Gx(g.output)??null,ok:g.ok!==!1,...g.error===void 0?{}:{error:g.error},at:b});continue}if(j===nT){c.push({id:g.toolUseId,tool:j,title:"Message to you",renderer:"notify",props:{input:(v==null?void 0:v.input)??null,output:g.output??null,ok:g.ok!==!1},at:b,tone:g.ok===!1?"critical":void 0,source:"notify",substantial:!1});continue}const w=Gx(g.output);if(g.ok===!1){c.push({id:g.toolUseId,tool:j,title:Tr(j),renderer:"structured",props:{value:g.error??w??null,failed:!0},at:b,tone:"critical",source:"fallback",substantial:!1});continue}T5(w)&&(u+=1);const k=l.get(j);if(k){const S=N$(k,w),{renderer:C}=S;let{props:E}=S;if(C==="preview"){const T=E,I=T.target??(T.awaiting&&(a!=null&&a.has(Ll(T.awaiting)))?T.awaiting:null);if(I===null)continue;E={...T,target:I,awaiting:null};const F=Ll(I);c=c.filter(D=>!(D.source==="descriptor"&&D.renderer==="preview"&&D.props.target!==null&&Ll(D.props.target)===F))}c.push({id:g.toolUseId,tool:j,title:k.title??Tr(j),renderer:C,props:E,at:b,source:"descriptor",substantial:qx(C,E)});continue}const N={value:_y(w)?{input:v==null?void 0:v.input,output:w}:w};M5("structured",N)&&c.push({id:g.toolUseId,tool:j,title:Tr(j),renderer:"structured",props:N,at:b,source:"fallback",substantial:qx("structured",N)})}}for(const p of c)p.source==="descriptor"&&p.renderer==="preview"&&(p.props={...p.props,changes:u});return I5(c)}const q0="forAgent";function Gx(e){if(e===null||typeof e!="object"||Array.isArray(e)||!(q0 in e))return e;const{[q0]:n,...s}=e;return s}function I5(e){if(e.length<=G0)return e;const n=e.length-G0;return[...e.slice(0,n).filter(r=>r.source==="approval"),...e.slice(n)]}function P5(e,n,s){if(n===null||typeof n!="object")return null;const{renderer:r,title:a,data:i}=n,l=typeof r=="string"&&Fh(r)?r:"structured";return{id:e,tool:Vx,title:typeof a=="string"&&a.trim()!==""?a:"Shown",renderer:l,props:l==="structured"&&!Fh(String(r))?{value:i}:i,at:s,substantial:!0,source:"canvas"}}function M5(e,n){const s=n??{};return!!(s.failed===!0||qx(e,n)||Fy(s.value).kind==="error")}function qx(e,n){const s=n??{};switch(e){case"timeseries":return Ko(s.points)>0;case"bars":return Ko(s.bars)>0;case"keyvalue":return Ko(s.pairs)>0;case"tiles":return s.notice!==!0&&Ko(s.tiles)>0;case"document":return!!s.text||!!s.src;case"diff":return!!s.diff;case"terminal":return!!s.output||!!s.command;case"image":return!!s.artifactId;case"preview":return!!s.target;case"envelope":return!0;case"table":return(Array.isArray(s.groups)?s.groups:[]).some(a=>Ko(a.rows)>0);default:return _y(s.value)?!0:s.failed===!0?!1:sB(s.value)}}function Ko(e){return Array.isArray(e)?e.length:0}function Yx(e){if(e.approval)return e.approval.state==="pending"?e.approval.id:null;for(const n of[e.error,e.output]){const s=oT(n,0);if(s)return s}return null}function D5(e,n,s={}){var o,c;const r=e.flatMap(u=>u.blocks),a=r.find(u=>u.type==="tool_use"&&u.id===n);if((a==null?void 0:a.type)!=="tool_use")return null;const i=r.find(u=>u.type==="tool_result"&&u.toolUseId===n),l=(o=s.redactInputOf)!=null&&o.has(a.name)?lT(a.input):a.input;return{id:n,tool:a.name,title:Tr(a.name),renderer:"structured",props:{value:{input:l,...(i==null?void 0:i.type)==="tool_result"?{status:((c=i.approval)==null?void 0:c.state)??(i.ok?"completed":"failed"),output:i.output,...i.error?{error:i.error}:{}}:{status:"Awaiting result"}}},at:null,source:"fallback",substantial:!1}}const O5=new Set(["value","text","password","secret","code"]);function lT(e){if(e===null||typeof e!="object"||Array.isArray(e))return e;const n={};for(const[s,r]of Object.entries(e))n[s]=O5.has(s)&&typeof r=="string"?"— withheld —":lT(r);return n}function oT(e,n){if(n>3||e===null||typeof e!="object")return null;const s=e,r=s.reason,a=s.actionId??s.approvalId;if(typeof a=="string"&&a!==""&&(r===void 0||r==="approval-required"))return a;for(const i of Object.values(s)){const l=oT(i,n+1);if(l)return l}return null}function Tr(e){const n=e.split(".");return n.length===1?_n(e):n.map(s=>_n(s)).join(" · ")}function Y0(e,n){return e.find(s=>s.source==="sources"&&s.props.entries.some(r=>r.id===n))??null}function rm({name:e,mime:n,sizeBytes:s,thumbnail:r,state:a,error:i,onOpen:l,onRemove:o,size:c="md",detail:u}){const d=Ly(n,e),f=u??[Ci[d],ds(s)].filter(Boolean).join(" · "),m=t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"wb-file-visual","data-family":d,children:r?t.jsx("img",{src:r,alt:""}):t.jsx(Hy,{family:d})}),t.jsxs("span",{className:"wb-file-text",children:[t.jsx("span",{className:"wb-file-name",title:e,children:e}),t.jsx("span",{className:"wb-file-meta",children:a==="uploading"?"Uploading…":a==="failed"?"Upload failed":f})]})]});return t.jsxs("span",{className:"wb-file","data-size":c,"data-state":a,"data-thumb":r?"true":void 0,title:a==="failed"?i:void 0,children:[l?t.jsx("button",{type:"button",className:"wb-file-open",onClick:l,"aria-label":`Open ${e}`,children:m}):t.jsx("span",{className:"wb-file-open",children:m}),o?t.jsx("button",{type:"button",className:"wb-file-x","aria-label":`Remove ${e}`,onClick:o,children:t.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10","aria-hidden":"true",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",children:t.jsx("path",{d:"M2.5 2.5l5 5M7.5 2.5l-5 5"})})}):null]})}function Hy({family:e}){const n={width:20,height:20,viewBox:"0 0 20 20","aria-hidden":!0,fill:"none",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round"};switch(e){case"image":return t.jsxs("svg",{...n,children:[t.jsx("rect",{x:"3",y:"4",width:"14",height:"12",rx:"2"}),t.jsx("circle",{cx:"7.5",cy:"8.5",r:"1.4"}),t.jsx("path",{d:"M17 13l-3.6-3.6a1 1 0 0 0-1.4 0L6 15.5"})]});case"pdf":return t.jsxs("svg",{...n,children:[t.jsx("path",{d:"M6 2.5h5.5L16 7v9.5a1 1 0 0 1-1 1H6a1 1 0 0 1-1-1v-13a1 1 0 0 1 1-1z"}),t.jsx("path",{d:"M11.5 2.5V7H16"}),t.jsx("path",{d:"M7.5 13.5h5M7.5 11h5"})]});case"table":return t.jsxs("svg",{...n,children:[t.jsx("rect",{x:"3",y:"4",width:"14",height:"12",rx:"1.5"}),t.jsx("path",{d:"M3 8.5h14M3 12.5h14M8 4v12M13 4v12"})]});case"text":return t.jsxs("svg",{...n,children:[t.jsx("path",{d:"M6 2.5h5.5L16 7v9.5a1 1 0 0 1-1 1H6a1 1 0 0 1-1-1v-13a1 1 0 0 1 1-1z"}),t.jsx("path",{d:"M11.5 2.5V7H16"}),t.jsx("path",{d:"M7.5 10.5h5M7.5 13.5h3.5"})]});case"code":return t.jsx("svg",{...n,children:t.jsx("path",{d:"M7 6l-4 4 4 4M13 6l4 4-4 4M11.5 4l-3 12"})});case"audio":return t.jsx("svg",{...n,children:t.jsx("path",{d:"M4 8v4M7.5 5.5v9M11 3.5v13M14.5 6.5v7M18 8.5v3"})});case"video":return t.jsxs("svg",{...n,children:[t.jsx("rect",{x:"3",y:"5",width:"10",height:"10",rx:"1.5"}),t.jsx("path",{d:"M13 9l4-2.5v7L13 11"})]});case"archive":return t.jsxs("svg",{...n,children:[t.jsx("rect",{x:"4",y:"3",width:"12",height:"14",rx:"1.5"}),t.jsx("path",{d:"M10 3v3M10 8v2M10 12v2M8.5 14h3"})]});default:return t.jsxs("svg",{...n,children:[t.jsx("path",{d:"M6 2.5h5.5L16 7v9.5a1 1 0 0 1-1 1H6a1 1 0 0 1-1-1v-13a1 1 0 0 1 1-1z"}),t.jsx("path",{d:"M11.5 2.5V7H16"})]})}}function L5(e,n,s){const r=Q0(e),a=Q0(n==null?void 0:n.input),i=fi(r==null?void 0:r.name)??B5(fi(r==null?void 0:r.handle))??fi(r==null?void 0:r.agent)??fi(a==null?void 0:a.agent),l=typeof e=="string"?e.trim()||null:fi(r==null?void 0:r.text)??fi(r==null?void 0:r.note),o=J0(r==null?void 0:r.durationMs)??J0(r==null?void 0:r.elapsedMs),c=n!=null&&n.at?Date.parse(n.at):NaN,u=s?Date.parse(s):NaN,d=Number.isFinite(c)&&Number.isFinite(u)&&u>=c?u-c:null;return{who:i,question:fi(a==null?void 0:a.task),answer:l,files:Ph(e),durationMs:o??d}}function F5(e,n){var r;let s=null;for(const a of e)for(const i of a.blocks??[])i.type==="tool_result"&&i.name===Ja&&((r=i.delegation)==null?void 0:r.approvalId)===n&&(s=i.toolUseId);if(s===null)return null;for(const a of e)for(const i of a.blocks??[])if(i.type==="tool_use"&&i.id===s)return{input:i.input,at:a.at||null};return null}function _5({block:e,messages:n,answeredAt:s}){const r=L5(e.output,F5(n,e.actionId),s),a=[r.who?`Asked ${r.who}`:null,r.durationMs===null?null:`took ${z5(r.durationMs)}`].filter(i=>i!==null);return t.jsxs("div",{className:"wb-delegation-result","data-testid":"delegation-result",children:[a.length>0?t.jsx("p",{className:"wb-delegation-facts",children:a.join(" · ")}):null,r.question?t.jsx("blockquote",{className:"wb-delegation-question",children:r.question}):null,r.answer?t.jsx("div",{className:"wb-delegation-answer","data-testid":"delegation-answer",children:t.jsx(ur,{text:r.answer})}):t.jsx("p",{className:"wb-delegation-facts",children:"No answer came back."}),r.files.length>0?t.jsx("div",{className:"wb-msg-files",role:"list","aria-label":`Files ${r.who??"the colleague"} made`,children:r.files.map(i=>t.jsx("a",{role:"listitem",href:Ya(i.artifactId),download:!0,children:t.jsx(rm,{name:i.filename??"Untitled file",mime:i.mime,sizeBytes:i.sizeBytes,thumbnail:Oy(i.mime)?_r(i.artifactId):null,size:"sm"})},i.artifactId))}):null,t.jsx(Ot,{summary:"Raw JSON",children:t.jsx("pre",{className:"wb-approval-output mono",children:U5(e.output)})})]})}function z5(e){if(e<1e3)return`${Math.round(e)}ms`;const n=Math.round(e/1e3);if(n<60)return`${n}s`;const s=Math.floor(n/60);return s<60?`${s}m ${String(n%60).padStart(2,"0")}s`:`${Math.floor(s/60)}h ${String(s%60).padStart(2,"0")}m`}function U5(e){if(typeof e=="string")return e;try{return JSON.stringify(e,null,2)??"null"}catch{return String(e)}}function B5(e){return e===null?null:`@${e.replace(/^@/,"")}`}function fi(e){return typeof e=="string"&&e.trim()!==""?e:null}function J0(e){return typeof e=="number"&&Number.isFinite(e)?e:null}function Q0(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}const W5=1e3;function H5({messageId:e,text:n,onReadAloud:s}){const[r,a]=h.useState(!1),i=h.useRef(null),l=h.useSyncExternalStore(YB,qB)===e;h.useEffect(()=>()=>{i.current&&clearTimeout(i.current)},[]);const o=()=>{var c;(c=navigator.clipboard)==null||c.writeText(n).then(()=>{a(!0),i.current&&clearTimeout(i.current),i.current=setTimeout(()=>a(!1),W5)},()=>{})};return t.jsxs("div",{className:"wb-reply-actions","data-testid":"reply-actions",children:[t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":r?"Copied":"Copy",title:r?"Copied":"Copy",onClick:o,children:t.jsx(le,{name:r?"check":"copy",size:14})}),r?t.jsx("span",{className:"wb-reply-copied",role:"status",children:"Copied"}):null,s?t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":l?"Stop reading aloud":"Read aloud",title:l?"Stop reading aloud":"Read aloud","aria-pressed":l,onClick:()=>l?ko():s(e,n),children:t.jsx(le,{name:l?"stop":"play",size:14})}):null]})}function K5(e){const n=V5(e);if(!n)return null;const s=kp(n.diff);if(s!==null)return{kind:"diff",diff:s};const r=kp(n.command),a=kp(n.plain),i=Np(n.exitCode);return r!==null&&(a!==null||i!==null||Np(n.pid)!==null)?{kind:"command",command:r,output:a,exitCode:i,elapsedMs:Np(n.elapsedMs)}:null}function kp(e){return typeof e=="string"&&e.trim()!==""?e:null}function Np(e){return typeof e=="number"&&Number.isFinite(e)?e:null}function V5(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}const X0="offer:",cT="owner:interjection";function G5(e){return e===cT}function q5(e){if(typeof e!="string"||!e.startsWith(X0))return null;const n=e.slice(X0.length).trim();return n===""?null:n}const Z0="brief:";function Y5(e){if(typeof e!="string"||!e.startsWith(Z0))return null;const n=e.slice(Z0.length).trim();return n===""?null:n}function Ky({messages:e,live:n,now:s,onOpen:r,working:a=!1,partial:i=null,agents:l,agentId:o,speakers:c,coordinatorId:u,workingAs:d,onOpenFile:f,onReadAloud:m,children:p,agentName:g,emptyHint:v,empty:b,plain:j=!1,workingLine:x,runs:y,onContinue:w}){var K;const k=h.useRef(null);h.useEffect(()=>{var ee;(ee=k.current)==null||ee.scrollIntoView({block:"end"})},[e.length,n.length,a,i==null?void 0:i.text.length,i==null?void 0:i.thinking.length,!!p]);const N=i&&!i.settled&&(i.text!==""||i.thinking!==""),S=e.filter(ee=>(ee.blocks??[]).some(l8)).map(uT),C=a8(S,y??[]),E=c??l??[],T=ee=>(o&&!c?E.find(ce=>ce.id===o):void 0)??E.find(ce=>ce.name===ee)??null,I=o?E.find(ee=>ee.id===o)??null:null,F=a||n.length>0,D=F||!!N,$=!!N&&i.text!=="",L=F&&!$,O=S.at(-1),M=(O==null?void 0:O.role)!=="assistant"||!!d,P=d??g??"Assistant",H=S.filter((ee,ce)=>{var pe;return ce===0||(c?(((pe=S[ce-1])==null?void 0:pe.speaker)??null)!==(ee.speaker??null):S[ce-1].role!==ee.role)}),U=D&&!M?((K=H.at(-1))==null?void 0:K.id)??null:null,V=(y??[]).reduce((ee,ce)=>ee===null||(ce.startedAt??"")>(ee.startedAt??"")?ce:ee,null),z=(y??[]).some(ee=>ee.finishedAt===null),X=w&&!D&&!z&&O&&(V==null?void 0:V.stopped)==="max_turns"&&C.get(O.id)===V?O.id:null;return t.jsx(w$.Provider,{value:l??c??[],children:t.jsxs("div",{className:"wb-messages","data-testid":"messages",children:[S.length===0&&n.length===0?b??t.jsx("p",{className:"wb-chat-empty",children:v}):null,S.map((ee,ce)=>{const pe=ee.speaker??null,oe=c?pe==="owner"||pe===null&&ee.role==="user":ee.role==="user",Re=c&&pe==="room",Oe=c&&pe&&pe!=="owner"&&pe!=="room"?c.find(de=>de.id===pe)??null:null,Je=S[ce-1],W=ce===0||(c?((Je==null?void 0:Je.speaker)??null)!==pe:Je.role!==ee.role);if(Re)return t.jsx("div",{className:"wb-msg wb-msg-room","data-role":"room",children:(ee.blocks??[]).filter(de=>de.type==="text").map((de,ke)=>t.jsx("span",{children:de.text},ke))},ee.id);const se=(ee.blocks??[]).filter(de=>de.type==="approval_result");if(se.length>0)return t.jsx("div",{className:"wb-msg","data-role":"assistant","data-testid":"approval-result",children:se.map((de,ke)=>t.jsx(o8,{block:de,messages:e,at:ee.at||null},ke))},ee.id);const Y=ee.role==="user"&&G5(pe),Ne=ee.role==="user"?Y5(pe):null;if(Ne)return t.jsx("div",{className:"wb-msg","data-role":"user","data-testid":"offer-turn",children:t.jsx("div",{className:"wb-bubble wb-bubble-offer",children:Ne})},ee.id);const we=ee.role==="user"?q5(pe):null;if(we){const de=(ee.blocks??[]).filter(ke=>ke.type==="text").map(ke=>ke.text).join(`
105
- `);return t.jsx("div",{className:"wb-msg","data-role":"user","data-testid":"offer-turn",children:t.jsx("div",{className:"wb-bubble wb-bubble-offer",title:de,children:we})},ee.id)}const fe=c&&Oe&&ee.role==="user"?t8(ee):null;if(fe){const de=S.slice(ce+1).find(Be=>Be.role==="assistant"&&Be.speaker&&Be.speaker!==Oe.id),ke=de!=null&&de.speaker?c.find(Be=>Be.id===de.speaker):void 0;return t.jsxs("details",{className:"wb-msg wb-msg-room wb-msg-ask","data-role":"room",children:[t.jsxs("summary",{children:[Oe.name," asked ",(ke==null?void 0:ke.name)??"a member",fe.request?`: ${fe.request.length>120?`${fe.request.slice(0,119)}…`:fe.request}`:""]}),fe.request?t.jsx("p",{children:fe.request}):null]},ee.id)}const ge=C.get(ee.id)??null,Pe=r8(ee,e),je=!oe&&!Y&&!j?s8(ee):"";return t.jsxs("div",{className:"wb-msg","data-role":oe||Y?"user":"assistant",children:[Y?t.jsx("div",{className:"wb-msg-added","data-testid":"added-while-working",children:"added while working"}):null,W&&!oe&&!Y?t.jsx(eN,{name:Oe?Oe.name:c&&pe&&pe!=="owner"&&pe!=="room"?pe:g??"Assistant",face:Oe??I??T(g),moving:L&&U===ee.id,children:Oe&&u===Oe.id?t.jsx("span",{className:"wb-msg-role",children:"coordinator"}):null}):null,Pe.length>0?t.jsx("div",{className:"wb-msg-files",role:"list","aria-label":"Files sent with this message",children:Pe.map(de=>t.jsx("span",{role:"listitem",children:By(de.mime)?t.jsx(sm,{artifactId:de.artifactId,name:de.filename??"Untitled file",mime:de.mime,sizeBytes:de.sizeBytes}):t.jsx(rm,{name:de.filename??"Untitled file",mime:de.mime,sizeBytes:de.sizeBytes,thumbnail:Oy(de.mime)?_r(de.artifactId):null,...f?{onOpen:()=>f(de)}:{}})},de.artifactId))}):null,(ee.blocks??[]).map((de,ke)=>{const Be=X5(ee.blocks??[],ke,e);if(Be==="inside")return null;if(Be)return t.jsx(Z5,{refusals:Be.refusals},ke);if(de.type==="thinking")return j||de.text.trim()===""?null:t.jsx(Jx,{text:de.text},ke);if(de.type==="text")return de.text.trim()===""?null:oe?t.jsx("div",{className:"wb-bubble",children:de.text},ke):t.jsx("div",{className:"wb-bubble","data-rich":"true",children:t.jsx(ur,{text:de.text})},ke);if(de.type==="attachment")return null;if(de.type==="tool_use"){if(j)return null;const Ue=Vy(e,de.id),ut=Ue?d8(Ue):null,dt=!ut&&de.name===nT&&Ue?sT(Ue.output):null,Q=!ut&&de.name===b5&&(Ue!=null&&Ue.ok)?N5(de.input,Ue.output):null;return Q&&S5(Q)?t.jsx(K0,{view:Q},ke):t.jsxs(h.Fragment,{children:[t.jsx(Qx,{label:ut&&!(Ue!=null&&Ue.delegation)?`Approval · ${de.name}`:Tr(de.name),tool:de.name,ok:(Ue==null?void 0:Ue.ok)??null,running:Ue===null,...ut?{status:ut.status,waiting:ut.waiting,approval:!0}:dt?{status:dt}:{},gist:Wy(de.name,de.input),body:Ue?K5(Ue.output):null,opens:!0,onOpen:()=>r(de.id)},ke),Q?t.jsx(K0,{view:Q}):null]},ke)}return null}),ge?t.jsxs("div",{className:"wb-msg-budget","data-testid":"budget-stop",children:[t.jsx("span",{children:i8(ge)}),X===ee.id?t.jsx(A,{size:"sm",className:"wb-msg-budget-continue","data-testid":"budget-continue",onClick:w,children:"Continue"}):null]}):null,ee.feedback&&!oe&&!Y?t.jsx(m8,{feedback:ee.feedback}):null,je!==""?t.jsx(H5,{messageId:ee.id,text:je,onReadAloud:m}):null]},ee.id)}),D?t.jsxs("div",{className:"wb-msg","data-role":"assistant","data-testid":"live-turn",children:[M?t.jsx(eN,{name:P,face:T(P)??I,moving:L}):null,N&&i.thinking!==""&&!j?t.jsx(Jx,{text:i.thinking,live:i.text==="",seconds:e8(i.thinkingStartedAt,i.textStartedAt??s)}):null,$?t.jsxs("div",{className:"wb-bubble","data-live":"true","data-rich":"true",children:[t.jsx(ur,{text:i.text}),t.jsx("span",{className:"wb-caret","aria-hidden":"true"})]}):null,a&&n.length===0&&!N?t.jsxs("span",{className:"wb-working",role:"status","aria-live":"polite","data-testid":"working",children:[x??`${d??g??"The agent"} is working`,t.jsxs("span",{className:"wb-dots","aria-hidden":"true",children:[t.jsx("i",{}),t.jsx("i",{}),t.jsx("i",{})]})]}):null,n.map(ee=>t.jsx(Qx,{label:Tr(ee.name),tool:ee.name,ok:null,running:!0,elapsed:Math.max(0,Math.round((s-ee.startedAt)/1e3)),opens:!1,onOpen:()=>r(ee.toolUseId)},ee.toolUseId))]}):null,p,t.jsx("div",{ref:k})]})})}function eN({name:e,face:n,moving:s=!1,children:r}){const a=(n==null?void 0:n.picture)??null,i=v$(s?a:null);return t.jsxs("div",{className:"wb-msg-who","data-testid":"turn-head",children:[t.jsx("span",{className:"wb-msg-mark","data-moving":s?i&&a?"blob":"ring":void 0,children:s&&i&&a?t.jsx(ku,{state:"working",size:"sm",still:a,className:"wb-msg-blob"}):t.jsx(Nn,{id:(n==null?void 0:n.id)??e,name:(n==null?void 0:n.name)??e,unavailable:n?!n.available:!1,...n?{face:n}:{}})}),t.jsx("span",{children:e}),r]})}function J5(e){var n,s;return((s=(n=/ may delegate to ([^;]*);/.exec(e)??/\(allowed: ([^)]*)\)/.exec(e))==null?void 0:n[1])==null?void 0:s.trim())||null}const Q5="delegation refused:";function X5(e,n,s){const r=i=>{const l=e[i];if(!l||l.type!=="tool_use"||l.name!==Ja)return null;const o=Vy(s,l.id);if(!o||o.ok!==!1)return null;const c=typeof o.error=="string"?o.error:String(o.error??"");if(!c.trimStart().startsWith(Q5))return null;const u=l.input??{};return{target:typeof u.agent=="string"&&u.agent!==""?u.agent:"a colleague",message:c}};if(!r(n))return null;if(r(n-1))return"inside";const a=[];for(let i=n;;i+=1){const l=r(i);if(!l)break;a.push(l)}return a.length<2?null:{refusals:a}}function Z5({refusals:e}){const[n,s]=h.useState(!1),r=e.map(o=>J5(o.message)).find(o=>o!==null)??null,a=e.map(o=>o.target),i=a.slice(0,3),l=`Delegation refused ${e.length} times: ${i.join(", ")}${a.length>i.length?", …":""}`+(r?` (allowed: ${r})`:"");return t.jsxs("div",{className:"wb-refusals","data-testid":"delegation-refusals","data-open":n||void 0,children:[t.jsxs("button",{type:"button",className:"wb-tool","data-ok":!1,"aria-expanded":n,onClick:()=>s(o=>!o),children:[t.jsx("span",{className:"wb-tool-mark","data-ok":"false","aria-hidden":"true"}),t.jsx("span",{className:"wb-tool-label",children:l}),t.jsx(le,{name:"arrow",className:"wb-tool-arrow"})]}),n?t.jsx("div",{className:"wb-refusals-list",children:e.map((o,c)=>t.jsxs("div",{className:"wb-refusal",children:[t.jsxs("span",{className:"wb-tool","data-static":"true","data-ok":!1,children:[t.jsx("span",{className:"wb-tool-mark","data-ok":"false","aria-hidden":"true"}),t.jsxs("span",{className:"wb-tool-label",children:[Tr(Ja)," · ",o.target]}),t.jsx("span",{className:"wb-tool-elapsed",children:"refused"})]}),t.jsx("p",{className:"wb-refusal-why",children:o.message})]},c))}):null]})}function e8(e,n){return e===null?null:Math.max(0,Math.round((n-e)/1e3))}function Jx({text:e,live:n=!1,seconds:s=null}){const[r,a]=h.useState(!1),i=n?`Thinking${s!==null&&s>0?` · ${s}s`:""}`:s!==null&&s>0?`Thought for ${s}s`:"Thoughts";return t.jsxs("div",{className:"wb-thought","data-live":n||void 0,"data-open":r||void 0,children:[t.jsxs("button",{type:"button",className:"wb-thought-toggle","aria-expanded":r,onClick:()=>a(l=>!l),children:[n?t.jsxs("span",{className:"wb-dots","aria-hidden":"true",children:[t.jsx("i",{}),t.jsx("i",{}),t.jsx("i",{})]}):t.jsx(le,{name:"thought"}),t.jsx("span",{children:i}),t.jsx(le,{name:"arrow",className:"wb-tool-arrow"})]}),r?t.jsx("div",{className:"wb-thought-text",children:t.jsx(ur,{text:e})}):null]})}function t8(e){var r;const n=((r=(e.blocks??[]).find(a=>a.type==="text"))==null?void 0:r.text)??"",s=/You are a member of the group "[^"]*"\. @([\w-]+), the coordinator, asks you now:\n\n([\s\S]*?)(?:\n\nAnswer for the room|$)/.exec(n);return s?{handle:s[1],request:s[2].trim()}:null}function uT(e){const n=e.blocks??[];if(e.role!=="assistant"||n.length<2)return e;const s=[];let r=!1;for(const a of n){const i=s[s.length-1];a.type==="text"&&(i==null?void 0:i.type)==="text"?(s[s.length-1]={...i,text:i.text+n8(i.text,a.text)+a.text},r=!0):s.push(a)}return r?{...e,blocks:s}:e}function n8(e,n){return e===""||n===""||/\s$/.test(e)||/^\s/.test(n)||/^[.,;:!?)\]}»”’'"]/.test(n)?"":/[.!?:…)"”»]$/.test(e)?`
106
-
107
- `:""}function s8(e){return(uT(e).blocks??[]).filter(n=>n.type==="text").map(n=>n.text.trim()).filter(n=>n!=="").join(`
108
-
109
- `)}function r8(e,n){const s=[],r=new Set,a=i=>{r.has(i.artifactId)||(r.add(i.artifactId),s.push(i))};for(const i of e.blocks??[])if(i.type==="attachment"&&a(i),i.type==="tool_use"&&i.name===Ja){const l=Vy(n,i.id);l!=null&&l.ok&&Ph(l.output).forEach(a)}return s}function a8(e,n){const s=n.filter(l=>l.startedAt!==null&&l.finishedAt!==null),r=(l,o)=>o.at!==""&&o.at>=l.startedAt&&o.at<=l.finishedAt,a=(l,o)=>l!==o&&l.startedAt>=o.startedAt&&l.finishedAt<=o.finishedAt&&(l.startedAt>o.startedAt||l.finishedAt<o.finishedAt),i=new Map;for(const l of s){if(l.stopped!=="max_turns"&&l.stopped!=="max_tokens"||l.noticed!==!0||l.runId===null)continue;let o=null;for(const c of e)c.role!=="assistant"||!r(l,c)||(o=c);o===null||s.some(c=>a(c,l)&&r(c,o))||i.has(o.id)||i.set(o.id,l)}return i}function i8(e){if(e.stopped==="max_tokens")return"Length limit reached · answer cut off";const n=e.turns;return n===null?"Turn budget reached":`Turn budget reached · ${n} ${n===1?"step":"steps"}`}function l8(e){return e.type==="text"||e.type==="thinking"?e.text.trim()!=="":e.type==="tool_use"||e.type==="attachment"||e.type==="approval_result"}function o8({block:e,messages:n,at:s}){const[r,a]=h.useState(!1),i=e.state==="succeeded";return t.jsxs("div",{className:"wb-approval","data-open":r||void 0,children:[t.jsxs("button",{type:"button",className:"wb-tool","data-ok":i,"aria-expanded":r,onClick:()=>a(l=>!l),children:[t.jsx("span",{className:"wb-tool-mark","data-ok":i?"true":"false","aria-hidden":"true"}),t.jsx("span",{className:"wb-tool-label",children:e.name===""?"Approved action":Tr(e.name)}),t.jsx("span",{className:"wb-tool-elapsed",children:e.state}),t.jsx(le,{name:"arrow",className:"wb-tool-arrow"})]}),r&&e.name===Ja?t.jsx(_5,{block:e,messages:n,answeredAt:s}):null,r&&e.name!==Ja?t.jsx("pre",{className:"wb-approval-output mono",children:c8(e.output)}):null]})}function c8(e){if(typeof e=="string")return e;try{return JSON.stringify(e,null,2)??"null"}catch{return String(e)}}const u8=40;function d8(e){var s,r;if(((s=e.delegation)==null?void 0:s.state)==="waiting")return{status:e.delegation.approvalId?"waiting for your approval":"running",waiting:!0};if(Yx(e))return{status:"waiting",waiting:!0};const n=(r=e.approval)==null?void 0:r.state;return n?n==="approved"||n==="executing"?{status:"approved",waiting:!0}:n==="succeeded"?{status:"approved",waiting:!1}:{status:n,waiting:!1}:null}function Qx({label:e,tool:n,ok:s,running:r,elapsed:a,opens:i,onOpen:l,status:o,waiting:c=!1,approval:u=!1,gist:d=null,body:f=null}){const[m,p]=h.useState(!1),g=t.jsxs(t.Fragment,{children:[r?t.jsx("span",{className:"wb-pulse","aria-hidden":"true"}):t.jsx("span",{className:"wb-tool-mark","data-ok":c?"pending":s===!1?"false":"true","aria-hidden":"true"}),t.jsx("span",{className:"wb-tool-label",children:e}),d?t.jsx("span",{className:"wb-tool-gist mono","data-testid":"tool-gist",children:d}):null,a===void 0?null:t.jsxs("span",{className:"wb-tool-elapsed",children:[a,"s"]}),o||s===!1?t.jsx("span",{className:"wb-tool-elapsed",children:o??"failed"}):null]}),v={"data-ok":s===null?void 0:s,"data-running":r,"data-gist":d?!0:void 0,"data-approval":u||void 0};return f?t.jsxs("div",{className:"wb-toolcall","data-open":m||void 0,children:[t.jsxs("div",{className:"wb-tool","data-split":"true",...v,children:[t.jsxs("button",{type:"button",className:"wb-tool-toggle","aria-expanded":m,onClick:()=>p(b=>!b),children:[t.jsx(le,{name:"chevron",className:"wb-tool-chevron"}),g]}),i?t.jsxs(zc,{children:[t.jsx(Uc,{asChild:!0,children:t.jsx("button",{type:"button",className:"wb-tool-open","aria-label":"Open on the canvas",onClick:l,children:t.jsx(le,{name:"arrow",className:"wb-tool-arrow"})})}),t.jsx(Bc,{children:t.jsxs(Wc,{className:"ui-tip",sideOffset:6,children:[t.jsx("span",{className:"ui-tip-title",children:"Open on the canvas"}),t.jsx("span",{className:"ui-tip-hint mono",children:n})]})})]}):null]}),m?t.jsx(h8,{body:f,onOpen:i?l:null}):null]}):i?t.jsxs(zc,{children:[t.jsx(Uc,{asChild:!0,children:t.jsxs("button",{className:"wb-tool",...v,onClick:l,children:[g,t.jsx(le,{name:"arrow",className:"wb-tool-arrow"})]})}),t.jsx(Bc,{children:t.jsxs(Wc,{className:"ui-tip",sideOffset:6,children:[t.jsx("span",{className:"ui-tip-title",children:"Open on the canvas"}),t.jsx("span",{className:"ui-tip-hint mono",children:n})]})})]}):t.jsx("span",{className:"wb-tool","data-static":"true",...v,children:g})}function h8({body:e,onOpen:n}){const s=n?{label:"Open on the canvas",onClick:n}:void 0;if(e.kind==="diff")return t.jsx("div",{className:"wb-tool-body","data-kind":"diff","data-testid":"tool-body",children:t.jsx($h,{text:e.diff,limit:u8,...s?{more:s}:{}})});const r=[e.exitCode===null?null:`exit ${e.exitCode}`,e.elapsedMs===null?null:f8(e.elapsedMs)].filter(a=>a!==null);return t.jsxs("div",{className:"wb-tool-body","data-kind":"command","data-testid":"tool-body",children:[t.jsxs("div",{className:"wb-tool-command",children:[t.jsx("code",{className:"mono",children:e.command}),r.length>0?t.jsx("span",{className:"wb-tool-facts","data-failed":e.exitCode!==null&&e.exitCode!==0?!0:void 0,children:r.join(" · ")}):null]}),e.output?t.jsx("pre",{className:"wb-tool-output",children:e.output}):null]})}function f8(e){return e<1e3?`${Math.round(e)}ms`:`${(e/1e3).toFixed(1)}s`}function Vy(e,n){for(const s of e)for(const r of s.blocks??[])if(r.type==="tool_result"&&r.toolUseId===n)return r;return null}function m8({feedback:e}){const n=e.source==="telegram"?"on Telegram":`on ${e.source}`;return t.jsxs("div",{className:"wb-msg-feedback","data-value":e.value,"data-testid":"message-feedback",title:`You reacted ${e.emoji} ${n}`,children:[t.jsx("span",{className:"wb-msg-feedback-emoji","aria-label":`You reacted ${e.emoji} ${n}`,children:e.emoji}),t.jsx("span",{children:n}),e.note?t.jsxs("span",{className:"wb-msg-feedback-note",children:["“",e.note,"”"]}):null]})}const p8=20*1024*1024,g8=500,ba=e=>`/skills/${encodeURIComponent(e)}`,md=e=>`/skills/bundles/${encodeURIComponent(e)}`;async function x8(e){var n;try{const{staged:s}=await ty("/skills/bundles",e,"bundle.zip");return s}catch(s){const r=s instanceof xe?(n=s.detail)==null?void 0:n.refusal:void 0;throw r?new dT({...r,filename:e.name,error:s instanceof Error?s.message:void 0}):s}}class dT extends Error{constructor(s){super(s.error??`“${s.filename}” was refused.`);fb(this,"name","BundleRefused");this.refusal=s}}const Gt={list:()=>ye("/skills"),detail:e=>ye(ba(e)),downloadUrl:e=>`/api${ba(e)}/download`,create:e=>Z("/skills",e),saveText:(e,n)=>Z(`${ba(e)}/text`,{text:n}),grant:(e,n)=>Z(`${ba(e)}/grants`,n),trust:e=>Z(`${ba(e)}/trust`),remove:e=>tr(ba(e)),file:(e,n)=>ye(`${ba(e)}/file`,{path:n}),imageUrl:(e,n)=>`/api${ba(e)}/image?path=${encodeURIComponent(n)}`,uploadBundle:x8,stagedFile:(e,n)=>ye(`${md(e)}/file`,{path:n}),stagedImageUrl:(e,n)=>`/api${md(e)}/image?path=${encodeURIComponent(n)}`,acceptBundle:(e,n)=>Z(md(e),n),discardBundle:e=>tr(md(e))};function hT(e,n){return`${vt}?tab=skills${e?`&skill=${encodeURIComponent(e)}`:""}${e&&n?`&skfile=${encodeURIComponent(n)}`:""}`}function v8(e){var s;const n=(s=/[?&]skfile=([^&]+)/.exec(e))==null?void 0:s[1];if(!n)return null;try{return decodeURIComponent(n)}catch{return null}}function j8(e){var s;const n=(s=/[?&]skill=([^&]+)/.exec(e))==null?void 0:s[1];if(!n)return null;try{return decodeURIComponent(n)}catch{return null}}function fT(e){const n=document.createElement("a");n.href=Gt.downloadUrl(e),n.download="",document.body.appendChild(n),n.click(),n.remove()}const Gy=[{id:"mine",title:"Yours",aside:"Written or uploaded by you."},{id:"learned",title:"Learned",aside:"An agent proposed it and you kept it."},{id:"plugin",title:"From plugins",aside:"Comes with a plugin and goes with it."},{id:"catalogue",title:"From the catalogue",aside:"Came with a teammate. Yours to change."}];function Qa(e){return e.length<=1?e[0]??"":`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}function Ks(e,n){var s;return((s=e.find(r=>r.id===n))==null?void 0:s.name)??n}function qy(e){return e.charAt(0).toUpperCase()+e.slice(1)}function Yy(e,n){const s=e.shadowedBy??[];if(!s.length)return"Every agent";const r=s.map(a=>{var i;return`@${((i=n.find(l=>l.id===a))==null?void 0:i.handle)??a}`});return`Every agent except ${Qa(r)} (${s.length===1?"has its own":"each has its own"})`}function mT(e,n){return e.holders.some(s=>s.agent===n)}function y8(e,n){if(e.every)return Yy(e,n);const s=e.holders.map(r=>Ks(n,r.agent));return s.length?Qa(s):"No agent uses it yet"}function w8(e){return!e.every&&e.holders.length===0}function b8(){const e=new Date;return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`}function tN(e){return e.slice(0,10)===b8()?"today":`on ${gu(e,{compact:!0})}`}function pc(e,n,s=!1){var l,o;if(e.learned){const c=e.learned.by,u=s&&e.holders.some(f=>f.agent===c),d=e.learned.keptAt?` · kept ${Ve(e.learned.keptAt)}`:"";return`${u?"":`learned by ${Ks(n,c)} · `}v${e.learned.version}${e.learned.edited?" with your correction":""}${d}`}const r=e.from;if((r==null?void 0:r.kind)==="plugin")return`from ${qy(r.plugin)} ${r.version}`;if((r==null?void 0:r.kind)==="catalogue")return`came with ${Ks(n,r.agent)} ${r.version}`;if((r==null?void 0:r.kind)==="upload")return`uploaded${e.created?` ${tN(e.created)}`:""} · ${r.filename}`;const a=((l=e.created)==null?void 0:l.slice(0,10))??null,i=((o=e.updatedAt)==null?void 0:o.slice(0,10))??null;return a&&(!i||i<=a)?`written by you ${tN(a)}`:e.updatedAt?`edited by you ${Ve(e.updatedAt)}`:"written by you"}function pT(e){return e.charAt(0).toUpperCase()+e.slice(1)}function Jy(e,n){var s;return e.untrusted==="page"?`Untrusted: a web page was in view when ${Ks(n,((s=e.learned)==null?void 0:s.by)??e.home??"")} proposed it.`:e.bundle?"Untrusted: it came in a .zip, so agents read its text as outside text and its scripts can’t run.":"Untrusted: it came from a file, so agents read it as outside text."}function Rr(e){return e<1024*1024?`${Math.max(1,Math.round(e/1024))} KB`:`${(e/(1024*1024)).toFixed(e<10*1024*1024?1:0).replace(/\.0$/,"")} MB`}function gT(e,n){return e.every?n.filter(s=>!(e.shadowedBy??[]).includes(s.id)).map(s=>s.id):e.holders.map(s=>s.agent)}function k8(e,n){const s=e.bundle;if(!s)return null;const r=s.scripts.length;if(!r)return`No scripts · ${s.files} file${s.files===1?"":"s"} beside the text`;const a=gT(e,n),i=u=>{var d;return((d=n.find(f=>f.id===u))==null?void 0:d.canRunScripts)===!0},l=a.filter(i).map(u=>Ks(n,u)),o=a.filter(u=>!i(u)).map(u=>Ks(n,u)),c=`${r} script${r>1?"s":""}`;return e.untrusted?`${c} · they can’t run until you mark it as yours`:a.length?l.length?`${c} · ${Qa(l)} can run them, asking first${o.length?`; ${Qa(o)} ${o.length>1?"read":"reads"} the text only`:""}`:`${c} · nobody holding it can run them, so it’s text only`:`${c} · they run only through an agent you allow, and ask first`}function N8(e){var n;switch(e.kind){case"big":return{title:`“${e.filename}” is too big`,body:`${e.size?`It’s ${Rr(e.size)}; a`:"A"} bundle can be up to 20 MB unpacked. Leave large files out — SKILL.md can say where to find them.`};case"count":return{title:`“${e.filename}” holds too many files`,body:`It holds ${e.files??"over 500"} files; a bundle can hold up to ${g8}.`};case"noskill":{const s=(e.looked??[]).filter(r=>r!=="");return{title:`No SKILL.md in “${e.filename}”`,body:`buddi looked at the top${s.length?` and inside ${s.join(", ")}`:""}. A bundle needs SKILL.md in one of them, with scripts/ and assets/ beside it.`}}case"paths":{const s=((n=e.entries)==null?void 0:n.length)??0;return{title:`“${e.filename}” was refused`,body:`${s===1?"One entry reaches":`${s===2?"Two":s} entries reach`} outside the bundle, so nothing was unpacked. A bundle holds plain files inside its own folder.`,items:(e.entries??[]).map(r=>({path:r.path,rest:r.why==="is a link"&&r.target?`is a link to ${r.target}`:r.why}))}}case"executable":return{title:`“${e.filename}” was refused`,body:"Something that runs is outside scripts/, so nothing was kept. A bundle keeps anything that runs in scripts/.",items:(e.entries??[]).map(s=>({path:s.path,rest:s.why}))};case"frontmatter":return{title:`“${e.filename}” has no usable SKILL.md`,body:"Its SKILL.md needs front matter with a description (when it’s used) between --- lines, then the steps."};case"notzip":return{title:`“${e.filename}” isn’t a .zip or a .md`,body:"A skill is one Markdown file, or a .zip bundle with SKILL.md inside."};default:return{title:`“${e.filename}” was refused`,body:e.error??"It could not be read as a bundle."}}}function nN(e){const n=e.file.split(/[\\/]/).pop()??e.file;return e.bundle?`skills/${e.name}/${n}`:e.home?`agents/${e.home}/skills/${n}`:`skills/${n}`}function Qy(e){return e.every?[]:e.holders.map(n=>n.agent)}function S8(e,n){var s;if(e.learned){const r=Ks(n,e.learned.by);return`Saved as v${e.learned.version+1}, your correction. v${e.learned.version} stays in ${r}’s folder.`}return((s=e.from)==null?void 0:s.kind)==="catalogue"?`${Ks(n,e.from.agent)}’s next update will ask before it replaces your change.`:null}function C8(e,n,s){var o;const r=n.stops.map(c=>Ks(s,c)),a=e.learned?Ks(s,e.learned.by):"";if(e.learned&&!n.every&&n.stops.length===1&&n.stops[0]===e.learned.by)return`${a} stops using it and won’t propose it again for 90 days. Earlier versions stay in its folder.`;const i=n.every?"Every agent stops using it.":r.length===0?"No agent uses it, so nothing changes.":`${Qa(r)} ${r.length>1?"stop":"stops"} using it.`,l=n.then==="versions-kept"?`${a} won’t propose it again for 90 days. Earlier versions stay in its folder.`:n.then==="catalogue-asks"?`${((o=e.from)==null?void 0:o.kind)==="catalogue"?Ks(s,e.from.agent):"Its teammate"}’s next update asks before bringing it back.`:"The file goes to the trash folder.";return`${i} ${l}`}function E8(e,n){var c,u;const s=n.replace(/\r\n/g,`
110
- `),r=/^---\n([\s\S]*?)\n---\n*/.exec(s),a=d=>{var m;return(r?((m=new RegExp(`^${d}:\\s*(.*)$`,"m").exec(r[1]))==null?void 0:m[1])??"":"").trim().replace(/^(['"])(.*)\1$/,"$2")},i=r?s.slice(r[0].length):s,l=(u=(c=/^#\s+(.+)$/m.exec(i))==null?void 0:c[1])==null?void 0:u.trim(),o=a("name");return{title:l||(o?pT(o.replace(/-/g," ")):e.replace(/\.md$/i,"")),description:a("description"),body:i}}function A8(e){const n=e==null?void 0:e.envelope;if(!n||typeof n!="object"||Array.isArray(n))return null;const s=n.skillRun;if(!s||typeof s!="object")return null;const r=s;return typeof r.bundle!="string"||typeof r.script!="string"?null:{bundle:r.bundle,title:typeof r.title=="string"?r.title:r.bundle,script:r.script,interpreter:typeof r.interpreter=="string"?r.interpreter:"",args:Array.isArray(r.args)?r.args.filter(a=>typeof a=="string"):[],reads:typeof r.reads=="string"?r.reads:"",writes:typeof r.writes=="string"?r.writes:"",files:typeof r.files=="number"?r.files:0}}function Sp(e){return/[\s"'\\]/.test(e)||e===""?JSON.stringify(e):e}function $8(e){const n=[];for(let s=0;s<e.length;s+=1){const r=e[s],a=e[s+1];r.startsWith("-")&&!r.includes("=")&&a!==void 0&&!a.startsWith("-")?(n.push(`${Sp(r)} ${Sp(a)}`),s+=1):n.push(Sp(r))}return n}function T8({action:e,run:n,agentName:s,count:r,busy:a,error:i,onDecide:l}){const o=a!==null||e.state!=="pending",c=$8(n.args);return t.jsxs("section",{id:"approval-dock",tabIndex:-1,className:"wb-question skb-dock","data-kind":"approval","aria-label":"Approval needed","data-testid":"approval-dock",children:[t.jsxs("div",{className:"wb-question-head",children:[t.jsx("span",{className:"wb-question-kicker",children:"Needs your OK"}),r>1?t.jsxs("span",{className:"wb-dock-count","data-testid":"approval-dock-count",children:["1 of ",r]}):null,t.jsxs("strong",{children:[s," wants to run a script from ",n.title]})]}),t.jsxs("div",{className:"wb-dock-section wb-dock-subject",children:[t.jsx("code",{className:"wb-dock-gist",children:[n.interpreter,n.script].filter(Boolean).join(" ")}),t.jsx("span",{className:"wb-dock-where",children:"From a bundle you marked as yours."})]}),t.jsx("div",{className:"wb-dock-section",children:t.jsx(qt,{items:[{label:"Arguments",value:c.length?t.jsx("span",{className:"mono skb-args",children:c.map((u,d)=>t.jsx("span",{children:u},`${d}:${u}`))}):"None"},{label:"Working folder",value:t.jsx("span",{className:"mono skb-path",children:n.writes})},{label:"What it may touch",value:`Reads ${n.title}’s ${n.files} file${n.files===1?"":"s"} without changing them, and the working folder. Writes only in the working folder.`}]})}),t.jsx(ne,{message:i}),t.jsx("div",{className:"wb-dock-section",children:t.jsxs(te,{children:[t.jsx("span",{className:"skb-dock-note",children:"Scripts ask every time."}),t.jsx(et,{}),t.jsx(A,{variant:"ghost",size:"sm",disabled:o,onClick:()=>l("reject"),children:a==="reject"?"Rejecting…":"Reject"}),t.jsx(A,{size:"sm",onClick:()=>{window.location.hash=hT(n.bundle,n.script)},children:"Show the script"}),t.jsx(A,{variant:"good",size:"sm",disabled:o,onClick:()=>l("approve"),children:a==="approve"?"Allowing…":"Allow once"})]})})]})}const xT="approval-dock";function R8(){var n;const e=document.getElementById(xT);e&&((n=e.scrollIntoView)==null||n.call(e,{block:"nearest"}),e.focus())}const I8=["workspace","cwd","workdir","root"];function vT({approvals:e,timezone:n,now:s,version:r,onDecided:a,onSay:i,onOpenFull:l}){const[o,c]=h.useState([]),u=e.filter(m=>!o.includes(m.approvalId)),d=u[0];if(!d)return null;const f=m=>c(p=>p.includes(m)?p:[...p,m]);return t.jsx(P8,{item:d,count:u.length,timezone:n,now:s,version:r,onSettled:m=>{f(d.approvalId),m&&a(m)},onSay:i,onOpenFull:()=>l(d.toolUseId)},d.approvalId)}function P8({item:e,count:n,timezone:s,now:r,version:a,onSettled:i,onSay:l,onOpenFull:o}){var E;const[c,u]=h.useState(null),[d,f]=h.useState(null),[m,p]=h.useState(null),[g,v]=h.useState("");h.useEffect(()=>{let T=!1;return R.approval(e.approvalId).then(I=>{T||(u(I),I.state!=="pending"&&i(I))}).catch(I=>{T||f(I instanceof xe?I.message:String(I))}),()=>{T=!0}},[e.approvalId,a]);const b=c!==null&&c.state==="pending"&&Date.parse(c.expiresAt)<=r;h.useEffect(()=>{b&&c&&i({...c,state:"expired"})},[b]);const{values:j,controls:x}=My(c==null?void 0:c.choices),y=(T,I)=>{const F=g.trim();p(T),f(null),(j&&T==="approve"?R.decide(e.approvalId,T,I,j):R.decide(e.approvalId,T,I)).then(D=>{i(D.action),F&&l(F)}).catch(D=>{f(D instanceof xe?D.message:String(D)),p(null)})},w=A8(c);if(c&&w){const T=c.agentId?c.agentId.charAt(0).toUpperCase()+c.agentId.slice(1):"An agent";return t.jsx(T8,{action:c,run:w,agentName:T,count:n,busy:m,error:d,onDecide:I=>y(I)})}const k=m!==null||c===null||c.state!=="pending",N=((E=c==null?void 0:c.permissionScopes)==null?void 0:E.includes("always"))??!1,S=c?Wy(c.tool,c.canonicalArgs)??D8(c.preview):null,C=c?M8(c):null;return t.jsxs("section",{id:xT,tabIndex:-1,className:"wb-question","data-kind":"approval","aria-label":"Approval needed","data-testid":"approval-dock",children:[t.jsxs("div",{className:"wb-question-head",children:[t.jsx("span",{className:"wb-question-kicker",children:"Needs your OK"}),n>1?t.jsxs("span",{className:"wb-dock-count","data-testid":"approval-dock-count",children:["1 of ",n]}):null,t.jsx("strong",{children:c?Tr(c.tool):"Loading the request…"}),e.askedBy?t.jsx("span",{className:"wb-dock-asker","data-testid":"approval-dock-asker",children:e.askedBy}):null]}),S||C?t.jsxs("div",{className:"wb-dock-section wb-dock-subject",children:[S?t.jsx("code",{className:"wb-dock-gist",children:S}):null,C?t.jsxs("span",{className:"wb-dock-where",children:["in ",t.jsx("span",{className:"mono",children:C})]}):null]}):null,x?t.jsx("div",{className:"wb-dock-section",children:x}):null,t.jsx(ne,{message:d}),t.jsx("div",{className:"wb-dock-section",children:t.jsx("input",{className:"wb-dock-instead",value:g,onChange:T=>v(T.target.value),onKeyDown:T=>{T.key==="Enter"&&T.preventDefault()},placeholder:"Tell the agent what to do instead (optional)","aria-label":"Tell the agent what to do instead (optional)",disabled:m!==null})}),t.jsxs("div",{className:"wb-dock-section wb-dock-actions",children:[t.jsxs("span",{className:"wb-dock-meta",children:[c?t.jsxs(t.Fragment,{children:["Expires ",ct(c.expiresAt,s)," · "]}):null,t.jsx("button",{type:"button",className:"wb-link",onClick:o,children:"See the full request on the Canvas"})]}),t.jsx(A,{variant:"ghost",size:"sm",disabled:k,onClick:()=>y("reject"),children:m==="reject"?"Rejecting…":"Reject"}),N?t.jsxs(t.Fragment,{children:[t.jsx(A,{variant:"ghost",size:"sm",disabled:k,onClick:()=>y("approve","conversation"),children:"Auto: this conversation"}),t.jsx(A,{size:"sm",disabled:k,onClick:()=>y("approve","always"),children:"Always: this agent"})]}):null,t.jsx(A,{variant:"good",size:"sm",disabled:k,onClick:()=>y("approve"),children:m==="approve"?"Approving…":N?"Allow once":"Approve"})]})]})}function M8(e){for(const n of[e.canonicalArgs,e.envelope])if(!(n===null||typeof n!="object"||Array.isArray(n)))for(const s of I8){const r=n[s];if(typeof r=="string"&&r.trim()!=="")return r.trim()}return null}function D8(e){const n=(e??"").split(`
111
- `).map(s=>s.trim()).find(Boolean);return n?n.length>160?`${n.slice(0,157)}…`:n:null}const O8=2e3;function L8({conversationId:e,agentId:n,runId:s=null,result:r=null,waiting:a=null,agents:i=[]}){const l=r!==null,[o,c]=h.useState(l),u=!o||a!==null,{data:d,error:f}=me(()=>qe.conversation(e),[e,o,(a==null?void 0:a.approvalId)??null],u?O8:void 0),m=(d==null?void 0:d.runs)??[],p=s===null?null:m.find(w=>w.runId===s)??null,g=l||a===null&&(s!==null?p!==null&&p.finishedAt!==null:m.length>0&&m.every(w=>w.finishedAt!==null));h.useEffect(()=>{g&&c(!0)},[g]);const v=r?r.ok?"done":"failed":a!=null&&a.approvalId?"waiting":g?"done":"working",b=i.find(w=>w.id===n)??null,j=(b==null?void 0:b.name)??(d==null?void 0:d.agentId)??n,x=(d==null?void 0:d.messages)??[],y=(r==null?void 0:r.text)??F8(x);return t.jsxs("div",{className:"wb-delegate","data-testid":"delegate-view","data-status":v,children:[t.jsxs("header",{className:"wb-delegate-head",children:[t.jsx(fn,{agents:i,id:n}),t.jsxs("div",{className:"wb-delegate-who",children:[t.jsx("strong",{children:j}),t.jsx("span",{className:"wb-delegate-status","data-status":v,role:"status",children:v==="working"?t.jsxs(t.Fragment,{children:["Working",t.jsxs("span",{className:"wb-dots","aria-hidden":"true",children:[t.jsx("i",{}),t.jsx("i",{}),t.jsx("i",{})]})]}):v==="waiting"?"Waiting for your approval":v==="failed"?"Failed":"Done"})]})]}),f?t.jsx("p",{className:"muted",children:f}):null,t.jsx("div",{className:"wb-delegate-work",children:x.map((w,k)=>t.jsx("div",{className:"wb-delegate-turn",children:(w.blocks??[]).map((N,S)=>{if(N.type==="thinking")return N.text.trim()===""?null:t.jsx(Jx,{text:N.text},S);if(N.type==="tool_use"){const C=z8(_8(x,N.id));return t.jsx(Qx,{label:Tr(N.name),tool:N.name,ok:C.ok,running:C.running,waiting:C.waiting,status:C.status,gist:Wy(N.name,N.input),opens:!1,onOpen:()=>{}},S)}return null})},w.id??k))}),y?t.jsx("div",{className:"wb-delegate-answer","data-testid":"delegate-answer",children:t.jsx(ur,{text:y})}):v==="working"||v==="waiting"?t.jsxs("p",{className:"muted",children:[j," has not answered yet."]}):null,r!=null&&r.files&&r.files.length>0?t.jsx("div",{className:"wb-msg-files",role:"list","aria-label":`Files ${j} made`,"data-testid":"delegate-files",children:r.files.map(w=>t.jsx("a",{role:"listitem",href:Ya(w.artifactId),download:!0,children:t.jsx(rm,{name:w.filename??"Untitled file",mime:w.mime,sizeBytes:w.sizeBytes,thumbnail:Oy(w.mime)?_r(w.artifactId):null})},w.artifactId))}):null,t.jsxs("div",{className:"wb-delegate-actions",children:[v==="waiting"?t.jsx(A,{variant:"accent",onClick:()=>R8(),"data-testid":"delegate-to-approval",children:"Go to the approval"}):null,t.jsx("a",{className:"ui-btn",href:Ze(n||(d==null?void 0:d.agentId)||"",e),children:"Open this conversation"})]})]})}function F8(e){for(let n=e.length-1;n>=0;n-=1){const s=e[n];if(s.role!=="assistant")continue;const r=(s.blocks??[]).filter(a=>a.type==="text").map(a=>a.text.trim()).filter(a=>a!=="").join(`
112
-
113
- `);if(r!=="")return r}return null}function _8(e,n){for(const s of e)for(const r of s.blocks??[])if(r.type==="tool_result"&&r.toolUseId===n)return r;return null}function z8(e){var s;if(e===null)return{running:!0,ok:null,waiting:!1,status:void 0};const n=(s=e.approval)==null?void 0:s.state;return n==="pending"?{running:!1,ok:null,waiting:!0,status:"waiting approval"}:n==="approved"||n==="executing"?{running:!0,ok:null,waiting:!1,status:"running"}:n==="succeeded"?{running:!1,ok:!0,waiting:!1,status:void 0}:n?{running:!1,ok:!1,waiting:!1,status:n}:{running:!1,ok:e.ok,waiting:!1,status:void 0}}const sN=1024*1024;function U8({files:e,agentId:n,root:s,revision:r}){const[a,i]=h.useState({kind:"dir",path:""});return h.useEffect(()=>i({kind:"dir",path:""}),[e.plugin,n]),t.jsx("div",{className:"wb-files","data-testid":"files-view",children:a.kind==="dir"?t.jsx(B8,{files:e,agentId:n,root:s,path:a.path,revision:r,go:i}):t.jsx(W8,{files:e,agentId:n,root:s,path:a.path,revision:r,go:i})})}function jT({root:e,path:n,go:s}){const r=n===""?[]:n.split("/"),a=[{label:e,path:""},...r.map((i,l)=>({label:i,path:r.slice(0,l+1).join("/")}))];return t.jsx("nav",{className:"wb-files-crumbs","aria-label":"Where you are in the workspace",children:a.map((i,l)=>{const o=l===a.length-1;return t.jsxs("span",{className:"wb-files-crumb",children:[l>0?t.jsx("span",{className:"wb-files-sep","aria-hidden":"true",children:"/"}):null,o?t.jsx("span",{className:"wb-files-here mono","aria-current":"location",children:i.label}):t.jsx("button",{type:"button",className:"wb-files-step mono",onClick:()=>s({kind:"dir",path:i.path}),children:i.label})]},i.path)})})}function B8({files:e,agentId:n,root:s,path:r,revision:a,go:i}){const[l,o]=h.useState(null),[c,u]=h.useState(null),[d,f]=h.useState(!1),[m,p]=h.useState(null);h.useEffect(()=>{let b=!1;return u(null),R.pageQuery(e.plugin,e.list,{agent:n,...r?{path:r}:{}}).then(j=>{b||o(j.data)}).catch(j=>{b||u(j instanceof Error?j.message:String(j))}),()=>{b=!0}},[e.plugin,e.list,n,r,a]),h.useEffect(()=>p(null),[r]);const g=async()=>{f(!0),p(null);try{const b=await fetch(R.pageFileUrl(e.plugin,e.archive,{agent:n,...r?{path:r}:{}}),{credentials:"same-origin"});if(!b.ok){const w=await b.json().catch(()=>null);p((w==null?void 0:w.error)??"The archive could not be made.");return}const j=await b.blob(),x=URL.createObjectURL(j),y=document.createElement("a");y.href=x,y.download=`${r===""?s:r.split("/").at(-1)}.zip`,y.click(),window.setTimeout(()=>URL.revokeObjectURL(x),1e4)}catch{p("The archive could not be made.")}finally{f(!1)}},v=l&&l.path===r?l.entries:null;return t.jsxs(t.Fragment,{children:[t.jsxs(te,{children:[t.jsx(jT,{root:s,path:r,go:i}),t.jsx(et,{}),t.jsx(A,{size:"sm",onClick:()=>void g(),disabled:d||v===null||v.length===0,children:d?"Packing…":"Download as archive"})]}),m?t.jsx(G,{tone:"warning",role:"alert",children:m}):null,c?t.jsx(G,{tone:"critical",role:"alert",children:c}):null,v===null?c?null:t.jsx(ve,{children:"Reading the folder…"}):v.length===0?t.jsx(ve,{children:r===""?t.jsxs(t.Fragment,{children:["Nothing in this workspace yet. To hand the agent a file, add it to the ",t.jsx("a",{href:pa,children:"Files library"})," and mention it here."]}):"This folder is empty."}):t.jsx(at,{children:v.map(b=>t.jsx(Xe,{href:"#",onClick:()=>i({kind:b.kind,path:b.path}),lead:t.jsx(K8,{kind:b.kind}),title:t.jsxs("span",{className:"mono",children:[b.name,b.kind==="dir"?"/":""]}),side:b.kind==="file"?ds(b.bytes):void 0},b.path))}),l&&l.path===r&&(l.skipped>0||l.truncated)?t.jsxs("p",{className:"wb-files-note",children:[l.truncated?`Only the first ${l.entries.length} entries are shown. `:"",l.skipped>0?`${l.skipped} ${l.skipped===1?"entry is":"entries are"} not shown: symbolic links and protected paths are never read.`:""]}):null]})}function W8({files:e,agentId:n,root:s,path:r,revision:a,go:i}){const[l,o]=h.useState(null),[c,u]=h.useState(null),[d,f]=h.useState(!1);h.useEffect(()=>{let j=!1;return u(null),R.pageQuery(e.plugin,e.stat,{agent:n,path:r}).then(x=>{j||o(x.data)}).catch(x=>{j||u(x instanceof Error?x.message:String(x))}),()=>{j=!0}},[e.plugin,e.stat,n,r,a]);const m=l&&l.path===r?l:null,p=m?`${m.bytes}-${Math.round(m.mtimeMs)}`:"",g=m?R.pageFileUrl(e.plugin,e.read,{agent:n,path:r,v:p}):"",v=R.pageFileUrl(e.plugin,e.read,{agent:n,path:r,download:"1"}),b=(m==null?void 0:m.type)==="text"&&m.bytes<=sN;return t.jsxs(t.Fragment,{children:[t.jsxs(te,{children:[t.jsx(jT,{root:s,path:r,go:i}),t.jsx(et,{}),b?t.jsx(A,{size:"sm","aria-pressed":d,onClick:()=>f(j=>!j),children:"Wrap"}):null,t.jsx(ht,{size:"sm",href:v,download:(m==null?void 0:m.name)??r.split("/").at(-1),children:"Download"})]}),c?t.jsx(G,{tone:"critical",role:"alert",children:c}):null,m===null?c?null:t.jsx(ve,{children:"Reading the file…"}):m.type==="image"?t.jsx("figure",{className:"wb-files-picture",children:t.jsx("img",{src:g,alt:m.name})}):m.type==="pdf"?t.jsx("div",{className:"file-preview file-preview-pdf",children:t.jsx("object",{data:g,type:"application/pdf","aria-label":m.name,children:t.jsx(G,{children:"Your browser cannot show this PDF here. Download it to open it."})})}):b?t.jsx(H8,{src:g,wrap:d}):t.jsxs(t.Fragment,{children:[t.jsx(G,{children:m.type==="text"?`This file is over ${ds(sN)}, too long to read here. Download it to open it.`:"This kind of file is not shown here. Download it to open it."}),t.jsx(qt,{items:[{label:"Size",value:ds(m.bytes)},{label:"Type",value:t.jsx("span",{className:"mono",children:m.mime})}]})]})]})}function H8({src:e,wrap:n}){const[s,r]=h.useState(null),[a,i]=h.useState(!1);return h.useEffect(()=>{let l=!1;return i(!1),fetch(e,{credentials:"same-origin"}).then(async o=>{if(!o.ok)throw new Error(String(o.status));const c=await o.text();l||r(c)}).catch(()=>{l||i(!0)}),()=>{l=!0}},[e]),a?t.jsx(G,{tone:"critical",children:"The file could not be read."}):s===null?t.jsx(ve,{children:"Reading the file…"}):s===""?t.jsx(ve,{children:"This file is empty."}):t.jsx("pre",{className:"wb-files-text","data-wrap":n?"true":void 0,"data-testid":"files-text",children:s})}function K8({kind:e}){return t.jsx("span",{className:"wb-files-icon","data-kind":e,"aria-hidden":"true",children:t.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:1.4,strokeLinecap:"round",strokeLinejoin:"round",children:e==="dir"?t.jsx("path",{d:"M2 4.2h4.2l1.4 1.6H14v7H2z"}):t.jsx("path",{d:"M4 2.4h5l3 3v8.2H4zM9 2.4v3h3"})})})}function V8({input:e,output:n,ok:s}){const r=o5(e),a=sT(n)??(s?"sent":"not sent");return t.jsxs("div",{className:"wb-envelope",children:[t.jsxs("div",{className:"envelope",children:[t.jsxs("dl",{className:"envelope-head",children:[t.jsx("dt",{children:"To"}),t.jsx("dd",{className:"wb-envelope-action",children:"You"}),t.jsx("dt",{children:"Status"}),t.jsx("dd",{children:t.jsx(Ee,{tone:c5(a,s),dot:!0,children:a})})]}),t.jsxs("div",{className:"envelope-body",children:[t.jsx("strong",{children:r.title}),r.text?`
114
-
115
- ${r.text}`:null]})]}),t.jsx(Ot,{summary:"The call",children:t.jsxs("dl",{className:"ui-kv wb-envelope-fields",children:[t.jsx("dt",{children:"Urgency"}),t.jsx("dd",{children:r.urgency}),r.link?t.jsxs(t.Fragment,{children:[t.jsx("dt",{children:"Link"}),t.jsx("dd",{className:"mono",children:r.link})]}):null,r.key?t.jsxs(t.Fragment,{children:[t.jsx("dt",{children:"Key"}),t.jsx("dd",{className:"mono",children:r.key})]}):null]})})]})}const Zo=e=>e!==null&&typeof e=="object"&&!Array.isArray(e)?e:{},Kt=e=>typeof e=="string"&&e.trim()!==""?e:null,G8={blocked:"Blocked — that address is on this computer or a private network, which the reader never opens.",forbidden:"The site turned the reader away. It may need a sign-in or refuse automated readers.",unauthorised:"The page needs a sign-in, which the reader doesn’t have.","not-found":"Page not found — the link may be old or mistyped.",timeout:"Timed out — the site didn’t answer in time.","too-large":"Too large to read — the page is bigger than the reader takes.","unsupported-content":"Not a web page — a PDF, an image or a file the reader doesn’t open.","rate-limited":"The site is limiting how often it can be read. Try again later.","server-error":"The site had a problem of its own.","too-many-redirects":"The link kept redirecting, so the reader gave up.",network:"Couldn’t reach the site.",unreadable:"The page came back unreadable.","turned-away":"The site turned the reader away with a robot check."};function q8(e){const n=e.slice(0,4e3);if(n.length<20)return!1;let s=0;for(const r of n){const a=r.codePointAt(0);(a===65533||a<32&&a!==9&&a!==10&&a!==13||a>=127&&a<160)&&(s+=1)}return s/n.length>.1}function Cp(e){try{return new URL(e).hostname.replace(/^www\./,"")}catch{return e}}function Y8(e){if(!e)return null;try{const n=new URL(e);return n.protocol==="http:"||n.protocol==="https:"?n.href:null}catch{return null}}function Xx(e){try{const n=new URL(e);return`${n.hostname.replace(/^www\./,"")}${n.pathname.replace(/\/+$/,"")}${n.search}`}catch{return e}}function rN(e){var n;return((n=e.match(/[\p{L}\p{N}]/u))==null?void 0:n[0])??"?"}function yT(e){const n=Zo(e.input),s=Zo(e.output),r={input:e.input,...e.ok===null?{status:"Awaiting result"}:{output:e.output},...e.error===void 0?{}:{error:e.error}},a=e.ok===!1,i=Kt(e.error)??Kt(Zo(e.error).message);if(Array.isArray(s.results)||Kt(n.query)&&!Kt(n.url)){const f=(Array.isArray(s.results)?s.results:[]).map(p=>Zo(p)).flatMap(p=>{const g=Kt(p.url);return g?[{title:Kt(p.title)??Cp(g),url:g,host:Kt(p.source)??Cp(g),snippet:Kt(p.snippet)}]:[]}),m=s.available===!1;return{kind:"search",id:e.id,raw:r,query:Kt(s.query)??Kt(n.query)??"",state:e.ok===null?"pending":a||m?"failed":"ok",provider:Kt(s.provider),results:f,why:a?`The search failed${i?`: ${i}`:"."}`:m?Kt(s.provider)?"The search couldn’t be run this time.":"Web search isn’t set up on this buddi yet — `buddi doctor` says how.":null}}const l=Kt(s.url)??Kt(n.url)??"",o=!a&&s.ok!==!1&&q8(Kt(s.text)??""),c=a||s.ok===!1||o,u=o?"unreadable":Kt(s.problem),d=Kt(s.message);return{kind:"page",id:e.id,url:l,raw:r,host:Kt(s.source)??Cp(l),state:e.ok===null?"pending":c?"failed":"ok",title:Kt(s.title),text:o?null:Kt(s.text),truncated:s.truncated===!0,retrievedAt:Kt(s.retrievedAt)??e.at,why:c?(u&&G8[u])??(d?d.charAt(0).toUpperCase()+d.slice(1)+(/[.!?]$/.test(d)?"":"."):null)??`The read failed${i?`: ${i}`:"."}`:null}}function J8(e){const n=e.entries.map(yT),s=n.filter(a=>a.kind==="search").length,r=n.length-s;return[s?`${s} ${s===1?"search":"searches"}`:null,r?`${r} ${r===1?"page":"pages"}`:null].filter(Boolean).join(" · ")}function Q8(e){return e.split(/\s+/).filter(Boolean).length}function X8(e){return e>=1e3?`${(e/1e3).toFixed(1).replace(/\.0$/,"")}k words`:`${e} ${e===1?"word":"words"}`}function Z8(e,n){if(!e)return null;const s=new Date(e);return Number.isNaN(s.getTime())?null:Xt(s,n??Intl.DateTimeFormat().resolvedOptions().timeZone)}function wT({url:e,className:n,children:s}){const r=Y8(e);return r?t.jsxs("a",{className:`wb-src-link ${n}`,href:r,target:"_blank",rel:"noopener noreferrer",children:[s,t.jsx("span",{className:"wb-src-out","aria-hidden":"true",children:"↗"})]}):t.jsx("span",{className:n,children:s})}function bT({value:e}){const[n,s]=h.useState(!1);return t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",className:"wb-src-quiet","data-raw":"","aria-expanded":n,onClick:()=>s(!n),children:n?"Hide JSON":"Raw JSON"}),n?t.jsx("pre",{className:"wb-src-raw",children:JSON.stringify(e,null,2)}):null]})}function eW({page:e,focused:n,timezone:s}){const[r,a]=h.useState(n),[i,l]=h.useState(!1),o=h.useRef(null);if(h.useEffect(()=>{var m,p;n&&(a(!0),(p=(m=o.current)==null?void 0:m.scrollIntoView)==null||p.call(m,{block:"nearest"}))},[n]),e.state==="pending")return t.jsx("li",{className:"wb-src-page","data-state":"pending",ref:o,children:t.jsxs("div",{className:"wb-src-row",children:[t.jsx("span",{className:"wb-src-tile","data-state":"pending","aria-hidden":"true",children:rN(e.host)}),t.jsxs("span",{className:"wb-src-head",children:[t.jsxs("span",{className:"wb-src-title",children:["Reading ",e.host,"…"]}),t.jsx("span",{className:"wb-src-meta",children:e.url})]}),t.jsx("span",{})]})});const c=e.state==="failed",u=e.text?Q8(e.text):0,d=Z8(e.retrievedAt,s),f=[e.host,d?`read ${d}`:null,u?X8(u):null,u?`${Math.max(1,Math.round(u/230))} min read`:null].filter(Boolean).join(" · ");return t.jsxs("li",{className:"wb-src-page","data-open":r?"true":void 0,"data-state":e.state,ref:o,children:[t.jsxs("div",{className:"wb-src-row",children:[t.jsx("span",{className:"wb-src-tile","data-tone":c?"critical":void 0,"aria-hidden":"true",children:c?"!":rN(e.host)}),t.jsxs("span",{className:"wb-src-head",children:[c?t.jsxs("span",{className:"wb-src-title",children:["Couldn’t read ",e.host]}):t.jsx(wT,{url:e.url,className:"wb-src-title",children:e.title??e.host}),c?t.jsx("span",{className:"wb-src-why",children:e.why}):t.jsx("span",{className:"wb-src-meta",children:f})]}),t.jsx("button",{type:"button",className:"wb-src-toggle","aria-expanded":r,"aria-label":r?`Hide what was read from ${e.host}`:`Show what was read from ${e.host}`,onClick:()=>a(!r),children:t.jsx(le,{name:"chevron"})})]}),r?t.jsxs("div",{className:"wb-src-body",children:[c?t.jsx("p",{className:"wb-src-note",children:e.url}):t.jsxs(t.Fragment,{children:[e.text?t.jsx("p",{className:"wb-src-text","data-clamped":i?void 0:"true",children:e.text}):t.jsx("p",{className:"wb-src-note",children:"The page had no text to read."}),e.truncated?t.jsx("p",{className:"wb-src-note",children:"Only the beginning of the page was read; it was longer than the limit."}):null]}),t.jsxs("div",{className:"wb-src-foot",children:[!c&&e.text?t.jsx("button",{type:"button",className:"wb-src-quiet",onClick:()=>l(!i),children:i?"Show less":"Show more"}):null,t.jsx(bT,{value:e.raw})]})]}):null]})}const aN=3;function tW({search:e,read:n,focused:s}){const[r,a]=h.useState(!1),i=h.useRef(null);h.useEffect(()=>{var c,u;s&&((u=(c=i.current)==null?void 0:c.scrollIntoView)==null||u.call(c,{block:"nearest"}))},[s]);const l=r?e.results:e.results.slice(0,aN),o=e.state==="pending"?"Searching…":[e.provider,e.state==="ok"?`${e.results.length} ${e.results.length===1?"result":"results"}`:null].filter(Boolean).join(" · ");return t.jsxs("div",{className:"wb-src-list","data-state":e.state,ref:i,children:[t.jsxs("div",{className:"wb-src-query",children:[t.jsxs("span",{className:"wb-src-query-text",children:["“",e.query,"”"]}),o?t.jsx("span",{className:"wb-src-query-meta",children:o}):null,t.jsx("span",{className:"wb-src-query-raw",children:t.jsx(bT,{value:e.raw})})]}),e.state==="failed"?t.jsx("p",{className:"wb-src-empty wb-src-why",children:e.why}):null,e.state==="ok"&&e.results.length===0?t.jsx("p",{className:"wb-src-empty",children:"No results."}):null,l.length>0?t.jsx("ol",{className:"wb-src-results",children:l.map(c=>t.jsxs("li",{className:"wb-src-result",children:[t.jsx(wT,{url:c.url,className:"wb-src-result-title",children:c.title}),t.jsx("span",{className:"wb-src-result-site",children:c.host}),c.snippet?t.jsx("p",{className:"wb-src-result-snippet",children:c.snippet}):null,n.has(Xx(c.url))?t.jsx("span",{className:"wb-src-result-side",children:t.jsx(Ee,{tone:"good",children:"Read"})}):null]},c.url))}):null,e.results.length>aN?t.jsx("div",{className:"wb-src-more",children:t.jsx("button",{type:"button",className:"wb-src-quiet",onClick:()=>a(!r),children:r?"Show fewer":`Show all ${e.results.length}`})}):null]})}function nW({entries:e,focus:n,timezone:s}){const r=e.map(yT),a=r.filter(o=>o.kind==="page"),i=r.filter(o=>o.kind==="search"),l=new Set(a.filter(o=>o.state==="ok").flatMap(o=>{const c=e.find(d=>d.id===o.id),u=Kt(Zo(c==null?void 0:c.input).url);return[Xx(o.url),...u?[Xx(u)]:[]]}));return t.jsxs("div",{className:"wb-src",children:[a.length>0?t.jsxs("div",{className:"wb-src-group",children:[t.jsx("p",{className:"wb-src-kicker",children:"Read"}),t.jsx("ul",{className:"wb-src-list",children:a.map(o=>t.jsx(eW,{page:o,focused:n===o.id,timezone:s},o.id))})]}):null,i.length>0?t.jsxs("div",{className:"wb-src-group",children:[t.jsx("p",{className:"wb-src-kicker",children:"Searched"}),i.map(o=>t.jsx(tW,{search:o,read:l,focused:n===o.id},o.id))]}):null]})}const sW=3,rW=152,aW=104,iW=100,lW=2,iN=5;function oW({renderables:e,activeId:n,onActivate:s,timezone:r,onDecided:a,onChangeAgent:i,face:l,descriptors:o,grantedTools:c,agentName:u,maxTabs:d,browserPanel:f,agents:m,onClose:p,loading:g=!1}){const[v,b]=cW(d);if(e.length===0)return t.jsxs("div",{className:"wb-canvas","data-testid":"canvas",children:[t.jsx("div",{className:"wb-canvas-tabs",ref:v,"aria-hidden":"true",children:t.jsx("span",{className:"wb-canvas-label",children:"Canvas"})}),t.jsx("div",{className:"wb-canvas-body wb-canvas-body-empty",children:g?null:t.jsxs("div",{className:"wb-empty",children:[l?t.jsx("span",{className:"wb-empty-face",children:l}):null,t.jsx("p",{className:"ui-empty wb-empty-line",children:mW(u,pW(o??[],c??[]))})]})})]});const j=e.some(w=>w.id===n)?n:e[e.length-1].id,{shown:x,hidden:y}=uW(e,j,b);return t.jsx("div",{className:"wb-canvas","data-testid":"canvas",children:t.jsxs(Hz,{value:j,onValueChange:s,className:"contents",children:[t.jsxs("div",{className:"wb-canvas-tabs",ref:v,children:[t.jsx("span",{className:"wb-canvas-label","aria-hidden":"true",children:"Canvas"}),t.jsx(Kz,{className:"wb-tabstrip","aria-label":"Canvas",children:x.map(w=>t.jsxs("div",{className:"wb-tab-item",children:[t.jsxs(Vz,{value:w.id,className:"wb-tab","data-tone":w.tone,onKeyDown:k=>{k.key==="Delete"&&p&&lN(w)&&(k.preventDefault(),p(w.id))},children:[w.tone==="warning"||w.tone==="critical"?t.jsx("span",{className:"wb-tab-dot","data-tone":w.tone,"aria-hidden":"true"}):null,t.jsx("span",{className:"wb-tab-text",children:w.title}),w.count?t.jsx("span",{className:"wb-tab-count",children:w.count}):null]}),p&&lN(w)?t.jsx("button",{className:"wb-tab-close","aria-label":`Close ${w.title} tab`,title:"Dismiss panel; keep conversation history",onClick:()=>p(w.id),children:"×"}):null]},w.id))}),t.jsx(dW,{items:y,onActivate:s,timezone:r})]}),e.map(w=>t.jsx(Gz,{value:w.id,className:"wb-canvas-body","data-renderer":w.source==="descriptor"&&w.renderer==="preview"?"preview":void 0,"data-dense":xW.has(w.renderer)?"true":void 0,children:t.jsxs("section",{className:"ui-panel","data-flush":w.source==="descriptor"&&w.renderer==="preview"?"true":void 0,children:[w.source!=="browser"&&w.source!=="files"&&!(w.source==="descriptor"&&w.renderer==="preview")?t.jsxs("header",{className:"ui-panel-head",children:[t.jsx("h2",{className:"ui-panel-title",children:w.title}),t.jsx("span",{className:"ui-panel-tool mono",children:w.source==="sources"?J8(w.props):w.tool})]}):null,w.tone==="critical"?t.jsxs("p",{className:"muted",children:["Recorded tool failure",w.at?` · ${ct(w.at,Intl.DateTimeFormat().resolvedOptions().timeZone)}`:"",". This is history, not live session status."]}):null,w.source==="browser"?f:w.source==="profile"?t.jsx(IB,{...w.props,...i?{onChange:i}:{}}):w.source==="artifact"?t.jsx(r5,{...w.props}):w.source==="files"?t.jsx(U8,{...w.props}):w.source==="sources"?t.jsx(nW,{...w.props,timezone:r}):w.source==="notify"?t.jsx(V8,{...w.props}):w.source==="delegate"?t.jsx(L8,{...w.props,agents:m??[]}):t.jsx(RB,{renderer:w.renderer,props:w.props,timezone:r,onDecided:a})]})},w.id))]})})}function lN(e){return e.source==="approval"?!1:e.source==="browser"?e.pinned!==!0:e.source!=="files"}function cW(e){const[n,s]=h.useState(iN),r=h.useRef(null);return[h.useCallback(i=>{var o;if((o=r.current)==null||o.disconnect(),r.current=null,!i||e!==void 0||typeof ResizeObserver>"u")return;const l=()=>{const c=i.clientWidth;if(c===0)return;const u=Math.floor((c-iW-aW)/rW);s(Math.max(lW,Math.min(iN,u)))};l(),r.current=new ResizeObserver(l),r.current.observe(i)},[e]),e??n]}function uW(e,n,s){const r=new Set(e.filter(i=>i.id===n||i.source==="approval"||i.pinned===!0).map(i=>i.id)),a=new Set(r);for(let i=e.length-1;i>=0&&a.size<s;i-=1)a.add(e[i].id);return{shown:e.filter(i=>a.has(i.id)),hidden:e.filter(i=>!a.has(i.id))}}function dW({items:e,onActivate:n,timezone:s}){if(e.length===0)return null;const r=e.some(a=>a.tone==="critical")?"critical":e.some(a=>a.tone==="warning")?"warning":null;return t.jsxs(ju,{modal:!1,children:[t.jsx(yu,{asChild:!0,children:t.jsxs("button",{className:"wb-tab wb-tab-more","data-tone":r??void 0,"aria-label":`${e.length} more ${e.length===1?"view":"views"} in this conversation`,children:[r?t.jsx("span",{className:"wb-tab-dot","data-tone":r,"aria-hidden":"true"}):null,t.jsxs("span",{className:"wb-tab-text",children:[e.length," more"]}),t.jsx(le,{name:"chevron-down"})]})}),t.jsx(xo,{children:t.jsxs(wu,{className:"ui-menu","data-wide":"true",align:"end",sideOffset:6,children:[t.jsx(Di,{className:"ui-menu-label",children:"Earlier in this conversation"}),[...e].reverse().map(a=>t.jsxs(zs,{className:"ui-menu-item",onSelect:()=>n(a.id),children:[t.jsxs("span",{className:"ui-menu-item-text",children:[a.tone==="warning"||a.tone==="critical"?t.jsx("span",{className:"wb-tab-dot","data-tone":a.tone,"aria-hidden":"true"}):null,a.title]}),t.jsx("span",{className:"ui-menu-note mono",children:hW(a.at,s)??a.tool})]},a.id))]})})]})}function hW(e,n){if(!e)return null;const s=new Date(e);return Number.isNaN(s.getTime())?null:Xt(s,n)}const fW={timeseries:"charts",table:"tables",bars:"comparisons",keyvalue:"figures",tiles:"cards",document:"pages it read",diff:"diffs",terminal:"command output",image:"pictures",preview:"running apps",envelope:"drafts",structured:"results"};function mW(e,n){const s=e?`What ${e} shows you`:"What your agent shows you",r=[...new Set(n.map(a=>fW[a.renderer]??"results"))].slice(0,3);return r.length>0?`${s} lands here: ${r.join(", ")}.`:`${s} lands here.`}function pW(e,n){const s=new Set(n),r=new Set,a=e.filter(c=>{if(!s.has(c.tool))return!1;const u=gW(c);return r.has(u)?!1:(r.add(u),!0)}),i=new Set,l=a.filter(c=>i.has(c.renderer)?!1:(i.add(c.renderer),!0)),o=a.filter(c=>!l.includes(c));return[...l,...o].slice(0,sW)}function gW(e){return e.title&&e.title.trim()!==""?e.title:e.tool.split(".").map(n=>n.replace(/[_-]+/g," ")).join(" · ").replace(/\b\w/,n=>n.toUpperCase())}const xW=new Set(["table","diff","files"]),vW=3.5*6e4,jW=2e3;function yW(e,n,s={}){const[r,a]=h.useState({served:new Set,live:new Set,scope:n}),i=h.useRef(r.served);if(r.scope!==n){const u={served:new Set,live:new Set,scope:n};i.current=u.served,a(u)}const l=s.check??R.previewCheck,o=s.everyMs??jW,c=e.map(u=>`${Ll(u)}@${u.at??""}`).join("|");return h.useEffect(()=>{const u=new Map;for(const p of e){const g=Ll(p);if(i.current.has(g))continue;const v=p.at===null?Number.NaN:Date.parse(p.at),b=Number.isNaN(v)?0:v+vW,j=u.get(g);(!j||b>j.until)&&u.set(g,{plugin:p.plugin,name:p.name,until:b})}if(u.size===0)return;let d=!1,f;const m=async()=>{const p=Date.now();for(const[g,v]of[...u]){const b=await l(v.plugin,v.name).catch(()=>null);if(d)return;const j=p<=v.until;b!=null&&b.ok?(u.delete(g),a(x=>{const y={served:new Set(x.served).add(g),live:j?new Set(x.live).add(g):x.live,scope:x.scope};return i.current=y.served,y})):j||u.delete(g)}!d&&u.size>0&&(f=setTimeout(()=>void m(),o))};return m(),()=>{d=!0,f!==void 0&&clearTimeout(f)}},[c,n,l,o]),r}const Zx="workspace-files";function wW(e){let n=0;for(const s of e)for(const r of s.blocks??[]){if(r.type!=="tool_result"||r.ok===!1)continue;const a=r.output;if(a===null||typeof a!="object"||Array.isArray(a))continue;const{diff:i,path:l}=a;typeof i=="string"&&i.trim()!==""&&typeof l=="string"&&l!==""&&(n+=1)}return n}function bW(e){const[n,s]=h.useState(null);return h.useEffect(()=>{if(s(null),!e)return;let r=!1;return(async()=>{var i;const a=await R.pages();for(const l of Array.isArray(a==null?void 0:a.files)?a.files:[]){const o=await R.pageQuery(l.plugin,l.workspace,{agent:e}).catch(()=>null),c=(i=o==null?void 0:o.data)==null?void 0:i.workspace;if(c&&typeof c.name=="string")return{files:l,agentId:e,root:c.name}}return null})().then(a=>{r||s(a)}).catch(()=>{}),()=>{r=!0}},[e]),n&&n.agentId===e?n:null}function kW(e,n){return{id:Zx,tool:"",title:"Files",renderer:"files",props:{files:e.files,agentId:e.agentId,root:e.root,revision:n},at:null,source:"files",pinned:!0,substantial:!1}}function ev(e){return`agent-properties:${e}`}function NW(e){return{id:ev(e.id),tool:`@${e.handle}`,title:"Properties",renderer:"profile",props:{profile:e},at:null,source:"profile",substantial:!1}}function SW(e){return!e||e.download===0?"Fetching the browser…":e.phase==="downloading"?`Fetching ${e.what}… ${e.percent}%`:e.phase==="installing"?`Setting up ${e.what}…`:e.phase==="done"?"Installed.":"The install stopped."}function kT({progress:e}){return t.jsxs(ie,{gap:"sm",children:[t.jsx("span",{role:"status",children:SW(e)}),t.jsx(Py,{value:(e==null?void 0:e.percent)??0,label:"Fetching the browser"})]})}function CW(e,n,s,r){const a=e.width||1,i=e.height||1,l=n.pageScaleFactor||1,o=(s-e.left)*(n.deviceWidth/a)/l,c=((r-e.top)*(n.deviceHeight/i)-n.offsetTop)/l,u=(d,f)=>Math.max(0,Math.min(Math.round(d),Math.round(f)));return{x:u(o,n.deviceWidth),y:u(c,n.deviceHeight)}}function Ep(e){return(e.altKey?1:0)|(e.ctrlKey?2:0)|(e.metaKey?4:0)|(e.shiftKey?8:0)}function oN(e){return[...e].length===1&&e.codePointAt(0)>=32&&e.codePointAt(0)!==127}const EW=4e3;function AW(e){return e.replace(/\r\n?/g,`
116
- `).replace(/[\u0000-\u0008\u000b-\u001f\u007f]/g,"").slice(0,EW)}const $W=["left","middle","right"],TW=33;function RW(e,n){return e.deviceWidth===n.deviceWidth&&e.deviceHeight===n.deviceHeight&&e.pageScaleFactor===n.pageScaleFactor&&e.offsetTop===n.offsetTop}function IW(e){if(e.byteLength<3)return null;const n=new DataView(e);if(n.getUint8(0)!==1)return null;const s=n.getUint16(1);if(e.byteLength<3+s)return null;try{return{metadata:JSON.parse(new TextDecoder().decode(new Uint8Array(e,3,s))),jpeg:new Blob([new Uint8Array(e,3+s)],{type:"image/jpeg"})}}catch{return null}}function PW(e=window.location){return`${e.protocol==="https:"?"wss":"ws"}://${e.host}/api/browser/hand`}function MW({sessionId:e,csrf:n,onGiveBack:s,connect:r}){const[a,i]=h.useState("connecting"),[l,o]=h.useState(null),[c,u]=h.useState(!1),[d,f]=h.useState(null),[m,p]=h.useState(!1),[g,v]=h.useState(0),b=h.useRef(null),j=h.useRef(null),x=h.useRef(null),y=h.useRef({at:0});h.useEffect(()=>{const $=r??(M=>new WebSocket(M));let L=!0,O;try{O=$(PW())}catch{i("lost");return}return O.binaryType="arraybuffer",b.current=O,O.onopen=()=>O.send(JSON.stringify({type:"hello",csrf:n,sessionId:e})),O.onmessage=M=>{if(!L)return;if(typeof M.data!="string"){const H=IW(M.data);if(!H||(f(U=>U&&RW(U,H.metadata)?U:H.metadata),u(!0),typeof createImageBitmap!="function"))return;createImageBitmap(H.jpeg).then(U=>{var z,X,K;const V=j.current;if(!L||!V){(z=U.close)==null||z.call(U);return}(V.width!==U.width||V.height!==U.height)&&(V.width=U.width,V.height=U.height),(X=V.getContext("2d"))==null||X.drawImage(U,0,0),(K=U.close)==null||K.call(U)}).catch(()=>{});return}const P=JSON.parse(M.data);if(P.type==="driving"){i("driving"),o(null);return}(P.type==="refused"||P.type==="ended")&&(o(P.error??"The screen cannot be driven from here."),i("refused"))},O.onclose=()=>{L&&i(M=>M==="refused"?M:"lost")},O.onerror=()=>{L&&i(M=>M==="refused"?M:"lost")},()=>{L=!1,b.current=null;try{O.close()}catch{}}},[e,n,g,r]),h.useEffect(()=>()=>{clearTimeout(y.current.timer)},[]);const w=h.useCallback($=>{const L=b.current;if(L)try{L.send(JSON.stringify({type:"input",input:$}))}catch{}},[]),k=$=>{var M;const L=j.current;if(!L||!d)return null;const O=(M=L.getBoundingClientRect)==null?void 0:M.call(L);return O?CW(O,d,$.clientX,$.clientY):null},N=$=>{const L=y.current,O=Date.now();clearTimeout(L.timer),L.timer=void 0;const M=L.at+TW-O;if(M<=0){L.at=O,L.pending=void 0,w($);return}L.pending=$,L.timer=setTimeout(()=>{const P=y.current.pending;y.current.timer=void 0,y.current.pending=void 0,y.current.at=Date.now(),P&&w(P)},M)},S=()=>{const $=y.current;clearTimeout($.timer),$.timer=void 0;const L=$.pending;$.pending=void 0,L&&($.at=Date.now(),w(L))},C=$=>L=>{var P,H;const O=k(L);if(!O)return;$==="mousePressed"&&(L.preventDefault(),(H=(P=j.current)==null?void 0:P.focus)==null||H.call(P));const M={kind:"mouse",type:$,x:O.x,y:O.y,button:$W[L.button]??"left",clickCount:$==="mouseMoved"?0:Math.min(3,Math.max(1,L.detail||1)),modifiers:Ep(L)};if($==="mouseMoved"){N(M);return}S(),w(M)},E=$=>{const L=k($);L&&(S(),w({kind:"wheel",x:L.x,y:L.y,deltaX:Math.round($.deltaX),deltaY:Math.round($.deltaY)}))},T=$=>$.ctrlKey||$.metaKey||$.altKey,I=$=>{var O,M;if($.key==="Escape"&&T($)){p(!1),(M=(O=$.target).blur)==null||M.call(O);return}if($.preventDefault(),($.metaKey||$.ctrlKey)&&($.key==="v"||$.key==="V"))return;const L=Ep($);if(oN($.key)&&!T($)){w({kind:"key",type:"char",key:$.key,code:$.code,text:$.key,modifiers:L});return}w({kind:"key",type:"keyDown",key:$.key,code:$.code,modifiers:L})},F=$=>{$.key==="Escape"&&T($)||($.preventDefault(),!(($.metaKey||$.ctrlKey)&&($.key==="v"||$.key==="V"))&&(oN($.key)&&!T($)||w({kind:"key",type:"keyUp",key:$.key,code:$.code,modifiers:Ep($)})))},D=$=>{var O;$.preventDefault();const L=AW(((O=$.clipboardData)==null?void 0:O.getData("text/plain"))??"");L!==""&&w({kind:"text",text:L})};return t.jsxs("section",{className:"hand","data-testid":"remote-hand","data-phase":a,"aria-label":"Driving the host browser",children:[t.jsxs("div",{className:"hand-bar",children:[t.jsx("span",{className:"hand-said",role:"status",children:"You are driving. Nothing you type here is kept."}),t.jsxs(te,{align:"end",children:[t.jsx(A,{size:"sm",variant:m?"accent":"ghost","aria-pressed":m,onClick:()=>{var L,O,M,P;const $=!m;p($),$?(O=(L=x.current)==null?void 0:L.focus)==null||O.call(L):(P=(M=x.current)==null?void 0:M.blur)==null||P.call(M)},children:"Keyboard"}),t.jsx(A,{size:"sm",variant:"accent",onClick:s,children:"Give it back"})]})]}),a==="lost"?t.jsxs(G,{tone:"warning",role:"status",children:["Connection lost. The picture below is the last frame that arrived.",t.jsx(te,{align:"end",children:t.jsx(A,{size:"sm",variant:"accent",onClick:()=>{i("connecting"),v($=>$+1)},children:"Reconnect"})})]}):null,a==="refused"&&l?t.jsx(G,{tone:"warning",role:"status",children:l}):null,t.jsx("div",{className:"hand-screen",children:c?t.jsx("canvas",{ref:j,className:"hand-picture",role:"img","aria-label":"The host browser, live","data-testid":"hand-picture",tabIndex:0,onMouseDown:C("mousePressed"),onMouseUp:C("mouseReleased"),onMouseMove:C("mouseMoved"),onWheel:E,onKeyDown:I,onKeyUp:F,onPaste:D,onContextMenu:$=>$.preventDefault()}):t.jsx("p",{className:"muted hand-waiting",children:a==="lost"?"No picture arrived before the connection dropped.":"Waiting for the first frame…"})}),t.jsx("input",{ref:x,className:"hand-typing","aria-label":"Type into the host browser",autoComplete:"off",autoCapitalize:"off",autoCorrect:"off",spellCheck:!1,value:"",onChange:()=>{},onKeyDown:I,onKeyUp:F,onPaste:D,onBlur:()=>p(!1)})]})}function DW(e){return e==="darwin"?"this Mac":"this computer"}let Ap=null;function am(){const[e,n]=h.useState(void 0);return h.useEffect(()=>{let s=!0;return Ap??(Ap=R.session().then(r=>r.platform,()=>{Ap=null})),Ap.then(r=>{s&&n(r)}),()=>{s=!1}},[]),DW(e)}function OW({embedded:e,timezone:n}={}){var c;const{data:s,error:r,reload:a}=me(()=>R.browser(),[],3e3),i=me(()=>R.session(),[]),l=(c=i.data)!=null&&c.platform?i.data.platform==="darwin":!0,o=!!i.data||!!i.error;return t.jsxs(Zn,{embedded:e,title:"Computer & browser",children:[t.jsx(ne,{message:r}),!s||!o?t.jsx(ve,{children:"Checking the host…"}):t.jsx(LW,{data:s,macOS:l,reload:a,timezone:n},JSON.stringify(s.settings??null))]})}function LW({data:e,macOS:n,reload:s,timezone:r}){var E,T,I,F,D;const[a,i]=h.useState(!1),[l,o]=h.useState(null),[c,u]=h.useState(!1),d=e.settings&&!n&&e.settings.mode==="computer"?{...e.settings,mode:"playwright"}:e.settings,f=(d==null?void 0:d.mode)??(!n&&e.mode==="computer"?"playwright":e.mode),m=f==="computer",p=(E=e.sessions)!=null&&E.length?e.sessions:e.session?[e]:[],g=p.length>0||e.busy,v=async $=>{i(!0),o(null);try{await $()}catch(L){o(L instanceof Error?L.message:String(L))}finally{i(!1),s()}},b=$=>void v(()=>R.browserSettings($)),j=e.permissions,x=f==="playwright"?e.browser:void 0,y=((T=x==null?void 0:x.install)==null?void 0:T.state)==="running",w=(x==null?void 0:x.engine)==="none",k=n&&((I=e.helper)==null?void 0:I.present)===!1,N=k?((F=e.helper)==null?void 0:F.message)??"The computer helper is missing from this install. Update buddi.":void 0,S=!!e.enabled&&!w&&!(x!=null&&x.problem)&&!(m&&k)&&(!m||!(j!=null&&j.supported)||j.accessibility&&j.screenRecording),C=m?"Ready. Agents can use your computer within the apps you allow below.":f==="extension"?"Ready. Agents work in your Chrome, in background tabs, through the buddi extension.":(x==null?void 0:x.engine)==="chrome"?"Ready. Agents work in their own browser, a separate Google Chrome profile. Your apps are never touched.":"Ready. Agents work in their own browser. Your apps are never touched.";return t.jsxs(ie,{gap:"lg",children:[t.jsx(ne,{message:l}),t.jsx(ue,{title:"Status",panel:!0,actions:t.jsxs(t.Fragment,{children:[t.jsx(A,{size:"sm",disabled:a,onClick:()=>void v(()=>R.computerPermissions(!1)),children:"Check again"}),m&&!S&&(j!=null&&j.supported)?t.jsx(A,{size:"sm",variant:"accent",disabled:a||g,onClick:()=>void v(()=>R.computerPermissions(!0)),children:"Request macOS permissions"}):null,w||y?t.jsx(A,{size:"sm",variant:"accent",disabled:a||y,onClick:()=>void v(()=>R.browserInstall()),children:y?"Installing…":"Install Chromium"}):null]}),children:t.jsxs(ie,{children:[e.enabled?w?t.jsxs(G,{tone:"warning",title:"No browser installed for the agents yet",children:["Install Chromium here (about 150 MB), or run ",t.jsx("code",{children:"buddi browser install"})," on this machine."]}):x!=null&&x.problem?t.jsx(G,{tone:"warning",children:x.message}):m&&k?t.jsx("p",{className:"muted",children:"“Use my apps” cannot run on this install; see its card below."}):S?t.jsx(G,{tone:"good",children:C}):t.jsx(G,{tone:"warning",children:"macOS has not granted everything yet. Grant the permissions below, then check again."}):t.jsx(G,{tone:"warning",children:"The host is not available. Start buddi serve on a machine with a desktop session."}),!m||k?null:j!=null&&j.supported?t.jsxs("ul",{className:"perm-list",children:[t.jsxs("li",{className:"perm-row",children:[t.jsx(Ee,{tone:j.accessibility?"good":"warning",children:j.accessibility?"Granted":"Needed"}),t.jsx("span",{className:"perm-name",children:"Accessibility"}),t.jsx("span",{className:"muted",children:"Lets agents click and type in the apps you allow."})]}),t.jsxs("li",{className:"perm-row",children:[t.jsx(Ee,{tone:j.screenRecording?"good":"warning",children:j.screenRecording?"Granted":"Needed"}),t.jsx("span",{className:"perm-name",children:"Screen Recording"}),t.jsx("span",{className:"muted",children:"Lets agents see the window they are working in."})]})]}):j?t.jsx("p",{className:"muted",children:"Computer control requires macOS 14 or later."}):null,((D=x==null?void 0:x.install)==null?void 0:D.state)==="running"?t.jsx(kT,{progress:x.install.progress}):x!=null&&x.install?t.jsx("p",{className:"muted",role:"status",children:x.install.state==="done"?"Chromium is installed. Agents can open their browser now.":`The install did not finish: ${x.install.line??"no reason given"}`}):null,x!=null&&x.headless&&!w?t.jsx("p",{className:"muted",children:"The agents’ browser runs headless on this machine, since it has no display. Watch it and take over from the conversation’s Canvas."}):null,m&&!k&&(j!=null&&j.message)?t.jsx("p",{className:"muted",children:j.message}):null,m&&(j!=null&&j.supported)&&!S?t.jsx("p",{className:"muted",children:"macOS may ask you to restart buddi after granting them."}):null]})}),t.jsx(ue,{title:"Who is driving",panel:!0,actions:p.length>0?t.jsx(A,{variant:"danger",size:"sm",disabled:a,onClick:()=>void v(()=>R.browserControl("stop")),children:m?"Stop computer control":"Stop all browsers"}):void 0,children:p.length===0?t.jsx("p",{className:"ui-card-meta",children:"Nobody right now. Ask an agent to open a website or one of the allowed apps, and you will see it working on that conversation’s Canvas."}):t.jsx("div",{className:"ui-list",children:p.map($=>t.jsxs("a",{className:"ui-list-row",href:Ze($.session.agentId,$.session.conversationId),children:[t.jsx(Nn,{id:$.session.agentId,name:$.session.agentId,size:"sm"}),t.jsxs("span",{className:"ui-list-main",children:[t.jsx("span",{className:"ui-list-title",children:$.session.task}),t.jsxs("span",{className:"ui-list-sub",children:[$.session.agentId,", ",$.busy?"working":$.state,", ",$.session.steps," of ",$.session.maxSteps," steps"]})]}),t.jsx("span",{className:"ui-list-side",children:"Open the Canvas"})]},$.session.id))})}),d?t.jsxs(t.Fragment,{children:[t.jsx(ue,{title:"How agents get a screen",panel:!0,children:t.jsxs(ie,{divided:!0,children:[t.jsxs("div",{className:"mode-choice",role:"radiogroup","aria-label":"Control mode",children:[n?t.jsx($p,{current:d.mode,value:"computer",disabled:a||g||!e.enabled,title:"Use my apps",health:N,body:"Agents work in your own windows, signed in as you, in the browser profile you choose below. One agent at a time. Releasing control leaves everything open.",onPick:()=>b({...d,mode:"computer"})}):null,t.jsx($p,{current:d.mode,value:"playwright",disabled:a||g||!e.enabled,title:"Give agents their own browser",body:"A separate browser profile with its own tabs, one per conversation. Your apps are never touched.",onPick:()=>b({...d,mode:"playwright"})}),t.jsx($p,{current:d.mode,value:"extension",disabled:a||g||!e.enabled,title:"Your browser",body:"Uses the Chrome you are signed in to, in background tabs, through the buddi extension.",onPick:()=>b({...d,mode:"extension"})})]}),n?null:t.jsx("p",{className:"muted",children:"Using your own apps is macOS-only."}),g?t.jsx("p",{className:"muted",children:"Finish or stop the current session before changing this."}):null,d.mode==="extension"?t.jsx(VW,{busy:a,timezone:r}):null]})}),n?t.jsx(ue,{title:"Apps agents may use",panel:!0,children:t.jsxs(ie,{children:[d.mode!=="computer"?t.jsx("p",{className:"muted",children:"Only used by “Use my apps”. The list is kept for when you switch back."}):null,t.jsx(GW,{settings:d,disabled:a||g||!e.enabled,onChange:b,onAdd:()=>u(!0)}),t.jsx(Ot,{summary:"Details",children:t.jsxs("div",{className:"ui-prose muted",children:[t.jsx("p",{children:"Agents see what is on screen in these apps, and what they see goes to the agent’s model provider. Allow only apps you want operated."}),t.jsx("p",{children:"Never type a password or a sign-in code in chat. Sign in yourself, in the app, while you have taken over."}),t.jsx("p",{children:"This is an allow list, not a sandbox: an allowed app’s own network traffic is not inspected."})]})})]})}):null,c?t.jsx(XW,{chosen:d.allowedApps,onClose:()=>u(!1),onPick:$=>{u(!1),d.allowedApps.includes($)||b({...d,allowedApps:[...d.allowedApps,$]})}}):null]}):null]})}const FW="kmbckpnnjfggeffkkbmkggojnolkdokb",_W="pbfpjefkiijjgefblpnlnlpmeaddfbah",zW="https://chromewebstore.google.com/detail/pbfpjefkiijjgefblpnlnlpmeaddfbah",UW=[FW,_W].filter(Boolean);function BW(e,n){const s=i=>/^\d+(\.\d+){0,3}$/.test(i.trim())?i.trim().split(".").map(Number):null,r=s(e),a=s(n);if(!r||!a)return!1;for(let i=0;i<4;i++){const l=(r[i]??0)-(a[i]??0);if(l!==0)return l<0}return!1}async function WW(){var e;try{if(typeof chrome>"u"||!((e=chrome==null?void 0:chrome.runtime)!=null&&e.sendMessage))return null;for(const n of UW)try{const s=await chrome.runtime.sendMessage(n,{type:"buddi.status"});if(s!=null&&s.installed)return s}catch{}return null}catch{return null}}function HW(e=navigator){var s,r,a;const n=e.userAgent??"";return(s=e.userAgentData)!=null&&s.mobile||/Android|iPhone|iPad|iPod|Mobile/i.test(n)?"phone":(a=(r=e.userAgentData)==null?void 0:r.brands)!=null&&a.some(i=>/Chromium/i.test(i.brand))||/Chrome\/|Chromium\/|Edg\//.test(n)&&!/Firefox\/|OPR\//.test(n)?"chromium":"other"}function KW(e){try{return new URL(e).origin===window.location.origin}catch{return!1}}function VW({busy:e,timezone:n}){const{data:s,error:r,reload:a}=me(()=>R.extension(),[],3e3),i=am(),l=me(()=>WW(),[],3e3).data??null,[o,c]=h.useState(""),[u,d]=h.useState(!1),[f,m]=h.useState(null),p=(l==null?void 0:l.state)==="pairing"?l.code??"":"";h.useEffect(()=>{p&&c(p)},[p]);const g=async y=>{d(!0),m(null);try{await y()}catch(w){m(w instanceof Error?w.message:String(w))}finally{d(!1),a()}},v=e||u,b=n??Intl.DateTimeFormat().resolvedOptions().timeZone,j=HW(),x=j==="phone"?null:j==="other"?t.jsx("p",{className:"muted",children:"The buddi extension needs Chrome, Edge, Brave or Arc on a computer. Open this page in one of them to install it."}):t.jsxs(ie,{children:[t.jsxs(te,{children:[t.jsx("span",{className:"muted",children:"Install the buddi extension from the Chrome Web Store, then pair it here."}),t.jsx(et,{}),t.jsx(ht,{variant:"accent",href:zW,target:"_blank",rel:"noopener noreferrer",children:"Add to Chrome"})]}),t.jsx(Ot,{summary:"Developer install",children:t.jsxs("div",{className:"ui-prose muted",children:[t.jsx("p",{children:"Open chrome://extensions, turn on Developer mode, choose Load unpacked, and pick this folder."}),t.jsx(Dt,{label:"The unpacked extension",children:(s==null?void 0:s.path)??"…"})]})})]});return t.jsxs(ie,{divided:!0,children:[t.jsx(ne,{message:r??f}),t.jsxs(te,{children:[t.jsx(Ee,{tone:s!=null&&s.connected?"good":"warning",children:s!=null&&s.connected?"Connected":"Not connected"}),t.jsxs("span",{className:"muted",children:[s!=null&&s.connected&&s.pairedAt?`Paired with Chrome on ${i} since ${ct(s.pairedAt,b)}`:s!=null&&s.pairedAt?"Paired, but Chrome is not running the extension right now.":"No browser is paired with this buddi yet.",s!=null&&s.extension?` · extension ${s.extension}`:""]})]}),t.jsxs(ie,{children:[t.jsxs("p",{className:"muted",children:[l?`The browser you are reading this in has the extension, version ${l.version}.`:j==="phone"?"The extension runs in Chrome, Edge, Brave or Arc on a computer: install and pair it from there.":s!=null&&s.connected?"The browser you are reading this in has no buddi extension. You only need it here to pair this browser instead.":"The browser you are reading this in has no buddi extension yet.",(l==null?void 0:l.state)==="paired"?" It is already paired with a buddi.":"",(l==null?void 0:l.state)==="disconnected"?" It is not connected yet: press Connect in its popup.":""]}),l&&(s!=null&&s.extensionMinimum)&&BW(l.version,s.extensionMinimum)?t.jsx("p",{className:"muted",children:`This extension is ${l.version}; this buddi needs ${s.extensionMinimum} or later. Update it from chrome://extensions or the store.`}):null,l&&!KW(l.gateway)?t.jsx(G,{tone:"warning",children:`The extension is pointed at ${l.gateway}; set it to ${window.location.origin} in the popup.`}):null]}),s!=null&&s.pending?t.jsxs(te,{valign:"end",children:[t.jsx(re,{grow:!0,label:"Pair your browser",hint:"Type the six digits the buddi extension is showing.",children:t.jsx("input",{"aria-label":"Pairing code",inputMode:"numeric",placeholder:"482 913",value:o,onChange:y=>c(y.target.value)})}),t.jsx(et,{}),t.jsx(A,{variant:"accent",disabled:v||o.replace(/[^0-9]/g,"").length!==6,onClick:()=>void g(async()=>{await R.pairExtension(o),c("")}),children:"Pair"})]}):null,x?s!=null&&s.connected?t.jsx(Ot,{summary:"Pair a different browser",children:x}):x:null,t.jsx(te,{align:"end",children:t.jsx(A,{variant:"danger",disabled:v||!(s!=null&&s.pairedAt),onClick:()=>void g(()=>R.forgetExtension()),children:"Forget this browser"})})]})}function $p({current:e,value:n,title:s,body:r,health:a,disabled:i,onPick:l}){const o=e===n;return t.jsxs("button",{type:"button",role:"radio","aria-checked":o,className:"mode-option",disabled:i,onClick:()=>{o||l()},children:[t.jsx("span",{className:"mode-option-dot","aria-hidden":"true"}),t.jsxs("span",{className:"mode-option-text",children:[t.jsx("span",{className:"mode-option-title",children:s}),t.jsx("span",{className:"mode-option-body",children:r}),a?t.jsx("span",{className:"mode-option-health",role:"status",children:a}):null]})]})}function GW({settings:e,disabled:n,onChange:s,onAdd:r}){const a=me(()=>R.installedApps(),[]),i=l=>{var o,c;return((c=(o=a.data)==null?void 0:o.apps.find(u=>u.id===l))==null?void 0:c.name)??l};return t.jsxs(t.Fragment,{children:[e.allowedApps.length===0?t.jsx(ve,{children:"No apps yet. Agents cannot touch anything until you add one."}):t.jsx("ul",{className:"ui-list","aria-label":"Allowed apps",children:e.allowedApps.map(l=>t.jsxs("li",{className:"ui-list-row",children:[t.jsx(Nn,{id:l,name:i(l),size:"sm"}),t.jsxs("span",{className:"ui-list-main",children:[t.jsxs("span",{className:"ui-list-title",children:[i(l),l===e.browserApp?t.jsx(Ee,{tone:"accent",className:"app-role",children:"browser"}):null]}),t.jsx("span",{className:"ui-list-sub mono",children:l})]}),t.jsxs(te,{children:[l!==e.browserApp&&QW(l)?t.jsx(A,{size:"sm",variant:"ghost",disabled:n,onClick:()=>s({...e,browserApp:l}),children:"Use as browser"}):null,l===e.browserApp?t.jsx("span",{className:"muted",children:"In use as the browser"}):t.jsx(A,{size:"sm",variant:"ghost",disabled:n,onClick:()=>s({...e,allowedApps:e.allowedApps.filter(o=>o!==l)}),children:"Remove"})]})]},l))}),t.jsxs(te,{children:[t.jsx(A,{variant:"accent",disabled:n,onClick:r,children:"Add an app"}),t.jsx("span",{className:"muted",children:"The app marked as browser is the one agents open websites in."})]}),e.mode==="computer"&&qW.includes(e.browserApp)?t.jsx(YW,{settings:e,disabled:n,onChange:s}):null]})}const qW=["com.google.Chrome","org.chromium.Chromium","com.microsoft.edgemac","com.brave.Browser"];function YW({settings:e,disabled:n,onChange:s}){var l;const a=((l=me(()=>R.browserProfiles(e.browserApp),[e.browserApp]).data)==null?void 0:l.profiles)??[],i=e.browserProfile?a.some(o=>o.directory===e.browserProfile):!0;return t.jsx(re,{label:"Browser profile",hint:e.browserProfile?"Websites open in this profile, signed in as it is.":"Not chosen: websites open in whichever profile’s window is in front, or the last one you used.",children:t.jsxs("select",{value:e.browserProfile??"",disabled:n,onChange:o=>{const{browserProfile:c,...u}=e;s(o.target.value?{...u,browserProfile:o.target.value}:u)},children:[t.jsx("option",{value:"",children:"Whichever is in front"}),!i&&e.browserProfile?t.jsxs("option",{value:e.browserProfile,children:[e.browserProfile," (not found)"]}):null,a.map(o=>t.jsxs("option",{value:o.directory,children:[o.name,o.directory==="Default"?"":` (${o.directory})`]},o.directory))]})})}const JW=["com.google.Chrome","com.apple.Safari","org.chromium.Chromium","com.microsoft.edgemac","com.brave.Browser","org.mozilla.firefox","company.thebrowser.Browser"];function QW(e){return JW.includes(e)}function XW({chosen:e,onClose:n,onPick:s}){const r=me(()=>R.installedApps(),[]),[a,i]=h.useState(""),[l,o]=h.useState(""),c=h.useMemo(()=>{var f;const u=((f=r.data)==null?void 0:f.apps)??[],d=a.trim().toLowerCase();return u.filter(m=>!d||m.name.toLowerCase().includes(d)||m.id.toLowerCase().includes(d)).slice(0,60)},[r.data,a]);return t.jsxs(Ge,{title:"Add an app",onClose:n,children:[t.jsx("input",{autoFocus:!0,"aria-label":"Search apps",placeholder:"Search installed apps",value:a,onChange:u=>i(u.target.value)}),t.jsx(ne,{message:r.error}),r.data?c.length===0?t.jsx(ve,{children:"No app matches."}):t.jsx("ul",{className:"ui-list","aria-label":"Installed apps",children:c.map(u=>{const d=e.includes(u.id);return t.jsxs("li",{className:"ui-list-row",children:[t.jsx(Nn,{id:u.id,name:u.name,size:"sm"}),t.jsxs("span",{className:"ui-list-main",children:[t.jsx("span",{className:"ui-list-title",children:u.name}),t.jsx("span",{className:"ui-list-sub mono",children:u.id})]}),t.jsx(A,{size:"sm",disabled:d,onClick:()=>s(u.id),children:d?"Allowed":"Allow"})]},u.id)})}):t.jsx(ve,{children:"Reading your Applications folder…"}),t.jsx(Ot,{summary:"Add by bundle identifier instead",children:t.jsxs(te,{children:[t.jsx("input",{"aria-label":"Bundle identifier",placeholder:"com.apple.TextEdit",value:l,onChange:u=>o(u.target.value)}),t.jsx(A,{disabled:!l.trim(),onClick:()=>s(l.trim()),children:"Allow this identifier"})]})})]})}function ZW({data:e,error:n,reload:s,compact:r=!1,refresh:a,screenshotSrc:i,onScreenshotError:l,onScreenshotLoad:o,controls:c=!0}){var D,$,L;const[u,d]=h.useState(!1),[f,m]=h.useState(null),[p,g]=h.useState(null),[v,b]=h.useState(null),[j,x]=h.useState(!1),y=am(),w=async O=>{d(!0),m(null),b(null),x(!1);try{const M=O!=="stop"&&(e!=null&&e.session)?await R.browserControl(O,e.session.id):await R.browserControl(O);O==="takeover"?M.hand&&M.session?g(M.session.id):M.handReason==="browser-offline"?x(!0):b(M.handMessage??null):g(null)}catch(M){m(M instanceof Error?M.message:String(M))}finally{d(!1),s()}},k=async()=>{if(e!=null&&e.settings){d(!0),m(null);try{e.session&&await R.browserControl("release",e.session.id),await R.browserSettings({...e.settings,mode:"playwright"}),x(!1),g(null),b("Switched to buddi’s browser. Send the agent a message and it opens the page there.")}catch(O){m(O instanceof Error?O.message:String(O))}finally{d(!1),s()}}},N=p&&((D=e==null?void 0:e.session)==null?void 0:D.id)===p&&e.state==="paused"?p:null,S=!!(e!=null&&e.enabled)&&!u,C=(e==null?void 0:e.mode)==="computer",E=(e==null?void 0:e.mode)==="extension",T=C?"Stop computer control interrupts native input and revokes access. Take over pauses agent input. Release ends this conversation’s control without closing your apps. Already dispatched actions cannot be undone. Avoid using the same mouse and keyboard while the agent is working.":"Stop all browsers closes every session and revokes access until you resume. Take over, Resume and Close & release affect only the selected conversation. An in-flight action is interrupted by closing its tabs. Actions already submitted cannot be undone.",I=e!=null&&e.busy?"Working":(e==null?void 0:e.state)==="running"?"Ready":(e==null?void 0:e.state)??"Connecting",F=e!=null&&e.busy||(e==null?void 0:e.state)==="running"?"good":(e==null?void 0:e.state)==="stopped"||(e==null?void 0:e.state)==="error"?"critical":void 0;return t.jsxs("section",{className:"browser-panel","data-compact":r?"true":void 0,"aria-label":"Host browser",children:[t.jsxs("div",{className:"browser-heading",children:[t.jsxs("div",{children:[r?null:t.jsx("p",{className:"browser-eyebrow",children:"On your host machine"}),t.jsx("h2",{className:"browser-title",children:C?"Computer":E?"Your browser":"Browser"})]}),t.jsx(Ee,{tone:F,children:t.jsx("span",{role:"status",children:I})})]}),r?t.jsx("a",{className:"browser-full-view",href:"#/browser",children:C?"Open computer view & settings ↗":"Open full browser view ↗"}):t.jsx("p",{className:"ui-page-lede",children:C?"Your apps, operated through macOS accessibility, screenshots and input. No browser debugging connection.":E?"Your own Chrome, signed in as you, working in background tabs grouped as “buddi”. You keep browsing.":"A real browser window, driven by your assistant. You stay in control."}),t.jsx(ne,{message:n??f}),c?t.jsxs(te,{children:[t.jsx(A,{variant:"danger",disabled:!S||(e==null?void 0:e.state)==="stopped",onClick:()=>void w("stop"),children:C?"Stop computer control":"Stop all browsers"}),t.jsx(A,{disabled:!S||!(e!=null&&e.session)||(e==null?void 0:e.state)==="paused",onClick:()=>void w("takeover"),children:"Take over"}),t.jsx(A,{disabled:!S||(e==null?void 0:e.busy)||!["stopped","paused"].includes((e==null?void 0:e.state)??""),onClick:()=>void w("resume"),children:"Resume access"}),t.jsx(A,{disabled:!S||!(e!=null&&e.session),onClick:()=>void w("release"),children:C?"Release control":"Close & release"})]}):null,c?r?t.jsx(Ot,{summary:"About these controls",children:t.jsx("p",{className:"muted",children:T})}):t.jsx("p",{className:"muted",children:T}):null,v?t.jsx(G,{tone:"warning",role:"status",children:v}):null,j&&E?t.jsx(G,{tone:"warning",role:"status",title:"Your browser isn’t connected.",action:t.jsxs(te,{align:"end",children:[e!=null&&e.settings?t.jsx(A,{size:"sm",disabled:u,onClick:()=>void k(),children:"Switch to buddi’s browser"}):null,t.jsx(A,{size:"sm",variant:"accent",disabled:u,onClick:()=>void w("takeover"),children:"Try again"})]}),children:`There is no Chrome tab to show or drive. Open Chrome on ${y}: the buddi extension reconnects by itself, then try again. Or switch every agent to buddi’s own browser (it doesn’t have your Chrome sign-ins; switch back on this page).`}):null,e!=null&&e.message&&!N&&!(j&&E)?t.jsx(G,{tone:"warning",role:"status",children:e.message}):null,e!=null&&e.session?t.jsxs("div",{className:"browser-task",children:[t.jsxs("div",{className:"ui-row",children:[t.jsx("strong",{children:e.session.agentId}),t.jsxs("span",{className:"muted",children:[e.session.steps," / ",e.session.maxSteps," steps"]})]}),r?null:t.jsx("p",{children:e.session.task}),t.jsxs("p",{className:"muted",children:["Last action: ",e.lastAction??"None"," · Access expires ",Xt(new Date(e.session.expiresAt),Intl.DateTimeFormat().resolvedOptions().timeZone)]})]}):t.jsx("p",{className:"browser-task muted",children:e!=null&&e.enabled?C?"No agent is driving. Ask an agent granted browser.* to open a website or an allowed native app.":"No agent is driving. Ask an agent granted browser.* to open a website.":"The host browser is unavailable. Start buddi serve on a machine with a desktop session."}),N?t.jsx(MW,{sessionId:N,csrf:Bi(),onGiveBack:()=>void w("resume")}):null,t.jsxs("div",{className:"browser-window",hidden:!!N,children:[t.jsxs("div",{className:"browser-address",children:[t.jsx("span",{"aria-hidden":"true",children:"◉"}),t.jsx("span",{children:(($=e==null?void 0:e.page)==null?void 0:$.url)??(C?"Waiting for an application":"Waiting for a website")})]}),e!=null&&e.hasScreenshot&&e.page?t.jsxs("figure",{children:[t.jsx("img",{src:i??`/api/browser/screenshot?v=${encodeURIComponent(e.page.id)}${e.session?`&sessionId=${encodeURIComponent(e.session.id)}`:""}${a?`&tick=${a}`:""}`,alt:`Last browser observation: ${e.page.title||e.page.url}`,...l?{onError:l}:{},...o?{onLoad:o}:{}},i??e.page.id),t.jsxs("figcaption",{children:["Last observation · ",Xt(new Date(e.page.capturedAt),Intl.DateTimeFormat().resolvedOptions().timeZone)," · ",e.page.title||"Untitled page"]})]}):t.jsxs("div",{className:"browser-empty",children:[t.jsx("strong",{children:C?"Your selected app will appear here":"Your browser activity will appear here"}),t.jsx("p",{children:C?"Only the selected app window is captured, not the whole desktop. This preview is not interactive.":"This is a view of the host browser, not a second browser or a remote desktop."})]})]}),(((L=e==null?void 0:e.page)==null?void 0:L.tabs.length)??0)>1?t.jsx(Ot,{summary:`${e.page.tabs.length} open tabs`,children:t.jsx("ul",{className:"ui-prose",children:e.page.tabs.map(O=>t.jsxs("li",{children:[O.title||O.id," — ",O.url]},O.id))})}):null,t.jsxs("p",{className:"muted",children:[C?"Sign in directly in the host app during takeover. Don’t send passwords or MFA codes in chat. Native apps retain your existing logins and documents. Secure accessibility fields are masked; other sensitive window content can still appear in screenshots.":"Sign in directly in this conversation’s host tab during takeover. Don’t send passwords or MFA codes in chat. Agent tabs share saved logins and cookies."," ",N?"While you are driving this is a live view of the page; nothing you type is kept.":"Screenshots update after agent actions; this is not a live video feed."]})]})}const eH=2e3,tH=5;function nH(e,n){if(!e.hasScreenshot||!e.page)return null;const s=e.session?`&sessionId=${encodeURIComponent(e.session.id)}`:"";return`/api/browser/screenshot?v=${encodeURIComponent(e.page.id)}${s}`}function sH({status:e,error:n,reload:s,steps:r,live:a,focusedStepId:i=null}){var y;const[l,o]=h.useState(0),[c,u]=h.useState(0),d=c>=tH;h.useEffect(()=>{if(!a||d)return;const w=window.setInterval(()=>{typeof document<"u"&&document.hidden||o(k=>k+1)},eH);return()=>window.clearInterval(w)},[a,d]);const f=h.useRef(null);a&&(e!=null&&e.session)&&(f.current=e);const[m,p]=h.useState(null),g=h.useRef(null),v=((y=e==null?void 0:e.page)==null?void 0:y.id)??null;h.useEffect(()=>{const w=a&&e?nH(e):null;if(!w||typeof fetch!="function"||typeof(URL==null?void 0:URL.createObjectURL)!="function")return;let k=!1;return(async()=>{try{const N=await fetch(w);if(!N.ok||k)return;const S=await N.blob();if(k)return;const C=URL.createObjectURL(S);g.current&&URL.revokeObjectURL(g.current),g.current=C,p(C)}catch{}})(),()=>{k=!0}},[a,v]),h.useEffect(()=>()=>{g.current&&typeof(URL==null?void 0:URL.revokeObjectURL)=="function"&&URL.revokeObjectURL(g.current)},[]);const b=f.current,j=a?e:b?m?b:{...b,hasScreenshot:!1}:e,x=r.at(-1)??null;return t.jsxs("div",{className:"wb-browser","data-testid":"browser-view","data-live":a?"true":"false",children:[t.jsx(ZW,{data:j,error:n,reload:s,compact:!0,controls:a,...a?{refresh:l}:{},...!a&&m?{screenshotSrc:m}:{},onScreenshotError:()=>u(w=>w+1),onScreenshotLoad:()=>u(0)}),a?d?t.jsx("p",{className:"muted wb-browser-ended",role:"status",children:"The last observation could not be loaded. Showing what arrived before it."}):null:t.jsx("p",{className:"muted wb-browser-ended",role:"status",children:"This session has ended. What is on this panel is the last thing it showed."}),t.jsx(rH,{steps:r,newestId:(x==null?void 0:x.id)??null,focusedId:i??null,live:a})]})}function rH({steps:e,newestId:n,focusedId:s,live:r}){const a=h.useRef(null);return h.useEffect(()=>{var l;if(!s||!a.current)return;const i=a.current.querySelector(`[data-step="${CSS!=null&&CSS.escape?CSS.escape(s):s}"]`);(l=i==null?void 0:i.scrollIntoView)==null||l.call(i,{block:"nearest"})},[s]),e.length===0?t.jsx("p",{className:"muted wb-browser-empty",children:r?"No action taken on this screen yet.":"This conversation took no action on the screen."}):t.jsx("section",{className:"wb-browser-steps","aria-label":"Steps taken on this screen",children:t.jsx("ol",{className:"wb-browser-list",ref:a,children:e.map((i,l)=>{const o=i.awaiting?"awaiting":i.ok===null?"running":i.ok?"ok":"failed";return t.jsxs("li",{"data-step":i.id,className:"wb-browser-step","data-state":o,"data-newest":i.id===n?"true":void 0,"data-focused":i.id===s?"true":void 0,children:[t.jsx("span",{className:"wb-browser-index mono",children:l+1}),t.jsxs("span",{className:"wb-browser-what",children:[t.jsx("strong",{children:i.action}),i.target?t.jsx("span",{className:"muted wb-browser-target",children:i.target}):null,i.error?t.jsx("span",{className:"wb-browser-error",children:i.error}):null]}),t.jsx("span",{className:"wb-browser-outcome","data-state":o,children:o==="awaiting"?"Awaiting approval":o==="running"?"Working":o==="ok"?"Done":"Failed"})]},i.id)})})})}function aH({agentId:e,conversationId:n}){const{data:s,error:r,reload:a}=me(()=>R.host(e,n),[e,n],2e3),[i,l]=h.useState(null),[o,c]=h.useState(!1),u=async p=>{c(!0),l(null);try{await p(),a()}catch(g){l(g instanceof Error?g.message:String(g))}finally{c(!1)}},d=(s==null?void 0:s.permissions)??[],f=(s==null?void 0:s.runs)??[],m=d.some(p=>!p.conversationId)?"Always allowed":d.length?"Conversation auto-mode":"Ask each time";return t.jsx(Ot,{className:"host-controls",summary:`Host execution · ${r?"Status unavailable":m}${f.length?` · ${f.length} running`:""}`,children:t.jsxs(ie,{gap:"sm",children:[t.jsx("p",{className:"muted",children:"Commands run as your user, not in a sandbox. Auto-mode covers all commands within its scope. Stop interrupts a command; revoke also ends the permission. Neither undoes completed changes."}),t.jsx(ne,{message:i??r}),d.map(p=>t.jsxs(te,{children:[t.jsxs("span",{children:[p.agentId,": ",p.conversationId?"conversation auto-mode":"always allowed"]}),t.jsx(A,{size:"sm",disabled:o,onClick:()=>void u(()=>R.revokeHost(p.id)),children:"Revoke permission"})]},p.id)),d.length?null:t.jsx("p",{className:"muted",children:"The next command will ask for approval. Choose its permission scope there."}),f.map(p=>t.jsxs(ie,{gap:"sm",children:[t.jsxs("p",{children:[p.agentId," · ",t.jsx("span",{className:"mono",children:p.cwd})]}),t.jsx(Dt,{children:p.command}),t.jsx(Dt,{label:"Command output",children:p.stdout||p.stderr?`${p.stdout}
117
- ${p.stderr}`:"Waiting for output…"}),t.jsx(te,{children:t.jsx(A,{size:"sm",variant:"danger",disabled:o,onClick:()=>void u(()=>R.stopHost(p.agentId,p.conversationId)),children:"Stop command"})})]},p.actionId))]})})}const NT="browser.act",iH="browser.status",Vd=new Set([NT,iH]);function lH(e,n,s){const r=e==null?void 0:e.session;return!r||!n||!s||r.agentId!==n||r.conversationId!==s?null:{id:`host-browser:${r.id}`,title:e.mode==="computer"?"Computer":"Browser",tool:"Host browser",renderer:"browser",source:"browser",pinned:!0,props:{},at:null,substantial:!1}}function oH(e,n){return{...e,title:`${n==="computer"?"Computer":"Browser"} (ended)`,pinned:!1}}function cH(e){var r;const n=[],s=new Map;for(const a of e)for(const i of a.blocks??[]){if(i.type==="tool_use"&&i.name===NT){const o={id:i.id,action:uH(i.input)??"act",target:dH(i.input),ok:null,awaiting:!1,error:null,at:a.at??null};n.push(o),s.set(i.id,o);continue}if(i.type!=="tool_result")continue;const l=s.get(i.toolUseId);if(l){if(((r=i.approval)==null?void 0:r.state)==="pending"){l.awaiting=!0,l.ok=null,l.error=null;continue}l.awaiting=!1,l.ok=i.ok,l.error=i.ok?null:hH(i)}}return n}function cN(e,n){var r;let s=!1;for(const a of e)for(const i of a.blocks??[])if(i.type==="tool_use"&&i.id===n&&(s=Vd.has(i.name)),i.type==="tool_result"&&i.toolUseId===n&&((r=i.approval)==null?void 0:r.state)==="pending")return null;return s?n:null}function uH(e){if(e===null||typeof e!="object")return null;const n=e.action;return typeof n=="string"&&n!==""?n:null}function dH(e){if(e===null||typeof e!="object")return null;const n=e;for(const r of["url","appId","direction","key","tabId"]){const a=n[r];if(typeof a=="string"&&a!=="")return a}const s=n.target;if(s!==null&&typeof s=="object"){const r=s,a=r.name;if(typeof a=="string"&&a!=="")return a;const i=r.ref;if(typeof i=="string"&&i!=="")return i;if(typeof r.x=="number"&&typeof r.y=="number")return`${r.x}, ${r.y}`}return null}function hH(e){for(const n of[e.error,e.output]){if(typeof n=="string"&&n.trim()!=="")return n.trim();if(n!==null&&typeof n=="object")for(const s of["message","error","reason"]){const r=n[s];if(typeof r=="string"&&r.trim()!=="")return r.trim()}}return null}const fH="web.read",mH="web.search",pH=new Set([fH,mH]);function gH({agentId:e,groupId:n,currentId:s,timezone:r,onSelect:a,onNew:i}){const[l,o]=h.useState(null),[c,u]=h.useState(null),[d,f]=h.useState(0);return h.useEffect(()=>{let m=!1;return o(null),u(null),(n?qe.groupConversations(n):qe.conversations(e,100)).then(p=>{m||o(p.conversations)}).catch(p=>{m||u(p instanceof Error?p.message:String(p))}),()=>{m=!0}},[e,n,d]),t.jsxs("section",{className:"wb-history","aria-label":"Past conversations",children:[t.jsxs("div",{className:"ui-toolbar",children:[t.jsx("strong",{children:"Past conversations"}),t.jsx("button",{className:"ui-btn",onClick:i,children:"New conversation"})]}),c?t.jsxs("p",{role:"alert",children:[c," ",t.jsx("button",{className:"ui-btn",onClick:()=>f(m=>m+1),children:"Retry"})]}):l===null?t.jsx("p",{className:"muted",children:"Loading conversations…"}):l.length===0?t.jsx("p",{className:"muted",children:"No conversations yet."}):t.jsx("ul",{children:l.map(m=>t.jsx("li",{children:t.jsxs("a",{href:n?xi(n,m.id):Ze(e,m.id),"aria-current":m.id===s?"page":void 0,onClick:p=>{p.button===0&&!p.metaKey&&!p.ctrlKey&&!p.shiftKey&&!p.altKey&&(p.preventDefault(),a(m.id))},children:[t.jsx("span",{children:m.preview||m.opening||"Untitled conversation"}),t.jsxs("small",{children:[ct(m.lastMessageAt??m.startedAt??m.createdAt??null,r)," · ",m.messageCount," messages",m.id===s?" · Current":""]})]})},m.id))}),t.jsx("a",{href:"#/conversations",children:"View all agents’ conversation records ↗"}),(l==null?void 0:l.length)===100?t.jsx("p",{className:"muted",children:"Showing the 100 most recent conversations."}):null]})}const ST="buddi.dismissedTabs";function xH(){try{const e=JSON.parse(sessionStorage.getItem(ST)??"{}");return!e||typeof e!="object"||Array.isArray(e)?{}:Object.fromEntries(Object.entries(e).filter(([,n])=>Array.isArray(n)&&n.every(s=>typeof s=="string")))}catch{return{}}}function uN(e){try{sessionStorage.setItem(ST,JSON.stringify(Object.fromEntries(Object.entries(e).slice(-100))))}catch{}}const tv="​",Tp=/(`[^`\n]+`)|(\*\*[^*\n]+\*\*)|(\*[^*\s][^*\n]*\*|_[^_\s][^_\n]*_)|(\[[^\]\n]+\]\([^)\s]+\))|(https?:\/\/[^\s)]+)|(@[a-z][a-z0-9-]*)/gi;function Rp(e,n,s){const r=[];let a=0,i=0;Tp.lastIndex=0;for(let l=Tp.exec(e);l;l=Tp.exec(e)){l.index>a&&r.push(e.slice(a,l.index));const o=l[0],c=`${s}-${i++}`;if(l[1])r.push(t.jsxs("span",{className:"cv-code",children:[t.jsx("span",{className:"cv-mark",children:"`"}),o.slice(1,-1),t.jsx("span",{className:"cv-mark",children:"`"})]},c));else if(l[2])r.push(t.jsxs("span",{className:"cv-b",children:[t.jsx("span",{className:"cv-mark",children:"**"}),o.slice(2,-2),t.jsx("span",{className:"cv-mark",children:"**"})]},c));else if(l[3])r.push(t.jsxs("span",{className:"cv-i",children:[t.jsx("span",{className:"cv-mark",children:o[0]}),o.slice(1,-1),t.jsx("span",{className:"cv-mark",children:o[0]})]},c));else if(l[4]){const u=o.indexOf("](");r.push(t.jsxs("span",{className:"cv-link-md",children:[t.jsx("span",{className:"cv-mark",children:"["}),t.jsx("span",{className:"cv-link",children:o.slice(1,u)}),t.jsx("span",{className:"cv-mark",children:o.slice(u)})]},c))}else if(l[5])r.push(t.jsx("span",{className:"cv-link",children:o},c));else{const u=l.index>0?e[l.index-1]:" ",d=/[\s(]/.test(u)?n.find(f=>f.handle.toLowerCase()===o.slice(1).toLowerCase()):void 0;r.push(d?t.jsx("span",{className:"cv-chip",...d.accent,children:o},c):o)}a=l.index+o.length}return a<e.length&&r.push(e.slice(a)),r}function vH(e,n){const s=e.split(`
118
- `);let r=null;return s.map((a,i)=>{const l=/^```(\w*)\s*$/.exec(a);if(r===null&&l){r=l[1]??"";const u=s.slice(i+1).some(d=>/^```\s*$/.test(d));return t.jsxs("div",{className:"cv-line","data-code":"open","data-unclosed":u?void 0:"true",children:[t.jsx("span",{className:"cv-mark",children:a}),r?t.jsx("span",{className:"cv-lang","aria-hidden":"true","data-paint-extra":"",children:tA(r)}):null]},i)}if(r!==null)return/^```\s*$/.test(a)?(r=null,t.jsx("div",{className:"cv-line","data-code":"close",children:t.jsx("span",{className:"cv-mark",children:a})},i)):t.jsx("div",{className:"cv-line","data-code":"body",children:t.jsx("span",{className:"cv-code-ink",children:a||tv})},i);const o=/^(#{1,3} )(.*)$/.exec(a);if(o)return t.jsxs("div",{className:"cv-line","data-h":o[1].length-1,children:[t.jsx("span",{className:"cv-mark",children:o[1]}),t.jsx("span",{className:"cv-h",children:Rp(o[2],n,String(i))})]},i);const c=/^(\s*)([-*]|\d+\.)( )(.*)$/.exec(a);return c?t.jsxs("div",{className:"cv-line",children:[c[1],t.jsx("span",{className:"cv-bullet",children:c[2]}),c[3],Rp(c[4],n,String(i))]},i):t.jsx("div",{className:"cv-line",children:a?Rp(a,n,String(i)):tv},i)})}const Xy=(e,n)=>`${e}-opt-${n}`;function jH({id:e,items:n,active:s,onPick:r,phone:a,maxHeight:i}){let l=null;return t.jsxs("div",{className:"cv-pop","data-testid":"mention-popup",children:[t.jsx("div",{className:"cv-pop-list",id:e,role:"listbox","aria-label":"Mention someone",style:i?{maxHeight:i}:void 0,children:n.map((o,c)=>{const u=o.group!==l?l=o.group:null;return t.jsxs(h.Fragment,{children:[u?t.jsx("div",{className:"cv-pop-group",role:"presentation",children:u}):null,t.jsxs("div",{id:Xy(e,c),role:"option","aria-selected":c===s,"aria-label":`${o.name}, @${o.handle}. ${o.effect}`,className:"cv-pop-row","data-mention":"true","data-active":c===s||void 0,onMouseDown:d=>{d.preventDefault(),r(o)},children:[t.jsx(Nn,{id:o.id,name:o.name,size:"sm",...o.face?{face:o.face}:{}}),t.jsxs("span",{className:"cv-pop-title",children:[o.name," ",t.jsxs("span",{className:"cv-pop-handle",children:["@",o.handle]})]}),c===s?t.jsx("span",{className:"cv-pop-effect",children:o.effect}):null,c===s&&!a?t.jsx("kbd",{className:"cv-kbd",children:"↵"}):null]})]},o.id)})}),a?null:t.jsxs("div",{className:"cv-pop-foot","aria-hidden":"true",children:[t.jsxs("span",{children:[t.jsx("kbd",{className:"cv-kbd",children:"↑"}),t.jsx("kbd",{className:"cv-kbd",children:"↓"})," choose"]}),t.jsxs("span",{children:[t.jsx("kbd",{className:"cv-kbd",children:"↵"})," or ",t.jsx("kbd",{className:"cv-kbd",children:"Tab"})," mention"]}),t.jsxs("span",{children:[t.jsx("kbd",{className:"cv-kbd",children:"Esc"})," close"]})]})]})}function yH({id:e,items:n,active:s,onPick:r,phone:a,query:i,maxHeight:l}){if(n.length===0)return t.jsx("div",{className:"cv-pop","data-testid":"command-menu",children:t.jsx("div",{className:"cv-pop-list",id:e,role:"listbox","aria-label":"Commands",children:t.jsxs("div",{className:"cv-pop-empty",role:"status",children:["No command called ",t.jsxs("span",{className:"mono",children:["/",i]}),". ",a?"Send sends it as text.":"Enter sends it as text."]})})});let o=null;return t.jsxs("div",{className:"cv-pop","data-testid":"command-menu",children:[t.jsx("div",{className:"cv-pop-list",id:e,role:"listbox","aria-label":"Commands",style:l?{maxHeight:l}:void 0,children:n.map((c,u)=>{const d=c.group!==o?o=c.group:null;return t.jsxs(h.Fragment,{children:[d?t.jsx("div",{className:"cv-pop-group",role:"presentation",children:d}):null,t.jsxs("div",{id:Xy(e,u),role:"option","aria-selected":u===s,"aria-disabled":c.off||void 0,"aria-label":`/${c.name}${c.args?` ${c.args}`:""}: ${c.desc}`,className:"cv-pop-row","data-cmd":"true","data-active":u===s||void 0,"data-off":c.off||void 0,onMouseDown:f=>{f.preventDefault(),c.off||r(c)},children:[t.jsxs("span",{className:"cv-pop-cmd",children:["/",c.name,c.args?t.jsxs("span",{className:"cv-pop-args",children:[" ",c.args]}):null]}),t.jsx("span",{className:"cv-pop-desc",children:c.desc}),a?null:c.key?t.jsx("kbd",{className:"cv-kbd",children:c.key}):u===s?t.jsx("kbd",{className:"cv-kbd",children:"↵"}):null]})]},`${c.group}/${c.name}`)})}),a?null:t.jsxs("div",{className:"cv-pop-foot","aria-hidden":"true",children:[t.jsxs("span",{children:[t.jsx("kbd",{className:"cv-kbd",children:"↑"}),t.jsx("kbd",{className:"cv-kbd",children:"↓"})," choose"]}),t.jsxs("span",{children:[t.jsx("kbd",{className:"cv-kbd",children:"↵"})," run"]}),t.jsxs("span",{children:[t.jsx("kbd",{className:"cv-kbd",children:"Tab"})," add words"]}),t.jsxs("span",{children:[t.jsx("kbd",{className:"cv-kbd",children:"Esc"})," close"]})]})]})}const wH=350,bH=60;function kH({conversationId:e,onText:n,onNotice:s}){const[r,a]=h.useState("idle"),i=h.useRef("idle"),l=x=>{i.current=x,a(x)},o=h.useRef(null),c=h.useRef(null),u=h.useRef(null),d=h.useRef(null),f=h.useRef(null),m=h.useRef({onText:n,onNotice:s,conversationId:e});m.current={onText:n,onNotice:s,conversationId:e};const p=()=>{u.current!==null&&(window.clearTimeout(u.current),u.current=null)},g=async()=>{if(i.current!=="idle")return;m.current.onNotice(null),l("starting"),c.current=null;let x;try{x=await HB(k=>{var N;return(N=f.current)==null?void 0:N.call(f,k)})}catch(k){d.current=null,l("idle"),m.current.onNotice(WB(k));return}const y=c.current;c.current=null;const w=i.current;if(y==="discard"||w!=="starting"){x.cancel(),w==="starting"&&l("idle");return}o.current=x,l("recording"),u.current=window.setTimeout(()=>void v(!1),zB),y&&v(y.sendNow)},v=async x=>{d.current=null;const y=o.current;if(!y){i.current==="starting"&&(c.current={sendNow:x});return}o.current=null,p(),l("transcribing");try{const w=await y.stop();if(w.size<=44){m.current.onNotice("Nothing was recorded.");return}const k=new File([w],`recording-${new Date().toISOString().slice(0,19).replace(/[:T]/g,"-")}.wav`,{type:"audio/wav"}),N=await qe.attach(k),S=m.current.conversationId,C=await qe.transcribe({artifactId:N.artifactId,...S?{conversationId:S}:{}});m.current.onText(C.text,x)}catch(w){m.current.onNotice(w instanceof xe||w instanceof Error?w.message:String(w))}finally{l("idle")}},b=()=>{d.current=null;const x=o.current;if(!x){i.current==="starting"&&(c.current="discard");return}o.current=null,p(),x.cancel(),l("idle")};h.useEffect(()=>{const x=y=>{if(d.current===null)return;const w=Date.now()-d.current;d.current=null,w>=wH&&v(y.shiftKey)};return window.addEventListener("pointerup",x),()=>window.removeEventListener("pointerup",x)},[]);const j=r==="starting"||r==="recording";return h.useEffect(()=>{if(!j)return;const x=y=>{y.isComposing||y.repeat||(y.key==="Escape"?(y.preventDefault(),y.stopPropagation(),b()):y.key==="Enter"&&(y.preventDefault(),y.stopPropagation(),v(y.shiftKey)))};return window.addEventListener("keydown",x,!0),()=>window.removeEventListener("keydown",x,!0)},[j]),h.useEffect(()=>()=>{var x;(x=o.current)==null||x.cancel(),p()},[]),{state:r,hold:()=>{d.current=Date.now(),g()},start:()=>{d.current=null,g()},finish:x=>void v(x),discard:b,levels:f}}function NH({disabled:e,voice:n}){const s=a=>{e||a.button>0||n.state!=="idle"||(a.preventDefault(),n.hold())},r=a=>{a.detail!==0||e||n.state!=="idle"||n.start()};return t.jsx("button",{type:"button",className:"ui-icon-btn wb-mic","data-size":"sm","aria-label":"Talk",title:"Talk: click to start, or hold to speak and let go to stop",disabled:e,onPointerDown:s,onClick:r,onContextMenu:a=>a.preventDefault(),children:t.jsx(le,{name:"mic"})})}function SH({voice:e}){const n=h.useRef(null),s=e.state==="transcribing";return h.useEffect(()=>{var r;(r=n.current)==null||r.focus()},[]),t.jsxs("div",{className:"wb-listening",role:"group","aria-label":"Recording","data-phase":s?"transcribing":"listening",children:[t.jsx("p",{className:"wb-listening-label","aria-live":"polite",children:s?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"wb-listening-spinner","aria-hidden":"true"}),"Transcribing…"]}):"Listening…"}),t.jsxs("div",{className:"wb-listening-row",children:[t.jsx(CH,{sink:e.levels,frozen:s}),t.jsx("button",{type:"button",className:"wb-send","data-variant":"quiet","aria-label":"Discard recording",title:"Discard (Escape)",disabled:s,onClick:()=>e.discard(),children:t.jsx(le,{name:"close"})}),t.jsx("button",{ref:n,type:"button",className:"wb-send","aria-label":"Stop and transcribe",title:"Stop and transcribe (Enter); Shift sends at once",disabled:s,onClick:r=>e.finish(r.shiftKey),children:t.jsx(le,{name:"check"})})]})]})}function CH({sink:e,frozen:n}){const[s,r]=h.useState(()=>Array(bH).fill(0));return h.useEffect(()=>{if(!n)return e.current=a=>r(i=>[...i.slice(1),a]),()=>{e.current=null}},[n]),t.jsx("div",{className:"wb-wave","aria-hidden":"true","data-testid":"waveform",children:s.map((a,i)=>t.jsx("span",{className:"wb-wave-bar",style:{"--level":a.toFixed(3)}},i))})}const EH="This browser cannot capture a tab. Chrome, Safari and Firefox can, on a secure address.",pd="The tab could not be captured. Try again, and pick the tab itself rather than the whole screen.",AH=e=>e instanceof Error&&(e.name==="NotAllowedError"||e.name==="AbortError");async function $H(e={}){var r;const n=e.media??(typeof navigator>"u"?void 0:navigator.mediaDevices);if(!n||typeof n.getDisplayMedia!="function")throw new Error(EH);let s;try{s=await n.getDisplayMedia({video:{displaySurface:"browser"},audio:!1,selfBrowserSurface:"exclude",surfaceSwitching:"exclude",preferCurrentTab:!1})}catch(a){if(AH(a))return null;throw new Error(pd)}try{const a=e.document??document,i=a.createElement("video");i.muted=!0,i.playsInline=!0,i.srcObject=s,await new Promise((d,f)=>{i.onloadedmetadata=()=>d(),i.onerror=()=>f(new Error(pd))}),await i.play(),await new Promise(d=>{const f=i.requestVideoFrameCallback;typeof f=="function"?f.call(i,()=>d()):setTimeout(d,120)});const l=a.createElement("canvas");l.width=i.videoWidth,l.height=i.videoHeight;const o=l.getContext("2d");if(!o||l.width===0)throw new Error(pd);o.drawImage(i,0,0);const c=await new Promise(d=>l.toBlob(d,"image/png"));if(!c)throw new Error(pd);const u=(((r=e.now)==null?void 0:r.call(e))??new Date).toISOString().slice(0,19).replace("T"," ").replace(/:/g,".");return new File([c],`Tab ${u}.png`,{type:"image/png"})}finally{s.getTracks().forEach(a=>a.stop())}}const dN="Send files once the agent has answered.",nv="wb-composer-input",TH="(max-width: 720px)",hN={desk:288,phone:240};function RH(e,n,s){const[r,a]=h.useState(void 0);return h.useEffect(()=>{if(!n)return;const i=window.visualViewport??null,l=()=>{const o=e.current;if(!o||typeof o.getBoundingClientRect!="function")return;const c=o.getBoundingClientRect().top-(i?i.offsetTop:0),u=Math.floor(c-(s?16:64)),d=s?hN.phone:hN.desk;a(u>0&&u<d?Math.max(u,96):void 0)};return l(),i==null||i.addEventListener("resize",l),i==null||i.addEventListener("scroll",l),window.addEventListener("resize",l),()=>{i==null||i.removeEventListener("resize",l),i==null||i.removeEventListener("scroll",l),window.removeEventListener("resize",l)}},[n,s,e]),r}const Zy=h.forwardRef(function({disabled:n,running:s,onSend:r,onStop:a,agentName:i,draft:l,model:o,setupHref:c,thinking:u,onThinking:d,onOpenFile:f,mentions:m,team:p,onCommand:g,history:v,threadKey:b,conversationId:j,readAloud:x,onReadAloud:y,placeholder:w,slim:k},N){var Zi,ui,di;const S=b?`buddi.draft.${b}`:null,C=B=>{if(!B)return"";try{return window.localStorage.getItem(B)??""}catch{return""}},[E,T]=h.useState(()=>C(S)),[I,F]=h.useState(()=>E.length),[D,$]=h.useState([]),[L,O]=h.useState(!1),[M,P]=h.useState(null),[H,U]=h.useState(!1),[V,z]=h.useState(null),X=h.useRef(null),K=h.useRef(null),ee=h.useRef(null),ce=ws(TH),pe=`cv-pop-${h.useId().replace(/[^a-zA-Z0-9_-]/g,"")}`,oe=ZD(),Re=h.useMemo(()=>{const B=He=>p==null?void 0:p.agents.find(en=>en.id===He),Fe=(He,en)=>Oi(jo(He??{id:en}));if(m)return m.map(He=>{const en=He.id??He.handle,xn=B(en);return{id:en,handle:He.handle,name:He.name,effect:`Asks @${He.handle} in this room`,group:"In this room",accent:Fe(xn,en),...xn?{face:xn}:{}}});if(!p)return[];const We=p.agents.find(He=>He.roles.includes(Fr)&&He.id!==p.selfId),Ut=p.agents.filter(He=>He.id!==p.selfId&&He!==We);return[...We?[{id:We.id,handle:We.handle,name:We.name,effect:`Borrows ${We.name} for this message`,group:"Borrow",accent:Oi({key:"buddi"}),face:We}]:[],...Ut.map(He=>({id:He.id,handle:He.handle,name:He.name,effect:`${i} asks @${He.handle}`,group:"Ask a teammate",accent:Fe(He,He.id),face:He}))]},[m,p,i]),Oe=!m&&p?((Zi=p.agents.find(B=>B.roles.includes(Fr)&&B.id!==p.selfId))==null?void 0:Zi.handle)??null:null,[Je,W]=h.useState(!1),[se,Y]=h.useState(0),Ne=!!g,we=Ne&&i_(E,I),fe=!Je&&Re.length>0?r_(E,I):null,ge=!Je&&Ne&&!fe?a_(E,I):null,Pe=fe?Re.filter(B=>!we||B.group!=="Borrow").filter(B=>B.handle.toLowerCase().startsWith(fe.query.toLowerCase())||B.name.toLowerCase().startsWith(fe.query.toLowerCase())).map(B=>we?{...B,group:"Talk to",effect:`Talk to ${B.name} from here on`}:B).slice(0,8):[],je=h.useMemo(()=>[...qD(i,s),...JD(oe)],[i,s,oe]),de=ge?je.filter(B=>B.name.startsWith(ge.query.toLowerCase())):[],ke=fe&&Pe.length>0?"mention":ge?"slash":null,Be=ke==="mention"?Pe:ke==="slash"?de:[],Ue=Be.length>0?Math.min(se,Be.length-1):-1,ut=RH(ee,ke!==null,ce),dt=v??[],[Q,Ae]=h.useState(-1),tt=h.useRef(E),Ct=h.useRef(S);if(Ct.current!==S){Ct.current=S;const B=C(S);tt.current=B,B!==E&&(T(B),F(B.length),Ae(-1),z(null))}const yt=B=>{if(tt.current=B,!!S)try{B===""?window.localStorage.removeItem(S):window.localStorage.setItem(S,B)}catch{}},kt=B=>{T(B.value),F(B.caret),W(!1),Y(0),Q<0&&yt(B.value);const Fe=K.current;Fe&&(Fe.value=B.value,Fe.setSelectionRange(B.caret,B.caret),window.requestAnimationFrame(()=>{Fe.focus(),Fe.setSelectionRange(B.caret,B.caret)}))},Bn=B=>{T(B),F(B.length),W(!1);const Fe=K.current;Fe&&(Fe.value=B,Fe.setSelectionRange(B.length,B.length))},hs=B=>!B.value.slice(0,B.selectionStart??B.value.length).includes(`
119
- `),In=()=>E===""||Q>=0&&E===dt[Q],fs=()=>{Q<0||(Ae(-1),Bn(tt.current))},Zt=D.some(B=>B.state==="uploading"),ms=D.length>0,Tt=s&&ms,$e=!n&&!Zt&&!Tt&&E.trim()!=="",Qe=B=>{const Fe=[];for(const We of Array.from(B??[])){const Ut=`${We.name}:${We.size}:${Math.random().toString(36).slice(2,8)}`;Fe.push(Ut);const He=We.type.startsWith("image/")&&typeof URL.createObjectURL=="function"?URL.createObjectURL(We):null;$(en=>[...en,{key:Ut,filename:We.name||"Pasted image",mime:We.type||"application/octet-stream",sizeBytes:We.size,thumbnail:He,state:"uploading"}]),qe.attach(We).then(en=>$(xn=>xn.map(ts=>ts.key===Ut?{...ts,state:"ready",uploaded:en}:ts))).catch(en=>$(xn=>xn.map(ts=>ts.key===Ut?{...ts,state:"failed",error:en instanceof xe?en.message:String(en)}:ts)))}return Fe},ze=B=>{B.thumbnail&&typeof URL.revokeObjectURL=="function"&&URL.revokeObjectURL(B.thumbnail)},Nt=B=>{const Fe=D.find(We=>We.key===B);Fe&&(ze(Fe),Fe.state==="ready"&&Fe.uploaded&&qe.discardAttachment(Fe.uploaded.artifactId).catch(()=>{})),$(We=>We.filter(Ut=>Ut.key!==B)),(V==null?void 0:V.kind)==="long"&&V.key===B&&z(null)};h.useImperativeHandle(N,()=>({addFiles:B=>{var Fe;Qe(B),(Fe=K.current)==null||Fe.focus()},focus:()=>{var B;return(B=K.current)==null?void 0:B.focus()}}));const q=h.useRef(D);q.current=D,h.useEffect(()=>()=>q.current.forEach(ze),[]);const he=h.useRef(0);h.useEffect(()=>{if(!l||l.at===he.current)return;he.current=l.at;const B=E.trim()==="";T(We=>We.trim()===""?l.text:We),Q<0&&B&&yt(l.text);const Fe=K.current;Fe&&(Fe.focus(),window.requestAnimationFrame(()=>{Fe.setSelectionRange(Fe.value.length,Fe.value.length),F(Fe.value.length)}))},[l]);const Sn=()=>{Ae(-1),yt(""),T(""),F(0),z(null),W(!1)},on=(B,Fe)=>{if(g){if(B==="stop"&&!s){Sn();return}Sn(),g(B,Fe)}},Se=B=>{const Fe=(B??E).trim();if(B===void 0?!$e:n||Zt||Tt||Fe==="")return;const We=B===void 0&&g?l_(Fe):null;if(We&&Sk(We.name)&&D.length===0){if(We.name==="use"&&We.arg===""){kt({value:"/use @",caret:6});return}on(We.name,We.arg.replace(/^@/,""));return}const Ut=D.filter(He=>He.state==="ready"&&He.uploaded).map(He=>He.uploaded);r(Fe,Ut),D.forEach(ze),Sn(),$([])},Me=B=>{if(fe){if(we&&g){on("use",B.handle);return}kt(o_(E,I,fe.start,B.handle))}},nt=(B,Fe)=>{if(B.off)return;const We=E.slice(I);if(Fe||QD(B)){const He=`/${B.name} ${B.name==="use"?"@":""}`;kt({value:He+We.replace(/^\S*/,"").replace(/^ /,""),caret:He.length});return}if(B.source==="chat"&&Sk(B.name)){on(B.name,"");return}const Ut=`/${B.name}`;if(n||Zt||Tt){kt({value:`${Ut} `,caret:Ut.length+1});return}Se(Ut)},lt=B=>{if(B.nativeEvent.isComposing)return;if(ke&&Be.length>0){if(B.key==="ArrowDown"){B.preventDefault(),Y((Ue+1)%Be.length);return}if(B.key==="ArrowUp"){B.preventDefault(),Y((Ue-1+Be.length)%Be.length);return}if(B.key==="Enter"&&!B.shiftKey||B.key==="Tab"){B.preventDefault();const He=Be[Ue];ke==="mention"?Me(He):nt(He,B.key==="Tab");return}}if(ke&&B.key==="Escape"){B.preventDefault(),W(!0);return}if(B.key==="ArrowUp"&&!B.shiftKey&&!B.altKey&&!B.metaKey&&!B.ctrlKey){const He=B.currentTarget;if(dt.length>0&&Q+1<dt.length&&hs(He)&&In()){B.preventDefault(),Q<0&&(tt.current=E),Ae(Q+1),Bn(dt[Q+1]);return}}if(B.key==="ArrowDown"&&!B.shiftKey&&!B.altKey&&!B.metaKey&&!B.ctrlKey&&Q>=0&&E===dt[Q]){if(B.preventDefault(),Q===0){fs();return}Ae(Q-1),Bn(dt[Q-1]);return}if(B.key==="Escape"&&Q>=0){B.preventDefault(),fs();return}if(B.key==="Escape"&&s&&g){B.preventDefault(),a();return}const Fe=B.currentTarget,We=Fe.selectionStart??I,Ut=Fe.selectionStart===Fe.selectionEnd;if(B.key==="Tab"&&Ut&&!B.altKey&&!B.metaKey&&!B.ctrlKey){const He=d_(E,We,B.shiftKey);if(He){B.preventDefault(),kt(He);return}}if(B.key==="Enter"&&!B.shiftKey&&!B.metaKey&&!B.ctrlKey&&!B.altKey){const He=Ut?u_(E,We):null;if(He){B.preventDefault(),kt(He);return}if(dc(E,We))return;B.preventDefault(),Se();return}B.key==="Enter"&&(B.metaKey||B.ctrlKey)&&(B.preventDefault(),Se())},gn=B=>{var ts,To;const Fe=Array.from(((ts=B.clipboardData)==null?void 0:ts.files)??[]);if(Fe.length>0){B.preventDefault(),Qe(Fe);return}const We=typeof((To=B.clipboardData)==null?void 0:To.getData)=="function"?B.clipboardData.getData("text/plain"):"";if(We==="")return;const Ut=B.currentTarget,He=Ut.selectionStart??I,en=Ut.selectionEnd??He,xn=E.slice(0,He)+E.slice(en);if(We.length>n_){B.preventDefault();const Gr=new File([We],"pasted-text.txt",{type:"text/plain"}),[qr]=Qe([Gr]),xr=We.replace(/\n$/,"").split(`
120
- `).length,Tu=`${xr} ${xr===1?"line":"lines"} · ${Math.ceil(We.length/1024)} KB`;$(Ru=>Ru.map(Ro=>Ro.key===qr?{...Ro,detail:Tu}:Ro)),xn!==E&&kt({value:xn,caret:He}),z({kind:"long",key:qr,text:We,caret:He});return}if(h_(We)&&!dc(xn,He)){B.preventDefault();const Gr=f_(We),qr=m_(xn,He,We,Gr);z({kind:"fenced",lang:Gr,block:qr.value.slice(He,qr.caret),text:We}),kt(qr)}},Cn=()=>{if(V){if(V.kind==="fenced"){const B=E.indexOf(V.block);B>=0&&kt({value:E.slice(0,B)+V.text+E.slice(B+V.block.length),caret:B+V.text.length})}else{Nt(V.key);const B=Math.min(V.caret,E.length);kt({value:E.slice(0,B)+V.text+E.slice(B),caret:B+V.text.length})}z(null)}},Wn=D.filter(B=>B.state==="failed"),Hn=Wn.length,es=kH({conversationId:j??null,onNotice:P,onText:(B,Fe)=>{const We=E.trim()===""?B:`${E.replace(/\s+$/,"")} ${B}`;if(Fe){Se(We);return}Bn(We),Q<0&&yt(We)}}),Yt=es.state!=="idle",ci=h.useRef(!1);h.useEffect(()=>{var B;ci.current&&!Yt&&((B=K.current)==null||B.focus()),ci.current=Yt},[Yt]);const Ms=ke!==null&&!Yt&&!n,Ji=sy(E,I),xt=dc(E,I),Js=p_(E).map(B=>Re.find(Fe=>Fe.handle.toLowerCase()===B)).filter(B=>!!B),jm=Oe!==null&&((ui=nA(E))==null?void 0:ui.handle)===Oe.toLowerCase(),Qi=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform||navigator.userAgent),ym=B=>B.group==="Borrow"?jm?`borrows ${B.name} for this message`:`${i} asks them`:B.group==="In this room"?"is asked in this room":`${i} asks them`,gr=Hn>0?Hn===1&&((di=Wn[0])!=null&&di.error)?Wn[0].error:`${Hn} files failed to upload and will not be sent`:M??(Tt?dN:null),Xi=gr??(s||Ms?null:Ji?"Enter continues the list · Enter on an empty item ends it · Tab indents":xt?`In a code block Enter adds a line · ${Qi?"⌘":"Ctrl+"}Enter sends`:Js.length>0?t.jsxs(t.Fragment,{children:[t.jsxs("span",{className:"cv-chip",...Js[0].accent,children:["@",Js[0].handle]})," ",ym(Js[0]),Js.length>1?` · and ${Js.length-1} more`:""]}):E!==""?"Enter sends, Shift+Enter for a new line":null),Au=w??(s?`${i} is working…`:m?"Message the room · @ to ask someone":p&&Ne?`Message ${i} · @ to mention, / for commands`:`Message ${i}`),Pn=h.useMemo(()=>Re.map(B=>({handle:B.handle,accent:B.accent})),[Re]),$u=B=>F(B.selectionStart??B.value.length);return t.jsx("div",{className:"wb-composer cv","data-testid":"composer","data-slim":k||void 0,"data-phone":ce?"true":void 0,"data-busy":E.trim()!==""||ms||Yt?"true":void 0,children:t.jsxs("div",{className:"cv-anchor",children:[Ms&&ke==="mention"?t.jsx(jH,{id:pe,items:Pe,active:Ue,onPick:Me,phone:ce,maxHeight:ut}):null,Ms&&ke==="slash"?t.jsx(yH,{id:pe,items:de,active:Ue,onPick:B=>nt(B,!1),phone:ce,query:(ge==null?void 0:ge.query)??"",maxHeight:ut}):null,t.jsxs("div",{ref:ee,className:"wb-composer-box cv-box","data-focused":H||Yt,"data-disabled":n,"data-listening":Yt||void 0,children:[D.length>0?t.jsx("div",{className:"wb-composer-files",role:"list","aria-label":"Files to send",children:D.map(B=>t.jsx("span",{role:"listitem",children:t.jsx(rm,{name:B.filename,mime:B.mime,sizeBytes:B.sizeBytes,thumbnail:B.thumbnail,state:B.state,error:B.error,onRemove:()=>Nt(B.key),...f&&B.state==="ready"&&B.uploaded?{onOpen:()=>f(IH(B.uploaded))}:{},size:"sm",detail:B.detail})},B.key))}):null,t.jsxs("label",{className:"sr-only",htmlFor:nv,children:["Message ",i]}),t.jsxs("div",{className:"cv-field",hidden:Yt,children:[t.jsxs("div",{className:"cv-paint","aria-hidden":"true","data-testid":"composer-paint",children:[vH(E,Pn),t.jsx("span",{className:"cv-tail",children:tv})]}),t.jsx("textarea",{id:nv,ref:K,value:E,rows:1,spellCheck:!1,placeholder:Au,"aria-controls":Ms?pe:void 0,"aria-expanded":Ms?!0:void 0,"aria-autocomplete":Re.length>0||Ne?"list":void 0,"aria-activedescendant":Ms&&Ue>=0?Xy(pe,Ue):void 0,onChange:B=>{T(B.target.value),$u(B.target),W(!1),Y(0),Q<0&&yt(B.target.value)},onSelect:B=>$u(B.currentTarget),onFocus:()=>U(!0),onBlur:()=>U(!1),onKeyDown:lt,onPaste:gn,disabled:n,hidden:Yt})]}),Yt?t.jsx(SH,{voice:es}):null,V&&!Yt?t.jsxs("div",{className:"cv-note",role:"status",children:[t.jsx("span",{className:"cv-note-icon",children:t.jsx(le,{name:V.kind==="long"?"pasted-doc":"code"})}),t.jsx("span",{className:"cv-note-text",children:V.kind==="fenced"?t.jsxs(t.Fragment,{children:["Pasted as code · ",tA(V.lang)]}):t.jsx(t.Fragment,{children:"Long paste, attached as a file"})}),t.jsx(A,{size:"sm",variant:"ghost",onClick:Cn,children:V.kind==="fenced"?"Undo":"Put it in the message"})]}):null,t.jsxs("div",{className:"wb-composer-row",hidden:Yt,children:[t.jsx("input",{ref:X,type:"file",multiple:!0,hidden:!0,"data-testid":"file-input",onChange:B=>{Qe(B.target.files),B.target.value=""}}),t.jsx("button",{className:"ui-icon-btn","data-size":"sm","aria-label":"Attach a file",title:"Attach a file — or paste one, or drop it anywhere on the chat",onClick:()=>{var B;return(B=X.current)==null?void 0:B.click()},disabled:n,children:t.jsx(le,{name:"clip"})}),t.jsx(NH,{disabled:n,voice:es}),ce?null:t.jsx("button",{className:"ui-icon-btn","data-size":"sm","aria-label":"Snap a tab",title:"Snap a tab — one picture of another tab in this browser, attached here",onClick:()=>{P(null),O(!0),$H().then(B=>{var Fe;B&&(Qe([B]),(Fe=K.current)==null||Fe.focus())}).catch(B=>P(B instanceof Error?B.message:String(B))).finally(()=>O(!1))},disabled:n||L,children:t.jsx(le,{name:"camera"})}),o&&!ce?c?t.jsxs("a",{className:"wb-composer-model",href:c,title:"The model this agent runs on. Click to change it.",children:[t.jsx("span",{className:"wb-composer-model-dot","aria-hidden":"true"}),o]}):t.jsxs("span",{className:"wb-composer-model",title:"The model this agent runs on",children:[t.jsx("span",{className:"wb-composer-model-dot","aria-hidden":"true"}),o]}):null,d?t.jsxs("button",{type:"button",className:"wb-composer-think","aria-pressed":gd(u),disabled:n||s,title:s?`Wait for ${i} to finish — this run started with thinking ${gd(u)?"on":"off"}`:gd(u)?"Reasoning before the answer is on. Click to turn it off — answers come back faster.":"Reasoning before the answer is off. Click to turn it on.",onClick:()=>d(gd(u)?"off":"on"),children:[t.jsx("span",{className:"wb-composer-think-dot","aria-hidden":"true"}),"Thinking"]}):null,y?t.jsx("button",{type:"button",className:"ui-icon-btn wb-read-aloud","data-size":"sm","aria-label":"Read replies aloud","aria-pressed":!!x,title:x?"Replies are read aloud. Click to stop.":"Read replies aloud, through the voice chosen in Settings → Speech",onClick:()=>y(!x),children:t.jsx(le,{name:"speaker"})}):null,t.jsx("span",{className:"wb-hint cv-hint","data-shown":!!Xi&&(!ce||gr!==null),"data-tone":Hn>0||M!==null?"critical":void 0,children:ce&&gr===null?null:Xi}),s?t.jsx("button",{className:"ui-btn","data-variant":"stop",onClick:a,children:"Stop"}):null,t.jsx("button",{className:"wb-send","aria-label":"Send",title:Tt?dN:Zt?"Waiting for the upload to finish":s?`Send — ${i} picks it up between steps`:"Send",onClick:()=>Se(),disabled:!$e,children:t.jsx(le,{name:"send"})})]})]})]})})});function gd(e){return(e??"on")==="on"}function IH(e){return{type:"attachment",artifactId:e.artifactId,filename:e.filename,mime:e.mime,kind:e.kind,sizeBytes:e.sizeBytes}}function CT({question:e,disabled:n,onAnswer:s,onSkip:r}){const[a,i]=h.useState("");return h.useEffect(()=>{if(n)return;const l=o=>{o.key!=="Escape"||o.defaultPrevented||(o.preventDefault(),r())};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[n,r]),t.jsxs("section",{className:"wb-question","aria-label":"Question from agent","data-testid":"question-picker",children:[t.jsxs("div",{className:"wb-question-head",children:[t.jsx("span",{className:"wb-question-kicker",children:"Needs your input"}),t.jsx(A,{className:"wb-question-skip",variant:"ghost",size:"sm",disabled:n,onClick:r,title:"Skip this question (Esc). The agent carries on without an answer.",children:"Skip"}),t.jsx("strong",{children:PH(e.question)})]}),e.options.length>0?t.jsx("div",{className:"wb-question-options",children:e.options.map((l,o)=>t.jsxs("button",{className:"wb-question-option","data-recommended":l.recommended||void 0,disabled:n,onClick:()=>s(l.label,l.id),children:[t.jsx("span",{className:"wb-question-number",children:o+1}),t.jsxs("span",{children:[t.jsxs("span",{className:"wb-question-label",children:[l.label,l.recommended?t.jsx("em",{children:"Recommended"}):null]}),l.hint?t.jsx("small",{children:l.hint}):null]})]},l.id))}):null,e.allowOther?t.jsxs("form",{className:"wb-question-other",onSubmit:l=>{l.preventDefault(),a.trim()&&s(a.trim())},children:[t.jsx("input",{value:a,onChange:l=>i(l.target.value),placeholder:e.options.length?"Something else…":"Type your answer…",disabled:n}),t.jsx("button",{className:"ui-btn","data-variant":"accent",disabled:n||!a.trim(),children:"Answer"})]}):null,t.jsx("p",{className:"wb-question-note",children:"This answers a question. It does not approve an action. Esc skips it."})]})}function PH(e){const n=[];let s=0;for(const r of e.matchAll(/https:\/\/[^\s<>"']+/g)){const a=r[0].replace(/[.,;:!?)\]]+$/,""),i=r.index??0;i>s&&n.push(e.slice(s,i)),n.push(t.jsx("a",{href:a,target:"_blank",rel:"noopener noreferrer",children:a},i)),s=i+a.length}return s<e.length&&n.push(e.slice(s)),n}function MH(e,n){const s=i=>{var l;return`@${((l=n.find(o=>o.id===i))==null?void 0:l.handle)??i}`},[r,...a]=e;return r===void 0?"":[s(r),...a.map(i=>`asked by ${s(i)}`)].join(", ")}function DH(e,n,s){return e?[...iT({messages:e.messages,descriptors:[],...s?{awaiting:new Map(s)}:{}}).filter(a=>a.source==="approval").map(a=>({approvalId:a.props.approvalId,toolUseId:a.id})),...ET(e,n)]:[]}function ET(e,n){return((e==null?void 0:e.delegatedApprovals)??[]).map(s=>({approvalId:s.approvalId,toolUseId:s.toolUseId??"",askedBy:MH(s.chain,n)}))}function fN(e){return e instanceof xe||e instanceof Error?e.message:String(e)}function AT({conversation:e,conversationId:n,agentId:s,now:r,refresh:a,onRunStarted:i,onError:l,navigate:o}){const[c,u]=h.useState(null),[d,f]=h.useState([]),[m,p]=h.useState(!1),g=((e==null?void 0:e.offers)??[]).filter(j=>!d.includes(j.id)&&Date.parse(j.expiresAt)>r),v=j=>{var y;const x=g.find(w=>w.id===j);if(((y=x==null?void 0:x.handoff)==null?void 0:y.kind)==="install"){o(l3(x.handoff.package));return}l(null),u(j),f(w=>[...w,j]),R.takeOffer(j,n??void 0).then(w=>{if(w.agentId&&w.agentId!==s){o(Ze(w.agentId,w.conversationId??null));return}w.runId&&i(),n&&a(n)}).catch(w=>{f(k=>k.filter(N=>N!==j)),l(fN(w)),n&&a(n)}).finally(()=>u(null))},b=j=>{const x=e==null?void 0:e.question;x&&(l(null),p(!0),i(),qe.answerQuestion(x.id,j).then(()=>{if(n)return a(n)}).catch(y=>l(fN(y),!0)).finally(()=>p(!1)))};return{openOffers:g,takingOffer:c,takeOffer:v,answeringQuestion:m,answerQuestion:(j,x)=>b({answer:j,...x?{optionId:x}:{}}),skipQuestion:()=>b({answer:"",skipped:!0})}}function $T({offers:e,disabled:n,onTake:s}){return e.length===0?null:t.jsx("div",{className:"wb-offers","data-testid":"chat-offers",children:e.map(r=>{var a,i;return t.jsx("button",{type:"button",className:"ui-btn",disabled:n,title:((a=r.handoff)==null?void 0:a.kind)==="install"?`Opens ${r.handoff.title}'s install sheet`:r.prompt,"data-handoff":(i=r.handoff)==null?void 0:i.kind,onClick:()=>s(r.id),children:r.label},r.id)})})}function OH(e,n){return e.messages<=0?!1:e.chars>e.maxChars?!0:e.lastActivityAt===null||e.idleTimeoutMs===null?!1:n-Date.parse(e.lastActivityAt)>e.idleTimeoutMs}function LH(e){const n=e/864e5;if(n>=1&&Number.isInteger(n))return n===7?"1 week":`${n} day${n===1?"":"s"}`;const s=e/36e5;if(s>=1&&Number.isInteger(s))return`${s} hour${s===1?"":"s"}`;const r=Math.round(e/6e4);return`${r} minute${r===1?"":"s"}`}function FH(e){const{lifetime:n,startedAt:s,now:r,timezone:a}=e;if(!n||n.messages<=0)return{text:"New conversation",title:"Nothing has been said in this one yet.",tone:"quiet"};const i=`${Math.round(n.maxChars/1e3)}k characters`,l=(n.idleTimeoutMs===null?`A conversation ends once its transcript grows past ${i}. `:`A conversation ends after ${LH(n.idleTimeoutMs)} idle, or once its transcript grows past ${i}. `)+"What the agent remembers about you carries over.",o=`${n.messages} message${n.messages===1?"":"s"}`;if(OH(n,r))return{text:`${o} · your next message starts a fresh one`,title:l,tone:"note"};const c=s?Ve(s,r):"";return{text:c===""?o:`${o} · started ${c}`,title:s?`Started ${ct(s,a)}. ${l}`:l,tone:"quiet"}}function _H({text:e,onDelete:n}){const[s,r]=h.useState(!1),[a,i]=h.useState(null);return t.jsx("div",{className:"wb-carryover","data-testid":"chat-carryover",children:t.jsxs(Ot,{summary:"Carried over from the previous conversation",children:[t.jsx("p",{className:"wb-carryover-text",children:e}),t.jsxs(te,{align:"end",children:[a?t.jsx("span",{className:"critical",role:"alert",children:a}):null,t.jsx(A,{size:"sm",variant:"danger-ghost",disabled:s,onClick:()=>{r(!0),i(null),n().catch(l=>{i(l instanceof Error?l.message:String(l)),r(!1)})},children:"Delete note"})]})]})})}function TT(e){return e.length<2?e.join(""):`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}function RT(e,n){return e.members.map(s=>n.find(r=>r.id===s)).filter(s=>s!==void 0)}function zH(e,n){var a;const s=RT(e,n),r=e.members.filter(i=>!n.some(l=>l.id===i));if(!n.some(i=>i.id===e.coordinator))return{kind:"coordinator",text:`${e.coordinator} coordinated this group and is no longer in buddi, so the group can't take requests.`,action:"Choose a coordinator"};if(s.length<2){const i=r.length>0?`: ${r.join(", ")} ${r.length===1?"was":"were"} removed from buddi`:"";return{kind:"alone",text:`Only ${((a=s[0])==null?void 0:a.name)??e.coordinator} is left here${i}.`,action:"Add a member"}}return null}function UH(){return t.jsx("span",{className:"ui-avatar group-gone-face","aria-hidden":"true",children:"?"})}function BH({group:e,agents:n,onClose:s,onSaved:r}){const[a,i]=h.useState(!1),[l,o]=h.useState(null),c=[e.coordinator,...e.members.filter(g=>g!==e.coordinator)],u=e.members.length>2,d=Cy(n).filter(g=>!e.members.includes(g.id)),f=!n.some(g=>g.id===e.coordinator),m=async g=>{i(!0),o(null);try{r(await qe.updateGroup(e.id,g))}catch(v){o(v instanceof xe?v.message:String(v))}finally{i(!1)}},p=g=>void m({members:e.members.filter(v=>v!==g)});return t.jsxs(Ge,{title:"Members",onClose:s,children:[t.jsxs("p",{className:"group-lede",children:[e.name," · ",e.members.length," agents. Each keeps its own account, tools and approvals; being here grants nothing."]}),f?t.jsxs(G,{tone:"warning",children:[e.coordinator," coordinated this group and is no longer in buddi. Pick who coordinates now."]}):null,l?t.jsx(G,{tone:"critical",children:l}):null,t.jsx(at,{children:c.map(g=>{const v=n.find(j=>j.id===g),b=g===e.coordinator;return v?t.jsx(Xe,{lead:t.jsx(fn,{agents:n,id:g}),title:v.name,sub:v.description,side:t.jsxs(t.Fragment,{children:[b?t.jsx(Ee,{tone:"accent",children:"Coordinator"}):null,f&&v.available?t.jsx(A,{size:"sm",disabled:a,onClick:()=>void m({coordinator:g}),children:"Make coordinator"}):null,t.jsx(Rs,{label:`More for ${v.name}`,...b?{note:"Coordinates the group"}:{},items:[!b&&v.available&&{label:"Make coordinator",hint:"Reads your requests, answers for the room",onSelect:()=>void m({coordinator:g})},{label:`Open ${v.name}'s page`,onSelect:()=>{window.location.hash=Pt(g)}},!b&&"separator",!b&&{label:"Remove from group",hint:u?"What it said stays":"A group needs two",tone:"critical",onSelect:()=>{u?p(g):o("A group needs two agents. Add someone before taking this one out.")}}]})]})},g):t.jsx(Xe,{lead:t.jsx(UH,{}),title:t.jsx("span",{className:"group-gone-id",children:g}),sub:t.jsxs("span",{className:"group-gone-line",children:["No longer in buddi",b?" · was the coordinator":u?"":" · add a member to take it out"]}),side:u&&!b?t.jsx(A,{size:"sm",disabled:a,onClick:()=>p(g),children:"Remove"}):void 0},g)})}),t.jsxs("div",{className:"group-add",children:[t.jsx("h3",{className:"group-add-title",children:"Add a member"}),d.length>0?t.jsx(at,{children:d.map(g=>t.jsx(Xe,{lead:t.jsx(fn,{agents:n,id:g.id,size:"sm"}),title:g.name,sub:g.description,side:t.jsx(A,{size:"sm",disabled:a,onClick:()=>void m({members:[...e.members,g.id]}),children:"Add"})},g.id))}):t.jsx("p",{className:"group-quiet",children:"Everyone who can join a group is here."})]}),t.jsx("p",{className:"group-quiet",children:"Members read what is said here and what they recall from shared and group memory; nothing an agent knows privately comes in on its own. Taking a member out leaves what it said in the history."})]})}function WH({group:e,onClose:n,onSaved:s}){const[r,a]=h.useState(e.name),[i,l]=h.useState(!1),[o,c]=h.useState(null),u=r.trim()!==""&&r.trim()!==e.name&&!i,d=async()=>{if(u){l(!0),c(null);try{s(await qe.updateGroup(e.id,{name:r.trim()}))}catch(f){c(f instanceof xe?f.message:String(f)),l(!1)}}};return t.jsx(zt,{title:"Rename group",onClose:n,foot:t.jsxs(t.Fragment,{children:[t.jsx(A,{variant:"ghost",onClick:n,children:"Cancel"}),t.jsx(A,{variant:"accent",disabled:!u,onClick:()=>void d(),children:i?"Renaming…":"Rename"})]}),children:t.jsx("form",{onSubmit:f=>{f.preventDefault(),d()},children:t.jsxs(ie,{children:[t.jsx(re,{label:"Name",hint:"What this team is for: Household finances, The move, Tax season.",children:t.jsx("input",{value:r,autoFocus:!0,maxLength:80,onFocus:f=>f.currentTarget.select(),onChange:f=>a(f.target.value)})}),o?t.jsx(G,{tone:"critical",children:o}):null]})})})}function IT(e){const[n,s]=h.useState(null);return h.useEffect(()=>{let r=!0;return qe.group(e).then(a=>{var i;r&&s(((i=a.history)==null?void 0:i.conversations)??null)}).catch(()=>{}),()=>{r=!1}},[e]),n}function HH(e){return e===null?"Its conversations":e===0?"Nothing has been said yet, and its next conversation":`Its ${e} ${e===1?"conversation":"conversations"}`}function KH({group:e,onClose:n,onCleared:s}){const r=IT(e.id),[a,i]=h.useState(!1),[l,o]=h.useState(null),c=async()=>{i(!0),o(null);try{await qe.clearGroup(e.id),s()}catch(d){o(d instanceof xe?d.message:String(d)),i(!1)}},u=r===0;return t.jsxs(zt,{title:`Clear the history of ${e.name}?`,onClose:n,foot:t.jsxs(t.Fragment,{children:[t.jsx(A,{variant:"ghost",onClick:n,children:"Cancel"}),t.jsx(A,{variant:"danger",disabled:a||u,"data-testid":"group-clear-confirm",onClick:()=>void c(),children:a?"Clearing…":"Clear history"})]}),children:[t.jsx("p",{className:"group-dialog-text",children:u?"Nothing has been said in this group yet, so there is nothing to clear.":`${HH(r)} ${r===1?"is":"are"} deleted for good, and anything it is doing now stops. The group, its members and what it remembers stay; files it made stay in Files.`}),l?t.jsx(G,{tone:"critical",children:l}):null]})}function VH({group:e,agents:n,onClose:s,onDeleted:r}){const a=IT(e.id),[i,l]=h.useState(!1),[o,c]=h.useState(null),u=RT(e,n).map(m=>m.name),d=async()=>{l(!0),c(null);try{const{undoUntil:m}=await qe.deleteGroup(e.id);r(m)}catch(m){c(m instanceof xe?m.message:String(m)),l(!1)}},f=a===null?"its conversations":a===0?"nothing said yet":`its ${a} ${a===1?"conversation":"conversations"}`;return t.jsxs(zt,{title:`Delete ${e.name}?`,onClose:s,foot:t.jsxs(t.Fragment,{children:[t.jsx(A,{variant:"ghost",onClick:s,children:"Cancel"}),t.jsx(A,{variant:"danger",disabled:i,"data-testid":"group-delete-confirm",onClick:()=>void d(),children:i?"Deleting…":"Delete group"})]}),children:[t.jsxs("p",{className:"group-dialog-text",children:["The group goes with ",f," and what it remembers."," ",u.length>0?`${TT(u)} ${u.length===1?"is":"are"} not touched, and files it made stay in Files.`:"Files it made stay in Files."]}),o?t.jsx(G,{tone:"critical",children:o}):null]})}const Gd=320,PT="buddi.chatWidth";function GH({timezone:e,agents:n,agentId:s,defaultAgentId:r=null,group:a=null,onGroupAction:i,onSelectAgent:l,onWorking:o,attention:c,agentsInHeader:u,narrow:d,canvasOpen:f,onOpenCanvas:m,onCloseCanvas:p,newConversationSignal:g,requestedConversationId:v,requestedTab:b,onConversationOpened:j}){var ab,ib,lb,ob,cb,ub,db;const x=am(),[y,w]=h.useState([]),[k,N]=h.useState(null),[S,C]=h.useState(null),[E,T]=h.useState(null),[I,F]=h.useState([]),[D,$]=h.useState([]),[L,O]=h.useState(null),[M,P]=h.useState(!1),[H,U]=h.useState(new Map),[V,z]=h.useState(null),[X,K]=h.useState(xH),[ee,ce]=h.useState([]),[pe,oe]=h.useState(!1),Re=h.useRef(0),Oe=h.useRef(null),[Je,W]=h.useState(!1),se=h.useRef(g??0),Y=h.useRef(s),Ne=h.useRef({agentId:s,conversationId:k});Ne.current={agentId:s,conversationId:k};const we=X[k??""]??[],[fe,ge]=h.useState(null),[Pe,je]=h.useState(null),[de,ke]=h.useState(()=>Date.now()),[Be,Ue]=h.useState(qH),ut=h.useRef(null),[dt,Q]=h.useState(null),[Ae,tt]=h.useState(!1),[Ct,yt]=h.useState(null),[kt,Bn]=h.useState(J$),hs=h.useRef(kt);hs.current=kt;const In=h.useRef(null),[fs,Zt]=h.useState(null),ms=h.useCallback(J=>{Bn(J),Q$(J),J||ko()},[]),[Tt,$e]=h.useState(null),[Qe,ze]=h.useState(null);h.useEffect(()=>{if(!s)return;const J=t_(s);J&&yt({text:J,at:Date.now()})},[s]);const Nt=a?`group:${a.id}`:s??null,q=[...n.top,...n.middle,...n.bottom],he=q.find(J=>J.id===s)??null,Sn=me(()=>R.providerAccounts(),[]),on=a?a.members.map(J=>q.find(ae=>ae.id===J)).filter(J=>!!J):[],[Se,Me]=h.useState(null),nt=M?Se??s??null:null;h.useEffect(()=>{o==null||o(nt)},[nt,o]),h.useEffect(()=>()=>o==null?void 0:o(null),[o]),h.useEffect(()=>{let J=!1;return qe.views().then(ae=>{J||w(ae.views??[])}).catch(()=>{}),()=>{J=!0}},[]),h.useEffect(()=>{if(!s)return;const J=Y.current===s;if(Y.current=s,J&&v&&v===Ne.current.conversationId)return;let ae=!1;return N(null),C(null),T(null),F([]),ge(null),P(!1),z(null),ce([]),Qi(null),W(!1),Q(null),v?(v!=="new"?N(v):T(Nt),()=>{ae=!0}):((a?qe.groupConversations(a.id):qe.conversations(s)).then(Te=>{if(ae)return;const Ie=[...Te.conversations??[]].sort(YH)[0];Ie?(N(Ie.id),j==null||j(s,Ie.id)):T(Nt)}).catch(()=>{ae||T(Nt)}),()=>{ae=!0})},[s,a==null?void 0:a.id,Nt,v,j]);const lt=h.useCallback(J=>qe.conversation(J).then(ae=>{if(Ne.current.conversationId===J){if(ae.agentId!==Ne.current.agentId)throw new Error("This conversation belongs to another agent. Open it from that agent’s history.");C(ae),F(Te=>Te.filter(Ie=>!Ip(ae,Ie)))}}).catch(ae=>{Ne.current.conversationId===J&&ge(ka(ae))}),[]);h.useEffect(()=>{if(!k)return;let J=!1;return U(new Map),$([]),qe.conversation(k).then(ae=>{if(!J){if(ae.agentId!==s)throw new Error("This conversation belongs to another agent. Open it from that agent’s history.");C(ae),F(Te=>Te.filter(Ie=>!Ip(ae,Ie)))}}).catch(ae=>{J||ge(ka(ae))}),()=>{J=!0}},[k,s]),h.useEffect(()=>{if(!k)return;let J=!1;const ae=window.setInterval(()=>{qe.conversation(k).then(Te=>{J||Te.agentId!==Ne.current.agentId||(C(Te),F(Ie=>Ie.filter(st=>!Ip(Te,st))))}).catch(()=>{})},3e3);return()=>{J=!0,window.clearInterval(ae)}},[k,s]),h.useEffect(()=>{if(!k)return;const J=Kf({url:qe.streamUrl(k),onEvent:ae=>{var Te;switch(ae.name){case"run.started":In.current=null,P(!0),O(null),Me(En(ae.data.agentId));break;case"live":{const Ie=En(ae.data.runId)??"",st=Number(ae.data.turn??0),St=ae.data.kind==="thinking"?"thinking":"text",ot=En(ae.data.text)??"",Yr=Date.now();if(St==="text"){const ns=In.current;In.current=ns&&ns.runId===Ie&&ns.turn===st?{...ns,text:ns.text+ot}:{runId:Ie,turn:st,text:ot}}O(ns=>{const tl=ns&&ns.runId===Ie&&ns.turn===st?ns:{runId:Ie,turn:st,text:"",thinking:"",thinkingStartedAt:null,textStartedAt:null,settled:!1};return St==="thinking"?{...tl,thinking:tl.thinking+ot,thinkingStartedAt:tl.thinkingStartedAt??Yr}:{...tl,text:tl.text+ot,textStartedAt:tl.textStartedAt??Yr}});break}case"live.snapshot":{const Ie=En(ae.data.runId)??"",st=Number(ae.data.turn??0),St=En(ae.data.text)??"",ot=En(ae.data.thinking)??"",Yr=Number(ae.data.startedAt??Date.now());In.current={runId:Ie,turn:st,text:St},O({runId:Ie,turn:st,text:St,thinking:ot,thinkingStartedAt:ot?Yr:null,textStartedAt:St?Yr:null,settled:!1});break}case"live.settle":{const Ie=En(ae.data.runId)??"",st=Number(ae.data.turn??0);O(St=>St&&St.runId===Ie&&St.turn===st?{...St,settled:!0}:St);break}case"tool.called":{const Ie=En(ae.data.toolUseId)??En(ae.data.id),st=En(ae.data.name)??En(ae.data.tool)??"tool";Ie&&$(St=>[...St.filter(ot=>ot.toolUseId!==Ie),{toolUseId:Ie,name:st,startedAt:Date.now()}]);break}case"tool.result":{const Ie=En(ae.data.toolUseId)??En(ae.data.id);Ie&&$(st=>st.filter(St=>St.toolUseId!==Ie)),lt(k);break}case"reaction":lt(k);break;case"message.appended":lt(k).then(()=>{O(Ie=>Ie!=null&&Ie.settled?null:Ie)});break;case"awaiting-approval":{const Ie=En(ae.data.approvalId)??En(ae.data.actionId),st=En(ae.data.toolUseId);Ie&&st&&U(St=>new Map(St).set(st,Ie)),$(St=>St.filter(ot=>ot.toolUseId!==st)),lt(k);break}case"run.finished":{P(!1),$([]),O(null),Me(null);const Ie=En(ae.data.message);ge(Ie??null);const st=((Te=In.current)==null?void 0:Te.text.trim())??"";In.current=null,!Ie&&st!==""&&hs.current&&Uh(st,k).then(St=>{St&&Zt(St)}),lt(k);break}}}});return()=>J.close()},[k,lt]),h.useEffect(()=>{const J=window.setInterval(()=>ke(Date.now()),D.length===0?6e4:1e3);return()=>window.clearInterval(J)},[D.length]);const gn=me(()=>s&&k?R.browser({agentId:s,conversationId:k}):Promise.resolve(void 0),[s,k],1500),Cn=gn.error?void 0:gn.data,Wn=Cn!=null&&Cn.session&&Cn.session.agentId===s&&Cn.session.conversationId===k?Cn:void 0,Hn=lH(Wn,s,k),es=(Hn==null?void 0:Hn.id)??null,[Yt,ci]=h.useState(null),Ms=Wn==null?void 0:Wn.mode;h.useEffect(()=>{Hn&&s&&k&&ci({agentId:s,conversationId:k,tab:oH(Hn,Ms)})},[es,Ms,s,k]);const Ji=Yt&&Yt.agentId===s&&Yt.conversationId===k&&!we.includes(Yt.tab.id)?Yt.tab:null,xt=Hn??Ji,Js=h.useMemo(()=>cH((S==null?void 0:S.messages)??[]),[S]),[jm,Qi]=h.useState(null),ym=h.useMemo(()=>R5({messages:(S==null?void 0:S.messages)??[],descriptors:y}),[S,y]),gr=yW(ym,k??null),Xi=bW(a?null:s),Au=h.useMemo(()=>wW((S==null?void 0:S.messages)??[]),[S]),Pn=h.useMemo(()=>{const ae=iT({messages:(S==null?void 0:S.messages)??[],descriptors:y,awaiting:H,served:gr.served,...xt?{folded:Vd}:{},gathered:pH}).filter(Ie=>Ie.source==="approval"||!we.includes(Ie.id)),Te=V?Y0(ae,V):null;if(Te&&(Te.props={...Te.props,focus:V}),V&&!Te&&!we.includes(V)&&!ae.some(Ie=>Ie.id===V)){const Ie=D5((S==null?void 0:S.messages)??[],V,{redactInputOf:Vd});Ie&&!Vd.has(Ie.tool)&&ae.push(Ie)}xt&&ae.push(xt);for(const Ie of ee)ae.push(D6(Ie));return Xi&&ae.unshift(kW(Xi,Au)),dt?[...ae,NW(dt)]:ae},[S,y,H,dt,es,xt==null?void 0:xt.title,V,X,k,ee,gr.served,Xi,Au]),$u=h.useMemo(()=>{var ae;const J=[];for(const Te of(S==null?void 0:S.messages)??[]){if(Te.role!=="user"||Te.speaker&&Te.speaker!=="owner")continue;const Ie=(ae=Te.blocks.find(st=>st.type==="text"))==null?void 0:ae.text.trim();Ie&&J.unshift(Ie)}return J},[S]),Zi=h.useMemo(()=>Pn.filter(J=>J.source==="approval"),[Pn]),ui=Zi.at(-1)??null,di=h.useMemo(()=>[...Zi.map(J=>({approvalId:J.props.approvalId,toolUseId:J.id})),...ET(S,q)],[Zi,S==null?void 0:S.delegatedApprovals]),B=h.useMemo(()=>{for(let J=Pn.length-1;J>=0;J-=1){const ae=Pn[J];if(ae!=null&&ae.substantial)return ae.id}return null},[Pn]),Fe=h.useRef(null),We=((ab=Pn.filter(J=>(J.source!=="browser"||J.pinned===!0)&&J.id!==Zx).at(-1))==null?void 0:ab.id)??((ib=Pn.filter(J=>J.id!==Zx).at(-1))==null?void 0:ib.id)??null;h.useEffect(()=>{if(B&&B!==Fe.current){Fe.current=B,z(B);return}V===null&&We&&z(We)},[B,V,We]);const Ut=h.useRef(gr.live);h.useEffect(()=>{const J=Ut.current;Ut.current=gr.live;const ae=[...gr.live].filter(st=>!J.has(st));if(ae.length===0||ui||V!==null&&V!==Fe.current)return;const Ie=[...Pn].reverse().find(st=>st.source==="descriptor"&&st.renderer==="preview"&&st.props.target!==null&&ae.includes(Ll(st.props.target)));Ie&&z(Ie.id)},[gr.live,Pn,ui,V]);const He=h.useRef(null);h.useEffect(()=>{es!==He.current&&(He.current=es,es&&!ui&&z(es))},[es,ui]);const en=h.useRef(null),xn=b==="browser"?(xt==null?void 0:xt.id)??null:null;h.useEffect(()=>{!xn||en.current===xn||(en.current=xn,z(xn))},[xn]);const ts=(xt==null?void 0:xt.id)??null;h.useEffect(()=>{!ts||!V||cN((S==null?void 0:S.messages)??[],V)!==null&&(Qi(V),z(ts))},[ts,V,S]);const To=J=>{ce(ae=>ae.some(Te=>Te.artifactId===J.artifactId)?ae:[...ae,J]),z(Wd(J.artifactId)),d&&(m==null||m())},Gr=!a&&he&&!he.available?m$(he):null,qr=a?t.jsx("span",{className:"wb-group-stack","aria-hidden":"true",children:a.members.slice(0,2).map(J=>{const ae=q.find(Te=>Te.id===J);return t.jsx(Yf,{className:"wb-group-chip",id:J,name:(ae==null?void 0:ae.name)??"?",face:ae,initials:1},J)})}):null,xr=a&&q.length>0?zH(a,q):null,Tu=(xr==null?void 0:xr.kind)==="coordinator",Ru=Ix(a?null:he),Ro=he&&Qe===he.id?Tt:(he==null?void 0:he.thinking)??null,iM=J=>{if(!he)return;const ae=he.id;ze(ae),$e(J),R.setAgentEngine(ae,{thinking:J}).catch(Te=>{ze(null),ge(Te instanceof xe?Te.message:String(Te))})},wm=(J,ae)=>{if(!s)return;const Te=a?null:eK(J,q,s);if(Te){ge(null),qe.send(Te.agent.id,{text:Te.rest,attachmentIds:ae.map(ot=>ot.artifactId)}).then(ot=>{window.location.hash=Ze(Te.agent.id,ot.conversationId)}).catch(ot=>ge(ka(ot)));return}const Ie=ae.map(ot=>ot.artifactId),st=M,St={id:`optimistic:${Date.now()}`,role:"user",at:new Date().toISOString(),blocks:[{type:"text",text:J},...ae.map(ot=>({type:"attachment",artifactId:ot.artifactId,filename:ot.filename,mime:ot.mime,kind:ot.kind,sizeBytes:ot.sizeBytes}))],...st?{speaker:cT}:{}};F(ot=>st?[...ot,St]:[St]),ge(null),je(null),P(!0),(a?qe.sendToGroup(a.id,{...k?{conversationId:k}:{},text:J,attachmentIds:Ie}):qe.send(s,{...k?{conversationId:k}:{},text:J,attachmentIds:Ie})).then(async ot=>{Ne.current.agentId!==s||Ne.current.conversationId!==k||(je(ot.rolledOver===!0?"(New thread — the room had grown long. Where it stopped carries over as a summary.)":null),ot.conversationId!==k?(C(null),N(ot.conversationId)):await lt(ot.conversationId),ot.queued===!0&&F(Yr=>Yr.filter(ns=>ns.id!==St.id)),j==null||j(s,ot.conversationId))}).catch(ot=>{F(Yr=>Yr.filter(ns=>ns.id!==St.id)),ge(ka(ot)),P(!1)})},{openOffers:lM,takingOffer:oM,takeOffer:cM,answeringQuestion:uM,answerQuestion:dM,skipQuestion:hM}=AT({conversation:S,conversationId:k??null,agentId:(he==null?void 0:he.id)??null,now:de,refresh:lt,onRunStarted:()=>{je(null),P(!0)},onError:(J,ae)=>{ge(J),ae&&P(!1)},navigate:J=>{window.location.hash=J}}),fM=()=>{if(s){if(dt){Q(null);return}tt(!0),R.agentProfile(s).then(J=>{Q(J),z(ev(J.id)),d&&(m==null||m())}).catch(J=>ge(ka(J))).finally(()=>tt(!1))}},mM=J=>{yt({text:J.prompt,at:Date.now()}),l(J.agentId),d&&(p==null||p())},Qw=()=>{k&&qe.cancel(k).catch(J=>ge(ka(J))).finally(()=>{P(!1),$([])})},pM=(J,ae)=>{if(ge(null),J==="stop"){Qw();return}if(J==="use"){const Te=ae.replace(/^@/,"").toLowerCase(),Ie=q.find(st=>st.handle.toLowerCase()===Te||st.id===Te);if(!Ie){je(Te?`No agent called @${Te}.`:"Say who: /use @handle.");return}je(null),l(Ie.id);return}if(J==="new"){const Te=q.find(Ie=>Ie.roles.includes(Fr));if(!Te){je("There is no agent here that makes agents.");return}ae.trim()&&xu(Te.id,`I'd like a teammate for this: ${ae.trim()}`),l(Te.id);return}R.quiet(ae).then(Te=>je(Te.text)).catch(Te=>ge(ka(Te)))},Iu=h.useCallback(()=>{if(N(null),C(null),F([]),P(!1),ge(null),je(null),$([]),U(new Map),z(null),ce([]),Qi(null),Fe.current=null,a){qe.startGroupConversation(a.id).then(({conversationId:J})=>{N(J),s&&(j==null||j(s,J))}).catch(J=>ge(ka(J)));return}T(Nt),s&&(j==null||j(s,"new"))},[s,a,Nt,j]);h.useEffect(()=>{g&&g!==se.current&&(se.current=g,Iu())},[g,Iu]);const Xw=J=>{k&&lt(k),R.overview().catch(()=>{}),J.state!=="pending"&&U(ae=>new Map([...ae].filter(([,Te])=>Te!==J.id)))},Pu=h.useRef(!1);h.useEffect(()=>{const J=Te=>{if(!Pu.current)return;const Ie=Math.max(Gd,Math.min(720,Te.clientX-52));Ue(Ie)},ae=()=>{if(Pu.current){Pu.current=!1;try{Be!==null&&window.localStorage.setItem(PT,String(Be))}catch{}}};return window.addEventListener("pointermove",J),window.addEventListener("pointerup",ae),()=>{window.removeEventListener("pointermove",J),window.removeEventListener("pointerup",ae)}},[Be]);const gM=((lb=q.find(J=>J.id===r))==null?void 0:lb.name)??null,Zw=a?[]:mU(he,gM),eb=!(S&&S.conversationId===k)&&!(!k&&E!==null&&E===Nt),tb=eb?t.jsx("div",{className:"wb-chat-loading","data-testid":"chat-loading","aria-busy":"true"}):!a&&he?t.jsx(O$,{quiet:!0,still:!0,className:"wb-chat-field",children:t.jsxs("div",{className:"wb-chat-opening","data-testid":"chat-opening",children:[t.jsx(fn,{agents:q,id:he.id,size:"xl"}),t.jsx("h2",{className:"wb-chat-hello",children:`Hi, I'm ${he.name}.`}),t.jsx("p",{className:"wb-chat-intro",children:pU(he)}),Zw.length>0?t.jsx("div",{className:"wb-starters",role:"group","aria-label":`Things to ask ${he.name}`,children:Zw.map(J=>t.jsx("button",{type:"button",className:"wb-starter",onClick:()=>{var ae;yt({text:J,at:Date.now()}),(ae=Oe.current)==null||ae.focus()},children:J},J))}):null]})}):null,nb=t.jsx(oW,{renderables:Pn,activeId:(V?(ob=Y0(Pn,V))==null?void 0:ob.id:null)??V,onActivate:z,onClose:J=>{dt&&J===ev(dt.id)?Q(null):ee.some(ae=>Wd(ae.artifactId)===J)?ce(ae=>ae.filter(Te=>Wd(Te.artifactId)!==J)):k&&K(ae=>{const Te={...ae,[k]:[...new Set([...ae[k]??[],J])]};return uN(Te),Te}),V===J&&z(null)},timezone:e,onDecided:Xw,onChangeAgent:mM,agents:q,browserPanel:xt?t.jsx(sH,{status:Wn,error:gn.error,reload:gn.reload,steps:Js,live:Hn!==null,focusedStepId:jm},xt.id):null,descriptors:y,grantedTools:a?on.flatMap(J=>J.tools??[]):(he==null?void 0:he.tools)??[],...he?{agentName:he.name}:{},loading:eb,...!a&&he?{face:t.jsx(fn,{agents:q,id:he.id,size:"xl"})}:{}}),sb=(ub=(cb=[...(S==null?void 0:S.messages)??[],...I].find(J=>J.role==="user"))==null?void 0:cb.blocks.find(J=>J.type==="text"))==null?void 0:ub.text.trim(),rb=sb?sb.split(`
121
- `)[0]:"New conversation",el=FH({lifetime:(S==null?void 0:S.lifetime)??null,startedAt:(S==null?void 0:S.startedAt)??null,now:de,timezone:e});return t.jsxs(t.Fragment,{children:[t.jsxs("section",{className:"wb-chat",ref:ut,style:d||Be===null?void 0:{width:Be},"data-sized":!d&&Be!==null?"true":void 0,"data-testid":"chat-column","data-dropping":pe||void 0,onDragEnter:J=>{xd(J)&&(J.preventDefault(),Re.current+=1,oe(!0))},onDragOver:J=>{xd(J)&&(J.preventDefault(),J.dataTransfer.dropEffect="copy")},onDragLeave:J=>{xd(J)&&(Re.current=Math.max(0,Re.current-1),Re.current===0&&oe(!1))},onDrop:J=>{var ae;xd(J)&&(J.preventDefault(),Re.current=0,oe(!1),s&&((ae=Oe.current)==null||ae.addFiles(J.dataTransfer.files)))},children:[pe?t.jsx("div",{className:"wb-drop","aria-hidden":"true",children:t.jsxs("div",{className:"wb-drop-card",children:[t.jsx(JH,{}),t.jsx("strong",{children:"Drop to attach"}),t.jsx("span",{children:he?`It goes with your next message to ${he.name}`:"Pick an agent first"})]})}):null,t.jsxs("header",{className:"wb-chat-head","data-testid":"chat-head",...!a&&he?Oi(jo(he)):{},children:[t.jsxs("div",{className:"wb-head-row",children:[a?t.jsx("span",{className:"wb-head-face","aria-hidden":"true",children:qr}):he?t.jsx("a",{className:"wb-head-face",href:Pt(he.id),"aria-label":`${he.name}'s page`,children:t.jsx(fn,{agents:q,id:he.id})}):null,t.jsxs("div",{className:"wb-head-text",children:[a?t.jsx("span",{className:"wb-head-title",children:a.name}):t.jsx("span",{className:"wb-head-title",title:rb,children:rb}),t.jsx("span",{className:"wb-head-meta","data-tone":el.tone,title:a?`${on.map(J=>J.name).join(", ")}. Coordinator: ${(he==null?void 0:he.name)??a.coordinator}.`:el.title,children:a?`${on.map(J=>J.name).join(", ")} · ${el.text}`:he?t.jsxs(t.Fragment,{children:[t.jsx("a",{className:"wb-head-name",href:Pt(he.id),title:`${he.name}'s page`,children:he.name})," ",t.jsxs("span",{className:"wb-head-handle",children:["@",he.handle]}),` · ${el.tone==="quiet"&&el.text==="New conversation"?`on ${x}`:el.text}`]}):"No agent"})]}),t.jsx("button",{className:"ui-icon-btn wb-head-more","data-size":"sm","aria-label":"New chat",title:"New chat",disabled:!s,onClick:()=>{W(!1),Iu()},children:t.jsx(le,{name:"plus",size:16})}),t.jsx("button",{className:"ui-icon-btn wb-head-more","aria-label":"History",title:"Earlier conversations","aria-expanded":Je,"data-open":Je?"true":void 0,disabled:!s,onClick:()=>W(J=>!J),children:t.jsx(QH,{})}),d?t.jsxs("button",{className:"ui-btn",onClick:m,disabled:Pn.length===0,children:["Canvas",Pn.length>0?` (${Pn.length})`:""]}):null,a?t.jsx(mN,{disabled:!1,label:"More about this group",title:a.name,sub:TT(on.map(J=>J.name)),face:qr,items:[{label:"Members",hint:`${a.members.length} agents · ${he?`${he.name} coordinates`:"no coordinator"}`,testId:"group-members",onSelect:()=>i==null?void 0:i("members")},{label:"Rename…",hint:"What this team is for",testId:"group-rename",onSelect:()=>i==null?void 0:i("rename")},"separator",{label:"Clear history…",hint:"Keeps the group and its members",testId:"group-clear",onSelect:()=>i==null?void 0:i("clear")},{label:"Delete group…",hint:"With its history; the agents stay",tone:"critical",testId:"group-delete",onSelect:()=>i==null?void 0:i("delete")}]}):t.jsx(mN,{disabled:!s,label:"More about this agent",title:(he==null?void 0:he.name)??"Agent",...he?{sub:`@${he.handle}`,face:t.jsx(fn,{agents:q,id:he.id,size:"sm"})}:{},items:[{label:dt?"Close properties":"Properties",hint:"What this agent can do, on the Canvas",testId:"agent-properties",disabled:Ae,onSelect:fM},...he?[{label:"Set up",hint:"Identity, model and access",href:Pt(he.id,"setup")},{label:"Open agent page",hint:"Profile, activity and setup",href:Pt(he.id)}]:[]]})]}),u?t.jsx(g$,{agents:n,currentId:s,attention:c,onSelect:l,orientation:"horizontal",...nt?{working:new Set([nt])}:{}}):null]}),Je&&s?t.jsx(gH,{agentId:s,...a?{groupId:a.id}:{},currentId:k,timezone:e,onNew:()=>{W(!1),Iu()},onSelect:J=>{if(J===k){W(!1);return}W(!1),C(null),F([]),P(!1),z(null),ge(null),je(null),ce([]),N(J),j==null||j(s,J,!1)}}):null,s&&k?t.jsx(aH,{agentId:s,conversationId:k},`${s}:${k}`):null,fe?t.jsx("div",{className:"wb-chat-notice",children:t.jsx(ne,{message:fe})}):null,Pe?t.jsx("div",{className:"wb-chat-notice","data-testid":"chat-notice",children:Pe}):null,S!=null&&S.carriedOver?t.jsx(_H,{text:S.carriedOver,onDelete:async()=>{const J=S.conversationId;await qe.deleteCarryOver(J),C(ae=>{if(!ae||ae.conversationId!==J)return ae;const{carriedOver:Te,...Ie}=ae;return Ie})}},S.conversationId):null,t.jsx(Ky,{messages:[...(S==null?void 0:S.messages)??[],...I],live:D,now:de,working:M,partial:L,agents:q,...S!=null&&S.runs?{runs:S.runs}:{},...s&&k?{onContinue:()=>wm("continue",[])}:{},...a?{speakers:q,coordinatorId:a.coordinator}:{},...Se?{workingAs:((db=q.find(J=>J.id===Se))==null?void 0:db.name)??Se}:{},onOpenFile:To,onReadAloud:(J,ae)=>{Zt(null),Uh(ae,k??void 0,J).then(Te=>{Te&&Zt(Te)})},onOpen:J=>{if(xt){const ae=cN([...(S==null?void 0:S.messages)??[],...I],J);if(ae){Qi(ae),z(xt.id),d&&(m==null||m());return}}k&&K(ae=>{const Te={...ae,[k]:(ae[k]??[]).filter(Ie=>Ie!==J)};return uN(Te),Te}),z(J),d&&(m==null||m())},...he?{agentName:he.name,agentId:he.id}:{},...tb?{empty:tb}:{},emptyHint:a?`Give the team a task once; ${he?he.name:"the coordinator"} brings members in. @ addresses one of them.`:he?`Nothing here yet. Ask ${he.name} for something.`:"Loading agents…"}),t.jsx($T,{offers:lM,disabled:oM!==null,onTake:cM}),xr?t.jsx("div",{className:"wb-composer-blocked","data-testid":"group-problem","data-kind":xr.kind,children:t.jsx(G,{tone:Tu?"warning":void 0,role:"status",children:t.jsxs("span",{children:[xr.text," ",t.jsx("button",{type:"button",className:"wb-link-btn",onClick:()=>i==null?void 0:i("members"),children:xr.action})]})})}):null,Gr?t.jsx("div",{className:"wb-composer-blocked","data-testid":"composer-blocked",children:t.jsxs(G,{tone:"warning",role:"status",children:[Gr," ",t.jsx("a",{href:Le(Ru.section),children:Ru.label})]})}):di.length>0?t.jsx(vT,{approvals:di,timezone:e,now:de,version:S,onDecided:Xw,onSay:J=>wm(J,[]),onOpenFull:J=>{z(J),d&&(m==null||m())}}):null,Gr||di.length>0?null:S!=null&&S.question?t.jsx(CT,{question:S.question,disabled:uM||M,onAnswer:dM,onSkip:hM},S.question.id):null,Gr||Tu?null:t.jsxs("div",{hidden:di.length>0||!!(S!=null&&S.question),"data-testid":"composer-slot",children:[t.jsx(Zy,{ref:Oe,disabled:!s,running:M,onSend:wm,onStop:Qw,agentName:a?a.name:(he==null?void 0:he.name)??"the agent",draft:Ct,history:$u,threadKey:k??(a?`group:${a.id}`:s),model:a?null:(he==null?void 0:he.model)??null,setupHref:a?null:he?Pt(he.id,"setup","brain"):null,thinking:Ro,...!a&&he&&sA(rA(he,Sn.data))?{onThinking:iM}:{},...a?{mentions:on.map(J=>({id:J.id,handle:J.handle,name:J.name})),team:{agents:q,selfId:""}}:s?{team:{agents:q,selfId:s}}:{},onCommand:pM,onOpenFile:To,conversationId:k??null,readAloud:kt,onReadAloud:ms}),fs?t.jsx("p",{className:"wb-voice-note",role:"status",children:fs}):null]})]}),d?f?t.jsxs("div",{className:"wb-sheet",role:"dialog","aria-label":"Canvas",children:[t.jsxs("div",{className:"wb-sheet-head",children:[t.jsx("strong",{children:"Canvas"}),t.jsx("button",{className:"ui-btn",onClick:p,children:"Close"})]}),nb]}):null:t.jsxs(t.Fragment,{children:[t.jsx("button",{className:"wb-grip","aria-label":"Resize the conversation column",onPointerDown:J=>{var ae,Te;Pu.current=!0,(Te=(ae=J.currentTarget).setPointerCapture)==null||Te.call(ae,J.pointerId)},onKeyDown:J=>{const ae=Te=>{var Ie;return Te??((Ie=ut.current)==null?void 0:Ie.offsetWidth)??Gd};J.key==="ArrowLeft"&&Ue(Te=>Math.max(Gd,ae(Te)-16)),J.key==="ArrowRight"&&Ue(Te=>Math.min(720,ae(Te)+16))}}),nb]})]})}function qH(){try{const e=window.localStorage.getItem(PT),n=Number(e);return e!==null&&Number.isFinite(n)&&n>=Gd?n:null}catch{return null}}function YH(e,n){return Date.parse(n.lastMessageAt??n.startedAt??n.createdAt??"")-Date.parse(e.lastMessageAt??e.startedAt??e.createdAt??"")}function En(e){return typeof e=="string"&&e!==""?e:null}function ka(e){return e instanceof xe||e instanceof Error?e.message:String(e)}function Ip(e,n){var r;const s=(r=n.blocks.find(a=>a.type==="text"))==null?void 0:r.text.trim();if(!s)return!0;for(let a=e.messages.length-1;a>=0;a-=1){const i=e.messages[a];if(i.role!=="user")continue;const l=i.blocks.find(o=>o.type==="text");if(l)return l.text.trim()===s}return!1}function xd(e){var s;const n=(s=e.dataTransfer)==null?void 0:s.types;return!!(n&&Array.from(n).includes("Files"))}function JH(){return t.jsxs("svg",{width:"28",height:"28",viewBox:"0 0 28 28","aria-hidden":"true",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M14 4v13M8.5 11.5 14 17l5.5-5.5"}),t.jsx("path",{d:"M5 19.5v2a2.5 2.5 0 0 0 2.5 2.5h13a2.5 2.5 0 0 0 2.5-2.5v-2"})]})}function QH(){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16","aria-hidden":"true",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M2.6 8a5.4 5.4 0 1 0 1.6-3.8"}),t.jsx("path",{d:"M2.4 2.6v2.6h2.6M8 5.2V8l2 1.3"})]})}function XH(){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16","aria-hidden":"true",fill:"currentColor",children:[t.jsx("circle",{cx:"8",cy:"3.4",r:"1.35"}),t.jsx("circle",{cx:"8",cy:"8",r:"1.35"}),t.jsx("circle",{cx:"8",cy:"12.6",r:"1.35"})]})}function mN({items:e,disabled:n,label:s,title:r,sub:a,face:i}){const[l,o]=h.useState(!1),c=h.useRef(null);h.useEffect(()=>{if(!l)return;const d=m=>{c.current&&!c.current.contains(m.target)&&o(!1)},f=m=>{m.key==="Escape"&&o(!1)};return window.addEventListener("mousedown",d),window.addEventListener("keydown",f),()=>{window.removeEventListener("mousedown",d),window.removeEventListener("keydown",f)}},[l]);const u=d=>{const f=t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"ui-menu-item-text",children:d.label}),d.hint?t.jsx("span",{className:"ui-menu-item-hint",children:d.hint}):null]});return d.href?t.jsx("a",{className:"ui-menu-item",role:"menuitem",href:d.href,"data-tone":d.tone,onClick:()=>o(!1),children:f},d.label):t.jsx("button",{className:"ui-menu-item",role:"menuitem","data-testid":d.testId,"data-tone":d.tone,disabled:d.disabled,onClick:()=>{var m;o(!1),(m=d.onSelect)==null||m.call(d)},children:f},d.label)};return t.jsxs("div",{className:"wb-head-menu",ref:c,children:[t.jsx("button",{className:"ui-icon-btn wb-head-more","data-testid":"chat-menu","aria-label":s,"aria-haspopup":"menu","aria-expanded":l,"data-open":l?"true":void 0,disabled:n,onClick:()=>o(d=>!d),children:t.jsx(XH,{})}),l?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"wb-head-menu-scrim","aria-hidden":"true",onClick:()=>o(!1)}),t.jsxs("div",{className:"ui-menu wb-head-menu-list",role:"menu","aria-label":r,children:[t.jsxs("div",{className:"wb-head-menu-head","aria-hidden":"true",children:[i,t.jsxs("span",{className:"wb-head-menu-heading",children:[t.jsx("span",{className:"wb-head-menu-title",children:r}),a?t.jsx("span",{className:"wb-head-menu-sub",children:a}):null]})]}),e.map((d,f)=>d==="separator"?t.jsx("div",{className:"ui-menu-sep",role:"separator"},`sep-${f}`):u(d)),t.jsx("button",{type:"button",className:"ui-btn wb-head-menu-cancel",onClick:()=>o(!1),children:"Cancel"})]})]}):null]})}let pN=!1;const ZH=new Set(["missing","unconfigured","not-english"]);async function Uh(e,n,s=null){const r=X$(s);try{const a=await qe.say({text:e,...n?{conversationId:n}:{}});return _0(r)&&await JB(a.audioUrl,a.mime,s),null}catch(a){_0(r)&&ko();const i=a instanceof xe&&a.detail&&typeof a.detail=="object"?a.detail.reason:void 0;return typeof i=="string"&&ZH.has(i)&&(s!==null||!pN)?(pN=!0,a.message):null}}function eK(e,n,s){const r=nA(e);if(!r||r.rest==="")return null;const a=n.find(i=>i.roles.includes(Fr));return!a||a.id===s||a.handle.toLowerCase()!==r.handle?null:{agent:a,rest:r.rest}}const sv="buddi:ask";function tK(e){const n={text:e,handled:!1};return window.dispatchEvent(new CustomEvent(sv,{detail:n})),n.handled}let Os=null;function nK(e){if(Bd(e)!==null)return!1;const n=a$(e);return n!==kn&&n!==oa}function sK({agent:e,agents:n,open:s,onOpenChange:r,navigate:a,timezone:i}){const l=h.useRef(null),o=h.useRef(s),c=`Ask ${e.name}`,[u,d]=h.useState(!1),[f,m]=h.useState(null);return h.useEffect(()=>{const p=g=>{const v=g.detail;!v||typeof v.text!="string"||(v.handled=!0,m({text:v.text,at:Date.now()}),r(!0))};return window.addEventListener(sv,p),()=>window.removeEventListener(sv,p)},[r]),h.useEffect(()=>{if(s||!u||!Os)return;const p=Kf({url:qe.streamUrl(Os.conversationId),lastEventId:Os.lastEventId??null,onEvent:g=>{g.name==="run.finished"&&d(!1)}});return()=>p.close()},[s,u]),h.useEffect(()=>{const p=g=>{!g.altKey||g.ctrlKey||g.metaKey||g.code!=="Slash"||(g.preventDefault(),r(!s))};return window.addEventListener("keydown",p),()=>window.removeEventListener("keydown",p)},[s,r]),h.useEffect(()=>{var p;o.current&&!s&&((p=l.current)==null||p.focus()),o.current=s},[s]),s?t.jsx(aK,{agent:e,agents:n,timezone:i,navigate:a,onClose:()=>r(!1),onBusy:d,prefill:f}):t.jsxs(zc,{children:[t.jsx(Uc,{asChild:!0,children:t.jsx("button",{ref:l,type:"button",className:"wb-ask-fab","data-busy":u?"true":void 0,"aria-label":c,onClick:()=>r(!0),children:t.jsx(rK,{busy:u})})}),t.jsx(Bc,{children:t.jsx(Wc,{className:"ui-tip",side:"left",sideOffset:8,children:c})})]})}function rK({busy:e}){const[n,s]=h.useState(!1);return n?t.jsx(Qc,{size:"lg"}):t.jsx(ku,{state:e?"working":"idle",className:"wb-ask-fab-face",onStillError:()=>s(!0)})}function aK({agent:e,agents:n,timezone:s,navigate:r,onClose:a,onBusy:i,prefill:l}){const o=h.useRef(null),[c,u]=h.useState(Os&&Os.agentId===e.id?Os.conversationId:null),[d,f]=h.useState(null),[m,p]=h.useState([]),[g,v]=h.useState([]),[b,j]=h.useState(null),[x,y]=h.useState(!1),[w,k]=h.useState(!1),[N,S]=h.useState(null),[C,E]=h.useState(l??null);h.useEffect(()=>{l&&E(l)},[l]);const[T,I]=h.useState(Date.now()),[F,D]=h.useState(J$),$=h.useRef(F);$.current=F;const[L,O]=h.useState(null),[M,P]=h.useState(new Map),H=h.useRef(null),U=h.useCallback(async fe=>{try{const ge=await qe.conversation(fe);f(ge),p(Pe=>Pe.filter(je=>!iK(ge,je)))}catch{}},[]);h.useEffect(()=>{c&&U(c)},[c,U]),h.useEffect(()=>{if(!c)return;const fe=Kf({url:qe.streamUrl(c),onEvent:ge=>{var Pe;switch(ge.name){case"run.started":H.current=null,y(!0),j(null);break;case"live":{const je=Ln(ge.data.runId)??"",de=Number(ge.data.turn??0),ke=ge.data.kind==="thinking"?"thinking":"text",Be=Ln(ge.data.text)??"",Ue=Date.now();if(ke==="text"){const ut=H.current;H.current=ut&&ut.runId===je&&ut.turn===de?{...ut,text:ut.text+Be}:{runId:je,turn:de,text:Be}}j(ut=>{const dt=ut&&ut.runId===je&&ut.turn===de?ut:{runId:je,turn:de,text:"",thinking:"",thinkingStartedAt:null,textStartedAt:null,settled:!1};return ke==="thinking"?{...dt,thinking:dt.thinking+Be,thinkingStartedAt:dt.thinkingStartedAt??Ue}:{...dt,text:dt.text+Be,textStartedAt:dt.textStartedAt??Ue}});break}case"live.snapshot":{const je=Ln(ge.data.runId)??"",de=Number(ge.data.turn??0),ke=Ln(ge.data.text)??"",Be=Ln(ge.data.thinking)??"",Ue=Number(ge.data.startedAt??Date.now());H.current={runId:je,turn:de,text:ke},y(!0),j({runId:je,turn:de,text:ke,thinking:Be,thinkingStartedAt:Be?Ue:null,textStartedAt:ke?Ue:null,settled:!1});break}case"live.settle":{const je=Ln(ge.data.runId)??"",de=Number(ge.data.turn??0);j(ke=>ke&&ke.runId===je&&ke.turn===de?{...ke,settled:!0}:ke);break}case"tool.called":{const je=Ln(ge.data.toolUseId)??Ln(ge.data.id),de=Ln(ge.data.name)??Ln(ge.data.tool)??"tool";je&&v(ke=>[...ke.filter(Be=>Be.toolUseId!==je),{toolUseId:je,name:de,startedAt:Date.now()}]);break}case"tool.result":{const je=Ln(ge.data.toolUseId)??Ln(ge.data.id);je&&v(de=>de.filter(ke=>ke.toolUseId!==je)),U(c);break}case"awaiting-approval":{const je=Ln(ge.data.approvalId)??Ln(ge.data.actionId),de=Ln(ge.data.toolUseId);je&&de&&P(ke=>new Map(ke).set(de,je)),de&&v(ke=>ke.filter(Be=>Be.toolUseId!==de)),U(c).then(()=>j(ke=>ke!=null&&ke.settled?null:ke));break}case"message.appended":U(c).then(()=>j(je=>je!=null&&je.settled?null:je));break;case"run.finished":{y(!1),v([]),j(null);const je=Ln(ge.data.message);S(je??null);const de=((Pe=H.current)==null?void 0:Pe.text.trim())??"";H.current=null,!je&&de!==""&&$.current&&Uh(de,c).then(ke=>{ke&&O(ke)}),U(c);break}}}});return()=>{Os&&Os.conversationId===c&&(Os.lastEventId=fe.lastEventId()),fe.close()}},[c,U]),h.useEffect(()=>{i(x||w)},[x,w,i]),h.useEffect(()=>{if(g.length===0)return;const fe=window.setInterval(()=>I(Date.now()),1e3);return()=>window.clearInterval(fe)},[g.length]);const V=(fe,ge)=>{k(!0),S(null);const Pe={id:`local-${Date.now()}`,role:"user",at:new Date().toISOString(),blocks:[{type:"text",text:fe}]};p(je=>[...je,Pe]),(async()=>{try{const je=c??(await qe.startConversation(e.id)).conversationId;je!==c&&(Os={agentId:e.id,conversationId:je},u(je));const de=await qe.send(e.id,{conversationId:je,text:fe,...ge.length>0?{attachmentIds:ge.map(ke=>ke.artifactId)}:{}});de.conversationId!==je&&(Os={agentId:e.id,conversationId:de.conversationId},u(de.conversationId)),y(!0),U(de.conversationId)}catch(je){p(de=>de.filter(ke=>ke.id!==Pe.id)),S(je instanceof xe?je.message:String(je)),E({text:fe,at:Date.now()})}finally{k(!1)}})()},z=(fe,ge)=>{if(S(null),fe==="stop"){X();return}if(fe==="use"){const Pe=ge.replace(/^@/,"").toLowerCase(),je=n.find(de=>de.handle.toLowerCase()===Pe||de.id===Pe);if(!je){O(Pe?`No agent called @${Pe}.`:"Say who: /use @handle.");return}r(Ze(je.id));return}if(fe==="new"){const Pe=n.find(je=>je.roles.includes(Fr));if(!Pe){O("There is no agent here that makes agents.");return}ge.trim()&&xu(Pe.id,`I'd like a teammate for this: ${ge.trim()}`),r(Ze(Pe.id));return}R.quiet(ge).then(Pe=>O(Pe.text)).catch(Pe=>S(Pe instanceof Error?Pe.message:String(Pe)))},X=()=>{c&&qe.cancel(c).catch(fe=>S(String(fe))).finally(()=>y(!1))},K=()=>{var fe;Os=null,u(null),f(null),p([]),v([]),j(null),y(!1),S(null),P(new Map),(fe=o.current)==null||fe.focus()},ee=fe=>{D(fe),Q$(fe),fe||ko()},ce=c?Ze(e.id,c):Ze(e.id),pe=[...(d==null?void 0:d.messages)??[],...m],{openOffers:oe,takingOffer:Re,takeOffer:Oe,answeringQuestion:Je,answerQuestion:W,skipQuestion:se}=AT({conversation:d,conversationId:c,agentId:e.id,now:T,refresh:U,onRunStarted:()=>y(!0),onError:(fe,ge)=>{S(fe),ge&&y(!1)},navigate:r}),Y=h.useMemo(()=>DH(d,n,M),[d,n,M]),Ne=Y.length===0?(d==null?void 0:d.question)??null:null,we=fe=>{c&&U(c),R.overview().catch(()=>{}),fe.state!=="pending"&&P(ge=>new Map([...ge].filter(([,Pe])=>Pe!==fe.id)))};return t.jsxs(C6,{title:e.name,label:`${e.name}, a quick chat`,onClose:a,onOpenAutoFocus:fe=>{var ge;fe.preventDefault(),(ge=o.current)==null||ge.focus()},onCloseAutoFocus:fe=>fe.preventDefault(),actions:t.jsxs(t.Fragment,{children:[t.jsx(A,{size:"sm",variant:"ghost",onClick:K,disabled:c===null&&m.length===0,children:"New"}),t.jsx(ht,{size:"sm",variant:"ghost",href:ce,onClick:fe=>{fe.preventDefault(),r(ce)},children:"Open in Chat"})]}),children:[t.jsx("div",{className:"wb-ask-thread",children:t.jsx(Ky,{messages:pe,live:g,now:T,working:x||w,partial:b,agents:n,agentName:e.name,agentId:e.id,onOpen:()=>r(ce),onReadAloud:(fe,ge)=>{O(null),Uh(ge,c??void 0,fe).then(Pe=>{Pe&&O(Pe)})},emptyHint:`Ask ${e.name} anything, without leaving this page.`})}),t.jsxs("div",{className:"wb-ask-compose",children:[N?t.jsx(ne,{message:N}):null,t.jsx($T,{offers:oe,disabled:Re!==null,onTake:Oe}),Y.length>0?t.jsx(vT,{approvals:Y,timezone:s,now:T,version:d,onDecided:we,onSay:fe=>V(fe,[]),onOpenFull:()=>r(ce)}):Ne?t.jsx(CT,{question:Ne,disabled:Je||x,onAnswer:W,onSkip:se},Ne.id):null,t.jsxs("div",{hidden:Y.length>0||Ne!==null,"data-testid":"composer-slot",children:[t.jsx(Zy,{ref:o,disabled:w||!e.available,running:x,onSend:V,onStop:X,agentName:e.name,placeholder:`Message ${e.name}…`,draft:C,threadKey:`dock.${c??e.id}`,conversationId:c,readAloud:F,onReadAloud:ee,team:{agents:n,selfId:e.id},onCommand:z}),L?t.jsx("p",{className:"wb-voice-note",role:"status",children:L}):null]})]})]})}function Ln(e){return typeof e=="string"?e:null}function iK(e,n){var r;const s=(r=n.blocks)==null?void 0:r.find(a=>a.type==="text");return!s||s.type!=="text"?!1:e.messages.some(a=>a.role==="user"&&(a.blocks??[]).some(i=>i.type==="text"&&i.text.includes(s.text)))}const MT=3;function lK(e){if(e==="approval"||e==="question")return"accent";if(e==="watcher"||e==="reminder")return"warm";if(e==="failure")return"critical"}function oK(e,n){return e?n?"above-dock":"above-button":"corner"}function cK({placement:e,children:n}){return t.jsx("div",{className:"wb-toast-stack","data-placement":e,children:n})}function uK(e){return e.state==="shown"&&e.seenAt===null}function dK(e){const[n,s]=h.useState([]),r=h.useRef(new Set),a=h.useRef(new Set),i=h.useCallback(()=>{e&&R.notifications(20).then(({notifications:o})=>{const c=o.filter(u=>uK(u)&&!r.current.has(u.id));s(u=>{const d=new Set(u.map(m=>m.id)),f=c.filter(m=>!d.has(m.id));return f.length===0?u:[...u,...f].sort((m,p)=>p.createdAt.localeCompare(m.createdAt))})}).catch(()=>{})},[e]);h.useEffect(()=>{for(const o of n.slice(0,MT))a.current.has(o.id)||(a.current.add(o.id),R.notificationSeen(o.id).catch(()=>{}))},[n]);const l=h.useCallback(o=>{r.current.add(o),s(c=>c.filter(u=>u.id!==o))},[]);return{queue:n,refresh:i,dismiss:l}}function hK({queue:e,agents:n,navigate:s,onDismiss:r}){if(e.length===0)return null;const a=e.slice(0,MT),i=e.length-a.length;return t.jsxs("section",{className:"nt-toasts","aria-label":"Notifications",children:[a.map(l=>t.jsxs("div",{className:"ui-toast nt-toast","data-tone":lK(l.kind),role:"status",children:[l.agentId?t.jsx(fn,{agents:n,id:l.agentId,size:"sm"}):null,t.jsxs("div",{className:"nt-toast-main",children:[t.jsx("div",{className:"ui-toast-title",children:Kc(l)}),l.text?t.jsx("div",{className:"ui-toast-body nt-toast-line",children:fK(l.text)}):null,l.link?t.jsx("a",{className:"nt-toast-link",href:l.link,onClick:o=>{o.preventDefault(),r(l.id),s(l.link)},children:"See"}):null]}),t.jsx("button",{type:"button",className:"nt-toast-x","aria-label":`Dismiss ${Kc(l)}`,onClick:()=>r(l.id),children:"×"})]},l.id)),i>0?t.jsxs("p",{className:"nt-toasts-more",children:["and ",i," more"]}):null]})}function fK(e){var n;return((n=e.split(`
122
- `).find(s=>s.trim()!==""))==null?void 0:n.trim())??""}const mK=3e4,pK=1e3;function gK(e,n,s){const r=h.useRef(n);r.current=n;const a=h.useRef(s);a.current=s,h.useEffect(()=>{if(!e)return;let i=!1,l=-1/0,o=null,c=null,u=!0;const d=()=>document.visibilityState!=="hidden",f=j=>{var x;l=Date.now(),R.presence(j).catch(y=>{var w;y instanceof xe&&y.status===401&&(i=!0,(w=a.current)==null||w.call(a))}),j==="active"&&((x=r.current)==null||x.call(r))},m=j=>{if(i||(o=j,c!==null))return;const x=l+pK-Date.now();if(x<=0){o=null,f(j);return}c=window.setTimeout(()=>{if(c=null,i||o===null)return;const y=o;o=null,f(y)},x)},p=()=>{u=!0,d()&&m("active")},g=()=>{u=!1,m("away")},v=()=>m(d()?"active":"away");d()&&m("active");const b=window.setInterval(()=>{d()&&u&&m("active")},mK);return window.addEventListener("focus",p),window.addEventListener("blur",g),document.addEventListener("visibilitychange",v),()=>{i=!0,window.clearInterval(b),c!==null&&window.clearTimeout(c),window.removeEventListener("focus",p),window.removeEventListener("blur",g),document.removeEventListener("visibilitychange",v)}},[e])}function xK({agents:e,onClose:n,onCreated:s}){return f$(e)?t.jsx(vK,{agents:Cy(e),onClose:n,...s?{onCreated:s}:{}}):t.jsx(Ge,{title:"A new group",onClose:n,children:t.jsxs(G,{children:["A group needs two agents. Make another one with ",dU(e)," first."]})})}function vK({agents:e,onClose:n,onCreated:s}){var j,x;const[r,a]=h.useState(""),[i,l]=h.useState([]),[o,c]=h.useState(((j=e.find(y=>y.roles.includes(bu)))==null?void 0:j.id)??((x=e[0])==null?void 0:x.id)??""),[u,d]=h.useState(!1),[f,m]=h.useState(null),p=[...new Set([o,...i])].filter(Boolean),g=r.trim()!==""&&o!==""&&p.length>=2,v=y=>l(w=>w.includes(y)?w.filter(k=>k!==y):[...w,y]),b=async()=>{d(!0),m(null);try{s==null||s(await qe.createGroup({name:r.trim(),coordinator:o,members:p.filter(y=>y!==o)}))}catch(y){m(y instanceof xe?y.message:String(y))}finally{d(!1)}};return t.jsx(Ge,{title:"A new group",onClose:n,children:t.jsxs(ie,{children:[t.jsx(re,{label:"Name",hint:"What this team is for: Household finances, The move, Tax season.",children:t.jsx("input",{value:r,autoFocus:!0,maxLength:80,onChange:y=>a(y.target.value),placeholder:"Household finances"})}),t.jsx(re,{label:"Coordinator",hint:"Reads your request, brings members in, and answers for the group. Concierge by default.",children:t.jsx("select",{value:o,onChange:y=>c(y.target.value),children:e.map(y=>t.jsx("option",{value:y.id,children:y.name},y.id))})}),t.jsx(re,{label:"Members",hint:"Each keeps its own account, tools and approvals. Membership grants nothing.",children:t.jsx("div",{className:"group-pick",role:"group","aria-label":"Members",children:e.filter(y=>y.id!==o).map(y=>t.jsxs("label",{className:"group-pick-row","data-on":i.includes(y.id)||void 0,children:[t.jsx("input",{type:"checkbox",checked:i.includes(y.id),onChange:()=>v(y.id)}),t.jsx(fn,{agents:e,id:y.id,size:"sm"}),t.jsxs("span",{className:"group-pick-text",children:[t.jsx("span",{className:"group-pick-name",children:y.name}),t.jsx("span",{className:"group-pick-desc",children:y.description})]})]},y.id))})}),t.jsx(G,{children:"Members read what is said in this group and what they recall from shared and group memory. Nothing an agent knows privately is brought in on its own: what enters the room is seen by the room."}),f?t.jsx(G,{tone:"critical",children:f}):null,t.jsxs(te,{align:"end",children:[t.jsx(A,{onClick:n,children:"Cancel"}),t.jsx(A,{variant:"accent",disabled:!g||u,onClick:()=>void b(),children:u?"Creating…":"Create group"})]})]})})}const jK=1e4;function eu({title:e,body:n,duration:s,onUndo:r,onGone:a}){return t.jsxs(aL,{className:"ui-toast wb-undo-toast",duration:s,onOpenChange:i=>{i||a()},"data-testid":"undo-toast",children:[t.jsx("span",{className:"ui-toast-mark","aria-hidden":"true"}),t.jsxs("div",{className:"ui-toast-main",children:[t.jsx(iL,{className:"ui-toast-title",children:e}),n?t.jsx(lL,{className:"ui-toast-body",children:n}):null]}),r?t.jsx(oL,{altText:"Undo",asChild:!0,children:t.jsx("button",{type:"button",className:"ui-btn wb-undo-toast-action","data-variant":"ghost","data-size":"sm",onClick:r,children:"Undo"})}):null]})}function ew(e){const[n,s]=h.useState(null),[r,a]=h.useState(null),[i,l]=h.useState(null);return{busy:n,note:r,failure:i,decide:async(c,u,d,f)=>{var p,g,v,b;s(c),l(null),a(null);let m;try{const j=f?await R.decide(c,u,d,f):await R.decide(c,u,d);m={decision:u,...(p=j.execution)!=null&&p.state?{state:j.execution.state}:{},...j.execution&&"result"in j.execution?{result:j.execution.result}:{}},a(u==="reject"?`Rejected ${j.action.tool}.`:((g=j.execution)==null?void 0:g.state)==="succeeded"?`Approved and done: ${j.action.tool}.`:`Approved ${j.action.tool}: ${((v=j.execution)==null?void 0:v.state)??"no execution"}${(b=j.execution)!=null&&b.message?` (${j.execution.message})`:""}`)}catch(j){l(j instanceof Error?j.message:String(j))}finally{s(null),e(m)}}}}function tw({action:e,timezone:n,busy:s,onDecide:r,agentName:a}){var d,f;const[i,l]=h.useState(!1),{values:o,controls:c}=My(e.choices),u=m=>o?r(e.id,"approve",m,o):r(e.id,"approve",m);return t.jsxs(Ts,{tone:"accent",title:e.tool,meta:t.jsxs(t.Fragment,{children:[t.jsxs(Ee,{children:["v",e.toolVersion]}),t.jsxs("span",{className:"muted",children:["asked by ",a??e.agentId]})]}),children:[t.jsx(Dt,{children:e.preview}),t.jsxs("p",{className:"ui-card-meta",children:["Expires ",ct(e.expiresAt,n)," (",Ve(e.expiresAt),"). Policy v",e.policyVersion,", args ",Hc(e.argsHash,12),e.jobId?`, job ${Hc(e.jobId)}`:"","."]}),c,t.jsxs(te,{children:[t.jsx(A,{variant:"good",disabled:s,onClick:()=>u(),children:(d=e.permissionScopes)!=null&&d.length?"Allow once":"Approve"}),(f=e.permissionScopes)!=null&&f.length?t.jsxs(t.Fragment,{children:[t.jsx(A,{disabled:s,onClick:()=>u("conversation"),children:"Auto: this conversation"}),t.jsx(A,{disabled:s,onClick:()=>u("always"),children:"Always: this agent"})]}):null,t.jsx(A,{variant:"danger",disabled:s,onClick:()=>r(e.id,"reject"),children:"Reject"}),t.jsx(A,{variant:"ghost",onClick:()=>l(m=>!m),"aria-expanded":i,children:i?"Hide envelope":"Show envelope"})]}),i?t.jsxs("div",{className:"ui-card-foot",children:[t.jsx(ue,{title:"Envelope: everything that decides what the world will see",children:t.jsx(Dt,{children:ks(e.envelope)})}),t.jsx(ue,{title:"Canonical arguments",children:t.jsx(Dt,{children:ks(e.canonicalArgs)})})]}):null]})}function nw(e,n,s){const[r,a]=h.useState(!1),[i,l]=h.useState(null),[o,c]=h.useState(null);return{accept:()=>{e&&(a(!0),c(null),R.acceptPluginAgent(e,n).then(d=>{l(d.agent),s==null||s(d.agent)}).catch(d=>c(d instanceof xe?d.message:String(d))).finally(()=>a(!1)))},busy:r,created:i,failure:o}}function DT({agent:e}){return t.jsxs(G,{tone:"good",role:"status",children:["@",e.handle," is ready. ",t.jsxs("a",{href:Ze(e.id),children:["Talk to @",e.handle]})]})}function OT(e,n,s){const r=e.canonicalArgs;return e.tool==="platform.accept_plugin_agent"&&(r==null?void 0:r.plugin)===n&&typeof r.agent=="string"&&r.agent.toLowerCase()===s.toLowerCase()}function yK(e,n){var a;const s=me(()=>R.approvals(),[e,n],15e3);return{action:((a=s.data)==null?void 0:a.pending.find(i=>OT(i,e,n)))??null,reload:s.reload}}function wK({action:e,onDecided:n}){const{busy:s,failure:r,decide:a}=ew(i=>n(i));return t.jsxs(ie,{gap:"sm",children:[t.jsx(tw,{action:e,timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,busy:s===e.id,onDecide:(i,l,o,c)=>{a(i,l,o,c)}}),t.jsx(ne,{message:r})]})}function sw({plugin:e,agent:n,text:s,label:r,handle:a,onDismiss:i}){var f;const l=nw(e,n),o=yK(e,n),[c,u]=h.useState(null),d=l.created??c;if(d)return t.jsx(DT,{agent:d});if(o.action){const m=a??((f=/@(\S+)/.exec(r))==null?void 0:f[1])??n;return t.jsxs(ie,{gap:"sm",children:[t.jsx("span",{children:s}),t.jsx(wK,{action:o.action,onDecided:p=>{(p==null?void 0:p.decision)==="approve"&&p.state==="succeeded"?u({id:n,handle:m,name:m}):o.reload()}})]})}return t.jsxs(ie,{gap:"sm",children:[t.jsxs(te,{children:[t.jsx("span",{children:s}),t.jsx(et,{}),i?t.jsx(A,{variant:"ghost",disabled:l.busy,onClick:i,children:"Not now"}):null,t.jsx(A,{variant:"accent",disabled:l.busy,onClick:l.accept,children:r})]}),t.jsx(ne,{message:l.failure})]})}function LT(){var n;const e=me(()=>R.agentOffers(),[],6e4);return{offers:((n=e.data)==null?void 0:n.offers)??[],reload:e.reload}}function FT({offers:e,reload:n}){return e.length===0?null:t.jsx(ue,{title:"From your plugins",aside:`${e.length} to decide`,panel:!0,children:t.jsx(ie,{gap:"sm",divided:!0,children:e.map(s=>t.jsx(sw,{plugin:s.plugin,agent:s.agent,text:s.text,label:`Create @${s.handle}`,handle:s.handle,onDismiss:()=>{R.dismissAgentOffer(s.plugin,s.agent).then(n,n)}},`${s.plugin}/${s.agent}`))})})}const bK=512*1024,kK=/^[A-Za-z0-9+/]*={0,2}$/;function _T(e){const n=e==null?void 0:e.play;if(typeof n!="object"||n===null)return null;const{mime:s,data:r}=n;return typeof s!="string"||!/^audio\/[a-z0-9.+-]+$/i.test(s.split(";")[0].trim())||typeof r!="string"||r===""||!kK.test(r)||Math.floor(r.length*3/4)>bK+2?null:{mime:s,data:r}}function zT(e){const n=e==null?void 0:e.message;return typeof n=="string"&&n.trim()!==""?n:null}let ea=null,gc=null,tu=null;const rv=new Set;function UT(){for(const e of rv)e()}function ec(){ea&&(ea.onended=null,ea.onerror=null,ea.pause()),gc&&URL.revokeObjectURL(gc),gc=null,tu!==null&&(tu=null,UT())}async function BT(e,n){ec();const s=atob(e.data),r=new Uint8Array(s.length);for(let a=0;a<s.length;a+=1)r[a]=s.charCodeAt(a);ea??(ea=new Audio),gc=URL.createObjectURL(new Blob([r],{type:e.mime})),tu=n,ea.onended=ec,ea.onerror=ec,ea.src=gc,UT();try{await ea.play()}catch{throw ec(),new Error("The browser would not play the sound.")}}function gN(e){e!==void 0&&tu!==e||ec()}function NK(){return h.useSyncExternalStore(e=>(rv.add(e),()=>rv.delete(e)),()=>tu,()=>null)}const SK=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],wr=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],xN=/^\d{4}-\d{2}-\d{2}$/;function Ei(e){return e.split("-").map(Number)}function ii(e,n){const[s,r,a]=Ei(e);return new Date(Date.UTC(s,r-1,a+n)).toISOString().slice(0,10)}function WT(e){const[n,s,r]=Ei(e);return new Date(Date.UTC(n,s-1,r)).getUTCDay()}function HT(e){return SK[WT(e)]}function KT(e){return Ei(e)[2]}function vN(e){return ii(e,-((WT(e)+6)%7))}function Vn(e){return gu(e,{weekday:!0,compact:!0})}function CK(e,n){return e===n?`Today · ${Vn(e)}`:e===ii(n,1)?`Tomorrow · ${Vn(e)}`:Vn(e)}function sr(e){return HF(e)}const jN=new Map;function av(e,n){let s=jN.get(n);s||(s=new Intl.DateTimeFormat("en-GB",{timeZone:n,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",hourCycle:"h23"}),jN.set(n,s));const r=Object.fromEntries(s.formatToParts(e).map(a=>[a.type,a.value]));return{date:`${r.year}-${r.month}-${r.day}`,minutes:Number(r.hour)*60+Number(r.minute)}}function EK(e,n=new Date){return av(n,e).date}function AK(e,n){return e==="week"?{from:vN(n),days:7}:e==="month"?{from:vN(`${n.slice(0,8)}01`),days:42}:{from:n,days:7}}function $K(e,n,s){if(e!=="month")return ii(n,s*7);const[r,a]=Ei(n);return new Date(Date.UTC(r,a-1+s,1)).toISOString().slice(0,10)}function TK(e,n,s,r){const[a,i]=Ei(n);if(e==="month")return eA(a,i);const l=ii(s,r-1),[o,c,u]=Ei(s),[d,f,m]=Ei(l);return XE().date==="iso"?`${s} – ${l}`:KF()?c===f&&o===d?`${wr[c-1]} ${u} – ${m}, ${d}`:o===d?`${wr[c-1]} ${u} – ${wr[f-1]} ${m}, ${d}`:`${wr[c-1]} ${u}, ${o} – ${wr[f-1]} ${m}, ${d}`:c===f&&o===d?`${u} – ${m} ${wr[f-1]} ${d}`:o===d?`${u} ${wr[c-1]} – ${m} ${wr[f-1]} ${d}`:`${u} ${wr[c-1]} ${o} – ${m} ${wr[f-1]} ${d}`}function cl(e){return e==null?"":String(e)}function RK(e,n,s,r){const a=[],i=new Set;return e.forEach((l,o)=>{const c=cl(Ce(l,n.id)),u=cl(Ce(l,n.title)),d=cl(Ce(l,n.start)),f=cl(Ce(l,n.end));if(c===""||i.has(c)||d===""){console.warn(`buddi: ${r}: event ${o} has no id, a repeated one, or no start — not drawn`);return}i.add(c);const m=n.allDay===void 0?void 0:Ce(l,n.allDay),p=m===void 0?xN.test(d):m===!0||m==="true",g=n.tone===void 0?0:Number(Ce(l,n.tone)),v=Number.isFinite(g)?(Math.trunc(g)%4+4)%4:0,b={id:c,title:u,calendar:n.calendar===void 0?"":cl(Ce(l,n.calendar)),tone:v,location:n.location===void 0?"":cl(Ce(l,n.location)),row:l};if(p){const k=d.slice(0,10),N=xN.test(f.slice(0,10))&&f.slice(0,10)>k?f.slice(0,10):ii(k,1);a.push({...b,allDay:!0,startDate:k,startMin:0,endDate:N,endMin:0});return}const j=new Date(d);if(Number.isNaN(j.getTime())){console.warn(`buddi: ${r}: event ${o} starts at "${d}", which is not a time — not drawn`);return}const x=new Date(f),y=av(j,s),w=Number.isNaN(x.getTime())||x<j?y:av(x,s);a.push({...b,allDay:!1,startDate:y.date,startMin:y.minutes,endDate:w.date,endMin:w.minutes})}),a}function IK(e,n){if(e.allDay)return n>=e.startDate&&n<e.endDate?{from:0,to:1440,allDay:!0}:null;if(n<e.startDate||n>e.endDate)return null;const s=n===e.startDate?e.startMin:0,r=n===e.endDate?e.endMin:1440,a=e.startDate===e.endDate&&e.startMin===e.endMin;return r<=s&&!(a&&n===e.startDate)?null:{from:s,to:r,allDay:s===0&&r===1440}}function rw(e,n){return e.map(s=>({event:s,part:IK(s,n)})).filter(s=>s.part!==null).sort((s,r)=>Number(r.part.allDay)-Number(s.part.allDay)||s.part.from-r.part.from||r.part.to-s.part.to)}function aw(e,n){if(n.allDay)return"All day";const s=e.startDate!==e.endDate;return s&&n.from===0?`until ${sr(n.to)}`:s&&n.to===1440?`from ${sr(n.from)}`:n.from===n.to?sr(n.from):`${sr(n.from)}–${sr(n.to)}`}function iv(e,n,s){return[aw(e,n),e.title,e.location,e.calendar,Vn(s)].filter(Boolean).join(", ")}const VT=30;function PK(e){const n=[];let s=[],r=-1;const a=[],i=()=>{const l=Math.max(1,...s.map(o=>o.lane+1));for(const o of s)n.push({...o,lanes:l});s=[],a.length=0};for(const l of e){const o=Math.max(l.part.to,l.part.from+VT);s.length>0&&l.part.from>=r&&i();let c=a.findIndex(u=>u<=l.part.from);c===-1?(c=a.length,a.push(o)):a[c]=o,s.push({...l,lane:c,lanes:1}),r=Math.max(r,o)}return s.length>0&&i(),n}function MK(e){if(e<60)return`${e} min`;const n=Math.floor(e/60),s=e%60;return s===0?`${n} h`:`${n} h ${String(s).padStart(2,"0")}`}function DK(e){if(e.allDay){const a=ii(e.endDate,-1);return a>e.startDate?`${Vn(e.startDate)} – ${Vn(a)} · all day`:`${Vn(e.startDate)} · all day`}const n=Math.round((Date.parse(`${e.endDate}T00:00:00Z`)-Date.parse(`${e.startDate}T00:00:00Z`))/864e5),s=n*1440+e.endMin-e.startMin,r=n===0?`${Vn(e.startDate)} · ${sr(e.startMin)}–${sr(e.endMin)}`:`${Vn(e.startDate)} ${sr(e.startMin)} – ${Vn(e.endDate)} ${sr(e.endMin)}`;return s>0?`${r} · ${MK(s)}`:r}const OK={week:"Week",month:"Month",list:"List"},LK=["week","month","list"],FK="(max-width: 720px)";function _K(e){try{return window.localStorage.getItem(e)}catch{return null}}function zK(e,n){try{window.localStorage.setItem(e,n)}catch{}}function UK(e){const n=e.views&&e.views.length>0?e.views:LK,s=ws(FK),[r,a]=h.useState(()=>{const p=_K(e.storageKey);return p!==null&&n.includes(p)?p:null}),i=s&&n.includes("list")?"list":e.default&&n.includes(e.default)?e.default:n[0],l=r??i,[o,c]=h.useState(e.today),[u,d]=h.useState(null),{from:f,days:m}=AK(l,o);return{views:n,view:l,setView:p=>{a(p),zK(e.storageKey,p),d(null)},anchor:o,today:e.today,go:p=>{c(p===0?e.today:$K(l,o,p)),d(null)},from:f,days:m,to:ii(f,m),selected:u,select:d}}function BK({state:e,events:n,hours:s,empty:r,label:a,onEvent:i,count:l}){const{view:o,anchor:c,today:u,from:d,days:f}=e,m=h.useMemo(()=>Array.from({length:f},(j,x)=>ii(d,x)),[d,f]),p=o==="month"?"month":"week",g=e.selected??(c.slice(0,7)===u.slice(0,7)?u:`${c.slice(0,8)}01`),v=o==="month"?g:o==="week"&&!i?e.selected:null,b=j=>{if(!j.target.closest('input, textarea, select, [contenteditable="true"]')&&!(j.altKey||j.ctrlKey||j.metaKey)){if(j.key==="ArrowLeft")e.go(-1);else if(j.key==="ArrowRight")e.go(1);else if(j.key==="t"||j.key==="T")e.go(0);else return;j.preventDefault()}};return t.jsxs("div",{className:"cal",role:"region","aria-label":a,tabIndex:0,onKeyDown:b,children:[t.jsxs("div",{className:"cal-bar",children:[t.jsx(A,{size:"sm","aria-label":`Previous ${p}`,onClick:()=>e.go(-1),children:t.jsx(le,{name:"chevron-left",size:14})}),t.jsx(A,{size:"sm",onClick:()=>e.go(0),children:"Today"}),t.jsx(A,{size:"sm","aria-label":`Next ${p}`,onClick:()=>e.go(1),children:t.jsx(le,{name:"chevron-right",size:14})}),t.jsxs("h3",{className:"cal-title","aria-live":"polite",children:[TK(o,c,d,f),l!==void 0?t.jsx("span",{className:"cal-count",children:l===0?"No events":l===1?"1 event":`${l} events`}):null]}),e.views.length>1?t.jsx(ln,{label:"View",options:e.views.map(j=>({value:j,label:OK[j]})),value:o,onChange:e.setView}):null]}),o==="week"?t.jsx(WK,{dates:m,today:u,events:n,hours:s??[7,21],onPick:e.select,onEvent:i}):null,o==="month"?t.jsx(KK,{dates:m,month:c.slice(0,7),today:u,events:n,selected:g,onPick:e.select,onEvent:i}):null,o==="list"?t.jsx("div",{className:"cal-list",children:m.map(j=>t.jsx(yN,{date:j,today:u,events:n,empty:r,onEvent:i},j))}):null,v?t.jsx(yN,{date:v,today:u,events:n,empty:r,onEvent:i}):null]})}function yN({date:e,today:n,events:s,empty:r,onEvent:a}){const i=rw(s,e);return t.jsx(Ye,{flush:!0,title:CK(e,n),children:t.jsx(at,{children:i.length===0?t.jsx(Xe,{title:t.jsx("span",{className:"muted",children:r})}):i.map(({event:l,part:o})=>t.jsx(Xe,{lead:t.jsx("span",{className:"cal-dot","data-tone":l.tone,"aria-hidden":"true"}),title:l.title,sub:l.location||void 0,side:aw(l,o),...a?{onClick:()=>a(l)}:{}},l.id))})})}function WK({dates:e,today:n,events:s,hours:r,onPick:a,onEvent:i}){const l=h.useRef(null);h.useLayoutEffect(()=>{const d=l.current;d&&(d.scrollTop=d.scrollHeight/24*r[0])},[r[0]]);const o=VK(l),c=e.map(d=>({date:d,items:rw(s,d)})),u=d=>d===n?"true":void 0;return t.jsx(Ye,{flush:!0,children:t.jsxs("div",{className:"cal-week",role:"grid","aria-label":`Week of ${Vn(e[0])}`,style:{"--cal-span":r[1]-r[0],"--cal-scrollbar":`${o}px`},children:[t.jsxs("div",{className:"cal-row",role:"row",children:[t.jsx("span",{className:"cal-gutter","aria-hidden":"true"}),e.map(d=>t.jsxs("div",{className:"cal-day-head",role:"columnheader","data-today":u(d),"aria-label":Vn(d),children:[t.jsx("span",{className:"cal-wd",children:HT(d)}),t.jsx("span",{className:"cal-num",children:KT(d)})]},d))]}),t.jsxs("div",{className:"cal-row cal-allday",role:"row",children:[t.jsx("span",{className:"cal-gutter cal-gutter-label",children:"All day"}),c.map(({date:d,items:f})=>t.jsx("div",{className:"cal-allday-cell",role:"gridcell","data-today":u(d),children:f.filter(m=>m.part.allDay).map(({event:m,part:p})=>t.jsx("button",{type:"button",className:"cal-chip","data-tone":m.tone,"aria-label":iv(m,p,d),onClick:()=>i?i(m):a(d),children:m.title},m.id))},d))]}),t.jsx("div",{className:"cal-scroll",ref:l,children:t.jsxs("div",{className:"cal-row cal-times",role:"row",children:[t.jsx("div",{className:"cal-gutter cal-hours","aria-hidden":"true",children:Array.from({length:23},(d,f)=>f+1).map(d=>t.jsx("span",{className:"cal-hour-label",style:{top:`calc(var(--cal-hour) * ${d})`},children:sr(d*60)},d))}),c.map(({date:d,items:f})=>t.jsx("div",{className:"cal-col",role:"gridcell","aria-label":Vn(d),"data-today":u(d),children:PK(f.filter(m=>!m.part.allDay)).map(({event:m,part:p,lane:g,lanes:v})=>t.jsxs("button",{type:"button",className:"cal-event","data-tone":m.tone,"data-short":p.to-p.from<60?"true":void 0,"data-lane":g,"aria-label":iv(m,p,d),onClick:()=>i?i(m):a(d),style:{top:`calc(var(--cal-hour) * ${p.from/60})`,height:`calc(var(--cal-hour) * ${Math.max(p.to-p.from,VT)/60})`,left:`calc((100% - var(--space-1)) * ${g/v} + var(--space-0))`,width:`calc((100% - var(--space-1)) / ${v} - var(--space-0))`},children:[t.jsx("span",{className:"cal-event-time",children:aw(m,p)}),t.jsx("span",{className:"cal-event-title",children:m.title})]},m.id))},d))]})})]})})}const HK=3;function KK({dates:e,month:n,today:s,events:r,selected:a,onPick:i,onEvent:l}){const o=Array.from({length:6},(f,m)=>e.slice(m*7,m*7+7)),[c,u]=n.split("-").map(Number),d=eA(c,u);return t.jsx(Ye,{flush:!0,children:t.jsxs("div",{className:"cal-month",role:"grid","aria-label":d,children:[t.jsx("div",{className:"cal-row",role:"row",children:e.slice(0,7).map(f=>t.jsx("div",{className:"cal-wd-head",role:"columnheader",children:HT(f)},f))}),o.map(f=>t.jsx("div",{className:"cal-row",role:"row",children:f.map(m=>{const p=rw(r,m),g=p.slice(0,HK),v=p.length-g.length,b=p.length===0?"nothing":p.length===1?"1 event":`${p.length} events`;return t.jsxs("div",{className:"cal-cell",role:"gridcell","aria-selected":m===a,"data-date":m,"data-today":m===s?"true":void 0,"data-outside":m.slice(0,7)!==n?"true":void 0,"data-selected":m===a?"true":void 0,onClick:()=>i(m),children:[t.jsx("button",{type:"button",className:"cal-num","aria-label":`${Vn(m)}, ${b}`,"aria-pressed":m===a,children:KT(m)}),g.map(({event:j,part:x})=>t.jsx("button",{type:"button",className:"cal-chip","data-tone":j.tone,"data-timed":x.allDay?void 0:"true","aria-label":iv(j,x,m),...l?{onClick:y=>{y.stopPropagation(),i(m),l(j)}}:{},children:x.allDay?j.title:t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"cal-dot","data-tone":j.tone,"aria-hidden":"true"}),t.jsx("span",{className:"cal-chip-time",children:sr(x.from)})," ",j.title]})},j.id)),v>0?t.jsxs("button",{type:"button",className:"cal-more","aria-label":`${v} more on ${Vn(m)}`,children:["+",v]}):null]},m)})},f[0]))]})})}function VK(e){const[n,s]=h.useState(0);return h.useLayoutEffect(()=>{const r=e.current;if(!r)return;const a=()=>s(Math.max(0,r.offsetWidth-r.clientWidth));if(a(),typeof ResizeObserver>"u")return;const i=new ResizeObserver(a);return i.observe(r),()=>i.disconnect()},[e]),n}const GT={width:1200,height:200,top:28,right:12,bottom:24,left:36};function GK(e,n){if(n==="percent")return[0,50,100];let s=e.length>0?Math.min(...e):0,r=e.length>0?Math.max(...e):1;n!=="temp"&&(s=Math.min(0,s)),s===r&&(s-=1,r+=1);const a=10**Math.floor(Math.log10(Math.max(1,(r-s)/3))),i=c=>Math.ceil(r/c)-Math.floor(s/c);let l=[1,2,5,10].map(c=>c*a).find(c=>i(c)<=3)??a*10;i(l)<2&&(l>1?l/=2:r+=l);const o=[];for(let c=Math.floor(s/l)*l;c<=Math.ceil(r/l)*l+l/1e3;c+=l)o.push(Math.round(c*1e6)/1e6);return o}function vd(e,n){return n==="temp"?`${e}°`:n==="percent"?`${e}%`:String(e)}function qK(e){const n=GT,s=e.values.length,r=n.width-n.left-n.right,a=n.height-n.top-n.bottom,i=n.height-n.bottom,l=s>0?r/s:r,o=j=>vi(n.left+l*(j+.5)),c=e.values.filter(j=>j!==null&&Number.isFinite(j)),u=GK(c,e.unit),d=u[0],f=u[u.length-1],m=j=>vi(n.top+a-(j-d)/(f-d)*a),p=e.values.map((j,x)=>{const y=j!==null&&Number.isFinite(j);return{index:x,x:o(x),y:y?m(j):null,value:y?j:null}}),g=[],v=[];if(e.kind==="area"){let j=[];const x=()=>{if(j.length===0)return;const y=j.map((w,k)=>`${k===0?"M":"L"}${w.x},${w.y}`).join(" ");g.push(y),v.push(`${y} L${j[j.length-1].x},${i} L${j[0].x},${i} Z`),j=[]};for(const y of p)y.y===null?x():j.push(y);x()}const b=e.kind==="bars"?p.flatMap(j=>j.y===null?[]:[{index:j.index,x:vi(j.x-l*.28),y:j.y,width:vi(l*.56),height:vi(i-j.y)}]):[];return{ticks:u.map(j=>({value:j,y:m(j)})),lines:g,areas:v,bars:b,points:p,slot:l,floor:i}}function YK({title:e,note:n,xs:s,series:r,tiles:a,labelEvery:i=3}){var k;const[l,o]=h.useState(((k=r[0])==null?void 0:k.id)??""),[c,u]=h.useState(null),[d,f]=h.useState(null),m=h.useRef(null),p=s.length,g=c??d,v=r.find(N=>N.id===l)??r[0],b=qK(v),j=GT,x=N=>N%i===0||N===g,y=v.values.filter(N=>N!==null&&Number.isFinite(N));h.useEffect(()=>{const N=m.current,S=g===null?null:N==null?void 0:N.children[g];!N||!S||typeof N.scrollTo!="function"||(S.offsetLeft<N.scrollLeft?N.scrollTo({left:S.offsetLeft,behavior:"smooth"}):S.offsetLeft+S.offsetWidth>N.scrollLeft+N.clientWidth&&N.scrollTo({left:S.offsetLeft+S.offsetWidth-N.clientWidth,behavior:"smooth"}))},[g]);const w=N=>{var E,T,I;const S=N.key==="ArrowRight"?1:N.key==="ArrowLeft"?-1:0,C=N.key==="Home"?0:N.key==="End"?p-1:S===0?null:Math.max(0,Math.min(p-1,(d??-S)+S));C!==null&&(N.preventDefault(),f(C),(I=(T=(E=m.current)==null?void 0:E.children[C])==null?void 0:T.querySelector("button"))==null||I.focus())};return t.jsxs(Ye,{...e?{title:e}:{},children:[n?t.jsx("p",{className:"ui-panel-sub",children:n}):null,t.jsxs("div",{className:"pg-series",onMouseLeave:()=>u(null),children:[r.length>1?t.jsx("div",{className:"pg-series-tabs",role:"tablist","aria-label":"Series",children:r.map(N=>t.jsx("button",{type:"button",role:"tab",className:"ui-tab","aria-selected":N.id===v.id,onClick:()=>o(N.id),children:N.label},N.id))}):null,t.jsxs("figure",{className:"pg-series-chart","data-kind":v.kind,children:[t.jsxs("svg",{viewBox:`0 0 ${j.width} ${j.height}`,"aria-hidden":"true",focusable:"false","data-testid":"series-svg",children:[b.ticks.map(N=>t.jsxs("g",{children:[t.jsx("line",{className:"pg-series-grid",x1:j.left,x2:j.width-j.right,y1:N.y,y2:N.y}),t.jsx("text",{className:"pg-series-tick",x:j.left-8,y:N.y,textAnchor:"end",dominantBaseline:"middle",children:vd(N.value,v.unit)})]},N.value)),b.areas.map((N,S)=>t.jsx("path",{className:"pg-series-area",d:N},`a${S}`)),b.lines.map((N,S)=>t.jsx("path",{className:"pg-series-line",d:N},`l${S}`)),b.bars.map(N=>t.jsx("rect",{className:"pg-series-bar","data-index":N.index,"data-hover":N.index===g?"true":void 0,x:N.x,y:N.y,width:N.width,height:N.height},N.index)),g!==null&&b.points[g]?t.jsx("line",{className:"pg-series-guide","data-index":g,x1:b.points[g].x,x2:b.points[g].x,y1:j.top-4,y2:b.floor}):null,v.kind==="area"?b.points.map(N=>N.y!==null&&x(N.index)?t.jsx("circle",{className:"pg-series-dot","data-index":N.index,"data-hover":N.index===g?"true":void 0,cx:N.x,cy:N.y,r:N.index===g?5:3},N.index):null):null,b.points.map(N=>N.y!==null&&N.value!==null&&x(N.index)?t.jsx("text",{className:"pg-series-value","data-index":N.index,"data-hover":N.index===g?"true":void 0,x:N.x,y:N.y-(v.kind==="area"?10:6),textAnchor:"middle",children:vd(N.value,v.unit)},N.index):null),b.points.map(N=>N.index%i===0?t.jsx("text",{className:"pg-series-x",x:N.x,y:j.height-6,textAnchor:"middle",children:s[N.index]},N.index):null),b.points.map(N=>t.jsx("rect",{className:"pg-series-hit","data-index":N.index,x:vi(j.left+b.slot*N.index),y:0,width:vi(b.slot),height:j.height,onMouseEnter:()=>u(N.index),onClick:()=>f(N.index)},N.index))]}),t.jsx("figcaption",{className:"sr-only",children:y.length===0?`${v.label}: no values.`:`${v.label}, ${p} ${p===1?"point":"points"} from ${s[0]} to ${s[p-1]}: lowest ${vd(Math.min(...y),v.unit)}, highest ${vd(Math.max(...y),v.unit)}.`})]}),t.jsx("ul",{className:"wb-tiles","data-layout":"strip",ref:m,onKeyDown:w,children:a.map((N,S)=>t.jsx("li",{className:"wb-tile",children:t.jsx("button",{type:"button",className:"ui-card","data-index":S,"data-hover":S===g?"true":void 0,"aria-pressed":S===d,"aria-label":[N.label,N.value,...N.lines].filter(C=>C!=="").join(", "),onMouseEnter:()=>u(S),onClick:()=>f(S),children:t.jsxs("div",{className:"wb-tile-body","aria-hidden":"true",children:[t.jsx("span",{className:"wb-tile-icon","data-icon":N.icon??"dot",children:t.jsx(le,{name:bo(N.icon),size:22})}),N.value!==""?t.jsx("span",{className:"wb-tile-value tnum",children:N.value}):null,t.jsx("span",{className:"wb-tile-label",children:N.label}),N.lines.map((C,E)=>t.jsx("span",{className:"wb-tile-line",children:C},E))]})})},S))})]})]})}function vi(e){return Math.round(e*10)/10}const iw=h.createContext(null),Bh=h.createContext(!1);function mt(){const e=h.useContext(iw);if(!e)throw new Error("a plugin page component outside a plugin page");return e}function lv(e,n=new Set){if(Array.isArray(e))for(const s of e)lv(s,n);else if(e&&typeof e=="object"){const s=e.query;typeof s=="string"&&n.add(s);for(const r of Object.values(e))lv(r,n)}return n}function qT(e,n){if(n.size===0)return!1;for(const s of lv(e))if(n.has(s))return!0;return!1}function YT(){const[e,n]=h.useState(!1);return h.useEffect(()=>{if(!e)return;const s=()=>{document.visibilityState==="hidden"&&n(!1)};return document.addEventListener("visibilitychange",s),window.addEventListener("blur",s),()=>{document.removeEventListener("visibilitychange",s),window.removeEventListener("blur",s)}},[e]),[e,()=>n(s=>!s)]}function JT({revealed:e,onToggle:n}){return t.jsx(A,{size:"sm",variant:"ghost","aria-pressed":e,onClick:n,children:e?"Hide":"Show"})}function QT(){return t.jsx("p",{className:"muted",children:"Hidden until you show it."})}function XT({children:e}){const[n,s]=YT();return t.jsxs(ie,{gap:"sm",children:[t.jsx(te,{align:"end",children:t.jsx(JT,{revealed:n,onToggle:s})}),n?t.jsx(Bh.Provider,{value:!0,children:e}):t.jsx(QT,{})]})}function lw(e){return e===void 0||e==="neutral"?void 0:e}function ov(e){return lw(e)}function JK(e){const n=lw(e);return n==="accent"?void 0:n}function _t(e,n){if(!n)return!0;const s=Ce(e,n.path),r=n.in!==void 0?n.in.includes(s):s===n.equals;return n.not===!0?!r:r}function Wh(e){if(typeof e!="string"||e.length>2048)return null;try{const n=new URL(e);return n.protocol==="https:"&&n.hostname!==""&&n.username===""&&n.password===""?n.href:null}catch{return null}}function QK({plugin:e,images:n,row:s}){const a=(Array.isArray(n)?n.map(l=>({asset:Ke(s,l.asset),label:String(Ke(s,l.label)??"").trim()})):(()=>{const l=Ce(s,n.from);return(Array.isArray(l)?l:[]).map(o=>({asset:Ce(o,n.asset),label:String(Ce(o,n.label)??"").trim()}))})()).filter(l=>l.label!=="");if(a.length===0)return null;const i=a.length===1?a[0].label:`${a[0].label} and ${a.length-1} more`;return t.jsxs("span",{className:"pl-stack","data-testid":"row-images",children:[t.jsx("span",{className:"pl-stack-logos",children:a.slice(0,3).map((l,o)=>t.jsx(No,{src:Su(e,l.asset),label:l.label},o))}),t.jsx("span",{className:"pl-stack-words",children:i})]})}function Xl({href:e,children:n,className:s}){return t.jsxs("a",{href:e,target:"_blank",rel:"noopener noreferrer",className:s,onClick:r=>r.stopPropagation(),children:[n,t.jsx("span",{className:"wb-src-out","aria-hidden":"true",children:"↗"}),t.jsx("span",{className:"sr-only",children:" (opens in a new tab)"})]})}function va(e,n,s){if("href"in n)return Wh(Ke(s,n.href))??"";if("chat"in n){const i=Ke(s,n.chat);return i==null?"":Ze(String(i))}if("proposals"in n)return v3(e.plugin);const r=e.pages.find(i=>i.id===n.page);if((r==null?void 0:r.place)==="settings")return Lr(e.plugin,n.page);const a=n.item===void 0?null:Ke(s,n.item);return Or(e.plugin,n.page,a==null?null:String(a))}function as(e,n){return e.replace(/\{count\}/g,String(n.count??0)).replace(/\{([^{}|]+)\|([^{}|]+)\}/g,(s,r,a)=>(n.count??0)===1?r:a).replace(/\{([A-Za-z_][A-Za-z0-9_.]*)\}/g,(s,r)=>{const a=Ce(n.row,r);return a==null?"":String(a)})}function Hh(e,n){if(e===void 0)return;if(typeof e=="string")return e;const s=Ke(n,e);return s==="good"||s==="warning"||s==="critical"||s==="neutral"?s:void 0}function ZT(e,n,s){const r={};for(const[a,i]of Object.entries(e??{})){let l;"param"in i?l=s.params[i.param]:"route"in i?l=i.route==="plugin"?s.plugin:i.route==="page"?s.page:s.item:l=Ke(n,i),!(l==null||l==="")&&(r[a]=String(l))}return r}function Ys(e,n){var r,a,i;const s={};for(const[l,o]of Object.entries(e??{}))if("row"in o)s[l]=Ce(n.row,o.row);else if("choice"in o)s[l]=n.choice;else if("field"in o){if((r=n.omit)!=null&&r.has(o.field))continue;const c=(a=n.fields)==null?void 0:a[o.field],u=(i=n.shape)==null?void 0:i.find(d=>d.name===o.field);if(c===""&&(u==null?void 0:u.required)!==!0&&(u===void 0||u.type==="number"))continue;s[l]=c}else"selected"in o?s[l]=n.selected??[]:"param"in o?s[l]=n.scope.params[o.param]:s[l]=Ke(n.data,o);return s}function Rn(e,n,s,r){const a=mt(),i=e?{...ZT(e.params,n,a),...r}:{},l=JSON.stringify([(e==null?void 0:e.query)??null,i,a.version]),o=me(()=>e?R.pageQuery(a.plugin,e.query,i).then(c=>c.data):Promise.resolve(void 0),[l],s);return{data:o.data,error:o.error,loading:o.loading}}function ja(){const e=mt(),n=h.useId(),[s,r]=h.useState(null),[a,i]=h.useState(null),[l,o]=h.useState(null),[c,u]=h.useState(null),[d,f]=h.useState(null),m=(j,x)=>{if(j.done===void 0)return null;if(typeof j.done=="string")return j.done;const y=Ke(x,j.done);return y==null?null:String(y)},p=(j,x,y)=>{const w=j??"refresh";if(typeof w=="object"){const k="href"in w.route?"":va(e,w.route,x);k===""?e.refresh():e.navigate(k);return}w==="close"&&(y==null||y()),e.refresh()},g=async(j,x,y)=>{r(j.tool),i(null),o(null);try{const w=await R.pageAct(e.plugin,{tool:j.tool,args:x});if(w.approvalId)return u(w.approvalId),f({then:j.then,ref:j,...y?{onDone:y}:{}}),!1;u(null),f(null);const k=_T(w.result);return o(m(j,w.result)??(k?zT(w.result):null)),k&&await BT(k,n),p(j.then,w.result,y),!0}catch(w){return i(w instanceof Error?w.message:String(w)),e.refresh(),!1}finally{r(null)}},v=j=>{if(!j){e.refresh();return}const x=d;if(u(null),f(null),x&&j.decision==="approve"&&j.state==="succeeded"){o(m(x.ref,j.result)),p(x.then,void 0,x.onDone);return}e.refresh()},b=()=>{i(null),o(null)};return{running:s,busy:s!==null,error:a,done:l,approvalId:c,waiting:(d==null?void 0:d.ref.pending)??null,settle:v,run:g,reset:b}}function Gi({action:e,args:n,disabled:s,running:r,count:a,row:i,onRun:l}){const[o,c]=h.useState(!1),u=f=>as(f,{...a===void 0?{}:{count:a},row:i}),d=u(e.label);return o&&e.confirm?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"ui-toolbar-note",children:u(e.confirm)}),t.jsx(A,{variant:"ghost",onClick:()=>c(!1),children:"Cancel"}),t.jsxs(A,{variant:e.tone==="danger"?"danger":"accent",disabled:s,onClick:()=>{c(!1),l(e,n)},children:["Yes, ",d.toLowerCase()]})]}):t.jsx(A,{variant:e.tone==="danger"?"danger":e.tone==="accent"?"accent":void 0,disabled:s,onClick:()=>e.confirm?c(!0):l(e,n),children:r&&e.busy?e.busy:d})}function Kh({id:e,onDecided:n}){const s=mt(),r=me(()=>R.approval(e),[e,s.version]),{busy:a,note:i,failure:l,decide:o}=ew(c=>{n?n(c):s.refresh()});return r.error?t.jsx(ne,{message:r.error}):r.data?t.jsxs(ie,{children:[t.jsx(tw,{action:r.data,timezone:s.timezone,busy:a===e,onDecide:(c,u,d,f)=>{o(c,u,d,f)}}),i?t.jsx(G,{tone:"good",role:"status",children:i}):null,t.jsx(ne,{message:l})]}):t.jsx(ve,{children:"Loading the approval…"})}function zr({act:e}){return e.error?t.jsx(ne,{message:e.error}):e.approvalId?e.waiting?t.jsxs(ie,{children:[t.jsx(G,{role:"status",children:e.waiting}),t.jsx(Kh,{id:e.approvalId,onDecided:e.settle})]}):t.jsx(Kh,{id:e.approvalId,onDecided:e.settle}):e.done?t.jsx(G,{tone:"good",role:"status",children:e.done}):null}function nu(e,n){const s={};for(const r of e){const a=r.from===void 0?void 0:Ce(n,r.from);s[r.name]=r.multiple?Array.isArray(a)?a.map(String):[]:a!==void 0?a:r.type==="checkbox"?!1:""}return s}function eR(e,n,s){const r=mt(),a=e.optionsFrom,i=a?{...ZT(a.query.params,s,r),...Object.fromEntries((a.dependsOn??[]).map(c=>[c,String(n[c]??"")]).filter(([,c])=>c!==""))}:{},l=JSON.stringify([(a==null?void 0:a.query.query)??null,i,r.version]),o=me(()=>a?R.pageQuery(r.plugin,a.query.query,i).then(c=>c.data):Promise.resolve(void 0),[l]);return a?{options:dr(o.data,a.rows).map(c=>({value:String(Ce(c,a.value)??""),label:String(Ce(c,a.label)??"")})),loading:o.loading}:{options:e.options??[],loading:!1}}function XK({field:e,fields:n,value:s,values:r,data:a,disabled:i,compact:l,onChange:o}){const c=eR(e,r,a),u={id:`f-${e.name}`,required:e.required,name:e.name,disabled:i,...l&&e.hint?{title:e.hint}:{}},d=l?void 0:e.hint;if(e.type==="select"&&e.multiple){const m=Array.isArray(s)?s.map(String):[],g=e.max!==void 0&&m.length>=e.max?`Up to ${e.max}; remove one to add another.`:void 0;return t.jsx(re,{label:e.label,hint:l?void 0:[d,g].filter(Boolean).join(" ")||void 0,group:!0,children:t.jsx(A6,{id:u.id,label:e.label,options:c.options,value:m,max:e.max,disabled:i,onChange:o})})}if(e.type==="select"){const m=t.jsxs("select",{...u,value:String(s??""),onChange:p=>o(p.target.value),children:[t.jsx("option",{value:"",children:c.loading?"Loading…":"—"}),c.options.map(p=>t.jsx("option",{value:p.value,children:p.label},p.value))]});return e.action&&!l?t.jsx(ZK,{field:e,action:e.action,fields:n??[e],values:r,data:a,disabled:i,hint:d,children:m}):t.jsx(re,{label:e.label,hint:d,children:m})}if(e.type==="textarea")return t.jsx(re,{label:e.label,hint:d,wide:!0,children:t.jsx("textarea",{...u,value:String(s??""),onChange:m=>o(m.target.value),rows:6})});if(e.type==="checkbox")return t.jsx(re,{label:e.label,hint:d,inline:!0,wide:!l,children:t.jsx("input",{...u,type:"checkbox",checked:s===!0,onChange:m=>o(m.target.checked)})});const f=e.type==="secret"?"password":e.type==="number"?"number":e.type;return t.jsx(re,{label:e.label,hint:d,children:t.jsx("input",{...u,type:f,value:s==null?"":String(s),min:e.min,max:e.max,step:e.step,...l&&e.hint?{placeholder:e.hint}:{},onChange:m=>o(e.type==="number"?e9(m.target.value):m.target.value)})})}function ZK({field:e,action:n,fields:s,values:r,data:a,disabled:i,hint:l,children:o}){const c=mt(),u=h.useId(),d=NK()===u,[f,m]=h.useState(!1),[p,g]=h.useState(null),[v,b]=h.useState(null),[j,x]=h.useState(null);h.useEffect(()=>()=>gN(u),[u]);const y=ow(s,r,a),w=n.args!==void 0?Ys(n.args,{data:a,fields:r,shape:s,omit:y,scope:c}):Object.fromEntries(Object.entries(r).filter(([S,C])=>!y.has(S)&&C!=="")),k=async()=>{if(d){gN(u);return}m(!0),g(null),b(null),x(null);try{const S=await R.pageAct(c.plugin,{tool:n.tool,args:w});if(S.approvalId){x(S.approvalId);return}g(zT(S.result));const C=_T(S.result);C&&await BT(C,u)}catch(S){b(S instanceof Error?S.message:String(S))}finally{m(!1)}},N=d?"Stop":n.label;return t.jsx(re,{label:e.label,hint:l,action:t.jsx(A,{"data-shape":"icon","aria-label":f?`${n.label}: working`:N,title:N,"aria-busy":f||void 0,"aria-pressed":n.icon==="play"?d:void 0,disabled:i===!0||f,onClick:()=>void k(),children:f?t.jsx("span",{className:"ui-spinner","aria-hidden":"true"}):t.jsx(le,{name:d?"stop":n.icon??"arrow"})}),after:v?t.jsx(ne,{message:v}):j?t.jsx(Kh,{id:j,onDecided:()=>x(null)}):p?t.jsx("span",{className:"ui-field-hint",role:"status",children:p}):null,children:o})}function e9(e){if(e.trim()==="")return"";const n=Number(e);return Number.isFinite(n)?n:e}function tR(e,n){return{...typeof n=="object"&&n!==null?n:{},...e}}function ow(e,n,s){const r=tR(n,s);return new Set(e.filter(a=>a.when!==void 0&&!_t(r,a.when)||a.disabledWhen!==void 0&&_t(r,a.disabledWhen)).map(a=>a.name))}function im({fields:e,values:n,data:s,disabled:r,compact:a,columns:i,onChange:l}){const o=tR(n,s);return t.jsx(Ns,{dense:a,columns:i,children:e.filter(c=>c.when===void 0||_t(o,c.when)).map(c=>t.jsx(XK,{field:c,fields:e,compact:a,value:n[c.name],values:n,data:s,disabled:r===!0||c.disabledWhen!==void 0&&_t(o,c.disabledWhen),onChange:u=>l(c.name,u)},c.name))})}const su=h.createContext(!1),nR=h.createContext(!1),sR=h.createContext(!1);function Is({title:e,note:n,actions:s,children:r}){const a=h.useContext(su);return t.jsx(ue,{title:e,aside:n,actions:s,panel:a,children:t.jsx(su.Provider,{value:!1,children:t.jsx(nR.Provider,{value:a,children:r})})})}function Ur({component:e,data:n,choose:s,chosen:r}){const a=mt(),i=h.useContext(Bh);if(!_t(n,e.when)||e.where!==void 0&&e.where!==(n9()?"local":"remote"))return null;if(e.kind!=="section"&&!i&&qT(e,a.sensitive))return t.jsx(XT,{children:t.jsx(Ur,{component:e,data:n,...s?{choose:s}:{},...r===void 0?{}:{chosen:r}})});switch(e.kind){case"section":return t.jsx(t9,{component:e,data:n});case"notice":return t.jsx(s9,{component:e,data:n});case"link":return t.jsx(r9,{component:e,data:n});case"progress":return t.jsx(i9,{component:e,data:n});case"chart":return t.jsx(l9,{component:e,data:n});case"stats":return t.jsx(o9,{component:e,data:n});case"list":return t.jsx(u9,{component:e,data:n,...s?{onChoose:s}:{},...r===void 0?{}:{chosen:r}});case"table":return t.jsx(m9,{component:e,data:n});case"detail":return t.jsx(v9,{component:e,data:n});case"form":return t.jsx(j9,{component:e,data:n});case"search":return t.jsx(b9,{component:e,data:n});case"list-detail":return t.jsx(k9,{component:e,data:n});case"repeat":return t.jsx(N9,{component:e,data:n});case"calendar":return t.jsx(S9,{component:e,data:n});case"tiles":return t.jsx(E9,{component:e,data:n});case"series-panel":return t.jsx(A9,{component:e,data:n});case"hero":return t.jsx($9,{component:e,data:n});case"tabs":return t.jsx(T9,{component:e,data:n});case"expand":return t.jsx(R9,{component:e,data:n});case"button":return t.jsx(uR,{component:e,data:n});case"menu":return t.jsx(rR,{component:e,data:n});case"approval":return t.jsx(B9,{component:e,data:n});case"artifact":return t.jsx(W9,{component:e,data:n});case"editor":return t.jsx(H9,{component:e,data:n});case"agent-offer":return t.jsx(I9,{component:e});case"stories":return t.jsx(D9,{component:e,data:n});default:return t.jsx(G,{children:"This page uses a part this dashboard does not know yet. Reload buddi to see it."})}}function t9({component:e,data:n}){const s=mt(),r=h.useContext(Bh),[a,i]=YT(),l=!r&&qT(e.body,s.sensitive),o=l&&!a,c=h.useContext(su);let u=e.body.length;const d=v=>{var b;return v.kind==="button"||v.kind==="link"||v.kind==="menu"||v.kind==="form"&&((b=v.drawer)==null?void 0:b.button)!==void 0&&!v.title};for(;c&&u>0&&d(e.body[u-1]);)u-=1;const f=e.body.slice(0,u),m=[...e.actions??[],...e.body.slice(u)],[p,g]=h.useState(null);return t.jsx(cv.Provider,{value:g,children:t.jsx(Is,{title:e.title,note:e.note,actions:m.length>0||l?t.jsxs(t.Fragment,{children:[m.map((v,b)=>t.jsx(Ur,{component:v,data:n},b)),l?t.jsx(JT,{revealed:a,onToggle:i}):null]}):void 0,children:t.jsxs(ie,{gap:"lg",divided:c,children:[p,o?t.jsx(QT,{}):t.jsx(Bh.Provider,{value:r||l,children:t.jsx(cv.Provider,{value:null,children:f.map((v,b)=>t.jsx(Ur,{component:v,data:n},b))})})]})})})}const cv=h.createContext(null);function n9(){const e=typeof location>"u"?"":location.hostname;return e==="127.0.0.1"||e==="localhost"||e==="::1"||e==="[::1]"}function rR({component:e,data:n}){var c;const s=mt(),r=ja(),a=h.useContext(cv),i=e.items.filter(u=>_t(n,u.when)).map(u=>({label:u.label,...u.hint?{hint:u.hint}:{},onSelect:()=>{u.open!==void 0?s.setParams({open:u.open}):u.action&&r.run(u.action,Ys(u.action.args,{data:n,row:n,scope:s}))}})),l=(c=e.items.find(u=>{var d;return((d=u.action)==null?void 0:d.tool)===r.running}))==null?void 0:c.action,o=r.error||r.done||r.approvalId?t.jsx(zr,{act:r}):null;return h.useEffect(()=>{a&&a(o)},[r.error,r.done,r.approvalId,r.waiting]),h.useEffect(()=>()=>a==null?void 0:a(null),[a]),t.jsxs(t.Fragment,{children:[t.jsx(Rs,{label:e.label,items:i,stacked:e.items.some(u=>u.hint!==void 0),trigger:t.jsxs("button",{type:"button",className:"ui-btn pl-menu-btn","data-variant":e.tone==="accent"?"accent":void 0,disabled:r.busy,children:[(l==null?void 0:l.busy)??e.label,t.jsx(le,{name:"chevron-down",size:12})]})}),a?null:o]})}function s9({component:e,data:n}){const s=mt(),r=ja(),a=typeof e.text=="string"?e.text:String(Ke(n,e.text)??""),i=e.link&&_t(n,e.link.when)?e.link:void 0,l=i?va(s,i.to,n):"",o=i?typeof i.label=="string"?i.label:String(Ke(n,i.label)??""):"",c=i&&l!==""&&o!==""?"href"in i.to?t.jsx(Xl,{href:l,children:o}):t.jsx("a",{href:l,onClick:d=>{d.preventDefault(),s.navigate(l)},children:o}):null;if(e.look==="quiet")return a===""&&!c?null:t.jsxs("p",{className:"pl-quiet","data-tone":e.tone,children:[e.icon?t.jsx(le,{name:e.icon,size:14}):null,t.jsxs("span",{children:[a,c?t.jsxs(t.Fragment,{children:[a?" · ":null,c]}):null]})]});const u=e.action;return t.jsxs(t.Fragment,{children:[t.jsxs(G,{tone:lw(e.tone),title:e.title,action:u?t.jsx(Gi,{action:u,args:Ys(u.args,{data:n,scope:s}),disabled:r.busy,running:r.running===u.tool,onRun:(d,f)=>void r.run(d,f)}):void 0,children:[a,c?t.jsxs(t.Fragment,{children:[" ",c]}):null]}),t.jsx(dR,{act:r})]})}function r9({component:e,data:n}){const s=mt(),r=va(s,e.to,n);return r===""?null:"href"in e.to?t.jsx(te,{children:t.jsxs(ht,{href:r,target:"_blank",rel:"noopener noreferrer",variant:e.tone==="accent"?"accent":void 0,children:[e.label,t.jsx("span",{className:"wb-src-out","aria-hidden":"true",children:"↗"}),t.jsx("span",{className:"sr-only",children:" (opens in a new tab)"})]})}):t.jsx(te,{children:t.jsx(ht,{href:r,variant:e.tone==="accent"?"accent":void 0,onClick:a=>{a.preventDefault(),s.navigate(r)},children:e.label})})}function wN(e){return Math.round(e/1e6)}function a9(e,n){const s=ys(Ke(n,e.value))??0,r=e.total?ys(Ke(n,e.total)):null,a=e.total?r&&r>0?s/r:0:s,i=Math.max(0,Math.min(1,a)),l=Math.floor(i*100),o=a>=1,c=e.total&&r&&r>0?`${wN(s)} of ${Math.max(1,wN(r))} MB · ${l}%`:`${l}%`;return{percent:l,full:o,line:c}}function i9({component:e,data:n}){const s=c=>c===void 0?"":typeof c=="string"?c:String(Ke(n,c)??""),r=s(e.label),a=s(e.done),{percent:i,full:l,line:o}=a9(e,n);return t.jsxs(ie,{gap:"sm",children:[r?t.jsx("span",{children:r}):null,l&&a?t.jsx("span",{role:"status",children:a}):t.jsxs(t.Fragment,{children:[t.jsx(Py,{value:i,label:r||"Progress"}),t.jsx("span",{role:"status",children:o})]})]})}function l9({component:e,data:n}){const s=Rn(e.query,n),r=e.rows===void 0?Array.isArray(s.data)?s.data:[]:dr(s.data,e.rows),a=r.map(d=>String(Ce(d,e.x)??"")),i=d=>r.map(f=>ys(Ce(f,d))??null),l=e.series!==void 0,o=e.y===void 0?[]:Array.isArray(e.y)?e.y:[e.y],c=l?e.series.map(d=>({label:d.label,values:i(d.y),type:d.type,...d.unit?{unit:d.unit}:{}})):o.map(d=>({label:o.length===1?e.label??d:d,values:i(d)})),u=e.target?ys(Ke(s.data,e.target))??null:null;return t.jsxs(Is,{title:e.title,note:e.note,children:[t.jsx(ne,{message:s.error}),r.length===0?s.loading||s.data===void 0?t.jsx(ve,{children:"Loading…"}):t.jsx(qi,{text:e.empty??"Nothing recorded yet."}):t.jsx(w6,{xs:a,series:c,type:l?"mixed":e.type??"line",target:u,...e.label?{label:e.label}:{},formatX:d=>/^\d{4}-\d{2}-\d{2}/.test(d)?Sx(d):d,formatY:d=>pn(d,"number",null)})]})}function o9({component:e,data:n}){const s=Rn(e.query,n);return t.jsxs(Is,{title:e.title,note:e.note,children:[t.jsx(ne,{message:s.error}),s.data===void 0?t.jsx(ve,{children:e.empty??"Loading…"}):t.jsx(tm,{children:e.items.map((r,a)=>t.jsx(Er,{label:r.label,value:pn(Ke(s.data,r.value),r.unit??"text",null),tone:JK(r.tone)},a))})]})}function aR(e,n,s,r){const a=(n.meta??[]).map(k=>String(Ke(s,k)??"")).filter(k=>k!==""),i=String(Ke(s,n.title)??""),l=n.to&&!r?va(e,n.to,s):null,o=l===""?null:l,c=o!==null&&n.to!==void 0&&"href"in n.to,u=n.images?t.jsx(QK,{plugin:e.plugin,images:n.images,row:s}):null,f=[...n.pill?[n.pill]:[],...n.pills??[]].map((k,N)=>{const S=Ke(s,k.value);if(S==null||S==="")return null;const C=c9(k,S,s);return t.jsx(Ee,{tone:ov(C.tone),children:C.text},N)}),m=o&&c?t.jsx(Xl,{href:o,children:i}):o?t.jsx("a",{href:o,onClick:k=>{k.preventDefault(),e.navigate(o)},children:i}):i,p=n.tag?Ke(s,n.tag):void 0,g=p==null||p===""?null:t.jsx("span",{className:"pl-row-tag",children:String(p)}),v=n.status?Ke(s,n.status.text):void 0,b=n.status?Hh(n.status.tone,s):void 0,j=v==null||v===""?null:t.jsx("span",{className:"pl-row-status","data-tone":b,children:String(v)}),x=n.sub?String(Ke(s,n.sub)??""):"",y=n.swatch?Ce(s,n.swatch):void 0,w=n.logo?t.jsx(No,{className:"pl-logo-lg",src:Su(e.plugin,Ke(s,n.logo.asset)),label:String(Ke(s,n.logo.label)??"")}):n.swatch?typeof y=="string"&&uw.test(y)?t.jsx("span",{className:"pl-swatch","aria-hidden":"true",style:{"--swatch":y}}):t.jsx("span",{className:"pl-swatch","data-none":"true","aria-hidden":"true"}):null;return{text:i,href:o,outside:c,lead:w,pills:t.jsx(t.Fragment,{children:f}),meta:a.join(" · "),title:u?t.jsxs(t.Fragment,{children:[u,t.jsx("span",{className:"pl-row-title",children:m}),g]}):g?t.jsxs(t.Fragment,{children:[m,g]}):m,sub:j?t.jsxs(t.Fragment,{children:[x?t.jsx("span",{className:"pl-row-line",children:x}):null,j]}):n.sub?x:null,side:t.jsxs(t.Fragment,{children:[f,a.length>0?t.jsxs("span",{className:"muted",children:[" ",a.join(" · ")]}):null]})}}function c9(e,n,s){const r=String(n),a=e.labels??{},i=e.tones??{};return{text:Object.prototype.hasOwnProperty.call(a,r)?a[r]:r,tone:Object.prototype.hasOwnProperty.call(i,r)?i[r]:Hh(e.tone,s)}}function dr(e,n){const s=Ce(e,n);return Array.isArray(s)?s:[]}function iR(e,n,s){const r=[],a=new Set;return e.forEach((i,l)=>{const o=n===void 0?void 0:Ce(i,n),c=o==null||o===""?null:String(o);if(c===null){console.warn(`buddi: plugin ${s.plugin}, page ${s.page}, ${s.component}: row ${l} has no value at "${n??"(no key)"}" — not drawn`);return}if(a.has(c)){console.warn(`buddi: plugin ${s.plugin}, page ${s.page}, ${s.component}: two rows share the key "${c}" — the second is not drawn`);return}a.add(c),r.push({key:c,row:i})}),r}function u9({component:e,data:n,onChoose:s,chosen:r}){var N;const a=mt(),i=h.useContext(sR),l=Rn(e.query,n),o=ja(),[c,u]=h.useState([]),d=i&&!e.select&&(e.actions??[]).length===0&&(e.bulk??[]).length===0,f=dr(l.data,e.rows),m=e.collapsed?dr(l.data,e.collapsed.rows):[],p=lR(e.actions,f,o),g={plugin:a.plugin,page:a.page,component:`list "${e.title??e.rows}"`},v=iR([...f,...m],e.key??((N=e.select)==null?void 0:N.key),g),b=new Map(v.map(S=>[S.row,S.key])),j=new Set(v.map(S=>S.row)),x=new Set(v.filter(({row:S})=>{var C;return((C=e.select)==null?void 0:C.disabledWhen)===void 0||!_t(S,e.select.disabledWhen)}).map(({key:S})=>S)),y=c.filter(S=>x.has(S)),w=h.useMemo(()=>{const S=f.filter(T=>j.has(T));if(!e.groupBy)return[{label:null,aside:null,asideTone:void 0,rows:S}];const C=new Map;for(const T of S){const I=String(Ce(T,e.groupBy.key)??"");C.set(I,[...C.get(I)??[],T])}const E=(T,I)=>{var $,L,O;const F=(L=($=e.groupBy)==null?void 0:$.labels)==null?void 0:L[T];if(F!==void 0)return F;const D=(O=e.groupBy)!=null&&O.label?Ce(I,e.groupBy.label):void 0;return D==null||D===""?T:String(D)};return[...C].map(([T,I])=>{var $,L;const F=($=e.groupBy)!=null&&$.aside?Ce(I[0],e.groupBy.aside):void 0,D=(L=e.groupBy)!=null&&L.asideTone?Ce(I[0],e.groupBy.asideTone):void 0;return{label:E(T,I[0]),aside:F==null||F===""?null:String(F),asideTone:D==="warning"||D==="critical"?D:void 0,rows:I}})},[f,e.groupBy,v.length]),k=S=>S.map(C=>{var L;const E=aR(a,e.item,C,s),T=b.get(C);if(d&&(s||E.href&&!E.outside))return t.jsx(I$,{href:E.href??"#",current:r===T,onClick:()=>s?s(T):a.navigate(E.href),title:E.text,meta:E.meta,sub:E.sub,side:E.pills},T);const I=((L=e.select)==null?void 0:L.disabledWhen)!==void 0&&_t(C,e.select.disabledWhen),F=(e.actions??[]).filter(O=>_t(C,O.when)),D=F.filter(O=>O.menu!==!0),$=F.filter(O=>O.menu===!0);return t.jsx(Xe,{lead:E.lead?E.lead:e.select?t.jsx("input",{type:"checkbox","aria-label":`Select ${E.text}`,disabled:I,checked:c.includes(T),onClick:O=>O.stopPropagation(),onChange:O=>u(M=>O.target.checked?[...M,T]:M.filter(P=>P!==T))}):void 0,title:s?t.jsx("a",{href:"#","aria-current":r===T?"true":void 0,onClick:O=>{O.preventDefault(),s(T)},children:E.text}):E.title,sub:E.sub,side:t.jsxs(t.Fragment,{children:[E.side,e.item.choice?t.jsx(h9,{choice:e.item.choice,row:C,data:l.data,act:o}):null,D.map((O,M)=>t.jsx(cw,{action:O,row:C,data:l.data,act:o,onForm:p.show},M)),$.length>0?t.jsx(oR,{actions:$,row:C,title:E.text,data:l.data,act:o,onForm:p.show}):null]})},T)});return t.jsxs(Is,{title:e.title,note:e.note,children:[t.jsx(ne,{message:l.error}),p.open?null:t.jsx(zr,{act:o}),p.open?t.jsx(cR,{open:p.open,data:l.data,act:o,onClose:p.close,onDone:p.finish}):null,w.every(S=>S.rows.length===0)?l.loading?t.jsx(ve,{children:"Loading…"}):t.jsx(qi,{text:e.empty??"Nothing here yet."}):t.jsxs(at,{children:[e.select?t.jsx(Xe,{lead:t.jsx("input",{type:"checkbox","aria-label":"Select every row",checked:x.size>0&&y.length===x.size,disabled:x.size===0,onChange:S=>u(S.target.checked?[...x]:[])}),title:t.jsxs("span",{className:"muted",children:[x.size," to choose from"]})}):null,w.map((S,C)=>{var E,T;return(E=e.groupBy)!=null&&E.actions||(T=e.groupBy)!=null&&T.asideTone?t.jsxs("section",{className:"pl-group","aria-label":S.label??void 0,children:[t.jsxs("header",{className:"pl-group-head",children:[t.jsx("span",{className:"pl-group-title",children:S.label}),S.aside?t.jsx("span",{className:"pl-group-aside","data-tone":S.asideTone,children:S.aside}):null,t.jsx(d9,{actions:e.groupBy.actions??[],row:S.rows[0],title:S.label??"",data:l.data,act:o,onForm:p.show})]}),k(S.rows)]},C):t.jsxs("div",{children:[S.label?t.jsxs("div",{className:"ui-list-group","data-aside":S.aside?"true":void 0,children:[S.label,S.aside?t.jsx("span",{className:"pl-group-aside",children:S.aside}):null]}):null,k(S.rows)]},C)})]}),e.collapsed&&m.some(S=>j.has(S))?t.jsx(Ot,{summary:`${e.collapsed.label} (${m.filter(S=>j.has(S)).length})`,children:t.jsx(at,{children:k(m.filter(S=>j.has(S)))})}):null,e.bulk&&e.bulk.length>0?t.jsxs(te,{align:"end",children:[t.jsxs("span",{className:"ui-toolbar-note",children:[y.length," selected"]}),e.bulk.map((S,C)=>{const E=y.length>0||S.all!==!0?y:[...x];return t.jsx(Gi,{action:S,args:Ys(S.args,{data:l.data,selected:E,scope:a}),count:E.length,disabled:o.busy||E.length===0,running:o.running===S.tool,onRun:(T,I)=>{u([]),o.run(T,I)}},C)})]}):null]})}function d9({actions:e,row:n,title:s,data:r,act:a,onForm:i}){const l=e.filter(u=>_t(n,u.when));if(l.length===0)return null;const o=l.filter(u=>u.menu!==!0),c=l.filter(u=>u.menu===!0);return t.jsxs("span",{className:"pl-group-act",children:[o.map((u,d)=>t.jsx(cw,{action:u,row:n,data:r,act:a,onForm:i},d)),c.length>0?t.jsx(oR,{actions:c,row:n,title:s,data:r,act:a,onForm:i}):null]})}function h9({choice:e,row:n,data:s,act:r}){const a=mt(),i=String(Ce(n,e.value)??""),[l,o]=h.useState(null);h.useEffect(()=>o(null),[i]);const c=l??i,u=e.options.filter(d=>_t(n,d.when));return t.jsx("span",{className:"ui-segment pl-choice",role:"radiogroup","aria-label":as(e.label,{row:n}),"aria-busy":l!==null&&r.running===e.tool?"true":void 0,children:u.map(d=>{const f=d.disabledWhen!==void 0&&_t(n,d.disabledWhen),m=f&&d.hint?as(d.hint,{row:n}):void 0;return t.jsx("button",{type:"button",role:"radio",className:"ui-tab","aria-checked":c===d.value,disabled:f||r.busy,title:m,"aria-description":m,onClick:()=>{if(d.value===c)return;o(d.value);const p=Ys(e.args,{data:s,row:n,choice:d.value,scope:a});r.run(e,p).then(g=>{g||o(null)})},children:d.label},d.value)})})}function f9(e,n,s){return Object.entries(e).every(([r,a])=>{const i=typeof a=="string"?a:Ce(s,a.row);return i!=null&&n[r]===String(i)})}function lR(e,n,s){const r=mt(),[a,i]=h.useState(null);return h.useEffect(()=>{var l;if(!(a!==null||n.length===0))for(const o of e??[]){const c=(l=o.form)==null?void 0:l.openWhen;if(!c)continue;const u=n.find(d=>_t(d,o.when)&&f9(c,r.params,d));if(u!==void 0){i({action:o,row:u}),r.setParams(Object.fromEntries(Object.keys(c).map(d=>[d,null])));return}}},[n.length,JSON.stringify(r.params)]),{open:a,show:(l,o)=>{s.reset(),i({action:l,row:o})},close:()=>{s.reset(),i(null)},finish:()=>i(null)}}function cw({action:e,row:n,data:s,act:r,onForm:a}){const i=mt();return e.form?t.jsx(A,{disabled:r.busy,onClick:()=>a(e,n),children:as(e.label,{row:n})}):t.jsx(Gi,{action:e,args:Ys(e.args,{data:s,row:n,scope:i}),disabled:r.busy,running:r.running===e.tool,row:n,onRun:(l,o)=>void r.run(l,o)})}function oR({actions:e,row:n,title:s,data:r,act:a,onForm:i}){const l=mt(),[o,c]=h.useState(null),u=m=>void a.run(m,Ys(m.args,{data:r,row:n,scope:l})),d=[];let f;return e.forEach((m,p)=>{m.group!==f?(p>0&&d.push("separator"),m.group&&d.push({heading:m.group}),f=m.group):m.tone==="danger"&&p>0&&d.push("separator"),d.push({label:as(m.label,{row:n}),...m.hint?{hint:as(m.hint,{row:n})}:{},...m.tone==="danger"?{tone:"critical"}:{},onSelect:()=>m.form?i(m,n):m.confirm?c(m):u(m)})}),t.jsxs(t.Fragment,{children:[t.jsx(Rs,{label:`More for ${s}`,items:d,sheet:{title:s}}),o?t.jsx(zt,{title:as(o.confirm??o.label,{row:n}),onClose:()=>c(null),foot:t.jsxs(t.Fragment,{children:[t.jsx(A,{variant:"ghost",onClick:()=>c(null),children:"Cancel"}),t.jsx(A,{variant:o.tone==="danger"?"danger":"accent",onClick:()=>{const m=o;c(null),u(m)},children:as(o.label,{row:n})})]})}):null]})}function cR({open:e,data:n,act:s,onClose:r,onDone:a}){const i=mt(),{action:l,row:o}=e,c=l.form,[u,d]=h.useState(()=>nu(c.fields,o)),f=c.fields.some(v=>v.required&&(u[v.name]===""||u[v.name]===void 0)),{confirm:m,...p}=l,g={...p,label:c.submit};return t.jsx(Ge,{title:as(c.title,{row:o}),onClose:r,foot:t.jsxs(te,{align:"end",children:[t.jsx(A,{variant:"ghost",onClick:r,children:"Cancel"}),t.jsx(Gi,{action:g,args:Ys(l.args,{data:n,row:o,fields:u,shape:c.fields,scope:i}),disabled:s.busy||f,running:s.running===l.tool,row:o,onRun:(v,b)=>void s.run(v,b,a)})]}),children:t.jsxs(ie,{children:[t.jsx(im,{fields:c.fields,values:u,data:o,onChange:(v,b)=>d(j=>({...j,[v]:b}))}),t.jsx(ne,{message:s.error})]})})}function m9({component:e,data:n}){const s=Rn(e.query,n),r=ja(),a=dr(s.data,e.rows),i=lR(e.actions,a,r);return t.jsxs(Is,{title:e.title,note:e.note,children:[t.jsx(ne,{message:s.error}),i.open?null:t.jsx(zr,{act:r}),i.open?t.jsx(cR,{open:i.open,data:s.data,act:r,onClose:i.close,onDone:i.finish}):null,a.length===0?s.loading?t.jsx(ve,{children:"Loading…"}):t.jsx(qi,{text:e.empty??"Nothing here yet."}):t.jsxs(Kr,{children:[t.jsx("thead",{children:t.jsxs("tr",{children:[e.columns.map(l=>t.jsx("th",{children:l.label},l.key)),e.actions&&e.actions.length>0?t.jsx("th",{"aria-label":"Actions"}):null]})}),t.jsx("tbody",{children:a.map((l,o)=>t.jsxs("tr",{children:[e.columns.map(c=>{const u=c.pill?null:pn(Ce(l,c.key),c.type??"text",null);return t.jsxs("td",{"data-fit":c.fit,title:g9(c,l,u),children:[c.pill?null:t.jsx(p9,{column:c,row:l}),c.pill?t.jsx(x9,{column:c,row:l}):c.fit==="truncate"?t.jsx("span",{className:"ui-table-cut",children:u}):u]},c.key)}),e.actions&&e.actions.length>0?t.jsx("td",{children:t.jsx(te,{align:"end",children:e.actions.filter(c=>_t(l,c.when)).map((c,u)=>t.jsx(cw,{action:c,row:l,data:s.data,act:r,onForm:i.show},u))})}):null]},o))})]})]})}const uw=/^#(?:[0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i;function p9({column:e,row:n}){if(!e.swatch)return null;const s=Ce(n,e.swatch);return typeof s!="string"||!uw.test(s)?null:t.jsx("span",{className:"ui-table-swatch","aria-hidden":"true",style:{"--swatch":s}})}function g9(e,n,s){if(e.hint){const r=Ce(n,e.hint);if(r!=null&&r!=="")return String(r)}return e.fit==="truncate"&&s?s:void 0}function x9({column:e,row:n}){var l,o;const s=Ce(n,e.key);if(Array.isArray(s))return t.jsx(t.Fragment,{children:s.map((c,u)=>{var v;const d=c,f=typeof d=="object"&&d!==null?d.value:c;if(f==null||f==="")return null;const m=typeof d=="object"&&d!==null?d.tone:void 0,p=(v=e.pill)==null?void 0:v.labels,g=p&&Object.prototype.hasOwnProperty.call(p,String(f))?p[String(f)]:pn(f,e.type??"text",null);return t.jsx(Ee,{tone:ov(Hh(typeof m=="string"?m:void 0,n)),children:g},u)})});const r=(l=e.pill)==null?void 0:l.labels,a=String(s),i=r&&Object.prototype.hasOwnProperty.call(r,a)?r[a]:pn(s,e.type??"text",null);return t.jsx(Ee,{tone:ov(Hh((o=e.pill)==null?void 0:o.tone,n)),children:i})}function v9({component:e,data:n}){const s=Rn(e.query,n);return s.error?t.jsx(ne,{message:s.error}):s.data===void 0?t.jsx(ve,{children:e.empty??"Loading…"}):t.jsx(Is,{title:e.title,note:e.note,children:t.jsxs(ie,{gap:"lg",children:[e.fields.length>0?t.jsx(qt,{items:e.fields.map(r=>({key:r.label,label:r.label,value:pn(Ke(s.data,r.value),r.unit??"text",null)}))}):null,e.body.map((r,a)=>t.jsx(Ur,{component:r,data:s.data},a))]})})}function j9({component:e,data:n}){var m;const s=mt(),r=Rn(e.initial,n),a=ja(),[i,l]=h.useState(!1),o=((m=e.drawer)==null?void 0:m.id)!==void 0&&s.params.open===e.drawer.id,c=i||o,u=p=>{l(p),!p&&o&&s.setParams({open:null})},d=JSON.stringify([r.data??null,s.version]),f=t.jsx(y9,{component:e,data:n,initialData:r.data,act:a,onDone:()=>u(!1)},d);return e.drawer?e.drawer.button===void 0&&!e.title?t.jsxs(t.Fragment,{children:[t.jsx(zr,{act:a}),c?t.jsx(Ge,{title:e.drawer.title,onClose:()=>u(!1),children:f}):null]}):t.jsxs(ue,{title:e.title,aside:e.note,actions:e.drawer.button!==void 0?t.jsx(A,{variant:"accent",onClick:()=>u(!0),children:e.drawer.button}):void 0,children:[t.jsx(zr,{act:a}),c?t.jsx(Ge,{title:e.drawer.title,onClose:()=>u(!1),children:f}):null]}):t.jsxs(Is,{title:e.title,note:e.note,children:[t.jsx(ne,{message:r.error}),f]})}function y9({component:e,data:n,initialData:s,act:r,onDone:a}){const i=h.useContext(nR),l=mt(),[o,c]=h.useState(()=>nu(e.fields,s)),u=ow(e.fields,o,s),d=e.fields.some(f=>f.required&&!u.has(f.name)&&(o[f.name]===""||o[f.name]===void 0||Array.isArray(o[f.name])&&o[f.name].length===0));return t.jsxs(ie,{children:[t.jsx(im,{fields:e.fields,columns:e.columns,values:o,data:s,onChange:(f,m)=>c(p=>({...p,[f]:m}))}),e.drawer?null:t.jsx(zr,{act:r}),t.jsx(te,{align:"end",className:i?"ui-panel-foot":void 0,children:t.jsx(Gi,{action:e.submit,args:Ys(e.submit.args,{data:n,fields:o,shape:e.fields,omit:u,scope:l}),disabled:r.busy||d,running:r.running===e.submit.tool,onRun:(f,m)=>void r.run(f,m,a)})})]})}function w9(e,n){var r;if(e.type==="checkbox")return e.label;const s=(r=e.options)==null?void 0:r.find(a=>a.value===n);return`${e.label}: ${s?s.label:n}`}function bN(e){return e!=null&&e!==""&&e!==!1&&e!=="false"}function b9({component:e,data:n}){const s=mt(),[r,a]=h.useState(()=>nu(e.fields,n)),[i,l]=h.useState(e.auto===!0),[o,c]=h.useState(!1),u=e.fields.every(C=>!C.required||String(r[C.name]??"")!==""),d=Rn(i&&u?e.query:void 0,n),f=dr(d.data,e.rows),m=e.count===void 0?void 0:Ce(d.data,e.count),p=e.note===void 0?void 0:Ce(d.data,e.note),g=e.fields.find(C=>C.type==="text"||C.type==="email")??null,v=e.fields.filter(C=>C!==g),b=C=>{s.setParams(Object.fromEntries(e.fields.map(E=>[E.name,String(C[E.name]??"")||null]))),l(!0)},j=(C,E)=>{const T={...r,[C]:E};a(T),e.auto&&b(T)},x=()=>{const C=nu(e.fields,null);a(C),e.auto?b(C):(s.setParams(Object.fromEntries(e.fields.map(E=>[E.name,null]))),l(!1))},y=i?v.filter(C=>bN(s.params[C.name])):[],w=g?y.map(C=>t.jsx(Rh,{label:C.label,onRemove:()=>{const E={...r,[C.name]:C.type==="checkbox"?!1:""};a(E),b(E)},children:w9(C,String(s.params[C.name]))},C.name)):[],k=v.filter(C=>bN(r[C.name])).length,N=e.auto&&!e.reset?null:t.jsxs(t.Fragment,{children:[e.reset?t.jsx(A,{variant:"ghost",onClick:x,children:"Clear"}):null,e.auto?null:t.jsx(A,{type:"submit",variant:"accent",disabled:!u,children:"Search"})]}),S=e.results.to?e.results:e.to?{...e.results,to:e.to}:e.results;return t.jsx(Is,{title:e.title,children:t.jsxs(ie,{children:[t.jsx(D$,{label:e.title??"Search",onSubmit:()=>{!e.auto&&u&&b(r)},main:g?t.jsx("input",{id:`f-${g.name}`,name:g.name,type:g.type==="email"?"email":"search","aria-label":g.label,placeholder:g.hint??g.label,title:g.hint,required:g.required,value:String(r[g.name]??""),onChange:C=>j(g.name,C.target.value)}):void 0,filters:v.length>0?t.jsx(im,{fields:v,values:r,data:n,compact:!0,onChange:j}):void 0,...g&&v.length>0?{filtersOpen:o,onToggleFilters:()=>c(C=>!C),active:k}:{},chips:w.length>0?w:void 0,actions:N}),t.jsx(ne,{message:d.error}),i&&(m!==void 0||p!==void 0)?t.jsxs("p",{className:"ui-card-meta",children:[m===void 0?"":`${pn(m,"number",null)} in all. `,p===void 0?"":String(p)]}):null,i?f.length===0?t.jsx(ve,{children:d.loading?"Searching…":e.empty??"Nothing matches."}):t.jsx("div",{className:"ui-panel","data-flush":"true",children:t.jsx(at,{children:f.map((C,E)=>{const T=aR(s,S,C);return t.jsx(Xe,{title:T.title,sub:T.sub,side:T.side},E)})})}):null]})})}function k9({component:e,data:n}){const s=mt(),r=e.selection==="local",[a,i]=h.useState(null),l=r?a:s.params[e.param]??s.item,o=r&&a!==null?{...s,params:{...s.params,[e.param]:a}}:null,c=t.jsx(ie,{gap:"lg",divided:!0,children:e.detail.map((u,d)=>t.jsx(Ur,{component:u,data:n},d))});return t.jsx(su.Provider,{value:!1,children:t.jsx(P$,{list:t.jsx(sR.Provider,{value:!0,children:t.jsx(Ur,{component:e.list,data:n,chosen:l??null,...r?{choose:i}:{}})}),detail:l?o?t.jsx(iw.Provider,{value:o,children:c}):c:void 0,empty:e.empty??"Choose one to see it here."})})}function N9({component:e,data:n}){var v;const s=mt(),[r,a]=h.useState(!1),i=Rn(e.query,n,r&&e.poll?e.poll.seconds*1e3:void 0),l=e.poll!==void 0&&i.data!==void 0&&_t(i.data,e.poll.while);h.useEffect(()=>a(l),[l]);const o=dr(i.data,e.rows),c=(v=e.poll)==null?void 0:v.finish,u=ja(),[d,f]=h.useState(()=>new Set),m=c?o.find(b=>{if(!_t(b,c.when))return!1;const j=String(Ce(b,e.key)??"");return j!==""&&!d.has(j)}):void 0,p=m===void 0?null:String(Ce(m,e.key)??"");h.useEffect(()=>{!c||m===void 0||p===null||p===""||d.has(p)||u.busy||(f(b=>new Set([...b,p])),u.run(c.action,Ys(c.action.args,{data:m,row:m,scope:s})))},[p,u.busy]);const g=c!==void 0&&u.running===c.action.tool;return t.jsxs(Is,{title:e.title,note:e.note,children:[t.jsx(ne,{message:i.error}),g?t.jsxs("p",{className:"pl-wait",role:"status",children:[t.jsx("span",{className:"pl-spin","aria-hidden":"true"}),c.action.busy??c.action.label]}):t.jsx(zr,{act:u}),g?null:o.length===0?i.loading?t.jsx(ve,{children:"Loading…"}):t.jsx(qi,{text:e.empty??"Nothing here yet."}):t.jsx(ie,{gap:"lg",divided:!0,children:iR(o,e.key,{plugin:s.plugin,page:s.page,component:`repeat "${e.title??e.rows}"`}).map(({key:b,row:j})=>t.jsx(ue,{children:t.jsx(ie,{children:e.body.map((x,y)=>t.jsx(Ur,{component:x,data:j},y))})},b))})]})}function S9({component:e,data:n}){const s=mt(),r=UK({...e.views?{views:e.views}:{},...e.default?{default:e.default}:{},today:EK(s.timezone),storageKey:`buddi.calendar-view:${s.plugin}/${s.page}`}),a=Rn(e.query,n,void 0,{from:r.from,to:r.to}),i=h.useMemo(()=>RK(dr(a.data,e.events),e.map,s.timezone,`plugin ${s.plugin}, page ${s.page}, calendar`),[a.data,e.events,e.map,s.timezone,s.plugin,s.page]),[l,o]=h.useState(null),c=e.sheet&&l!==null?i.find(u=>u.id===l)??null:null;return t.jsxs(Is,{title:e.title,note:e.note,children:[t.jsx(ne,{message:a.error}),t.jsx(BK,{state:r,events:i,hours:e.hours,empty:e.empty??"Nothing.",label:e.title??"Calendar",onEvent:e.sheet?u=>o(u.id):void 0,count:e.count&&a.data!==void 0?i.length:void 0}),c&&e.sheet?t.jsx(C9,{event:c,sheet:e.sheet,onClose:()=>o(null)}):null]})}function C9({event:e,sheet:n,onClose:s}){const r=mt(),a=e.row,i=p=>{if(p===void 0)return"";const g=Ce(a,p);return g==null?"":String(g)},l=DK(e),o=i(n.color),c=i(n.notes),u=Wh(i(n.mapHref)),d=n.open?Wh(i(n.open.href)):null,f=n.open?i(n.open.label):"",m=p=>{const g=as(p.replace(/\{when\}/g,l),{row:{...a,title:e.title,calendar:e.calendar,location:e.location}});s(),tK(g)||r.navigate(oa)};return t.jsx(Ge,{title:e.title,onClose:s,foot:n.asks&&n.asks.length>0?t.jsx(te,{align:"end",children:n.asks.map((p,g)=>t.jsx(A,{onClick:()=>m(p.text),children:p.label},g))}):void 0,children:t.jsxs("div",{className:"pl-event-sheet",children:[t.jsx("p",{className:"pl-event-when",children:l}),e.calendar?t.jsxs("p",{className:"pl-event-cal",children:[o&&uw.test(o)?t.jsx("span",{className:"pl-swatch","aria-hidden":"true",style:{"--swatch":o}}):t.jsx("span",{className:"cal-dot","data-tone":e.tone,"aria-hidden":"true"}),e.calendar]}):null,e.location?t.jsxs("p",{className:"pl-event-where",children:[t.jsx(le,{name:"pin",size:14}),u?t.jsx(Xl,{href:u,children:e.location}):t.jsx("span",{children:e.location})]}):null,c?t.jsx("p",{className:"pl-event-notes",children:c}):null,d&&f?t.jsx("p",{className:"pl-event-open",children:t.jsx(Xl,{href:d,className:"wb-src-link",children:f})}):null]})})}function E9({component:e,data:n}){var f;const s=mt(),r=Rn(e.query,n),a={items:"$",icon:e.icon,value:e.value,label:e.label,...e.lines?{lines:e.lines}:{},...e.tone?{tone:e.tone}:{}},i=dr(r.data,e.items).flatMap(m=>{const p=Ey([m],a).tiles[0];return p?[{tile:p,key:e.select?String(Ce(m,e.select.key)??""):""}]:[]}),l=e.select,o=l?Math.max(0,i.findIndex(m=>m.key===s.params[l.param])):null,c=((f=i[0])==null?void 0:f.key)??"",u=l?s.params[l.param]:void 0,d=i.some(m=>m.key===u);return h.useEffect(()=>{l&&c!==""&&!d&&s.setParams({[l.param]:c})},[l==null?void 0:l.param,c,d]),t.jsxs(Is,{title:e.title,note:e.note,children:[t.jsx(ne,{message:r.error}),r.data===void 0?t.jsx(ve,{children:"Loading…"}):i.length===0?t.jsx(qi,{text:e.empty??"Nothing to show."}):t.jsx(G$,{props:{tiles:i.map(m=>m.tile),notice:!1,empty:""},...e.layout?{layout:e.layout}:{},...l?{selected:o,onPick:m=>{var p;return s.setParams({[l.param]:((p=i[m])==null?void 0:p.key)||null})}}:{}})]})}function A9({component:e,data:n}){const s=Rn(e.query,n),r=dr(s.data,e.points);if(s.data===void 0||r.length===0)return t.jsxs(Is,{title:e.title,note:e.note,children:[t.jsx(ne,{message:s.error}),s.data===void 0?t.jsx(ve,{children:"Loading…"}):t.jsx(qi,{text:e.empty??"Nothing to show."})]});const a=r.map(c=>String(Ce(c,e.x)??"")),i={items:"$",icon:e.tiles.icon,value:e.tiles.value,label:e.tiles.label,...e.tiles.lines?{lines:e.tiles.lines}:{}},l=r.map((c,u)=>Ey([c],i).tiles[0]??{icon:null,value:"",label:a[u]??"",lines:[],tone:"neutral",link:null}),o=e.series.map(c=>({id:c.id,label:c.label,kind:c.kind,...c.unit?{unit:c.unit}:{},values:r.map(u=>ys(Ce(u,c.y))??null)}));return t.jsxs(t.Fragment,{children:[t.jsx(ne,{message:s.error}),t.jsx(YK,{...e.title?{title:e.title}:{},...e.note?{note:e.note}:{},...e.labelEvery?{labelEvery:e.labelEvery}:{},xs:a,series:o,tiles:l})]})}function $9({component:e,data:n}){const s=Rn(e.query,n),r=o=>{const c=Ce(s.data,o);return c==null?"":String(c)};if(s.data===void 0||s.data===null)return t.jsxs(t.Fragment,{children:[t.jsx(ne,{message:s.error}),t.jsx(ve,{children:s.loading?"Loading…":e.empty??"Nothing to show."})]});const a=r(e.value),i=r(e.title),l=e.facts.map(o=>({label:o.label,value:r(o.path)})).filter(o=>o.value!=="");return t.jsxs("section",{className:"pg-hero","aria-label":[a,i,...l.map(o=>`${o.label} ${o.value}`)].filter(Boolean).join(", "),children:[t.jsxs("div",{className:"pg-hero-main","aria-hidden":"true",children:[t.jsx("span",{className:"pg-hero-icon",children:t.jsx(le,{name:bo(Ox(Ke(s.data,e.icon))),size:44})}),t.jsx("span",{className:"pg-hero-value",children:a}),i?t.jsx("span",{className:"pg-hero-title",children:i}):null]}),l.length>0?t.jsx("dl",{className:"pg-hero-facts","aria-hidden":"true",children:l.map(o=>t.jsxs("div",{className:"pg-hero-fact",children:[t.jsx("dt",{children:o.label}),t.jsx("dd",{children:o.value})]},o.label))}):null]})}function T9({component:e,data:n}){var g;const s=mt(),[r,a]=h.useState(e.default??e.tabs[0].id),i=e.param,l=i?s.params[i]??e.default??e.tabs[0].id:r,o=v=>i?s.setParams({[i]:v}):a(v),c=e.pick,{options:u}=eR({name:(c==null?void 0:c.param)??"",label:(c==null?void 0:c.label)??"",...c!=null&&c.options?{options:c.options}:{},...c!=null&&c.optionsFrom?{optionsFrom:c.optionsFrom}:{}},{},n),d=c?u.some(v=>v.value===s.params[c.param])?s.params[c.param]:((g=u[0])==null?void 0:g.value)??"":"",f=e.tabs.find(v=>v.id===l)??e.tabs[0],m=(c==null?void 0:c.look)==="chips",p=c!=null&&c.add?va(s,c.add.to,n):"";return t.jsxs("div",{className:"pg-tabs",children:[t.jsxs("div",{className:"pg-tabs-bar","data-only":e.tabs.length===1?"pick":void 0,"data-chips":m?"true":void 0,children:[c&&m&&u.length>0?t.jsxs("div",{className:"pl-chips",role:"group","aria-label":c.label,children:[u.map(v=>t.jsx(A,{size:"sm","aria-pressed":v.value===d,onClick:()=>s.setParams({[c.param]:v.value}),children:v.label},v.value)),c.add&&p!==""?t.jsxs(ht,{size:"sm",variant:"ghost",href:p,onClick:v=>{v.preventDefault(),s.navigate(p)},children:[t.jsx(le,{name:"plus",size:12}),c.add.label]}):null]}):c&&u.length>1?t.jsx(ln,{label:c.label,options:u,value:d,onChange:v=>s.setParams({[c.param]:v})}):null,e.tabs.length>1?t.jsx("span",{className:"pg-tabs-switch",children:t.jsx(ln,{label:e.title??"View",options:e.tabs.map(v=>({value:v.id,label:v.label})),value:f.id,onChange:o})}):null]}),f.body.map((v,b)=>t.jsx(Ur,{component:v,data:n},`${f.id}-${b}`))]})}function R9({component:e,data:n}){const[s,r]=h.useState(!1),a=Rn(s?e.query:void 0,n),i=typeof e.label=="string"?e.label:String(Ke(n,e.label)??"");return t.jsxs(Ot,{summary:i,boxed:!0,onToggle:l=>r(l),children:[t.jsx(ne,{message:a.error}),a.data===void 0?t.jsx(ve,{children:"Loading…"}):t.jsx(ie,{children:e.body.map((l,o)=>t.jsx(Ur,{component:l,data:a.data},o))})]})}function uR({component:e,data:n}){const s=mt(),r=ja();return t.jsxs(t.Fragment,{children:[t.jsx(te,{align:"end",children:t.jsx(Gi,{action:e.action,args:Ys(e.action.args,{data:n,row:n,scope:s}),disabled:r.busy,running:r.running===e.action.tool,row:n,onRun:(a,i)=>void r.run(a,i)})}),t.jsx(zr,{act:r})]})}function I9({component:e}){const n=mt();return t.jsx(sw,{plugin:n.plugin,agent:e.agent,text:e.text,label:e.label})}function P9(e){if(!e||typeof e!="object")return null;const n=e;return typeof n.id!="string"||n.id===""||typeof n.title!="string"?null:{...n,outlets:Array.isArray(n.outlets)?n.outlets.filter(s=>s&&typeof s.name=="string"):[]}}function uv(e){return e.length===0?"":e.length===1?e[0].name:`${e[0].name} and ${e.length-1} more`}function kN(e,n,s){const r={};for(const[a,i]of Object.entries(e))"row"in i?r[a]=Ce(n,i.row):"item"in i?r[a]=Ce(s,i.item):r[a]=Ke(n,i);return r}const M9=8e3;function NN(e,n,s){const r=[];let a=null;return e.forEach((i,l)=>{if(!_t(n,i.when))return;const o=i.each?Array.isArray(Ce(n,i.each))?Ce(n,i.each).slice(0,4):[]:[void 0];if(o.length!==0){l>0&&r.length>0&&i.group!==a&&r.push("separator"),i.group&&i.group!==a&&r.push({heading:i.group}),a=i.group;for(const c of o)r.push({label:as(i.label,{row:c===void 0?n:c}),...i.hint?{hint:as(i.hint,{row:n})}:{},onSelect:()=>s(i,c)})}}),r}function D9({component:e,data:n}){var S,C;const s=mt(),r=Rn(e.query,n),a=ja(),i=e.param??"story",[l,o]=h.useState(null);h.useEffect(()=>{if(!l)return;const E=setTimeout(()=>o(null),M9);return()=>clearTimeout(E)},[l]);const c=dr(r.data,e.rows).map(P9).filter(E=>E!==null),u=e.ways??[],d=s.params[i],f=d?c.find(E=>E.id===d)??null:null,m=async(E,T,I,F)=>{var O;const D=kN(E.args,T,I);if(!await a.run({tool:E.tool,label:E.label,...E.done!==void 0?{done:E.done}:{},...E.then?{then:E.then}:{}},D)||!E.hides)return;d===T.id&&s.setParams({[i]:null});const L=typeof E.done=="string"?as(E.done,{row:I===void 0?T:I}):"Hidden.";o({id:T.id,group:((O=T.group)==null?void 0:O.id)??null,index:F,text:L,...E.undo?{undo:{tool:E.undo.tool,label:E.undo.label,args:kN(E.undo.args,T,I)}}:{}})},p=()=>{const E=l;o(null),E!=null&&E.undo&&a.run({tool:E.undo.tool,label:E.undo.label},E.undo.args)},g=[];for(const E of c){if(l&&E.id===l.id)continue;const T=e.groups&&E.group?E.group.id:null;let I=g.find(F=>F.id===T);I||(I={id:T,name:e.groups&&E.group?E.group.name:null,rows:[]},g.push(I)),I.rows.push(E)}l&&!g.some(E=>E.id===l.group)&&g.push({id:l.group,name:null,rows:[]});const v=(S=e.groups)==null?void 0:S.param,b=!(g.length===1&&v!==void 0&&s.params[v]===g[0].id),j=(E,T)=>t.jsx(_9,{row:E,plugin:s.plugin,menu:NN(u,E,(I,F)=>void m(I,E,F,T)),onOpen:()=>s.setParams({[i]:E.id})},E.id),x=E=>t.jsxs("div",{className:"pl-story-gone",role:"status",children:[t.jsx("span",{children:E.text}),E.undo?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"pl-story-gone-sep","aria-hidden":"true",children:"·"}),t.jsx(A,{size:"sm",variant:"ghost",onClick:p,children:E.undo.label})]}):null]},`gone-${E.id}`),y=E=>{const T=E.rows.map(j);return l&&l.group===E.id&&T.splice(Math.min(l.index,T.length),0,x(l)),T};let w;if(r.data===void 0&&r.loading)w=t.jsx("div",{className:"pl-story-grid","aria-busy":"true","aria-label":"Fetching stories",children:Array.from({length:6},(E,T)=>t.jsxs("div",{className:"ui-card pl-story cat-skel pl-story-skel",children:[t.jsxs("span",{className:"pl-story-head",children:[t.jsx("i",{className:"cat-skel-face pl-story-skel-logo"}),t.jsx("i",{className:"cat-skel-line","data-w":"30"})]}),t.jsx("i",{className:"cat-skel-line","data-w":"90"}),t.jsx("i",{className:"cat-skel-line","data-w":"70"}),t.jsx("i",{className:"cat-skel-line","data-w":"40"})]},T))});else if(c.length===0&&!l){const E=(e.emptyStates??[]).find(T=>_t(r.data,T.when));if(E){const T=F=>F===void 0?"":typeof F=="string"?F:String(Ke(r.data,F)??""),I=(E.actions??[]).map((F,D,$)=>{const L=D===$.length-1&&($.length>1||E.warm===!0);if(F.set)return t.jsx(A,{size:"sm",variant:L?"accent":"ghost",onClick:()=>s.setParams(F.set),children:F.label},D);const O=F.to?va(s,F.to,r.data):"";return O===""?null:t.jsx(ht,{size:"sm",variant:L?"accent":"ghost",href:O,onClick:M=>{M.preventDefault(),s.navigate(O)},children:F.label},D)});w=t.jsx(ve,{warm:E.warm===!0,title:T(E.title),action:I.length>0?t.jsx(te,{children:I}):void 0,children:T(E.text)})}else w=t.jsx(qi,{text:e.empty??"Nothing here yet."})}else w=g.map(E=>{var T;return t.jsxs("section",{className:"pl-story-group","aria-label":E.name??e.title??"Stories",children:[b&&E.name?t.jsxs("header",{className:"pl-story-group-head",children:[t.jsx("h2",{className:"pl-story-group-title",children:E.name}),v&&E.id?t.jsxs("a",{href:"#",className:"pl-story-group-aside",onClick:I=>{I.preventDefault(),s.setParams({[v]:E.id})},children:[((T=e.groups)==null?void 0:T.label)??"See all",t.jsx(le,{name:"arrow",size:12})]}):null]}):null,t.jsx("div",{className:"pl-story-grid",children:y(E)})]},E.id??"all")});const k=u.find(E=>E.hides&&!E.each&&_t(f,E.when)),N=u.filter(E=>E!==k);return t.jsxs("div",{className:"pl-stories",children:[t.jsx(ne,{message:r.error}),t.jsx(dR,{act:a}),w,f?t.jsx(Ge,{title:f.kicker??((C=f.group)==null?void 0:C.name)??e.title??"Story",onClose:()=>s.setParams({[i]:null}),foot:t.jsxs(te,{children:[k?t.jsx(A,{variant:"ghost",disabled:a.busy,onClick:()=>void m(k,f,void 0,0),children:as(k.label,{row:f})}):null,N.length>0?t.jsx(Rs,{label:`Less of this: ${f.title}`,trigger:t.jsx("button",{type:"button",className:"ui-btn","data-variant":"ghost",disabled:a.busy,children:"Less of this…"}),items:NN(N,f,(E,T)=>void m(E,f,T,0)),stacked:!0}):null,t.jsx(et,{}),e.ask&&_t(f,e.ask.when)?t.jsx(O9,{to:e.ask.to,row:f,label:e.ask.label,accent:!0}):null]}),children:t.jsx(z9,{row:f,plugin:s.plugin,edition:e.edition})}):null]})}function dR({act:e}){return e.error?t.jsx(ne,{message:e.error}):e.approvalId?t.jsx(zr,{act:e}):null}function O9({to:e,row:n,label:s,accent:r}){const a=mt(),i=va(a,e,n);return i===""?null:"href"in e?t.jsx(ht,{variant:r?"accent":"ghost",href:i,target:"_blank",rel:"noopener noreferrer",children:s}):t.jsx(ht,{variant:r?"accent":"ghost",href:i,onClick:l=>{l.preventDefault(),a.navigate(i)},children:s})}function L9({row:e}){var s;const n=((s=e.mark)==null?void 0:s.kind)==="told";return!e.opinion&&!e.languages&&!e.mark?null:t.jsxs("span",{className:"pl-story-marks",children:[e.opinion?t.jsx(Jl,{children:"Opinion"}):null,e.languages?t.jsx("span",{className:"pl-story-lang",children:e.languages}):null,e.mark?n?t.jsxs("span",{className:"pl-story-told",children:[t.jsx(le,{name:"check",size:12}),e.mark.text]}):t.jsx("span",{className:"pl-story-new",children:e.mark.text}):null]})}function F9({plugin:e,outlets:n}){return n.length===0?null:t.jsxs("span",{className:"pl-stack","aria-label":uv(n),children:[t.jsx("span",{className:"pl-stack-logos",children:n.slice(0,3).map((s,r)=>t.jsx(No,{src:Su(e,s.logo),label:s.name},r))}),t.jsx("span",{className:"pl-stack-words",children:uv(n)})]})}function _9({row:e,plugin:n,menu:s,onOpen:r}){var i;const a=uv(e.outlets);return t.jsxs("article",{className:"ui-card pl-story","data-told":e.quiet?"true":void 0,"data-opinion":e.opinion?"true":void 0,tabIndex:0,onClick:r,onKeyDown:l=>{l.target!==l.currentTarget||l.key!=="Enter"||(l.preventDefault(),r())},"aria-label":`${e.opinion?"Opinion: ":""}${e.title}.${a?` ${a}`:""}${e.ago?`, ${e.ago}`:""}.`,children:[t.jsxs("header",{className:"pl-story-head",children:[t.jsx(F9,{plugin:n,outlets:e.outlets}),e.ago?t.jsx("span",{className:"pl-story-time",children:e.ago}):null,s.length>0?t.jsx("span",{className:"pl-story-more",onClick:l=>l.stopPropagation(),onKeyDown:l=>l.stopPropagation(),children:t.jsx(Rs,{label:`Ways out for ${e.title}`,items:s.map(l=>typeof l=="string"||"heading"in l?l:{label:l.label,...l.hint?{hint:l.hint}:{},onSelect:l.onSelect}),sheet:{title:e.title,sub:[e.kicker??((i=e.group)==null?void 0:i.name),a].filter(Boolean).join(" · ")},stacked:!0})}):null]}),t.jsx("h3",{className:"pl-story-title",children:e.title}),e.lead?t.jsx("p",{className:"pl-story-lead",children:e.lead}):null,t.jsx(L9,{row:e})]})}function z9({row:e,plugin:n,edition:s}){const r=Array.isArray(e.sources)?e.sources.filter(l=>l&&typeof l.title=="string"):[],a=Array.isArray(e.timeline)?e.timeline.filter(l=>l&&typeof l.text=="string"):[],i=s&&_t(e,s.when)?s:void 0;return t.jsxs("div",{className:"pl-story-sheet",children:[t.jsxs("div",{className:"pl-story-sheet-lead",children:[e.opinion?t.jsx(Jl,{children:"Opinion"}):null,t.jsx("h3",{className:"pl-story-sheet-title",children:e.title}),e.summary??e.lead?t.jsx("p",{className:"pl-story-sheet-summary",children:e.summary??e.lead}):null,e.update?t.jsxs("p",{className:"pl-story-sheet-update",children:[e.mark&&e.mark.kind==="new"?t.jsx("span",{className:"pl-story-new",children:e.mark.text}):null,e.update]}):null,e.meta||i?t.jsxs("p",{className:"pl-story-sheet-meta",children:[e.meta,i?t.jsxs(t.Fragment,{children:[e.meta?" · ":null,t.jsx(U9,{to:i.to,row:e,label:i.label})]}):null]}):null]}),r.length>0?t.jsxs("section",{className:"pl-story-sheet-block",children:[t.jsx("h4",{className:"pl-story-sheet-head",children:"Sources"}),t.jsx("ul",{className:"pl-story-sources",children:r.map((l,o)=>{const c=Wh(l.url);return t.jsxs("li",{className:"pl-story-source",children:[t.jsx(No,{className:"pl-logo-md",src:Su(n,l.logo),label:l.outlet}),t.jsxs("span",{className:"pl-story-source-text",children:[c?t.jsx(Xl,{href:c,className:"wb-src-link pl-story-source-title",children:l.title}):t.jsx("span",{className:"pl-story-source-title",children:l.title}),l.meta?t.jsx("span",{className:"pl-story-source-meta",children:l.meta}):null]})]},o)})})]}):null,a.length>0?t.jsxs("section",{className:"pl-story-sheet-block",children:[t.jsx("h4",{className:"pl-story-sheet-head",children:"How it moved"}),t.jsx("ol",{className:"pl-story-timeline",children:a.map((l,o)=>t.jsxs("li",{className:"pl-story-tl","data-told":l.told?"true":void 0,"data-last":o===a.length-1?"true":void 0,children:[t.jsx("span",{className:"pl-story-tl-at",children:l.at}),t.jsx("span",{className:"pl-story-tl-dot","aria-hidden":"true"}),t.jsx("span",{className:"pl-story-tl-what",children:l.text})]},o))})]}):null]})}function U9({to:e,row:n,label:s}){const r=mt(),a=va(r,e,n);return a===""?null:"href"in e?t.jsx(Xl,{href:a,children:s}):t.jsx("a",{href:a,onClick:i=>{i.preventDefault(),r.navigate(a)},children:s})}function B9({component:e,data:n}){const s=Ce(n,e.path);return typeof s!="string"||s===""?null:t.jsx(Kh,{id:s})}function W9({component:e,data:n}){const s=Ce(n,e.path);return typeof s!="string"||s===""?null:t.jsx(te,{children:t.jsx("a",{href:Ya(s),children:e.label})})}function H9({component:e,data:n}){const s=Rn(e.query,n),r=ja();return s.error?t.jsx(ne,{message:s.error}):s.data===void 0?t.jsx(ve,{children:e.empty??"Loading…"}):t.jsxs(t.Fragment,{children:[t.jsx(zr,{act:r}),t.jsx(K9,{component:e,data:n,loaded:s.data,act:r},JSON.stringify(s.data))]})}function K9({component:e,data:n,loaded:s,act:r}){const a=mt(),[i,l]=h.useState(()=>nu(e.fields,s)),o={...i,version:Ce(s,e.version)},c=ow(e.fields,i,s),u=e.readOnlyWhen!==void 0&&_t(s,e.readOnlyWhen),d=(e.actions??[]).filter(p=>p.placement==="leading"),f=(e.actions??[]).filter(p=>p.placement!=="leading"),m=(p,g)=>t.jsx(Gi,{action:p,args:Ys(p.args,{data:n,fields:o,shape:e.fields,omit:c,scope:a}),disabled:r.busy,running:r.running===p.tool,onRun:(v,b)=>void r.run(v,b)},`${p.tool}-${g}`);return t.jsx(Is,{title:e.title,note:e.note,children:t.jsxs(ie,{children:[t.jsx(im,{fields:e.fields,values:i,data:s,disabled:u,onChange:(p,g)=>l(v=>({...v,[p]:g}))}),u?null:t.jsxs(te,{align:"end",children:[d.map(m),d.length>0?t.jsx(et,{}):null,m(e.save,-1),f.map(m)]}),e.footnote?t.jsx("p",{className:"ui-toolbar-note",children:e.footnote}):null]})})}function dw({page:e,item:n,navigate:s,timezone:r,embedded:a,siblings:i,params:l}){const[o,c]=h.useState(()=>({...l})),u=JSON.stringify(l??{});h.useEffect(()=>{l&&Object.keys(l).length>0&&c(b=>({...b,...l}))},[u]);const[d,f]=h.useState(0),m={plugin:e.plugin,page:e.id,pages:i??[e],item:n??null,params:{...o,...n?{item:n}:{},...Y9(e,n)},setParams:b=>c(j=>{const x={...j};for(const[y,w]of Object.entries(b))w===null?delete x[y]:x[y]=w;return x}),navigate:s,timezone:r,version:d,refresh:()=>f(b=>b+1),sensitive:new Set(e.sensitive??[])},p=e.body[0],g=!a&&(p==null?void 0:p.kind)==="notice"&&p.look!=="quiet"&&p.link===void 0&&p.action===void 0&&p.when===void 0&&p.title===void 0&&(p.tone===void 0||p.tone==="neutral")?p.text:void 0,v=g===void 0?e:{...e,body:e.body.slice(1)};return t.jsx(iw.Provider,{value:m,children:t.jsx(V9,{page:v,embedded:a===!0,lede:g})})}function V9({page:e,embedded:n,lede:s}){const r=mt(),a=e.data!==void 0&&r.sensitive.has(e.data.query),i=Rn(a?void 0:e.data,null),l=i.data??null,o=s===void 0||typeof s=="string"?s:Ke(l,s),c=o==null||o===""?void 0:String(o),u=!n&&e.actions&&e.actions.length>0?t.jsx(t.Fragment,{children:e.actions.map((d,f)=>t.jsx(G9,{component:d,data:l},f))}):void 0;return t.jsx(Zn,{embedded:n,title:e.title,lede:c,actions:u,children:t.jsx(q9,{page:e,boxed:n,root:a?void 0:i})})}function G9({component:e,data:n}){const s=mt();if(!_t(n,e.when))return null;if(e.kind==="button")return t.jsx(uR,{component:e,data:n});if(e.kind==="menu")return t.jsx(rR,{component:e,data:n});const r=va(s,e.to,n);if(r==="")return null;const a=e.tone==="accent"?"accent":"ghost";return"href"in e.to?t.jsxs(ht,{variant:a,href:r,target:"_blank",rel:"noopener noreferrer",children:[e.label,t.jsx("span",{className:"wb-src-out","aria-hidden":"true",children:"↗"})]}):t.jsx(ht,{variant:a,href:r,onClick:i=>{i.preventDefault(),s.navigate(r)},children:e.label})}function q9({page:e,boxed:n,root:s}){const r=mt();return e.data&&r.sensitive.has(e.data.query)?t.jsx(XT,{children:t.jsx(SN,{page:e,boxed:n})}):t.jsx(SN,{page:e,boxed:n,root:s})}function SN({page:e,boxed:n,root:s}){const r=Rn(s?void 0:e.data,null),a=s??r;return t.jsxs(ie,{gap:"lg",divided:!n,children:[t.jsx(ne,{message:a.error}),t.jsx(su.Provider,{value:n,children:e.body.map((i,l)=>t.jsx(Ur,{component:i,data:a.data??null},l))})]})}function Y9(e,n){if(!n)return{};const s=[],r=a=>{for(const i of a)if(i.kind==="list-detail")s.push(i.param),r(i.detail);else if(i.kind==="section"||i.kind==="detail"||i.kind==="expand")r(i.body);else if(i.kind==="tabs")for(const l of i.tabs)r(l.body)};return r(e.body),Object.fromEntries(s.map(a=>[a,n]))}function J9(e){return t.jsx(dw,{...e,embedded:!0})}function qi({text:e}){const n=e.search(/[.!?]\s/),s=n===-1?e.replace(/[.]$/,""):e.slice(0,n+(e[n]==="."?0:1)),r=n===-1?"":e.slice(n+1).trim();return t.jsx(Jn,{title:s,children:r||null})}const CN=[{id:"",label:"All files"},{id:"produced",label:"Created by agents"},{id:"uploaded",label:"Uploaded by you"}],Q9=["","image","pdf","table","text","code","audio","video","archive","file"];function X9({hash:e,timezone:n,navigate:s,agents:r}){var D;const a=r3(e),i=(a==null?void 0:a.artifactId)??null,l=(a==null?void 0:a.filters.origin)??"",o=(a==null?void 0:a.filters.family)??"",c=(a==null?void 0:a.filters.q)??"",[u,d]=h.useState(c);h.useEffect(()=>{d(c)},[c]);const f=($,L=!1)=>s(ad(i,{q:c,origin:l,family:o,...$}),L);h.useEffect(()=>{if(u===c)return;const $=window.setTimeout(()=>f({q:u},!0),250);return()=>window.clearTimeout($)},[u]);const[m,p]=h.useState(null),[g,v]=h.useState(null),[b,j]=h.useState(null),[x,y]=h.useState(!1),[w,k]=h.useState(!1),N=$=>{var L;return $?((L=r.find(O=>O.id===$))==null?void 0:L.name)??$:""},S=h.useRef(0);h.useEffect(()=>{const $=++S.current;p(null),v(null),y(!1),j(null),R.library({...c?{q:c}:{},...l?{origin:l}:{},...o?{family:o}:{}}).then(L=>{S.current===$&&(p(L.entries),v(L.next))}).catch(L=>{S.current===$&&j(L instanceof xe?L.message:String(L))})},[c,l,o]);const C=()=>{if(!g||x)return;y(!0);const $=S.current;R.library({...c?{q:c}:{},...l?{origin:l}:{},...o?{family:o}:{},cursor:g}).then(L=>{S.current===$&&(p(O=>{const M=new Set((O??[]).map(P=>P.id));return[...O??[],...L.entries.filter(P=>!M.has(P.id))]}),v(L.next))}).catch(L=>{S.current===$&&j(L instanceof xe?L.message:String(L))}).finally(()=>{S.current===$&&y(!1)})},E=(l?1:0)+(o?1:0),T=((D=CN.find($=>$.id===l))==null?void 0:D.label)??l,I=t.jsxs(t.Fragment,{children:[m===null?t.jsx(ve,{children:"Loading…"}):m.length===0?t.jsx(ve,{children:"No file matches that."}):t.jsx(at,{children:m.map($=>t.jsx(I$,{href:ad($.id,{q:c,origin:l,family:o}),current:$.id===i,onClick:()=>s(ad($.id,{q:c,origin:l,family:o})),lead:t.jsx("span",{className:"files-row-visual","data-family":$.family,children:$.family==="image"&&!$.deleted?t.jsx("img",{src:_r($.id),alt:"",loading:"lazy"}):t.jsx(Hy,{family:$.family})}),title:$.filename??"Untitled file",meta:t.jsx("span",{title:ct($.createdAt,n),children:Ve($.createdAt)}),sub:`${$.caption&&$.origin==="produced"?`${$.caption} · `:""}${Ci[$.family]} · ${ds($.sizeBytes)} · ${hR($,N)}${Z9($,N)}`},$.id))}),g?t.jsx("div",{className:"files-more",children:t.jsx(A,{size:"sm",onClick:C,disabled:x,children:x?"Loading…":"Show more"})}):null]}),F=m!==null&&m.length===0&&!c&&!l&&!o&&!u;return t.jsxs("div",{className:"ui-page files","data-selected":i?"true":void 0,children:[t.jsxs("header",{className:"ui-page-head",children:[t.jsx("h2",{className:"ui-page-title",children:"Files"}),t.jsx("p",{className:"ui-page-lede",children:"What your agents made or were given."})]}),F?t.jsx(Jn,{icon:"files",title:"Nothing here yet",children:"Drop a file into any conversation and it shows up here too."}):t.jsxs(t.Fragment,{children:[t.jsx(D$,{label:"Files",onSubmit:()=>f({q:u},!0),main:t.jsx("input",{type:"search",value:u,placeholder:"Search by name or label","aria-label":"Search files by name or label",onChange:$=>d($.target.value)}),filters:t.jsxs(Ns,{dense:!0,children:[t.jsx(re,{label:"Origin",children:t.jsx("select",{value:l,"aria-label":"Origin",onChange:$=>f({origin:$.target.value}),children:CN.map($=>t.jsx("option",{value:$.id,children:$.label},$.id))})}),t.jsx(re,{label:"Kind",children:t.jsx("select",{value:o,"aria-label":"Kind",onChange:$=>f({family:$.target.value}),children:Q9.map($=>t.jsx("option",{value:$,children:$===""?"Any kind":Ci[$]},$))})})]}),filtersOpen:w,onToggleFilters:()=>k($=>!$),active:E,chips:E>0?t.jsxs(t.Fragment,{children:[l?t.jsx(Rh,{label:"Origin",onRemove:()=>f({origin:""}),children:T}):null,o?t.jsx(Rh,{label:"Kind",onRemove:()=>f({family:""}),children:Ci[o]}):null]}):void 0}),t.jsx(ne,{message:b}),t.jsx(P$,{className:"files-split",label:"Files",list:I,detail:i?t.jsx(eV,{id:i,timezone:n,agents:r,navigate:s,onBack:()=>s(ad(null,{q:c,origin:l,family:o}))},i):void 0,empty:"Choose a file to see it here."})]})]})}function Z9(e,n){var a,i;const s=(a=e.context)!=null&&a.groupName?`in ${e.context.groupName}`:(i=e.context)!=null&&i.agentId&&e.context.agentId!==e.agentId?`with ${n(e.context.agentId)}`:"",r=e.contexts>1?`${e.contexts} conversations`:"";return[s,r].filter(Boolean).map(l=>` · ${l}`).join("")}function hR(e,n){return e.origin==="uploaded"?"You sent it":e.origin==="produced"?`Made by ${n(e.agentId)||"an agent"}`:e.agentId?`Saved by ${n(e.agentId)}`:"Origin unknown"}function eV({id:e,timezone:n,agents:s,navigate:r,onBack:a}){const[i,l]=h.useState(null),[o,c]=h.useState(!1),[u,d]=h.useState(null);h.useEffect(()=>{let x=!1;return l(null),d(null),R.libraryEntry(e).then(y=>{x||l(y)}).catch(y=>{x||d(y instanceof xe&&y.status===404?"This file is no longer in the library.":y instanceof xe?y.message:String(y))}),()=>{x=!0}},[e]);const f=x=>{var y;return x?((y=s.find(w=>w.id===x))==null?void 0:y.name)??x:""};if(u)return t.jsxs("div",{className:"files-detail-body",children:[t.jsx(A,{size:"sm",onClick:a,className:"files-back",children:"Back to Files"}),t.jsx(G,{tone:"critical",children:u})]});if(!i)return t.jsx("div",{className:"files-detail-body",children:t.jsx(ve,{children:"Loading…"})});const{entry:m,contexts:p,contextsTotal:g,available:v}=i,b=m.filename??"Untitled file",j=()=>{c(!0),R.libraryEntry(e,p.length).then(x=>l(y=>y&&{...y,contexts:[...y.contexts,...x.contexts],contextsTotal:x.contextsTotal})).catch(()=>{}).finally(()=>c(!1))};return t.jsxs("div",{className:"files-detail-body",children:[t.jsx(A,{size:"sm",onClick:a,className:"files-back",children:"Back to Files"}),t.jsxs("header",{className:"files-detail-head",children:[t.jsx("span",{className:"files-detail-mark","data-family":m.family,"aria-hidden":"true",children:t.jsx(Hy,{family:m.family})}),t.jsxs("div",{className:"files-detail-text",children:[t.jsx("h3",{className:"files-detail-name",children:b}),t.jsxs("p",{className:"files-detail-meta",children:[Ci[m.family]," · ",ds(m.sizeBytes)," · ",ct(m.createdAt,n)]})]}),v?t.jsx(tT,{artifactId:m.id,filename:m.filename,mime:m.mime}):null]}),v?null:t.jsx(G,{tone:"warning",children:"The file's bytes are no longer on this machine. What is known about it stays here; the download will not work."}),t.jsx(eT,{artifactId:m.id,filename:m.filename,mime:m.mime,family:m.family,available:v}),t.jsx(qt,{items:[{label:"Origin",value:hR(m,f)},...m.caption&&m.origin==="produced"?[{label:"Filed under",value:m.caption}]:[],...m.agentId&&m.origin==="produced"?[{label:"Made by",value:t.jsxs("span",{className:"files-agent",children:[t.jsx(fn,{agents:s,id:m.agentId,size:"sm"}),f(m.agentId)]})}]:[],{label:"Type",value:t.jsx("span",{className:"mono",children:m.mime})},{label:"Id",value:t.jsx("span",{className:"mono",children:m.id})}]}),t.jsxs("section",{className:"files-conversations",children:[t.jsx("h4",{className:"ui-section-title",children:"Conversations"}),p.length===0?t.jsx("p",{className:"muted",children:"No conversation is recorded for this file. It may date from before the library kept track."}):t.jsx("ul",{className:"files-ctx",role:"list",children:p.map(x=>{const y=x.groupId?xi(x.groupId,x.conversationId):Ze(x.conversationAgentId,x.conversationId),w=x.groupId?x.groupName??"a group":f(x.conversationAgentId);return t.jsxs("li",{className:"files-ctx-row",children:[t.jsxs("span",{className:"files-ctx-text",children:[t.jsx("span",{children:x.groupId?`Group: ${w}`:w}),t.jsxs("span",{className:"muted",children:[" · ",x.kind==="produced"?`made by ${f(x.agentId)||"an agent"}`:x.kind==="reused"?"sent again":"sent by you"," · ",Ve(x.at)]})]}),t.jsx("a",{className:"ui-btn","data-size":"sm",href:y,onClick:k=>{k.preventDefault(),r(y)},children:"Open conversation"})]},`${x.conversationId}:${x.kind}`)})}),p.length<g?t.jsx(te,{align:"end",children:t.jsx(A,{size:"sm",onClick:j,disabled:o,children:o?"Loading…":`Show ${g-p.length} more`})}):null]})]})}const tV={mail:"mail",money:"money",calendar:"calendar",people:"agents",file:"files",chart:"chart",bell:"bell",plug:"plug",key:"key",globe:"globe",sun:"sun",cloud:"cloud",news:"news"};function fR(e){return e&&tV[e]||"plug"}const mR="buddi.keepClose";let Zl=null;const dv=new Set;function hv(){for(const e of dv)e()}typeof window<"u"&&(window.addEventListener("beforeinstallprompt",e=>{e.preventDefault(),Zl=e,hv()}),window.addEventListener("appinstalled",()=>{Zl=null,fw(),hv()}));function lm(){const[e,n]=h.useState(Zl);return h.useEffect(()=>{const s=()=>n(Zl);return dv.add(s),s(),()=>{dv.delete(s)}},[]),pR()?null:e}async function hw(e){try{await e.prompt();const n=await e.userChoice;Zl===e&&(Zl=null);const s=(n==null?void 0:n.outcome)==="accepted";return s&&fw(),hv(),s}catch{return!1}}function nV(){try{return window.localStorage.getItem(mR)!==null}catch{return!1}}function fw(){try{window.localStorage.setItem(mR,"dismissed")}catch{}}function pR(){var e;try{return((e=window.matchMedia)==null?void 0:e.call(window,"(display-mode: standalone)").matches)??!1}catch{return!1}}function sV(e=window.location.hostname){const n=e.replace(/^\[|\]$/g,"").toLowerCase();return n==="127.0.0.1"||n==="::1"||n==="localhost"}function gR(e){return/Edg\//.test(e)?"In Edge, choose Apps → Install buddi from the … menu.":/(Chrome|CriOS)\//.test(e)?"In Chrome, click the install icon in the address bar.":/Safari\//.test(e)&&/Mac/.test(e)?"In Safari, choose File → Add to Dock.":null}function rV(e){return/Mac|iPhone|iPad/.test(e)}function aV(){const e=lm(),[n,s]=h.useState(nV);if(n||!e)return null;const r=()=>{fw(),s(!0)};return t.jsxs("div",{className:"home-install",role:"region","aria-label":"Install buddi",children:[t.jsx("p",{className:"home-install-text",children:"Install buddi as an app, one click from your dock."}),t.jsxs(te,{align:"end",children:[t.jsx(A,{size:"sm",variant:"ghost",onClick:r,children:"Not now"}),t.jsx(A,{size:"sm",variant:"accent",onClick:()=>{hw(e).then(a=>{a&&s(!0)})},children:"Install"})]})]})}function iV(){const e=lm(),[n,s]=h.useState(void 0),[r]=h.useState(pR);if(h.useEffect(()=>{if(r)return;let o=!0;return R.session().then(c=>{o&&s(c.platform)},()=>{}),()=>{o=!1}},[r]),r)return null;const a=typeof navigator>"u"?"":navigator.userAgent,i=sV(),l=e?null:gR(a);return t.jsx(ue,{title:"The dashboard as an app",panel:!0,foot:e?t.jsx(te,{align:"end",children:t.jsx(A,{variant:"accent",onClick:()=>{hw(e)},children:"Install the app"})}):void 0,children:t.jsxs(ie,{children:[t.jsxs("p",{children:[e?"This browser can install buddi as an app: its own window, the Blob as its icon. ":l?`${l} `:null,"Or bookmark it with ",rV(a)?"⌘D":"Ctrl+D",".",i?null:" This tailnet address installs as its own app, separate from the one on the machine buddi runs on."]}),i&&n==="darwin"?t.jsxs("p",{children:["On this Mac, ",t.jsx("span",{className:"mono",children:"buddi dashboard --install-app"})," puts a double-clickable app in ~/Applications that signs you in each time it opens (docs/cli.md, under Everyday)."]}):null]})})}const lV=""+new URL("earth-2560-Ce3xs8Cb.webp",import.meta.url).href,oV=""+new URL("earth-phone-BqC7cDhk.webp",import.meta.url).href,cV="data:image/webp;base64,UklGRloGAABXRUJQVlA4IE4GAADQKgCdASrAAJAAPpVInUolpKmtqTe6EbASiUdvknkVpMHex+cfn6FpYp/9uZP+p3tPRfzQ/Vd/Sej/8/++pP8bkmkrujVcbfosAWVvo98GPJDgcpdpkar6crJ+OUcccXvyduwiVqZIt11sMX//3JP2wugWcHYMSjhNfw/YXfPBz7/+f4KsYSTyT6uayU6+fROo0TO6X4IyHrF+l6toP//txS0FMPUdRtJ6p+KCT2dP3gpLomT/wObriNY+VMOA0Zv+Tv48yM6/mEHjtXwfON8gBTL8RqQm7vROt+4EPvqHCsf6f1vUb+PxZm8Y0/H4GI68rdhftV4yy/CoatiRgTrzW8ekWPCSt9eJvusnrXMcJruQHwSz5/vX9vG8C1y5aeF5l34kChCD3TSgQUw9kBS9sQ1NbMi1pMKuJqUEgiZd/2y+wAjF/DOKI3FZHBa5Q2qCooTfUj9A0XCixL3kuiAA/vqtztWnhuK0AAUKVrOx4/8K6IntNvzYOatrdU3xfr4QYYAHyIAAE90qDuxwvNSaslOgj1XzeQ7o4CiG+WFb4zwdPY6lyVxnN49hB6ipRsqQgAGt1TM/WHRmZXsFqcgHgXvLRO/p+gY76bpHJq4QeDFM3Q6tVUsq12eA8xdt9XMl/j2W0PHmipASSSIaS5KLMTjz4jtZfUwqTOj0emDBJw60TFqwI7jSvw3mbEwxxbojRIHLx6DfSdsFdhjJvJMS7fn0N+lA61ZOdS0OwUdd69Dt/YuIccchkuSR0QX9woaHISeHgXHlRAF2XLwciGQqbLIy9BogJ/4g+AKroStuCVhcYugjGC2gxUtl2UrwpIDcHI1ccHnGLv68wJ5AAfOSAKcV1RtS2UUbfSRLCnU6xoa6KmV/rAxptF6OJf8GfEOtKNwm6VddtwyPoa9muhJGhR/j6ruJ/kFnMRNLH7WcXtQIhNlVo8xRvRaoH9RGwIfvhwAigF4zejYm1wAynQhgR7ecE/15lbKTsTBb8Y9fEc9zNmZZgMzlto8cNZj+0+k1TTQ0wmrRktZ299Sqko1Ov4yDQRP0iKSe/g8XpiHowGqR5N0lsvJeEojijafpSRp0k3G59maRyl+1LsIb5YW8WfgFHbtRtYszt39yl7EPwLfsYwXOWqPwg0IVemW8v5CMln54J4c9m95OIxJHYL7cQTzWyrY8qgaxhR5vtr+NJyiQTlKN31r1xeJhCmJZKtY9OIGzesGUOdmetfh1jmfh5YtwdxOG900hLMD4vv1jYXAng8YZpjDTRUcuUrlYiO+BtcbnuIUA9SVRzFAdwReo1Rry/Sm7lNWjORAVT0B4dXzkfjv/+SykUdSAYx2evoGEJeUFqXPQt16XiwAduftyvFBUlNVwP8bZv+Hg3wueDwbUZYgaHM2qC7CJdIdf4uB9elmZViV9gssG5C8+Vk1BCJoqMasH9cFJcYjqlpDSWtZ5XcTreCV+dBwxHKh/IfqUOmZWnvYIE6xQ0YlVMc2CZuriPdRDQEoKjgMZ67X1f7XsanRDwL3attVpj5zWBRiXYdoGzt/O4w9zk/qCWUbZyy7ik+prantqxCiKAbRE7jZhTXFGprni/fldU5v5vRozeswfGCVXQzQpmjEMJA5uV4eB1w0ooNYM+ZV9yo/rqYIfhQHnzn3N7N44UBzZl6EI7806lpMMDZMk2Vd7aTc7dapectSczJ1D9mZ0MKvd0Skg1Euq1uGwQNEu1ANTFFUYIOmREj8d3vYHkWlhmuiTLKbQxl4CgDYk4vH6kA9iGe43Mo5BF4WoiQ6OqRJTxel29R6Yc/FWmw/enfMaPdyWgKnVSn6TSLoPcgJ6lu1pd39McpTo92Aw0czVjUXTcdSL3c38q4YyOdJkv6sw+FeXr/DOXP3S3xXjo7SMXD2UED68pQEVkjf4SaSqWUarBkeacGOlssJDsoVFm46XleiI+Ug9j+hAVyLDPKsLDo+8qrFgcEexTGjmonZnow0nKD80SpF+KbZD78vfc4MJN2F5ZhWC+mDVgv6Bj8kTD6MGV+6YllFA/AdnvTw+idzBKLNTYe7PEcq2AWNOAog/43qtjJQbAdxGkS8KewzmlpTP4KIuDoynjBuqv9Y6PR+nv2IZpWyNvqTUkqiFJnCQI/XKogTppN/pcEAOJ+XFqAA=",fv={desk:lV,phone:oV,thumb:cV},Pp={author:"ActionVance",authorUrl:"https://unsplash.com/@actionvance",photoUrl:"https://unsplash.com/photos/outer-space-photography-of-earth-t7EL2iG3jMc"};function uV(e){return e?fv.phone:fv.desk}function xR(){const[e,n]=h.useState(()=>new Date);return h.useEffect(()=>{let s;const r=()=>{s=setTimeout(()=>{n(new Date),r()},6e4-Date.now()%6e4+50)};return r(),()=>clearTimeout(s)},[]),e}const dV=3,vR=8e3,hV={hiddenHere:new Set,restoredHere:new Set};function fV(e,n){return n.hiddenHere.has(e.id)?!0:e.hidden&&!n.restoredHere.has(e.id)}function mV(e,n=hV){return(e??[]).filter(s=>!fV(s,n)).slice(0,dV)}function jR(e){const[n,s]=h.useState(new Set),[r,a]=h.useState(new Set),[i,l]=h.useState(null),o=h.useRef(e);o.current=e;const c=(m,p)=>new Set(m).add(p),u=(m,p)=>{const g=new Set(m);return g.delete(p),g};return h.useEffect(()=>{if(!i)return;const m=window.setTimeout(()=>l(null),vR);return()=>window.clearTimeout(m)},[i]),{hiddenHere:n,restoredHere:r,justHidden:i,hide:(m,p)=>{s(g=>c(g,m.id)),a(g=>u(g,m.id)),l({glance:m,spot:p}),R.setGlanceHidden(m.id,!0).then(()=>{var g;return(g=o.current)==null?void 0:g.call(o)},()=>{s(g=>u(g,m.id)),l(g=>(g==null?void 0:g.glance.id)===m.id?null:g)})},undo:()=>{if(!i)return;const{glance:m}=i;l(null),s(p=>u(p,m.id)),a(p=>c(p,m.id)),R.setGlanceHidden(m.id,!1).then(()=>{var p;return(p=o.current)==null?void 0:p.call(o)},()=>{a(p=>u(p,m.id)),s(p=>c(p,m.id))})}}}function pV({hiding:e,spot:n}){const s=e.justHidden;return!s||s.spot!==n?null:t.jsxs("span",{className:"home-glance-undo",role:"status","aria-live":"polite","data-spot":n,children:[t.jsxs("span",{children:[s.glance.title," hidden"]}),t.jsx("span",{className:"home-glance-sep","aria-hidden":"true",children:"·"}),t.jsx(A,{size:"sm",variant:"ghost",onClick:e.undo,children:"Undo"})]})}function gV(e){return e.link?Uy(e.link.plugin,e.link.page,e.link.place):null}function xV({glances:e,navigate:n,onChanged:s,except:r,hiding:a}){var u,d;const i=jR(s),l=a??i,o=mV(e,l).filter(f=>!(r!=null&&r.has(f.id))),c=t.jsx(pV,{hiding:l,spot:"line"});return o.length===0&&((u=l.justHidden)==null?void 0:u.spot)!=="line"?null:t.jsxs("span",{className:"home-glances",children:[((d=l.justHidden)==null?void 0:d.spot)==="line"?t.jsxs("span",{className:"home-glance",children:[t.jsx("span",{className:"home-glance-sep","aria-hidden":"true",children:"·"}),c]}):null,o.map(f=>{const m=gV(f),p=t.jsxs(t.Fragment,{children:[t.jsx(le,{name:bo(f.icon),size:14}),t.jsx("span",{children:f.text})]});return t.jsxs("span",{className:"home-glance",children:[t.jsx("span",{className:"home-glance-sep","aria-hidden":"true",children:"·"}),m?t.jsx("a",{className:"home-glance-text",href:m,onClick:g=>{g.preventDefault(),n(m)},children:p}):t.jsx("span",{className:"home-glance-text",children:p}),t.jsx("button",{type:"button",className:"home-glance-hide","aria-label":`Hide ${f.title} from Home`,title:"Hide from Home",onClick:()=>l.hide(f,"line"),children:t.jsx(le,{name:"close",size:10})})]},f.id)})]})}function vV(e){const a=Math.min(...e),l=Math.max(...e)-a||1,o=Math.max(e.length-1,1);return e.map((c,u)=>[u/o*100,2+(1-(c-a)/l)*(24-2*2)])}function jV({points:e,className:n="wg-spark"}){const s=vV(e).map(([r,a])=>`${r.toFixed(1)},${a.toFixed(1)}`);return t.jsxs("svg",{className:n,viewBox:"0 0 100 24",preserveAspectRatio:"none","aria-hidden":"true","data-testid":"spark",children:[t.jsx("path",{d:`M0,24 L${s.join(" L")} L100,24 Z`,fill:"currentColor",opacity:"0.12",stroke:"none"}),t.jsx("polyline",{points:s.join(" "),fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",vectorEffect:"non-scaling-stroke"})]})}const ul=Math.PI/180;function yV(e,n,s){const r=e.getTime()/864e5+24405875e-1-2451545,a=(357.529+.98560028*r)*ul,l=(280.459+.98564736*r+1.915*Math.sin(a)+.02*Math.sin(2*a))*ul,o=(23.439-36e-8*r)*ul,c=Math.atan2(Math.cos(o)*Math.sin(l),Math.cos(l)),u=Math.asin(Math.sin(o)*Math.sin(l)),f=((18.697374558+24.06570982441908*r)*15+s)*ul-c,m=n*ul,p=Math.sin(m)*Math.sin(u)+Math.cos(m)*Math.cos(u)*Math.cos(f);return Math.asin(Math.max(-1,Math.min(1,p)))/ul}function wV(e,n,s){return yV(e,n,s)>-.833}const bV={small:2,medium:4},EN=new Map;function kV(e){let n=EN.get(e);return n||(n=new Intl.DateTimeFormat("en-US",{timeZone:e,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hourCycle:"h23"}),EN.set(e,n)),n}function AN(e,n){const s=Object.fromEntries(kV(n).formatToParts(e).map(l=>[l.type,l.value])),r=Number(s.hour)%24,a=Number(s.minute),i=Date.UTC(Number(s.year),Number(s.month)-1,Number(s.day),r,a);return{date:`${s.year}-${s.month}-${s.day}`,h:r,m:a,s:Number(s.second),offset:Math.round((i-Math.floor(e.getTime()/6e4)*6e4)/6e4)}}function NV(e){if(e===0)return"Same time";const n=Math.floor(Math.abs(e)/60),s=Math.abs(e)%60;return`${e>0?"+":"−"}${n===0?`${s} min`:s===0?`${n} h`:`${n} h ${s}`}`}function SV(e){if(e===0)return"same time";const n=Math.floor(Math.abs(e)/60),s=Math.abs(e)%60;return`${[n?`${n} hour${n===1?"":"s"}`:"",s?`${s} minute${s===1?"":"s"}`:""].filter(Boolean).join(" ")} ${e>0?"ahead":"behind"}`}function CV(e,n,s,r,a){const i=AN(e,n.zone),l=AN(e,s),o=i.date===l.date?"Today":i.date>l.date?"Tomorrow":"Yesterday",c=i.offset-l.offset,u=mu(a?{timeFormat:a}:{},()=>Xt(e,n.zone)),d=r?"your time":SV(c);return{...i,day:o,daytime:typeof n.latitude=="number"&&typeof n.longitude=="number"?wV(e,n.latitude,n.longitude):i.h>=6&&i.h<18,offsetText:r?"Here":NV(c),time:u,label:`${n.label}, ${u}${o==="Today"?"":` ${o.toLowerCase()}`}, ${d}`}}function EV(e,n){const s=n?e.s:0;return{hour:(e.h%12+e.m/60+s/3600)*30,minute:(e.m+s/60)*6,second:n?e.s*6:null}}function AV(e){const[n,s]=h.useState(()=>new Date);return h.useEffect(()=>{const r=e?1e3:6e4;let a;const i=()=>{a=setTimeout(()=>{s(new Date),i()},r-Date.now()%r+5)};return s(new Date),i(),()=>clearTimeout(a)},[e]),n}function $N({angle:e,length:n,width:s}){return t.jsxs("g",{className:"wg-clock-hand",transform:`rotate(${e} 50 50)`,children:[t.jsx("line",{x1:"50",y1:"50",x2:"50",y2:"42",strokeWidth:Math.min(s,1.8)}),t.jsx("line",{x1:"50",y1:"42",x2:"50",y2:50-n,strokeWidth:s})]})}const $V=Array.from({length:12},(e,n)=>n);function TV({time:e,seconds:n}){const s=EV(e,n);return t.jsxs("svg",{className:"wg-clock-face",viewBox:"0 0 100 100","aria-hidden":"true",focusable:"false",children:[t.jsx("circle",{className:"wg-clock-dial",cx:"50",cy:"50",r:"49.25"}),$V.map(r=>t.jsx("line",{className:"wg-clock-tick","data-major":r%3===0?"true":void 0,x1:"50",y1:r%3===0?6.5:7.5,x2:"50",y2:r%3===0?14:12,transform:`rotate(${r*30} 50 50)`},r)),t.jsx($N,{angle:s.hour,length:24,width:4.6}),t.jsx($N,{angle:s.minute,length:37,width:3.4}),s.second===null?null:t.jsx("g",{className:"wg-clock-second","data-testid":"second-hand",transform:`rotate(${s.second} 50 50)`,children:t.jsx("line",{x1:"50",y1:"59",x2:"50",y2:"9"})}),t.jsx("circle",{className:"wg-clock-pin",cx:"50",cy:"50",r:"2.8"}),s.second===null?null:t.jsx("circle",{className:"wg-clock-pin-second",cx:"50",cy:"50",r:"1.5"})]})}function RV({body:e,size:n}){const s=ws("(prefers-reduced-motion: reduce)"),r=AV(!s),a=e.clocks.slice(0,bV[n]);return t.jsx("div",{className:"wg-clocks","data-count":a.length,children:a.map((i,l)=>{let o;try{o=CV(r,i,e.home,l===0&&i.zone===e.home,e.time)}catch{return null}return t.jsxs("div",{className:"wg-clock","data-night":o.daytime?void 0:"true",role:"img","aria-label":o.label,title:`${i.label} · ${o.time}`,children:[t.jsx(TV,{time:o,seconds:!s}),t.jsxs("span",{className:"wg-clock-words","aria-hidden":"true",children:[t.jsx("span",{className:"wg-clock-city",children:i.label}),t.jsx("span",{className:"wg-clock-day","data-today":o.day==="Today"?"true":void 0,children:o.day}),t.jsx("span",{className:"wg-clock-off",children:o.offsetText})]})]},`${i.label}-${i.zone}`)})})}const Mp=3,IV={small:4,medium:6};function Dp({icon:e,size:n}){return e?t.jsx("span",{className:"wg-icon",children:t.jsx(le,{name:bo(e),size:n})}):null}function om({body:e,size:n}){switch(e.kind){case"stat":return t.jsxs(t.Fragment,{children:[t.jsxs("span",{className:"wg-stat-now",children:[t.jsx(Dp,{icon:e.icon,size:24}),t.jsx("span",{className:"wg-value",children:e.value})]}),e.caption?t.jsx("span",{className:"wg-caption",children:e.caption}):null,t.jsx("span",{className:"wg-push"}),e.trend?t.jsxs("span",{className:"wg-trend",children:[t.jsx(jV,{points:e.trend.points,className:"wg-spark"}),e.trend.label?t.jsx("span",{children:e.trend.label}):null]}):null,e.foot?t.jsx("span",{className:"wg-foot",children:e.foot}):null]});case"list":{const s=e.rows.slice(0,Math.min(e.max??Mp,n==="medium"?5:Mp));return t.jsxs(t.Fragment,{children:[t.jsx("ul",{className:"wg-list","data-dense":s.length>Mp?"true":void 0,"data-wrap":e.wrap?"true":void 0,children:s.map((r,a)=>t.jsxs("li",{className:"wg-row","data-marked":r.image?"true":void 0,children:[r.image?t.jsx(No,{className:"wg-mark",src:rT(r.image.src)?r.image.src:null,label:r.image.label??r.title}):null,t.jsxs("span",{className:"wg-row-text",children:[t.jsx("span",{className:"wg-row-title",children:r.title}),r.sub&&n==="medium"?t.jsx("span",{className:"wg-row-sub",children:r.sub}):null]}),r.side?t.jsx("span",{className:"wg-row-side","data-tone":r.tone,children:r.side}):null]},`${r.title}-${a}`))}),t.jsx("span",{className:"wg-push"}),e.more?t.jsx("span",{className:"wg-foot",children:e.more}):null]})}case"strip":return t.jsxs(t.Fragment,{children:[t.jsxs("span",{className:"wg-strip-head",children:[t.jsx(Dp,{icon:e.icon,size:20}),e.value?t.jsx("span",{className:"wg-strip-value",children:e.value}):null,e.caption?t.jsx("span",{className:"wg-caption",children:e.caption}):null]}),t.jsx("span",{className:"wg-push"}),t.jsx("span",{className:"wg-strip",children:e.items.slice(0,IV[n]).map((s,r)=>t.jsxs("span",{className:"wg-tile",children:[t.jsx("span",{className:"wg-tile-label",children:s.label}),t.jsx(Dp,{icon:s.icon,size:18}),t.jsx("span",{className:"wg-tile-value",children:s.value})]},`${s.label}-${r}`))})]});case"progress":{const s=Math.round(Math.max(0,Math.min(1,e.ratio))*100);return t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"wg-value",children:e.value}),e.caption?t.jsx("span",{className:"wg-caption",children:e.caption}):null,t.jsx("span",{className:"wg-push"}),t.jsx("span",{className:"ui-meter",role:"meter","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":s,"aria-label":e.caption??e.value,children:t.jsx("span",{className:"ui-meter-fill","data-tone":e.tone,style:{inlineSize:`${s}%`}})}),e.foot?t.jsx("span",{className:"wg-foot",children:e.foot}):null]})}case"clocks":return t.jsx(RV,{body:e,size:n});case"text":return t.jsxs("span",{className:"wg-text",children:[e.icon?t.jsx("span",{className:"wg-text-icon",children:t.jsx(le,{name:bo(e.icon),size:18})}):null,t.jsxs("span",{className:"wg-text-words",children:[t.jsx("span",{className:"wg-text-main",children:e.text}),e.sub?t.jsx("span",{className:"wg-row-sub",children:e.sub}):null]})]})}}function mv({label:e,options:n,multiple:s,value:r,onChange:a}){const i=Array.isArray(r)?r:[r],l=c=>i.includes(c),o=c=>{if(!s)return a(c);a(l(c)?i.filter(u=>u!==c):[...i,c])};return t.jsx("div",{className:"wg-options",role:s?"group":"radiogroup","aria-label":e,children:n.map(c=>t.jsxs("button",{type:"button",role:s?"checkbox":"radio","aria-checked":l(c.value),className:"wg-option","data-on":l(c.value)?"true":void 0,onClick:()=>o(c.value),children:[t.jsx("span",{className:"wg-option-mark","data-multiple":s?"true":void 0,"aria-hidden":"true",children:s&&l(c.value)?t.jsx(le,{name:"check",size:12}):null}),t.jsxs("span",{className:"wg-option-text",children:[t.jsx("span",{className:"wg-option-name",children:c.label}),c.sub?t.jsx("span",{className:"wg-option-sub",children:c.sub}):null]})]},c.value))})}function TN(e){return"place"in e?e.place:`town:${e.latitude.toFixed(3)},${e.longitude.toFixed(3)}`}function PV(e){var n;return{label:((n=e.name.split(",")[0])==null?void 0:n.trim())||e.name,name:e.name,latitude:e.latitude,longitude:e.longitude,timezone:e.timezone??null}}function MV({field:e,value:n,places:s,onChange:r}){const a=Array.isArray(n)?n:n?[n]:[],[i,l]=h.useState(""),[o,c]=h.useState([]),[u,d]=h.useState(!1),[f,m]=h.useState(null),p=new Map;for(const w of s)p.set(w.id,{value:{place:w.id},label:w.label,sub:w.name});for(const w of[...a,...o])"place"in w||p.set(TN(w),{value:w,label:w.label,sub:w.name});const g=[...p.entries()].map(([w,k])=>({value:w,label:k.label,sub:k.sub})),v=a.map(TN),b=s.find(w=>w.id==="home"||w.label.toLowerCase()==="home")??s[0],j=e.multiple?v:v[0]??(b==null?void 0:b.id)??"",x=w=>{const k=(Array.isArray(w)?w:[w]).map(N=>{var S;return(S=p.get(N))==null?void 0:S.value}).filter(N=>!!N);r(e.multiple?k.slice(-3):k[0]??null)},y=()=>{const w=i.trim();w.length<2||(d(!0),m(null),R.findPlace(w).then(({found:k})=>{const N=k.slice(0,3).map(PV);c(N),N.length===0?m(`Nothing found for “${w}”.`):e.multiple?r([...a,N[0]].slice(-3)):r(N[0])}).catch(()=>m("The place finder didn’t answer. Try again in a moment.")).finally(()=>d(!1)))};return t.jsxs("div",{className:"wg-field-stack",children:[g.length>0?t.jsx(mv,{label:e.label,options:g,multiple:e.multiple,value:j,onChange:x}):null,t.jsxs("div",{className:"wg-find",children:[t.jsx("input",{value:i,placeholder:"Find a town: Tokyo","aria-label":`Find a town for ${e.label}`,onChange:w=>l(w.target.value),onKeyDown:w=>{w.key==="Enter"&&(w.preventDefault(),y())}}),t.jsx(A,{size:"sm",disabled:u||i.trim().length<2,onClick:y,children:u?"Finding…":"Find"})]}),f?t.jsx("span",{className:"ui-field-hint",children:f}):null]})}function DV({field:e,value:n,sheet:s,onChange:r}){var i;let a;switch(e.kind){case"select":{const l=e.options??[],o=typeof n=="string"?n:e.default??((i=l[0])==null?void 0:i.value)??"",c=l.length>0&&l.length<=3&&l.every(u=>u.label.length<=14);a=l.length===0?t.jsx("span",{className:"ui-field-hint",children:"Nothing to choose from yet."}):c?t.jsx(ln,{label:e.label,options:l,value:o,onChange:r}):t.jsx(mv,{label:e.label,options:l,value:o,onChange:r});break}case"multiselect":{const l=e.options??[];a=l.length===0?t.jsx("span",{className:"ui-field-hint",children:"Nothing to choose from yet."}):t.jsx(mv,{label:e.label,options:l,multiple:!0,value:Array.isArray(n)?n:e.default??[],onChange:r});break}case"toggle":return t.jsxs("div",{className:"wg-field",children:[t.jsxs("label",{className:"wg-toggle",children:[t.jsx("input",{type:"checkbox",checked:typeof n=="boolean"?n:e.default??!1,onChange:l=>r(l.target.checked)}),t.jsx("span",{children:e.label})]}),e.hint?t.jsx("span",{className:"ui-field-hint",children:e.hint}):null]});case"text":a=t.jsx("input",{"aria-label":e.label,value:typeof n=="string"?n:e.default??"",maxLength:e.max??60,placeholder:e.placeholder,onChange:l=>r(l.target.value)});break;case"place":a=t.jsx(MV,{field:e,value:n,places:s.places,onChange:r});break;case"timeFormat":a=t.jsx(ln,{label:e.label,options:[{value:"profile",label:ZE()},{value:"12h",label:"12-hour"},{value:"24h",label:"24-hour"}],value:n==="12h"||n==="24h"?n:"profile",onChange:r});break}return t.jsxs("div",{className:"wg-field",role:"group","aria-label":e.label,children:[t.jsx("span",{className:"wg-field-label",children:e.label}),a,e.hint?t.jsx("span",{className:"ui-field-hint",children:e.hint}):null]})}function OV({info:e,placement:n,surface:s,view:r,label:a}){var u;const i=s==="lock",l=((u=r==null?void 0:r.body)==null?void 0:u.kind)==="text",o=i&&(l||n.size==="small")?"small":n.size,c=r?r.body?e.sensitive?t.jsxs("span",{className:"wg-state",children:[t.jsx("span",{className:"wg-mask","aria-hidden":"true",children:"••••"}),t.jsx("span",{className:"wg-state-sub",children:"Hidden on this screen."})]}):t.jsx(om,{body:r.body,size:o}):t.jsx("span",{className:"wg-state",children:t.jsx("span",{className:"wg-state-sub",children:r.state==="error"?`Couldn't load this${r.error?`: ${r.error}`:""}.`:"Nothing to show right now."})}):t.jsxs("span",{className:"wg-skel-body","aria-hidden":"true",children:[t.jsx("span",{className:"wg-skel","data-w":"half"}),t.jsx("span",{className:"wg-skel","data-w":"third"}),t.jsx("span",{className:"wg-push"}),t.jsx("span",{className:"wg-skel"})]});return t.jsx("div",{className:"wg-preview","data-surface":s,"aria-label":`Preview of ${a}`,role:"img",children:t.jsxs("div",{className:"wg-frame","data-size":o,"data-variant":i?"compact":void 0,"data-kind":r!=null&&r.body&&!e.sensitive?r.body.kind:void 0,"aria-hidden":"true",children:[i?null:t.jsx("div",{className:"wg-head",children:t.jsx("span",{className:"wg-title",children:a})}),t.jsx("div",{className:"wg-body",children:c}),i?t.jsx("span",{className:"wg-compact-title",children:a}):null]})})}function yR({info:e,placement:n,surface:s,onSave:r,onRemove:a,onClose:i}){const l=me(()=>R.widgetSettings(e.id),[e.id]),[o,c]=h.useState(n.settings??{}),[u,d]=h.useState(null),[f,m]=h.useState(n.label??e.title),[p,g]=h.useState(!1),[v,b]=h.useState(null),j=h.useRef(0),x=h.useMemo(()=>JSON.stringify(o),[o]);h.useEffect(()=>{const k=++j.current,N=window.setTimeout(()=>{R.previewWidget({widget:e.id,size:n.size,settings:o}).then(S=>{k===j.current&&(d(S.view),m(S.label))}).catch(()=>{k===j.current&&d({state:"error",error:"the preview could not be made"})})},u?250:0);return()=>window.clearTimeout(N)},[x,e.id,n.size]);const y=()=>{g(!0),b(null),r(o).then(k=>{g(!1),k||b("Couldn’t keep these settings. Try again.")})},w=s==="lock"?"the lock screen":"Home";return t.jsx(Ge,{title:f,onClose:i,foot:t.jsxs(te,{children:[t.jsxs(A,{variant:"danger-ghost",onClick:a,children:["Remove from ",s==="lock"?"lock screen":"Home"]}),t.jsx(et,{}),t.jsx(A,{variant:"ghost",onClick:i,children:"Cancel"}),t.jsx(A,{variant:"accent",onClick:y,disabled:p||!l.data,children:p?"Saving…":"Save"})]}),children:t.jsxs("div",{className:"wg-sheet",children:[t.jsx(OV,{info:e,placement:n,surface:s,view:u,label:f}),t.jsxs("p",{className:"wg-sheet-note",children:[e.builtIn?"Built in":`From the ${e.plugin} plugin`," · on ",w,". These settings are this one’s own",s==="lock"?"; Home keeps its own":"","."]}),t.jsx(ne,{message:v??(l.error?"Couldn’t read this widget’s settings.":null)}),l.data?l.data.fields.map(k=>t.jsx(DV,{field:k,value:o[k.key],sheet:l.data,onChange:N=>c({...o,[k.key]:N})},k.key)):l.error?null:t.jsx("p",{className:"wg-sheet-note","aria-busy":"true",children:"Reading its choices…"})]})})}const LV=6e4,wR="buddi.clock",bR="buddi.home.widgets";function FV(){try{const e=Number(window.localStorage.getItem(bR));return Number.isInteger(e)&&e>0?Math.min(e,6):0}catch{return 0}}function _V(e){try{window.localStorage.setItem(bR,String(e))}catch{}}function kR(){const e=new Uint8Array(4);return crypto.getRandomValues(e),`w-${Array.from(e,n=>n.toString(16).padStart(2,"0")).join("")}`}function NR(e,n){const s=h.useRef(n);s.current=n,h.useEffect(()=>{if(!e)return;let r;const a=()=>{r=setTimeout(()=>{s.current(),a()},6e4-Date.now()%6e4+1e3)};return a(),()=>clearTimeout(r)},[e])}function zV(){const e=me(()=>R.widgets("home"),[],LV),[n,s]=h.useState(void 0);return h.useEffect(()=>{e.data&&s(e.data)},[e.data]),h.useEffect(()=>{n&&_V(n.home.length)},[n]),NR((n==null?void 0:n.home.some(r=>{var a,i;return r.widget===wR&&((i=(a=n.views[r.key])==null?void 0:a.body)==null?void 0:i.kind)!=="clocks"}))??!1,e.reload),{answer:n,error:e.error,apply:s,reload:e.reload}}function UV(e){return new Set(((e==null?void 0:e.home)??[]).map(n=>n.widget))}function BV(e){const[n,s]=h.useState(!1);return h.useEffect(()=>{if(!e||!n)return;const r=()=>{(document.visibilityState==="hidden"||!document.hasFocus())&&s(!1)};return document.addEventListener("visibilitychange",r),window.addEventListener("blur",r),()=>{document.removeEventListener("visibilitychange",r),window.removeEventListener("blur",r)}},[e,n]),[n,s]}const SR=(e,n)=>e.label??(n==null?void 0:n.title)??e.widget;function WV({info:e,placement:n,view:s,index:r,count:a,editing:i,navigate:l,act:o,onRetry:c,retrying:u,drag:d}){var S;const[f,m]=BV(e.sensitive===!0),p=(s==null?void 0:s.state)??"error",g=e.sensitive===!0&&!f,v=e.link?Uy(e.link.plugin,e.link.page,e.link.place):null,b=v!==null&&!i&&p!=="error"&&!g,j=n.size==="small"?"medium":"small",x=SR(n,e),y=n.key,w=(((S=e.settings)==null?void 0:S.length)??0)>0;let k;!s&&i?k=t.jsx("span",{className:"wg-state",children:t.jsx("span",{className:"wg-state-sub",children:"Fills in when you press Done."})}):p==="error"||!s?k=t.jsxs("span",{className:"wg-state",children:[t.jsx("span",{className:"wg-state-title",children:"Couldn't load this."}),s!=null&&s.error?t.jsxs("span",{className:"wg-state-sub",children:[HV(s.error),"."]}):null,i?null:t.jsx(A,{size:"sm",onClick:c,disabled:u,children:u?"Trying…":"Try again"})]}):p==="empty"||!s.body?k=t.jsx("span",{className:"wg-state",children:t.jsx("span",{className:"wg-state-sub",children:"Nothing to show right now."})}):g?k=t.jsxs("span",{className:"wg-state",children:[t.jsx("span",{className:"wg-mask","aria-hidden":"true",children:"••••"}),t.jsx("span",{className:"wg-state-sub",children:"Hidden on this screen."}),i?null:t.jsx(A,{size:"sm",onClick:()=>m(!0),children:"Show"})]}):k=t.jsx(om,{body:s.body,size:n.size});const N=C=>{C.dataTransfer.effectAllowed="move",C.dataTransfer.setData("text/plain",y),d.start(y)};return t.jsxs("div",{className:"wg-frame",role:"group","aria-label":x,"data-id":e.id,"data-key":y,"data-size":n.size,"data-kind":s!=null&&s.body&&!g&&p!=="error"?s.body.kind:void 0,"data-state":p==="ok"?void 0:p,"data-linked":b?"true":void 0,"data-dragging":d.dragging===y?"true":void 0,"data-over":d.over===y&&d.dragging!==y?"true":void 0,draggable:i?!0:void 0,onDragStart:i?N:void 0,onDragOver:i?C=>{d.dragging&&(C.preventDefault(),d.enter(y))}:void 0,onDrop:i?C=>{C.preventDefault(),d.drop(y)}:void 0,onDragEnd:i?()=>d.end():void 0,children:[t.jsxs("div",{className:"wg-head",children:[i?t.jsx("button",{type:"button",className:"ui-icon-btn wg-grip","data-size":"sm","data-grip":y,"aria-label":`Move ${x}, position ${r+1} of ${a}: arrow keys`,title:"Drag, or use the arrow keys",onKeyDown:C=>{(C.key==="ArrowLeft"||C.key==="ArrowUp")&&(C.preventDefault(),o("earlier")),(C.key==="ArrowRight"||C.key==="ArrowDown")&&(C.preventDefault(),o("later"))},children:t.jsx(le,{name:"grip",size:14})}):null,t.jsx("span",{className:"wg-title",children:x}),p==="stale"?t.jsx("span",{className:"wg-stale",title:s!=null&&s.error?`Couldn't refresh: ${s.error}.`:void 0,children:s!=null&&s.updatedAt?`${Zj(s.updatedAt)} old`:"Not current"}):null,i&&w?t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":`Settings for ${x}`,title:"Settings",onClick:()=>o("settings"),children:t.jsx(le,{name:"settings",size:14})}):null,i?t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":`Take ${x} off Home`,title:"Take off Home",onClick:()=>o("hide"),children:t.jsx(le,{name:"close",size:12})}):t.jsx("span",{className:"wg-more",children:t.jsx(Rs,{label:`More for ${x}`,note:s!=null&&s.updatedAt?`${e.builtIn?"Built in":e.plugin} · ${Ve(s.updatedAt)}`:e.builtIn?"Built in":e.plugin,items:[w?{label:"Settings…",onSelect:()=>o("settings")}:null,r>0?{label:"Move earlier",onSelect:()=>o("earlier")}:null,r<a-1?{label:"Move later",onSelect:()=>o("later")}:null,e.sizes.includes(j)?{label:`Make it ${j}`,onSelect:()=>o("size",j)}:null,{label:"Edit widgets",onSelect:()=>o("edit")},"separator",{label:"Hide from Home",onSelect:()=>o("hide")}]})})]}),b?t.jsx("a",{className:"wg-body",href:v,onClick:C=>{C.preventDefault(),l(v)},children:k}):t.jsx("div",{className:"wg-body",children:k}),i?t.jsxs("div",{className:"wg-edit-bar",children:[e.sizes.length>1?t.jsx("span",{className:"ui-segment",role:"radiogroup","aria-label":`Size of ${x}`,children:["small","medium"].filter(C=>e.sizes.includes(C)).map(C=>t.jsx("button",{type:"button",className:"ui-tab",role:"radio","aria-checked":n.size===C,onClick:()=>o("size",C),children:C==="small"?"Small":"Medium"},C))}):t.jsx("span",{className:"wg-edit-note",children:e.sizes[0]==="small"?"Small only":"Medium only"}),t.jsxs("span",{className:"wg-edit-move",children:[t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","data-move":`${y}:earlier`,"aria-label":`Move ${x} earlier`,title:"Move earlier",disabled:r===0,onClick:()=>o("earlier"),children:t.jsx(le,{name:"chevron-left"})}),t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","data-move":`${y}:later`,"aria-label":`Move ${x} later`,title:"Move later",disabled:r===a-1,onClick:()=>o("later"),children:t.jsx(le,{name:"chevron-right"})})]})]}):null]})}function HV(e){const n=e.replace(/\.$/,"");return n.charAt(0).toUpperCase()+n.slice(1)}function KV({widgets:e,navigate:n}){const{answer:s,apply:r}=e,[a,i]=h.useState(!1),[l,o]=h.useState([]),[c,u]=h.useState(null),[d,f]=h.useState(""),[m,p]=h.useState(null),[g,v]=h.useState(!1),[b,j]=h.useState(null),[x,y]=h.useState(null),[w,k]=h.useState(null),[N,S]=h.useState(null),[C,E]=h.useState(new Set),[T]=h.useState(FV),I=h.useRef(null);if(h.useEffect(()=>{if(!c)return;const W=window.setTimeout(()=>u(null),vR);return()=>window.clearTimeout(W)},[c]),h.useEffect(()=>{var se;const W=I.current;W&&(I.current=null,(se=document.querySelector(`[data-grip="${CSS.escape(W)}"], [data-move="${CSS.escape(W)}"]`))==null||se.focus())}),!s)return T===0?null:t.jsxs("section",{className:"ui-section wg-section","aria-label":"Widgets","aria-busy":"true",children:[t.jsx("div",{className:"ui-section-head",children:t.jsx("h3",{className:"ui-section-title",children:"Widgets"})}),t.jsx("div",{className:"wg-grid",children:Array.from({length:T},(W,se)=>t.jsxs("div",{className:"wg-frame","data-state":"loading","aria-hidden":"true",children:[t.jsx("div",{className:"wg-head"}),t.jsxs("span",{className:"wg-skel-body",children:[t.jsx("span",{className:"wg-skel","data-w":"half"}),t.jsx("span",{className:"wg-skel","data-w":"third"}),t.jsx("span",{className:"wg-push"}),t.jsx("span",{className:"wg-skel"})]})]},se))})]});if(s.available.every(W=>W.builtIn)&&s.home.length===0)return null;const F=new Map(s.available.map(W=>[W.id,W])),D=a?l:s.home,$=W=>SR(W,F.get(W.widget)),L=(W,se)=>(p(null),r({...se,home:W,arranged:{...se.arranged,home:!0}}),R.saveWidgets("home",W).then(Y=>(r(Y),!0),Y=>(r(se),p(`Couldn't save your widgets: ${Y instanceof Error?Y.message:String(Y)}`),!1))),O=(W,se,Y)=>{if(Y<0||Y>=W.length||se===Y)return null;const Ne=W.slice(),[we]=Ne.splice(se,1);return Ne.splice(Y,0,we),f(`${$(we)}, position ${Y+1} of ${Ne.length}.`),Ne},M=()=>{o(s.home),E(new Set),u(null),p(null),i(!0)},P=W=>(se,Y)=>{const Ne=D[W];if(se==="edit"){M();return}if(se==="settings"){S(Ne.key);return}if(a){if(se==="earlier"||se==="later"){const we=O(l,W,se==="earlier"?W-1:W+1);if(we){const fe=document.activeElement;I.current=(fe==null?void 0:fe.dataset.grip)??(fe==null?void 0:fe.dataset.move)??null,o(we)}}se==="size"&&Y&&(o(l.map((we,fe)=>fe===W?{...we,size:Y}:we)),E(new Set([...C,Ne.key]))),se==="hide"&&(o(l.filter((we,fe)=>fe!==W)),f(`${$(Ne)} taken off.`));return}if(se==="earlier"||se==="later"){const we=O(s.home,W,se==="earlier"?W-1:W+1);we&&L(we,s)}se==="size"&&Y&&L(s.home.map((we,fe)=>fe===W?{...we,size:Y}:we),s),se==="hide"&&L(s.home.filter((we,fe)=>fe!==W),s).then(we=>{we&&u({item:Ne,at:W})})},H=()=>{if(!c)return;const W=s.home.filter(se=>se.key!==c.item.key);W.splice(Math.min(c.at,W.length),0,c.item),u(null),L(W,s)},U=()=>{v(!0),L(l,s).then(W=>{v(!1),W&&(i(!1),f("Widgets saved."))})},V=W=>{j(W),R.refreshWidget(W).then(r,()=>{}).finally(()=>j(null))},z=W=>{var Ne;const se={key:kR(),widget:W.id,size:W.sizes[0],settings:{}},Y=l.some(we=>we.widget===W.id);o([...l,se]),f(`${W.title} added.`),Y&&(((Ne=W.settings)==null?void 0:Ne.length)??0)>0&&S(se.key)},X=(W,se)=>a?(o(l.map(Y=>{if(Y.key!==W)return Y;const{label:Ne,...we}=Y;return{...we,settings:se}})),E(new Set([...C,W])),S(null),Promise.resolve(!0)):L(s.home.map(Y=>Y.key===W?{...Y,settings:se}:Y),s).then(Y=>(Y&&(S(null),f("Settings saved.")),Y)),K=W=>{S(null);const se=D.findIndex(Y=>Y.key===W);se>=0&&P(se)("hide")},ee={dragging:x,over:w,start:W=>y(W),enter:W=>{w!==W&&k(W)},end:()=>{y(null),k(null)},drop:W=>{const se=l.findIndex(we=>we.key===x),Y=l.findIndex(we=>we.key===W),Ne=se>=0&&Y>=0?O(l,se,Y):null;Ne&&o(Ne),y(null),k(null)}},ce=c?t.jsxs("div",{className:"wg-undo","data-size":c.item.size,role:"status","aria-live":"polite",children:[t.jsxs("span",{children:[$(c.item)," hidden"]}),t.jsx("span",{className:"home-glance-sep","aria-hidden":"true",children:"·"}),t.jsx(A,{size:"sm",variant:"ghost",onClick:H,children:"Undo"})]},"undo"):null,pe=[];D.forEach((W,se)=>{const Y=F.get(W.widget);if(!Y)return;c&&!a&&c.at===se&&pe.push(ce);const Ne=a&&(C.has(W.key)||!s.home.some(we=>we.key===W.key));pe.push(t.jsx(WV,{info:Y,placement:W,view:Ne?void 0:s.views[W.key],index:se,count:D.length,editing:a,navigate:n,act:P(se),onRetry:()=>V(W.key),retrying:b===W.key,drag:ee},W.key))}),c&&!a&&c.at>=D.length&&pe.push(ce);const oe=s.available.filter(W=>!W.builtIn),Re=oe.length-2,Oe=N?D.find(W=>W.key===N):void 0,Je=Oe?F.get(Oe.widget):void 0;return t.jsxs("section",{className:"ui-section wg-section","aria-label":"Widgets",children:[t.jsxs("div",{className:"ui-section-head",children:[t.jsx("h3",{className:"ui-section-title",children:"Widgets"}),a?t.jsxs("div",{className:"ui-toolbar","data-align":"end",children:[t.jsx(A,{size:"sm",variant:"ghost",onClick:()=>{i(!1),o([])},disabled:g,children:"Cancel"}),t.jsx(A,{size:"sm",variant:"accent",onClick:U,disabled:g,children:g?"Saving…":"Done"})]}):D.length>0?t.jsx("div",{className:"ui-toolbar","data-align":"end",children:t.jsx(A,{size:"sm",variant:"ghost",onClick:M,children:"Edit"})}):null]}),t.jsx("p",{className:"sr-only","aria-live":"polite",children:d}),m?t.jsx(G,{tone:"critical",role:"alert",children:m}):null,D.length===0&&!a&&!c?t.jsxs("div",{className:"wg-empty",children:[t.jsxs("div",{className:"wg-empty-text",children:[t.jsx("p",{className:"wg-empty-title",children:"Add widgets to Home"}),t.jsxs("p",{className:"wg-empty-sub",children:["Small live panels from your plugins:"," ",(oe.length>0?oe:s.available).slice(0,2).map(W=>W.title).join(", "),Re>0?` and ${Re} more`:"","."]})]}),t.jsx(A,{size:"sm",variant:"accent",onClick:M,children:"Add widgets"})]}):pe.length>0?t.jsx("div",{className:"wg-grid","data-editing":a?"true":void 0,children:pe}):null,a?t.jsxs("div",{className:"wg-gallery",role:"region","aria-label":"Add widgets",children:[t.jsxs("div",{className:"wg-gallery-head",children:[t.jsx("p",{className:"wg-gallery-title",children:"Add widgets"}),t.jsx("a",{className:"wg-gallery-aside",href:Le("lock"),onClick:W=>{W.preventDefault(),n(Le("lock"))},children:"The lock screen has its own pick"})]}),t.jsx("ul",{className:"wg-gallery-list",children:s.available.map(W=>{var ge;const se=l.filter(Pe=>Pe.widget===W.id).length,Y=(((ge=W.settings)==null?void 0:ge.length)??0)>0,Ne=W.builtIn?"Built in":`${W.plugin} plugin`,we=W.sizes.length>1?"small or medium":`${W.sizes[0]} only`,fe=se>1?` · ${se} on Home`:se===1&&Y?" · on Home":"";return t.jsxs("li",{className:"wg-add",children:[t.jsxs("span",{className:"wg-add-text",children:[t.jsx("span",{className:"wg-add-title",children:W.title}),t.jsxs("span",{className:"wg-add-sub",children:[Ne," · ",we,W.sensitive?" · hidden until you show it":"",fe]})]}),se>0&&!Y?t.jsx("span",{className:"wg-add-note",children:"On Home"}):t.jsxs(A,{size:"sm","aria-label":`${se>0?"Add another":"Add"} ${W.title}`,onClick:()=>z(W),children:[t.jsx(le,{name:"plus",size:12})," ",se>0?"Add another":"Add"]})]},W.id)})}),t.jsxs("a",{className:"wg-gallery-more",href:Ex("widgets"),onClick:W=>{W.preventDefault(),n(Ex("widgets"))},children:[t.jsx(le,{name:"plug",size:14}),t.jsx("span",{children:"Get more widgets"}),t.jsx("span",{className:"wg-gallery-more-sub",children:"from plugins on withbuddi.com"})]})]}):null,Oe&&Je?t.jsx(yR,{info:Je,placement:Oe,surface:"home",onClose:()=>S(null),onSave:W=>X(Oe.key,W),onRemove:()=>K(Oe.key)}):null]})}function mw(e,n){return!e||e==="image"&&!n?"earth":e}const VV="(max-width: 720px)",GV=3e4,qV={1:"a minute",5:"5 minutes",15:"15 minutes",60:"an hour"};function Op(e,n){return{time:Xt(e,n),day:Wr(e,n,{weekday:!0})}}function pw(e,n){return e?mu({timeFormat:e.time,...e.date==="off"?{}:{dateFormat:e.date}},n):n()}function YV(e,n,s=new Date,r){return pw(r,()=>JV(e,n,s))}function JV(e,n,s){if(!e.lockedAt)return"Locked";const r=new Date(e.lockedAt),i=Op(r,n).day===Op(s,n).day?Op(r,n).time:Xj(r,n);return e.reason==="idle"?`Locked after ${e.delayMinutes?qV[e.delayMinutes]??`${e.delayMinutes} minutes`:"a while"} away, at ${i}`:e.reason==="start"?`Locked since this session began, at ${i}`:`Locked by you at ${i}`}function QV(e){const n=()=>e?Math.max(0,Math.ceil((Date.parse(e)-Date.now())/1e3)):0,[s,r]=h.useState(n);return h.useEffect(()=>{if(r(n()),!e)return;const a=window.setInterval(()=>r(n()),500);return()=>window.clearInterval(a)},[e]),s}const XV=e=>`${Math.floor(e/60)}:${String(e%60).padStart(2,"0")}`;function RN({size:e=16}){return t.jsx(le,{name:"lock",size:e})}function CR({size:e=16}){return t.jsx("svg",{width:e,height:e,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:t.jsx("path",{d:"M3 8h9.6M8.6 4l4 4-4 4"})})}function ZV(){return t.jsxs("svg",{width:18,height:18,viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[t.jsx("path",{d:"M7.6 5h8a1.4 1.4 0 0 1 1.4 1.4v7.2A1.4 1.4 0 0 1 15.6 15h-8L3 10z"}),t.jsx("path",{d:"M9.6 8l4 4M13.6 8l-4 4"})]})}function IN({text:e}){const[n,s]=h.useState(!1),r=()=>{var a;(a=navigator.clipboard)==null||a.writeText(e).then(()=>{s(!0),window.setTimeout(()=>s(!1),1600)}).catch(()=>{})};return t.jsxs("div",{className:"so-cmd",children:[t.jsx("code",{className:"so-cmd-text",children:e}),t.jsx(A,{size:"sm",onClick:r,children:n?"Copied":"Copy"})]})}function e7({onClose:e}){return t.jsx(zt,{title:"Forgot your PIN?",onClose:e,foot:t.jsx(A,{variant:"accent",onClick:e,children:"Done"}),children:t.jsxs("div",{className:"lk-forgot",children:[t.jsx("p",{className:"lk-forgot-text",children:"The PIN covers this dashboard; it doesn’t sign you in. On the computer buddi runs on, run one of these:"}),t.jsxs("div",{className:"lk-forgot-way",children:[t.jsx(IN,{text:"buddi dashboard --unlock"}),t.jsx("p",{className:"lk-forgot-hint",children:"Opens buddi without the PIN, once. It prints a link for your other devices too, good for five minutes."})]}),t.jsxs("div",{className:"lk-forgot-way",children:[t.jsx(IN,{text:"buddi dashboard --remove-pin"}),t.jsx("p",{className:"lk-forgot-hint",children:"Removes the PIN on every device. Set a new one in Settings → Lock screen."})]})]})})}function t7({approvals:e,needs:n,after:s,onPick:r}){const a=[];return e>0&&a.push({key:"approvals",n:e,text:e===1?"approval waiting":"approvals waiting"}),n>0&&a.push({key:"needs",n,text:e>0?n===1?"more needs you":"more need you":n===1?"thing needs you":"things need you"}),a.length===0?null:t.jsx("ul",{className:"lk-badges","aria-label":"Waiting for you",children:a.map(i=>t.jsx("li",{children:t.jsxs("button",{type:"button",className:"lk-chip","data-kind":i.key,"aria-pressed":s===i.key,disabled:!r,title:r?i.key==="needs"?"Open Needs you once unlocked":"Open your approvals once unlocked":void 0,onClick:()=>r==null?void 0:r(s===i.key?null:i.key),children:[t.jsx("span",{className:"ui-badge","aria-hidden":"true",children:i.n>99?"99+":i.n}),t.jsxs("span",{children:[t.jsxs("span",{className:"lk-sr",children:[i.n," "]}),i.text]})]})},i.key))})}function n7(e,n){const s=n?2:4;let r=0,a=0;for(const i of e){const l=Math.min(i==="medium"?2:1,s);a+l>s&&(a=0),a+=l,r=Math.max(r,a)}return r}function s7(e){return e.filter(n=>!(n.view.body.kind==="text"&&!n.view.body.sub))}function r7({widgets:e,phone:n}){const s=s7(e);if(s.length===0)return null;const r=s.map(i=>({w:i,size:n||i.view.body.kind==="text"?"small":i.size})),a=n7(r.map(({size:i})=>i),n);return t.jsx("div",{className:"lk-widgets",children:t.jsx("div",{className:"lk-grid","data-phone":n?"true":void 0,"data-cols":a,children:r.map(({w:i,size:l})=>t.jsxs("div",{className:"wg-frame","data-variant":"compact","data-size":l,"data-kind":i.view.body.kind,role:"group","aria-label":i.title,children:[t.jsx("div",{className:"wg-body",children:t.jsx(om,{body:i.view.body,size:l})}),t.jsx("span",{className:"wg-compact-title",children:i.title})]},i.key??i.id))})})}function a7({text:e}){const n=/^(.*?)[\s\u202f]?([AaPp]\.?[Mm]\.?)$/.exec(e);return t.jsx("p",{className:"lk-time","aria-label":e,children:n?t.jsxs(t.Fragment,{children:[n[1],t.jsx("span",{className:"lk-ampm","aria-hidden":"true",children:n[2]})]}):e})}function PN(e,n){const s=Object.fromEntries(new Intl.DateTimeFormat("en-US",{timeZone:n,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",hourCycle:"h23"}).formatToParts(e).map(a=>[a.type,a.value])),r=Date.UTC(Number(s.year),Number(s.month)-1,Number(s.day),Number(s.hour)%24,Number(s.minute));return Math.round((r-Math.floor(e.getTime()/6e4)*6e4)/6e4)}function i7(e,n,s){try{const r=PN(e,n)-PN(e,s);if(r===0)return"Same time";const a=u=>new Intl.DateTimeFormat("en-CA",{timeZone:u,year:"numeric",month:"2-digit",day:"2-digit"}).format(e),i=a(n)!==a(s)?r>0?", tomorrow":", yesterday":"",l=Math.floor(Math.abs(r)/60),o=Math.abs(r)%60;return`${o===0?`${l} h`:l===0?`${o} min`:`${l} h ${o}`} ${r>0?"ahead":"behind"}${i}`}catch{return""}}function l7(e,n,s){const r=s??{date:null,zone:null};return pw(s,()=>({time:Xt(e,n),day:r.date==="off"?null:Wr(e,n,{weekday:!0}),zone:r.zone?{label:r.zone.label,time:Xt(e,r.zone.timezone),offset:i7(e,r.zone.timezone,n)}:null}))}function ER({data:e,now:n,phone:s,pad:r=!1,after:a,onPick:i}){const l=(e==null?void 0:e.timezone)??Intl.DateTimeFormat().resolvedOptions().timeZone,o=l7(n,l,e==null?void 0:e.clockView),c=mw(e==null?void 0:e.background,e==null?void 0:e.image),u=(e==null?void 0:e.focus)??null,d=u?pw(e==null?void 0:e.clockView,()=>s?u7(ru(u,l,n)):`${ki[u.mode]} ${ru(u,l,n)}`):"";return t.jsxs(t.Fragment,{children:[c==="earth"?t.jsxs("div",{className:"lk-ground","aria-hidden":"true",children:[t.jsx("img",{className:"lk-photo","data-earth":"true",src:uV(s),alt:"",decoding:"async"}),t.jsx("div",{className:"lk-scrim"})]}):c==="image"&&(e!=null&&e.image)?t.jsxs("div",{className:"lk-ground","aria-hidden":"true",children:[t.jsx("img",{className:"lk-photo",src:e.image,alt:""}),t.jsx("div",{className:"lk-scrim"})]}):t.jsx("div",{className:"ui-fieldbg lk-ground","aria-hidden":"true"}),t.jsxs("header",{className:"lk-top",children:[t.jsxs("span",{className:"lk-brand",children:[t.jsx(Qc,{size:"sm"}),t.jsx("span",{children:"buddi"})]}),t.jsx("span",{className:"lk-top-spacer"}),u?t.jsxs("span",{className:"lk-chip","data-kind":"focus",children:[t.jsx(le,{name:"moon",size:13}),t.jsx("span",{children:d})]}):null]}),t.jsxs("div",{className:"lk-main",children:[o.day?t.jsx("p",{className:"lk-date",children:o.day}):null,t.jsx(a7,{text:o.time}),o.zone?t.jsxs("p",{className:"lk-zone",children:[t.jsx("span",{className:"lk-zone-name",children:o.zone.label}),t.jsx("span",{className:"lk-zone-time",children:o.zone.time}),o.zone.offset?t.jsx("span",{className:"lk-zone-off",children:o.zone.offset}):null]}):null,r||!e?null:t.jsx(t7,{approvals:e.approvals,needs:e.needs??0,after:a??null,...i?{onPick:i}:{}}),r||!e?null:t.jsx(r7,{widgets:e.widgets,phone:s})]})]})}function o7({value:e,disabled:n,onDigit:s,onBack:r,onSubmit:a}){return t.jsxs("div",{className:"lk-pad",role:"group","aria-label":"PIN pad",children:[["1","2","3","4","5","6","7","8","9"].map(i=>t.jsx("button",{type:"button",className:"lk-key",disabled:n,onClick:()=>s(i),children:i},i)),t.jsx("button",{type:"button",className:"lk-key","data-kind":"quiet","aria-label":"Delete",disabled:n||e.length===0,onClick:r,children:t.jsx(ZV,{})}),t.jsx("button",{type:"button",className:"lk-key",disabled:n,onClick:()=>s("0"),children:"0"}),t.jsx("button",{type:"button",className:"lk-key","data-kind":"go","aria-label":"Unlock",disabled:n||e.length<4,onClick:a,children:t.jsx(CR,{size:18})})]})}function c7({initial:e,onUnlocked:n}){const s=ws(VV),r=xR(),[a,i]=h.useState(null),l=a??e,[o,c]=h.useState(""),[u,d]=h.useState(null),[f,m]=h.useState((e==null?void 0:e.waitUntil)??null),[p,g]=h.useState(!1),[v,b]=h.useState(!1),[j,x]=h.useState(!1),[y,w]=h.useState(!1),[k,N]=h.useState(!1),[S,C]=h.useState(null),E=h.useRef(null),T=QV(f),I=T>0,F=h.useRef(n),D=h.useRef(S);D.current=S,F.current=X=>{D.current&&(window.location.hash=ql),n(X)};const $=X=>{var K;C(X),s&&X?w(!0):(K=E.current)==null||K.focus()},L=h.useCallback(()=>{R.lockScreen().then(X=>{b(!1),i(X),m(X.waitUntil),X.locked||F.current(X)}).catch(X=>{X instanceof xe&&X.status===401?window.location.reload():Eh(X)&&b(!0)})},[]);h.useEffect(()=>{L();const X=window.setInterval(L,GV),K=()=>{document.visibilityState==="visible"&&L()};return document.addEventListener("visibilitychange",K),()=>{window.clearInterval(X),document.removeEventListener("visibilitychange",K)}},[L]),NR((a==null?void 0:a.widgets.some(X=>X.id===wR&&X.view.body.kind!=="clocks"))??!1,L),h.useEffect(()=>{var X;!s&&!j&&!I&&((X=E.current)==null||X.focus())},[s,j,I,p]),h.useEffect(()=>{!I&&f&&d(null)},[I,f]);const O=X=>{X==null||X.preventDefault(),!(p||I||o.length<4)&&(g(!0),R.unlock(o).then(K=>{var ce;if(c(""),K.locked){g(!1);return}if((ce=window.matchMedia)==null?void 0:ce.call(window,"(prefers-reduced-motion: reduce)").matches){F.current(K);return}N(!0),window.setTimeout(()=>F.current(K),240)}).catch(K=>{if(g(!1),c(""),!(K instanceof xe))return d("Something went wrong. Try again.");const ee=K.detail??{};if(K.status===403||K.status===429){ee.waitUntil&&m(ee.waitUntil);const ce=ee.triesLeft??0;d(ee.waitUntil?"That PIN isn’t right.":`That PIN isn’t right. ${ce} ${ce===1?"try":"tries"} left.`)}else Eh(K)?d("buddi isn’t answering. Try again in a moment."):d(K.message)}))},M=(a==null?void 0:a.timezone)??Intl.DateTimeFormat().resolvedOptions().timeZone,P=mw(l==null?void 0:l.background,l==null?void 0:l.image),H=(a==null?void 0:a.owner)??null,U=v?{tone:"critical",text:"buddi isn’t answering. The lock stays until it does."}:I?{tone:"critical",text:`Too many tries. Try again in ${XV(T)}.`}:u?{tone:"critical",text:u}:S?{tone:void 0,text:S==="needs"?"Unlock to open what needs you.":"Unlock to open your approvals."}:{tone:void 0,text:l?YV(l,M,r,a==null?void 0:a.clockView):"Locked"},V=X=>X.replace(/\D/g,"").slice(0,8),z=t.jsxs("div",{className:"lk-who",children:[t.jsx("span",{className:"lk-face","aria-hidden":"true",children:(H??"You").slice(0,1).toUpperCase()}),H?t.jsx("span",{className:"lk-owner",children:H}):null]});return t.jsxs("div",{className:"lk","data-bg":P,"data-phone":s?"true":void 0,"data-view":y?"pad":"glance","data-opening":k?"true":void 0,role:"dialog","aria-modal":"true","aria-label":"buddi is locked","data-testid":"lock-screen",children:[t.jsx(ER,{data:a??(l?{...d7(l)}:null),now:r,phone:s,pad:y,after:S,onPick:$}),t.jsx("footer",{className:"lk-unlock",children:s&&!y?t.jsxs(t.Fragment,{children:[t.jsxs("button",{type:"button",className:"lk-chip lk-enter",onClick:()=>w(!0),children:[t.jsx(RN,{size:14}),t.jsx("span",{children:"Enter PIN"})]}),t.jsx("p",{className:"lk-note","data-tone":U.tone,role:"status","aria-live":"polite",children:U.text})]}):s?t.jsxs(t.Fragment,{children:[z,t.jsx("div",{className:"lk-dots","aria-hidden":"true","data-state":u?"wrong":void 0,children:o.length===0?t.jsx("span",{className:"lk-dots-empty",children:"Enter your PIN"}):Array.from(o).map((X,K)=>t.jsx("span",{className:"lk-dot"},K))}),t.jsx("span",{className:"lk-sr","aria-live":"polite",children:o.length===1?"1 digit entered":`${o.length} digits entered`}),t.jsx("p",{className:"lk-note","data-tone":U.tone,role:"status","aria-live":"polite",children:U.text}),t.jsx(o7,{value:o,disabled:I||p,onDigit:X=>{d(null),c(V(o+X))},onBack:()=>c(o.slice(0,-1)),onSubmit:()=>O()}),t.jsxs("div",{className:"lk-pad-foot",children:[t.jsx("button",{type:"button",className:"lk-link",onClick:()=>x(!0),children:"Forgot PIN?"}),t.jsx("button",{type:"button",className:"lk-link",onClick:()=>{w(!1),c(""),d(null)},children:"Cancel"})]})]}):t.jsxs(t.Fragment,{children:[z,t.jsxs("form",{className:"lk-pin","data-state":u&&!I?"wrong":I?"wait":void 0,onSubmit:O,children:[t.jsx(RN,{size:15}),t.jsx("input",{ref:E,type:"password",inputMode:"numeric",autoComplete:"off",maxLength:8,"aria-label":"PIN","aria-describedby":"lk-note",placeholder:I?"Wait a moment":"Enter your PIN",disabled:I,value:o,onChange:X=>{d(null),c(V(X.target.value))}}),t.jsx("button",{type:"submit",className:"lk-go","aria-label":"Unlock",disabled:p||I||o.length<4,children:t.jsx(CR,{})})]}),t.jsx("p",{className:"lk-note",id:"lk-note","data-tone":U.tone,role:"status","aria-live":"polite",children:U.text}),t.jsx("button",{type:"button",className:"lk-link",onClick:()=>x(!0),children:"Forgot PIN?"})]})}),j?t.jsx(e7,{onClose:()=>x(!1)}):null]})}function u7(e){return e.slice(0,1).toUpperCase()+e.slice(1)}function d7(e){return{timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,background:e.background,image:e.image,focus:null,approvals:0,needs:0,widgets:[]}}const h7=3e4,f7=5e3,m7="buddi-lock",pv="buddi-locked",p7=Le("lock");function AR(){var n;const e=navigator;return/mac|iphone|ipad|ipod/i.test(((n=e.userAgentData)==null?void 0:n.platform)||navigator.platform||navigator.userAgent)}function g7(e=AR()){return e?"⌃⌘L":"Ctrl+Alt+L"}function x7(e,n=AR()){return!(e.code==="KeyL"||e.key.toLowerCase()==="l")||!e.ctrlKey||e.shiftKey?!1:n?e.metaKey&&!e.altKey:e.altKey&&!e.metaKey}const $R=h.createContext({pin:!1,state:null,lockNow:()=>{},update:()=>{},shortcut:"⌃⌘L"});function cm(){return h.useContext($R)}function jd(e){try{e?localStorage.setItem(pv,"1"):localStorage.removeItem(pv)}catch{}}function v7(){try{return localStorage.getItem(pv)==="1"}catch{return!1}}function j7(){try{return typeof BroadcastChannel>"u"?null:new BroadcastChannel(m7)}catch{return null}}function y7({children:e}){const[n,s]=h.useState("checking"),[r,a]=h.useState(null),i=h.useRef(null),l=h.useRef(Date.now()),o=h.useRef(0),c=h.useRef(0),u=h.useRef(0),d=h.useCallback((v,b)=>{v&&a(v),s(b?"locked":"open"),jd(b),b||(l.current=Date.now())},[]),f=h.useCallback(()=>{R.lockState().then(v=>d(v,v.locked)).catch(v=>{if(v instanceof xe&&v.status===401)return s("open");d(null,v7())})},[d]);h.useEffect(()=>{f()},[f]);const m=h.useCallback((v="owner")=>{var b;if(!(r!=null&&r.pin)){window.location.hash=p7;return}s("locked"),jd(!0),v==="owner"&&((b=i.current)==null||b.postMessage({type:"locked"})),(v==="idle"?R.lockNow("idle",Date.now()-l.current):R.lockNow(v)).then(j=>{var x;v==="idle"&&j.locked&&((x=i.current)==null||x.postMessage({type:"locked"})),d(j,j.locked)}).catch(()=>f())},[r==null?void 0:r.pin,d,f]);h.useEffect(()=>{const v=()=>{s("locked"),jd(!0),f()};return window.addEventListener(hx,v),()=>window.removeEventListener(hx,v)},[f]),h.useEffect(()=>{const v=j7();if(i.current=v,!!v)return v.onmessage=b=>{const j=b.data;(j==null?void 0:j.type)==="locked"?(s("locked"),jd(!0)):(j==null?void 0:j.type)==="unlocked"?f():(j==null?void 0:j.type)==="activity"&&typeof j.at=="number"&&(l.current=Math.max(l.current,j.at))},()=>{v.close(),i.current=null}},[f]),h.useEffect(()=>{const v=b=>{x7(b)&&(b.preventDefault(),n==="open"&&m("owner"))};return window.addEventListener("keydown",v,!0),()=>window.removeEventListener("keydown",v,!0)},[n,m]);const p=r!=null&&r.pin?r.delayMinutes:null;h.useEffect(()=>{if(n!=="open"||!(r!=null&&r.pin))return;c.current=l.current;const v=()=>{var N;const k=Date.now();l.current=k,k-u.current>1e4&&(u.current=k,(N=i.current)==null||N.postMessage({type:"activity",at:k}))},b=()=>{const k=Date.now();l.current<=c.current||k-o.current<h7||(o.current=k,c.current=l.current,R.lockActivity().catch(()=>{}))},j=()=>{if(p!==null&&Date.now()-l.current>=p*6e4){m("idle");return}b()},x=["pointerdown","pointermove","keydown","wheel","touchstart"];for(const k of x)window.addEventListener(k,v,{passive:!0,capture:!0});const y=window.setInterval(j,f7),w=()=>{document.visibilityState==="visible"&&j()};return document.addEventListener("visibilitychange",w),()=>{for(const k of x)window.removeEventListener(k,v,{capture:!0});window.clearInterval(y),document.removeEventListener("visibilitychange",w)}},[n,r==null?void 0:r.pin,p,m]);const g=h.useMemo(()=>({pin:(r==null?void 0:r.pin)===!0,state:r,lockNow:()=>m("owner"),update:v=>d(v,v.locked),shortcut:g7()}),[r,m,d]);return n==="checking"?null:n==="locked"?t.jsx(c7,{initial:r,onUnlocked:v=>{var b;(b=i.current)==null||b.postMessage({type:"unlocked"}),d(v,!1)}}):t.jsx($R.Provider,{value:g,children:e})}const TR="a connection needs you";function w7({attention:e,place:n,onNavigate:s,theme:r,onTheme:a,plugins:i=[],updateAvailable:l=!1,settingsDot:o,version:c,stale:u=!1,reload:d,timezone:f,status:m}){return t.jsxs("nav",{className:"rail","aria-label":"Places",children:[t.jsx("a",{className:"rail-mark",href:kn,onClick:p=>{p.preventDefault(),s(kn)},"aria-label":"buddi home",children:t.jsx(Qc,{})}),w3.filter(p=>p.route!==yn).map(p=>t.jsx(Lp,{label:p.label,href:p.route,active:n===p.route,badge:p.route===kn?e:0,onClick:()=>s(p.route),children:MN[p.route]},p.route)),i.map(p=>{const g=Or(p.plugin,p.id);return t.jsx(Lp,{label:p.title,href:g,active:n===g,badge:0,onClick:()=>s(g),children:t.jsx(le,{name:fR(p.icon)})},g)}),t.jsx("div",{className:"rail-spacer"}),t.jsx(Lp,{label:"Settings",href:yn,active:n===yn,badge:0,dot:l?"a newer buddi is ready":o,onClick:()=>s(yn),children:MN[yn]}),m,t.jsx(k7,{theme:r,onTheme:a,onNavigate:s,version:c,stale:u,reload:d,timezone:f})]})}const b7=[{value:"light",label:"Light"},{value:"dark",label:"Dark"},{value:"system",label:"System"}];function k7({theme:e,onTheme:n,onNavigate:s,version:r,stale:a,reload:i=()=>window.location.reload(),timezone:l}){var w,k,N;const o=me(()=>R.owner(),[]),c=cm(),u=me(()=>R.focus(),[],6e4),d=((w=u.data)==null?void 0:w.focus)??null,f=(S,C)=>{R.setFocus(S,C).finally(()=>u.reload())},m=((N=(k=o.data)==null?void 0:k.preferredName)==null?void 0:N.trim())||null,p=(m??"You").slice(0,1).toUpperCase(),[g]=h.useState(L3),[v]=h.useState(C7),b=lm(),j=m?`You: ${m}`:"You",x=d?`${ki[d.mode]} ${ru(d,l)}`:null,y=[j,x,a?"reload to update":null].filter(Boolean).join(", ");return t.jsx("div",{className:"rail-owner",children:t.jsxs(ju,{modal:!1,children:[t.jsx(yu,{asChild:!0,children:t.jsxs("button",{type:"button",className:"rail-owner-btn","aria-label":y,children:[t.jsx("span",{className:"rail-owner-face","aria-hidden":"true",children:p}),a?t.jsx("span",{className:"ui-badge rail-dot","data-kind":"dot","data-testid":"owner-dot","aria-hidden":"true"}):null,d?t.jsx("span",{className:"rail-focus","data-testid":"owner-focus","aria-hidden":"true",children:t.jsx(le,{name:"moon",size:10})}):null]})}),t.jsx(xo,{children:t.jsxs(wu,{className:"ui-menu rail-owner-menu",side:"right",align:"end",sideOffset:10,children:[t.jsxs("div",{className:"rail-owner-head",children:[t.jsx("span",{className:"rail-owner-face","data-size":"lg","aria-hidden":"true",children:p}),t.jsxs("span",{className:"rail-owner-who",children:[t.jsx("span",{className:"rail-owner-name",children:m??"You"}),t.jsx("span",{className:"rail-owner-sub",children:"On this Mac"})]})]}),t.jsx(ra,{className:"ui-menu-sep"}),t.jsx(S7,{focus:d,timezone:l,onSwitch:f}),t.jsx(ra,{className:"ui-menu-sep"}),t.jsx(Di,{className:"ui-menu-label",children:"Theme"}),t.jsx("div",{className:"rail-owner-theme",children:t.jsx(ln,{label:"Theme",options:b7,value:e,onChange:n})}),t.jsx(ra,{className:"ui-menu-sep"}),c.pin?t.jsxs(zs,{className:"ui-menu-item rail-owner-reload",onSelect:()=>c.lockNow(),children:[t.jsx("span",{children:"Lock now"}),t.jsx("kbd",{className:"rail-owner-kbd",children:c.shortcut})]}):t.jsx(zs,{className:"ui-menu-item",onSelect:()=>s(Le("lock")),children:"Set up a lock screen…"}),t.jsx(zs,{className:"ui-menu-item",onSelect:()=>s(Le("appearance")),children:"Change appearance"}),b?t.jsx(zs,{className:"ui-menu-item",onSelect:()=>{hw(b)},children:"Install the app"}):null,g||a?t.jsxs(zs,{className:"ui-menu-item rail-owner-reload","data-update":a?"true":void 0,onSelect:()=>i(),children:[t.jsx("span",{children:a?"Reload to update":"Reload"}),v?t.jsx("kbd",{className:"rail-owner-kbd",children:v}):null]}):null,r?t.jsxs(t.Fragment,{children:[t.jsx(ra,{className:"ui-menu-sep"}),t.jsxs(zs,{className:"ui-menu-item rail-owner-version","data-update":r.updateAvailable?"true":void 0,onSelect:()=>s(Le("system")),children:[t.jsxs("span",{className:"mono",children:["buddi ",r.current]}),r.updateAvailable&&r.latest?t.jsxs("span",{className:"rail-owner-update",children:["A newer buddi is ready: ",r.latest]}):null]})]}):null]})})]})})}const ki={normal:"Off","urgent-only":"Urgent only","do-not-disturb":"Do not disturb"},N7=[{value:"1h",label:"For 1 hour"},{value:"3h",label:"For 3 hours"},{value:"tomorrow",label:"Until tomorrow morning"},{value:"indefinite",label:"Until I turn it off"}];function ru(e,n,s=new Date){if(!e.until)return"until you turn it off";const r=new Date(e.until),a=n??Intl.DateTimeFormat().resolvedOptions().timeZone,i=c=>new Intl.DateTimeFormat("en-CA",{timeZone:a,dateStyle:"short"}).format(c),l=Xt(r,a);return i(r)===i(s)?`until ${l}`:`until ${new Intl.DateTimeFormat("en-US",{timeZone:a,weekday:"short"}).format(r)} ${l}`}function S7({focus:e,timezone:n,onSwitch:s}){return t.jsxs(Rz,{children:[t.jsxs(Iz,{className:"ui-menu-item rail-owner-focus",children:[t.jsx("span",{children:"Focus"}),t.jsx("span",{className:"rail-owner-kbd",children:e?ki[e.mode]:"Off"})]}),t.jsx(xo,{children:t.jsxs(Pz,{className:"ui-menu rail-owner-menu",sideOffset:6,children:[t.jsx("p",{className:"ui-menu-empty",role:"status",children:e?`${ki[e.mode]} ${ru(e,n)}${e.by==="schedule"?", from a schedule":""}.`:"No focus is on."}),["do-not-disturb","urgent-only"].map(r=>t.jsxs(QA,{children:[t.jsx(ra,{className:"ui-menu-sep"}),t.jsx(Di,{className:"ui-menu-label",children:ki[r]}),N7.map(a=>t.jsx(zs,{className:"ui-menu-item","aria-label":`${ki[r]} ${a.label.toLowerCase()}`,onSelect:()=>s(r,a.value),children:a.label},a.value))]},r)),e?t.jsxs(t.Fragment,{children:[t.jsx(ra,{className:"ui-menu-sep"}),t.jsx(zs,{className:"ui-menu-item",onSelect:()=>s("normal"),children:"Turn off"})]}):null]})})]})}function C7(){const e=window.navigator.userAgent;return/iPhone|iPad|Android|Mobile/.test(e)?null:/Mac/.test(e)?"⌘R":"Ctrl+R"}function Lp({label:e,href:n,active:s,badge:r,dot:a,onClick:i,children:l}){return t.jsxs("a",{className:"rail-link",href:n,"data-active":s?"true":void 0,"aria-current":s?"page":void 0,"aria-label":r>0?`${e}, ${r} waiting`:a?`${e}, ${a}`:e,onClick:o=>{o.preventDefault(),i()},children:[t.jsxs("span",{className:"rail-icon",children:[l,r>0?t.jsx("span",{className:"rail-badge","aria-hidden":"true",children:r>99?"99+":r}):null,r===0&&a?t.jsx("span",{className:"ui-badge rail-dot","data-kind":"dot","data-testid":"rail-dot","aria-hidden":"true"}):null]}),t.jsx("span",{className:"rail-label",children:e})]})}const MN={[pa]:t.jsx(le,{name:"files"}),[kn]:t.jsx(le,{name:"home"}),[oa]:t.jsx(le,{name:"chat"}),[vt]:t.jsx(le,{name:"agents"}),[At]:t.jsx(le,{name:"activity"}),[yn]:t.jsx(le,{name:"settings"})},au=e=>`${e.plugin}:${e.id}`,E7=new Set;let gw=E7,DN=!1;const gv=new Set;function xv(e){gw=e;for(const n of gv)n()}function A7(e){return gv.add(e),()=>gv.delete(e)}const ON=()=>gw;function $7(){DN||(DN=!0,Promise.resolve().then(()=>R.rail()).then(e=>xv(new Set(Array.isArray(e==null?void 0:e.hidden)?e.hidden.filter(n=>typeof n=="string"):[]))).catch(()=>{}))}async function T7(e,n){const s=gw,r=new Set(s);n?r.add(au(e)):r.delete(au(e)),xv(r);try{await R.setRailHidden(e.plugin,e.id,n)}catch(a){throw xv(s),a}}function RR(){return h.useEffect($7,[]),h.useSyncExternalStore(A7,ON,ON)}function R7(e,n){return e.filter(s=>!n.has(au(s)))}function I7(e){return e instanceof HTMLElement?e.isContentEditable?!0:e.tagName==="INPUT"||e.tagName==="TEXTAREA"||e.tagName==="SELECT":!1}function P7(e,n=!0,s){h.useEffect(()=>{if(!n)return;const r=a=>{if(a.key!=="/"||a.defaultPrevented||a.ctrlKey||a.metaKey||a.altKey||I7(a.target))return;a.preventDefault();const i=document.getElementById(nv);if(i instanceof HTMLTextAreaElement){!i.disabled&&!i.hidden&&i.focus();return}s?s():e(kn)};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[e,n,s])}const IR="buddi.theme";function M7(e=PR()){try{const n=e==null?void 0:e.getItem(IR);return n==="light"||n==="dark"||n==="system"?n:"system"}catch{return"system"}}function D7(e,n=PR()){try{n==null||n.setItem(IR,e)}catch{}}function O7(e,n=document.documentElement){n&&(e==="system"?n.removeAttribute("data-theme"):n.setAttribute("data-theme",e))}function PR(){try{return window.localStorage}catch{return}}const MR="buddi.ground",DR="buddi.pageWidth";function L7(e=FR()){const n=a=>{try{return(e==null?void 0:e.getItem(a))??null}catch{return null}},s=n(MR),r=n(DR);return{theme:M7(e),ground:s==="sand"?"sand":"blue",width:r==="narrow"||r==="full"?r:"wide"}}function OR(e,n=document.documentElement){n&&(O7(e.theme,n),e.ground==="sand"?n.setAttribute("data-ground","sand"):n.removeAttribute("data-ground"),e.width==="wide"?n.removeAttribute("data-width"):n.setAttribute("data-width",e.width))}function F7(e,n=FR()){D7(e.theme,n);try{n==null||n.setItem(MR,e.ground),n==null||n.setItem(DR,e.width)}catch{}}let Fl=null;const vv=new Set;function jv(){return Fl||(Fl=L7()),Fl}function _7(e){return vv.add(e),()=>vv.delete(e)}function z7(e){Fl={...jv(),...e},OR(Fl),F7(Fl);for(const n of vv)n()}function LR(){return[h.useSyncExternalStore(_7,jv,jv),z7]}function FR(){try{return window.localStorage}catch{return}}const LN=7,U7=1e4;function B7({timezone:e,embedded:n,agents:s=[],navigate:r}){const{data:a,error:i,reload:l}=me(()=>R.sentinels(),[],3e4),[o,c]=h.useState(null),[u,d]=h.useState(null),[f,m]=h.useState(null),[p,g]=h.useState(null),[v,b]=h.useState(!1),[j,x]=h.useState(null),y=a==null?void 0:a.alerts,w=(y==null?void 0:y.open)??[],k=M=>{r?r(M):window.location.hash=M},N=M=>{var P;return M?((P=s.find(H=>H.id===M))==null?void 0:P.name)??null:null},S=async M=>{c(null);try{await M()}catch(P){c(P instanceof xe||P instanceof Error?P.message:String(P))}finally{l()}},C=M=>d({...M,id:Date.now()}),E=(M,P,H)=>S(async()=>{const{keys:U}=await R.snoozeAlerts(M,!0,H);C({title:P,undo:()=>R.snoozeAlerts(U,!1)})}),T=M=>S(async()=>{const{id:P}=await R.muteAlert(M.keys[0],M.stop.scope);C({title:"You won’t hear about this again",body:"Turn it back on in Settings → Watchers.",undo:()=>R.unmuteAlert(P)})}),I=M=>S(async()=>{const{agentId:P,conversationId:H}=await R.askAboutAlerts(M.keys);k(Ze(P,H))}),F=M=>S(async()=>{const[P]=(await R.actOnAlerts([{key:M.key,action:M.index}])).results;if(P!=null&&P.error)throw new Error(P.error);P!=null&&P.approvalId?C({title:"Waiting for your approval",body:"Decide it in Needs you on Home."}):C({title:`${M.label}: done`})}),D=(M,P)=>{P.kind==="open"?k(P.place==="files"?pa:P.plugin&&P.page?Or(P.plugin,P.page,P.item):pa):P.kind==="ask"?I(M):P.kind==="dismiss"?E(M.keys,"Set aside until it changes"):P.kind==="fill"?m(P):P.confirm?g(P):F(P)},$=()=>{const M=w.flatMap(P=>P.keys);E(M,`Cleared ${w.length} for a week`,LN)},L=y==null?void 0:y.recap,O=W7((L==null?void 0:L.nextAt)??null,e);return t.jsxs(Zn,{embedded:n,title:"Alerts",lede:"What needs a decision from you.",children:[t.jsx(ne,{message:i??o}),t.jsxs(Ye,{flush:!0,title:"Needs a decision",tool:w.length>0?String(w.length):void 0,actions:w.length>1?t.jsx(A,{size:"sm",variant:"ghost",onClick:$,children:"Clear all"}):void 0,children:[a?w.length===0?t.jsxs("div",{className:"al-empty",children:[t.jsx(le,{name:"check"}),t.jsxs("div",{children:[t.jsx("p",{className:"al-empty-title",children:"Nothing needs a decision."}),t.jsxs("p",{className:"al-empty-line",children:["Your watchers are quiet. What they notice in passing waits for ",O,"."]})]})]}):t.jsx("ul",{className:"al-list",children:w.map(M=>t.jsx(FN,{group:M,agentName:N(M.agentId),onAct:D,onStop:T,onNotNow:P=>void E(P.keys,"Snoozed for a week",LN)},M.id))}):null,L&&L.count>0?t.jsxs("p",{className:"al-recap","data-testid":"recap-line",children:[t.jsxs("span",{children:[L.count," ",L.count===1?"note":"notes"," saved for ",O]}),t.jsx("span",{"aria-hidden":"true",children:"·"}),t.jsx("button",{type:"button",className:"wb-link",onClick:()=>b(!0),children:"Preview"})]}):null]}),y&&(y.snoozed.length>0||y.resolved.length>0)?t.jsxs("p",{className:"al-quiet",children:[y.snoozed.length>0?t.jsxs("button",{type:"button",className:"wb-link","aria-expanded":j==="snoozed",onClick:()=>x(j==="snoozed"?null:"snoozed"),children:[y.snoozed.length," snoozed"]}):null,y.snoozed.length>0&&y.resolved.length>0?t.jsx("span",{"aria-hidden":"true",children:"·"}):null,y.resolved.length>0?t.jsxs("button",{type:"button",className:"wb-link","aria-expanded":j==="resolved",onClick:()=>x(j==="resolved"?null:"resolved"),children:[y.resolved.length," resolved this week"]}):null]}):null,j==="snoozed"&&y?t.jsx(Ye,{flush:!0,title:"Snoozed",children:t.jsx("ul",{className:"al-list",children:y.snoozed.map(M=>t.jsxs("li",{className:"al-row",children:[t.jsxs("div",{className:"al-main",children:[t.jsx("p",{className:"al-title",children:M.title}),t.jsx("p",{className:"al-sub",children:M.snoozedUntil?`Back ${Ve(M.snoozedUntil)}`:"Until it changes"})]}),t.jsx("div",{className:"al-actions",children:t.jsx(A,{size:"sm",onClick:()=>void S(async()=>{await R.snoozeAlerts(M.keys,!1)}),children:"Bring back"})})]},M.id))})}):null,j==="resolved"&&y?t.jsx(Ye,{flush:!0,title:"Resolved this week",children:t.jsx("ul",{className:"al-list",children:y.resolved.map(M=>t.jsx("li",{className:"al-row",children:t.jsxs("div",{className:"al-main",children:[t.jsx("p",{className:"al-title",children:M.title}),t.jsx("p",{className:"al-sub",children:M.resolvedAt?`Resolved ${Ve(M.resolvedAt)}`:null})]})},M.id))})}):null,v&&L?t.jsxs(Ge,{title:H7(O),onClose:()=>b(!1),children:[t.jsxs("p",{className:"al-form-note",children:["What the watchers noted. buddi reads them out in ",O,"; nothing here needs you now, but you can act on one early."]}),t.jsx("ul",{className:"al-list al-list-sheet",children:L.groups.map(M=>t.jsx(FN,{group:M,agentName:N(M.agentId),recap:!0,onAct:(P,H)=>{H.kind!=="fill"&&b(!1),D(P,H)},onStop:P=>{T(P)}},M.id))})]}):null,f?t.jsx(K7,{action:f,onClose:()=>m(null),onSaved:M=>{m(null),b(!1),C({title:`Saved ${M}`}),l()}}):null,p?t.jsx(zt,{title:p.label,onClose:()=>g(null),foot:t.jsxs(t.Fragment,{children:[t.jsx(A,{variant:"ghost",onClick:()=>g(null),children:"Cancel"}),t.jsx(A,{variant:p.tone==="danger"?"danger":"accent",onClick:()=>{const M=p;g(null),F(M)},children:p.label})]}),children:t.jsx("p",{children:p.confirm})}):null,u?t.jsx(eu,{title:u.title,...u.body?{body:u.body}:{},duration:U7,...u.undo?{onUndo:()=>{const M=u.undo;S(async()=>{await M()})}}:{},onGone:()=>d(null)},u.id):null]})}function W7(e,n,s=Date.now()){if(!e)return"the weekly recap";const r=new Date(e);return Number.isNaN(r.getTime())||r.getTime()-s>7*864e5?"the weekly recap":`${new Intl.DateTimeFormat("en",{weekday:"long",timeZone:n}).format(r)}’s recap`}function H7(e){return e.charAt(0).toUpperCase()+e.slice(1)}function yd(e,n){return e.kind==="ask"?e.label??(n?`Ask ${n}`:"Ask about it"):e.label}function FN({group:e,agentName:n,recap:s,onAct:r,onNotNow:a,onStop:i}){const[l,o]=h.useState(!1),[c,u,...d]=e.actions,f=e.actions.some(p=>p.kind==="ask"),m=e.items.length>1;return t.jsxs("li",{className:"al-row","data-urgent":e.urgent&&!s?"true":void 0,children:[t.jsxs("div",{className:"al-main",children:[t.jsx("p",{className:"al-title",children:e.title}),e.line?t.jsx("p",{className:"al-line",children:e.line}):null,t.jsxs("p",{className:"al-sub",children:[n?t.jsx("span",{children:n}):null,n&&!s?t.jsx("span",{"aria-hidden":"true",children:"·"}):null,s?null:t.jsxs("span",{children:["noticed ",Ve(e.since)]}),m?t.jsxs(t.Fragment,{children:[n||!s?t.jsx("span",{"aria-hidden":"true",children:"·"}):null,t.jsx("button",{type:"button",className:"wb-link al-toggle","aria-expanded":l,onClick:()=>o(p=>!p),children:l?"Hide":`Show the ${e.items.length}`})]}):null]}),l&&m?t.jsx("ul",{className:"al-items",children:e.items.map(p=>t.jsxs("li",{className:"al-item",children:[p.subject?t.jsx("span",{className:"al-item-who",children:p.subject.label}):null,t.jsx("span",{className:"al-item-note",children:p.subject?p.note:p.line}),p.actions&&p.actions.length>0?t.jsx("span",{className:"al-item-actions",children:p.actions.map((g,v)=>t.jsx(A,{size:"sm",variant:g.kind==="run"&&g.tone==="danger"?"danger-ghost":"ghost",onClick:()=>r(e,g),children:yd(g,n)},v))}):null]},p.key))}):null]}),t.jsxs("div",{className:"al-actions",children:[c?t.jsx(A,{size:"sm",variant:"accent",onClick:()=>r(e,c),children:yd(c,n)}):null,u?t.jsx(A,{size:"sm",variant:u.kind==="run"&&u.tone==="danger"?"danger-ghost":void 0,onClick:()=>r(e,u),children:yd(u,n)}):null,a?t.jsx(A,{size:"sm",variant:"ghost",onClick:()=>a(e),children:"Not now"}):null,t.jsx("span",{className:"al-more",children:t.jsx(Rs,{label:`More for ${e.title}`,sheet:{title:e.title},items:[...d.map(p=>({label:yd(p,n),...p.kind==="run"&&p.tone==="danger"?{tone:"critical"}:{},onSelect:()=>r(e,p)})),!f&&{label:n?`Ask ${n}`:"Ask about it",onSelect:()=>r(e,{kind:"ask",label:null})},"separator",{label:"Stop telling me this",hint:"Undo in Settings → Watchers",onSelect:()=>i(e)}]})})]})]})}function K7({action:e,onClose:n,onSaved:s}){const r=e.fields.length===1,[a,i]=h.useState(()=>Object.fromEntries(e.fields.map(p=>[p.key,r&&p.value!==null?String(p.value):""]))),[l,o]=h.useState({}),[c,u]=h.useState(!1),[d,f]=h.useState(null),m=async()=>{const p=e.fields.filter(g=>(a[g.key]??"").trim()!=="").map(g=>({key:g.key,action:g.index,value:(a[g.key]??"").trim()}));if(p.length===0){n();return}u(!0),f(null);try{const{results:g}=await R.actOnAlerts(p),v=Object.fromEntries(g.filter(b=>b.error).map(b=>[b.key,b.error]));o(v),Object.keys(v).length===0&&s(p.length)}catch(g){f(g instanceof Error?g.message:String(g))}finally{u(!1)}};return t.jsx(Ge,{title:e.title,onClose:n,foot:t.jsxs("div",{className:"al-form-foot",children:[t.jsx(A,{variant:"ghost",onClick:n,children:"Cancel"}),t.jsx(A,{variant:"accent",disabled:c,onClick:()=>void m(),children:c?"Saving…":"Save"})]}),children:t.jsxs("div",{className:"al-form",children:[t.jsx(ne,{message:d}),t.jsx("p",{className:"al-form-note",children:r?"Check it and save.":"Type what each is today. Leave the ones you don’t know; they stay as they are."}),t.jsx("div",{className:"al-form-rows",children:e.fields.map(p=>t.jsxs("label",{className:"al-form-row",children:[t.jsxs("span",{className:"al-form-label",children:[t.jsx("span",{children:p.label}),p.hint?t.jsx("span",{className:"al-form-hint",children:p.hint}):null]}),t.jsx("input",{type:p.type==="date"?"date":"text",inputMode:p.type==="number"?"decimal":void 0,value:a[p.key]??"",placeholder:"—","aria-label":p.label,onChange:g=>i(v=>({...v,[p.key]:g.target.value}))}),l[p.key]?t.jsx("span",{className:"al-form-error",children:l[p.key]}):null]},p.key))})]})})}function V7({mutes:e,onChanged:n}){const[s,r]=h.useState(null);return e.length===0?null:t.jsxs(Ye,{flush:!0,title:"Silenced",tool:String(e.length),children:[t.jsx(ne,{message:s}),t.jsx("ul",{className:"al-list",children:e.map(a=>t.jsxs("li",{className:"al-row",children:[t.jsxs("div",{className:"al-main",children:[t.jsx("p",{className:"al-title al-silenced-label",children:a.label}),t.jsxs("p",{className:"al-sub",children:["You said “Stop telling me this” ",Ve(a.createdAt)]})]}),t.jsx("div",{className:"al-actions",children:t.jsx(A,{size:"sm",onClick:()=>{r(null),R.unmuteAlert(a.id).then(n,i=>r(i instanceof Error?i.message:String(i)))},children:"Tell me again"})})]},a.id))})]})}const _N=5e3,zN=50;function G7({timezone:e,embedded:n}){var j;const[s,r]=h.useState(""),[a,i]=h.useState(""),[l,o]=h.useState(null),c=me(()=>R.eventKinds(),[]),{data:u,error:d}=me(()=>R.events({kind:s||void 0,q:a||void 0,limit:zN}),[s,a],_N),[f,m]=h.useState({events:[],cursor:null,busy:!1,error:null});h.useEffect(()=>{m({events:[],cursor:null,busy:!1,error:null})},[s,a]);const p=f.events.length>0?f.cursor:(u==null?void 0:u.nextCursor)??null,g=async()=>{if(p){m(x=>({...x,busy:!0,error:null}));try{const x=await R.events({kind:s||void 0,q:a||void 0,before:p,limit:zN});m(y=>({events:[...y.events,...x.events],cursor:x.nextCursor,busy:!1,error:null}))}catch(x){m(y=>({...y,busy:!1,error:x instanceof Error?x.message:String(x)}))}}},v=new Set(((u==null?void 0:u.events)??[]).map(x=>x.id)),b=[...(u==null?void 0:u.events)??[],...f.events.filter(x=>!v.has(x.id))];return t.jsxs(Zn,{embedded:n,title:"Events",lede:"The append-only log. Everything the installation did, including what you do here.",children:[t.jsxs(te,{children:[t.jsxs("select",{"aria-label":"Event kind",value:s,onChange:x=>r(x.target.value),children:[t.jsx("option",{value:"",children:"every kind"}),(((j=c.data)==null?void 0:j.kinds)??[]).map(x=>t.jsxs("option",{value:x.kind,children:[x.kind," (",x.count,")"]},x.kind))]}),t.jsx("input",{"aria-label":"Payload contains",placeholder:"payload contains…",value:a,onChange:x=>i(x.target.value),size:28}),s||a?t.jsx(A,{onClick:()=>{r(""),i("")},children:"Clear"}):null,t.jsxs("span",{className:"muted",children:["refreshes every ",_N/1e3,"s"]})]}),t.jsx(ne,{message:d}),t.jsx(Ye,{flush:!0,children:!u||b.length===0?t.jsx(ve,{children:"No events match."}):t.jsxs(Kr,{children:[t.jsx("thead",{children:t.jsxs("tr",{children:[t.jsx("th",{children:"#"}),t.jsx("th",{children:"When"}),t.jsx("th",{children:"Kind"}),t.jsx("th",{children:"Payload"})]})}),t.jsx("tbody",{children:b.map(x=>t.jsxs("tr",{"data-clickable":"true",onClick:()=>o(x),children:[t.jsx("td",{className:"mono muted",children:x.id}),t.jsxs("td",{className:"nowrap",children:[ct(x.createdAt,e),t.jsx("div",{className:"sub",children:Ve(x.createdAt)})]}),t.jsx("td",{className:"mono nowrap",children:x.kind}),t.jsx("td",{className:"mono muted",children:cr(ks(x.payload).replace(/\s+/g," "),120)})]},x.id))})]})}),p||f.error?t.jsxs(te,{children:[t.jsxs("span",{className:"muted",children:[b.length," shown",p?", older ones are kept":"","."]}),t.jsx("span",{className:"ui-toolbar-spacer"}),f.error?t.jsx("span",{className:"critical",children:f.error}):null,p?t.jsx(A,{disabled:f.busy,onClick:()=>void g(),children:f.busy?"Loading…":"Load older"}):null]}):null,l?t.jsxs(Ge,{title:l.kind,onClose:()=>o(null),children:[t.jsxs("p",{className:"muted",children:["Event ",l.id," · ",ct(l.createdAt,e),l.conversationId?t.jsxs(t.Fragment,{children:[" · ",t.jsx("a",{href:`#/conversations/${l.conversationId}`,children:"conversation"})]}):null]}),t.jsx(Dt,{children:ks(l.payload)})]}):null]})}const UN=["pending","leased","suspended","failed","succeeded","cancelled"],Vo=50,q7=1e4,Y7=(e,n,s=`${n}s`)=>e===1?n:s;function J7({timezone:e,embedded:n,initialState:s}){var U,V;const[r,a]=h.useState(s??""),[i,l]=h.useState(null),[o,c]=h.useState(null),[u,d]=h.useState(null),[f,m]=h.useState(!1),p=r==="failed",{data:g,error:v,reload:b}=me(()=>R.jobs({...r?{state:r}:{},...r?{}:{dismissed:"0"},limit:String(Vo)}),[r],1e4),j=me(()=>R.jobFailures(),[],1e4),[x,y]=h.useState({jobs:[],done:!1,busy:!1});h.useEffect(()=>{y({jobs:[],done:!1,busy:!1})},[r]);const w=async()=>{y(z=>({...z,busy:!0}));try{const z=await R.jobs({...r?{state:r}:{dismissed:"0"},limit:String(Vo),offset:String(Vo+x.jobs.length)});y(X=>({jobs:[...X.jobs,...z.jobs],done:z.jobs.length<Vo,busy:!1}))}catch(z){c(z instanceof Error?z.message:String(z)),y(X=>({...X,busy:!1}))}},k=new Set(((g==null?void 0:g.jobs)??[]).map(z=>z.id)),N=[...(g==null?void 0:g.jobs)??[],...x.jobs.filter(z=>!k.has(z.id))],S=(g==null?void 0:g.counts)??{},C=r?S[r]??0:UN.reduce((z,X)=>z+(S[X]??0),0),E=!x.done&&N.length<C&&((g==null?void 0:g.jobs.length)??0)>=Vo,T=((U=j.data)==null?void 0:U.open)??[],I=((V=j.data)==null?void 0:V.dismissed)??[],F=T.reduce((z,X)=>z+X.count,0),D=I.reduce((z,X)=>z+X.count,0),$=()=>{b(),j.reload()},L=z=>d({...z,id:Date.now()}),O=async z=>{c(null);try{await z()}catch(X){c(X instanceof Error?X.message:String(X))}finally{$()}},M=async z=>{await O(async()=>{await z,l(null)})},P=z=>O(async()=>{const{ids:X}=await R.dismissJobs(z==="all"?{all:!0}:{ids:z});X.length!==0&&L({title:`Dismissed ${X.length===1?"it":X.length}`,body:"Kept under Dismissed, below.",undo:()=>R.undismissJobs(X)})}),H=(z,X)=>O(async()=>{const{jobs:K}=await R.retryJobs({ids:z});if(K.length===0)return;const ee=K.length===1;L({title:`Retrying ${ee?"it":K.length}`,body:X?`${ee?"It runs":"They run"} as soon as a worker is free.`:`If what broke ${ee?"it":"them"} hasn’t changed, ${ee?"it":"they"} will fail the same way.`})});return t.jsxs(Zn,{embedded:n,title:"Jobs",lede:`${g!=null&&g.paused?"Paused: nothing is being claimed. ":""}Bounded retries with backoff; past the budget a job waits for you.`,actions:n?void 0:t.jsx(A,{size:"sm",variant:g!=null&&g.paused?"accent":void 0,onClick:()=>M(R.setPaused(!((g==null?void 0:g.paused)??!1))),children:g!=null&&g.paused?"Resume the queue":"Pause the queue"}),children:[t.jsx(ne,{message:v??j.error??o}),T.length>0?t.jsxs(Ye,{flush:!0,title:"Gave up",tool:String(F),actions:F>1?t.jsx(A,{size:"sm",variant:"ghost",onClick:()=>void P("all"),children:"Dismiss all"}):void 0,children:[t.jsx("ul",{className:"al-list",children:T.map(z=>t.jsx(WN,{group:z,timezone:e,onOpen:l,onRetry:X=>void H(X,z.likelyFixed),onDismiss:X=>void P(X)},z.key))}),t.jsx("p",{className:"al-recap",children:t.jsx("span",{children:"These will not run again on their own. Dismissed jobs stay on record; any failed job older than 14 days is dismissed for you."})})]}):p&&j.data?t.jsx(Ye,{flush:!0,children:t.jsxs("div",{className:"al-empty",children:[t.jsx(le,{name:"check"}),t.jsxs("div",{children:[t.jsx("p",{className:"al-empty-title",children:"No failed job needs you."}),t.jsx("p",{className:"al-empty-line",children:D>0?"The ones you dismissed stay on record, below.":"Every job either ran or is still on its way."})]})]})}):null,D>0||p?t.jsxs("p",{className:"al-quiet jb-quiet",children:[D>0?t.jsxs("button",{type:"button",className:"wb-link","aria-expanded":f,onClick:()=>m(z=>!z),children:[D," dismissed"]}):null,D>0&&p?t.jsx("span",{"aria-hidden":"true",children:"·"}):null,p?t.jsx("button",{type:"button",className:"wb-link",onClick:()=>a(""),children:"Show the whole queue"}):null]}):null,f&&I.length>0?t.jsx(Ye,{flush:!0,title:"Dismissed",children:t.jsx("ul",{className:"al-list",children:I.map(z=>t.jsx(WN,{group:z,timezone:e,dismissed:!0,onOpen:l,onRetry:X=>void H(X,z.likelyFixed)},z.key))})}):null,p?null:t.jsx(Ye,{flush:!0,title:"Queue",actions:t.jsxs("select",{"aria-label":"Job state",value:r,onChange:z=>a(z.target.value),children:[t.jsx("option",{value:"",children:"every state"}),UN.map(z=>t.jsxs("option",{value:z,children:[z," (",S[z]??0,")"]},z))]}),children:!g||N.length===0?t.jsx(ve,{children:"No jobs match."}):t.jsxs(Kr,{children:[t.jsx("thead",{children:t.jsxs("tr",{children:[t.jsx("th",{children:"Kind"}),t.jsx("th",{children:"State"}),t.jsx("th",{className:"num",children:"Attempts"}),t.jsx("th",{children:"Last error"}),t.jsx("th",{children:"Updated"}),t.jsx("th",{})]})}),t.jsx("tbody",{children:N.map(z=>t.jsxs("tr",{children:[t.jsxs("td",{className:"clickable",onClick:()=>l(z),children:[z.kind,t.jsx("div",{className:"sub mono",children:Hc(z.id)})]}),t.jsxs("td",{children:[t.jsx(Nu,{state:z.state}),z.suspendedReason?t.jsx("div",{className:"sub",children:cr(z.suspendedReason,40)}):null,z.acknowledgedAt?t.jsx("div",{className:"sub",children:"dismissed"}):null]}),t.jsxs("td",{className:"num",children:[z.attempts,"/",z.maxAttempts]}),t.jsx("td",{className:z.lastError?"critical":"muted",children:z.lastError?cr(z.lastError,80):"—"}),t.jsxs("td",{className:"nowrap",children:[ct(z.updatedAt,e),t.jsx("div",{className:"sub",children:Ve(z.updatedAt)})]}),t.jsx("td",{children:t.jsxs(te,{align:"end",children:[["failed","cancelled","suspended"].includes(z.state)?t.jsx(A,{size:"sm",onClick:()=>M(R.retryJob(z.id)),children:"Retry"}):null,["pending","leased","suspended","failed"].includes(z.state)?t.jsx(A,{size:"sm",variant:"danger",onClick:()=>M(R.cancelJob(z.id)),children:"Cancel"}):null]})})]},z.id))})]})}),E&&!p?t.jsxs(te,{children:[t.jsxs("span",{className:"muted",children:[N.length," of ",C," shown."]}),t.jsx("span",{className:"ui-toolbar-spacer"}),t.jsx(A,{disabled:x.busy,onClick:()=>void w(),children:x.busy?"Loading…":"Load older"})]}):null,i?t.jsxs(Ge,{title:i.kind,onClose:()=>l(null),children:[t.jsx("p",{className:"muted mono",children:i.id}),i.lastError?t.jsx(ue,{title:"Last error",children:t.jsx(Dt,{children:i.lastError})}):null,t.jsx(ue,{title:"Payload",children:t.jsx(Dt,{children:ks(i.payload)})}),t.jsx(ue,{title:"Result",children:t.jsx(Dt,{children:ks(i.result)})}),i.conversationId?t.jsx("p",{children:t.jsx("a",{href:`#/conversations/${i.conversationId}`,children:"open the transcript"})}):null]}):null,u?t.jsx(eu,{title:u.title,...u.body?{body:u.body}:{},duration:q7,...u.undo?{onUndo:()=>{const z=u.undo;O(async()=>{await z()})}}:{},onGone:()=>d(null)},u.id):null]})}function BN(e){var s;if(e.missionName)return e.missionName;const n=(s=e.job.payload)==null?void 0:s.prompt;return typeof n=="string"&&n.trim()!==""?cr(n.trim().split(`
123
- `)[0],48):e.job.kind==="agent-run"?"Agent run":e.job.kind}function WN({group:e,timezone:n,dismissed:s,onOpen:r,onRetry:a,onDismiss:i}){var g;const[l,o]=h.useState(!1),c=e.jobs.length>1,u=e.jobs.map(v=>v.job.id),d=e.agents.map(v=>v.name??v.id),f=e.jobs[0],m=e.jobs.every(v=>v.job.acknowledgedBy==="auto"),p=s?m?"dismissed on its own after 14 days":`dismissed ${Ve(((g=e.jobs[0])==null?void 0:g.job.acknowledgedAt)??e.lastAt)}`:`gave up ${Ve(e.lastAt)}`;return t.jsxs("li",{className:"al-row","data-urgent":s?void 0:"true",children:[t.jsxs("div",{className:"al-main",children:[t.jsx("p",{className:"al-title",children:c?`${e.label} · ${e.count}`:e.label}),s?null:t.jsx("p",{className:"al-line",children:e.reason}),t.jsxs("p",{className:"al-sub",children:[d.length>0?t.jsxs(t.Fragment,{children:[t.jsx("span",{children:d.join(", ")}),t.jsx("span",{"aria-hidden":"true",children:"·"})]}):null,!c&&f?t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",className:"wb-link",onClick:()=>r(f.job),children:BN(f)}),t.jsx("span",{"aria-hidden":"true",children:"·"})]}):null,t.jsx("span",{title:ct(e.lastAt,n),children:p}),c?t.jsxs(t.Fragment,{children:[t.jsx("span",{"aria-hidden":"true",children:"·"}),t.jsx("button",{type:"button",className:"wb-link al-toggle","aria-expanded":l,onClick:()=>o(v=>!v),children:l?"Hide":`Show the ${e.count}`})]}):null]}),l&&c?t.jsx("ul",{className:"al-items",children:e.jobs.map(v=>t.jsxs("li",{className:"al-item jb-item",children:[v.agentName||v.agentId?t.jsx("span",{className:"al-item-who",children:v.agentName??v.agentId}):null,t.jsxs("span",{className:"al-item-note",children:[t.jsx("button",{type:"button",className:"wb-link",onClick:()=>r(v.job),children:BN(v)})," · ",Xj(new Date(v.job.updatedAt),n)," · tried ",v.job.attempts," ",Y7(v.job.attempts,"time")]}),t.jsxs("span",{className:"jb-item-acts",children:[t.jsx("button",{type:"button",className:"wb-link",onClick:()=>a([v.job.id]),children:"Retry"}),i?t.jsxs(t.Fragment,{children:[t.jsx("span",{"aria-hidden":"true",children:"·"}),t.jsx("button",{type:"button",className:"wb-link",onClick:()=>i([v.job.id]),children:"Dismiss"})]}):null]})]},v.job.id))}):null]}),t.jsxs("div",{className:"al-actions",children:[t.jsx(A,{size:"sm",variant:e.likelyFixed&&!s?"accent":void 0,onClick:()=>a(u),children:c?"Retry all":"Retry"}),i?t.jsx(A,{size:"sm",variant:"ghost",onClick:()=>i(u),children:"Dismiss"}):null]})]})}const Q7=[{id:"conversations",label:"Conversations"},{id:"jobs",label:"Jobs"},{id:"approvals",label:"Approvals"},{id:"alerts",label:"Alerts"},{id:"events",label:"Events"}];function X7({hash:e,timezone:n,navigate:s,agents:r}){var u,d;const a=/^#\/activity\/conversations\/(.+)$/.exec(e),i=f=>{var m;return((m=r.find(p=>p.id===f))==null?void 0:m.name)??f};if(a){let f=a[1];try{f=decodeURIComponent(f)}catch{}return t.jsx(tG,{id:f,timezone:n,navigate:s,nameOf:i})}const l=((u=/^#\/activity\/([a-z]+)/.exec(e))==null?void 0:u[1])??"conversations",o=(d=/[?&]state=([a-z]+)/.exec(e))==null?void 0:d[1],c=f=>m=>{m.preventDefault(),s(f)};return t.jsxs("div",{className:"ui-page",children:[t.jsx(Ql,{title:"Activity",lede:"Everything your agents ran, newest first.",actions:t.jsx(rG,{})}),t.jsx(aG,{}),t.jsx(yo,{children:Q7.map(f=>{const m=f.id==="conversations"?At:`${At}/${f.id}`;return t.jsx(Li,{href:m,active:l===f.id,onClick:c(m),children:f.label},f.id)})}),l==="conversations"?t.jsx(Z7,{timezone:n,navigate:s,nameOf:i,agents:r}):null,l==="jobs"?t.jsx(J7,{timezone:n,embedded:!0,initialState:o},o??""):null,l==="approvals"?t.jsx(eG,{timezone:n,nameOf:i}):null,l==="alerts"?t.jsx(B7,{timezone:n,embedded:!0,agents:r,navigate:s}):null,l==="events"?t.jsx(G7,{timezone:n,embedded:!0}):null]})}function Z7({timezone:e,navigate:n,nameOf:s,agents:r}){const{data:a,error:i}=me(()=>R.conversations(),[],3e4);return t.jsxs(t.Fragment,{children:[t.jsx(ne,{message:i}),t.jsx(Ye,{flush:!0,children:a?a.conversations.length===0?t.jsx(Jn,{icon:"activity",title:"Nothing has run yet",children:"Conversations and runs show up here as your agents work."}):t.jsx(at,{children:a.conversations.map(l=>t.jsx(Xe,{href:qc(l.id),onClick:()=>n(qc(l.id)),lead:t.jsx(fn,{agents:r,id:l.agentId,size:"sm"}),title:l.opening?cr(l.opening,100):"Untitled conversation",sub:`${s(l.agentId)}, ${l.messageCount} message${l.messageCount===1?"":"s"}, ${l.runs} run${l.runs===1?"":"s"}, ${YF(l.usage)}`,side:t.jsx("span",{title:ct(l.lastMessageAt??l.createdAt,e),children:Ve(l.lastMessageAt??l.createdAt)})},l.id))}):t.jsx(ve,{children:"Loading…"})})]})}function eG({timezone:e,nameOf:n}){const{data:s,error:r}=me(()=>R.approvals(),[],1e4),a=[...(s==null?void 0:s.pending)??[],...(s==null?void 0:s.recent)??[]];return t.jsxs(t.Fragment,{children:[t.jsx(ne,{message:r}),t.jsx(Ye,{flush:!0,children:s?a.length===0?t.jsx(Jn,{icon:"bell",title:"No approvals yet",children:"When an agent asks before acting, the request and your answer are kept here."}):t.jsxs(Kr,{children:[t.jsx("thead",{children:t.jsxs("tr",{children:[t.jsx("th",{children:"Tool"}),t.jsx("th",{children:"State"}),t.jsx("th",{children:"Asked by"}),t.jsx("th",{children:"Decided"}),t.jsx("th",{children:"Created"})]})}),t.jsx("tbody",{children:a.map(i=>t.jsxs("tr",{children:[t.jsxs("td",{children:[i.tool,t.jsx("div",{className:"sub mono",children:Hc(i.id)})]}),t.jsx("td",{children:t.jsx(Nu,{state:i.state})}),t.jsx("td",{children:n(i.agentId)}),t.jsx("td",{className:"nowrap",children:i.decidedAt?t.jsxs(t.Fragment,{children:[ct(i.decidedAt,e),t.jsxs("div",{className:"sub",children:["via ",i.decidedVia??"—"]})]}):t.jsx("span",{className:"muted",children:"—"})}),t.jsxs("td",{className:"nowrap",children:[ct(i.createdAt,e),t.jsx("div",{className:"sub",children:Ve(i.createdAt)})]})]},i.id))})]}):t.jsx(ve,{children:"Loading…"})})]})}function tG({id:e,timezone:n,navigate:s,nameOf:r}){const[a,i]=h.useState(null),[l,o]=h.useState(null);h.useEffect(()=>{let u=!1;return R.conversation(e).then(d=>{u||i(d)}).catch(d=>{u||o(d instanceof Error?d.message:String(d))}),()=>{u=!0}},[e]);const c=u=>d=>{d.preventDefault(),s(u)};return t.jsxs("div",{className:"ui-page",children:[t.jsx("p",{className:"page-crumbs",children:t.jsx("a",{href:At,onClick:c(At),children:"Activity"})}),t.jsxs("header",{className:"ui-page-head",children:[t.jsxs("div",{className:"ui-page-head-row",children:[t.jsxs("h2",{className:"ui-page-title",children:[t.jsx(A,{size:"sm",onClick:()=>s(At),children:"← Back"}),t.jsx("span",{children:"Transcript"})]}),a?t.jsx("div",{className:"ui-page-actions",children:t.jsx(ht,{size:"sm",href:Ze(a.agentId,e),onClick:c(Ze(a.agentId,e)),children:"Open in chat"})}):null]}),t.jsx("p",{className:"ui-page-lede mono",children:e})]}),t.jsx(ne,{message:l}),a?t.jsxs(t.Fragment,{children:[t.jsxs(tm,{children:[t.jsx(Er,{label:"Agent",value:r(a.agentId),size:"sm"}),t.jsx(Er,{label:"Runs",value:a.runs.length}),t.jsx(Er,{label:"Tokens",value:`${dn(a.usage.input)} / ${dn(a.usage.output)}`,note:dx(a.usage)?`input / output, ${dx(a.usage)}`:"input / output"}),t.jsx(Er,{label:"Started",value:ct(a.createdAt,n),size:"sm"})]}),a.runs.length>0?t.jsx(Ye,{title:"Runs",flush:!0,children:t.jsxs(Kr,{children:[t.jsx("thead",{children:t.jsxs("tr",{children:[t.jsx("th",{children:"Started"}),t.jsx("th",{children:"Finished"}),t.jsx("th",{className:"num",children:"Turns"}),t.jsx("th",{children:"Stopped"}),t.jsx("th",{className:"num",children:"Tokens"}),t.jsx("th",{className:"num",children:"Cached"})]})}),t.jsx("tbody",{children:a.runs.map((u,d)=>t.jsxs("tr",{children:[t.jsxs("td",{className:"nowrap",children:[ct(u.startedAt,n)," ",u.resumed?t.jsx(Ee,{children:"resumed"}):null]}),t.jsx("td",{className:"nowrap",children:ct(u.finishedAt,n)}),t.jsx("td",{className:"num",children:u.turns??"—"}),t.jsxs("td",{children:[u.stopped??"—",u.actionId?t.jsxs("div",{className:"sub mono",children:["action ",Hc(u.actionId)]}):null]}),t.jsxs("td",{className:"num muted nowrap",children:[dn(u.usage.input)," / ",dn(u.usage.output)]}),t.jsx("td",{className:"num muted nowrap",children:u.usage.cacheRead||u.usage.cacheWrite?dn((u.usage.cacheRead??0)+(u.usage.cacheWrite??0)):"—"})]},d))})]})}):null,t.jsx(ue,{title:"Messages",children:t.jsx(ie,{children:a.messages.map(u=>t.jsxs("article",{className:"transcript-msg",children:[t.jsxs("header",{className:"transcript-who",children:[u.speaker===HN?"approved action, result":u.role,", ",ct(u.createdAt,n)]}),t.jsxs("div",{className:"transcript-body",children:[u.blocks.length===0?t.jsx("span",{className:"muted",children:"(empty)"}):null,u.speaker===HN?u.blocks.map((d,f)=>t.jsx(nG,{block:d},f)):u.blocks.map((d,f)=>t.jsx(sG,{block:d},f))]})]},u.id))})})]}):t.jsx(ve,{children:"Loading…"})]})}const HN="approval:resume";function nG({block:e}){return t.jsxs("div",{className:"transcript-tool",children:[t.jsx("div",{className:"transcript-tool-name mono",children:"← approved action"}),t.jsx(Dt,{children:e.type==="text"?e.text??"":ks(e)})]})}function sG({block:e}){return e.type==="text"?t.jsx("div",{className:"transcript-text",children:t.jsx(ur,{text:e.text??""})}):e.type==="thinking"?t.jsxs("details",{className:"transcript-thinking",children:[t.jsx("summary",{children:"Thoughts"}),t.jsx("div",{className:"transcript-thinking-text",children:t.jsx(ur,{text:e.text??""})})]}):e.type==="thinking_hidden"?t.jsx("div",{className:"transcript-thinking-hidden",children:"Thinking (hidden)"}):e.ref===void 0&&e.type==="provider_native"?t.jsx(t.Fragment,{}):e.type==="tool_use"?t.jsxs("div",{className:"transcript-tool",children:[t.jsxs("div",{className:"transcript-tool-name mono",children:["→ ",e.name]}),t.jsx(Dt,{children:ks(e.input)})]}):e.type==="tool_result"?t.jsxs("div",{className:"transcript-tool","data-tone":e.isError?"critical":void 0,children:[t.jsxs("div",{className:"transcript-tool-name mono",children:["← ",e.isError?"error":"result"]}),t.jsx(Dt,{children:e.content??""})]}):t.jsxs("div",{className:"transcript-tool",children:[t.jsx("div",{className:"transcript-tool-name mono",children:e.type}),t.jsx(Dt,{children:ks(e.ref)})]})}function rG(){const{data:e,reload:n}=me(()=>R.overview(),[],1e4),[s,r]=h.useState(!1);if(!e)return null;const a=()=>{r(!0),R.setPaused(!e.paused).then(n,n).finally(()=>r(!1))};return t.jsx(A,{size:"sm",variant:e.paused?"accent":void 0,disabled:s,onClick:a,children:e.paused?"Resume all":"Pause all"})}function aG(){const{data:e,reload:n}=me(()=>R.overview(),[],1e4);if(h.useEffect(()=>(window.addEventListener(bi,n),()=>window.removeEventListener(bi,n)),[n]),!e)return null;const s=a=>e.jobs[a]??0,r=s("leased");return t.jsxs(tm,{children:[t.jsx(Er,{label:"Jobs done",value:dn(s("succeeded"))}),t.jsx(Er,{label:"Failed",value:dn(s("failed")),...s("failed")>0?{tone:"critical"}:{}}),t.jsx(Er,{label:"Queued",value:dn(s("pending")),note:`${r} running`}),t.jsx(Er,{label:"Approvals",value:dn(e.approvals.pending),note:"waiting for you"})]})}const iG=["replay-all","coalesce","latest-only","skip-after-deadline"];function _R({timezone:e,embedded:n,agentId:s}){const{data:r,error:a,reload:i}=me(()=>R.missions(),[],3e4),l=((r==null?void 0:r.missions)??[]).filter(d=>!s||d.agentId===s),[o,c]=h.useState(null),u=async d=>{c(null);try{await d,i()}catch(f){c(f instanceof Error?f.message:String(f))}};return t.jsxs(Zn,{embedded:n,title:"Missions",lede:"Standing schedules. A disabled mission materializes nothing.",children:[t.jsx(ne,{message:a??o}),!r||l.length===0?t.jsxs(Jn,{icon:"calendar",title:"No missions yet",children:["Run ",t.jsx("code",{children:"buddi missions add-defaults"})," for the standard set."]}):t.jsx(ie,{children:l.map(d=>t.jsx(lG,{mission:d,timezone:e,onRun:u},d.id))})]})}function lG({mission:e,timezone:n,onRun:s}){const[r,a]=h.useState(!1);return t.jsxs(Ts,{tone:e.enabled&&!e.pausedReason?"good":"muted",title:t.jsxs(t.Fragment,{children:[e.name," ",t.jsx("span",{className:"mono muted",children:e.id})]}),meta:t.jsxs(t.Fragment,{children:[t.jsx(Ee,{mono:!0,children:e.agentId}),e.alwaysDeliver?t.jsx(Ee,{children:"always delivers"}):null,e.enabled?null:t.jsx(Ee,{tone:"warning",children:e.endedAt?"ended":"disabled"}),e.pausedReason?t.jsx(Ee,{tone:"warning",children:e.pausedReason}):null]}),actions:t.jsxs(t.Fragment,{children:[t.jsx(A,{size:"sm",onClick:()=>s(R.setMissionEnabled(e.id,!e.enabled)),children:e.enabled?"Disable":"Enable"}),t.jsx(A,{size:"sm",variant:"ghost",onClick:()=>a(i=>!i),"aria-expanded":r,children:r?"Less":"More"})]}),children:[e.stillUsefulAskedAt?t.jsx(G,{tone:"warning",title:"Still useful?",action:t.jsxs(te,{align:"end",children:[t.jsx(A,{size:"sm",onClick:()=>s(R.answerStillUseful(e.id,"stop")),children:"Stop"}),t.jsx(A,{size:"sm",variant:"accent",onClick:()=>s(R.keepMission(e.id)),children:"Keep"})]}),children:`It has run ${e.quietRuns??"many"} times in a row without anything to tell you.`}):null,e.stopWhen||e.endsAt?t.jsxs("p",{className:"ui-card-meta",children:[e.stopWhen?`Stops itself when ${e.stopWhen}. `:"",e.endedAt?`Ended ${ct(e.endedAt,n)}.`:e.endsAt?`Ends ${ct(e.endsAt,n)}.`:""]}):null,t.jsxs("p",{className:"ui-card-meta",children:[e.schedule?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"mono",children:e.schedule.cron})," ",e.schedule.timezoneExplicit===!1?t.jsx("span",{title:e.schedule.timezone,children:"follows your timezone"}):e.schedule.timezone," ","· rev"," ",e.schedule.revision," · next"," ",e.nextRun?`${ct(e.nextRun,n)} (${Ve(e.nextRun)})`:"—"]}):"no schedule — enqueued by hand or by a sentinel",t.jsx("br",{}),"Last notification:"," ",e.lastNotification?`${e.lastNotification.kind==="mission.delivered"?"delivered":"silent"} ${Ve(e.lastNotification.at)}${e.lastNotification.reason?` — ${e.lastNotification.reason}`:""}`:"none"]}),r?t.jsxs("div",{className:"ui-card-foot",children:[e.schedule?t.jsxs(te,{children:[t.jsx(re,{inline:!0,label:"Misfire policy",children:t.jsx("select",{value:e.schedule.misfirePolicy,onChange:i=>s(R.setMisfirePolicy(e.id,i.target.value)),children:iG.map(i=>t.jsx("option",{value:i,children:i},i))})}),t.jsx("span",{className:"muted",children:"What a week asleep does: replay every instant, coalesce into one, keep only the latest, or skip past a deadline."})]}):null,t.jsx(ue,{title:"Prompt",children:t.jsx(Dt,{children:e.prompt})}),t.jsx(ue,{title:"Recent occurrences",children:t.jsx(Ye,{flush:!0,children:e.occurrences.length===0?t.jsx(ve,{children:"Never run."}):t.jsxs(Kr,{children:[t.jsx("thead",{children:t.jsxs("tr",{children:[t.jsx("th",{children:"Scheduled"}),t.jsx("th",{children:"State"}),t.jsx("th",{children:"Finished"}),t.jsx("th",{children:"Detail"})]})}),t.jsx("tbody",{children:e.occurrences.map(i=>t.jsxs("tr",{children:[t.jsx("td",{className:"nowrap",children:ct(i.scheduledAt,n)}),t.jsx("td",{children:t.jsx(Nu,{state:i.state})}),t.jsx("td",{className:"nowrap",children:ct(i.finishedAt,n)}),t.jsxs("td",{className:i.error?"critical":"muted",children:[i.error?cr(i.error,120):null,i.runConversationId?t.jsx("a",{href:`#/conversations/${i.runConversationId}`,children:"transcript"}):null]})]},i.id))})]})})})]}):null]})}function oG(e,n){const s=`${e} offer${e===1?"":"s"}`,r=n?` from ${n}`:"";return`Dismiss ${s}${r}? They stop appearing everywhere. Nothing runs, and you can still see them under "Dismissed and lapsed" for a week.`}function zR({ids:e,agentName:n,onDone:s}){const r=e.length,[a,i]=h.useState(!1),[l,o]=h.useState(!1);return r<=0?null:a?t.jsxs("span",{className:"ui-row",children:[t.jsx("span",{className:"muted",children:oG(r,n)}),t.jsx(A,{size:"sm",variant:"danger",disabled:l,onClick:()=>{o(!0),R.dismissOffers(e).then(()=>{i(!1),s()}).finally(()=>o(!1))},children:`Dismiss ${r}`}),t.jsx(A,{size:"sm",variant:"ghost",disabled:l,onClick:()=>i(!1),children:"Keep them"})]}):t.jsx(A,{size:"sm",variant:"ghost",onClick:()=>i(!0),children:"Dismiss all"})}function UR({embedded:e,agentId:n,agentName:s}){const{data:r,error:a,reload:i}=me(()=>R.offers(),[],2e4),l=j=>!n||j.agentId===n,o=((r==null?void 0:r.offers)??[]).filter(l),c=((r==null?void 0:r.closed)??[]).filter(l),[u,d]=h.useState(null),[f,m]=h.useState(null),[p,g]=h.useState(null),v=async(j,x)=>{d(null),m(j);try{const y=await R.takeOffer(j);g(y.jobId?`On it — ${x}. Started as job ${y.jobId}.`:`Taken — ${x}. No worker is running here, so nothing has started yet.`),i()}catch(y){d(y instanceof Error?y.message:String(y))}finally{m(null)}},b=async(j,x)=>{d(null),m(j);try{await R.dismissOffer(j),g(`Dismissed — ${x}. It will not come back.`),i()}catch(y){d(y instanceof Error?y.message:String(y))}finally{m(null)}};return t.jsxs(Zn,{embedded:e,title:"Offers",lede:"Things an agent already worked out that you might want done. Taking one asks that agent the sentence it wrote. It authorizes nothing, and anything that would leave this machine still comes back to you as an approval.",children:[t.jsx(ne,{message:a??u}),p?t.jsx(G,{tone:"good",role:"status",children:p}):null,o.length>0?t.jsxs(te,{children:[t.jsx("span",{className:"ui-toolbar-spacer"}),t.jsx(zR,{ids:o.map(j=>j.id),agentName:s,onDone:()=>{g(null),i()}})]}):null,!r||o.length===0?t.jsx(Jn,{icon:"bulb",title:"Nothing on offer",children:"When an agent works out something you might want done, it waits here."}):t.jsx(ie,{children:o.map(j=>t.jsx(Ts,{tone:"accent",title:j.label,meta:t.jsxs(t.Fragment,{children:[t.jsx(Ee,{mono:!0,children:j.agentId}),t.jsxs("span",{className:"muted",children:["expires ",Ve(j.expiresAt)]})]}),actions:t.jsxs(t.Fragment,{children:[t.jsx(A,{size:"sm",variant:"ghost",disabled:f===j.id,onClick:()=>void b(j.id,j.label),children:"Not now"}),t.jsx(A,{variant:"accent",size:"sm",disabled:f===j.id,onClick:()=>void v(j.id,j.label),children:"Take"})]}),children:t.jsx("p",{className:"ui-card-meta",children:j.prompt})},j.id))}),c.length>0?t.jsxs(Ot,{summary:`Dismissed and lapsed (${c.length})`,boxed:!0,children:[t.jsx(Ye,{flush:!0,children:t.jsx(at,{children:c.map(j=>t.jsx(Xe,{title:j.label,sub:`${j.agentId} — ${ZF(j)}`,side:Ve(j.dismissedAt??j.lapsedAt??j.createdAt)},j.id))})}),t.jsx("p",{className:"muted",children:"These stop being shown a week after they closed."})]}):null]})}const cG={work:"Work",money:"Money",home:"Home",health:"Health",learning:"Learning",life:"Life"},xw=e=>cG[e]??um(e);function um(e){return e.charAt(0).toUpperCase()+e.slice(1)}function rn(e){return e.length<2?e.join(""):`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}function eo(e){return e.replace(/\.0$/,"")}function uG(e){return e.avatar?R.marketAssetUrl(e.avatar):void 0}const dG={mailbox:{title:"your mailbox",fix:"Add a mailbox",route:Lr("email","settings")},"image-account":{title:"a drawing account",fix:"Choose a drawing account",route:Lr("image","settings")}};function vw(e){return dG[e.replace(/\?$/,"")]??{title:e,fix:"Set it up",route:Le()}}const dm=e=>um(e);function BR(e){return e.kind==="plugin"?e.title:vw(e.name).title}function WR(e){if(e.kind==="need"){const n=vw(e.name);return{label:n.fix,route:n.route}}return e.fix==="enable"?{label:`Turn on ${e.title}`,route:Le("plugins")}:e.fix==="update"?{label:`Update ${e.title}`,route:Le("plugins")}:e.byBuddi?null:{label:`Install ${e.title}`,route:Le("plugins")}}function hG(e,n,s){const r=new Set((e.missing??[]).map(o=>o.name)),i=[...Object.keys(e.requires),...Object.keys(e.optional)].filter(o=>!r.has(o)&&n.has(o)).map(dm),l=e.needs.includes("mailbox")||e.needs.includes("mailbox?");return s===!0&&l&&!r.has("mailbox")&&i.push("your mailbox"),i}function Fp(e){return um(e.replace(/\.md$/i,"").replace(/[-_]+/g," ").trim())}const KN=(e,n)=>e.includes(n),fG={email:{title:"Mail",line:e=>KN(e,"email.draft")||KN(e,"email.*")?"Reads and searches your mail. Writes drafts; you send them.":"Searches and reads your mail."},calendar:{title:"Calendar",line:()=>"Reads your calendars. Never adds or moves an event."},weather:{title:"Weather",line:()=>"Reads the forecast for your places."},reminder:{title:"Reminders",line:e=>e.some(n=>n.startsWith("schedule."))?"Sets reminders and runs its own missions.":"Sets reminders."},memory:{title:"Memory",line:()=>"Remembers what you tell it. You can read every note."},owner:{title:"You",line:()=>"Messages you when something needs you."},web:{title:"Web",line:()=>"Searches and reads web pages."},artifacts:{title:"Files",line:()=>"Reads what you share in Files."},finance:{title:"Finance",line:()=>"Reads your accounts, cards, loans and statements."},image:{title:"Image",line:()=>"Makes pictures with your drawing account."},speech:{title:"Speech",line:()=>"Says words out loud."},goal:{title:"Goals",line:()=>"Keeps your goals and progress."},canvas:{title:"Canvas",line:()=>"Draws on the canvas beside your chat."}},mG={schedule:"reminder",browser:"web"};function Vh(e,n=new Map){const s=[],r=new Map;for(const a of e){const i=a.replace(/\?$/,""),l=i.split(".")[0]??i,o=mG[l]??l;r.has(o)||(r.set(o,[]),s.push(o)),r.get(o).push(i)}return s.map(a=>{const i=r.get(a),l=fG[a],o=i.some(u=>n.get(u)==="gated"||u.endsWith(".*")&&[...n].some(([d,f])=>f==="gated"&&d.startsWith(u.slice(0,-1)))),c=l?l.line(i):`${i.length===1?"One of its tools":`${i.length} of its tools`}.`;return[(l==null?void 0:l.title)??um(a),o&&!/asks you/i.test(c)?`${c} Asks you first before it changes anything.`:c]})}function VN(e){return e.length===0?"Nothing beyond its own chat.":`Reaches ${rn(e.map(([n])=>n))}.`}function Gh(e){return new Map((e??[]).filter(n=>n.tier).map(n=>[n.name,n.tier]))}function So({entry:e,size:n}){const s=uG(e);return t.jsx("span",{className:"cat-face","data-size":n,children:t.jsx(Nn,{id:e.name,name:e.title,size:n==="xxl"?"xl":n,face:{tools:e.tools,...s?{picture:s}:{}}})})}const HR=800,pG=e=>{var n;return((n=/^.*?[.!?](?=\s|$)/.exec(e.trim()))==null?void 0:n[0])??e.trim()},_l=e=>e instanceof xe?e.message:String(e);function ta({entry:e,children:n}){return t.jsxs("span",{className:"plugins-sheet-title",children:[t.jsx(So,{entry:e,size:"lg"}),t.jsxs("span",{className:"plugins-sheet-name",children:[t.jsx("span",{children:n}),t.jsxs("span",{className:"plugins-sheet-by",children:["by ",e.author.name,e.trust==="by-buddi"?t.jsxs(t.Fragment,{children:[" · ",t.jsx(Ee,{tone:"accent",children:"by buddi"})]}):null]})]})]})}function _p({state:e,children:n}){return t.jsxs("li",{className:"cat-step","data-state":e,children:[t.jsx("span",{className:"cat-step-mark",children:e==="done"?t.jsx(le,{name:"check",size:12}):e==="failed"?t.jsx(le,{name:"alert",size:14}):null}),t.jsx("span",{children:n})]})}function zp(e){const n=e.kind==="plugin"?["Installing","Installed"]:["Adding","Added"];return e.state==="done"?{state:"done",words:`${n[1]} ${e.title}`}:e.state==="failed"?{state:"failed",words:e.kind==="plugin"?`${e.title} didn’t install`:`${e.title} wasn’t added`}:e.state==="waiting"?{state:"next",words:`${n[0]} ${e.title}`}:{state:"now",words:`${n[0]} ${e.title}…`}}function gG(e){const[n,s]=h.useState(null),[r,a]=h.useState(null);return h.useEffect(()=>{if(s(null),a(null),!e)return;let i=!1,l;const o=()=>{R.catalogueJob(e).then(c=>{i||(s(c),c.state==="running"&&(l=window.setTimeout(o,HR)))}).catch(c=>{i||a(_l(c))})};return o(),()=>{i=!0,l!==void 0&&window.clearTimeout(l)}},[e]),{job:n,error:r,setJob:s}}function KR({entry:e,navigate:n,onClose:s,onAdded:r}){var Je;const a=ws("(max-width: 720px)"),[i,l]=h.useState(null),[o,c]=h.useState(null),[u,d]=h.useState({}),[f,m]=h.useState(""),[p,g]=h.useState([]),[v,b]=h.useState(!1),[j,x]=h.useState(null),[y,w]=h.useState(!1),[k,N]=h.useState(null),{job:S,error:C,setJob:E}=gG(j),[T,I]=h.useState(!1),[F,D]=h.useState(null),[$,L]=h.useState(!1),O=h.useRef(!1),[M,P]=h.useState([]);h.useEffect(()=>{if(!i||i.plugins.length===0)return;let W=!1;return Promise.resolve().then(()=>R.market()).then(se=>{W||P((se==null?void 0:se.plugins)??[])}).catch(()=>{}),()=>{W=!0}},[i]),h.useEffect(()=>{let W=!1;return R.cataloguePlan(e.name).then(se=>{W||(l(se),d(Object.fromEntries(se.fills.map(Y=>[Y.id,Y.value]))),m(se.handle))}).catch(se=>{W||c(_l(se))}),()=>{W=!0}},[e.name]),h.useEffect(()=>{(S==null?void 0:S.state)==="done"&&S.agent&&!O.current&&(O.current=!0,r==null||r(S.agent))},[S,r]);const H=()=>{i&&(w(!0),N(null),O.current=!1,R.catalogueInstall(e.name,{version:i.version,fills:u,handle:f,missionsOn:p,tools:i.tools.map(W=>W.name)}).then(W=>x(W.jobId)).catch(W=>N(_l(W))).finally(()=>w(!1)))},U=()=>{x(null),H()},V=e.title,z=S==null?void 0:S.agent,X=W=>{z&&(W&&xu(z.id,W),s(),n(Ze(z.id)))},K=W=>{S&&(I(!0),D(null),R.catalogueConfirm(S.id,W).then(se=>{E(se),W||s()}).catch(se=>D(_l(se))).finally(()=>I(!1)))};if((S==null?void 0:S.state)==="confirm"&&S.confirm){const W=Vh(S.confirm.tools.map(Y=>Y.name),Gh(S.confirm.tools)),se=S.steps.filter(Y=>Y.kind==="plugin"&&Y.state==="done").map(Y=>Y.title);return t.jsxs(Ge,{title:t.jsxs(ta,{entry:e,children:["Add ",V]}),onClose:s,foot:t.jsxs(te,{children:[t.jsx(et,{}),t.jsx(A,{variant:"ghost",disabled:T,onClick:()=>K(!1),children:"Don’t add it"}),t.jsxs(A,{variant:"accent",disabled:T,onClick:()=>K(!0),children:["Add ",V]})]}),children:[t.jsx("ol",{className:"cat-steps","data-testid":"cat-confirm",children:S.steps.filter(Y=>Y.kind==="plugin").map(Y=>{const{state:Ne,words:we}=zp(Y);return t.jsx(_p,{state:Ne,children:we},`${Y.kind}-${Y.name}`)})}),t.jsxs(G,{tone:"warning",title:`${V} would get more than the list showed.`,children:[se.length>0?`With ${rn(se)} installed, `:"","its tools resolved to a different set",S.confirm.unshown.length>0?`, including ${rn(S.confirm.unshown)}`:"",". Look at what it can reach before you add it."]}),t.jsx(ne,{message:F}),t.jsxs("div",{className:"cat-block",children:[t.jsx("h3",{className:"cat-block-title",children:"What it can reach"}),t.jsxs("p",{className:"cat-prose",children:[VN(W)," ",t.jsx("button",{type:"button",className:"plugins-link cat-link",onClick:()=>L(!$),children:$?"Hide":"See all"})]}),$?t.jsx("dl",{className:"cat-reach",children:W.map(([Y,Ne])=>t.jsxs("div",{className:"cat-reach-row",children:[t.jsx("dt",{children:Y}),t.jsx("dd",{children:Ne})]},Y))}):null]}),t.jsx("p",{className:"cat-small",children:"The plugins stay installed either way; Settings → Plugins removes them."})]})}if(j&&(!S||S.state==="running")){const W=S==null?void 0:S.steps[S.steps.length-1],se=(S==null?void 0:S.approvalId)&&(W==null?void 0:W.state)==="adding";return t.jsxs(Ge,{title:t.jsxs(ta,{entry:e,children:["Add ",V]}),onClose:s,foot:t.jsx(te,{align:"end",children:t.jsx(A,{onClick:s,children:"Close"})}),children:[t.jsx("ol",{className:"cat-steps","aria-live":"polite","data-testid":"cat-progress",children:((S==null?void 0:S.steps)??[]).map(Y=>{const{state:Ne,words:we}=zp(Y);return t.jsx(_p,{state:Ne,children:we},`${Y.kind}-${Y.name}`)})}),se?t.jsxs(G,{tone:"accent",action:t.jsx(A,{size:"sm",onClick:()=>{s(),n(ql)},children:"Open it"}),children:["Adding ",V," waits for your approval in Needs you."]}):null,t.jsx(ne,{message:C}),t.jsxs("p",{className:"cat-small",children:["You can close this; it carries on, and ",V," joins the team when it’s done."]})]})}if((S==null?void 0:S.state)==="done"){const W=S.steps.filter(Ne=>Ne.kind==="plugin").map(Ne=>Ne.title),se=(i==null?void 0:i.missions.length)??e.missions.length,Y=p.length;return t.jsxs(Ge,{title:t.jsx(ta,{entry:e,children:V}),onClose:s,foot:t.jsxs(te,{children:[t.jsx(A,{variant:"ghost",onClick:()=>{s(),n(sn())},children:"Back to teammates"}),t.jsx(et,{}),t.jsx(A,{variant:"accent",onClick:()=>X(),children:"Say hello"})]}),children:[t.jsxs("div",{className:"cat-done","data-testid":"cat-done",children:[t.jsx(So,{entry:e,size:"xxl"}),t.jsxs("p",{className:"cat-done-title",children:[V," is on your team."]}),t.jsxs("p",{className:"cat-small",children:["@",(z==null?void 0:z.handle)??f,W.length?` · ${rn(W)} installed`:"",se>0&&Y<se?` · ${se-Y===1?"a mission":"missions"} off until you turn ${se-Y===1?"it":"them"} on`:""]})]}),e.examples.length>0?t.jsxs("div",{className:"cat-block",children:[t.jsx("h3",{className:"cat-block-title",children:"Try one"}),t.jsx("div",{className:"wb-starters",children:e.examples.map(Ne=>t.jsx("button",{type:"button",className:"wb-starter",onClick:()=>X(Ne),children:Ne},Ne))})]}):null]})}if((S==null?void 0:S.state)==="failed"){const W=S.steps.find(se=>se.kind==="plugin"&&se.state==="failed");return t.jsxs(Ge,{title:t.jsxs(ta,{entry:e,children:[V," wasn’t added"]}),onClose:s,foot:t.jsxs(te,{children:[t.jsx(et,{}),t.jsx(A,{variant:"ghost",onClick:s,children:"Close"}),t.jsx(A,{variant:"accent",disabled:y,onClick:U,children:"Try again"})]}),children:[t.jsx("ol",{className:"cat-steps","data-testid":"cat-failed",children:S.steps.map(se=>{const{state:Y,words:Ne}=zp(se);return t.jsx(_p,{state:Y==="now"?"next":Y,children:Y==="now"?Ne.replace(/…$/,""):Ne},`${se.kind}-${se.name}`)})}),t.jsx(G,{tone:"critical",title:`${S.error??"It stopped before it finished"}.`,action:S.approvalId?t.jsx(A,{size:"sm",onClick:()=>{s(),n(ql)},children:"Open the approval"}):void 0,children:t.jsxs("p",{children:["Nothing was added and nothing else changed.",W?t.jsxs(t.Fragment,{children:[" ",W.title," waits in"," ",t.jsx("a",{href:Le("plugins"),onClick:se=>{se.preventDefault(),s(),n(Le("plugins"))},children:"Settings → Plugins"})," ","if you’d rather look at it there."]}):null]})}),t.jsx(ne,{message:k})]})}const ee=(i==null?void 0:i.plugins.filter(W=>W.fix==="install"&&W.byBuddi))??[],ce=(i==null?void 0:i.blocked)??[],pe=ce[0],oe=pe?WR(pe):null,Re=Vh(i?i.tools.map(W=>W.name):e.tools,Gh([...((Je=e.claims)==null?void 0:Je.tools)??[],...((i==null?void 0:i.tools)??[]).filter(W=>W.tier!=="unknown")])),Oe=W=>{var se;return((se=e.missions.find(Y=>Y.id===W))==null?void 0:se.when)??""};return t.jsxs(Ge,{title:t.jsxs(ta,{entry:e,children:["Add ",V]}),onClose:s,foot:t.jsxs(te,{children:[a?null:t.jsx("span",{className:"plugins-foot-note",children:ee.length?`Installs ${rn(ee.map(W=>W.title))}, then adds ${V}.`:"Nothing runs until you add it."}),t.jsx(et,{}),t.jsx(A,{variant:"ghost",onClick:s,children:"Cancel"}),t.jsxs(A,{variant:"accent",disabled:!i||ce.length>0||y||f.length<2,onClick:H,children:["Add ",V]})]}),children:[t.jsxs("p",{className:"cat-lede",children:[e.pitch," One approval adds it; you can change or remove it from its page."]}),t.jsx(ne,{message:o??k}),!i&&!o?t.jsx(ve,{children:"Reading what it needs…"}):i?t.jsxs(ie,{divided:!0,gap:"lg",children:[ee.length>0?t.jsxs("div",{className:"cat-block",children:[t.jsx("h3",{className:"cat-block-title",children:"Installed on the way"}),t.jsx("ul",{className:"cat-plugins",children:ee.map(W=>{const se=M.find(Y=>Y.name===W.name);return t.jsxs("li",{children:[t.jsx(Un,{svg:se==null?void 0:se.iconSvg}),t.jsxs("span",{className:"cat-plugin-text",children:[t.jsxs("span",{className:"cat-plugin-name",children:[W.title," ",W.version?t.jsx("span",{className:"plugins-ver",children:W.version}):null]}),t.jsx("span",{className:"cat-small",children:se!=null&&se.summary?pG(se.summary):"Made by buddi; installed only if it matches what withbuddi.com lists."})]}),t.jsx(Ee,{tone:"accent",children:"by buddi"})]},W.name)})})]}):null,pe?t.jsxs(G,{tone:"warning",action:oe?t.jsx(A,{size:"sm",onClick:()=>{s(),n(oe.route)},children:oe.label}):void 0,children:[V," needs ",rn(ce.map(BR))," first. Add ",ce.length===1?"it":"them",", then come back; nothing is added until then."]}):null,i.fills.length>0?t.jsxs("div",{className:"cat-block",children:[t.jsxs("h3",{className:"cat-block-title",children:["A few picks ",t.jsx("span",{className:"cat-block-aside",children:"filled in for you"})]}),t.jsx("div",{className:"cat-fills",children:i.fills.map(W=>t.jsx(re,{label:t.jsxs(t.Fragment,{children:[W.label,W.optional?t.jsx("span",{className:"faint",children:" · optional"}):null]}),children:W.choices&&W.choices.length>0?t.jsxs("select",{value:u[W.id]??"",onChange:se=>d({...u,[W.id]:se.target.value}),children:[W.kind==="calendar"?t.jsx("option",{value:"",children:"All of them"}):null,W.choices.map(se=>t.jsx("option",{value:se,children:se},se))]}):W.kind==="time"?t.jsx("input",{type:"time",value:u[W.id]??"",onChange:se=>d({...u,[W.id]:se.target.value})}):t.jsx("input",{value:u[W.id]??"",onChange:se=>d({...u,[W.id]:se.target.value})})},W.id))})]}):null,t.jsx("div",{className:"cat-block",children:t.jsx(re,{label:"Handle",hint:"How you call it in chat and on Telegram.",children:t.jsxs("span",{className:"cat-handle",children:[t.jsx("span",{className:"mono faint",children:"@"}),t.jsx("input",{className:"mono","aria-label":"Handle",value:f,onChange:W=>m(W.target.value.toLowerCase().replace(/[^a-z0-9-]/g,""))})]})})}),i.missions.length>0?t.jsxs("div",{className:"cat-block",children:[t.jsxs("h3",{className:"cat-block-title",children:["Missions ",t.jsx("span",{className:"cat-block-aside",children:"off unless you turn one on"})]}),t.jsx("ul",{className:"cat-missions","data-switches":"true",children:i.missions.map(W=>t.jsxs("li",{children:[t.jsx("span",{className:"cat-mission-name",children:W.name}),t.jsx("span",{className:"cat-mission-when",children:Oe(W.id)}),t.jsx(R$,{checked:p.includes(W.id),label:`Turn on ${W.name}`,onChange:se=>g(se?[...p,W.id]:p.filter(Y=>Y!==W.id))})]},W.id))})]}):null,t.jsxs("div",{className:"cat-block",children:[t.jsx("h3",{className:"cat-block-title",children:"What it can reach"}),t.jsxs("p",{className:"cat-prose",children:[VN(Re)," ",t.jsx("button",{type:"button",className:"plugins-link cat-link",onClick:()=>b(!v),children:v?"Hide":"See all"})]}),v?t.jsx("dl",{className:"cat-reach",children:Re.map(([W,se])=>t.jsxs("div",{className:"cat-reach-row",children:[t.jsx("dt",{children:W}),t.jsx("dd",{children:se})]},W))}):null]})]}):null]})}function xG(e){const n=[];let s=null,r=0;for(const a of e){const i=/^@@ -\d+,\d+ \+(\d+),(\d+) @@$/.exec(a);if(i){const c=Number(i[2])===0?Number(i[1])+1:Number(i[1]);n.length>0&&c-1>r&&n.push({kind:"gap",count:c-1-r}),s=c;continue}const l=a.startsWith("+ ")?"add":a.startsWith("- ")?"del":"ctx",o=l==="ctx"&&!a.startsWith(" ")?a:a.slice(2);l==="del"||s===null?n.push({kind:l,text:o,n:null}):(n.push({kind:l,text:o,n:s}),r=s,s+=1)}return n}function GN({lines:e,label:n}){return t.jsx("div",{className:"cat-diff",role:"region","aria-label":n,children:xG(e).map((s,r)=>s.kind==="gap"?t.jsxs("div",{className:"cat-diff-line","data-kind":"gap",children:[t.jsx("span",{className:"cat-diff-n","aria-hidden":"true"}),t.jsx("span",{className:"cat-diff-k","aria-hidden":"true"}),t.jsxs("span",{children:["⋯ ",s.count," ",s.count===1?"line":"lines"]})]},r):t.jsxs("div",{className:"cat-diff-line","data-kind":s.kind,children:[t.jsx("span",{className:"cat-diff-n","aria-hidden":"true",children:s.n??""}),t.jsx("span",{className:"cat-diff-k","aria-hidden":"true",children:s.kind==="add"?"+":s.kind==="del"?"-":" "}),t.jsx("span",{children:s.text||" "})]},r))})}function VR({entry:e,agentId:n,onClose:s,onUpdated:r}){const[a,i]=h.useState(null),[l,o]=h.useState(null),[c,u]=h.useState(!1),[d,f]=h.useState(!1),[m,p]=h.useState(!1);h.useEffect(()=>{let y=!1;return R.catalogueUpdatePlan(e.name,n).then(w=>{y||i(w)}).catch(w=>{y||o(_l(w))}),()=>{y=!0}},[e.name,n]);const g=eo((a==null?void 0:a.version)??e.version),v=y=>{a&&(f(!0),o(null),R.catalogueUpdate(e.name,n,a.plan,y).then(()=>{p(!0),r==null||r()}).catch(w=>{o(_l(w)),R.catalogueUpdatePlan(e.name,n).then(i).catch(()=>{})}).finally(()=>f(!1)))};if(m)return t.jsx(Ge,{title:t.jsxs(ta,{entry:e,children:[e.title," ",g]}),onClose:s,foot:t.jsx(te,{align:"end",children:t.jsx(A,{variant:"accent",onClick:s,children:"Done"})}),children:t.jsx(G,{tone:"good",title:`${e.title} is on ${g}.`,role:"status",children:a!=null&&a.edited?"Your version is in the trash folder if you want any of it back.":"Your picks and missions are as they were."})});if(!a)return t.jsxs(Ge,{title:t.jsxs(ta,{entry:e,children:["Update ",e.title]}),onClose:s,children:[t.jsx(ne,{message:l}),l?null:t.jsx(ve,{children:"Reading what changed…"})]});const b=a.personaDiff.filter(y=>y.startsWith("+ ")).length,j=a.personaDiff.filter(y=>y.startsWith("- ")).length;if(a.edited)return t.jsxs(Ge,{title:t.jsxs(ta,{entry:e,children:[e.title," ",g," is out"]}),onClose:s,foot:t.jsxs(te,{children:[c?null:t.jsx(A,{variant:"ghost",onClick:()=>u(!0),children:"See what changed"}),t.jsx(et,{}),t.jsx(A,{variant:"ghost",onClick:s,children:"Keep mine"}),t.jsx(A,{variant:"danger",disabled:d,onClick:()=>v(!0),children:"Replace my changes"})]}),children:[t.jsx(G,{tone:"accent",children:a.replacesOwn&&a.replacesOwn.length>0?`${g} brings ${a.replacesOwn.length===1?"a skill":"skills"} named like your own (${rn(a.replacesOwn)}), so nothing is updated on its own. Yours stay exactly as they are unless you replace them; replaced, they go to the trash folder.`:a.via?`${e.title} replaces your @${a.handle}. You’ve changed @${a.handle}, so nothing is replaced on its own. Your file stays exactly as it is unless you replace it; its handle, chats, memory and missions stay either way.`:`You’ve changed ${e.title} since you added it, so nothing is updated on its own. Your file stays exactly as it is unless you replace it.`}),t.jsx(ne,{message:l}),t.jsxs(ie,{divided:!0,gap:"lg",children:[t.jsxs("div",{className:"cat-block",children:[t.jsxs("h3",{className:"cat-block-title",children:["New in ",g]}),t.jsx("p",{className:"cat-prose",children:a.changes})]}),t.jsxs("div",{className:"cat-block",children:[t.jsxs("h3",{className:"cat-block-title",children:["Your file and ",g," ",t.jsx("button",{type:"button",className:"cat-block-aside plugins-link",onClick:()=>u(!c),children:c?"Hide":"See what changed"})]}),c?t.jsxs(t.Fragment,{children:[t.jsx(GN,{lines:a.personaDiff,label:`Your ${e.title} against ${g}`}),t.jsxs("p",{className:"cat-small",children:["Lines marked − are in your file and not in ",g,"; + is new in ",g,". Replacing keeps your picks, and drops what you wrote by hand."]})]}):t.jsxs("p",{className:"cat-small",children:[j===1?"1 line":`${j} lines`," only in your file, ",b===1?"1 line":`${b} lines`," new in ",g,"."]})]})]})]});const x=a.added.length>0?`New: ${rn(Vh(a.added.map(y=>y.name),Gh(a.added)).map(([y])=>y))}. The approval lists each tool.`:"No new tools. It reaches what it reaches today.";return t.jsxs(Ge,{title:t.jsxs(ta,{entry:e,children:["Update ",e.title," to ",g]}),onClose:s,foot:t.jsxs(te,{children:[t.jsx("span",{className:"plugins-foot-note",children:"Your picks and handle stay."}),t.jsx(et,{}),t.jsx(A,{variant:"ghost",onClick:s,children:"Not now"}),t.jsxs(A,{variant:"accent",disabled:d,onClick:()=>v(!1),children:["Update ",e.title]})]}),children:[t.jsx("p",{className:"cat-lede",children:a.changes}),t.jsx(ne,{message:l}),t.jsxs(ie,{divided:!0,gap:"lg",children:[t.jsxs("div",{className:"cat-block",children:[t.jsx("h3",{className:"cat-block-title",children:"What changes in its file"}),a.personaDiff.length>0?t.jsx(GN,{lines:a.personaDiff,label:a.via?`@${a.handle} against ${e.title} ${g}`:`${e.title} ${eo(a.fromVersion)} against ${g}`}):t.jsx("p",{className:"cat-prose",children:"Its persona stays word for word."})]}),t.jsxs("div",{className:"cat-block",children:[t.jsx("h3",{className:"cat-block-title",children:"What it can reach"}),t.jsxs("p",{className:"cat-prose",children:[x,a.removed.length>0?` No longer: ${a.removed.join(", ")}.`:""]})]}),t.jsxs("div",{className:"cat-block",children:[t.jsx("h3",{className:"cat-block-title",children:"Missions"}),t.jsxs("p",{className:"cat-prose",children:[a.missionsAdded.length>0?`${rn(a.missionsAdded.map(y=>y.name))} added, off until you turn ${a.missionsAdded.length===1?"it":"them"} on.`:"None added.",(a.missionsChanged??[]).length>0?" Their prompt, hour and switch stay yours.":" Yours stay as they are."]}),(a.missionsChanged??[]).map(y=>t.jsxs("p",{className:"cat-prose",children:[y.name,": new settings — ",y.words,"."]},y.id))]}),a.retires&&a.retires.length>0?t.jsxs("div",{className:"cat-block",children:[t.jsx("h3",{className:"cat-block-title",children:"Skills"}),t.jsxs("p",{className:"cat-prose",children:[g," no longer has ",rn(a.retires),"; ",a.retires.length===1?"it goes":"they go"," to the trash folder."]})]}):null]})]})}function li(e){if(e.state==="unavailable")return"unavailable";const n=e.installed;return e.state!=="installed"||!n?"ready":n.drift==="update"?"update":n.drift==="edited-update"?"edited":"added"}function jw(){const e=me(()=>R.plugins(),[]);return h.useMemo(()=>{var n;return new Set((((n=e.data)==null?void 0:n.installed)??[]).filter(s=>s.loaded&&s.enabled!==!1).map(s=>s.name))},[e.data])}function yw(){return t.jsx(le,{name:"check",size:14})}function vG({entry:e,loaded:n,mailbox:s}){const r=li(e);if(r==="unavailable")return t.jsx("span",{className:"cat-chips",children:t.jsx("span",{className:"cat-chip","data-need":"true",children:"Needs a newer buddi"})});const a=e.missing??[];if(a.length>0)return t.jsx("span",{className:"cat-chips",children:t.jsxs("span",{className:"cat-chip","data-need":"true",children:["Needs ",rn(a.map(BR))]})});if(r!=="ready")return null;const i=hG(e,n,s);if(i.length===0)return null;const l=`Uses ${rn(i)}`;return t.jsx("span",{className:"cat-uses",title:l,children:l})}function jG({entry:e,onAdd:n,onUpdate:s}){const r=li(e),a=i=>l=>{l.stopPropagation(),i()};return r==="added"?t.jsxs("span",{className:"cat-added",children:[t.jsx(yw,{}),"Added"]}):r==="update"?t.jsx(A,{size:"sm",onClick:a(s),"aria-label":`Update ${e.title}`,children:"Update"}):r==="edited"?t.jsx(A,{size:"sm",onClick:a(s),children:"See what changed"}):r==="unavailable"?null:t.jsx(A,{size:"sm",variant:"accent",onClick:a(n),"aria-label":`Add ${e.title}`,children:"Add"})}function yG({entry:e}){var a,i,l,o;const n=li(e),s=eo(e.version),r=(a=e.installed)==null?void 0:a.handle;return(i=e.installed)!=null&&i.via&&n==="update"?t.jsxs("p",{className:"cat-note",children:["Replaces your @",r,": it keeps its handle, chats, memory and missions."]}):(l=e.installed)!=null&&l.via&&n==="edited"?t.jsxs("p",{className:"cat-note",children:["Replaces your @",r,", which you’ve changed."]}):n==="update"?t.jsxs("p",{className:"cat-note",children:[s," is out: ",e.changes.charAt(0).toLowerCase()+e.changes.slice(1)]}):n==="edited"?t.jsxs("p",{className:"cat-note",children:["You’ve changed ",e.title,"; ",s," is out."]}):n==="added"?t.jsxs("p",{className:"cat-note","data-quiet":"true",children:["On your team as @",(o=e.installed)==null?void 0:o.handle]}):n==="unavailable"?t.jsx("p",{className:"cat-note","data-quiet":"true",children:e.reason}):null}function GR({entry:e,loaded:n,mailbox:s,onOpen:r,onAdd:a,onUpdate:i}){return t.jsx("div",{className:"cat-card","data-state":li(e),"data-testid":`cat-card-${e.name}`,children:t.jsxs(Ts,{onClick:r,label:`${e.title}: details`,children:[t.jsxs("div",{className:"cat-card-head",children:[t.jsx(So,{entry:e,size:"lg"}),t.jsxs("div",{className:"cat-card-name",children:[t.jsx("h3",{className:"ui-card-title",children:e.title}),t.jsx("div",{className:"cat-card-kind",children:xw(e.category)})]})]}),t.jsx("p",{className:"cat-pitch",children:e.pitch}),t.jsx(yG,{entry:e}),t.jsxs("div",{className:"cat-card-foot",children:[t.jsx(vG,{entry:e,loaded:n,mailbox:s}),t.jsx(et,{}),t.jsx(jG,{entry:e,onAdd:a,onUpdate:i})]})]})})}function wG({row:e,agents:n,navigate:s,pages:r}){const a=nw(e.plugin,e.agent,()=>window.dispatchEvent(new Event(Dr))),i=a.created??(e.state==="installed"?{id:e.agent,handle:e.handle,name:e.name}:null),l=r?V$(e.plugin,r.all):dm(e.plugin);return t.jsx("div",{className:"cat-card","data-state":i?"added":"ready","data-testid":`cat-card-${e.agent}`,children:t.jsxs(Ts,{onClick:i?()=>s(Pt(i.id)):void 0,label:i?`Open @${i.handle}`:void 0,children:[t.jsxs("div",{className:"cat-card-head",children:[t.jsx("span",{className:"cat-face","data-size":"lg",children:t.jsx(Nn,{id:e.agent,name:e.name,size:"lg",face:n.find(o=>o.id===e.agent)})}),t.jsxs("div",{className:"cat-card-name",children:[t.jsx("h3",{className:"ui-card-title",children:e.name}),t.jsxs("div",{className:"cat-card-kind",children:["From ",l]})]})]}),t.jsx("p",{className:"cat-pitch",children:e.text}),i?t.jsxs("p",{className:"cat-note","data-quiet":"true",children:["On your team as @",i.handle]}):null,t.jsxs("div",{className:"cat-card-foot",children:[t.jsx(ne,{message:a.failure}),t.jsx(et,{}),i?t.jsxs("span",{className:"cat-added",children:[t.jsx(yw,{}),"Added"]}):t.jsx(A,{size:"sm",variant:"accent",disabled:a.busy,onClick:o=>{o.stopPropagation(),a.accept()},"aria-label":`Add ${e.name}`,children:"Add"})]})]})})}function bG({n:e=6}){return t.jsx("div",{className:"cat-grid","aria-busy":"true","aria-label":"Loading the catalogue","data-testid":"cat-loading",children:Array.from({length:e},(n,s)=>t.jsxs("div",{className:"ui-card cat-skel",children:[t.jsxs("div",{className:"cat-card-head",children:[t.jsx("i",{className:"cat-skel-face"}),t.jsxs("span",{className:"cat-card-name",children:[t.jsx("i",{className:"cat-skel-line","data-w":"40"}),t.jsx("i",{className:"cat-skel-line","data-w":"20"})]})]}),t.jsx("i",{className:"cat-skel-line","data-w":"90"}),t.jsx("i",{className:"cat-skel-line","data-w":"70"})]},s))})}function kG(e,n,s){const r=e.find(a=>a.roles.includes(Fr));r&&(s.trim()&&xu(r.id,`I'd like a teammate for this: ${s.trim()}`),n(Ze(r.id)))}function NG({sheet:e,view:n,navigate:s,onClose:r,onChanged:a}){const i=e?n==null?void 0:n.agents.find(l=>l.name===e.name):void 0;return!e||!i?null:e.kind==="update"&&i.installed?t.jsx(VR,{entry:i,agentId:i.installed.agentId,onClose:r,onUpdated:a}):t.jsx(KR,{entry:i,navigate:s,onClose:r,onAdded:a})}const SG=[{value:"all",label:"All"},{value:"work",label:"Work"},{value:"money",label:"Money"},{value:"home",label:"Home"},{value:"health",label:"Health"},{value:"learning",label:"Learning"},{value:"life",label:"Life"}];function CG(e,n){return[e.title,e.pitch,e.about,e.description,xw(e.category)].some(s=>s.toLowerCase().includes(n))}function EG({name:e,agents:n,navigate:s,pluginPages:r}){const[a,i]=h.useState(0),l=me(()=>R.catalogue(a>0),[a]),o=jw(),[c,u]=h.useState(""),[d,f]=h.useState("all"),[m,p]=h.useState(null),g=l.data,v=()=>{l.reload(),window.dispatchEvent(new Event(Dr))},b=()=>i(E=>E+1),j=t.jsx(NG,{sheet:m,view:g,navigate:s,onClose:()=>p(null),onChanged:v}),x=e?g==null?void 0:g.agents.find(E=>E.name===e):void 0,y=h.useRef(!1);if(h.useEffect(()=>{y.current||!x||!o3(window.location.hash,x.name)||(y.current=!0,li(x)==="ready"&&p({kind:"install",name:x.name}))},[x]),e&&g&&!g.unavailable&&x)return t.jsxs(t.Fragment,{children:[t.jsx(TG,{entry:x,loaded:o,agents:n,navigate:s,onAdd:()=>p({kind:"install",name:x.name}),onUpdate:()=>p({kind:"update",name:x.name})}),j]});const w=c.trim().toLowerCase(),N=((g==null?void 0:g.agents)??[]).filter(E=>(d==="all"||E.category===d)&&(!w||CG(E,w))),S=((g==null?void 0:g.fromPlugins)??[]).filter(E=>d==="all"&&(!w||[E.name,E.text,E.description].some(T=>T.toLowerCase().includes(w)))),C=E=>()=>s(E);return t.jsxs(Iy,{children:[t.jsx(Ql,{before:t.jsx(Ih,{inline:!0,items:[{label:"Agents",href:vt,onClick:C(vt)}]}),title:"Add a teammate",lede:"Agents tested with the plugins they use. Adding one is one approval, and it becomes a file on this computer you can change."}),e&&g&&!g.unavailable&&!x?t.jsxs(G,{tone:"warning",children:["The catalogue lists no teammate called “",e,"”. Here is everyone it does list."]}):null,t.jsxs("div",{className:"cat-bar",children:[t.jsxs("div",{className:"cat-search",children:[t.jsx(le,{name:"search",size:16}),t.jsx(nm,{label:"Search teammates",value:c,placeholder:"Search: meals, money, a language…",onChange:u})]}),t.jsx("div",{className:"cat-cats",children:t.jsx(M$,{label:"Category",options:SG,value:d,onChange:f})})]}),g&&!g.unavailable?g.stale?t.jsxs("p",{className:"plugins-quiet","data-testid":"cat-stale",children:[t.jsx(le,{name:"globe",size:14}),"From the list kept ",g.fetchedAt?AG(g.fetchedAt):"earlier",": withbuddi.com didn’t answer just now."," ",t.jsx("button",{type:"button",className:"plugins-link",onClick:b,children:"Try again"})]}):t.jsxs("p",{className:"plugins-quiet",children:[t.jsx(le,{name:"globe",size:14}),"Opening this page fetched the list from withbuddi.com. Nothing else leaves."]}):null,l.error&&!g?t.jsx(ve,{warm:!0,title:"The catalogue didn’t load",action:t.jsx(A,{variant:"accent",size:"sm",onClick:b,children:"Try again"}),children:l.error}):g?g.unavailable?t.jsx(ve,{warm:!0,title:"The catalogue needs withbuddi.com",action:t.jsx(A,{variant:"accent",size:"sm",disabled:l.loading,onClick:b,children:"Try again"}),children:"This computer can’t reach it right now, and there’s no saved copy yet. Try again when you’re online."}):N.length+S.length>0?t.jsxs("div",{className:"cat-grid","data-testid":"cat-grid",children:[N.map(E=>t.jsx(GR,{entry:E,loaded:o,mailbox:g.mailbox,onOpen:()=>s(sn(E.name)),onAdd:()=>p({kind:"install",name:E.name}),onUpdate:()=>p({kind:"update",name:E.name})},E.name)),S.map(E=>t.jsx(wG,{row:E,agents:n,navigate:s,pages:r},`${E.plugin}/${E.agent}`))]}):t.jsx(ve,{warm:!0,title:"No teammate for that yet",action:t.jsxs("span",{className:"cat-empty-acts",children:[t.jsx(A,{size:"sm",variant:"ghost",onClick:()=>{u(""),f("all")},children:"Show all"}),t.jsx(A,{size:"sm",variant:"accent",onClick:()=>kG(n,s,c),children:"Ask Agent Father"})]}),children:w?t.jsxs(t.Fragment,{children:["Nothing in the catalogue does “",c.trim(),"”. Agent Father can make one for you; your words go with you."]}):"Nothing in this category yet."}):t.jsx(bG,{}),g&&!g.unavailable&&g.delisted.length>0?t.jsx(Ye,{title:"No longer in the catalogue",children:t.jsx("ul",{className:"cat-plugins","data-testid":"cat-delisted",children:g.delisted.map(E=>t.jsxs("li",{children:[t.jsx(fn,{agents:n,id:E.agentId,size:"sm"}),t.jsxs("span",{className:"cat-plugin-text",children:[t.jsx("a",{className:"cat-plugin-name",href:Pt(E.agentId),onClick:T=>{T.preventDefault(),s(Pt(E.agentId))},children:E.name??`@${E.handle}`}),t.jsxs("span",{className:"cat-small",children:["@",E.handle," keeps working as it is; no updates will come."]})]})]},E.agentId))})}):null,j]})}function AG(e){const n=Math.round((Date.now()-Date.parse(e))/36e5);if(!Number.isFinite(n)||n<1)return"an hour ago";if(n<24)return`${n} h ago`;const s=Math.round(n/24);return s===1?"yesterday":`${s} days ago`}function mi({title:e,children:n}){return t.jsxs("section",{className:"cat-row",children:[t.jsx("h2",{className:"cat-row-title",children:e}),t.jsx("div",{className:"cat-row-body",children:n})]})}function $G({entry:e,loaded:n,navigate:s}){const r=new Map((e.missing??[]).map(i=>[i.name,i])),a=[...Object.keys(e.requires).map(i=>({name:i,needed:!0,need:!1})),...Object.keys(e.optional).map(i=>({name:i,needed:!1,need:!1})),...e.needs.map(i=>({name:i.replace(/\?$/,""),needed:!i.endsWith("?"),need:!0}))];return a.length===0?t.jsx("p",{className:"cat-small",children:"None. It works with what buddi has."}):t.jsx("ul",{className:"cat-plugins",children:a.map(({name:i,needed:l,need:o})=>{const c=r.get(i),u=c?WR(c):null,d=o?vw(i).title:(c==null?void 0:c.kind)==="plugin"?c.title:dm(i),f=o?l&&!c:n.has(i);return t.jsxs("li",{children:[t.jsx("span",{className:"ui-app-icon","aria-hidden":"true",children:t.jsx(le,{name:o?i==="mailbox"?"mail":"key":"plug",size:14})}),t.jsxs("span",{className:"cat-plugin-text",children:[t.jsx("span",{className:"cat-plugin-name",children:d.charAt(0).toUpperCase()+d.slice(1)}),t.jsx("span",{className:"cat-small",children:l?"Needed":"Better with it"})]}),u?t.jsx(A,{size:"sm",onClick:()=>s(u.route),children:u.label}):c?t.jsx("span",{className:"cat-small",children:"Installed when you add it"}):f?t.jsxs("span",{className:"cat-added",children:[t.jsx(yw,{}),o?"You have one":"Installed"]}):t.jsx("span",{className:"cat-small",children:o?"Optional":"Not installed"})]},`${o?"need":"plugin"}-${i}`)})})}function TG({entry:e,loaded:n,agents:s,navigate:r,onAdd:a,onUpdate:i}){var g,v,b,j;const l=li(e),c=(g=e.installed)==null?void 0:g.agentId,u=eo(e.version),d=(v=e.installed)!=null&&v.via?e.installed:void 0,f=x=>{c&&(x&&xu(c,x),r(Ze(c)))},m=Vh(e.tools,Gh((b=e.claims)==null?void 0:b.tools)),p=e.replaces.map(x=>Fp(x.split("/")[1]??x));return t.jsxs(Iy,{children:[t.jsxs("a",{className:"cat-back",href:sn(),onClick:x=>{x.preventDefault(),r(sn())},children:[t.jsx(le,{name:"chevron-left",size:12}),"Teammates"]}),t.jsxs("header",{className:"cat-hero",children:[t.jsx(So,{entry:e,size:"xxl"}),t.jsxs("div",{className:"cat-hero-text",children:[t.jsx("h1",{className:"cat-hero-title",children:e.title}),t.jsx("p",{className:"cat-hero-pitch",children:e.pitch}),t.jsxs("p",{className:"cat-hero-meta",children:[e.trust==="by-buddi"?t.jsx(Ee,{tone:"accent",children:"by buddi"}):null,t.jsx("span",{children:xw(e.category)}),t.jsx("span",{"aria-hidden":"true",children:"·"}),t.jsx("span",{className:"mono",children:d?e.version:((j=e.installed)==null?void 0:j.version)??e.version}),e.installed?t.jsxs(t.Fragment,{children:[t.jsx("span",{"aria-hidden":"true",children:"·"}),t.jsxs("span",{children:["on your team as ",t.jsxs("span",{className:"mono",children:["@",e.installed.handle]})]})]}):null]})]}),t.jsx("div",{className:"cat-hero-act",children:l==="ready"?t.jsxs(A,{variant:"accent",onClick:a,children:["Add ",e.title]}):l==="update"?t.jsxs(t.Fragment,{children:[t.jsx(A,{variant:"ghost",onClick:()=>f(),children:"Open chat"}),t.jsx(A,{variant:"accent",onClick:i,children:d?`Update @${d.handle} to ${e.title}`:`Update to ${u}`})]}):l==="edited"?t.jsxs(t.Fragment,{children:[t.jsx(A,{variant:"ghost",onClick:()=>f(),children:"Open chat"}),t.jsx(A,{onClick:i,children:"See what changed"})]}):l==="unavailable"?null:t.jsx(A,{variant:"accent",onClick:()=>f(),children:"Open chat"})})]}),l==="edited"&&d?t.jsxs(G,{tone:"accent",children:[e.title," replaces your @",d.handle,". You’ve changed it, so it isn’t replaced on its own: your file stays as it is unless you replace it."]}):l==="edited"?t.jsxs(G,{tone:"accent",children:["You’ve changed ",e.title," since you added it, so ",u," isn’t applied on its own. Your file stays as it is unless you replace it."]}):l==="unavailable"?t.jsx(G,{tone:"warning",children:e.reason}):null,t.jsx(Ye,{flush:!0,children:t.jsxs("div",{className:"cat-rows",children:[t.jsxs(mi,{title:"What it does",children:[t.jsx("p",{className:"cat-prose",children:e.about}),p.length>0?t.jsxs("p",{className:"cat-small",children:["Does what ",rn(p)," did. If you have ",rn(p)," and haven’t changed it, it’s offered as an update."]}):null]}),e.examples.length>0?t.jsxs(mi,{title:"Ask it",children:[t.jsx("div",{className:"wb-starters",children:e.examples.map(x=>t.jsx("button",{type:"button",className:"wb-starter",disabled:!c,onClick:()=>f(x),children:x},x))}),c?null:t.jsx("p",{className:"cat-small",children:"Once it’s on your team, a tap opens a chat with it."})]}):null,t.jsx(mi,{title:"Skills",children:e.skills.length===0?t.jsx("p",{className:"cat-small",children:"None. It works from its persona."}):t.jsxs(t.Fragment,{children:[t.jsx("ul",{className:"cat-plugins","data-testid":"cat-skills",children:e.skills.map(x=>t.jsxs("li",{children:[t.jsx("span",{className:"ui-app-icon","aria-hidden":"true",children:t.jsx(le,{name:"files",size:14})}),t.jsxs("span",{className:"cat-plugin-text",children:[t.jsx("span",{className:"cat-plugin-name",children:Fp(x.name)}),x.description?t.jsx("span",{className:"cat-small",children:x.description}):null,t.jsx(Ot,{summary:"Read it",children:t.jsx(Dt,{label:`${Fp(x.name)}: the skill's text`,children:x.text})})]})]},x.name))}),t.jsxs("p",{className:"cat-small",children:["Plain text, no code."," ",c?t.jsxs(t.Fragment,{children:["Read and change them on ",t.jsx("a",{href:Pt(c,"skills"),onClick:x=>{x.preventDefault(),r(Pt(c,"skills"))},children:"its Skills tab"}),"."]}):"Once it’s on your team they’re files you can read and change."]})]})}),t.jsxs(mi,{title:"What it can reach",children:[t.jsx("dl",{className:"cat-reach",children:m.map(([x,y])=>t.jsxs("div",{className:"cat-reach-row",children:[t.jsx("dt",{children:x}),t.jsx("dd",{children:y})]},x))}),t.jsx("p",{className:"cat-small",children:"Anything that sends or pays still asks you first, every time. You can change any of this on its page."})]}),t.jsx(mi,{title:"Missions",children:e.missions.length>0?t.jsx("ul",{className:"cat-missions",children:e.missions.map(x=>t.jsxs("li",{children:[t.jsx("span",{className:"cat-mission-name",children:x.name}),t.jsx("span",{className:"cat-mission-when",children:x.when}),t.jsx("span",{className:"cat-off",children:"off until you turn it on"})]},x.id))}):t.jsx("p",{className:"cat-small",children:"None. It works when you ask."})}),t.jsx(mi,{title:"Plugins",children:t.jsx($G,{entry:e,loaded:n,navigate:r})}),t.jsxs(mi,{title:"Version",children:[t.jsxs("p",{className:"cat-prose",children:[t.jsx("span",{className:"mono",children:e.version})," · ",e.changes]}),t.jsx("p",{className:"cat-small",children:"Reviewed in withbuddi/buddi-market. An update always asks you, and never touches a file you changed."})]})]})})]})}function RG(e){var r,a;const n=me(()=>R.agents(),[e]),s=(a=(r=n.data)==null?void 0:r.catalogue)==null?void 0:a[e];return{entry:s?{...s,agentId:e}:void 0,reload:n.reload}}function IG({entry:e,navigate:n,onUpdated:s}){const[r,a]=h.useState(null),[i,l]=h.useState(null),[o,c]=h.useState(!1),u=e.delisted?null:e.drift==="update"?"update":e.drift==="edited-update"?"edited":null,d=()=>{c(!0),l(null),R.catalogue().then(f=>{const m=f.agents.find(p=>p.name===e.package);m?a(m):l(f.unavailable??`The catalogue no longer lists ${e.title}.`)}).catch(f=>l(f instanceof xe?f.message:String(f))).finally(()=>c(!1))};return t.jsxs(t.Fragment,{children:[t.jsxs("p",{className:"agent-catalogue-line","data-testid":"agent-catalogue-line","data-delisted":e.delisted?"true":void 0,children:[e.delisted?t.jsx("span",{children:"No longer in the catalogue"}):t.jsx("a",{href:sn(e.package),onClick:f=>{f.preventDefault(),n(sn(e.package))},children:"From the catalogue"}),t.jsx("span",{"aria-hidden":"true",children:" · "}),t.jsxs("span",{children:[e.title," ",e.via?`(was ${e.via.split("/")[1]??e.via})`:eo(e.version)]}),e.delisted?t.jsx("span",{className:"muted",children:" · it keeps working; no updates will come"}):null,u?t.jsx(A,{size:"sm",variant:u==="update"?"accent":void 0,disabled:o,onClick:d,children:u==="update"&&e.latest?`Update to ${eo(e.latest)}`:u==="update"?"Update":"See what changed"}):null]}),i?t.jsx(ne,{message:i}):null,r?t.jsx(VR,{entry:r,agentId:e.agentId,onClose:()=>a(null),onUpdated:s}):null]})}function PG(e){return typeof e=="string"?e:e.name??e.id??"a mission"}function MG({agentId:e,name:n,navigate:s}){const[r,a]=h.useState(!1),[i,l]=h.useState(null),[o,c]=h.useState(null),[u,d]=h.useState(!1),[f,m]=h.useState(null),p=()=>{a(!1),m(null),s(vt)},g=w=>w instanceof xe?w.message:String(w),v=()=>{a(!0),c(null),l(null),R.agentRemovePreview(e).then(l).catch(w=>c(g(w)))},b=()=>{d(!0),c(null),R.removeAgent(e).then(w=>{var N;window.dispatchEvent(new Event(Dr));const k=(N=w.result)==null?void 0:N.delegateListsNotUpdated;if(Array.isArray(k)&&k.length>0){m(k.map(S=>String((S==null?void 0:S.handle)??(S==null?void 0:S.id)??"")));return}a(!1),s(vt)}).catch(w=>c(g(w))).finally(()=>d(!1))},j=(i==null?void 0:i.pausesMissions.map(PG))??[],x=(i==null?void 0:i.unusedPlugins)??[],y=((i==null?void 0:i.handedWorkBy)??[]).map(w=>`@${w}`);return t.jsxs(Ye,{children:[t.jsxs(te,{children:[t.jsxs("div",{className:"agent-remove-text",children:[t.jsx("strong",{children:"Remove from team"}),t.jsx("span",{className:"muted",children:"Its file goes to the trash folder; what it remembers and its conversations stay."})]}),t.jsxs(A,{variant:"danger-ghost",onClick:v,children:["Remove ",n,"…"]})]}),r&&f?t.jsx(zt,{title:`${n} is off your team`,onClose:p,foot:t.jsx(A,{variant:"accent",onClick:p,children:"Done"}),children:t.jsxs(G,{tone:"warning",title:"Cleanup is incomplete",role:"status",children:["The delegate list of ",rn(f.map(w=>`@${w}`))," could not be updated and still names it. That entry reaches nobody; edit the list to remove it."]})}):r?t.jsxs(zt,{title:`Remove ${n} from your team?`,onClose:()=>a(!1),foot:t.jsxs(t.Fragment,{children:[t.jsx(A,{variant:"ghost",onClick:()=>a(!1),children:"Cancel"}),t.jsx(A,{variant:"danger",disabled:u||!i,onClick:b,children:"Remove from team"})]}),children:[t.jsx(ne,{message:o}),i?t.jsxs("div",{className:"ui-stack","data-testid":"remove-preview",children:[t.jsxs("p",{children:["@",i.handle,"’s folder moves to the trash folder, so it can be brought back by hand."]}),j.length>0?t.jsxs("p",{children:["Its ",j.length===1?"mission":"missions"," ",rn(j)," ",j.length===1?"is":"are"," paused."]}):null,y.length>0?t.jsxs("p",{children:[rn(y)," will stop handing work to it."]}):null,x.length>0?t.jsxs("p",{children:["No other agent uses ",rn(x.map(dm)),"; it stays installed."," ",t.jsxs("a",{href:Le("plugins"),onClick:w=>{w.preventDefault(),a(!1),s(Le("plugins"))},children:["Remove ",x.length===1?"it":"them"," in Settings → Plugins"]}),"."]}):null]}):o?null:t.jsx("p",{className:"muted",children:"Reading what it would change…"})]}):null]})}const qR=["January","February","March","April","May","June","July","August","September","October","November","December"],qh=e=>e?{day:String(e.day),month:String(e.month),year:e.year?String(e.year):""}:{day:"",month:"",year:""};function Yh(e){if(e.day===""&&e.month===""&&e.year.trim()==="")return null;if(e.day===""||e.month==="")return"incomplete";const s=e.year.trim();return s!==""&&!/^\d{4}$/.test(s)?"incomplete":{day:Number(e.day),month:Number(e.month),year:s===""?null:Number(s)}}const DG=(e,n)=>(e??null)===(n??null)||!!e&&!!n&&e.day===n.day&&e.month===n.month&&(e.year??null)===(n.year??null),YR=(e,n=!0)=>`${e.day} ${qR[e.month-1]}${n&&e.year?` ${e.year}`:""}`;function yv({label:e,hint:n,value:s,onChange:r}){const a=Yh(s)==="incomplete";return t.jsx(re,{group:!0,label:e,hint:a?"A day and a month; the year is optional, four digits.":n,children:t.jsxs("div",{className:"day-month",children:[t.jsxs("select",{"aria-label":`${e}: day`,value:s.day,onChange:i=>r({...s,day:i.target.value}),children:[t.jsx("option",{value:"",children:"Day"}),Array.from({length:31},(i,l)=>t.jsx("option",{value:String(l+1),children:l+1},l+1))]}),t.jsxs("select",{"aria-label":`${e}: month`,value:s.month,onChange:i=>r({...s,month:i.target.value}),children:[t.jsx("option",{value:"",children:"Month"}),qR.map((i,l)=>t.jsx("option",{value:String(l+1),children:i},i))]}),t.jsx("input",{"aria-label":`${e}: year (optional)`,inputMode:"numeric",placeholder:"Year",maxLength:4,value:s.year,onChange:i=>r({...s,year:i.target.value.replace(/\D/g,"")})})]})})}const OG=8e3;function LG(e){return e.kind==="policy"&&e.state==="open"&&String(e.payload.plugin??"")==="memory"&&e.ruleKind==="person"}function FG(e){if(!e.next)return null;const n=e.next.what==="birthday"?"Birthday":"Anniversary",s=e.next.turning===null?"":e.next.what==="birthday"?` · turns ${e.next.turning}`:` · ${e.next.turning} years`;if(e.next.inDays===0)return`${n} today${s}`;if(e.next.inDays===1)return`${n} tomorrow${s}`;if(e.next.inDays<=14)return`${n} in ${e.next.inDays} days${s}`;if(e.next.inDays<=31)return`${n} in ${Math.round(e.next.inDays/7)} weeks`;const r=e[e.next.what];return r?`${n} ${YR(r,!1)}`:null}function qN({name:e,small:n}){return t.jsx("span",{className:"person-face","data-size":n?"sm":void 0,"aria-hidden":"true",children:e.trim().charAt(0).toUpperCase()})}function _G(){var b,j;const e=me(()=>R.people(),[],6e4),n=me(()=>R.proposals(),[],6e4),[s,r]=h.useState(null),[a,i]=h.useState(null),[l,o]=h.useState(null),[c,u]=h.useState(null),[d,f]=h.useState(null),m=async(x,y)=>{f(x),u(null);try{return await y(),e.reload(),n.reload(),!0}catch(w){return u(w instanceof xe?w.message:String(w)),!1}finally{f(null)}},p=(((b=n.data)==null?void 0:b.open)??[]).filter(LG),g=((j=e.data)==null?void 0:j.people)??[],v=x=>[x.relationship,x.birthday?`born ${YR(x.birthday)}`:null].filter(Boolean).join(" · ")||"No details yet";return t.jsxs(ie,{gap:"lg",children:[c?t.jsx(G,{tone:"critical",children:c}):null,p.length>0?t.jsxs(G,{tone:"accent",title:p.length===1?"One person to keep?":`${p.length} people to keep?`,children:[t.jsx("p",{children:"Your agents and your notes name them. Keep them as people and every agent knows who they are; nothing is added until you say so."}),t.jsx(Ye,{flush:!0,children:t.jsx(at,{children:p.map(x=>{var y;return t.jsx(Xe,{lead:t.jsx(qN,{name:String(((y=x.payload.matcher)==null?void 0:y.person)??"?"),small:!0}),title:String(x.payload.action??""),sub:t.jsx("span",{className:"person-from",children:x.why}),side:t.jsxs("span",{className:"person-side",children:[t.jsx(A,{variant:"ghost",size:"sm",disabled:d!==null,onClick:()=>void m(`discard:${x.id}`,()=>R.discardProposal(x.id,"Not a person")),children:"Not a person"}),t.jsx(A,{size:"sm",disabled:d!==null,onClick:()=>void m(`keep:${x.id}`,()=>R.keepProposal(x.id)),children:"Keep"})]})},x.id)})})}),p.length>1?t.jsx(te,{align:"end",children:t.jsxs(A,{variant:"accent",size:"sm",disabled:d!==null,onClick:()=>void m("keep-all",()=>R.keepAllProposals(p.map(x=>x.id))),children:["Keep all (",p.length,")"]})}):null]}):null,t.jsxs(ue,{title:"People",aside:"every agent knows who they are",panel:!0,flush:!0,actions:t.jsx(A,{variant:"accent",size:"sm",onClick:()=>r("new"),children:"Add a person"}),children:[e.data?g.length===0?t.jsx(ve,{children:"Nobody yet. Tell any agent “Marion is my wife, her birthday is 14 March”, or add someone here. Agents ask before they add anyone you did not tell them about."}):t.jsx(at,{children:g.map(x=>{const y=FG(x);return t.jsx(Xe,{label:`${x.name}: edit`,onClick:()=>r(x),lead:t.jsx(qN,{name:x.name}),title:x.name,sub:v(x),side:t.jsxs("span",{className:"person-side",children:[y?t.jsx(Ee,{tone:x.next&&x.next.inDays<=7?"accent":void 0,children:y}):null,x.reminders?t.jsx("span",{className:"person-bell",title:"Reminders on","aria-label":"Reminders on",children:t.jsx(le,{name:"bell",size:14})}):null]})},x.id)})}):t.jsx(ve,{children:e.error??"Loading…"}),t.jsx("p",{className:"person-note",children:"Agents read each person in one line: name, who they are to you, how to address them, their dates. Notes are read only when an agent looks the person up."})]}),s?t.jsx(zG,{person:s==="new"?null:s,onClose:()=>r(null),onSaved:()=>{r(null),e.reload()},onForget:x=>{r(null),i(x)}}):null,a?t.jsx(Ge,{title:`Forget ${a.name}?`,onClose:()=>i(null),foot:t.jsxs(te,{children:[t.jsx(et,{}),t.jsx(A,{variant:"ghost",onClick:()=>i(null),children:"Cancel"}),t.jsx(A,{variant:"danger",disabled:d!==null,onClick:()=>{const x=a;m(`forget:${x.id}`,()=>R.forgetPerson(x.id)).then(y=>{i(null),y&&o({id:Date.now(),person:x})})},children:"Forget"})]}),children:t.jsxs("p",{children:["Every agent stops knowing who ",a.name," is",a.reminders!==null?", and the reminders for their dates are removed":"",". Notes that mention them stay in Notes."]})}):null,l?t.jsx(eu,{title:`Forgot ${l.person.name}.`,duration:OG,onUndo:()=>{const x=l.person;m(`restore:${x.id}`,()=>R.restorePerson(x.id))},onGone:()=>o(null)},l.id):null]})}function zG({person:e,onClose:n,onSaved:s,onForget:r}){const[a,i]=h.useState((e==null?void 0:e.name)??""),[l,o]=h.useState((e==null?void 0:e.relationship)??""),[c,u]=h.useState((e==null?void 0:e.addressAs)??""),[d,f]=h.useState(qh(e==null?void 0:e.birthday)),[m,p]=h.useState(qh(e==null?void 0:e.anniversary)),[g,v]=h.useState((e==null?void 0:e.notes)??""),[b,j]=h.useState((e==null?void 0:e.reminders)===!0),[x,y]=h.useState(!1),[w,k]=h.useState(null),N=Yh(d),S=Yh(m),C=N==="incomplete"||S==="incomplete",E=N!==null&&N!=="incomplete"||S!==null&&S!=="incomplete",T=async()=>{if(!C){y(!0),k(null);try{const I=F=>F.trim()===""?null:F.trim();await R.savePerson({...e?{id:e.id}:{},name:a.trim(),relationship:I(l),addressAs:I(c),birthday:N,anniversary:S,notes:I(g),reminders:E&&b}),s()}catch(I){k(I instanceof xe?I.message:String(I))}finally{y(!1)}}};return t.jsx(Ge,{title:e?e.name:"Add a person",onClose:n,foot:t.jsxs(te,{children:[e?t.jsx(A,{variant:"danger-ghost",disabled:x,onClick:()=>r(e),children:"Forget…"}):null,t.jsx(et,{}),t.jsx(A,{variant:"ghost",onClick:n,children:"Cancel"}),t.jsx(A,{variant:"accent",disabled:x||a.trim()===""||C,onClick:()=>void T(),children:x?"Saving…":"Save"})]}),children:t.jsxs(ie,{gap:"lg",children:[t.jsxs(Ns,{children:[t.jsx(re,{label:"Name",children:t.jsx("input",{value:a,maxLength:80,placeholder:"Marion",autoFocus:!e,onChange:I=>i(I.target.value)})}),t.jsx(re,{label:"Who they are to you",children:t.jsx("input",{value:l,maxLength:60,placeholder:"wife, brother, accountant…",onChange:I=>o(I.target.value)})})]}),t.jsx(re,{label:"How to address them",hint:"What agents call them when they write to you about them, or to them for you.",children:t.jsx("input",{value:c,maxLength:80,placeholder:a.trim()||"Mum, Dr Lee…",onChange:I=>u(I.target.value)})}),t.jsx(yv,{label:"Birthday",hint:"The year is optional.",value:d,onChange:f}),t.jsx(yv,{label:"Anniversary",hint:"A wedding, the day you met: the year is optional.",value:m,onChange:p}),t.jsx(re,{label:"Notes",hint:"Gift ideas, allergies, what they are into. Read when an agent looks them up.",children:t.jsx("textarea",{rows:3,maxLength:1e3,value:g,onChange:I=>v(I.target.value)})}),t.jsxs("div",{className:"person-remind","data-off":E?void 0:"true",children:[t.jsxs("div",{className:"person-remind-text",children:[t.jsx("div",{className:"person-remind-title",children:"Remind me of their dates"}),t.jsx("div",{className:"ui-field-hint",children:E?"A week before and on the day, from the front desk, with an offer to find something.":"Add a birthday or an anniversary first."})]}),t.jsx(R$,{checked:E&&b,disabled:!E,onChange:j,label:"Remind me of their dates"})]}),w?t.jsx(G,{tone:"critical",children:w}):null]})})}const UG=["fact","observation","todo"];function JR({embedded:e,agents:n,timezone:s,agentId:r,initialTab:a="people"}){const{data:i,error:l,reload:o}=me(()=>R.memory(r),[r],3e4),[c,u]=h.useState(null),[d,f]=h.useState(null),[m,p]=h.useState(null),[g,v]=h.useState(a),b=S=>{var C;return S==="shared"?"Everyone":((C=n.find(E=>E.id===S))==null?void 0:C.name)??S},j=async S=>{p(null);try{await S,o()}catch(C){p(C instanceof xe?C.message:String(C))}},x={nameOf:b,timezone:s,onChangePreference:S=>u({key:S.key,scope:S.scope}),onForgetPreference:S=>void j(R.forgetPreference({key:S.key,scope:S.scope})),onEditNote:S=>f(S),onForgetNote:S=>void j(R.forgetNote(S.id))},y=r?b(r):"",w=r&&i?{preferences:i.preferences.filter(S=>S.scope===r),notes:i.notes.filter(S=>S.scope===r)}:null,k=r&&i?{preferences:i.preferences.filter(S=>S.scope==="shared"),notes:i.notes.filter(S=>S.scope==="shared")}:null,N=t.jsx(A,{variant:"accent",size:"sm",onClick:()=>u({key:"",scope:r??"shared"}),children:"Add a preference"});return t.jsxs(Zn,{embedded:e,title:"Memory",lede:"What your agents have kept about you. Correct anything here; they see the change on their next turn.",children:[t.jsx(ne,{message:l??m}),w&&k?t.jsxs(ie,{gap:"lg",children:[t.jsx(ue,{title:"Preferences",aside:`what you told ${y} alone`,actions:N,panel:!0,flush:!0,children:t.jsx(Up,{preferences:w.preferences,empty:`Nothing stated to ${y} alone yet.`,...x})}),t.jsx(ue,{title:"Notes",aside:`what ${y} wrote down for itself`,panel:!0,flush:!0,children:t.jsx(Bp,{notes:w.notes,empty:`${y} has kept no private notes yet.`,...x})}),t.jsx(Ot,{summary:`Shared with every agent, which ${y} also reads · ${k.preferences.length} preferences, ${k.notes.length} notes`,children:t.jsxs(ie,{gap:"lg",children:[t.jsx(ue,{title:"Shared preferences",panel:!0,flush:!0,children:t.jsx(Up,{preferences:k.preferences,empty:"No shared preferences.",...x})}),t.jsx(ue,{title:"Shared notes",panel:!0,flush:!0,children:t.jsx(Bp,{notes:k.notes,empty:"No shared notes.",...x})})]})})]}):t.jsxs(ie,{gap:"lg",children:[t.jsx(yo,{label:"Memory",children:[["people","People"],["preferences","Preferences",i==null?void 0:i.preferences.length],["notes","Notes",i==null?void 0:i.notes.length]].map(([S,C,E])=>t.jsx(Li,{href:`${Le("memory")}?tab=${S}`,active:g===S,...E?{count:E}:{},onClick:T=>{T.preventDefault(),v(S)},children:C},S))}),g==="people"?t.jsx(_G,{}):null,g==="preferences"?t.jsx(ue,{title:"Preferences",aside:"what you said you want, one current value each",actions:N,panel:!0,flush:!0,children:i?t.jsx(Up,{preferences:i.preferences,empty:'Nothing stated yet. Tell any agent "from now on…" or add one here.',...x}):t.jsx(ve,{children:"Loading…"})}):null,g==="notes"?t.jsx(ue,{title:"Notes",aside:"what an agent wrote down, with who wrote it",panel:!0,flush:!0,children:i?t.jsx(Bp,{notes:i.notes,empty:"No notes yet. An agent writes one when you state something durable about your life.",...x}):t.jsx(ve,{children:"Loading…"})}):null]}),c?t.jsx(BG,{agents:n,existing:(i==null?void 0:i.preferences)??[],initial:c,onClose:()=>u(null),onSave:async S=>{await j((async()=>{await R.setPreference(S),c.key===S.key&&c.scope!==S.scope&&await R.forgetPreference({key:c.key,scope:c.scope})})()),u(null)}}):null,d?t.jsx(WG,{note:d,agents:n,onClose:()=>f(null),onSave:S=>j(R.updateNote(d.id,S)).then(()=>f(null))}):null]})}function Up({preferences:e,empty:n,nameOf:s,onChangePreference:r,onForgetPreference:a}){return e.length===0?t.jsx(ve,{children:n}):t.jsxs(Kr,{children:[t.jsx("thead",{children:t.jsxs("tr",{children:[t.jsx("th",{children:"Preference"}),t.jsx("th",{children:"Value"}),t.jsx("th",{children:"Who sees it"}),t.jsx("th",{className:"num",children:"Since"}),t.jsx("th",{})]})}),t.jsx("tbody",{children:e.map(i=>t.jsxs("tr",{children:[t.jsx("td",{className:"mono",children:i.key}),t.jsx("td",{children:i.value}),t.jsx("td",{children:t.jsx(QR,{scope:i.scope,name:s(i.scope)})}),t.jsxs("td",{className:"num muted",title:i.updatedAt??"",children:[i.updatedAt?Ve(i.updatedAt,Date.now()):"",i.revision>1?` · rev ${i.revision}`:""]}),t.jsx("td",{className:"num",children:t.jsxs(te,{align:"end",children:[t.jsx(A,{size:"sm",onClick:()=>r(i),title:"Store a new value for this key",children:"Change"}),t.jsx(A,{size:"sm",variant:"ghost",onClick:()=>a(i),children:"Forget"})]})})]},`${i.scope}:${i.key}`))})]})}function Bp({notes:e,empty:n,nameOf:s,timezone:r,onEditNote:a,onForgetNote:i}){return e.length===0?t.jsx(ve,{children:n}):t.jsxs(Kr,{children:[t.jsx("thead",{children:t.jsxs("tr",{children:[t.jsx("th",{children:"Note"}),t.jsx("th",{children:"Kind"}),t.jsx("th",{children:"Who sees it"}),t.jsx("th",{children:"Written by"}),t.jsx("th",{className:"num",children:"When"}),t.jsx("th",{})]})}),t.jsx("tbody",{children:e.map(l=>t.jsxs("tr",{children:[t.jsx("td",{className:"memory-note",children:l.content}),t.jsx("td",{children:t.jsx(Ee,{tone:l.kind==="todo"?"warning":l.kind==="fact"?"good":void 0,children:l.kind})}),t.jsx("td",{children:t.jsx(QR,{scope:l.scope,name:s(l.scope)})}),t.jsx("td",{className:"muted",children:l.createdByAgent?s(l.createdByAgent):""}),t.jsxs("td",{className:"num muted",title:l.createdAt??"",children:[l.createdAt?Ve(l.createdAt,Date.now()):"",l.expiresAt?t.jsxs("span",{className:"memory-expires",children:[" · until ",Wr(new Date(l.expiresAt),r,{year:!0,compact:!0})]}):null]}),t.jsx("td",{className:"num",children:t.jsxs(te,{align:"end",children:[t.jsx(A,{size:"sm",onClick:()=>a(l),children:"Edit"}),t.jsx(A,{size:"sm",variant:"ghost",onClick:()=>i(l),children:"Forget"})]})})]},l.id))})]})}function QR({scope:e,name:n}){return t.jsx(Ee,{tone:e==="shared"?"accent":void 0,title:e==="shared"?"Every agent reads this":`Only ${n} reads this`,children:n})}function XR({value:e,agents:n,onChange:s}){return t.jsxs("select",{value:e,onChange:r=>s(r.target.value),children:[t.jsx("option",{value:"shared",children:"Everyone"}),n.map(r=>t.jsxs("option",{value:r.id,children:["Only ",r.name]},r.id))]})}function BG({agents:e,existing:n,initial:s,onClose:r,onSave:a}){const i=n.find(x=>x.key===s.key&&x.scope===s.scope),[l,o]=h.useState(s.key),[c,u]=h.useState((i==null?void 0:i.value)??""),[d,f]=h.useState(s.scope),[m,p]=h.useState(!1),g=l.trim().toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,""),v=n.find(x=>x.key===g&&x.scope===d),b=!i||g!==i.key||c.trim()!==i.value||d!==i.scope,j=g!==""&&c.trim()!==""&&b;return t.jsx(Ge,{title:"A preference",onClose:r,children:t.jsxs(ie,{children:[t.jsx(G,{children:'A preference is a standing choice, in your words: "paid biweekly on Thursdays", "answers short, numbers first". Storing the same key again records a correction and keeps the old value in the history.'}),t.jsx(re,{label:"Key",hint:g&&g!==l?`Stored as ${g}`:"Short and stable, like reporting_currency or tone.",children:t.jsx("input",{value:l,autoFocus:s.key==="",onChange:x=>o(x.target.value),placeholder:"reporting_currency"})}),t.jsx(re,{label:"Value",children:t.jsx("textarea",{rows:3,value:c,maxLength:2e3,autoFocus:s.key!=="",onChange:x=>u(x.target.value),placeholder:"EUR"})}),t.jsx(re,{label:"Who should know",hint:"Shared reaches every agent. Private stays with one.",children:t.jsx(XR,{value:d,agents:e,onChange:f})}),v&&v!==i?t.jsxs(G,{tone:"warning",children:['This replaces the value already stored for this key here, "',v.value,'" (revision ',v.revision,")."]}):null,i&&d!==i.scope?t.jsxs(G,{children:["It moves: the copy for ",i.scope==="shared"?"everyone":"that agent"," is retired and this one takes over."]}):null,t.jsxs(te,{align:"end",children:[t.jsx(A,{onClick:r,children:"Cancel"}),t.jsx(A,{variant:"accent",disabled:!j||m,onClick:()=>{p(!0),a({key:g,value:c.trim(),scope:d}).finally(()=>p(!1))},children:i?"Save change":"Save"})]})]})})}function WG({note:e,agents:n,onClose:s,onSave:r}){var p;const[a,i]=h.useState(e.content),[l,o]=h.useState(e.scope),[c,u]=h.useState(e.kind),[d,f]=h.useState(!1),m=a.trim()!==e.content||l!==e.scope||c!==e.kind;return t.jsx(Ge,{title:"A note",onClose:s,children:t.jsxs(ie,{children:[t.jsx(re,{label:"What it says",hint:"One sentence that makes sense months from now, on its own.",children:t.jsx("textarea",{rows:4,value:a,maxLength:2e3,autoFocus:!0,onChange:g=>i(g.target.value)})}),t.jsxs(Ns,{children:[t.jsx(re,{label:"Kind",children:t.jsx("select",{value:c,onChange:g=>u(g.target.value),children:UG.map(g=>t.jsx("option",{value:g,children:g},g))})}),t.jsx(re,{label:"Who sees it",children:t.jsx(XR,{value:l,agents:n,onChange:o})})]}),e.createdByAgent?t.jsxs("p",{className:"muted",children:["Written by ",((p=n.find(g=>g.id===e.createdByAgent))==null?void 0:p.name)??e.createdByAgent,e.createdAt?`, ${Ve(e.createdAt,Date.now())}`:"",". Editing keeps that record."]}):null,t.jsxs(te,{align:"end",children:[t.jsx(A,{onClick:s,children:"Cancel"}),t.jsx(A,{variant:"accent",disabled:!m||a.trim()===""||d,onClick:()=>{f(!0);const g={};a.trim()!==e.content&&(g.content=a.trim()),l!==e.scope&&(g.scope=l),c!==e.kind&&(g.kind=c),r(g).finally(()=>f(!1))},children:"Save"})]})]})})}const Jh="host.exec",HG={bundle:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M3.4 6.4 10 3.2l6.6 3.2v7.2L10 16.8l-6.6-3.2Z"}),t.jsx("path",{d:"M3.4 6.4 10 9.6l6.6-3.2M10 9.6v7.2"})]})],folder:[16,1.5,t.jsx("path",{d:"M2.2 4.4a1 1 0 0 1 1-1h3l1.4 1.6h5.2a1 1 0 0 1 1 1v6.6a1 1 0 0 1-1 1H3.2a1 1 0 0 1-1-1Z"})],doc:[16,1.5,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M4.4 1.9h4.8l3 3v8.2a1 1 0 0 1-1 1H4.4a1 1 0 0 1-1-1V2.9a1 1 0 0 1 1-1Z"}),t.jsx("path",{d:"M9 2v3h3"})]})],script:[16,1.5,t.jsxs(t.Fragment,{children:[t.jsx("rect",{x:"1.9",y:"2.6",width:"12.2",height:"10.8",rx:"1.4"}),t.jsx("path",{d:"m4.6 6.4 2 1.6-2 1.6M8.4 10h3"})]})],font:[16,1.5,t.jsx("path",{d:"M3.4 13 8 3l4.6 10M5 9.6h6"})],image:[16,1.5,t.jsxs(t.Fragment,{children:[t.jsx("rect",{x:"2",y:"2.6",width:"12",height:"10.8",rx:"1.4"}),t.jsx("circle",{cx:"5.8",cy:"6.2",r:"1.2"}),t.jsx("path",{d:"m2.4 12 3.8-3.6 2.6 2.4 2-1.8 3 2.6"})]})],upload:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M10 13.2V3.6M6.2 7.2 10 3.4l3.8 3.8"}),t.jsx("path",{d:"M3.6 12.6v2.6a1.4 1.4 0 0 0 1.4 1.4h10a1.4 1.4 0 0 0 1.4-1.4v-2.6"})]})],shield:[16,1.5,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M8 1.8 13 3.6v4c0 3-2.1 5.4-5 6.6-2.9-1.2-5-3.6-5-6.6v-4Z"}),t.jsx("path",{d:"m5.8 8 1.6 1.6 2.8-3"})]})]};function Ba({name:e,size:n}){const[s,r,a]=HG[e];return t.jsx("svg",{width:n??s,height:n??s,viewBox:`0 0 ${s} ${s}`,"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeWidth:r,strokeLinecap:"round",strokeLinejoin:"round",children:a})}function ww({size:e}){return t.jsx("span",{className:"ui-app-icon","data-size":e,"aria-hidden":"true",children:t.jsx(Ba,{name:"bundle",size:e?22:18})})}const KG={skill:"doc",script:"script",font:"font",image:"image",data:"doc",template:"doc",other:"doc"},VG={skill:"The skill",script:"Script",font:"Font",image:"Picture",data:"Data",template:"Template",other:"File"};function GG(e){const n=[],s=new Set,r=[...e].sort((a,i)=>a.path==="SKILL.md"?-1:i.path==="SKILL.md"?1:a.path.localeCompare(i.path));for(const a of r){const i=a.path.split("/");i.slice(0,-1).forEach((l,o)=>{const c=i.slice(0,o+1).join("/");s.has(c)||(s.add(c),n.push({dir:c,name:`${i[o]}/`,depth:o}))}),n.push({file:a,name:i[i.length-1],depth:i.length-1})}return n}function ZR({files:e,selected:n,onSelect:s}){return t.jsx("ul",{className:"skb-tree",role:s?"listbox":void 0,"aria-label":"Files in the bundle",children:GG(e).map(r=>"dir"in r?t.jsxs("li",{className:"skb-node","data-dir":"true","data-depth":Math.min(r.depth,6),children:[t.jsx(Ba,{name:"folder",size:14}),t.jsx("span",{className:"skb-name",children:r.name})]},`d:${r.dir}`):t.jsxs("li",{className:"skb-node","data-depth":Math.min(r.depth,6),"data-kind":r.file.kind,"data-selected":n===r.file.path?"true":void 0,role:s?"option":void 0,"aria-selected":s?n===r.file.path:void 0,tabIndex:s?0:void 0,onClick:s?()=>s(r.file.path):void 0,onKeyDown:s?a=>{(a.key==="Enter"||a.key===" ")&&(a.preventDefault(),s(r.file.path))}:void 0,children:[t.jsx(Ba,{name:KG[r.file.kind],size:14}),t.jsx("span",{className:"skb-name",title:r.file.path,children:r.name}),r.file.kind==="script"?t.jsx("span",{className:"skb-flag",children:r.file.setup?"setup":"script"}):null,t.jsx("span",{className:"skb-size",children:Rr(r.file.size)})]},r.file.path))})}function qG(e,n){const s=e.setup?"A setup script. It didn’t run when you uploaded the bundle and never runs on its own. ":"";return n.untrusted?`${s}It can’t run until you mark the bundle as yours. Then it runs only when an agent you allow runs it with ${Jh}, and asks you first.`:n.run.length?`${s}It runs only when ${Qa(n.run)} ${n.run.length>1?"run":"runs"} it with ${Jh}, and asks you first. It can read this bundle’s files, not change them.`:n.held?`${s}Nobody holding this skill can run scripts, so it never runs.`:`${s}It runs only when an agent you allow runs it, and asks you first. It can read the bundle’s files, not change them.`}function eI({file:e,skillView:n,read:s,imageUrl:r,reach:a}){const[i,l]=h.useState(null);if(h.useEffect(()=>{if(e.kind==="skill")return;let c=!0;return l({path:e.path}),s(e.path).then(u=>{c&&l({path:e.path,file:u.file})},u=>{c&&l({path:e.path,error:u instanceof xe?u.message:String(u)})}),()=>{c=!1}},[e.path,e.kind]),e.kind==="skill")return t.jsx("div",{className:"skb-view",children:n});const o=(i==null?void 0:i.path)===e.path?i.file:void 0;return t.jsxs("div",{className:"skb-view",children:[t.jsxs("div",{className:"skills-text-bar",children:[t.jsxs("span",{className:"skb-view-kind",children:[VG[e.kind]," · ",Rr(e.size)]}),t.jsx("span",{className:"skills-file mono",children:e.path})]}),e.kind==="script"?t.jsxs("p",{className:"skb-script-note",children:[t.jsx(Ba,{name:"shield",size:14}),t.jsx("span",{children:qG(e,a)})]}):null,i!=null&&i.error?t.jsx(ne,{message:i.error}):e.kind==="font"?t.jsxs("div",{className:"skb-blank",children:[t.jsx(Ba,{name:"font",size:20}),t.jsx("span",{children:"A font. The skill’s scripts or documents set text with it; there’s nothing to read here."})]}):e.kind==="image"&&(o!=null&&o.image)?t.jsx("div",{className:"skb-picture",children:t.jsx("img",{src:r(e.path),alt:e.path})}):o?o.binary||o.text===void 0?t.jsxs("div",{className:"skb-blank",children:[t.jsx(Ba,{name:"doc",size:20}),t.jsxs("span",{children:["Not text, so there’s nothing to read here. ",Rr(e.size),"."]})]}):t.jsx(Dt,{label:e.path,children:o.text}):t.jsx("p",{className:"skills-note",children:"Reading the file…"})]})}function tI({children:e}){return t.jsx("div",{className:"skb-files",children:e})}function nI({children:e}){return t.jsxs("p",{className:"skb-promise",children:[t.jsx(Ba,{name:"shield",size:16}),t.jsx("span",{children:e})]})}const YG="Up to 20 MB and 500 files. Nothing in it runs when you upload it.";function JG({initialRefusal:e,onClose:n,onMd:s,onStaged:r}){var v;const[a,i]=h.useState(!1),[l,o]=h.useState(e??null),[c,u]=h.useState(null),[d,f]=h.useState(null),m=h.useRef(null),p=b=>{if(!(!b||c)){if(f(null),/\.md$/i.test(b.name)){s(b);return}if(!/\.zip$/i.test(b.name)){o({kind:"notzip",filename:b.name});return}if(b.size>p8){o({kind:"big",filename:b.name,size:b.size});return}u(b.name),Gt.uploadBundle(b).then(j=>r(j),j=>{u(null),j instanceof dT?o(j.refusal):f(j instanceof xe?j.message:String(j))})}},g=l?N8(l):null;return t.jsxs(Ge,{title:"Upload a skill",onClose:n,children:[t.jsx("input",{ref:m,type:"file",accept:".zip,.md,application/zip,text/markdown",hidden:!0,"data-testid":"skill-drop-file",onChange:b=>{var j;p((j=b.target.files)==null?void 0:j[0]),b.target.value=""}}),t.jsxs("div",{className:"skills-sheet skb-drop-sheet",children:[g?t.jsx(G,{tone:"critical",title:g.title,role:"alert",children:t.jsxs("div",{className:"skb-refusal",children:[g.body,(v=g.items)!=null&&v.length?t.jsx("ul",{className:"skb-refused",children:g.items.map(b=>t.jsxs("li",{children:[t.jsx("span",{className:"mono",children:b.path})," ",b.rest]},b.path))}):null]})}):null,t.jsx(ne,{message:d}),t.jsxs("div",{className:"skb-drop","data-over":a?"true":void 0,"data-testid":"skill-drop",onDragOver:b=>{b.preventDefault(),i(!0)},onDragLeave:()=>i(!1),onDrop:b=>{var j;b.preventDefault(),i(!1),p((j=b.dataTransfer.files)==null?void 0:j[0])},children:[t.jsx("span",{className:"skb-drop-glyph",children:t.jsx(Ba,{name:"upload",size:24})}),t.jsx("span",{className:"skb-drop-title",children:c?`Reading “${c}”…`:a?"Drop to read it":g?"Drop another file here":"Drop a .zip or a .md here"}),t.jsx(A,{variant:g?void 0:"accent",disabled:c!==null,onClick:()=>{var b;return(b=m.current)==null?void 0:b.click()},children:g?"Choose another file":"Choose a file"}),t.jsx("span",{className:"skb-drop-limits",children:YG})]}),t.jsxs("section",{className:"skills-sec skb-shape","aria-label":"What a bundle looks like",children:[t.jsx("h3",{className:"skills-sec-title",children:"What a bundle looks like"}),t.jsxs("dl",{className:"skb-shape-tree",children:[t.jsx("dt",{className:"mono",children:"cover-art-kit/"}),t.jsx("dd",{}),t.jsx("dt",{className:"mono","data-in":"true",children:"SKILL.md"}),t.jsx("dd",{children:"the skill: a name, when it’s used, the steps"}),t.jsx("dt",{className:"mono","data-in":"true",children:"scripts/"}),t.jsx("dd",{children:"run only by an agent you allow, asking first"}),t.jsx("dt",{className:"mono","data-in":"true",children:"assets/"}),t.jsx("dd",{children:"fonts, templates, pictures it reads"})]})]})]})]})}function QG({checked:e,onChange:n,lead:s,title:r,sub:a}){return t.jsxs("label",{className:"skills-pick-row",children:[t.jsx("input",{type:"checkbox",checked:e,onChange:i=>n(i.target.checked)}),s,t.jsxs("span",{className:"skills-pick-text",children:[t.jsx("span",{className:"skills-pick-title",children:r}),a?t.jsx("span",{className:"skills-pick-sub",children:a}):null]})]})}function XG({staged:e,agents:n,faces:s,onClose:r,onBack:a,onAdded:i}){var N,S;const l=e.files.filter(C=>C.kind==="script"),[o,c]=h.useState(((N=l.find(C=>C.setup))==null?void 0:N.path)??((S=l[0])==null?void 0:S.path)??"SKILL.md"),[u,d]=h.useState([]),[f,m]=h.useState(!1),[p,g]=h.useState(!1),[v,b]=h.useState(null),j=n.filter(C=>C.canRunScripts).map(C=>C.name),x=e.files.find(C=>C.path===o)??e.files[0],y=C=>{Gt.discardBundle(e.id).catch(()=>{}),C()},w=async()=>{g(!0),b(null);try{const{skill:C}=await Gt.acceptBundle(e.id,{agents:u,mine:f});i(C)}catch(C){b(C instanceof xe?C.message:String(C)),g(!1)}},k=l.some(C=>C.setup);return t.jsxs(Ge,{size:"wide",title:t.jsxs("span",{className:"skills-sheet-title",children:[t.jsx(ww,{size:"lg"}),t.jsxs("span",{className:"skills-sheet-name",children:[t.jsx("span",{children:e.filename}),t.jsxs("span",{className:"skills-sheet-by",children:[e.files.length," files · ",Rr(e.size)," unpacked · read, not saved yet"]})]})]}),onClose:()=>y(r),foot:t.jsxs(te,{children:[t.jsx(A,{variant:"ghost",onClick:()=>y(a),children:"Choose another file"}),t.jsx(et,{}),t.jsx(A,{variant:"ghost",onClick:()=>y(r),children:"Cancel"}),t.jsx(A,{variant:"accent",disabled:p,onClick:()=>void w(),children:"Add the skill"})]}),children:[l.length?t.jsxs(G,{title:`${l.length} script${l.length>1?"s":""} inside. None of them ran.`,children:["They run later only when an agent you allow runs them, after you mark the bundle as yours, and each run asks you first",k?" — setup scripts too.":"."]}):null,t.jsx(ne,{message:v}),t.jsxs("div",{className:"skills-sheet",children:[t.jsxs("section",{className:"skills-sec","aria-label":"From its SKILL.md",children:[t.jsx("header",{className:"skills-sec-head",children:t.jsx("h3",{className:"skills-sec-title",children:"From its SKILL.md"})}),t.jsx(qt,{items:[{label:"Name",value:e.skill.title},{label:"When it’s used",value:e.skill.description},{label:"First lines",value:t.jsxs("span",{className:"skb-first",children:[e.skill.firstLines,e.skill.firstLines.length>=160?"…":""]})}]})]}),t.jsxs("section",{className:"skills-sec","aria-label":"What’s inside",children:[t.jsxs("header",{className:"skills-sec-head",children:[t.jsx("h3",{className:"skills-sec-title",children:"What’s inside"}),t.jsxs("span",{className:"skills-sec-aside skills-note",children:[Rr(e.size)," unpacked · ",Rr(e.packed)," as a .zip"]})]}),t.jsxs(tI,{children:[t.jsx(ZR,{files:e.files,selected:x.path,onSelect:c}),t.jsx(eI,{file:x,read:C=>Gt.stagedFile(e.id,C),imageUrl:C=>Gt.stagedImageUrl(e.id,C),reach:{run:[],held:!1,untrusted:!1},skillView:t.jsx(ZG,{staged:e})})]}),t.jsx("p",{className:"skills-note",children:"Checked: every file stays inside the bundle, no links, nothing over the limits. Pick a file to read it before you add it."})]}),t.jsxs("section",{className:"skills-sec","aria-label":"Who uses it",children:[t.jsx("header",{className:"skills-sec-head",children:t.jsx("h3",{className:"skills-sec-title",children:"Who uses it"})}),t.jsx("div",{className:"skills-who",children:n.filter(C=>C.writable).map(C=>t.jsx(QG,{checked:u.includes(C.id),onChange:E=>d(E?[...u,C.id]:u.filter(T=>T!==C.id)),lead:t.jsx(Nn,{id:C.id,name:C.name,size:"sm",face:s.find(E=>E.id===C.id)}),title:C.name,sub:C.canRunScripts&&l.length?"can run scripts":void 0},C.id))}),t.jsx("p",{className:"skills-note",children:l.length?j.length?`Only ${Qa(j)} ${j.length>1?"have":"has"} a tool that runs scripts; the others read the text. You can change this later.`:"No agent has a tool that runs scripts, so they all read the text only. You can change this later.":"You can change this later. With nobody ticked it’s kept and does nothing."})]}),t.jsx("section",{className:"skills-sec",children:t.jsxs("label",{className:"plugins-check",children:[t.jsx("input",{type:"checkbox",checked:f,onChange:C=>m(C.target.checked)}),t.jsxs("span",{children:[t.jsx("span",{className:"plugins-check-title",children:"Mark as mine"}),t.jsx("span",{className:"plugins-check-hint",children:l.length?"I wrote it, or I’ve read it and its scripts and trust them. Otherwise agents read its text as outside text and its scripts can’t run.":"I wrote it, or I’ve read it and trust it. Otherwise agents read its text as outside text."})]})]})})]})]})}function ZG({staged:e}){const[n,s]=h.useState(null);return h.useEffect(()=>{let r=!0;return Gt.stagedFile(e.id,"SKILL.md").then(a=>{r&&s(a.file.text??"")},()=>{r&&s("")}),()=>{r=!1}},[e.id]),t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"skills-text-bar",children:[t.jsx("span",{className:"skb-view-kind",children:"The skill"}),t.jsx("span",{className:"skills-file mono",children:"SKILL.md"})]}),n===null?t.jsx("p",{className:"skills-note",children:"Reading the file…"}):t.jsx(Dt,{label:"SKILL.md",children:n})]})}const eq=5e4,Fi=e=>e instanceof xe?e.message:String(e),tq=e=>n=>{n.stopPropagation(),e==null||e()};function nq({faces:e,navigate:n,command:s,openSkill:r,openFile:a}){const i=me(()=>Gt.list(),[]),[l,o]=h.useState(r?{id:r,...a?{file:a}:{}}:null),[c,u]=h.useState(null),[d,f]=h.useState(null),[m,p]=h.useState(null),[g,v]=h.useState(null),b=h.useRef(null);h.useEffect(()=>{r&&o({id:r,...a?{file:a}:{}})},[r,a]),h.useEffect(()=>{s&&u(s.kind==="write"?{kind:"write"}:{kind:"drop"})},[s]);const j=k=>{var S;const N=(S=k.target.files)==null?void 0:S[0];k.target.value="",N&&x(N)},x=k=>{if(!/\.md$/i.test(k.name)){f(`“${k.name}” isn’t a .md file. A skill is one Markdown file.`);return}if(k.size>eq){f(`“${k.name}” is over 50 KB. A skill is a short text.`);return}const N=new FileReader;N.onload=()=>{f(null),u({kind:"upload",file:{name:k.name,size:k.size,...E8(k.name,String(N.result))}})},N.readAsText(k)},y=k=>{p(null),k!==void 0&&v(k),i.reload()};return t.jsxs(t.Fragment,{children:[t.jsx("input",{ref:b,type:"file",accept:".md,text/markdown",hidden:!0,"data-testid":"skill-file",onChange:j}),d?t.jsx(G,{tone:"warning",action:t.jsx(A,{size:"sm",onClick:()=>{f(null),u({kind:"drop"})},children:"Pick another file"}),children:d}):null,t.jsx(ne,{message:m}),g?t.jsx(G,{tone:"good",role:"status",children:g}):null,t.jsx(sq,{view:i,onOpen:k=>o({id:k.id}),onAct:(k,N)=>w(k,N)}),t.jsx(sI,{view:i.data,faces:e,open:l,setOpen:o,dialog:c,setDialog:u,navigate:n,onChanged:y,onFailed:p}),(c==null?void 0:c.kind)==="write"&&i.data?t.jsx(JN,{agents:i.data.agents,faces:e,onClose:()=>u(null),onSaved:k=>{u(null),y(`Saved “${k.title}”.`)}}):null,(c==null?void 0:c.kind)==="drop"?t.jsx(JG,{onClose:()=>u(null),onMd:k=>{u(null),x(k)},onStaged:k=>u({kind:"zip",staged:k})}):null,(c==null?void 0:c.kind)==="zip"&&i.data?t.jsx(XG,{staged:c.staged,agents:i.data.agents,faces:e,onClose:()=>u(null),onBack:()=>u({kind:"drop"}),onAdded:k=>{u(null),y(`Added “${k.title}”.`),o({id:k.id})}}):null,(c==null?void 0:c.kind)==="upload"&&i.data?t.jsx(JN,{agents:i.data.agents,faces:e,upload:c.file,onClose:()=>u(null),onSaved:k=>{u(null),y(`Saved “${k.title}”.`)}}):null]});function w(k,N){v(null),N==="trust"?Gt.trust(k.id).then(()=>y(),S=>p(Fi(S))):N==="download"?fT(k.id):N==="plugin"?n(Le("plugins")):N==="edit"?(u(null),o({id:k.id,edit:!0})):u({kind:N,id:k.id})}}function sq({view:e,onOpen:n,onAct:s}){if(!e.data&&e.error)return t.jsx(ve,{warm:!0,title:"Couldn’t load your skills",action:t.jsx(A,{variant:"accent",size:"sm",onClick:e.reload,children:"Try again"}),children:"buddi didn’t answer. Your skill files are untouched."});if(!e.data)return t.jsx(aq,{});const{skills:r,agents:a}=e.data;return r.length===0?t.jsx(ve,{warm:!0,title:"No skills yet",children:"A skill teaches an agent one kind of task, in plain words. Write one here, or upload a .md file you already have."}):t.jsx(Ye,{flush:!0,children:Gy.map(i=>{const l=r.filter(o=>o.group===i.id);return l.length?t.jsxs("section",{className:"skills-group","aria-label":i.title,children:[t.jsxs("header",{className:"skills-group-head",children:[t.jsx("h3",{className:"skills-group-title",children:i.title}),t.jsx("span",{className:"skills-group-aside",children:i.aside})]}),t.jsx(at,{children:l.map(o=>t.jsx(rq,{row:o,agents:a,onOpen:n,onAct:s},o.id))})]},i.id):null})})}function rq({row:e,agents:n,onOpen:s,onAct:r}){var o,c,u;const a=e.untrusted?["trust","Mark as mine"]:w8(e)?["picker","Choose agents"]:null,i=y8(e,n),l=k8(e,n);return t.jsx(Xe,{onClick:()=>s(e),label:`${e.title}: details`,lead:e.bundle?t.jsx(ww,{}):t.jsx(Un,{icon:"files"}),title:e.bundle?t.jsxs("span",{className:"skb-title",children:[e.title,t.jsx(Jl,{children:"bundle"})]}):e.title,sub:t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"skills-line",children:e.description}),t.jsxs("span",{className:"skills-line skills-meta",children:[i," · ",pc(e,n,!0)]}),l?t.jsx("span",{className:"skills-line skb-scripts",children:l}):null,e.untrusted?t.jsx("span",{className:"skills-status","data-tone":"warning",children:Jy(e,n)}):null]}),side:t.jsxs("span",{className:"skills-side",children:[a?t.jsx(A,{size:"sm",onClick:tq(()=>r(e,a[0])),children:a[1]}):null,t.jsx(Rs,{label:`More for ${e.title}`,sheet:{title:e.title,sub:i},items:[{label:"Choose agents…",hint:"Give it or take it away",onSelect:()=>r(e,"picker")},e.editable?{label:e.bundle?"Edit SKILL.md":"Edit text",onSelect:()=>r(e,"edit")}:null,{label:"Download",hint:e.bundle?".zip with its files":".md file",onSelect:()=>r(e,"download")},((o=e.from)==null?void 0:o.kind)==="plugin"?{label:`Open ${qy(e.from.plugin)}`,onSelect:()=>r(e,"plugin")}:null,e.deletable&&((c=e.from)==null?void 0:c.kind)!=="plugin"?"separator":null,e.deletable&&((u=e.from)==null?void 0:u.kind)!=="plugin"?{label:"Delete…",tone:"critical",onSelect:()=>r(e,"delete")}:null]})]})})}function aq(){return t.jsx(Ye,{flush:!0,children:t.jsxs("div",{className:"skills-group skills-loading","aria-busy":"true","aria-label":"Loading skills",children:[t.jsx("header",{className:"skills-group-head",children:t.jsx("i",{className:"cat-skel-line","data-w":"20"})}),t.jsx(at,{children:[0,1,2].map(e=>t.jsxs("div",{className:"ui-list-row",children:[t.jsx("span",{className:"ui-app-icon"}),t.jsxs("span",{className:"ui-list-main skills-skel",children:[t.jsx("i",{className:"cat-skel-line","data-w":"40"}),t.jsx("i",{className:"cat-skel-line","data-w":"70"})]})]},e))})]})})}function sI({view:e,faces:n,open:s,setOpen:r,dialog:a,setDialog:i,navigate:l,onChanged:o,onFailed:c}){if(!e)return null;const u=m=>e.skills.find(p=>p.id===m),d=s?u(s.id):void 0,f=a&&"id"in a?u(a.id):void 0;return t.jsxs(t.Fragment,{children:[d?t.jsx(iq,{row:d,agents:e.agents,faces:n,initialEdit:!!(s!=null&&s.edit),...s!=null&&s.file?{initialFile:s.file}:{},onClose:()=>r(null),onPicker:()=>i({kind:"picker",id:d.id}),onDelete:()=>i({kind:"delete",id:d.id}),onChanged:o,onFailed:c,navigate:l},`${d.id}-${s!=null&&s.edit?"edit":"read"}`):null,(a==null?void 0:a.kind)==="picker"&&f?t.jsx(lq,{row:f,agents:e.agents,faces:n,onCancel:()=>i(null),onSaved:()=>{i(null),o()}}):null,(a==null?void 0:a.kind)==="delete"&&f?t.jsx(cq,{row:f,agents:e.agents,onCancel:()=>i(null),onDeleted:m=>{i(null),r(null),o(m)}}):null]})}function rI({title:e,sub:n}){return t.jsxs("span",{className:"skills-sheet-title",children:[t.jsx(Un,{icon:"files",size:"lg"}),t.jsxs("span",{className:"skills-sheet-name",children:[t.jsx("span",{children:e}),t.jsx("span",{className:"skills-sheet-by",children:n})]})]})}function tc({title:e,aside:n,children:s}){return t.jsxs("section",{className:"skills-sec","aria-label":e,children:[t.jsxs("header",{className:"skills-sec-head",children:[t.jsx("h3",{className:"skills-sec-title",children:e}),n?t.jsx("span",{className:"skills-sec-aside",children:n}):null]}),s]})}function YN({file:e,body:n,text:s}){const[r,a]=h.useState("read");return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"skills-text-bar",children:[t.jsx(ln,{label:"Show the text as",value:r,onChange:a,options:[{value:"read",label:"Read"},{value:"source",label:"Source"}]}),t.jsx("span",{className:"skills-file mono",children:e})]}),r==="read"?t.jsx(ur,{className:"wb-md skills-md",text:n}):t.jsx(Dt,{label:e,children:s})]})}function iq({row:e,agents:n,faces:s,initialEdit:r,initialFile:a,onClose:i,onPicker:l,onDelete:o,onChanged:c,onFailed:u,navigate:d}){var K,ee,ce,pe;const f=me(()=>Gt.detail(e.id),[e.id,e.updatedAt,e.untrusted,(K=e.learned)==null?void 0:K.version]),[m,p]=h.useState(!!r&&e.editable),[g,v]=h.useState(null),[b,j]=h.useState(!1),[x,y]=h.useState(null),[w,k]=h.useState(r?"SKILL.md":a??"SKILL.md"),N=((ee=f.data)==null?void 0:ee.text)??"",S=pT(pc(e,n)),C=S8(e,n),E=((ce=e.from)==null?void 0:ce.kind)==="plugin"?qy(e.from.plugin):null,T=oe=>s.find(Re=>Re.id===oe),I=e.bundle??null,F=((pe=f.data)==null?void 0:pe.bundle)??null,D=(I==null?void 0:I.scripts.length)??0,$=oe=>{var Re;return((Re=n.find(Oe=>Oe.id===oe))==null?void 0:Re.canRunScripts)===!0},L=gT(e,n).filter($).map(oe=>Ks(n,oe)),O=async(oe,Re)=>{j(!0),y(null);try{await oe(),Re==null||Re(),c()}catch(Oe){y(Fi(Oe)),u(Fi(Oe))}finally{j(!1)}},M=oe=>{O(()=>Gt.grant(e.id,{agents:Qy(e).filter(Re=>Re!==oe)}))},P=()=>{O(()=>Gt.saveText(e.id,g??N),()=>{p(!1),v(null)})},H=()=>{k("SKILL.md"),p(!0)},U=(oe,Re)=>{var Oe,Je;if(I)return D?$(oe)?t.jsxs("span",{className:"skb-can",children:["Can run its scripts with ",t.jsx("span",{className:"mono",children:Jh}),", asking each time"]}):"Reads the text only: it has no tool that runs scripts":"Uses the text and its files";if(((Oe=e.learned)==null?void 0:Oe.by)===oe)return"Proposed it";if(((Je=e.from)==null?void 0:Je.kind)==="catalogue"&&e.from.agent===oe)return"Came with it";if(Re==="home")return"In its own folder"},V=t.jsx("textarea",{className:"skills-editor",value:g??N,onChange:oe=>v(oe.target.value),"aria-label":`Text of ${e.title}`,spellCheck:!1,autoFocus:!0}),z=I&&F?`Bundle · ${F.files.length} files · ${Rr(F.size)} · ${pc(e,n)}`:I?`Bundle · ${I.files+1} files · ${Rr(I.size)} · ${pc(e,n)}`:S,X=(F==null?void 0:F.files.find(oe=>oe.path===w))??(F==null?void 0:F.files[0]);return t.jsxs(Ge,{size:"wide",title:I?t.jsxs("span",{className:"skills-sheet-title",children:[t.jsx(ww,{size:"lg"}),t.jsxs("span",{className:"skills-sheet-name",children:[t.jsx("span",{children:e.title}),t.jsx("span",{className:"skills-sheet-by",children:z})]})]}):t.jsx(rI,{title:e.title,sub:S}),onClose:i,foot:m?t.jsxs(te,{align:"end",children:[t.jsx(A,{variant:"ghost",disabled:b,onClick:()=>{p(!1),v(null)},children:"Cancel"}),t.jsx(A,{variant:"accent",disabled:b||!f.data,onClick:P,children:I?"Save SKILL.md":"Save"})]}):t.jsxs(te,{children:[e.deletable&&!E?t.jsx(A,{variant:"danger-ghost",onClick:o,children:"Delete…"}):null,t.jsx(et,{}),t.jsx(A,{onClick:()=>fT(e.id),children:I?"Download .zip":"Download"}),e.editable?t.jsx(A,{variant:e.untrusted?void 0:"accent",onClick:H,children:I?"Edit SKILL.md":"Edit text"}):null]}),children:[e.untrusted?t.jsxs(G,{tone:"warning",action:t.jsx(A,{size:"sm",variant:"accent",disabled:b,onClick:()=>void O(()=>Gt.trust(e.id)),children:"Mark as mine"}),children:[Jy(e,n)," Mark it as yours once you’ve read it",D?" and its scripts":"","."]}):null,t.jsx(ne,{message:x}),t.jsxs("div",{className:"skills-sheet",children:[t.jsx(tc,{title:"When it’s used",children:t.jsx("p",{className:"skills-desc",children:e.description})}),t.jsxs(tc,{title:"Used by",aside:t.jsx(A,{size:"sm",onClick:l,children:"Change…"}),children:[D?t.jsx(nI,{children:e.untrusted?"Its scripts can’t run until you mark it as yours. Then they run only when an agent you allow runs them, and ask first. Nothing ran when it was uploaded.":"Scripts run only when an agent you allow runs them, and ask first. Nothing ran when it was uploaded."}):null,e.every?t.jsx(at,{children:t.jsx(Xe,{lead:t.jsx(Un,{icon:"agents"}),title:Yy(e,n),sub:D?L.length?`Now, and any you add later. ${Qa(L)} can run its scripts, asking each time.`:"Now, and any you add later. None of them can run its scripts.":"Now, and any you add later."})}):e.holders.length?t.jsx("div",{className:I?"skb-holders":void 0,children:t.jsx(at,{children:e.holders.map(oe=>{const Re=n.find(Oe=>Oe.id===oe.agent);return t.jsx(Xe,{lead:t.jsx(Nn,{id:oe.agent,name:(Re==null?void 0:Re.name)??oe.agent,size:"sm",face:T(oe.agent)}),title:t.jsxs(t.Fragment,{children:[(Re==null?void 0:Re.name)??oe.agent," ",t.jsxs("span",{className:"skills-handle",children:["@",(Re==null?void 0:Re.handle)??oe.agent]})]}),sub:U(oe.agent,oe.how),side:oe.how==="home"?void 0:t.jsx(A,{size:"sm",variant:"ghost",disabled:b,onClick:()=>M(oe.agent),"aria-label":`Take away from ${(Re==null?void 0:Re.name)??oe.agent}`,children:"Take away"})},oe.agent)})})}):t.jsx("p",{className:"skills-note",children:"No agent uses it yet, so it does nothing. Choose who should."})]}),I?t.jsxs(tc,{title:"Files",aside:F?t.jsxs("span",{className:"skills-note",children:[F.files.length," files · ",Rr(F.size)]}):void 0,children:[!f.data||!F||!X?f.error?t.jsx(ne,{message:f.error}):t.jsx(ve,{children:"Reading the bundle…"}):t.jsxs(tI,{children:[t.jsx(ZR,{files:F.files,selected:X.path,onSelect:m?null:k}),t.jsx(eI,{file:X,read:oe=>Gt.file(e.id,oe),imageUrl:oe=>Gt.imageUrl(e.id,oe),reach:{run:L,held:e.every||e.holders.length>0,untrusted:e.untrusted!==null},skillView:m?V:t.jsx(YN,{file:nN(e),body:f.data.body,text:N})})]}),t.jsx("p",{className:"skills-note",children:"Read only, except SKILL.md. To change any other file, upload the bundle again."})]}):t.jsxs(tc,{title:"The text",children:[f.data?m?V:t.jsx(YN,{file:nN(e),body:f.data.body,text:N}):f.error?t.jsx(ne,{message:f.error}):t.jsx(ve,{children:"Reading the file…"}),m&&C?t.jsx("p",{className:"skills-note",children:C}):null,E?t.jsxs("p",{className:"skills-note",children:["Comes with ",E,", so it’s changed there. To stop an agent using it, take it away above."," ",t.jsx("a",{href:Le("plugins"),onClick:oe=>{oe.preventDefault(),d(Le("plugins"))},children:"Open Plugins"})]}):null]})]})]})}function Qh({checked:e,disabled:n,onChange:s,lead:r,title:a,sub:i}){return t.jsxs("label",{className:"skills-pick-row","data-disabled":n?"true":void 0,children:[t.jsx("input",{type:"checkbox",checked:e,disabled:n,onChange:l=>s(l.target.checked)}),r,t.jsxs("span",{className:"skills-pick-text",children:[t.jsx("span",{className:"skills-pick-title",children:a}),i?t.jsx("span",{className:"skills-pick-sub",children:i}):null]})]})}function aI({label:e,value:n,onChange:s}){return t.jsxs("div",{className:"cat-search",children:[t.jsx(le,{name:"search",size:16}),t.jsx(nm,{label:e,value:n,placeholder:e,onChange:s})]})}function lq({row:e,agents:n,faces:s,onCancel:r,onSaved:a}){var k;const[i,l]=h.useState(e.every),[o,c]=h.useState(Qy(e)),[u,d]=h.useState(""),[f,m]=h.useState(!1),[p,g]=h.useState(null),v=u.trim().toLowerCase(),b=n.filter(N=>!v||`${N.name} ${N.handle}`.toLowerCase().includes(v)),j=(N,S)=>c(S?[...o,N]:o.filter(C=>C!==N)),x=((k=e.bundle)==null?void 0:k.scripts.length)??0,y=x?[["Can run its scripts",b.filter(N=>N.canRunScripts)],["Text only",b.filter(N=>!N.canRunScripts)]]:[[null,b]],w=async()=>{m(!0),g(null);try{await Gt.grant(e.id,i?{every:!0,agents:[]}:{agents:o}),a()}catch(N){g(Fi(N))}finally{m(!1)}};return t.jsx(zt,{title:`Who uses “${e.title}”?`,onClose:r,foot:t.jsxs(t.Fragment,{children:[t.jsx(A,{variant:"ghost",onClick:r,children:"Cancel"}),t.jsx(A,{variant:"accent",disabled:f,onClick:()=>void w(),children:"Save"})]}),children:t.jsxs("div",{className:"skills-pick",children:[x?t.jsxs(nI,{children:[x," script",x>1?"s":""," come",x>1?"":"s"," with it. Only an agent with a tool that runs commands can run them, and it asks you each time",e.untrusted?", once you’ve marked it as yours":"","."]}):null,t.jsx(aI,{label:"Find an agent",value:u,onChange:d}),t.jsx(ne,{message:p}),t.jsxs("div",{className:"skills-pick-list",children:[v||!e.shareable?null:t.jsx(Qh,{checked:i,onChange:l,lead:t.jsx(Un,{icon:"agents"}),title:"Every agent",sub:x?"Now and later. Scripts still ask each time.":"Now, and any you add later."}),y.map(([N,S])=>S.length?t.jsxs("div",{className:"skills-pick-group",role:N?"group":void 0,"aria-label":N??void 0,children:[N?t.jsxs("div",{className:"skills-pick-group-title",children:[N,N==="Text only"?" · no tool that runs scripts":" · asking you each time"]}):null,S.map(C=>{const E=e.home===C.id,T=(e.shadowedBy??[]).includes(C.id),I=E||T||!C.writable;return t.jsx(Qh,{checked:!T&&(i||E||o.includes(C.id)),disabled:i||I,onChange:F=>j(C.id,F),lead:t.jsx(Nn,{id:C.id,name:C.name,size:"sm",face:s.find(F=>F.id===C.id)}),title:t.jsxs(t.Fragment,{children:[C.name," ",t.jsxs("span",{className:"skills-handle",children:["@",C.handle]})]}),sub:E?"Its own skill, in its folder":T?"Has its own skill of this name, and uses that":C.writable?x&&C.canRunScripts?t.jsxs("span",{className:"skb-can",children:["With ",t.jsx("span",{className:"mono",children:Jh})]}):void 0:"Ships with buddi, so its file doesn’t change"},C.id)})]},N??"all"):null),b.length?null:t.jsxs("p",{className:"skills-note skills-pick-none",children:["No agent called “",u.trim(),"”."]})]}),t.jsx("p",{className:"skills-note",children:"Saved in each agent’s file, so the file stays the record."})]})})}function oq({agent:e,view:n,onCancel:s,onSaved:r}){const a=x=>mT(x,e.id),[i,l]=h.useState(n.skills.filter(a).map(x=>x.id)),[o,c]=h.useState(""),[u,d]=h.useState(!1),[f,m]=h.useState(null),p=o.trim().toLowerCase(),g=x=>!p||`${x.title} ${x.description}`.toLowerCase().includes(p),v=x=>x.every||x.home===e.id||!e.writable,b=async()=>{d(!0),m(null);try{for(const x of n.skills){if(v(x))continue;const y=i.includes(x.id);if(y===a(x))continue;const w=Qy(x);await Gt.grant(x.id,{agents:y?[...w,e.id]:w.filter(k=>k!==e.id)})}r()}catch(x){m(Fi(x))}finally{d(!1)}},j=n.skills.some(g);return t.jsx(zt,{title:`Skills ${e.name} uses`,onClose:s,foot:t.jsxs(t.Fragment,{children:[t.jsx(A,{variant:"ghost",onClick:s,children:"Cancel"}),t.jsx(A,{variant:"accent",disabled:u||!e.writable,onClick:()=>void b(),children:"Save"})]}),children:t.jsxs("div",{className:"skills-pick",children:[t.jsx(aI,{label:"Find a skill",value:o,onChange:c}),t.jsx(ne,{message:f}),e.writable?null:t.jsxs("p",{className:"skills-note",children:[e.name," ships with buddi, so its file doesn’t change. Ask Agent Father to make it yours first."]}),t.jsxs("div",{className:"skills-pick-list",children:[Gy.map(x=>{const y=n.skills.filter(w=>w.group===x.id&&g(w));return y.length?t.jsxs("div",{className:"skills-pick-group",role:"group","aria-label":x.title,children:[t.jsx("div",{className:"skills-pick-group-title",children:x.title}),y.map(w=>t.jsx(Qh,{checked:i.includes(w.id),disabled:v(w),onChange:k=>l(k?[...i,w.id]:i.filter(N=>N!==w.id)),title:w.title,sub:w.every?a(w)?"Every agent uses it":Yy(w,n.agents):w.home===e.id?"Its own skill, in its folder":w.description},w.id))]},x.id):null}),j?null:t.jsxs("p",{className:"skills-note skills-pick-none",children:["No skill matches “",o.trim(),"”."]})]})]})})}function JN({agents:e,faces:n,upload:s,onClose:r,onSaved:a}){const[i,l]=h.useState((s==null?void 0:s.title)??""),[o,c]=h.useState((s==null?void 0:s.description)??""),[u,d]=h.useState((s==null?void 0:s.body)??""),[f,m]=h.useState([]),[p,g]=h.useState(!1),[v,b]=h.useState(!1),[j,x]=h.useState(null),y=i.trim()!==""&&o.trim()!==""&&u.trim()!=="",w=s?`${Math.max(1,Math.round(s.size/1024))} KB`:"",k=async()=>{b(!0),x(null);try{const{skill:N}=await Gt.create({title:i.trim(),description:o.trim(),body:u,agents:f,...s?{upload:{filename:s.name,mine:p}}:{}});a(N)}catch(N){x(Fi(N))}finally{b(!1)}};return t.jsxs(Ge,{size:"wide",title:s?t.jsx(rI,{title:s.name,sub:`${w} · read, not saved yet`}):"Write a skill",onClose:r,foot:t.jsxs(te,{align:"end",children:[t.jsx(A,{variant:"ghost",onClick:r,children:"Cancel"}),t.jsx(A,{variant:"accent",disabled:!y||v,onClick:()=>void k(),children:"Save skill"})]}),children:[t.jsx(ne,{message:j}),t.jsxs("div",{className:"skills-sheet",children:[t.jsxs("section",{className:"skills-sec skills-form",children:[t.jsx(re,{label:"Name",hint:"Short, like a task: “Weekly money recap”.",children:t.jsx("input",{value:i,onChange:N=>l(N.target.value),autoFocus:!s})}),t.jsx(re,{label:"When it’s used",hint:"One line. Agents read it to decide when the skill applies.",children:t.jsx("input",{value:o,onChange:N=>c(N.target.value),placeholder:"When I ask about the week’s spending"})}),t.jsx(re,{label:"The text",hint:"Plain Markdown: steps, rules, what a good answer looks like.",children:t.jsx("textarea",{className:"skills-editor",value:u,onChange:N=>d(N.target.value),spellCheck:!1,placeholder:`1. Total spent this week.
124
- 2. The three biggest charges.
125
- 3. Anything odd.`})})]}),t.jsxs(tc,{title:"Who uses it",children:[t.jsx("div",{className:"skills-who",children:e.map(N=>t.jsx(Qh,{checked:f.includes(N.id),disabled:!N.writable,onChange:S=>m(S?[...f,N.id]:f.filter(C=>C!==N.id)),lead:t.jsx(Nn,{id:N.id,name:N.name,size:"sm",face:n.find(S=>S.id===N.id)}),title:N.name},N.id))}),t.jsx("p",{className:"skills-note",children:"You can change this later. With nobody ticked it’s kept and does nothing."})]}),s?t.jsx("section",{className:"skills-sec",children:t.jsxs("label",{className:"plugins-check",children:[t.jsx("input",{type:"checkbox",checked:p,onChange:N=>g(N.target.checked)}),t.jsxs("span",{children:[t.jsx("span",{className:"plugins-check-title",children:"Mark as mine"}),t.jsx("span",{className:"plugins-check-hint",children:"I wrote it, or I’ve read it and trust it. Otherwise agents read it as outside text."})]})]})}):null]})]})}function cq({row:e,agents:n,onCancel:s,onDeleted:r}){const a=me(()=>Gt.detail(e.id),[e.id]),[i,l]=h.useState(!1),[o,c]=h.useState(null),u=h.useMemo(()=>a.data?C8(e,a.data.onDelete,n):null,[a.data,e,n]),d=async()=>{l(!0),c(null);try{const f=await Gt.remove(e.id);r(`Deleted “${e.title}”.${f.movedTo?" The file is in the trash folder.":f.versionsKept?" Its earlier versions are kept.":""}`)}catch(f){c(Fi(f)),l(!1)}};return t.jsxs(zt,{title:`Delete “${e.title}”?`,onClose:s,foot:t.jsxs(t.Fragment,{children:[t.jsx(A,{variant:"ghost",onClick:s,children:"Cancel"}),t.jsx(A,{variant:"danger",disabled:i||!a.data,onClick:()=>void d(),children:"Delete"})]}),children:[t.jsx(ne,{message:o??a.error}),t.jsx("p",{className:"skills-dialog-text",children:u??"Checking who uses it…"})]})}function uq(e){var n;return((n=Gy.find(s=>s.id===e.group))==null?void 0:n.title)??""}function dq({agentId:e,agentName:n,faces:s=[],navigate:r}){const a=me(()=>Gt.list(),[e]),[i,l]=h.useState(null),[o,c]=h.useState(null),[u,d]=h.useState(!1),[f,m]=h.useState(null),[p,g]=h.useState(null),v=k=>{m(null),g(k??null),a.reload()},b=k=>{Gt.trust(k.id).then(()=>v(),N=>m(N instanceof Error?N.message:String(N)))};if(!a.data)return a.error?t.jsx(ve,{warm:!0,title:"Couldn’t load the skills",action:t.jsx(A,{variant:"accent",size:"sm",onClick:a.reload,children:"Try again"}),children:"buddi didn’t answer. The skill files are untouched."}):t.jsx(ve,{children:"Loading…"});const j=a.data,x=j.agents.find(k=>k.id===e)??{id:e,handle:e,name:n,writable:!1},y=j.skills.filter(k=>mT(k,e)),w=hT();return t.jsxs(t.Fragment,{children:[t.jsx(ne,{message:f}),p?t.jsx(G,{tone:"good",role:"status",children:p}):null,t.jsx(Ye,{flush:!0,title:"Skills",actions:t.jsxs(t.Fragment,{children:[t.jsxs("a",{className:"skills-all",href:w,onClick:k=>{k.preventDefault(),r(w)},children:["All skills",t.jsx(le,{name:"chevron-right",size:12})]}),t.jsx(A,{size:"sm",onClick:()=>d(!0),children:"Choose skills…"})]}),children:y.length?t.jsx("div",{className:"skills-group",children:t.jsx(at,{children:y.map(k=>t.jsx(Xe,{onClick:()=>l({id:k.id}),label:`${k.title}: details`,lead:t.jsx(Un,{icon:"files"}),title:k.title,sub:t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"skills-line",children:k.description}),t.jsxs("span",{className:"skills-line skills-meta",children:[uq(k)," · ",k.every?"every agent uses it":pc(k,j.agents,!0)]}),k.untrusted?t.jsx("span",{className:"skills-status","data-tone":"warning",children:Jy(k,j.agents)}):null]}),side:t.jsx("span",{className:"skills-side",children:k.untrusted?t.jsx(A,{size:"sm",onClick:N=>{N.stopPropagation(),b(k)},children:"Mark as mine"}):t.jsx("span",{className:"skills-chevron","aria-hidden":"true",children:t.jsx(le,{name:"chevron-right",size:14})})})},k.id))})}):t.jsxs(ve,{children:[n," uses no skills yet. Choose some, or write one on the Skills page."]})}),t.jsx(sI,{view:j,faces:s,open:i,setOpen:l,dialog:o,setDialog:c,navigate:r,onChanged:v,onFailed:m}),u?t.jsx(oq,{agent:x,view:j,onCancel:()=>d(!1),onSaved:()=>{d(!1),v()}}):null]})}function iI({timezone:e,embedded:n,agentId:s}){const{data:r,error:a,reload:i}=me(()=>R.reminders(),[],3e4),l=((r==null?void 0:r.reminders)??[]).filter(d=>!s||d.agentId===s),[o,c]=h.useState(null),u=async d=>{c(null);try{await R.cancelReminder(d),i()}catch(f){c(f instanceof Error?f.message:String(f))}};return t.jsxs(Zn,{embedded:n,title:"Reminders",lede:"A reminder wakes an agent with a note and the instruction to check before it speaks, never a message queued for delivery.",children:[t.jsx(ne,{message:a??o}),t.jsx(Ye,{flush:!0,children:r?l.length===0?t.jsx(Jn,{icon:"bell",title:"No reminders",children:"Ask any agent to remind you of something, and it shows up here."}):t.jsxs(Kr,{children:[t.jsx("thead",{children:t.jsxs("tr",{children:[t.jsx("th",{children:"Due"}),t.jsx("th",{children:"Agent"}),t.jsx("th",{children:"Note"}),t.jsx("th",{children:"State"}),t.jsx("th",{})]})}),t.jsx("tbody",{children:l.map(d=>t.jsxs("tr",{children:[t.jsxs("td",{className:"nowrap",children:[ct(d.dueAt,e),t.jsx("div",{className:"sub",children:Ve(d.dueAt)})]}),t.jsx("td",{className:"mono",children:d.agentId}),t.jsxs("td",{children:[d.text,d.context?t.jsx(Ot,{summary:"context",children:t.jsx(Dt,{children:ks(d.context)})}):null]}),t.jsxs("td",{children:[t.jsx(Nu,{state:d.state}),d.cancelReason?t.jsx("div",{className:"sub",children:d.cancelReason}):null]}),t.jsx("td",{children:d.state==="pending"?t.jsx(A,{size:"sm",variant:"danger",onClick:()=>u(d.id),children:"Cancel"}):null})]},d.id))})]}):t.jsx(ve,{children:"Loading…"})})]})}const hq=/(flux|klein|schnell|qwen[-_]?image|image)/i;function lI(e){return e.kind==="image"||e.kind===void 0&&hq.test(e.id)}function fq(e){const n=((e==null?void 0:e.models)??[]).filter(s=>!lI(s));return[...n.filter(s=>s.loaded),...n.filter(s=>!s.loaded)].map(s=>s.id)}function wv(e){return fq(e)[0]}function bw(e){return(e==null?void 0:e.detectedContextWindowSource)==="mlxh"}function mq(e){return(e??0)<40960?"mlxh’s max_prompt_tokens; raise it with `mlxh config max_prompt_tokens 40960` for long conversations":"mlxh’s max_prompt_tokens"}function oI(e){let n=e;try{n=new URL(e).host}catch{}return`mlxh is not answering on ${n}. Start it with \`mlxh serve\`, or \`mlxh service install\` to keep it running.`}const cI="an image model; pick it in the Image plugin, not here";function kw({accountId:e,label:n,value:s,onChange:r,disabled:a=!1}){const[i,l]=h.useState(null),[o,c]=h.useState(!1),[u,d]=h.useState(""),[f,m]=h.useState(!1),p=h.useRef(0),g=async x=>{if(!e)return;const y=++p.current;c(!0),d("");try{const w=await R.accountModels(e,x);y===p.current&&l(w)}catch(w){y===p.current&&d(w instanceof Error?w.message:"Could not load models. Custom entry is still available.")}finally{y===p.current&&c(!1)}};if(h.useEffect(()=>(l(null),m(!1),d(""),g(!1),()=>{p.current++}),[e]),!e)return t.jsxs(t.Fragment,{children:[t.jsx(re,{label:n,children:t.jsx("input",{required:!0,maxLength:150,value:s,disabled:a,onChange:x=>r(x.target.value)})}),t.jsx("p",{className:"ui-toolbar-note",children:"Save and connect the account to load its model list. You can enter a model manually now."})]});const v=(i==null?void 0:i.models)??[],b=!!s&&!v.some(x=>x.id===s),j=[i&&!v.length?"This account returned no models. You can enter a custom model.":null,i!=null&&i.truncated?"Showing the first part of this provider’s list. Custom model entry is available.":null,i?"Uses saved account settings. Listed models may not support every agent tool. Your selection is unchanged until you save.":null].filter(Boolean);return t.jsxs(t.Fragment,{children:[t.jsx(re,{label:n,children:t.jsxs("select",{value:f?"__buddi_custom__":s,disabled:a,onChange:x=>{x.target.value==="__buddi_custom__"?m(!0):(m(!1),r(x.target.value))},children:[t.jsx("option",{value:"",disabled:!0,children:"Choose a model"}),b&&t.jsxs("option",{value:s,children:[s," (current",i?", not listed":"",")"]}),v.map(x=>t.jsxs("option",{value:x.id,children:[x.name===x.id?x.id:`${x.name} — ${x.id}`,x.isDefault?" (provider default)":"",x.image?` — ${cI}`:""]},x.id)),t.jsx("option",{value:"__buddi_custom__",children:"Custom model…"})]})}),t.jsx(A,{disabled:a||o,onClick:()=>void g(!0),children:o?"Loading models…":"Refresh models"}),f&&t.jsx(re,{label:`Custom ${n.toLowerCase()}`,children:t.jsx("input",{required:!0,maxLength:150,value:s,disabled:a,onChange:x=>r(x.target.value)})}),u&&t.jsx("p",{role:"alert",className:"ui-toolbar-note critical",children:u}),j.length>0&&t.jsx("p",{className:"ui-toolbar-note",children:j.join(" ")})]})}function pq(e,n){const s=new Set(n),r=[],a=new Set;for(const i of e){for(const o of i.tools)a.add(o.name);const l=i.tools.filter(o=>s.has(o.name));l.length!==0&&(i.glob&&l.length===i.tools.length?r.push(i.glob):r.push(...l.map(o=>o.name)))}return r.push(...n.filter(i=>!a.has(i))),r}function gq(e,n){return[...e].sort().join(",")===[...n].sort().join(",")}const xq="This agent will not remember anything between conversations.";function vq({view:e,chosen:n,onChange:s,disabled:r}){var k;const[a,i]=h.useState(""),[l,o]=h.useState(null),[c,u]=h.useState(()=>new Set),d=N=>u(S=>{const C=new Set(S);return C.has(N)?C.delete(N):C.add(N),C}),f=N=>{i(N),u(new Set)},m=h.useId(),p=new Set(n),g=new Set(e.groups.flatMap(N=>N.tools.filter(S=>S.core).map(S=>S.name))),v=(N,S)=>{const C=S.filter(E=>p.has(E));if(C.length!==0){if(C.some(E=>g.has(E))){o({plugin:N,names:C});return}s(n.filter(E=>!C.includes(E)))}},b=N=>{s([...n,...N.filter(S=>!p.has(S))])},j=a.trim().toLowerCase(),x=(N,S)=>j===""||N.toLowerCase().includes(j)||S.toLowerCase().includes(j),y=e.groups.map(N=>({group:N,tools:N.tools.filter(S=>x(S.name,S.description))})).filter(N=>N.tools.length>0),w=(((k=e.suggested)==null?void 0:k.tools)??[]).filter(N=>!p.has(N.name));return t.jsxs("div",{className:"tool-picker",children:[e.suggested&&w.length>0?t.jsxs("div",{className:"tool-picker-group",role:"group","aria-labelledby":`${m}-suggested`,children:[t.jsx("div",{className:"tool-picker-head",children:t.jsx("span",{id:`${m}-suggested`,className:"tool-picker-plugin",children:e.suggested.label})}),t.jsx("ul",{className:"ui-list tool-picker-list","aria-label":e.suggested.label,children:w.map(N=>t.jsxs("li",{className:"ui-list-row",children:[t.jsxs("span",{className:"ui-list-main",children:[t.jsx("span",{className:"ui-list-title mono",children:N.name}),t.jsx("span",{className:"ui-list-sub",children:N.description})]}),t.jsx(A,{size:"sm",disabled:r,"aria-label":`Add ${N.name}`,onClick:()=>b([N.name]),children:"Add"})]},N.name))})]}):null,t.jsxs("label",{className:"tool-picker-search",children:[t.jsx("span",{className:"ui-field-label",children:"Find a tool"}),t.jsx("input",{type:"search",value:a,placeholder:"Name or what it does",onChange:N=>f(N.target.value)})]}),y.length===0?t.jsxs(ve,{children:["No installed tool matches “",a.trim(),"”."]}):null,y.map(({group:N,tools:S})=>{const C=N.tools.filter($=>$.grantable).map($=>$.name),E=N.tools.filter($=>p.has($.name)).length,T=!!N.glob&&E===N.tools.length,I=`${m}-${N.plugin}`,F=`${m}-${N.plugin}-list`,D=j!==""?!c.has(N.plugin):c.has(N.plugin);return t.jsxs("div",{className:"tool-picker-group",role:"group","aria-labelledby":I,"data-open":D?"true":void 0,children:[t.jsxs("div",{className:"tool-picker-head",children:[t.jsxs("button",{type:"button",className:"tool-picker-toggle","aria-expanded":D,"aria-controls":F,onClick:()=>d(N.plugin),children:[t.jsx(jq,{}),t.jsx("span",{id:I,className:"tool-picker-plugin",children:N.plugin}),t.jsx("span",{className:"muted",children:T?`all ${N.tools.length}`:`${E} of ${N.tools.length} granted`})]}),t.jsx(A,{size:"sm",variant:"ghost","aria-label":`All ${N.plugin} tools`,disabled:r||C.every($=>p.has($)),onClick:()=>b(C),children:"all"}),t.jsx(A,{size:"sm",variant:"ghost","aria-label":`No ${N.plugin} tools`,disabled:r||!C.some($=>p.has($)),onClick:()=>v(N.plugin,C),children:"none"})]}),(l==null?void 0:l.plugin)===N.plugin?t.jsx(G,{tone:"warning",role:"alert",children:t.jsxs("div",{className:"tool-picker-confirm",children:[t.jsx("span",{children:xq}),t.jsx("span",{className:"ui-toolbar-spacer"}),t.jsx(A,{size:"sm",onClick:()=>o(null),children:"Keep"}),t.jsx(A,{size:"sm",variant:"danger",onClick:()=>{s(n.filter($=>!l.names.includes($))),o(null)},children:"Remove"})]})}):null,t.jsx("ul",{id:F,className:"ui-list tool-picker-list",hidden:!D,children:S.map($=>{const L=`${m}-${$.name}`;return t.jsxs("li",{className:"ui-list-row",children:[t.jsx("input",{type:"checkbox",id:L,checked:p.has($.name),disabled:r||!$.grantable,onChange:O=>O.target.checked?b([$.name]):v(N.plugin,[$.name])}),t.jsxs("label",{htmlFor:L,className:"ui-list-main",children:[t.jsxs("span",{className:"ui-list-title",children:[t.jsx("span",{className:"mono",children:$.name}),$.core?t.jsx(Ee,{tone:"accent",children:"core"}):null,$.gated?t.jsx(Ee,{tone:"warning",children:"asks you"}):null]}),t.jsx("span",{className:"ui-list-sub",children:$.grantable?$.description:`${$.description} Granted only by editing the file by hand.`})]})]},$.name)})})]},N.plugin)})]})}function jq(){return t.jsx("svg",{className:"tool-picker-chevron",viewBox:"0 0 11 11","aria-hidden":"true",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("path",{d:"M2.8 4.2 5.5 6.9l2.7-2.7"})})}const Ls={json:"That is not JSON. Paste the whole block, braces included.",empty:"There is no server in it.",command:'It starts a program on this computer rather than naming an address. Use "A program on this computer" instead.',sse:"buddi speaks Streamable HTTP; this server is SSE-only.",url:"It has no url. buddi connects to a server by its https:// address."},Ta=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function uI(e){let n;try{n=JSON.parse(e.trim())}catch{throw new Error(Ls.json)}if(!Ta(n))throw new Error(Ls.json);let s,r=n;if("mcpServers"in n){const u=n.mcpServers;if(!Ta(u))throw new Error(Ls.empty);const d=Object.keys(u);if(d.length===0)throw new Error(Ls.empty);if(d.length>1)throw new Error(`It names ${d.length} servers (${d.join(", ")}). Paste one at a time.`);s=d[0];const f=u[s];if(!Ta(f))throw new Error(Ls.url);r=f}if("command"in r)throw new Error(Ls.command);if(typeof r.type=="string"&&r.type.toLowerCase()==="sse")throw new Error(Ls.sse);const a=typeof r.url=="string"?r.url.trim():"";if(a==="")throw new Error(Ls.url);const i=Ta(r.headers)?Object.entries(r.headers).filter(u=>typeof u[1]=="string"&&u[0].trim()!==""):[],l=i.find(([u])=>u.toLowerCase()==="authorization")??i[0];let o,c=!1;if(l){const[u,d]=l,f=/^(Bearer|Basic)\s+/i.exec(d.trim()),m=f?`${f[1].charAt(0).toUpperCase()}${f[1].slice(1).toLowerCase()} `:"";let p=f?d.trim().slice(f[0].length).trim():d.trim();/\$\{[^}]*\}|^\$[A-Z_][A-Z0-9_]*$|^<[^>]+>$/i.test(p)&&(c=!0,p=""),o={name:u.trim(),prefix:m,value:p}}return{url:a,...s?{name:s}:{},...o?{header:o}:{},dropped:i.filter(u=>u!==l).map(([u])=>u),placeholder:c}}const xc={command:"It names no command to run.",claude:"That claude mcp add line names no server and no command. It looks like: claude mcp add <name> -- <command> <args…>",quote:"A quote in that line is never closed.",env:"An environment variable is written NAME=value."};function dI(e){return/TOKEN|KEY|SECRET|PASSWORD|PASSWD|CREDENTIAL|AUTH/i.test(e)}const hI=/^[A-Za-z_][A-Za-z0-9_]*$/;function yq(e){return/\$\{[^}]*\}|^\$[A-Z_][A-Z0-9_]*$|^<[^>]+>$|^your[_-]/i.test(e.trim())}function fI(e,n){const s=yq(n);return{name:e,value:s?"":n,secret:dI(e),placeholder:s}}function mI(e){const n=[];let s="",r=!1,a=null;for(let i=0;i<e.length;i+=1){const l=e[i];if(a==="'"){l==="'"?a=null:s+=l;continue}if(a==='"'){if(l==='"')a=null;else if(l==="\\"&&i+1<e.length&&'"\\$`\n'.includes(e[i+1])){const o=e[++i];o!==`
126
- `&&(s+=o)}else s+=l;continue}if(l==="\\"){const o=e[i+1];if(o===void 0)continue;if(i+=1,o===`
127
- `||o==="\r"&&e[i+1]===`
128
- `){o==="\r"&&(i+=1);continue}s+=o,r=!0;continue}if(l==="'"||l==='"'){a=l,r=!0;continue}if(/\s/.test(l)){r&&(n.push(s),s="",r=!1);continue}s+=l,r=!0}if(a)throw new Error(xc.quote);return r&&n.push(s),n}function wq(e){const n=mI(e.trim());let s=0;n[s]==="claude"&&(s+=1),n[s]==="mcp"&&(s+=1),n[s]==="add"&&(s+=1);const r=[],a=[];let i="stdio",l,o;const c=d=>{const f=d.indexOf("="),m=f>0?d.slice(0,f).trim():"";if(!hI.test(m))throw new Error(xc.env);r.push(fI(m,d.slice(f+1)))},u=[];for(;s<n.length;s+=1){const d=n[s];if(d==="--"){o=n.slice(s+1);break}const[f,m]=d.startsWith("--")&&d.includes("=")?[d.slice(0,d.indexOf("=")),d.slice(d.indexOf("=")+1)]:[d,void 0];if(f==="-e"||f==="--env"){if(m!==void 0){c(m);continue}let p=!1;for(;s+1<n.length&&/^[A-Za-z_][A-Za-z0-9_]*=/.test(n[s+1]);)c(n[++s]),p=!0;if(!p)throw new Error(xc.env);continue}if(f==="-s"||f==="--scope"){m===void 0&&(s+=1);continue}if(f==="-t"||f==="--transport"){i=(m??n[++s]??"stdio").toLowerCase();continue}if(f==="-H"||f==="--header"){const p=m??n[++s];p&&a.push(p);continue}if(!(f.startsWith("-")&&l===void 0)){if(l===void 0){l=d;continue}u.push(d)}}if(o===void 0?o=u:u.length>0&&(o=[...u,...o]),i==="http"||i==="sse"||o.length===1&&/^https?:\/\//i.test(o[0])){const d=o[0];if(!d)throw new Error(Ls.url);const f={};for(const m of a){const p=m.indexOf(":");p>0&&(f[m.slice(0,p).trim()]=m.slice(p+1).trim())}return{kind:"remote",config:uI(JSON.stringify({mcpServers:{[l??"server"]:{type:i,url:d,headers:f}}}))}}if(!l||o.length===0)throw new Error(xc.claude);return{kind:"program",program:{name:l,command:o[0],args:o.slice(1),env:r}}}function bq(e){const n=e.trim();if(/^claude\s+mcp\s+add\b/.test(n))return wq(n);let s;try{s=JSON.parse(n)}catch{throw new Error(Ls.json)}if(!Ta(s))throw new Error(Ls.json);let r,a=s;if("mcpServers"in s){const c=s.mcpServers;if(!Ta(c))throw new Error(Ls.empty);const u=Object.keys(c);u.length===1&&Ta(c[u[0]])&&(r=u[0],a=c[r])}if(!("command"in a))return{kind:"remote",config:uI(n)};const i=typeof a.command=="string"?a.command.trim():"";if(i==="")throw new Error(xc.command);const l=Array.isArray(a.args)?a.args.map(c=>String(c)):[],o=Ta(a.env)?Object.entries(a.env).filter(([c])=>hI.test(c)).map(([c,u])=>fI(c,String(u??""))):[];return{kind:"program",program:{...r?{name:r}:{},command:i,args:l,env:o}}}function Nw({code:e,label:n="Your code",large:s=!1}){const[r,a]=h.useState(!1),i=async()=>{var l;try{await((l=navigator.clipboard)==null?void 0:l.writeText(e)),a(!0)}catch{}};return t.jsxs(te,{valign:"end",children:[t.jsx(re,{label:n,grow:!0,children:t.jsx("input",{readOnly:!0,value:e,"data-code":s?"large":void 0,spellCheck:!1,onFocus:l=>l.currentTarget.select()})}),t.jsx(A,{onClick:()=>void i(),children:r?"Copied":"Copy"})]})}function pI(e){if(e.phase==="starting")return{label:"Starting",tone:"accent"};switch(e.state){case"connected":return{label:"Connected",tone:"good",dot:!0};case"needs-reconnect":return{label:"Sign in again",tone:"warning"};case"needs-review":return{label:"Needs review",tone:"warning"};case"unreachable":return{label:e.transport==="stdio"?"Failed":"Unreachable",tone:"critical"};default:return{label:"Not finished",tone:"muted"}}}const kq="It can delete or destroy something, so it asks you every time and is never remembered.";function Nq(e){return e.tier==="auto"?{label:"Runs on its own",tone:"good"}:e.destructive?{label:"Asks you every time",tone:"critical"}:{label:"Asks you first",tone:"warning"}}const gI="buddi-connections",Sq="/connections/callback",Cq="This service does not let buddi register itself. Create an app in its developer settings with the redirect address below, and paste its client id here. A token is usually simpler.",xI="Services and programs your team can use, and the tools each one brings.",Sw=(e,n,s)=>`${e} ${e===1?n:s}`;function QN(e,n){return e.transport==="stdio"?void 0:n.find(s=>Ew(s.url,e.url))}function Cw({connection:e,card:n,size:s}){return n?t.jsx(Un,{letter:n.name.slice(0,1).toUpperCase(),size:s}):t.jsx(Un,{icon:(e==null?void 0:e.transport)==="stdio"?"terminal":"globe",size:s})}function vI({connection:e}){const n=pI(e);return t.jsx(Ee,{tone:n.tone,dot:n.dot,children:n.label})}const Wp=e=>n=>{n.stopPropagation(),e()},qd=[{value:"address",label:"An address",text:"Any server on the web, by its https:// address. buddi opens it and reads what it offers, and nothing else until you have read its tools.",button:"Give its address"},{value:"program",label:"A program",text:"A server buddi starts itself on this computer, like npx or uvx, with its arguments and variables.",button:"Describe it"},{value:"paste",label:"A config",text:"The mcpServers block another app uses for it, or the claude mcp add line its docs print.",button:"Paste it"}],jI="buddi.connections.add-way";function Eq(){try{const e=window.localStorage.getItem(jI);return qd.some(n=>n.value===e)?e:"address"}catch{return"address"}}function Aq({embedded:e,timezone:n,connection:s}={}){const r=me(()=>R.connections(),[],3e4),[a,i]=h.useState(null),[l,o]=h.useState(s??null);h.useEffect(()=>{s&&o(s)},[s]);const[c,u]=h.useState(null),[d,f]=h.useState(null),m=r.data,p=N=>{var S;return((S=m==null?void 0:m.agents.find(C=>C.id===N))==null?void 0:S.name)??N},g=n??Intl.DateTimeFormat().resolvedOptions().timeZone,v=(m==null?void 0:m.connections)??[],b=(m==null?void 0:m.catalog)??[],j=b.filter(N=>!v.some(S=>S.transport!=="stdio"&&Ew(N.url,S.url))),x=l?v.find(N=>N.id===l):void 0,y=c?v.find(N=>N.id===c):void 0,w=d?v.find(N=>N.id===d):void 0,k=N=>{o(null),i(N)};return t.jsxs(Zn,{embedded:e,title:"Connections",lede:xI,children:[t.jsxs(ie,{gap:"lg",children:[t.jsxs("p",{className:"plugins-quiet connections-quiet",children:[t.jsx(le,{name:"plug",size:14}),t.jsxs("span",{children:["A connection is a service or program buddi talks to; a plugin is code buddi installs and runs."," ",t.jsx("a",{href:Le("plugins"),children:"Plugins"})]})]}),!m&&!r.error?t.jsx(ve,{children:"Reading your connections…"}):null,t.jsx(ne,{message:r.error}),m&&!m.vault?t.jsx(G,{tone:"warning",children:"This installation has no vault, so a service that asks for a sign-in cannot be connected. Turn the vault on first."}):null,m?t.jsx(Ye,{flush:!0,title:"Your connections",tool:v.length>0?Sw(v.length,"connection","connections"):void 0,children:v.length===0?t.jsx(ve,{title:"Nothing connected yet",children:"Pick a service below, or add your own: an address, a program on this computer, or a config you already have."}):t.jsx("div",{className:"connections-rows",children:t.jsx(at,{children:v.map(N=>t.jsx($q,{connection:N,card:QN(N,b),twin:N.slug!==null&&v.some(S=>S.id!==N.id&&S.name===N.name),onOpen:()=>o(N.id),onFlow:k},N.id))})})}):null,m&&j.length>0?t.jsx(Ye,{title:"Connect a service",children:t.jsx("div",{className:"connections-tiles",children:j.map(N=>t.jsxs("div",{className:"connections-tile",children:[t.jsx(Cw,{card:N}),t.jsxs("span",{className:"connections-tile-main",children:[t.jsx("span",{className:"connections-tile-name",children:N.name}),t.jsx("span",{className:"connections-tile-blurb",children:N.blurb})]}),t.jsx(A,{size:"sm",onClick:()=>k({step:"address",card:N}),"aria-label":`Connect ${N.name}`,children:"Connect"})]},N.id))})}):null,m?t.jsx(Mq,{onFlow:N=>k({step:N})}):null]}),x?t.jsx(Rq,{connection:x,card:QN(x,b),agentName:p,timezone:g,onClose:()=>o(null),onFlow:k,onDisconnect:()=>u(x.id),onHolders:()=>f(x.id)}):null,w&&m?t.jsx(Iq,{connection:w,agents:m.agents,onCancel:()=>f(null),onDone:()=>{f(null),r.reload()}},w.id):null,y?t.jsx(Pq,{connection:y,agentName:p,onCancel:()=>u(null),onDone:()=>{u(null),o(null),r.reload()}},y.id):null,a&&m?t.jsx(Dq,{start:a,agents:m.agents,catalog:m.catalog,tokens:m.tokens??m.vault,onClose:()=>{i(null),r.reload()}}):null]})}function $q({connection:e,card:n,twin:s,onOpen:r,onFlow:a}){const i=e.state==="pending-review",l=s?`${e.name} (${e.slug})`:e.name,o=e.transport==="stdio"?e.program:void 0,c=o?o.line:e.host,u=i?"its tools are not reviewed yet":Sw(e.toolCount,"tool","tools");return t.jsx(Xe,{onClick:r,label:`${l}: details`,lead:t.jsx(Cw,{connection:e,card:n}),title:l,sub:t.jsx("span",{className:"connections-sub","data-kind":o?"program":void 0,children:`${c} · ${u}`}),side:t.jsxs("span",{className:"plugins-side",children:[i?t.jsx("span",{className:"connections-act",children:t.jsx(A,{size:"sm",variant:"accent",onClick:Wp(()=>a({step:e.signedIn?"review":"consent",connection:e})),children:"Finish"})}):e.state==="needs-reconnect"&&e.authKind!=="none"?t.jsx("span",{className:"connections-act",children:t.jsx(A,{size:"sm",onClick:Wp(()=>a({step:"consent",connection:e,keepGrants:!0})),children:"Sign in"})}):e.state==="needs-review"?t.jsx("span",{className:"connections-act",children:t.jsx(A,{size:"sm",onClick:Wp(()=>a({step:"review",connection:e,keepGrants:!0})),children:"Review"})}):null,t.jsx(vI,{connection:e}),t.jsx(le,{name:"chevron-right",size:14})]})})}const Tq={oauth:"Its own sign-in page. buddi keeps the sign-in in its vault.",token:"A token you pasted, kept in buddi’s vault and sent only here.",none:"Nothing; it asks for no sign-in."};function Rq({connection:e,card:n,agentName:s,timezone:r,onClose:a,onFlow:i,onHolders:l,onDisconnect:o}){const c=e.state==="pending-review",u=e.transport==="stdio"?e.program:void 0,d=()=>i({step:"consent",connection:e,keepGrants:!0}),f=()=>i({step:"review",connection:e,keepGrants:!0}),m=()=>i({step:e.signedIn?"review":"consent",connection:e});return t.jsxs(Ge,{title:t.jsxs("span",{className:"plugins-sheet-title",children:[t.jsx(Cw,{connection:e,card:n,size:"lg"}),t.jsxs("span",{className:"plugins-sheet-name",children:[t.jsx("span",{children:e.name}),t.jsxs("span",{className:"plugins-sheet-by",children:[u?"A program on this computer":"A service at an address"," · ",t.jsx(vI,{connection:e})]})]})]}),onClose:a,foot:t.jsxs(te,{children:[t.jsx(A,{variant:"danger-ghost",onClick:o,children:"Disconnect…"}),t.jsx(et,{}),u?t.jsx(A,{onClick:()=>i({step:"program",connection:e,keepGrants:!0}),children:"Change"}):null,e.authKind!=="none"&&!c?t.jsx(A,{variant:e.state==="needs-reconnect"?"accent":void 0,onClick:d,children:"Reconnect"}):null,c?t.jsx(A,{variant:"accent",onClick:m,children:"Finish"}):t.jsx(A,{variant:e.state==="needs-review"?"accent":void 0,onClick:f,children:"Review again"})]}),children:[c?t.jsx(G,{children:"Not finished: its tools are not reviewed yet, so no agent can use them."}):null,e.state==="needs-reconnect"?t.jsx(G,{tone:"warning",action:e.authKind!=="none"?t.jsx(A,{size:"sm",variant:"accent",onClick:d,children:"Sign in again"}):void 0,children:"Its sign-in ran out or was refused. Until you reconnect, each of its tools answers with one sentence instead of running."}):null,e.state==="needs-review"?t.jsxs(G,{tone:"warning",action:t.jsx(A,{size:"sm",variant:"accent",onClick:f,children:"Review it"}),children:["It changed its tools since you reviewed them. The new and changed ones wait until you review it again",e.heldTools?` (${e.heldTools} of the ones you kept ${e.heldTools===1?"waits":"wait"})`:"","; the others keep working."]}):null,e.state==="unreachable"&&e.unreachableSince?t.jsx(G,{tone:"critical",children:u?`It stopped answering at ${ct(e.unreachableSince,r)}; the next call starts it again.`:`Unreachable since ${ct(e.unreachableSince,r)}, retrying.`}):null,u!=null&&u.changedSinceReview?t.jsx(G,{tone:"warning",children:"Its command changed since you reviewed it, so its tools wait until you review it again."}):null,e.phase==="starting"?t.jsx(G,{tone:"accent",role:"status",children:"Starting it… The first start can take a minute or two while it downloads."}):null,t.jsx("div",{className:"plugins-facts",children:t.jsx(qt,{items:[u?{label:"Command",value:t.jsx("span",{className:"connections-line",children:u.line})}:{label:"Address",value:t.jsx("span",{className:"connections-line",children:e.url})},...u?[{label:"Runs",value:"On this computer as you, with your PATH and only the variables you named. It stops after ten quiet minutes."}]:[],...u&&u.env.length>0?[{label:"Variables",value:t.jsx("span",{className:"mono",children:u.env.map(p=>`${p.name}${p.secret?" (secret)":""}`).join(", ")})}]:[],...u?[]:[{label:"Signs in with",value:Tq[e.authKind]}],{label:"Tools",value:c?"Not reviewed yet":`${Sw(e.toolCount,"tool","tools")}${e.reviewedAt?` · reviewed ${Ve(e.reviewedAt)}`:""}`},...c?[]:[{label:"Held by",value:t.jsxs("span",{className:"connections-holders",children:[t.jsx("span",{children:e.agents.length===0?"No agent holds these tools yet.":e.agents.map(s).join(", ")}),t.jsx(A,{size:"sm",onClick:l,"aria-label":"Change who holds it",children:e.agents.length===0?"Give them":"Change"})]})}]]})}),e.stderr&&e.stderr.length>0?t.jsx(ue,{title:"What the program last said",children:t.jsx(Dt,{label:"Its last lines on stderr",children:e.stderr.join(`
129
- `)})}):null,n&&!c?t.jsxs("div",{className:"connections-another",children:[t.jsxs("p",{children:["Another ",n.name," account or workspace? It connects beside this one, with its own sign-in and its own name. In the browser, sign in as that other account."]}),t.jsx(A,{size:"sm",onClick:()=>i({step:"address",card:n}),children:"Add another account"})]}):null]})}function Iq({connection:e,agents:n,onCancel:s,onDone:r}){const[a,i]=h.useState(()=>new Set(e.agents)),[l,o]=h.useState(!1),[c,u]=h.useState(null),d=(p,g)=>i(v=>{const b=new Set(v);return g?b.add(p):b.delete(p),b}),f=a.size===e.agents.length&&e.agents.every(p=>a.has(p)),m=async()=>{o(!0),u(null);try{const p=await R.grantConnection(e.id,[...a],!0);p.failed.length>0?u(p.failed.map(g=>`${g.agent}: ${g.message}`).join("; ")):r()}catch(p){u(hr(p))}finally{o(!1)}};return t.jsxs(zt,{title:`Who holds ${e.name}`,onClose:s,foot:t.jsxs(t.Fragment,{children:[t.jsx(A,{variant:"ghost",disabled:l,onClick:s,children:"Cancel"}),t.jsx(A,{variant:"accent",disabled:l||f,onClick:()=>void m(),children:"Save"})]}),children:[t.jsx("p",{className:"plugins-dialog-text",children:"Each agent you tick can use its tools; untick one to take them away. Approvals still ask as before."}),t.jsx("div",{className:"ui-stack","data-gap":"sm",role:"group","aria-label":"Agents",children:n.map(p=>t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:a.has(p.id),onChange:g=>d(p.id,g.target.checked)}),t.jsxs("span",{children:[p.name,p.frontDesk?" (front desk)":""]})]},p.id))}),t.jsx(ne,{message:c})]})}function Pq({connection:e,agentName:n,onCancel:s,onDone:r}){const[a,i]=h.useState(!1),[l,o]=h.useState(null),c=e.agents.map(n),u=async()=>{i(!0),o(null);try{await R.disconnect(e.id),r()}catch(d){o(hr(d))}finally{i(!1)}};return t.jsxs(zt,{title:`Disconnect ${e.name}?`,onClose:s,foot:t.jsxs(t.Fragment,{children:[t.jsx(A,{variant:"ghost",disabled:a,onClick:s,children:"Cancel"}),t.jsx(A,{variant:"danger",disabled:a,onClick:()=>void u(),children:"Disconnect"})]}),children:[t.jsxs("p",{className:"plugins-dialog-text",children:["buddi forgets its sign-in and its tools."," ",c.length>0?`${c.join(" and ")} ${c.length===1?"loses":"lose"} them.`:"No agent holds its tools."]}),t.jsx(ne,{message:l})]})}function Mq({onFlow:e}){const[n,s]=h.useState(Eq),r=qd.find(i=>i.value===n)??qd[0],a=i=>{s(i);try{window.localStorage.setItem(jI,i)}catch{}};return t.jsx(Ye,{title:"Add your own",actions:t.jsx(ln,{label:"How to add it",options:qd.map(({value:i,label:l})=>({value:i,label:l})),value:n,onChange:a}),children:t.jsxs("div",{className:"connections-add",children:[t.jsx("p",{className:"connections-add-text",children:r.text}),t.jsx(A,{variant:"accent",onClick:()=>e(n),children:r.button})]})})}function Dq({start:e,agents:n,catalog:s=[],tokens:r=!0,onClose:a,pollMs:i=2e3}){const[l,o]=h.useState(e.step),[c,u]=h.useState(e.connection),[d,f]=h.useState("unknown"),[m,p]=h.useState(null),[g,v]=h.useState(null),b=(m==null?void 0:m.url)??(c==null?void 0:c.url),j=e.card??s.find(w=>b!==void 0&&Ew(w.url,b)),x=(c==null?void 0:c.name)??(j==null?void 0:j.name)??(m==null?void 0:m.name)??"the service",y=l==="paste"?"Paste a config":l==="address"?"Connect a service":l==="program"?c?`Change ${c.name}`:"A program on this computer":l==="consent"?`Sign in to ${x}`:l==="review"?`What ${x} brings`:"Who gets these tools";return t.jsxs(Ge,{title:y,onClose:a,size:"wide",children:[l==="paste"?t.jsx(Oq,{onRead:w=>{w.kind==="program"?(v(w.program),o("program")):(p(w.config),o("address"))}}):null,l==="address"?t.jsx(Lq,{card:j,pasted:m,onDone:(w,k)=>{u(w),k==="none"?o("review"):(f(k),o("consent"))}}):null,l==="program"?t.jsx(Kq,{connection:c,pasted:g,tokens:r,onDone:w=>{var k;v(null),u(w),e.keepGrants&&!((k=w.program)!=null&&k.changedSinceReview)&&w.state!=="pending-review"?a():o("review")}}):null,l==="consent"&&c?t.jsx(zq,{connection:c,signIn:d,card:j,pasted:m==null?void 0:m.header,placeholder:(m==null?void 0:m.placeholder)??!1,tokens:r,pollMs:i,onSignedIn:w=>{p(null),u(w),e.keepGrants?a():o("review")}}):null,l==="review"&&c?t.jsx(Vq,{connection:c,onKept:w=>{u(w),e.keepGrants?a():o("grant")}}):null,l==="grant"&&c?t.jsx(Gq,{connection:c,agents:n,onDone:a}):null]})}function Ew(e,n){const s=r=>r.trim().replace(/\/+$/,"").toLowerCase();return s(e)===s(n)}function hr(e){return e instanceof Error?e.message:String(e)}function Oq({onRead:e}){const[n,s]=h.useState(""),[r,a]=h.useState(null),i=()=>{try{const l=bq(n);s(""),a(null),e(l)}catch(l){a(hr(l))}};return t.jsxs("form",{className:"ui-stack",onSubmit:l=>{l.preventDefault(),i()},children:[t.jsxs("p",{children:["Paste the block another app uses for this server, the one with ",t.jsx("span",{className:"mono",children:"mcpServers"}),", or the"," ",t.jsx("span",{className:"mono",children:"claude mcp add"})," line its docs print. A remote server gives its address, name and one header; a program its command, arguments and variables. Nothing is kept before you have read it on the next screen."]}),t.jsx(re,{label:"Config",hint:"A url for a remote server, or a command for a program on this computer.",children:t.jsx("textarea",{className:"mono",rows:8,required:!0,autoFocus:!0,spellCheck:!1,autoComplete:"off",value:n,placeholder:'{ "mcpServers": { "github": { "url": "…", "headers": { "Authorization": "Bearer …" } } } }',onChange:l=>s(l.target.value)})}),t.jsx(ne,{message:r}),t.jsx(te,{align:"end",children:t.jsx(A,{type:"submit",variant:"accent",disabled:n.trim()==="",children:"Read it"})})]})}function Lq({card:e,pasted:n,onDone:s}){var m,p;const[r,a]=h.useState((n==null?void 0:n.url)??(e==null?void 0:e.url)??""),[i,l]=h.useState(!1),[o,c]=h.useState(null),u=async()=>{l(!0),c(null);try{const g=await R.addConnection(r.trim(),(e==null?void 0:e.name)??(n==null?void 0:n.name));s(g.connection,g.signIn)}catch(g){c(hr(g))}finally{l(!1)}},d=((m=e==null?void 0:e.auth)==null?void 0:m.recommended)==="token",f=((p=e==null?void 0:e.auth)==null?void 0:p.recommended)==="device"&&e.auth.device!==void 0;return t.jsxs("form",{className:"ui-stack",onSubmit:g=>{g.preventDefault(),u()},children:[e?t.jsxs("p",{children:["buddi opens ",e.name,"’s server, reads its name and what it offers, and asks whether it wants you to sign in. Nothing else is sent."]}):t.jsx("p",{children:"Where is the server? buddi opens it, reads its name and what it offers, and nothing else until you have read its tools."}),t.jsx(re,{label:"Address",hint:"An https:// address. A server you start with npx, uvx or a local command is “A program on this computer” instead.",children:t.jsx("input",{required:!0,autoFocus:!e&&!n,spellCheck:!1,value:r,placeholder:"https://",onChange:g=>a(g.target.value)})}),e&&!e.verified?t.jsxs("p",{className:"ui-card-meta",children:["This address is the one ",e.name," published; buddi has not checked it since."]}):null,f?t.jsxs("p",{className:"ui-card-meta",children:[e.name," signs in with a code you type on its site. The next screen shows it."]}):d?t.jsxs("p",{className:"ui-card-meta",children:[e.name," signs in with a token you make on its site. The next screen links to the page."]}):e!=null&&e.clientIdRequired?t.jsxs("p",{className:"ui-card-meta",children:[e.name," does not let buddi register itself: signing in needs a token, or a client id from its developer settings."]}):null,n!=null&&n.header?t.jsx("p",{className:"ui-card-meta",children:n.placeholder?`Your config has a placeholder where the ${n.header.name} header's token goes. You paste the token itself on the next screen.`:`The ${n.header.name} header from your config waits for the sign-in screen. buddi tries it before it keeps it.`}):null,n&&n.dropped.length>0?t.jsxs("p",{className:"ui-card-meta",children:["buddi sends one header, so ",n.dropped.join(", ")," ",n.dropped.length===1?"was":"were"," left out."]}):null,t.jsx(ne,{message:o}),t.jsx(te,{align:"end",children:t.jsx(A,{type:"submit",variant:"accent",disabled:i||r.trim()==="",children:i?"Opening…":"Continue"})})]})}const Fq={device:"Device",oauth:"Sign in",token:"Token",client:"Client id"};function _q(e,n,s="none"){const r=e==="manual"?["token","client"]:["oauth","token"],a=n?r:r.filter(i=>i!=="token");return s==="first"?["device",...a]:s==="offered"?[...a.filter(i=>i!=="client"),"device",...a.filter(i=>i==="client")]:a}function zq({connection:e,signIn:n,card:s,pasted:r,placeholder:a,tokens:i,pollMs:l,onSignedIn:o}){var H,U;const[c,u]=h.useState(n),d=(H=s==null?void 0:s.auth)!=null&&H.device?s.auth.recommended==="device"?"first":"offered":"none",f=_q(c,i,d),m=r!==void 0||d!=="first"&&(e.authKind==="token"||((U=s==null?void 0:s.auth)==null?void 0:U.recommended)==="token"),[p,g]=h.useState(()=>m&&f.includes("token")?"token":f[0]),v=f.includes(p)?p:f[0],[b,j]=h.useState(Cq),[x,y]=h.useState(""),[w,k]=h.useState(null),[N,S]=h.useState(!1),[C,E]=h.useState(null),[T,I]=h.useState(!1),[F,D]=h.useState(null),$=`${location.origin}${Sq}`,L=h.useRef(o);L.current=o,h.useEffect(()=>{if(!T)return;let V=!1;const z=async()=>{if(!V){V=!0;try{L.current(await R.connection(e.id))}catch(pe){E(hr(pe))}}},X=typeof BroadcastChannel=="function"?new BroadcastChannel(gI):null;X&&(X.onmessage=pe=>{var oe;((oe=pe.data)==null?void 0:oe.id)===e.id&&z()});let K;const ee=Date.now(),ce=async()=>{if(!V){try{const pe=await R.connection(e.id);if((!e.signedIn||e.authKind==="token")&&pe.signedIn&&pe.authKind==="oauth"){z();return}}catch{}if(Date.now()-ee>10*6e4){I(!1),E("The sign-in did not come back within ten minutes. Start it again.");return}K=window.setTimeout(()=>void ce(),l)}};return K=window.setTimeout(()=>void ce(),l),()=>{V=!0,X==null||X.close(),window.clearTimeout(K)}},[T,e,l]);const O=async V=>{var z;S(!0),E(null);try{const{authorizeUrl:X}=await R.connectionConsent(e.id,V);k(X)}catch(X){X instanceof xe&&((z=X.detail)==null?void 0:z.code)==="client-id"?(j(X.message),u("manual"),g("client")):E(hr(X))}finally{S(!1)}};h.useEffect(()=>{v!=="oauth"||w!==null||O()},[v]);const M=V=>{const z=window.open(V,"_blank");z?(z.opener=null,D(null)):D(V),I(!0)},P=V=>{g(V),k(null),E(null),I(!1),D(null)};return t.jsxs("div",{className:"ui-stack",children:[f.length>1?t.jsx(ln,{label:"How to sign in",options:f.map(V=>({value:V,label:Fq[V]})),value:v,onChange:P}):null,v==="oauth"?t.jsxs(t.Fragment,{children:[t.jsxs("p",{children:["buddi opens ",e.name,"’s own sign-in page in a new tab. You say yes there, the tab comes back here, and buddi keeps the sign-in in its vault. No agent ever sees it."]}),N?t.jsxs(ve,{children:["Getting ",e.name,"’s sign-in page…"]}):null]}):null,v==="client"?t.jsxs(t.Fragment,{children:[t.jsx(G,{tone:"warning",children:b}),t.jsx(re,{label:"Client id",children:t.jsx("input",{required:!0,spellCheck:!1,value:x,onChange:V=>{y(V.target.value),k(null),I(!1)}})}),t.jsxs("p",{className:"ui-card-meta",children:["Its redirect address: ",t.jsx("span",{className:"mono",children:$})]})]}):null,v==="token"?t.jsx(Wq,{connection:e,card:s,pasted:r,placeholder:a,onSignedIn:o}):null,v==="device"?t.jsx(Bq,{connection:e,service:(s==null?void 0:s.name)??e.name,pollMs:l,onSignedIn:o}):null,(v==="oauth"||v==="client")&&T?t.jsxs(G,{tone:"accent",role:"status",children:["Waiting for you to say yes on ",e.name,"’s page…"]}):null,(v==="oauth"||v==="client")&&F?t.jsx("p",{children:t.jsxs("a",{href:F,target:"_blank",rel:"noopener noreferrer",children:["Open ",e.name,"’s sign-in page"]})}):null,v==="oauth"||v==="client"?t.jsx(ne,{message:C}):null,v==="oauth"?t.jsx(te,{align:"end",children:t.jsx(A,{variant:"accent",onClick:()=>{w&&M(w)},disabled:w===null,children:T?"Open it again":`Sign in to ${e.name}`})}):null,v==="client"?t.jsx(te,{align:"end",children:w===null?t.jsx(A,{variant:"accent",onClick:()=>void O(x.trim()),disabled:N||x.trim()==="",children:N?"Checking…":"Continue"}):t.jsx(A,{variant:"accent",onClick:()=>M(w),children:T?"Open it again":`Open ${e.name}’s sign-in page`})}):null]})}function Uq(e){try{const n=new URL(e);return`${n.host}${n.pathname==="/"?"":n.pathname.replace(/\/$/,"")}`}catch{return e}}function Bq({connection:e,service:n,pollMs:s,onSignedIn:r}){const[a,i]=h.useState(null),[l,o]=h.useState(null),[c,u]=h.useState(0),[d,f]=h.useState(null),m=h.useRef(r);m.current=r,h.useEffect(()=>{let v=!1,b;i(null),o(null),f(null);const j=async()=>{var x,y;if(!v){try{const w=await R.connection(e.id);if(v)return;if(((x=w.device)==null?void 0:x.state)==="done"){m.current(w);return}if(((y=w.device)==null?void 0:y.state)==="failed"){o(w.device.reason??"The sign-in did not finish. Start again.");return}}catch{}b=window.setTimeout(()=>void j(),s)}};return(async()=>{try{const x=await R.connectionDevice(e.id);if(v)return;i({userCode:x.userCode,verificationUri:x.verificationUri}),b=window.setTimeout(()=>void j(),s)}catch(x){v||o(hr(x))}})(),()=>{v=!0,window.clearTimeout(b)}},[e.id,s,c]);const p=v=>{const b=window.open(v,"_blank");b?(b.opener=null,f(null)):f(v)},g=a?Uq(a.verificationUri):"";return t.jsxs(t.Fragment,{children:[t.jsxs("p",{children:["Type this code on ",n,"’s site and say yes there. buddi keeps the sign-in in its vault and sends it only to"," ",t.jsx("span",{className:"mono",children:e.host}),". No agent ever sees it."]}),a===null&&l===null?t.jsxs(ve,{children:["Asking ",n," for a code…"]}):null,a&&l===null?t.jsxs(t.Fragment,{children:[t.jsx(Nw,{code:a.userCode,label:`Your code for ${n}`,large:!0}),t.jsxs(G,{tone:"accent",role:"status",children:["Waiting for you to approve on ",n,"…"]}),d?t.jsx("p",{children:t.jsxs("a",{href:d,target:"_blank",rel:"noopener noreferrer",children:["Open ",g]})}):null,t.jsx(te,{align:"end",children:t.jsxs(A,{variant:"accent",onClick:()=>p(a.verificationUri),children:["Open ",g]})})]}):null,l!==null?t.jsxs(t.Fragment,{children:[t.jsx(ne,{message:l}),t.jsx(te,{align:"end",children:t.jsx(A,{variant:"accent",onClick:()=>u(v=>v+1),children:"Start again"})})]}):null]})}function Wq({connection:e,card:n,pasted:s,placeholder:r,onSignedIn:a}){var j,x;const[i,l]=h.useState((s==null?void 0:s.value)??""),[o,c]=h.useState((s==null?void 0:s.name)??"Authorization"),[u,d]=h.useState((s==null?void 0:s.prefix)??(s?"":"Bearer ")),[f,m]=h.useState(!1),[p,g]=h.useState(null),v=async()=>{m(!0),g(null);try{const y=await R.connectionToken(e.id,{token:i.trim(),header:o.trim(),prefix:u});l(""),a(y.connection)}catch(y){g(hr(y))}finally{m(!1)}},b=(j=n==null?void 0:n.auth)==null?void 0:j.tokenPage;return t.jsxs("form",{className:"ui-stack",onSubmit:y=>{y.preventDefault(),v()},children:[t.jsxs("p",{children:[b?`Make a token on ${e.name}’s site and paste it here.`:`Paste a token ${e.name} gave you.`," buddi tries it on"," ",t.jsx("span",{className:"mono",children:e.host})," first, keeps it in its vault, and sends it only there. No agent ever sees it."]}),b?t.jsx("p",{children:t.jsxs("a",{href:b,target:"_blank",rel:"noopener noreferrer",children:["Make a token on ",e.name]})}):null,r?t.jsx(G,{tone:"accent",children:"Your config had a placeholder where the token goes. Paste the token itself."}):null,t.jsx(re,{label:"Token",hint:(x=n==null?void 0:n.auth)==null?void 0:x.tokenHint,children:t.jsx("input",{type:"password",required:!0,autoFocus:!(s!=null&&s.value),autoComplete:"off",spellCheck:!1,value:i,onChange:y=>l(y.target.value)})}),t.jsxs(Ns,{columns:2,dense:!0,children:[t.jsx(re,{label:"Header",hint:"Most services want Authorization.",children:t.jsx("input",{required:!0,spellCheck:!1,value:o,onChange:y=>c(y.target.value)})}),t.jsx(re,{label:"Before the token",hint:"Usually “Bearer ”, with its space. Empty for none.",children:t.jsx("input",{spellCheck:!1,value:u,onChange:y=>d(y.target.value)})})]}),t.jsx(ne,{message:p}),t.jsx(te,{align:"end",children:t.jsx(A,{type:"submit",variant:"accent",disabled:f||i.trim()===""||o.trim()==="",children:f?"Trying it…":"Try it and keep it"})})]})}function Hq(e){return e!==""&&/^[A-Za-z0-9_@%+=:,./-]+$/.test(e)?e:`'${e.replace(/'/g,"'\\''")}'`}function Kq({connection:e,pasted:n,tokens:s=!0,onDone:r}){const a=e==null?void 0:e.program,i=h.useRef(0),l=()=>(i.current+=1,i.current),[o,c]=h.useState((e==null?void 0:e.name)??(n==null?void 0:n.name)??""),[u,d]=h.useState((a==null?void 0:a.command)??(n==null?void 0:n.command)??""),[f,m]=h.useState(()=>((a==null?void 0:a.args)??(n==null?void 0:n.args)??[]).map($=>({key:l(),value:$}))),[p,g]=h.useState(()=>a?a.env.map($=>({key:l(),name:$.name,value:$.value??"",secret:$.secret,kept:$.secret})):((n==null?void 0:n.env)??[]).map($=>({key:l(),name:$.name,value:$.value,secret:$.secret,kept:!1}))),[v,b]=h.useState(!1),[j,x]=h.useState(null),y=/\s/.test(u.trim())?mI(u.trim()):[u.trim()],w=y[0]??"",k=[...y.slice(1),...f.map($=>$.value)],N=[w,...k].filter(($,L)=>L>0||$!==""),S=()=>{y.length<2||(d(w),m($=>[...y.slice(1).map(L=>({key:l(),value:L})),...$]))},C=N.map(Hq).join(" "),E=p.filter($=>$.secret&&$.value===""&&!$.kept).map($=>$.name||"a variable"),T=((n==null?void 0:n.env)??[]).filter($=>$.placeholder).map($=>$.name),I=($,L)=>m(O=>O.map(M=>M.key===$?{...M,value:L}:M)),F=($,L)=>g(O=>O.map(M=>M.key===$?{...M,...L}:M)),D=async()=>{b(!0),x(null);const $={name:o.trim(),command:w,args:k,env:p.filter(L=>L.name.trim()!=="").map(L=>({name:L.name.trim(),value:L.value,secret:L.secret}))};try{r(e?await R.updateProgram(e.id,$):(await R.addProgram($)).connection),g(L=>L.map(O=>O.secret?{...O,value:""}:O))}catch(L){x(hr(L))}finally{b(!1)}};return t.jsxs("form",{className:"ui-stack",onSubmit:$=>{$.preventDefault(),D()},children:[t.jsx("p",{children:"A server buddi starts itself on this computer, as you, when an agent needs it, and stops after ten quiet minutes. It runs with your PATH and only the variables you name here. The review screen is the first time it runs, only to list its tools."}),t.jsxs(Ns,{columns:2,children:[t.jsx(re,{label:"Name",children:t.jsx("input",{required:!0,autoFocus:!n&&!e,maxLength:80,spellCheck:!1,value:o,onChange:$=>c($.target.value)})}),t.jsx(re,{label:"Command",hint:"The program that starts the server: npx, uvx, node, or a full path. A whole line is split into it and its arguments.",children:t.jsx("input",{required:!0,spellCheck:!1,autoComplete:"off",className:"mono",value:u,placeholder:"npx",onChange:$=>d($.target.value),onBlur:S})})]}),t.jsx(re,{label:"Arguments",group:!0,hint:"One per row, exactly as the server's docs give them. No shell: quotes and $VARIABLES are passed as they are.",children:t.jsxs("div",{className:"ui-stack","data-gap":"sm",children:[f.map(($,L)=>t.jsxs("div",{className:"connections-row",children:[t.jsx("input",{"aria-label":`Argument ${L+1}`,className:"mono",spellCheck:!1,autoComplete:"off",value:$.value,onChange:O=>I($.key,O.target.value)}),t.jsx(A,{size:"sm",variant:"ghost",onClick:()=>m(O=>O.filter(M=>M.key!==$.key)),"aria-label":`Remove argument ${L+1}`,children:"Remove"})]},$.key)),t.jsx(te,{children:t.jsx(A,{size:"sm",onClick:()=>m($=>[...$,{key:l(),value:""}]),children:"Add an argument"})})]})}),t.jsx(re,{label:"Environment variables",group:!0,hint:"A secret is kept in buddi's vault and handed to the program only when it starts. Names with TOKEN, KEY, SECRET or PASSWORD start as secrets.",children:t.jsxs("div",{className:"ui-stack","data-gap":"sm",children:[p.map(($,L)=>t.jsxs("div",{className:"connections-row","data-kind":"env",children:[t.jsx("input",{"aria-label":`Variable ${L+1} name`,className:"mono",spellCheck:!1,autoComplete:"off",placeholder:"NAME",value:$.name,onChange:O=>{const M=O.target.value;F($.key,$.value===""&&!$.kept?{name:M,secret:dI(M)}:{name:M})}}),t.jsx("input",{"aria-label":`Variable ${L+1} value`,type:$.secret?"password":"text",spellCheck:!1,autoComplete:"off",placeholder:$.kept&&$.value===""?"Kept. Type to replace it.":"value",value:$.value,onChange:O=>F($.key,{value:O.target.value})}),t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:$.secret,onChange:O=>F($.key,{secret:O.target.checked,kept:O.target.checked&&$.kept})}),t.jsx("span",{children:"Secret"})]}),t.jsx(A,{size:"sm",variant:"ghost",onClick:()=>g(O=>O.filter(M=>M.key!==$.key)),"aria-label":`Remove variable ${L+1}`,children:"Remove"})]},$.key)),t.jsx(te,{children:t.jsx(A,{size:"sm",onClick:()=>g($=>[...$,{key:l(),name:"",value:"",secret:!1,kept:!1}]),children:"Add a variable"})})]})}),T.length>0?t.jsxs(G,{tone:"accent",children:["Your config had a placeholder for ",T.join(", "),". Type the value itself."]}):null,!s&&p.some($=>$.secret)?t.jsx(G,{tone:"warning",children:"This installation has no vault, so a secret cannot be kept. Turn the vault on first, or switch Secret off."}):null,t.jsx("p",{className:"ui-card-meta",children:"A server that signs you in through a browser opens it on this computer, so it needs a screen. On a machine without one, give it a token as a secret variable instead."}),t.jsxs("div",{className:"ui-stack","data-gap":"sm",children:[t.jsx("span",{className:"ui-field-label",children:"It will run"}),t.jsx(Dt,{label:"The command line",children:C||"…"})]}),t.jsx(ne,{message:j}),t.jsx(te,{align:"end",children:t.jsx(A,{type:"submit",variant:"accent",disabled:v||o.trim()===""||u.trim()===""||E.length>0,title:E.length>0?`Give ${E.join(", ")} a value.`:void 0,children:v?"Saving…":e?"Save":"Continue"})})]})}function Vq({connection:e,onKept:n}){const s=me(()=>R.connectionReview(e.id),[e.id]),[r,a]=h.useState(null),[i,l]=h.useState(!1),[o,c]=h.useState(null),u=s.data,d=r??(u==null?void 0:u.slug)??"",f=async()=>{var p;if(u){l(!0),c(null);try{n(await R.saveConnectionReview(e.id,{hash:u.hash,...u.slugEditable?{slug:d}:{}}))}catch(g){g instanceof xe&&((p=g.detail)==null?void 0:p.code)==="changed"&&s.reload(),c(hr(g))}finally{l(!1)}}};if(!u)return s.error?t.jsx(ne,{message:s.error}):e.transport==="stdio"?t.jsxs(ve,{children:["Starting ",e.name,"… The first start can take a minute or two while it downloads."]}):t.jsxs(ve,{children:["Reading what ",e.name," offers…"]});const m=u.tools.filter(p=>p.problem===null).length;return t.jsxs("div",{className:"ui-stack",children:[t.jsxs("p",{children:["Read what ",e.name," brings before it brings it. Each tool gets a buddi name and a tier from what the server says it does; anything that changes something asks you first, on the same approval card as every other tool."]}),u.program?t.jsx(G,{tone:"warning",title:"This runs on this computer as you",children:t.jsxs(ie,{gap:"sm",children:[t.jsx(Dt,{label:"The command",children:u.program.line}),t.jsx("p",{children:"It can read and change what you can, and reach the network. buddi starts it with only the variables below, stops it after ten quiet minutes, and asks you again if its command changes."}),u.program.env.length>0?t.jsxs("p",{className:"ui-card-meta",children:["Variables: ",u.program.env.map(p=>`${p.name}${p.secret?" (secret)":""}`).join(", ")]}):null]})}):t.jsxs("p",{className:"ui-card-meta",children:["buddi talks to ",t.jsx("span",{className:"mono",children:u.host})," for these tools, and nowhere else."]}),u.annotatedNothing?t.jsxs(G,{tone:"warning",children:[e.name," says nothing about what its tools do, so every one of them asks you first."]}):null,u.changes&&u.changes.added.length+u.changes.changed.length+u.changes.removed.length>0?t.jsxs(G,{tone:"warning",title:`${e.name} changed its tools since your last review.`,children:[t.jsxs("ul",{className:"connections-changes","aria-label":"What changed",children:[u.changes.added.length>0?t.jsxs("li",{children:["New: ",t.jsx("span",{className:"mono",children:u.changes.added.join(", ")})]}):null,u.changes.changed.length>0?t.jsxs("li",{children:["Changed: ",t.jsx("span",{className:"mono",children:u.changes.changed.join(", ")})]}):null,u.changes.removed.length>0?t.jsxs("li",{children:["Gone: ",t.jsx("span",{className:"mono",children:u.changes.removed.join(", ")})]}):null]}),t.jsx("p",{children:"Until you keep this list, the new and changed tools wait; the others keep working."})]}):null,u.slugEditable?t.jsx(re,{label:"Its name in buddi",hint:`Tools are called mcp.${d||"…"}.<tool>. Lower case, letters, digits, _ and -.`,children:t.jsx("input",{required:!0,spellCheck:!1,maxLength:24,value:d,onChange:p=>a(p.target.value.toLowerCase())})}):null,u.tools.length===0?t.jsxs(ve,{children:[e.name," lists no tools."]}):t.jsx("div",{className:"ui-list","aria-label":"Tools",children:u.tools.map(p=>{const g=Nq(p),v=u.slugEditable?p.fullName.replace(/^mcp\.[^.]+\./,`mcp.${d||u.slug}.`):p.fullName;return t.jsx("div",{className:"ui-list-row connections-tool",children:t.jsxs("div",{className:"ui-stack","data-gap":"sm",children:[t.jsxs("div",{className:"ui-card-head",children:[t.jsx("span",{className:"mono",children:v}),p.problem?t.jsx(Ee,{tone:"muted",children:"Cannot be used"}):t.jsx(Ee,{tone:g.tone,children:g.label}),p.change==="added"?t.jsx(Jl,{children:"New"}):p.change==="changed"?t.jsx(Jl,{children:"Changed"}):null]}),p.description?t.jsx("p",{className:"ui-card-meta",children:p.description}):null,!p.problem&&p.tier==="gated"?t.jsx("p",{className:"ui-card-meta",children:p.destructive?kq:"You can remember its approval for an agent when you give it the tools, or later on the agent’s Tools tab."}):null,p.problem?t.jsxs("p",{className:"ui-card-meta",children:["Left out: ",p.problem,"."]}):null]})},p.name)})}),t.jsx(ne,{message:o}),t.jsx(te,{align:"end",children:t.jsx(A,{variant:"accent",onClick:()=>void f(),disabled:i||u.slugEditable&&d.trim()==="",children:m===1?"Keep this tool":`Keep these ${m} tools`})})]})}function Gq({connection:e,agents:n,onDone:s}){var b;const r=n.find(j=>j.frontDesk)??n[0],[a,i]=h.useState(()=>new Set(r?[r.id]:[])),o=(((b=me(()=>R.connectionTools(e.id),[e.id]).data)==null?void 0:b.tools)??[]).filter(j=>j.tier==="gated"),[c,u]=h.useState(()=>new Set),[d,f]=h.useState(!1),[m,p]=h.useState(null),g=(j,x)=>{i(y=>{const w=new Set(y);return x?w.add(j):w.delete(j),w})},v=async()=>{f(!0),p(null);try{const j=await R.grantConnection(e.id,[...a]);if(j.failed.length>0){p(j.failed.map(x=>`${x.agent}: ${x.message}`).join(" "));return}for(const x of j.granted)for(const y of c)await R.setRememberedApproval(x,y,!0);s()}catch(j){p(hr(j))}finally{f(!1)}};return t.jsxs("div",{className:"ui-stack",children:[t.jsxs("p",{children:[r?`Give these tools to ${r.name}?`:"Which agents get these tools?"," Each one you tick gets ",t.jsx("span",{className:"mono",children:e.grant})," on its tools line."]}),t.jsx("div",{className:"ui-stack","data-gap":"sm",role:"group","aria-label":"Agents",children:n.map(j=>t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:a.has(j.id),onChange:x=>g(j.id,x.target.checked)}),t.jsxs("span",{children:[j.name,j.frontDesk?" (front desk)":""]})]},j.id))}),t.jsx("p",{className:"ui-card-meta",children:"No one is fine too: the connection waits here until you give it to someone."}),o.length>0?t.jsxs("div",{className:"ui-stack","data-gap":"sm",role:"group","aria-label":"Remembered approval",children:[t.jsx("p",{children:"These ask you first. Tick one to remember your approval for the agents above, so it asks only once."}),o.map(j=>t.jsxs(ie,{gap:"sm",children:[t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",disabled:!j.rememberable,checked:c.has(j.tool),onChange:x=>u(y=>{const w=new Set(y);return x.target.checked?w.add(j.tool):w.delete(j.tool),w})}),t.jsx("span",{className:"mono",children:j.tool})]}),j.why?t.jsx("p",{className:"ui-card-meta",children:j.why}):null]},j.tool))]}):null,t.jsx(ne,{message:m}),t.jsxs(te,{align:"end",children:[t.jsx(A,{onClick:s,disabled:d,children:"Not now"}),t.jsx(A,{variant:"accent",onClick:()=>void v(),disabled:d||a.size===0,children:"Give them"})]})]})}const qq=(e,n,s)=>`${e} ${e===1?n:s}`;function Yq(e){return e.state==="pending-review"||!e.slug?"Not finished: its tools are not reviewed yet.":e.state==="needs-review"?"Its tools changed and need your review.":e.state==="needs-reconnect"?"Its sign-in ended; sign in again first.":null}function Jq({agentId:e,agentName:n,readOnly:s,version:r,onSaved:a}){const[i,l]=h.useState({}),o=me(()=>R.connections().then(y=>(l({}),y)),[r]),[c,u]=h.useState(null),[d,f]=h.useState(null),m=Le("connections"),p=async(y,w)=>{u(y.id),f(null);try{const k=await R.setConnectionHolder(y.id,e,w);l(N=>({...N,[y.id]:k.held})),a==null||a()}catch(k){f(k instanceof Error?k.message:String(k))}finally{u(null)}},g=o.data,v=(g==null?void 0:g.connections)??[],b=y=>i[y.id]??y.agents.includes(e),j=g?g.agents.some(y=>y.id===e):!0,x=v.filter(b).length;return t.jsxs(ue,{title:"Connections",aside:g&&v.length>0?`holds ${x} of ${v.length} · saved as you change them`:void 0,panel:!0,children:[t.jsx(ne,{message:o.error??d}),g?v.length===0?t.jsxs("p",{className:"ui-card-meta",children:["Nothing is connected yet. ",t.jsx("a",{href:m,children:"Connect a service in Connections"})]}):j?t.jsxs(t.Fragment,{children:[s?t.jsx(G,{tone:"warning",children:"This agent ships with buddi, so its connections are read-only here. Ask Agent Father to make it yours, then it can change."}):null,t.jsx("ul",{className:"ui-list delegate-list","aria-label":`Connections ${n} holds`,children:v.map(y=>{const w=b(y),k=Yq(y),N=y.transport==="stdio"?"on this computer":y.host,S=y.slug?qq(y.toolCount,"tool","tools"):"tools not reviewed",C=`holds-${e}-${y.id}`;return t.jsxs("li",{className:"ui-list-row",children:[t.jsx("input",{type:"checkbox",role:"switch",id:C,checked:w,"aria-checked":w,disabled:s||c!==null||k!==null&&!w,onChange:E=>void p(y,E.target.checked)}),t.jsxs("label",{htmlFor:C,className:"ui-list-main",children:[t.jsxs("span",{className:"ui-list-title",children:[y.name,k?t.jsxs(t.Fragment,{children:[" ",t.jsx(Ee,{tone:"warning",children:pI(y).label})]}):null]}),t.jsx("span",{className:"ui-list-sub",children:`${N} · ${S}`}),k?t.jsxs("span",{className:"ui-list-sub",children:[k," ",t.jsx("a",{href:m,children:"Open Connections"})]}):null]})]},y.id)})})]}):t.jsxs("p",{className:"ui-card-meta",children:[n," makes and changes agents, so it holds no connections."]}):o.error?null:t.jsx(ve,{children:"Loading the connections…"})]})}const Qq=(e,n)=>!!e&&!!n&&e.kind===n.kind&&(e.kind==="mascot"?e.role===n.role:e.kind==="emoji"?e.value===n.value:!0);async function yI(e){const n=await fetch(Vi(e));if(!n.ok)throw new Error(`The picture could not be read (${n.status}).`);const s=await n.blob();return new File([s],`buddi-blob-${e}.png`,{type:"image/png"})}function Xq({face:e,onPick:n,label:s=_.assistant.face,kept:r,disabled:a,disableEmoji:i,children:l}){return t.jsxs("div",{className:"meet-faces",role:"group","aria-label":s,children:[t.jsxs("div",{className:"meet-face-row",children:[r?t.jsx("button",{type:"button",className:"meet-face","data-kind":"image","data-chosen":(e==null?void 0:e.kind)==="kept"?"true":void 0,"aria-pressed":(e==null?void 0:e.kind)==="kept","aria-label":"The current picture",disabled:a,onClick:()=>n({kind:"kept",url:r}),children:t.jsx("img",{src:r,alt:""})}):null,$U.map(o=>{const c={kind:"mascot",role:o},u=Qq(e,c);return t.jsx("button",{type:"button",className:"meet-face","data-kind":"image","data-chosen":u?"true":void 0,"aria-pressed":u,"aria-label":_.assistant.mascot(o),disabled:a,onClick:()=>n(c),children:t.jsx("img",{src:Vi(o),alt:""})},o)})]}),t.jsx("div",{className:"meet-face-row",children:RU.map(o=>{const c=(e==null?void 0:e.kind)==="emoji"&&e.value===o;return t.jsx("button",{type:"button",className:"meet-face","data-chosen":c?"true":void 0,"aria-pressed":c,disabled:a||i,onClick:()=>n({kind:"emoji",value:o}),children:o},o)})}),l]})}const Zq=["mirror","en","fr"],eY=[{value:"3h",label:"3 hours"},{value:"1d",label:"A day"},{value:"1w",label:"A week"},{value:"never",label:"Never"}],Hp=10,Kp=500,wI=[{id:"identity",label:"Identity"},{id:"brain",label:"Brain"},{id:"tools",label:"Tools"},{id:"team",label:"Team"}],XN=e=>{var n;return e==="access"?"tools":((n=wI.find(s=>s.id===e))==null?void 0:n.id)??"identity"};function tY({agentId:e,section:n,navigate:s}){var v,b,j;const{data:r,error:a,reload:i}=me(()=>R.agents(),[]),[l,o]=h.useState(null),[c,u]=h.useState(null),[d,f]=h.useState(XN(n));h.useEffect(()=>f(XN(n)),[n]);const m=x=>{f(x),s==null||s(Pt(e,"setup",x))},p=async x=>{o(null),u(null);try{const y=await x;u(y.changed.length===0?`No file change needed. ${y.note}.`:`Changed ${y.changed.join(", ")}. ${y.note}.`),i()}catch(y){o(y instanceof Error?y.message:String(y))}},g=r==null?void 0:r.agents.find(x=>x.id===e);return t.jsxs(ie,{gap:"lg",children:[t.jsx(yo,{level:"secondary",label:"Setup",children:wI.map(x=>t.jsx(Li,{href:Pt(e,"setup",x.id),active:d===x.id,onClick:y=>{y.preventDefault(),m(x.id)},children:x.label},x.id))}),t.jsx(ne,{message:a??l}),c?t.jsx(G,{tone:"good",role:"status",children:c}):null,r?g?t.jsx(nY,{agent:g,all:r.agents,engine:r.engines.find(x=>x.id===g.id),providers:r.providers,accounts:r.providerAccounts,shown:d,onShow:m,onRun:p,onSaved:i},`${g.id}:${(v=r.engines.find(x=>x.id===g.id))==null?void 0:v.model}:${(j=(b=r.providerAccounts)==null?void 0:b.bindings.find(x=>x.agentId===g.id))==null?void 0:j.accountId}`):t.jsx(ve,{children:"This agent is not installed as a file."}):t.jsx(ve,{children:"Loading…"})]})}function nY({agent:e,all:n,engine:s,providers:r,accounts:a,shown:i,onShow:l,onRun:o,onSaved:c}){const u=(s==null?void 0:s.provider)??e.provider.kind,d=r.find(N=>N.kind===u),f=(s==null?void 0:s.model)??e.model,[m,p]=h.useState(String((s==null?void 0:s.maxTurns)??e.maxTurns)),[g,v]=h.useState(null),b=N=>{o(R.setAgentEngine(e.id,N))},j=N=>{const S=r.find(C=>C.kind===N);b({provider:N,model:(S==null?void 0:S.defaultModel)??f})},x=(d==null?void 0:d.models.map(N=>N.id))??[],y=x.includes(f)?x:[f,...x],w=s?s.available:!0,k=(s==null?void 0:s.unavailableReason)??"no credential";return t.jsxs(t.Fragment,{children:[t.jsx("div",{hidden:i!=="identity",children:t.jsxs(ie,{gap:"lg",children:[w?null:t.jsxs(G,{tone:"warning",children:["This agent cannot run right now."," ",t.jsx("a",{href:Pt(e.id,"setup","brain"),onClick:N=>{N.preventDefault(),l("brain")},children:"See Brain."})]}),t.jsx(sY,{agent:e,onSaved:c})]})}),t.jsx("div",{hidden:i!=="brain",children:t.jsxs(ie,{gap:"lg",children:[w?null:t.jsxs(G,{tone:"warning",children:["This agent cannot run right now: ",k,"."]}),t.jsx(ue,{panel:!0,children:t.jsxs(ie,{divided:!0,children:[t.jsxs(ue,{title:"Runs on",children:[a?t.jsx(uY,{agentId:e.id,accounts:a,onRun:o}):t.jsxs(Ns,{children:[t.jsx(re,{label:"Provider",children:t.jsx("select",{value:u,onChange:N=>j(N.target.value),children:r.map(N=>t.jsxs("option",{value:N.kind,children:[N.kind,N.usable?"":" (no credential)"]},N.kind))})}),t.jsxs(re,{label:"Model",children:[t.jsx("input",{list:`models-${e.id}`,defaultValue:f,onBlur:N=>{N.target.value.trim()!==""&&N.target.value.trim()!==f&&b({model:N.target.value.trim()})}}),t.jsx("datalist",{id:`models-${e.id}`,children:y.map(N=>t.jsx("option",{value:N},N))})]})]}),a?null:t.jsxs("p",{className:"ui-card-meta",children:[(s==null?void 0:s.credentialKind)??e.provider.credentialKind," from"," ",t.jsx("span",{className:"mono",children:(s==null?void 0:s.credentialEnv)??e.provider.credentialEnv}),d&&!d.usable?` · default model ${d.defaultModel} (${d.defaultFrom})`:""]}),s!=null&&s.restartRequired?t.jsx("p",{className:"warning",children:"This file has changed since the service loaded it. Run `buddi service restart`."}):null]}),t.jsx(ue,{title:"Behaviour",aside:"saved as you change them",children:t.jsxs(Ns,{children:[t.jsx(re,{label:"Steps per reply",hint:`${s!=null&&s.maxTurnsIsDefault?`Default ${s.defaultMaxTurns??40}. `:""}Each tool call is a step; a reply that uses them all stops and offers Continue.`,after:g?t.jsx("span",{className:"critical save-error",role:"alert",children:g}):null,children:t.jsx("input",{type:"number",min:Hp,max:Kp,value:m,onChange:N=>{p(N.target.value),v(null)},onBlur:()=>{const N=Number(m);if(!Number.isInteger(N)||N<Hp||N>Kp){v(`Between ${Hp} and ${Kp}.`);return}N!==((s==null?void 0:s.maxTurns)??e.maxTurns)&&b({maxTurns:N})}})}),t.jsx(re,{label:"Language",hint:"Mirror answers in whatever language you write.",children:t.jsx("select",{value:(s==null?void 0:s.language)??e.language,onChange:N=>b({language:N.target.value}),children:Zq.map(N=>t.jsx("option",{value:N,children:N},N))})}),s?t.jsx(re,{label:"New chat after",hint:"Idle time before your next message starts a fresh conversation, with a carried-over note. A transcript that grows too long starts one either way.",children:t.jsx("select",{"aria-label":"New chat after",value:s.idleRollover??"3h",onChange:N=>b({idleRollover:N.target.value==="3h"?null:N.target.value}),children:eY.map(N=>t.jsx("option",{value:N.value,children:N.label},N.value))})}):null,sA(rA(s??{id:e.id,provider:u},a))?t.jsx(re,{label:"Thinking",hint:"Reasoning before the answer. Off is faster and cheaper.",children:t.jsxs("select",{"aria-label":"Thinking",value:(s==null?void 0:s.thinking)??"default",onChange:N=>b({thinking:N.target.value==="default"?null:N.target.value}),children:[t.jsx("option",{value:"default",children:"Model default"}),t.jsx("option",{value:"on",children:"On"}),t.jsx("option",{value:"off",children:"Off"})]})}):t.jsx(re,{label:"Thinking",hint:g_,children:t.jsx("span",{className:"ui-card-meta",children:"Up to the model"})})]})})]})}),t.jsx(Ot,{summary:"Built-in context",boxed:!0,children:t.jsx("p",{className:"ui-card-meta",children:"Every agent receives current time, owner timezone and server-host information. system.time and system.info are always available, without grants or approval. Host and browser access still require their own permissions."})})]})}),t.jsx("div",{hidden:i!=="tools",children:t.jsxs(ie,{gap:"lg",children:[t.jsx(rY,{agent:e,all:n,onSaved:c}),t.jsx(Jq,{agentId:e.id,agentName:e.name,readOnly:e.isExample===!0,version:e.tools.join(","),onSaved:c})]})}),t.jsx("div",{hidden:i!=="team",children:t.jsx(ie,{gap:"lg",children:t.jsx(mY,{agent:e,all:n,onSaved:c})})})]})}function bI({dirty:e,busy:n,failure:s,label:r,onSave:a}){return t.jsxs(t.Fragment,{children:[s?t.jsx("span",{className:"critical save-error",role:"alert",children:s}):t.jsx("span",{className:e?"warning":"muted",children:e?"Not saved yet.":"Saved. Applies to new runs."}),t.jsx("span",{className:"ui-toolbar-spacer"}),t.jsx(A,{variant:"accent",disabled:!e||n,onClick:a,children:r})]})}const kI=t.jsx(G,{tone:"warning",children:"This agent ships with buddi, so its file is read-only here. Ask Agent Father to make it yours, then these fields can change."});function sY({agent:e,onSaved:n}){var D;const[s,r]=h.useState(e.name),[a,i]=h.useState(e.handle),[l,o]=h.useState(e.description),[c,u]=h.useState(e.avatar??""),[d,f]=h.useState(!1),m=me(()=>R.agentFile(e.id),[e.id]),[p,g]=h.useState(null),v=((D=m.data)==null?void 0:D.persona.trim())??"",b=p??v,j=m.data!==void 0&&p!==null&&p.trim()!==v,[x,y]=h.useState(!1),[w,k]=h.useState(null),[N,S]=h.useState(null),C=s.trim()!==e.name||a.trim().replace(/^@/,"")!==e.handle||l.trim()!==e.description||c.trim()!==(e.avatar??"")||j,E=c.trim()!==""&&(c.trim()!==(e.avatar??"")||!e.picture),T=bv(E?{...e,avatar:c.trim()}:e),I={...T?{avatar:T}:{},...e.accent?{accent:e.accent}:{},roles:e.roles,tools:e.tools,...!E&&e.picture?{picture:e.picture}:{}},F=async()=>{y(!0),k(null),S(null);try{const $=await R.updateAgentFile(e.id,{name:s.trim(),handle:a.trim().replace(/^@/,""),description:l.trim(),...c.trim()===""?{}:{avatar:c.trim()},...j&&b.trim()!==""?{persona:b.trim()}:{}});e.picture&&c.trim()!==""&&c.trim()!==(e.avatar??"")&&(await R.removeAgentPicture(e.id),window.dispatchEvent(new Event(Dr))),g(null),m.reload(),S($.message),n()}catch($){k($ instanceof Error?$.message:String($))}finally{y(!1)}};return t.jsx(ue,{title:"Who it is",aside:t.jsx("span",{className:"mono",children:e.id}),panel:!0,foot:e.isExample?void 0:t.jsx(bI,{dirty:C,busy:x,failure:w,label:"Save who it is",onSave:()=>void F()}),children:t.jsxs(ie,{children:[e.isExample?kI:null,N?t.jsx(G,{tone:"good",role:"status",children:N}):null,t.jsxs(Ns,{children:[t.jsx(re,{label:"Name",hint:"What it is called, everywhere.",children:t.jsx("input",{value:s,disabled:x||e.isExample,onChange:$=>r($.target.value)})}),t.jsx(re,{label:"Handle",hint:"What you type to reach it. One handle, one agent.",children:t.jsx("input",{value:a,disabled:x||e.isExample,onChange:$=>i($.target.value)})})]}),t.jsxs(te,{children:[t.jsx(Nn,{id:e.id,name:s.trim()||e.name,size:"xl",face:I}),t.jsx(A,{"aria-expanded":d,onClick:()=>f($=>!$),children:d?"Hide faces":"Change face"})]}),d?t.jsx(oY,{agent:e,avatar:c,onEmoji:u,onChanged:n,disabled:x}):null,t.jsx(re,{label:"Description",hint:"One or two sentences. Its colleagues read this.",children:t.jsx("textarea",{rows:2,value:l,disabled:x||e.isExample,onChange:$=>o($.target.value)})}),t.jsx(re,{label:"Persona",hint:t.jsxs(t.Fragment,{children:["Who it is and how it works, in its own file. It reads this before every conversation; ",t.jsx("code",{children:"{{today}}"})," is filled in with the date at run time."]}),wide:!0,children:m.error?t.jsx(ne,{message:m.error}):m.data?t.jsx("textarea",{className:"setup-persona",value:b,rows:Math.max(6,b.split(`
130
- `).length+1),disabled:x||e.isExample,onChange:$=>g($.target.value)}):t.jsx(ve,{children:"Reading its file…"})})]})})}function rY({agent:e,all:n,onSaved:s}){var E;const r=me(()=>R.agentTools(e.id),[e.id,e.tools.join(",")]),[a,i]=h.useState(null),[l,o]=h.useState(()=>new Set((e.roles??[]).filter(c0))),[c,u]=h.useState((e.roles??[]).filter(T=>!c0(T)).join(", ")),[d,f]=h.useState(!1),[m,p]=h.useState(null),[g,v]=h.useState(null),b=(T,I)=>T.split(I).map(F=>F.trim()).filter(F=>F!==""),j=((E=r.data)==null?void 0:E.granted)??e.tools,x=a??j,y=r.data!==void 0&&!gq(x,j),w=u0(l,b(c,/[\n,]/)),k=T=>o(I=>{const F=new Set(I);return F.has(T)?F.delete(T):F.add(T),F}),S=y||!((T,I)=>T.join(",")===I.join(","))(w,u0(new Set(e.roles??[]),e.roles??[])),C=async()=>{f(!0),p(null),v(null);try{const T=await R.updateAgentFile(e.id,{...y&&r.data?{tools:pq(r.data.groups,x)}:{},roles:w});v(T.message),i(null),r.reload(),s()}catch(T){p(T instanceof Error?T.message:String(T))}finally{f(!1)}};return t.jsx(ue,{title:"Roles and tools",panel:!0,foot:e.isExample?void 0:t.jsx(bI,{dirty:S,busy:d,failure:m,label:"Save roles and tools",onSave:()=>void C()}),children:t.jsxs(ie,{children:[e.isExample?kI:null,g?t.jsx(G,{tone:"good",role:"status",children:g}):null,t.jsxs("div",{className:"ui-field",children:[t.jsx("span",{className:"ui-field-label",id:`roles-${e.id}`,children:"Roles"}),t.jsx("div",{className:"role-chips",role:"group","aria-labelledby":`roles-${e.id}`,children:wy.map(T=>{const I=A3(n,T.id),F=I&&I.id!==e.id?I:void 0;return t.jsxs("button",{type:"button",className:"role-chip","aria-pressed":l.has(T.id),"data-on":l.has(T.id)?"true":void 0,disabled:d||e.isExample,onClick:()=>k(T.id),children:[t.jsx("span",{className:"role-chip-label",children:T.label}),t.jsx("span",{className:"role-chip-meaning",children:T.meaning}),F?t.jsxs("span",{className:"role-chip-holder",children:["Held by ",F.name,". If both claim it, the one listed first keeps it."]}):null]},T.id)})}),t.jsx("span",{className:"ui-field-hint",children:"Where buddi sends things when you do not say who. Tools are granted below."})]}),t.jsx(re,{label:"Other roles",hint:"Only a plugin that asks for a role by name reads these. Comma separated.",children:t.jsx("input",{value:c,disabled:d||e.isExample,onChange:T=>u(T.target.value)})}),t.jsxs("div",{className:"ui-field",children:[t.jsxs("span",{className:"ui-field-label",children:["Tools · ",j.length," granted"]}),r.error?t.jsx(ne,{message:r.error}):r.data?t.jsx(vq,{view:r.data,chosen:x,onChange:i,disabled:d||e.isExample}):t.jsx(ve,{children:"Loading the installed tools…"})]}),t.jsx(aY,{agentId:e.id,version:j.join(","),disabled:d||e.isExample}),iY(j)?t.jsx(lY,{agentId:e.id}):null]})})}function aY({agentId:e,version:n,disabled:s}){var g;const r=me(()=>Promise.resolve().then(()=>R.rememberedApprovals(e)),[e,n]),a=me(()=>Promise.resolve().then(()=>R.connections()).catch(()=>null),[]),[i,l]=h.useState(null),[o,c]=h.useState(null),u=((g=r.data)==null?void 0:g.tools)??[];if(u.length===0)return null;const d=async(v,b)=>{l(v),c(null);try{await R.setRememberedApproval(e,v,b),r.reload()}catch(j){c(j instanceof Error?j.message:String(j))}finally{l(null)}},f=new Map;for(const v of u)f.set(v.connection,[...f.get(v.connection)??[],v]);const m=v=>{var b,j;return((j=(b=a.data)==null?void 0:b.connections.find(x=>x.slug===v))==null?void 0:j.name)??v},p=v=>v.tool.split(".").slice(2).join(".")||v.tool;return t.jsxs("div",{className:"ui-field",children:[t.jsx("span",{className:"ui-field-label",children:"Connection tools that ask first"}),t.jsx("div",{className:"ui-stack","data-gap":"sm",role:"group","aria-label":"Remembered approvals",children:[...f].map(([v,b])=>{const j=b.filter(k=>k.rememberable),x=b.filter(k=>!k.rememberable),y=j.filter(k=>k.remembered),w=t.jsxs("span",{className:"remembered-summary",children:[t.jsx("span",{className:"remembered-name",children:m(v)}),t.jsxs("span",{className:"ui-card-meta",children:[` · ${b.length} ask first`,y.length>0?` · ${y.length} remembered: ${y.map(p).join(", ")}`:""]})]});return t.jsxs(Ot,{summary:w,boxed:!0,children:[t.jsx("div",{className:"ui-stack","data-gap":"sm",role:"group","aria-label":`${m(v)}: remember my approval`,children:j.map(k=>t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:k.remembered,disabled:s||i!==null,onChange:N=>void d(k.tool,N.target.checked),"aria-label":`Remember my approval for ${k.tool}`}),t.jsx("span",{className:"mono",children:p(k)})]},k.tool))}),x.length>0?t.jsxs("p",{className:"ui-card-meta remembered-always",children:["These can delete or destroy something, so they always ask and are never remembered:"," ",t.jsx("span",{className:"mono",children:x.map(p).join(", ")})]}):null]},v)})}),t.jsx(ne,{message:o}),t.jsx("span",{className:"ui-field-hint",children:"Tick a tool to remember your approval: it asks once, then runs for this agent."})]})}function iY(e){return e.some(n=>n==="owner.notify"||n==="owner.*"||n==="owner.notify?"||n==="owner.*?")}function lY({agentId:e}){var d,f;const n=me(()=>R.notificationSettings(),[]),[s,r]=h.useState(null),[a,i]=h.useState(!1),[l,o]=h.useState(null),c=s??((f=(d=n.data)==null?void 0:d.settings.agents)==null?void 0:f.muted.includes(e))??!1,u=m=>{i(!0),o(null),r(m),R.setAgentMuted(e,m).then(p=>r(p.agents.muted.includes(e))).catch(p=>{r(!m),o(p instanceof Error?p.message:String(p))}).finally(()=>i(!1))};return t.jsxs("div",{className:"ui-field",children:[t.jsx("span",{className:"ui-field-label",children:"Messages to you"}),t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:c,disabled:a||!n.data,onChange:m=>u(m.target.checked),"aria-label":"Mute this agent's messages"}),t.jsx("span",{children:"Mute its messages"})]}),t.jsx(ne,{message:n.error??l}),t.jsx("span",{className:"ui-field-hint",children:"With owner.notify it can message you itself; muted, it is refused and told so."})]})}function bv(e){if(e.avatar)return/^[A-Za-z0-9_-]+\.(png|jpe?g|gif|webp)$/i.test(e.avatar)?{kind:"image",url:`/api/agents/${encodeURIComponent(e.id)}/avatar`}:{kind:"emoji",value:e.avatar.slice(0,8)}}function oY({agent:e,avatar:n,onEmoji:s,onChanged:r,disabled:a}){const[i,l]=h.useState(null),[o,c]=h.useState(!1),[u,d]=h.useState(null),f=n.trim()!==""&&(n.trim()!==(e.avatar??"")||!e.picture),m=i??(f?{kind:"emoji",value:n.trim()}:e.picture?{kind:"kept",url:e.picture}:null),p=async g=>{if(d(null),g.kind==="emoji"){s(g.value);return}if(g.kind==="kept"){s(e.avatar??"");return}l(g),c(!0);try{await R.uploadAgentPicture(e.id,await yI(g.role)),s(e.avatar??""),r(),window.dispatchEvent(new Event(Dr))}catch(v){d(v instanceof Error?v.message:String(v))}finally{l(null),c(!1)}};return t.jsxs("div",{className:"ui-field",children:[t.jsx("span",{className:"ui-field-label",children:"Face"}),t.jsx(Xq,{face:m,label:"Face",kept:e.picture,disabled:a||o,disableEmoji:e.isExample,onPick:g=>void p(g),children:t.jsx(cY,{agent:e,onChanged:r})}),u?t.jsx("span",{className:"critical save-error",role:"alert",children:u}):null]})}function cY({agent:e,onChanged:n}){const[s,r]=h.useState(null),[a,i]=h.useState(null),[l,o]=h.useState(!1),[c,u]=h.useState(null),[d,f]=h.useState(null),[m,p]=h.useState(0);h.useEffect(()=>{if(!s)return i(null);const S=URL.createObjectURL(s);return i(S),()=>URL.revokeObjectURL(S)},[s]);const g=S=>{r(null),p(C=>C+1),f(S),n(),window.dispatchEvent(new Event(Dr))},v=async S=>{o(!0),u(null),f(null);try{g(await S())}catch(C){u(C instanceof Error?C.message:String(C))}finally{o(!1)}},b=()=>v(async()=>(await R.uploadAgentPicture(e.id,s)).note??null),j=()=>v(async()=>(await R.removeAgentPicture(e.id),null)),x={avatar:bv(e),...e.accent?{accent:e.accent}:{},roles:e.roles,tools:e.tools,...a??e.picture?{picture:a??e.picture}:{}},[y,w]=h.useState(!1),k=h.useRef(null),N=S=>{u(null),f(null),r(S??null)};return t.jsxs("div",{className:"setup-upload","data-dragging":y?"true":void 0,onDragOver:S=>{S.preventDefault(),l||w(!0)},onDragLeave:()=>w(!1),onDrop:S=>{var C;S.preventDefault(),w(!1),l||N((C=S.dataTransfer.files)==null?void 0:C[0])},children:[t.jsxs(te,{children:[t.jsx(Nn,{id:e.id,name:e.name,size:"xl",face:x}),t.jsx("input",{ref:k,className:"sr-only",type:"file","aria-label":"Choose a picture",accept:"image/png,image/gif,image/svg+xml,.png,.gif,.svg",disabled:l,onChange:S=>{var C;return N((C=S.target.files)==null?void 0:C[0])}},m),t.jsx(A,{disabled:l,onClick:()=>{var S;return(S=k.current)==null?void 0:S.click()},children:"Upload a picture"}),t.jsx("span",{className:"setup-upload-name",children:s?s.name:"or drop one here"}),t.jsx("span",{className:"ui-toolbar-spacer"}),e.picture&&!s?t.jsx(A,{variant:"ghost",disabled:l,onClick:()=>void j(),children:"Remove picture"}):null,t.jsx(A,{variant:"accent",disabled:!s||l,onClick:()=>void b(),children:"Save picture"})]}),c?t.jsx("span",{className:"critical save-error",role:"alert",children:c}):t.jsx("span",{className:"ui-field-hint",children:d??"Your own picture: a PNG, GIF or SVG up to 1 MB, kept as a square PNG; a GIF keeps its first frame."})]})}function uY({agentId:e,accounts:n,onRun:s}){const r=n.bindings.find(p=>p.agentId===e),[a,i]=h.useState((r==null?void 0:r.accountId)??""),[l,o]=h.useState((r==null?void 0:r.model)??""),[c,u]=h.useState(!1),d=n.accounts.find(p=>p.id===a),f=a!==((r==null?void 0:r.accountId)??"")||l!==((r==null?void 0:r.model)??""),m=n.accounts.find(p=>p.id===(r==null?void 0:r.accountId));return t.jsxs("div",{className:"ui-stack",children:[t.jsxs(te,{valign:"end",children:[t.jsx(re,{label:"Account",children:t.jsxs("select",{value:a,disabled:c,onChange:p=>{var g;i(p.target.value),o(((g=n.accounts.find(v=>v.id===p.target.value))==null?void 0:g.defaultModel)??"")},children:[t.jsx("option",{value:"",children:"Choose an account"}),n.accounts.map(p=>t.jsxs("option",{value:p.id,disabled:!p.enabled,children:[p.label,p.enabled?p.configured?"":" (needs credential)":" (disabled)"]},p.id))]})}),t.jsx(kw,{accountId:d!=null&&d.configured?a:void 0,label:"Model",value:l,onChange:o,disabled:c},`${a}:${d==null?void 0:d.revision}`)]}),t.jsxs(te,{children:[f&&a&&l.trim()?t.jsxs("span",{className:"warning",children:["Not saved yet. New runs still use ",m?`${m.label}, ${(r==null?void 0:r.model)??""}`:"nothing","."]}):t.jsx("span",{className:"muted",children:m?`Running on ${m.label} with ${(r==null?void 0:r.model)??"no model"}.`:"No account chosen yet: this agent cannot run until you save one."}),t.jsx("span",{className:"ui-toolbar-spacer"}),t.jsx(A,{variant:"accent",disabled:c||!a||!l.trim()||!f,onClick:()=>{u(!0),s(R.assignProviderAccount(e,a,l).finally(()=>u(!1)))},children:"Save account selection"})]})]})}const dY=["platform.create_agent","platform.update_agent","platform.write_skill","platform.delete_agent","platform.accept_plugin_agent","platform.accept_plugin_skill"],Vp=e=>e.tools.some(n=>dY.includes(n)),hY=["front-desk","maker"],fY={"front-desk":"Can ask: everyone, as the front desk",maker:"Can ask: everyone, as the maker",list:"Can ask: everyone"};function mY({agent:e,all:n,onSaved:s}){const[r,a]=h.useState(e.delegates),[i,l]=h.useState(!1),[o,c]=h.useState(null),[u,d]=h.useState(!1),[f,m]=h.useState(e.delegates),[p,g]=h.useState(e.asksEveryone),[v,b]=h.useState(!1),j=n.filter(T=>T.id!==e.id),x=hY.find(T=>{var I;return(I=e.roles)==null?void 0:I.includes(T)}),y=p===void 0||v,w=v||[...r].sort().join(",")!==[...f].sort().join(","),k=n.filter(T=>T.id!==e.id&&(T.delegates.includes(e.id)||T.asksEveryone!==void 0&&!Vp(e))),N=T=>a(I=>I.includes(T)?I.filter(F=>F!==T):[...I,T]),S=async T=>{l(!0),c(null),d(!1);try{const I=await R.setDelegates(e.id,T);m(I.delegates),a(I.delegates),g(I.asksEveryone),b(!1),d(!0),s()}catch(I){c(I instanceof Error?I.message:String(I))}finally{l(!1)}},C=()=>{a(j.filter(T=>!Vp(T)).map(T=>T.id)),b(!0),d(!1)},E=w?"Not saved yet.":u?"Saved. Applies to the next run.":y?r.length===0?"Asks nobody.":`May ask ${r.length} agent${r.length===1?"":"s"}.`:"Asks everyone.";return t.jsx(ue,{title:"Delegation",aside:e.tools.includes("agent.delegate")?"holds agent.delegate":"no agent.delegate tool: it cannot ask anyone until granted",panel:!0,foot:e.isExample?void 0:t.jsxs(t.Fragment,{children:[t.jsx("span",{className:w?"warning":"muted",children:E}),t.jsx("span",{className:"ui-toolbar-spacer"}),y&&x!==void 0?t.jsx(A,{disabled:i,onClick:()=>void S(["*"]),children:"Let it ask everyone"}):null,y?t.jsx(A,{variant:"accent",disabled:!w||i,onClick:()=>void S(r),children:"Save who it can ask"}):t.jsx(A,{variant:"accent",disabled:i,onClick:C,children:"Limit to…"})]}),children:t.jsxs(ie,{divided:!0,children:[t.jsxs(ue,{title:"Can ask",children:[e.isExample?t.jsx(G,{tone:"warning",children:"This agent ships with buddi, so its allowlist is read-only here. Ask Agent Father to make it yours, then it can change."}):null,t.jsx(ne,{message:o}),y?j.length===0?t.jsx(ve,{children:"Nobody else is installed."}):t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"ui-card-meta",children:"Only the agents ticked here. New teammates must be added here before it can ask them."}),t.jsx("ul",{className:"ui-list delegate-list","aria-label":"Agents this one may ask",children:j.map(T=>{const I=Vp(T);return t.jsxs("li",{className:"ui-list-row",children:[t.jsx("input",{type:"checkbox",id:`can-ask-${e.id}-${T.id}`,checked:r.includes(T.id),disabled:I||e.isExample||i,onChange:()=>N(T.id)}),t.jsxs("label",{htmlFor:`can-ask-${e.id}-${T.id}`,className:"ui-list-main",children:[t.jsxs("span",{className:"ui-list-title",children:[T.name," ",t.jsxs("span",{className:"mono muted",children:["@",T.handle]})]}),t.jsx("span",{className:"ui-list-sub",children:I?"Makes and changes agents. Never reachable by delegation.":T.description})]})]},T.id)})})]}):t.jsxs("p",{className:"ui-card-meta",children:[fY[p??"list"],". New agents are included without being added here; agents that make and change agents are never reachable by delegation."]})]}),t.jsx(ue,{title:"Asked by",children:k.length===0?t.jsxs("p",{className:"ui-card-meta",children:["No other agent may hand work to ",e.name,"."]}):t.jsx(b6,{children:k.map(T=>t.jsx(Ee,{children:T.name},T.id))})})]})})}const pY=[{id:"team",label:"Team"},{id:"missions",label:"Missions"},{id:"offers",label:"Offers"},{id:"reminders",label:"Reminders"},{id:"skills",label:"Skills"}],gY=[{id:"conversations",label:"Conversations"},{id:"missions",label:"Missions"},{id:"offers",label:"Offers"},{id:"reminders",label:"Reminders"},{id:"memory",label:"Memory"},{id:"skills",label:"Skills"},{id:"setup",label:"Setup"}];function xY(e){const n=c3(e.hash);return n?t.jsx(EG,{name:n.name,agents:e.agents,navigate:e.navigate,pluginPages:e.pluginPages}):t.jsx(vY,{...e})}function vY({hash:e,timezone:n,navigate:s,agents:r,attention:a,defaultAgentId:i}){var j,x,y,w,k;const l=i3(e),o=((j=/[?&]tab=([a-z]+)/.exec(e))==null?void 0:j[1])??"team",c=N=>S=>{S.preventDefault(),s(N)},u=me(()=>R.agents(),[]),d=am(),f=me(()=>R.offers(),[],2e4),m=LT(),p=(((x=f.data)==null?void 0:x.offers.length)??0)+m.offers.length,g=((w=(y=u.data)==null?void 0:y.default)==null?void 0:w.defaultAgentId)??i??null,[v,b]=h.useState(null);return t.jsxs("div",{className:"ui-page",children:[t.jsx(Ql,{title:"Agents",lede:o==="skills"?`Skills are short texts an agent follows for one kind of task. Each is a file on ${d}, or a folder when scripts and files come with it.`:`Your team. Each one is a file on ${d} — what it can reach is listed on its page.`,actions:o==="skills"?t.jsxs(t.Fragment,{children:[t.jsx(A,{onClick:()=>b({kind:"upload",at:Date.now()}),children:"Upload"}),t.jsx(A,{variant:"accent",onClick:()=>b({kind:"write",at:Date.now()}),children:"Write a skill"})]}):t.jsx(ht,{variant:"accent",href:sn(),onClick:c(sn()),children:"Add a teammate"})}),t.jsx(yo,{children:pY.map(N=>t.jsx(Li,{href:N.id==="team"?vt:`${vt}?tab=${N.id}`,active:o===N.id,count:N.id==="offers"?p:void 0,onClick:c(N.id==="team"?vt:`${vt}?tab=${N.id}`),children:N.label},N.id))}),o==="missions"?t.jsx(_R,{timezone:n,embedded:!0}):null,o==="offers"?t.jsx(FT,{offers:m.offers,reload:m.reload}):null,o==="offers"?t.jsx(UR,{embedded:!0}):null,o==="reminders"?t.jsx(iI,{timezone:n,embedded:!0}):null,o==="skills"?t.jsx(nq,{faces:r,navigate:s,command:v,openSkill:j8(e),openFile:v8(e)}):null,o==="team"?t.jsx(jY,{data:u.data,error:u.error,reload:u.reload}):null,o==="team"?r.length===0?t.jsx(Jn,{icon:"agents",title:"No agents yet",children:"Each agent is a file in the installation's agents folder."}):t.jsx("div",{className:"agents-grid",children:h$(r,g).map(N=>{const S=qf(a.get(N.id));return t.jsxs("div",{className:"ui-card agent-card","data-interactive":"true",...Oi(jo(N)),"data-unavailable":N.available?void 0:"true",children:[t.jsx("div",{className:"agent-card-top"}),t.jsx("div",{className:"agent-card-face",children:t.jsx(Nn,{id:N.id,name:N.name,size:"xl",unavailable:!N.available,face:N})}),t.jsxs("div",{children:[t.jsxs("div",{className:"ui-card-title",children:[t.jsx("a",{className:"agent-card-link",href:Pt(N.id,"conversations"),onClick:c(Pt(N.id,"conversations")),children:N.name}),t.jsxs("span",{className:"agent-card-handle mono faint",children:["@",N.handle]})]}),t.jsx("p",{className:"ui-card-meta agent-card-desc",children:N.description})]}),t.jsxs("div",{className:"ui-row",children:[N.id===g?t.jsx(Jl,{children:"front desk"}):null,S?t.jsx(Ee,{tone:"critical",dot:!0,children:"waiting for you"}):N.available?t.jsx(Ee,{tone:"good",dot:!0,children:"ready"}):t.jsx(Ee,{tone:"warning",children:cr(N.unavailableReason??"cannot run",60)}),t.jsx(Ee,{mono:!0,children:N.model}),t.jsx(ht,{className:"agent-card-talk",size:"sm",href:Ze(N.id),onClick:c(Ze(N.id)),"aria-label":`Talk to ${N.name}`,children:"Talk"})]})]},N.id)})}):null,l?t.jsx(Ge,{title:((k=r.find(N=>N.id===l.agentId))==null?void 0:k.name)??l.agentId,size:"wide",onClose:()=>s(vt),children:t.jsx(yY,{agentId:l.agentId,agent:r.find(N=>N.id===l.agentId),agents:r,tab:l.tab??"conversations",...l.section?{section:l.section}:{},timezone:n,navigate:s,attention:a})}):null]})}function jY({data:e,error:n,reload:s}){const r=e==null?void 0:e.default,[a,i]=h.useState(null),[l,o]=h.useState(!1),[c,u]=h.useState(null),[d,f]=h.useState(null);if(n)return t.jsx(ne,{message:n});if(!r||r.choices.length===0)return null;const m=r.defaultAgentId,p=a??m??"",g=p!==""&&p!==m,v=r.problem,b=x=>x.map(y=>{var w;return((w=r.choices.find(k=>k.id===y))==null?void 0:w.name)??y}).join(" and "),j=async()=>{o(!0),u(null),f(null);try{const x=await R.setDefaultAgent(p);f(x.note),i(null),s()}catch(x){u(x instanceof Error?x.message:String(x))}finally{o(!1)}};return t.jsx(Ye,{children:t.jsxs("div",{className:"ui-stack",children:[t.jsx(ne,{message:c}),(v==null?void 0:v.code)==="multiple-defaults"?t.jsx(G,{tone:"warning",role:"status",children:`Two agents claim default in their files: ${b(v.agents)}. The one chosen here wins.`}):(v==null?void 0:v.code)==="no-default-agent"?t.jsx(G,{tone:"warning",role:"status",children:"No agent file claims the default and this installation has not recorded one. Choose who answers when you name nobody."}):null,d?t.jsx(G,{tone:"good",role:"status",children:d}):null,t.jsxs(te,{children:[t.jsxs("div",{className:"default-agent-text",children:[t.jsx("h3",{className:"default-agent-title",children:"Default agent"}),t.jsx("span",{className:"ui-field-hint",children:"Where a chat that names nobody lands."})]}),t.jsx("span",{className:"ui-toolbar-spacer"}),t.jsxs("select",{"aria-label":"Default agent",value:p,disabled:l,onChange:x=>i(x.target.value),children:[p===""?t.jsx("option",{value:"",children:"Choose an agent"}):null,r.choices.map(x=>t.jsxs("option",{value:x.id,disabled:!x.available,children:[x.name," @",x.handle,x.available?"":" (cannot run)"]},x.id))]}),t.jsx(A,{variant:"accent",disabled:l||!g,onClick:()=>void j(),children:"Save"})]})]})})}function yY({agentId:e,agent:n,agents:s,tab:r,section:a,timezone:i,navigate:l,attention:o}){const c=p=>g=>{g.preventDefault(),l(p)},u=qf(o.get(e)),d=(n==null?void 0:n.name)??e,f=RG(e),m=n!==void 0&&!n.roles.includes(Fr)&&!n.roles.includes(bu);return t.jsxs("div",{className:"ui-stack","data-gap":"lg",children:[t.jsxs("header",{className:"agent-head",children:[t.jsx(Nn,{id:e,name:d,size:"xl",unavailable:n?!n.available:!1,face:n}),t.jsxs("div",{className:"agent-head-text",children:[t.jsx("p",{className:"ui-page-lede",children:(n==null?void 0:n.description)??"This agent is not in the roster right now."}),f.entry?t.jsx(IG,{entry:f.entry,navigate:l,onUpdated:f.reload}):null,t.jsxs("div",{className:"ui-row",children:[n?t.jsxs("span",{className:"muted mono",children:["@",n.handle]}):null,n?t.jsx("span",{className:"muted",children:n.model}):null,u?t.jsx(Ee,{tone:"critical",children:u}):n&&!n.available?t.jsx(Ee,{tone:"warning",children:n.unavailableReason??"cannot run"}):null]})]}),t.jsx("div",{className:"ui-page-actions",children:t.jsxs(ht,{variant:"accent",href:Ze(e),onClick:c(Ze(e)),children:["Talk to ",d]})})]}),n&&!n.available?t.jsxs(G,{tone:"warning",role:"status",children:[m$(n)," ",t.jsx("a",{href:Le(Ix(n).section),children:Ix(n).label})]}):null,t.jsx(yo,{children:gY.map(p=>t.jsx(Li,{href:Pt(e,p.id),active:r===p.id,onClick:c(Pt(e,p.id)),children:p.label},p.id))}),r==="conversations"?t.jsx(wY,{agentId:e,navigate:l}):null,r==="missions"?t.jsx(_R,{timezone:i,embedded:!0,agentId:e}):null,r==="offers"?t.jsx(UR,{embedded:!0,agentId:e,agentName:d}):null,r==="reminders"?t.jsx(iI,{timezone:i,embedded:!0,agentId:e}):null,r==="memory"?t.jsx(JR,{embedded:!0,agents:s,timezone:i,agentId:e}):null,r==="skills"?t.jsx(dq,{agentId:e,agentName:d,faces:s,navigate:l}):null,r==="setup"?t.jsx(tY,{agentId:e,section:a,navigate:l}):null,r==="setup"&&m?t.jsx(MG,{agentId:e,name:d,navigate:l}):null]})}function wY({agentId:e,navigate:n}){const{data:s,error:r}=me(()=>qe.conversations(e,50),[e]);if(r)return t.jsx(ve,{children:r});const a=(s==null?void 0:s.conversations)??[];return t.jsx(Ye,{flush:!0,children:s?a.length===0?t.jsx(Jn,{icon:"chat",title:"No conversations yet",children:"Say hello, and the conversation shows up here."}):t.jsx(at,{children:a.map(i=>t.jsx(Xe,{href:Ze(e,i.id),onClick:()=>n(Ze(e,i.id)),title:cr(i.preview||i.opening||"Untitled conversation",90),sub:`${i.messageCount} message${i.messageCount===1?"":"s"}`,side:Ve(i.lastMessageAt??i.startedAt??i.createdAt??null)},i.id))}):t.jsx(ve,{children:"Loading…"})})}const bY=3e4;function NI(){const{data:e,reload:n}=me(()=>R.recovery(),[],bY),s=h.useRef(n);return s.current=n,h.useEffect(()=>{const r=()=>s.current(),a=()=>{document.visibilityState==="visible"&&r()};return window.addEventListener("focus",r),document.addEventListener("visibilitychange",a),()=>{window.removeEventListener("focus",r),document.removeEventListener("visibilitychange",a)}},[]),{data:e,reload:n}}function ZN(e){return e.kind==="account"?e.accountId?s$(e.accountId):Le("accounts"):e.kind==="telegram"?Le("telegram"):e.kind==="connection"?e.connectionId?r$(e.connectionId):Le("connections"):e.kind==="email"?e.settingsRoute:Le("secrets")}function kY(e){return e.install?x3(e.install):Cx}const NY=Le("system");function SY(e){return e.loadsAtRestart?`installed — loads at the next restart${e.waiting?`; ${e.waiting.note}`:""}`:e.waiting?`${e.name} — ${e.waiting.note}`:e.source}const SI="This buddi was restored from a backup. Nothing runs on its own until you finish the checklist.";function CY({view:e,onLeft:n}){const{secrets:s,plugins:r,pending:a,grants:i}=e.checklist,l=e.checklist.keptTables??[],[o,c]=h.useState(!0),[u,d]=h.useState([]),[f,m]=h.useState(!1),[p,g]=h.useState(null),[v,b]=h.useState(!1),j=r.filter(k=>!k.installed||k.waiting!==void 0||k.loadsAtRestart===!0),x=a.jobs+a.missions+a.approvals+a.telegramChats,y=k=>{d(N=>N.includes(k)?N.filter(S=>S!==k):[...N,k])},w=()=>{m(!0),g(null),Gf({kind:"recovery"},()=>R.leaveRecovery({dropPending:o,keepGrants:u})).then(k=>{k&&k.restarting===!1&&Yl(),b(!0),n==null||n()}).catch(k=>g(k instanceof xe?k.message:String(k))).finally(()=>m(!1))};return t.jsx(Ye,{title:"Back from a backup",children:t.jsxs(ie,{divided:!0,children:[t.jsxs(ue,{children:[t.jsx(qt,{items:[{label:"Restored",value:e.restoredAt??"just now"},{label:"From",value:t.jsx("span",{className:"mono",children:e.archive??"—"})}]}),t.jsx("p",{className:"ui-card-meta",children:"Nothing runs on its own yet: no schedules, no watchers, no phone. Chat works. Go through what is below, then turn this buddi back on."})]}),t.jsx(ue,{title:"Keys to paste again",children:s.length===0?t.jsx(ve,{children:"Nothing is missing."}):t.jsx(at,{children:s.map(k=>t.jsx(Xe,{title:k.label??k.name,sub:k.name?t.jsx("span",{className:"mono",children:k.name}):void 0,side:k.signIn?t.jsx(ht,{size:"sm",href:ZN(k),"aria-label":`Sign in again: ${k.label??k.name}`,children:"Sign in again"}):t.jsx(ht,{size:"sm",href:ZN(k),"aria-label":`Fix ${k.label??k.name}`,children:"Fix"})},`${k.kind}:${k.accountId??k.name}`))})}),t.jsx(ue,{title:"Add-ons to install again",children:j.length===0&&l.length===0?t.jsx(ve,{children:"Everything the backup named is installed."}):t.jsxs(at,{children:[j.map(k=>t.jsx(Xe,{title:t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"mono",children:k.name})," ",k.version]}),sub:SY(k),side:k.loadsAtRestart?t.jsx(ht,{size:"sm",href:NY,"aria-label":`Restart to load ${k.name}`,children:"Restart"}):k.installed?void 0:t.jsx(ht,{size:"sm",href:kY(k),"aria-label":`Install ${k.name} again`,children:k.install?"Install":"Find it"})},k.name)),l.map(k=>t.jsx(Xe,{title:t.jsx("span",{className:"mono",children:k.table}),sub:k.sentence},`kept:${k.table}`))]})}),t.jsx(ue,{title:"Work that was waiting",children:x===0?t.jsx(ve,{children:"Nothing was in flight when the backup was taken."}):t.jsxs(ie,{gap:"sm",children:[t.jsx(qt,{items:[{label:"Jobs",value:String(a.jobs)},{label:"Missions",value:String(a.missions)},{label:"Waiting for an answer",value:String(a.approvals)},{label:"Phones",value:String(a.telegramChats)}]}),t.jsxs("label",{className:"recovery-check",children:[t.jsx("input",{type:"checkbox",checked:o,onChange:k=>c(k.target.checked)}),t.jsx("span",{children:"Drop it. It was queued somewhere else, days ago."})]})]})}),t.jsx(ue,{title:"Standing permissions",children:i.length===0?t.jsx(ve,{children:"No agent had a standing permission."}):t.jsxs(ie,{gap:"sm",children:[t.jsx("p",{className:"ui-card-meta",children:"Each of these lets an agent act without asking. Keep only the ones you meant."}),t.jsx("ul",{className:"recovery-list",children:i.map(k=>t.jsx("li",{children:t.jsxs("label",{className:"recovery-check",children:[t.jsx("input",{type:"checkbox",checked:u.includes(k.id),onChange:()=>y(k.id),"aria-label":`Keep ${k.tool} for ${k.agent}`}),t.jsxs("span",{children:[t.jsx("span",{className:"mono",children:k.tool})," for ",k.agent," ",t.jsx("span",{className:"ui-card-meta",children:k.scope}),k.description?t.jsxs("span",{className:"ui-card-meta",children:[" — ",k.description]}):null]})]})},k.id))})]})}),t.jsx(ue,{children:t.jsxs(ie,{gap:"sm",children:[t.jsx(ne,{message:p}),v?t.jsx(G,{tone:"good",role:"status",children:"Turning everything back on. This page comes back in a few seconds."}):t.jsx("p",{className:"ui-card-meta",children:"Leaving starts the schedules, the watchers and the phone again. buddi restarts itself to do it."}),t.jsx(te,{align:"end",children:t.jsx(A,{variant:"accent",disabled:f||v,onClick:w,children:"Leave recovery mode"})})]})})]})})}function EY({days:e,mailbox:n,money:s,pictures:r}){const a=[];(n||e)&&a.push("chief-of-staff"),s&&a.push("cfo"),r&&a.push("illustrator");for(const i of["researcher","tutor"])a.length<3&&a.push(i);return a.slice(0,4)}function CI(e,n,s=4){const r=i=>!!i&&li(i)==="ready"&&i.addable,a=EY(n).map(i=>e.find(l=>l.name===i)).filter(r);for(const i of["researcher","tutor"]){if(a.length>=3)break;const l=e.find(o=>o.name===i);r(l)&&!a.includes(l)&&a.push(l)}return a.slice(0,s)}function AY(e,n){const s=e.filter(r=>r.id!==n&&!r.roles.includes(bu)&&!r.roles.includes(Fr));return e.length>0&&s.length<=1}async function $Y(e,n=HR){try{const{jobId:s}=await R.catalogueInstall(e.name,{version:e.version,tools:e.tools});for(;;){const r=await R.catalogueJob(s);if(r.state!=="running")return r;await new Promise(a=>setTimeout(a,n))}}catch(s){return{error:s instanceof xe?s.message:String(s)}}}function TY({entry:e,checked:n,onChange:s}){return t.jsxs("label",{className:"cat-pick","data-checked":n?"true":void 0,children:[t.jsx("input",{type:"checkbox",checked:n,onChange:r=>s(r.target.checked)}),t.jsx(So,{entry:e,size:"lg"}),t.jsxs("span",{className:"cat-pick-text",children:[t.jsx("span",{className:"cat-pick-name",children:e.title}),t.jsx("span",{className:"cat-pick-pitch",children:e.pitch})]})]})}function RY({entry:e,added:n,onOpen:s,onAdd:r}){return t.jsxs("div",{className:"cat-suggest",role:"button",tabIndex:0,"aria-label":`${e.title}: details`,"data-testid":`cat-suggest-${e.name}`,onClick:s,onKeyDown:a=>{a.target===a.currentTarget&&a.key==="Enter"&&s()},children:[t.jsx(So,{entry:e,size:"lg"}),t.jsxs("span",{className:"cat-pick-text",children:[t.jsx("span",{className:"cat-pick-name",children:e.title}),t.jsx("span",{className:"cat-pick-pitch",children:e.pitch})]}),n?t.jsxs("span",{className:"cat-added",children:[t.jsx(le,{name:"check",size:14}),"Added"]}):t.jsx(A,{size:"sm",variant:"accent","aria-label":`Add ${e.title}`,onClick:a=>{a.stopPropagation(),r()},children:"Add"})]})}function IY({navigate:e}){const[n,s]=h.useState(null),[r,a]=h.useState(null),[i,l]=h.useState([]),o=jw();h.useEffect(()=>{let u=!1;return R.catalogue().then(d=>{u||s(d.unavailable?[]:d.agents)}).catch(()=>{u||s([])}),()=>{u=!0}},[]);const c=h.useMemo(()=>n===null?null:CI(n,{days:!0,mailbox:!0,money:o.has("finance"),pictures:o.has("image")},3),[n,o]);return!c||c.length===0?null:t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"cat-suggest-lede",children:"Teammates who could take a job off your hands, from what you set up:"}),t.jsx("div",{className:"cat-suggests","data-testid":"home-suggestions",children:c.map(u=>t.jsx(RY,{entry:u,added:i.includes(u.name),onOpen:()=>e(sn(u.name)),onAdd:()=>a(u)},u.name))}),r?t.jsx(KR,{entry:r,navigate:e,onClose:()=>a(null),onAdded:()=>{l(u=>[...u,r.name]),window.dispatchEvent(new Event(Dr))}}):null]})}function PY({setUp:e,navigate:n}){var j;const[s,r]=h.useState(null),[a,i]=h.useState([]),[l,o]=h.useState("picking"),[c,u]=h.useState([]),[d,f]=h.useState([]),m=JSON.stringify(e);if(h.useEffect(()=>{let x=!1;return R.catalogue().then(y=>{if(x)return;const w=y.unavailable?[]:CI(y.agents,e);r(w),i(w.map(k=>k.name))}).catch(()=>{x||r([])}),()=>{x=!0}},[m]),!s||s.length===0)return null;const p=()=>n(sn()),g=async()=>{o("adding");const x=[],y=[];for(const w of s.filter(k=>a.includes(k.name))){const k=await $Y(w);"error"in k&&!("state"in k)?y.push({entry:w,error:k.error}):k.state==="done"?x.push(w):k.state==="confirm"?y.push({entry:w,error:"it gets more than its card showed, so it waits for your approval in Needs you"}):y.push({entry:w,error:k.error??"it stopped before it finished"})}u(x),f(y),o("added"),x.length>0&&window.dispatchEvent(new Event(Dr))},v=a.length,b=l==="adding"?`Adding ${v===1?((j=s.find(x=>x.name===a[0]))==null?void 0:j.title)??"1":v}…`:v===s.length?"Add these":v>0?`Add these ${v}`:"Tick one to add";return t.jsx("section",{className:"handover-team","aria-label":"Who do you want on your team?","data-testid":"handover-team",children:l==="added"?t.jsxs(t.Fragment,{children:[c.length>0?t.jsxs(G,{tone:"good",role:"status",title:`${rn(c.map(x=>x.title))} ${c.length===1?"is":"are"} on your team.`,action:t.jsx(A,{variant:"ghost",size:"sm",onClick:p,children:"See all teammates"}),children:["Say hello in Chat. ",c.length===1?"Its missions are":"Their missions are"," off until you turn them on."]}):null,d.length>0?t.jsxs(G,{tone:"critical",role:"alert",title:`${rn(d.map(x=>x.entry.title))} ${d.length===1?"wasn’t":"weren’t"} added.`,action:c.length===0?t.jsx(A,{variant:"ghost",size:"sm",onClick:p,children:"See all teammates"}):void 0,children:[d.map(x=>`${x.entry.title}: ${x.error.replace(/[.\s]+$/,"")}.`).join(" ")," Nothing else changed; try again from the catalogue."]}):null]}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"handover-team-head",children:[t.jsx("h2",{className:"handover-team-title",children:"Who do you want on your team?"}),t.jsx("p",{className:"cat-small",children:"Picked from what you just set up. Their plugins are already in, so one click adds them all."})]}),t.jsx("div",{className:"cat-picks",children:s.map(x=>t.jsx(TY,{entry:x,checked:a.includes(x.name),onChange:y=>i(y?[...a,x.name]:a.filter(w=>w!==x.name))},x.name))}),t.jsx("div",{className:"handover-team-foot",children:t.jsxs(te,{children:[t.jsx(A,{variant:"ghost",onClick:p,children:"See all teammates"}),t.jsx(et,{}),t.jsx(A,{variant:"accent",disabled:v===0||l==="adding",onClick:()=>void g(),children:b})]})})]})})}const eS=3,MY=40;function DY({agent:e,navigate:n}){var g;const s=h.useRef(null),[r,a]=h.useState(!1),[i,l]=h.useState(null),[o,c]=h.useState(null),u=me(()=>qe.conversations(e.id,eS),[e.id],3e4),d=ws(Ry),f=ws("(pointer: coarse)");h.useEffect(()=>{var v;!d&&!f&&((v=s.current)==null||v.focus())},[]);const m=(v,b)=>{a(!0),l(null),(async()=>{try{const{conversationId:j}=await qe.startConversation(e.id),x=await qe.send(e.id,{conversationId:j,text:v,...b.length>0?{attachmentIds:b.map(y=>y.artifactId)}:{}});n(Ze(e.id,x.conversationId))}catch(j){l(j instanceof xe?j.message:String(j)),c({text:v,at:Date.now()}),a(!1)}})()},p=(((g=u.data)==null?void 0:g.conversations)??[]).slice(0,eS);return t.jsxs("div",{className:"home-ask",children:[i?t.jsx(ne,{message:i}):null,t.jsx(Zy,{ref:s,disabled:r||!e.available,running:!1,onSend:m,onStop:()=>{},agentName:e.name,placeholder:`Message ${e.name}…`,draft:o,threadKey:`home.${e.id}`,slim:!0}),p.length>0?t.jsxs("div",{className:"home-continue",children:[t.jsx("span",{className:"home-continue-label",id:`home-continue-${e.id}`,children:"Continue"}),t.jsx("ul",{className:"home-continue-chips","aria-labelledby":`home-continue-${e.id}`,children:p.map(v=>{const b=Ze(e.id,v.id),j=v.opening??v.preview??"Untitled conversation",x=Zj(v.lastMessageAt??v.createdAt??v.startedAt??null);return t.jsx("li",{children:t.jsxs("a",{className:"home-continue-chip",href:b,title:j,onClick:y=>{y.preventDefault(),n(b)},children:[t.jsx("span",{className:"home-continue-title",children:cr(j,MY)}),x?t.jsx("span",{className:"home-continue-when",children:x}):null]})},v.id)})})]}):null]})}function OY(e){const n=e.indexOf("?");if(n===-1)return;const s=new URLSearchParams(e.slice(n+1)).get("tip");return s&&/^[a-z0-9-]{1,40}$/.test(s)?s:void 0}function LY({navigate:e,preview:n,hidden:s}){var c;const r=me(()=>R.currentTip(n),[n]),[a,i]=h.useState(null),l=((c=r.data)==null?void 0:c.tip)??null;if(!l||a===l.id||s)return null;const o=u=>{i(l.id),!n&&(u==="dismiss"?R.dismissTip(l.id):R.laterTip(l.id)).catch(()=>{})};return t.jsx("div",{className:"home-tip","data-tip":l.id,children:t.jsxs(G,{children:[t.jsxs("div",{className:"ui-notice-row",children:[t.jsx("p",{className:"ui-notice-body",children:l.text}),t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":"Not now",title:"Not now",onClick:()=>o("later"),children:t.jsx(le,{name:"close"})})]}),t.jsxs(te,{children:[t.jsx(et,{}),t.jsx(A,{variant:"ghost",size:"sm",onClick:()=>o("dismiss"),children:"Not this again"}),t.jsx(A,{variant:"accent",size:"sm",onClick:()=>e(l.action.route),children:l.action.label})]})]})})}const kv="buddi.tipsOpen";function FY(e){return gu(e,{compact:!0})}function _Y(e){switch(e.status){case"today":return"Due today";case"holding":return"Waiting";case"quiet":return"Not needed now";case"dismissed":return"Dismissed";case"shown":return e.shownAt?`Shown on ${FY(e.shownAt)}`:"Shown"}}function zY(){try{return window.localStorage.getItem(kv)==="1"}catch{return!1}}function UY(){const e=me(()=>R.tips(),[]),[n,s]=h.useState(zY),r=h.useCallback(a=>{s(a);try{a?window.localStorage.setItem(kv,"1"):window.localStorage.removeItem(kv)}catch{}},[]);return{open:n,setOpen:r,list:e}}function BY({tips:e}){const{open:n,setOpen:s,list:r}=e,a=!!r.data&&!r.data.enabled&&r.data.tips.some(i=>i.status==="today");return t.jsxs("button",{type:"button",className:"ui-icon-btn home-tips-btn","aria-label":a?"Tips, one due today":"Tips","aria-pressed":n,title:"Tips","data-open":n,onClick:()=>{n||r.reload(),s(!n)},children:[t.jsx(le,{name:"bulb"}),a?t.jsx("span",{className:"home-tips-dot","data-testid":"tips-dot"}):null]})}function WY({tips:e,navigate:n}){var b,j;const{open:s,setOpen:r,list:a}=e,[i,l]=h.useState(null),[o,c]=h.useState(null),[u,d]=h.useState(null);if(!s)return null;const f=((b=a.data)==null?void 0:b.tips)??null,m=u??((j=a.data)==null?void 0:j.enabled)??!0,p=x=>l(x instanceof xe?x.message:String(x)),g=x=>{c(x),l(null),R.restoreTip(x).then(()=>a.reload(),p).finally(()=>c(null))},v=x=>{c("switch"),l(null),d(x),R.saveTipsSettings(x).then(y=>{d(y.enabled),a.reload()}).catch(y=>{d(!x),p(y)}).finally(()=>c(null))};return t.jsx("div",{className:"home-tips","data-testid":"tips-section",children:t.jsxs(ue,{title:"Tips",children:[t.jsx(ne,{message:a.error??i}),t.jsx("div",{className:"tips-grid",children:(f??[]).map(x=>t.jsx("div",{className:"tips-card","data-tip":x.id,"data-status":x.status,children:t.jsxs(Ts,{tone:x.status==="today"?"accent":void 0,children:[t.jsx("div",{children:t.jsx(Ee,{tone:x.status==="today"?"accent":"muted",children:_Y(x)})}),t.jsx("p",{className:"tips-card-text",children:x.text}),t.jsxs(te,{children:[t.jsx(et,{}),x.status==="dismissed"?t.jsx(A,{size:"sm",disabled:o===x.id,onClick:()=>g(x.id),children:"Bring back"}):t.jsx(A,{size:"sm",variant:x.status==="today"?"accent":void 0,onClick:()=>n(x.action.route),children:x.action.label})]})]})},x.id))}),t.jsxs(te,{children:[t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:m,disabled:o==="switch"||f===null,onChange:x=>v(x.target.checked)}),t.jsx("span",{children:"Tips on Home"})]}),t.jsx(et,{}),t.jsx(A,{variant:"ghost",size:"sm",onClick:()=>r(!1),children:"Close"})]})]})})}function HY(e){return e.length<=1?e[0]??"":e.length<=4?`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`:`${e.slice(0,3).join(", ")} and ${e.length-3} more`}function KY({glance:e,team:n,onClose:s}){if(!e.today||!e.note)return null;const r=n.filter(a=>a.available).slice(0,8);return t.jsxs("section",{className:"bd-card","aria-label":"Your birthday",children:[e.image?t.jsxs("figure",{className:"bd-art",children:[t.jsx("img",{src:_r(e.image),alt:"A picture your team made for your birthday"}),t.jsx("figcaption",{children:"Made for you"})]}):null,t.jsxs("div",{className:"bd-body",children:[t.jsx("p",{className:"bd-kicker",children:"From your team"}),t.jsx("p",{className:"bd-note",children:e.note}),r.length>0?t.jsxs("div",{className:"bd-foot",children:[t.jsx("span",{className:"bd-faces",children:r.slice(0,4).map(a=>t.jsx(fn,{agents:n,id:a.id,size:"sm"},a.id))}),t.jsx("span",{className:"bd-sign",children:HY(r.map(a=>a.name))})]}):null]}),t.jsx("button",{type:"button",className:"ui-icon-btn bd-close","data-size":"sm","aria-label":"Put it away for today",title:"Put it away for today",onClick:s,children:t.jsx(le,{name:"close"})})]})}const EI="buddi.needsYouView";function VY(){try{return window.localStorage.getItem(EI)==="list"?"list":"deck"}catch{return"deck"}}function GY(e){try{window.localStorage.setItem(EI,e)}catch{}}function qY(e,n,s){const r=(n.alsoFrom??[]).filter(a=>a!==n.agentId).map(s);return r.length===0?e:`${e} · also ${r.join(", ")}`}function YY({rows:e,agents:n,label:s,onOpen:r,onDone:a}){const[i,l]=h.useState(0);if(e.length===0)return t.jsx(ve,{mascot:!0,children:"Nothing needs you. Your agents are on it."});const o=Math.min(i,e.length-1),c=e[o],u=e.length>1,d=v=>l((o+v+e.length)%e.length),f=()=>r(c),m=()=>a(c),p=v=>{const b=v.target;b.closest('input, textarea, select, [contenteditable="true"]')||(v.key==="ArrowRight"&&u?(v.preventDefault(),d(1)):v.key==="ArrowLeft"&&u?(v.preventDefault(),d(-1)):v.key==="Enter"&&!b.closest("button, a")?(v.preventDefault(),(c.link||c.agentId)&&f()):(v.key==="d"||v.key==="Delete")&&!v.metaKey&&!v.ctrlKey&&!v.altKey&&(v.preventDefault(),m()))},g=t.jsxs("span",{className:"home-deck-from",children:[c.agentId?t.jsx(fn,{agents:n,id:c.agentId,size:"sm"}):null,t.jsx("span",{children:s(c)})]});return t.jsx("div",{className:"home-deck","data-depth":Math.min(e.length-1,2),role:"region","aria-label":"Needs you, one at a time","aria-roledescription":"deck",tabIndex:0,onKeyDown:p,children:t.jsx(Ts,{as:"article",title:g,meta:t.jsx("span",{className:"ui-card-meta",children:c.state==="held"?"today":Ve(c.createdAt)}),actions:t.jsxs(t.Fragment,{children:[t.jsxs("span",{className:"home-deck-count","aria-live":"polite",children:[o+1," of ",e.length]}),t.jsx(A,{size:"sm",variant:"ghost","aria-label":"Previous",disabled:!u,onClick:()=>d(-1),children:t.jsx(le,{name:"chevron-left"})}),t.jsx(A,{size:"sm",variant:"ghost","aria-label":"Next",disabled:!u,onClick:()=>d(1),children:t.jsx(le,{name:"chevron-right"})})]}),foot:t.jsxs(te,{align:"end",children:[t.jsx(A,{onClick:m,children:"Done"}),c.link||c.agentId?t.jsx(A,{variant:"accent",onClick:f,children:"Open"}):null]}),children:t.jsxs("div",{className:"home-deck-body",children:[t.jsx("p",{className:"home-deck-title",children:Kc(c)}),c.text?t.jsx("p",{className:"home-deck-text",children:c.text}):null,c.action?t.jsx("p",{className:"home-deck-text",children:t.jsx("strong",{children:c.action})}):null]})})})}function JY({timezone:e,navigate:n,agents:s,defaultAgentId:r,attention:a,update:i,connectionSignals:l=[],hash:o="",pluginPages:c}){var ut,dt,Q,Ae,tt,Ct,yt,kt,Bn,hs,In,fs,Zt,ms,Tt,$e,Qe,ze,Nt;const u=me(()=>R.overview(),[],15e3),d=me(()=>R.approvals(),[],1e4),f=me(()=>R.missions(),[],6e4),m=me(()=>R.reminders(),[],6e4),p=me(()=>R.conversations(),[],3e4),g=me(()=>R.offers(),[],3e4),v=me(()=>R.proposals(),[],6e4),b=me(()=>R.agentOffers(),[],6e4),j=me(()=>R.owner(),[]),x=me(()=>R.birthday(),[],5*6e4),y=me(()=>R.notificationsNeedingYou(),[],3e4),w=h.useMemo(()=>h$(s,r??null),[s,r]),k=AY(s,r),{busy:N,note:S,failure:C,decide:E}=ew(()=>{d.reload(),u.reload()}),T=u.data,I=s.find(q=>q.id===r)??null,F=q=>{var he;return((he=s.find(Sn=>Sn.id===q))==null?void 0:he.name)??q},D=q=>he=>{he.preventDefault(),n(q)},$=((ut=d.data)==null?void 0:ut.pending)??[],L=((dt=T==null?void 0:T.jobs)==null?void 0:dt.failed)??0,O=((Q=T==null?void 0:T.sentinels)==null?void 0:Q.openUrgent)??0,M=((Ae=v.data)==null?void 0:Ae.open.length)??0,P=(((tt=b.data)==null?void 0:tt.offers)??[]).filter(q=>!$.some(he=>OT(he,q.plugin,q.agent))),H=XY(((Ct=y.data)==null?void 0:Ct.notifications)??[],$),[U,V]=h.useState(new Set),[z,X]=h.useState(VY),K=H.filter(q=>!U.has(q.id)),ee=q=>{V(he=>new Set(he).add(q.id)),R.notificationSeen(q.id).catch(()=>{})},ce=q=>{ee(q);const he=q.link??(q.agentId?Ze(q.agentId):null);he&&n(he)},pe=q=>qY(q.agentId?F(q.agentId):q.pluginId?V$(q.pluginId,c==null?void 0:c.all):QY[q.kind],q,F),oe=nJ(T==null?void 0:T.dismissed,()=>u.reload()),Re=(((yt=T==null?void 0:T.sentinels)==null?void 0:yt.errors)??[]).filter(q=>!oe.is(`watcher-error:${q.sentinelId}`,q.error)),Oe=((T==null?void 0:T.mail)??[]).filter(q=>q.lastError&&!oe.is(`source-error:${q.sourceId}`,q.lastError)),Je=ZY(a),W=l.filter(q=>!oe.is(`connection:${q.id}`,q.sentence)),se=(((kt=T==null?void 0:T.needsYou)==null?void 0:kt.recovery)??0)>0,Y=$.length+Je.length+(L>0?1:0)+(O>0?1:0)+(M>0?1:0)+P.length+H.length+W.length+(se?1:0);h.useEffect(()=>{var q,he;o===ql&&((he=(q=document.getElementById(Nv))==null?void 0:q.scrollIntoView)==null||he.call(q,{behavior:"smooth",block:"start"}))},[o]);const Ne=h.useMemo(()=>{var q,he;return iJ(((q=f.data)==null?void 0:q.missions)??[],((he=m.data)==null?void 0:he.reminders)??[])},[f.data,m.data]),we=(((Bn=p.data)==null?void 0:Bn.conversations)??[]).slice(0,5),fe=((hs=g.data)==null?void 0:hs.offers)??[],ge=fe.slice(0,sJ),Pe=UY(),je=fe.length-ge.length,de=jR(()=>u.reload()),ke=zV(),Be=h.useMemo(()=>UV(ke.answer),[ke.answer]),Ue=fJ((T==null?void 0:T.needsYou)??{approvals:$.length,questions:Je.length,failed:L,urgent:O,proposals:M,agentsToSetUp:P.length,asks:H.length,signIns:W.length,recovery:se?1:0},(T==null?void 0:T.paused)??!1);return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"home-band",children:[t.jsxs("header",{className:"home-top",children:[t.jsxs("div",{className:"home-top-text",children:[t.jsxs("p",{className:"home-date",children:[t.jsx("span",{children:uJ(T==null?void 0:T.now,e)}),t.jsx(xV,{glances:T==null?void 0:T.glances,navigate:n,except:Be,hiding:de}),t.jsx(BY,{tips:Pe})]}),t.jsx("h1",{className:"home-greeting",children:(In=x.data)!=null&&In.today?oJ(x.data.name??((fs=j.data)==null?void 0:fs.preferredName)??((Zt=j.data)==null?void 0:Zt.displayName)):cJ(T==null?void 0:T.now,e,((ms=j.data)==null?void 0:ms.preferredName)||((Tt=j.data)==null?void 0:Tt.displayName))}),t.jsx(mJ,{items:Ue,navigate:n})]}),t.jsx("div",{className:"home-side",children:t.jsx(y$,{size:"lg",anim:"idle"})})]}),($e=x.data)!=null&&$e.today&&x.data.note&&!oe.is("birthday",x.data.date)?t.jsx(KY,{glance:x.data,team:w,onClose:()=>oe.close("birthday",x.data.date)}):null]}),t.jsxs("div",{className:"home",children:[I?t.jsx(DY,{agent:I,navigate:n},I.id):null,t.jsx(WY,{tips:Pe,navigate:n}),t.jsx(LY,{navigate:n,preview:OY(o),hidden:Pe.open}),i&&i.updateAvailable&&!i.checkout&&i.latest&&!oe.is("update",i.latest)?t.jsx(G,{tone:"accent",action:t.jsx(Cl,{label:"Not now — tell me at the next version",onClick:()=>oe.close("update",i.latest)}),children:t.jsxs("p",{children:["A newer buddi is ready: ",t.jsx("span",{className:"mono",children:i.latest}),"."," ",t.jsx("a",{href:Le("system"),onClick:D(Le("system")),children:"Upgrade from Settings → Version."})]})}):null,Re.map(q=>t.jsxs(G,{tone:"warning",action:t.jsx(Cl,{label:"Hide until the error changes",onClick:()=>oe.close(`watcher-error:${q.sentinelId}`,q.error)}),children:["Watcher ",q.sentinelId," failed: ",q.error]},q.sentinelId)),Oe.map(q=>t.jsxs(G,{tone:"warning",action:t.jsx(Cl,{label:"Hide until the error changes",onClick:()=>oe.close(`source-error:${q.sourceId}`,q.lastError)}),children:["Source ",q.sourceId,": ",q.lastError]},q.sourceId)),t.jsx(ne,{message:u.error??d.error??C}),S?t.jsx(G,{tone:"good",role:"status",children:S}):null,Y>0?t.jsx("div",{id:Nv,className:"home-needs",children:t.jsx(ue,{title:"Needs you",aside:t.jsx("a",{href:Ax,onClick:D(Ax),children:"All notifications"}),actions:H.length>0?t.jsx(ln,{label:"Show what needs you as",options:[{value:"list",label:"List"},{value:"deck",label:"Deck"}],value:z,onChange:q=>{X(q),GY(q)}}):void 0,children:t.jsxs(ie,{children:[$.map(q=>t.jsx(tw,{action:q,timezone:e,busy:N===q.id,onDecide:E,agentName:F(q.agentId)},q.id)),O>0?t.jsx(G,{tone:"warning",children:t.jsx("a",{href:`${At}/alerts`,onClick:D(`${At}/alerts`),children:hJ(O,((Qe=T==null?void 0:T.sentinels)==null?void 0:Qe.decisions)??[])})}):null,Je.length>0||H.length>0&&z==="list"?t.jsx(Ye,{flush:!0,children:t.jsxs(at,{children:[Je.map(q=>t.jsx(Xe,{href:q.route,onClick:()=>n(q.route),lead:t.jsx(fn,{agents:s,id:q.agentId,size:"sm"}),title:"Asked you a question",sub:`${F(q.agentId)} · waiting for your answer`,side:Ve(q.at)},q.agentId)),z==="list"?K.map(q=>t.jsx(Xe,{href:q.link??void 0,onClick:()=>ce(q),lead:q.agentId?t.jsx(fn,{agents:s,id:q.agentId,size:"sm"}):void 0,title:Kc(q),sub:q.action?`${pe(q)} · ${q.action}`:pe(q),side:q.state==="held"?"today":Ve(q.createdAt)},q.id)):null]})}):null,H.length>0&&z==="deck"?t.jsx(YY,{rows:K,agents:s,label:pe,onOpen:ce,onDone:ee}):null,L>0?t.jsx(G,{tone:"critical",children:t.jsxs("a",{href:`${At}/jobs?state=failed`,onClick:D(`${At}/jobs?state=failed`),children:[L," failed job",L===1?"":"s",". See why, then retry or dismiss ",L===1?"it":"them","."]})}):null,M>0?t.jsx(G,{tone:"accent",children:t.jsxs("a",{href:Le("proposals"),onClick:D(Le("proposals")),children:[M," proposal",M===1?"":"s"," from your agents to keep or discard."]})}):null,W.map(q=>t.jsx(G,{tone:"accent",action:t.jsx(Cl,{label:"Not now — tell me if it changes",onClick:()=>oe.close(`connection:${q.id}`,q.sentence)}),children:t.jsxs("p",{children:[q.sentence," ",t.jsx("a",{href:Le("connections"),onClick:D(Le("connections")),children:"Settings → Connections."})]})},q.id)),P.map(q=>t.jsx(Ye,{children:t.jsx(sw,{plugin:q.plugin,agent:q.agent,text:q.text,label:`Create @${q.handle}`,handle:q.handle,onDismiss:()=>{R.dismissAgentOffer(q.plugin,q.agent).then(()=>b.reload())}})},`${q.plugin}/${q.agent}`)),se?t.jsx(G,{tone:"warning",children:t.jsxs("p",{children:[SI," ",t.jsx("a",{href:$x,onClick:D($x),children:"Open the checklist."})]})}):null]})})}):null,t.jsx(KV,{widgets:ke,navigate:n}),t.jsxs(ue,{title:"Your team",aside:k?t.jsx("a",{href:sn(),onClick:D(sn()),children:"See all teammates"}):t.jsx("a",{href:vt,onClick:D(vt),children:"All agents"}),children:[s.length===0?t.jsx(ve,{mascot:!0,children:"No agents yet. Add one under Agents."}):t.jsxs("div",{className:"home-team",children:[w.map(q=>{const he=qf(a.get(q.id));return t.jsxs("a",{className:"home-face",...Oi(jo(q)),href:Ze(q.id),onClick:D(Ze(q.id)),"data-waiting":he?"true":void 0,"data-unavailable":q.available?void 0:"true",children:[t.jsx(Nn,{id:q.id,name:q.name,size:"lg",unavailable:!q.available,face:q}),t.jsxs("span",{className:"home-face-text",children:[t.jsx("span",{className:"home-face-name",children:q.name}),t.jsx("span",{className:"home-face-status",children:he?pJ(he):q.available?cr(q.description,60):q.unavailableReason??"Cannot run right now."})]})]},q.id)}),k?null:t.jsxs("a",{className:"team-add",href:sn(),onClick:D(sn()),"data-testid":"team-add",children:[t.jsx(le,{name:"plus",size:14}),"Add a teammate"]})]}),k?t.jsx(IY,{navigate:n}):null]}),ge.length>0?t.jsx(ue,{title:"On offer",aside:t.jsxs("span",{className:"ui-row",children:[je>0?t.jsxs("a",{href:`${vt}?tab=offers`,onClick:D(`${vt}?tab=offers`),children:[je," more"]}):null,t.jsx(zR,{ids:fe.map(q=>q.id),onDone:()=>g.reload()})]}),children:t.jsx("div",{className:"home-offers",children:ge.map(q=>t.jsx(aJ,{offer:q,agents:s,open:D(Pt(q.agentId,"offers")),onDismissed:()=>g.reload()},q.id))})}):null,t.jsx(aV,{}),(Nt=(ze=v.data)==null?void 0:ze.digest)!=null&&Nt.latest&&tJ(v.data.digest.latest,T==null?void 0:T.now,oe.is)?t.jsx(dJ,{digest:v.data.digest.latest,go:D,onClose:()=>oe.close(AI,v.data.digest.latest.at)}):null,t.jsxs("div",{className:"home-columns",children:[t.jsx(ue,{title:"Coming up",aside:t.jsx("a",{href:`${vt}?tab=missions`,onClick:D(`${vt}?tab=missions`),children:"All missions"}),children:t.jsx(Ye,{flush:!0,children:Ne.length===0?t.jsx(ve,{mascot:!0,children:"Nothing scheduled. Missions and reminders will show here."}):t.jsx(at,{children:Ne.map(q=>t.jsx(Xe,{href:q.route,onClick:()=>n(q.route),lead:t.jsx(fn,{agents:s,id:q.agentId,size:"sm"}),title:q.title,sub:`${q.kind} for ${F(q.agentId)}`,side:Ve(q.at)},q.key))})})}),t.jsx(ue,{title:"Lately",aside:t.jsx("a",{href:At,onClick:D(At),children:"All activity"}),children:t.jsx(Ye,{flush:!0,children:we.length===0?t.jsx(ve,{mascot:!0,children:"Nothing has run yet. Say hello to someone on your team."}):t.jsx(at,{children:we.map(q=>t.jsx(Xe,{href:Ze(q.agentId,q.id),onClick:()=>n(Ze(q.agentId,q.id)),lead:t.jsx(fn,{agents:s,id:q.agentId,size:"sm"}),title:q.opening?cr(q.opening,80):"Untitled conversation",sub:`${F(q.agentId)}, ${q.messageCount} message${q.messageCount===1?"":"s"}`,side:Ve(q.lastMessageAt??q.createdAt)},q.id))})})})]}),((T==null?void 0:T.home)??[]).filter(q=>!oe.is(tS(q.id),nS)).map(q=>t.jsx(gJ,{block:q,onHide:()=>oe.close(tS(q.id),nS)},q.id)),T!=null&&T.jobs&&T.missions?t.jsxs("p",{className:"home-foot muted",children:[dn(T.jobs.pending??0)," queued, ",dn(T.jobs.leased??0)," running, ",dn(T.missions.enabled)," of ",dn(T.missions.total)," missions on."," ",T.paused?t.jsx(Ee,{tone:"warning",children:"paused"}):t.jsx(Ee,{tone:"good",children:"running"})," ",t.jsx("a",{href:qc("").replace(/\/conversations\/$/,""),onClick:D(At),children:"Activity"})," · ",t.jsx("a",{href:Le("system"),onClick:D(Le("system")),children:"System"})]}):null]})]})}const QY={approval:"Approval",question:"Question",watcher:"Watcher",reminder:"Reminder",failure:"Failure",recap:"Report",plugin:"Plugin",agent:"Message"};function XY(e,n){const s=new Set(n.map(r=>r.id));return e.filter(r=>r.needsOwner===!0&&r.kind!=="approval"&&r.kind!=="question"&&r.actedAt===null&&r.state!=="stored"&&r.seenAt===null&&!(r.actionId&&s.has(r.actionId)))}function ZY(e){const n=[];for(const s of e.values())s.question&&n.push({agentId:s.agentId,at:s.question.at,route:Ze(s.agentId,s.question.conversationId)});return n.sort((s,r)=>s.at.localeCompare(r.at))}const AI="digest",eJ=3*864e5;function tS(e){return`block:${e}`}const nS="hidden";function tJ(e,n,s){if(s(AI,e.at))return!1;const r=Date.parse(e.at),a=n?Date.parse(n):Date.now();return Number.isFinite(r)&&a-r<eJ}function nJ(e,n){const[s,r]=h.useState({});return{is:(l,o)=>(s[l]??(e==null?void 0:e[l]))===o,close:(l,o)=>{r(c=>({...c,[l]:o})),R.homeDismiss(l,o).then(n,()=>{r(c=>{const u={...c};return delete u[l],u})})}}}function Cl({label:e,onClick:n}){return t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":e,title:e,onClick:n,children:t.jsx(le,{name:"close"})})}const sJ=6,rJ=500;function aJ({offer:e,agents:n,open:s,onDismissed:r}){const[a,i]=h.useState(!1),l=h.useRef(null),o=h.useRef(!1),c=()=>{a||(i(!0),R.dismissOffer(e.id).then(r).finally(()=>i(!1)))},u=()=>{l.current!==null&&clearTimeout(l.current),l.current=null};return t.jsxs("span",{className:"home-offer-chip",children:[t.jsxs("a",{className:"home-offer",href:Pt(e.agentId,"offers"),onClick:d=>{if(o.current){o.current=!1,d.preventDefault();return}s(d)},title:e.prompt,onTouchStart:()=>{o.current=!1,u(),l.current=setTimeout(()=>{o.current=!0,c()},rJ)},onTouchEnd:u,onTouchMove:u,onTouchCancel:u,children:[t.jsx(fn,{agents:n,id:e.agentId,size:"sm"}),t.jsx("span",{children:e.label})]}),t.jsx("button",{type:"button",className:"home-offer-x","aria-label":`Dismiss ${e.label}`,disabled:a,onClick:c,children:"×"})]})}function iJ(e,n){const s=[];for(const r of e)r.enabled&&r.nextRun&&s.push({key:`m-${r.id}`,at:r.nextRun,title:r.name,kind:"Mission",agentId:r.agentId,route:Pt(r.agentId,"missions")});for(const r of n)r.state==="pending"&&s.push({key:`r-${r.id}`,at:r.dueAt,title:r.text,kind:"Reminder",agentId:r.agentId,route:Pt(r.agentId,"reminders")});return s.sort((r,a)=>r.at.localeCompare(a.at)).slice(0,5)}function lJ(e,n){try{const s=new Intl.DateTimeFormat("en-GB",{hour:"numeric",hourCycle:"h23",timeZone:n}).format(e?new Date(e):new Date);return Number(s)}catch{return new Date().getHours()}}function oJ(e){return e?`Happy birthday, ${e}.`:"Happy birthday."}function cJ(e,n,s){const r=lJ(e,n),a=s!=null&&s.trim()?`, ${s.trim()}`:"";return r<5?`Still up${a}?`:r<12?`Good morning${a}.`:r<18?`Good afternoon${a}.`:`Good evening${a}.`}function uJ(e,n){try{return Wr(e?new Date(e):new Date,n,{weekday:!0})}catch{return ct(e??null,n)}}function dJ({digest:e,go:n,onClose:s}){var i,l;const r=e.summary??[],a=Object.entries(((i=e.feedback)==null?void 0:i.byAgent)??{}).map(([o,c])=>[o,[c.up>0?`${c.up} 👍`:"",c.down>0?`${c.down} 👎`:"",c.neutral>0?`${c.neutral} other`:""].filter(Boolean).join(" ")]).filter(([,o])=>o!=="").map(([o,c])=>{var u;return`${((u=e.agentNames)==null?void 0:u[o])??o}: ${c}`});return r.length===0&&a.length===0?null:t.jsx(ue,{title:"What buddi learned this week",aside:t.jsxs("span",{className:"ui-row",children:[t.jsx("span",{className:"muted",children:Ve(e.at)}),s?t.jsx(Cl,{label:"Hide until next week",onClick:s}):null]}),children:t.jsx(Ye,{children:t.jsxs(ie,{divided:!0,children:[r.length>0?t.jsx("ul",{className:"home-digest-list","data-plain":"",children:r.map(o=>t.jsxs("li",{children:[o.text,o.link?t.jsxs(t.Fragment,{children:[" · ",t.jsx("a",{href:o.link.route,onClick:n(o.link.route),children:o.link.label})]}):null]},o.key))}):null,a.length>0?t.jsxs("div",{"data-testid":"digest-reactions",children:[t.jsx("p",{className:"ui-card-meta",children:"Your reactions"}),t.jsxs("ul",{className:"home-digest-list",children:[a.map(o=>t.jsx("li",{children:o},o)),(((l=e.feedback)==null?void 0:l.notes)??[]).map((o,c)=>{var u;return t.jsxs("li",{children:["What was off (",((u=e.agentNames)==null?void 0:u[o.agentId])??o.agentId,"): ",o.note]},`note-${c}`)})]})]}):null]})})})}function hJ(e,n){const s=n[0];return s?e>1?`${s.title} And ${e-1} more to decide on.`:s.title:`${e} alert${e===1?"":"s"} from your watchers need${e===1?"s":""} a decision.`}const Nv="home-needs";function fJ(e,n=!1){const s=(a,i,l=`${i}s`)=>a===1?i:l,r=[];return e.approvals>0&&r.push({key:"approvals",count:e.approvals,label:s(e.approvals,"approval")}),e.questions>0&&r.push({key:"questions",count:e.questions,label:s(e.questions,"question")}),e.urgent>0&&r.push({key:"urgent",count:e.urgent,label:s(e.urgent,"urgent alert"),tone:"critical",route:`${At}/alerts`}),e.failed>0&&r.push({key:"failed",count:e.failed,label:s(e.failed,"failed job"),tone:"critical",route:`${At}/jobs?state=failed`}),n&&r.push({key:"paused",count:null,label:"Paused",route:`${At}/jobs`}),e.proposals>0&&r.push({key:"proposals",count:e.proposals,label:s(e.proposals,"proposal"),route:Le("proposals")}),e.asks>0&&r.push({key:"asks",count:e.asks,label:s(e.asks,"request")}),e.signIns>0&&r.push({key:"signins",count:e.signIns,label:s(e.signIns,"connection to check","connections to check")}),e.agentsToSetUp>0&&r.push({key:"agents",count:e.agentsToSetUp,label:s(e.agentsToSetUp,"agent to set up","agents to set up")}),e.recovery>0&&r.push({key:"recovery",count:null,label:"Restore to finish"}),r}function mJ({items:e,navigate:n}){if(e.length===0)return t.jsx("p",{className:"home-calm",children:"Nothing needs you. Your agents are on it."});const s=()=>{var r,a;(a=(r=document.getElementById(Nv))==null?void 0:r.scrollIntoView)==null||a.call(r,{behavior:"smooth",block:"start"})};return t.jsx("p",{className:"home-counts",children:e.map((r,a)=>{const i=t.jsxs(t.Fragment,{children:[r.count!==null?t.jsxs(t.Fragment,{children:[t.jsx("strong",{children:r.count})," "]}):null,r.label]});return t.jsxs(h.Fragment,{children:[a>0?t.jsx("span",{className:"home-count-sep","aria-hidden":"true",children:"·"}):null,r.route?t.jsx("a",{className:"home-count","data-tone":r.tone,href:r.route,onClick:l=>{l.preventDefault(),n(r.route)},children:i}):t.jsx("button",{type:"button",className:"home-count","data-tone":r.tone,onClick:s,children:i})]},r.key)})})}function pJ(e){return e.charAt(0).toUpperCase()+e.slice(1)}function gJ({block:e,onHide:n}){const[s,r]=h.useState(!1),a=e.sensitive===!0&&!s;h.useEffect(()=>{if(!e.sensitive||!s)return;const l=()=>{document.visibilityState==="hidden"&&r(!1)};return document.addEventListener("visibilitychange",l),window.addEventListener("blur",l),()=>{document.removeEventListener("visibilitychange",l),window.removeEventListener("blur",l)}},[e.sensitive,s]);const i=t.jsxs("span",{className:"ui-row",children:[e.rows.length>0&&e.rowsTitle&&!a?t.jsxs("span",{className:"muted",children:[e.rowsTitle.toLowerCase()," below"]}):null,e.sensitive?t.jsx(A,{size:"sm",variant:"ghost","aria-pressed":!a,onClick:()=>r(l=>!l),children:a?"Show":"Hide"}):null,t.jsx(Cl,{label:`Hide ${e.title} from Home`,onClick:n})]});return t.jsxs(ue,{title:e.title,aside:i,children:[e.note?t.jsx(G,{tone:"warning",children:e.note}):null,e.stats.length>0?t.jsx(tm,{children:e.stats.map(l=>t.jsx(Er,{label:l.label,value:a?"••••":l.value,note:a?void 0:l.note,tone:a?void 0:l.tone},l.label))}):null,e.rows.length>0?a?t.jsxs("p",{className:"muted",children:[e.rows.length," item",e.rows.length===1?"":"s"," hidden."]}):t.jsx(Ye,{flush:!0,children:t.jsx(at,{children:e.rows.map((l,o)=>t.jsx(Xe,{title:l.title,sub:l.sub,side:l.side?t.jsx("span",{className:l.tone==="critical"?"critical":l.tone==="good"?"good":void 0,children:l.side}):void 0},`${l.title}-${o}`))})}):null]})}const xJ=2e3,vJ={queued:"Getting started.",stopping:"Stopping the gateway. The database stays up.",snapshot:"Taking a copy of what is here now, first.",database:"Putting the database back.",recovery:"Marking this installation as restored.",files:"Putting the files back.",starting:"Starting back up.",encrypt:"Locking it with your passphrase.",done:"Done.",failed:"That did not work.","rolled-back":"That did not work, so everything was put back as it was."};function Sv(e){return vJ[e.phase]??e.detail??e.phase}const jJ=new Set(["done","failed","rolled-back"]);function $I(e){return e!==void 0&&(jJ.has(e.phase)||!!e.finishedAt)}function yJ(e,n=!1){const[s,r]=h.useState(void 0),[a,i]=h.useState(!1),[l,o]=h.useState(null),c=h.useRef(!1);return h.useEffect(()=>{if(!e){r(void 0),i(!1),c.current=!1;return}let u=!1;const d=()=>{n&&c.current||R.backupJob(e).then(m=>{if(!u){if(n&&(u$({step:Sv(m)}),(m.phase==="failed"||m.phase==="rolled-back")&&Yl()),c.current){window.location.reload();return}r(m),o(null),$I(m)&&(u=!0)}}).catch(m=>{if(!u){if(m instanceof xe&&m.status!==0&&m.status<500){n&&Yl(),o(m.message);return}c.current=!0,n||i(!0)}})};d();const f=window.setInterval(d,xJ);return()=>{u=!0,window.clearInterval(f)}},[e,n]),{job:s,away:a,error:l}}function wJ({job:e,away:n,error:s}){return s?t.jsx(ne,{message:s}):n?t.jsx(G,{tone:"warning",role:"status",children:"buddi is restarting. This page comes back on its own when it answers again."}):e?e.phase==="rolled-back"||e.phase==="failed"?t.jsxs(G,{tone:"critical",role:"alert",children:[Sv(e)," ",e.error??""]}):t.jsxs(G,{tone:e.phase==="done"?"good":void 0,role:"status",children:[Sv(e),e.copyLate?" The backup was made, but the copy to your folder did not go through.":"",e.error?` ${e.error}`:""]}):null}function bJ(){var x,y,w,k,N,S,C;const e=me(()=>R.backups(),[],3e4),n=NI(),s=me(()=>R.service(),[]),[r,a]=h.useState(null),[i,l]=h.useState(!1),o=yJ(r,i),[c,u]=h.useState(null),[d,f]=h.useState(!1),[m,p]=h.useState(null),g=((x=e.data)==null?void 0:x.supervised)??((y=s.data)==null?void 0:y.supervised),v=m!==null||g===!1,b=((w=e.data)==null?void 0:w.archives)??[],j=(E,T=!1)=>{f(!0),u(null),l(T),E().then(I=>{var F;T&&I.job&&Vf({kind:"restore",patienceMs:c$}),a(((F=I.job)==null?void 0:F.id)??null)}).catch(I=>{I instanceof xe&&I.status===409?p(I.message):u(I instanceof xe?I.message:String(I))}).finally(()=>{f(!1),e.reload()})};return h.useEffect(()=>{$I(o.job)&&e.reload()},[(k=o.job)==null?void 0:k.phase]),t.jsxs(ie,{gap:"lg",children:[(N=n.data)!=null&&N.active?t.jsx(CY,{view:n.data,onLeft:n.reload}):null,t.jsx(ne,{message:e.error??c}),t.jsx(wJ,{...o}),t.jsx(NJ,{onSaved:()=>e.reload()}),t.jsx(ue,{title:"Backups",panel:!0,actions:t.jsx(A,{variant:"accent",size:"sm",disabled:d,onClick:()=>j(()=>R.startBackup(!0)),children:"Back up now"}),children:t.jsxs(ie,{divided:!0,children:[t.jsx(ue,{children:t.jsxs("p",{className:"ui-card-meta",children:["Kept in ",t.jsx("span",{className:"mono",children:((S=e.data)==null?void 0:S.dir)??"…"}),". A backup holds your agents, conversations, memory and files. It never holds a key."]})}),t.jsx(ue,{children:e.data&&b.length===0?t.jsx(Jn,{icon:"archive",title:"No backups yet",children:"Make one now, or turn on the nightly backup."}):e.data?t.jsxs(Kr,{children:[t.jsx("thead",{children:t.jsxs("tr",{children:[t.jsx("th",{children:"Name"}),t.jsx("th",{children:"Taken"}),t.jsx("th",{children:"Size"}),t.jsx("th",{children:"State"}),t.jsx("th",{})]})}),t.jsx("tbody",{children:b.map(E=>{var T;return t.jsx(SJ,{archive:E,busy:d,database:(T=e.data)==null?void 0:T.database,checkout:v,onVerify:()=>j(()=>R.verifyArchive(E.name)),onRestore:(I,F)=>j(()=>R.restoreArchive({name:E.name,...I?{passphrase:I}:{},...F?{confirm:F}:{}}),!0)},E.name)})})]}):t.jsx(ve,{children:"Loading…"})})]})}),t.jsx(CJ,{}),t.jsx(EJ,{busy:d,checkout:v,checkoutSaid:m,database:(C=e.data)==null?void 0:C.database,onRestore:(E,T,I)=>j(()=>R.restoreUpload(E,{passphrase:T,confirm:I}),!0)})]})}const kJ={enabled:!1,time:"03:00",keep:7,encryptLocal:!0,copyTo:null};function NJ({onSaved:e}){var p;const n=me(()=>R.backupSchedule(),[]),[s,r]=h.useState(null),[a,i]=h.useState(!1),[l,o]=h.useState(null),[c,u]=h.useState(!1);h.useEffect(()=>{n.data&&r(n.data)},[n.data]);const d={...kJ,...s??n.data??{}};if(((p=n.data)==null?void 0:p.supervised)===!1)return t.jsx(ue,{title:"Every night",panel:!0,children:t.jsx(ue,{children:t.jsx(G,{tone:"warning",children:n.data.error??"This installation schedules its own backups."})})});const f=g=>{u(!1),r({...d,...g})},m=()=>{i(!0),o(null),R.setBackupSchedule(d).then(g=>{r(g),u(!0),e()}).catch(g=>o(g instanceof xe?g.message:String(g))).finally(()=>i(!1))};return t.jsx(ue,{title:"Every night",panel:!0,foot:t.jsx(A,{variant:"accent",disabled:a,onClick:m,children:"Save"}),children:t.jsxs(ie,{divided:!0,children:[t.jsx(ue,{children:t.jsxs(ie,{gap:"sm",children:[t.jsx(ne,{message:l}),t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:d.enabled,onChange:g=>f({enabled:g.target.checked})}),t.jsx("span",{children:"Back this buddi up on its own"})]}),t.jsxs(Ns,{children:[t.jsx(re,{label:"At",children:t.jsx("input",{type:"time",value:d.time,onChange:g=>f({time:g.target.value})})}),t.jsx(re,{label:"Keep",hint:"How many to keep before the oldest is thrown away.",children:t.jsx("input",{type:"number",min:1,max:365,value:d.keep,onChange:g=>f({keep:Number(g.target.value)||1})})})]}),t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:d.encryptLocal,onChange:g=>f({encryptLocal:g.target.checked})}),t.jsx("span",{children:"Lock each one with the passphrase"})]})]})}),t.jsx(ue,{children:t.jsxs(ie,{gap:"sm",children:[t.jsx(re,{label:"Also copy to a folder",hint:"A second disk, or a folder that syncs somewhere. Left empty, backups stay on this machine.",children:t.jsx("input",{type:"text",value:d.copyTo??"",placeholder:"/Volumes/backup/buddi",onChange:g=>f({copyTo:g.target.value===""?null:g.target.value})})}),c?t.jsxs(G,{tone:"good",role:"status",children:["Saved.",d.lastRunAt?` Last run ${Ve(d.lastRunAt)}.`:""]}):null]})})]})})}function SJ({archive:e,busy:n,database:s,checkout:r,onVerify:a,onRestore:i}){const[l,o]=h.useState(!1),[c,u]=h.useState(""),[d,f]=h.useState("");return t.jsxs(t.Fragment,{children:[t.jsxs("tr",{children:[t.jsx("td",{className:"mono",children:e.name}),t.jsx("td",{children:Ve(e.createdAt)}),t.jsx("td",{children:ds(e.bytes)}),t.jsxs("td",{children:[e.encrypted?t.jsx(Ee,{tone:"good",children:"locked"}):t.jsx(Ee,{tone:"muted",children:"plain"})," ",e.envelopeOk===!1?t.jsx(Ee,{tone:"critical",children:"damaged"}):null]}),t.jsx("td",{children:t.jsxs(te,{align:"end",children:[t.jsx(A,{size:"sm",disabled:n,onClick:a,children:"Verify"}),t.jsx(A,{size:"sm",variant:"ghost",onClick:()=>o(!l),children:"Restore…"})]})})]}),l?t.jsx("tr",{children:t.jsx("td",{colSpan:5,children:r?t.jsx(G,{tone:"warning",children:TI}):t.jsx(RI,{what:`${e.name}, taken ${Ve(e.createdAt)}, ${ds(e.bytes)}`,database:s,needsPassphrase:e.encrypted,passphrase:c,onPassphrase:u,confirm:d,onConfirm:f,busy:n,onCancel:()=>o(!1),onGo:()=>i(c,d)})})}):null]})}const TI="Restoring needs the packaged installation. In a checkout, run: buddi backup restore <file>";function RI({what:e,database:n,needsPassphrase:s,passphrase:r,onPassphrase:a,confirm:i,onConfirm:l,busy:o,onCancel:c,onGo:u}){const d=n??"",f=d===""?i.trim()!=="":i.trim()===d;return t.jsxs(ie,{gap:"sm",children:[t.jsxs(G,{tone:"warning",children:["This replaces everything in this buddi with ",e,". What is here now is copied first, so a restore that fails puts it back."]}),s?t.jsx(re,{label:"The passphrase this one was locked with",children:t.jsx("input",{type:"password",autoComplete:"off",value:r,onChange:m=>a(m.target.value)})}):null,t.jsx(re,{label:d?`Type ${d} to confirm`:"Type the name of this database to confirm",hint:d?void 0:"The same name buddi shows on the System tab.",children:t.jsx("input",{value:i,onChange:m=>l(m.target.value)})}),t.jsxs(te,{align:"end",children:[t.jsx(A,{variant:"ghost",onClick:c,children:"Cancel"}),t.jsx(A,{variant:"danger",disabled:o||!f||s&&r==="",onClick:u,children:"Restore"})]})]})}function CJ(){const[e,n]=h.useState(null),[s,r]=h.useState(""),[a,i]=h.useState(!1),[l,o]=h.useState(null),[c,u]=h.useState(!1),d=()=>{i(!0),o(null),R.backupPassphrase().then(m=>n(m.passphrase)).catch(m=>o(m instanceof xe?m.message:String(m))).finally(()=>i(!1))},f=()=>{i(!0),o(null),R.setBackupPassphrase(s.trim()).then(m=>{n(m.passphrase),r(""),u(!0)}).catch(m=>o(m instanceof xe?m.message:String(m))).finally(()=>i(!1))};return t.jsx(ue,{title:"The passphrase",panel:!0,children:t.jsxs(ie,{divided:!0,children:[t.jsx(ue,{children:t.jsxs(ie,{gap:"sm",children:[t.jsx(ne,{message:l}),t.jsx("p",{className:"ui-card-meta",children:"This is the only thing that opens an encrypted backup. Write it down."}),e?t.jsx("p",{className:"backup-phrase mono",children:e}):t.jsx(te,{align:"end",children:t.jsx(A,{disabled:a,onClick:d,children:"Show it"})}),c?t.jsx(G,{tone:"good",role:"status",children:"Saved. Backups made from now on use it; older ones keep the one they were made with."}):null]})}),t.jsx(ue,{children:t.jsxs(ie,{gap:"sm",children:[t.jsx(re,{label:"Use my own",hint:"Six words you can read out loud beat a short one nobody can.",children:t.jsx("input",{type:"text",autoComplete:"off",value:s,onChange:m=>{u(!1),r(m.target.value)}})}),t.jsx(te,{align:"end",children:t.jsx(A,{variant:"accent",disabled:a||s.trim()==="",onClick:f,children:"Use this one"})})]})})]})})}function EJ({busy:e,checkout:n,checkoutSaid:s,database:r,onRestore:a}){const[i,l]=h.useState(null),[o,c]=h.useState(""),[u,d]=h.useState(""),[f,m]=h.useState(!1);return n?t.jsx(ue,{title:"Restore from a file",panel:!0,children:t.jsx(ue,{children:t.jsx(G,{tone:"warning",children:s??TI})})}):t.jsx(ue,{title:"Restore from a file",panel:!0,children:t.jsxs(ie,{divided:!0,children:[t.jsx(ue,{children:t.jsxs(ie,{gap:"sm",children:[t.jsx("p",{className:"ui-card-meta",children:"A backup from another buddi, or one you keep somewhere else."}),t.jsxs(Ns,{children:[t.jsx(re,{label:"The backup file",children:t.jsx("input",{type:"file",onChange:p=>{var g;m(!1),l(((g=p.target.files)==null?void 0:g[0])??null)}})}),t.jsx(re,{label:"Its passphrase",hint:"Only if it was locked with one.",children:t.jsx("input",{type:"password",autoComplete:"off",value:o,onChange:p=>c(p.target.value)})})]}),f?null:t.jsx(te,{align:"end",children:t.jsx(A,{variant:"accent",disabled:e||!i,onClick:()=>m(!0),children:"Restore"})})]})}),f&&i?t.jsx(ue,{children:t.jsx(RI,{what:`${i.name}, ${ds(i.size)}`,database:r,needsPassphrase:!1,passphrase:o,onPassphrase:c,confirm:u,onConfirm:d,busy:e,onCancel:()=>m(!1),onGo:()=>a(i,o,u)})}):null]})})}const II="gemini-2.5-pro";function hm(e){return e.replace(/^models\//,"")}const Aw=/(image|tts|audio|live|embedding|vision|robotics|transcribe)/;function PI(e){const n=e.map(hm);let s;for(const r of n){const a=/^gemini-(\d+(?:\.\d+)*)-pro(?:-(.+))?$/.exec(r);if(!a||Aw.test(a[2]??""))continue;const i=a[1].split(".").map(Number),l=(a[2]??"")!=="";(!s||Xh(i,s.version)>0||Xh(i,s.version)===0&&s.preview&&!l)&&(s={id:r,version:i,preview:l})}return(s==null?void 0:s.id)??n.find(r=>r.startsWith("gemini-"))}function MI(e){let n;for(const s of e.map(hm)){const r=/^gemini-(\d+(?:\.\d+)*)-flash(?:-(.+))?$/.exec(s);if(!r||/lite/.test(r[2]??"")||Aw.test(r[2]??""))continue;const a=r[1].split(".").map(Number),i=(r[2]??"")!=="";(!n||Xh(a,n.version)>0||Xh(a,n.version)===0&&n.preview&&!i)&&(n={id:s,version:a,preview:i})}return n==null?void 0:n.id}function DI(e){return/^gemini-[\d.]+-pro(?:-|$)/.test(hm(e))}function AJ(e){return[...new Set(e.map(hm).filter(n=>n.startsWith("gemini-")&&!Aw.test(n)))]}function OI(e){return e.httpStatus===429||e.state==="rate-limited"||e.state==="quota-exhausted"}function Xh(e,n){for(let s=0;s<Math.max(e.length,n.length);s+=1){const r=(e[s]??0)-(n[s]??0);if(r!==0)return r}return 0}function LI(e,n){if(!n||e.kind!=="openai-compatible")return!1;const s=r=>r.replace(/\/+$/,"");return s(e.baseUrl)===s(n)}function $J({embedded:e,account:n}={}){const{data:s,error:r,reload:a,loading:i}=me(()=>R.providerAccounts(),[]),[l,o]=h.useState(!1),[c,u]=h.useState(null),[d,f]=h.useState(""),[m,p]=h.useState(!1),[g,v]=h.useState(!1),[b,j]=h.useState(n??null);h.useEffect(()=>{n&&j(n)},[n]);const x=s==null?void 0:s.accounts.some(S=>{var C;return((C=S.login)==null?void 0:C.state)==="pending"&&S.login.expiresAt&&Date.parse(S.login.expiresAt)>Date.now()});h.useEffect(()=>{if(!x)return;const S=setInterval(a,2e3);return()=>clearInterval(S)},[x,a]);const y=async(S,C)=>{o(!0),u(null),f(""),v(!1);try{const E=await S();return f((E==null?void 0:E.warning)??C),a(),!0}catch(E){return u(E instanceof Error?E.message:"Could not apply change."),a(),!1}finally{o(!1)}},w=(s==null?void 0:s.accounts)??[],k=w.find(S=>S.id===b)??w[0],N=S=>{var C;return LI(S,(C=s==null?void 0:s.gemini)==null?void 0:C.baseUrl)?"Gemini":FI(S)};return t.jsxs(Zn,{embedded:e,title:"Model accounts",lede:"Give each API key or subscription a name, then pick one per agent. An account never falls back to another credential on its own.",children:[t.jsx(ne,{message:r??c}),d&&t.jsx(G,{tone:"good",role:"status",children:d}),g&&t.jsx(G,{role:"status",children:i?"Refreshing account status…":r?"Could not refresh account status. Try again.":"Account status refreshed. This checks saved credentials; it does not renew subscription tokens or test connections."}),!s&&!r&&t.jsx(ve,{children:"Loading accounts…"}),r&&t.jsx(te,{children:t.jsx(A,{onClick:a,children:"Retry"})}),s&&t.jsxs(t.Fragment,{children:[(s.vault.locked||s.vault.kind==="none")&&t.jsx(G,{tone:"warning",children:s.vault.advice||"Run buddi init on the host to configure secure credential storage."}),m&&t.jsx(Ge,{title:"Add an account",onClose:()=>p(!1),children:t.jsx("div",{id:"new-provider-account",children:t.jsx(_J,{accounts:w,codexEnabled:s.codexEnabled,anthropicOAuthEnabled:s.anthropicOAuthEnabled,gemini:s.gemini,busy:l,run:y,onDone:S=>{p(!1),S&&j(S)}})})}),t.jsx(ue,{title:"Accounts",aside:`Secrets live in the ${TJ(s.vault.kind)}; Postgres holds names and assignments only.`,actions:t.jsxs(t.Fragment,{children:[t.jsx(A,{variant:"ghost",size:"sm",disabled:l||i,onClick:()=>{u(null),f(""),v(!0),a()},children:i?"Refreshing…":"Refresh status"}),t.jsx(A,{variant:"accent",size:"sm",disabled:l,"aria-expanded":m,"aria-controls":"new-provider-account",onClick:()=>p(!m),children:"Add account"})]}),panel:!0,flush:!0,children:w.length===0?t.jsx(Jn,{icon:"chip",title:"No accounts yet",children:"Add one to give your agents a model to run on."}):t.jsxs("div",{className:"accounts",children:[t.jsx("nav",{className:"accounts-list","aria-label":"Accounts",children:w.map(S=>t.jsxs("button",{type:"button",className:"accounts-row","aria-pressed":(k==null?void 0:k.id)===S.id,onClick:()=>j(S.id),children:[t.jsx(RJ,{kind:S.kind,auth:S.auth}),t.jsxs("span",{className:"accounts-row-text",children:[t.jsx("span",{className:"accounts-row-name",children:S.label}),Zh(S)?t.jsxs("span",{className:"accounts-row-sub","data-tone":"warning",children:[N(S)," · back at ",$w(Zh(S).until)]}):t.jsxs("span",{className:"accounts-row-sub",children:[N(S)," · ",S.assignedAgents.length===0?"no agents":`${S.assignedAgents.length} agent${S.assignedAgents.length===1?"":"s"}`]})]}),t.jsx(zI,{account:S})]},S.id))}),k?t.jsx(OJ,{account:k,provider:N(k),anthropicOAuthEnabled:s.anthropicOAuthEnabled,busy:l,run:y},`${k.id}:${k.revision}`):null]})})]})]})}function TJ(e){return e==="keychain"?"macOS Keychain":e==="file"?"encrypted file vault":e==="none"?"vault (none configured)":e}function FI(e){return e.kind==="codex"?"ChatGPT subscription":e.kind==="anthropic"?e.auth==="anthropic-oauth"?"Claude subscription":"Anthropic API":e.kind==="openai"?"OpenAI API":e.auth==="device-key"?"Ollama Cloud":bw(e)?"mlxh":"OpenAI-compatible"}function _I(e){return e.detectedContextWindowSource==="mlxh"?mq(e.detectedContextWindowTokens):e.detectedContextWindowSource!=="provider"?"assumed":e.kind==="codex"?"from ChatGPT":"from the provider"}function RJ({kind:e,auth:n}){const s=e==="anthropic"?"A":e==="codex"?"G":e==="openai"?"O":"∞",r=e==="anthropic"?"3":e==="codex"?"2":e==="openai"?"5":"4";return t.jsx("span",{className:"ui-avatar","data-tint":r,"aria-hidden":"true",title:`${e} · ${n}`,children:s})}function IJ(e){return e==="connected"?"good":["rate-limited","quota-exhausted","provider-unavailable"].includes(e)?"warning":"critical"}function Zh(e,n=Date.now()){const s=e.rateLimit;return e.enabled&&e.configured&&s&&Date.parse(s.until)>n?s:null}const PJ=()=>Intl.DateTimeFormat().resolvedOptions().timeZone;function $w(e,n=new Date,s=PJ()){const r=new Date(e),a=i=>i.toLocaleDateString("en-CA",{timeZone:s});return a(r)===a(n)?Xt(r,s):a(r)===a(new Date(n.getTime()+864e5))?`tomorrow at ${Xt(r,s)}`:Xj(r,s)}function zI({account:e,long:n}){const s=Zh(e);if(s){const i=`Rate-limited until ${$w(s.until)}`;return t.jsx("span",{title:i,children:t.jsx(Ee,{tone:"warning",children:n?i:"Rate-limited"})})}const r=e.enabled?e.configured?"good":"warning":void 0,a=e.enabled?e.configured?"Configured":"Needs credential":"Disabled";return t.jsx(Ee,{tone:r,children:a})}function MJ({id:e}){const[n,s]=h.useState(!1),r=()=>{var a;(a=navigator.clipboard)==null||a.writeText(e).then(()=>{s(!0),window.setTimeout(()=>s(!1),1600)}).catch(()=>{})};return t.jsxs("span",{className:"accounts-id",children:[t.jsx("code",{className:"accounts-id-text",children:e}),t.jsx(A,{variant:"ghost",size:"sm",onClick:r,"aria-label":"Copy the id of this account",children:n?"Copied":"Copy"})]})}function DJ({account:e,provider:n}){const s=Zh(e);if(!s)return null;const r=s.provider??n,a=$w(s.until);if(s.scope==="day"){const i=e.assignedAgents,l=i.length===1?i[0]:"its agents",o=s.provider==="ChatGPT",c=o?"This ChatGPT plan has reached its usage limit":s.limit!==null?`${s.freeTier?`${r}'s free tier allows`:`${r} allows this account`} ${s.limit.toLocaleString()} ${s.unit??"requests"} a day`:`${r} says this account has used today's allowance`,u=s.freeTier&&s.provider==="Gemini"?", or turn on billing for the key at aistudio.google.com":"";return t.jsx(G,{tone:"warning",title:c,action:i.length>0?t.jsx(ht,{size:"sm",href:i.length===1?Pt(i[0],"setup","brain"):vt,children:i.length===1?`Change ${i[0]}'s account`:"Change their accounts"}):void 0,children:t.jsxs("p",{children:["It resets ",/^tomorrow/.test(a)?a:`at ${a}`,". Until then buddi doesn't send this account's requests to ",r,", so ",i.length?`${l}'s runs stop with this note`:"a run on it stops with this note"," instead of failing again and again. To keep going ",o?"before then":"today",", ",i.length?`give ${l} another account`:"use another account",u,"."]})})}return t.jsx(G,{tone:"warning",title:`${r} asked buddi to slow down`,children:t.jsxs("p",{children:["It said to wait until ",a,". A run that meets this waits and tries again — up to a minute during a conversation, longer for work in the background."]})})}function Tw(e){return{id:e.id,revision:e.revision,label:e.label,kind:e.kind,auth:e.auth,baseUrl:e.baseUrl,defaultModel:e.defaultModel,enabled:e.enabled,contextWindowTokens:e.contextWindowTokens??null}}function OJ({account:e,provider:n,busy:s,run:r,anthropicOAuthEnabled:a}){const[i,l]=h.useState(!1),[o,c]=h.useState(!1);return t.jsxs("section",{className:"accounts-detail","aria-label":e.label,children:[t.jsxs("div",{className:"ui-card-head",children:[t.jsx("h3",{className:"ui-card-title",children:e.label}),t.jsx(zI,{account:e,long:!0})]}),t.jsx(qt,{items:[{label:"Provider",value:n},{label:"Default model",value:t.jsx("span",{className:"mono",children:e.defaultModel||"—"})},{label:"Context window",value:t.jsx("span",{className:"mono",children:`${(e.contextWindowTokens??e.detectedContextWindowTokens??0).toLocaleString()} tokens${e.contextWindowTokens?"":` (${_I(e)})`}`})},...e.baseUrl?[{label:"Endpoint",value:t.jsx("span",{className:"mono",children:e.baseUrl})}]:[],{label:"Used by",value:e.assignedAgents.length?t.jsx("span",{className:"ui-row",children:e.assignedAgents.map(u=>t.jsx("a",{href:Pt(u,"setup","brain"),children:u},u))}):t.jsxs("span",{className:"ui-row",children:[t.jsx("span",{className:"muted",children:"No agents"}),t.jsx("a",{href:vt,children:"Assign to an agent"})]})},...e.tokenExpiresAt?[{label:"Access token",value:`expires ${ct(e.tokenExpiresAt,Intl.DateTimeFormat().resolvedOptions().timeZone)} (not your subscription renewal date)`}]:[],{label:"ID",value:t.jsx(MJ,{id:e.id})}]}),t.jsx(DJ,{account:e,provider:n}),e.removalPending&&t.jsx(G,{tone:"warning",children:"Removal is pending. Unlock the vault, then retry Remove account."}),e.reconnectRequired&&t.jsxs(G,{tone:"warning",children:["Token refresh did not finish. Reconnect this ",e.kind==="codex"?"ChatGPT":"Claude"," account."]}),e.auth==="anthropic-oauth"&&t.jsx(WI,{account:e,enabled:!!a,busy:s,run:r}),e.kind==="codex"&&t.jsx(UI,{account:e,busy:s,run:r}),e.auth==="device-key"&&t.jsx(BI,{account:e,busy:s,run:r}),t.jsxs(te,{children:[t.jsx(A,{disabled:s||e.removalPending,onClick:()=>l(!0),children:"Edit account"}),t.jsx(A,{disabled:s||e.removalPending,onClick:()=>void r(()=>R.saveProviderAccount({...Tw(e),enabled:!e.enabled}),e.enabled?"Account disabled. Subsequent model calls will stop; already-sent requests cannot be recalled.":"Account enabled."),children:e.enabled?"Disable":"Enable"}),e.kind!=="codex"&&t.jsx(A,{disabled:s||!e.enabled||!e.configured,onClick:()=>void r(()=>R.testProviderAccount(e.id),"Connection test finished."),children:"Test connection"}),t.jsx(A,{variant:"danger",disabled:s||e.assignedAgents.length>0,title:e.assignedAgents.length?"Reassign its agents before removing this account":void 0,onClick:()=>c(!0),children:"Remove account"})]}),e.test&&t.jsxs(t.Fragment,{children:[t.jsxs(G,{role:"status",tone:IJ(e.test.state),children:[t.jsx("p",{children:e.test.message}),e.test.retryAt?t.jsxs("p",{children:["Provider suggested retry time: ",new Date(e.test.retryAt).toLocaleString(),". This is retry advice, not a guaranteed quota reset."]}):["rate-limited","quota-exhausted"].includes(e.test.state)&&t.jsx("p",{children:"The provider did not supply a usable Retry-After time. Reset time is unknown."})]}),t.jsxs("p",{className:"muted",children:["Tested at ",new Date(e.test.checkedAt).toLocaleString(),e.test.httpStatus?` · HTTP ${e.test.httpStatus}`:"",". This is not a quota reset or subscription renewal date."]})]}),i&&t.jsx(Ge,{title:`Edit ${e.label}`,onClose:()=>l(!1),children:t.jsx(LJ,{account:e,busy:s,run:r,onDone:()=>l(!1)})}),o&&t.jsxs(G,{tone:"critical",children:[t.jsxs("p",{children:["Remove “",e.label,"” and its stored credential from Buddi? This does not revoke it at the provider or remove it from backups."]}),t.jsxs(te,{children:[t.jsx(A,{variant:"danger",disabled:s,onClick:()=>void r(()=>R.removeProviderAccount(e.id,e.revision),"Account removed from Buddi."),children:"Confirm removal"}),t.jsx(A,{disabled:s,onClick:()=>c(!1),children:"Cancel"})]})]}),t.jsx(Ot,{summary:"Details",children:t.jsxs("div",{className:"ui-prose muted",children:[e.kind==="codex"?t.jsxs(t.Fragment,{children:[t.jsx("p",{children:"Talks to OpenAI’s Codex backend directly with your ChatGPT sign-in. The credential stays in buddi’s vault; buddi refreshes it and never reads your own Codex login."}),t.jsx("p",{children:"Native tool-step usage reporting is incomplete. Do not use Buddi’s token or API-cost estimates as subscription billing or remaining quota."}),t.jsx("p",{children:"After connecting, assign this account to an agent and send a test message. Model turns use your subscription allowance."})]}):t.jsx("p",{children:"Testing sends a small fixed prompt and may incur a charge. No conversation or files are sent. Configured does not mean verified."}),e.auth==="device-key"&&t.jsx("p",{children:"Ollama Cloud with a device key: buddi made a key pair and keeps it in the vault; ollama.com only ever saw the public half and this computer’s name. Each request to ollama.com is signed with the key, and nothing else is sent with it. Disconnect asks ollama.com to forget the device and removes the key from buddi either way."}),e.auth==="anthropic-oauth"&&t.jsx("p",{children:"Claude subscription sign-in. Tokens remain in Buddi’s vault and refresh before use. Uses your plan’s monthly Agent SDK credits; after them, an API key. Remaining credits are unknown here."}),t.jsx("p",{children:"Subscription login is separate from API-key access."})]})})]})}function UI({account:e,busy:n,run:s}){var r,a,i;return t.jsxs(t.Fragment,{children:[t.jsxs(te,{children:[t.jsx(A,{disabled:n||!e.enabled||e.removalPending||((r=e.login)==null?void 0:r.state)==="pending",onClick:()=>void s(()=>R.codexAccountAction(e.id,"login",e.revision),"Complete device sign-in below."),children:e.configured?"Reconnect ChatGPT":"Connect ChatGPT"}),((a=e.login)==null?void 0:a.state)==="pending"&&t.jsx(A,{disabled:n,onClick:()=>void s(()=>R.codexAccountAction(e.id,"cancel-login",e.revision),"Sign-in cancelled."),children:"Cancel sign-in"}),t.jsx(A,{disabled:n||!e.configured,onClick:()=>void s(()=>R.codexAccountAction(e.id,"logout",e.revision),"Subscription disconnected from Buddi. Your regular Codex login is unchanged."),children:"Disconnect"})]}),((i=e.login)==null?void 0:i.state)==="pending"&&t.jsxs(G,{tone:"accent",role:"status",children:[t.jsxs("p",{children:["Here is your code: ",t.jsx("strong",{children:e.login.userCode}),". Open the link, enter it, and approve buddi on openai.com."]}),e.login.userCode&&t.jsx(Nw,{code:e.login.userCode}),e.login.verificationUrl&&t.jsx(te,{children:t.jsx(ht,{variant:"accent",href:e.login.verificationUrl,target:"_blank",rel:"noreferrer",children:"Open openai.com"})}),e.login.expiresAt&&t.jsxs("p",{className:"muted",children:["The code works until ",Xt(new Date(e.login.expiresAt),Intl.DateTimeFormat().resolvedOptions().timeZone),". Start again after that; this is the sign-in timeout, not your subscription expiry."]})]}),e.login&&e.login.state!=="pending"&&t.jsx("p",{role:"status",className:"muted",children:e.login.message??`Sign-in ${e.login.state}.`})]})}function LJ({account:e,busy:n,run:s,onDone:r,codexEnabled:a,anthropicOAuthEnabled:i}){const[l,o]=h.useState((e==null?void 0:e.label)??""),[c,u]=h.useState((e==null?void 0:e.kind)??"anthropic"),[d,f]=h.useState((e==null?void 0:e.auth)??"api-key"),[m,p]=h.useState((e==null?void 0:e.baseUrl)??""),[g,v]=h.useState((e==null?void 0:e.defaultModel)??"claude-sonnet-5"),[b,j]=h.useState(""),[x,y]=h.useState(e!=null&&e.contextWindowTokens?String(e.contextWindowTokens):""),w=N=>{u(N),f(N==="codex"?"chatgpt":"api-key"),j(""),p(N==="openai-compatible"?"http://localhost:11434/v1":""),v(N==="anthropic"?"claude-sonnet-5":N==="openai"?"gpt-5":"")},k=!l.trim()||!g.trim();return t.jsxs("form",{className:"ui-stack",onSubmit:N=>{N.preventDefault();const S=b;j(""),s(()=>R.saveProviderAccount({...e?{id:e.id,revision:e.revision}:{},label:l,kind:c,auth:d,baseUrl:m,defaultModel:g,enabled:(e==null?void 0:e.enabled)??!0,contextWindowTokens:x.trim()?Number(x):null,...S.trim()?{secret:S}:{}}),"Account saved. Agent model selections are unchanged.").then(C=>{C&&r()})},children:[t.jsxs("fieldset",{disabled:n,className:"ui-fields","data-stack":"true",children:[t.jsx(re,{label:"Account name",children:t.jsx("input",{autoFocus:!0,required:!0,maxLength:100,value:l,onChange:N=>o(N.target.value),placeholder:"Anthropic — Personal"})}),t.jsx(re,{label:"Provider",children:t.jsxs("select",{disabled:!!e,value:d==="anthropic-oauth"?"anthropic-oauth":d==="device-key"?"ollama-cloud":c,onChange:N=>{N.target.value==="anthropic-oauth"?(w("anthropic"),f("anthropic-oauth")):w(N.target.value)},children:[t.jsx("option",{value:"anthropic",children:"Anthropic API"}),t.jsx("option",{value:"openai",children:"OpenAI API"}),t.jsx("option",{value:"openai-compatible",children:"OpenAI-compatible endpoint"}),(e==null?void 0:e.auth)==="device-key"&&t.jsx("option",{value:"ollama-cloud",children:"Ollama Cloud"}),(i||(e==null?void 0:e.auth)==="anthropic-oauth")&&t.jsx("option",{value:"anthropic-oauth",children:"Claude subscription"}),(a||(e==null?void 0:e.kind)==="codex")&&t.jsx("option",{value:"codex",children:"ChatGPT subscription"})]})}),c==="openai-compatible"&&d!=="device-key"&&t.jsxs(t.Fragment,{children:[t.jsx(re,{label:"API base URL",hint:"Include the API path, such as /v1 or /api/v1. Conversation data will be sent to this endpoint. The model must support tool calling to use agent tools.",children:t.jsx("input",{required:!0,type:"url",value:m,onChange:N=>p(N.target.value)})}),t.jsx(re,{label:"Authentication",children:t.jsxs("select",{disabled:!!e,value:d,onChange:N=>{f(N.target.value),j("")},children:[t.jsx("option",{value:"api-key",children:"API key"}),t.jsx("option",{value:"none",children:"No key (local/self-hosted)"})]})})]}),t.jsx(te,{valign:"end",children:t.jsx(kw,{accountId:e!=null&&e.configured&&e.enabled?e.id:void 0,label:"Default model",value:g,onChange:v,disabled:n},`${e==null?void 0:e.id}:${e==null?void 0:e.revision}`)}),t.jsx(re,{label:"Context window",hint:bw(e)?"mlxh refuses a prompt over its max_prompt_tokens, and its model manager does not report the number, so buddi assumes 8,192. After `mlxh config max_prompt_tokens 40960`, enter the same number here.":"Tokens this endpoint actually serves. Leave blank unless you run the model yourself and set a window of your own — a conversation is ended once its history would fill half of this.",children:t.jsx("input",{type:"number",inputMode:"numeric",min:8e3,max:2e6,step:1e3,value:x,placeholder:e!=null&&e.detectedContextWindowTokens?`${e.detectedContextWindowTokens} (${_I(e)})`:"assumed from the model",onChange:N=>y(N.target.value)})}),c==="codex"&&t.jsx("p",{className:"muted",children:"Pick a model from the list once the account is connected."}),d==="anthropic-oauth"&&t.jsx("p",{className:"muted",children:"Save this account, then choose Connect Claude. You will approve in your browser and paste the authorization code here, not in chat. No existing agent assignment changes."}),d==="api-key"&&t.jsx(re,{label:e?"Replacement API key (leave blank to keep)":"API key",children:t.jsx("input",{type:"password",autoComplete:"new-password",spellCheck:!1,value:b,onChange:N=>j(N.target.value)})}),e&&t.jsx("p",{className:"muted",children:"Saving changes stops an active run at its next model call. Start a new turn afterward. Changing the default model does not change existing agent assignments."}),t.jsxs(te,{align:"end",children:[t.jsx(A,{onClick:r,children:"Cancel"}),t.jsx(A,{type:"submit",variant:"accent",disabled:k,children:"Save account"})]})]}),k&&t.jsx("p",{className:"muted",children:"Enter an account name and default model to enable Save account. The example name is a placeholder."})]})}function BI({account:e,busy:n,run:s}){var o;const r=((o=e.login)==null?void 0:o.state)==="pending"&&e.login.attemptId?e.login:null,a=h.useRef(s);a.current=s,h.useEffect(()=>{if(!(r!=null&&r.attemptId))return;let c=!1,u=!1;const d=setInterval(()=>{c||u||(u=!0,R.ollamaPoll(e.id,r.attemptId).then(f=>{c||f.state==="waiting"||(c=!0,f.state==="connected"?a.current(async()=>{},`Connected as ${f.username}, device ${f.deviceName}.`):a.current(async()=>{throw new Error(f.message)},""))}).catch(()=>{}).finally(()=>{u=!1}))},2e3);return()=>{c=!0,clearInterval(d)}},[e.id,r==null?void 0:r.attemptId]);const i=()=>{const c=typeof window.open=="function"?window.open("","_blank"):null;s(async()=>{try{const u=await R.ollamaConnect(e.id,e.revision);return c&&(c.location.href=u.verificationUrl),u}catch(u){throw c==null||c.close(),u}},"Press Connect on the ollama.com page. This card notices on its own.")},l=e.device;return t.jsxs(t.Fragment,{children:[l&&t.jsx("p",{className:"muted",role:"status",children:l.connectedAt?`Connected as ${l.username||"an ollama.com account"}, device ${l.deviceName}.`:`Not connected yet. Device ${l.deviceName}.`}),t.jsxs(te,{children:[t.jsx(A,{disabled:n||!e.enabled||e.removalPending||!!r,onClick:i,children:e.configured?"Reconnect Ollama":"Connect Ollama"}),t.jsx(A,{disabled:n||!l||e.removalPending,onClick:()=>void s(async()=>({warning:(await R.ollamaDisconnect(e.id,e.revision)).note}),"Disconnected."),children:"Disconnect"})]}),r&&t.jsxs(G,{tone:"accent",role:"status",children:[t.jsxs("p",{children:[t.jsx("a",{href:r.verificationUrl,target:"_blank",rel:"noreferrer",children:"Open the ollama.com page"})," and press Connect. Sign in there first if it asks."]}),t.jsxs("p",{className:"muted",children:["buddi stops waiting at ",r.expiresAt&&Xt(new Date(r.expiresAt),Intl.DateTimeFormat().resolvedOptions().timeZone),"."]})]})]})}function WI({account:e,enabled:n,busy:s,run:r}){var l,o,c,u,d;const[a,i]=h.useState("");return h.useEffect(()=>{i("")},[(l=e.login)==null?void 0:l.attemptId,(o=e.login)==null?void 0:o.state]),t.jsxs(t.Fragment,{children:[!n&&t.jsx(G,{tone:"warning",children:"Claude subscription sign-in is turned off on this host."}),t.jsxs(te,{children:[t.jsx(A,{disabled:s||!n||!e.enabled||e.removalPending||((c=e.login)==null?void 0:c.state)==="pending",onClick:()=>void r(()=>R.anthropicAccountAction(e.id,"login",e.revision),"Open the Claude consent link below. Existing credentials remain until sign-in succeeds."),children:e.configured?"Reconnect Claude":"Connect Claude"}),((u=e.login)==null?void 0:u.state)==="pending"&&t.jsx(A,{disabled:s,onClick:()=>{i(""),r(()=>R.anthropicAccountAction(e.id,"cancel-login",e.revision),"Claude sign-in cancelled.")},children:"Cancel sign-in"}),t.jsx(A,{disabled:s||!e.configured||e.removalPending,onClick:()=>{i(""),r(()=>R.anthropicAccountAction(e.id,"logout",e.revision),"Claude disconnected from Buddi. This does not revoke access at Anthropic.")},children:"Disconnect Claude"})]}),((d=e.login)==null?void 0:d.state)==="pending"&&t.jsxs("form",{className:"ui-notice","data-tone":"accent",onSubmit:f=>{f.preventDefault();const m=a;i(""),r(()=>R.anthropicAccountAction(e.id,"complete-login",e.revision,{attemptId:e.login.attemptId,code:m}),"Claude connected. Edit account to load its model list, then assign it to an agent.")},children:[t.jsx("p",{children:t.jsx("a",{href:e.login.verificationUrl,target:"_blank",rel:"noreferrer",children:"Open Claude consent page"})}),t.jsxs("p",{className:"muted",children:["Use the Claude account you want to connect. Paste the entire code including #state. This attempt expires at ",e.login.expiresAt&&Xt(new Date(e.login.expiresAt),Intl.DateTimeFormat().resolvedOptions().timeZone),"; restarting Buddi also ends it."]}),t.jsx(re,{label:"Claude authorization code",children:t.jsx("input",{type:"password",autoComplete:"off",spellCheck:!1,maxLength:8192,value:a,onChange:f=>i(f.target.value),disabled:s})}),t.jsx(te,{align:"end",children:t.jsx(A,{type:"submit",variant:"accent",disabled:s||!a.trim(),children:"Complete Claude sign-in"})})]})]})}const Gp={anthropic:"claude-sonnet-5",openai:"gpt-5",codex:"gpt-5.5"};function qp(e,n,s){return Cv(e==="codex"?"ChatGPT subscription":e==="anthropic"?n==="anthropic-oauth"?"Claude subscription":"Anthropic API":e==="openai"?"OpenAI API":n==="device-key"?"Ollama Cloud":"Local endpoint",s)}function Cv(e,n){const s=new Set(n.map(r=>r.trim().toLowerCase()));if(!s.has(e.toLowerCase()))return e;for(let r=2;r<100;r+=1)if(!s.has(`${e} ${r}`.toLowerCase()))return`${e} ${r}`;return e}const FJ="That key was refused. Check it and paste it again.";function _J({accounts:e,busy:n,run:s,onDone:r,codexEnabled:a,anthropicOAuthEnabled:i,gemini:l}){const o=e.map(Y=>Y.label),[c,u]=h.useState(null),[d,f]=h.useState("anthropic"),[m,p]=h.useState("api-key"),[g,v]=h.useState(()=>qp("anthropic","api-key",o)),[b,j]=h.useState(!1),[x,y]=h.useState(""),[w,k]=h.useState(""),[N,S]=h.useState(null),[C,E]=h.useState(!1),[T,I]=h.useState(""),[F,D]=h.useState(""),[$,L]=h.useState(!1),[O,M]=h.useState(!1),[P,H]=h.useState(!1),[U,V]=h.useState(void 0),z=(Y,Ne,we=!1)=>{f(Y),p(Ne),k(""),S(null),I(""),D(""),L(!1),M(we),H(!1),V(void 0),y(we?"":Y==="openai-compatible"?"http://localhost:11434/v1":""),b||v(we?qp(Y,"device-key",o):qp(Y,Ne,o))},X=Y=>{z("openai-compatible",Y?"api-key":"device-key",!0),Y&&R.ollama().then(Ne=>y(Ne.cloudBaseUrl)).catch(()=>{})},K=()=>{l&&(z("openai-compatible","api-key"),H(!0),y(l.baseUrl),b||v(Cv("Gemini",o)))},ee=()=>{z("openai-compatible","none"),V(null),b||v(Cv("mlxh",o)),R.mlxh().then(Y=>{V(Y),y(Y.baseUrl)}).catch(()=>V(void 0))},ce=U!==void 0,pe=c?e.find(Y=>Y.id===c):void 0;if(c)return pe?t.jsx(zJ,{account:pe,busy:n,run:s,anthropicOAuthEnabled:i,onDone:()=>r(pe.id)}):t.jsx(ve,{children:"Saving…"});const oe=d==="openai-compatible"&&m!=="device-key",Re=d==="codex"||m==="anthropic-oauth"||m==="device-key",Oe=!Re&&(m==="none"||w.trim()!=="")&&(!oe||x.trim()!==""),Je=async()=>{var Y,Ne;E(!0),I("");try{const we=await R.probeModels({kind:d,auth:m,...oe?{baseUrl:x}:{},...w.trim()?{secret:w}:{}});S(we),F||D(((Y=we.models.find(fe=>fe.isDefault))==null?void 0:Y.id)??((Ne=we.models[0])==null?void 0:Ne.id)??"")}catch(we){I(we instanceof Error?we.message:"Could not load models. You can still enter a custom model.")}finally{E(!1)}},W=F.trim(),se=!g.trim()||oe&&!x.trim()||oe&&!P&&!ce&&!W||P&&!w.trim()||ce&&!(U!=null&&U.running);return t.jsxs("form",{className:"ui-stack",onSubmit:Y=>{var ge;Y.preventDefault();const Ne=w;k("");let we=W||(ce?wv(U)??((ge=U==null?void 0:U.models[0])==null?void 0:ge.id):void 0)||(m==="device-key"?_d:Gp[d])||"claude-sonnet-5",fe;(async()=>{if(P){we=II;try{const Be=(await R.probeModels({kind:"openai-compatible",auth:"api-key",baseUrl:x,secret:Ne})).models.map(Ue=>Ue.id);we=PI(Be)??we,fe=DI(we)?MI(Be):void 0}catch{}}let Pe,je=!1;!await s(async()=>{if(Pe=await R.saveProviderAccount({label:g,kind:d,auth:m,baseUrl:x,defaultModel:we,enabled:!0,...Ne.trim()?{secret:Ne}:{}}),m!=="api-key")return Pe;const ke=await R.testProviderAccount(Pe.id);if(ke.state==="connected")return Pe;if(ny(ke)){const Be=Pe.id;Pe=void 0;try{const Ue=(await R.providerAccounts()).accounts.find(ut=>ut.id===Be);Ue&&await R.removeProviderAccount(Be,Ue.revision)}catch{}throw new Error(FJ)}if(P&&fe&&OI(ke)){const Be=(await R.providerAccounts()).accounts.find(Ue=>Ue.id===Pe.id);if(Be&&(await R.saveProviderAccount({...Tw(Be),defaultModel:fe}),(await R.testProviderAccount(Pe.id)).state==="connected"))return{...Pe,warning:`Account saved. Google's free tier has no Pro allowance, so it starts on ${fe}; turn on billing at Google to use Pro.`}}return je=!0,{...Pe,warning:`Account saved. ${ke.message}`}},"Account saved.")||!Pe||(P||ce||je?u(Pe.id):W||!Re?r(Pe.id):u(Pe.id))})()},children:[t.jsxs("fieldset",{disabled:n,className:"ui-fields","data-stack":"true",children:[t.jsx(re,{label:"Provider",children:t.jsxs("select",{value:m==="anthropic-oauth"?"anthropic-oauth":O?"ollama-cloud":P?"gemini":ce?"mlxh":d,onChange:Y=>{if(Y.target.value==="anthropic-oauth")z("anthropic","anthropic-oauth");else if(Y.target.value==="gemini")K();else if(Y.target.value==="mlxh")ee();else if(Y.target.value==="ollama-cloud")z("openai-compatible","device-key",!0);else{const Ne=Y.target.value;z(Ne,Ne==="codex"?"chatgpt":"api-key")}},children:[t.jsx("option",{value:"anthropic",children:"Anthropic API"}),t.jsx("option",{value:"openai",children:"OpenAI API"}),l&&t.jsx("option",{value:"gemini",children:"Gemini (Google AI key)"}),t.jsx("option",{value:"ollama-cloud",children:"Ollama Cloud"}),t.jsx("option",{value:"mlxh",children:"mlxh, local MLX models on this Mac"}),t.jsx("option",{value:"openai-compatible",children:"OpenAI-compatible endpoint (Ollama, OpenRouter, vLLM…)"}),i&&t.jsx("option",{value:"anthropic-oauth",children:"Claude subscription"}),a&&t.jsx("option",{value:"codex",children:"ChatGPT subscription"})]})}),t.jsx(re,{label:"Account name",hint:"Proposed from the provider. Change it to anything you will recognise.",children:t.jsx("input",{autoFocus:!0,required:!0,maxLength:100,value:g,onChange:Y=>{v(Y.target.value),j(!0)},placeholder:"Anthropic — Personal"})}),O&&t.jsxs("label",{className:"ui-row",children:[t.jsx("input",{type:"checkbox",checked:m==="api-key",onChange:Y=>X(Y.target.checked)}),t.jsx("span",{children:"Use a key instead"})]}),oe&&t.jsxs(t.Fragment,{children:[t.jsx(re,{label:"API base URL",hint:"Include the API path, such as /v1 or /api/v1. Conversation data will be sent to this endpoint. The model must support tool calling to use agent tools.",children:t.jsx("input",{required:!0,type:"url",value:x,onChange:Y=>{y(Y.target.value),S(null)}})}),!P&&!ce&&t.jsx(re,{label:"Authentication",children:t.jsxs("select",{value:m,onChange:Y=>{p(Y.target.value),k(""),S(null)},children:[t.jsx("option",{value:"api-key",children:"API key"}),t.jsx("option",{value:"none",children:"No key (local/self-hosted)"})]})})]}),m==="api-key"&&t.jsx(re,{label:"API key",hint:"Stored in the vault, never shown again.",children:t.jsx("input",{type:"password",autoComplete:"new-password",spellCheck:!1,value:w,onChange:Y=>{k(Y.target.value),S(null)}})}),ce?U===null?t.jsx("p",{className:"muted",children:"Looking for mlxh on this computer…"}):U!=null&&U.running?t.jsxs(ie,{gap:"sm",children:[t.jsxs("p",{className:"muted",children:["mlxh answers with ",U.models.length===1?"one model":`${U.models.length} models`,". No key: mlxh takes any. buddi starts on ",wv(U)??"the first","; the next step lists the rest. A model that is not loaded takes up to a minute on its first answer."]}),U.models.some(Y=>Y.kind==="image")?t.jsxs("p",{className:"muted",children:[U.models.filter(Y=>Y.kind==="image").map(Y=>Y.id).join(", "),": ",cI,"."]}):null]}):t.jsx(G,{tone:"warning",children:oI((U==null?void 0:U.baseUrl)??x)}):P&&l?t.jsxs("p",{className:"muted",children:[t.jsx("a",{href:l.keyUrl,target:"_blank",rel:"noreferrer",children:"Get a key at aistudio.google.com"}),". buddi picks the newest Gemini Pro your key can reach; the next step lists the rest."]}):Re?t.jsx("p",{className:"muted",children:d==="codex"?"You will connect your ChatGPT subscription on the next step, with a code you enter on openai.com, and pick a model then.":m==="device-key"?"You will connect on the next step: ollama.com opens, you press Connect, and no key is typed. Free to start.":"You will connect your Claude subscription on the next step, in your browser, and pick a model then."}):t.jsxs("div",{className:"ui-field",children:[t.jsx("span",{className:"ui-field-label",children:"Model"}),N?t.jsxs("div",{className:"ui-row",children:[t.jsxs("select",{"aria-label":"Model",value:$?"__custom__":F,onChange:Y=>{Y.target.value==="__custom__"?(L(!0),D("")):(L(!1),D(Y.target.value))},children:[N.models.map(Y=>t.jsxs("option",{value:Y.id,children:[Y.name===Y.id?Y.id:`${Y.name} — ${Y.id}`,Y.isDefault?" (provider default)":"",Y.thinks?" · thinks":""]},Y.id)),t.jsx("option",{value:"__custom__",children:"Custom model…"})]}),t.jsx(A,{size:"sm",disabled:C||!Oe,onClick:()=>void Je(),children:C?"Loading…":"Reload"})]}):t.jsxs("div",{className:"ui-row",children:[t.jsx(A,{disabled:C||!Oe,onClick:()=>void Je(),children:C?"Loading models…":"Load models"}),oe?t.jsx("span",{className:"muted",children:"Ask the endpoint what it serves."}):t.jsxs("span",{className:"muted",children:["Optional now: ",Gp[d]," is used until you pick one."]})]}),$||oe&&!N?t.jsx("input",{"aria-label":"Custom model",required:oe,maxLength:150,value:F,onChange:Y=>D(Y.target.value),placeholder:oe?"qwen3:8b":Gp[d]}):null,T?t.jsx("span",{className:"ui-field-hint critical",role:"alert",children:T}):null,N!=null&&N.truncated?t.jsx("span",{className:"ui-field-hint",children:"Showing the first part of the provider’s list."}):null]}),t.jsxs(te,{align:"end",children:[t.jsx(A,{onClick:()=>r(),children:"Cancel"}),t.jsx(A,{type:"submit",variant:"accent",disabled:se,children:"Save account"})]})]}),se&&!ce&&t.jsxs("p",{className:"muted",children:["Enter an account name",P?" and a key":oe?", an endpoint and a model":""," to enable Save account."]})]})}function zJ({account:e,busy:n,run:s,anthropicOAuthEnabled:r,onDone:a}){const[i,l]=h.useState(e.defaultModel),o=e.configured;return t.jsxs(ie,{gap:"lg",children:[t.jsxs(G,{tone:"good",children:["Saved “",e.label,"”."]}),e.auth==="anthropic-oauth"&&!o?t.jsx(WI,{account:e,enabled:!!r,busy:n,run:s}):null,e.kind==="codex"&&!o?t.jsx(UI,{account:e,busy:n,run:s}):null,e.auth==="device-key"&&!o?t.jsx(BI,{account:e,busy:n,run:s}):null,o?t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"ui-page-lede",children:"Pick the model this account offers by default. An agent can still choose another when you assign it."}),t.jsx(te,{valign:"end",children:t.jsx(kw,{accountId:e.enabled?e.id:void 0,label:"Default model",value:i,onChange:l,disabled:n},`${e.id}:${e.revision}`)}),t.jsxs(te,{align:"end",children:[t.jsx(A,{onClick:a,children:"Skip for now"}),t.jsx(A,{variant:"accent",disabled:n||!i.trim(),onClick:()=>{if(i===e.defaultModel){a();return}s(()=>R.saveProviderAccount({...Tw(e),defaultModel:i}),"Default model saved.").then(c=>{c&&a()})},children:"Done"})]})]}):t.jsx(te,{children:t.jsx(A,{onClick:a,children:"Finish later"})})]})}const sS=new Set(["co.uk","org.uk","me.uk","ltd.uk","plc.uk","net.uk","sch.uk","ac.uk","gov.uk","nhs.uk","police.uk","mod.uk","gov.ie","co.at","or.at","ac.at","gv.at","com.pl","net.pl","org.pl","info.pl","biz.pl","edu.pl","gov.pl","waw.pl","com.es","org.es","nom.es","gob.es","edu.es","com.pt","org.pt","gov.pt","edu.pt","com.gr","org.gr","net.gr","edu.gr","gov.gr","com.cy","org.cy","net.cy","gov.cy","ac.cy","com.mt","org.mt","net.mt","edu.mt","gov.mt","co.hu","org.hu","info.hu","com.ro","org.ro","info.ro","nom.ro","co.rs","org.rs","edu.rs","gov.rs","in.rs","com.ua","org.ua","net.ua","gov.ua","edu.ua","in.ua","kiev.ua","com.ru","org.ru","net.ru","msk.ru","spb.ru","co.no","priv.no","com.hr","from.hr","iz.hr","name.hr","co.it","gov.it","edu.it","asso.fr","com.fr","gouv.fr","nom.fr","prd.fr","tm.fr","co.je","net.je","org.je","co.gg","net.gg","org.gg","co.im","net.im","org.im","gc.ca","on.ca","qc.ca","bc.ca","ab.ca","com.mx","org.mx","net.mx","edu.mx","gob.mx","ny.us","ca.us","tx.us","fl.us","wa.us","k12.ca.us","lib.ca.us","com.br","net.br","org.br","gov.br","edu.br","art.br","blog.br","eco.br","emp.br","ind.br","inf.br","tv.br","app.br","dev.br","com.ar","org.ar","net.ar","gob.ar","edu.ar","int.ar","tur.ar","com.co","org.co","net.co","edu.co","gov.co","nom.co","com.pe","org.pe","net.pe","gob.pe","edu.pe","nom.pe","com.ve","org.ve","net.ve","gob.ve","co.ve","com.uy","org.uy","net.uy","gub.uy","edu.uy","com.ec","org.ec","net.ec","gob.ec","edu.ec","fin.ec","com.bo","org.bo","net.bo","gob.bo","edu.bo","com.py","org.py","net.py","gov.py","edu.py","gob.cl","gov.cl","co.cl","com.do","org.do","net.do","gob.do","edu.do","com.gt","org.gt","net.gt","gob.gt","edu.gt","co.cr","or.cr","fi.cr","go.cr","ac.cr","com.pa","org.pa","net.pa","gob.pa","com.sv","org.sv","gob.sv","edu.sv","com.ni","org.ni","gob.ni","com.hn","org.hn","net.hn","gob.hn","com.cu","org.cu","net.cu","gob.cu","com.jm","org.jm","net.jm","gov.jm","com.tt","org.tt","net.tt","gov.tt","co.tt","com.pr","org.pr","net.pr","gov.pr","com.au","net.au","org.au","edu.au","gov.au","asn.au","id.au","co.nz","net.nz","org.nz","ac.nz","govt.nz","school.nz","geek.nz","gen.nz","kiwi.nz","maori.nz","co.jp","ne.jp","or.jp","ac.jp","ad.jp","ed.jp","go.jp","gr.jp","lg.jp","com.cn","net.cn","org.cn","gov.cn","edu.cn","ac.cn","com.hk","net.hk","org.hk","edu.hk","gov.hk","idv.hk","com.tw","net.tw","org.tw","edu.tw","gov.tw","idv.tw","co.kr","or.kr","ne.kr","go.kr","ac.kr","re.kr","pe.kr","co.in","net.in","org.in","firm.in","gen.in","ind.in","ac.in","edu.in","gov.in","res.in","nic.in","com.sg","net.sg","org.sg","edu.sg","gov.sg","per.sg","com.my","net.my","org.my","edu.my","gov.my","name.my","co.id","or.id","ac.id","go.id","web.id","my.id","biz.id","net.id","sch.id","co.th","in.th","ac.th","go.th","or.th","net.th","com.vn","net.vn","org.vn","edu.vn","gov.vn","com.ph","net.ph","org.ph","edu.ph","gov.ph","com.pk","net.pk","org.pk","edu.pk","gov.pk","com.bd","org.bd","net.bd","gov.bd","edu.bd","com.lk","org.lk","gov.lk","edu.lk","com.np","org.np","gov.np","edu.np","com.kh","org.kh","gov.kh","com.mm","org.mm","gov.mm","com.fj","org.fj","gov.fj","ac.fj","com.pg","org.pg","gov.pg","ac.pg","com.kz","org.kz","gov.kz","edu.kz","com.tr","net.tr","org.tr","gov.tr","edu.tr","gen.tr","biz.tr","info.tr","av.tr","bel.tr","k12.tr","co.il","org.il","net.il","ac.il","gov.il","muni.il","com.sa","net.sa","org.sa","gov.sa","edu.sa","med.sa","co.ae","net.ae","org.ae","gov.ae","ac.ae","com.qa","org.qa","net.qa","gov.qa","edu.qa","com.kw","org.kw","net.kw","gov.kw","edu.kw","com.bh","org.bh","net.bh","gov.bh","edu.bh","com.om","org.om","net.om","gov.om","co.om","com.jo","org.jo","net.jo","gov.jo","edu.jo","com.lb","org.lb","net.lb","gov.lb","edu.lb","com.eg","org.eg","net.eg","gov.eg","edu.eg","eun.eg","co.ir","ac.ir","gov.ir","org.ir","net.ir","co.za","org.za","net.za","gov.za","ac.za","web.za","edu.za","nom.za","com.ng","org.ng","net.ng","gov.ng","edu.ng","name.ng","co.ke","or.ke","ne.ke","go.ke","ac.ke","sc.ke","co.tz","or.tz","ne.tz","go.tz","ac.tz","co.ug","or.ug","ne.ug","go.ug","ac.ug","com.gh","org.gh","gov.gh","edu.gh","co.ma","net.ma","org.ma","gov.ma","ac.ma","press.ma","com.tn","org.tn","gov.tn","ens.tn","fin.tn","com.dz","org.dz","net.dz","gov.dz","edu.dz","com.et","org.et","gov.et","edu.et","co.zw","org.zw","gov.zw","ac.zw","co.zm","org.zm","gov.zm","ac.zm","co.bw","org.bw","ac.bw","com.na","org.na","co.na","co.mz","org.mz","gov.mz","com.cm","co.cm","net.cm","gov.cm","com.sn","org.sn","edu.sn","gouv.sn","com.ci","co.ci","or.ci","go.ci","ac.ci","com.tg","gouv.tg","co.rw","gov.rw","ac.rw","*.ck","*.er","*.fk","*.jm","*.kh","*.mm","*.np","*.pg","*.bd","github.io","githubusercontent.com","gitlab.io","bitbucket.io","pages.dev","workers.dev","trycloudflare.com","vercel.app","vercel.dev","now.sh","netlify.app","netlify.com","herokuapp.com","herokussl.com","cloudfront.net","amazonaws.com","s3.amazonaws.com","elasticbeanstalk.com","awsapprunner.com","amplifyapp.com","azurewebsites.net","azurestaticapps.net","cloudapp.net","azureedge.net","azurefd.net","blob.core.windows.net","trafficmanager.net","appspot.com","firebaseapp.com","web.app","run.app","cloudfunctions.net","blogspot.com","fly.dev","onrender.com","up.railway.app","deno.dev","deno.net","glitch.me","repl.co","replit.dev","replit.app","ngrok.io","ngrok.app","ngrok-free.app","ngrok.dev","ngrok-free.dev","surge.sh","readthedocs.io","myshopify.com","wixsite.com","webflow.io","framer.app","framer.website","ondigitalocean.app","digitaloceanspaces.com","supabase.co","fastly.net","global.ssl.fastly.net","edgecompute.app","duckdns.org","dyndns.org","ddns.net","no-ip.org","hopto.org","zapto.org","eu.org","us.org","neocities.org","codeberg.page","sourceforge.io","pythonanywhere.com","streamlit.app","hf.space"]);function UJ(e){const n=e.toLowerCase().replace(/\.$/,"");if(!n.includes(".")||sS.has(n))return!0;const s=n.slice(n.indexOf(".")+1);return sS.has(`*.${s}`)}function BJ(e){return typeof e=="string"&&e.includes("*")}function WJ(e){const n=/^(https?):\/\/([^/?#@\s]+)(?:[/?#]\S*)?$/i.exec(e.trim());if(n===null)return{ok:!1,reason:"invalid"};const[,s,r]=n;if(!r.startsWith("*.")||r.slice(2).includes("*"))return{ok:!1,reason:"placement"};let a;try{a=new URL(`${s.toLowerCase()}://${r.slice(2)}`)}catch{return{ok:!1,reason:"invalid"}}const i=a.hostname;return i===""||i.startsWith("[")||/^[\d.]+$/.test(i)||i.startsWith(".")||i.includes("..")?{ok:!1,reason:"invalid"}:UJ(i)?{ok:!1,reason:"public-suffix"}:{ok:!0,value:{pattern:`${a.protocol}//*.${a.host}`,protocol:a.protocol,suffix:i,port:a.port}}}const rS=["every-time","first-time","pre-approved"];function HI(e){const n=rS.indexOf(e);return rS.slice(0,n<0?1:n+1)}function Yi(e){return e.endsWith(".account")}const HJ="Stored, not usable until it has a binding.";function KJ(e){return e==="browser.field"?"the origin of the site that holds the field, e.g. https://en.wikipedia.org or *.wikimedia.org":e==="browser.form.data"?"the origin, then the field name — e.g. https://localhost:8443 card-number":e==="browser.native.type"?"the app’s bundle id, e.g. com.bank.app":e==="http.header"?"the host, then the header name — e.g. localhost:9200 Authorization":e==="http.url"?"the plugin, then the host — e.g. calendar calendar.google.com":e==="http.basic"?"the plugin, then the host — e.g. calendar *.icloud.com":e==="http.bearer"?"the plugin, then the host — e.g. calendar www.googleapis.com":e==="developer.env"?"the workspace, then the variable name — e.g. cour des comptes ADMIN_PASSWORD":Yi(e)?"the account id, e.g. acct-1":'the place, as JSON — e.g. {"host":"localhost","header":"Authorization"}'}const KI={"browser.form.data":{hint:"an origin, then the field name",build:(e,n)=>({origin:e,field:n})},"http.header":{hint:"a host, then the header name",build:(e,n)=>({host:e,header:n})},"http.url":{hint:"a plugin, then the host",build:(e,n)=>({plugin:e,host:n})},"http.basic":{hint:"a plugin, then the host",build:(e,n)=>({plugin:e,host:n})},"http.bearer":{hint:"a plugin, then the host",build:(e,n)=>({plugin:e,host:n})},"developer.env":{hint:"a workspace, then the variable name",build:(e,n)=>({workspace:e,variable:n})}},VJ="A wildcard may only stand for the leftmost part of a site, like *.wikimedia.org.",GJ=e=>`That is a public suffix; ${e} would match every site.`,aS="Give the site as an origin, like https://en.wikipedia.org.";function iS(e){const n=/^[a-z][a-z0-9+.-]*:\/\//i.test(e)?e:["https:","//",e].join("");if(BJ(e)){const s=WJ(n);if(s.ok)return{ok:!0,target:s.value.pattern};if(s.reason==="placement")return{ok:!1,error:VJ};if(s.reason==="public-suffix"){const r=n.replace(/^[a-z][a-z0-9+.-]*:\/\//i,"").replace(/[/?#:].*$/,"").toLowerCase();return{ok:!1,error:GJ(r)}}return{ok:!1,error:aS}}try{const s=new URL(n);if(s.origin==="null"||s.protocol!=="https:"&&s.protocol!=="http:")throw new Error("not an origin");return{ok:!0,target:s.origin}}catch{return{ok:!1,error:aS}}}function qJ(e){const n=e.search(/\s\S+\s*$/);if(n<=0)return null;const s=e.slice(n).trim(),r=e.slice(0,n).trim();return r&&s?[r,s]:null}function YJ(e,n){const s=n.trim();if(s==="")return{ok:!1,error:"Give the exact place this value may go."};if(s.startsWith("{"))try{const i=JSON.parse(s);return i!==null&&typeof i=="object"&&!Array.isArray(i)?{ok:!0,target:i}:{ok:!1,error:'A target in JSON is an object, like {"host":"localhost","header":"Authorization"}.'}}catch{return{ok:!1,error:"That opens like JSON but does not parse."}}if(e==="browser.field")return iS(s);if(e==="browser.native.type"||Yi(e))return{ok:!0,target:s};const r=KI[e];if(r===void 0)return{ok:!0,target:s};const a=qJ(s);if(a===null)return{ok:!1,error:`${e} needs both: ${r.hint}.`};if(e==="browser.form.data"){const i=iS(a[0]);return i.ok?{ok:!0,target:r.build(i.target,a[1])}:i}return{ok:!0,target:r.build(a[0],a[1])}}function JJ(e){if(typeof e=="string")return e;try{return JSON.stringify(e)??""}catch{return""}}function VI(e,n){if(typeof n=="string")return n;if(n!==null&&typeof n=="object"&&!Array.isArray(n)){const s=n,r=KI[e];if(r!==void 0){const a=Object.keys(r.build("a","b")),i=a.map(l=>s[l]);if(a.every(l=>typeof s[l]=="string"))return i.join(" · ")}}try{return JSON.stringify(n)??String(n)}catch{return String(n)}}const Co="accounts.provider";function GI(e,n){if(typeof e!="object"||e===null)return[];const s=e[n];return Array.isArray(s)?s.flatMap(r=>{if(typeof r!="object"||r===null)return[];const a=r.place,i=r.count;return typeof a!="string"||typeof i!="number"||!(i>0)?[]:[{place:a,count:i}]}):[]}function qI(e){const n=e.map(({place:s,count:r})=>`${r.toLocaleString("en-GB")} ${r===1?s.replace(/s$/,""):s}`);return n.length<=1?n[0]??"":`${n.slice(0,-1).join(", ")} and ${n[n.length-1]}`}function QJ(e){const n=GI(e,"found");return n.length?`The value already sits in ${qI(n)}.`:""}function XJ(e){const n=GI(e,"scrubbed");return n.length?`Replaced with ‹secret:…› in ${qI(n)}.`:""}const ZJ=/^(PROVIDER_ACCOUNT_|CODEX_ACCOUNT_|ANTHROPIC_ACCOUNT_|OLLAMA_DEVICE_)/,eQ=/^MCP_(TOKEN|ENV|CONNECTION)_/,YI="GMAIL_APP_PASSWORD";function ya(e){const n=e.usedBy??[],s=e.bindings.map(r=>r.kind);if(n.some(r=>r.kind==="mailbox")||s.includes("email.account")||e.name===YI)return"mail";if(n.some(r=>r.kind==="model-account")||s.includes(Co)||ZJ.test(e.name))return"models";if(n.some(r=>r.kind==="connection")||s.includes("mcp.env")||eQ.test(e.name))return"connections";for(const r of e.bindings){if((r.kind==="http.url"||r.kind==="http.basic"||r.kind==="http.bearer")&&Rw(r.target)&&typeof r.target.plugin=="string")return`plugin:${r.target.plugin}`;if(Yi(r.kind))return`plugin:${r.kind.slice(0,-8)}`}return"mine"}function tQ(e){if(e==="mine")return{title:"Your secrets",aside:"Agents fill these where you allow, without seeing them."};if(e==="mail")return{title:"Mail",aside:"Mailbox passwords. A new one is set on the Email page, which tests it first."};if(e==="models")return{title:"Model accounts",aside:"Managed in Model accounts."};if(e==="connections")return{title:"Connections",aside:"Managed in Connections."};const n=e.slice(7);return n==="calendar"?{title:"Calendar links and sign-ins",aside:"Private links and app passwords, used only by the calendar plugin."}:{title:n.charAt(0).toUpperCase()+n.slice(1),aside:`Kept for the ${n} plugin.`}}function nQ(e,n){const s=r=>r==="mine"?0:r==="mail"?1:r==="models"?3:r==="connections"?4:2;return s(e)-s(n)||e.localeCompare(n)}function JI(e){return e==="models"||e==="connections"}function Rw(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function lS(e){const n=e.replace(/^[a-z][a-z0-9+.-]*:\/\//i,"").replace(/\/.*$/,"").replace(/^www\./,"");return n.startsWith("*.")?`any ${n.slice(2)} site`:n}const Iw=e=>(e.usedBy??[]).flatMap(n=>n.kind==="mailbox"?[n]:[]),fm=e=>(e.usedBy??[]).find(n=>n.kind==="model-account"),Pw=e=>(e.usedBy??[]).find(n=>n.kind==="connection");function vc(e,n=new Map){var r,a;const s=ya(e);if(s==="mail"){const i=Iw(e)[0];return i?`${i.provider==="Email"?"Mailbox":i.provider} ${i.auth==="xoauth2"?"sign-in":"app password"}`:"Old mailbox password"}if(s==="models"){const i=fm(e),l=(i==null?void 0:i.id)??((r=e.bindings.find(c=>c.kind===Co&&typeof c.target=="string"))==null?void 0:r.target),o=typeof l=="string"?n.get(l):void 0;return(o==null?void 0:o.label)??(i==null?void 0:i.label)??"Old model account key"}if(s==="connections")return((a=Pw(e))==null?void 0:a.name)??"Old connection sign-in";if(s.startsWith("plugin:")){const i=/^[^:]{1,40}:\s+(.+)$/.exec(e.name);return i?i[1]:e.name}return e.name}function sQ(e,n){var r,a,i;if(ya(e)!=="models")return null;const s=((r=fm(e))==null?void 0:r.id)??((a=e.bindings.find(l=>l.kind===Co&&typeof l.target=="string"))==null?void 0:a.target);return typeof s=="string"?((i=n.get(s))==null?void 0:i.provider)??null:null}function QI(e,n){const s=Rw(n)?n:{},r=a=>typeof s[a]=="string"?s[a]:"";return e==="browser.field"&&typeof n=="string"?`Filled on ${lS(n)}`:e==="browser.form.data"&&r("origin")?`Filled into “${r("field")}” on ${lS(r("origin"))}`:e==="browser.native.type"&&typeof n=="string"?`Typed into the app ${n}`:(e==="http.header"||e==="http.url"||e==="http.basic"||e==="http.bearer")&&r("host")?`Sent only to ${r("host")}`:e==="developer.env"&&r("variable")?`Given to ${r("workspace")} as ${r("variable")}`:e==="mcp.env"&&r("variable")?`Given to a program as ${r("variable")}`:e==="email.account"?"Used by a mailbox":e===Co?"Used by a model account":Yi(e)?`Used by a ${e.slice(0,-8)} account`:`Goes to ${VI(e,n)}`}function rQ(e,n){return Yi(e)||e===Co?"Signed in":QI(e,n).replace(/^Sent only to/,"Sent to")}const aQ={"api-key":"API key for this model account",chatgpt:"ChatGPT sign-in for this model account","anthropic-oauth":"Claude sign-in for this model account","device-key":"Ollama device key for this model account"};function iQ(e){return e.length<=1?e.join(""):`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}function Mw(e){const n=ya(e);if(n==="mail"){const i=Iw(e).map(l=>l.address);return i.length?`Used by the ${i.length===1?"mailbox":"mailboxes"} ${iQ(i)}`:e.name===YI?"From the old .env setup":"No mailbox uses it"}if(n==="models"){const i=fm(e);return i?aQ[i.auth]??"Key for this model account":"No model account uses it"}if(n==="connections"){const i=Pw(e);if(i!=null&&i.variable)return`Given to the program as ${i.variable}`;const l=e.bindings.find(c=>c.kind==="http.header"),o=l&&Rw(l.target)&&typeof l.target.host=="string"?l.target.host:null;return o?`Sign-in token · sent only to ${o}`:i?"Sign-in for this connection":"No connection uses it"}if(e.bindings.length===0)return"";const s=e.bindings.map(i=>QI(i.kind,i.target));let r=s.length<=2?s.join(" · "):`${s[0]} and ${s.length-1} more places`;const a=new Set(e.bindings.map(i=>i.rule==="first-time"&&i.firstApprovedAt!==null?"pre-approved":i.rule));return a.size===1&&a.has("every-time")&&(r+=" · asks you every time"),a.size===1&&a.has("first-time")&&(r+=" · asks you the first time"),e.totp&&(r+=" · a fresh code each time"),r}function lQ(e,n=Date.now()){return e.lastUse?`Last used ${Ve(e.lastUse.at,n)}`:"Never used"}function Ev(e){return Lr("email","settings",{account:e,set:"password"})}function XI(e){var s,r;const n=ya(e);if(n==="models"){const a=(s=fm(e))==null?void 0:s.id;return{label:"Managed in Model accounts",href:a?s$(a):Le("accounts")}}if(n==="connections"){const a=(r=Pw(e))==null?void 0:r.id;return{label:"Managed in Connections",href:a?r$(a):Le("connections")}}return null}function ZI(e){const n=/is not bound to (.+?)\.?$/.exec(e);if(!n)return null;const s=n[1];return/[0-9a-f]{8}-[0-9a-f]{4}-/i.test(s)?null:s}function eP(e,n=Date.now()){if(e.unused)return null;const s=ya(e),r=Iw(e)[0],a=XI(e),i=()=>r?{label:"Set password",href:Ev(r.id)}:a?{label:s==="models"?"Fix in Model accounts":"Fix in Connections",href:a.href}:{label:"Set a value",action:"replace"},l=e.lastUse,o=l?Ve(l.at,n):"",c=(l==null?void 0:l.detail)??"";if(e.hasValue===!1||(l==null?void 0:l.outcome)==="refused"&&/has no value stored/.test(c))return{text:"No value stored.",fix:i()};if(r!=null&&r.loginFailedAt)return{text:`${r.provider==="Email"?"The mail server":r.provider} turned it down at sign-in ${Ve(r.loginFailedAt,n)}.`,fix:{label:"Set password",href:Ev(r.id)}};if((l==null?void 0:l.outcome)==="refused"){if(/vault is locked/.test(c))return{text:`Held back ${o}: the vault was locked.`,fix:null};if(/TOTP secret/.test(c))return{text:`Held back ${o}: a one-time code goes only into a field on a website.`,fix:null};if(/is not bound to/.test(c)){const u=s==="mine"?ZI(c):null;return{text:u?`Held back ${o}: it was asked for at ${u}, where it may not go.`:`Held back ${o}: it was asked for somewhere it may not go.`,fix:s==="mine"?{label:"Change where it may go",action:"places"}:null}}return{text:`Held back ${o}: ${nP(c||null)}.`,fix:null}}if((l==null?void 0:l.outcome)==="failed"){const u=r?i():a?null:{label:"Replace value",action:"replace"};return{text:`Didn’t go through ${o}${c?`: ${c.replace(/\.$/,"")}`:""}.`,fix:u}}return(l==null?void 0:l.outcome)==="pending"?{text:`Waiting for your approval since ${o}.`,fix:{label:"Review",href:ql}}:s==="mine"&&e.bindings.length===0?{text:"Can’t be used anywhere until you choose where it may go.",fix:{label:"Choose where it may go",action:"places"}}:null}function tP(e){if(!e.unused)return"";const n=ya(e);return n==="mail"?"Not used by anything — no mailbox uses it any more.":n==="models"?"Not used by anything — no model account uses it any more.":n==="connections"?"Not used by anything — no connection uses it any more.":"Not used by anything — what it was for is gone."}function Av(e){return e.usageUnknown&&!e.unused?"Couldn’t check what uses it just now.":""}function El(e){return!!e.unused&&!JI(ya(e))}function oQ(e){if(e.unused||e.bindings.length===0)return"Nothing uses it, so nothing stops working.";const n=Mw(e).split(" · ")[0]??"";return n.startsWith("Filled on ")?`Agents can no longer fill it on ${n.slice(10)}.`:n.startsWith("Sent only to ")?`Agents can no longer send it to ${n.slice(13)}.`:`Whatever uses it stops working: ${n.charAt(0).toLowerCase()}${n.slice(1)}.`}const cQ={"every-time":"Every time","first-time":"The first time, then not again","pre-approved":"Never — allowed ahead of time"};function uQ(e){const n={"browser.field":"A field on a website","browser.form.data":"A form field, by its name","browser.native.type":"An app on this computer","http.header":"A request to a host","http.url":"A plugin’s web address","http.basic":"A plugin’s sign-in","http.bearer":"A plugin’s account sign-in","developer.env":"A workspace variable","mcp.env":"A program’s variable",[Co]:"A model account"};return n[e]?n[e]:Yi(e)?`A ${e.slice(0,-8)} account`:e}const dQ={"every-time":"Every time","first-time":"The first time","pre-approved":"Never"};function nP(e){if(!e)return"buddi didn’t hand it over";if(/has no value stored/.test(e))return"no value was stored";if(/vault is locked/.test(e))return"the vault was locked";if(/TOTP secret/.test(e))return"a one-time code goes only into a field on a website";const n=/is not bound to/.test(e)?ZI(e):void 0;return n!==void 0?n?`asked for at ${n}, where it may not go`:"asked for somewhere it may not go":e.replace(/\.$/,"")}function hQ(e){return e==="browser.field"?"www.pnc.com":e==="browser.form.data"?"www.pnc.com card-number":e==="browser.native.type"?"com.bank.app":e==="http.header"?"api.github.com Authorization":e==="http.url"?"calendar calendar.google.com":e==="http.basic"?"calendar caldav.fastmail.com":e==="http.bearer"?"calendar www.googleapis.com":e==="developer.env"?"my-app ADMIN_PASSWORD":Yi(e)?"acct-1":'{"host":"localhost","header":"Authorization"}'}function ef(e){return HI(e).includes("first-time")?"first-time":e}function fQ(e){const n=rQ(e.kind,e.target);return e.outcome==="refused"?{text:`Held back — ${nP(e.detail)}`,tone:"warning"}:e.outcome==="failed"?{text:`Didn’t go through — ${(e.detail??n).replace(/\.$/,"")}`,tone:"warning"}:e.outcome==="pending"?{text:`Asked for your approval · ${n}`}:{text:n}}async function _i(e,n,s,r){s(!0),r(null);try{return(await R.secretsAct(e,n)).result}catch(a){return r(a instanceof Error?a.message:String(a)),null}finally{s(!1)}}const sP="Passwords, keys and links your agents use without ever seeing them. Each goes only where you allow.";function mQ(e,n){if(n==="mail")return"mail";if(n==="models")return"chip";if(n==="connections")return"plug";if(n==="plugin:calendar")return"calendar";const s=e.bindings.map(r=>r.kind);return s.some(r=>r.startsWith("browser."))?"globe":s.includes("developer.env")?"terminal":"key"}function pQ({embedded:e,timezone:n,secret:s,adding:r,navigate:a}={}){const i=me(()=>R.secrets(),[]),l=me(()=>R.providerAccounts(),[]),o=h.useMemo(()=>{var g;return new Map((((g=l.data)==null?void 0:g.accounts)??[]).map(v=>[v.id,{label:v.label,provider:FI(v)}]))},[l.data]),[c,u]=h.useState(s?{what:"replace",name:s}:r?{what:"add"}:null);h.useEffect(()=>{s&&u({what:"replace",name:s})},[s]),h.useEffect(()=>{r&&u({what:"add"})},[r]);const d=()=>{u(null),(s||r)&&a&&a(Le("secrets"))},f=i.data,m=h.useMemo(()=>{const g=new Map;for(const v of(f==null?void 0:f.secrets)??[]){const b=ya(v);g.set(b,[...g.get(b)??[],v])}return[...g.entries()].sort(([v],[b])=>nQ(v,b))},[f]),p=c&&c.what!=="add"?(f==null?void 0:f.secrets.find(g=>g.name===c.name))??null:null;return t.jsxs(Zn,{embedded:e,title:"Keys and secrets",lede:sP,actions:e?void 0:t.jsx(A,{variant:"accent",size:"sm",onClick:()=>u({what:"add"}),children:"Add a secret"}),children:[t.jsxs(ie,{gap:"lg",children:[!f&&!i.error?t.jsx(ve,{children:"Opening the vault…"}):null,i.error?t.jsxs(ie,{gap:"sm",children:[t.jsx(ne,{message:i.error}),t.jsx(te,{children:t.jsx(A,{onClick:i.reload,children:"Retry"})})]}):null,f&&f.secrets.length===0?t.jsx(Ye,{children:t.jsx(Jn,{icon:"lock",title:"Nothing stored yet.",children:"Add a site password or an API token, and say where an agent may use it. Mailbox passwords and calendar links show up here as you add them."})}):null,f&&f.secrets.length>0?t.jsx(Ye,{flush:!0,children:m.map(([g,v])=>{const b=tQ(g);return t.jsxs("section",{className:"secrets-group","aria-label":b.title,children:[t.jsxs("header",{className:"secrets-group-head",children:[t.jsx("h3",{className:"secrets-group-title",children:b.title}),t.jsx("span",{className:"secrets-group-aside",children:b.aside})]}),t.jsx(at,{children:v.map(j=>t.jsx(xQ,{secret:j,group:g,accounts:o,onOpen:x=>u({what:x,name:j.name})},j.name))})]},g)})}):null,f&&f.ownKeys.length>0?t.jsx(Ot,{summary:`buddi’s own keys · ${f.ownKeys.length}`,children:t.jsxs("p",{className:"secrets-note",children:["The keys buddi itself runs on, read from its environment:"," ",f.ownKeys.map((g,v)=>t.jsxs("span",{children:[v>0?", ":"",t.jsx("code",{className:"mono",children:g})]},g)),". They aren’t changed here, and buddi hides them in whatever it sends out, like your own."]})}):null]}),(c==null?void 0:c.what)==="add"&&f?t.jsx(yQ,{destinations:f.destinations,onClose:d,onChanged:i.reload}):null,p&&(c==null?void 0:c.what)==="sheet"?t.jsx(vQ,{secret:p,accounts:o,timezone:n,onClose:d,onOpen:g=>u({what:g,name:p.name})}):null,p&&(c==null?void 0:c.what)==="replace"?t.jsx(wQ,{secret:p,title:vc(p,o),onClose:d,onChanged:i.reload}):null,p&&(c==null?void 0:c.what)==="rename"?t.jsx(bQ,{secret:p,onClose:d,onChanged:i.reload}):null,p&&(c==null?void 0:c.what)==="places"&&f?t.jsx(kQ,{secret:p,title:vc(p,o),destinations:f.destinations,onClose:d,onChanged:i.reload}):null,p&&(c==null?void 0:c.what)==="delete"?t.jsx(NQ,{secret:p,title:vc(p,o),onClose:d,onChanged:i.reload}):null]})}const tf=e=>n=>{n.stopPropagation(),e==null||e()};function rP({fix:e,onOpen:n}){return"href"in e?t.jsx(ht,{size:"sm",href:e.href,onClick:tf(),children:e.label}):t.jsx(A,{size:"sm",onClick:tf(()=>n(e.action)),children:e.label})}function gQ(e,n,s){if(n==="mine")return[{label:"Replace value…",onSelect:()=>s("replace")},{label:"Rename…",onSelect:()=>s("rename")},{label:"Change where it may go…",hint:"Places, and when it asks",onSelect:()=>s("places")},{label:"Usage history",onSelect:()=>s("sheet")},"separator",{label:"Delete…",tone:"critical",onSelect:()=>s("delete")}];if(n==="mail"){const r=(e.usedBy??[]).find(a=>a.kind==="mailbox");return[r&&!e.unused?{label:"Set a new password",hint:"On the Email page, which tests it first",onSelect:()=>{window.location.hash=Ev(r.id)}}:null,{label:"Usage history",onSelect:()=>s("sheet")},El(e)?"separator":null,El(e)?{label:"Remove…",tone:"critical",onSelect:()=>s("delete")}:null]}return[{label:n==="plugin:calendar"?"Replace link…":"Replace value…",onSelect:()=>s("replace")},{label:"Usage history",onSelect:()=>s("sheet")},El(e)?"separator":null,El(e)?{label:"Remove…",tone:"critical",onSelect:()=>s("delete")}:null]}function xQ({secret:e,group:n,accounts:s,onOpen:r}){const a=vc(e,s),i=sQ(e,s),l=[Mw(e),lQ(e)].filter(Boolean).join(" · "),o=eP(e),c=tP(e),u=Av(e),d=JI(n)?XI(e):null;return t.jsx(Xe,{onClick:()=>r("sheet"),label:`${a}: details`,lead:t.jsx(Un,{icon:mQ(e,n)}),title:t.jsxs(t.Fragment,{children:[a,i?t.jsx("span",{className:"secrets-tag",children:i}):null]}),sub:t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"secrets-line",children:l}),o?t.jsx("span",{className:"secrets-status","data-tone":"warning",children:o.text}):null,c?t.jsx("span",{className:"secrets-status",children:c}):null,u?t.jsx("span",{className:"secrets-status",children:u}):null]}),side:t.jsxs("span",{className:"secrets-side",children:[o!=null&&o.fix?t.jsx(rP,{fix:o.fix,onOpen:r}):null,c&&El(e)?t.jsx(A,{size:"sm",variant:"ghost",onClick:tf(()=>r("delete")),children:"Remove…"}):null,d?t.jsxs("a",{className:"secrets-managed",href:d.href,onClick:tf(),children:[d.label,t.jsx(le,{name:"chevron-right",size:12})]}):t.jsx(Rs,{label:`More for ${a}`,items:gQ(e,n,r),sheet:{title:a,sub:l}})]})})}function vQ({secret:e,accounts:n,timezone:s,onClose:r,onOpen:a}){const i=ya(e),l=vc(e,n),o=eP(e),c=tP(e),u=[...new Set(e.bindings.map(m=>m.rule))],d=e.lastUse,f=(e.usedBy??[]).map(m=>({label:m.kind==="mailbox"?"Mailbox":m.kind==="model-account"?"Model account":"Connection",value:t.jsx("code",{className:"mono secrets-mono",children:m.id})}));return t.jsx(Ge,{title:l,onClose:r,foot:i==="mine"?t.jsxs(te,{children:[t.jsx(A,{variant:"danger-ghost",onClick:()=>a("delete"),children:"Delete…"}),t.jsx(et,{}),t.jsx(A,{onClick:()=>a("rename"),children:"Rename…"}),t.jsx(A,{variant:"accent",onClick:()=>a("replace"),children:"Replace value…"})]}):void 0,children:t.jsxs(ie,{gap:"lg",children:[t.jsx(qt,{items:[{label:"Where it may go",value:Mw(e)||"Nowhere yet"},...u.length===1&&i==="mine"?[{label:"Asks you",value:cQ[u[0]]}]:[],{label:"Last used",value:d?`${Ve(d.at)}${d.agentId?` by ${d.agentId}`:""}`:"Never"}]}),o?t.jsx(G,{tone:"warning",action:o.fix?t.jsx(rP,{fix:o.fix,onOpen:a}):void 0,children:o.text}):null,c?El(e)?t.jsxs(G,{action:t.jsx(A,{size:"sm",onClick:()=>a("delete"),children:"Remove…"}),children:[c," Nothing removes it but you."]}):t.jsx(G,{children:c}):null,Av(e)?t.jsx(G,{children:Av(e)}):null,t.jsxs(ie,{gap:"sm",children:[t.jsx("h3",{className:"secrets-sheet-head",children:"Usage history"}),t.jsx(jQ,{name:e.name,timezone:s})]}),t.jsx(Ot,{summary:"Details",children:t.jsxs(ie,{gap:"sm",children:[t.jsx(qt,{items:[{label:"Stored as",value:t.jsx("code",{className:"mono secrets-mono",children:e.name})},...e.bindings.map((m,p)=>({key:`b${p}`,label:p===0?"Bindings":"",value:t.jsxs("code",{className:"mono secrets-mono",children:[m.kind," ",VI(m.kind,m.target)," · ",m.rule]})})),...e.totp?[{label:"One-time code",value:"buddi fills the current code, never the seed"}]:[],...f]}),t.jsx("p",{className:"secrets-note",children:"What buddi keeps for it, never the value. “Held back” means buddi declined to hand the value over — not bound to that place, no value stored, or the vault locked — so it never left."})]})})]})})}function jQ({name:e,timezone:n}){const s=me(()=>R.secretUses(e,50),[e]);if(s.error)return t.jsx(ne,{message:s.error});if(!s.data)return t.jsx(ve,{children:"Reading the history…"});const r=s.data.uses;return r.length===0?t.jsx("p",{className:"secrets-note",children:"Nothing has used it yet."}):t.jsx(at,{children:r.map((a,i)=>{const l=fQ(a);return t.jsx(Xe,{title:t.jsx("span",{className:"secrets-history","data-tone":l.tone,children:l.text}),sub:`${ct(a.at,n??"UTC")} · ${a.agent??(a.plugin?`the ${a.plugin} plugin`:"you")}`},i)})})}function aP({title:e,result:n,scrubbed:s,busy:r,failure:a,onScrub:i}){const l=QJ(n);return t.jsxs(ie,{gap:"sm",children:[t.jsxs(G,{tone:"good",role:"status",children:["Saved “",e,"”. Its value is never shown again."]}),t.jsx("p",{className:"secrets-note",children:l||"Nothing of the value sits where buddi already holds text."}),t.jsx(ne,{message:a}),l?t.jsx(te,{children:t.jsx(A,{variant:"accent",disabled:r||s!==null,onClick:i,children:s===null?"Scrub the history":XJ(s)||"Nothing of it was left to replace."})}):null]})}function iP({destinations:e,bindings:n,disabled:s,onChange:r}){const a=(i,l)=>{r(n.map((o,c)=>c===i?{...o,...l}:o))};return t.jsxs(ie,{gap:"sm",children:[n.map((i,l)=>{const o=e.find(d=>d.kind===i.kind),c=(o==null?void 0:o.maxRule)??i.rule,u=o?e:[...e,{kind:i.kind,plugin:"",maxRule:i.rule}];return t.jsxs("div",{className:"secrets-place",children:[t.jsx(re,{label:"Kind of place",children:t.jsx("select",{value:i.kind,disabled:s,onChange:d=>{var p;const f=d.target.value,m=(p=e.find(g=>g.kind===f))==null?void 0:p.maxRule;a(l,{kind:f,rule:m?ef(m):i.rule})},children:u.map(d=>t.jsx("option",{value:d.kind,children:uQ(d.kind)},d.kind))})}),t.jsx(re,{label:"The place",children:t.jsx("input",{type:"text",spellCheck:!1,disabled:s,value:i.target,placeholder:hQ(i.kind),onChange:d=>a(l,{target:d.target.value})})}),t.jsx(re,{label:"Asks you",children:t.jsx("select",{value:i.rule,disabled:s,onChange:d=>a(l,{rule:d.target.value}),children:HI(c).map(d=>t.jsx("option",{value:d,children:dQ[d]},d))})}),t.jsx(A,{size:"sm",variant:"ghost",disabled:s,onClick:()=>r(n.filter((d,f)=>f!==l)),children:"Remove"}),t.jsxs("p",{className:"ui-field-hint secrets-place-hint",children:["The place: ",KJ(i.kind),"."]})]},l)}),n.length===0?t.jsx("p",{className:"ui-field-hint",children:HJ}):null,e.length?t.jsx(te,{children:t.jsx(A,{size:"sm",disabled:s,onClick:()=>r([...n,{kind:e[0].kind,target:"",rule:ef(e[0].maxRule)}]),children:"Add a place"})}):t.jsx("p",{className:"ui-field-hint",children:"Nothing installed here takes a secret yet, so there is nowhere to send one."})]})}function lP(e){const n=e.map(r=>YJ(r.kind,r.target)),s=n.findIndex(r=>!r.ok);return s!==-1?{ok:!1,error:`Place ${s+1}: ${n[s].error}`}:{ok:!0,bindings:e.map((r,a)=>({kind:r.kind,target:n[a].target,rule:r.rule}))}}function yQ({destinations:e,onClose:n,onChanged:s}){const[r,a]=h.useState(""),[i,l]=h.useState(""),[o,c]=h.useState(!1),[u,d]=h.useState(()=>e.length?[{kind:e[0].kind,target:"",rule:ef(e[0].maxRule)}]:[]),[f,m]=h.useState(!1),[p,g]=h.useState(null),[v,b]=h.useState(null),[j,x]=h.useState(null),y=async()=>{const k=lP(u);if(!k.ok){g(k.error);return}const N=i;l("");const S=await _i("secrets.put",{name:r.trim(),value:N,totp:o,bindings:k.bindings},m,g);S!==null&&(b({name:r.trim(),result:S}),s())},w=async()=>{const k=await _i("secrets.scrub_history",{name:(v==null?void 0:v.name)??""},m,g);k!==null&&(x(k),s())};return v?t.jsx(Ge,{title:"Add a secret",onClose:n,foot:t.jsx(te,{align:"end",children:t.jsx(A,{onClick:n,children:"Done"})}),children:t.jsx(aP,{title:v.name,result:v.result,scrubbed:j,busy:f,failure:p,onScrub:()=>void w()})}):t.jsx(Ge,{title:"Add a secret",size:"wide",onClose:n,foot:t.jsxs(te,{align:"end",children:[t.jsx(A,{onClick:n,children:"Cancel"}),t.jsx(A,{type:"submit",form:"secrets-add",variant:"accent",disabled:f,children:"Save secret"})]}),children:t.jsxs("form",{id:"secrets-add",className:"ui-stack","data-gap":"lg",onSubmit:k=>{k.preventDefault(),y()},children:[t.jsxs("fieldset",{disabled:f,className:"ui-stack","data-gap":"sm",children:[t.jsx(re,{label:"Name",hint:"What agents ask for it by. Saving a name that exists replaces that secret’s value.",children:t.jsx("input",{required:!0,autoFocus:!0,maxLength:200,value:r,onChange:k=>a(k.target.value),placeholder:"PNC password"})}),t.jsx(re,{label:"Value",hint:"Kept in the vault and never shown again, not even here.",children:t.jsx("input",{type:"password",autoComplete:"new-password",spellCheck:!1,required:!0,value:i,onChange:k=>l(k.target.value)})}),t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:o,onChange:k=>c(k.target.checked)}),t.jsx("span",{children:"It’s a one-time-code seed — buddi fills the current code, never the seed"})]})]}),t.jsxs("fieldset",{disabled:f,className:"ui-stack","data-gap":"sm",children:[t.jsx("h3",{className:"secrets-sheet-head",children:"Where it may go"}),t.jsx("p",{className:"secrets-note",children:"Agents can use it only in these places. Anywhere else, buddi holds it back and the row says so."}),t.jsx(iP,{destinations:e,bindings:u,disabled:f,onChange:d})]}),p?t.jsx(G,{tone:"critical",role:"alert",children:p}):null]})})}function wQ({secret:e,title:n,onClose:s,onChanged:r}){const[a,i]=h.useState(""),[l,o]=h.useState(!1),[c,u]=h.useState(null),[d,f]=h.useState(null),[m,p]=h.useState(null),g=async()=>{const b=a;i("");const j=await _i("secrets.put",{name:e.name,value:b,totp:e.totp,bindings:e.bindings.map(({kind:x,target:y,rule:w})=>({kind:x,target:y,rule:w}))},o,u);j!==null&&(f(j),r())},v=async()=>{const b=await _i("secrets.scrub_history",{name:e.name},o,u);b!==null&&(p(b),r())};return d?t.jsx(zt,{title:`Replaced the value of “${n}”`,onClose:s,foot:t.jsx(A,{variant:"accent",onClick:s,children:"Done"}),children:t.jsx(aP,{title:n,result:d,scrubbed:m,busy:l,failure:c,onScrub:()=>void v()})}):t.jsx(zt,{title:`Replace the value of “${n}”`,onClose:s,foot:t.jsxs(t.Fragment,{children:[t.jsx(A,{variant:"ghost",onClick:s,children:"Cancel"}),t.jsx(A,{type:"submit",form:"secrets-replace",variant:"accent",disabled:l||a==="",children:"Save value"})]}),children:t.jsxs("form",{id:"secrets-replace",className:"ui-stack","data-gap":"sm",onSubmit:b=>{b.preventDefault(),a!==""&&g()},children:[t.jsx(re,{label:"New value",hint:"Kept in the vault and never shown again. Where it may go stays the same.",children:t.jsx("input",{type:"password",autoComplete:"new-password",spellCheck:!1,required:!0,autoFocus:!0,disabled:l,value:a,onChange:b=>i(b.target.value)})}),t.jsx(ne,{message:c})]})})}function bQ({secret:e,onClose:n,onChanged:s}){const[r,a]=h.useState(e.name),[i,l]=h.useState(!1),[o,c]=h.useState(null),u=r.trim()!==""&&r.trim()!==e.name,d=async()=>{await _i("secrets.rename",{name:e.name,to:r.trim()},l,c)!==null&&(s(),n())};return t.jsx(zt,{title:`Rename “${e.name}”`,onClose:n,foot:t.jsxs(t.Fragment,{children:[t.jsx(A,{variant:"ghost",onClick:n,children:"Cancel"}),t.jsx(A,{type:"submit",form:"secrets-rename",variant:"accent",disabled:i||!u,children:"Rename"})]}),children:t.jsxs("form",{id:"secrets-rename",className:"ui-stack","data-gap":"sm",onSubmit:f=>{f.preventDefault(),u&&d()},children:[t.jsx(re,{label:"Name",hint:"What agents ask for it by. One that uses the old name needs the new one.",children:t.jsx("input",{required:!0,autoFocus:!0,maxLength:200,disabled:i,value:r,onChange:f=>a(f.target.value)})}),t.jsx(ne,{message:o})]})})}function kQ({secret:e,title:n,destinations:s,onClose:r,onChanged:a}){const[i,l]=h.useState(()=>e.bindings.length?e.bindings.map(m=>({kind:m.kind,target:JJ(m.target),rule:m.rule})):s.length?[{kind:s[0].kind,target:"",rule:ef(s[0].maxRule)}]:[]),[o,c]=h.useState(!1),[u,d]=h.useState(null),f=async()=>{const m=lP(i);if(!m.ok){d(m.error);return}await _i("secrets.rebind",{name:e.name,bindings:m.bindings},c,d)!==null&&(a(),r())};return t.jsx(Ge,{title:`Where “${n}” may go`,size:"wide",onClose:r,foot:t.jsxs(te,{align:"end",children:[t.jsx(A,{onClick:r,children:"Cancel"}),t.jsx(A,{type:"submit",form:"secrets-places",variant:"accent",disabled:o,children:"Save"})]}),children:t.jsxs("form",{id:"secrets-places",className:"ui-stack","data-gap":"sm",onSubmit:m=>{m.preventDefault(),f()},children:[t.jsx("p",{className:"secrets-note",children:"Agents can use it only in these places. Anywhere else, buddi holds it back and the row says so."}),t.jsx(iP,{destinations:s,bindings:i,disabled:o,onChange:l}),u?t.jsx(G,{tone:"critical",role:"alert",children:u}):null]})})}function NQ({secret:e,title:n,onClose:s,onChanged:r}){const[a,i]=h.useState(!1),[l,o]=h.useState(null),c=!!e.unused,u=async()=>{await _i("secrets.delete",{name:e.name},i,o)!==null&&(r(),s())};return t.jsxs(zt,{title:`${c?"Remove":"Delete"} “${n}”?`,onClose:s,foot:t.jsxs(t.Fragment,{children:[t.jsx(A,{variant:"ghost",onClick:s,children:"Cancel"}),t.jsx(A,{variant:"danger",disabled:a,onClick:()=>void u(),children:c?"Remove":"Delete"})]}),children:[t.jsxs("p",{className:"secrets-dialog-text",children:[oQ(e)," The value is gone for good; its usage history stays, under its name."]}),t.jsx(ne,{message:l})]})}function SQ({timezone:e,embedded:n}){var p;const{data:s,error:r,reload:a}=me(()=>R.sentinels(),[],3e4),[i,l]=h.useState(null),[o,c]=h.useState(null),u=(s==null?void 0:s.installed)??[],d=((s==null?void 0:s.runs)??[]).filter(g=>g.lastError),f=u.filter(g=>!g.enabled),m=(g,v)=>{l(g),c(null),R.setSentinelEnabled(g,v).catch(b=>c(b instanceof xe?b.message:String(b))).finally(()=>{l(null),a()})};return t.jsxs(Zn,{embedded:n,title:"Watchers",children:[t.jsx(ne,{message:r??o}),t.jsx(G,{children:"Watchers are small checks that run on their own, with no model involved. An urgent finding wakes an agent, which verifies it before it tells you. The rest waits for the weekly recap."}),d.length>0?t.jsx(G,{tone:"warning",children:d.length===1?"One watcher failed on its last run.":`${d.length} watchers failed on their last run.`}):null,f.length>0?t.jsxs(G,{tone:"warning",children:[f.length===1?"One watcher is off.":`${f.length} watchers are off.`," A watcher that is off does not run, and what it already found stays as it was."]}):null,t.jsx(ue,{title:"Installed",aside:t.jsx("a",{href:`${At}/alerts`,children:"See what they found"}),panel:!0,flush:!0,children:s?u.length===0?t.jsx(Jn,{icon:"eye",title:"No watchers are installed",children:"Plugins bring their own."}):t.jsx(at,{children:u.map(g=>{const v=s.runs.find(b=>b.sentinelId===g.id);return t.jsx(Xe,{lead:t.jsx(Ee,{tone:g.enabled?v!=null&&v.lastError?"critical":v?"good":void 0:"muted",children:g.enabled?v!=null&&v.lastError?"failed":v?"ok":"never ran":"off"}),title:g.description,sub:`${g.id}, every ${CQ(g.every)}${v!=null&&v.lastError?`. ${v.lastError}`:""}`,side:t.jsxs(t.Fragment,{children:[t.jsx("span",{title:v?ct(v.lastRunAt,e):void 0,children:v?Ve(v.lastRunAt):"never ran"}),t.jsx(A,{size:"sm",disabled:i===g.id,onClick:()=>m(g.id,!g.enabled),children:g.enabled?"Turn off":"Turn on"})]})},g.id)})}):t.jsx(ve,{children:"Loading…"})}),t.jsx(V7,{mutes:((p=s==null?void 0:s.alerts)==null?void 0:p.mutes)??[],onChanged:a})]})}function CQ(e){if(e%86400===0){const s=e/86400;return s===1?"day":`${s} days`}if(e%3600===0){const s=e/3600;return s===1?"hour":`${s} hours`}const n=Math.max(1,Math.round(e/60));return n===1?"minute":`${n} minutes`}const oS=4,EQ={time:"profile",date:"profile",zone:null};function AQ({data:e,phone:n}){const s=h.useRef(null),r=xR(),[a,i]=h.useState(.4),l=n?390:1280,o=n?780:800;h.useEffect(()=>{const u=s.current;if(!u)return;const d=()=>i(u.clientWidth/l||.4);if(d(),typeof ResizeObserver>"u")return;const f=new ResizeObserver(d);return f.observe(u),()=>f.disconnect()},[l]);const c=(e==null?void 0:e.owner)??null;return t.jsx("div",{ref:s,className:"lke-preview","data-phone":n?"true":void 0,style:{aspectRatio:`${l} / ${o}`},role:"img","aria-label":"Preview of the lock screen",children:t.jsxs("div",{className:"lk","data-preview":"true","data-bg":mw(e==null?void 0:e.background,e==null?void 0:e.image),"data-phone":n?"true":void 0,"data-view":"glance",style:{width:l,height:o,transform:`scale(${a})`},"aria-hidden":"true",children:[t.jsx(ER,{data:e??null,now:r,phone:n}),t.jsx("footer",{className:"lk-unlock",children:n?t.jsxs("span",{className:"lk-chip lk-enter",children:[t.jsx(le,{name:"lock",size:14}),t.jsx("span",{children:"Enter PIN"})]}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"lk-who",children:[t.jsx("span",{className:"lk-face",children:(c??"You").slice(0,1).toUpperCase()}),c?t.jsx("span",{className:"lk-owner",children:c}):null]}),t.jsxs("span",{className:"lk-pin",children:[t.jsx(le,{name:"lock",size:15}),t.jsx("span",{className:"lke-pin-hint",children:"Enter your PIN"})]})]})})]})})}function $Q({info:e,placement:n,index:s,count:r,onSize:a,onSettings:i,onMove:l,onRemove:o}){var u;const c=n.label??e.title;return t.jsxs("li",{className:"lke-row","data-key":n.key,children:[t.jsxs("span",{className:"lke-row-text",children:[t.jsx("span",{className:"lke-row-title",children:c}),t.jsx("span",{className:"lke-row-sub",children:e.builtIn?"Built in":`${e.plugin} plugin`})]}),t.jsxs("span",{className:"lke-row-tools",children:[e.sizes.length>1?t.jsx(ln,{label:`Size of ${c}`,options:["small","medium"].filter(d=>e.sizes.includes(d)).map(d=>({value:d,label:d==="small"?"Small":"Medium"})),value:n.size,onChange:a}):null,t.jsxs("span",{className:"lke-row-acts",children:[(((u=e.settings)==null?void 0:u.length)??0)>0?t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":`Settings for ${c}`,title:"Settings",onClick:i,children:t.jsx(le,{name:"settings",size:14})}):null,t.jsxs("span",{className:"lke-move",children:[t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":`Move ${c} earlier`,title:"Move earlier",disabled:s===0,onClick:()=>l(-1),children:t.jsx(le,{name:"chevron-left"})}),t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":`Move ${c} later`,title:"Move later",disabled:s===r-1,onClick:()=>l(1),children:t.jsx(le,{name:"chevron-right"})})]}),t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":`Take ${c} off the lock screen`,title:"Take off the lock screen",onClick:o,children:t.jsx(le,{name:"close",size:12})})]})]})]})}function cS(e){return e?"place"in e?`place:${e.place}`:`town:${e.timezone}:${e.label}`:""}function TQ({clock:e,onClock:n,version:s}){var V,z,X;const r=e??EQ,a=me(()=>R.lockScreen(),[s]),i=me(()=>R.widgets("lock"),[]),l=me(()=>R.owner(),[]),[o,c]=h.useState(void 0),[u,d]=h.useState(!1),[f,m]=h.useState(null),[p,g]=h.useState(null),[v,b]=h.useState(null),[j,x]=h.useState(null);h.useEffect(()=>{i.data&&c(i.data)},[i.data]);const y=((V=a.data)==null?void 0:V.timezone)??Intl.DateTimeFormat().resolvedOptions().timeZone,w=(o==null?void 0:o.lock)??[],k=new Map(((o==null?void 0:o.available)??[]).map(K=>[K.id,K])),N=w.length>=oS,S=K=>{if(!o)return Promise.resolve(!1);const ee=o;return m(null),c({...o,lock:K,arranged:{...o.arranged,lock:!0}}),R.saveWidgets("lock",K).then(ce=>(c(ce),a.reload(),!0),ce=>(c(ee),m(`Couldn't save the lock screen's widgets: ${ce instanceof Error?ce.message:String(ce)}`),!1))},C=(K,ee)=>{const ce=w.slice(),[pe]=ce.splice(K,1);ce.splice(K+ee,0,pe),S(ce)},E=(K,ee)=>{const ce=k.get(K);!ce||N||S([...w,{key:kR(),widget:K,size:ce.sizes.includes("small")?"small":ce.sizes[0],settings:ee}])},T=K=>{if(K==="find"){b({query:"",found:[],busy:!1});return}if(b(null),K==="")return n({...r,zone:null});if(K.startsWith("place:"))return n({...r,zone:{place:K.slice(6)}});const ee=r.zone&&!("place"in r.zone)?r.zone:j;ee&&n({...r,zone:ee})},I=()=>{if(!v||v.query.trim().length<2)return;const K=v.query.trim();b({query:v.query,found:[],busy:!0}),R.findPlace(K).then(({found:ee})=>{var Re;const ce=ee.filter(Oe=>Oe.timezone);if(ce.length===0){b({query:K,found:[],busy:!1,missed:`Nothing with a timezone found for “${K}”.`});return}const pe=ce[0],oe={label:((Re=pe.name.split(",")[0])==null?void 0:Re.trim())||pe.name,timezone:pe.timezone};x(oe),b(null),n({...r,zone:oe})}).catch(()=>b({query:K,found:[],busy:!1,missed:"The place finder didn’t answer. Try again in a moment."}))},F=new Date,D=K=>mu({dateFormat:K},()=>Wr(F,y,{weekday:!0})),$=(((z=l.data)==null?void 0:z.places)??[]).filter(K=>K.timezone&&K.timezone!==y),L=r.zone&&!("place"in r.zone)?r.zone:j,O=((o==null?void 0:o.home)??[]).filter(K=>k.has(K.widget)&&!k.get(K.widget).sensitive),M=((o==null?void 0:o.available)??[]).filter(K=>!K.sensitive),P=((o==null?void 0:o.available)??[]).filter(K=>K.sensitive).map(K=>K.title),H=p?w.find(K=>K.key===p):void 0,U=H?k.get(H.widget):void 0;return t.jsxs(ue,{title:"What it shows",aside:"Every change is kept at once.",panel:!0,children:[t.jsxs("div",{className:"lke",children:[t.jsxs("div",{className:"lke-look",children:[t.jsx(AQ,{data:a.data,phone:u}),t.jsxs("div",{className:"lke-look-foot",children:[t.jsx(ln,{label:"Preview on",options:[{value:"desk",label:"Desk"},{value:"phone",label:"Phone"}],value:u?"phone":"desk",onChange:K=>d(K==="phone")}),t.jsxs("span",{className:"lke-look-note",children:["As it shows now",(X=a.data)!=null&&X.focus?", with your focus on":"","."]})]})]}),t.jsxs("div",{className:"lke-controls",children:[t.jsx(ne,{message:f}),t.jsxs("div",{className:"lke-group",role:"group","aria-label":"Clock",children:[t.jsx("p",{className:"lke-group-title",children:"Clock"}),t.jsxs("div",{className:"wg-field",role:"group","aria-label":"Time",children:[t.jsx("span",{className:"wg-field-label",children:"Time"}),t.jsx(ln,{label:"Time",options:[{value:"profile",label:ZE()},{value:"12h",label:"12-hour"},{value:"24h",label:"24-hour"}],value:r.time,onChange:K=>n({...r,time:K})})]}),t.jsx(re,{label:"Date",children:t.jsxs("select",{value:r.date,onChange:K=>n({...r,date:K.target.value}),children:[t.jsxs("option",{value:"profile",children:["Profile · ",D(null)]}),t.jsx("option",{value:"short",children:D("short")}),t.jsx("option",{value:"long",children:D("long")}),t.jsx("option",{value:"iso",children:D("iso")}),t.jsx("option",{value:"off",children:"No date"})]})}),t.jsx(re,{label:"A second clock",hint:"A place in another zone, under the time.",children:t.jsxs("select",{value:v?"find":cS(r.zone),onChange:K=>T(K.target.value),children:[t.jsx("option",{value:"",children:"None"}),$.map(K=>t.jsxs("option",{value:`place:${K.id}`,children:[K.label," — ",K.name.split(",")[0]]},K.id)),r.zone&&"place"in r.zone&&!$.some(K=>K.id===r.zone.place)?t.jsx("option",{value:cS(r.zone),children:"A place no longer in another zone"}):null,L?t.jsx("option",{value:`town:${L.timezone}:${L.label}`,children:L.label}):null,t.jsx("option",{value:"find",children:"Another town…"})]})}),v?t.jsxs("div",{className:"wg-field-stack",children:[t.jsxs("div",{className:"wg-find",children:[t.jsx("input",{autoFocus:!0,value:v.query,placeholder:"Find a town: Tokyo","aria-label":"Find a town for the second clock",onChange:K=>b({...v,query:K.target.value}),onKeyDown:K=>{K.key==="Enter"&&(K.preventDefault(),I()),K.key==="Escape"&&b(null)}}),t.jsx(A,{size:"sm",disabled:v.busy||v.query.trim().length<2,onClick:I,children:v.busy?"Finding…":"Find"})]}),v.missed?t.jsx("span",{className:"ui-field-hint",children:v.missed}):null]}):null]}),t.jsxs("div",{className:"lke-group",role:"group","aria-label":"Widgets",children:[t.jsxs("div",{className:"lke-group-head",children:[t.jsxs("p",{className:"lke-group-title",children:["Widgets ",t.jsxs("span",{className:"lke-count",children:[w.length," of ",oS]})]}),N||!o?t.jsxs(A,{size:"sm",disabled:!0,children:[t.jsx(le,{name:"plus",size:12})," Add a widget"]}):t.jsx(Rs,{label:"Add a widget",trigger:t.jsxs("button",{type:"button",className:"ui-btn","data-size":"sm",children:[t.jsx(le,{name:"plus",size:12})," Add a widget"]}),items:[O.length>0?{heading:"As on Home"}:null,...O.map(K=>({label:K.label??k.get(K.widget).title,hint:"same settings",onSelect:()=>E(K.widget,K.settings)})),O.length>0?"separator":null,{heading:"Every widget"},...M.map(K=>({label:K.title,onSelect:()=>E(K.id,{})})),"separator",{label:"Get more widgets",hint:"Browse",onSelect:()=>{window.location.hash=Ex("widgets")}}]})]}),o?w.length===0?t.jsx("p",{className:"lke-empty",children:"No widgets: just the clock and the counts."}):t.jsx("ul",{className:"lke-list",children:w.map((K,ee)=>{const ce=k.get(K.widget);return ce?t.jsx($Q,{info:ce,placement:K,index:ee,count:w.length,onSize:pe=>void S(w.map(oe=>oe.key===K.key?{...oe,size:pe}:oe)),onSettings:()=>g(K.key),onMove:pe=>C(ee,pe),onRemove:()=>void S(w.filter(pe=>pe.key!==K.key))},K.key):null})}):t.jsx("p",{className:"lke-empty","aria-busy":"true",children:"Reading the lock screen’s widgets…"}),t.jsxs("p",{className:"ui-field-hint",children:[N?"Four is the most it holds; take one off to add another. ":"","Each keeps its own settings, apart from Home’s.",P.length>0?` A sensitive widget — ${P.join(", ")} — never shows here.`:" A sensitive widget never shows here."," ","One with nothing to show right now stays off until it has."]})]}),t.jsxs("p",{className:"lke-note",children:[t.jsx(le,{name:"moon",size:13}),t.jsx("span",{children:"Your focus shows at the top only while one is on. Approvals and what else needs you show as counts when there are some, never what they say."})]})]})]}),H&&U?t.jsx(yR,{info:U,placement:H,surface:"lock",onClose:()=>g(null),onSave:K=>S(w.map(ee=>ee.key===H.key?{...ee,settings:K}:ee)).then(ee=>(ee&&g(null),ee)),onRemove:()=>{g(null),S(w.filter(K=>K.key!==H.key))}}):null]})}const RQ=[{id:"earth",label:"Earth"},{id:"field",label:"Buddi"},{id:"dawn",label:"Dawn"},{id:"sea",label:"Sea"},{id:"moss",label:"Moss"},{id:"dusk",label:"Dusk"}],IQ=[{value:"1",label:"1 min"},{value:"5",label:"5 min"},{value:"15",label:"15 min"},{value:"60",label:"1 hour"},{value:"never",label:"Never"}],PQ=e=>e.delayMinutes===null?"never":String(e.delayMinutes);function $v(e){if(e instanceof xe){const n=e.detail??{};return e.status===429||n.waitUntil?"Too many wrong tries. Wait a moment, then try again.":e.status===403&&typeof n.triesLeft=="number"?`${e.message} ${n.triesLeft} ${n.triesLeft===1?"try":"tries"} left.`:e.message}return"Something went wrong. Try again."}function MQ({kind:e,onClose:n,onDone:s}){const[r,a]=h.useState(""),[i,l]=h.useState(""),[o,c]=h.useState(""),[u,d]=h.useState(null),[f,m]=h.useState(!1),p=e==="remove",g=e!=="set",v=!f&&(!g||r.length>=4)&&(p||i.length>=4&&o.length>=4),b=w=>w.replace(/\D/g,"").slice(0,8),j=e==="set"?"Set a PIN":e==="change"?"Change your PIN":"Remove the PIN?",x=w=>{if(w==null||w.preventDefault(),!v)return;if(!p&&i!==o){d("The two PINs aren’t the same.");return}m(!0),d(null),(p?R.removePin(r):R.setPin(i,g?r:void 0)).then(s).catch(N=>{m(!1),d($v(N))})},y=(w,k,N,S)=>t.jsx(re,{label:w,children:t.jsx("input",{type:"password",inputMode:"numeric",autoComplete:w==="Current PIN"?"current-password":"new-password",maxLength:8,autoFocus:S,value:k,onChange:C=>{d(null),N(b(C.target.value))}})});return t.jsx(zt,{title:j,onClose:n,foot:t.jsxs(t.Fragment,{children:[t.jsx(A,{variant:"ghost",onClick:n,children:"Cancel"}),t.jsx(A,{variant:p?"danger":"accent",disabled:!v,onClick:()=>x(),children:p?"Remove PIN":e==="set"?"Set PIN":"Change PIN"})]}),children:t.jsxs("form",{className:"lk-form",onSubmit:x,children:[t.jsx("p",{className:"lk-honest",children:p?"The dashboard stops locking, on every device. You can set a PIN again any time.":"Four to eight digits. You type it to open the dashboard after it locks, on any device signed in to it."}),g?y("Current PIN",r,a,!0):null,p?null:y(e==="set"?"PIN":"New PIN",i,l,!g),p?null:y("The same again",o,c,!1),u?t.jsx(G,{tone:"critical",children:u}):null,t.jsx("button",{type:"submit",hidden:!0,"aria-hidden":"true",tabIndex:-1})]})})}function DQ(e){const n=cm(),s=me(()=>R.lockState(),[]),[r,a]=h.useState(null),[i,l]=h.useState(null),[o,c]=h.useState(!1),u=h.useRef(null),d=s.data??n.state,f=b=>{n.update(b),s.reload()},m=b=>{l(null),b.then(f).catch(j=>l($v(j)))},p=b=>{b&&(c(!0),l(null),R.uploadLockBackground(b).then(f).catch(j=>l($v(j))).finally(()=>{c(!1),u.current&&(u.current.value="")}))};if(!d)return t.jsx(ue,{title:"Lock screen",panel:!0,children:t.jsx(ne,{message:s.error?"Couldn’t read the lock screen’s settings.":null})});const g=d.pin,v=(b,j)=>t.jsxs("button",{type:"button",className:"lk-swatch","data-bg":b,"aria-pressed":d.background===b,"aria-label":j,title:j,onClick:()=>m(R.setLockSettings({background:b})),children:[b==="image"&&d.image?t.jsx("img",{src:d.image,alt:""}):b==="earth"?t.jsx("img",{src:fv.thumb,alt:""}):t.jsx("span",{className:"lk-swatch-field"}),t.jsx("span",{className:"lk-swatch-label",children:j})]},b);return t.jsxs(t.Fragment,{children:[t.jsxs(ue,{title:"Lock screen",aside:"Kept for every device signed in to this dashboard.",actions:g?t.jsxs(A,{size:"sm",onClick:()=>n.lockNow(),children:[t.jsx(le,{name:"lock",size:13})," Lock now"]}):void 0,panel:!0,children:[t.jsxs(ie,{divided:!0,gap:"lg",children:[t.jsx("p",{className:"lk-honest ui-section",children:"A privacy screen over this dashboard, on every device signed in to it: it locks when nobody has used it for a while, or when you lock it, and opens with your PIN. A new browser opens locked too. It isn’t a second sign-in — anyone who can run buddi on this computer can open it without the PIN. Telegram and buddi in your coding tools carry on as before."}),t.jsx(ne,{message:i}),t.jsxs("div",{className:"lk-pref ui-section",children:[t.jsxs("div",{className:"lk-pref-text",children:[t.jsx("div",{className:"lk-pref-label",children:"PIN"}),t.jsx("div",{className:"ui-field-hint",children:g?"Set. Kept hashed on this buddi; five wrong tries, then a wait that grows.":"Four to eight digits. Until you set one, nothing locks."})]}),g?t.jsxs(te,{children:[t.jsx(A,{size:"sm",variant:"ghost",onClick:()=>a("remove"),children:"Remove…"}),t.jsx(A,{size:"sm",onClick:()=>a("change"),children:"Change…"})]}):t.jsx(A,{size:"sm",variant:"accent",onClick:()=>a("set"),children:"Set a PIN"})]}),t.jsxs("div",{className:"lk-pref ui-section","data-off":g?void 0:"true","aria-disabled":g?void 0:"true",children:[t.jsxs("div",{className:"lk-pref-text",children:[t.jsx("div",{className:"lk-pref-label",children:"Lock after"}),t.jsx("div",{className:"ui-field-hint",children:g?t.jsxs(t.Fragment,{children:["Nobody using it for this long. Lock it yourself from your menu",t.jsxs("span",{className:"lk-shortcut",children:[", or with ",t.jsx("kbd",{className:"lk-kbd",children:n.shortcut})]}),"."]}):"Set a PIN first."})]}),t.jsx(ln,{label:"Lock after",options:IQ,value:g?PQ(d):"",onChange:b=>{g&&m(R.setLockSettings({delayMinutes:b==="never"?null:Number(b)}))}})]}),t.jsxs("div",{className:"lk-pref ui-section","data-stack":"true",children:[t.jsxs("div",{className:"lk-pref-text",children:[t.jsx("div",{className:"lk-pref-label",children:"Background"}),t.jsx("div",{className:"ui-field-hint",children:"Behind the time and your widgets, on every device. A picture is kept as a JPEG of at most 2560 pixels, without its location or other details."})]}),t.jsxs("div",{className:"lk-swatches",role:"group","aria-label":"Background",children:[RQ.map(b=>v(b.id,b.label)),d.image?v("image","Your picture"):null,t.jsxs("label",{className:"lk-swatch","data-kind":"add","aria-busy":o?"true":void 0,children:[t.jsx("input",{ref:u,type:"file",accept:"image/jpeg,image/png",className:"lk-sr",disabled:o,onChange:b=>{var j;return p((j=b.target.files)==null?void 0:j[0])}}),t.jsx("span",{className:"lk-swatch-field","data-kind":"add",children:t.jsx(le,{name:"plus",size:16})}),t.jsx("span",{className:"lk-swatch-label",children:o?"Adding…":d.image?"Replace":"Your picture"})]})]}),t.jsxs("p",{className:"lk-credit",children:["Earth: photo by ",t.jsx("a",{href:Pp.authorUrl,target:"_blank",rel:"noreferrer",children:Pp.author})," on ",t.jsx("a",{href:Pp.photoUrl,target:"_blank",rel:"noreferrer",children:"Unsplash"})]}),d.image?t.jsx(te,{align:"end",children:t.jsx(A,{size:"sm",variant:"ghost",onClick:()=>m(R.removeLockBackground()),children:"Remove picture"})}):null]})]}),r?t.jsx(MQ,{kind:r,onClose:()=>a(null),onDone:b=>{a(null),f(b)}}):null]}),t.jsx(TQ,{clock:d.clock,onClock:b=>m(R.setLockSettings({clock:b})),version:`${d.background}:${d.image??""}:${JSON.stringify(d.clock??null)}`})]})}const Yp=60;function oP(e){return e instanceof xe?e.message:"Something went wrong. Try again."}function OQ(e,n,s=Date.now()){const r=`made ${Wr(new Date(e.createdAt),n,{compact:!0})} ${e.createdVia==="cli"?"in the terminal":"here"}`;return`buddi_…${e.hint} · ${r} · ${e.lastUsedAt?`last used ${Ve(e.lastUsedAt,s)}`:"never used"}`}function LQ({onClose:e,onMade:n}){const[s,r]=h.useState(""),[a,i]=h.useState(!1),[l,o]=h.useState(null),[c,u]=h.useState(null),[d,f]=h.useState(!1),m=!a&&s.trim()!==""&&s.trim().length<=Yp,p=g=>{g==null||g.preventDefault(),m&&(i(!0),o(null),R.createApiToken(s.trim()).then(v=>{u({token:v.token,name:v.apiToken.name}),n()}).catch(v=>o(oP(v))).finally(()=>i(!1)))};if(c){const g=()=>{var v;(v=navigator.clipboard)==null||v.writeText(c.token).then(()=>{f(!0),window.setTimeout(()=>f(!1),1600)}).catch(()=>{})};return t.jsx(zt,{title:`Token for ${c.name}`,onClose:e,foot:t.jsx(A,{variant:"accent",onClick:e,children:"Done"}),children:t.jsxs("div",{className:"at-form",children:[t.jsxs("div",{className:"at-secret",children:[t.jsx("code",{className:"at-secret-text","aria-label":"The token",children:c.token}),t.jsx(A,{size:"sm",onClick:g,children:d?"Copied":"Copy"})]}),t.jsx(G,{tone:"warning",title:"Copy it now",children:"buddi keeps only a fingerprint of it, so it can’t show it again. Lost it? Revoke it and make another."}),t.jsx("p",{className:"at-text",children:"Send it as a header on every request:"}),t.jsx("code",{className:"at-try",children:`curl -H "Authorization: Bearer buddi_…" ${location.origin}/api/overview`})]})})}return t.jsx(zt,{title:"Make a token",onClose:e,foot:t.jsxs(t.Fragment,{children:[t.jsx(A,{variant:"ghost",onClick:e,children:"Cancel"}),t.jsx(A,{variant:"accent",disabled:!m,onClick:()=>p(),children:"Make token"})]}),children:t.jsxs("form",{className:"at-form",onSubmit:p,children:[t.jsx("p",{className:"at-text",children:"It acts as you on buddi’s HTTP API. Anything a gated tool does still waits for your approval here or on Telegram."}),t.jsx(re,{label:"What will use it",hint:`So you can tell tokens apart later. Up to ${Yp} characters.`,children:t.jsx("input",{autoFocus:!0,value:s,maxLength:Yp,placeholder:"Home Assistant",onChange:g=>{o(null),r(g.target.value)}})}),l?t.jsx(G,{tone:"critical",children:l}):null,t.jsx("button",{type:"submit",hidden:!0,"aria-hidden":"true",tabIndex:-1})]})})}function FQ({token:e,onClose:n,onRevoked:s}){const[r,a]=h.useState(!1),[i,l]=h.useState(null),o=()=>{a(!0),l(null),R.revokeApiToken(e.id).then(()=>{s(),n()}).catch(c=>{a(!1),l(oP(c))})};return t.jsxs(zt,{title:`Revoke “${e.name}”?`,onClose:n,foot:t.jsxs(t.Fragment,{children:[t.jsx(A,{variant:"ghost",onClick:n,children:"Cancel"}),t.jsx(A,{variant:"danger",disabled:r,onClick:o,children:"Revoke"})]}),children:[t.jsx("p",{className:"at-text",children:"A request carrying it is refused from now on. Whatever uses it stops working until you give it a new token."}),i?t.jsx(G,{tone:"critical",children:i}):null]})}function _Q({timezone:e}){var o;const n=me(()=>R.apiTokens(),[]),[s,r]=h.useState(!1),[a,i]=h.useState(null),l=((o=n.data)==null?void 0:o.tokens)??[];return t.jsxs(ie,{gap:"lg",children:[t.jsx("p",{className:"ui-page-lede",children:"Let a script or another program use buddi without the dashboard. A token acts as you, minus the decisions only you make here."}),t.jsx(ne,{message:n.error?"Couldn’t read the API tokens.":null}),t.jsx(ue,{title:"Tokens",aside:"Kept as a fingerprint · shown once",actions:t.jsx(A,{variant:"accent",size:"sm",onClick:()=>r(!0),children:"Make a token"}),panel:!0,flush:!0,children:n.data&&l.length===0?t.jsxs(ve,{title:"No tokens yet.",children:["Make one here, or in a terminal with ",t.jsx("code",{className:"mono",children:"buddi api-token create <name>"}),"."]}):t.jsx(at,{children:l.map(c=>t.jsx(Xe,{lead:t.jsx(Un,{icon:"key"}),title:c.name,sub:OQ(c,e),side:t.jsx(A,{size:"sm",variant:"ghost",onClick:()=>i(c),children:"Revoke…"})},c.id))})}),t.jsxs(ue,{title:"What a token can’t do",panel:!0,children:[t.jsxs("ul",{className:"at-cant",children:[t.jsx("li",{children:"Approve anything, or make a change where your click is the approval. It can reject."}),t.jsx("li",{children:"Change what an agent may do without asking: its tools, who it hands work to, a connection given out, an “Always”."}),t.jsx("li",{children:"Install or run code buddi hasn’t run before: plugins, upgrades, program connections."}),t.jsx("li",{children:"Change how buddi is reached or unlocked — PIN, Tailscale, Telegram pairing, other tokens — or restore a backup."}),t.jsx("li",{children:"Read or store a secret: owner secrets, model account keys, the backup passphrase."})]}),t.jsxs("p",{className:"at-foot",children:["In a terminal: ",t.jsx("code",{className:"mono",children:"buddi api-token create"}),", ",t.jsx("code",{className:"mono",children:"list"}),", ",t.jsx("code",{className:"mono",children:"revoke"}),". Every route, and which a token may call: docs/api.md."]})]}),s?t.jsx(LQ,{onClose:()=>r(!1),onMade:()=>n.reload()}):null,a?t.jsx(FQ,{token:a,onClose:()=>i(null),onRevoked:()=>n.reload()}):null]})}function zQ({embedded:e}){const{data:n,error:s,reload:r}=me(()=>R.owner(),[]);return t.jsxs(Zn,{embedded:e,title:"You",lede:"What every agent knows about the person it is talking to.",children:[t.jsx(ne,{message:s}),n?t.jsxs(ie,{gap:"lg",children:[t.jsx(WQ,{initial:n,onSaved:r}),t.jsx(GQ,{initial:n})]}):null]})}const cP=new Date(Date.UTC(2026,9,1,14,5));function UQ(){return[["",`Auto (${mu({timeFormat:null},()=>Xt(cP,"UTC"))} here)`],["12h","12-hour · 2:05 PM"],["24h","24-hour · 14:05"]]}function BQ(){return[["",`Auto (${mu({dateFormat:null},()=>Wr(cP,"UTC",{weekday:!0}))} here)`],["short","Thu, Oct 1"],["long","Thursday, 1 October"],["iso","2026-10-01"]]}function WQ({initial:e,onSaved:n}){var L,O,M;const[s,r]=h.useState(e.preferredName??""),[a,i]=h.useState(e.timezone??""),[l,o]=h.useState(e.timeFormat??""),[c,u]=h.useState(e.dateFormat??""),[d,f]=h.useState(e.language??""),[m,p]=h.useState(e.about??""),[g,v]=h.useState(e.fullName??""),[b,j]=h.useState(e.pronouns??""),[x,y]=h.useState(qh(e.birthday)),[w,k]=h.useState(!1),[N,S]=h.useState(!1),[C,E]=h.useState(null);h.useEffect(()=>{r(e.preferredName??""),i(e.timezone??""),o(e.timeFormat??""),u(e.dateFormat??""),f(e.language??""),p(e.about??""),v(e.fullName??""),j(e.pronouns??""),y(qh(e.birthday))},[e.preferredName,e.timezone,e.timeFormat,e.dateFormat,e.language,e.about,e.fullName,e.pronouns,(L=e.birthday)==null?void 0:L.day,(O=e.birthday)==null?void 0:O.month,(M=e.birthday)==null?void 0:M.year]);const T=Yh(x),I=s.trim()!==(e.preferredName??"")||a!==(e.timezone??"")||l!==(e.timeFormat??"")||c!==(e.dateFormat??"")||d.trim()!==(e.language??"")||m.trim()!==(e.about??"")||g.trim()!==(e.fullName??"")||b.trim()!==(e.pronouns??"")||T!=="incomplete"&&!DG(T,e.birthday),F=async()=>{k(!0),E(null);try{const P=await R.setOwner({preferredName:s.trim()===""?null:s.trim(),timezone:a===""?null:a,timeFormat:l===""?null:l,dateFormat:c===""?null:c,language:d.trim()===""?null:d.trim(),about:m.trim()===""?null:m.trim(),fullName:g.trim()===""?null:g.trim(),pronouns:b.trim()===""?null:b.trim(),...T!=="incomplete"?{birthday:T}:{}});Qj({timeFormat:P.timeFormat??null,dateFormat:P.dateFormat??null}),window.dispatchEvent(new Event(ux)),S(!0),n()}catch(P){E(P instanceof xe?P.message:String(P))}finally{k(!1)}},D=e.zones.length>0?e.zones:[e.detectedTimezone],$=P=>H=>{S(!1),P(H)};return t.jsx(ue,{title:"Your profile",aside:"read by every agent, as context",panel:!0,foot:t.jsxs(t.Fragment,{children:[N&&!I?t.jsx("span",{className:"muted",children:"Saved"}):null,t.jsx(A,{variant:"accent",disabled:!I||w,onClick:()=>void F(),children:w?"Saving…":"Save"})]}),children:t.jsxs(ie,{divided:!0,gap:"lg",children:[t.jsx(ue,{title:"Who you are",children:t.jsxs(Ns,{children:[t.jsx(re,{label:"Full name",hint:"For letters, forms and bookings.",children:t.jsx("input",{value:g,maxLength:120,placeholder:e.displayName??"Your full name",onChange:P=>$(v)(P.target.value)})}),t.jsx(re,{label:"What the agents call you",hint:"How you like to be addressed.",children:t.jsx("input",{value:s,maxLength:80,placeholder:e.displayName??"Your name",onChange:P=>$(r)(P.target.value)})}),t.jsx(re,{label:"Pronouns",hint:"Optional.",children:t.jsx("input",{value:b,maxLength:40,placeholder:"he/him, she/her, they/them…",onChange:P=>$(j)(P.target.value)})}),t.jsx(yv,{label:"Birthday",hint:"The year is optional. Your team greets you on the day.",value:x,onChange:$(y)})]})}),t.jsx(ue,{title:"Time and language",children:t.jsxs(Ns,{children:[t.jsx(re,{label:"Timezone",hint:`This host is in ${e.detectedTimezone}. Existing schedules keep the zone they were made in.`,children:t.jsxs("select",{value:a,onChange:P=>$(i)(P.target.value),children:[t.jsx("option",{value:"",children:"Not set (use the host's)"}),D.map(P=>t.jsx("option",{value:P,children:P},P))]})}),t.jsx(re,{label:"Time",children:t.jsx("select",{value:l,onChange:P=>$(o)(P.target.value),children:UQ().map(([P,H])=>t.jsx("option",{value:P,children:H},P))})}),t.jsx(re,{label:"Dates",hint:"Auto follows this browser's language. Agents write them your way too.",children:t.jsx("select",{value:c,onChange:P=>$(u)(P.target.value),children:BQ().map(([P,H])=>t.jsx("option",{value:P,children:H},P))})}),t.jsx(re,{label:"Answer me in",hint:"A language, as you would say it. Blank mirrors whatever you write in.",children:t.jsx("input",{value:d,maxLength:40,placeholder:"English, français…",onChange:P=>$(f)(P.target.value)})})]})}),t.jsxs(ue,{title:"About you",children:[t.jsx(re,{label:"In your own words",hint:"Who you are, how you like answers, anything every agent should keep in mind. A few lines is plenty.",children:t.jsx("textarea",{rows:4,maxLength:1e3,value:m,placeholder:"I run a small studio and prefer short answers with the numbers first. Call me by my first name.",onChange:P=>$(p)(P.target.value)})}),C?t.jsx(G,{tone:"critical",children:C}):null]})]})})}const HQ=["Home","Work"];function KQ(e){const n=e.trim().toLowerCase();return n==="home"?"home":n==="work"?"briefcase":"pin"}function uS({label:e,empty:n}){return t.jsx("span",{className:"place-glyph","data-empty":n?"true":void 0,"aria-hidden":"true",children:t.jsx(le,{name:KQ(e),size:18})})}function VQ(e){var s;const n=((s=e.name.split(",").pop())==null?void 0:s.trim())??"";return e.address?n&&!e.address.toLowerCase().includes(n.toLowerCase())?`${e.address} · ${n}`:e.address:e.name}function GQ({initial:e}){var c;const[n,s]=h.useState(e.places??[]);h.useEffect(()=>s(e.places??[]),[e]);const[r,a]=h.useState(null),i=e.timezone??e.detectedTimezone,l=HQ.filter(u=>!n.some(d=>d.label.toLowerCase()===u.toLowerCase())),o=h.useMemo(()=>new Date,[n]);return t.jsxs(ue,{title:"Places",aside:"the front desk, and plugins you allow",actions:t.jsx(A,{size:"sm",onClick:()=>a({label:""}),children:"Add a place"}),panel:!0,flush:!0,children:[t.jsxs(at,{children:[n.map(u=>t.jsx(Xe,{label:`${u.label}: edit`,onClick:()=>a({place:u,label:u.label}),lead:t.jsx(uS,{label:u.label}),title:u.label,sub:VQ(u),side:u.timezone&&u.timezone!==i?t.jsxs(Ee,{children:[Xt(o,u.timezone)," there"]}):void 0},u.id)),l.map(u=>t.jsx(Xe,{label:`${u}: add`,onClick:()=>a({label:u}),lead:t.jsx(uS,{label:u,empty:!0}),title:t.jsx("span",{className:"muted",children:u}),sub:"Not set",side:t.jsx(A,{size:"sm",onClick:d=>{d.stopPropagation(),a({label:u})},children:"Add"})},u))]}),t.jsx("p",{className:"place-note",children:"Only the town is looked up, on Open-Meteo, to find where it is and its timezone. The address stays on this computer."}),r?t.jsx(qQ,{editing:r,zones:e.zones.length>0?e.zones:[e.detectedTimezone],onClose:()=>a(null),onSaved:u=>{s(u),a(null)}},((c=r.place)==null?void 0:c.id)??`new:${r.label}`):null]})}function qQ({editing:e,zones:n,onClose:s,onSaved:r}){const a=e.place,[i,l]=h.useState(e.label),[o,c]=h.useState((a==null?void 0:a.address)??""),[u,d]=h.useState(a?[{name:a.name,latitude:a.latitude,longitude:a.longitude,...a.timezone?{timezone:a.timezone}:{}}]:null),[f,m]=h.useState(0),[p,g]=h.useState((a==null?void 0:a.timezone)??""),[v,b]=h.useState(null),[j,x]=h.useState(null),[y,w]=h.useState((a==null?void 0:a.address)??""),k=u==null?void 0:u[f],N=()=>{o.trim().length<2||(b("find"),x(null),R.findPlace(o.trim()).then(I=>{var F;d(I.found),w(o.trim()),m(0),g(((F=I.found[0])==null?void 0:F.timezone)??""),I.found.length===0&&x("Nothing found by that name. Try the town, with its country.")}).catch(I=>x(I instanceof xe?I.message:String(I))).finally(()=>b(null)))},S=()=>{k&&(b("save"),x(null),R.savePlace({...a?{id:a.id}:{},label:i.trim(),address:o.trim()===""?null:o.trim(),name:k.name,latitude:k.latitude,longitude:k.longitude,timezone:p===""?null:p}).then(I=>r(I.places)).catch(I=>x(I instanceof xe?I.message:String(I))).finally(()=>b(null)))},C=()=>{a&&(b("remove"),x(null),R.removePlace(a.id).then(I=>r(I.places)).catch(I=>x(I instanceof xe?I.message:String(I))).finally(()=>b(null)))},E=a?a.label:e.label?`Add ${e.label}`:"Add a place",T=p!==""&&!n.includes(p)?[p,...n]:n;return t.jsx(Ge,{title:E,onClose:s,foot:t.jsxs(te,{children:[a?t.jsx(A,{variant:"danger-ghost",disabled:v!==null,onClick:C,children:v==="remove"?"Removing…":"Remove"}):null,t.jsx(et,{}),t.jsx(A,{variant:"ghost",onClick:s,children:"Cancel"}),t.jsx(A,{variant:"accent",disabled:!k||i.trim()===""||v!==null,onClick:S,children:v==="save"?"Saving…":"Save"})]}),children:t.jsxs(ie,{gap:"lg",children:[t.jsx(re,{label:"Name",hint:"What you call it: Home, Work, Mum's.",children:t.jsx("input",{value:i,maxLength:40,autoFocus:!e.label,onChange:I=>l(I.target.value)})}),t.jsx(re,{label:"Address",hint:"A street address, or just the town.",action:t.jsx(A,{disabled:o.trim().length<2||v!==null,onClick:N,children:v==="find"?"Finding…":"Find"}),children:t.jsx("input",{value:o,maxLength:200,autoFocus:!!e.label&&!a,placeholder:"12 Elm Street, Portland, Maine",onChange:I=>c(I.target.value),onKeyDown:I=>{I.key==="Enter"&&(I.preventDefault(),N())}})}),u&&u.length>0?t.jsx("div",{className:"place-found",role:"radiogroup","aria-label":"Which place",children:u.map((I,F)=>t.jsxs("button",{type:"button",role:"radio","aria-checked":F===f,className:"place-option","data-on":F===f?"true":void 0,onClick:()=>{m(F),g(I.timezone??"")},children:[t.jsx("span",{className:"place-radio","aria-hidden":"true"}),t.jsxs("span",{className:"place-option-text",children:[t.jsx("span",{className:"place-option-name",children:I.name}),t.jsxs("span",{className:"place-option-sub",children:[I.latitude.toFixed(2),", ",I.longitude.toFixed(2),I.timezone?` · ${I.timezone}`:""]})]})]},`${I.latitude},${I.longitude}`))}):t.jsx("p",{className:"place-note-inline",children:"Find it to pin it on the map; nothing is saved until you say Save."}),a&&u&&o.trim()!==y?t.jsx("p",{className:"place-note-inline",children:"The address changed. Find it again to move the pin, or save to keep it where it is."}):null,t.jsx(re,{label:"Its timezone",hint:k?"From where it is. Change it if that is wrong.":"Filled in once the place is found.",children:t.jsxs("select",{value:p,disabled:!k,onChange:I=>g(I.target.value),children:[t.jsx("option",{value:"",children:"Not known"}),T.map(I=>t.jsx("option",{value:I,children:I},I))]})}),t.jsx(ne,{message:j})]})})}const YQ=2e6;function dS(e,n){const s=e.replace(/\r\n/g,`
131
- `).replace(/\n+$/,"").split(`
132
- `),r=n.replace(/\r\n/g,`
133
- `).replace(/\n+$/,"").split(`
134
- `);if(e.trim()===n.trim())return"(no change)";if(s.length*r.length>YQ)return[...s.map(c=>`-${c}`),...r.map(c=>`+${c}`)].join(`
135
- `);const a=Array.from({length:s.length+1},()=>new Uint32Array(r.length+1));for(let c=s.length-1;c>=0;c--)for(let u=r.length-1;u>=0;u--)a[c][u]=s[c]===r[u]?a[c+1][u+1]+1:Math.max(a[c+1][u],a[c][u+1]);const i=[];let l=0,o=0;for(;l<s.length&&o<r.length;)s[l]===r[o]?(i.push(` ${s[l]}`),l++,o++):a[l+1][o]>=a[l][o+1]?i.push(`-${s[l++]}`):i.push(`+${r[o++]}`);for(;l<s.length;)i.push(`-${s[l++]}`);for(;o<r.length;)i.push(`+${r[o++]}`);return i.join(`
136
- `)}const uP={skill:"skill",policy:"rule",change:"change to itself"};function JQ(e){return e===null||typeof e!="object"||Array.isArray(e)?String(e??""):Object.entries(e).filter(([n,s])=>!/Id$/.test(n)&&s!==null&&s!==void 0&&s!=="").map(([n,s])=>`${n} ${typeof s=="object"?JSON.stringify(s):String(s)}`).join(" · ")}function Tv(e){return[...new Set(e.split(/[,\n]/).map(n=>n.trim().replace(/^[-*]\s+/,"")).filter(n=>n!==""))]}function QQ(e,n){const s=e.change;if(!s||s.part!=="tools")return[];if(n===e.editable)return s.added;const r=new Set(Tv(s.current??""));return Tv(n).filter(a=>!r.has(a))}function XQ(e){const n=i=>i.kind==="policy"&&i.ruleKind?`${String(i.payload.plugin??"")}\0${i.ruleKind}`:null,s=new Map;for(const i of e){const l=n(i);l&&s.set(l,(s.get(l)??0)+1)}const r=new Map,a=[];for(const i of e){const l=n(i);if(!l||(s.get(l)??0)<2){a.push(i);continue}let o=r.get(l);o||(o={key:l,label:i.ruleKindLabel||i.ruleKind||"Rules",plugin:String(i.payload.plugin??""),cards:[]},r.set(l,o),a.push(o)),o.cards.push(i)}return a}function ZQ(e){return"cards"in e}function hS(e,n){return!n||e.kind==="policy"&&e.payload.plugin===n}function eX({embedded:e,plugin:n}){const{data:s,error:r,reload:a}=me(()=>R.proposals(),[],3e4),[i,l]=h.useState(null),[o,c]=h.useState(null),[u,d]=h.useState(null),[f,m]=h.useState({}),p=async(x,y,w=!1)=>{l(null),c(null),d(x),m(({[x]:k,...N})=>N);try{c(await y()),a()}catch(k){const N=k instanceof Error?k.message:String(k);w?m(S=>({...S,[x]:N})):l(N)}finally{d(null)}},g=LT(),v=((s==null?void 0:s.open)??[]).filter(x=>hS(x,n)),b=((s==null?void 0:s.closed)??[]).filter(x=>hS(x,n)),j=x=>t.jsx(aX,{proposal:x,busy:u===x.id,refusal:f[x.id]??null,onKeep:y=>void p(x.id,async()=>{const w=await R.keepProposal(x.id,y);return`${x.title}: ${w.note}`},!0),onDiscard:y=>void p(x.id,async()=>(await R.discardProposal(x.id,y),`Discarded: ${x.title}. ${x.agent} will be told once and will not propose it again for 90 days.`))},x.id);return t.jsxs(Zn,{embedded:e,title:"Proposals",lede:"What your agents learned and would like to keep: a procedure, a rule, a change to their own instructions. Keep what is right, correct what is nearly right, discard the rest. A few rules apply themselves, where their plugin allows it (one you always keep, one that only quiets mail sent to many); its own page lists them, with Undo.",children:[t.jsx(ne,{message:r??i}),n?t.jsxs(G,{role:"status",children:["Showing the rules ",n," proposes. ",t.jsx("a",{href:Le("proposals"),children:"Show every proposal"})]}):null,o?t.jsx(G,{tone:"good",role:"status",children:o}):null,n?null:t.jsx(FT,{offers:g.offers,reload:g.reload}),!s||v.length===0?t.jsx(ue,{title:"Waiting",panel:!0,children:s?n?t.jsx(Jn,{icon:"bulb",title:`No rule from ${n} is waiting`,children:"It proposes one when you decide the same way several times running."}):t.jsx(Jn,{icon:"bulb",title:"Nothing proposed",children:"When an agent learns something worth keeping, it waits here."}):t.jsx(ve,{children:"Loading…"})}):t.jsx(ue,{title:"Waiting",aside:`${v.length} to decide`,children:XQ(v).map(x=>ZQ(x)?t.jsx(tX,{group:x,busy:u===x.key,onKeepAll:()=>void p(x.key,async()=>{const y=await R.keepAllProposals(x.cards.map(w=>w.id));return`${x.label}: ${y.note}`}),card:y=>j(y)},x.key):j(x))}),b.length>0?t.jsx(ue,{title:`Kept, discarded and expired (${b.length})`,aside:"These stop being shown a week after they were decided.",panel:!0,flush:!0,children:t.jsx(at,{children:b.map(x=>{var y;return t.jsx(Xe,{title:x.title,sub:`${x.agent}: ${nX(x)}`,side:x.kind==="skill"&&x.state==="kept"&&((y=x.skill)!=null&&y.live)?t.jsxs(te,{align:"end",children:[t.jsx("span",{className:"muted",children:Ve(x.decidedAt??x.createdAt)}),t.jsx(A,{size:"sm",variant:"ghost",disabled:u===x.id,onClick:()=>void p(x.id,async()=>{const w=x.skill;return await R.removeSkill(x.agent,w.name),`Removed ${w.name} from ${x.agent}. Its versions are kept, and ${x.agent} will not propose it again for 90 days.`}),children:"Remove this skill"})]}):Ve(x.decidedAt??x.createdAt)},x.id)})})}):null,!n&&(s!=null&&s.digest)?t.jsx(rX,{schedule:s.digest.schedule,onSaved:a}):null]})}function tX({group:e,busy:n,onKeepAll:s,card:r}){const a=e.cards.length,i=e.cards.some(l=>l.untrusted);return t.jsx(Ts,{tone:i?"warning":"accent",title:`${e.label} (${a})`,meta:t.jsxs(t.Fragment,{children:[t.jsx(Ee,{children:uP.policy}),t.jsx(Ee,{mono:!0,children:e.plugin})]}),foot:t.jsx(te,{align:"end",children:t.jsxs(A,{variant:"accent",size:"sm",disabled:n,onClick:s,children:["Keep all (",a,")"]})}),children:t.jsxs(ie,{gap:"sm",children:[t.jsxs("p",{children:[a," rules of the same kind from ",e.plugin,", each learned from your own decisions. Keep all keeps every one of them as if you had kept each, in one go."]}),t.jsx(Ot,{summary:`Show each of the ${a}`,children:t.jsx(ie,{gap:"sm",children:e.cards.map(l=>r(l))})})]})})}function nX(e){switch(e.state){case"kept":return e.decidedBy==="auto"?e.note??"Kept by itself.":e.kind==="skill"&&e.skill?e.skill.live?`Kept as ${e.skill.name}, version ${e.skill.version}; it loads on the agent's next run.`:`Kept; ${e.skill.name} has a newer version now (${e.skill.version}).`:e.note??"Kept.";case"discarded":return e.reason?`Discarded: ${e.reason}`:"Discarded.";case"expired":return`Expired: ${e.reason??"not decided in 30 days"}.`;default:return"Waiting."}}const sX=Array.from({length:24},(e,n)=>n),fS=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];function rX({schedule:e,onSaved:n}){const[s,r]=h.useState(e.day),[a,i]=h.useState(e.hour),[l,o]=h.useState(!1),[c,u]=h.useState(null),d=s!==e.day||a!==e.hour,f=async()=>{o(!0),u(null);try{await R.setDigestSchedule(s,a),u({tone:"good",text:`The digest now runs on ${fS[s]} at ${String(a).padStart(2,"0")}:00.`}),n()}catch(m){u({tone:"critical",text:m instanceof Error?m.message:String(m)})}finally{o(!1)}};return t.jsx(ue,{title:"Weekly digest",panel:!0,foot:t.jsx(A,{variant:"accent",disabled:l||!d,onClick:()=>void f(),children:"Save"}),children:t.jsxs(ie,{children:[t.jsxs("p",{className:"muted",children:["Once a week, one message on Telegram and a card on Home: what your agents learned, what waits here, and what the rules you kept stopped them doing. No message when nothing was learned and nothing waits.",e.next?` Next: ${Ve(e.next)}.`:""]}),t.jsxs(te,{children:[t.jsx(re,{label:"Day",children:t.jsx("select",{value:s,disabled:l,onChange:m=>r(Number(m.target.value)),children:fS.map((m,p)=>t.jsx("option",{value:p,children:m},m))})}),t.jsx(re,{label:`Hour (${e.timezone})`,children:t.jsx("select",{value:a,disabled:l,onChange:m=>i(Number(m.target.value)),children:sX.map(m=>t.jsxs("option",{value:m,children:[String(m).padStart(2,"0"),":00"]},m))})})]}),c?t.jsx(G,{tone:c.tone,role:"status",children:c.text}):null]})})}function mS(e,n){return e==="tools"?Tv(n).join(`
137
- `):n}function aX({proposal:e,busy:n,refusal:s,onKeep:r,onDiscard:a}){const[i,l]=h.useState(e.editable??""),[o,c]=h.useState(""),u=e.editable!==null&&i!==e.editable,d=e.payload,f=e.echoes??[],m=e.kind==="change"?e.change??null:null,p=QQ(e,i);return t.jsx(Ts,{tone:e.untrusted?"warning":"accent",title:e.title,meta:t.jsxs(t.Fragment,{children:[t.jsx(Ee,{children:uP[e.kind]}),t.jsx(Ee,{mono:!0,children:e.agent}),e.untrusted?t.jsx(Ee,{tone:"warning",children:"untrusted text in view"}):null,p.length>0?t.jsx(Ee,{tone:"warning",children:"widens its tools"}):null]}),foot:t.jsxs(te,{align:"end",children:[s?t.jsx("span",{className:"proposal-refusal",role:"alert",children:s}):null,t.jsx("input",{"aria-label":"Reason for discarding (optional)",placeholder:"Reason for discarding (optional)",value:o,maxLength:300,disabled:n,onChange:g=>c(g.target.value)}),t.jsx(A,{variant:"ghost",size:"sm",disabled:n,onClick:()=>a(o.trim()||void 0),children:"Discard"}),t.jsx(A,{variant:"accent",size:"sm",disabled:n||e.editable!==null&&i.trim()==="",onClick:()=>r(u?i:void 0),children:u?"Keep my version":"Keep"})]}),children:t.jsxs(ie,{gap:"sm",children:[e.why?t.jsx("p",{children:e.why}):null,t.jsxs("p",{className:"ui-card-meta",children:["Proposed by ",e.agent," ",Ve(e.createdAt),e.conversationId?t.jsxs(t.Fragment,{children:[" in ",t.jsx("a",{href:qc(e.conversationId),children:e.turn?`this conversation, turn ${e.turn}`:"this conversation"})]}):null,"."]}),e.untrusted?t.jsxs(G,{tone:"warning",title:e.kind==="policy"?"Learned from mail you received.":"Made with untrusted text in view.",children:[e.kind==="policy"?"The plugin counted this rule from your own triage decisions; no instruction in that mail can change what it does.":"Something written by someone other than you was in the agent's context when it proposed this. Read it for instructions that came from there rather than from you.",t.jsx("ul",{className:"proposal-sources",children:e.sources.map(g=>t.jsx("li",{className:"mono",children:g},g))}),f.length>0?t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"proposal-echo-lede",children:"These sentences of it also appear in that text:"}),t.jsx("ul",{className:"proposal-sources","aria-label":"Sentences found in the untrusted text",children:f.map(g=>t.jsx("li",{children:t.jsx("mark",{className:"wb-diff-mark",children:g})},g))})]}):null]}):null,e.kind==="skill"?t.jsxs(t.Fragment,{children:[typeof d.when=="string"?t.jsxs("p",{className:"ui-card-meta",children:["When: ",d.when]}):null,e.skill?t.jsxs(ie,{gap:"sm",children:[t.jsxs("p",{className:"ui-card-meta",children:[e.agent," already has this skill (",t.jsxs("a",{href:Pt(e.agent,"skills"),children:[e.skill.name,", version ",e.skill.version]}),"). Keeping this writes version ",e.skill.version+1,"; the earlier ones stay readable."]}),t.jsx($h,{text:dS(e.skill.steps,i),marks:f,label:`Version ${e.skill.version} against this proposal`})]}):null,t.jsx(re,{label:"The steps, as it would follow them",hint:"Correct them here and keep your version.",children:t.jsx("textarea",{rows:8,value:i,disabled:n,onChange:g=>l(g.target.value)})})]}):null,e.kind==="change"?t.jsxs(t.Fragment,{children:[p.length>0?t.jsxs(G,{tone:"warning",title:`Adds: ${p.join(", ")}`,children:["Keeping this lets ",e.agent," call tools it cannot call now."]}):null,m!=null&&m.refusal&&!u?t.jsx(G,{tone:"warning",title:"Keeping this as proposed will be refused.",children:m.refusal}):null,m&&m.current!==null?t.jsx($h,{text:dS(mS(m.part,m.current),mS(m.part,i)),marks:f,label:`${e.agent}'s ${m.part==="tools"?"tool list":"instructions"} now, against this proposal`}):typeof d.before=="string"?t.jsx(Ot,{summary:`What its ${d.part==="tools"?"tool list":"instructions"} said when proposed`,children:t.jsx(Dt,{children:d.before})}):null,t.jsx(re,{label:d.part==="tools"?"Proposed tool list":"Proposed instructions",hint:"Correct it here and keep your version.",children:t.jsx("textarea",{rows:8,value:i,disabled:n,onChange:g=>l(g.target.value)})})]}):null,e.kind==="policy"?t.jsx(qt,{items:[{label:"Plugin",value:t.jsx("span",{className:"mono",children:String(d.plugin??"")})},{label:"Matches",value:t.jsx("span",{className:"mono",children:JQ(d.matcher??{})})},{label:"Does",value:String(d.action??"")},...Array.isArray(d.verdicts)&&d.verdicts.length>0?[{label:"Learned from",value:`${d.verdicts.length} ${d.verdicts.length===1?"decision":"decisions"}`}]:[]]}):null]})})}function dP(e){return e.length>1?"small or medium":`${e[0]} only`}function iX(e){return["small","medium"].filter(n=>e.includes(n))}function hP({widget:e,size:n,svg:s}){var a;const r=(a=e.preview)==null?void 0:a[n];return t.jsxs("div",{className:"wg-frame","data-variant":"preview","data-size":n,"data-kind":r==null?void 0:r.kind,role:"img","aria-label":`${e.title}, ${n}: ${r?"a preview with sample data":"no preview"}`,children:[t.jsxs("div",{className:"wg-head",children:[t.jsx("span",{className:"wg-title",children:e.title}),r?t.jsx("span",{className:"wg-sample",children:"Sample"}):null]}),t.jsx("div",{className:"wg-body",children:r?t.jsx(om,{body:r,size:n}):t.jsxs("span",{className:"wg-state",children:[t.jsx(Un,{svg:s}),t.jsx("span",{className:"wg-state-sub",children:"No preview from this plugin."})]})})]})}function lX(e){const n=[{label:"Home",path:e.home}];if(e.path===e.home||!e.path.startsWith(`${e.home}/`))return n;let s=e.home;for(const r of e.path.slice(e.home.length+1).split("/"))s=`${s}/${r}`,n.push({label:r,path:s});return n}function oX({start:e,onPick:n,onClose:s}){const[r,a]=h.useState(null),[i,l]=h.useState(null),[o,c]=h.useState(""),u=(p,g=!1)=>{l(null),R.pluginFolders(p).then(v=>{a(v),c("")}).catch(v=>{g&&p!==void 0?u(void 0):l(v instanceof xe?v.message:String(v))})};h.useEffect(()=>{u(e,!0)},[]);const d=o.trim().toLowerCase(),f=((r==null?void 0:r.folders)??[]).filter(p=>d===""||p.name.toLowerCase().includes(d)),m=r?lX(r):[];return t.jsxs(Ge,{title:"Choose the folder",onClose:s,foot:t.jsxs(te,{children:[t.jsx("span",{className:"plugins-foot-note mono",children:(r==null?void 0:r.path)??""}),t.jsx(et,{}),t.jsx(A,{variant:"ghost",onClick:s,children:"Cancel"}),t.jsx(A,{variant:"accent",disabled:!r,onClick:()=>r&&n(r.path),children:"Use this folder"})]}),children:[t.jsx("p",{className:"plugins-note",children:"Folders on the computer buddi runs on, inside your home directory. The one you want holds the plugin's package.json and is already built."}),r?t.jsx(Ih,{label:"Folder",items:m.map((p,g)=>g===m.length-1?{key:p.path,label:p.label,current:!0}:{key:p.path,label:p.label,onClick:()=>u(p.path)})}):null,t.jsx(nm,{label:"Find a folder here",value:o,placeholder:"Find a folder here…",onChange:c}),t.jsx(ne,{message:i}),r?f.length===0?t.jsx(ve,{children:d===""?"No folders in here.":`No folder here is called anything like “${o.trim()}”.`}):t.jsx(Ye,{flush:!0,children:t.jsx(at,{children:f.map(p=>t.jsx(Xe,{onClick:()=>u(p.path),label:`Open ${p.name}`,lead:t.jsx(Un,{icon:"folder"}),title:p.name,side:p.plugin?t.jsx(Ee,{tone:"accent",children:"package.json"}):void 0},p.path))})}):i?null:t.jsx(ve,{children:"Reading the folders…"}),r!=null&&r.truncated?t.jsx("p",{className:"plugins-note",children:"Only the first 500 folders are listed; find one by name above."}):null]})}const cX="New tools and pages for your team, written by someone else. Each one is read with you, fact by fact, before any of it runs.";function pS(){return t.jsxs("p",{className:"plugins-quiet connections-quiet",children:[t.jsx(le,{name:"globe",size:14}),t.jsxs("span",{children:["A plugin is code buddi installs and runs; a connection is a service or program buddi talks to."," ",t.jsx("a",{href:Le("connections"),children:"Connections"})]})]})}const uX=1500,dX={fetching:"Fetching the package.","installing-dependencies":"Installing its dependencies. Nothing of the plugin has run.",reading:"Reading what it says it is.",done:"Read. Nothing has been imported yet.",failed:"That did not work."},hX="Restart buddi to apply it. In a checkout, stop it and run: buddi serve",fP=[{value:"npm",label:"From npm"},{value:"file",label:"A file"},{value:"directory",label:"A directory I built"}],mP="buddi.plugins.install-mode";function fX(){try{const e=window.localStorage.getItem(mP);if(fP.some(n=>n.value===e))return e}catch{}return"npm"}function mX(e){try{window.localStorage.setItem(mP,e)}catch{}}const wd=".tgz",Ir=(e,n,s)=>`${e} ${e===1?n:s}`;function pP(e){const n=[];return e.tools>0&&n.push(Ir(e.tools,"tool","tools")),e.sentinels>0&&n.push(`${e.sentinels} on a timer`),e.views>0&&n.push(Ir(e.views,"view","views")),e.agents>0&&n.push(`${Ir(e.agents,"agent","agents")} proposed`),n.length===0?"nothing on its own":n.join(", ")}function Rv(e){return e.kind==="registry"?`npm · ${e.name}@${e.version}`:e.kind==="tarball"?`a file on this machine · ${e.path}`:`a directory on this machine · ${e.path}`}function gP(e){return e.kind==="registry"?"npm":e.kind==="tarball"?"a file":"a directory"}function Dw(e,n){return e.kind==="directory"?"you, from this machine":e.kind==="tarball"?"a file on this machine":n??"nobody npm will name"}function xP(e){return e.author?e.author.name:e.source.kind==="registry"?e.publisher??"nobody npm will name":"you"}function mm({author:e}){return e.url?t.jsx("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",children:e.name}):t.jsx(t.Fragment,{children:e.name})}function Iv({value:e}){return e===void 0||e===""?t.jsx("span",{className:"muted",children:"none — this came off a disk"}):t.jsx("span",{className:"plugins-hash",children:e})}function vP(e){return e.length===0?"none; nothing leaves this computer":t.jsx("span",{className:"mono",children:e.join(", ")})}function Ow(e){return e.length===0?"Nothing beyond its own tables, its own folder and its own tools' approvals.":e.map(n=>`It ${n.words}.`).join(" ")}const Xa=e=>e instanceof xe?e.message:String(e);function pX(e){const[n,s]=h.useState(void 0),[r,a]=h.useState(null);return h.useEffect(()=>{if(!e){s(void 0),a(null);return}let i=!1;const l=()=>{R.pluginJob(e).then(c=>{i||(s(c),(c.phase==="done"||c.phase==="failed")&&(i=!0))}).catch(c=>{i||(a(Xa(c)),i=!0)})};l();const o=window.setInterval(l,uX);return()=>{i=!0,window.clearInterval(o)}},[e]),{job:n,error:r}}function gX({plugin:e,pages:n,navigate:s,variant:r}){const a=n.filter(i=>i.plugin===e);return a.length===0?null:t.jsx(t.Fragment,{children:a.map(i=>{const l=Or(i.plugin,i.id);return t.jsx(ht,{size:"sm",variant:r,href:l,"aria-label":`Open ${i.title}`,onClick:o=>{o.stopPropagation(),s&&(o.preventDefault(),s(l))},children:a.length===1?"Open":`Open ${i.title}`},i.id)})})}function jP({plugin:e}){var s;if(e.enabled===!1)return t.jsx(Ee,{children:"disabled"});const n=(s=e.needs)==null?void 0:s[0];return n?t.jsxs(Ee,{tone:"warning",children:["needs ",n.plugin]}):e.loadsAtRestart?t.jsx(Ee,{tone:"accent",children:"loads at restart"}):e.loaded&&e.setup?t.jsx(Ee,{tone:"warning",children:"needs setup"}):e.loaded?t.jsx(Ee,{tone:"good",dot:!0,children:"loaded"}):t.jsx(Ee,{tone:"critical",children:"did not load"})}function Lw({entry:e}){var n;return e.trust==="by-buddi"?t.jsx(Ee,{tone:"accent",children:"by buddi"}):t.jsxs(Ee,{tone:"good",children:["reviewed ",((n=e.reviewed)==null?void 0:n.version)??e.version]})}const Pv=Le("plugins"),Jp={installed:Pv,browse:`${Pv}?tab=browse`};function xX({railPages:e=[],settingsPages:n=[],navigate:s,hash:r=""}={}){const a=me(()=>R.plugins(),[],2e4),[i,l]=h.useState(null),{job:o,error:c}=pX(i),[u,d]=h.useState(null),[f,m]=h.useState(()=>o0(r));h.useEffect(()=>m(o0(r)),[r]);const[p,g]=h.useState(()=>l0(r));h.useEffect(()=>g(l0(r)),[r]);const[v,b]=h.useState(null),[j,x]=h.useState(null),[y,w]=h.useState(null),[k,N]=h.useState(null),[S,C]=h.useState(!1),E=Q=>{C(!0),R.market(Q).then(N).catch(Ae=>N({plugins:[],unavailable:Xa(Ae)})).finally(()=>C(!1))};h.useEffect(()=>{f==="browse"&&k===null&&!S&&E(!1)},[f]);const T=Q=>{d(null),l(Q)},I=Q=>d(Xa(Q)),[F,D]=h.useState(!1),$=Q=>{D(!0),b(null),Q.then(Ae=>{T(Ae.job.id),m("installed")}).catch(I).finally(()=>D(!1))},L=h.useRef(null);h.useEffect(()=>{const Q=y3(r);if(!(Q===null||L.current===Q)){L.current=Q,m("installed"),$(R.stagePlugin(Q));try{window.history.replaceState(window.history.state,"",Pv)}catch{}}},[r]);const O=Q=>Ae=>{Ae.preventDefault(),m(Q),b(null),s==null||s(Jp[Q])};h.useEffect(()=>{((o==null?void 0:o.phase)==="done"||(o==null?void 0:o.phase)==="failed")&&a.reload()},[o==null?void 0:o.phase]);const M=a.data,P=(M==null?void 0:M.checkout)??!0,H=(M==null?void 0:M.installed)??[],U=Q=>k==null?void 0:k.plugins.find(Ae=>Ae.installed!==void 0&&(Ae.installed.name??Ae.name)===Q.name),V=Q=>e.some(Ae=>Ae.plugin===Q),z=(Q,Ae)=>V(Q)?t.jsx(gX,{plugin:Q,pages:e,navigate:s,variant:Ae}):void 0,X=Q=>{const Ae=e.find(tt=>tt.plugin===Q);Ae&&s&&s(Or(Ae.plugin,Ae.id))},K=Q=>{const Ae=n.find(tt=>tt.plugin===Q);if(!(!Ae||!s))return()=>s(Lr(Ae.plugin,Ae.id))},ee=((k==null?void 0:k.plugins)??[]).filter(Q=>Q.update).length,ce=(Q,Ae)=>R.setPluginEnabled(Q,Ae).then(tt=>{jB(),w({name:Q,notes:tt.notes??[]}),a.reload()}),pe=(Q,Ae,tt)=>R.uninstallPlugin(Q,Ae?{purge:!0,confirm:tt}:{}).then(Ct=>{b(null),w({name:Q,notes:Ct.notes??[]}),a.reload()}),oe=Q=>{d(null),ce(Q,!0).catch(I)},Re=(Q,Ae)=>{const tt=k==null?void 0:k.plugins.find(yt=>{var kt;return(((kt=yt.installed)==null?void 0:kt.name)??yt.name)===Q&&yt.installed!==void 0}),Ct=tt&&Ae?`${tt.npm}@${Ae}`:void 0;$(Ct?R.updatePlugin(Q,Ae,Ct):R.updatePlugin(Q,Ae))},Oe=Q=>{d(null);const Ae=tt=>{const Ct=tt.plugins.find(yt=>{var kt;return yt.name===Q||((kt=yt.installed)==null?void 0:kt.name)===Q});if(!Ct){d(`${Q} is not listed on withbuddi.com. Add it from npm, a file or a directory above, then install this one.`);return}$(R.stagePlugin(`${Ct.npm}@${Ct.version}`))};if(k&&k.plugins.length>0)return Ae(k);D(!0),R.market(!1).then(tt=>{N(tt),Ae(tt)}).catch(I).finally(()=>D(!1))},Je=(Q,Ae)=>Ae===void 0?void 0:Ae.place==="settings"?Lr(Q,Ae.id):Or(Q,Ae.id),W=Q=>{var tt;if(Q.enabled===!1)return;const Ae=(tt=Q.needs)==null?void 0:tt[0];if(Ae)switch(Ae.state){case"missing":return{label:`Install ${Ae.plugin}`,run:()=>Oe(Ae.plugin)};case"disabled":return{label:`Enable ${Ae.plugin}`,run:()=>oe(Ae.plugin)};case"range":return{label:`Update ${Ae.plugin}`,run:()=>Re(Ae.plugin)};case"setup":{const Ct=Je(Ae.plugin,Ae.page),yt=Ct&&s?()=>s(Ct):K(Ae.plugin);return yt?{label:`Set up ${Ae.plugin}`,run:yt}:void 0}default:return{label:`See ${Ae.plugin}`,run:()=>b({kind:"installed",name:Ae.plugin})}}if(Q.loaded&&Q.setup){const Ct=Je(Q.name,Q.setup.page),yt=Ct&&s?()=>s(Ct):K(Q.name);return yt?{label:"Set it up",run:yt}:void 0}},se=t.jsxs(yo,{label:"Plugins",children:[t.jsx(Li,{href:Jp.installed,active:f==="installed",count:ee,onClick:O("installed"),children:"Installed"}),t.jsx(Li,{href:Jp.browse,active:f==="browse",onClick:O("browse"),children:"Browse"})]}),Y=(M==null?void 0:M.staged)??[],Ne=SX(Y,(o==null?void 0:o.phase)==="done"?o.stagedId:void 0),we=Y.find(Q=>Q.id===Ne),fe=Y.filter(Q=>Q.id!==Ne),ge=Q=>{b(null),EX(Q),l(null),a.reload()},Pe=(v==null?void 0:v.kind)==="staged"?fe.find(Q=>Q.id===v.name):void 0,je=(v==null?void 0:v.kind)==="installed"?H.find(Q=>Q.name===v.name):void 0,de=(v==null?void 0:v.kind)==="market"?k==null?void 0:k.plugins.find(Q=>Q.name===v.name):void 0,ke=y&&!(je&&je.name===y.name)&&y.notes.length>0?y.notes:null,Be=Pe?t.jsx(kX,{staged:Pe,onClose:()=>b(null),onInstalled:ge,onInstallFirst:Oe,onGone:()=>{b(null),a.reload()}},Pe.id):je?t.jsx(MX,{plugin:je,listing:U(je),notes:(y==null?void 0:y.name)===je.name?y.notes:null,canOpen:V(je.name)&&je.enabled!==!1,onOpen:()=>X(je.name),onClose:()=>b(null),onDisable:()=>x({kind:"disable",name:je.name}),onEnable:()=>oe(je.name),onRemove:()=>x({kind:"remove",name:je.name}),onUpdate:Q=>Re(je.name,Q),onSettings:je.enabled===!1?void 0:K(je.name),firstStep:W(je),busy:F}):de?t.jsx(BX,{entry:de,canOpen:de.installed!==void 0&&V(de.installed.name??de.name),onOpen:()=>{var Q;return X(((Q=de.installed)==null?void 0:Q.name)??de.name)},onClose:()=>b(null),onInstall:()=>$(R.stagePlugin(`${de.npm}@${de.version}`)),onUpdate:Q=>{var Ae;return Re(((Ae=de.installed)==null?void 0:Ae.name)??de.name,Q)},busy:F}):null,Ue=j?H.find(Q=>Q.name===j.name):void 0,ut=j?t.jsx(DX,{kind:j.kind,name:j.name,canDisable:(Ue==null?void 0:Ue.enabled)!==!1,onCancel:()=>x(null),onDisableInstead:()=>x({kind:"disable",name:j.name}),onDisable:()=>ce(j.name,!1).then(()=>x(null)),onRemove:(Q,Ae)=>pe(j.name,Q,Ae).then(()=>x(null))},`${j.kind}:${j.name}`):null;if(f==="browse")return t.jsxs(ie,{gap:"lg",children:[t.jsx(pS,{}),se,t.jsx(ne,{message:u}),t.jsx(GX,{kind:p,onKind:g,navigate:s,market:k,loading:S,busy:F,onRetry:()=>E(!0),onOpen:Q=>b({kind:"market",name:Q.name}),onInstall:Q=>$(R.stagePlugin(`${Q.npm}@${Q.version}`)),onUpdate:(Q,Ae)=>{var tt;return Re(((tt=Q.installed)==null?void 0:tt.name)??Q.name,Ae)}}),Be]});const dt=(M==null?void 0:M.builtIn)??[];return t.jsxs(ie,{gap:"lg",children:[t.jsx(pS,{}),se,t.jsx(ne,{message:a.error??u??c}),M!=null&&M.unavailable?t.jsx(G,{tone:"warning",children:M.unavailable}):null,ke?t.jsx(G,{role:"status",children:ke.join(" ")}):null,t.jsx(vX,{trust:(M==null?void 0:M.trust)??"",job:o,busy:o!==void 0&&o.phase!=="done"&&o.phase!=="failed",onStaged:T,onFailed:d}),we?t.jsx(wX,{staged:we,onInstalled:ge,onGone:()=>a.reload(),onInstallFirst:Oe},we.id):null,fe.length>0?t.jsx(Ye,{flush:!0,title:"Waiting for you",tool:Ir(fe.length,"package","packages"),children:t.jsx("div",{className:"plugins-rows",children:t.jsx(at,{children:fe.map(Q=>t.jsx(bX,{staged:Q,onReview:()=>{wP(Q),b({kind:"staged",name:Q.id})},onReject:()=>{d(null),R.rejectStaged(Q.id).then(()=>a.reload()).catch(I)}},Q.id))})})}):null,M!=null&&M.restartNeeded?t.jsx(CX,{checkout:P,waiting:H.filter(Q=>Q.loadsAtRestart)}):null,t.jsx($X,{list:H,firstStepFor:W}),t.jsx(Ye,{flush:!0,title:"Installed",tool:M?Ir(H.length,"plugin","plugins"):void 0,children:M?H.length===0?t.jsx(ve,{children:"Nothing installed yet. Only what buddi ships with is here."}):t.jsx("div",{className:"plugins-rows",children:t.jsx(at,{children:H.map(Q=>t.jsx(RX,{plugin:Q,listing:U(Q),open:Q.enabled===!1?void 0:z(Q.name,"ghost"),canOpen:V(Q.name)&&Q.enabled!==!1,busy:F,onDetails:()=>b({kind:"installed",name:Q.name}),onOpen:()=>X(Q.name),onSettings:Q.enabled===!1?void 0:K(Q.name),onDisable:()=>x({kind:"disable",name:Q.name}),onEnable:()=>oe(Q.name),onRemove:()=>x({kind:"remove",name:Q.name}),onUpdate:Ae=>Re(Q.name,Ae),firstStep:W(Q)},Q.name))})}):t.jsx(ve,{children:"Loading…"})}),dt.length>0?t.jsx(OX,{plugins:dt,openFor:z}):null,Be,ut]})}function vX({trust:e,job:n,busy:s,onStaged:r,onFailed:a}){const[i,l]=h.useState(fX),[o,c]=h.useState(""),[u,d]=h.useState(!1),[f,m]=h.useState(null),[p,g]=h.useState(null),[v,b]=h.useState(!1),[j,x]=h.useState(!1),y=h.useRef(null),w=C=>a(Xa(C)),k=C=>{l(C),mX(C),g(null)},N=()=>{d(!0),R.stagePlugin(o.trim()).then(C=>{r(C.job.id),c("")}).catch(w).finally(()=>d(!1))},S=C=>{if(C){if(!C.name.toLowerCase().endsWith(wd)){m(null),g(`${C.name} is not a ${wd}. A packed plugin is the file npm pack writes.`);return}g(null),m(C.name),d(!0),R.uploadPlugin(C).then(E=>r(E.job.id)).catch(w).finally(()=>d(!1))}};return t.jsxs(Ye,{title:"Add a plugin",actions:t.jsx(ln,{label:"Where it comes from",options:fP,value:i,onChange:k}),children:[t.jsxs("div",{className:"plugins-add",children:[i==="file"?t.jsxs("div",{className:"plugins-drop",role:"group","aria-label":"A plugin file","data-state":v?"over":p?"refused":f?"chosen":void 0,onDragOver:C=>{C.preventDefault(),b(!0)},onDragLeave:()=>b(!1),onDrop:C=>{var E,T;C.preventDefault(),b(!1),S((T=(E=C.dataTransfer)==null?void 0:E.files)==null?void 0:T[0])},children:[t.jsx(le,{name:"drop",size:20}),t.jsx("span",{className:"plugins-drop-text",children:p??(f?`${f} — reading it.`:t.jsxs(t.Fragment,{children:["Drop a ",t.jsx("span",{className:"mono",children:wd})," here: the file ",t.jsx("span",{className:"mono",children:"npm pack"})," ","writes. It is read the moment it lands."]}))}),t.jsx(A,{variant:"accent",disabled:s||u,onClick:()=>{var C;return(C=y.current)==null?void 0:C.click()},children:"Choose a file"}),t.jsx("input",{ref:y,type:"file",accept:wd,hidden:!0,"aria-hidden":"true",tabIndex:-1,onChange:C=>{var E;S((E=C.target.files)==null?void 0:E[0]),C.target.value=""}})]}):t.jsxs("div",{className:"plugins-add-row",children:[t.jsxs(te,{valign:"end",children:[t.jsx(re,{grow:!0,label:i==="npm"?"Package":"The directory it is in",children:t.jsx("input",{type:"text",value:o,placeholder:i==="npm"?"buddi-plugin-weather":"/home/you/code/buddi-plugin-weather",onChange:C=>c(C.target.value)})}),i==="directory"?t.jsx(A,{onClick:()=>x(!0),children:"Browse…"}):null,t.jsx(A,{variant:"accent",disabled:s||u||o.trim()==="",onClick:N,children:"Read it first"})]}),t.jsx("span",{className:"ui-field-hint",children:i==="npm"?"A package name, or a name@version. Reading fetches it and hashes it; nothing of it runs.":"The folder with its package.json, already built. Nothing of it runs until you say yes."})]}),n?t.jsxs("p",{className:"plugins-status",role:"status","data-tone":n.phase==="failed"?"critical":void 0,children:[dX[n.phase]," ",n.error??""]}):null,t.jsx("div",{className:"plugins-trust",children:t.jsx(G,{tone:"warning",children:e})})]}),j?t.jsx(oX,{start:o.trim().startsWith("/")?o.trim():void 0,onClose:()=>x(!1),onPick:C=>{c(C),x(!1)}}):null]})}function jX({staged:e}){var r,a;const n=((r=e.uses)==null?void 0:r.areas)??[],s=((a=e.uses)==null?void 0:a.dropped)??[];return t.jsxs("span",{className:"plugins-uses",children:[n.length===0?Ow([]):n.map(i=>t.jsxs("span",{children:["It ",i.words,". ",i.added?t.jsxs(Ee,{tone:"warning",children:["new in ",e.version]}):null]},i.use)),s.length>0?t.jsxs("span",{className:"muted",children:["No longer: ",s.map(i=>i.words).join("; "),"."]}):null]})}function yP(e,n,s){const[r,a]=h.useState(e.plan??null),[i,l]=h.useState(!1),[o,c]=h.useState(null);return{plan:r,busy:i,failed:o,approve:f=>{l(!0),c(null),R.approveStaged(e.id,{integrity:e.integrity??"",...f?{acknowledgeDrift:!0}:{}}).then(m=>{m.installed?n(e.name):m.plan&&a(m.plan)}).catch(m=>c(Xa(m))).finally(()=>l(!1))},reject:()=>{l(!0),c(null),R.rejectStaged(e.id).then(()=>s()).catch(f=>c(Xa(f))).finally(()=>l(!1))}}}function wP(e){e.openedAt||R.openedStaged(e.id).catch(()=>{})}function yX({staged:e,onInstallFirst:n}){return t.jsxs("span",{className:"plugins-requires",children:[(e.requires??[]).map(s=>t.jsxs("span",{className:"plugins-require",children:[t.jsxs("span",{title:s.range,children:[t.jsx("span",{className:"mono",children:s.plugin})," ",s.rangeWords??s.range]}),s.state==="ok"?t.jsx("span",{className:"plugins-require-ok",children:s.installed?`${s.installed} is here`:"here"}):s.state==="missing"?t.jsxs(t.Fragment,{children:[t.jsx(Ee,{tone:"warning",children:"not installed"}),n?t.jsxs(A,{size:"sm",onClick:()=>n(s.plugin),children:["Install ",s.plugin," first"]}):null]}):t.jsx(Ee,{tone:"warning",children:s.state==="disabled"?"disabled here":s.state==="range"?`${s.installed??"another version"} is here`:s.state==="failed"?"did not load here":"waiting here"})]},s.plugin)),(e.requires??[]).some(s=>s.state!=="ok")?t.jsx("span",{className:"muted",children:"It installs either way, and waits — tools and widgets off, nothing lost — until each is here and set up."}):null]})}function bP({staged:e,inSheet:n,onInstallFirst:s}){var a;const r=e.dependencies;return t.jsxs("div",{className:"plugins-staged","data-in":n?"sheet":void 0,children:[t.jsx("div",{className:"plugins-facts",children:t.jsx(qt,{items:[...e.author?[{label:"By",value:t.jsx(mm,{author:e.author})}]:[],{label:"From",value:e.uploadedName?`a file you chose · ${e.uploadedName}`:Rv(e.source)},{label:"Published by",value:Dw(e.source,e.publisher)},...e.previousSource&&e.previous?[{label:"Replaces",value:`${e.previous.version}, installed from ${Rv(e.previousSource)}`}]:e.source.kind==="directory"&&((a=e.previous)==null?void 0:a.version)===e.version?[{label:"Reinstalls",value:`${e.version}, the same version, its files read again from the folder`}]:[],...e.source.kind==="directory"?[]:[{label:"Installs as",value:e.installsAs?t.jsx("span",{className:"mono",children:e.installsAs}):"the name its manifest gives, read when you approve — it declares no buddi.name"}],...e.coreAsDependency?[{label:"Core",value:"It asks npm for buddi's core; buddi provides its own."}]:[],{label:"Dependencies",value:r.count===0?"none":`${r.count}${r.withScripts.length===0?", none of which run install scripts":`, of which these run install scripts: ${r.withScripts.join(", ")}`}`},{label:"What it reaches",value:t.jsx(jX,{staged:e})},...(e.requires??[]).length>0?[{label:"Needs",value:t.jsx(yX,{staged:e,onInstallFirst:s})}]:[],{label:"Integrity",value:t.jsx(Iv,{value:e.integrity})},...e.stagedHash?[{label:"Files on disk",value:t.jsx(Iv,{value:e.stagedHash})}]:[]]})}),t.jsxs("div",{className:"plugins-claim",children:[t.jsx("div",{className:"plugins-claim-head",children:"What it says about itself"}),t.jsx("div",{className:"plugins-claim-note",children:"From its own buddi.md. Nothing has checked it yet."}),e.claims.missing?t.jsx("p",{className:"plugins-claim-text",children:"It ships no buddi.md, so it says nothing about itself at all."}):t.jsxs("p",{className:"plugins-claim-text",children:["“",e.claims.text,"”"]}),t.jsx("div",{className:"plugins-facts",children:t.jsx(qt,{items:[{label:"Schema it owns",value:e.claims.schema?t.jsx("span",{className:"mono",children:e.claims.schema}):"it claims none"},{label:"Hosts it reaches",value:e.claims.hosts.length===0?"it claims none":t.jsx("span",{className:"mono",children:e.claims.hosts.join(", ")})}]})})]})]})}function kP({plan:e,busy:n,onReject:s,onInstallAnyway:r}){return t.jsxs(Ts,{tone:"warning",title:"What it said, and what it does",meta:t.jsx(Ee,{tone:"warning",children:"read this first"}),foot:t.jsxs(te,{children:[t.jsx("span",{className:"plugins-foot-note",children:"Install anyway says you read these."}),t.jsx(et,{}),t.jsx(A,{variant:"ghost",disabled:n,onClick:s,children:"Not this one"}),t.jsx(A,{variant:"danger",disabled:n,onClick:r,children:"Install anyway"})]}),children:[t.jsx("p",{className:"plugins-note",children:"Its prose and its manifest do not agree. Neither is authoritative; the manifest is what actually runs."}),t.jsx("ul",{className:"plugins-drift",children:e.drift.map(a=>t.jsx("li",{children:a},a))}),t.jsx(NP,{unlocks:e.agents??[]})]})}function wX({staged:e,onInstalled:n,onGone:s,onInstallFirst:r}){const{plan:a,busy:i,failed:l,approve:o,reject:c}=yP(e,n,s);h.useEffect(()=>wP(e),[e.id]);const u=(a==null?void 0:a.drift)??[];return t.jsxs(ie,{gap:"sm",children:[t.jsxs(Ts,{tone:"accent",title:t.jsxs(t.Fragment,{children:[e.name," ",t.jsx("span",{className:"plugins-ver",children:e.version})]}),meta:t.jsx(Ee,{children:"read, not installed"}),foot:t.jsxs(te,{children:[t.jsx("span",{className:"plugins-foot-note",children:"Nothing of it has run."}),t.jsx(et,{}),t.jsx(A,{variant:"ghost",disabled:i,onClick:c,children:"Not this one"}),t.jsx(A,{variant:"accent",disabled:i||u.length>0,onClick:()=>o(!1),children:"Install"})]}),children:[t.jsx(ne,{message:l}),t.jsx(bP,{staged:e,onInstallFirst:r})]}),a&&u.length>0?t.jsx(kP,{plan:a,busy:i,onReject:c,onInstallAnyway:()=>o(!0)}):null]})}function bX({staged:e,onReview:n,onReject:s}){const r=Ve(e.createdAt);return t.jsx(Xe,{onClick:n,label:`${e.name}: review`,lead:t.jsx(Un,{svg:void 0}),title:t.jsxs(t.Fragment,{children:[e.name," ",t.jsx("span",{className:"plugins-ver",children:e.version})]}),sub:`from ${gP(e.source)}${r?` · read ${r}`:""}`,side:t.jsxs("span",{className:"plugins-side",children:[t.jsxs("span",{className:"plugins-wait-extra",children:[t.jsx(Ee,{children:"read, not installed"}),t.jsx(A,{size:"sm",variant:"ghost",onClick:to(s),children:"Not this one"})]}),t.jsx(A,{size:"sm",onClick:to(n),children:"Review"})]})})}function kX({staged:e,onClose:n,onInstalled:s,onGone:r,onInstallFirst:a}){const{plan:i,busy:l,failed:o,approve:c,reject:u}=yP(e,s,r),d=(i==null?void 0:i.drift)??[];return t.jsxs(Ge,{title:t.jsx(zw,{svg:void 0,name:e.name,version:e.version,by:e.author?t.jsx(mm,{author:e.author}):Dw(e.source,e.publisher),pills:t.jsxs(t.Fragment,{children:[" · ",t.jsx(Ee,{children:"read, not installed"})]})}),onClose:n,foot:t.jsxs(te,{children:[t.jsx("span",{className:"plugins-foot-note",children:"Nothing of it has run."}),t.jsx(et,{}),t.jsx(A,{variant:"ghost",disabled:l,onClick:u,children:"Not this one"}),t.jsx(A,{variant:"accent",disabled:l||d.length>0,onClick:()=>c(!1),children:"Install"})]}),children:[t.jsx(ne,{message:o}),t.jsx(bP,{staged:e,inSheet:!0,onInstallFirst:a}),i&&d.length>0?t.jsx(kP,{plan:i,busy:l,onReject:u,onInstallAnyway:()=>c(!0)}):null]})}const NX=10*60*1e3;function SX(e,n,s=Date.now()){if(n&&e.some(i=>i.id===n))return n;const r=[...e].sort((i,l)=>(l.createdAt??"").localeCompare(i.createdAt??""))[0];if(!(r!=null&&r.createdAt))return null;const a=s-Date.parse(r.createdAt);return Number.isFinite(a)&&a<NX?r.id:null}function CX({checkout:e,waiting:n}){const[s,r]=h.useState(!1),[a,i]=h.useState(null),l=aU(n),o=l?`${l} ${n.length===1?"is":"are"} installed.`:"A plugin was installed, disabled or enabled since buddi started, and this buddi has not caught up.";return t.jsxs(ie,{gap:"sm",children:[t.jsx(ne,{message:a}),t.jsxs(G,{tone:e?"warning":"accent",role:"status",action:e?void 0:t.jsx(A,{size:"sm",variant:"accent",disabled:s,onClick:()=>{r(!0),i(null),Gf({kind:"plugins",...l?{line:`Loading ${l}…`}:{line:"Applying your plugin changes…"}},()=>R.serviceAction("restart")).catch(c=>i(Xa(c))).finally(()=>r(!1))},children:"Restart to load it"}),children:[o," ",e?hX:`${l?n.length===1?"Its tools appear":"Their tools appear":"It takes effect"} once buddi restarts, which takes a few seconds. This page waits and comes back by itself.`]})]})}const Fw="buddi.plugins.justInstalled";function EX(e){try{window.sessionStorage.setItem(Fw,e)}catch{}}function AX(){try{return window.sessionStorage.getItem(Fw)}catch{return null}}function $X({list:e,firstStepFor:n}){var u;const[s,r]=h.useState(()=>AX()),a=s?e.find(d=>d.name===s):void 0,i=a!==void 0&&(a.loaded||a.needs!==void 0),l=i&&(a.needs!==void 0||a.setup!==void 0),o=()=>{try{window.sessionStorage.removeItem(Fw)}catch{}r(null)};if(h.useEffect(()=>{i&&!l&&o()},[i,l]),!a||!l)return null;const c=n(a);return t.jsx(G,{tone:"accent",role:"status",action:t.jsxs(t.Fragment,{children:[t.jsx(A,{size:"sm",variant:"ghost",onClick:o,children:"Later"}),c?t.jsx(A,{size:"sm",variant:"accent",onClick:()=>{o(),c.run()},children:c.label}):null]}),children:a.needs?`${a.name} is installed and waits. ${_w(a)}.`:`${a.name} is loaded. First: ${((u=a.setup)==null?void 0:u.note)??"set it up on its settings page."}`})}const to=e=>n=>{n.stopPropagation(),e()},TX=e=>e.unlocks.filter(n=>n.drift.state==="not-accepted").length;function _w(e){var n;return e.needs&&e.needs.length>0?e.needs.map(s=>s.state==="setup"&&s.note?`${s.words}: ${s.note}`:s.words).join(" · "):((n=e.setup)==null?void 0:n.note)??"Not set up yet. Its settings say what it needs."}function RX({plugin:e,listing:n,open:s,canOpen:r,busy:a,onDetails:i,onOpen:l,onSettings:o,onDisable:c,onEnable:u,onRemove:d,onUpdate:f,firstStep:m}){const p=e.enabled===!1,g=TX(e),v=!p&&(e.needs!==void 0||e.loaded&&e.setup!==void 0);return t.jsx(Xe,{onClick:i,label:`${e.name}: details`,dimmed:p,lead:t.jsx(Un,{svg:n==null?void 0:n.iconSvg}),title:t.jsxs(t.Fragment,{children:[e.name," ",t.jsx("span",{className:"plugins-ver",children:e.version}),g>0?t.jsxs("span",{className:"plugins-ask",children:[Ir(g,"agent","agents")," to accept"]}):null]}),sub:v?t.jsx("span",{className:"plugins-sub","data-tone":"warning",children:_w(e)}):`by ${xP(e)} · from ${gP(e.source)} · ${pP(e.contribution)}`,side:t.jsxs("span",{className:"plugins-side",children:[v&&m?t.jsx(A,{size:"sm",onClick:to(m.run),children:m.label}):null,n!=null&&n.update?t.jsxs(A,{size:"sm",disabled:a,onClick:to(()=>f(n.update)),children:["Update to ",n.update]}):null,v?null:s,!v&&!r&&o?t.jsx(A,{size:"sm",variant:"ghost",onClick:b=>{b.stopPropagation(),o()},children:"Settings"}):null,t.jsx(jP,{plugin:e}),t.jsx(Rs,{label:`More for ${e.name}`,items:[{label:"Details",onSelect:i},r?{label:"Open its page",onSelect:l}:null,o?{label:"Its settings",onSelect:o}:null,e.source.kind==="directory"&&!a?{label:"Reinstall from folder",hint:"reads its files again",onSelect:()=>f()}:null,p?{label:"Enable",hint:"all of it comes back",onSelect:u}:{label:"Disable…",hint:"keeps its data",onSelect:c},"separator",{label:"Remove…",tone:"critical",onSelect:d}]})]})})}const IX={"not-accepted":["warning","not accepted"],"up-to-date":["good","up to date"],"owner-edited":["accent","yours, edited"],"proposal-changed":["warning","proposal changed"],"owner-edited-and-proposal-changed":["warning","edited, and changed"],gone:[void 0,"gone"]};function NP({plugin:e,unlocks:n}){return n.length===0?null:t.jsxs(ue,{title:"Agents it would unlock",children:[t.jsx("div",{className:"plugins-unlocks",children:t.jsx(at,{children:n.map(s=>t.jsx(PX,{plugin:e,unlock:s},s.id))})}),t.jsxs("p",{className:"plugins-note",children:["Nothing here is created by installing. Accept creates the agent with the tools listed; change or remove it"," ",t.jsx("a",{href:vt,children:"on the Agents page"}),"."]})]})}function PX({plugin:e,unlock:n}){const s=nw(e,n.id),r=s.created?"up-to-date":n.drift.state,[a,i]=IX[r];return t.jsxs("div",{className:"plugins-unlock",children:[t.jsx(Xe,{title:t.jsxs("span",{className:"plugins-handle",children:["@",n.handle]}),sub:s.created?"Accepted just now. It is on the Agents page.":n.drift.message,side:t.jsxs("span",{className:"plugins-side",children:[t.jsx(Ee,{tone:a,children:i}),e&&r==="not-accepted"?t.jsx(A,{size:"sm",variant:"accent",disabled:s.busy,onClick:s.accept,children:"Accept"}):null]})}),t.jsx(ne,{message:s.failure}),s.created?t.jsx(DT,{agent:s.created}):null]})}function zw({svg:e,name:n,version:s,by:r,pills:a}){return t.jsxs("span",{className:"plugins-sheet-title",children:[t.jsx(Un,{svg:e,size:"lg"}),t.jsxs("span",{className:"plugins-sheet-name",children:[t.jsxs("span",{children:[n," ",t.jsx("span",{className:"plugins-ver",children:s})]}),t.jsxs("span",{className:"plugins-sheet-by",children:["by ",r,a]})]})]})}function MX({plugin:e,listing:n,notes:s,canOpen:r,busy:a,onOpen:i,onSettings:l,onClose:o,onDisable:c,onEnable:u,onRemove:d,onUpdate:f,firstStep:m}){var x,y;const p=e.enabled===!1,g=e.author!==void 0&&e.source.kind==="directory",v=(n==null?void 0:n.summary)??e.description,b=(e.network??((y=(x=n==null?void 0:n.claims)==null?void 0:x.manifest)==null?void 0:y.network)??[]).map(w=>w.host),j=e.uses??(n==null?void 0:n.usesWords);return t.jsxs(Ge,{title:t.jsx(zw,{svg:n==null?void 0:n.iconSvg,name:e.name,version:e.version,by:e.author?t.jsx(mm,{author:e.author}):xP(e),pills:t.jsxs(t.Fragment,{children:[n?t.jsxs(t.Fragment,{children:[" · ",t.jsx(Lw,{entry:n})]}):null," · ",t.jsx(jP,{plugin:e})]})}),onClose:o,foot:t.jsxs(te,{children:[t.jsx(A,{variant:"danger-ghost",onClick:d,children:"Remove…"}),t.jsx(et,{}),l?t.jsx(A,{variant:"ghost",onClick:l,children:"Settings"}):null,r?t.jsx(A,{onClick:i,children:"Open"}):null,p?t.jsx(A,{onClick:u,children:"Enable"}):t.jsx(A,{variant:"ghost",onClick:c,children:"Disable…"}),n!=null&&n.update?t.jsxs(A,{variant:"accent",disabled:a,onClick:()=>f(n.update),children:["Update to ",n.update]}):t.jsx(A,{disabled:a,onClick:()=>f(),children:e.source.kind==="directory"?"Reinstall from folder":"Check for an update"})]}),children:[e.error?t.jsx(G,{tone:"critical",children:e.error}):null,s&&s.length>0?t.jsx(G,{role:"status",children:s.join(" ")}):null,p?t.jsx(G,{children:"Disabled: its tools, pages and watchers are off and its missions are paused. Its data is kept."}):null,!p&&e.needs&&e.needs.length>0?t.jsxs(G,{tone:"warning",action:m?t.jsx(A,{size:"sm",variant:"accent",onClick:m.run,children:m.label}):void 0,children:["Waiting: ",_w(e),". Its tools and widgets stay off until then; its data is kept."]}):!p&&e.loaded&&e.setup?t.jsxs(G,{tone:"warning",action:m?t.jsx(A,{size:"sm",variant:"accent",onClick:m.run,children:m.label}):void 0,children:["Not set up yet. ",e.setup.note??"Its settings say what it needs."]}):null,v?t.jsx("p",{className:"plugins-summary-full",children:v}):null,t.jsx("div",{className:"plugins-facts",children:t.jsx(qt,{items:[{label:"From",value:Rv(e.source)},...g?[]:[{label:"Published by",value:Dw(e.source,e.publisher)}],{label:"Integrity",value:t.jsx(Iv,{value:e.integrity})},{label:"Installed",value:Ve(e.installedAt)},...e.installedAs?[{label:"Installed as",value:e.installedAs}]:[],{label:"Contributes",value:pP(e.contribution)},...e.network||n?[{label:"Talks to hosts",value:vP(b)}]:[],...j?[{label:"Reaches in buddi",value:Ow(j)}]:[]]})}),t.jsx(NP,{plugin:e.name,unlocks:e.unlocks})]})}function DX({kind:e,name:n,canDisable:s,onCancel:r,onDisableInstead:a,onDisable:i,onRemove:l}){const[o,c]=h.useState(!1),[u,d]=h.useState(""),[f,m]=h.useState(!1),[p,g]=h.useState(null),v=j=>{m(!0),g(null),j().catch(x=>g(Xa(x))).finally(()=>m(!1))};if(e==="disable")return t.jsxs(zt,{title:`Disable ${n}?`,onClose:r,foot:t.jsxs(t.Fragment,{children:[t.jsx(A,{variant:"ghost",disabled:f,onClick:r,children:"Cancel"}),t.jsx(A,{variant:"accent",disabled:f,onClick:()=>v(i),children:"Disable"})]}),children:[t.jsx("p",{className:"plugins-dialog-text",children:"Its tools, pages and watchers stop now and its missions pause. Its data and the agents you accepted from it are kept; enable it to have it all back."}),t.jsx(ne,{message:p})]});const b=!o||u.trim()===n;return t.jsxs(zt,{title:`Remove ${n}?`,onClose:r,foot:t.jsxs(t.Fragment,{children:[s?t.jsx(A,{variant:"ghost",size:"sm",disabled:f,onClick:a,children:"Disable instead"}):null,t.jsx(et,{}),t.jsx(A,{variant:"ghost",disabled:f,onClick:r,children:"Cancel"}),t.jsx(A,{variant:"danger",disabled:f||!b,onClick:()=>v(()=>l(o,u.trim())),children:o?"Remove and drop its data":"Remove"})]}),children:[t.jsxs("p",{className:"plugins-dialog-text",children:["This takes ",n," off this machine and stops its code loading. Its tables and the agents you accepted from it stay."]}),t.jsxs("div",{className:"plugins-purge","data-on":o?"true":void 0,children:[t.jsxs("label",{className:"plugins-check",children:[t.jsx("input",{type:"checkbox",checked:o,onChange:j=>{c(j.target.checked),d("")}}),t.jsxs("span",{children:[t.jsx("span",{className:"plugins-check-title",children:"Also drop its data"}),t.jsx("span",{className:"plugins-check-hint",children:"Its tables are gone for good; there is no undo."})]})]}),o?t.jsx(re,{label:t.jsxs(t.Fragment,{children:["Type ",t.jsx("span",{className:"mono",children:n})," to confirm"]}),children:t.jsx("input",{autoFocus:!0,value:u,onChange:j=>d(j.target.value)})}):null]}),t.jsx(ne,{message:p})]})}function OX({plugins:e,openFor:n}){return t.jsxs(Ot,{boxed:!0,summary:`Ships with buddi · ${Ir(e.length,"plugin","plugins")}`,children:[t.jsx("p",{className:"plugins-note",children:"Compiled into this buddi: nothing to approve, nothing to remove. An agent still reaches one only if its own tools line names it."}),t.jsx("div",{className:"plugins-builtins",children:e.map(s=>{const r=(s.network??[]).map(i=>i.host),a=[s.description,s.author?`By ${s.author.name}.`:null,r.length>0?`Talks to ${r.join(", ")}.`:null].filter(Boolean).join(" ");return t.jsxs("div",{className:"plugins-builtin",title:a||void 0,children:[t.jsx("span",{className:"mono",children:s.name}),t.jsxs("span",{className:"plugins-builtin-n",children:[n(s.name,"ghost"),Ir(s.contribution.tools,"tool","tools")]})]},s.name)})})]})}const LX=[{value:"days",label:"Your days"},{value:"money",label:"Money"},{value:"voice",label:"Voice"},{value:"work",label:"Work"},{value:"home",label:"Home"},{value:"other",label:"Other"}];function FX(e,n){const s=n.trim().toLowerCase();return s===""?!0:[e.title,e.summary,e.npm,...(e.widgets??[]).map(r=>r.title)].some(r=>r.toLowerCase().includes(s))}function _X({pricing:e}){return e.kind==="free"?t.jsx(t.Fragment,{children:"free"}):t.jsxs(t.Fragment,{children:[e.kind==="paid"?"paid":"a subscription",e.trialDays?` · ${e.trialDays} days to try`:"",e.note?` · ${e.note}`:"",e.vendor?t.jsxs(t.Fragment,{children:[" · ",t.jsx("a",{href:e.vendor,target:"_blank",rel:"noopener noreferrer",children:"its maker's page"})]}):null]})}function zX({entry:e,busy:n,onOpen:s,onInstall:r,onUpdate:a}){var i,l;return t.jsxs(Ts,{onClick:s,label:`${e.title}: details`,children:[t.jsxs("div",{className:"plugins-card-head",children:[t.jsx(Un,{svg:e.iconSvg,size:"lg"}),t.jsxs("div",{className:"plugins-card-name",children:[t.jsx("h3",{className:"ui-card-title",children:e.title}),t.jsxs("div",{className:"plugins-card-by",children:["by ",((i=e.author)==null?void 0:i.name)??"someone who gave no name",(l=e.widgets)!=null&&l.length?` · ${Ir(e.widgets.length,"widget","widgets")}`:""]})]})]}),t.jsx("p",{className:"plugins-summary",children:e.summary}),t.jsxs("div",{className:"plugins-card-foot",children:[t.jsx(Lw,{entry:e}),e.installed?t.jsxs(Ee,{children:["installed ",e.installed.version]}):null,t.jsx(et,{}),e.update?t.jsxs(A,{size:"sm",disabled:n,onClick:to(()=>a(e.update)),children:["Update to ",e.update]}):e.installed?null:t.jsx(A,{size:"sm",variant:"accent",disabled:n,onClick:to(r),children:"Install"})]})]})}function UX(e){var o,c;const n=(o=e.claims)==null?void 0:o.manifest,s=n==null?void 0:n.tools;if(!s)return;const r=s.filter(u=>u.tier==="auto").length,a=s.length-r,i=((c=n==null?void 0:n.sentinels)==null?void 0:c.length)??0,l=[r>0?`${r} run without asking`:null,a>0?`${a} ask${a===1?"s":""} you first`:null,i>0?`${i} on a timer`:null].filter(Boolean);return l.length===0?"none":l.join(", ")}function BX({entry:e,canOpen:n,busy:s,onOpen:r,onClose:a,onInstall:i,onUpdate:l}){var m,p,g,v,b,j,x,y;const o=(m=e.screenshots)==null?void 0:m[0],c=(((g=(p=e.claims)==null?void 0:p.manifest)==null?void 0:g.network)??[]).map(w=>w.host),u=UX(e),d=((j=(b=(v=e.claims)==null?void 0:v.manifest)==null?void 0:b.agents)==null?void 0:j.length)??0,f=(y=(x=e.claims)==null?void 0:x.package)==null?void 0:y.dependencies;return t.jsxs(Ge,{title:t.jsx(zw,{svg:e.iconSvg,name:e.title,version:e.version,by:e.author?t.jsx(mm,{author:e.author}):"someone who gave no name",pills:t.jsxs(t.Fragment,{children:[" · ",t.jsx(Lw,{entry:e}),e.installed?t.jsxs(t.Fragment,{children:[" · ",t.jsxs(Ee,{children:["installed ",e.installed.version]})]}):null]})}),onClose:a,foot:t.jsxs(te,{children:[t.jsx("span",{className:"plugins-foot-note",children:e.installed&&!e.update?"This is the version you have.":"Install reads it first. Nothing of it runs until you say yes."}),t.jsx(et,{}),n?t.jsx(A,{onClick:r,children:"Open"}):null,e.update?t.jsxs(A,{variant:"accent",disabled:s,onClick:()=>l(e.update),children:["Update to ",e.update]}):e.installed?null:t.jsx(A,{variant:"accent",disabled:s,onClick:i,children:"Install"})]}),children:[o?t.jsx("img",{className:"plugins-shot",src:R.marketAssetUrl(o),alt:`${e.title}, as it looks in buddi`}):null,t.jsx("p",{className:"plugins-summary-full",children:e.summary}),t.jsx(HX,{entry:e}),t.jsx("div",{className:"plugins-facts",children:t.jsx(qt,{items:[{label:"Package",value:t.jsx("span",{className:"mono",children:`${e.npm}@${e.version}`})},...u?[{label:"Tools",value:u}]:[],...d>0?[{label:"Proposes",value:`${Ir(d,"agent","agents")}, created only if you accept`}]:[],{label:"Talks to hosts",value:vP(c)},{label:"Reaches in buddi",value:Ow(e.usesWords??[])},...f?[{label:"Dependencies",value:f.count===0?"none":`${f.count}${f.withScripts.length===0?", none of which run install scripts":`, of which these run install scripts: ${f.withScripts.join(", ")}`}`}]:[],{label:"Licence",value:t.jsxs(t.Fragment,{children:[e.license??"not stated"," · ",t.jsx(_X,{pricing:e.pricing})]})}]})})]})}function WX(e){return[dP(e.sizes),e.settings>0?"settings per placement":null,e.sensitive?"hidden until you show it, never on the lock screen":null].filter(Boolean).join(" · ")}function HX({entry:e}){const n=e.widgets??[];return n.length===0?null:t.jsx(ue,{title:"Widgets",aside:t.jsx("span",{className:"plugins-note",children:"Sample data, drawn as Home draws it"}),children:t.jsx("div",{className:"plugins-widgets",children:n.map(s=>t.jsxs("div",{className:"plugins-widget",children:[t.jsxs("div",{className:"plugins-widget-head",children:[t.jsx("span",{className:"plugins-widget-title",children:s.title}),t.jsx("span",{className:"plugins-widget-sub",children:WX(s)})]}),t.jsx("div",{className:"plugins-widget-frames",children:iX(s.sizes).map(r=>t.jsx(hP,{widget:s,size:r,svg:e.iconSvg},r))})]},s.id))})})}function KX(e){var s,r,a,i,l;const n=(s=e.claims)==null?void 0:s.manifest;return(((r=e.widgets)==null?void 0:r.length)??0)>0&&(((a=n==null?void 0:n.tools)==null?void 0:a.length)??0)===0&&(((i=n==null?void 0:n.sentinels)==null?void 0:i.length)??0)===0&&(((l=n==null?void 0:n.agents)==null?void 0:l.length)??0)===0}function VX({entries:e,busy:n,onOpen:s,onInstall:r}){return t.jsx("div",{className:"plugins-wgrid","data-testid":"browse-widgets",children:e.flatMap(a=>(a.widgets??[]).map(i=>{var o;const l=i.sizes[0]??"small";return t.jsxs("div",{className:"plugins-witem","data-size":l,children:[t.jsx("button",{type:"button",className:"plugins-witem-frame","aria-label":`${i.title}, from ${a.title}: details`,onClick:()=>s(a),children:t.jsx(hP,{widget:i,size:l,svg:a.iconSvg})}),t.jsxs("div",{className:"plugins-witem-foot",children:[t.jsxs("span",{className:"plugins-witem-text",children:[t.jsx("span",{className:"plugins-witem-title",children:i.title}),t.jsxs("span",{className:"plugins-witem-sub",children:[KX(a)?"A widget":`${a.title} plugin`," · by ",((o=a.author)==null?void 0:o.name)??"someone who gave no name"," · ",dP(i.sizes)]})]}),a.installed?t.jsx("span",{className:"plugins-witem-have",children:"Installed"}):t.jsx(A,{size:"sm",variant:"accent",disabled:n,"aria-label":`Install ${a.title}`,onClick:()=>r(a),children:"Install"})]})]},`${a.npm}:${i.id}`)}))})}function GX({kind:e="all",onKind:n,navigate:s,market:r,loading:a,busy:i,onRetry:l,onOpen:o,onInstall:c,onUpdate:u}){const[d,f]=h.useState(""),[m,p]=h.useState("all"),g=(r==null?void 0:r.plugins)??[],v=[{value:"all",label:"All"},{value:"recommended",label:"Recommended"},...LX.filter(w=>g.some(k=>k.category===w.value))],b=g.filter(w=>{var k;return e==="widgets"&&(((k=w.widgets)==null?void 0:k.length)??0)===0||m==="recommended"&&(w.trust!=="by-buddi"||w.installed)||m!=="all"&&m!=="recommended"&&w.category!==m?!1:FX(w,d)}),j=d.trim(),x=t.jsx("div",{className:"plugins-kind",children:t.jsx(ln,{label:"Show",options:qX,value:e,onChange:w=>n==null?void 0:n(w)})}),y=e==="plugins"||e==="widgets"?null:t.jsx(YX,{kind:e,navigate:s});return e==="agents"?t.jsxs(ie,{gap:"lg",children:[x,t.jsxs("p",{className:"plugins-quiet",children:[t.jsx(le,{name:"globe",size:14}),"Opening this tab fetched the list from withbuddi.com. Nothing else leaves."]}),y]}):t.jsxs(ie,{gap:"lg",children:[x,t.jsxs(te,{children:[t.jsx(nm,{grow:!0,label:e==="widgets"?"Search widgets":"Search plugins",value:d,placeholder:e==="widgets"?"Search widgets: weather, calendar, news…":"Search plugins: weather, money, calendar…",onChange:f}),t.jsx(M$,{label:"Show",options:v,value:m,onChange:p})]}),t.jsxs("p",{className:"plugins-quiet",children:[t.jsx(le,{name:"globe",size:14}),"Opening this tab fetched the list from withbuddi.com. Nothing else leaves."," ",t.jsx("button",{type:"button",className:"plugins-link",disabled:a,onClick:l,children:"Refresh"})]}),r===null||a&&r.unavailable?t.jsx(ve,{children:"Asking withbuddi.com…"}):r.unavailable?t.jsx(G,{tone:"warning",action:t.jsx(A,{size:"sm",disabled:a,onClick:l,children:"Try again"}),children:r.unavailable}):t.jsxs(t.Fragment,{children:[r.stale?t.jsxs(G,{tone:"warning",action:t.jsx(A,{size:"sm",disabled:a,onClick:l,children:"Try again"}),children:["withbuddi.com did not answer, so this is the list as it was",r.fetchedAt?` ${Ve(r.fetchedAt)}`:" last time","."]}):null,b.length>0&&e==="widgets"?t.jsx(VX,{entries:b,busy:i,onOpen:o,onInstall:c}):b.length>0?t.jsx("div",{className:"plugins-grid",children:b.map(w=>t.jsx(zX,{entry:w,busy:i,onOpen:()=>o(w),onInstall:()=>c(w),onUpdate:k=>u(w,k)},w.npm))}):t.jsx(ve,{warm:!0,title:"Nothing listed matches",children:j!==""?`No ${e==="widgets"?"widget":"plugin"} on withbuddi.com mentions “${j}”.`:e==="widgets"&&!g.some(w=>{var k;return(((k=w.widgets)==null?void 0:k.length)??0)>0})?"No plugin on withbuddi.com brings a widget yet.":g.length===0?"withbuddi.com lists no plugins yet.":"Nothing on this shelf yet."})]}),y]})}const qX=[{value:"all",label:"All"},{value:"plugins",label:"Plugins"},{value:"widgets",label:"Widgets"},{value:"agents",label:"Agents"}];function YX({kind:e,navigate:n}){const s=me(()=>R.catalogue(),[]),r=jw(),a=c=>n==null?void 0:n(c),i=s.data;if(!i)return s.error?t.jsx(G,{tone:"warning",children:s.error}):t.jsx(ve,{children:"Asking withbuddi.com…"});if(i.unavailable)return e==="agents"?t.jsx(G,{tone:"warning",children:i.unavailable}):null;const l=i.agents.filter(c=>li(c)==="ready"),o=e==="all"?l.slice(0,3):i.agents;return o.length===0?null:t.jsx(ue,{title:e==="all"?"Teammates":void 0,aside:t.jsx("a",{href:sn(),onClick:c=>{c.preventDefault(),a(sn())},children:e==="all"?`See all ${i.agents.length}`:"Open the catalogue"}),children:t.jsx("div",{className:"plugins-grid","data-testid":"browse-agents",children:o.map(c=>t.jsx(GR,{entry:c,loaded:r,onOpen:()=>a(sn(c.name)),onAdd:()=>a(sn(c.name)),onUpdate:()=>a(sn(c.name))},c.name))})})}var Cu={},JX=function(){return typeof Promise=="function"&&Promise.prototype&&Promise.prototype.then},SP={},Ps={};let Uw;const QX=[0,26,44,70,100,134,172,196,242,292,346,404,466,532,581,655,733,815,901,991,1085,1156,1258,1364,1474,1588,1706,1828,1921,2051,2185,2323,2465,2611,2761,2876,3034,3196,3362,3532,3706];Ps.getSymbolSize=function(n){if(!n)throw new Error('"version" cannot be null or undefined');if(n<1||n>40)throw new Error('"version" should be in range from 1 to 40');return n*4+17};Ps.getSymbolTotalCodewords=function(n){return QX[n]};Ps.getBCHDigit=function(e){let n=0;for(;e!==0;)n++,e>>>=1;return n};Ps.setToSJISFunction=function(n){if(typeof n!="function")throw new Error('"toSJISFunc" is not a valid function.');Uw=n};Ps.isKanjiModeEnabled=function(){return typeof Uw<"u"};Ps.toSJIS=function(n){return Uw(n)};var pm={};(function(e){e.L={bit:1},e.M={bit:0},e.Q={bit:3},e.H={bit:2};function n(s){if(typeof s!="string")throw new Error("Param is not a string");switch(s.toLowerCase()){case"l":case"low":return e.L;case"m":case"medium":return e.M;case"q":case"quartile":return e.Q;case"h":case"high":return e.H;default:throw new Error("Unknown EC Level: "+s)}}e.isValid=function(r){return r&&typeof r.bit<"u"&&r.bit>=0&&r.bit<4},e.from=function(r,a){if(e.isValid(r))return r;try{return n(r)}catch{return a}}})(pm);function CP(){this.buffer=[],this.length=0}CP.prototype={get:function(e){const n=Math.floor(e/8);return(this.buffer[n]>>>7-e%8&1)===1},put:function(e,n){for(let s=0;s<n;s++)this.putBit((e>>>n-s-1&1)===1)},getLengthInBits:function(){return this.length},putBit:function(e){const n=Math.floor(this.length/8);this.buffer.length<=n&&this.buffer.push(0),e&&(this.buffer[n]|=128>>>this.length%8),this.length++}};var XX=CP;function Eu(e){if(!e||e<1)throw new Error("BitMatrix size must be defined and greater than 0");this.size=e,this.data=new Uint8Array(e*e),this.reservedBit=new Uint8Array(e*e)}Eu.prototype.set=function(e,n,s,r){const a=e*this.size+n;this.data[a]=s,r&&(this.reservedBit[a]=!0)};Eu.prototype.get=function(e,n){return this.data[e*this.size+n]};Eu.prototype.xor=function(e,n,s){this.data[e*this.size+n]^=s};Eu.prototype.isReserved=function(e,n){return this.reservedBit[e*this.size+n]};var ZX=Eu,EP={};(function(e){const n=Ps.getSymbolSize;e.getRowColCoords=function(r){if(r===1)return[];const a=Math.floor(r/7)+2,i=n(r),l=i===145?26:Math.ceil((i-13)/(2*a-2))*2,o=[i-7];for(let c=1;c<a-1;c++)o[c]=o[c-1]-l;return o.push(6),o.reverse()},e.getPositions=function(r){const a=[],i=e.getRowColCoords(r),l=i.length;for(let o=0;o<l;o++)for(let c=0;c<l;c++)o===0&&c===0||o===0&&c===l-1||o===l-1&&c===0||a.push([i[o],i[c]]);return a}})(EP);var AP={};const eZ=Ps.getSymbolSize,gS=7;AP.getPositions=function(n){const s=eZ(n);return[[0,0],[s-gS,0],[0,s-gS]]};var $P={};(function(e){e.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};const n={N1:3,N2:3,N3:40,N4:10};e.isValid=function(a){return a!=null&&a!==""&&!isNaN(a)&&a>=0&&a<=7},e.from=function(a){return e.isValid(a)?parseInt(a,10):void 0},e.getPenaltyN1=function(a){const i=a.size;let l=0,o=0,c=0,u=null,d=null;for(let f=0;f<i;f++){o=c=0,u=d=null;for(let m=0;m<i;m++){let p=a.get(f,m);p===u?o++:(o>=5&&(l+=n.N1+(o-5)),u=p,o=1),p=a.get(m,f),p===d?c++:(c>=5&&(l+=n.N1+(c-5)),d=p,c=1)}o>=5&&(l+=n.N1+(o-5)),c>=5&&(l+=n.N1+(c-5))}return l},e.getPenaltyN2=function(a){const i=a.size;let l=0;for(let o=0;o<i-1;o++)for(let c=0;c<i-1;c++){const u=a.get(o,c)+a.get(o,c+1)+a.get(o+1,c)+a.get(o+1,c+1);(u===4||u===0)&&l++}return l*n.N2},e.getPenaltyN3=function(a){const i=a.size;let l=0,o=0,c=0;for(let u=0;u<i;u++){o=c=0;for(let d=0;d<i;d++)o=o<<1&2047|a.get(u,d),d>=10&&(o===1488||o===93)&&l++,c=c<<1&2047|a.get(d,u),d>=10&&(c===1488||c===93)&&l++}return l*n.N3},e.getPenaltyN4=function(a){let i=0;const l=a.data.length;for(let c=0;c<l;c++)i+=a.data[c];return Math.abs(Math.ceil(i*100/l/5)-10)*n.N4};function s(r,a,i){switch(r){case e.Patterns.PATTERN000:return(a+i)%2===0;case e.Patterns.PATTERN001:return a%2===0;case e.Patterns.PATTERN010:return i%3===0;case e.Patterns.PATTERN011:return(a+i)%3===0;case e.Patterns.PATTERN100:return(Math.floor(a/2)+Math.floor(i/3))%2===0;case e.Patterns.PATTERN101:return a*i%2+a*i%3===0;case e.Patterns.PATTERN110:return(a*i%2+a*i%3)%2===0;case e.Patterns.PATTERN111:return(a*i%3+(a+i)%2)%2===0;default:throw new Error("bad maskPattern:"+r)}}e.applyMask=function(a,i){const l=i.size;for(let o=0;o<l;o++)for(let c=0;c<l;c++)i.isReserved(c,o)||i.xor(c,o,s(a,c,o))},e.getBestMask=function(a,i){const l=Object.keys(e.Patterns).length;let o=0,c=1/0;for(let u=0;u<l;u++){i(u),e.applyMask(u,a);const d=e.getPenaltyN1(a)+e.getPenaltyN2(a)+e.getPenaltyN3(a)+e.getPenaltyN4(a);e.applyMask(u,a),d<c&&(c=d,o=u)}return o}})($P);var gm={};const Ra=pm,bd=[1,1,1,1,1,1,1,1,1,1,2,2,1,2,2,4,1,2,4,4,2,4,4,4,2,4,6,5,2,4,6,6,2,5,8,8,4,5,8,8,4,5,8,11,4,8,10,11,4,9,12,16,4,9,16,16,6,10,12,18,6,10,17,16,6,11,16,19,6,13,18,21,7,14,21,25,8,16,20,25,8,17,23,25,9,17,23,34,9,18,25,30,10,20,27,32,12,21,29,35,12,23,34,37,12,25,34,40,13,26,35,42,14,28,38,45,15,29,40,48,16,31,43,51,17,33,45,54,18,35,48,57,19,37,51,60,19,38,53,63,20,40,56,66,21,43,59,70,22,45,62,74,24,47,65,77,25,49,68,81],kd=[7,10,13,17,10,16,22,28,15,26,36,44,20,36,52,64,26,48,72,88,36,64,96,112,40,72,108,130,48,88,132,156,60,110,160,192,72,130,192,224,80,150,224,264,96,176,260,308,104,198,288,352,120,216,320,384,132,240,360,432,144,280,408,480,168,308,448,532,180,338,504,588,196,364,546,650,224,416,600,700,224,442,644,750,252,476,690,816,270,504,750,900,300,560,810,960,312,588,870,1050,336,644,952,1110,360,700,1020,1200,390,728,1050,1260,420,784,1140,1350,450,812,1200,1440,480,868,1290,1530,510,924,1350,1620,540,980,1440,1710,570,1036,1530,1800,570,1064,1590,1890,600,1120,1680,1980,630,1204,1770,2100,660,1260,1860,2220,720,1316,1950,2310,750,1372,2040,2430];gm.getBlocksCount=function(n,s){switch(s){case Ra.L:return bd[(n-1)*4+0];case Ra.M:return bd[(n-1)*4+1];case Ra.Q:return bd[(n-1)*4+2];case Ra.H:return bd[(n-1)*4+3];default:return}};gm.getTotalCodewordsCount=function(n,s){switch(s){case Ra.L:return kd[(n-1)*4+0];case Ra.M:return kd[(n-1)*4+1];case Ra.Q:return kd[(n-1)*4+2];case Ra.H:return kd[(n-1)*4+3];default:return}};var TP={},xm={};const jc=new Uint8Array(512),nf=new Uint8Array(256);(function(){let n=1;for(let s=0;s<255;s++)jc[s]=n,nf[n]=s,n<<=1,n&256&&(n^=285);for(let s=255;s<512;s++)jc[s]=jc[s-255]})();xm.log=function(n){if(n<1)throw new Error("log("+n+")");return nf[n]};xm.exp=function(n){return jc[n]};xm.mul=function(n,s){return n===0||s===0?0:jc[nf[n]+nf[s]]};(function(e){const n=xm;e.mul=function(r,a){const i=new Uint8Array(r.length+a.length-1);for(let l=0;l<r.length;l++)for(let o=0;o<a.length;o++)i[l+o]^=n.mul(r[l],a[o]);return i},e.mod=function(r,a){let i=new Uint8Array(r);for(;i.length-a.length>=0;){const l=i[0];for(let c=0;c<a.length;c++)i[c]^=n.mul(a[c],l);let o=0;for(;o<i.length&&i[o]===0;)o++;i=i.slice(o)}return i},e.generateECPolynomial=function(r){let a=new Uint8Array([1]);for(let i=0;i<r;i++)a=e.mul(a,new Uint8Array([1,n.exp(i)]));return a}})(TP);const RP=TP;function Bw(e){this.genPoly=void 0,this.degree=e,this.degree&&this.initialize(this.degree)}Bw.prototype.initialize=function(n){this.degree=n,this.genPoly=RP.generateECPolynomial(this.degree)};Bw.prototype.encode=function(n){if(!this.genPoly)throw new Error("Encoder not initialized");const s=new Uint8Array(n.length+this.degree);s.set(n);const r=RP.mod(s,this.genPoly),a=this.degree-r.length;if(a>0){const i=new Uint8Array(this.degree);return i.set(r,a),i}return r};var tZ=Bw,IP={},oi={},Ww={};Ww.isValid=function(n){return!isNaN(n)&&n>=1&&n<=40};var Vr={};const PP="[0-9]+",nZ="[A-Z $%*+\\-./:]+";let iu="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";iu=iu.replace(/u/g,"\\u");const sZ="(?:(?![A-Z0-9 $%*+\\-./:]|"+iu+`)(?:.|[\r
138
- ]))+`;Vr.KANJI=new RegExp(iu,"g");Vr.BYTE_KANJI=new RegExp("[^A-Z0-9 $%*+\\-./:]+","g");Vr.BYTE=new RegExp(sZ,"g");Vr.NUMERIC=new RegExp(PP,"g");Vr.ALPHANUMERIC=new RegExp(nZ,"g");const rZ=new RegExp("^"+iu+"$"),aZ=new RegExp("^"+PP+"$"),iZ=new RegExp("^[A-Z0-9 $%*+\\-./:]+$");Vr.testKanji=function(n){return rZ.test(n)};Vr.testNumeric=function(n){return aZ.test(n)};Vr.testAlphanumeric=function(n){return iZ.test(n)};(function(e){const n=Ww,s=Vr;e.NUMERIC={id:"Numeric",bit:1,ccBits:[10,12,14]},e.ALPHANUMERIC={id:"Alphanumeric",bit:2,ccBits:[9,11,13]},e.BYTE={id:"Byte",bit:4,ccBits:[8,16,16]},e.KANJI={id:"Kanji",bit:8,ccBits:[8,10,12]},e.MIXED={bit:-1},e.getCharCountIndicator=function(i,l){if(!i.ccBits)throw new Error("Invalid mode: "+i);if(!n.isValid(l))throw new Error("Invalid version: "+l);return l>=1&&l<10?i.ccBits[0]:l<27?i.ccBits[1]:i.ccBits[2]},e.getBestModeForData=function(i){return s.testNumeric(i)?e.NUMERIC:s.testAlphanumeric(i)?e.ALPHANUMERIC:s.testKanji(i)?e.KANJI:e.BYTE},e.toString=function(i){if(i&&i.id)return i.id;throw new Error("Invalid mode")},e.isValid=function(i){return i&&i.bit&&i.ccBits};function r(a){if(typeof a!="string")throw new Error("Param is not a string");switch(a.toLowerCase()){case"numeric":return e.NUMERIC;case"alphanumeric":return e.ALPHANUMERIC;case"kanji":return e.KANJI;case"byte":return e.BYTE;default:throw new Error("Unknown mode: "+a)}}e.from=function(i,l){if(e.isValid(i))return i;try{return r(i)}catch{return l}}})(oi);(function(e){const n=Ps,s=gm,r=pm,a=oi,i=Ww,l=7973,o=n.getBCHDigit(l);function c(m,p,g){for(let v=1;v<=40;v++)if(p<=e.getCapacity(v,g,m))return v}function u(m,p){return a.getCharCountIndicator(m,p)+4}function d(m,p){let g=0;return m.forEach(function(v){const b=u(v.mode,p);g+=b+v.getBitsLength()}),g}function f(m,p){for(let g=1;g<=40;g++)if(d(m,g)<=e.getCapacity(g,p,a.MIXED))return g}e.from=function(p,g){return i.isValid(p)?parseInt(p,10):g},e.getCapacity=function(p,g,v){if(!i.isValid(p))throw new Error("Invalid QR Code version");typeof v>"u"&&(v=a.BYTE);const b=n.getSymbolTotalCodewords(p),j=s.getTotalCodewordsCount(p,g),x=(b-j)*8;if(v===a.MIXED)return x;const y=x-u(v,p);switch(v){case a.NUMERIC:return Math.floor(y/10*3);case a.ALPHANUMERIC:return Math.floor(y/11*2);case a.KANJI:return Math.floor(y/13);case a.BYTE:default:return Math.floor(y/8)}},e.getBestVersionForData=function(p,g){let v;const b=r.from(g,r.M);if(Array.isArray(p)){if(p.length>1)return f(p,b);if(p.length===0)return 1;v=p[0]}else v=p;return c(v.mode,v.getLength(),b)},e.getEncodedBits=function(p){if(!i.isValid(p)||p<7)throw new Error("Invalid QR Code version");let g=p<<12;for(;n.getBCHDigit(g)-o>=0;)g^=l<<n.getBCHDigit(g)-o;return p<<12|g}})(IP);var MP={};const Mv=Ps,DP=1335,lZ=21522,xS=Mv.getBCHDigit(DP);MP.getEncodedBits=function(n,s){const r=n.bit<<3|s;let a=r<<10;for(;Mv.getBCHDigit(a)-xS>=0;)a^=DP<<Mv.getBCHDigit(a)-xS;return(r<<10|a)^lZ};var OP={};const oZ=oi;function no(e){this.mode=oZ.NUMERIC,this.data=e.toString()}no.getBitsLength=function(n){return 10*Math.floor(n/3)+(n%3?n%3*3+1:0)};no.prototype.getLength=function(){return this.data.length};no.prototype.getBitsLength=function(){return no.getBitsLength(this.data.length)};no.prototype.write=function(n){let s,r,a;for(s=0;s+3<=this.data.length;s+=3)r=this.data.substr(s,3),a=parseInt(r,10),n.put(a,10);const i=this.data.length-s;i>0&&(r=this.data.substr(s),a=parseInt(r,10),n.put(a,i*3+1))};var cZ=no;const uZ=oi,Qp=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"," ","$","%","*","+","-",".","/",":"];function so(e){this.mode=uZ.ALPHANUMERIC,this.data=e}so.getBitsLength=function(n){return 11*Math.floor(n/2)+6*(n%2)};so.prototype.getLength=function(){return this.data.length};so.prototype.getBitsLength=function(){return so.getBitsLength(this.data.length)};so.prototype.write=function(n){let s;for(s=0;s+2<=this.data.length;s+=2){let r=Qp.indexOf(this.data[s])*45;r+=Qp.indexOf(this.data[s+1]),n.put(r,11)}this.data.length%2&&n.put(Qp.indexOf(this.data[s]),6)};var dZ=so;const hZ=oi;function ro(e){this.mode=hZ.BYTE,typeof e=="string"?this.data=new TextEncoder().encode(e):this.data=new Uint8Array(e)}ro.getBitsLength=function(n){return n*8};ro.prototype.getLength=function(){return this.data.length};ro.prototype.getBitsLength=function(){return ro.getBitsLength(this.data.length)};ro.prototype.write=function(e){for(let n=0,s=this.data.length;n<s;n++)e.put(this.data[n],8)};var fZ=ro;const mZ=oi,pZ=Ps;function ao(e){this.mode=mZ.KANJI,this.data=e}ao.getBitsLength=function(n){return n*13};ao.prototype.getLength=function(){return this.data.length};ao.prototype.getBitsLength=function(){return ao.getBitsLength(this.data.length)};ao.prototype.write=function(e){let n;for(n=0;n<this.data.length;n++){let s=pZ.toSJIS(this.data[n]);if(s>=33088&&s<=40956)s-=33088;else if(s>=57408&&s<=60351)s-=49472;else throw new Error("Invalid SJIS character: "+this.data[n]+`
139
- Make sure your charset is UTF-8`);s=(s>>>8&255)*192+(s&255),e.put(s,13)}};var gZ=ao,LP={exports:{}};(function(e){var n={single_source_shortest_paths:function(s,r,a){var i={},l={};l[r]=0;var o=n.PriorityQueue.make();o.push(r,0);for(var c,u,d,f,m,p,g,v,b;!o.empty();){c=o.pop(),u=c.value,f=c.cost,m=s[u]||{};for(d in m)m.hasOwnProperty(d)&&(p=m[d],g=f+p,v=l[d],b=typeof l[d]>"u",(b||v>g)&&(l[d]=g,o.push(d,g),i[d]=u))}if(typeof a<"u"&&typeof l[a]>"u"){var j=["Could not find a path from ",r," to ",a,"."].join("");throw new Error(j)}return i},extract_shortest_path_from_predecessor_list:function(s,r){for(var a=[],i=r;i;)a.push(i),s[i],i=s[i];return a.reverse(),a},find_path:function(s,r,a){var i=n.single_source_shortest_paths(s,r,a);return n.extract_shortest_path_from_predecessor_list(i,a)},PriorityQueue:{make:function(s){var r=n.PriorityQueue,a={},i;s=s||{};for(i in r)r.hasOwnProperty(i)&&(a[i]=r[i]);return a.queue=[],a.sorter=s.sorter||r.default_sorter,a},default_sorter:function(s,r){return s.cost-r.cost},push:function(s,r){var a={value:s,cost:r};this.queue.push(a),this.queue.sort(this.sorter)},pop:function(){return this.queue.shift()},empty:function(){return this.queue.length===0}}};e.exports=n})(LP);var xZ=LP.exports;(function(e){const n=oi,s=cZ,r=dZ,a=fZ,i=gZ,l=Vr,o=Ps,c=xZ;function u(j){return unescape(encodeURIComponent(j)).length}function d(j,x,y){const w=[];let k;for(;(k=j.exec(y))!==null;)w.push({data:k[0],index:k.index,mode:x,length:k[0].length});return w}function f(j){const x=d(l.NUMERIC,n.NUMERIC,j),y=d(l.ALPHANUMERIC,n.ALPHANUMERIC,j);let w,k;return o.isKanjiModeEnabled()?(w=d(l.BYTE,n.BYTE,j),k=d(l.KANJI,n.KANJI,j)):(w=d(l.BYTE_KANJI,n.BYTE,j),k=[]),x.concat(y,w,k).sort(function(S,C){return S.index-C.index}).map(function(S){return{data:S.data,mode:S.mode,length:S.length}})}function m(j,x){switch(x){case n.NUMERIC:return s.getBitsLength(j);case n.ALPHANUMERIC:return r.getBitsLength(j);case n.KANJI:return i.getBitsLength(j);case n.BYTE:return a.getBitsLength(j)}}function p(j){return j.reduce(function(x,y){const w=x.length-1>=0?x[x.length-1]:null;return w&&w.mode===y.mode?(x[x.length-1].data+=y.data,x):(x.push(y),x)},[])}function g(j){const x=[];for(let y=0;y<j.length;y++){const w=j[y];switch(w.mode){case n.NUMERIC:x.push([w,{data:w.data,mode:n.ALPHANUMERIC,length:w.length},{data:w.data,mode:n.BYTE,length:w.length}]);break;case n.ALPHANUMERIC:x.push([w,{data:w.data,mode:n.BYTE,length:w.length}]);break;case n.KANJI:x.push([w,{data:w.data,mode:n.BYTE,length:u(w.data)}]);break;case n.BYTE:x.push([{data:w.data,mode:n.BYTE,length:u(w.data)}])}}return x}function v(j,x){const y={},w={start:{}};let k=["start"];for(let N=0;N<j.length;N++){const S=j[N],C=[];for(let E=0;E<S.length;E++){const T=S[E],I=""+N+E;C.push(I),y[I]={node:T,lastCount:0},w[I]={};for(let F=0;F<k.length;F++){const D=k[F];y[D]&&y[D].node.mode===T.mode?(w[D][I]=m(y[D].lastCount+T.length,T.mode)-m(y[D].lastCount,T.mode),y[D].lastCount+=T.length):(y[D]&&(y[D].lastCount=T.length),w[D][I]=m(T.length,T.mode)+4+n.getCharCountIndicator(T.mode,x))}}k=C}for(let N=0;N<k.length;N++)w[k[N]].end=0;return{map:w,table:y}}function b(j,x){let y;const w=n.getBestModeForData(j);if(y=n.from(x,w),y!==n.BYTE&&y.bit<w.bit)throw new Error('"'+j+'" cannot be encoded with mode '+n.toString(y)+`.
140
- Suggested mode is: `+n.toString(w));switch(y===n.KANJI&&!o.isKanjiModeEnabled()&&(y=n.BYTE),y){case n.NUMERIC:return new s(j);case n.ALPHANUMERIC:return new r(j);case n.KANJI:return new i(j);case n.BYTE:return new a(j)}}e.fromArray=function(x){return x.reduce(function(y,w){return typeof w=="string"?y.push(b(w,null)):w.data&&y.push(b(w.data,w.mode)),y},[])},e.fromString=function(x,y){const w=f(x,o.isKanjiModeEnabled()),k=g(w),N=v(k,y),S=c.find_path(N.map,"start","end"),C=[];for(let E=1;E<S.length-1;E++)C.push(N.table[S[E]].node);return e.fromArray(p(C))},e.rawSplit=function(x){return e.fromArray(f(x,o.isKanjiModeEnabled()))}})(OP);const vm=Ps,Xp=pm,vZ=XX,jZ=ZX,yZ=EP,wZ=AP,Dv=$P,Ov=gm,bZ=tZ,sf=IP,kZ=MP,NZ=oi,Zp=OP;function SZ(e,n){const s=e.size,r=wZ.getPositions(n);for(let a=0;a<r.length;a++){const i=r[a][0],l=r[a][1];for(let o=-1;o<=7;o++)if(!(i+o<=-1||s<=i+o))for(let c=-1;c<=7;c++)l+c<=-1||s<=l+c||(o>=0&&o<=6&&(c===0||c===6)||c>=0&&c<=6&&(o===0||o===6)||o>=2&&o<=4&&c>=2&&c<=4?e.set(i+o,l+c,!0,!0):e.set(i+o,l+c,!1,!0))}}function CZ(e){const n=e.size;for(let s=8;s<n-8;s++){const r=s%2===0;e.set(s,6,r,!0),e.set(6,s,r,!0)}}function EZ(e,n){const s=yZ.getPositions(n);for(let r=0;r<s.length;r++){const a=s[r][0],i=s[r][1];for(let l=-2;l<=2;l++)for(let o=-2;o<=2;o++)l===-2||l===2||o===-2||o===2||l===0&&o===0?e.set(a+l,i+o,!0,!0):e.set(a+l,i+o,!1,!0)}}function AZ(e,n){const s=e.size,r=sf.getEncodedBits(n);let a,i,l;for(let o=0;o<18;o++)a=Math.floor(o/3),i=o%3+s-8-3,l=(r>>o&1)===1,e.set(a,i,l,!0),e.set(i,a,l,!0)}function eg(e,n,s){const r=e.size,a=kZ.getEncodedBits(n,s);let i,l;for(i=0;i<15;i++)l=(a>>i&1)===1,i<6?e.set(i,8,l,!0):i<8?e.set(i+1,8,l,!0):e.set(r-15+i,8,l,!0),i<8?e.set(8,r-i-1,l,!0):i<9?e.set(8,15-i-1+1,l,!0):e.set(8,15-i-1,l,!0);e.set(r-8,8,1,!0)}function $Z(e,n){const s=e.size;let r=-1,a=s-1,i=7,l=0;for(let o=s-1;o>0;o-=2)for(o===6&&o--;;){for(let c=0;c<2;c++)if(!e.isReserved(a,o-c)){let u=!1;l<n.length&&(u=(n[l]>>>i&1)===1),e.set(a,o-c,u),i--,i===-1&&(l++,i=7)}if(a+=r,a<0||s<=a){a-=r,r=-r;break}}}function TZ(e,n,s){const r=new vZ;s.forEach(function(c){r.put(c.mode.bit,4),r.put(c.getLength(),NZ.getCharCountIndicator(c.mode,e)),c.write(r)});const a=vm.getSymbolTotalCodewords(e),i=Ov.getTotalCodewordsCount(e,n),l=(a-i)*8;for(r.getLengthInBits()+4<=l&&r.put(0,4);r.getLengthInBits()%8!==0;)r.putBit(0);const o=(l-r.getLengthInBits())/8;for(let c=0;c<o;c++)r.put(c%2?17:236,8);return RZ(r,e,n)}function RZ(e,n,s){const r=vm.getSymbolTotalCodewords(n),a=Ov.getTotalCodewordsCount(n,s),i=r-a,l=Ov.getBlocksCount(n,s),o=r%l,c=l-o,u=Math.floor(r/l),d=Math.floor(i/l),f=d+1,m=u-d,p=new bZ(m);let g=0;const v=new Array(l),b=new Array(l);let j=0;const x=new Uint8Array(e.buffer);for(let S=0;S<l;S++){const C=S<c?d:f;v[S]=x.slice(g,g+C),b[S]=p.encode(v[S]),g+=C,j=Math.max(j,C)}const y=new Uint8Array(r);let w=0,k,N;for(k=0;k<j;k++)for(N=0;N<l;N++)k<v[N].length&&(y[w++]=v[N][k]);for(k=0;k<m;k++)for(N=0;N<l;N++)y[w++]=b[N][k];return y}function IZ(e,n,s,r){let a;if(Array.isArray(e))a=Zp.fromArray(e);else if(typeof e=="string"){let u=n;if(!u){const d=Zp.rawSplit(e);u=sf.getBestVersionForData(d,s)}a=Zp.fromString(e,u||40)}else throw new Error("Invalid data");const i=sf.getBestVersionForData(a,s);if(!i)throw new Error("The amount of data is too big to be stored in a QR Code");if(!n)n=i;else if(n<i)throw new Error(`
141
- The chosen QR Code version cannot contain this amount of data.
142
- Minimum version required to store current data is: `+i+`.
143
- `);const l=TZ(n,s,a),o=vm.getSymbolSize(n),c=new jZ(o);return SZ(c,n),CZ(c),EZ(c,n),eg(c,s,0),n>=7&&AZ(c,n),$Z(c,l),isNaN(r)&&(r=Dv.getBestMask(c,eg.bind(null,c,s))),Dv.applyMask(r,c),eg(c,s,r),{modules:c,version:n,errorCorrectionLevel:s,maskPattern:r,segments:a}}SP.create=function(n,s){if(typeof n>"u"||n==="")throw new Error("No input text");let r=Xp.M,a,i;return typeof s<"u"&&(r=Xp.from(s.errorCorrectionLevel,Xp.M),a=sf.from(s.version),i=Dv.from(s.maskPattern),s.toSJISFunc&&vm.setToSJISFunction(s.toSJISFunc)),IZ(n,a,r,i)};var FP={},Hw={};(function(e){function n(s){if(typeof s=="number"&&(s=s.toString()),typeof s!="string")throw new Error("Color should be defined as hex string");let r=s.slice().replace("#","").split("");if(r.length<3||r.length===5||r.length>8)throw new Error("Invalid hex color: "+s);(r.length===3||r.length===4)&&(r=Array.prototype.concat.apply([],r.map(function(i){return[i,i]}))),r.length===6&&r.push("F","F");const a=parseInt(r.join(""),16);return{r:a>>24&255,g:a>>16&255,b:a>>8&255,a:a&255,hex:"#"+r.slice(0,6).join("")}}e.getOptions=function(r){r||(r={}),r.color||(r.color={});const a=typeof r.margin>"u"||r.margin===null||r.margin<0?4:r.margin,i=r.width&&r.width>=21?r.width:void 0,l=r.scale||4;return{width:i,scale:i?4:l,margin:a,color:{dark:n(r.color.dark||"#000000ff"),light:n(r.color.light||"#ffffffff")},type:r.type,rendererOpts:r.rendererOpts||{}}},e.getScale=function(r,a){return a.width&&a.width>=r+a.margin*2?a.width/(r+a.margin*2):a.scale},e.getImageWidth=function(r,a){const i=e.getScale(r,a);return Math.floor((r+a.margin*2)*i)},e.qrToImageData=function(r,a,i){const l=a.modules.size,o=a.modules.data,c=e.getScale(l,i),u=Math.floor((l+i.margin*2)*c),d=i.margin*c,f=[i.color.light,i.color.dark];for(let m=0;m<u;m++)for(let p=0;p<u;p++){let g=(m*u+p)*4,v=i.color.light;if(m>=d&&p>=d&&m<u-d&&p<u-d){const b=Math.floor((m-d)/c),j=Math.floor((p-d)/c);v=f[o[b*l+j]?1:0]}r[g++]=v.r,r[g++]=v.g,r[g++]=v.b,r[g]=v.a}}})(Hw);(function(e){const n=Hw;function s(a,i,l){a.clearRect(0,0,i.width,i.height),i.style||(i.style={}),i.height=l,i.width=l,i.style.height=l+"px",i.style.width=l+"px"}function r(){try{return document.createElement("canvas")}catch{throw new Error("You need to specify a canvas element")}}e.render=function(i,l,o){let c=o,u=l;typeof c>"u"&&(!l||!l.getContext)&&(c=l,l=void 0),l||(u=r()),c=n.getOptions(c);const d=n.getImageWidth(i.modules.size,c),f=u.getContext("2d"),m=f.createImageData(d,d);return n.qrToImageData(m.data,i,c),s(f,u,d),f.putImageData(m,0,0),u},e.renderToDataURL=function(i,l,o){let c=o;typeof c>"u"&&(!l||!l.getContext)&&(c=l,l=void 0),c||(c={});const u=e.render(i,l,c),d=c.type||"image/png",f=c.rendererOpts||{};return u.toDataURL(d,f.quality)}})(FP);var _P={};const PZ=Hw;function vS(e,n){const s=e.a/255,r=n+'="'+e.hex+'"';return s<1?r+" "+n+'-opacity="'+s.toFixed(2).slice(1)+'"':r}function tg(e,n,s){let r=e+n;return typeof s<"u"&&(r+=" "+s),r}function MZ(e,n,s){let r="",a=0,i=!1,l=0;for(let o=0;o<e.length;o++){const c=Math.floor(o%n),u=Math.floor(o/n);!c&&!i&&(i=!0),e[o]?(l++,o>0&&c>0&&e[o-1]||(r+=i?tg("M",c+s,.5+u+s):tg("m",a,0),a=0,i=!1),c+1<n&&e[o+1]||(r+=tg("h",l),l=0)):a++}return r}_P.render=function(n,s,r){const a=PZ.getOptions(s),i=n.modules.size,l=n.modules.data,o=i+a.margin*2,c=a.color.light.a?"<path "+vS(a.color.light,"fill")+' d="M0 0h'+o+"v"+o+'H0z"/>':"",u="<path "+vS(a.color.dark,"stroke")+' d="'+MZ(l,i,a.margin)+'"/>',d='viewBox="0 0 '+o+" "+o+'"',m='<svg xmlns="http://www.w3.org/2000/svg" '+(a.width?'width="'+a.width+'" height="'+a.width+'" ':"")+d+' shape-rendering="crispEdges">'+c+u+`</svg>
144
- `;return typeof r=="function"&&r(null,m),m};const DZ=JX,Lv=SP,zP=FP,OZ=_P;function Kw(e,n,s,r,a){const i=[].slice.call(arguments,1),l=i.length,o=typeof i[l-1]=="function";if(!o&&!DZ())throw new Error("Callback required as last argument");if(o){if(l<2)throw new Error("Too few arguments provided");l===2?(a=s,s=n,n=r=void 0):l===3&&(n.getContext&&typeof a>"u"?(a=r,r=void 0):(a=r,r=s,s=n,n=void 0))}else{if(l<1)throw new Error("Too few arguments provided");return l===1?(s=n,n=r=void 0):l===2&&!n.getContext&&(r=s,s=n,n=void 0),new Promise(function(c,u){try{const d=Lv.create(s,r);c(e(d,n,r))}catch(d){u(d)}})}try{const c=Lv.create(s,r);a(null,e(c,n,r))}catch(c){a(c)}}Cu.create=Lv.create;Cu.toCanvas=Kw.bind(null,zP.render);Cu.toDataURL=Kw.bind(null,zP.renderToDataURL);Cu.toString=Kw.bind(null,function(e,n,s){return OZ.render(e,s)});async function LZ(e){const n=await Cu.toString(e,{type:"svg",margin:1,errorCorrectionLevel:"M"});return`data:image/svg+xml;charset=utf-8,${encodeURIComponent(n)}`}const jS=10*6e4,FZ=2e3;function Vw(e,n){const[s,r]=h.useState(null),[a,i]=h.useState(null),[l,o]=h.useState(!1),[c,u]=h.useState(!1),d=h.useRef(e);d.current=e;const f=h.useRef(n);f.current=n;const m=h.useCallback(async()=>{const p=await R.telegramPairing();r(p),u(!1),o(!1),i(await LZ(p.link).catch(()=>""))},[]);return h.useEffect(()=>{if(!s||l||c)return;let p=!1;const g=Math.min(Date.parse(s.expiresAt)||Date.now()+jS,Date.now()+jS),v=window.setInterval(()=>{if(Date.now()>=g){u(!0);return}d.current().then(b=>{var j;p||!b||(o(!0),(j=f.current)==null||j.call(f))}).catch(()=>{})},FZ);return()=>{p=!0,window.clearInterval(v)}},[s,l,c]),{offer:s,square:a,paired:l,stale:c,ask:m}}function Gw({offer:e,square:n,children:s}){return t.jsxs("div",{className:"meet-pair",children:[n?t.jsx("img",{className:"meet-qr",src:n,alt:e.link}):null,t.jsx("a",{className:"meet-link",href:e.link,target:"_blank",rel:"noreferrer",children:e.link}),s]})}const UP=new Set(["approval","question"]),Yd={approval:{label:"Approvals",hint:"A run nobody is watching wants to do something gated."},question:{label:"Questions",hint:"A run asked you something and waits."},watcher:{label:"Watchers",hint:"A watcher or a source found something."},reminder:{label:"Reminders",hint:"A reminder an agent promised you came due."},failure:{label:"Failures",hint:"Background jobs died and will not be retried."},recap:{label:"Reports",hint:"Mission reports, the weekly recap, answers to actions you tapped."},plugin:{label:"Plugins",hint:"A plugin that may send you messages has something to say."},agent:{label:"Messages from your agents",hint:"An agent told you something itself."}},_Z=new Set(["agent"]),zZ={maxUrgency:"now",muted:[]};function UZ(e,n){var a;const s=Yd[e.kind].label.toLowerCase();return e.kind!=="agent"||!e.agentId?s:`from ${((a=n.find(i=>i.id===e.agentId))==null?void 0:a.name)??e.agentId}`}function BZ({timezone:e}){var j,x,y;const n=me(()=>R.notificationSettings(),[]),s=me(()=>R.agents(),[]),r=me(()=>R.notifications(20),[],3e4),a=h.useRef(!1);h.useEffect(()=>{var w,k;a.current||!r.data||window.location.hash!==Ax||(a.current=!0,(k=(w=document.getElementById("notifications-recent"))==null?void 0:w.scrollIntoView)==null||k.call(w,{block:"start"}))},[r.data]);const[i,l]=h.useState(null),[o,c]=h.useState(!1),[u,d]=h.useState(!1),[f,m]=h.useState(null),p=((j=n.data)==null?void 0:j.channels)??[],g=i??((x=n.data)==null?void 0:x.settings),v=w=>{g&&(d(!1),l({...g,...w}))},b=()=>{g&&(c(!0),d(!1),m(null),R.saveNotificationSettings(g).then(()=>{d(!0),l(null),n.reload()}).catch(w=>m(w instanceof xe?w.message:String(w))).finally(()=>c(!1)))};return t.jsxs(ie,{gap:"lg",children:[t.jsx(ue,{title:"Notifications",aside:"What buddi tells you when you are not looking at this page.",panel:!0,foot:t.jsx(A,{variant:"accent",disabled:o||!g,onClick:b,children:"Save"}),children:t.jsxs(ie,{divided:!0,children:[t.jsx(ne,{message:n.error??f}),t.jsx(ue,{title:"Where buddi reaches you",children:g?p.length===0?t.jsxs("p",{className:"ui-card-meta",children:["No channel yet, so everything waits for you here. ",t.jsx("a",{href:Le("telegram"),children:"Set up Telegram"})," and buddi can reach you on your phone."]}):t.jsxs(ie,{gap:"sm",children:[p.map(w=>{var k;return t.jsx(YZ,{channel:w,checked:(g.defaultChannel??((k=p[0])==null?void 0:k.kind))===w.kind,onPick:()=>v({defaultChannel:w.kind})},w.kind)}),p.some(w=>w.kind==="telegram")?null:t.jsxs("p",{className:"ui-card-meta",children:["Telegram is not set up. ",t.jsx("a",{href:Le("telegram"),children:"Set up Telegram"})]})]}):t.jsx(ve,{children:"Loading…"})}),t.jsx(ue,{title:"By kind",children:g?t.jsxs(ie,{gap:"sm",children:[e_.filter(w=>!_Z.has(w)).map(w=>t.jsxs("div",{className:"pref-row nt-kind",children:[t.jsxs("div",{className:"pref-text",children:[t.jsx("span",{className:"pref-label",children:Yd[w].label}),t.jsx("span",{className:"ui-field-hint",children:Yd[w].hint})]}),t.jsxs("select",{"aria-label":Yd[w].label,value:JZ(g,w,p),onChange:k=>{const N={...g.perKind};k.target.value==="default"?delete N[w]:N[w]=k.target.value,v({perKind:N})},children:[t.jsx("option",{value:"default",children:"Default"}),p.map(k=>t.jsx("option",{value:k.kind,children:k.label},k.kind)),UP.has(w)?null:t.jsx("option",{value:"off",children:"Off"})]})]},w)),t.jsx("p",{className:"ui-field-hint",children:"Off keeps it in the list below and never sends it."})]}):null}),t.jsx(ue,{title:"Messages from your agents",children:g?t.jsx(WZ,{settings:g,agents:((y=s.data)==null?void 0:y.agents)??[],onChange:v}):null}),t.jsx(ue,{title:"Focus schedules",children:g?t.jsxs(ie,{gap:"sm",children:[t.jsx(ZZ,{schedules:g.schedules,onChange:w=>v({schedules:w})}),t.jsxs("p",{className:"ui-field-hint",children:["Do not disturb holds everything but approvals and questions; Urgent only also lets watchers and failures through. What waited comes in one message when the focus ends. Switch a focus by hand from your initial at the foot of the rail, or /focus on Telegram. Times are on your clock (",e,")."]}),t.jsx("div",{className:"nt-times",children:t.jsx(re,{label:"End of the day",children:t.jsx("input",{type:"time",value:g.endOfDay,onChange:w=>v({endOfDay:w.target.value})})})}),t.jsx("p",{className:"ui-field-hint",children:"At the end of the day, what could wait goes out as one message."})]}):null}),u?t.jsx(G,{tone:"good",role:"status",children:"Saved."}):null]})}),t.jsx(HZ,{}),t.jsx("div",{id:"notifications-recent",className:"notifications-recent",children:t.jsxs(ue,{title:"The last twenty",panel:!0,flush:!0,children:[t.jsx(ne,{message:r.error}),r.data?r.data.notifications.length===0?t.jsx(ve,{children:"Nothing yet. What buddi tells you will be listed here."}):t.jsx(at,{children:r.data.notifications.map(w=>{var k;return t.jsx(Xe,{title:Kc(w),sub:`${ct(w.createdAt,e)} · ${UZ(w,((k=s.data)==null?void 0:k.agents)??[])} · ${QZ(w,p)}`,side:t.jsx(XZ,{row:w})},w.id)})}):t.jsx(ve,{children:"Loading…"})]})})]})}function WZ({settings:e,agents:n,onChange:s}){const r=e.perKind.agent!=="off",a=e.agents??zZ,i=o=>{const c={...e.perKind};o?delete c.agent:c.agent="off",s({perKind:c})},l=(o,c)=>s({agents:{...a,muted:c?[...new Set([...a.muted,o])]:a.muted.filter(u=>u!==o)}});return t.jsxs(ie,{gap:"sm",children:[t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:r,onChange:o=>i(o.target.checked)}),t.jsx("span",{children:"Agents may message you"})]}),t.jsxs("div",{className:"pref-row nt-kind",children:[t.jsxs("div",{className:"pref-text",children:[t.jsx("span",{className:"pref-label",children:"Highest urgency"}),t.jsx("span",{className:"ui-field-hint",children:"End of the day holds every message for the end-of-day message."})]}),t.jsxs("select",{"aria-label":"Highest urgency for agents",value:a.maxUrgency,disabled:!r,onChange:o=>s({agents:{...a,maxUrgency:o.target.value==="today"?"today":"now"}}),children:[t.jsx("option",{value:"now",children:"Now"}),t.jsx("option",{value:"today",children:"End of the day"})]})]}),n.length>0?t.jsx("div",{className:"ui-stack","data-gap":"sm",role:"group","aria-label":"Muted agents",children:n.map(o=>t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:a.muted.includes(o.id),disabled:!r,onChange:c=>l(o.id,c.target.checked),"aria-label":`Mute @${o.handle}`}),t.jsxs("span",{children:["Mute ",o.name," (@",o.handle,")"]})]},o.id))}):null,t.jsx("p",{className:"ui-field-hint",children:'An agent given the owner.notify tool can message you itself, signed "@agent: title" on Telegram; here the agent is named beside it. Each agent may send 6 urgent messages an hour and 20 a day. Off keeps them in the list below and never sends them.'})]})}function HZ(){var u;const e=me(()=>R.tipsSettings(),[]),[n,s]=h.useState(!1),[r,a]=h.useState(null),[i,l]=h.useState(null),o=i??((u=e.data)==null?void 0:u.enabled)??!0,c=d=>{s(!0),a(null),l(d),R.saveTipsSettings(d).then(f=>l(f.enabled)).catch(f=>{l(!d),a(f instanceof xe?f.message:String(f))}).finally(()=>s(!1))};return t.jsx(ue,{title:"Tips",panel:!0,children:t.jsxs(ie,{gap:"sm",children:[t.jsx(ne,{message:e.error??r}),t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:o,disabled:n||!e.data,onChange:d=>c(d.target.checked)}),t.jsx("span",{children:"Tips on Home"})]}),t.jsx("p",{className:"ui-field-hint",children:"When something in buddi has gone unused, Home may say so in one sentence, at most once a day."})]})})}function KZ({timezone:e}){return t.jsx(VZ,{timezone:e,onChange:()=>{}})}function VZ({timezone:e,onChange:n}){var C,E;const s=me(()=>R.telegramBot(),[]),r=me(()=>R.telegramDevices(),[]),[a,i]=h.useState(!1),[l,o]=h.useState(""),[c,u]=h.useState(!1),[d,f]=h.useState(null),[m,p]=h.useState(null),g=h.useRef(new Set),v=Vw(()=>R.telegramDevices().then(T=>T.devices.some(I=>!g.current.has(I.id))),()=>{r.reload(),n()}),b=((C=s.data)==null?void 0:C.configured)??!1,j=!b||a,x=()=>{var I;if(l.trim()===""||c)return;u(!0),f(null);const T=a&&(((I=s.data)==null?void 0:I.running)??!1);R.saveTelegramToken(l.trim()).then(F=>{o(""),i(!1),f(F.restartNeeded?{ok:!1,text:F.note??"Saved. It will be ready the next time buddi starts."}:T?{ok:!0,text:"Saved. The new bot takes over the next time buddi starts."}:{ok:!0,text:"Saved."}),s.reload(),n()}).catch(F=>f({ok:!1,text:F instanceof xe?F.message:String(F)})).finally(()=>u(!1))},y=()=>{var T;p(null),g.current=new Set((((T=r.data)==null?void 0:T.devices)??[]).map(I=>I.id)),v.ask().catch(I=>p(I instanceof xe?I.message:String(I)))},{offer:w,square:k,paired:N,stale:S}=v;return t.jsx(ue,{title:"Telegram",aside:"Talk to buddi from your phone.",panel:!0,children:t.jsxs(ie,{divided:!0,children:[t.jsx(ue,{title:"The bot",foot:j?t.jsxs(t.Fragment,{children:[a?t.jsx(A,{variant:"ghost",onClick:()=>{i(!1),o("")},children:"Cancel"}):null,t.jsx(A,{variant:"accent",disabled:c||l.trim()==="",onClick:x,children:"Save token"})]}):void 0,children:t.jsxs(ie,{gap:"sm",children:[t.jsx(ne,{message:s.error}),!s.data&&!s.error?t.jsx(ve,{children:"Loading…"}):b&&!a?t.jsxs("div",{className:"nt-channel",children:[t.jsx("span",{className:"pref-label",children:(E=s.data)!=null&&E.username?`Bot: @${s.data.username}`:"A bot token is saved."}),t.jsx(A,{variant:"ghost",size:"sm",onClick:()=>{i(!0),f(null)},children:"Replace token"})]}):null,j?t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"ui-card-meta",children:"Ask @BotFather for a bot and paste its token here."}),t.jsx(re,{label:"Bot token",grow:!0,children:t.jsx("input",{type:"password",value:l,autoComplete:"off",spellCheck:!1,onChange:T=>o(T.target.value),onKeyDown:T=>{T.key==="Enter"&&(T.preventDefault(),x())}})})]}):null,d?t.jsx(G,{tone:d.ok?"good":"warning",role:"status",children:d.text}):null]})}),t.jsxs(ue,{title:"Your devices",children:[t.jsx(ne,{message:r.error}),r.data?r.data.devices.length===0?t.jsx("p",{className:"ui-card-meta",children:"No phone is paired yet."}):t.jsx(at,{children:r.data.devices.map(T=>t.jsx(Xe,{title:T.name??`Telegram user ${T.userId}`,sub:`Paired ${ct(T.pairedAt,e)} · ${T.lastSeenAt?`last spoke ${Ve(T.lastSeenAt)}`:"has not spoken yet"}`,side:t.jsx(GZ,{id:T.id,onGone:()=>{r.reload(),n()}})},T.id))}):r.error?null:t.jsx(ve,{children:"Loading…"})]}),t.jsx(ue,{title:"Pair a device",foot:b&&(!w||N)?t.jsx(A,{variant:w?void 0:"accent",onClick:y,children:"Pair a phone"}):b&&S?t.jsx(A,{variant:"accent",onClick:y,children:"New code"}):void 0,children:t.jsxs(ie,{gap:"sm",children:[t.jsx(ne,{message:m}),b?N?t.jsx(G,{tone:"good",role:"status",children:"Paired."}):w&&S?t.jsx("p",{className:"ui-card-meta",children:"That code has run out."}):w?t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"ui-card-meta",children:"Open this on your phone, then send /start to the bot."}),t.jsx(Gw,{offer:w,square:k,children:t.jsx(qZ,{text:w.link})}),t.jsxs("p",{className:"ui-field-hint",children:["The code works until ",ct(w.expiresAt,e),"."]})]}):t.jsx("p",{className:"ui-card-meta",children:"Pair another phone, or the first one if you skipped it."}):t.jsx("p",{className:"ui-card-meta",children:"Save a bot token first."})]})})]})})}function GZ({id:e,onGone:n}){const[s,r]=h.useState(!1),[a,i]=h.useState(!1),[l,o]=h.useState(null);if(!s)return t.jsx(A,{size:"sm",onClick:()=>r(!0),children:"Unpair"});const c=()=>{i(!0),o(null),R.unpairTelegramDevice(e).then(n).catch(u=>o(u instanceof xe?u.message:String(u))).finally(()=>i(!1))};return t.jsxs("span",{className:"nt-channel",children:[t.jsx("span",{className:"ui-field-hint",role:l?"alert":void 0,children:l??"It will no longer reach your agents."}),t.jsx(A,{size:"sm",variant:"ghost",disabled:a,onClick:()=>r(!1),children:"Keep"}),t.jsx(A,{size:"sm",variant:"danger",disabled:a,onClick:c,children:"Unpair"})]})}function qZ({text:e}){const[n,s]=h.useState(null),r=()=>{var a;if(!((a=navigator.clipboard)!=null&&a.writeText)){s("Select the link to copy it.");return}navigator.clipboard.writeText(e).then(()=>s("Copied."),()=>s("Select the link to copy it."))};return t.jsxs("span",{className:"nt-channel",children:[t.jsx(A,{size:"sm",onClick:r,children:"Copy"}),n?t.jsx("span",{className:"ui-field-hint",role:"status",children:n}):null]})}function YZ({channel:e,checked:n,onPick:s}){const[r,a]=h.useState(!1),[i,l]=h.useState(null),o=()=>{a(!0),l(null),R.testChannel(e.kind).then(()=>l({ok:!0,text:"Sent. Check that it arrived."})).catch(c=>l({ok:!1,text:c instanceof xe?c.message:String(c)})).finally(()=>a(!1))};return t.jsxs("div",{className:"nt-channel",children:[t.jsxs("label",{children:[t.jsx("input",{type:"radio",name:"nt-default-channel",checked:n,onChange:s}),t.jsxs("span",{className:"nt-channel-text",children:[t.jsxs("span",{className:"pref-label",children:[e.label,e.where?`, ${e.where}`:""]}),t.jsxs("span",{className:"ui-field-hint",children:["The title and a few lines of each message go to ",e.label,"."]}),i?t.jsx("span",{className:"nt-channel-sent","data-tone":i.ok?void 0:"critical",role:"status",children:i.text}):null]})]}),t.jsx(A,{size:"sm",disabled:r,onClick:o,children:"Send a test"})]})}function JZ(e,n,s){const r=e.perKind[n];return r==="off"?UP.has(n)?"default":"off":r&&s.some(a=>a.kind===r)?r:"default"}function QZ(e,n){var s;return e.channel&&e.channel!=="dashboard"?((s=n.find(r=>r.kind===e.channel))==null?void 0:s.label)??e.channel:"dashboard"}function XZ({row:e}){return e.state==="failed"?t.jsxs("span",{className:"nt-state","data-tone":"critical",children:["Failed: ",e.error??"no reason given"]}):e.actedAt?t.jsx("span",{className:"nt-state",children:"Acted on"}):e.seenAt?t.jsx("span",{className:"nt-state",children:"Seen"}):e.state==="held"?t.jsx("span",{className:"nt-state",children:"Waiting"}):e.state==="stored"?t.jsx("span",{className:"nt-state",children:"Kept"}):e.state==="sent"?t.jsx("span",{className:"nt-state",children:"Sent"}):t.jsx("span",{className:"nt-state",children:"Not seen"})}const yS={mon:"Mon",tue:"Tue",wed:"Wed",thu:"Thu",fri:"Fri",sat:"Sat",sun:"Sun"},wS={mode:"do-not-disturb",days:[...gx],from:"22:00",to:"07:00"};function ZZ({schedules:e,onChange:n}){const s=(r,a)=>n(e.map((i,l)=>l===r?{...i,...a}:i));return t.jsxs(ie,{gap:"sm",children:[e.length===0?t.jsx("p",{className:"ui-card-meta",children:"No schedule: a focus is on only when you switch one on."}):null,e.map((r,a)=>{const i=a+1;return t.jsxs("div",{className:"nt-schedule",role:"group","aria-label":`Schedule ${i}`,children:[t.jsxs("select",{"aria-label":`Schedule ${i} mode`,value:r.mode,onChange:l=>s(a,{mode:l.target.value}),children:[t.jsx("option",{value:"do-not-disturb",children:"Do not disturb"}),t.jsx("option",{value:"urgent-only",children:"Urgent only"})]}),t.jsx("span",{className:"nt-days",children:gx.map(l=>{const o=r.days.includes(l);return t.jsx("button",{type:"button",className:"nt-day","aria-pressed":o,"aria-label":`Schedule ${i} ${yS[l]}`,onClick:()=>s(a,{days:o?r.days.filter(c=>c!==l):gx.filter(c=>c===l||r.days.includes(c))}),children:yS[l]},l)})}),t.jsx(re,{label:"From",children:t.jsx("input",{type:"time","aria-label":`Schedule ${i} from`,value:r.from,onChange:l=>s(a,{from:l.target.value})})}),t.jsx(re,{label:"To",children:t.jsx("input",{type:"time","aria-label":`Schedule ${i} to`,value:r.to,onChange:l=>s(a,{to:l.target.value})})}),t.jsx(A,{size:"sm",variant:"ghost","aria-label":`Remove schedule ${i}`,onClick:()=>n(e.filter((l,o)=>o!==a)),children:"Remove"})]},a)}),t.jsx("div",{className:"nt-schedule-add",children:t.jsx(A,{size:"sm",onClick:()=>n([...e,{...wS,days:[...wS.days]}]),children:"Add a schedule"})})]})}const eee={you:"person",appearance:"sun",notifications:"bell",telegram:"send",memory:"notebook",proposals:"bulb",accounts:"key",computer:"monitor",secrets:"key",connections:"globe",lock:"lock",api:"terminal",watchers:"eye",backup:"archive",system:"chip",plugins:"plug"};function tee(e){const n=k3.map(r=>({id:r.id,route:Le(r.id),label:r.label,icon:eee[r.id],group:r.group})),s=[...e].sort((r,a)=>r.title.localeCompare(a.title,void 0,{sensitivity:"base"})||r.plugin.localeCompare(a.plugin)||r.id.localeCompare(a.id)).map(r=>({id:n$(r.plugin,r.id),route:Lr(r.plugin,r.id),label:r.title,icon:fR(r.icon),group:"plugins"}));return[...n,...s]}function BP(e){return b3.map(n=>({id:n.id,label:n.label,entries:e.filter(s=>s.group===n.id)})).filter(n=>n.entries.length>0)}function WP(e,n,s){return n?`${e}, ${n} open`:s?`${e}, ${s}`:void 0}function nee({entries:e,active:n,counts:s={},dots:r={},navigate:a}){var u;const i=h.useRef(null),l=BP(e),o=e.some(d=>d.id===n)?n:(u=e[0])==null?void 0:u.id,c=d=>{var g;const f=[...((g=i.current)==null?void 0:g.querySelectorAll("a.settings-nav-link"))??[]],m=f.indexOf(document.activeElement);if(m===-1)return;const p=v=>{var b;d.preventDefault(),(b=f[Math.max(0,Math.min(f.length-1,v))])==null||b.focus()};if(d.key==="ArrowDown")p(m+1);else if(d.key==="ArrowUp")p(m-1);else if(d.key==="Home")p(0);else if(d.key==="End")p(f.length-1);else if(d.key==="Enter"||d.key===" "){d.preventDefault();const v=f[m].getAttribute("href");v&&a(v)}};return t.jsx("nav",{className:"settings-nav","aria-label":"Settings sections",ref:i,onKeyDown:c,children:l.map(d=>t.jsxs("div",{className:"settings-nav-group",role:"group","aria-labelledby":`settings-nav-${d.id}`,children:[t.jsx("div",{className:"settings-nav-label",id:`settings-nav-${d.id}`,children:d.label}),d.entries.map(f=>{const m=f.id===n,p=s[f.id],g=r[f.id];return t.jsxs("a",{className:"settings-nav-link",href:f.route,"data-active":m?"true":void 0,"aria-current":m?"page":void 0,"aria-label":WP(f.label,p,g),tabIndex:f.id===o?0:-1,onClick:v=>{v.preventDefault(),a(f.route)},children:[t.jsx(le,{name:f.icon,className:"settings-nav-icon"}),t.jsx("span",{className:"settings-nav-text",children:f.label}),p?t.jsx("span",{className:"ui-badge settings-nav-count","aria-hidden":"true",children:p>99?"99+":p}):g?t.jsx("span",{className:"ui-badge settings-nav-dot","data-kind":"dot","data-testid":"settings-nav-dot","aria-hidden":"true"}):null]},f.id)})]},d.id))})}function see({entries:e,active:n,counts:s={},dots:r={},navigate:a}){const i=BP(e),l=e.find(o=>o.id===n)??e[0];return t.jsx("nav",{className:"settings-menu","aria-label":"Settings sections",children:t.jsxs(ju,{modal:!1,children:[t.jsx(yu,{asChild:!0,children:t.jsxs("button",{type:"button",className:"settings-menu-trigger","aria-label":`Settings section: ${(l==null?void 0:l.label)??""}`,children:[l?t.jsx(le,{name:l.icon,className:"settings-nav-icon"}):null,t.jsx("span",{className:"settings-nav-text",children:l==null?void 0:l.label}),t.jsx(le,{name:"chevron-down",className:"settings-menu-chevron"})]})}),t.jsx(xo,{children:t.jsx(wu,{className:"ui-menu settings-menu-list",align:"start",sideOffset:6,children:t.jsx($z,{value:n,onValueChange:o=>{const c=e.find(u=>u.id===o);c&&a(c.route)},children:i.map((o,c)=>t.jsxs(QA,{children:[c>0?t.jsx(ra,{className:"ui-menu-sep"}):null,t.jsx(Di,{className:"ui-menu-label",children:o.label}),o.entries.map(u=>{const d=s[u.id],f=r[u.id];return t.jsxs(Tz,{value:u.id,className:"ui-menu-item settings-menu-item","data-active":u.id===n?"true":void 0,"aria-label":WP(u.label,d,f),children:[t.jsxs("span",{className:"settings-menu-entry",children:[t.jsx(le,{name:u.icon,className:"settings-nav-icon"}),t.jsx("span",{className:"settings-nav-text",children:u.label})]}),d?t.jsx("span",{className:"ui-badge settings-nav-count","aria-hidden":"true",children:d>99?"99+":d}):f?t.jsx("span",{className:"ui-badge settings-nav-dot","data-kind":"dot","aria-hidden":"true"}):null]},u.id)})]},o.id))})})})]})})}function ree({hash:e,timezone:n,navigate:s,agents:r,pluginPages:a}){var y,w,k;const i=N3(e),l=K$(a!==void 0),o=a??l,c=t$(e),u=c?o.find(c.plugin,c.page):void 0,d=u?null:h3(e,o.settings);h.useEffect(()=>{d&&s(d,!0)},[d,s]);const f=ws(Ry),m=tee(o.settings),g={proposals:((w=(y=me(()=>Promise.resolve().then(()=>R.proposals()),[],3e4).data)==null?void 0:y.open)==null?void 0:w.length)??0},v=me(()=>R.version(),[]),b=me(()=>Promise.resolve().then(()=>R.connectionSignals()),[],6e4),j={};v.data&&!v.data.checkout&&v.data.updateAvailable&&(j.system="a newer buddi is ready"),(((k=b.data)==null?void 0:k.signals)??[]).length>0&&(j.connections=TR);const x={entries:m,active:i,counts:g,dots:j,navigate:N=>s(N)};return t.jsxs("div",{className:"settings",children:[f?null:t.jsx(nee,{...x}),t.jsx("div",{className:"settings-body",children:t.jsxs("div",{className:"ui-page",children:[i==="secrets"?t.jsx(Ql,{before:t.jsx(Ih,{inline:!0,items:[{label:"Settings",href:yn,onClick:()=>s(yn)}]}),title:"Keys and secrets",lede:sP,actions:t.jsx(ht,{variant:"accent",size:"sm",href:i0,onClick:N=>{N.preventDefault(),s(i0)},children:"Add a secret"})}):i==="plugins"||i==="connections"?t.jsx(Ql,{before:t.jsx(Ih,{inline:!0,items:[{label:"Settings",href:yn,onClick:()=>s(yn)}]}),title:i==="plugins"?"Plugins":"Connections",lede:i==="plugins"?cX:xI}):t.jsxs("header",{className:"ui-page-head",children:[t.jsx("h2",{className:"ui-page-title",children:"Settings"}),t.jsx("p",{className:"ui-page-lede",children:"How this installation runs, and where it reaches."})]}),f?t.jsx(see,{...x}):null,u?t.jsx(J9,{page:u,params:vy(e),navigate:s,timezone:n,siblings:o.all.filter(N=>N.plugin===u.plugin)}):null,i==="you"?t.jsx(zQ,{embedded:!0}):null,i==="appearance"?t.jsx(aee,{railPages:o.rail}):null,i==="notifications"?t.jsx(BZ,{timezone:n}):null,i==="telegram"?t.jsx(KZ,{timezone:n}):null,i==="memory"?t.jsx(JR,{embedded:!0,agents:r,timezone:n,initialTab:Nee(e)}):null,i==="proposals"?t.jsx(eX,{embedded:!0,plugin:j3(e)}):null,i==="accounts"?t.jsx($J,{embedded:!0,account:f3(e)}):null,i==="computer"?t.jsx(OW,{embedded:!0,timezone:n}):null,i==="secrets"?t.jsx(pQ,{embedded:!0,timezone:n,secret:p3(e),adding:g3(e),navigate:s}):null,i==="connections"?t.jsx(Aq,{embedded:!0,timezone:n,connection:m3(e)}):null,i==="lock"?t.jsx(DQ,{navigate:s}):null,i==="api"?t.jsx(_Q,{timezone:n}):null,i==="watchers"?t.jsx(SQ,{timezone:n,embedded:!0}):null,i==="backup"?t.jsx(bJ,{}):null,i==="plugins"?t.jsx(xX,{railPages:o.rail,settingsPages:o.settings,navigate:s,hash:e}):null,i==="system"?t.jsx(oee,{timezone:n}):null]})})]})}function aee({railPages:e}){const[n,s]=LR();return t.jsx(ue,{title:"Appearance",aside:"Kept in this browser only. Another browser keeps its own.",panel:!0,children:t.jsxs(ie,{divided:!0,gap:"lg",children:[t.jsx(ng,{label:"Theme",hint:"System follows your Mac.",children:t.jsx(ln,{label:"Theme",options:[{value:"light",label:"Light"},{value:"dark",label:"Dark"},{value:"system",label:"System"}],value:n.theme,onChange:r=>s({theme:r})})}),t.jsx(ng,{label:"Background",hint:"Blue carries the first-run colours through the app. Sand is quieter.",children:t.jsx(ln,{label:"Background",options:[{value:"blue",label:"Blue"},{value:"sand",label:"Sand"}],value:n.ground,onChange:r=>s({ground:r})})}),t.jsx(ng,{label:"Page width",hint:"How far pages stretch on a wide screen.",children:t.jsx(ln,{label:"Page width",options:[{value:"narrow",label:"Narrow"},{value:"wide",label:"Wide"},{value:"full",label:"Full"}],value:n.width,onChange:r=>s({width:r})})}),t.jsx(lee,{pages:e}),t.jsx(iee,{})]})})}function iee(){var c,u,d;const e=me(()=>R.overview(),[]),[n,s]=h.useState(null),r=((c=e.data)==null?void 0:c.glances)??[],a=((u=e.data)==null?void 0:u.home)??[],i=((d=e.data)==null?void 0:d.dismissed)??{};if(r.length===0&&a.length===0)return null;const l=(f,m)=>{s(f),R.setGlanceHidden(f,!m).then(()=>e.reload()).finally(()=>s(null))},o=(f,m)=>{s(`block:${f}`),R.homeDismiss(`block:${f}`,m?null:"hidden").then(()=>e.reload()).finally(()=>s(null))};return t.jsxs(t.Fragment,{children:[r.length>0?t.jsxs("div",{className:"pref-row ui-section",children:[t.jsxs("div",{className:"pref-text",children:[t.jsx("span",{className:"pref-label",children:"Home glances"}),t.jsx("span",{className:"ui-field-hint",children:"The lines beside the date on Home, at most three. Kept for every browser."})]}),t.jsx(ie,{gap:"sm",children:r.map(f=>t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:!f.hidden,disabled:n===f.id,onChange:m=>l(f.id,m.target.checked)}),t.jsx("span",{children:f.title})]},f.id))})]}):null,a.length>0?t.jsxs("div",{className:"pref-row ui-section",children:[t.jsxs("div",{className:"pref-text",children:[t.jsx("span",{className:"pref-label",children:"Home sections"}),t.jsx("span",{className:"ui-field-hint",children:"What the plugins put on Home. Kept for every browser."})]}),t.jsx(ie,{gap:"sm",children:a.map(f=>t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:i[`block:${f.id}`]!=="hidden",disabled:n===`block:${f.id}`,onChange:m=>o(f.id,m.target.checked)}),t.jsx("span",{children:f.title})]},f.id))})]}):null]})}function lee({pages:e}){const n=RR(),[s,r]=h.useState(null);if(e.length===0)return null;const a=(i,l)=>{r(null),T7(i,!l).catch(o=>r(o instanceof Error?o.message:String(o)))};return t.jsxs("div",{className:"pref-row ui-section",children:[t.jsxs("div",{className:"pref-text",children:[t.jsx("span",{className:"pref-label",children:"In the rail"}),t.jsx("span",{className:"ui-field-hint",children:"The plugin pages beside Home and Chat. One you turn off still opens from Settings → Plugins. Kept for every browser."})]}),t.jsxs(ie,{gap:"sm",children:[t.jsx(ne,{message:s}),e.map(i=>t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:!n.has(au(i)),onChange:l=>a(i,l.target.checked)}),t.jsx("span",{children:i.title})]},au(i)))]})]})}function ng({label:e,hint:n,children:s}){return t.jsxs("div",{className:"pref-row ui-section",children:[t.jsxs("div",{className:"pref-text",children:[t.jsx("span",{className:"pref-label",children:e}),t.jsx("span",{className:"ui-field-hint",children:n})]}),s]})}function oee({timezone:e}){const n=me(()=>R.overview(),[],15e3),s=me(()=>R.session(),[]),r=me(()=>R.providerAccounts(),[]),a=n.data;return t.jsxs(ie,{gap:"lg",children:[t.jsx(ne,{message:n.error}),t.jsx(wee,{}),a?t.jsx(ue,{title:"The queue",panel:!0,actions:t.jsx(A,{size:"sm",variant:a.paused?"accent":void 0,onClick:()=>{R.setPaused(!a.paused).then(()=>n.reload())},children:a.paused?"Resume the queue":"Pause the queue"}),children:t.jsxs("p",{className:"ui-card-meta",children:[a.paused?"Paused. Nothing is being claimed until you resume.":"Running. Jobs are claimed as they come due."," ",a.paused?t.jsx(Ee,{tone:"warning",children:"paused"}):t.jsx(Ee,{tone:"good",children:"running"})]})}):null,t.jsxs(ue,{title:"This host",panel:!0,children:[t.jsx(qt,{items:[{label:"Time zone",value:e},{label:"Server time",value:a?ct(a.now,e):"…"},{label:"Bound to",value:s.data?`${s.data.host}:${s.data.port}`:"…"},{label:"Credential vault",value:r.data?hee(r.data.vault.kind):"…"}]}),r.data&&(r.data.vault.locked||r.data.vault.kind==="none")?t.jsx(G,{tone:"warning",children:r.data.vault.advice||"Run buddi init on the host to configure secure credential storage."}):null]}),t.jsx(dee,{}),t.jsx(iV,{}),t.jsx(cee,{}),t.jsx(ue,{title:"Mail and sources",panel:!0,children:a?a.mail.length===0?t.jsx(ve,{children:"No sources are installed."}):t.jsx(qt,{items:a.mail.map(i=>({key:i.sourceId,label:t.jsx("span",{className:"mono",children:i.sourceId}),value:i.lastError?t.jsx("span",{className:"critical",children:i.lastError}):t.jsxs("span",{children:["polled ",Ve(i.lastRunAt)]})}))}):t.jsx(ve,{children:"Loading…"})})]})}function cee(){var p;const e=me(()=>R.tailscale(),[]),[n,s]=h.useState(null),[r,a]=h.useState(!1),[i,l]=h.useState(null),[o,c]=h.useState(!1),u=e.data,d=n??((u==null?void 0:u.login)||((p=u==null?void 0:u.self)==null?void 0:p.login)||""),f=(u==null?void 0:u.proxied)===!0,m=g=>{a(!0),l(null),c(!1),R.setTailscale({enabled:g,login:d.trim()}).then(()=>{c(!0)}).catch(v=>l(v instanceof xe?v.message:String(v))).finally(()=>{a(!1),e.reload()})};return t.jsx(ue,{title:"Sign in through Tailscale",panel:!0,foot:t.jsx(A,{variant:"accent",disabled:r||!u||f,onClick:()=>m((u==null?void 0:u.enabled)??!1),children:"Save"}),children:t.jsx(ie,{divided:!0,children:t.jsx(ue,{children:t.jsxs(ie,{gap:"sm",children:[t.jsx(ne,{message:e.error??i}),t.jsx("p",{className:"ui-card-meta",children:u?u.available&&u.self?`Tailscale is running on this machine as ${u.self.login}.`:u.available?"Tailscale is running on this machine.":"Tailscale is not running here.":"…"}),f?t.jsxs(t.Fragment,{children:[t.jsx(G,{tone:"warning",children:"Change this from the computer buddi runs on."}),t.jsx("p",{className:"ui-card-meta",children:u!=null&&u.enabled?`On, for ${d}`:"Off"})]}):null,t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:(u==null?void 0:u.enabled)??!1,disabled:r||!u||f,onChange:g=>m(g.target.checked)}),t.jsx("span",{children:"Let this Tailscale login sign in"})]}),t.jsx(re,{label:"Tailscale login",children:t.jsx("input",{type:"text",value:d,placeholder:"you@example.com",disabled:r||!u||f,onChange:g=>s(g.target.value)})}),t.jsx("p",{className:"ui-card-meta",children:"Anyone signed in to Tailscale as this login, on any device in your tailnet, is signed in to buddi. The proxy must run on this machine:"}),t.jsxs("div",{className:"tailscale-command",children:[t.jsx("code",{className:"mono",children:(u==null?void 0:u.serveCommand)??"tailscale serve"}),t.jsx(A,{size:"sm",disabled:r||!u,onClick:()=>{uee((u==null?void 0:u.serveCommand)??"")},children:"Copy"})]}),t.jsx("p",{className:"ui-card-meta",children:"This gives your tailnet the trust this machine already has: buddi cannot tell the Tailscale proxy from another program running here, and any program that can reach the dashboard on this machine can already read buddi’s files."}),o?t.jsx(G,{tone:"good",role:"status",children:"Saved."}):null]})})})})}async function uee(e){var n;try{await((n=navigator.clipboard)==null?void 0:n.writeText(e))}catch{}}function dee(){var u;const e=me(()=>R.service(),[],1e4),[n,s]=h.useState(null),[r,a]=h.useState(!1),[i,l]=h.useState(null),o=(u=e.data)!=null&&u.supervised?e.data.status:void 0;if(!o)return null;const c=d=>{a(!0),l(null),Gf({kind:d},()=>R.serviceAction(d)).then(()=>{s(null)}).catch(f=>{l(f.message),e.reload()}).finally(()=>{a(!1)})};return t.jsx(ue,{title:"Service",panel:!0,children:t.jsxs(ie,{divided:!0,children:[t.jsx(ue,{children:t.jsx(qt,{items:[{label:"Database",value:t.jsx(bS,{state:o.database,pid:o.databasePid})},{label:"Gateway",value:t.jsx(bS,{state:o.gateway,pid:o.gatewayPid})},{label:"Supervisor",value:t.jsxs("span",{className:"mono",children:["pid ",o.supervisorPid]})}]})}),t.jsx(ue,{children:t.jsxs(ie,{gap:"sm",children:[t.jsx(ne,{message:i}),n?t.jsx(G,{tone:"warning",role:"alert",children:n==="stop"?"Stopping the gateway closes this dashboard. The database keeps running; run buddi in a terminal to bring the dashboard back.":"Restarting the gateway takes a few seconds. This page waits for it and comes back by itself."}):t.jsx("p",{className:"ui-card-meta",children:"Stopping the gateway ends this dashboard until buddi is run again."}),t.jsx(te,{align:"end",children:n?t.jsxs(t.Fragment,{children:[t.jsx(A,{variant:"ghost",disabled:r,onClick:()=>{s(null),l(null)},children:"Cancel"}),t.jsx(A,{variant:n==="stop"?"danger":"accent",disabled:r,onClick:()=>{c(n)},children:n==="stop"?"Stop it":"Restart it"})]}):t.jsxs(t.Fragment,{children:[t.jsx(A,{variant:"ghost",onClick:()=>{s("stop")},children:"Stop gateway"}),t.jsx(A,{variant:"accent",onClick:()=>{s("restart")},children:"Restart gateway"})]})})]})})]})})}function bS({state:e,pid:n}){return t.jsxs("span",{children:[t.jsx(Ee,{tone:e==="running"?"good":e==="stopped"?"warning":e==="failed"?"critical":"muted",children:e})," ",n===null?t.jsx("span",{className:"ui-card-meta",children:"no process"}):t.jsxs("span",{className:"mono",children:["pid ",n]})]})}function hee(e){return e==="keychain"?"macOS Keychain":e==="file"?"Encrypted file vault":e==="none"?"None":e}const fee=2e3,rf={starting:"Getting started.",backup:"Taking a backup first, so there is a way back.",stopping:"Stopping the gateway. The database stays up.",installing:"Installing the new version.",verifying:"Checking that the new version can start its database.","rolling-back":"The new version could not start its database. Putting the previous one back.",restarting:"Restarting buddi on the new version.",migrating:"Bringing the database up to date.",done:"Done.",failed:"That did not work."},mee=new Set(["done","failed","rolled-back"]),pee="The check asks the npm registry for the newest version and sends nothing else.",gee="This takes a backup, installs the new version and restarts buddi. This page waits for it and comes back by itself.",xee="A checkout upgrades with git pull, then buddi upgrade in a terminal.",vee=15*6e4;function jee(e){const n=e.step==="starting"?"while starting":`at ${e.step??"an unknown step"}`;return`The upgrade to ${e.to} failed ${n}: ${e.error??"no reason given"}. The backup taken first is ${e.backup??"not available"}. Run buddi doctor in a terminal; it prints the way back.`}function kS(e,n=Date.now()){const s=e[e.length-1];if((s==null?void 0:s.outcome)!=="failed")return null;const r=Date.parse(s.finishedAt??s.startedAt);return Number.isFinite(r)&&n-r<vee?s:null}function yee(e,n){const[s,r]=h.useState(void 0),[a,i]=h.useState(null),l=h.useRef(n);return l.current=n,h.useEffect(()=>{if(!e){r(void 0);return}let o=!1,c=!1;const u=()=>{o||c||R.upgradeJob(e).then(f=>{var m;o||(r(f),i(null),u$({step:rf[f.phase]??f.detail??f.phase}),(mee.has(f.phase)||f.finishedAt)&&(o=!0,f.phase==="failed"&&(Yl(),(m=l.current)==null||m.call(l,f))))}).catch(f=>{o||(f instanceof xe&&f.status!==0&&f.status<500?(o=!0,Yl(),i(f.message)):c=!0)})};u();const d=window.setInterval(u,fee);return()=>{o=!0,window.clearInterval(d)}},[e]),{job:s,error:a}}function wee(){const e=me(()=>R.version(),[]),[n,s]=h.useState(null),[r,a]=h.useState(!1),[i,l]=h.useState(!1),[o,c]=h.useState(null),[u,d]=h.useState(null),f=h.useCallback(j=>{s(null),d(j)},[]),m=yee(n,f),p=e.data,g=()=>{l(!0),c(null),R.checkVersion().catch(j=>c(j instanceof xe?j.message:String(j))).finally(()=>{l(!1),e.reload()})},v=j=>{l(!0),c(null),R.setVersionCheck(j).catch(x=>c(x instanceof xe?x.message:String(x))).finally(()=>{l(!1),e.reload()})},b=()=>{l(!0),c(null),d(null),Gf({kind:"upgrade",line:p!=null&&p.latest?`Upgrading to ${p.latest}…`:"Upgrading…",step:rf.starting,patienceMs:c$},()=>R.startUpgrade(p==null?void 0:p.latest)).then(j=>{var x;a(!1),s(((x=j==null?void 0:j.job)==null?void 0:x.id)??null)}).catch(j=>c(j instanceof xe?j.message:String(j))).finally(()=>l(!1))};return p!=null&&p.checkout?t.jsx(ue,{title:"Version",panel:!0,children:t.jsxs(ie,{divided:!0,children:[t.jsx(ue,{children:t.jsx(qt,{items:[{label:"Running",value:t.jsx("span",{className:"mono",children:p.current})}]})}),t.jsx(ue,{children:t.jsx("p",{className:"ui-card-meta",children:xee})})]})}):t.jsx(ue,{title:"Version",panel:!0,children:t.jsxs(ie,{divided:!0,children:[t.jsx(ue,{children:t.jsxs(ie,{gap:"sm",children:[t.jsx(ne,{message:e.error??o}),t.jsx(qt,{items:[{label:"Running",value:p?t.jsx("span",{className:"mono",children:p.current}):"…"},{label:"Newest",value:p?p.updateAvailable&&p.latest?t.jsxs("span",{children:["A newer buddi is available: ",t.jsx("span",{className:"mono",children:p.latest})]}):p.checkedAt?t.jsxs("span",{children:["This is the latest, as of ",Ve(p.checkedAt),"."]}):t.jsx("span",{children:"Not checked yet."}):"…"}]}),p!=null&&p.error?t.jsxs(G,{tone:"warning",children:["The last check did not get an answer: ",p.error]}):null,t.jsx(te,{align:"end",children:t.jsx(A,{disabled:i,onClick:g,children:"Check now"})})]})}),t.jsx(ue,{children:t.jsxs(ie,{gap:"sm",children:[t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:(p==null?void 0:p.checkEnabled)??!1,disabled:i||!p,onChange:j=>v(j.target.checked)}),t.jsx("span",{children:"Check once a day"})]}),t.jsx("p",{className:"ui-card-meta",children:pee})]})}),p!=null&&p.updateAvailable&&p.latest&&p.latestNotes?t.jsx(ue,{title:`What changes in ${p.latest}`,children:t.jsx(ur,{text:p.latestNotes})}):null,t.jsx(ue,{children:t.jsxs(ie,{gap:"sm",children:[t.jsx(bee,{...m,job:m.job??u??void 0}),!m.job&&!u&&!m.error&&p&&kS(p.history)?t.jsx(G,{tone:"critical",role:"alert",children:jee(kS(p.history))}):null,r?t.jsx(G,{tone:"warning",role:"alert",children:gee}):null,t.jsx(te,{align:"end",children:r?t.jsxs(t.Fragment,{children:[t.jsx(A,{variant:"ghost",disabled:i,onClick:()=>a(!1),children:"Cancel"}),t.jsxs(A,{variant:"accent",disabled:i,onClick:b,children:["Upgrade to ",p==null?void 0:p.latest]})]}):t.jsx(A,{variant:"accent",disabled:i||n!==null||!(p!=null&&p.updateAvailable),onClick:()=>a(!0),children:p!=null&&p.updateAvailable&&p.latest?`Upgrade to ${p.latest}`:"Upgrade"})})]})}),p&&p.history.length>0?t.jsx(ue,{title:"Upgrades so far",children:t.jsx(qt,{items:p.history.slice().reverse().map(j=>({key:j.startedAt,label:t.jsxs("span",{className:"mono",children:[j.from," → ",j.to]}),value:t.jsx(kee,{attempt:j})}))})}):null]})})}function bee({job:e,error:n}){return n?t.jsx(ne,{message:n}):e?e.phase==="failed"?t.jsxs(G,{tone:"critical",role:"alert",children:[rf.failed," ",e.error??""," buddi is still running on the version it had."]}):t.jsx(G,{tone:e.phase==="done"?"good":void 0,role:"status",children:rf[e.phase]??e.detail??e.phase}):null}function kee({attempt:e}){return t.jsxs("span",{children:[t.jsx(Ee,{tone:e.outcome==="done"?"good":e.outcome==="failed"?"critical":"warning",children:e.outcome})," ",Ve(e.startedAt),e.step?`, at ${e.step}`:"",e.error?`: ${e.error}`:"",e.backup?t.jsxs("span",{className:"ui-card-meta",children:[" Backup: ",t.jsx("span",{className:"mono",children:e.backup})]}):null]})}function Nee(e){var s;return((s=/[?&]tab=(people|preferences|notes)\b/.exec(e))==null?void 0:s[1])??"people"}const af=["hello","brain","takeOn","reach","assistant","handover"],HP={hello:"you",brain:"model",takeOn:"take-on",reach:"reach",assistant:"agent",handover:"hello"};function KP(e){return((e==null?void 0:e.accounts)??[]).filter(n=>n.enabled&&n.configured&&n.removalPending!==!0)}function See(e){var i,l,o;const n=KP(e.accounts),s=e.assistant?(((i=e.accounts)==null?void 0:i.bindings)??[]).find(c=>c.agentId===e.assistant.id):void 0,r=(s==null?void 0:s.accountId)??((o=(l=e.onboarding)==null?void 0:l.details)==null?void 0:o.accountId);if(!r)return;const a=n.find(c=>c.id===r);if(a)return{accountId:a.id,label:a.label,model:(s==null?void 0:s.model)??a.defaultModel}}function VP(e){var i,l,o,c,u;const n=See(e),s=e.onboarding&&!e.onboarding.needs.agent?e.assistant:void 0,r=((i=e.onboarding)==null?void 0:i.details)??{},a=((l=e.onboarding)==null?void 0:l.stepsDone)??[];return{...(o=e.owner)!=null&&o.preferredName?{name:e.owner.preferredName}:{},...(c=e.owner)!=null&&c.timezone?{clock:e.owner.timezone}:{},...n?{brain:n}:{},...Array.isArray(r.takeOn)?{takeOn:r.takeOn}:s?{takeOn:[]}:{},...r.reach?{reach:r.reach}:a.includes("reach")||s?{reach:{}}:{},...a.includes("browser")||((u=r.reach)==null?void 0:u.browser)===!0?{browser:e.browser??"other"}:{},...s?{assistant:s}:{}}}function GP(e,n){return n==="hello"?typeof e.name=="string"&&e.name!==""&&typeof e.clock=="string"&&e.clock!=="":n==="brain"?e.brain!==void 0:n==="takeOn"?e.takeOn!==void 0:n==="reach"?e.reach!==void 0:n==="assistant"?e.assistant!==void 0:!1}function Jd(e){return af.find(n=>!GP(e,n))??"handover"}function Cee(e){const n=af.indexOf(e);return n>0?af[n-1]:null}function NS(e,n,s){return s===n?"now":GP(e,s)?"done":"todo"}function Eee(e,n){return{...e}}const Fv="buddi.firstRun.restore";function _v(e){try{e===null?window.sessionStorage.removeItem(Fv):window.sessionStorage.setItem(Fv,e)}catch{}}function qP(){try{return window.sessionStorage.getItem(Fv)}catch{return null}}function Aee(e){const n=VP(e),s=Jd(n);return{answers:n,open:s,stay:s!=="handover"}}function $ee(e){return e.trim().startsWith("sk-ant-")?"anthropic":"openai"}function Tee(e){const n=e.normalize("NFKD").replace(/[̀-ͯ]/g,"").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^[^a-z]+/,"").replace(/-+$/,"").slice(0,20).replace(/-+$/,"");return n===""?"assistant":n}const Ree=6e4,Iee=5*6e4,YP=1500,Pee=2e3,Mee="(max-width: 720px)";function Eo(){const e=h.useRef(null);return h.useEffect(()=>{let n=0,s=0;const r=l=>{const o=l.ownerDocument.activeElement;if(o===null||o===l.ownerDocument.body||o===l.ownerDocument.documentElement)return!0;const c=l.closest('[role="dialog"]');return c!==null&&o.tagName==="BUTTON"&&o.closest('[role="dialog"]')===c},a=()=>{const l=e.current;l&&r(l)&&l.focus()},i=()=>{a(),s=window.setTimeout(a,0)};return typeof window.requestAnimationFrame=="function"?n=window.requestAnimationFrame(i):i(),window.addEventListener("focus",a),()=>{n&&window.cancelAnimationFrame(n),window.clearTimeout(s),window.removeEventListener("focus",a)}},[]),e}const qw=h.createContext({busy:0,report:()=>{}});function Dee({children:e}){const[n,s]=h.useState(0),r=h.useCallback(i=>s(l=>Math.max(0,l+(i?1:-1))),[]),a=h.useMemo(()=>({busy:n,report:r}),[n,r]);return t.jsx(qw.Provider,{value:a,children:e})}function ft({children:e}){const{busy:n}=h.useContext(qw);return t.jsxs("div",{className:"wiz-say",children:[t.jsx(ku,{state:n>0?"working":"idle",size:"sm",className:"wiz-say-face"}),t.jsx("div",{className:"wiz-bubble",children:e})]})}function rt({children:e}){return t.jsx(t.Fragment,{children:e})}function pr({line:e}){const{report:n}=h.useContext(qw);return h.useEffect(()=>(n(!0),()=>n(!1)),[n]),t.jsxs("div",{className:"wiz-busy",role:"status","aria-live":"polite",children:[t.jsxs("span",{className:"wiz-pulse","aria-hidden":"true",children:[t.jsx("i",{}),t.jsx("i",{}),t.jsx("i",{})]}),e]})}const Yw=h.createContext(null);function mn({children:e,actions:n}){const s=h.useContext(Yw),r=n==null?null:s?uo.createPortal(n,s):t.jsx("div",{className:"wiz-dock-inline",children:n});return t.jsxs(t.Fragment,{children:[e?t.jsx("div",{className:"wiz-ask",children:e}):null,r]})}function Ss({onClick:e,disabled:n}){return t.jsxs(A,{variant:"ghost",size:"lg",onClick:e,disabled:n,children:[t.jsx(le,{name:"chevron-left"}),_.back]})}function Ao({children:e,onClick:n,disabled:s}){return t.jsxs(A,{variant:"accent",size:"lg",onClick:n,disabled:s,children:[e,t.jsx(le,{name:"arrow"})]})}function Oee({navigate:e,timezone:n}){var Bn,hs,In,fs,Zt,ms,Tt;const s=ws(Mee),[r,a]=h.useState(void 0);h.useEffect(()=>{R.session().then($e=>a($e.platform)).catch(()=>{})},[]);const[i,l]=h.useState({}),[o,c]=h.useState(null),[u,d]=h.useState(void 0),[f,m]=h.useState(void 0),[p,g]=h.useState([]),[v,b]=h.useState(null),[j,x]=h.useState(null),[y,w]=h.useState(!1),[k,N]=h.useState(null),[S,C]=h.useState(null),[E,T]=h.useState(null),[I,F]=h.useState(null),[D,$]=h.useState(()=>qP()?"running":"idle"),[L,O]=h.useState({}),[M,P]=h.useState([]),[H,U]=h.useState(0),V=h.useRef(void 0),[z,X]=h.useState(null),K=h.useCallback(()=>{Promise.resolve().then(()=>R.takeOnProgress()).then($e=>{$e&&Array.isArray($e.plugins)&&X($e)}).catch(()=>{})},[]);h.useEffect(()=>{if(!(z!=null&&z.running))return;const $e=window.setInterval(K,Pee);return()=>window.clearInterval($e)},[z==null?void 0:z.running,K]);const ee=h.useMemo(()=>{try{return Intl.DateTimeFormat().resolvedOptions().timeZone||n}catch{return n}},[n]),ce=h.useRef(e);ce.current=e;const pe=h.useCallback(async($e=!0,Qe=!1)=>{var gn,Cn,Wn,Hn,es,Yt,ci,Ms,Ji;const[ze,Nt,q,he,Sn,on]=await Promise.all([R.onboarding().catch(()=>{}),R.owner().catch(()=>{}),R.providerAccounts().catch(()=>{}),qe.agents().catch(()=>{}),R.browser().catch(()=>{}),R.providers().catch(()=>{})]);d(q);const Se=(Cn=(gn=on==null?void 0:on.providers.find(xt=>xt.kind==="anthropic"))==null?void 0:gn.defaultModel)==null?void 0:Cn.trim();m(Se||void 0),g((Nt==null?void 0:Nt.zones)??[]),N(((Wn=ze==null?void 0:ze.details)==null?void 0:Wn.conversationId)??null);const Me=(he==null?void 0:he.agents.find(xt=>xt.id===he.defaultAgentId))??(he==null?void 0:he.agents[0]);Me&&b(Me),C(ze&&!ze.needs.agent&&Me?{id:Me.id,name:Me.name,avatar:((Hn=Me.avatar)==null?void 0:Hn.kind)==="emoji"?Me.avatar.value:"",description:Me.description,...Me.picture?{picture:Me.picture}:{}}:null),Array.isArray((es=ze==null?void 0:ze.details)==null?void 0:es.takeOn)&&K();const nt={onboarding:ze,owner:Nt,accounts:q,browser:(Yt=Sn==null?void 0:Sn.browser)==null?void 0:Yt.engine,...Me?{assistant:{id:Me.id,name:Me.name,avatar:((ci=Me.avatar)==null?void 0:ci.kind)==="emoji"?Me.avatar.value:""}}:{}};if(Qe){const xt=Aee(nt);if(l(xt.answers),c(xt.open),!xt.stay){const Js=(Ms=ze==null?void 0:ze.details)==null?void 0:Ms.conversationId;ce.current(Js&&Me?Ze(Me.id,Js):kn,!0)}return}if($e&&(ze==null?void 0:ze.state)==="done"){const xt=(Ji=ze.details)==null?void 0:Ji.conversationId;ce.current(xt&&Me?Ze(Me.id,xt):kn,!0);return}if(!$e)return;const lt=VP(nt);l(lt),c(xt=>xt??Jd(lt))},[]);h.useEffect(()=>{pe()},[pe]);const oe=($e,Qe={})=>{Promise.resolve().then(()=>R.onboardingStep(HP[$e],Qe)).catch(()=>{})},Re=$e=>Jd($e)==="brain"&&L.brain?{...$e,brain:L.brain}:$e,Oe=($e,Qe)=>{const ze=Re(Qe);ze.brain&&(V.current=ze.brain),x(null),P([]),l(ze),$e==="brain"&&ze.brain?oe($e,{accountId:ze.brain.accountId}):$e==="reach"?oe($e,ze.reach?{reach:ze.reach}:{}):$e!=="takeOn"&&oe($e),c(Jd(ze))},Je=($e,Qe)=>{x(null),l(Qe),Qe.brain&&(V.current=Qe.brain),$e==="brain"&&Qe.brain&&oe($e,{accountId:Qe.brain.accountId})},W=$e=>{x(null),l(Qe=>Eee(Qe)),c($e)},se=()=>{if(!o)return;const $e=Cee(o==="handover"?"handover":o);$e&&W($e)},Y=()=>{const $e=i.brain??V.current,Qe=((z==null?void 0:z.plugins)??[]).filter(ze=>ze.state==="ready").map(ze=>ze.title);x(null),O({}),P([]),l({}),c("hello"),U(ze=>ze+1),(async()=>{var Se;const[ze,Nt,q]=await Promise.all([Promise.resolve().then(()=>R.providerAccounts()).catch(()=>{}),Promise.resolve().then(()=>R.telegram()).catch(()=>{}),Promise.resolve().then(()=>R.browser()).catch(()=>{})]),he=KP(ze),Sn=$e&&he.some(Me=>Me.id===$e.accountId)?$e:void 0;ze&&d(ze),O(Sn?{brain:Sn}:{});const on=[...new Set(he.map(Me=>Me.label)),...Nt!=null&&Nt.paired?[_.startOver.telegram]:[],...((Se=q==null?void 0:q.browser)==null?void 0:Se.engine)==="chromium"?[_.startOver.browser]:[],...Qe];P(on.length>0?[_.startOver.said(on.join(", "))]:[])})()},Ne=()=>{w(!0),R.skipOnboarding().then(()=>e(kn)).catch($e=>x($e instanceof xe?$e.message:String($e))).finally(()=>w(!1))},we=me(()=>R.version().catch(()=>({current:""})),[]),fe=h.useRef(null);h.useEffect(()=>{fe.current&&(fe.current.scrollTop=0)},[o]);const ge=D==="running",Pe=Object.keys(i).length===0,je={answers:i,accounts:u,claudeModel:f,zones:p,browserZone:ee,assistantAgent:v,met:k,onMet:N,existing:S,progress:z,onProgress:K,navigate:e,onSettled:$e=>o&&Oe(o,$e),onKept:$e=>o&&Je(o,$e),onBack:se,onTrouble:x,onReload:()=>void pe(!1),onPickAnotherBrain:()=>W("brain"),onSpoken:F},de=(i.takeOn??[]).map($e=>{var Qe;return((Qe=hc.find(ze=>ze.id===$e))==null?void 0:Qe.title)??$e}),ke=(z==null?void 0:z.plugins)??[],Be=ke.filter($e=>$e.state==="ready").length,Ue=ke.length===0?null:z!=null&&z.running?_.takeOn.installing(Be,ke.length):Be===ke.length?_.takeOn.installed:null,ut=[(Bn=i.reach)!=null&&Bn.phone?_.reach.done.phone:null,(hs=i.reach)!=null&&hs.mailbox?_.reach.done.mailbox:null,(In=i.reach)!=null&&In.app||(fs=i.reach)!=null&&fs.browser?_.reach.done.app:null].filter($e=>$e!==null),dt={hello:{answer:_.hello.answer(i.name??""),sub:i.clock??null},brain:{answer:_.brain.answer(((Zt=i.brain)==null?void 0:Zt.label)??"")},takeOn:{answer:_.takeOn.answer(de),sub:Ue},reach:{answer:_.reach.answer(ut)},assistant:{answer:((ms=i.assistant)==null?void 0:ms.name)??""}},Q=af.filter($e=>$e!=="handover"),Ae=o===null||o==="handover"?Q.length:Q.indexOf(o),tt=Math.min(Ae,Q.length-1),Ct=I?null:t.jsxs("div",{className:"wiz-map-out",children:[t.jsx("button",{type:"button",className:"wiz-link",disabled:y,onClick:Ne,children:_.later}),o==="hello"&&Pe&&D==="idle"?t.jsx("button",{type:"button",className:"wiz-link",onClick:()=>$("form"),children:_.restore.offer}):!ge&&o!==null&&!(o==="hello"&&Pe)?t.jsx("button",{type:"button",className:"wiz-link",disabled:y,onClick:Y,children:_.startOver.link}):null]}),yt=r===void 0||r==="darwin"?_.tagline:_.taglineElsewhere,kt=o&&o!=="handover"?t.jsx("span",{className:"wiz-count",children:_.count(Ae+1)}):t.jsx("span",{className:"wiz-count"});return t.jsx(Yw.Provider,{value:E,children:t.jsx(Dee,{children:t.jsxs(O$,{className:"wiz-ground",children:[t.jsx("div",{className:"wiz",ref:fe,"data-phone":s?"true":void 0,"data-testid":"meet",children:t.jsxs("div",{className:"wiz-frame",children:[s?t.jsxs("div",{className:"wiz-strip",children:[t.jsx(Qc,{size:"sm"}),t.jsx("span",{className:"wiz-dots","aria-label":o&&o!=="handover"?_.count(Ae+1):void 0,children:Q.map($e=>t.jsx("i",{"data-state":NS(i,o,$e)},$e))}),t.jsx("span",{className:"wiz-strip-name",children:o&&o!=="handover"?_.strip(Ae+1,_.chapters[Ae]??""):_.handover.starterLabel})]}):t.jsxs("nav",{className:"wiz-map","aria-label":"Chapters",children:[t.jsxs("div",{className:"wiz-head",children:[t.jsx(Qc,{size:"lg"}),t.jsxs("div",{children:[t.jsx("div",{className:"wiz-head-name",children:"buddi"}),t.jsx("div",{className:"wiz-head-line",children:yt}),(Tt=we.data)!=null&&Tt.current?t.jsxs("div",{className:"wiz-head-version mono",children:["buddi ",we.data.current]}):null]})]}),Q.map(($e,Qe)=>{const ze=ge?$e==="hello"?"now":"todo":NS(i,o,$e),Nt=dt[$e];return t.jsxs("div",{className:"wiz-ch","data-state":ze,"aria-current":ze==="now"?"step":void 0,children:[t.jsx("span",{className:"wiz-num","data-state":ze,children:ze==="done"?t.jsx(le,{name:"check",size:12}):Qe+1}),t.jsxs("span",{className:"wiz-ch-label",children:[ze==="done"?Nt.answer:_.chapters[Qe],ze==="done"&&Nt.sub?t.jsx("span",{className:"wiz-ch-sub",children:Nt.sub}):null]}),ze==="done"&&!ge?t.jsx("button",{type:"button",className:"wiz-link",onClick:()=>W($e),children:_.change}):null]},$e)}),t.jsx("div",{className:"wiz-map-spacer"}),t.jsx("div",{className:"wiz-map-note",children:_.mapNotes[tt]}),Ct]}),t.jsx("div",{className:"wiz-stage",role:"main",children:t.jsxs("div",{className:"wiz-column","data-width":o==="hello"?"narrow":o==="brain"?"mid":"wide",children:[t.jsxs($6,{dock:t.jsxs(t.Fragment,{children:[kt,t.jsx("div",{className:"wiz-dock-actions",ref:T})]}),children:[ge?t.jsx(hte,{onDone:$e=>{$("idle"),P([...$e?[_.restore.welcome($e)]:[],_.restore.keys]),pe(!0,!0)},onFailed:$e=>{$("idle"),x($e)}}):o==="hello"?t.jsx(Lee,{...je}):o==="brain"?t.jsx(_ee,{...je}):o==="takeOn"?t.jsx(nte,{...je}):o==="reach"?t.jsx(ste,{...je}):o==="assistant"?t.jsx(ote,{...je}):o==="handover"?t.jsx(cte,{...je}):t.jsx(pr,{}),M.length>0||j?t.jsxs(rt,{children:[M.map($e=>t.jsx(ft,{children:$e},$e)),j?t.jsx(ft,{children:j}):null]}):null]},`${H}-${o??""}-${ge?"r":""}`),s?t.jsx("div",{className:"wiz-phone-out",children:Ct}):null]})})]})}),D==="form"?t.jsx(dte,{onCancel:()=>$("idle"),onStarted:()=>$("running"),onTrouble:x}):null]})})})}function $o({children:e}){return t.jsx("h1",{className:"wiz-title",children:e})}function SS(e){try{return Xt(new Date,e)}catch{return""}}function Lee({answers:e,zones:n,browserZone:s,onSettled:r,onTrouble:a}){const i=Eo(),[l,o]=h.useState(e.name??""),[c,u]=h.useState(e.clock??s),[d,f]=h.useState(!1),[m,p]=h.useState(!1),g=()=>{const v=l.trim();v===""||m||(p(!0),R.setOwner({preferredName:v,timezone:c}).then(()=>r({...e,name:v,clock:c})).catch(b=>a(b instanceof xe?b.message:String(b))).finally(()=>p(!1)))};return t.jsxs(t.Fragment,{children:[t.jsx($o,{children:_.hello.title}),t.jsx(rt,{children:_.hello.opening.map(v=>t.jsx(ft,{children:v},v))}),t.jsxs(mn,{actions:t.jsx(Ao,{onClick:g,disabled:m||l.trim()==="",children:_.hello.submit}),children:[t.jsxs("div",{className:"wiz-pair",children:[t.jsx(re,{label:_.name.label,children:t.jsx("input",{ref:i,placeholder:_.name.placeholder,maxLength:80,value:l,onChange:v=>o(v.target.value),onKeyDown:v=>{v.key==="Enter"&&(v.preventDefault(),g())}})}),d?t.jsx(re,{label:_.clock.label,hint:_.clock.hint(SS(c)),children:t.jsx("select",{value:c,onChange:v=>u(v.target.value),children:(n.includes(c)?n:[c,...n]).map(v=>t.jsx("option",{value:v,children:v},v))})}):t.jsx(re,{label:_.clock.label,hint:_.clock.hint(SS(c)),action:t.jsx(A,{size:"lg",onClick:()=>f(!0),children:_.clock.change}),children:t.jsx("input",{value:c,readOnly:!0})})]}),t.jsx("div",{className:"wiz-foot",children:_.hello.foot})]})]})}const Fee={free:{icon:"cloud",tone:"good"},claude:{icon:"bulb",tone:"mail"},chatgpt:{icon:"chat",tone:"coding"},key:{icon:"key",tone:"accent"},local:{icon:"monitor",tone:"plain",wide:!0}};function _ee(e){const{accounts:n,answers:s,onSettled:r,onKept:a,onReload:i,onBack:l}=e,[o,c]=h.useState(null),[u,d]=h.useState("key"),[f,m]=h.useState(null),[p,g]=h.useState(!1),[v,b]=h.useState(null),[j,x]=h.useState(null),[y,w]=h.useState(null),k=(n==null?void 0:n.anthropicOAuthEnabled)===!0,N=(n==null?void 0:n.codexEnabled)===!0,S=n==null?void 0:n.gemini,[C,E]=h.useState(null);h.useEffect(()=>{let H=!1;const U=()=>{Promise.resolve().then(()=>R.ollama()).then(z=>{!H&&z&&b(z)}).catch(()=>{}),Promise.resolve().then(()=>R.mlxh()).then(z=>{!H&&z&&x(z)}).catch(()=>{H||x({running:!1,baseUrl:"",manager:!1,models:[]})})};U();const V=window.setInterval(U,4e3);return()=>{H=!0,window.clearInterval(V)}},[]);const T=async H=>{if(s.assistant??e.existing)try{await R.bindBrain({accountId:H.accountId,model:H.model})}catch(U){return U instanceof xe?U.message:String(U)}return i(),a({...s,brain:H}),C==null||C.close(),E(null),c(null),w(null),null},I=async(H,U,V)=>{g(!0),m(null);try{const z=await R.saveProviderAccount(H);let X=await R.testProviderAccount(z.id),K=H.defaultModel,ee=!1;if(X.state!=="connected"&&V&&V!==K&&OI(X)){const pe=(await R.providerAccounts()).accounts.find(oe=>oe.id===z.id);pe&&(await R.saveProviderAccount({id:pe.id,revision:pe.revision,label:pe.label,kind:pe.kind,auth:pe.auth,baseUrl:pe.baseUrl,defaultModel:V,enabled:pe.enabled}),X=await R.testProviderAccount(z.id),X.state==="connected"&&(K=V,ee=!0))}if(X.state!=="connected"){try{const pe=(await R.providerAccounts()).accounts.find(oe=>oe.id===z.id);pe&&await R.removeProviderAccount(z.id,pe.revision)}catch{}return m(X.message),X}const ce=await T({accountId:z.id,label:U,model:K,...ee?{freeTier:ee}:{}});return ce&&m(ce),X}catch(z){return m(z instanceof xe?z.message:String(z)),null}finally{g(!1)}},F=async H=>{g(!0),m(null);try{const U=await R.saveProviderAccount(H);let V;try{V=await R.testProviderAccount(U.id)}finally{try{const z=(await R.providerAccounts()).accounts.find(X=>X.id===U.id);z&&await R.removeProviderAccount(U.id,z.revision)}catch{}}return V.state!=="connected"&&m(V.message),V}catch(U){return m(U instanceof xe?U.message:String(U)),null}finally{g(!1)}},D=(H,U,V)=>{if(H.length<=1){I(U(H[0]??""),V);return}w({models:H,make:U,label:V})},$=H=>{if(H===o)return;C==null||C.close(),E((H==="free"||H==="chatgpt")&&typeof window.open=="function"?window.open("","_blank"):null),m(null),w(null),d("key"),c(H)},L=()=>{C==null||C.close(),E(null),w(null),m(null),c(null)},O=QP(v,j),M=["free",...k?["claude"]:[],...N?["chatgpt"]:[],"key","local"];let P=null;return y?P=t.jsxs(t.Fragment,{children:[t.jsx(rt,{children:t.jsx(ft,{children:_.brain.model.ask})}),p?t.jsx(pr,{line:_.brain.checking.service}):f?t.jsx(rt,{children:t.jsx(ft,{children:f})}):null,t.jsx(zee,{busy:p,models:y.models,onBack:L,onUse:H=>void I(y.make(H),y.label)})]}):o==="key"?P=t.jsxs(t.Fragment,{children:[t.jsx(ln,{label:_.brain.keyKinds.label,value:u,onChange:H=>{m(null),d(H)},options:[{value:"key",label:_.brain.keyKinds.key},...S?[{value:"gemini",label:_.brain.keyKinds.gemini}]:[],{value:"service",label:_.brain.keyKinds.service}]}),u==="gemini"&&S?t.jsx(Bee,{busy:p,problem:f,preset:S,onBack:L,onUse:I},"gemini"):u==="service"?t.jsx(Kee,{busy:p,problem:f,address:(v==null?void 0:v.cloudBaseUrl)??"",onBack:L,onOffer:D,onTrial:F,onUse:I},"service"):t.jsx(Uee,{busy:p,problem:f,onBack:L,onUse:I},"key")]}):o==="local"?P=t.jsx(Hee,{busy:p,problem:f,probe:v,mlxh:j,onBack:L,onOffer:D,onUse:I,onCloud:()=>$("free")}):o==="free"?P=t.jsx(Gee,{...e,busy:p,consent:C,onBack:L,onConnected:T}):o==="chatgpt"?P=t.jsx(Jee,{...e,busy:p,consent:C,onBack:L,onConnected:T}):o==="claude"&&(P=t.jsx(Xee,{...e,busy:p,problem:f,onBack:L,onConnected:T})),t.jsxs(t.Fragment,{children:[t.jsx($o,{children:_.brain.title}),t.jsx(rt,{children:t.jsx(ft,{children:_.brain.ask})}),t.jsx("div",{className:"wiz-grid",role:"group","aria-label":_.brain.ask,children:M.map(H=>{const U=Fee[H],V=_.brain.cards[H];return t.jsxs("button",{type:"button",className:"wiz-opt","aria-pressed":o===H,"data-wide":U.wide?"true":void 0,onClick:()=>$(H),children:[t.jsx("span",{className:"wiz-glyph","data-tone":U.tone,"aria-hidden":"true",children:t.jsx(le,{name:U.icon})}),t.jsxs("span",{children:[t.jsx("span",{className:"wiz-opt-title",children:V.title}),t.jsx("span",{className:"wiz-opt-line",children:H==="local"?O:V.line}),"pill"in V?t.jsx(Ee,{tone:"good",children:V.pill}):null]})]},H)})}),P,P===null&&s.brain?t.jsxs(rt,{children:[t.jsx(ft,{children:s.brain.freeTier?_.brain.worksOnFlash(s.brain.model):_.brain.works(s.brain.model)}),t.jsx(qee,{...e}),s.brain.label===_.brain.ollama.label||s.brain.label===_.brain.mlxh.label?t.jsx(G,{tone:"warm",title:_.brain.ollama.honestTitle,children:_.brain.ollama.honest}):null]}):null,P===null?t.jsx(mn,{actions:t.jsxs(t.Fragment,{children:[t.jsx(Ss,{onClick:l}),t.jsx(Ao,{onClick:()=>s.brain&&r(s),disabled:!s.brain,children:_.brain.submit})]})}):null]})}function zee({busy:e,models:n,onBack:s,onUse:r}){const[a,i]=h.useState(n[0]??"");return t.jsx(mn,{actions:t.jsxs(t.Fragment,{children:[t.jsx(Ss,{onClick:s,disabled:e}),t.jsx(A,{variant:"accent",size:"lg",disabled:e||a==="",onClick:()=>r(a),children:_.brain.model.submit})]}),children:t.jsx(re,{label:_.brain.model.label,grow:!0,children:t.jsx("select",{value:a,onChange:l=>i(l.target.value),children:n.map(l=>t.jsx("option",{value:l,children:l},l))})})})}function JP({models:e,picked:n,disabled:s,onPick:r}){return t.jsx(re,{label:_.brain.model.label,grow:!0,children:t.jsx("select",{value:n,disabled:s,onChange:a=>r(a.target.value),children:e.map(a=>t.jsx("option",{value:a,children:a},a))})})}function Uee({busy:e,problem:n,onBack:s,onUse:r}){const a=Eo(),[i,l]=h.useState(""),[o,c]=h.useState(null),[u,d]=h.useState(!1),[f,m]=h.useState([]),[p,g]=h.useState(""),[v,b]=h.useState(!1),j=e||u,x=!v&&n!==null&&f.length>0,y=o??$ee(i),w=()=>{const k=i.trim();k===""||j||(d(!0),b(!1),(async()=>{var E;let N=y==="anthropic"?"claude-sonnet-5":"gpt-5",S=f;if(x&&p!=="")N=p;else try{const T=await R.probeModels({kind:y,auth:"api-key",secret:k});N=((E=T.models.find(I=>I.isDefault))==null?void 0:E.id)??N,S=T.models.map(I=>I.id)}catch{S=[]}d(!1);const C=await r({label:y==="anthropic"?_.brain.key.anthropic:_.brain.key.openai,kind:y,auth:"api-key",baseUrl:"",defaultModel:N,enabled:!0,secret:k},y==="anthropic"?_.brain.key.anthropic:_.brain.key.openai);if(!(!C||C.state==="connected")){if(ny(C)){b(!0),m([]);return}m(S.includes(N)||S.length===0?S:[N,...S]),g(N)}})())};return t.jsxs(t.Fragment,{children:[j?t.jsx(rt,{children:t.jsx(pr,{line:_.brain.checking.key})}):v?t.jsx(rt,{children:t.jsx(ft,{children:_.brain.key.refused})}):n?t.jsx(rt,{children:t.jsx(ft,{children:n})}):null,t.jsxs(mn,{actions:t.jsxs(t.Fragment,{children:[t.jsx(Ss,{onClick:s,disabled:j}),t.jsx(A,{variant:"accent",size:"lg",disabled:j||i.trim()==="",onClick:w,children:x?_.brain.model.retry:_.brain.key.submit})]}),children:[t.jsx(re,{label:_.brain.key.field,grow:!0,children:t.jsx("input",{ref:a,type:"password",autoComplete:"off",spellCheck:!1,placeholder:_.brain.key.placeholder,value:i,onChange:k=>{l(k.target.value),m([])},onKeyDown:k=>{k.key==="Enter"&&(k.preventDefault(),w())}})}),x?t.jsx(JP,{models:f,picked:p,disabled:j,onPick:g}):null,t.jsxs("button",{type:"button",className:"wiz-link",onClick:()=>c(y==="anthropic"?"openai":"anthropic"),children:[y==="anthropic"?_.brain.key.anthropic:_.brain.key.openai," · ",_.brain.key.which]})]})]})}function Bee({busy:e,problem:n,preset:s,onBack:r,onUse:a}){const i=Eo(),[l,o]=h.useState(""),[c,u]=h.useState(!1),[d,f]=h.useState([]),[m,p]=h.useState(""),g=e||c,v=n!==null&&d.length>0,b=()=>{const j=l.trim();j===""||g||(u(!0),(async()=>{let x=II,y;if(v&&m!=="")x=m;else try{const k=(await R.probeModels({kind:"openai-compatible",auth:"api-key",baseUrl:s.baseUrl,secret:j})).models.map(N=>N.id);x=PI(k)??x,y=DI(x)?MI(k):void 0,f(AJ(k)),p(y??x)}catch{}u(!1),await a({label:_.brain.gemini.label,kind:"openai-compatible",auth:"api-key",baseUrl:s.baseUrl,defaultModel:x,enabled:!0,secret:j},_.brain.gemini.label,y)})())};return t.jsxs(t.Fragment,{children:[g?t.jsx(rt,{children:t.jsx(pr,{line:_.brain.checking.gemini})}):n?t.jsx(rt,{children:t.jsx(ft,{children:n})}):null,t.jsxs(mn,{actions:t.jsxs(t.Fragment,{children:[t.jsx(Ss,{onClick:r,disabled:g}),t.jsx(A,{variant:"accent",size:"lg",disabled:g||l.trim()==="",onClick:b,children:_.brain.gemini.submit})]}),children:[t.jsx(re,{label:_.brain.gemini.field,grow:!0,children:t.jsx("input",{ref:i,type:"password",autoComplete:"off",spellCheck:!1,placeholder:_.brain.gemini.placeholder,value:l,onChange:j=>o(j.target.value),onKeyDown:j=>{j.key==="Enter"&&(j.preventDefault(),b())}})}),v?t.jsx(re,{label:_.brain.model.label,grow:!0,children:t.jsx("select",{value:m,disabled:g,onChange:j=>p(j.target.value),children:d.map(j=>t.jsx("option",{value:j,children:j},j))})}):null,t.jsx("a",{className:"wiz-link",href:s.keyUrl,target:"_blank",rel:"noreferrer",children:_.brain.gemini.get})]})]})}function QP(e,n){return e===null||n===null?_.brain.local.looking:!e.running&&!n.running?_.brain.local.missing:_.brain.local.found({...e.running?{ollama:e.models.length}:{},...n.running?{mlxh:n.models.length}:{}})}const Wee=1e3;function CS({command:e}){const[n,s]=h.useState(!1);return h.useEffect(()=>{if(!n)return;const r=window.setTimeout(()=>s(!1),1600);return()=>window.clearTimeout(r)},[n]),t.jsxs("div",{className:"rs-cmd",children:[t.jsx("code",{className:"rs-cmd-text",children:e}),t.jsx(A,{size:"sm",onClick:()=>{var r;return void((r=navigator.clipboard)==null?void 0:r.writeText(e).then(()=>s(!0),()=>{}))},children:n?_.brain.ollama.copied:_.brain.ollama.copy})]})}const ES=e=>(e/1e9).toFixed(1);function Hee({busy:e,problem:n,probe:s,mlxh:r,onBack:a,onOffer:i,onUse:l,onCloud:o}){const c=(s==null?void 0:s.models)??[],u=wv(r),d=s==null?void 0:s.machine,[f,m]=h.useState(null),[p,g]=h.useState(null),v=h.useRef(null),b=f??(s==null?void 0:s.pull)??null,j=(b==null?void 0:b.state)==="pulling",x=D=>({label:_.brain.ollama.label,kind:"openai-compatible",auth:"none",baseUrl:(s==null?void 0:s.baseUrl)??"",defaultModel:D,enabled:!0});h.useEffect(()=>{if(!j)return;let D=!1;const $=window.setInterval(()=>{R.ollamaPullState().then(L=>{!D&&L.pull&&m(L.pull)},()=>{})},Wee);return()=>{D=!0,window.clearInterval($)}},[j]),h.useEffect(()=>{(f==null?void 0:f.state)!=="done"||!s||v.current===f.model||(v.current=f.model,l(x(f.model),_.brain.ollama.label))},[f==null?void 0:f.state,f==null?void 0:f.model,s]);const y=D=>{g(null),v.current=null,R.ollamaPull(D).then($=>m($.pull),$=>g($ instanceof xe?$.message:String($)))},w=()=>{!(r!=null&&r.running)||!u||l({label:_.brain.mlxh.label,kind:"openai-compatible",auth:"none",baseUrl:r.baseUrl,defaultModel:u,enabled:!0},_.brain.mlxh.label)},k=s!==null&&r!==null&&!s.running&&!r.running,N=()=>{s&&i(c,x,_.brain.ollama.label)},S=(d==null?void 0:d.platform)==="darwin"?"this Mac":"this computer",C=(s==null?void 0:s.running)===!0&&c.length===0,E=d!==void 0&&!(r!=null&&r.running)&&(C||k||j),T=d!=null&&d.cloudSuggested?d.memoryGb<7?"memory":"gpu":null,I=d?t.jsxs("div",{className:"wiz-foot",children:[_.brain.ollama.cloud(T,d.memoryGb)," ",t.jsx("button",{type:"button",className:"wiz-link",onClick:o,children:_.brain.ollama.useCloud})]}):null;let F=null;if(E&&d){const D=(b==null?void 0:b.state)==="failed"?b:null;if(j&&b){const $=b.total>0?b.completed/b.total:0;F=t.jsxs("div",{className:"wiz-stack",children:[t.jsxs("div",{className:"wiz-busy","data-boxed":"true",children:[t.jsxs("span",{className:"wiz-pulse","aria-hidden":"true",children:[t.jsx("i",{}),t.jsx("i",{}),t.jsx("i",{})]}),t.jsx("span",{children:_.brain.ollama.fetching(b.model,ES(b.completed),b.total>0?ES(b.total):"")}),t.jsxs("span",{className:"wiz-busy-side",children:[Math.round($*100),"%"]})]}),t.jsx(Py,{value:$*100,label:_.brain.ollama.fetch(b.model)}),t.jsx("div",{className:"wiz-foot",children:_.brain.ollama.fetchingFoot})]})}else if(C){const $=(D==null?void 0:D.model)??d.recommended.model;F=t.jsxs("div",{className:"wiz-stack",children:[t.jsx(rt,{children:t.jsx(ft,{children:D?_.brain.ollama.failed(D.error??""):_.brain.ollama.empty(S,d.memoryGb,d.recommended.model,d.recommended.sizeGb)})}),p?t.jsx(G,{tone:"critical",children:p}):null,t.jsxs(te,{children:[t.jsx("span",{className:"wiz-foot",children:_.brain.ollama.emptyFoot(S)}),t.jsx(et,{}),t.jsx(A,{variant:"accent",size:"lg",disabled:e,onClick:()=>y($),children:D?_.brain.ollama.again:_.brain.ollama.fetch($)})]}),I]})}else d.installed?F=t.jsxs("div",{className:"wiz-stack",children:[t.jsx(rt,{children:t.jsx(ft,{children:_.brain.ollama.stopped(d.platform)})}),d.platform==="linux"?t.jsx(CS,{command:"ollama serve"}):null,I]}):F=t.jsxs("div",{className:"wiz-stack",children:[t.jsx(rt,{children:t.jsx(ft,{children:_.brain.ollama.missing(S)})}),d.install.command?t.jsx(CS,{command:d.install.command}):null,t.jsxs(te,{children:[t.jsx("span",{className:"wiz-foot",children:_.brain.ollama.missingHow(d.platform,S)}),t.jsx(et,{}),d.platform==="linux"?null:t.jsx(ht,{size:"lg",href:d.install.url,target:"_blank",rel:"noreferrer",children:_.brain.ollama.download})]}),I]})}return t.jsxs(t.Fragment,{children:[e?t.jsx(rt,{children:t.jsx(pr,{line:_.brain.checking.ollama})}):n?t.jsx(rt,{children:t.jsx(ft,{children:n})}):null,F,t.jsx(mn,{actions:t.jsxs(t.Fragment,{children:[t.jsx(Ss,{onClick:a,disabled:e}),s!=null&&s.running&&c.length>0?t.jsx(A,{variant:r!=null&&r.running?void 0:"accent",size:"lg",disabled:e,onClick:N,children:_.brain.ollama.connect}):null,r!=null&&r.running?t.jsx(A,{variant:"accent",size:"lg",disabled:e||!u,onClick:w,children:_.brain.mlxh.connect}):null,k&&s&&!d?t.jsx(ht,{variant:"accent",size:"lg",href:s.downloadUrl,target:"_blank",rel:"noreferrer",children:_.brain.ollama.download}):null]}),children:E?null:t.jsxs("span",{className:"wiz-foot",children:[QP(s,r),r!=null&&r.running&&!u?` ${_.brain.mlxh.noBrain}`:"",k&&(r!=null&&r.baseUrl)?` ${oI(r.baseUrl)}`:""]})})]})}function Kee({busy:e,problem:n,address:s,onBack:r,onOffer:a,onTrial:i,onUse:l}){const o=Eo(),[c,u]=h.useState(s),[d,f]=h.useState(""),[m,p]=h.useState(!1),[g,v]=h.useState([]),[b,j]=h.useState(""),[x,y]=h.useState(!1),w=e||m,k=!x&&n!==null&&g.length>0,N=()=>{c.trim()===""||w||(p(!0),y(!1),(async()=>{var L;const S=d.trim()?"api-key":"none",C=O=>({label:_.brain.service.label,kind:"openai-compatible",auth:S,baseUrl:c.trim(),defaultModel:O,enabled:!0,...d.trim()?{secret:d.trim()}:{}}),E=(O,M,P)=>{if(!(!O||O.state==="connected")){if(ny(O)){y(!0),v([]);return}v(M),j(P)}};if(S==="api-key"&&k&&b!==""){p(!1),E(await l(C(b),_.brain.service.label),g,b);return}let T=[],I;try{const O=await R.probeModels({kind:"openai-compatible",auth:S,baseUrl:c.trim(),...d.trim()?{secret:d.trim()}:{}});T=O.models.map(M=>M.id),I=(L=O.models.find(M=>M.isDefault))==null?void 0:L.id}catch{}p(!1);const F=I?[I]:T;if(S==="none"){a(F,C,_.brain.service.label);return}const D=F[0]??"";if(F.length<=1){E(await l(C(D),_.brain.service.label),T,D);return}const $=await i(C(D));($==null?void 0:$.state)==="connected"?a(F,C,_.brain.service.label):E($,T,D)})())};return t.jsxs(t.Fragment,{children:[w?t.jsx(rt,{children:t.jsx(pr,{line:_.brain.checking.service})}):x?t.jsx(rt,{children:t.jsx(ft,{children:_.brain.key.refused})}):n?t.jsx(rt,{children:t.jsx(ft,{children:n})}):null,t.jsxs(mn,{actions:t.jsxs(t.Fragment,{children:[t.jsx(Ss,{onClick:r,disabled:w}),t.jsx(A,{variant:"accent",size:"lg",disabled:w||c.trim()==="",onClick:N,children:k?_.brain.model.retry:_.brain.service.submit})]}),children:[t.jsx(re,{label:_.brain.service.address,grow:!0,children:t.jsx("input",{ref:o,value:c,placeholder:_.brain.service.addressPlaceholder,onChange:S=>{u(S.target.value),v([])}})}),t.jsx(re,{label:_.brain.service.key,children:t.jsx("input",{type:"password",autoComplete:"off",spellCheck:!1,value:d,onChange:S=>{f(S.target.value),v([])}})}),k?t.jsx(JP,{models:g,picked:b,disabled:w,onPick:j}):null]})]})}const Vee=2e3;function Gee({busy:e,consent:n,onBack:s,onConnected:r,accounts:a}){const[i,l]=h.useState(!0),[o,c]=h.useState(null),[u,d]=h.useState(null),[f,m]=h.useState(0),p=h.useRef(-1),g=h.useRef(null),v=_.brain.cloud.label;h.useEffect(()=>{if(p.current===f)return;p.current=f,l(!0),c(null);const j=f===0?n:g.current;(async()=>{try{const x=((a==null?void 0:a.accounts)??[]).find(N=>N.auth==="device-key"),y=x?{id:x.id}:await R.saveProviderAccount({label:v,kind:"openai-compatible",auth:"device-key",baseUrl:"",defaultModel:_d,enabled:!0}),w=(await R.providerAccounts()).accounts.find(N=>N.id===y.id),k=await R.ollamaConnect(w.id,w.revision);d({id:w.id,attemptId:k.attemptId,url:k.verificationUrl}),j&&(j.location.href=k.verificationUrl)}catch(x){j==null||j.close(),c(x instanceof xe?x.message:String(x))}finally{l(!1)}})()},[f]),h.useEffect(()=>{if(!u)return;let j=!1,x=!1;const y=async()=>{if(!(j||x)){x=!0;try{const k=await R.ollamaPoll(u.id,u.attemptId);if(j||k.state==="waiting")return;if(j=!0,d(null),k.state==="failed"){c(k.message);return}l(!0),c(await b(u.id)),l(!1)}catch{}finally{x=!1}}},w=window.setInterval(()=>void y(),Vee);return()=>{j=!0,window.clearInterval(w)}},[u]);const b=async j=>{try{const x=(await R.accountModels(j).catch(()=>({models:[]}))).models.map(N=>N.id),y=x.length===0||x.includes(_d)?_d:x[0],w=(await R.providerAccounts()).accounts.find(N=>N.id===j);w&&w.defaultModel!==y&&await R.saveProviderAccount({id:w.id,revision:w.revision,label:w.label,kind:w.kind,auth:w.auth,baseUrl:w.baseUrl,defaultModel:y,enabled:w.enabled});const k=await R.testProviderAccount(j);return k.state!=="connected"?k.message:await r({accountId:j,label:v,model:y})}catch(x){return x instanceof xe?x.message:String(x)}};return t.jsxs(t.Fragment,{children:[i||e?t.jsx(rt,{children:t.jsx(pr,{line:_.brain.checking.cloud})}):o?t.jsx(rt,{children:t.jsx(ft,{children:o})}):u?t.jsx(rt,{children:t.jsx(ft,{children:_.brain.cloud.waiting})}):null,t.jsx(mn,{actions:t.jsxs(t.Fragment,{children:[t.jsx(Ss,{onClick:s,disabled:i||e}),u?t.jsx(ht,{variant:"accent",size:"lg",href:u.url,target:"_blank",rel:"noreferrer",children:_.brain.cloud.open}):o?t.jsx(A,{variant:"accent",size:"lg",disabled:i||e,onClick:()=>{g.current=typeof window.open=="function"?window.open("","_blank"):null,m(j=>j+1)},children:_.brain.cloud.again}):null]})})]})}function qee({answers:e,accounts:n,onKept:s,onTrouble:r}){var p;const a=e.brain,i=a?((n==null?void 0:n.accounts)??[]).find(g=>g.id===a.accountId):void 0,[l,o]=h.useState([]),[c,u]=h.useState(!1),d=bw(i),f=(i==null?void 0:i.auth)==="device-key"||(i==null?void 0:i.kind)==="codex"||d||!!i&&LI(i,(p=n==null?void 0:n.gemini)==null?void 0:p.baseUrl);if(h.useEffect(()=>{if(!f||!i)return;let g=!1;return R.accountModels(i.id).then(v=>{const b=d?v.models.filter(j=>!lI({id:j.id,...j.image?{kind:"image"}:{}})):v.models;g||o(b.map(j=>j.id))}).catch(()=>{}),()=>{g=!0}},[f,i==null?void 0:i.id]),!f||!i||!a||l.length<2)return null;const m=g=>{g===a.model||c||(u(!0),r(null),(async()=>{try{await R.saveProviderAccount({id:i.id,revision:i.revision,label:i.label,kind:i.kind,auth:i.auth,baseUrl:i.baseUrl,defaultModel:g,enabled:i.enabled}),e.assistant&&await R.bindBrain({accountId:i.id,model:g}),s({...e,brain:{accountId:a.accountId,label:a.label,model:g}})}catch(v){r(v instanceof xe?v.message:String(v))}finally{u(!1)}})())};return t.jsx(ft,{children:t.jsx(re,{label:_.brain.model.change,children:t.jsx("select",{value:a.model,disabled:c,onChange:g=>m(g.target.value),children:(l.includes(a.model)?l:[a.model,...l]).map(g=>t.jsx("option",{value:g,children:g},g))})})})}const AS="gpt-5.5",Yee=2e3;function Jee({busy:e,consent:n,onBack:s,onConnected:r,accounts:a}){const[i,l]=h.useState(!0),[o,c]=h.useState(null),[u,d]=h.useState(null),[f,m]=h.useState(0),p=h.useRef(-1),g=h.useRef(null),v=h.useRef(null),b=_.brain.chatgpt.label;h.useEffect(()=>()=>{const y=v.current;v.current=null,y&&R.codexAccountAction(y.id,"cancel-login",y.revision).catch(()=>{})},[]),h.useEffect(()=>{if(p.current===f)return;p.current=f,l(!0),c(null);const y=f===0?n:g.current;(async()=>{try{const w=((a==null?void 0:a.accounts)??[]).find(C=>C.kind==="codex"),k=w?{id:w.id}:await R.saveProviderAccount({label:b,kind:"codex",auth:"chatgpt",baseUrl:"",defaultModel:AS,enabled:!0}),N=(await R.providerAccounts()).accounts.find(C=>C.id===k.id),S=await R.codexAccountAction(N.id,"login",N.revision);if(!(S!=null&&S.verificationUrl)||!S.userCode)throw new Error((S==null?void 0:S.message)??_.brain.chatgpt.failed);v.current={id:N.id,revision:N.revision},d({id:N.id,revision:N.revision,url:S.verificationUrl,code:S.userCode}),y&&(y.location.href=S.verificationUrl)}catch(w){y==null||y.close(),c(w instanceof xe||w instanceof Error?w.message:String(w))}finally{l(!1)}})()},[f]),h.useEffect(()=>{if(!u)return;let y=!1,w=!1;const k=async()=>{if(!(y||w)){w=!0;try{const S=(await R.providerAccounts()).accounts.find(E=>E.id===u.id);if(y)return;const C=S==null?void 0:S.login;if(!C||C.state==="pending")return;if(y=!0,v.current=null,d(null),C.state!=="connected"){c(C.message??_.brain.chatgpt.failed);return}l(!0),c(await j(u.id)),l(!1)}catch{}finally{w=!1}}},N=window.setInterval(()=>void k(),Yee);return()=>{y=!0,window.clearInterval(N)}},[u]);const j=async y=>{var w,k;try{const N=(await R.accountModels(y).catch(()=>({models:[]}))).models,S=((w=N.find(E=>E.isDefault))==null?void 0:w.id)??((k=N[0])==null?void 0:k.id)??AS,C=(await R.providerAccounts()).accounts.find(E=>E.id===y);return C&&C.defaultModel!==S&&await R.saveProviderAccount({id:C.id,revision:C.revision,label:C.label,kind:C.kind,auth:C.auth,baseUrl:C.baseUrl,defaultModel:S,enabled:C.enabled}),await r({accountId:y,label:b,model:S})}catch(N){return N instanceof xe?N.message:String(N)}},x=()=>{const y=v.current;v.current=null,y&&R.codexAccountAction(y.id,"cancel-login",y.revision).catch(()=>{}),s()};return t.jsxs(t.Fragment,{children:[i||e?t.jsx(rt,{children:t.jsx(pr,{line:_.brain.checking.chatgpt})}):o?t.jsx(rt,{children:t.jsx(ft,{children:o})}):u?t.jsx(rt,{children:t.jsxs(ft,{children:[_.brain.chatgpt.codeBefore,t.jsx("strong",{children:u.code}),_.brain.chatgpt.codeAfter]})}):null,t.jsx(mn,{actions:t.jsxs(t.Fragment,{children:[t.jsx(Ss,{onClick:x,disabled:i||e}),u?t.jsx(ht,{variant:"accent",size:"lg",href:u.url,target:"_blank",rel:"noreferrer",children:_.brain.chatgpt.open}):o?t.jsx(A,{variant:"accent",size:"lg",disabled:i||e,onClick:()=>{g.current=typeof window.open=="function"?window.open("","_blank"):null,m(y=>y+1)},children:_.brain.chatgpt.again}):null]}),children:u?t.jsx(Nw,{code:u.code,label:_.brain.chatgpt.code}):null})]})}const Qee="claude-sonnet-5";function Xee({busy:e,problem:n,onBack:s,onConnected:r,accounts:a,claudeModel:i}){const[l,o]=h.useState(!1),[c,u]=h.useState(null),[d,f]=h.useState(null),[m,p]=h.useState(""),g=h.useRef(null);h.useEffect(()=>()=>{const y=g.current;g.current=null,y&&R.anthropicAccountAction(y.id,"cancel-login",y.revision).catch(()=>{})},[]);const v=()=>{const y=g.current;g.current=null,y&&R.anthropicAccountAction(y.id,"cancel-login",y.revision).catch(()=>{}),s()},b=i??Qee,j=()=>{o(!0),u(null);const y=typeof window.open=="function"?window.open("","_blank"):null;(async()=>{try{const w=((a==null?void 0:a.accounts)??[]).find(E=>E.auth==="anthropic-oauth"),k=w?{id:w.id}:await R.saveProviderAccount({label:_.brain.claude.label,kind:"anthropic",auth:"anthropic-oauth",baseUrl:"",defaultModel:b,enabled:!0}),S=(await R.providerAccounts()).accounts.find(E=>E.id===k.id),C=await R.anthropicAccountAction(S.id,"login",S.revision);g.current={id:S.id,revision:S.revision+1},f({id:S.id,revision:S.revision+1,url:C.verificationUrl??"",attemptId:C.attemptId??""}),y&&C.verificationUrl?y.location.href=C.verificationUrl:y==null||y.close()}catch(w){y==null||y.close(),u(w instanceof xe?w.message:String(w))}finally{o(!1)}})()},x=()=>{!d||m.trim()===""||(g.current=null,o(!0),(async()=>{try{await R.anthropicAccountAction(d.id,"complete-login",d.revision,{attemptId:d.attemptId,code:m.trim()});const y=await R.testProviderAccount(d.id);if(y.state!=="connected"){u(y.message);return}u(await r({accountId:d.id,label:_.brain.claude.label,model:b}))}catch(y){u(y instanceof xe?y.message:String(y))}finally{o(!1)}})())};return t.jsxs(t.Fragment,{children:[l||e?t.jsx(rt,{children:t.jsx(pr,{line:_.brain.checking.claude})}):n??c?t.jsx(rt,{children:t.jsx(ft,{children:n??c})}):null,d?t.jsxs(t.Fragment,{children:[t.jsx(rt,{children:t.jsx(ft,{children:_.brain.claude.waiting})}),t.jsx(mn,{actions:t.jsxs(t.Fragment,{children:[t.jsx(Ss,{onClick:v,disabled:l}),t.jsx(ht,{size:"lg",href:d.url,target:"_blank",rel:"noreferrer",children:_.brain.claude.open}),t.jsx(A,{variant:"accent",size:"lg",disabled:l||m.trim()==="",onClick:x,children:_.brain.claude.finish})]}),children:t.jsx(re,{label:_.brain.claude.paste,grow:!0,children:t.jsx(Zee,{value:m,onChange:p})})})]}):t.jsx(mn,{actions:t.jsxs(t.Fragment,{children:[t.jsx(Ss,{onClick:v,disabled:e||l}),t.jsx(A,{variant:"accent",size:"lg",disabled:e||l,onClick:j,children:_.brain.claude.start})]})})]})}function Zee({value:e,onChange:n}){const s=Eo();return t.jsx("input",{ref:s,type:"password",autoComplete:"off",spellCheck:!1,value:e,onChange:r=>n(r.target.value)})}const ete={days:"calendar",mail:"mail",money:"money",voice:"bulb",code:"monitor",pictures:"files"};function tte(e){const n=(e==null?void 0:e.plugins)??[];if(n.length===0)return null;const s=n.map(a=>a.title),r=n.filter(a=>a.state==="failed");if(e!=null&&e.running){const a=n.filter(i=>i.state==="ready"||i.state==="failed").length;return{line:_.takeOn.fetching(s,Math.min(a+1,n.length),n.length),done:!1}}return r.length>0?{line:r.map(a=>_.takeOn.failed(a.title,a.reason??"")).join(" "),done:!0}:{line:_.takeOn.ready(s),done:!0}}function nte({answers:e,progress:n,onProgress:s,onSettled:r,onBack:a,onTrouble:i}){const[l,o]=h.useState(()=>e.takeOn??[...DU]),[c,u]=h.useState(!1),d=hc.filter(g=>l.includes(g.id)),f=g=>o(v=>v.includes(g)?v.filter(b=>b!==g):[...v,g]),m=g=>{c||(u(!0),Promise.resolve().then(()=>R.takeOn(g)).then(()=>{s(),r({...e,takeOn:g})}).catch(v=>i(v instanceof xe?v.message:String(v))).finally(()=>u(!1)))},p=tte(n);return t.jsxs(t.Fragment,{children:[t.jsx($o,{children:_.takeOn.title}),t.jsx(rt,{children:t.jsx(ft,{children:_.takeOn.ask})}),t.jsxs(mn,{actions:t.jsxs(t.Fragment,{children:[t.jsx(Ss,{onClick:a,disabled:c}),t.jsx(A,{variant:"ghost",size:"lg",disabled:c,onClick:()=>m([]),children:_.takeOn.none}),t.jsx(Ao,{onClick:()=>m(hc.filter(g=>l.includes(g.id)).map(g=>g.id)),disabled:c||l.length===0,children:_.takeOn.submit})]}),children:[t.jsx("div",{className:"wiz-grid","data-cols":"3",role:"group","aria-label":_.takeOn.title,children:hc.map(g=>{const v=l.includes(g.id);return t.jsxs("button",{type:"button",className:"wiz-opt","data-tile":"true","aria-pressed":v,onClick:()=>f(g.id),children:[t.jsxs("span",{className:"wiz-tile-top",children:[t.jsx("span",{className:"wiz-glyph","aria-hidden":"true",children:t.jsx(le,{name:ete[g.id]})}),t.jsx("span",{className:"wiz-tick","aria-hidden":"true",children:v?t.jsx(le,{name:"check",size:12}):null})]}),t.jsxs("span",{children:[t.jsx("span",{className:"wiz-opt-title",children:g.title}),t.jsx("span",{className:"wiz-opt-plugins",children:g.plugins})]}),t.jsx("span",{className:"wiz-opt-line",children:g.line})]},g.id)})}),d.length>0?t.jsxs("div",{className:"wiz-stack",children:[p?t.jsxs("div",{className:"wiz-busy","data-boxed":"true",role:"status",children:[t.jsxs("span",{className:"wiz-pulse","data-done":p.done?"true":void 0,"aria-hidden":"true",children:[t.jsx("i",{}),t.jsx("i",{}),t.jsx("i",{})]}),t.jsx("span",{children:p.line}),l.includes("mail")?t.jsx("span",{className:"wiz-busy-side",children:_.takeOn.builtIn}):null]}):null,t.jsx("div",{className:"wiz-foot",children:d.map(g=>g.note).join(" ")})]}):t.jsx("div",{className:"wiz-foot",children:_.takeOn.nothing})]})]})}function ste({answers:e,navigate:n,onSettled:s,onBack:r}){var g,v,b;const[a,i]=h.useState(((g=e.reach)==null?void 0:g.phone)===!0),[l,o]=h.useState(((v=e.reach)==null?void 0:v.mailbox)===!0),[c,u]=h.useState(((b=e.reach)==null?void 0:b.app)===!0),[d,f]=h.useState(e.browser),m=(e.takeOn??[]).includes("mail"),p=()=>{const j={phone:a,mailbox:l,app:c,browser:d==="chrome"||d==="chromium"||d==="installed"};d!==void 0&&Promise.resolve().then(()=>R.onboardingStep("browser")).catch(()=>{}),s({...e,reach:j,...d!==void 0?{browser:d}:{}})};return t.jsxs(t.Fragment,{children:[t.jsx($o,{children:_.reach.title}),t.jsx(rt,{children:t.jsx(ft,{children:_.reach.ask})}),t.jsx(mn,{actions:t.jsxs(t.Fragment,{children:[t.jsx(Ss,{onClick:r}),t.jsx(Ao,{onClick:p,children:_.reach.submit})]}),children:t.jsxs("div",{className:"wiz-rows",children:[t.jsx(rte,{paired:a,onPaired:()=>i(!0)}),t.jsx(ite,{wanted:m,added:l,onAdded:o,navigate:n,timezone:e.clock??"UTC"}),t.jsx(lte,{app:c,onApp:()=>u(!0),browser:d,onBrowser:f}),a?t.jsx(G,{tone:"good",role:"status",children:_.reach.phone.hello}):null]})})]})}function rte({paired:e,onPaired:n}){const[s,r]=h.useState(null),[a,i]=h.useState(!1),l=h.useRef(n);l.current=n,h.useEffect(()=>{let c=!1;return Promise.resolve().then(()=>R.telegram()).then(u=>{c||!u||(r(u),u.paired&&l.current())}).catch(()=>{c||r({configured:!1,running:!1,paired:!1})}),()=>{c=!0}},[]);const o=(s==null?void 0:s.configured)===!0&&s.running===!0&&!e;return t.jsxs("div",{className:"wiz-row",children:[t.jsx("span",{className:"wiz-glyph","aria-hidden":"true",children:t.jsx(le,{name:"chat"})}),t.jsxs("span",{className:"wiz-row-text",children:[t.jsx("span",{className:"wiz-opt-title",children:_.reach.phone.title}),t.jsx("span",{className:"wiz-opt-line",children:_.reach.phone.line})]}),e?t.jsx("span",{className:"wiz-row-side",children:t.jsx(Ee,{tone:"good",dot:!0,children:_.reach.phone.paired})}):o?t.jsx(ate,{onPaired:n}):t.jsx("span",{className:"wiz-row-side",children:t.jsx(A,{size:"lg",disabled:s===null,onClick:()=>i(!0),children:_.reach.phone.setUp})}),a?t.jsx(Ge,{title:_.telegram.sheet,onClose:()=>i(!1),children:t.jsx(fte,{onPaired:n,onDismiss:()=>i(!1)})}):null]})}function ate({onPaired:e}){const{offer:n,square:s,paired:r,stale:a,ask:i}=Vw(()=>R.telegram().then(o=>o.paired),e),l=h.useRef(!1);return h.useEffect(()=>{l.current||(l.current=!0,i().catch(()=>{}))},[i]),r?t.jsx("span",{className:"wiz-row-side",children:t.jsx(Ee,{tone:"good",dot:!0,children:_.reach.phone.paired})}):a||!n?t.jsx("span",{className:"wiz-row-side",children:t.jsx(A,{size:"lg",onClick:()=>void i().catch(()=>{}),children:_.telegram.newCode})}):t.jsx("span",{className:"wiz-qr-slot",children:t.jsx(Gw,{offer:n,square:s})})}function ite({wanted:e,added:n,onAdded:s,navigate:r,timezone:a}){const[i,l]=h.useState(void 0),[o,c]=h.useState(!1),[u,d]=h.useState(null),f=h.useCallback(()=>{Promise.resolve().then(()=>R.pageQuery("email","accounts")).then(m=>{var g,v,b;const p=((b=(v=(g=m==null?void 0:m.data)==null?void 0:g.accounts)==null?void 0:v[0])==null?void 0:b.address)??null;d(p),s(p!==null)}).catch(()=>{})},[]);return h.useEffect(()=>{let m=!1;return Promise.resolve().then(()=>R.pages()).then(p=>{if(m)return;const g=((p==null?void 0:p.pages)??[]).filter(b=>b.plugin==="email"),v=g.find(b=>b.id==="settings")??null;l(v?{page:v,siblings:g}:null)}).catch(()=>{m||l(null)}),f(),()=>{m=!0}},[f]),t.jsxs("div",{className:"wiz-row",children:[t.jsx("span",{className:"wiz-glyph","data-tone":"mail","aria-hidden":"true",children:t.jsx(le,{name:"mail"})}),t.jsxs("span",{className:"wiz-row-text",children:[t.jsx("span",{className:"wiz-opt-title",children:e?_.reach.mailbox.forTriage:_.reach.mailbox.title}),t.jsx("span",{className:"wiz-opt-line",children:i===null?_.reach.mailbox.unavailable:_.reach.mailbox.line})]}),t.jsx("span",{className:"wiz-row-side",children:n||u?t.jsx(Ee,{tone:"good",dot:!0,mono:u!==null,children:u??_.reach.mailbox.added}):i?t.jsx(A,{size:"lg",onClick:()=>c(!0),children:_.reach.mailbox.add}):null}),o&&i?t.jsx(Ge,{title:_.reach.mailbox.sheet,size:"wide",onClose:()=>{c(!1),f()},children:t.jsx(dw,{page:i.page,siblings:i.siblings,navigate:r,timezone:a,embedded:!0})}):null]})}function lte({app:e,onApp:n,browser:s,onBrowser:r}){const a=lm(),i=typeof navigator>"u"?null:gR(navigator.userAgent),[l,o]=h.useState(null),[c,u]=h.useState("idle"),[d,f]=h.useState(null),[m,p]=h.useState(null),[g,v]=h.useState(void 0),b=h.useRef(!1),j=h.useRef(!0);h.useEffect(()=>(j.current=!0,Promise.resolve().then(()=>R.browser()).then(C=>{var T;if(!j.current)return;const E=C==null?void 0:C.browser;E?((T=E.install)==null?void 0:T.state)==="running"?(o("none"),b.current=!0,u("installing"),w()):o(E.engine):o("other")}).catch(()=>{j.current&&o("other")}),()=>{j.current=!1}),[]);const x=(C,E)=>{j.current&&(b.current=!1,u("failed"),f(C),p(E??null))},y=async C=>{u("launching");let E;try{E=await R.browserCheck()}catch(T){return x(T instanceof xe?T.message:String(T))}if(j.current){if(E.ok){u("idle"),o(C),r(b.current?"installed":C);return}x(E.message,E.command)}},w=async()=>{var T,I;let C;try{C=await R.browser()}catch(F){return x(F instanceof xe?F.message:String(F))}if(!j.current)return;const E=C.browser;if(!E)return x(_.browser.failed(""));if(((T=E.install)==null?void 0:T.state)==="running"){u("installing"),v(E.install.progress),window.setTimeout(()=>void w(),1e3);return}return E.engine!=="none"?y(E.engine):x(((I=E.install)==null?void 0:I.line)??"")},k=()=>{if(p(null),l==="chrome"||l==="chromium"){y(l);return}b.current=!0,u("installing"),v(void 0),Promise.resolve().then(()=>R.browserInstall()).then(()=>{j.current&&window.setTimeout(()=>void w(),1e3)}).catch(C=>x(C instanceof xe?C.message:String(C)))},N=s==="chrome"||s==="chromium"||s==="installed",S=c==="installing"||c==="launching";return t.jsxs("div",{className:"wiz-row","data-wrap":c!=="idle"?"true":void 0,children:[t.jsx("span",{className:"wiz-glyph","data-tone":"good","aria-hidden":"true",children:t.jsx(le,{name:"globe"})}),t.jsxs("span",{className:"wiz-row-text",children:[t.jsx("span",{className:"wiz-opt-title",children:_.reach.app.title}),t.jsx("span",{className:"wiz-opt-line",children:_.reach.app.line})]}),t.jsxs("span",{className:"wiz-row-side",children:[e?t.jsx(Ee,{tone:"good",dot:!0,children:_.reach.app.installed}):a?t.jsx(A,{size:"lg",onClick:()=>{a.prompt().then(()=>a.userChoice).then(C=>{(!C||C.outcome==="accepted")&&n()}).catch(()=>{})},children:_.reach.app.install}):null,N?t.jsx(Ee,{tone:"good",dot:!0,children:_.reach.app.ready(s==="chrome"?"chrome":"chromium")}):l===null||l==="other"?null:t.jsx(A,{size:"lg",disabled:S,onClick:k,children:S?_.browser.installing:c==="failed"?_.browser.retry:l==="chrome"?_.reach.app.chrome:l==="chromium"?_.reach.app.chromium:_.reach.app.fetch})]}),!e&&!a&&i?t.jsx("span",{className:"wiz-row-note",children:i}):null,c==="installing"?t.jsxs("div",{className:"wiz-row-more",children:[t.jsx("span",{className:"wiz-opt-line",children:_.browser.needs}),t.jsx(kT,{progress:g})]}):c==="launching"?t.jsx("div",{className:"wiz-row-more",children:t.jsx(pr,{line:_.browser.launching})}):c==="failed"?t.jsxs("div",{className:"wiz-row-more",children:[t.jsx("span",{className:"wiz-opt-line",children:_.browser.failed(d??"")}),m?t.jsx(ute,{command:m}):null]}):null]})}function ote({answers:e,existing:n,onSettled:s,onTrouble:r,onReload:a,onBack:i}){const[l,o]=h.useState(()=>(n==null?void 0:n.name)??AU),[c,u]=h.useState(()=>n!=null&&n.picture||n!=null&&n.avatar?null:"buddi"),[d,f]=h.useState(n?null:_.assistant.purposeValue),[m,p]=h.useState(n?"":_.assistant.purposeValue);h.useEffect(()=>{if(!n)return;let y=!1;return R.firstAgentPersona().then(w=>{y||(f(w.persona),p(w.persona))},w=>{y||r(w instanceof xe?w.message:String(w))}),()=>{y=!0}},[n==null?void 0:n.id]);const[g,v]=h.useState(!1),b=hc.filter(y=>(e.takeOn??[]).includes(y.id)&&"mate"in y).map(y=>y.mate),j=x0.find(y=>y.id===c),x=()=>{if(l.trim()===""||g)return;v(!0);const y=!n||d!==null&&m.trim()!==""&&m.trim()!==d.trim()?{instructions:m.trim()}:{},w=n?R.updateFirstAgent({name:l.trim(),...y}):R.createFirstAgent({name:l.trim(),handle:Tee(l),description:"",...y,...e.brain?{accountId:e.brain.accountId}:{}});(async()=>{let k;try{k=await w}catch(S){r(S instanceof xe?S.message:String(S)),v(!1);return}let N=null;try{j&&await R.uploadAgentPicture(k.id,await yI(j.role))}catch(S){N=S instanceof xe?S.message:String(S)}v(!1),a(),s({...e,assistant:{id:k.id,name:l.trim(),avatar:j?"":(n==null?void 0:n.avatar)??""}}),N&&r(N)})()};return t.jsxs(t.Fragment,{children:[t.jsx($o,{children:_.assistant.title}),t.jsx(rt,{children:t.jsxs(ft,{children:[_.assistant.ask,b.length>0?_.assistant.team(b):""]})}),t.jsx(mn,{actions:t.jsxs(t.Fragment,{children:[t.jsx(Ss,{onClick:i,disabled:g}),t.jsx(Ao,{onClick:x,disabled:g||l.trim()===""||d===null,children:_.assistant.submit})]}),children:t.jsxs("div",{className:"wiz-meet",children:[t.jsxs("div",{className:"wiz-face",children:[t.jsx("span",{className:"wiz-face-tile","data-agent":(j==null?void 0:j.id)??"buddi","aria-hidden":"true",children:j?t.jsx("img",{src:Vi(j.role),alt:""}):n!=null&&n.picture?t.jsx("img",{src:n.picture,alt:""}):t.jsx("span",{className:"wiz-face-emoji",children:(n==null?void 0:n.avatar)??""})}),t.jsx("div",{className:"wiz-swatches",role:"group","aria-label":_.assistant.colour,children:x0.map(y=>t.jsx("button",{type:"button",className:"wiz-swatch","data-agent":y.id,"aria-label":_.assistant.swatch(y.label),"aria-pressed":c===y.id,onClick:()=>u(y.id)},y.id))}),t.jsx("span",{className:"wiz-face-cap",children:_.assistant.colour})]}),t.jsxs("div",{className:"wiz-stack",children:[t.jsx(re,{label:_.assistant.name,children:t.jsx("input",{value:l,maxLength:60,onChange:y=>o(y.target.value)})}),t.jsx(re,{label:_.assistant.purpose,hint:_.assistant.purposeHint,children:t.jsx("textarea",{className:"wiz-persona",value:m,maxLength:8e3,rows:7,onChange:y=>p(y.target.value)})})]})]})})]})}function cte({answers:e,assistantAgent:n,met:s,onMet:r,navigate:a,onPickAnotherBrain:i,onSpoken:l,progress:o,onProgress:c}){var L,O;const u=e.assistant,[d,f]=h.useState(s),[m,p]=h.useState([]),[g,v]=h.useState(!1),[b,j]=h.useState(!1),[x,y]=h.useState(!0),[w,k]=h.useState(!1),N=h.useRef(!1),S=h.useMemo(()=>n?[n]:[],[n]);h.useEffect(()=>{c()},[]),h.useEffect(()=>{if(!u||N.current)return;if(N.current=!0,s){f(s);return}let M=!1;return(async()=>{try{const P=await qe.startConversation(u.id);if(M)return;f(P.conversationId),r(P.conversationId),await R.onboardingStep(HP.handover,{conversationId:P.conversationId}).catch(()=>{}),await qe.send(u.id,{conversationId:P.conversationId,text:IU,opening:!0})}catch{M||(y(!1),v(!0))}})(),()=>{M=!0}},[u==null?void 0:u.id,s]),h.useEffect(()=>{if(!d)return;let M=!1;const P=Date.now(),H=()=>{qe.conversation(d).then(V=>{if(M)return;p(V.messages);const z=Date.now()-P;if(V.messages.some($S)){y(!1),v(!1),j(!1);return}const X=V.runs??[],K=X.some(ce=>ce.finishedAt===null),ee=X.length>0&&!K;j(K&&z>=Ree),(ee||z>=Iee)&&(y(!1),v(!0))}).catch(()=>{})};H();const U=window.setInterval(H,YP);return()=>{M=!0,window.clearInterval(U)}},[d]);const C=u&&d?Ze(u.id,d):null,E=m.some($S);h.useEffect(()=>{E&&C&&l(C)},[E,C,l]);const T=e.takeOn??[],I=_.handover.starters({days:T.includes("days"),mail:T.includes("mail"),mailbox:((L=e.reach)==null?void 0:L.mailbox)===!0}),F={days:T.includes("days"),mailbox:((O=e.reach)==null?void 0:O.mailbox)===!0,money:T.includes("money"),pictures:T.includes("pictures")},D=(o==null?void 0:o.waiting)??[],$=M=>{!u||!d||w||(k(!0),Promise.resolve().then(()=>qe.send(u.id,{conversationId:d,text:M})).then(()=>a(Ze(u.id,d),!0)).catch(()=>k(!1)))};return t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"wiz-hello",children:t.jsx(Ky,{messages:m,live:[],now:Date.now(),onOpen:()=>{},working:x,agents:S,agentName:(u==null?void 0:u.name)??"",...u?{agentId:u.id}:{},emptyHint:_.handover.waiting,plain:!0,workingLine:_.handover.looking((u==null?void 0:u.name)??"")})}),b&&!g?t.jsx(rt,{children:t.jsx(ft,{children:_.handover.slow})}):null,g?t.jsxs(t.Fragment,{children:[t.jsx(rt,{children:t.jsx(ft,{children:_.handover.silent})}),t.jsx(mn,{actions:t.jsx(Ao,{onClick:i,children:_.handover.again})})]}):null,E?t.jsx("div",{className:"wiz-starters",role:"group","aria-label":_.handover.starterLabel,children:I.map(M=>t.jsx("button",{type:"button",className:"wiz-starter",disabled:w,onClick:()=>$(M),children:M},M))}):null,E?t.jsx(PY,{setUp:F,navigate:M=>a(M,!0)}):null,E&&D.length>0?t.jsx(G,{tone:"warm",title:_.handover.waitingTitle(D.length),action:t.jsx(A,{variant:"accent",onClick:()=>a(kn,!0),children:_.handover.home}),children:_.handover.waitingBody(D)}):null,E&&C?t.jsx(mn,{actions:t.jsx(ht,{variant:"accent",size:"lg",href:C,onClick:M=>{M.preventDefault(),a(C,!0)},children:_.done.open})}):null]})}function ute({command:e}){const[n,s]=h.useState("idle"),r=()=>{var a;if(!((a=navigator.clipboard)!=null&&a.writeText)){s("failed");return}navigator.clipboard.writeText(e).then(()=>s("done"),()=>s("failed"))};return t.jsxs(ie,{gap:"sm",children:[t.jsx(Dt,{label:"The command to run",children:e}),t.jsxs(te,{align:"end",children:[n==="failed"?t.jsx("span",{className:"ui-toolbar-note",children:"Select it to copy."}):null,t.jsx(A,{size:"sm",onClick:r,children:n==="done"?"Copied":"Copy"})]})]})}function $S(e){return e.role==="assistant"&&(e.blocks??[]).some(n=>n.type==="text"&&n.text.trim()!=="")}function dte({onCancel:e,onStarted:n,onTrouble:s}){const[r,a]=h.useState(null),[i,l]=h.useState(""),[o,c]=h.useState(!1),u=()=>{!r||o||(c(!0),s(null),R.firstRunRestore(r,i.trim()).then(d=>{_v(d.job.id),n()}).catch(d=>s(d instanceof xe?d.message:String(d))).finally(()=>c(!1)))};return t.jsx(Ge,{title:_.restore.sheet,onClose:e,children:t.jsxs("div",{className:"wiz-restore",children:[t.jsx("p",{className:"wiz-foot",children:_.restore.lede}),t.jsx(re,{label:_.restore.file,children:t.jsx("input",{type:"file",onChange:d=>{var f;return a(((f=d.target.files)==null?void 0:f[0])??null)}})}),t.jsx(re,{label:_.restore.passphrase,hint:_.restore.passphraseHint,children:t.jsx("input",{type:"password",autoComplete:"off",value:i,onChange:d=>l(d.target.value)})}),t.jsxs(te,{align:"end",children:[t.jsx(A,{variant:"ghost",onClick:e,children:_.restore.cancel}),t.jsx(A,{variant:"accent",disabled:o||!r,onClick:u,children:_.restore.submit})]})]})})}function hte({onDone:e,onFailed:n}){const[s,r]=h.useState([]),a=h.useRef({onDone:e,onFailed:n});a.current={onDone:e,onFailed:n},h.useEffect(()=>{const l=qP();if(!l)return;let o=!1;const c=()=>{R.backupJob(l).then(d=>{o||(r(f=>f.includes(d.phase)?f:[...f,d.phase]),d.phase==="done"?(o=!0,_v(null),R.owner().then(f=>a.current.onDone(f.preferredName??void 0),()=>a.current.onDone(void 0))):(d.phase==="rolled-back"||d.phase==="failed")&&(o=!0,_v(null),a.current.onFailed(d.error??_.restore.phases[d.phase])))}).catch(()=>{})};c();const u=window.setInterval(c,YP);return()=>{o=!0,window.clearInterval(u)}},[]);const i=s.filter(l=>l in _.restore.phases);return t.jsxs(t.Fragment,{children:[t.jsx($o,{children:_.restore.title}),t.jsxs(rt,{children:[t.jsx(ft,{children:_.restore.started}),i.map(l=>t.jsx(ft,{children:_.restore.phases[l]},l))]}),t.jsx(pr,{})]})}function fte(e){return t.jsx(Yw.Provider,{value:null,children:t.jsx("div",{className:"wiz-sheet-body",children:t.jsx(mte,{...e})})})}function mte({onPaired:e,onDismiss:n}){const s=Eo(),[r,a]=h.useState(""),[i,l]=h.useState(!1),[o,c]=h.useState(null),{offer:u,square:d,paired:f,stale:m,ask:p}=Vw(()=>R.telegram().then(b=>b.paired),e),g=()=>{r.trim()===""||i||(l(!0),c(null),(async()=>{try{const b=await R.saveTelegramToken(r.trim());if(a(""),b.restartNeeded){c(b.note??_.telegram.restart);return}await p()}catch(b){c(b instanceof xe?b.message:String(b))}finally{l(!1)}})())},v=()=>{c(null),p().catch(b=>c(b instanceof xe?b.message:String(b)))};return f?t.jsxs(t.Fragment,{children:[t.jsx(rt,{children:t.jsx(ft,{children:_.telegram.paired})}),t.jsx(mn,{actions:t.jsx(A,{variant:"accent",onClick:n,children:_.telegram.close})})]}):u?t.jsxs(t.Fragment,{children:[t.jsx(rt,{children:t.jsx(ft,{children:m?_.telegram.expired:_.telegram.scan})}),t.jsx(mn,{actions:t.jsxs(t.Fragment,{children:[t.jsx(A,{variant:"ghost",onClick:n,children:_.telegram.notNow}),m?t.jsx(A,{variant:"accent",onClick:v,children:_.telegram.newCode}):null]}),children:m?null:t.jsx(Gw,{offer:u,square:d})})]}):t.jsxs(t.Fragment,{children:[t.jsxs(rt,{children:[t.jsx(ft,{children:_.telegram.how}),o?t.jsx(ft,{children:o}):null]}),t.jsx(mn,{actions:t.jsxs(t.Fragment,{children:[t.jsx(A,{variant:"ghost",onClick:n,children:_.telegram.notNow}),t.jsx(A,{variant:"accent",disabled:i||r.trim()==="",onClick:g,children:_.telegram.submit})]}),children:t.jsx(re,{label:_.telegram.field,grow:!0,children:t.jsx("input",{ref:s,type:"password",value:r,autoComplete:"off",spellCheck:!1,onChange:b=>a(b.target.value),onKeyDown:b=>{b.key==="Enter"&&(b.preventDefault(),g())}})})})]})}const sg={recovery:0,lost:1,paused:2},pte="Lost buddi. Retrying…",gte="The queue is paused. Nothing is being claimed until you resume it.";function xte(e){const n=[];return e.recovery&&n.push({id:"recovery",priority:sg.recovery,tone:"warning",text:SI,action:{label:"Finish the checklist",href:$x}}),e.lost&&n.push({id:"lost",priority:sg.lost,tone:"critical",text:pte}),e.paused&&n.push({id:"paused",priority:sg.paused,tone:"warning",text:gte,action:{label:"Resume",onClick:()=>{R.setPaused(!1).catch(()=>{})}}}),n}function vte({banners:e,onNavigate:n}){if(e.length===0)return null;const s=[...e].sort((l,o)=>l.priority-o.priority),r=s[0],a=s.slice(1),i=r.action;return t.jsxs("div",{className:"shell-banner",role:"status","data-tone":r.tone,"data-banner":r.id,children:[t.jsx("span",{className:"shell-banner-dot","aria-hidden":"true"}),t.jsx("span",{className:"shell-banner-text",children:r.text}),a.length>0?t.jsxs("span",{className:"shell-banner-more",title:a.map(l=>l.text).join(`
145
- `),children:["+",a.length," more"]}):null,i!=null&&i.href?t.jsx(ht,{size:"sm",href:i.href,onClick:l=>{l.preventDefault(),n(i.href)},children:i.label}):i?t.jsx(A,{size:"sm",onClick:i.onClick,children:i.label}):null]})}const XP=1e4,jte=3e4,ZP=6e3,Jw=/^(localhost|127(?:\.\d{1,3}){3}|\[?::1\]?)$|\.localhost$/i;function yte(e){return Jw.test(e)?t.jsxs(t.Fragment,{children:["Is buddi running on this Mac? ",t.jsx("code",{children:"buddi status"})," says."]}):t.jsx(t.Fragment,{children:"Is Tailscale on, and the Mac it runs on awake?"})}async function eM(e){let n;const s=new Promise((r,a)=>{n=setTimeout(()=>a(new xe(0,Ch)),e)});try{return{up:!0,version:await Promise.race([R.version(),s])}}catch(r){return Eh(r)?{up:!1}:{up:!0}}finally{clearTimeout(n)}}function tM(e){var n;return e.up&&ky((n=e.version)==null?void 0:n.web)?(window.location.reload(),!1):e.up}function wte({host:e,onRetry:n,retrying:s}){return t.jsxs("main",{className:"unreachable",role:"alert",children:[t.jsx("span",{className:"ui-blob","data-size":"lg","aria-hidden":"true",children:t.jsx("img",{src:Vi("core"),alt:""})}),t.jsxs("h1",{children:["buddi isn't answering at ",e,"."]}),t.jsx("p",{children:yte(e.replace(/:\d+$/,""))}),t.jsx("div",{className:"unreachable-actions",children:t.jsx(A,{variant:"accent",onClick:n,disabled:s,children:s?"Retrying…":"Retry"})})]})}function bte({children:e}){const[n,s]=h.useState("checking"),[r,a]=h.useState(!1),i=h.useRef(!1),l=h.useCallback(async()=>{if(i.current)return;i.current=!0,a(!0);const o=await eM(ZP);i.current=!1,a(!1),s(c=>c==="checking"?o.up?"up":"down":tM(o)?"up":"down")},[]);return h.useEffect(()=>{l()},[l]),h.useEffect(()=>{if(n!=="down")return;const o=window.setInterval(()=>void l(),XP);return()=>window.clearInterval(o)},[n,l]),n==="checking"?null:n==="down"?t.jsx(wte,{host:window.location.host,onRetry:()=>void l(),retrying:r}):t.jsx(t.Fragment,{children:e})}function kte(e=jte){const[n,s]=h.useState(!1);return h.useEffect(()=>{let r;const a=()=>{clearTimeout(r);const l=Vc();if(l===null)return s(!1);const o=l+e-Date.now();o<=0?s(!0):r=setTimeout(a,o)};a();const i=ey(a);return()=>{i(),clearTimeout(r)}},[e]),n}function Nte(){const e=kte();return h.useEffect(()=>{if(!e)return;const n=window.setInterval(()=>{eM(ZP).then(tM)},XP);return()=>window.clearInterval(n)},[e]),e}const Ste={local:"Local",tailnet:"Tailnet",reconnecting:"Reconnecting…"},TS=(e,n,s=`${n}s`)=>e===1?n:s;function Cte(){return Intl.DateTimeFormat().resolvedOptions().timeZone}function Ete(e){return e.includes("/")?e.split("/").pop().replace(/_/g," "):e}function Ate(e,n){return n?"reconnecting":Jw.test(e)?"local":"tailnet"}function nM(e,n,s=Cte()){const r=[],a=Ste[e.link];if(r.push({key:"link",route:Le("system"),dot:e.link==="reconnecting"?"warning":"good",text:a,label:`Connection: ${a}`}),e.focus){const u=`${ki[e.focus.mode]} ${ru(e.focus,e.timezone,n)}`;r.push({key:"focus",route:Le("notifications"),icon:"moon",text:u,label:`Focus: ${u}`})}const i=[];if(e.working>0&&i.push({key:"working",dot:"working",text:`${e.working} ${TS(e.working,"agent")} working`}),i.push(e.paused?{key:"queue",tone:"warning",text:"Queue paused"}:{key:"queue",text:"Queue running"}),e.failed>0&&i.push({key:"failed",tone:"critical",text:`${e.failed} failed`}),r.push({key:"work",route:e.failed>0?`${At}/jobs?state=failed`:`${At}/jobs`,parts:i,label:`Work: ${i.map(u=>u.text).join(", ")}`}),e.approvals>0){const u=`${TS(e.approvals,"approval")} waiting`;r.push({key:"approvals",route:ql,count:e.approvals,text:u,label:`${e.approvals} ${u}`})}if(e.version){const u=e.version.updateAvailable&&e.version.latest?e.version.latest:null;r.push({key:"version",route:Le("system"),end:!0,mono:`buddi ${e.version.current}`,update:u!==null,label:`buddi ${e.version.current}${u?`, a newer buddi is ready: ${u}`:""}`})}const l=e.timezone||s,o=Xt(n,l),c=l!==s;return r.push({key:"time",route:Le("you"),end:!0,time:o,...c?{zone:Ete(l)}:{},label:`Your time: ${o}${c?`, ${l}`:""}`}),r}function $te(e){var n;return e.link==="reconnecting"||e.failed>0?"critical":e.paused?"warning":e.approvals>0||(((n=e.version)==null?void 0:n.updateAvailable)??!1)?"attention":"good"}function sM(){const[e,n]=h.useState(()=>new Date);return h.useEffect(()=>{let s;const r=()=>{s=setTimeout(()=>{n(new Date),r()},6e4-Date.now()%6e4)};return r(),()=>clearTimeout(s)},[]),e}function Tte(){const[e,n]=h.useState(()=>Vc()!==null);return h.useEffect(()=>ey(()=>n(Vc()!==null)),[]),e}function rM({item:e}){var n;return t.jsxs(t.Fragment,{children:[e.dot?t.jsx("span",{className:"shell-status-dot","data-tone":e.dot,"aria-hidden":"true"}):null,e.icon?t.jsx(le,{name:e.icon,size:12}):null,e.count?t.jsx("span",{className:"ui-badge","aria-hidden":"true",children:e.count>99?"99+":e.count}):null,(n=e.parts)==null?void 0:n.map((s,r)=>t.jsxs(h.Fragment,{children:[r>0?t.jsx("span",{className:"shell-status-sep","aria-hidden":"true",children:"·"}):null,s.dot?t.jsx("span",{className:"shell-status-dot","data-tone":s.dot,"aria-hidden":"true"}):null,t.jsx("span",{"data-tone":s.tone,children:s.text})]},s.key)),e.text?t.jsx("span",{children:e.text}):null,e.mono?t.jsx("span",{className:"shell-status-mono",children:e.mono}):null,e.update?t.jsx("span",{className:"ui-badge","data-kind":"dot","data-testid":"status-update-dot","aria-hidden":"true"}):null,e.time?t.jsx("span",{className:"shell-status-time",children:e.time}):null,e.zone?t.jsx("span",{className:"shell-status-zone",children:e.zone}):null]})}function Rte({status:e,onNavigate:n}){const s=sM(),r=cm(),a=nM(e,s),i=l=>t.jsx("a",{className:"shell-status-item","data-item":l.key,href:l.route,"aria-label":l.label,title:l.label,onClick:o=>{o.preventDefault(),n(l.route)},children:t.jsx(rM,{item:l})},l.key);return t.jsxs("footer",{className:"shell-status","aria-label":"Status",children:[a.filter(l=>!l.end).map(i),t.jsx("span",{className:"shell-status-spacer"}),a.filter(l=>l.end).map(i),r.pin?t.jsx("button",{type:"button",className:"shell-status-item shell-status-lock","data-item":"lock","aria-label":`Lock now (${r.shortcut})`,title:`Lock now (${r.shortcut})`,onClick:()=>r.lockNow(),children:t.jsx(le,{name:"lock",size:13})}):null]})}function Ite({status:e,onNavigate:n}){const s=sM(),r=cm(),a=$te(e);return t.jsx("div",{className:"rail-status",children:t.jsxs(ju,{modal:!1,children:[t.jsx(yu,{asChild:!0,children:t.jsx("button",{type:"button",className:"rail-status-btn","aria-label":"Status",children:t.jsx("span",{className:"rail-status-dot","data-tone":a,"data-testid":"rail-status-dot","aria-hidden":"true"})})}),t.jsx(xo,{children:t.jsxs(wu,{className:"ui-menu rail-status-menu",side:"right",align:"end",sideOffset:10,children:[t.jsx(Di,{className:"ui-menu-label",children:"Status"}),nM(e,s).map(i=>t.jsx(zs,{asChild:!0,onSelect:()=>n(i.route),children:t.jsx("a",{className:"ui-menu-item rail-status-item","data-item":i.key,href:i.route,"aria-label":i.label,children:t.jsx("span",{className:"rail-status-line",children:t.jsx(rM,{item:i})})})},i.key)),r.pin?t.jsxs(t.Fragment,{children:[t.jsx(ra,{className:"ui-menu-sep"}),t.jsx(zs,{className:"ui-menu-item rail-status-item","data-item":"lock",onSelect:()=>r.lockNow(),children:t.jsxs("span",{className:"rail-status-line",children:[t.jsx(le,{name:"lock",size:12}),t.jsx("span",{children:"Lock now"})]})})]}):null]})})]})})}const Pte=1e4;function aM(){return h.useSyncExternalStore(eU,m0,m0)}function Mte(e){switch(e.kind){case"plugins":return{title:"Restarting buddi",line:e.line??"Loading your plugins…"};case"upgrade":return{title:"Upgrading buddi",line:e.line??"Upgrading…"};case"restore":return{title:"Restoring buddi",line:e.line??"Putting your backup in place…"};case"recovery":return{title:"Restarting buddi",line:e.line??"Turning schedules, watchers and the phone back on…"};case"stop":return{title:"buddi is stopped",line:"This page comes back by itself once buddi is started again."};default:return{title:"Restarting buddi",line:e.line??"Back in a few seconds…"}}}function RS(e){const n=Math.max(0,Math.floor(e/1e3));return`${Math.floor(n/60)}:${String(n%60).padStart(2,"0")}`}function Dte({command:e}){const[n,s]=h.useState(!1);return h.useEffect(()=>{if(!n)return;const r=window.setTimeout(()=>s(!1),1600);return()=>window.clearTimeout(r)},[n]),t.jsxs("div",{className:"rs-cmd",children:[t.jsx("code",{className:"rs-cmd-text",children:e}),t.jsx(A,{size:"sm",onClick:()=>{var r;(r=navigator.clipboard)==null||r.writeText(e).then(()=>s(!0),()=>{})},children:n?"Copied":"Copy"})]})}function Ote({state:e,elapsedMs:n,hostname:s=window.location.hostname,onReload:r=()=>Ol.reload()}){const a=Mte(e),i=e.kind==="stop",l=!i&&n>=(e.patienceMs??Y3),o=Jw.test(s),c=h.useRef(null);h.useEffect(()=>{var d;return(d=c.current)==null?void 0:d.focus()},[]);const u=i?o?"This starts it again, in Terminal on this computer:":"On the computer buddi runs on, this starts it again:":o?"This says what it’s doing, in Terminal on this computer:":"On the computer buddi runs on, this says what it’s doing. Is that computer awake, and Tailscale on?";return t.jsx("div",{className:"ui-fieldbg rs-field","data-quiet":"true",children:t.jsx("div",{ref:c,className:"rs",role:"dialog","aria-modal":"true","aria-labelledby":"rs-title",tabIndex:-1,"data-state":i?"stopped":l?"long":"waiting",children:t.jsxs("div",{className:"rs-body",children:[t.jsx("span",{className:"ui-mascot rs-blob","data-size":"lg","aria-hidden":"true",children:t.jsx(ku,{role:"core",state:i||l?"idle":"working",className:"ui-mascot-blob"})}),t.jsx("h1",{id:"rs-title",className:"rs-title",children:a.title}),t.jsx("p",{className:"rs-line",role:"status",children:l?"Still waiting — buddi may need a hand.":a.line}),!l&&e.step?t.jsx("p",{className:"rs-step",children:e.step}):null,i||l?null:t.jsx("div",{className:"rs-track","aria-hidden":"true",children:t.jsx("span",{})}),i||l?t.jsxs("div",{className:"rs-help",children:[t.jsx("p",{className:"rs-help-line",children:u}),t.jsx(Dte,{command:i?"buddi service start":"buddi status"})]}):null,t.jsxs("div",{className:"rs-foot",children:[t.jsx("span",{className:"rs-meta",children:i?"Checking every few seconds.":l?`${RS(n)} · still checking every few seconds`:n>=Pte?`${RS(n)} · this page reloads when buddi is back`:"This page reloads when buddi is back."}),i||l?t.jsx(A,{size:"sm",variant:l?"accent":void 0,onClick:r,children:"Reload"}):null]})]})})})}function Lte(e){const[n,s]=h.useState(()=>Ol.now());return h.useEffect(()=>{if(!e)return;s(Ol.now());const r=window.setInterval(()=>s(Ol.now()),1e3);return()=>window.clearInterval(r)},[e]),e?Math.max(0,n-e.startedAt):0}function Fte({children:e}){const n=aM(),s=Lte(n),r=h.useRef(null);return h.useEffect(()=>{nU();let a=Vc()!==null;const i=ey(()=>{const o=Vc()!==null;a&&!o&&p0(),a=o}),l=()=>void p0();return window.addEventListener(Yc,l),()=>{i(),window.removeEventListener(Yc,l)}},[]),h.useEffect(()=>{const a=r.current;a&&(a.toggleAttribute("inert",n!==null),n?a.setAttribute("aria-hidden","true"):a.removeAttribute("aria-hidden"))},[n]),t.jsxs(t.Fragment,{children:[t.jsx("div",{ref:r,className:"rs-host",children:e}),n?t.jsx(Ote,{state:n,elapsedMs:s}):null]})}const _te="(max-width: 1080px)",zte="(max-width: 720px)";function Ute(){const[e,n]=h.useState(()=>window.location.hash||kn);h.useEffect(()=>{const r=()=>n(window.location.hash||kn);return window.addEventListener("hashchange",r),()=>window.removeEventListener("hashchange",r)},[]);const s=h.useCallback((r,a=!1)=>{a?window.history.replaceState(null,"",r):window.location.hash=r,n(r)},[]);return[e,s]}function Bte(){const[e,n]=LR();h.useEffect(()=>{OR(e)},[e]);const s=h.useCallback(r=>n({theme:r}),[n]);return[e.theme,s]}const IS=new Map;function Wte(){var q,he,Sn,on;const[e,n]=Ute(),[s,r]=h.useState("UTC"),[a,i]=h.useState({approvals:0,failed:0,paused:!1,running:0,needs:0}),[l,o]=Bte(),c=ws(Ry),[u,d]=h.useState(!1),[f,m]=h.useState([]),[p,g]=h.useState(null),[v,b]=h.useState(null),[j,x]=h.useState([]),[y,w]=h.useState(!1),[k,N]=h.useState(null),[S,C]=h.useState(null),[E,T]=h.useState(0),[I,F]=h.useState(null),D=uU(),$=f.find(Se=>Se.id===p)??null,L=$!==null&&nK(e),[O,M]=h.useState(!1),P=h.useCallback(()=>M(!0),[]);h.useEffect(()=>{L||M(!1)},[L]),P7(n,Bd(e)===null,L?P:void 0);const H=ws(_te),U=NI(),V=K$(),z=RR(),X=me(()=>Promise.resolve().then(()=>R.version()),[],F3),K=X.data;G3(X.reload);const ee=K&&!K.checkout&&K.updateAvailable?K:null,ce=ky(K==null?void 0:K.web);q3(K==null?void 0:K.web);const pe=((q=me(()=>Promise.resolve().then(()=>R.connectionSignals()),[],6e4).data)==null?void 0:q.signals)??[],[oe,Re]=h.useState(null),Oe=h.useMemo(()=>new Set(oe?[oe]:[]),[oe]),[Je,W]=h.useState(new Map);h.useEffect(()=>{const Se=()=>{R.conversations().then(nt=>{const lt=new Map;for(const gn of nt.conversations){const Cn=gn.lastMessageAt??gn.createdAt,Wn=lt.get(gn.agentId);(!Wn||Cn>Wn)&&lt.set(gn.agentId,Cn)}W(lt)}).catch(()=>{})};Se();const Me=window.setInterval(Se,3e4);return()=>window.clearInterval(Me)},[e]);const[se,Y]=h.useState(!1);h.useEffect(()=>{if(se)return;let Se=!1;return R.onboarding().then(Me=>{Se||(Y(!0),Me.state==="pending"&&Me.needs.model&&!Bd(window.location.hash)&&n(s3,!0))}).catch(()=>{Se||Y(!0)}),()=>{Se=!0}},[se,n]),h.useEffect(()=>{const Se=S3(e);Se&&n(Se,!0)},[e,n]),h.useEffect(()=>{let Se=!1;const Me=()=>{qe.agents().then(lt=>{Se||(m(lt.agents),XD(lt.commands),I3(lt.defaultAgentId??null),g(lt.defaultAgentId??null),b(gn=>{var Cn;return gn??lt.defaultAgentId??((Cn=lt.agents[0])==null?void 0:Cn.id)??null}))}).catch(()=>{})};Me();const nt=window.setInterval(Me,15e3);return window.addEventListener("focus",Me),window.addEventListener(Dr,Me),()=>{Se=!0,window.clearInterval(nt),window.removeEventListener("focus",Me),window.removeEventListener(Dr,Me)}},[e]),h.useEffect(()=>{let Se=!1;const Me=()=>{qe.groups().then(lt=>{Se||x(lt.groups)}).catch(()=>{})};Me();const nt=window.setInterval(Me,3e4);return()=>{Se=!0,window.clearInterval(nt)}},[e]);const Ne=d$(f,p),we=a3(e),fe=ZA(e),ge=fe?j.find(Se=>Se.id===fe.groupId)??null:null,Pe=fe?null:(we==null?void 0:we.agentId)??v;h.useEffect(()=>{we&&b(we.agentId)},[we==null?void 0:we.agentId]);const je=h.useRef(null);we&&(je.current=e);const de=Se=>{b(Se),n(Ze(Se))},ke=Se=>n(xi(Se)),Be=h.useCallback((Se,Me,nt=!0)=>n(fe?xi(fe.groupId,Me):Ze(Se,Me),nt),[n,fe==null?void 0:fe.groupId]),[Ue,ut]=h.useState(!1),[,dt]=h.useState(0);h.useEffect(()=>{const Se=()=>{dt(Me=>Me+1),R.session().then(Me=>r(Me.timezone)).catch(()=>{})};return window.addEventListener(ux,Se),()=>window.removeEventListener(ux,Se)},[]),h.useEffect(()=>{R.session().then(Se=>{Qj({timeFormat:Se.timeFormat??null,dateFormat:Se.dateFormat??null}),r(Se.timezone),ut(!0)}).catch(()=>{})},[]);const Q=dK(Ue);gK(Ue,Q.refresh,()=>ut(!1)),h.useEffect(()=>{const Se=()=>{R.overview().then(nt=>{var lt;return i({approvals:nt.approvals.pending,failed:nt.jobs.failed??0,paused:nt.paused,running:nt.running??0,needs:((lt=nt.needsYou)==null?void 0:lt.total)??nt.approvals.pending+(nt.jobs.failed??0)})}).catch(()=>{})};Se();const Me=window.setInterval(Se,2e4);return window.addEventListener(bi,Se),()=>{window.clearInterval(Me),window.removeEventListener(bi,Se)}},[]);const Ae=me(()=>Promise.resolve().then(()=>R.focus()),[],6e4),tt=h.useRef(Ae.reload);tt.current=Ae.reload,h.useEffect(()=>{const Se=()=>tt.current();return window.addEventListener(bi,Se),()=>window.removeEventListener(bi,Se)},[]);const Ct=Tte(),yt=Nte(),kt=aM()!==null,Bn=ws(zte);h.useEffect(()=>{if(!Ue)return;if(e===C3){w(!0),n(oa,!0);return}const Se=E3(e),Me=new Date().toDateString();!Se||IS.get(Se)===Me||(IS.set(Se,Me),R.tipsSeenPage(Se).catch(()=>{}))},[e,Ue,n]);const hs={link:Ate(window.location.hostname,Ct&&!kt),focus:((he=Ae.data)==null?void 0:he.focus)??null,working:a.running,paused:a.paused,failed:a.failed,approvals:a.approvals,version:K?{current:K.current,latest:K.latest,updateAvailable:!K.checkout&&K.updateAvailable}:void 0,timezone:s},In=xte({recovery:((Sn=U.data)==null?void 0:Sn.active)===!0,lost:yt&&!kt,paused:a.paused}),fs=Bd(e),Zt=a$(e),ms=Zt===oa,Tt=k?j.find(Se=>Se.id===k.groupId)??null:null,$e=Se=>x(Me=>Me.map(nt=>nt.id===Se.id?Se:nt)),Qe=()=>N(null),ze=y?t.jsx(xK,{agents:f,onClose:()=>w(!1),onCreated:Se=>{x(Me=>[...Me,Se]),w(!1),n(xi(Se.id))}}):Tt&&(k==null?void 0:k.kind)==="members"?t.jsx(BH,{group:Tt,agents:f,onClose:Qe,onSaved:$e}):Tt&&(k==null?void 0:k.kind)==="rename"?t.jsx(WH,{group:Tt,onClose:Qe,onSaved:Se=>{$e(Se),Qe()}}):Tt&&(k==null?void 0:k.kind)==="clear"?t.jsx(KH,{group:Tt,onClose:Qe,onCleared:()=>{Qe(),T(Se=>Se+1),n(xi(Tt.id),!0)}}):Tt&&(k==null?void 0:k.kind)==="delete"?t.jsx(VH,{group:Tt,agents:f,onClose:Qe,onDeleted:Se=>{const Me=j.findIndex(nt=>nt.id===Tt.id);Qe(),x(nt=>nt.filter(lt=>lt.id!==Tt.id)),C({group:Tt,index:Me,until:Se}),n(je.current??oa)}}):null,Nt=()=>{const Se=S;Se&&(C(null),qe.restoreGroup(Se.group.id).then(Me=>{x(nt=>{if(nt.some(gn=>gn.id===Me.id))return nt;const lt=[...nt];return lt.splice(Math.min(Math.max(Se.index,0),lt.length),0,Me),lt}),n(xi(Me.id))}).catch(()=>F(Se.group.name)))};return fs?t.jsx(Vk,{delayDuration:400,children:t.jsxs(Pk,{swipeDirection:"right",children:[t.jsx(Oee,{navigate:n,timezone:s}),t.jsx(Mk,{className:"ui-toasts"})]})}):t.jsx(_U,{picture:(on=f.find(Se=>Se.id===p))==null?void 0:on.picture,children:t.jsx(Vk,{delayDuration:400,children:t.jsxs(Pk,{swipeDirection:"right",children:[ze,t.jsxs("div",{className:"wb-shell",children:[t.jsx(vte,{banners:In,onNavigate:n}),t.jsxs("div",{className:"wb",children:[t.jsx(w7,{attention:a.needs,place:Zt,onNavigate:n,theme:l,onTheme:o,plugins:R7(V.rail,z),updateAvailable:ee!==null,settingsDot:pe.length>0?TR:void 0,stale:ce,timezone:s,version:K&&!K.checkout?{current:K.current,latest:K.latest,updateAvailable:K.updateAvailable}:K?{current:K.current,updateAvailable:!1}:void 0,status:Bn?t.jsx(Ite,{status:hs,onNavigate:n}):void 0}),ms&&!H?t.jsx(g$,{agents:Ne,currentId:Pe,attention:D,onSelect:de,lastActivity:Je,working:Oe,groups:j,currentGroupId:(ge==null?void 0:ge.id)??null,onSelectGroup:ke,onNewGroup:()=>w(!0)}):null,ms?t.jsx(GH,{timezone:s,agents:Ne,agentId:ge?ge.coordinator:Pe,defaultAgentId:p,group:ge,...ge?{onGroupAction:Se=>N({kind:Se,groupId:ge.id})}:{},requestedConversationId:(fe==null?void 0:fe.conversationId)??(we==null?void 0:we.conversationId),requestedTab:we==null?void 0:we.tab,onConversationOpened:Be,onSelectAgent:de,onWorking:Re,attention:D,agentsInHeader:H,narrow:c,canvasOpen:u,onOpenCanvas:()=>d(!0),onCloseCanvas:()=>d(!1)},`room-${E}`):t.jsx("main",{"data-ground":Hte(Zt,e)?"plain":void 0,"data-layout":Zt===yn?"split":void 0,children:t.jsx(Kte,{hash:e,place:Zt,timezone:s,navigate:n,agents:f,defaultAgentId:p,attention:D,pluginPages:V,update:ee,connectionSignals:pe})})]}),Bn?null:t.jsx(Rte,{status:hs,onNavigate:n})]}),L&&$?t.jsx(sK,{agent:$,agents:f,timezone:s,open:O,onOpenChange:M,navigate:n}):null,t.jsxs(cK,{placement:oK(L,O),children:[t.jsx(hK,{queue:Q.queue,agents:f,navigate:n,onDismiss:Q.dismiss}),S?t.jsx(eu,{title:`Deleted ${S.group.name}`,body:"Its history goes for good in a few seconds.",duration:jK,onUndo:Nt,onGone:()=>C(null)},S.group.id):null,I?t.jsx(eu,{title:`${I} is gone for good`,body:"Undo came too late to bring it back.",duration:6e3,onGone:()=>F(null)},`late-${I}`):null,t.jsx(Mk,{className:"ui-toasts"})]})]})})})}function Hte(e,n){return xy(n)!==null}function Kte({place:e,pluginPages:n,...s}){const r={...s,pluginPages:n},a=xy(s.hash);if(a){const i=n.find(a.plugin,a.page);if(i)return t.jsx(dw,{page:i,item:a.item??null,params:vy(s.hash),navigate:s.navigate,timezone:s.timezone,siblings:n.all.filter(l=>l.plugin===a.plugin)});if(n.all.length===0)return t.jsx(t.Fragment,{})}switch(e){case vt:return t.jsx(xY,{...r});case At:return t.jsx(X7,{...s});case yn:return t.jsx(ree,{...r});case pa:return t.jsx(X9,{...s});default:return t.jsx(JY,{...r})}}function Vte(){"serviceWorker"in navigator&&window.addEventListener("load",()=>{const e=`./sw.js?v=${encodeURIComponent(by)}`;navigator.serviceWorker.register(e,{scope:"./"}).catch(()=>{})})}function Gte({search:e=location.search}){const[n,s]=h.useState(null),r=h.useRef(!1);return h.useEffect(()=>{if(r.current)return;r.current=!0;const a=new URLSearchParams(e);try{history.replaceState(null,"",location.pathname)}catch{}const i=a.get("state")??"",l=a.get("code")??void 0,o=a.get("error")??void 0;R.connectionCallback({state:i,...l?{code:l}:{},...o?{error:o}:{}}).then(c=>{s({ok:!0,name:c.name,cli:c.cli===!0});try{const u=new BroadcastChannel(gI);u.postMessage({id:c.id}),u.close()}catch{}window.setTimeout(()=>{try{window.close()}catch{}},1500)}).catch(c=>s({ok:!1,message:c instanceof Error?c.message:String(c)}))},[e]),t.jsx("main",{className:"ui-page connections-callback",children:t.jsxs(ie,{gap:"lg",children:[t.jsx("h2",{className:"ui-page-title",children:"Connections"}),n===null?t.jsx(G,{tone:"accent",role:"status",children:"Finishing the sign-in…"}):null,n!=null&&n.ok?t.jsxs(G,{tone:"good",role:"status",title:`Signed in to ${n.name}`,children:["buddi keeps the sign-in in its vault. You can close this tab; ",n.cli?"the terminal carries on.":"the other one carries on."]}):null,n&&!n.ok?t.jsx(G,{tone:"critical",role:"alert",title:"Nothing was connected",children:n.message}):null,n?t.jsx(ht,{href:"/#/settings/connections",children:"Back to Connections"}):null]})})}const PS=document.getElementById("root");PS&&V1(PS).render(t.jsx(h.StrictMode,{children:location.pathname==="/connections/callback"?t.jsx(Gte,{}):t.jsx(Fte,{children:t.jsx(bte,{children:t.jsx(y7,{children:t.jsx(Wte,{})})})})}));Vte();export{Yte as c,yM as g};